akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n = 5;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i + 1 != a[i]) {
            cout << i + 1 << '\n';
            rr;
        }
    }
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	inline char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=gc();}
	}
};
using io::gi;
struct qwq{
	int a,b;
	inline bool operator<(const qwq &x)const{
		return a<x.a;
	}
};
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
const ll p=1000000007ll,inf=1000000000000000000ll;
const int N=200005;
char s[N];
int main(){
	int n,i,t=0,f=1;ll ans=1ll;
	scanf("%d%s",&n,s+1);n<<=1;
	s[0]='W';
	for(i=1;i<=n;++i){
		if(s[i]==s[i-1])f^=1;
		if(f)++t;
		else ans=ans*(t--)%p;//printf("%d %lld\n",t,ans);
	}
	if(t){printf("0");return 0;}
	n>>=1;
	for(i=1;i<=n;++i)ans=ans*i%p;
	printf("%lld",ans);
	return 0;
}

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

int main() {
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  
  for(int i=0; i<ty-sy; i++) cout << 'U';
  for(int i=0; i<tx-sx; i++) cout << 'R';
  for(int i=0; i<ty-sy; i++) cout << 'D';
  for(int i=0; i<tx-sx; i++) cout << 'L';
  cout << 'L';
  for(int i=0; i<ty-sy+1; i++) cout << 'U';
  for(int i=0; i<tx-sx+1; i++) cout << 'R';
  cout << 'D';
  cout << 'R';
  for(int i=0; i<ty-sy+1; i++) cout << 'D';
  for(int i=0; i<tx-sx+1; i++) cout << 'L';
  cout << 'U';
  
}



Measured memory_bytes: 256
import heapq
def dijkstra(s, neighbor):
    dist = [float('inf')] * N
    dist[s] = 0
    que = [(0, s)]
    heapq.heapify(que)
    while que:
        d, v = heapq.heappop(que)
        if d > dist[v]:
            continue
        for u, l in neighbor[v]:
            tmp_d = d + l
            if tmp_d < dist[u]:
                dist[u] = tmp_d
                heapq.heappush(que, (tmp_d, u))
    return dist

N, M, s, t = map(int, input().split())
yen = [[] for _ in range(N)]
snuuk = [[] for _ in range(N)]
for _ in range(M):
    u, v, a, b = map(int, input().split())
    yen[u-1].append((v-1, a))
    yen[v-1].append((u-1, a))
    snuuk[u-1].append((v-1, b))
    snuuk[v-1].append((u-1, b))

dist_s = dijkstra(s-1, yen)
dist_t = dijkstra(t-1, snuuk)
ans = [-1] * N
tmp = float('inf')
for i in range(N-1, -1, -1):
    if dist_s[i] + dist_t[i] < tmp:
        tmp = dist_s[i] + dist_t[i]
    ans[i] = 10 ** 15 - tmp
print(*ans, sep='\n')


Measured memory_bytes: 88084
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    ll n;
    cin >> n;
    vector<ll>c(n-1),s(n-1),f(n-1);
    rep(i,n-1) {
        cin >> c[i] >> s[i] >> f[i];
    }
    rep(i,n-1) {
        ll ans = 0;
        ll arrived = s[i]+c[i];
        ans += arrived;
        for(int j = i+1;j<n-1;j++) {
            if(arrived<=s[j]) { //開通式前に到着
                ans = s[j]+c[j];
                arrived = s[j]+c[j];
            }
            else if(arrived%f[j]==0) {//開通式後に到着
                ans = arrived+c[j];
                arrived += c[j];
            }
            else {
                ll k = (arrived-s[j]+f[j])/f[j];
                ans = k*f[j]+s[j]+c[j];
                arrived = k*f[j]+s[j]+c[j];
            } 
        }
        cout << ans << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long
#define sf(n) scanf("%lld",&n)
#define pf(n) printf("%lld\n",n)
#define sff(x,y) scanf("%lld %lld",&x,&y)
#define pff(x,y) printf("%lld %lld\n",x,y)
#define REP(I,N) for(I=0;I<N;I++)
#define REPP(I,A,B) for(I=A;I<=B;I++)
#define MS0(X) memset(X,0,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define F first
#define S second
#define Mod 1000000007
#define pb push_back
#define RF freopen("riyad.txt","r",stdin)
#define WF freopen("out.txt","w",stdout)
#define YES printf("YES\n")
#define NO printf("NO\n")

using namespace std;

typedef unsigned long long Ull;
typedef pair < int , int > Pii;
typedef pair < ll , ll > Pll;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //RF;
    //WF;
    ll i,tc,cs=1,n,m,k,cnt=0,j,q;
    string a,b,c,d,e,f;
    cin>>a;
    ll len = a.size();
    b = a;
    j = (len+3)/2 - 1;
    i = (len-1)/2;
    c = a.substr(0,i);
    d = c;
    e = a.substr(j,len-j);
    f = e;
    reverse(b.begin(),b.end());
    reverse(d.begin(),d.end());
    reverse(f.begin(),f.end());
    if(a == b && c == d && e == f)
        cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    long long K; cin >> K;
    vector<long long> A(N); for (auto& a : A) cin >> a;
    long long best = 0;
    for (long long bit = 1LL << 40; bit; bit >>= 1) {
        int cnt = 0;
        for (auto a : A) if (a & bit) cnt++;
        if (cnt <= N / 2) best |= bit;
    }
    //cout<<"best"<<best<<"\n";
    long long ans = 0;
    for (auto a : A) ans += a ^ K; // X == K
    for (long long bit = 1LL << 40; bit; bit >>= 1) {
        if (K & bit) {
            long long X = (K & ~(bit - 1) & ~bit) | (best & (bit - 1));
            long long f = 0;
            for (auto a : A) f += a ^ X;
            ans = max(ans, f);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;
//階乗できるよ
ll kaizyo(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) {
    ll x;
    cin >> x;
    x--;
    a.at(i) = x;
  }

  vector<bool> flag(n,false);
  ll current_pos = 0;
  ll count = 0;
  ll point_city;
  while(1){
    if(flag.at(current_pos) == true) {
      point_city = current_pos;
      break;
    }
    flag.at(current_pos) = true;
    current_pos = a.at(current_pos);
  }  

  ll first_point = INF,second_point = INF;

  current_pos = 0;

  while(1) {
    if(current_pos == point_city){
      if(first_point != INF) {
        second_point = count;
        break;
      }
      first_point = count;
    }
    count++;
    current_pos = a.at(current_pos);
  }

  ll roop_len = second_point - first_point;
  
  //cout << roop_len << ' ' << first_point << endl;

  if(k <= first_point){
    ll current_pos_min = 0;
    rep(i,k) {
      current_pos_min = a.at(current_pos_min);
    }
   cout << current_pos_min + 1 << endl;
  }
  else{
    k = k - first_point;
    k = k % roop_len;
    //cout << k << endl;
    ll current_pos_max = point_city;
    rep(i,k) {
      current_pos_max = a.at(current_pos_max);
    }
    cout << current_pos_max + 1 << endl;
  }


}




Measured memory_bytes: 4844
def p(val):
    print(val)


n = int(input())
sho = 10**9+7
vv=0
if n==1:
    vv=0
else:
    vv = ((10**n%sho - 9**n%sho -9**n%sho +8**n%sho)%sho)
p(vv)

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
    int n, m;
    ll k;
    cin >> n >> m >> k;
    vector<ll>a(n+1),b(m+1),suma(n+1),sumb(m+1);
    rep(i, 0, n)cin >> a[i+1];
    rep(i, 0, m)cin >> b[i+1];

    rep(i, 0, n)suma[i+1]=suma[i]+a[i+1];
    rep(i, 0, m)sumb[i+1]=sumb[i]+b[i+1];

    int ans = 0;
    bool flag = false; 
    rep(i, 0, n+1){
        ll temp = k - suma[i];
        if(temp < 0)break;
        int l = -1;
        int r = m+1;
        while(r-l>1){
            int s = (l+r)/2;
            if(sumb[s]>temp) r = s;
            else l = s;
        }
        ans = max(ans, i+l); 
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N;
    cin >> N;

    ll T, A;
    cin >> T >> A;

    ll ans = 1;
    float mini = 1e6;
    for(ll i=0; i<N; i++)
    {
        ll h;
        cin >> h;

        if(abs(abs(T-(float)(h*0.006)-A)) < mini)
        {
            mini = abs(abs(T-(float)(h*0.006)-A));
            ans = i+1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll A, B, C;
    scanf("%lld %lld %lld", &A, &B, &C);
    rep(i, 1, 2*B+1){
        if((i*A)%B==C){
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const ll llinf = LLONG_MAX;
const ull ullinf = ULLONG_MAX;

ll n;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;
#endif
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  string ans = "";
  ll now = 1;
  ll m = 2;
  while (n != 0) {
    if (n % m != 0) {
      ans += "1";
      n -= now;
    } else ans += "0";
    now *= -2;
    m *= 2;
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}


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

int main () {
    int N, X, answer = 1, D = 0;
    cin >> N >> X;

    vector <int> L (N);
    for (int i = 0; i < N; i++){
        cin >> L .at(i);
    }

    for (int i = 0; i < N; i++){
        D += L .at(i);
        if(D <= X){
            answer++;
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define LL long long

#include <algorithm>
#include <vector>
void _150() {
    LL n;
    cin >> n;

    // int p[8];
    // int q[8];
    int temp;
    vector<int> p, q;
    vector<int> perm_base;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        p.push_back(temp);
        perm_base.push_back(i + 1);
    }
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        q.push_back(temp);
    }

    LL a, b, index;
    a = -1;
    b = -1;
    index = 0;
    do {
        if (perm_base == p) {
            a = index;
        }

        if (perm_base == q) {
            b = index;
        }

        if (a != -1 && b != -1) {
            break;
        }

        index++;
    } while (next_permutation(perm_base.begin(), perm_base.end()));

    cout << abs(a - b) << endl;
}

#include <string>
void _151() {
    int n, m;
    cin >> n >> m;
    int p[100000] = {0};
    int correct[100000] = {0};
    int penalty_counts[100000] = {0};
    string temp;
    int correct_count = 0;
    for (int i = 0; i < m; ++i) {
        cin >> p[i] >> temp;
        if (temp == "AC") {
            if (correct[p[i] - 1] != 1) {
                correct_count++;
                correct[p[i] - 1] = 1;
            }
        } else {
            if (correct[p[i] - 1] != 1) {
                penalty_counts[p[i] - 1]++;
            }
        }
    }
    int penalty_count = 0;
    for (int i = 0; i < n; ++i) {
        if (correct[i] == 1) {
            penalty_count += penalty_counts[i];
        }
    }
    cout << correct_count << " " << penalty_count << endl;
}

#include <limits>
void _152_() { 
    int n;
    cin >> n;
    int temp;
    vector<int> p;
    int min_val = numeric_limits<int>::max();
    int count = 0;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        if (min_val >= temp) {
            min_val = temp;
            count++;
        }
    }
    cout << count << endl;
}

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

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

    if (n <= k) {
        cout << 0 << endl;
        return;
    }

    sort(h.begin(), h.end());

    int num_monsters = n - k;
    LL count = 0;
    for (int i = 0; i < num_monsters; ++i) {
        count += h[i];
    }
    cout << count << endl;
}

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



Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;


int main() {

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

	int n;
	cin >> n;

	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}


	std::sort(a.begin(), a.end(), [](int &i, int &j) {return i < j;});

	while (1) {
		for (int i = 1; i < n; i++) {
			int tmp = a[i] / a[0];
			if(tmp != 0) a[i] -= a[0] * tmp;
			else a[i] -= a[0];
			if (a[i] < 1) {
				a.erase(a.begin() + i);
				n--;
			}
		}
		std::sort(a.begin(), a.end(), [](int &i, int &j) {return i < j;});
		if (a.size() == 1)break;
	}

	cout << a[0] << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,a,b;
	cin >> n >> a >> b;
	ll ans = 0 , pre;
	cin >> pre;
	for(int i=2,x;i<=n;i++) {
		cin >> x;
		ans += min((ll)b,(ll)(x-pre) * a);
		pre = x;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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



int main() {
    ll T[2],A[2][2];
    cin>>T[0]>>T[1]>>A[0][0]>>A[0][1]>>A[1][0]>>A[1][1];
    ll s1end[2],s2end[2];
    s1end[0]=T[0]*A[0][0];
    s1end[1]=T[0]*A[1][0];
    s2end[0]=T[1]*A[0][1]+s1end[0];
    s2end[1]=T[1]*A[1][1]+s1end[1];
    if(s2end[0]==s2end[1]){
        cout<<"infinity"<<endl;
        return 0;
    }

    if(s2end[0]>s2end[1]){
        ll ans=max((s1end[1]-s1end[0])/(s2end[0]-s2end[1])*2ll+1ll,0ll);
        if((s1end[1]-s1end[0])%(s2end[0]-s2end[1])==0||s1end[1]-s1end[0]<0) ans--;
        cout<<max(ans,0ll)<<endl;
    }else{
        ll ans=max((s1end[0]-s1end[1])/(s2end[1]-s2end[0])*2ll+1ll,0ll);
        if((s1end[0]-s1end[1])%(s2end[1]-s2end[0])==0||s1end[0]-s1end[1]<0) ans--;
        cout<<max(ans,0ll)<<endl;
    }

    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	string s;
	cin >> n >> s;
	if (n % 2) {
	  cout << "No" << endl;
	  return 0;
	}
	rep (i, n / 2) {
	  if (s[i] != s[i + n / 2]) {
		cout << "No" << endl;
		return 0;
	  }
	}
	cout << "Yes" << endl;
    
    return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
    string in,out;
    cin>>in;
    int j=0;
    for(int i=0;i<in.size();i++){
        if(in.at(i)=='0'){
            out.push_back(j);
            out.at(j)='0';
            j++;
        }else if(in.at(i)=='1'){
            out.push_back(j);
            out.at(j)='1';
            j++;
        }else if(out.size()>0){
            out.pop_back();
            j--;
        }
        
    }
    cout<<out<<endl;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int A[] = new int[N];
        int minj, i,j, count=0;
        for(i=0; i<N; i++) A[i] = sc.nextInt();
        boolean swapped;

        for(i=0; i<N; i++)
        {
            minj = i;
            swapped = false;

            for(j=i; j<N; j++)
            {
                if(A[j]<A[minj])
                {
                    minj=j;
                    swapped = true;
                }
            }
            if(swapped)
            {
                count++;
                int c;
                //System.out.printf("swapping %d and %d\n",A[i],A[minj]);
                c=A[i];
                A[i]=A[minj];
                A[minj]=c;
                //for(int m=0;m<N; m++) System.out.printf("%d ",A[m]);
                //System.out.printf("\n");
            }
        }

        for(i=0; i<N-1; i++) System.out.printf("%d ",A[i]);
        System.out.printf("%d\n",A[N-1]);
        System.out.println(count);

        sc.close();
    }
}


Measured memory_bytes: 26516
#include<iostream>
#include<stdio.h>
#include<vector>
#define INF 2147483647
using namespace std;

class Lantern{
public:
	bool vector_find(vector<int> v,int key){
		for(int i=0;i<v.size();i++){
			if(v[i]==key){return 1;}
		}
		return 0;
	}
	int Solve(int n, int roadlist[100][100] ){
		int ans=0,i,j;
		vector<int> V;
		V.push_back(0);
		while(V.size()!=n){
			int u,v,min=INF;
			for(i=0;i<V.size();i++){
				for(j=0;j<n;j++){
					if(!vector_find(V,j)&&roadlist[V[i]][j]<min){
						u=i,v=j;
						min=roadlist[V[i]][j];
					}
				}
			}
			ans+=min;
			V.push_back(v);
		}
		return ans;
	}

};

int main(){
	int n,m;
	int rlist[100][100];
	Lantern lantern;
	while(1){
		for(int i=0;i<100;i++){
			for(int j=0;j<100;j++){
				rlist[i][j]=INF;
			}
		}
		
		scanf("%d",&n);
		if(n==0){break;}
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			int a,b,c;
			scanf("%d,%d,%d",&a,&b,&c);
			rlist[a][b]=rlist[b][a]=c/100-1;
		}
		printf("%d\n",lantern.Solve(n,rlist));
		
	}
	
	
	
}
	
	

Measured memory_bytes: 1244
import sys
n = int(input())
h = list(map(int,input().split()))
for k in range(n-1):
    if h[k+1]==h[k]-1:
        h[k+1]=h[k+1]+1
    elif h[k+1]>=h[k]:
        continue
    else:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 14252
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        v: [i64; n],
        c: [i64; n],
    }
    let mut diff = vec![0i64; n];
    for i in 0..n {
        diff[i] = v[i] - c[i]
    }
    println!("{}", diff.iter().filter(|&x| x > &0).sum::<i64>());
}


Measured memory_bytes: 4352
N = int(input())
d = []

time = 0;_x = 0;_y = 0

for i in range(N):
    t, x, y = map(int, input().split())
    time = t - time
    dis = abs(_x - x) + abs(_y - y)
    if dis == time:
        time, _x, _y = t, x, y
    elif dis < time and (time - dis) % 2 == 0:
        time, _x, _y = t, x, y
    else:
        print("No")
        exit()

print("Yes")


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

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

int N;

void dfs(string s, char mx)
{
	if (s.size() == N) {
		cout << s << endl;
		return;
	}

	for (char c = 'a'; c <= mx + 1; ++c) {
		dfs(s + c, c > mx ? c : mx);
	}
}

int main()
{
	cin >> N;

	dfs("", 'a'-1);
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int H, W, N;
	cin >> N >> H >> W;

	int a, b;
	a = N - H + 1;
	b = N - W + 1;

	cout << a * b << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int n,k,sum=0;
	cin >> n >> k;
	vector<int> l(n);
	for (int i = 0; i < n; i++) cin >> l[i];
	
	sort(l.begin(), l.end());
	for (int i = n - 1; i > n - k - 1; i--) {
		sum += l[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while(true)
int main(){
    int X;
    cin >> X;
    switch(X%7){
        case 2:
        cout << "sat" << endl;
        break;
        case 3:
        cout << "sun" << endl;
        break;
        case 4:
        cout << "mon" << endl;
        break;
        case 5:
        cout << "tue" << endl;
        break;
        case 6:
        cout << "wed" << endl;
        break;
        case 0:
        cout << "thu" << endl;
        break;
        case 1:
        cout << "fri" << endl;
        break;
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
    int n, m, ans = 0;
    cin >> n;
    VI time(n);
    rep(i, n)
    {
        cin >> time.at(i);
        ans += time.at(i);
    }
    cin >> m;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        cout << ans - time.at(a - 1) + b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N,K = [int(i) for i in input().split()]


kaneko = []

for i in range(N):
    a,b = [int(i) for i in input().split()]
    c = [a,b]
    kaneko.append(c)

kaneko = sorted(kaneko)
sum = 0

for i in range(N):
    sum += kaneko[i][1]
    if sum >= K:
        print(kaneko[i][0])
        break

Measured memory_bytes: 25256
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 1e5 + 10;
const int M = (int) 101;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int INF1 = (int) 1e9 + 3;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;

int n;
int a[N], b[N];

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i] >> b[i];
    }
    ll suff = 0;
    for (int i = n; i >= 1; i--) {
      ll up = (a[i] + suff + b[i] - 1) / b[i];
      up *= b[i];
      suff = up - a[i];
    }
    cout << suff;
    return 0;
}

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

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    ll ans = 0;
    
    string inp; cin >> inp;
    
    string bef = "-";
    string now = "";
    
    rep(i, inp.size()){
        now += inp[i];
        if(now != bef){
            ans ++;
            bef = now;
            now = "";
        }
    }
    cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 720
import numpy as np
import sys
buf = sys.stdin.buffer
N,Q = map(int,buf.readline().split())
S = np.zeros(N+2, dtype='S1')
S[1:] = np.frombuffer(buf.read(N+1), dtype='S1')
A = (S == b'A')
C = (S == b'C')
AC = (A[:-1] & C[1:])
AC_cum = list(AC.cumsum())

for _ in range(Q):
  L,R = map(int,buf.readline().split())
  print(AC_cum[R-1] - AC_cum[L-1])


Measured memory_bytes: 17576
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long x = scan.nextLong();
		long y = scan.nextLong();
		long normal = Math.min(x,y/2L);
		if(y-normal<=1) {
			System.out.println(normal);
			return;
		}
		System.out.println(normal+(y-normal*2)/4L);
	}
}


Measured memory_bytes: 20820
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 998244353; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



long long power(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, zero = 0, maximum = 0;
	vector<int> D;
	vector<int> con;
	
	cin>>N;
	
	D.resize(N);
	con.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>D[i];
		// if(!D[i])zero++;
		con[D[i]]++;
		maximum = max(maximum, D[i]);
	}
	
	if(D[0]){
		cout<<0<<endl;
	} else if(con[0] >= 2){
		cout<<0<<endl;
	} else {
		int ans = 1;
		
		for(int i = 1; i <= maximum; i++){
			if(con[i] == 0) ans = 0;
			// else ans *= power(i, con[i]);
			else ans *= power(con[i-1], con[i]);
			
			ans %= MOD;
		}
		
		cout<<ans<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
 
typedef struct{
  double x;
  double y;
} Point;
 
void koch(int, Point, Point);
 
int main(int argc, char const *argv[]) {
 
  Point p1,p2; 
  int n;
 
  scanf("%d",&n);
 
  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
 
  printf("%.8f %.8f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);
 
  return 0;
}
 
void koch(int n, Point p1, Point p2){
 
  if( n == 0 ) return;
 
  Point s,t,u;
  double th = M_PI * 60.0 / 180.0;
 
  s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
  u.x = (t.x-s.x) * cos(th) - (t.y-s.y) * sin(th) + s.x;
  u.y = (t.x-s.x) * sin(th) + (t.y-s.y) * cos(th) + s.y;
 
  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,p2);
 
}

Measured memory_bytes: 644
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
 
typedef long long ll;
typedef long double ld;
 
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
 
using namespace std;

vector <int> g[1000000];

int a[1000000], n;

int dfs (int x, int p)
{
	for (int to : g[x])
		if (to != p)
			a[x] ^= dfs (to, x) + 1;

	return a[x];
}

int main ()
{
	cin >> n;

	for (int i = 0; i < n - 1; i++)
	{
		int u, v;

		scanf ("%d%d", &u, &v);

		g[u-1].push_back (v - 1);
		g[v-1].push_back (u - 1);
	}

	if (dfs (0, -1)) cout << "Alice";
	else cout << "Bob";
}

Measured memory_bytes: 33792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX 50

signed main(){
    int n;
    cin >> n;
    int c[2][n];
    rep(i,n){
        cin >> c[0][i];
    }
    rep(i,n){
        cin >> c[1][i];
    }
    vector<vector<int>> dp(1 << n, vector<int>(MAX + 1, INF));
    dp[0][0] = 0;
    for(int bit = 0; bit < 1 << n; bit++){
        int now = 0;
        int dist[n];
        for(int i = 0; i < n; i++){
            if(!(bit & 1 << i)){
                dist[i] = now;
                now++;
            }
        }
        int cnt = n - now;
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)) continue;
            int k = abs(i - cnt);
            for(int j = 0; j <= c[k % 2][i]; j++){
                dp[bit | (1 << i)][c[k % 2][i]] = min(dp[bit | (1 << i)][c[k % 2][i]], dp[bit][j] + dist[i]);
            }
        }
    }
    int ans = INF;
    for(int i = 0; i <= 50; i++){
        ans = min(ans, dp[(1 << n) - 1][i]);
    }
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}

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

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

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

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

int main(){
	static int n;
	static int a[300010];
	scanf("%d",&n);
	rep(i,3*n)scanf("%d",&a[i]);
	sort(a,a+(3*n));
	ll ret = 0;
	rep(i,n){
		ret += a[3*n-1-2*i-1];
	}
	cout << ret << endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

int N, Q, p[100010], b[100010], c[100010];
ll sum;
int main() {
	scanf("%d", &N);
	rep(i, 0, N) {
		int tmp; scanf("%d", &tmp);
		p[tmp]++;
		sum += tmp;
	}
	scanf("%d", &Q);
	rep(i, 0, Q) scanf("%d%d", &b[i], &c[i]);

	rep(i, 0, Q){
		int _b = b[i], _c = c[i];
		sum -= p[_b] * _b;
		sum += p[_b] * _c;
		p[_c] += p[_b];
		p[_b] = 0;
		printf("%lld\n", sum);
	}
    return 0;
}


Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n,s=0; cin>>n;
  int a[n],b[n],c[n];
  rep(i,n) cin>>a[i],a[i]--;
  rep(i,n) cin>>b[i];
  rep(i,n-1) cin>>c[i];
  rep(i,n){
    s+=b[i];
    if(a[i]&&a[i]-1==a[i-1]) s+=c[a[i-1]];
  }
  cout<<s;
}

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

using namespace std;

#define int long long
#define endl "\n"

void rwf() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

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

	//rwf();

	string s;
	cin >> s;

	for(int i=0; i<s.length(); i++) {
		if(s[i]=='7') {
			cout << "Yes";
			return 0;
		}
	}

	cout << "No";

	return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        long S = sc.nextLong();
        long[] X = new long[3];
        long[] Y = new long[3];
        X[0] = 0;
        Y[0] = 0;
        X[1] = 1000000000;
        Y[1] = 1;
        X[2] = (X[1] - S % X[1]) % X[1];
        Y[2] = (S + X[2]) / X[1];
        for (int i = 0; i < 3; i++) {
            System.out.print(X[i] + " " + Y[i] + " ");
        }
        System.out.println();
    }
}

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

// next_permutation版

int main(){
    int N; cin >> N;
    int p=0;
    int q=0;
    rep(i, N){
        int t; cin >> t;
        p = p*10+t;
    }
    rep(i, N){
        int t; cin >> t;
        q = q*10+t;
    }

    // 順列列挙
    vector<int> array_n(N);
    vector<int> ans_v;
    iota(array_n.begin(), array_n.end(), 1);
    do{
        int tmp=0;
        rep(i, N) tmp = tmp*10 + array_n[i];
        ans_v.push_back(tmp);
    }while(next_permutation(array_n.begin(), array_n.end()));
    

    int a_v=0;
    int b_v=0;
    rep(i, ans_v.size()){
        if(ans_v.at(i) == p) a_v=i;
        if(ans_v.at(i) == q) b_v=i;
    }


    cout << abs(a_v -b_v) << endl;


    return 0;
}

Measured memory_bytes: 640
/*Anikash Chakraborty cpp*/
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define w(t) int t; cin>>t; while(t--)
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<long long>
#define MAX 100002
#define MOD 1000000007
#define ll long long
 
using namespace std;
ll bigmod(ll b, ll p, ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
bool vis[MAX];
vector<ll> adj[MAX];
void dfs(ll u)
{
    vis[u] = true;
    for(auto i:adj[u])
        if(!vis[i]) dfs(i);
}

ll dp[MAX];
int solve(vi a,ll n){
    int dp[n+1];
    
    dp[0]=0;
      dp[1]=abs(a[0]-a[1]);
     
      for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i-2]-a[i]));
     
      return dp[n-1];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        memset(dp,-1,sizeof dp);
    
        ll n;
        cin>>n;
        vi a(n);

        REP(i,n) cin>>a[i];
        
        cout<<solve(a,n)<<endl;

        // REP(i,n) cout<<dp[i]<<" ";
        // cout<<endl;
        

    
    
 
}



Measured memory_bytes: 4608
#include <iostream>
#include <stdio.h>


long long int gcd(long long int c, long long int d)
{
	return d? gcd(d, c % d) : c;
}

using namespace std;

int main()
{
	long long int a, b, c, d, s1, s2;
	cin >> a >> b >> c >> d;
	
	--a;
	s1 = a / c  - (a / ((c/gcd(c,d))*d)) + a / d;
	s1 = a - s1;
	s2 = b / c  - (b / ((c/gcd(c,d))*d)) + b / d;
	s2 = b - s2;
	
	
	cout << s2 - s1;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

char s[303][303];
int ans[303][303];

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H,W,K,cnt=1;
	vector<pair<int,int>> p;
	cin >> H >> W >> K;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> s[i][j];
			if(s[i][j]=='#'){
				ans[i][j]=cnt;
				cnt++;
				p.emplace_back(i,j);
			}
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(ans[i][j]){
				int t = j;
				while(ans[i][t-1]== 0 && (t-1)>=0){
					ans[i][t-1] = ans[i][j];
					t--;
				}
				t = j;
				while(ans[i][t+1]==0  && (t+1)<W){
					ans[i][t+1] = ans[i][j];
					t++;
				}
			}
		}
	}
	rep(i,H){
		rep(j,W){
			if(ans[i][j] && ans[i-1][j]==0 && i-1>=0){
				rep(k,W)ans[i-1][k] = ans[i][k];
				i--;
				continue;
			}
		}
	}
	rep(i,H){
		rep(j,W){
			if(ans[i][j] && ans[i+1][j]==0 && i+1<H){
				rep(k,W)ans[i+1][k] = ans[i][k];
			}
		}
	}
	rep(i,H){
		rep(j,W){
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
}

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

int main() {
  int N, k;
  cin >> N >> k;
  int s;
  int Y = 1000000000;
  for (int s = 0; s <= N; s++) {  // s=0-NでXの最小値を求める→小さければ更新
    int X = 1;                    // Xは結果
    for (int i = 0; i < s; i++) { // s回2をかける 
      X = 2 * X;
    }
    X = X + k * (N-s);             // X=2^s+(N-s)k
    if (X < Y)
      Y = X;
  }
  cout << Y << endl;
}


Measured memory_bytes: 256
import sys
import math

def resolve():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = [0]
    cur = 0
    for a in A:
        cur += a
        B.append(cur)
    #print(B)
    C = []
    for b in B:
        C.append(b%M)
    import collections
    counts = collections.Counter(C)
    #print(counts)
    ans = 0
    for count in counts.values():
        ans += count*(count-1)//2
    print(ans)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 64152
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
typedef pair<int, int> P;

int dist[100005][3];

signed main(){
    int a, b , c, k;
    cin >> a >> b >> c>>k;
    if(a+b>=k) cout << min(k,a) << endl;
    else cout << a-(k-(a+b)) << endl;
    return 0;
}

Measured memory_bytes: 3508
import itertools
n,m,x = map(int,input().split())

a = [[int(i) for i in input().split()] for _ in range(n)] #行列
#s = [int(input()) for _ in range()] #縦
#a = [int(x) for x in input().split()] #横

sum1 = [0] * (m+1)
sum2 = [0] * (m+1)

ans = 0

st = list(itertools.product([0,1], repeat = n))
#print(st)

for i in range(n):
    for j in range(m+1):
        sum1[j] += a[i][j]
for  i in range(1,m+1):
    if sum1[i] < x:
        sum1[0] = -1
        print(-1)
        exit()

ans = sum1[0]

for i in range(2**n):
    for j in range(n):
        for k in range(m+1):
            #print(i,j,k)
            sum2[k] +=  a[j][k]*st[i][j]
    #print(sum2)
    for i in range(1,m+1):
        if sum2[i]  < x:
            sum2[0]= 100000000
    ans = min(sum2[0],ans)
    #print(ans)
    sum2 = [0] * (m+1)

print(ans)


Measured memory_bytes: 9648
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;
int main() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (ll i = 0; i < N; i++) cin >> A[i] >> B[i];
    ll cnt = 0;
    for (ll i = N - 1; i >= 0; i--) cnt += B[i] * ceil((A[i] + cnt) / (long double)B[i]) - A[i] - cnt;
    cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    long long n, m;
    while (cin >> n >> m, n) {
        vector <long long> p(n);
        rep (i, n) cin >> p[i];
        p.push_back(0);

        vector <long long> sum[2];
        rep (i, 2) rep (j, n + 1) rep (k, n + 1) sum[i].push_back(p[j] + p[k]);

        long long ans = 0;
        sort(sum[1].begin(), sum[1].end());
        for (long long num : sum[0]) {
            auto tmp = lower_bound(sum[1].begin(), sum[1].end(),
                                   m - num
                                   );
            if (tmp != sum[1].begin()) tmp--;
            ans = max(ans,
                      num + *tmp > m ? 0 : num + *tmp
                      );
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 26560
N, K = map(int, input().split())
X = list(int(x) for x in input().split())

ans = 10**18
for l in range(N-(K-1)):
    r = l + K - 1
    ans = min(ans, abs(X[l]) + abs(X[r] - X[l]))
    ans = min(ans, abs(X[r]) + abs(X[l] - X[r]))

print(ans)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	lint q,h,s,d,n,min1L,min2L;
	cin>>q>>h>>s>>d>>n;
	min1L=min({q*4,h*2,s});
	min2L=min(min1L*2,d);
	cout<<(n%2?min2L*(n/2)+min1L:min2L*(n/2))<<endl;
}


Measured memory_bytes: 256