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

#ifdef DEBUG
#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))

#define LOGM(msg) (cerr << (msg))

#define LOGV(vec, sep) {                                        \
    cerr << #vec << " =";                                       \
    for (const auto& v : (vec)) cerr << " " << v;               \
    cerr << (sep); }

#define LOGA(arr, N, sep) {                                     \
        cerr << #arr << " =";                                   \
        for (int i = 0; i < N; ++i) cerr << " " << (arr)[i];    \
        cerr << (sep); }

#define LOGA2(arr, N, M, sep) {                                 \
        cerr << #arr << " =\n";                                 \
        for (int i = 0; i < N; ++i) {                           \
            for (int j = 0; j < M; ++j)                         \
                cerr << (arr)[i][j] << " ";                     \
            cerr << endl;                                       \
        } cerr << (sep); }
#else
#define LOG(var, sep)
#define LOGM(msg)
#define LOGV(vec, sep)
#define LOGA(arr, N, sep)
#define LOGA2(arr, N, M, sep)
#endif

using namespace std;
using iii = tuple<int, int, int>;

template<typename T>
class BITree {
private:
    vector<T> ts;
    int N;

public:
    BITree(int n) : ts(n + 1, 0), N(n) {}

    T RSQ(int i, int j)
    {
        return RSQ(j) - RSQ(i - 1);
    }

private:
    int LSB(int n) { return n & (-n); }

    T RSQ(int i)
    {
        T sum = 0;

        while (i >= 1)
        {
            sum += ts[i];
            i -= LSB(i);
        }

        return sum;
    }

public:
    void add(int i, const T& x)
    {
        if (i == 0)
            return;

        while (i <= N)
        {
            ts[i] += x;
            i += LSB(i);
        }
    }
};


vector<int> solve(int N, int Q, const vector<int>& xs, const vector<iii>& qs)
{
    priority_queue<iii, vector<iii>, greater<iii>> pq(qs.begin(), qs.end());
    BITree<int> ft(N);
    map<int, int> is;
    vector<int> ans(Q);

    for (int R = 1; R <= N; ++R)
    {
        ft.add(R, 1);

        auto c = xs[R];
        LOG(c, ' '); LOG(is[c], endl);

        if (is[c])
            ft.add(is[c], -1);

        is[c] = R;

        while (not pq.empty() and get<0>(pq.top()) == R)
        {
            auto L = get<1>(pq.top()), i = get<2>(pq.top());
LOG(L, ' '); LOG(R, ' '); LOG(i, ' '); LOG(ft.RSQ(L, R), endl);
            pq.pop();

            ans[i] = ft.RSQ(L, R);
        }
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, Q;
    cin >> N >> Q;

    vector<int> xs(N + 1);

    for (int i = 1; i <= N; ++i)
        cin >> xs[i];

    vector<iii> qs(Q);

    for (int i = 0; i < Q; ++i)
    {
        int L, R;
        cin >> L >> R;
        qs[i] = iii(R, L, i);
    }

    auto ans = solve(N, Q, xs, qs);

    for (auto x : ans)
        cout << x << '\n';

    return 0;
}


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

using namespace std;

int main(){
    int n; cin>>n;
    vector<int> a(n);
    for (int i=0; i<n; ++i) cin>>a[i];
    int m = a[0], c = 1;
    for (int i=1; i<n; ++i){
        if (a[i]>= m) ++c;
        m = max(m, a[i]);
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
a = list(map(int, input().split()))
if a[1]!=0:
    b = list(map(int, input().split()))
    c=100
    d=0
    for i in range(201):
        if abs(a[0]-i)<c and i not in b:
            c=abs(a[0]-i)
            d=i
        if i>c+a[0]:
            break
    print(d)

else:
    print(a[0])

Measured memory_bytes: 9200
# 169A
# 1.入力をちゃんと受け取ること
# ex:「2　5」　a=2,b=5
a, b = map(int, input().split())
#print(a)
#print(b)
# 2.目的通りの計算をする
# ex:2つの整数AとBの掛け算をやる
answer = a * b
# 3.計算の結果を出力する
print(answer)

Measured memory_bytes: 9028
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> a(n);
	int ans=1;
	int cnt=1;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(a[i]){
			cnt++;
			ans=max(ans,cnt);
		}
		else{
			cnt=1;
		}
	}
	cout << ans << endl;
} 


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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 mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};


int main(){
    int n,k;cin >> n >> k;
    LL r,p,s;cin >> r >> s >> p;
    string t;cin >> t;
    vector<bool> u(n,false);
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        if(i < k){
            if(t[i] == 'r') ans+=p;
            else if(t[i] == 'p') ans += s;
            else ans += r;
            u[i] = true;
        }
        else{
            if(u[i-k]&&t[i] == t[i-k]){
            }
            else{
                if(t[i] == 'r') ans+=p;
                else if(t[i] == 'p') ans += s;
                else ans += r;
                u[i] = true;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
two = 0
four = 0

for i in a:
    if i%4 == 0:
        four += 1
    elif i%2 == 0:
        two += 1

if n == two:
    print("Yes")
elif four/(n - two) >= 0.5:
    print("Yes")
elif four/(n - 1) >= 0.5:
    print("Yes")
else:
    print("No")

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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    int ns = 0;
    rep(i,s.length()){
        if(s[i] == 'S') ns++;
        else {
            if(ns > 0) {
                ans += 2;
                ns--;
            }
        }
    }
    cout << s.length() - ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>

vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
	int N;
	cin >> N;
    
    vector<int> Ai;
    rep(i,N){
		int tmp_Ai;
		cin >> tmp_Ai;
		Ai.push_back(tmp_Ai);
	}
    
    sort(Ai.begin(),Ai.end());
    vector<int64_t> MinDiv;
    vector<int64_t> secondMinDiv;

    MinDiv = divisor(Ai.at(0));
    secondMinDiv = divisor(Ai.at(1));
    
    int ans1 = 0;
    
  	rep(i,MinDiv.size()){
      int tmpcnt = 0;
      rep(j,N){
        if((Ai.at(j) % MinDiv.at(i)) != 0) tmpcnt++;
      }
      if(tmpcnt < 2) ans1 = MinDiv.at(i);
	}
  
	int ans2 = 0;
  	rep(i,secondMinDiv.size()){
      int tmpcnt = 0;
      rep(j,N){
        if((Ai.at(j) % secondMinDiv.at(i)) != 0) tmpcnt++;
      }
      if(tmpcnt < 2) ans2 = secondMinDiv.at(i);
	}  
  
  	cout << max(ans1,ans2) << endl;
    return 0;
}


Measured memory_bytes: 892
def main():
    n,k = map(int,input().split())
    a = [0] * n
    for i in range(k):
        d = int(input())
        x = list(map(int,input().split()))
        for j in range(d):
            a[x[j]-1] = 1


    print(a.count(0))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
from collections import Counter
n = int(input().strip())
vs = [int(i) for i in input().split(' ')]
vs1 = vs[::2]
vs2 = vs[1::2]
a = Counter(vs1).most_common()
b = Counter(vs2).most_common()

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    candidates = []
    if len(a) != 1:
        candidates.append(n - a[1][1] - b[0][1])
    if len(b) != 1:
        candidates.append(n - a[0][1] - b[1][1])
    if len(candidates) != 0:
        print(min(candidates))
    else:
        print(n//2)


Measured memory_bytes: 21084
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <climits>
#include <random>
#include<algorithm>

#define int_max 2147483647;

//AGC 30

void Problem_A(void)
{
    int a ,b ;
    std::cin>>a>>b;
    if(b%a == 0)
    {
        std::cout<<a+b;
    }
    else
    {
        std::cout<<b - a;
    }
}

void Problem_B(void)
{
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int> > mat (n,std::vector<int>(m+1));
    for(int i = 0; i < n ; i ++)
    {
        std::cin>> mat[i][0];
        for (int j = 1; j <= int(mat[i][0]); j++)
        {
            std::cin>>mat[i][j];
        }
    }

    std::vector<int> manage_vec(m);
    for(int i = 0; i < m; i ++)
    {
        manage_vec[i] = 0;
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j <= int(mat[i][0]); j++)
        {
            manage_vec[mat[i][j]-1] = manage_vec[mat[i][j]-1] + 1;
        }
    }
    int check = 0;
    for (int i = 0; i < m; i++)
    {
        if(manage_vec[i] == n)
        {
            check = check + 1;
        }
    }

        std::cout<<check;
    
    return;
}


void Problem_C(void)
{
    int n;
    std::cin>>n;

    std::vector<int> vec(n);

    for(int i = 0; i < n ; i ++)
    {
        std::cin>>vec[i];
    }

    int check = n;
    int min;
    int point_min;
    int r , q ;
    while(1)
    {
        std::sort(vec.begin(),vec.end());
        for(int i = 0; i < n ; i ++)
        {
            if(vec[i]!=0)
            {
                min = vec[i];
                point_min = i;

                break;
            }
        }

        if (point_min == n - 1)
        {
            std::cout << min;
            return;
        }

        for(int i = point_min + 1 ; i < n ; i ++)
        {
            vec[i] = vec[i]%min;
        }

    }

    return;
}
int main(int argc, char const *argv[])
{
    Problem_C();
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;

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

    int ans = 0;
    unordered_set<int> dish;
    for (size_t i = 0; i < n; i++)
    {
        int d;
        cin >> d;
        if (dish.count(d) == 0) {
            ans++;
            dish.insert(d);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll letter[26]={0};
char s[maxn];
int main()
{
	scanf("%s",s);
	ll len=strlen(s);
	ll ans=(len-1)*len/2+1;
	for(int i=0;i<len;i++)
	{
		letter[s[i]-'a']++;
	}
	for(int i=0;i<26;i++)
	{
		ans-=(letter[i]*(letter[i]-1)/2);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
typedef long long ll;

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

struct state{
  ll v;
  state() : v(0){}
  state(const vector<int> &v) : v(0) { REP(i,v.size()) set(i, v[i]); }
  vector<int> decode(int n) const{
    vector<int> v(n); REP(i,n) v[i] = get(i);
    return v;
  }

  inline void set(int pos, int val){
    v &= ~(((1ll << ((pos + 1) * 4)) - 1) - ((1ll << (pos * 4)) - 1));
    v |= ((ll)val) << (pos * 4);
  }

  inline int get(int pos) const{
    return (v >> (pos * 4)) & ((1 << 4) - 1);
  }
};

map<ll, int> solve(int n, state s, map<ll, int> *prev = NULL){
  map<ll, int> ret;

  queue<state> q;
  ret[s.v] = 0; q.push(s);

  while(q.size()){
    const state st = q.front(); q.pop();
    const int cnt  = ret[st.v];

    if(prev != NULL && prev->count(st.v))
      throw (*prev)[st.v] + cnt;
    if(cnt == 4) continue;

    REP(i,n) REP(j,i){
      vector<int> v = st.decode(n);
      reverse(v.begin() + j, v.begin() + i + 1);
      const state next(v);
      if(ret.count(next.v) == 0){
        ret[next.v] = cnt + 1;
        q.push(next);
      }
    }
  }

  return ret;
}

int main(){
  const int n = getInt();
  state init;
  state goal;
  REP(i,n) init.set(i, getInt() - 1);
  REP(i,n) goal.set(i, i);

  if(init.v == goal.v){
    cout << 0 << endl;
  }else{
    map<ll, int> s1 = solve(n, init);
    try{
      map<ll, int> s2 = solve(n, goal, &s1);
      cout << 9 << endl;
    }catch(int e){
      cout << e << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 34992
A=int(input())
l=list(map(int,input().split()))
list_change=[0]*100001
for i in l:
   list_change[i]+=1
N=int(input())
total=sum(l)
for i in range(N):
   A,B=list(map(int,input().split()))
   X=list_change[A]
   list_change[A]=0
   list_change[B]+=X
   total+=(B-A)*X
   print(total)

Measured memory_bytes: 21056
#include <stdio.h>

int main()
{
    int a = 1, b = 1, c;

    for(a = 1; a <= 9; a++)
        for(b = 1; b <= 9; b++){
        c = a * b;
        printf("%dx%d=%d\n", a, b, c);
        }

    return 0;
}

Measured memory_bytes: 520
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
 
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;
 #define mod 998244353
int modval[25];
int arr[10];
signed main() {
 
	
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://www.coursera.org/learn/algorithms-on-strings/home/welcome
	//https://www.coursera.org/lecture/algorithms-on-strings/suffix-array-and-suffix-tree-TV4I6
	
	int a;
	cin>>a;
	cout<<a*a*3;	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2005;
string str;
int n,m,q,a[N][N],v[N][N],e[N][N],s[N][N],up[N][N],lf[N][N];
int main()
{
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)
	{
		cin>>str;
		for(int j=0;j<m;j++)
		  a[i][j+1]=str[j]-'0';
	}
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    {
	    	v[i][j]=v[i-1][j]+v[i][j-1]-v[i-1][j-1]+a[i][j];
	    	if(a[i][j])  e[i][j]=a[i-1][j]+a[i][j-1];
		}
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+e[i][j];
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    up[i][j]=up[i][j-1]+(a[i][j]&&a[i-1][j]);
	for(int j=1;j<=m;j++)
	  for(int i=1;i<=n;i++)
	    lf[i][j]=lf[i-1][j]+(a[i][j]&&a[i][j-1]);
	while(q--)
	{
		int x1,x2,y1,y2,nv,ne;
		cin>>x1>>y1>>x2>>y2;
		nv=v[x2][y2]-v[x2][y1-1]-v[x1-1][y2]+v[x1-1][y1-1];
		ne=s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1];
		ne-=up[x1][y2]-up[x1][y1-1]+lf[x2][y1]-lf[x1-1][y1];
		cout<<nv-ne<<endl;
	}
}

Measured memory_bytes: 96000
k,t=map(int,raw_input().split())
a=map(int,raw_input().split())
a.sort()
for i in xrange(t):
    j=t-1
    while 1:
        if i==j:
            if a[i]-1<0:
                print(0)
            else:
                print(a[i]-1)
            exit()
        if a[j]>=a[i]:
            a[j]-=a[i]
            break
        else:
            a[i]-=a[j]
            a[j]=0
            j-=1

Measured memory_bytes: 2696
#include<stdio.h>
#include<string.h>
int main(void){
char s[100];
  int count=0;
  scanf("%s",&s);
  int n=strlen(s);
  for(int i=0;i<strlen(s)/2;i++){
   // printf("%c %c\n",s[i],s[n-i-1]);
    if(s[i]!=s[n-i-1]){
      count++;
		
    }
  }
  printf("%d",count);
  return 0;
}
    
    



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

tmp = x[0]
ans = 0
for i in range(1,n):
    if (x[i]-tmp)*a <= b:
        ans += (x[i]-tmp)*a
    else:
        ans += b
    tmp = x[i]
print(ans)

Measured memory_bytes: 20124
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Card struct{ Number, Stock int }
type Cards []Card

func (c Cards) Len() int           { return len(c) }
func (c Cards) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c Cards) Less(i, j int) bool { return c[i].Number > c[j].Number }

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	sum := int64(0)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
		sum += int64(as[i])
	}
	sort.Ints(as)

	var cs Cards = make([]Card, m)
	for i := range cs {
		sc.Scan()
		cs[i].Stock, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		cs[i].Number, _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(cs)

	var p int
lb:
	for _, v := range cs {
		for i := 0; i < v.Stock; i++ {
			if p >= len(as) || v.Number < as[p] {
				break lb
			}
			sum += int64(v.Number - as[p])
			p++
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 4992
#include<stdio.h>

int graph[8][8],f[8];

int solve(int n,int v){
	int i,c=0,ans=0;
	for(i=1;i<n;i++){
		if(f[i]) c++;
		else{
			if(graph[v][i]==1){
				f[i]=1;
				ans+=solve(n,i);
				f[i]=0;
			}
		}
	}
	if(c==n-1) return 1;
	return ans;
}

int main(int argc, char const *argv[]) {
	int n,m,i,p,q;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d %d",&p,&q);
		graph[p-1][q-1]=1;
		graph[q-1][p-1]=1;
	}
	printf("%d\n",solve(n,0));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int digitSum(int n){
    int sum = 0;
    while (n > 0){
        sum += n %10;
        n /= 10;
    }
    return sum;
}
int main() {
    int N;
    cin >> N;
    int Cake = 4;
    int Donuts = 7;
    int count = 0;
    for (int i = 0; i < 100; ++i) {
        for (int j = 0; j < 100; ++j) {
            if(i*Cake + Donuts*j ==N)
                count++;
        }
    }
    if(count >= 1){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int max(int a, int b){
  if(a>=b){
    return a;
  }
  else{
    return b;
  }
}

int main(){
  char buf[1024];
  int A,B;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &A, &B);

  int add=A+B;
  int sub=A-B;
  int mul=A*B;

  int ans=max(add, sub);
  ans=max(ans, mul);

  printf("%d\n", ans);

  return 0;


}


Measured memory_bytes: 128
n,m = map(int,input().split())
h = list(map(int,input().split()))
l = [[]]*m
cnt = 0
for i in range(m):
    l[i] = list(map(int,input().split()))
f = [1]*n
for j in range(m):
    if h[l[j][0]-1] <= h[l[j][1]-1]:
        f[l[j][0]-1] = 0
    if h[l[j][0]-1] >= h[l[j][1]-1]:
        f[l[j][1]-1] = 0
print(sum(f))

Measured memory_bytes: 31884
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from itertools import product
coins = [10,50,100,500]

def coin_count(num):
    count = 0
    for coin in sorted(coins,reverse = True):
        count += num // coin
        num -= (num // coin)*coin
    return count

flag = True
while True:
    price = int(input())
    if price == 0:
        break

    if flag:
        flag = False
    else:
        print()

    has = list(map(int,input().split()))
    sum_coins = list(map(lambda x: x[0]*x[1], zip(has,coins)))


    change = (sum(sum_coins) - price)
    surplus = [change % 50 // 10, change % 100 // 50, change % 500 // 100, change // 500]

    for i in range(4):
        if has[i] > surplus[i]:
            print(coins[i],has[i] - surplus[i])

Measured memory_bytes: 6732
#include<stdio.h>
#include<string.h>
char S[200],A[200],B[200],R[200],C[200],*p;
int i,l,N,r;
 
int ch(char x)
{
	return x=='X'?N:x-'0';
}
 
void dfs(int a,int b,int cf,int p)
{
	int t;
	if(a<0&&b<0)
	{
		if(cf)R[p]='1';
		return;
	}
	else if(a<0||b<0)
	{
		t=(a>=0?ch(A[a]):ch(B[b]))+cf;
		R[p]=t%10+'0';
		dfs(a>=0?a-1:a,b>=0?b-1:b,t>9,p+1);
	}
	else
	{
		t=ch(A[a])+ch(B[b])+cf;
		R[p]=t%10+'0';
		dfs(a-1,b-1,t>9,p+1);
	}
}
 
int main()
{
	for(;gets(S);)
	{
		memset(R,0,sizeof(R));
		r=-1;
		p=strtok(S,"+");strcpy(A,p);
		p=strtok(NULL,"=");strcpy(B,p);
		p=strtok(NULL,"=");strcpy(C,p);
		l=strlen(C);
		for(N=0;N<10;N++)
		{
			dfs(strlen(A)-1,strlen(B)-1,0,0);
			if((N==0&&strlen(A)>1&&strlen(B)>1&&strlen(C)>1&&(A[0]=='X'||B[0]=='X'||C[0]=='X')))continue;
			if((strlen(R)>1&&R[strlen(R)-1]=='0')||l!=strlen(R))continue;
			for(i=0;i<l;i++)
				if(ch(R[i])!=ch(C[l-i-1]))
					break;
			if(i==l)
			{
				r=N;
				break;
			}
		}
		if(r==-1)puts("NA");
		else printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 528
package main

import (
	"fmt"
)

func main() {
	var a,b,t int
	fmt.Scan(&a,&b,&t)

	count := 0
	for i := 1; i <= t; i++ {
		if i % a == 0 {
			count += b
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 512
# ABC088C - Takahashi's Information
def main():
    arr = [list(map(int, input().rstrip().split())) for _ in range(3)]
    memo = []
    for i, j, k in arr:
        memo += [(i - j, j - k)]
    print("Yes" if len(set(memo)) == 1 else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(int, n, t, a);
	vector<pair<double, int>> vp;
	int x;
	rep(i, 0, n) {
		cin >> x;
		vp.eb(mp(abs(a - (t - x * 0.006)), i));
	}
	sort(all(vp));
	print(vp[0].se + 1);
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::BinaryHeap;
use std::collections::HashMap;

fn main() {
    let n: usize = read();
    let mut map: HashMap<i64, i64> = HashMap::new();
    let mut a: Vec<i64> = vec![];
    for _ in 0..n {
        let ai = read();
        let mut current = map.entry(ai).or_insert(0);
        *current += 1;
    }

    let mut bh: BinaryHeap<i64> = BinaryHeap::new();

    for (k, v) in map {
        if v > 1 {
            bh.push(k);
        }
        if v > 3 {
            bh.push(k);
        }
    }

    let first = match bh.pop() {
        Some(s) => s,
        None => {
            println!("0");
            return;
        }
    };
    let second = match bh.pop() {
        Some(s) => s,
        None => {
            println!("0");
            return;
        }
    };
    println!("{}", first * second);
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> pii;
typedef long long ll;
#define debug(x) cout << #x << "=" << x << endl;
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); cout << (i>0 ? " ":"") << v[i++]); cout << "\n"; return os;}

void square(vi &v){
    vi v2(v);
    for(int i=0;i<v.size();i++){
        //i -> v[i] -> v[v[i]]
        v2[i] = v[v[i]];
    }
    v = v2;
}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll k;
    cin >> n >> k;
    vi v2(n);
    int i;
    cin >> v2;
    for(i=0;i<n;i++) v2[i]--;
    vi ans(n);
    for(i=0;i<n;i++) ans[i] = i;
    while(k > 0){
        if(k&1){
            for(i=0;i<n;i++){
                // i -> ans[i] -> v2[ans[i]]
                ans[i] = v2[ans[i]];
            }
        }else{
        }
        k >>= 1;
        square(v2);
    }
    cout << (ans[0]+1) << "\n";

    return 0;
}

Measured memory_bytes: 5572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m;
  cin >> n >> m;
  vector<ll> pn(n, 0);
  vector<bool> AC(n, false); //falseなら未AC
  
  ll p;
  string s;
  ll ans1 = 0;
  rep(i, 0, m) {
    cin >> p >> s;
    if(!(AC[p-1]) and s=="AC") {
      ans1 += pn[p-1];
      AC[p-1] = true;
    }
    if(!(AC[p-1]) and s=="WA") pn[p-1]++;
  }

  cout << count(all(AC), true) << " " << ans1 << "\n";

}

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

string S; int K;

int main() {
  cin >> S >> K;
  int N = S.size();
  for (int j = 0; j < N-1 && K > 0; ++j) {
    int offset = ('z' - S[j] + 1) % 26;
    if (offset <= K) { 
      K -= offset;
      S[j] = 'a';
    }
  }
  S[N-1] = (S[N-1] - 'a' + K%26) % 26 + 'a';
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 512
// D - I hate Factorization
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll X; cin>>X;
	for(ll a=-200; a<=200; ++a)
		for(ll b=-200; b<=200; ++b)
			if(a*a*a*a*a - b*b*b*b*b == X){ cout<<a<<" "<<b<<endl; return 0; }
}

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

int main()
{
    int n,firstd,lastd;
    cin>>n;
    lastd=n%10;
    firstd=n;
    while(firstd>=10){
        firstd=firstd/10;
    }

    if(firstd==9||lastd==9) {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}



Measured memory_bytes: 3624
import sys
input=sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
ans1,total=0,0
for i in range(n):
    total+=A[i]
    if i%2==0 and total<=0:
        tmp=-total+1
        total=1
        ans1+=tmp
    elif i%2==1 and total>=0:
        tmp=total+1
        total=-1
        ans1+=tmp
ans2,total=0,0
for i in range(n):
    total+=A[i]
    if i%2==0 and total>=0:
        tmp=total+1
        total=-1
        ans2+=tmp
    elif i%2==1 and total<=0:
        tmp=-total+1
        total=1
        ans2+=tmp
print(min(ans1,ans2))

Measured memory_bytes: 14204
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }

int n, a[100010][3];
ll dp[100010][3];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i][0] >> a[i][1] >> a[i][2];

    rep(i, 3) {
        dp[0][i] = a[0][i];
    }
    for (int i = 1; i < n; i++) {
        rep(j, 3) {
            rep(k, 3) {
                if (j == k) continue;
                chmax(dp[i][k], dp[i-1][j] + a[i][k]);
            }
        }
    }

    ll ans = 0;
    rep(i, 3) {
        chmax(ans, dp[n-1][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
vector<int> G[1005];
vector<int> rG[1005];
bool used[1005];
int gr[1005];
int cnt[10000];

void dfs2(int v,int g){
	int su=0;
	for(int i=0;i<G[v].size();i++){
		su^=gr[G[v][i]];
	}
	cnt[g^su]++;
	for(int i=0;i<G[v].size();i++){
		dfs2(G[v][i],su^gr[G[v][i]]^g);
	}
}

int dfs(int v){
	used[v]=true;
	if(G[v].size()==0)return gr[v]=1;
	int su=0;
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]]){
			su^=dfs(G[v][i]);
		}
	}
	memset(cnt,0,sizeof(cnt));
	cnt[su]++;
	//printf("v=%d %d\n",v,su);
	for(int i=0;i<G[v].size();i++){
		dfs2(G[v][i],su^gr[G[v][i]]);
	}
	int val=0;
	while(cnt[val]>0){
		val++;
	}
	return (gr[v]=val);
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a;
		scanf("%d",&a);
		a--;
		G[a].push_back(i);
		rG[i].push_back(a);
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(rG[i].size()==0){
			int md=dfs(i);
			ans^=md;
			//printf("%d %d\n",i,md);
		}
	}
	printf("%s\n",ans==0?"Bob":"Alice");
	return 0;
}



Measured memory_bytes: 3352
N, *LR = [int(_) for _ in open(0).read().split()]
LR = sorted(set([(l, r + 1) for l, r in zip(LR[::2], LR[1::2])]))


class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def operate_right(self, p, v):  # apply operator from the right side
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = f(dat[p], v)
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def operate_left(self, p, v):  # apply operator from the left side
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = f(v, dat[p])
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        vl = vr = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                vl = f(vl, dat[l])
                l += 1
            if r & 1:
                r -= 1
                vr = f(dat[r], vr)
            l >>= 1
            r >>= 1
        return f(vl, vr)


minr = min(r for l, r in LR)
lminr = max(l for l, r in LR if r == minr)
maxl = max(l for l, r in LR)
rmaxl = min(r for l, r in LR if l == maxl)
LR2 = [lr for lr in LR if lr not in [(minr, lminr), (maxl, rmaxl)]]
LR = [(minr, lminr)] + LR2 + [(maxl, rmaxl)]
M = len(LR)
if M == 1:
    ans = 2 * (LR[0][1] - LR[0][0])
elif M == 2:
    ans = sum(r - l for l, r in LR)
else:
    #(lminr,minr)と(maxl,rmaxl)が同一または同じ回
    ans = max(0, minr - maxl) + max(r - l for l, r in LR2)
    #(lminr,minr)と(maxl,rmaxl)が違う回 [0,i)と[i,M)に分けて施行すればよい(i∈[1,M))
    st = SegmentTree([r for l, r in LR], min, 10**10)
    for i in range(1, M):
        v1 = max(0, minr - max(lminr, LR[i - 1][0]))
        v2 = max(0, st.query(i, M) - maxl)
        ans = max(ans, v1 + v2)
print(ans)


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

int main()
{
    string s,t;
    cin>>s>>t;
    int dp[s.length()+1][t.length()+1];
    for(int i=0;i<=s.length();i++)
    {
        dp[i][0]=0;
    }
    for(int i=0;i<=t.length();i++)
    dp[0][i]=0;
    for(int i=1;i<=s.length();i++)
    {
        char c=s[i-1];
        for(int j=1;j<=t.length();j++)
        {
            char d=t[j-1];
            if(c==d)
            dp[i][j]=max(1+dp[i-1][j-1],max(dp[i-1][j],dp[i][j-1]));
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string s_new="";
    int i=s.length();
    int j=t.length();
    int t2=dp[i][j];
    //cout<<t2<<"\n";
    while(t2>0)
    {
        if(t2==dp[i-1][j])
        {
            t2=dp[i-1][j];
            i-=1;
        }
        else if(t2==dp[i][j-1])
        {
            t2=dp[i][j-1];
            j-=1;
        }
        else
        {
            s_new=s[i-1]+s_new;
            t2=dp[i-1][j-1];
            i-=1;
            j-=1;
        }
    }
    cout<<s_new<<"\n";
}

Measured memory_bytes: 35456
import math

a, b, x = map(int, input().split())
s = x / a

if (s >= a * b / 2):
    print(math.atan2(2 * (a * b - s) / a, a) / math.pi * 180)
else:
    print(math.atan2(b, 2 * s / b) / math.pi * 180)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
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;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };



bool cmp(pll a, pll b){
    return a.second < b.second;
}
int main()
{
  int N;
  cin >> N;
  vector<pll> v(N);
  rep(i,N){
      cin >> v[i].first >> v[i].second;
  }

  sort(v.begin(),v.end(),cmp);

  bool ok= true;
  ll elapsedTime = 0;
  rep(i,N){
     elapsedTime += v[i].first;
     if(elapsedTime > v[i].second){
         ok = false;
     }
  }

  if(ok){
      fin("Yes");
  }else{
      fin("No");
  }

 


}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;	}


//Variables Declaration
int N ;
std::vector<int> stones;

int dp[(int)1e5+10];

int solve(int n ){

	if(dp[n]>=0) return dp[n];
	int ans = 0;
	if(n-1 >= 1){
		ans = 	abs(stones[n]-stones[n-1]) + solve(n-1);
	}
	if(n-2 >= 1){
		ans =	min(ans, abs(stones[n]-stones[n-2]) + solve(n-2));
	}

	return dp[n] = ans ;
}

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

	memset(dp, 0x3f,sizeof(dp));
 	cin >> N ;
 	stones.resize(N+1);

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

 	dp[1]=0;	
 	for(int i = 1 ; i <= N ; ++i){
 		if(i+1 <= N ) dp[i+1] = min ( dp[i+1] , dp[i] + abs( stones[i] - stones[i+1]));
 		if(i+2 <= N ) dp[i+2] = min ( dp[i+2] , dp[i] + abs( stones[i] - stones[i+2]));
 	}

 	cout << dp[N] << endl;
 //	cout << solve(N) << endl;
 	




	return 0;
}


Measured memory_bytes: 1024
N = int(input())
S = input()

C = ('SS', 'SW', 'WS', 'WW')
for i in range(4):
    ans = list(C[i])
    for j in range(1, N):
        if (ans[-1] == 'S' and S[j] == 'o') or(ans[-1] == 'W' and S[j] == 'x'):
            ans.append(ans[-2])
        else:
            ans.append('S' if ans[-2] == 'W' else 'W')
    if ans[0] == ans[-1]:
        ans.pop()
        if (ans[0] == 'S' and S[0] == 'o' and ans[-1] == ans[1]) or \
            (ans[0] == 'S' and S[0] == 'x' and ans[-1] != ans[1]) or \
                (ans[0] == 'W' and S[0] == 'o' and ans[-1] != ans[1]) or \
                (ans[0] == 'W' and S[0] == 'x' and ans[-1] == ans[1]):
            print(''.join(ans))
            exit()
print(-1)


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


void solve(long long A, long double B){
    long long iB = B * 100 + 0.5;
    A *= iB;
    A /= 100;
    cout << A << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    double B;
    scanf("%lf",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3868
n = gets.to_i
ans_hash = Hash.new(50)
n.times do
  tmp_hash = Hash.new(0)
  str = gets.chomp
  str.chars { |char| tmp_hash[char] += 1 }
  ("a".."z").each do |alphabet|
    ans_hash[alphabet] = [ans_hash[alphabet], tmp_hash[alphabet]].min
  end
end
ans_ary = []
ans_hash.each do |key, value|
  value.times { ans_ary << key }
end
puts ans_ary.join


Measured memory_bytes: 1788
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main() {
  int N, K;
  cin >> N >> K;
  cout << N-K+1 << endl;
  return 0;
}


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

int main() {
  int n,x;
  cin >> n >> x;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  int ans =0;
  for(int i=0;i<n && x>0 ;i++){
    if(x >= a[i]){
      ans++;
      x -= a[i];
    }
    else {
      x -= a[i];
      break;
    }
  }
  if(x <= 0) cout << ans << endl;
  else cout << ans -1 << endl;
  
  
  return 0;
}


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

using namespace std;


int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for (int i = 0; i < N; ++i) cin >> V[i];
  for (int i = 0; i < N; ++i) cin >> C[i];
  int value = 0;
  int cost = 0;
  for (int i = 0; i < N; ++i) {
    if (V[i] > C[i]) {
      value += V[i];
      cost += C[i];
    }
  }
  cout << value - cost << endl;
  return 0;
}



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

class MyClass
{
    public static void Main(string[] args)
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var H = input[0];
        var W = input[1];
        var a = new int[H, W];
        for (int i = 0; i < H; i++)
        {
            var input2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int j = 0; j < W; j++)
            {
                a[i, j] = input2[j];
            }
        }
        var min = int.MaxValue;
        for (int X = 0; X < H; X++)
        {
            for (int Y = 0; Y < W; Y++)
            {
                var sum = 0;
                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j < W; j++)
                    {
                        sum += a[i, j] * Math.Min(Math.Abs(X - i), Math.Abs(Y - j));
                    }
                }
                min = Math.Min(min, sum);
            }
        }
        Console.WriteLine(min);
    }
}


Measured memory_bytes: 20496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
template <class T>
void print(T x){cout << x << '\n';}

void solve(long long A, long long B, long long C, long long X){
  int counter=0;
  REP(i,A+1)REP(j,B+1)REP(k,C+1){
    if(500*i+100*j+50*k==X)counter++;
  }
  print(counter);

}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  long long X;
  scanf("%lld",&X);
  solve(A, B, C, X);
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    L=float(input())
    a=L/3
    b=(L-a)/2
    print(a*b*(L-a-b))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};
class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

	int find(int e) {
		return d[e];
	}
};

int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool prime(int a) {
	if (a == 1)
		return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(int x, int y) {
		if (same(x, y))
			return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}

	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(int x, int y) {
		return Find(x) == Find(y);
	}

	int get_Size(int a) {
		return s[a];
	}
};

vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}

signed main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=(b)/c-(a-1)/c;
    int y=(b)/d-(a-1)/d;
    int z=(b)/lcm(c,d)-(a-1)/lcm(c,d);
    cout<<b-a+1-(x+y-z)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

typedef unsigned long long ull;

const ull INF = ULLONG_MAX/3;

void add(int s, int t, ull x, vector<ull> &xList, vector<ull> &sxList){
    int nn = xList.size();
    int sn = sxList.size();
    int ss = s/sn;
    int tt = t/sn;
    if(ss == tt){
        for (int i=0;i<t-s+1;i++){
            xList[s+i] += x;
        }
    }else{
        for(int i=s;i<(ss+1)*sn;i++){
            xList[i] += x;
        }

        for(int i=tt*sn;i<t+1;i++){
            xList[i] += x;
        }

        for(int i=ss+1;i<tt;i++){
            sxList[i] += x;
        }
    }
}

ull get(int ind, vector<ull> &xList, vector<ull> &sxList){
    int sn = sxList.size();
    return xList[ind] + sxList[ind/sn];
}

int main(){
    int N, T, l ,r;
    cin >> N >> T;
    int sn = sqrt(T-1) + 1;

    vector<ull> xList(sn*sn, 0ull);
    vector<ull> sxList(sn, 0ull);

    for (int i=0;i<N;i++){
        cin >> l >> r;
        add(l, r-1, 1, xList, sxList);
    }

    ull M = 0ull;
    for(int i=0;i<T;i++){
        M = max(M, get(i, xList, sxList));
    }
    cout << M << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
 
int main(void)
{
  unsigned char c;
  scanf("%c", &c);
  
  if((int)c >= 65 && (int)c <= 90)
  {
    printf("A\n");
  }
  else if((int)c >= 97 && (int)c <= 122)
  {
    printf("a\n");
  }
  return 0;
}

Measured memory_bytes: 1580