akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

const int MOD = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    vector<int> b(m + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    int dp[n + 1][m + 1];
    memset(dp, 0, sizeof dp);
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i == 0 || j == 0) {
                dp[i][j] = 1;
            } else {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD;
                if (a[i] == b[j]) {
                    dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
                }
            }
        }
    }
    cout << dp[n][m] << endl;

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 34912
s=input()
n=len(s)
s1=s[:(n-1)//2]
flag=0
for i in range(len(s1)//2):
    if(s1[i]!=s1[-1-i]):
        flag=1
        break

s1=s[(n+3)//2-1:]
for i in range(len(s1)//2):
    if(s1[i]!=s1[-1-i]):
        flag=1
        break

for i in range(n//2):
    if s[i]!=s[-1-i]:
        flag=1
        break

if flag==1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

const int MAX = 100000;

int main(){
    int n;
    int v[MAX];
 
    cin >> n;
 
    for(int i = 0;i < n;i++){
        cin >> v[i];
    }
 
    int table1[MAX+1] = {0};
    int table2[MAX+1] = {0};
 
    for(int i = 0;i < n;i+=2){
        table1[v[i]]++;
        table2[v[i+1]]++;
    }
 
    int f1 = 0, f2, k1, s1 = 0, s2, k2;
    for(int i = 0;i <= MAX;i++){
        if (table1[i] > f1){
            k1 = i;
            f2 = f1;
            f1 = table1[i];
        } else if (table1[i] > f2){
            f2 = table1[i];
        }
        
        if (table2[i] > s1){
            k2 = i;
            s2 = s1;
            s1 = table2[i];
        } else if (table2[i] > s2){
            s2 = table2[i];
        }
    }

    //cout << k1 << ", " << f1 << ", " << f2 << ", " << k2 << ", " << s1 << ", " << s2 << endl;
    int ans;
    if (k1 == k2){
        if (f1 > s1){
            ans = n - f1 - s2;
        } else if (f1 < s1){
            ans = n - f2 - s1;
        } else {
            if (f2 > s2){
                ans = n - f2 - s1;
            } else {
                ans = n - f1 - s2;
            }
        }
    } else {
        ans = n - f1 - s1;
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a[5], min = 9, sum = 0;
	bool b = false;
	for(int i = 0; i < 5; i++){
		cin >> a[i];
		if(a[i] % 10 == 0){
			continue;
		}
		else{
			if(i == 0){
				min = a[i] % 10;
			}
			else if(a[i] % 10 < min){
				min = a[i] % 10;
			}
			b = true;
		}
	}
	if(!b){
		min = 0;
	}
	for(int i = 0; i < 5; i++){
		if(a[i] % 10 == 0){
			sum += a[i];
		}
		else{
			sum += a[i] + 10 - a[i] % 10;
		}
	}
	if(b){
		sum += min - 10;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
while 1:
    n = int(raw_input()); m = int(raw_input());
    if n==0 and m==0: break
    e = [[0 for i in range(501)] for j in range(501)]
    u = [0]*501; ans = 0;
    for i in range(m):
        f,t = map(int, raw_input().split())
        e[f][t] = e[t][f] = 1
    for i in range(2,n+1):
        if e[1][i]==1:
            if u[i]==0: ans+=1
            u[i] = 1
            for j in range(2,n+1):
                if e[i][j]==1 and u[j]==0:
                    ans+=1; u[j] = 1;
    print str(ans)

Measured memory_bytes: 8240
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
const ll mod=1e9+7;
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int n;
ll a[10009];
ll mx[1000006];
ll power(ll aa,ll b)
{
    ll c=1;
    for(;b;b>>=1){
        if(b&1)c=c*aa%mod;
        aa=aa*aa%mod;
    }
    return c%mod;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        ll x=a[i];
        for(ll v=2;v*v<=x;v++){
            if(x%v)continue;
            ll cur=0;
            while(x%v==0){
                cur++;
                x/=v;
            }
            mx[v]=max(mx[v],cur);
        }
        if(x!=1)mx[x]=max(mx[x],1ll);
    }
    ll lcm=1;
    for(ll i=1;i<=1000006;i++)
    {
        if(mx[i]) lcm = (lcm * power(i, mx[i])) % mod;
    }
//    log(lcm);
    
//    for(int i=2;i<=n;i++){
//        ll x=power(a[i]*prelcm,1);
//        ll y=power(__gcd(a[i],prelcm),mod-2);
//        prelcm=x%mod*y%mod;prelcm%=mod;
//    }
    ll sum=0;
    for(int i=1;i<=n;i++){
        sum=(sum+power(lcm,1)%mod*power(a[i],mod-2)%mod)%mod;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 6656
#include<stdio.h>

#define S 100

typedef struct EDGE{
	int cost;
	int node[2];	//always (node[0] <= node[1]).
}Edge;

Edge heap[S*S];	//minimum heap.
int N;	//number of elements in heap.
int n;
int group[S];
int numGroup;	//number of groups. when it is 1, all nodes are connected.
int cost;

void setEdge(Edge *dst, const Edge *src){
	dst->cost = src->cost;
	dst->node[0] = src->node[0];
	dst->node[1] = src->node[1];
}

//e1->cost < e2->cost:-1
//e1->cost == e2->cost:0
//e1->cost > e2->cost:1
int cmpEdge(Edge *e1, Edge *e2){
	return (e1->cost < e2->cost?-1:0) + (e1->cost > e2->cost?1:0);
}

void swapEdge(Edge *e1, Edge *e2){
	int temp;
	temp = e1->cost; e1->cost = e2->cost; e2->cost = temp;
	temp = e1->node[0]; e1->node[0] = e2->node[0]; e2->node[0] = temp;
	temp = e1->node[1]; e1->node[1] = e2->node[1]; e2->node[1] = temp;
	return;
}

void up(int i){
	if( i <= 1 ){ return; }
	if( cmpEdge(&heap[i], &heap[i/2]) == -1 ){
		swapEdge(&heap[i], &heap[i/2]);
		up(i/2);
	}
	return;
}

void down(int i){
	int j;
	if( 2*i > N ){ return; }
	if( cmpEdge(&heap[2*i], &heap[2*i+1]) == -1 ){
		j = 2*i;
	}else{
		j = 2*i+1;
	}
	if( cmpEdge(&heap[i], &heap[j]) == 1 ){
		swapEdge(&heap[i], &heap[j]);
		down(j);
	}
	return;
}

void add(Edge *e){
	N++;
	setEdge(&heap[N], e);
	up(N);
	return;
}

void delete(){
	if( N < 1 ){ return; }
	heap[1] = heap[N];
	N--;
	down(1);
	return;
}

void init(){
	int i;
	N = 0;
	for( i = 0; i < S; i++ ){ group[i] = i; }
	cost = 0;
	return;
}

void input(){
	int i, j;
	Edge e;
	scanf("%d", &n);
	numGroup = n;
	for( i = 0; i < n; i++ ){
		for( j = 0; j < n; j++ ){
			scanf("%d", &e.cost);
			if( i > j ){ continue; }
			if( e.cost < 0 ){ continue; }
			e.node[0] = i;
			e.node[1] = j;
			add(&e);
		}
	}
	return;
}

void printGroup(){
	int i;
	for( i = 0; i < n; i++ ){ printf("%d ", group[i]); }
	printf("\n");
}

//the group number change from en2 to en1.
void changeGroup(int en1, int en2){
	int i;
	for( i = 0; i < n; i++ ){
		if( group[i] == en2 ){ group[i] = en1; }
	}
	//printGroup();
	return;
}

void get(){
	Edge e;
	while( numGroup > 1 && N > 0 ){
		setEdge(&e, &heap[1]);
		delete();
		//printf("%d:%d,%d\n", e.cost, e.node[0], e.node[1]);
		if( group[e.node[0]] == group[e.node[1]] ){ continue; }
		//printf("select\n");
		cost += e.cost;
		changeGroup(group[e.node[0]], group[e.node[1]]);
	}
}

void print(){
	printf("%d\n", cost);
	return;
}

int main(){
	init();
	input();
	get();
	print();
	return 0;
}

Measured memory_bytes: 644
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void){

    int i,j;
    int n;
    int a[100000],b[100000],temp;
    int max,min,min_i;
    scanf("%d",&n);

    for(i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        
    if(n == 2){
        if(a[0] > a[1]){
            printf("%d %d\n",a[0],a[1]);
        }else{
            printf("%d %d\n",a[1],a[0]);
        }
    }else{
        max = a[0];
        for(i=0;i<n;i++){
            if(a[i] > max )max = a[i];
        }
        
        for(i=0;i<n;i++){
        if (a[i] > max -a[i]){
            b[i] = a[i];
        }else{
            b[i] = max -a[i];
        }
        }
        min = b[0];
        for(i = 0;i < n; i++){
            if(b[i] < min){
                min = b[i];
                min_i = i;
            }
        }

         printf("%d %d\n",max,a[min_i]);
    }
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main()
{
    string a;
    char s =',';
        cin >> a;
    for(int i=0; i <a.size() ; i++)
    {
        if (a.at(i)==s)
        {
            a.at(i)= ' ' ;
        }
    }

    cout << a ;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;


int main() {
	vector<vector<string>>m(100,vector<string>(100));
	rep(i, 0, 50) {
		rep(j, 0, 100) {
			m[i][j] = ".";
			m[99 - i][j] = "#";
		}
	}

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

	int cnt = 0;
	while (cnt < b - 1) {
		m[2*(cnt/ 50)][(2*cnt) % 100] = "#";
		cnt++;
	}

	cnt = 0;
	while (cnt < a - 1) {
		m[99 - 2 * (cnt / 50)][(2 * cnt) % 100] = ".";
		cnt++;
	}

	cout << "100 100" << endl;
	rep(i, 0, 100) {
		rep(j, 0, 100) {
			cout << m[i][j];
		}
		cout << endl;
	}



	return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
using namespace std;

char d[15];
long long f(long long val, long long pre, int len){
    if(d[len+1])
        return f(val+pre*10+d[len]-'0',0,len+1) + f(val,pre*10+d[len]-'0',len+1);
    return val+pre*10+d[len]-'0';
}
int main(){
    scanf("%s",d);
    printf("%lld\n",f(0,0,0));
    return 0;
}


Measured memory_bytes: 128
from collections import Counter

def prime_factorize_fast(n, res=Counter()):
    while n % 2 == 0:
        res[2] += 1
        n //= 2
    while n % 3 == 0:
        res[3] += 1
        n //= 3
    d = 5
    step = 2
    while d <= int(n ** .5):
        while n % d == 0:
            res[d] += 1
            n //= d
        d += step
        step = 6 - step
    if n != 1:
        res[n] += 1
    return res

N, P = map(int, input().split())
cnt = prime_factorize_fast(P)
ans = 1
for f in cnt:
    if cnt[f] >= N:
        ans *= f ** (cnt[f] // N)
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vpp vector<pair<long long,long long>>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define d0(x) cout<<(x)<<" "
#define c1(x) cin>>(x)
#define c2(x,y) cin>>(x)>>(y)
#define c3(x,y,z) cin>>(x)>>(y)>>(z)
#define c4(w,x,y,z) cin>>(w)>>(x)>>(y)>>(z)
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define fo(i,a,b) for(int i=a;i<b;i++)
#define alld(c) (c).rbegin(),(c).rend()
#define alli(c) (c).begin(),(c).end()
#define ll long long
const int M=1e9+7;
const double pyi=3.14159265358979323846;

 
int main()
{
	int n,m;
	sfi(n);sfi(m);
	int arr[m];

	int total=0;

	fo(i,0,m)
	{
		sfi(arr[i]);
		total+=arr[i];
	}

	if(total>n)
		d1(-1);
	else	
	d1(n-total);
	return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std; 
#define ll long long
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
int H, W;
int N;
int sr, sc;
string S, T;
string dis = "LRUD";

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> H >> W >> N;
    cin >> sr >> sc >> S >> T;
    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());

    bool flag = true;
    int l = 1, r = W;
    int u = 1, d = H;

    for(int i = 0; i < N; i++){
        if(T[i] == 'L') r = min(W, r + 1);
        if(T[i] == 'R') l = max(1, l - 1);
        if(T[i] == 'U') d = min(H, d + 1);
        if(T[i] == 'D') u = max(1, u - 1);
        
        if(S[i] == 'L') l++;
        if(S[i] == 'R') r--;
        if(S[i] == 'U') u++;
        if(S[i] == 'D') d--;
        if(r < l || d < u) flag = false;
    }
    if(l > sc || sc > r || u > sr || sr > d) flag = false;

    cout << (flag ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 920
#define ll long long
#define R register
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 2e5 + 5;
int n, m, l, r, dis, fa[maxn], d[maxn], h[maxn];
 
inline int get(int x, int ans = 0)
{
    if(x == fa[x]) return d[x];
    return d[x] + get(fa[x]);
}
 
inline int find(int x)
{
	if(x == fa[x]) return x;
    return find(fa[x]);
}
 
int main()
{
	for (R int i = 0; i < maxn; ++i) fa[i] = i, h[i] = 1;
	scanf("%d%d", &n, &m);
	for (R int i = 1; i <= m; ++i)
	{
		scanf("%d%d%d", &l, &r, &dis);
		int a = find(l), b = find(r);
		if(a != b) 
		{
		    if(h[a] > h[b]) fa[b] = a, d[b] = get(l) - get(r) + dis;
		    else if(h[a] < h[b]) fa[a] = b, d[a] = get(r) - get(l) - dis;
		    else fa[a] = b, d[a] = get(r) - get(l) -dis, ++h[b];
		}
		else if(get(r) - get(l) != dis) 
		    return puts("No"), 0;
	}
	return puts("Yes"), 0;
}

Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

ll h,w,d;
ll a[310][310];
map<ll,P> mp;
map<P,ll> pp;

void solve(){
    rep(i,h){
        rep(j,w){
            mp[a[i][j]]=P((ll)i,(ll)j);
        }
    }
    for(ll i=1;i<=d;i++){
        ll t=1;
        pp[P(i,i)]=0;
        while(i+t*d<=h*w){
            pp[P(i,i+t*d)]=pp[P(i,i+(t-1)*d)]+abs(mp[i+t*d].ft-mp[i+(t-1)*d].ft)+abs(mp[i+t*d].sc-mp[i+(t-1)*d].sc);
            //G[i][i+t*d]=G[i][i+(t-1)*d]+abs(mp[i+t*d].ft-mp[i+(t-1)*d].ft)+abs(mp[i+t*d].sc-mp[i+(t-1)*d].sc);
            t++;
        }
    }
}

signed main(){
    cin>>h>>w>>d;
    rep(i,h){
        rep(j,w) cin>>a[i][j];
    }
    solve();
    int q;
    cin>>q;
    while(q--){
        ll l,r;
        cin>>l>>r;
        ll m;
        if(l%d==0) m=d;
        else m=l%d;
        cout<<pp[P(m,r)]-pp[P(m,l)]<<endl;
    }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	string s; cin >> s;
	char a = 'a';
	string t;
	FOR(i, 0, 26) {
		t += string(1, a + i);
	}
	FOR(i, 0, SZ(t)) {
		if (s.find(t[i]) == string::npos) {
			cout << t[i] << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}


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

int main()
{
    std::string str;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            str = str + std::to_string(i) + "x" + std::to_string(j) + "=" + std::to_string(i * j) + "\n";
        }
    }
    std::cout << str;
    return 0;
}

Measured memory_bytes: 3196
#include<iostream>
using namespace std;
struct po{
  int num;
  char c;
};
int main(){
  int n;
  po a[100],b[100];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i].c>>a[i].num,b[i]=a[i];
  for(int i=0;i<n-1;i++) 
    for(int j=n-1;i<j;j--){
      po tmp=a[j];
      if(a[j-1].num>a[j].num)a[j]=a[j-1],a[j-1]=tmp;
    }  
  for(int i=0;i<n-1;i++){ 
    int mini=i;
    for(int j=i;j<n;j++){
      if(b[j].num<b[mini].num)mini=j;
    }
    po tmp=b[i];
    b[i]=b[mini],b[mini]=tmp;
  }
  bool f=1;

  for(int i=0;i<n-1;i++){
    cout<<a[i].c<<a[i].num<<" ";
    if(a[i].c!=b[i].c)f=0;
}
  cout<<a[n-1].c<<a[n-1].num<<endl;
  cout<<"Stable"<<endl;
  for(int i=0;i<n-1;i++)cout<<b[i].c<<b[i].num<<" ";
  cout<<b[n-1].c<<b[n-1].num<<endl;
  if(f)cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int score = 0;
    rep(i, 0, N-1) {
        if (S[i] == S[i+1]) score++;
    }
    int ans = min(score+2*K, N-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
def main():

    S = input()
    Q = int(input())

    reverse = False
    head = ''
    tail = ''

    for _ in range(Q):
        query= input()
        if query == '1':
            reverse = not reverse
            head, tail = tail, head
        else:
            _, f, c = query.split()
            if f == '1':
#                head = ''.join([head,c])
                head += c
            else:
#                tail = ''.join([tail,c])
                tail += c

    if reverse:
        S = S[::-1]

    print(''.join([head[::-1], S, tail]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 4468
import Data.Array

inputIntList :: IO [Int]
inputIntList = map read . words <$> getLine :: IO[Int]

isGood :: Array Int Int -> Array Int [Int] -> Int -> Bool
isGood hs paths idx = 0 == (length . filter (\x -> hs!idx <= hs!x)) (paths!idx)

main = do
    [n,m] <- inputIntList
    _hs <- inputIntList
    co <- getContents
    let hs = array (1,n) $ zip [1..] _hs
    let paths = accumArray (flip (:)) [] (1,n) $ foldl (\ p (x,y) -> ((x,y):(y,x):p)) [] $ map (\ [a,b] -> (a,b)) $ map (map read) $ map words $ lines co :: Array Int [Int]
    print $ length $ filter (isGood hs paths) [1..n]
    


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

import sys

def make_prime_list(lim):
    lst = [True for i in xrange(lim + 1)]
    prime_list = []
    num = 2
    while num ** 2 <= lim:
        for i in xrange(num * 2, lim + 1, num):
            lst[i] = False
        num += 1
        while not lst[num]:
            num += 1
    return [i for i in xrange(2, lim + 1) if lst[i]]

def solve():
    prime_list = make_prime_list(110000)
    accum = [0 for i in prime_list]
    accum[0] = prime_list[0]
    for i in xrange(1, len(accum)):
        accum[i] = accum[i - 1] + prime_list[i]

    while True:
        n = input()
        if n > 0:
            print accum[n - 1]
        else:
            sys.exit()

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9776
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

string s, ans;

int main() {

	cin >> s;

	for (int i = 0; i < s.size(); ++i)
		if (s[i] == '0')
			ans += '0';
		else if (s[i] == '1')
			ans += '1';
		else if (s[i] == 'B')
			if (ans.size() > 0)
			ans.erase(ans.size() - 1);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
const ll INF = 100000000000000000;

int main(){
    char ans[10];
    string s;
    cin>>s;
    int tmp = 0;
    rep(i,0,9) ans[i] = ' ';
    rep(i,0,s.length()-1){
        if(tmp<0) tmp = 0;
        if(s[i]=='0'){
            ans[tmp] = '0';
            tmp++;
        }
        if(s[i]=='1'){
            ans[tmp] = '1';
            tmp++;
        }
        if(s[i]=='B'){
            ans[tmp-1] = ' ';
            tmp--;

        }
    }
    rep(i,0,9){
        cout<<ans[i];
    }
    cout<<"\n";
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

int main() {
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 != m2) cout << 1 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256
#!/usr/bin/ruby
def dfs(v,d,c)
	$c[v]=c if !$c[v]
	return if $m[v]>=d||d==0
	$m[v]=d
	$h[v].each{|e|dfs(e,d-1,c)}
end
n,m=gets.split.map &:to_i
$c=[nil]*n
$m=[0]*n
$h=Hash.new{|h,k|h[k]=[]}
m.times{
	a,b=gets.split.map &:to_i
	$h[a-1]<<b-1
	$h[b-1]<<a-1
}
gets.to_i.times.map{
	gets.split.map &:to_i
}.reverse_each{|v,d,c|
	dfs(v-1,d,c)
}
puts $c.map{|e|e||0}

Measured memory_bytes: 26492
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int h, w;
    cin >> h >> w;
    array<int, 50> x1s{}, x2s{}, y1s{}, y2s{};
    for (int i = 0; i < 50; ++i) {
        x1s[i] = x2s[i] = y1s[i] = y2s[i] = -1;
    }
    vector<string> v(h);
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        v[i] = s;
        for (int j = 0; j < w; ++j) {
            if(isalpha(s[j])){
                if(!(~x1s[s[j]-'A'])){
                    y1s[s[j]-'A'] = i; x1s[s[j]-'A'] = j;
                }else {
                    y2s[s[j]-'A'] = i; x2s[s[j]-'A'] = j;
                }
            }
        }
    }

    int ok = 1, ans = 0;
    while(ok){
        ok = 0;
        for (int i = 0; i < 26; ++i) {
            if(!(~x1s[i])) continue;
            int x1 = x1s[i], y1 = y1s[i], x2 = x2s[i], y2 = y2s[i];
            if(x1 != x2 && y1 != y2){
                int g = 1, gg = 1;
                for (int j = min(x1, x2); j <= max(x1, x2); ++j) {
                    if(j != x1) g &= (v[y1][j] == '.');
                    if(j != x2) gg &= (v[y2][j] == '.');
                }
                for (int j = min(y1, y2); j <= max(y1, y2); ++j) {
                    if(j != y1) gg &= (v[j][x1] == '.');
                    if(j != y2) g &= (v[j][x2] == '.');
                }
                if(g | gg){
                    ans += 2;
                    ok = 1;
                    x1s[i] = -1;
                    v[y1][x1] = '.', v[y2][x2] = '.';
                }
            }else {
                if(x1 == x2){
                    int g = 1;
                    if(abs(y1-y2) == 1) g = 0;
                    for (int j = min(y1, y2)+1; j <= max(y1, y2)-1; ++j) {
                        g &= (v[j][x1] == '.');
                    }
                    if(g){
                        ans += 2;
                        ok = 1;
                        x1s[i] = -1;
                        v[y1][x1] = '.', v[y2][x2] = '.';
                    }
                }else {
                    int g = 1;
                    if(abs(x1-x2) == 1) g = 0;
                    for (int j = min(x1, x2)+1; j <= max(x1, x2)-1; ++j) {
                        g &= (v[y1][j] == '.');
                    }
                    if(g){
                        ans += 2;
                        ok = 1;
                        x1s[i] = -1;
                        v[y1][x1] = '.', v[y2][x2] = '.';
                    }
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3308
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
using ll =  long long;
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

ll MOD=1e9+7;
int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> a(n);
    for(auto & b : a) cin>>b;
    sort(a.begin(),a.end());
    vector<ll> s(n);
    s[0] = a[0];
    for(int i=1;i<n;++i){
        s[i] = s[i-1] + a[i];
    }
    if(s[n-1] < k){
        cout << n << endl;
        return 0;
    }
    int ret = n;
    ll sum = 0;
    for(int i=n-1;i>=0;--i){
        if(sum + a[i] < k){
            sum += a[i];
        }else ret = min(ret,i); 
    }
    cout << ret << endl;
    return 0;
}



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

int main(void) {
	int N, L;
	std::vector<std::string> S;
	std::cin >> N >> L;
	for(int i = 0; i < N; ++i) {
		std::string s;
		std::cin >> s;
		S.push_back(s);
	}
	std::sort(S.begin(), S.end());
	for(int i = 0; i < N; ++i) {
		std::cout << S[i];
	}
	std::cout << '\n';
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            ans += a[i] * a[j];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll long long;
int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
string s,t;
cin>>s>>t;
int count=0;
for(int i=0;i<s.size();i++){
   if(s[i]!=t[i]){
      count++;
      
   }
}
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 3708
import math
n, k = [int(i) for i in input().split()]
ans = 0
for ni in range(1, n + 1):
    if ni < k:
        ans += 1 / math.pow(2, math.ceil(math.log2(k / ni)))
    else:
        ans += 1
ans /= n
print(ans)


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

#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

struct edge
{
    int to;
    ll length;
};

vector<vector<edge>> tree;
vector<int> ans;

void dfs(int v, int p = -1)
{
    for (int i = 0; i < sz(tree[v]); i++)
    {
        int to = tree[v][i].to;
        int l = tree[v][i].length;
        if (to == p)
        {
            continue;
        }

        if (l % 2 == 0)
        {
            ans[to] = ans[v] % 2;
        }
        else
        {
            ans[to] = (ans[v] + 1) % 2;
        }
        dfs(to, v);
    }
}

int main()
{
    int n;
    cin >> n;
    tree.resize(n);
    ans.resize(n);

    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        tree[a].push_back((edge){b, c});
        tree[b].push_back((edge){a, c});
    }
    ans[0] = 1;
    dfs(0);

    rep(i, n)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 9600
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int n , a , b;
  C3(n,a,b);
  int aa = n*a;
  if(aa < b){
    P(aa);
  }
  else
    P(b);
  ret 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

#define int long long
#define u64 unsigned long long
#define reg register
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)
#define erep(i,G,x) for(reg int i=G.Head[x]; i; i=G.Nxt[i])

inline int Read() {
    int res = 0, f = 1;
    char c;
    while (c = getchar(), c < 48 || c > 57)if (c == '-')f = 0;
    do res = (res << 3) + (res << 1) + (c ^ 48);
    while (c = getchar(), c >= 48 && c <= 57);
    return f ? res : -res;
}

template<class T>inline bool Min(T &a, T const&b) {
    return a > b ? a = b, 1 : 0;
}
template<class T>inline bool Max(T &a, T const&b) {
    return a < b ? a = b, 1 : 0;
}

const int N = 2e5 + 5, M = 9e5 + 5;

int n, m, A[N], vis[N], Ans;

main() {
    n = Read();
    rep(i, 1, n)A[i] = Read(), Ans += A[i];
    if (!Ans) {
        cout << 0;
        return 0;
    }
    int An = 0;
    drep(i, n, 1) {
        int res = 0;
        for (reg int j = i; j <= n; j += i)res += vis[j];
        res %= 2;
        if (res != A[i])vis[i] = 1;
        if (vis[i])An++;
    }
    if (!An)return !puts("-1");
    cout << An << endl;
    rep(i, 1, n)if (vis[i])printf("%d ", i);
    return 0;
}

Measured memory_bytes: 3968
S = input()
count = {}
for s in S:
    if not s in count.keys():
        count[s] = 0
    count[s] += 1
count_sorted = sorted(count.items(),key=lambda x:-x[1])
if count_sorted[0][1] == 2 and count_sorted[1][1] == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n,k;
  cin>>n>>k;
  int l[n];
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  sort(l,l+n,greater<int>());
  int length=0;
  for(int i=0;i<k;i++){
    length+=l[i];
  }
  cout<<length<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    rep(i, n-1){
        int x;
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; i++)cout << a[i] << endl;
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int n,a[100010]={},ans=0;
  cin>>n;
  Fr(i,n) cin>>a[i];
  Fr(i,n-1){
    if(a[i]==i){swap(a[i],a[i+1]);ans++;}
  }
  if(a[n]==n) ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const ll INF = 1e16;

void solver(string s, bool &flg){

    map<char, int> dict;
    for(int i = 0; i != (int)s.size(); ++i){
        ++dict[s.at(i)];
    }

    int dif_ab, dif_bc, dif_ca;
    dif_ab = abs(dict['a'] - dict['b']);
    dif_bc = abs(dict['b'] - dict['c']);
    dif_ca = abs(dict['c'] - dict['a']);

    if( (dif_ab >= 2) || (dif_bc >= 2) || (dif_ca >= 2) ){
        flg = false;
    }
    else{
        flg = true;
    }
}

int main(){

    string s;
    cin >> s;

    bool flg;
    solver(s, flg);

    if(flg) cout << "YES"s << endl;
    else cout << "NO"s << endl;

    return 0; 
}

Measured memory_bytes: 3716
/*/ Author: KaySeeKay /*/

#include<bits/stdc++.h>
using namespace std;	

/*/---------------------------Defines-----------------------------------------/*/

#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)	
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 998244353
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;	
const int INF = 1e18L;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug begins----------------------------------/*/
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    if(n>0)
    s << arr[n - 1] ;
    s<< "]";
    return s.str();
}
#define trace(args...) {__trace_begin(__LINE__); __trace(split(#args, ',').begin(), args);}
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __trace_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __trace_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }
 
template<typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __trace_out_var(a);
    cerr << "; ";
    __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
inline int add(int x, int y, int mod) {
   if (y >= mod) y %= mod;
   if (x >= mod) x %= mod;
   x  += y;
   return (x >= mod ? x - mod : x);
} 
inline int sub(int x, int y, int mod) {
  x -= y;
  if (x + mod <= 0) {
	x %= mod;
  }
  return (x < 0 ? x+mod : x);
}
int dp[N];
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n,m;
		cin >>n >>m;
		vector<pair<int,int>>v(m);
		fm{
			int x,y;
			cin >> v[j].fi >> v[j].se;
		}
		sort(all(v));
		int ans ;
		dp[1]=1;
		dp[2]=MOD-1;
		for(int i=1;i<=n;i++){
			dp[i+1]+=dp[i];
			dp[i]%=MOD;
			fm{
				int l = v[j].fi;
				int r =v[j].se;
				dp[i+l]+=dp[i];
				dp[i+r+1]-=dp[i];
			}
		}
		ans= dp[n];
		cout << ans;
	
	}
	return 0;
}


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

using namespace std;

int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x12=x2-x1;
    int y12=y2-y1;

    cout << x2-y12 << " "
         << y2+x12 << " "
         << x1-y12 << " "
         << y1+x12 << endl;
}

Measured memory_bytes: 256
/*
Author : N_o_o_B
Created : April 22 2020 22:04:54 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    ll a,b,c;
    cin >> a >> b >> c;
    ll k;
    cin >> k;
    ll ans;
    if(k%2){
        ans = b - a;
    }
    else{
        ans = a - b;
    }
    cout << ans << endl;


    time_taken();
    return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  BS.getLine
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let p = compute as
  print p

lim = 10^18

compute :: [Int] -> Integer
compute as = if head as1 == 0 then 0 else loop 1 (reverse as)
  where
    as1 = sort as
    loop x [] = if x > lim then -1 else x
    loop x (a:as) = if xa > lim then -1 else loop xa as
      where
        xa = x * fromIntegral a

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    vi A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
        A[i]-=i+1;
    }
    sort(all(A));
    int b=A[(N-1)/2];
    ll res=0;
    for(int i=0; i<N; i++){
        res+=abs(A[i]-b);
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

int main() {
	int a[3];

	cin >> a[0] >> a[1] >> a[2];

	sort(&a[0], &a[3]);

	cout << a[2] * 10 + a[1] + a[0];

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
#define SEGMAX 131072
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, temp=1, ans=0;

	cin>>n;

	vll a(n), count;

	rep(i, n){
		cin>>a[i];
	}

	repr(i, 1, n){
		if(a[i]==a[i-1]){
			temp++;
		} else{
			count.push_back(temp);
			temp=1;
		}
	}
	count.push_back(temp);

	rep(i, count.size()){
		//cout<<count[i]<<endl;
		ans+=count[i]/2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
const int MAX=200005;
const ll SENTINEL=1ll<<32;
ll n,a[MAX],temp1[MAX/2],temp2[MAX/2];
ll merge(ll s[],int left, int right){
	ll cnt=0;
	int mid=left+(right-left)/2;
	int len1=mid-left,len2=right-mid;
	for(int i=0;i<len1;i++)temp1[i]=s[left+i];
	for(int i=0;i<len2;i++)temp2[i]=s[mid+i];
	int i=0,j=0,k;
	temp1[len1]=temp2[len2]=SENTINEL;
	for(k=left;k<right;k++){
		if(temp1[i]<=temp2[j]){
			s[k]=temp1[i++];
		}else {
			s[k]=temp2[j++];
			cnt+=len1-i;
		}
	}
	return cnt;
}
ll MergeSort(ll s[],int left,int right){
	if(left+1<right){
		int mid=left+(right-left)/2;
		ll cnt=0;
		cnt+=MergeSort(s,left,mid);
		cnt+=MergeSort(s,mid,right);
		cnt+=merge(s,left,right);
		return cnt;
	}
	return 0;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	cout<<MergeSort(a,0,n)<<endl;
	return 0;
}


Measured memory_bytes: 6204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L>R) cout << "Left" << endl;
  else if (L==R) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int val[100];
long long int abs(int a){return a<0?(long long)-a:(long long)a;}
int main(){
	long long int a;
	while(scanf("%lld",&a),a){
		int now=0;
		long long int len=1;
		for(int i=0;a;i++){
			val[now++]=a%(len*(-10))/len;
			if(val[now-1]<0)val[now-1]+=10;
			a-=(val[now-1])*len;
			len*=(-10);
		}
		for(int i=now-1;i>=0;i--)printf("%d",val[i]);
		printf("\n");
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans = 0;
    cin>>n;
    int l[200000], r[200000];
    for(int i = 0; i < n ; i++){
        cin>>l[i];
        cin>>r[i];
        ans += r[i] - l[i] +1;
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


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

  while(1){
  int n, m;
  cin >> n >> m;
  if(n==0 && m==0) break;

  int Taro[n], Hanako[m];

  REP(i, n) cin >> Taro[i];
  REP(i, m) cin >> Hanako[i];

  int tot_Taro=0, tot_Hanako=0;

  REP(i, n) tot_Taro += Taro[i];
  REP(i, m) tot_Hanako += Hanako[i];

  stable_sort(Taro, Taro+n);
  stable_sort(Hanako, Hanako+m);

  int num=-1;
  int dif;
  dif = tot_Hanako-tot_Taro;
  if(dif%2 != 0){
    cout << -1 << endl;
  }else{
    dif=dif/2;
  REP(i, m){
  if(binary_search(Taro, Taro+n, Hanako[i]-dif)){
      num = Hanako[i]-dif;
      cout << num << " "<< num+dif << endl;
      break;
  }
}if(num==-1) cout << -1 << endl;
}

}
  return 0;
}

Measured memory_bytes: 3036
#include <cmath>
#include <vector>
#include <iostream>
#include <limits>
#include <iostream>
#include <vector>
#include <cassert>
#include <complex>
#include <cstdio>
#include <set>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <queue>
#include <bitset>
#include <ctime>
#include <unordered_map>
#include <numeric>
#include <climits>

using namespace std;
typedef long long Long;
typedef long double Double;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef pair<Long,Long> PLL;

int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(Long &x) { return scanf("%lld", &x); }
char buff[1000010];
int read(string &s) { int r = scanf("%s", buff); s = buff; return r; }

#define dlog2(n) (31-__builtin_clz(n))

struct Edge {
	int u, v, cost;
};

int BF(vector<Edge> E, int N) {
	VI T(N, 1000000000);
	T[0] = 0;
	for (int i = 0; i < N; ++i) {
		for (Edge e : E) {
			T[e.v] = min(T[e.u] + e.cost, T[e.v]);
		}
	}
	int ans = T[N-1];
	for (int i = 0; i < N; ++i) {
		for (Edge e : E) {
			T[e.v] = min(T[e.u] + e.cost, T[e.v]);
		}
	}
	if (ans > T[N-1]) return -1;
	return max(-ans, 0);
}

int main() {

	int N, M, P;
	read(N, M, P);
	vector<Edge> E(M);
	for (int i = 0; i < M; ++i) {
		read(E[i].u, E[i].v, E[i].cost);
		E[i].u--; E[i].v--;
		E[i].cost = P - E[i].cost;
	}
	cout << BF(E, N) << endl;

	return 0;
}

/*
3 -> 2 -> 1
3 -> 1 -> 1
2 -> 1 -> 1
1 -> 2 -> 1
1 -> 1 -> 1



*/

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

int main(){
	int n,cnt=0,min=1,j=0;
	cin>>n;
	vector<int> a(n);
	vector<int> b;
	for(int i=0;i<n;i++)
		cin>>a[i];

	for(int i=0;i<n;i++){
		if(a[i]==min){
			min++;
			b.push_back(a[i]);
		}else if(a[i]>min){
			cnt++;
		}else if(a[i]<min){
			cnt++;
		}
	}

	if(b.size()==0&&min-1==0){
		cout<<-1;

	}
	else if(min-1==b.size()){
		cout<<cnt;
	}else{
		cout<<-1;
	}
	
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 20, mod = 1e9 + 7;
int n, m, cnt, e[N], f[1 << N], sz[1 << N], ans;

int main() {
	scanf("%d%d", &n, &m), cnt = (1 << n) - 1, f[0] = 1;
	for(int i = 1, x, y; i <= m; i++) scanf("%d%d", &x, &y), --x, --y, e[x] |= (1 << y);
	for(int i = 1; i <= cnt; i++) sz[i] = sz[i >> 1] + (i & 1);
	for(int i = 0; i <= cnt; i++) sz[i] = 1 << sz[i];
	for(int i = 2; i <= cnt; i++) if((i & 1) == ((i >> 1) & 1)) {
		for(int j = i; j; j = i & (j - 1)) if((j & 1) == ((j >> 1) & 1)) {
			int w = 1, v = (i ^ j);
			for(int k = 0; k < n; k++) if(i & (1 << k)) {
				if(j & (1 << k)) w = (ll)w * sz[e[k] & v] % mod;
				else w = (ll)w * (sz[e[k] & j] - 1) % mod;
			}
			f[i] = (f[i] + (ll)w * f[v] % mod) % mod;
		}
	}
	ans = 1; for(int i = 1; i <= m; i++) ans = (ans + ans) % mod;
	printf("%d\n", (ans + mod - f[cnt]) % mod);
	return 0;
}

Measured memory_bytes: 2432