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

const int MOD = 1000000007, inv2 = 500000004; 
namespace Modulo {
    int qpow(int x, int b) {int res = 1;while (b) {if (b & 1) res = 1LL * res * x % MOD;x = 1ll * x * x % MOD;b >>= 1;}return res; }
    int inv(int x) {int b = MOD - 2, res = 1;while (b) {if (b & 1) res = 1LL * res * x % MOD;x = 1ll * x * x % MOD;b >>= 1;}return res; }
    int add(int a, int b) {a += b;if (a >= MOD) a -= MOD;return a; }
    int mns(int a, int b) {a += MOD;a -= b;while (a >= MOD) a -= MOD;return a; }
    int mul(int a, int b) {return 1ll * a * b % MOD;}
    int divi(int a, int b) {if (b == 2) return 1ll * a * inv2 % MOD; return 1ll * a * inv(b) % MOD;}
}
using namespace Modulo;

const int N = 3005; 
int n, q, a[N];
int prob[N][N], prob1[N][N];



int main() {
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++) scanf ("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++)
            prob[j][i] = (a[j] > a[i]);
    }
    int q1 = q; 
    while (q--) {
        int x, y;
        scanf ("%d%d", &x, &y);
        if (x == y) continue;
        for (int i = 1; i <= n; i++) {
            if (i != x && i != y) {
                prob1[x][i] = divi(add(prob[x][i], prob[y][i]), 2);
                prob1[i][x] = divi(add(prob[i][x], prob[i][y]), 2);
                prob1[y][i] = prob1[x][i]; prob1[i][y] = prob1[i][x]; 
            } 
        }

        prob1[x][y] = prob1[y][x] = divi(add(prob[x][y], prob[y][x]), 2);
        for (int i = 1; i <= n; i++) {
            prob[x][i] = prob1[x][i];
            prob[y][i] = prob1[y][i];
            prob[i][x] = prob1[i][x];
            prob[i][y] = prob1[i][y]; 
        }
    }
    int ans = 0; 
    for (int i = 1; i <= n; i++)
        for (int j = 1; j < i; j++)
            ans = add(ans, prob[j][i]);
    cout << 1LL * ans * qpow(2, q1) % MOD << endl; 
    return 0; 
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
long long k,n,a[200003],sum[200004],ans,k1,k2,ans1,ans2,rsum[200004];
int main(){std::ios::sync_with_stdio(false);
cin>>n;sum[1]=0;
for(int i=1;i<=n;i++)
{
	cin>>a[i];
	a[i]-=i;
}
sort(a+1,a+n+1);
//cout<<a[1]<<endl;
for(int i=2;i<=n;i++)
{
//	cout<<a[i]<<endl;
	sum[i]+=abs(abs(a[i]-a[i-1])*(i-1)+sum[i-1]);
}rsum[n]=0;
for(int i=n-1;i>=1;i--)
{
	rsum[i]+=abs(abs(a[i]-a[i+1])*(n-i)+rsum[i+1]);
}
ans=lmx;
for(int i=1;i<=n;i++)
{
//	cout<<i<<" "<<sum[i]<<" "<<rsum[i]<<endl;
	ans=min(ans,rsum[i]+sum[i]);
}
cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





Measured memory_bytes: 4992
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	cout<<pow(n,3)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

ll A[200009];
ll F[200009];

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

	ll N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> F[i];
	sort(A, A + N);
	sort(F, F + N, greater<ll>());

	ll left = -1LL; ll right = 10000000000000LL;
	while (left + 1 != right) {
		ll mid = (left + right) / 2;
		ll tmpk = K;
		bool flag = true;
		for (int i = 0; i < N && flag; i++) {
			ll num = A[i] * F[i];
			ll d = num - mid;
			if (d > 0) {
				if (d%F[i] == 0) tmpk -= d / F[i];
				else tmpk -= (d / F[i] + 1);
			}
			if (tmpk < 0) flag = false;
		}
		if (flag) right = mid;
		else left = mid;
	}
	cout << right << endl;
	return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> A(N + 2);
	A[0] = 0;
	A[N + 1] = 0;
	auto sum = 0ll;
	for (auto i = 1; i <= N; ++i)
	{
		cin >> A[i];
		sum += abs(A[i] - A[i - 1]);
	}
	sum += abs(A[N + 1] - A[N]);

	for (auto i = 1; i <= N; ++i)
	{
		auto temp = sum - abs(A[i] - A[i - 1]);
		temp -= abs(A[i + 1] - A[i]);
		temp += abs(A[i + 1] - A[i - 1]);
		cout << temp << endl;
	}

	return 0;
}


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

int main(int argc, char const *argv[])
{
	int a, b; cin >> a >> b;
	if (a + b == 15)   printf("+\n");
	else if (a * b == 15) printf("*\n");
	else printf("x\n");
	return 0;
}



Measured memory_bytes: 256
from collections import deque


def read():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    return N, K, A

def sample():
    from random import randint
    N, K = 10**5, 10**4
    A = [randint(-10**9, 10**9) for i in range(N)]
    return N, K, A

def nCk_mod_v2_preprocess(n, p=10**9+7):
    f = [0 for i in range(n+1)]  # n!
    invf = [0 for i in range(n+1)]  # (n!)^-1
    f[0] = 1
    f[1] = 1
    invf[0] = 1
    invf[1] = 1
    for i in range(2, n+1):
        f[i] = f[i-1] * i % p
        invf[i] = pow(f[i], p-2, p)
    return f, invf

def nCk_mod(n, k, f, invf, p=10**9+7):
    if n < k or n < 0 or k < 0:
        return 0
    else:
        return (f[n] * invf[k] % p) * invf[n-k] % p

def solve(N, K, A, MOD=10**9+7):
    A = list(sorted(A, reverse=True))
    qmax = deque()
    qmin = deque()
    f, invf = nCk_mod_v2_preprocess(N, p=MOD)
    for i in range(1, N+1):
        # p = nCr(N-i-1, K-1)
        p = nCk_mod(N-i, K-1, f, invf)
        qmax.append(p * A[i-1] % MOD)
        qmin.append(p * A[N-i] % MOD)
    return (MOD + sum(qmax) - sum(qmin)) % MOD

if __name__ == '__main__':
    inputs = read()
    #inputs = sample()
    print("{}".format(solve(*inputs)))


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

int main(void)
{
  int N = 0;
  int L = 0;
  std::vector<std::string> s;

  std::cin >> N >> L;
  s.resize(N);
  for(int i = 0; i < N; i++){
    std::cin >> s[i];
  }

  std::sort(s.begin(), s.end());

  for(int i = 0; i < s.size(); i++)
    std::cout << s[i];
  std::cout << std::endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    long double pct = 0;
    long double sum = 0;
    for(int i = 1; i <= N; i++){
        int point = i;
        int count = 0;
        while(point < K){
            point *= 2;
            count ++;
        }
        sum += (long double)pow(0.5, count);
    }
    pct = sum / N;

    cout << setprecision(12) << pct << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	cin>>str;
	int ans = 7;
	for(int i=0;i<str.size();++i){
		if(str[i]=='o'){
			++ans;
		}
	}
	cout << ans*100 << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

int main(){
    int n;
    cin>>n;
    int d[n];
    for(int i=0;i<n;i++)cin>>d[i];
    sort(d,d+n);
    
    if(d[n/2]==d[n/2-1])cout<<0<<endl;
    else cout<<d[n/2]-d[n/2-1]<<endl;
    return 0;
}

Measured memory_bytes: 3984
n,x = map(int,input().split())

if n == 2:
    if x == 2:
        print('Yes')
        print('\n'.join(['1','2','3']))
    else:
        print('No')
else:
    if x == 1 or x == 2*n - 1:
        print('No')
    else:
        print('Yes')
        if x == 2:
            ans = list(range(3,2*n-2))
            ans = ans[:n-3] + [2*n - 1,1,2,2*n - 2] + ans[n-3:]
        else:
            ans = list(range(2*n - 1))
            ans = ans[3:x] + ans[x+1:2*n - 1]
            ans = ans[:n-3] + [1,2*n - 1,x,2] + ans[n-3:]
        print('\n'.join(str(i) for i in ans))


Measured memory_bytes: 85256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <string.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;



int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());
	string s;
	int cnt = 0;
	while(true)
	{
		cin >> s;
		if(s == "-")break;
		int n;
		cin >> n;

		REP(i,n)
		{
			int j;
			cin >> j;

			s = s.substr(j, s.size() - j) + s.substr(0, j);
		}

		cout << s << endl;
	}
	
	return 0;
}




Measured memory_bytes: 3152
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<int, pair<int, int>>PP;
typedef long long ll;

int main() {
	int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
	string s; cin >> s;
	bool flag = false;
	for (int i = min(a - 1, b - 1) + 1; i <= max(c - 1, d - 1); i++) {
		if (s[i - 1] == '#' && s[i] == '#') {
			cout << "No" << endl;
			return 0;
		}
	}
	for (int i = max(a - 1, b - 1)-1; i <= min(c - 1, d - 1) - 2 + 1; i++) {
		if (s[i] == '.' && (s[i + 1] == '.' && s[i + 2] == '.')) {
			flag = true;
			break;
		}
	}
	if (a > b && c > d) {
		cout << "Yes" << endl;
	}
	else if (a < b && c < d) {
		cout << "Yes" << endl;
	}
	else {
		if (flag == true) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

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

using namespace std;

const int M = 1e5 + 10;
int n, arr[M], seg[M * 4];

int build(int i, int l, int r) {
    if (l == r)
        seg[i] = arr[l];
    else {
        int mid = (l + r) / 2;
        seg[i] = max(build(i * 2 + 1, l, mid), build(i * 2 + 2, mid + 1, r));
    }
    return seg[i];
}

int modify(int i, int l, int r, int j) {
    if ((l < j && r < j) || (l > j && r > j))
        return seg[i];

    if (l == r)
        seg[i] = arr[l];
    else {
        int mid = (l + r) / 2;

        seg[i] = max(modify(i * 2 + 1, l, mid, j), modify(i * 2 + 2, mid + 1, r, j));
    }
    return seg[i];
}

int mxQ(int i, int L, int R, int l, int r) {
    if (l > R || r < L)
        return 0;

    if (L >= l && R <= r)
        return seg[i];

    int mid = (L + R) / 2;

    return max(mxQ(i * 2 + 1, L, mid, l, r), mxQ(i * 2 + 2, mid + 1, R, l, r));
}

int getN(int x, int l, int r) {
    if (l == n)
        return -1;

    if (l == r)
        return arr[l] > x ? l : -1;

    int mid = (l + r) / 2;

    if (mxQ(0, 0, n - 1, l, mid) > x)
        return getN(x, l, mid);

    if (mxQ(0, 0, n - 1, mid + 1, r) > x)
        return getN(x, mid + 1, r);

    return -1;
}

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

    cin >> n;
    int c = 1, ans[n] = {};

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

    build(0, 0, n - 1);

    for (int i = 0; i < n; i++) {
        if (!ans[i]) {
            int cur = arr[i];

            ans[i] = c;
            arr[i] = -1;
            modify(0, 0, n - 1, i);

            int next = getN(cur, i + 1, n - 1);

            while (next != -1) {
                cur = arr[next];

                ans[next] = c;
                arr[next] = -1;

                modify(0, 0, n - 1, next);

                next = getN(cur, next + 1, n - 1);
            }

            c++;
        }
    }

    cout << *max_element(ans, ans + n) << '\n';

    return 0;
}

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

using namespace std;

int main(){
    int x,n;
    cin >> x >> n;
    vector<int> p(101);
    //1から100まで代入
    for(int i = 1;i <= 100;i++){
        p[i] = i;
    }

    //x以外除く
    int count = 0;
    for(int i = 0;i < n;i++){
        int y;
        cin >> y;
        if(x != y){
        p[y] = -1;
        count++;
        }
    }

    

    //ソート
    sort(p.begin(),p.end());

    

    int ans = 0;

    //xの前後をansに
    for(int i = 0;i <= 100;i++){
        if(p[i] == x){
            if(x - p[i - 1] == p[i + 1] - x){
                ans = p[i - 1];

            }
            else if(x - p[i - 1] < p[i + 1] - x){
                ans = p[i - 1];
            }
            else if(p[x - 1] == -1){
                ans = p[i + 1];
            }
            else if(p[x + 1] < 1 || p[x + 1] > 100){
                ans = p[i - 1];
            
            }
            else{
                ans = p[i + 1];
               
            }

            if((p[i] == x)&&(i == 100)){
                ans = p[i - 1];
            }
        }
    }

    if(count == n){
        ans = x;
    }

    if(abs(101 - x) < abs(x - ans)){
        ans = 101;
    }
   

    cout << ans << endl;
    return 0;
}


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

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

using namespace std;

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

	int ans=n;
	int bcnt=0,wcnt=count(s.begin(),s.end(),'.');
	rep(i,n+1){
		ans=min(ans,bcnt+wcnt);
		if(i<n){
			if(s[i]=='#') bcnt++;
			else          wcnt--;
		}
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
string s; cin>>s;
int minv=1e9;
for(int i=0;i<s.size()-2; i++){
string tmp = "";
tmp += s[i];
tmp += s[i+1];
tmp += s[i+2];
int tmpv = stoi(tmp);
minv = min(minv,abs(753-tmpv));
}
cout<<minv<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007LL;

ll ipow(ll base, ll exp)
{
    ll result = 1LL;
    for (;;)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
    }

    return result;
}

struct DisjointSet {
    vector<int> parent, rank, size;
    DisjointSet(int n) : parent(n), rank(n, 1), size(n, 1) {
        for(int i = 0; i < n; ++i) 
            parent[i] = i;
    }

    int find(int u) {
        if(u == parent[u]) return u;
        return parent[u] = find(parent[u]);
    }

    void merge(int u, int v) {
        u = find(u); v = find(v);
        if(u == v) return;
        if(rank[u] > rank[v]) swap(u, v);
        parent[u] = v;
        if(rank[u] == rank[v]) ++rank[v];
        size[v] += size[u];
    }
};

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;
int x,y,z,k;
vl a;
vl b;
vl c;

int main(void) {
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 
    cout.tie(0);
    //freopen("in.txt", "r", stdin);
    cin >> x >> y >> z >> k;
    a.resize(x);
    b.resize(y);
    c.resize(z);
    rep(i,0,x) {
        cin >> a[i];
    }
    rep(i,0,y) {
        cin >> b[i];
    }
    rep(i,0,z) {
        cin >> c[i];
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());

    priority_queue<pair<ll, vi> > Q;
    vi start = vi(3);
    ll startsum = a[0] + b[0] + c[0];
    Q.push(mp(startsum, start));
    int cnt = 0;
    set<vi> s;
    while(!Q.empty() && cnt < k) {
        ll topsum = Q.top().F;
        vi idx = Q.top().S;
        Q.pop();
        if(s.find(idx) == s.end()) {
            cout << topsum << '\n';
            s.insert(idx);
        } else {
            continue;
        }

        int p = idx[0];
        int q = idx[1];
        int r = idx[2];

        if(p+1 < x) {
            ll nsum = topsum - a[p] + a[p+1];
            vi nidx = idx;
            nidx[0]++;
            Q.push(mp(nsum, nidx));
        }
        if(q+1 < y) {
            ll nsum = topsum - b[q] + b[q+1];
            vi nidx = idx;
            nidx[1]++;
            Q.push(mp(nsum, nidx));
        }
        if(r+1 < z) {
            ll nsum = topsum - c[r] + c[r+1];
            vi nidx = idx;
            nidx[2]++;
            Q.push(mp(nsum, nidx));
        }

        cnt ++;
    }
    return 0;
}


Measured memory_bytes: 1024
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

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

int dig, D[46];

ll dp[50][2][2];

ll f(int d, int cl, int cr){
	int d2 = dig-1-d;
	if(d2 < d) return cl==cr;
	if(d2 == d) return (10*cl-cr == D[d])*10;
	ll &ret = dp[d][cl][cr];
	if(ret!=-1) return ret;
	ret = 0;
	FOR(dl,0,10) FOR(dr,0,10) FOR(ncl,0,2) FOR(ncr,0,2){
		if(dr - cr + 10*ncr - dl == D[d] && dl + 10*cl - ncl - dr == D[d2]){
			if(!d && !dr) continue;
			//debug(dl, dr, ncl, ncr);
			ret += f(d+1, ncl, ncr);
		}
	}
	return ret;
}

int main(){
	int d, mnd=0; scan(d);
	FOR(_,0,49){
		if(d) mnd = _+1;
		D[_] = d%10;
		d/=10;
	}
	ll ans = 0;
	FOR(i,mnd,49){
		ms(dp,-1);
		dig = i;
		ans += f(0,0,0);
	}
	printf("%lld\n", ans);
}

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

using namespace std;
typedef long long ll;
const int N = 1e5+ 10;

void solved()
{
    int k;
    cin >> k;
    queue<ll> q;
    for(int i = 1;i <= 9;i++)q.push(i);

    while(1)
    {
        auto ans = q.front();
        q.pop();
        k--;
        if(!k)
        {
            cout << ans;
            return;
        }
        int t = ans % 10;
        if(t)q.push(ans * 10 + t - 1);
        q.push(ans * 10 + t);
        if(t < 9) q.push(ans * 10 + t + 1);
    }
}


int main()
{
#ifdef ONLINE_JUDGE
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#endif 
    int t = 1;
    solved();
#ifdef LOCAL
    system("pause");
#endif

    return 0;
}

Measured memory_bytes: 1792
while True:
    a, op, b = input().split()

    if '?' == op:
        break

    ans = 0

    if '+' == op:
        ans = int(a) + int(b)
    elif '-' == op:
        ans = int(a) - int(b)
    elif '*' == op:
        ans = int(a) * int(b)
    else:
        ans = int(a) // int(b)

    print(ans)


Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long double ld;
ld dp[20][200010]={};
int main(){
    int n;
    cin >> n;
    vector<ld>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<20;i++){
        for(int j=0;j<=200000;j++){
            dp[i][j] = 100000.0000;
        }
    }
    for(int i=1;i<=200000;i++){
        dp[0][i] = abs(a[0]-(ld)i)/a[0];
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<=200000;j++){
            for(int k=j;k<=200000;k+=j){
                dp[i][k] = min(dp[i][k],max(abs(a[i]-(ld)k)/a[i],dp[i-1][j]));
            }
        }
    }
    ld mi = 100000000.0000;
    for(int i=1;i<=200000;i++){
        mi = min(dp[n-1][i],mi);
    }
    cout << fixed << setprecision(15) <<  mi << endl;
    return 0;
}


Measured memory_bytes: 65760
#include <iostream>

using namespace std;

int main()
{
    string s; cin >> s;

    int ans = 1;
    char now = s[0];
    for (int i = 1; i < s.size(); ++i) {
        if (s[i] == now) continue;
        now = s[i];
        ++ans;
    }

    cout << --ans << endl;

    return 0;
}



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


def next_large_char(char, num):
    char_code = ord(char)
    if char_code + num > 90:
        return chr(char_code + num - ord("Z") + ord("A")-1)
    else:
        return chr(char_code + num)
    

nextS = [0]*len(S)
for i in range(len(S)):
    nextS[i] = next_large_char(S[i], N)

print("".join(nextS))

Measured memory_bytes: 39664
import java.util.*;

public class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] f = new int[10002];
	for (int x=1; x<100; x++) {
	    for (int y=1; y<100; y++) {
		for (int z=1; z<100;z++) {
		    if (x*x + y*y + z*z + x*y + y*z + z*x > 10001) break;
		    f[x*x + y*y + z*z + x*y + y*z + z*x] += 1;
		    
		}	
	    }
	}
	
	for (int i=1;i<=N;i++) {
	    System.out.println(f[i]);
	}
    }
}

Measured memory_bytes: 38852
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  if (x%y != 0) {
    return gcd(y, x % y);
  }
  return y;
}

ll f(ll x, ll y, ll i) {
  return y / i - (x-1) / i;
}

int main() {
  ll A, B, C, D;
  cin >> A >> B>> C >> D;
  ll ans = B-A+1 - (f(A, B, C) + f(A, B, D) - f(A, B, C * D / gcd(C, D)));
  cout << ans << endl;
}


Measured memory_bytes: 256
import itertools

n,m,R = map(int,input().split())
r = list(map(int,input().split()))
data = [[]for _ in range(0,n+1)]
d = [[] for _ in range(0,R)]

for i in range(0,m):
    a,b,c = map(int,input().split())
    data[a].append((b,c))
    data[b].append((a,c))

def dijkstra(start,num):
    g = [float("inf") for _ in range(0,n+1)]
    used = ["false" for _ in range(0,n+1)]
    g[start] = 0
    queue= []
    queue.append((start,data[start]))
    while queue:
        start,edge = queue.pop(0)
        for to,cost in edge:
            if g[to] > g[start] + cost:
                g[to] = g[start] + cost
                queue.append((to,data[to]))
    for i in range(0,R):
        d[num].append(g[r[i]])
    # print(g)
# dijkstra(1,0)

for i in range(0,R):
    dijkstra(r[i],i)
    # print(d[i])
ans = float("inf")
seq = itertools.permutations([i for i in range(0,R)])
for i in seq:
    dis = 0
    for j in range(0,len(i)-1):
        dis += d[i[j]][i[j+1]]
    if ans > dis:
        ans = dis
print(ans)


Measured memory_bytes: 6736
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	int A[210];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int sum = 0;
	while (true) {
		bool oddexist = false;
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 1) oddexist = true;
		}
		if (oddexist) break;
		for (int i = 0; i < N; i++) {
			A[i] /= 2;
		}
		sum++;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#encoding:utf-8 No.0060 2014.12.11
while gets
  cards = $_.chomp.split.map{|item| item.to_i}
  stack = [1,2,3,4,5,6,7,8,9,10] - cards

  under20 = 0
  stack.each do |item|
    if cards[0] + cards[1] + item <= 20
      under20 += 1
    end
  end

  if under20 >= 4
    puts "YES"
  else
    puts "NO"
  end
end

Measured memory_bytes: 6092
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

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

  int r = 0;
  int highest = 0;
  for (int i = 0; i < n; i++) {
    int h;
    scanf("%d", &h);

    if (h >= highest) {
      r += 1;
      highest = h;
    }
  }

  cout << r << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
using namespace std;
int main(){
    long sum[100001],sum1[100001],a[100000],f[50000],l,r,mid,z;
    int n,q,x;
    scanf("%d %d",&n,&q);
    sum[0]=sum1[0]=0;
    for(int i=0;i<n;i++){
        scanf("%ld",&a[i]);
        sum[i+1]=sum[i]+a[i];
        sum1[i+1]=sum1[i];
        if(i%2!=n%2){
            sum1[i+1]+=a[i];
        }
    }
    f[n/2-1]=0;
    for(int i=0;i<n/2;i++){
        x=n-2-2*i;
        if(x==0){

            break;
        }
        l=a[x-1];
        r=a[n-1-i];
        while(l<=r){
            mid=(l+r)/2;
            if(labs(a[n-i-2]-mid)<labs(a[x-1]-mid)){
                r=mid-1;
            }
            else{
                l=mid+1;
            }
        }
        f[i]=l;
    }
    for(int i=0;i<q;i++){
        scanf("%d",&z);
        if(n%2&&z<f[n/2-1]){
            printf("%ld\n",sum[n]-sum[n/2]);
        }
        else{
            l=0;
            r=n/2-1;
            while(l<r){
                mid=(l+r)/2;
                if(f[mid]>z){
                    l=mid+1;
                }
                else{
                    r=mid;
                }
            }
            printf("%ld\n",sum[n]-sum[n-l-1]+sum1[n-(l+1)*2]);
        }

    }
}

Measured memory_bytes: 4480
n, m = map(int, input().split())
ab = []
prod = [0]
prod_cum = [0]

num_cum = [0]
for i in range(n):
    a, b = map(int, input().split())
    ab.append([a,b])


#%%
ab.sort()

for i in range(n):
    a, b = ab[i][0],ab[i][1]
    # prod.append(a*b)
    prod_cum.append(a*b + prod_cum[-1])
    num_cum.append(b + num_cum[-1])
ab = [[0,0]] + ab
# print(ab)
# print(prod)
# print(prod_cum)
# print(num_cum)
# print(n, m, ab)
# n, m, ab = 4, 30, [[6, 18], [2, 5], [3, 10], [7, 9]]


#%%
ans = 0
prod = 0
for i in range(0, n+1):
    if num_cum[i] >= m:
        print(prod_cum[i] - ab[i][0] * (num_cum[i]-m))
        break



#%%
# ans = 0
# num = 0
# while num < m:
#     a0 = ab[0][0]
#     b0 = ab[0][1]
#     if b0 >= m - num:
#         ans += a0 * (m - num)
#         break
#     else:
#         ans += a0 * b0
#         num += b0
#         ab.remove([a0, b0])
#%%
# print(ans)
#%%


Measured memory_bytes: 30292
ans = 100000
n = int(input())

for a in range(1, (n // 2) + 1):
  b = n - a
  sum = 0

  while (a > 0) or (b > 0):
    sum += (a % 10)
    a = a // 10
    sum += (b % 10)
    b = b // 10

  if sum < ans:
    ans = sum

print(ans)

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }

int main(){
	int n ; 
	cin >> n ; 
	vector<ll> a(n+1) , b(n) ; 
	for(int i = 0; i <= n ; i++ )cin >> a[i] ; 
	for(int i = 0 ; i < n ; i++ )cin >> b[i] ; 
	ll ans = 0 ; 
	
	for(int i = 0 ; i < n ; i++ ){
		ll take = min(b[i],a[i]); 
		ans += take ; 
		b[i]-=take ; 
		a[i]-= take ; 
		take = min(b[i],a[i+1]);
		b[i]-=take ; 
		a[i+1]-= take ; 
		ans += take ; 
	}cout << ans << endl; 
}

Measured memory_bytes: 1792
import java.io.InputStream;
import java.io.IOException;

class MyScanner{
    InputStream stream;
    public MyScanner(){
        stream = System.in;
    }
    
    public int nextInt(){
        int ret = 0;
        try{
            while(true){
                char readed = (char)stream.read();
                if(readed < '0' || readed > '9'){
                    break;
                }
                ret = ret * 10 + (readed - '0');
            }
        }catch(IOException e){
            e.printStackTrace();
        }finally{
            return ret;
        }
    }
}

class Main {
    public static void main(String args[]) {
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();
        int[] t = new int[n];
        int sum = 0;
        for(int i = 0; i < n; ++i){
            t[i] = sc.nextInt();
            sum += t[i];
        }
        int m = sc.nextInt();
        for(int i = 0; i < m; ++i){
            int p, x;
            p = sc.nextInt() - 1;
            x = sc.nextInt();
            System.out.println(sum - t[p] + x);
        }
    }
}


Measured memory_bytes: 22612
import java.util.*;
public class Main {
	static long dist[][];
	static long dist2[][];
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int L = sc.nextInt();
		int A[] = new int[M];
		int B[] = new int[M];
		int C[] = new int[M];
		dist = new long[N][N];
		dist2 = new long[N][N];
		for(int i = 0; i < N; i++) {
			Arrays.fill(dist[i], Long.MAX_VALUE / 2);
			Arrays.fill(dist2[i], Long.MAX_VALUE / 2);
		}
		for(int i = 0; i < M; i++) {
			A[i] = sc.nextInt() - 1;
			B[i] = sc.nextInt() - 1;
			C[i] = sc.nextInt();
			dist[A[i]][B[i]] = C[i];
			dist[B[i]][A[i]] = C[i];
		}
		
		WarshallFloyd(N, L);
		WarshallFloyd2(N);
		
		int Q = sc.nextInt();
		int s[] = new int[Q];
		int t[] = new int[Q];
		for(int i = 0; i < Q; i++) {
			s[i] = sc.nextInt() - 1;
			t[i] = sc.nextInt() - 1;
		}
		for(int i = 0; i < Q; i++) {
			System.out.println(dist2[s[i]][t[i]] > Long.MAX_VALUE / 3 ? -1 : dist2[s[i]][t[i]] - 1);
		}
	}
	
	static void WarshallFloyd(int N, int L) {
		for(int k = 0; k < N; k++) {
			for(int i = 0; i < N; i++) {
				for(int j = 0; j < N; j++) {
					dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
					if(dist[i][j] <= L) {
						dist2[i][j] = 1;
					}
				}
			}
		}
	}
	
	static void WarshallFloyd2(int N) {
		for(int k = 0; k < N; k++) {
			for(int i = 0; i < N; i++) {
				for(int j = 0; j < N; j++) {
					dist2[i][j] = Math.min(dist2[i][j], dist2[i][k] + dist2[k][j]);
				}
			}
		}
	}
}


Measured memory_bytes: 95820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 2000001
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main() {
    int n,cnt=0;
    bool flag=true,flag2=true,flag3=true;
    cin>>n;
    vector<int> a(n,0);
    rep(i,n){
        cin>>a[i];
    }
    while(flag3){
        flag=false;
        flag3=false;
        rep(i,n){
            if(a[i]>0){
                a[i]--;
                flag=true;
                flag3=true;
            }else{
                if(flag){
                    cnt++;
                    flag=false;
                }
            }
        }
        if(flag){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}










Measured memory_bytes: 256
/**
 *   @FileName	c.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.01 00:30:51
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

ll f(string s) {
    return (s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
}
int main() {
    ll a;cin >> a;
    string b;cin >> b;
    cout << (a * f(b)) / 100 << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8, pi = acos(-1.0);
bool eq(ld a, ld b){return (abs(b-a)<eps);}
ld dot(Point a, Point b){return real(conj(a)*b);}
ld cross(Point a, Point b){ return imag(conj(a)*b);}

class Line{
public:
  Point a,b;
};

bool Parallel(const Line& l1, const Line& l2){
  return eq(cross(l1.b-l1.a,l2.b-l2.a), 0);
}

bool Orthogonal(const Line& l1, const Line& l2){
  return eq(dot(l1.b-l1.a,l2.b-l2.a), 0);
}

int result(const Line& l1, const Line& l2){
  if(Parallel(l1,l2)){return 2;}
  if(Orthogonal(l1,l2)){return 1;}
  return 0;
}

int main(){
  int q;cin>>q;
  REP(i,q){
    ld real, imag;
    Line s1,s2;
    cin>>real>>imag;
    s1.a = Point(real,imag);
    cin>>real>>imag;
    s1.b = Point(real,imag);
    cin>>real>>imag;
    s2.a = Point(real,imag);
    cin>>real>>imag;
    s2.b = Point(real,imag);
    cout<<result(s1,s2)<<endl;
  }
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   double a[n];
   vector<long double> x;
   for(long int i=0;i<n;i++)
   {
       cin>>a[i];
       x.push_back(a[i]);
   }
   while(x.size()!=1)
   {
       sort(x.begin(),x.end(),greater<long double>());
       x[x.size()-2]=(x[x.size()-1]+x[x.size()-2])/2.0;
       x.pop_back();
   }
   cout<<x[0];
}

Measured memory_bytes: 256
program main
 implicit none
 character*100 s
 integer ans,i,n
 read(*,*) s
 n = len_trim(s)
 ans = 0
 do i=1,n
  if(mod(i,2)==0)then
   if(s(i:i) == 'R') then
    ans = -1
    exit
   end if
  else
   if(s(i:i) == 'L') then
    ans = -1
    exit
   end if
  end if
 end do
 
 if(ans == -1) then
  write(*,*) 'No'
 else
  write(*,*) 'Yes'
 end if
end program main

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int g[15][15];
int main() {
	int N;
	cin >> N;

	rep(i, N) rep(j, N) g[i][j] = -1;

	rep(i, N) {
		int a = 0;
		cin >> a;
		rep(j, a) {
			int x, y;
			cin >> x >> y;
			x--;
			g[i][x] = y;
		}
	}

	int result = 0;
	// i番目の人は正直者と仮定して計算
	// 1 を Nだけ左にシフト => 2^n となる
	rep(i, 1 << N) {
		vector<int> d(N);

		rep(j, N) {
			// i の jビットめが 1 かどうか
			if (i >> j&1) {
				d[j] = 1;
			}
		}

		bool ok = true;
		rep(j, N) {
			if (d[j] == 1) {
				rep(k, N) {
					if(g[j][k] == -1) continue;
					if(g[j][k] != d[k]) ok = false;
				}
			}
		}

		// builtin_popcount ビットの 1の数を返す
		if (ok) result = max(result, __builtin_popcount(i));
	}

	cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
n,k,s = map(int,input().split())

cnt = 0
arr = [s//2]

if s == 10**9:
    arr = []
    for i in range(k):
        arr.append(s)
    for i in range(k,n):
        arr.append(1)
elif s == 1:
    arr = []
    for i in range(k):
        arr.append(1)
    for i in range(k,n):
        arr.append(1000000)

elif k == n:
    arr = [s for i in range(n)]
else:
    for i in range(n-1):
        if cnt < k:
            arr.append(s-arr[-1])
            cnt += 1
        else:
            arr.append(10**9)

ans = ""

for i in range(n-1):
    ans += str(arr[i]) + " "
ans += str(arr[-1])

print(ans)


Measured memory_bytes: 7212
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
// your code goes here
int n,m,k,tmp;
deque<int> lib;
 
void shuffle(){
    deque<int> a,b;
    for(int i=0;i<n;i++){
    a.push_back(lib[i]);
    }
    for(int i=n;i<2*n;i++){
    b.push_back(lib[i]);
    }
    lib.clear();
    for(int i=0;i<n;i++){
        lib.push_back(a.front());
        lib.push_back(b.front());
        a.pop_front();
        b.pop_front();
    }
}
int main() {
    cin >> n >> m;
    for(int i=1;i<=n*2;i++)
    lib.push_back(i);
    for(int i=0;i<m;i++){
        cin >>k;
        if(k==0)
        shuffle();
        else
        for(int j=0;j<lib.size()-k;j++){
            tmp=lib.back();
            lib.pop_back();
            lib.push_front(tmp);
        }
    }
    for(int i=0;i<lib.size();i++)
    cout << lib[i] << endl;
    return 0;
}



Measured memory_bytes: 3132
#include<stdio.h>

void print();

int n,i,j;
int Adj[100][100];

int main() {
  int u,k,v;

  scanf("%d", &n);
  
  for( i = 0 ; i  < n ; i++ ) {
    for( j = 0 ; j < n ; j++ ) {
      Adj[i][j] = 0;
    }
  }
 
  for( i = 0 ;  i < n ; i++ ) {
    scanf("%d%d", &u, &k);
    for( j = 0 ; j < k ; j++ ) {
      scanf("%d", &v);
      Adj[i][v-1] = 1;
    }
    k = 0;
  }

  print();

  return 0;
}

void print() {
  for( i = 0 ; i < n ; i++ ) {
    for( j = 0 ; j < n ; j++ ) {
      printf("%d",Adj[i][j]);
 if(j != n-1)printf(" ");
    }
    printf("\n");
  }
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll ans=0;

        ll ar[n+1];
        for(int i=1;i<=n;i++)
            cin>>ar[i];
        sort(ar+1,ar+n+1);
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                for(int k=j+1;k<=n;k++)
                {
                    if(ar[i]==ar[j] or ar[i]==ar[k] or ar[k]==ar[j])
                        continue;
                    if(ar[i]+ar[j]>ar[k])
                        ans++;
                }
            }
        }

        cout<<ans;
    }

    return 0;
}

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Swap<T>(ref T l, ref T r)
        {
            T t = l; l = r; r = t;
        }

        static void Main(string[] args)
        {
            var length = int.Parse(Console.ReadLine());
            var intArray = Console.ReadLine().Split(' ').Select<string, int>(x => int.Parse(x)).ToArray();
            var swapTimes = 0;
            for (var i = 0; i < length; i++)
            {
                for (var j = length - 1; i < j; j--)
                {
                    if (intArray[j - 1] > intArray[j])
                    {
                        Swap(ref intArray[j - 1], ref intArray[j]);
                        swapTimes++;
                    }
                }
            }
            var stringArray = intArray.Select<int, string>(x => x.ToString()).ToArray();
            Console.WriteLine(String.Join(" ", stringArray));
            Console.WriteLine(swapTimes);
        }
    }
}

Measured memory_bytes: 12112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl //小数をn桁で出力

int main() {
    IN(ll, n);
    IN(ll, k);
    n %= k;
    COUT(min(n, abs(k-n)));
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{ 
 
	public static void main(String[] args) { //Partition babyyyyyyyyy
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		String s = I.next();
		String t = I.next();
		ArrayList<Character> inc = new ArrayList<Character>();
		PriorityQueue<Character> dec = new PriorityQueue<Character>(Collections.reverseOrder());
		for (int i = 0; i < s.length(); i++) inc.add(s.charAt(i));
		for (int i = 0; i < t.length(); i++) dec.add(t.charAt(i));
		ArrayList<Character> inv = new ArrayList<Character>();
		while (!dec.isEmpty()) inv.add(dec.poll());
		Collections.sort(inc);
		boolean ez=false;
		boolean pos = false;
		for (int i = 0; i<Math.min(inv.size(),inc.size()); i++) {
			if (inc.get(i)<inv.get(i)) {
				ez=true;
				pos=true;
				break;
			}else if (inc.get(i)>inv.get(i)) {
				ez=true;
				pos=false;
				break;
			}
		}
		if (!ez) { //Equal prefix case
			if (s.length()<t.length()) pos=true; //If same prefix but shorter length 
			//(i.e abc and abcaaaaaa, abc is lexicographically smaller (similar 
			//to base 10 numbers; Earlier digits/letters hold greater value, but if same,
			//number of digits determines which is larger
		}
		O.pln(pos?"Yes":"No");
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 25676
from itertools import permutations
import math

N = int(input())
X, Y = [0] * N, [0] * N
for i in range(N):
    X[i], Y[i] = map(int, input().split())

dists_sum = 0
for order in permutations(range(N)):
    for i in range(1, N):
        cp, cn = order[i - 1], order[i]
        dists_sum += math.hypot(X[cn] - X[cp], Y[cn] - Y[cp])
print(dists_sum / math.factorial(N))

Measured memory_bytes: 3064