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

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> s(H);
    for (int i = 0; i < H; i++)
    {
        cin >> s.at(i);
    }

    vector<bool> has_strawberry(H);
    for (int i = 0; i < H; i++)
    {
        has_strawberry.at(i) = (s.at(i).find('#') != string::npos);
    }

    int last_h;
    vector<vector<int>> res(H, vector<int>(W));
    int k = 1;
    for (int i = 0; i < H; i++)
    {
        if (has_strawberry.at(i))
        {
            bool found = false;
            for (int j = 0; j < W; j++)
            {
                if (s.at(i).at(j) == '#')
                {
                    if (found)
                        k++;
                    else
                        found = true;
                }
                res.at(i).at(j) = k;
            }
            k++;

            int p = i - 1;
            while (p >= 0 && !has_strawberry.at(p))
            {
                for (int j = 0; j < W; j++)
                {
                    res.at(p).at(j) = res.at(i).at(j);
                }
                p--;
            }

            last_h = i;
        }
    }

    for (int i = last_h + 1; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            res.at(i).at(j) = res.at(last_h).at(j);
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cout << res.at(i).at(j) << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <bits/stdc++.h>
#define loop(N) for(int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long int>
#define lli long long int
#define plli pair<lli,lli>
using namespace std ;
void ps(string i){
    cout << i << endl;
}

template <class T>
void pt(T s){
    cout << s << endl;
}

void pi(int i){
    cout << i << endl;
}

template <class T>
void pv(vector<T> v){
    loop(v.size()){
        pt<T>(v[i]);
    }
}
/*********************************reused****************************/

int main()
{
    lli n;
    cin>>n;
    lli m = (lli) sqrt(n);

    cout<<m*m<<endl;
    return 0;
}



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

class UnionFind {
    vector<int> par;
    int n;

public:
    UnionFind(int sz) : par(sz, -1) {}

    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

    int size(int x) {
        return -par[find(x)];
    }
};


// verified
//   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A&lang=jp
void AOJ_DSL_1_A() {
    int n, q;
    cin >> n >> q;

    UnionFind uf(n);
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com) {
            cout << uf.same(x, y) << '\n';
        } else {
            uf.unite(x, y);
        }
    }
}

int main() {
    AOJ_DSL_1_A();
    return 0;
}


Measured memory_bytes: 3152
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>

using namespace std;

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

    int a, b;
    cin >> a >> b;

    if ((a & 1) & (b & 1)) {
        cout << "Odd\n";
    } else {
        std::cout << "Even\n";
    }

    return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<vector>
#include<set>
#include<utility>
#include<ctype.h>
#include<ctime>
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
# define ll long long
using namespace std;
int gcd(int a,int b){
    int r;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int GCD(int a,int b)
{
    if(a==0) return b;
    else return GCD(b%a,a);
}
long long int power(long long int a,long long int b){
    long long int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}
int palindrome(char *s,int len)
{
    int i,j,k,count=0,c=0;
    for(i=0,j=len-1;i<len,j>=0;i++,j--){
        if(s[i]==s[j]) count++;
    }
	if(count==len) return 1;
    	else return 0;
}
long long int binary(char *s,long long int len)
{
    long long int i,j,k,r=0,p=0,num;
    for(i=len-1;i>=0;i--){
        num=s[i]-'0';
        r+=(num*power(2,p));
        p++;
    }
    return r;
}
int binary_search(int *ara,int size,int n)
{
    int high,mid,low;
    low=0;
    high=size-1;
    while(low<=high){
        mid=(low+high)/2;
        if(ara[mid]==n){
            return 1;
        }
        else if(n>ara[mid]) low=mid+1;
        else if(n<ara[mid]) high=mid-1;
    }
    return -1;
}
int main()
{
	ios_base::sync_with_stdio(false);
//	cin.tie(nullptr);
//	cout.tie(nullptr);
	int i,j,k,n,T,q;
	string s1,s2,s3;
	char s[100001],c;
	cin>>s1>>s2>>s3;
    cout<<s1[0]<<s2[0]<<s3[0]<<endl;
	cout<<"\n";
}



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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

long long arr[100005], brr[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;
    long long a;

    for(int i = 0; i <= n; ++i)
        cin >> arr[i];
    for(int i = 0; i < n; ++i)
        cin >> brr[i];

    long long tot = 0;

    for(int i = 0; i < n; ++i){
        if(arr[i] >= brr[i]){
            //cout << arr[i] << " " << brr[i] << endl;
            tot += brr[i];
            brr[i] = 0;
        } else {
            //cout << "REM " << brr[i] - arr[i] << endl;
            tot += arr[i] + min(arr[i + 1], brr[i] - arr[i]);
            arr[i + 1] = max(0LL, arr[i + 1] - (brr[i] - arr[i]));
            //cout << arr[i + 1] << endl;
            brr[i] -= arr[i];
        }
    }

    cout << tot << "\n";


    return 0;

}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

long long n,a[10002];

void solve() {
  sort(a,a+n);
  long long cur=0,sum=0;
  rep(i,n-1) {
    cur+=a[i];sum+=cur;
  }
  printf("%lld\n",sum);
}

int main() {
  while(cin>>n,n) {
    rep(i,n) cin>>a[i];
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
s = gets.chomp.split("")

cnt = 0

((s.size)/2 + 1).times do |i|
  t = s.shift
  u = s.shift
  cnt += 1 if ((t == 'L') or (u == 'R'))
end

if cnt == 0
  puts 'Yes' 
else
  puts 'No'
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int n,l;cin>>n>>l;
  int a[n];rep(i,n)cin>>a[i];
  int knot;
  rep(i,n){
    if(i==n-1){
      cout<<"Impossible"<<endl;
      exit(0);
    }
    if(a[i]+a[i+1]>=l){
      knot=i;break;
    }
  }
  cout<<"Possible"<<endl;
  VI ans;
  ans.push_back(knot+1);
  rep(i,knot){
    int j=knot-1-i;
    ans.push_back(j+1);
  }
  rep(i,knot+1,n-1){
    ans.push_back(i+1);
  }
  reverse(all(ans));
  rep(i,ans.size())cout<<ans[i]<<endl;
}




Measured memory_bytes: 1784
#include <stdio.h>
int main(void){
	int a[10],c,i;
	char b[101];
	for(i=1;i<=6;i++)
		scanf("%d",&a[i]);
	scanf("%s",b);
	for(i=0;b[i] !='\0';i++){
		if(b[i]=='N'){
			c = a[1];
			a[1] = a[2];
			a[2] = a[6];
			a[6] = a[5];
			a[5] = c;}
		if(b[i]=='S'){
			c = a[1];
			a[1] = a[5];
			a[5] = a[6];
			a[6] = a[2];
			a[2] = c;}
		if(b[i]=='E'){
			c = a[1];
			a[1] = a[4];
			a[4] = a[6];
			a[6] = a[3];
			a[3] = c;}
		if(b[i]=='W'){
			c = a[1];
			a[1] = a[3];
			a[3] = a[6];
			a[6] = a[4];
			a[4] = c;}
	}
	printf("%d\n",a[1]);
	return 0;
}			
	

Measured memory_bytes: 596
#include<stdio.h>
int main(void)
{

	int num,i,n,j,v,A[100];


	scanf("%d",&num);


	for(i=0;i<=num-1;i++)
		scanf("%d",&A[i]);

	for(n=0;n<=num-1;n++){
			if (n==num-1)printf("%d\n",A[n]);
			else  printf("%d ",A[n]);
		}

	for(i=1;i<=num-1;i++){
		v=A[i];
		j=i-1;
		while(j>=0 && A[j]>v){
			A[j+1]=A[j];
			j--;
			A[j+1]=v;
		}
		

		for(n=0;n<=num-1;n++){
			if (n==num-1)printf("%d\n",A[n]);
			else printf("%d ",A[n]);
		}

	}

	return(0);
}


Measured memory_bytes: 2080
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
int map[100001];

void a(string s, int r) {
    int m=0;
    for(int i=1; i<r; i++) {
        if(s[i-1] == 'A' && s[i] == 'C') m++;
        map[i]=m;
    }
}

int main() {
    map[0]=0;
    string s;
    int n,q;
    scanf("%d %d\n",&n,&q);
    cin >> s;
    a(s,n);
    REP(i,q) {
        int l,r;
        scanf("%d %d\n",&l,&r);
        int ans=0;
        cout << map[r-1]-map[l-1] << "\n";
    }
    return 0;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-

_sum = 0
_avg = 0
n = 0


while 1:
    try:
        _s, _a = [int(e) for e in input().split(',')]
        _sum += _s * _a
        _avg += _a
        n += 1
    except:
        print(_sum)
        print(int(_avg / n + 0.5))
        break

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

int main(){
  int n;
  cin>>n;
  vector<int> b(n),a(n);
  rep(i,n) cin>>b[i];
  bool ok=1;
  int tmp=0;
  while(!b.empty()){
    bool k=0;
    for(int j=b.size()-1; j>=0; j--){
      if(j+1==b[j]){
        a[tmp]=b[j]; tmp++;
        b.erase(b.begin()+j);
        k=1;
        break;
      }
    }
        
    if(!k){
      ok=0; break;
    }
  }
  if(ok){
    reverse(a.begin(),a.end());
    rep(i,n) cout<<a[i]<<endl;
  }else cout<<-1<<endl;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

int main(void){
	ll H,W,D,X[90010],Y[90010],next[90010]={},A,Q,L[100010],R[100010],ans,r;
	scanf("%lld%lld%lld",&H,&W,&D);
	for(int i = 1; i <= H; ++i){
		for(int j = 1; j <= W; ++j){
			scanf("%lld",&A);
			Y[A]=i;
			X[A]=j;
		}
	}
	scanf("%lld",&Q);
	for(int i = 0; i < Q; ++i){
		scanf("%lld%lld",&L[i],&R[i]);
	}
	for(int i = 1; i <= H*W-D; ++i)next[i+D]=abs(X[i+D]-X[i])+abs(Y[i+D]-Y[i])+next[i];
	for(int i = 0; i < Q; ++i)printf("%lld\n",next[R[i]]-next[L[i]]);
	return 0;
}

Measured memory_bytes: 4736
from itertools import accumulate
from fractions import gcd


N = int(input())
A = list(map(int, input().split()))

cum_gcd_l = list(accumulate(A, gcd))
cum_gcd_r = list(accumulate(reversed(A), gcd))

ans = 0
for i in range(N):
    if i == 0:
        tmp = cum_gcd_r[-2]
    elif i == N-1:
        tmp = cum_gcd_l[-2]
    else:
        tmp = gcd(cum_gcd_l[i-1], cum_gcd_r[N-i-2])
    ans = max(tmp, ans)

print(ans)



Measured memory_bytes: 16144
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int main(){
  long long int Q, H, S, D;
  long long int N;
  cin >> Q >> H >> S >> D >> N;
  long long int Q1, H1, S1;
  Q1 = Q * 4;
  H1 = H * 2;
  S1 = S;
  long long int Q2, H2, S2, D2;
  Q2 = Q * 8;
  H2 = H * 4;
  S2 = S * 2;
  D2 = D;
  if (N == 1){
    if (Q1 < H1){
      if (Q1 < S1){
        cout << Q1;
      }else{
        cout << S1;
      }
    }else{
      if (H1 < S1){
        cout << H1;
      }else{
        cout << S1;
      }
    }
  }else{
    long long int result = 0;
    if ((N % 2) == 1){
      if (Q1 < H1){
        if (Q1 < S1){
          result +=  Q1;
        }else{
          result +=  S1;
        }
      }else{
        if (H1 < S1){
          result += H1;
        }else{
          result += S1;
        }
      }
    }
    if (Q2 < H2){
      if (Q2 < S2){
        if (Q2 < D2){
          result +=  Q2*(N/2);
        }else{
          result +=  D2*(N/2);
        }
      }else{
        if (S2 < D2){
          result +=  S2*(N/2);
        }else{
          result +=  D2*(N/2);
        }
      }
    }else{
      if (H2 < S2){
        if (H2 < D2){
          result +=  H2*(N/2);
        }else{
          result +=  D2*(N/2);
        }
      }else{
        if (S2 < D2){
          result +=  S2*(N/2);
        }else{
          result +=  D2*(N/2);
        }
      }
    }    
    cout << result;
  }
  return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer ::le,i,j,a=0,b=0,am,bm
  character(300000)::n
  read(*,*)j
  read(*,*)n
  le=len_trim(n)
  do i=1,le
    if(n(i:i)=='.')a=a+1
    if(n(i:i)=='#')b=b+1
  enddo
  am=a
  bm=b
  do j=1,le
    if(n(j:j)=='.')then
      a=a-1
      if(am>a)am=a
    else
      a=a+1
    endif
  enddo
  do j=le,1,-1
      if(n(j:j)=='#')then
      b=b-1
      if(bm>b)bm=b
    else
      b=b+1
    endif

  enddo
  write(*,*)min(am,bm)
end program main


Measured memory_bytes: 1084
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
map<int,int> me;
int main()
{
	int a,n,out=0;cin>>n;
	rep(i,n){
		cin>>a;me[a]++;
	}
	map<int,int>::iterator it=me.begin();
	while(it!=me.end()){
		int x=(*it).fi,y=(*it).se;
		if(y<x) out+=y;else out+=y-x;
		it++;
	}
	cout<<out<<endl;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(),t.end());

    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    ll x;
    cin >> x;
    ll now = 100, res = 0;
    while (now < x) {
        now += now / 100;
        res++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	

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

	int a,b;
	cin >> a >> b;

	if(a%2!=0 && b%2 != 0) cout << "Yes\n";
	else				cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    cakes = [[int(i) for i in input().split()] for _ in range(N)]

    ans = 0

    for i in range(8):
        ary = []
        for s in bin(i)[2:].zfill(3):
            ary.append(1 if s == "0" else -1)
        cakes.sort(key=lambda x: x[0]*ary[0]+x[1]*ary[1]+x[2]*ary[2])
        score = [0, 0, 0]
        for index in range(M):
            for n in range(3):
                score[n] += cakes[index][n]
        ans = max(ans, sum(map(abs, score)))

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40048
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

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

    int tak = (c+b-1)/b;
    int aoi = (a+d-1)/d;

    if(tak <= aoi) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }

    return 0;
}




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

using ll = long long;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N, K; cin >> N >> K;
    vector<int> A(N); cin >> A;

    vector<ll> sum;
    ll all_or = 0;
    rep(i, N) {
        ll s = 0;
        for (int j = i; j < N; j++) {
            s += A[j];
            sum.push_back(s);
            all_or |= s;
        }
    }

    ll ans = 0;
    for (ll b = (1LL << 41); b > 0; b >>= 1) {
        if (!(all_or & b)) continue;
        int c = 0;
        rep(i, sum.size()) {
            if (ans == 0 || (sum[i] & ans) == ans) {
                if (sum[i] & b) {
                    c++;
                }
            }
        }
        if (c >= K) {
            ans |= b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6128
#include<iostream>
#include<cstring>
using namespace std;
typedef long long int llint;
llint dp[105][100005],v[105],w[105],n,w1;
llint rek(int ind,int x) {
	if(ind==n) return 0;
	if(dp[ind][x]!=-1) return dp[ind][x];
	llint ret=0;
	ret=max(ret,rek(ind+1,x));
	if(x>=w[ind]) {
		ret=max(ret,rek(ind+1,x-w[ind])+v[ind]);
		//cout << ind << " " << x << "\n";
	}
	dp[ind][x]=ret;
	//cout << ind << " " << x << " " << ret << "\n"; 
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> w1;
	for(int i=0;i<n;i++) {
		cin >> w[i] >> v[i];
	}
	memset(dp,-1,sizeof(dp));
	cout << rek(0,w1);
	return 0;
}


Measured memory_bytes: 85648
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	ll x;
	cin >> x;
	ll now = 100;
	int y = 0;
	while (now < x){
		y++;
		now += (now / 100);
	}
	cout << y << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
    int key;
    struct node *left,*right,*par;
};
typedef struct node* node_pointer; 

node_pointer nil,root;

void insert(int);
void Preorder(node_pointer);
void Inorder(node_pointer);

int main(){
    int n,i;
    scanf("%d",&n);

    for(i=0; i<n; i++){
        char order[7];
        int num;
        scanf(" %s",order);

        if(strcmp(order,"insert") == 0 ){
            scanf("%d",&num);
            insert(num);
        }

        else if(strcmp(order,"print") == 0){
            Inorder(root);
            printf("\n");
            Preorder(root);
            printf("\n");
        }
    }

    return 0;
}

void insert(int num){
    node_pointer a,b,c;
    a = root;
    b = nil;
    c = (node_pointer)malloc(sizeof(struct node));
    c->key = num;
    c->right = nil;
    c->left = nil;

    //どの葉の子になるかを決める
    while(a != nil){
        b = a;       
        if(c->key < a->key) a = a->left;
        else a = a->right;
    }

    c->par = b;

    //決めた葉の右の子か左の子かを決める
    
    if(b == nil) root = c;
    else if(c->key < b->key) b->left = c;
    else b->right = c;
}

void Preorder(node_pointer a){
    if(a == nil) return;
    printf(" %d",a->key);
    if(a->left != nil) Preorder(a->left);
    if(a->right != nil) Preorder(a->right);
}

void Inorder(node_pointer a){
    if(a == nil) return;
    if(a->left != nil) Inorder(a->left);
    printf(" %d",a->key);
    if(a->right != nil) Inorder(a->right);
}



Measured memory_bytes: 26116
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#define MAX_N 1000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){// this size is really ok??
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

ll gcd(ll a,ll b){
  return b==0?a:gcd(b,a%b);
}

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

  int N;
  cin>>N;
  vector<ll> A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];

  setComb();

  vector<pair<ll,ll>> v(N);
  map<pair<ll,ll>,ll> mp;
  ll azero=0,bzero=0,zero=0;
  rep(i,N){
    if(A[i]==0||B[i]==0){
      if(A[i]==0&&B[i]==0) zero++;
      else if(A[i]==0) azero++;
      else bzero++;
      continue;
    }
    ll g=gcd(abs(A[i]),abs(B[i]));
    v[i]=mkp(A[i]/g,B[i]/g);

    ll a=A[i]/g,b=B[i]/g;
    if(mp.count(mkp(a,b))) mp[mkp(a,b)]++;
    else mp[mkp(a,b)]++;
  }

  ll ans=1;
  for(int i=0;i<N;i++){
    if(A[i]==0||B[i]==0) continue;
    ll a=v[i].first;
    ll b=v[i].second;
    if(mp.count(mkp(a,b))==false) continue;

    ll n=mp[mkp(a,b)];
    mp.erase(mkp(a,b));
    if(mp.count(mkp(-a,-b))){
      n+=mp[mkp(-a,-b)];
      mp.erase(mkp(-a,-b));
    }

    ll tar=0;
    if(mp.count(mkp(-b,a))){
      tar+=mp[mkp(-b,a)];
      mp.erase(mkp(-b,a));
    }
    if(mp.count(mkp(b,-a))){
      tar+=mp[mkp(b,-a)];
      mp.erase(mkp(b,-a));
    }

    ll res=mod_pow(2,n);
    add(res,mod_pow(2,tar));
    add(res,MOD-1);
    mul(ans,res);    
  }

  ll num=mod_pow(2,azero);
  add(num,mod_pow(2,bzero));
  add(num,MOD-1);
  mul(ans,num);

  add(ans,MOD-1);
  add(ans,zero);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 45320
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    sa = [0]
    for a in A:
        sa.append(sa[-1]+a)

    if N == 0:
        if A[0] == 1:
            return 1
        else:
            return -1

    if A[0] != 0:
        return -1
    ans = 1
    p = 1
    for i in range(1, N+1):
        if p * 2 < A[i]:
            return -1
        m = min(p*2, sa[-1] - sa[i])
        ans += m
        if m - A[i] < 0:
            return -1
        p = m - A[i]
    return ans




def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 101184
import bisect
 
N,M = map(int,input().split())
Price_List = list(map(int,input().split()))
Price_List.sort()
for i in range(M):
    New_Price = Price_List.pop(-1)//2
    Price_List.insert(bisect.bisect(Price_List,New_Price),New_Price)
print(sum(Price_List))

Measured memory_bytes: 84300
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


int Input[25];
int B[25];
int C[25];

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    int a; cin >> a; a--;
    Input[i] = a;
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N-1; i++) {
    cin >> C[i];
  }

  int ans = B[Input[0]];
  int prev = Input[0];

  for (int i = 1; i < N; i++) {
    ans += B[Input[i]];

    if (prev + 1 == Input[i]) {
      ans += C[prev];
    }
    prev = Input[i];
  }

  cout << ans << endl;
}


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

int main(){
  int n;
  cin >>n;
  int f[n][10],p[n][11];
  for(int i=0;i<n;i++)for(int j=0;j<10;j++)cin >>f[i][j];
  for(int i=0;i<n;i++)for(int j=0;j<11;j++)cin >>p[i][j];
  int ans=-INT_MIN;
  for(int bit=1;bit<(1<<10);bit++){
    int count=0;
    for(int i=0;i<n;i++){
      int c=0;
      for(int j=0;j<10;j++){
        if((bit>>j&1)&&f[i][j])c++;
      }
      count+=p[i][c];
    }
    ans=max(ans,count);
    cerr<<count;
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

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

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

class UnionFind {
public:
    vector <int> par;
    vector <int> siz;

    UnionFind(int sz_): par(sz_), siz(sz_, 1LL) {
        for (int i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (int i = 0; i < sz_; ++i) par[i] = i;
    }

    int root(int x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    int size(int x) {
        return siz[root(x)];
    }
};

signed main() {
  int N, M; 
  cin >> N >> M;

  UnionFind uf(M);
  vector<vector<int>> vec(N);
  REP(i, N){
    int K;
    cin >> K;
    REP(j, K){
      int L;
      cin >> L;
      L--;
      vec[i].emplace_back(L);
    }
  }

  REP(i, N){
    REP(j, vec[i].size()-1){
      uf.unite(vec[i][0], vec[i][j+1]);
    }
  }

  bool ans = true;
  REP(i, N-1){
    if(!uf.same(vec[i][0], vec[i+1][0])) ans = false;
  }

  ans? YES: NO;

  return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
bool used[500005];
char s[500005],t[500005];
bool flag,dame;

int main(){
	cin >> a >> b;
	if(a >= 13){
		p(b);
	}else if(6 <= a){
		p(b/2);
	}else{
		p(0);
	}
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];
    int ans=0;
    for(int i=0;i<n;i++){
        if(i+1==p[i] && i!=n-1) swap(p[i],p[i+1]),ans++;
        if(i==n-1 &&p[i]==n) ans++;
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
int main() {
	string s;
	map<string, string> weather;
	weather["Sunny"] = "Cloudy";
	weather["Cloudy"] = "Rainy";
	weather["Rainy"] = "Sunny";

	cin >> s;

	cout << weather[s] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int MAXN = 1e2+5;
int n,m;
string s[MAXN];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m);
	for(ri i=1;i<=n;++i)
		cin>>s[i];
	sort(s+1,s+1+n);
	for(ri i=1;i<=n;++i)
		cout<<s[i];
	return 0;
}

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

int main(void){
   int A,B,C,D;
   string s;
   cin>>s;
   A=s[0]-'0';
   B=s[1]-'0';
   C=s[2]-'0';
   D=s[3]-'0';
   if(A+B+C+D==7) {
      cout<<A<<"+"<<B<<"+"<<C<<"+"<<D<<"="<<7<<endl;
      return 0;
   }
   if(A+B+C-D==7) {
      cout<<A<<"+"<<B<<"+"<<C<<"-"<<D<<"="<<7<<endl;
      return 0;
   }
   if(A-B+C+D==7) {
      cout<<A<<"-"<<B<<"+"<<C<<"+"<<D<<"="<<7<<endl;
      return 0;
   }
   if(A+B-C+D==7) {
      cout<<A<<"+"<<B<<"-"<<C<<"+"<<D<<"="<<7<<endl;
      return 0;
   }
   if(A-B-C+D==7) {
      cout<<A<<"-"<<B<<"-"<<C<<"+"<<D<<"="<<7<<endl;
      return 0;
   }
   if(A-B+C-D==7) {
      cout<<A<<"-"<<B<<"+"<<C<<"-"<<D<<"="<<7<<endl;
      return 0;
   }
   if(A+B-C-D==7) {
      cout<<A<<"+"<<B<<"-"<<C<<"-"<<D<<"="<<7<<endl;
      return 0;
   }
   if(A-B-C-D==7) {
      cout<<A<<"-"<<B<<"-"<<C<<"-"<<D<<"="<<7<<endl;
      return 0;
   }

   return 0;
}



Measured memory_bytes: 256
import java.util.*

data class State(val v: Int, val w: Int)

fun main(args: Array<String>) {
  val k = readLine()!!.toInt()
  val visited = BooleanArray(k)
  val queue = ArrayDeque<State>()
  queue.offerLast(State(1, 1))
  while (queue.isNotEmpty()) {
    val s = queue.pollFirst()
    if (visited[s.v]) continue
    visited[s.v] = true

    if (s.v == 0) {
      println(s.w)
      return
    }

    val s1 = State((s.v * 10) % k, s.w)
    if (!visited[s1.v]) {
      queue.offerFirst(s1)
    }
    val s2 = State((s.v * 10 + 1) % k, s.w + 1)
    if (!visited[s2.v]) {
      queue.offerLast(s2)
    }
  }
  throw RuntimeException()
}


Measured memory_bytes: 36580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

template<class T> int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}

int main()
{
    ll n, m; cin >> n >> m;
    vector<ll> a = divisor(m);
    cout << a[former(a, m/n)] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 # define ld long double
# define pb push_back
# define max 1000000007
int main()
{
   
 
    ll t;
    //cin >> t;
    t = 1;
    while (t--)
    {
       ll n;cin>>n;
       ll h[n+1];for(ll i=1;i<=n;i++){ cin>>h[i];}
       ll cost[n+1];cost[1]=0;cost[2]=abs(h[1]-h[2]);
       for(ll i=3;i<=n;i++){
           cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
       }
       cout<<cost[n]<<endl;
    }
    cerr << endl
         << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
  int n,m;
  scanf("%d", &n);
  scanf("%d", &m);
  int a[n],i,j = 0;
  double sum = 0;
  for(i = 0;i < n;i++)
  {
    scanf("%d", &a[i]);
    sum = sum + a[i];
  }
  m = m*4;
  for(i = 0;i < n;i++)
  {
    if(a[i] >= sum / m)
      j++;
  }
  if(j >= m / 4)
    printf("Yes\n");
  else
    printf("No\n");
  
  return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	long long int A[3];
	for (int i = 0; i < 3; i++)
		cin >> A[i];
	sort(A, A + 3);
	if (A[2] % 2 == 0)
		cout << 0 << endl;
	else cout << A[0] * A[1] << endl;
}

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

int main()
{
	ll n;
	cin >> n;
	ll arr[n];

	map<ll,ll> alpha;
	ll total=0;
	for (ll i=0;i<=n-1;i++)
	{
		cin >> arr[i];
		alpha[arr[i]]++;
	}

	for (auto it=alpha.begin();it!=alpha.end();it++)
	{
		ll a=it->second;
		total=total+((a*(a-1))/2);
	}
	
	for (ll i=0;i<=n-1;i++)
	{
		ll a=alpha[arr[i]];
		ll b=(a*(a-1))/2;
		ll c=((a-1)*(a-2))/2;

		cout << total-b+c << endl;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define show(x) cerr << #x << " = " << x << "\n";
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define pb(x) emplace_back(x)
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = 998244353;
class mint {
public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

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

void Main(){

	ll N;
	cin >> N;
	
	ll ans = 0;
	rep2(i, 1, N + 1) ans += (N - 1) / i;
	print(ans);

}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin >> t;
	rep(i, t) Main();
	return 0;
	
}





Measured memory_bytes: 3700
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;
int a[N];
int l[N], r[N];
stack < int > s;

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    scanf("%d", a + i);
  }
  for(int i = 1; i <= n; ++i){
    while(!s.empty() && a[s.top()] > a[i]){
      r[s.top()] = i;
      s.pop();
    }
    s.push(i);
  }
  while(!s.empty()){
    r[s.top()] = n + 1;
    s.pop();
  }
  for(int i = n; i >= 1; --i){
    while(!s.empty() && a[s.top()] > a[i]){
      l[s.top()] = i;
      s.pop();
    }
    s.push(i);
  }
  while(!s.empty()){
    l[s.top()] = 0;
    s.pop();
  }
  ll ans = 0;
  for(int i = 1; i <= n; ++i){
    ans += (i - l[i]) * 1ll * (r[i] - i) * a[i];
  }
  printf("%lld", ans);

  return 0;
}


Measured memory_bytes: 3228
# coding: utf-8
from math import sin,cos,pi,sqrt
A,B,H,M=map(int,input().split())
a=(H/12+(1/12)*(M/60))*2*pi
b=(M/60)*2*pi

x1=A*cos(a)
y1=A*sin(a)
x2=B*cos(b)
y2=B*sin(b)

ans=sqrt((x1-x2)**2+(y1-y2)**2)

print(ans)

Measured memory_bytes: 9572
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
string N;
ll K;
ll combi(ll a, ll b){
	if(a<b) return 0;
	if(b==1) return a;
	if(b==2) return a*(a-1)/2;

	return a*(a-1)*(a-2)/6;
}
ll power(ll a){
	if(a==0) return 1;
	else return 9*power(a-1);
}

ll count(string N, ll K){
	ll d = N.size();

	ll res = 0;
	if(d>0){
		res += power(K)*combi(d-1, K);

		if(K==1){
			res +=  (N[0]-'0');
		}else{
			res += ((N[0]-'0')-1)*power(K-1)*combi(d-1, K-1);
			string S;
			//cout << S.size() <<endl;

			int k=1;
			while(N[k]-'0'==0) k++;

			for(int i=k;i<d;i++){
				S += N[i];
			}
			//cout << S <<endl;
			//cout << count(S, K-1) <<endl;
			res += count(S, K-1);
		}
	}
	
	return res;
}

int main(){
  	cin >> N >> K;
  	ll d = N.size();
  	if(d < K){
  		cout << 0 <<endl;
		return 0;
	}
	//cout << combi(2, 3) <<endl;
  	
  	cout << count(N, K) <<endl;

    
  	return 0;
}

Measured memory_bytes: 256
import heapq
import math
n, m = [int(v) for v in input().split()]
a_s = [-int(v) for v in input().split()]
#print(a_s)
heapq.heapify(a_s)
#print(a_s)
for i in range(m):
  max_a = heapq.heappop(a_s)
  heapq.heappush(a_s, max_a/2)

ans = 0
for a in a_s:
  ans += math.floor(-a)
print(ans)

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

#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define let const auto
#define USE1(T) template <typename T>
#define USE2(T, U) template <typename T, typename U>
#define I_ inline
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

USE1(T) using duo = std::pair<T, T>;
USE1(T) using vec = std::vector<T>;
using ll = long long;
// clang-format off
USE2(T,U) I_ bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U) I_ bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int) I_ T in(){T x;std::cin>>x;return x;}
USE1(T=int) I_ vec<T> in(int n){vec<T> v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE1(T) vec<T> ndvec(T v,int n){return vec<T>(n, v);}
USE2(T,...Ts) auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T) I_ void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts) I_ void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
I_ int rd(){int x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
I_ void wr(int x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
struct IoSetup {
  IoSetup(){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup;
// clang-format on
// }}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

ll ans = 0;
string S;
void dfs(int i = 0, ll c = 0, ll s = 0) {
  if (i == S.size()) {
    ans += s + c;
    return;
  }
  dfs(i + 1, c * 10 + S[i] - '0', s);
  if (c != 0) dfs(i + 1, S[i] - '0', s + c);
}

signed main() {
  cin >> S;
  dfs();
  pr(ans);
  return 0;
}


Measured memory_bytes: 256