akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x;
    cin >> a >> b;
    x = (a+b)/2;
    if( (a+b)%2!= 0 ){
        cout << x+1 << endl;
    }else{
        cout << x << endl;
    }
}

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

using namespace std;

const int N = (int)1e6 + 10;

int mark[N];
int prime[N];
int Size;

void init() {
    Size = 0;
    for (int i = 2; i < N; i++) {
        if (mark[i] == 0) {
            prime[Size++] = i;
        }
        if (i >= 1000) continue;
        for (int j = i * i; j < N; j+= i) {
            mark[j] = 1;
        }
    }
}

int main() {
    init();
    int X;
    cin >> X;
    int pos = lower_bound(prime, prime + Size, X) - prime;
    cout << prime[pos] << endl;
    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
const ll mod=998244353;
int main(void){
    ll n,s;cin>>n>>s;
    vector<vector<ll>> dp(3010,vector<ll>(3010,0));
    dp[0][0]=1;
    rep(i,n){
        ll a;cin>>a;
        for(ll j=0;j<=3000;j++){
            dp[i+1][j]+=dp[i][j]*2;
            dp[i+1][j]%=mod;
            if(j+a<=s) {
			    dp[i+1][j+a]+=dp[i][j];
			    dp[i+1][j+a]%=mod;
			}
        }
    }
    cout<<dp[n][s]<<endl;
}

Measured memory_bytes: 74260
#include <stdio.h>
int main(void){
	int i,j,a,b[101],c,cnt=0;
	scanf("%d",&a);
	for(i=0;i<a;i++)
		scanf("%d",&b[i]);
	for(i=0;i<a-1;i++){
		for(j=a-1;j>i;j--){	
			if(b[j] < b[j-1]){
				c = b[j-1];
				b[j-1] = b[j];
				b[j] = c;
				cnt++;
			}
		}
	}
	for(i=0;i<a;i++){
		printf("%d",b[i]);
		if(i!=a-1)
			printf(" ");
		else
			printf("\n");
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
int nu[maxn];
int vis[maxn];
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
    {
        scanf("%d", nu + i);
    }
    int cnt1 = 0, ans1 = 0;
    int cnt2 = 0, ans2 = 0;
    for(int i = 1; i <= n; i += 2)
    {
        ++vis[nu[i]];
        if(cnt1 < vis[nu[i]])
        {
            cnt1 = vis[nu[i]];
            ans1 = nu[i];
        }
    }
    for(int i = 1; i <= n; i += 2)
    {
        if(nu[i] == ans1) continue;
        if(cnt2 < vis[nu[i]])
        {
            cnt2 = vis[nu[i]];
            ans2 = nu[i];
        }
    }
    memset(vis, 0, sizeof(vis));
    int cnt3 = 0, ans3 = 0;
    int cnt4 = 0, ans4 = 0;
    for(int i = 2; i <= n; i += 2)
    {
        ++vis[nu[i]];
        if(cnt3 < vis[nu[i]])
        {
            cnt3 = vis[nu[i]];
            ans3 = nu[i];
        }
    }
    for(int i = 2; i <= n; i += 2)
    {
        if(ans3 == nu[i]) continue;
        if(cnt4 < vis[nu[i]])
        {
            cnt4 = vis[nu[i]];
            ans4 = nu[i];
        }
    }
    //printf("%d %d %d %d\n", cnt1, cnt2, cnt3, cnt4);
    int res = inf;
    if(ans1 != ans3)
    {
        res = min(res, n - cnt1 - cnt3);
    }
    if(ans1 != ans4)
    {
        res = min(res, n - cnt1 - cnt4);
    }
    if(ans2 != ans3)
    {
        res = min(res, n - cnt2 - cnt3);
    }
    if(ans2 != ans4)
    {
        res = min(res, n - cnt2 - cnt4);
    }
    res = min(res, n - cnt1);
    res = min(res, n - cnt3);
    printf("%d\n", res);
    return 0;
}
/*
10
1 1 1 1 1 1 2 1 2 1
*/


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

int main(){
  int N, X, T;
  cin >>N >>X >>T;
  
  int numbers;
  
  if (N % X == 0) {
  	numbers = N / X;
  }
  
  else {
    numbers = N / X + 1;
  }
  
  cout << numbers * T << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int lg[100010];
int rg[100010];
int a[100010];
int gcd(int a, int b) {
    if (a % b == 0) {
        return (b);
    }
    else {
        return (gcd(b, a % b));
    }
}
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    lg[1] = a[1];
    rg[n] = a[n];
    for (int i = 2; i <= n; i++) {
        lg[i] = gcd(lg[i - 1], a[i]);
    }
    for (int i = n - 1; i > 0; i--) {
        rg[i] = gcd(rg[i + 1], a[i]);
    }
    int ans = 0;
    if (ans < lg[n - 1]) {
        ans = lg[n - 1];
    }
    for (int i = 2; i < n; i++) {
        if (ans < gcd(lg[i - 1], rg[i + 1])) {
            ans = gcd(lg[i - 1], rg[i + 1]);
        }
    }
    if (ans < rg[2]) {
        ans = rg[2];
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4776
def Collatz(n) :
    if n % 2 == 0 :
        return n // 2
    else :
        return n * 3 + 1

while True :
    n = int(input())
    if n == 0 :
        break
    
    count = 0
    while n != 1 :
        n = Collatz(n)
        count += 1
    print(count)


Measured memory_bytes: 5596
row1 = list(map(int,input().split()))
row2 = list(map(int,input().split()))
row3 = list(map(int,input().split()))
n = int(input())
arr = []
for i in range(n):
    temp = int(input())
    arr.append(temp)

if row1[0] in arr and row1[1] in arr and row1[2] in arr or row2[0] in arr and row2[1] in arr and row2[2] in arr or row3[0] in arr and row3[1] in arr and row3[2] in arr:
    print("Yes")
    exit()
elif row1[0] in arr and row2[0] in arr and row3[0] in arr or row1[1] in arr and row2[1] in arr and row3[1] in arr or row1[2] in arr and row2[2] in arr and row3[2] in arr:
    print("Yes")
    exit()
elif row1[0] in arr and row2[1] in arr and row3[2] in arr or row1[2] in arr and row2[1] in arr and row3[0] in arr:
    print("Yes")
    exit()
else:
    print("No")

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
double n,a[100005],x,y=1e5;
map <int , double> v;
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        x+=a[i];
    }
    x/=n;
    for (int i=0;i<n;i++)
    {
        v[i]=abs (a[i]-x);
        y=min (abs (a[i]-x),y);
    }
    for (int i=0;i<n;i++)
    {
        if (v[i]==y)
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
aa,bb = map(int,input().split())
n = min(aa,bb)
b = max(aa,bb)
ans = 1
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
         if temp%i==0:
                  cnt=0
                  while temp%i==0:
                           cnt+=1
                           temp //= i
                  arr.append(i)

if temp!=1:
         arr.append(temp)

if arr==[] and n != 1:
         arr.append(n)

for j in range(len(arr)):
         if b % arr[j] == 0:
                  ans += 1
print (ans)


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC optimize("Ofast")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <random>
#include <cassert>
#include <complex>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef complex <LD> cld;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T1, typename T2>
T2 sum_mod(T1 x, T2 MOD) {
	if (x < 0)
		x += MOD;
	if (x >= MOD)
		x -= MOD;
	return x;
}

template <typename T1, typename T2>
T2 mul_mod(T1 x, T2 MOD) {
	if (x < 0)
		return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD);
	return x % MOD;
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 gen_rand;

const int N = (int)1e5 + 7;
const int LOG = 20;
const int N_ = (int)8e2 + 7;
const int MAXN = (int)5e5 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int CONST = 300;
const LL LINF = (i64)2e15;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1e-6;

/////////////////////////////////////////////////////////////////////

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
	gen_rand.seed(0);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	gen_rand.seed(time(0));
#endif

	LL k, x;
	cin >> k >> x;
	cout << (500LL * k >= x ? "Yes" : "No");

#ifdef _DEBUG 
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int a, b[20] = { 0 }, c, d, ans;
  
bool check(int e, int f)
 {
    if (e == c)
        return true;
    if (f == a)
        return false;
  
    return check(e, f + 1) || check(e + b[f], f + 1);
}
  
int main()
{
    cin >> a;
    for (int i = 0;i < a;++i)
    {
        cin >> b[i];
    }
  
    cin >> d;
    for (int i = 0;i < d;++i)
    {
        cin >> c;
  
        ans = check(0, 0);
        if (ans != 0)
            cout << "yes" << '\n';
        else
            cout << "no" << '\n';
    }
}

Measured memory_bytes: 3072
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll a, b;
  cin >> a >> b;
  set<ll> st;
  st.insert(1);
  st.insert(2);
  st.insert(3);
  st.erase(a);
  st.erase(b);
  cout << *st.begin() << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    a = list(map(int, input().split()))
    s = a[0]
    for i in range(1, N):
        s ^= a[i]
    ans = [str(x^s) for x in a]
    print(" ".join(ans))
if __name__ == "__main__":
    main()

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

using namespace std;

#define int long long 
#define F first 
#define S second 
#define pii pair<int,int> 
#define mpr make_pair

typedef long long ll;

const int maxn = 1e5+10;
const int mod = 998244353;
const int inf = 1e9+10;

int n, k, m, q;
int a[maxn];
vector<pii> edge;
vector<int> g[maxn];
bool mark[maxn];
int comp[maxn];

void dfs(int v, int k)
{
	comp[v] = k;
	mark[v] = 1;
	for(auto u : g[v])
		if(!mark[u]) dfs(u,k);
}

signed main()
{
//	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);	
	
	cin>> n >> m >> q;
	bool is_cyc = 0;
	for(int i = 1, a, b, c; i <= q; i++)
	{
		cin>> a >> b >> c;
		a++; b++;
		if(c == 0)
		{
			g[a].push_back(b);
			g[b].push_back(a);
		}
		else 
		{
			is_cyc = 1;
			edge.push_back({a,b});	
		}
	}	
	
	for(int i = 1; i <= n; i++) 
		if(!mark[i]) dfs(i,++k);
	
	for(auto e : edge)
	{
		int u = e.F, v = e.S;
		if(comp[u] == comp[v]) return cout<<"No", 0;
	}
	
	if(k <= 2 && is_cyc) return cout<<"No", 0;
	
	int L = n-1 + is_cyc, R = k * (k-1) / 2 + n-k;	
	if(m >= L && m <= R) cout<<"Yes";
	else cout<<"No";
}

















Measured memory_bytes: 11396
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


string s;
ll limit = pow(2, 19);
vector <vector <ll>>bits(26, vector<ll>(limit, 0));

void add(vector<ll> &bit, ll idx, ll num){
    while(idx < limit){
        bit[idx] += num;
        idx += idx & (idx*-1);
    }
}
ll sum(vector<ll> &bit, ll idx){
    ll ans = 0;
    while(idx > 0){
        ans += bit[idx];
        idx -= idx & (idx*-1);
    }
    return ans;
}
ll cnt(ll start, ll end){
    ll ans = 0;
    REP(i, 26){
        ll addd = sum(bits[i], end) - sum(bits[i], start);
        if (addd > 1){
            addd = 1;
        }
        ans += addd;
    }
    return ans;
}
void change(ll idx, char c){
    char moto = s[idx-1];
    if (moto == c){
        return;
    }
    add(bits[moto - 'a'], idx, -1);
    add(bits[c - 'a'], idx, 1);
    s[idx-1] = c;
}





int main(void){
    ll n; cin >> n;
    cin >> s;
    ll q; cin >> q;
    REP(i, n){
        add(bits[s[i] - 'a'], i+1, 1);
    }
    dump(s)
    REP(_, q){
        ll type; cin >> type;
        if (type == 1){
            ll i; cin >> i;
            char c; cin >> c;
            change(i, c);
        } else {
            ll l; cin >> l;
            ll r; cin >> r;
            cout << cnt(l-1, r) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 110976
s = input()
if s[0] == s[1] and s[2] ==s[3] and s[1] !=s[2]:
  print("Yes")
elif s[0] == s[2] and s[1] ==s[3] and s[1] !=s[2]:
  print("Yes")
elif s[0] == s[3] and s[1] ==s[2] and s[1] !=s[0]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define N 1000005
#define BB(V) V[V.size()-2]
#define ex(V) return printf(V),0
using namespace std;
int a[55];
int main(){
	int n;
	scanf("%d",&n);
	int mn=0,mx=0;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		if(a[mn]>a[i])mn=i;
		if(a[mx]<a[i])mx=i;
	}
	if(a[mn]>=0){
		printf("%d\n",n-1);
		for(int i=1;i<n;i++)printf("%d %d\n",i,i+1);
	}
	else if(a[mx]<=0){
		printf("%d\n",n-1);
		for(int i=n;i>1;i--)printf("%d %d\n",i,i-1);
	}
	else{
		printf("%d\n",2*n-1);
		if(-a[mn]>a[mx]){
			for(int i=0;i<n;i++)printf("%d %d\n",mn+1,i+1);
			for(int i=n;i>1;i--)printf("%d %d\n",i,i-1);
		}
		else{
			for(int i=0;i<n;i++)printf("%d %d\n",mx+1,i+1);
			for(int i=1;i<n;i++)printf("%d %d\n",i,i+1);
		}
	}
}

Measured memory_bytes: 256
H, W, M = map(int,input().split())
P = [list(map(int, input().split())) for i in range(M)]
for p in P:
    p[0] -= 1
    p[1] -= 1
cnth = [0]*H
cntw = [0]*W
ans = 0
for p in P:
    cnth[p[0]] += 1
for p in P:
    cntw[p[1]] += 1
mxh = max(cnth)
mxw = max(cntw)
cntx = 0
for p in P:
    if cnth[p[0]] == mxh and cntw[p[1]] == mxw:
        cntx += 1
if cntx == cnth.count(mxh) * cntw.count(mxw):
    ans = mxh + mxw -1
else:
    ans = mxh + mxw
print(ans)

Measured memory_bytes: 130168
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
   
   string S;
   long long K;
   cin >> S >> K;

   int numone = 0,i = 0;
   
   while(i < S.size() && S.at(i) == '1') {
      numone++;
      i++;
   }

   //cout << numone << endl;

   if(numone >= K || i == S.size()) {
      cout << 1 << endl;
   }else {
      cout << S.at(i) << endl;
   }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int M,N,i,p=0,ans=0,t=5;
main(){
  cin>>N>>M;
  int A[M],B[M];
  for(i=0;i<M;i++){
    cin>>A[i]>>B[i];
  }
  sort(A, A+M, greater<>());
  for(i=0;i<M;i++){
    if(p<M-1){
      if(A[i]>=N){
        p++;
      }else{
        ans+=N-A[i];
        p++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}



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


int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll r = a+b;
    ll s = n/r;
    ll t = n%r;
    ll ans = s*a + min(t,a);
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    string ans;
    rep(i, n) {
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 27 23:49:29 2019

@author: yuta
"""

NY = list(map(int,input().split()))

def main(ny):
    n = ny[0]
    y = ny[1]
    memory = [0]*3
    count = 0
    max_count = (n+1)**2
    if y != 0:
        for i in range(n+1):
            for j in range(n+1):
                    price = 10000*i + 5000*j + 1000*(n-i-j)
                    rest = y - price
                    if rest == 0 and n-i-j >=0:
                        memory = [i,j,(n-i-j)]
                        break
                    else:
                        count += 1
        
        if count == max_count:
            memory = [-1,-1,-1]
        
    else:
        memory = [-1,-1,-1]
        
    for i in range(2):
        print(memory[i],end = " ")
    print(memory[2])
main(NY)
        
    
    

Measured memory_bytes: 3064
#include <cstdio>
#include <cassert>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

typedef long long i64;

struct BIT {

	vector<int> data;
	int size;

	void init(int n)
	{
		size = n;
		data.resize(size + 1);
		fill(data.begin(), data.end(), 0);
	}

	void add(int pos, int x)
	{
		pos += 1;
		while(pos < size + 1) {
			data[pos] += x;
			pos += pos & -pos;
		}
	}

	int sum(int pos)
	{
		pos += 1;
		int s = 0;
		while(pos > 0) {
			s += data[pos];
			pos -= pos & -pos;
		}
		return s;
	}
};

const i64 mod = 998244353;

i64 modpow2(i64 x)
{
	i64 a = 1;
	i64 k = 2;

	for(int i = 0; i < 62; i++) {
		if((x >> i) & 1) {
			a = a * k % mod;
		}
		k = k * k % mod;
	}

	return a;
}

int main()
{
	int n;
	vector<pair<int, int>> ps;
	vector<int> xs, ys;

	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		ps.push_back({x, y});
		xs.push_back(x);
		ys.push_back(y);
	}

	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());

	for(int i = 0; i < n; i++) {
		int ox = ps[i].first, oy = ps[i].second;
		int x = lower_bound(xs.begin(), xs.end(), ox) - xs.begin();
		int y = lower_bound(ys.begin(), ys.end(), oy) - ys.begin();
		ps[i] = {x, y};
	}

	i64 ans = 0;
	BIT bit;

	sort(ps.begin(), ps.end());
	bit.init(n);

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

		int x = ps[i].first;
		int y = ps[i].second;

		int xl = x, xr = n - 1 - x;
		int yl = y, yr = n - 1 - y;
		int xlyl = bit.sum(y);
		int xlyr = i - xlyl;
		int xryl = yl - xlyl;
		int xryr = yr - xlyr;

		assert(xlyl + xlyr == xl);
		assert(xryl + xryr == xr);

		bit.add(y, 1);

		i64 a = 0;

		a += modpow2(n) - 1;
		a -= modpow2(xl) - 1;
		a -= modpow2(xr) - 1;
		a -= modpow2(yl) - 1;
		a -= modpow2(yr) - 1;
		a += modpow2(xlyl) - 1;
		a += modpow2(xlyr) - 1;
		a += modpow2(xryl) - 1;
		a += modpow2(xryr) - 1;
		a += 5 * mod;

		ans = (a + ans) % mod;

		//printf("%d (%d,%d) -> %d + %d + %d + %d, %lld\n", i, x, y, xlyl, xlyr, xryl, xryr, a);
	}

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

	return 0;
}


Measured memory_bytes: 4596
# Tenka1PC C - Align

N = int(input())
A = sorted([int(input()) for _ in range(N)], reverse=True)

mult = []
if N % 2 == 0:
    for i in range(N):
        if 0 <= i <= (N//2 - 1) - 1:
            mult.append(2)
        elif i == N // 2 - 1:
            mult.append(1)
        elif i == N // 2:
            mult.append(-1)
        else:
            mult.append(-2)
    ans = sum([a*m for a, m in zip(A, mult)])
else:
    mult1 = []
    mult2 = []
    for i in range(N):
        if 0 <= i <= (N//2 - 1) - 1:
            mult1.append(2)
        elif i == N // 2 - 1:
            mult1.append(1)
        elif i == N // 2:
            mult1.append(1)
        else:
            mult1.append(-2)
    for i in range(N):
        if 0 <= i <= (N//2 - 1):
            mult2.append(2)
        elif i == N // 2:
            mult2.append(-1)
        elif i == N // 2 + 1:
            mult2.append(-1)
        else:
            mult2.append(-2)
    ans = max(sum([a*m for a, m in zip(A, mult1)]), sum([a*m for a, m in zip(A, mult2)]))
print(ans)

Measured memory_bytes: 12508
#include<iostream>
#include<queue>
 
using namespace std;
 
int number=0;
int quantum=0;
int totaltime=0;
 
struct process {
    string name;
    int time;
};
 
int main(){
    queue<process> que;
    queue<process> ans;
    //input
    cin>>number>>quantum;
    for (int i=0; i<number; i++) {
        process p;
        cin>>p.name;
        cin>>p.time;
        que.push(p);
    }
    //process
    while (!que.empty()) {
        if (que.front().time <= quantum) {
            totaltime += que.front().time;
            process p;
            p.name = que.front().name;
            p.time = totaltime;
            ans.push(p);
            que.pop();
        }
        else{
            totaltime += quantum;
            process p;
            p.name = que.front().name;
            p.time = que.front().time - quantum;
            que.pop();
            que.push(p);
        }
    }
    //output
    while (!ans.empty()) {
        cout<<ans.front().name<<" "<<ans.front().time<<endl;
        ans.pop();
    }
    return 0;
}

Measured memory_bytes: 6124
#include<stdio.h>

int main(void){
    int a,b,c,sum;

    scanf("%d %d %d",&a,&b,&c);
    sum=b+c;

    if((sum-a)>0){
        printf("%d\n",sum-a);
    }else{
        printf("0\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
#define M 1000000007
#define MAX 100005
int A[MAX], tree[4 * MAX];
int power(int x, int p)
{
    if (p == 0)
        return 1;
    int y = power(x, p / 2);
    y *= y;
    y %= M;
    if (p % 2 == 0)
        return y;
    y *= x;
    y %= M;
    return y;
}
void build(int node, int start, int end)
{
    if (start == end)
        //Leaf node will have a single element
        tree[node] = start;
    else
    {
        int mid = (start + end) / 2;
        //Recurse on the left child
        build(2 * node, start, mid);
        //Recurse on the right child
        build(2 * node + 1, mid + 1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2 * node] + tree[2 * node + 1];
    }
}
void update(int node, int start, int end, int idx, int val)
{
    if (start == end)
    {
        //Leaf Node
        A[idx] = val;
        tree[node] += val;
    }
    else
    {
        int mid = (start - end) / 2 + end;
        if (start <= idx && idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update(2 * node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update(2 * node + 1, mid + 1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2 * node] + tree[2 * node + 1];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if (r < start || l > end)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if (l <= start && end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2 * node, start, mid, l, r);
    int p2 = query(2 * node + 1, mid + 1, end, l, r);
    return p1 + p2;
}
void Baap_ko_mat_sikha()
{
    int n;
    cin >> n;
    string s, t, ans;
    cin >> s >> t;
    rep(i, 0, n)
    {
        ans.pb(s[i]);
        ans.pb(t[i]);
    }
    cout << ans << endl;
}

signed main()
{

    rootdada;
    int t;
    t = 1;
    while (t--)
    {
        Baap_ko_mat_sikha();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
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;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
int N;
int p[200100];
vi a,b,c;
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> p[i];
	}
	a.resize(N);
	b.resize(N);
	c.resize(N);
	for(int i=0;i<N;i++){
		c[p[i]-1] = i;
	}	
	a[0] = 1;
	b[0] = c[0]-1;
	for(int i=1;i<N;i++){
		int diff = c[i]-c[i-1];
		if(diff>=0){
			a[i] = a[i-1]+diff+1;
			b[i] = b[i-1]-1;
		}else{
			a[i] = a[i-1]+1;
			b[i] = b[i-1]+diff-1;
		}
	}
	int g = b[N-1];
	for(int i=0;i<N;i++){
		cout << a[i];
		if(i+1<N)cout << ' ';
		else cout << endl;
	}
	for(int i=0;i<N;i++){
		cout << b[i]-g+1;
		if(i+1<N)cout << ' ';
		else cout << endl;
	}
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int v[3];
int main() {
	for (int i = 0; i < 3; ++i) {
		cin >> v[i];
	}
	int odd = 0, even = 0;
	for (int i = 0; i < 3; ++i) {
		if (v[i] % 2 == 0)even++;
		else odd++;
	}
	int ans = 0;
	if (odd == 2) {
		ans++;
		for (int i = 0; i < 3; ++i) {
			if (v[i] % 2 == 1) {
				v[i]++;
			}
		}
	}
	else if (even == 2) {
		ans++;
		for (int i = 0; i < 3; ++i) {
			if (v[i] % 2 == 0) {
				v[i]++;
			}
		}
	}
	int ma = max(v[0], max(v[1], v[2]));
	for (int i = 0; i < 3; ++i) {
		ans += (ma - v[i]) / 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	scanf("%d",&N);

	vector<int> V;
	int tmp;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	int num_query;
	scanf("%d",&num_query);

	int left,right,value;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d %d",&left,&right,&value);

		printf("%d\n",count(V.begin()+left,V.begin()+right,value));
	}

	return 0;
}



Measured memory_bytes: 3240
#include<stdio.h>
#include<stdlib.h>

int main()
{
  char str[20],x[10],y[10],z[10];
  int m,a,b,c,i=0,j=0,l=0;
  
  fgets(str,sizeof(str),stdin);
    
    for(;;){
      if(str[i]==' '){
	break;
      }
      x[i]=str[i];
      i++;
    }

    i++;

    for(;;){
      if(str[i]==' '){
	break;
      }
      y[j]=str[i];
      i++;
      j++;
    }

    for(;;){
      if(str[i]=='\0'){
	break;
      }
      z[l]=str[i+1];
      i++;
      l++;
    }

    a=atoi(x);
    b=atoi(y);
    c=atoi(z);
    j=0;

    if(a<1 || 10000<a || b<1 || 10000<b || c<1 || 10000<c || b<a){
      printf("Error!!\n");
    }else{
      for(i=a;i<=b;i++){
	if(c%i==0){
	  j++;
	}	
      }
      printf("%d\n",j);
    }
    
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;





void _main() {
        int n; cin >> n;
        vector<int> vec(n); cin >> vec;
        int now = 0, ans = 0;
        for (int i = n - 2; i >= 0; i--) {
                if (vec[i] >= vec[i + 1]) now++;
                else now = 0;
                ans = max(ans, now);
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

using namespace std;
string s;

int main() {
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<ull> vul;
typedef vector<pair<ll, ll>> vpl;
typedef pair<ll, ll> pl;
#define For(i, n) for(ll i = 0; i < n; i++)
#define len(n) (ll)(n).size()
#define Sort(a) sort(a.begin(), a.end())
ll dp[100010];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, k;
	cin >> n >> k;
	vl h(n + k);
	For(i, n) {
		cin >> h[i];
		dp[i] = 1e12;
	}
	for (ll i = n; i < n + k; i++) {
		h[i] = 0;
	}
	dp[0] = 0;
	For(i, n) {
		For(j, k) {
			dp[i + 1 + j] = min(dp[i + 1 + j], dp[i] + abs(h[i] - h[i + 1 + j]));
		}
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 4696
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N,C;
int D[39][39];
int clr[509][509];
int pat[3][39];

ll calc(int c1,int c2,int c3){
    ll res=0;
    int cl[]={c1,c2,c3};
    rep(gr,3){
        rep(c,30)if(pat[gr][c]){
            res+=D[c][cl[gr]]*pat[gr][c];
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>C;
    
    rep(i,C)rep(j,C) cin>>D[i][j];
    rep(i,N)rep(j,N) cin>>clr[i][j],clr[i][j]--;
    
    rep(i,N)rep(j,N){
        int gr=(i+j)%3;
        int c=clr[i][j];
        pat[gr][c]++;
    }
    
    ll mi=LLINF;
    rep(i,C){
        rep(j,C){
            if(i==j) continue;
            rep(k,C){
                if(i==k||j==k) continue;
                chmin(mi,calc(i,j,k));
            }
        }
    }
    cout1(mi)
}

Measured memory_bytes: 1280
import math
x, y = map(int, input().split())
MOD = 10**9+7
 
def combination(n, r, mod):
	r = min(r, n-r)
	num = 1
	d = 1
	for i in range(1, r+1):
		num = num * (n+1-i) % mod
		d = d * i % mod
	return num * pow(d, mod-2, mod) % mod
if (x+y)%3 != 0:
	print (0)
	exit()
n = (x+y)/3
yy = (2*x-y)/3
xx = (2*y-x)/3
if yy < 0:
  print (0)
  exit()
if xx < 0:
  print (0)
  exit()
if xx.is_integer() and yy.is_integer():
	print (combination(int(xx+yy),int(xx),MOD))
else:
	print (0)

Measured memory_bytes: 9224
N,H = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
B.append(0)
a = max(A)
B.sort()
ans = 0
while a <= B[-1] and H > 0:
    b = B.pop()
    H -= b
    ans += 1
H = max(0,H)
last = (H+a-1)//a
ans += last
print(ans)


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

int main() { 
    int a, b;
    cin >> a >> b;

    if (a == 1) {
        if (b == 1) {
            cout << "Draw" << endl;
        } else {
            cout << "Alice" << endl;
        }
    } else if (b == 1) {
        if (a == 1) {
            cout << "Draw" << endl;
        } else {
            cout << "Bob" << endl;
        }
    } else {
        if (a < b) {
            cout << "Bob" << endl;
        } else if (a > b) {
            cout << "Alice" << endl;
        } else {
            cout << "Draw" << endl;
        }
    }
}

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

int main(){
  ll x;
  cin>>x;
  for(ll a=0;a<=1000;a++){
    for(ll b=0;b<=1000;b++){
      if(a*a*a*a*a-b*b*b*b*b==x){
	cout<<a<<' '<<b<<endl;
	return 0;
      }
      if(a*a*a*a*a+b*b*b*b*b==x){
	cout<<a<<' '<<-b<<endl;
	return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;

        int count = 0;
        auto process = [](int n) {
            auto s = to_string(n);
            if (s.size() == 1) {
                return n;
            }
            int max_ = 0;
            for (int j = 0; j < s.size() - 1; ++j) {
                auto l = stoi(s.substr(0, j + 1));
                auto r = stoi(s.substr(j + 1));
                max_ = max(max_, l * r);
            }
            return max_;
        };
        while (true) {
            if (0 <= n && n <= 9) {
                break;
            }
            n = process(n);
            count += 1;
        }
        cout << count << endl;
    }
}


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

int main(void) {

    string S; cin >> S;
    string cmp = "CODEFESTIVAL2016";
    int cnt = 0;
    for (int i = 0; i < 16; i++) {
        if (S[i] != cmp[i]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<double,double> pd;

const double eps=1e-8;
int main()
{
    int n;
    cin >>n;

    vector<pd> p(n);
    rep(i,n) scanf(" %lf %lf", &p[i].fi, &p[i].se);

    if(n%2==1)
    {
        printf("NA\n");
        return 0;
    }

    //gravity point
    pd g=pd(0,0);
    rep(i,n)
    {
        g.fi+=p[i].fi;
        g.se+=p[i].se;
    }
    g.fi/=n;
    g.se/=n;

    bool valid=true;
    rep(i,n/2)
    {
        pd v1=pd(p[i].fi-g.fi,p[i].se-g.se);
        pd v2=pd(p[i+n/2].fi-g.fi,p[i+n/2].se-g.se);

        if(fabs(v1.fi+v2.fi)>=eps || fabs(v1.se+v2.se)>=eps)
        {
            valid=false;
            break;
        }
    }

    if(valid) printf("%lf %lf\n",g.fi,g.se);
    else printf("NA\n");

    return 0;
}

Measured memory_bytes: 3232
#include<iostream>
    using namespace std;
    int find(int c)
    {
      int sum=0;
      while(true){
        if(c!=0){sum+=c%10;c/=10;}
        else break;
      }
      return sum;
    }
    int main(){
      int N,a,b,sum;
      int total=0;
      cin>>N>>a>>b;
      for(int i=1;i<N+1;i++){
        sum=find(i);
        if(a<=sum&&sum<=b)total+=i;
      }
      cout<<total<<endl;
    }

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define FORd(i,a,b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define print(x) cout << x << newl;
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 

const int MXN = 2e5 + 5;
//const int MXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;

int N, dp[MXN], h[MXN];


int main(){ FAST
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

    cin >> N;
    F0R(i,N) cin >> h[i+1];
    dp[2] = abs(h[2]-h[1]);
    FOR(i,3,N+1){
        dp[i] = INF;
        dp[i] = min(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
        dp[i] = min(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[N] << newl;






	return 0;
}


Measured memory_bytes: 1024
import collections

def main():
    n = int(input())
    l = list(map(int, input().split()))
    
    if n<3:
        print(0)
        return
    
    leng = n
    ans = 0
    for i in range(leng-2):
        a = l[i]
        for j in range(i+1, leng-1):
            b = l[j]
            if a==b:
                continue
            
            for j in range(j+1, leng):
                c = l[j]
                if c==a or c==b:
                    continue
                
                if a<b+c:
                    if b<c+a:
                        if c<a+b:
                            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define t int t; cin>>t; while(t--)
#define clear(a,x) memset(a,x,sizeof(a))
#define boost ios_base::sync_with_stdio(false)
#define show(a) for(int bm=0;bm<a.size();bm++)cout<<a[bm]<<" ";
#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sc5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define pr1(x) printf("%d\n",x)
#define pr2(x,y) printf("%d %d\n",x,y)
#define pr3(x,y,z) printf("%d %d %d\n",x,y,z)
#define pr4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define pr5(a,b,c,d,e) printf("%d %d %d %d %d\n",a,b,c,d,e)
#define scl(x) scanf("%lld",&x)
#define prl(x) printf("%lld\n",x)
#define u(i,a,b) for(i=a;i<b;i++)
#define d(i,a,b) for(i=a;i>b;i--)
#define all(x) x.begin(),x.end() 
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp(x,y) make_pair(x,y) 
#define ff first
#define ss second
#define mod 1000000007
int func(int n)
{
    int c=0;
    while((n%2)==0)
    {
        n/=2;
        c++;
    }
    return c;
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    int m[3];
    clear(m,0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        int p=func(a[i]);
        if(p>=2)
            m[2]++; 
        else
            m[p]++;
    }
    if(!m[2] && m[0])
    {
        cout<<"No";
        return 0;
    }
    if(m[0])
    {
        if(m[1])
        {
            if(m[0]>m[2])
            {
                cout<<"No";
                    return 0;
            }
        }
        else
        {
            if(m[0]>m[2]+1)
            {
                cout<<"No";
                    return 0;
            }
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AGC008
{
    public class B
    {
        private void Run()
        {
            var input = Console.ReadLine().Trim().Split();
            var N = int.Parse(input[0]);
            var K = int.Parse(input[1]);
            var A = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();

            long left = 0;
            long right = A.Skip(K).Where(x => x > 0).Sum();
            long mid = A.Take(K).Sum();

            long res = left + Math.Max(mid, 0) + right;

            for (int i = 0; i < A.Length - K; i++)
            {
                if (A[i] > 0) { left += A[i]; }
                mid -= A[i];
                mid += A[i + K];
                if (A[i + K] > 0) { right -= A[i + K]; }

                res = Math.Max(res, left + Math.Max(mid, 0) + right);
            }

            Console.WriteLine(res);
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new B().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 19408
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	ll ret = 1;
	rep2(i, 1, n + 1) {
		ret = (i * ret) % MOD;
	}
	cout << ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
    string s;
    int A=99999,Z=0;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A'&&A>i){
            A=i;
        }else if(s[i]=='Z'&&i>Z){
            Z=i;
        }
    }
    cout <<Z-A+1<<endl;
}

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

typedef long long lint;

lint agl[15];
int r,D;

int main(){
	scanf("%d%d%d",&r,&D,&agl[0]);
	for(int i=1;i<=10;i++){
		agl[i]=agl[i-1]*r-D;
	}
	for(int i=1;i<=10;i++) 	printf("%lld\n",agl[i]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,a[3];
string s[100001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>a[0]>>a[1]>>a[2];
	rep(i,n){
		cin>>s[i];
	}
	
	int d=0;
	if(a[0]==0)
	d++;
	if(a[1]==0)
	d++;
	if(a[2]==0)
	d++;
	if(d>2){
		cout<<"No";
		re 0;
	}
	vi ans;
	rep(i,n){
		int n1=s[i][0]-'A',n2=s[i][1]-'A';
		if(a[n1]==0&&a[n2]==0){
			cout<<"No";
			re 0;
		}
		if(a[n1]==a[n2]){
			if(a[n1]==1&&i<n-1){
				if(s[i+1][0]==(char)(n1+'A')||s[i+1][1]==(char)(n1+'A')){
					a[n1]++;
					a[n2]--;
					ans.pb(n1);
				}else{
					a[n1]--;
					a[n2]++;
					ans.pb(n2);
				}
			}else{
				a[n1]++;
				a[n2]--;
				ans.pb(n1);
			}
		}else{
			if(a[n1]>a[n2]){
				a[n1]--;
				a[n2]++;
				ans.pb(n2);
			}else{
				a[n2]--;
				a[n1]++;
				ans.pb(n1);
			}
		}
	}
	cout<<"Yes\n";
	rep(i,sz(ans)){
		cout<<(char)('A'+ans[i])<<"\n";
	}
	re 0;
}


Measured memory_bytes: 7092
#include <bits/stdc++.h>
using namespace std;
bool u[1111];
int main() {
  int n,m,i;string s;
  cin>>n>>s>>m;
  for(i=0;i<n;i++)if(s[i]=='0'&&m)s[i]='1',u[i]=1,m--;
  for(i=n-1;i>=0;i--)if(s[i]=='1'&&m&&!u[i])s[i]='0',m--;
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 3208