akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

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

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 10000;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };


void solve() {
	ld x; cin >> x;
	x /= 3.0;
	ld ans = x * x*x;
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(7);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	int h, w;
	int d_max=80*80;
	while(scanf("%d%d", &h, &w)==2)
	{
		vvi a(h), b(h), c(h);
		for(int y=0;y<h;y++)
		{
			a[y].resize(w);
			for(int x=0;x<w;x++) scanf("%d", &a[y][x]);
		}
		for(int y=0;y<h;y++)
		{
			b[y].resize(w);
			for(int x=0;x<w;x++) scanf("%d", &b[y][x]);
		}

		for(int y=0;y<h;y++)
		{
			c[y].resize(w);
			for(int x=0;x<w;x++) c[y][x]=abs(a[y][x]-b[y][x]);
		}

		vector<vector<vector<bool> > > dp(h);
		for(int y=0;y<h;y++)
		{
			dp[y].resize(w);
			for(int x=0;x<w;x++)
			{
				dp[y][x].assign(d_max+1, false);
			}
		}

		dp[0][0][c[0][0]]=true;
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				for(int i=0;i<=d_max;i++)
				{
					if(dp[y][x][i]==false) continue;

					if(y+1<h)
					{
						int nbp=i+c[y+1][x];
						int nbn=abs(i-c[y+1][x]);
						dp[y+1][x][nbn]=true;
						if(nbp<=d_max) dp[y+1][x][nbp]=true;
					}
					if(x+1<w)
					{
						int nbp=i+c[y][x+1];
						int nbn=abs(i-c[y][x+1]);
						dp[y][x+1][nbn]=true;
						if(nbp<=d_max) dp[y][x+1][nbp]=true;
					}
				}
			}
		}
		int ans=0;
		for(ans=0;ans<=d_max && dp[h-1][w-1][ans]==false;ans++)
		{
			
		}
if(0)
{
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				printf("%d ", c[y][x]);
			}
			printf("\n");
		}
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				printf(" [");
				for(int i=0;i<=d_max;i++) if(dp[y][x][i]) printf(" %d", i);
				printf(" ]");
			}
			printf("\n");
		}
}
		printf("%d\n", ans);
	}
	return 0;
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void we_r_done(){cout<<"NO"; exit(0);}

void debug(string mssg){cout<<mssg; exit(0);}

using minHeap = priority_queue< int, vector< int >, greater< int > >;

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

    ///FastIO;

    int n;
    scn(n);
    int N = 3*n + 3;
    int a[N] ;
    lli mx[N] , mn[N];

    for(int i=1; i<=3*n; i++)scn(a[i]);

    minHeap mip;
    lli sum = 0;

    for(int i=1; i<=2*n; i++){

        if(mip.size()==n){
            if(mip.top()<a[i]){
                sum -= mip.top();
                sum += a[i];
                mip.pop();
                mip.push(a[i]);
            }
        }
        else{
            mip.push(a[i]);
            sum += a[i];
        }
        mx[i] = sum;
    }
    priority_queue<int>pq;
    sum = 0;

    for(int i=3*n; i>n; i--){

        if(pq.size()==n){
            if(pq.top()>a[i]){
                sum -= pq.top();
                sum += a[i];
                pq.pop();
                pq.push(a[i]);
            }
        }
        else{
            pq.push(a[i]);
            sum += a[i];
        }
        mn[i] = sum;
    }

    lli ans = mx[n]-mn[n+1];

    for(int i=n ;i<=2*n; i++){

        ans = max(ans , mx[i]-mn[i+1]);
       // cout<<mx[i]<<" "<<mn[i+1]<<endl;
    }
    cout<<ans;
    return 0;
    ///return main();
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)

///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 6648
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define lld long long int

int f(int n){
    return n%2 ? 3*n+1 : n/2;
}

int main(){
    int s;
    scanf("%d", &s);
    int* t = (int*)malloc(sizeof(int) * 1000001);
    rep(i, 0, 1000001){
        *(t+i) = 0;
    }
    *(t+s) = 1;
    rep(i, 2, 1000001){
        int x = f(s);
        if(*(t+x)){
            printf("%d", i);
            break;
        }else{
            *(t+x) = 1;
        }
        s = x;
    }

    return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int main() {

	int n, m, a, b;
	int ans = 0, r = 0;
	vector<int> v;
	bool list[100][100] = { false };
	
	cin >> n >> m;

	rep(i, m) {
		cin >> a >> b;
		list[a - 1][b - 1] = true;
		list[b - 1][a - 1] = true;
	}
	rep(i, n) {
		v.push_back(i);
	}

	do {

		rep(i, n - 1) {

			if (list[v[i]][v[i + 1]] == true || list[v[i + 1]][v[i]] == true) {
				r++;
			}
		}

		if (r == n - 1 && v[0] == 0) ans++;

		r = 0;

	} while (next_permutation(v.begin(), v.end()));
	
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d,tmp,e,f;
  cin >> a >> b >> c >> d;
  e = c;
  f = d;
   if(c<d){
    tmp = c;
    c = d;
    d = tmp;
  }
  long long r = c % d;
  while(r!=0){
    c = d;
    d = r;
    r = c % d;
  }
  long long g=e*f/d;
  cout << b-b/e-b/f+b/g-(a-1-(a-1)/e-(a-1)/f+(a-1)/g) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define mkp make_pair
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;

ll ans = 0, n, k;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    cin >> n >> k;
    if(k==0)
    {
        cout << n*n;
        return 0;
    }
    for(ll b=k+1; b<=n; b++)
        ans += b-k + (n-b)/(b)*(b-k) + max(0LL, (n%b+1)-k);
    cout << ans;
}



Measured memory_bytes: 256
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//ここから始めよう

signed main(){
    int n,a,b;cin>>n>>a>>b;
    cout<<min(a,b)<<" "<<max(a+b-n,(int)0);cout<<endl;
}

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

// Abstract Lazy Segment Tree (????±?????±?????????¶?????°???????????¨)
const int SIZE = 1 << 17; // 2^17 = 131072
template<typename T>
struct lazysegtree {
    // ?????????????????????
    T node[2*SIZE], lazy[2*SIZE], I;
    bool need_upd[2*SIZE];

    // ????????¬????????§??? (update, query ??? 2 ???????????????)
    // update function ??????????????????????????¢????????????
    // upd_f(X, Y, l, r) -> ????????? [l, r) ??§???????????????????????? X ??? Y ????????????
    // lazy ???????????? update ??¨??????????????? 1 ??????????????¨?????°?????????
    T (*upd_f)(T, T, int, int), (*qry_f)(T, T);

    // ???????????¨?????????????????????????????¨?????? node ??¨ lazy ??????????????§?????????
    lazysegtree(T (*op1)(T, T, int, int), T (*op2)(T, T), T X) {
        upd_f = op1;
        qry_f = op2;
        I = X;
        fill(lazy, lazy+2*SIZE, I);
        fill(node, node+2*SIZE, I);
        fill(need_upd, need_upd+2*SIZE, false);
    }

    void lazy_eval(int k, int l, int r) {
        if(!need_upd[k]) return;
        node[k] = upd_f(node[k], lazy[k], l, r);
        if(r - l > 1) {
            lazy[2*k+1] = upd_f(lazy[2*k+1], lazy[k], 0, 1);
            lazy[2*k+2] = upd_f(lazy[2*k+2], lazy[k], 0, 1);
            need_upd[2*k+1] = need_upd[2*k+2] = true;
        }
        lazy[k] = I;
        need_upd[k] = false;
    }

    // ???????????? [a, b) ??????????????? val ??????????????????
    // (upd_f ?????¨????????????)
    void update(int a, int b, T val, int l=0, int r=SIZE, int k=0) {
        lazy_eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = upd_f(lazy[k], val, 0, 1);
            need_upd[k] = true;
            lazy_eval(k, l, r);
        }
        else {
            int mid = (l + r) / 2;
            update(a, b, val, l, mid, 2*k+1);
            update(a, b, val, mid, r, 2*k+2);
            node[k] = qry_f(node[2*k+1], node[2*k+2]);
        }
    }

    // ???????????? [a, b) ?????????????????¨???????????????
    // (qry_f ?????¨????????????)
    T query(int a, int b, int l=0, int r=SIZE, int k=0) {
        lazy_eval(k, l, r);
        if(b <= l || r <= a) return I;
        if(a <= l && r <= b) return node[k];
        int mid = (l + r) / 2;
        T vl = query(a, b, l, mid, 2*k+1);
        T vr = query(a, b, mid, r, 2*k+2);
        return qry_f(vl, vr);
    }
};

// [[???????????????]]
// update ??¨??¨ query ??¨?????¢??°??¨????????? (??¢??°????????????????????????????????????????????????) ?????¨???????????£?¨???????
// ??????????????¨???update ??¨?????¢??°??? upd ??§???query ??¨?????¢??°??? fnd ??§??????????????? INT_MAX

typedef long long int ll;
ll upd(ll a, ll b, int l, int r) {return a+b;}
ll fnd(ll a, ll b) {return a+b;}
lazysegtree<ll> seg(upd, fnd, 0);

int main() {
    int N, Q; scanf("%d%d", &N, &Q);
    while(Q--) {
        int c, x, y; scanf("%d%d%d", &c, &x, &y);
        if(c == 0) {
            seg.update(x-1, x, y);
        }
        else {
            printf("%lld\n", seg.query(x-1, y));
        }
    }
    return 0;
}

Measured memory_bytes: 7096
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int x = in.nextInt();

		int c = 0;
		try {

			int h = in.nextInt();
			while(h <= x) {
				h += in.nextInt();
				c++;
			}
		}catch (NoSuchElementException e){
			c++;
		}
		System.out.println(c+1);
	}

}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		Integer p[] = new Integer[A];
		for(int i = 0; i < A; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p, Collections.reverseOrder());
		Integer ans[] = new Integer[X + Y + C];
		for(int i = 0; i < X; i++) {
			ans[i] = p[i];
		}
		Integer q[] = new Integer[B];
		for(int i = 0; i < B; i++) {
			q[i] = sc.nextInt();
		}
		Arrays.sort(q, Collections.reverseOrder());
		for(int i = 0; i < Y; i++) {
			ans[X + i] = q[i];
		}
		int r[] = new int[C];
		for(int i = 0; i < C; i++) {
			r[i] = sc.nextInt();
			ans[X + Y + i] = r[i];
		}
		Arrays.sort(ans, Collections.reverseOrder());
		
		long num = 0;
		for(int i = 0; i < X + Y; i++) {
			num += ans[i];
		}
		System.out.println(num);
	}
}


Measured memory_bytes: 102532
#include<stdio.h>

int main(){
	int n,max,min,i;
	long sum;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	max=a[0];
	for(i=1;i<n;i++){
		if(max<a[i]){
			max=a[i];
		}
	}
	min=a[0];
	for(i=1;i<n;i++){
		if(min>a[i]){
			min=a[i];
		}
	}
	sum=a[0];
	for(i=1;i<n;i++){
		sum=sum+a[i];
	}
	printf("%d %d %ld\n",min,max,sum);
    
return 0;	
}

Measured memory_bytes: 2764
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)



int main(){
	
	int N;
	cin>>N;
	
	vector<int> cnt(1<<N);
	
	for(int i=0;i<(1<<N);i++){
		int a = 0;
		int x = i;
		while(x!=0){
			if((x&1))a++;
			x/=2;
		}
		cnt[i] = a;
	}
	
	vector<int> mask(N);
	int base = (1<<N)-1;
	for(int i=0;i<N;i++){
		mask[i] = base - (1<<i);
	}
	
	
	
	vector<vector<int>> a(N,vector<int>(N));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin>>a[i][j];
		}
	}
	
	vector<vector<int>> dp(N+1,vector<int>(1<<N,0));//dp[i][j] i人目まで,女の状態がj
	dp[0][0] = 1;
	
	for(int i=1;i<=N;i++){
		for(int j=0;j<(1<<N);j++){
			if(cnt[j]!=i)continue;
			for(int k=0;k<N;k++){
				int x = j & mask[k];
				if(x==j)continue;
				if(a[i-1][k]){
					dp[i][j] = mod(dp[i][j] + dp[i-1][x]);
				}
			}
		}
	}
	
	cout<<dp[N][(1<<N)-1]<<endl;
	
	
	return 0;
}


Measured memory_bytes: 196992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char construct[3001][3001]={0};
int dp[3001][3001]={0};
string s,t;
int LCS(int x,int y){
    if(construct[x][y]!='\0'){
            return dp[x][y];
    }
    if((x==0)&&(y==0)){
            dp[x][y]=(int)(s[x]==t[y]);
            construct[x][y]='N';
            return dp[x][y];
            }
    if(x==0){
            if(s[x]!=t[y]){
                    dp[x][y]=LCS(x,y-1);
                    construct[x][y]='U';
                    return dp[x][y];
            }
            dp[x][y]=1;
            construct[x][y]='N';
            return dp[x][y];
    }
    if(y==0){
            if(s[x]!=t[y]){
                    dp[x][y]=LCS(x-1,y);
                    construct[x][y]='L';
                    return dp[x][y];
            }
            dp[x][y]=1;
            construct[x][y]='N';
            return dp[x][y];
    }
    if(s[x]==t[y]){
        dp[x][y]=1+LCS(x-1,y-1);
        construct[x][y]='D';
        return dp[x][y];
    }
    if(LCS(x-1,y)>=LCS(x,y-1)){
        dp[x][y]=LCS(x-1,y);
        construct[x][y]='L';
        return dp[x][y];
    } else{
        dp[x][y]=LCS(x,y-1);
        construct[x][y]='U';
        return dp[x][y];
    }

}
int main(){
    cin>>s>>t;
    string ans="";
    int len;
    len=LCS(s.size()-1,t.size()-1);
    if(len==0){cout<<ans; return 0;}
    int x=s.size()-1;
    int y=t.size()-1;
    while(true){
        if(construct[x][y]=='D'){ans+=s[x];--x;--y;}
        if(construct[x][y]=='L'){--x;}
        if(construct[x][y]=='U'){--y;}
        if(construct[x][y]=='N'){if(s[x]==t[y]){ans+=s[x];} break;}
    }
    string s1="";
    for(int i=ans.size()-1;i>=0;i--){
        s1+=ans[i];
    }
    cout<<s1;
    return 0;

}

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

using namespace std;

const int N = 1000005;

int n, m, q;
int len;
bool res[2][2 * N];
string a[2];
set<int> s[2];

void go(int x, int y) {
	int mn = 1e9;
	auto p0 = s[0].lower_bound(x);
	auto p1 = s[1].lower_bound(x);
	bool t = 0;
	if (p0 != s[0].end()) mn = *p0 - x;
	if (p1 != s[1].end()) {
		if (mn > *p1 - x) {
			t = 1, mn = *p1 - x;
		}
	}
	if (y + mn > q) {
		s[0].insert(x + q - y);
		s[1].insert(x + q - y);
		return;
	}
	s[t ^ 1].insert(x + mn);
	int cur = x + mn;
	while (1) {
		auto p = s[t].find(cur);
		if (p != s[t].end()) {
			s[t].erase(p), cur++;
		}
		else break;
	}
	auto p = s[t ^ 1].find(cur);
	if (p != s[t ^ 1].end()) {
		s[t ^ 1].erase(p);
		go(cur, y + mn);
		return;
	}
	s[t].insert(cur);
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m >> q >> a[0] >> a[1];
	len = max(n, m);
	
	reverse(a[0].begin(), a[0].end());
	reverse(a[1].begin(), a[1].end());
	while (a[0].size() < len) a[0].push_back('0');
	while (a[1].size() < len) a[1].push_back('0');

	for (int i = len - 1; i >= 0; --i) {
		if (a[0][i] == '0' && a[1][i] == '0') continue;
		if (a[0][i] == '0' && a[1][i] == '1') s[1].insert(i);
		if (a[0][i] == '1' && a[1][i] == '0') s[0].insert(i);
		if (a[0][i] == '1' && a[1][i] == '1') go(i, 0);
	}

	for (int i = 0; i < 2; ++i) {
		for (auto j : s[i]) res[i][j] = 1;
		int pos = *(--s[i].end());
		for (int j = pos; j >= 0; --j) cout << res[i][j];
		cout << '\n';
	}
}

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

using namespace std;

int main() { 
	
	//freopen ("in.txt", "r", stdin);
	
	int t;
	scanf ("%d", &t);
	
	long a[t][t];
	
	for (int i=0; i<t; i++) for (int j=0; j<t; j++) scanf ("%ld", &a[i][j]);
	
	long sum = 0;
	bool mark[t][t];
	memset(mark, false, sizeof mark);
	bool impossible = false;
	for (int i=0; i<t; i++) { 
		for (int j=0; j<t; j++) { 
			for (int k=j+1; k<t; k++) { 
				if(a[j][k]==a[j][i]+a[i][k] && i!=j && i!=k) mark[j][k] = true;
				if(a[j][k]>a[j][i]+a[i][k]) { 
					impossible = true;
					break;
				}
			}
		}		
	}
	if(impossible) { printf ("-1\n");  return 0;}
	for (int i=0; i<t; i++) for (int j=i+1; j<t;j++) if(!mark[i][j]) sum+=a[i][j];
	
	
	
		printf ("%ld\n", sum);
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

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

vector<pii> v[10000];
int b[10000];

int main() {
  int n, m;
  while(cin >> n >> m) {
    REP(i,n) v[i].clear();
    int s, t, e;
    while(scanf("%d%d%d", &s, &t, &e), s || t || e) {
      s--;t--;
      v[s].push_back(pii(t,e));
    }
    int L;
    cin >> L;
    REP(_,L) {
      REP(j,m) scanf("%d", b+j);
      REP(i,n) {
        ll ans = 0;
        for (auto p : v[i]) {
          ans += (ll)b[p.first] * p.second;
        }
        printf("%lld%c", ans, i != n-1 ? ' ': '\n');
      }
    }
  }
}

Measured memory_bytes: 2228
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main(){
    string x;
    while(cin >> x){
        if(x == "0") break;
        int sum = 0;
        for(int i = 0; i < x.size(); i++){
            sum += (int)(x[i] - '0');
        }
        cout << sum << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    A[a-1]++,A[b-1]++;
  }
  for(int &i:A)
    if(i%2==1){
      puts("NO");
      return 0;
    }
  puts("YES");
}

Measured memory_bytes: 3756
import sys
import numpy as np
import numba
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

i4 = numba.int32

def get_input():
    D = int(readline())
    C = np.array(readline().split(), np.int32)
    S = np.array([readline().split() for _ in range(D)], np.int32)
    return D, C, S

@njit((i4, i4[:], i4[:, :], i4[:]), cache=True)
def first_computation(D, C, S, T):
    x = 0
    last = np.zeros((26, D), np.int32)
    for d in range(D):
        if d:
            last[:, d] = last[:, d - 1]
        i = T[d]
        x += S[d, i]
        last[i, d] = d + 1
        for i in range(26):
            x -= C[i] * (d + 1 - last[i, d])
    return last, x

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4, i4), cache=True)
def difference_update(D, C, S, T, last_day, d, q):
    p = T[d]
    T[d] = q
    x = S[d, q] - S[d, p]

    i = np.searchsorted(last_day[p], d + 1)
    d_p = last_day[p, i - 1] if i >= 1 else 0
    coef = 0
    for k in range(d, D):
        if last_day[p, k] == d + 1:
            # k 日目に入るスコアの変更
            coef += d_p - d - 1
            last_day[p, k] = d_p
        else:
            break
    x += coef * C[p]

    coef = 0
    for k in range(d, D):
        if last_day[q, k] < d + 1:
            coef += (d + 1 - last_day[q, k])
            last_day[q, k] = d + 1
        else:
            break
    x += coef * C[q]
    return x

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4), cache=True)
def swap_update(D, C, S, T, last_day, d):
    p = T[d]
    q = T[d + 1]
    if p == q:
        return 0
    x = difference_update(D, C, S, T, last_day, d, q)
    x += difference_update(D, C, S, T, last_day, d + 1, p)
    return x

def output(T):
    T += 1
    print(*T, sep='\n')

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :]), cache=True)
def random_update(D, C, S, T, last_days):
    d = np.random.randint(0, D, 1)[0]
    p = T[d]
    xcum = 0
    for q in range(26):
        if p == q:
            continue
        xcum += difference_update(D, C, S, T, last_days, d, q)
        if xcum > 0:
            return q, xcum
    difference_update(D, C, S, T, last_days, d, p)
    return p, 0

@njit((i4, i4[:], i4[:, :], i4[:], i4[:,:]), cache=True)
def main(D, C, S, T, last_days):
    for _ in range(3 * 10**5):
        d = np.random.randint(1, D-1, 1)[0]
        x = swap_update(D,C,S,T,last_days,d)
        if x < 0:
            swap_update(D,C,S,T,last_days,d)
        random_update(D, C, S, T, last_days)[1]
    return T

def first_strategy(D, C, S):
    T = np.empty(D, np.int32)
    for d in range(D):
        T[d] = d % 26
    return T

D, C, S = get_input()

T = first_strategy(D, C, S)
last_days, score = first_computation(D, C, S, T)
T = main(D,C,S,T,last_days)
output(T)


Measured memory_bytes: 108232
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max()

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int n = s.size();
	int ct = 0;
	for(int i=0; i<n; i++) {
		if (s[i] != t[i]) ct++; 
	}
	cout << ct << endl;
}


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

int32_t main()
{
	int n;
	cin>>n;
	double p[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>p[i];
	}
	double dp[n][n+1]={};
	dp[0][0]=1.0-p[0];
	dp[0][1]=p[0];
	for(int i=1; i<n; ++i)
	{
		for(int j=0; j<=i+1; ++j)
		{
			dp[i][j]=dp[i-1][j-1]*p[i] + dp[i-1][j]*(1.0-p[i]);
		}
	}
	double ans=0.0;
	for(int i=n; 2*i>n; --i)
		ans+=dp[n-1][i];
	printf("%.9lf", ans);
}

Measured memory_bytes: 70528
#include <iostream>
using namespace std;
#define MAX 10000

int main(){
    int a, b, c, count = 0;
    
    cin >> a >> b >> c;
    
    for(int i = a; i <= b; i++){
        if((c % i) == 0) count++;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3112
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
x=sum(B)
for i in range(N-1):
    if A[i]+1==A[i+1]:
        x+=C[A[i]-1]
print(x)


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

int A,B;
scanf("%d %d", &A, &B);

if (A!=1&&B!=1){
    printf("1");
}
else if(A!=2&&B!=2){
    printf("2");
}
else if(A!=3&&B!=3){
    printf("3");
}




return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int A, P;
    cin >> A >> P;
    int ans = floor((3*A + P) / 2);
    print(ans);
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
double cal(long long x)
{
    long long sum=0,temp=x;
    while(x)
	{
        sum+=x%10;
        x/=10;
    }
    return (double)temp/sum;
}
int main()
{
	long long num=0,bot=1,temp1,temp2;
    int k;
    scanf("%d",&k);
    while(1)
	{
        while(1)
		{
			temp1=num+bot;
			temp2=num+bot*10;
			if(cal(temp1)<=cal(temp2))break;
            else bot=temp2-num;
        }
        num+=bot;
        printf("%lld\n",num);
        k--;
        if(!k)break;
    }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[] p = new int[n];
		int min = 100;
		List<Integer> xlist = new ArrayList<>();
		List<Integer> ylist = new ArrayList<>();
		List<Integer> zlist = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
			if (p[i] <= a) {
				xlist.add(p[i]);
			} else if (p[i] <= b) {
				ylist.add(p[i]);
			} else {
				zlist.add(p[i]);
			}
		}
		min = Math.min(Math.min(xlist.size(), ylist.size()), zlist.size());
		System.out.println(min);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
#include <complex>
#include <cassert>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define deb(a) cerr<< #a << "= " << (a)<<"\n";

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef complex<double> base;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p;p>>=1){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}

int K,N;
map<int,int> mp;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;

    int i,x;
    for (i=1; i<=N; i++){
        cin >> x;
        mp[x]++;
    }

    vi arr;
    for (auto it : mp)
        arr.pb(it.se);

    sort(all(arr));
    int res=0;
    if (arr.size()>K){
        for (int i=0; i<=arr.size()-K-1; i++)
            res+=arr[i];
    }

    cout << res << "\n";
	return 0;
}


Measured memory_bytes: 10872
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    long plusMax = Long.MIN_VALUE;
    long plusMin = Long.MAX_VALUE;
    long minusMax = Long.MIN_VALUE;
    long minusMin = Long.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      long x = sc.nextLong();
      long y = sc.nextLong();
      plusMax = Math.max(plusMax, x + y);
      plusMin = Math.min(plusMin, x + y);
      minusMax = Math.max(minusMax, x - y);
      minusMin = Math.min(minusMin, x - y);
    }
    System.out.println(Math.max(plusMax - plusMin, minusMax - minusMin));
  }
}

Measured memory_bytes: 53256
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut height: [i64; n],
    }
    let mut result = 0;
    for i in 0..height.len() {
        if i == 0 {
            continue;
        } else {
            let difference = height[i - 1] - height[i];
            if difference > 0 {
                height[i] += difference; // 踏み台の分を身長に加算
                result += difference;
            }
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 5444
N, Q = map(int, input().split())
S = input()
l, r = [0] * Q, [0] * Q
cnt = [0] * len(S)
for i in range(Q):
    l[i], r[i] = map(int, input().split())
    l[i] -= 1
    r[i] -= 1
for i in range(1, len(S)):
    if(i == 0): pass
    cnt[i] = cnt[i - 1]
    if (S[i] == 'C' and S[i - 1] == 'A'):
        cnt[i] += 1
for i in range(Q):
    print(cnt[r[i]] - cnt[l[i]])


Measured memory_bytes: 14256
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace  std ;
typedef long l ;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
long long power(long long k , long long n , long long m=1e9+7)
{
    long long res = 1;
    while(n)
    {
        if(n%2!=0)
        {
            res = (res*k)%m ;
        }
        k = (k*k)%m ;
        n = n/2 ;
    }
    return(res) ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    std::cout.unsetf ( std::ios::floatfield );//this and next line for floating precision upto 6
    std::cout.precision(10);
    ll a,b,c,d,e,x,i,j,n,t,m,k,y;
    double p,q,r,w,u ;
    string str = "",str1 = "" ;
    ll a1,a2,b1,b2 ;
    cin>>a>>b>>c>>k ;
    vll v1,v2,v3 ;
    for(i=0 ; i<a ; i=i+1)
    {
        cin>>d ;
        v1.pb(d) ;
    }
    for(i=0 ; i<b ; i=i+1)
    {
        cin>>d ;
        v2.pb(d) ;
    }
    for(i=0 ; i<c ; i=i+1)
    {
        cin>>d ;
        v3.pb(d) ;
    }
    sort(v1.rbegin(),v1.rend());
    sort(v2.rbegin(),v2.rend());
    sort(v3.rbegin(),v3.rend());
    vll v4 ;
    for(i=0 ; i<a ; i=i+1)
    {
        for(j=0 ; j<b ; j=j+1)
        {
            for(d=0 ; d<c ; d=d+1)
            {
            	v4.pb(v1[i]+v2[j]+v3[d]) ;
            	if((i+1)*(j+1)*(d+1)>k)
            	{
            		break;
				}
			}
        }
    }
    sort(v4.rbegin(),v4.rend()) ;
    for(i=0 ; i<k ; i=i+1)
    {
    	cout<<v4[i]<<"\n" ;
	}
}

Measured memory_bytes: 18676
H,W = map(int, raw_input().split())
a = [map(int, raw_input().split()) for y in range(H)]

ans = []
for y in range(H):
  for x in range(W-1):
    if a[y][x]%2!=0:
      a[y][x+1] += 1
      ans += [(y, x, y, x+1)]
  if y<H-1 and a[y][W-1]%2!=0:
    a[y+1][W-1] += 1
    ans += [(y, W-1, y+1, W-1)]
print len(ans)
for y1,x1,y2,x2 in ans:
  print y1+1, x1+1, y2+1, x2+1


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

int main() {
    vector<vector<int> > A(3, vector<int>(3));
    rep(i, 3){
        rep(j, 3){
            cin >> A.at(i).at(j);
        }
    }
    int N;
    cin >> N;
    vector<int> b(N);
    rep(i, N){
        cin >> b.at(i);
    }

    vector<vector<bool> > B(3, vector<bool>(3));
    rep(i, 3){
        rep(j, 3){
            B.at(i).at(j) = false;
            rep(k, N){
                if(A.at(i).at(j) == b.at(k)){
                    B.at(i).at(j) = true;
                }
            }
        }
    }

    string ans = "No";
    rep(i, 3){
        if (B.at(i).at(0) && B.at(i).at(1) && B.at(i).at(2)){
            ans = "Yes";
        }
    }
    rep(i, 3){
        if (B.at(0).at(i) && B.at(1).at(i) && B.at(2).at(i)){
            ans = "Yes";
        }
    }
    if (B.at(0).at(0) && B.at(1).at(1) && B.at(2).at(2)){
        ans = "Yes";
    }
    if (B.at(0).at(2) && B.at(1).at(1) && B.at(2).at(0)){
        ans = "Yes";
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ACalc {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int a;
        cin >> a;
        cout << a + a * a + a * a * a << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ACalc solver;
    solver.solve(in, out);
    return 0;
}


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

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

  double ans = 0;

  for(int i = 0; i < n; i++){
    double tmp;
    cin >> tmp;

    ans += (1/tmp);
  }

  printf("%.7lf\n", 1/ans);

  return 0;

}


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

int main() {
  int N;
  cin>>N;
  int a,b,c,d;
  a=N/1000;
  b=N/100%10;
  c=N/10%10;
  d=N%10;
  
  if(b==c){
  	if(a==b||c==d){
    	cout<<"Yes"<<endl;
    }else{
    	cout<<"No"<<endl;
    }
  }else{
  	cout<<"No"<<endl;
  }
}

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

int next(int pre,int now,const char&c){
    int res;
    if(!now){
        if(c=='o')res=pre;
        else res=pre^1;
    }
    else {
        if(c=='o')res=pre^1;
        else res=pre;
    }
    return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin>>n>>s;
  rep(i,2)rep(j,2){
      int pre=i;
      int now=j;
      map<int,string> mp;
      mp[0]='S';
      mp[1]='W';
      string ans=mp[i]+mp[j];
      rep(k,n-1){
          pre=next(pre,now,s[k+1]);
          if(k!=n-2)ans+=mp[pre];
          swap(pre,now);
      }
      if(now==i&&next(pre,now,s[0])==j){
          cout<<ans<<endl;
          return 0;
      }
  }
  cout<<-1<<endl;
  return 0;
  }


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

int n,A[100],sw;
int BubbleSort(int A[],int N){
     int sw = 0;
     bool flag = 1;
    for(int i = 0; flag; i++){
         flag = 0;
       for(int j = N-1;j >= i+1;j--){
           if(A[j] < A[j-1]){
             swap(A[j],A[j-1]);
             flag = 1;
             sw++;
           }
       }
    }
  return sw;
}

int main(){
  cin >> n;  
  for(int i = 0;i < n;i++) cin >> A[i];
  
  sw = BubbleSort(A,n);
  
  for(int i = 0;i < n;i++){
     if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  
  return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1<<28;
const int MOD = 1000000007;

int main(){
  int H = 1001, W = 101;
  while(true){
    int n, m, a;  cin >> n >> m >> a;
    if(n+m+a==0)  break;
    vector<vi>  lottery(H, vi(W));
    rep(i, 0, H) rep(j, 0, W) lottery[i][j] = j;

    rep(i, 0, m){
      int h, p, q;  cin >> h >> p >> q;
      if(h+p+q==0)  break;
      lottery[H-h][p] = q;
      lottery[H-h][q] = p;
    }

    rep(i, 0, H){
      a = lottery[i][a];
    }
    cout << a << endl;
  }
  return 0;
}



Measured memory_bytes: 3416
#include <stdio.h>

#define MAXN 200001
#define MOD 1000000007

long long f[MAXN], invf[MAXN];
int H, W, A, B;
long long ans;

long long modpow(long long x, long long y)
{
	long long ret = 1LL;

	while (y)
	{
		if (y & 1LL)
		{
			ret *= x;
			ret %= MOD;
		}
		x *= x;
		x %= MOD;
		y >>= 1LL;
	}

	return ret;
}

long long nCr(int n, int r)
{
	if (r == 0 || r == n) return 1;
	return ((f[n] * invf[n-r] % MOD) * invf[r] % MOD);
}

int main(void)
{
	int i;

	scanf("%d %d %d %d", &H, &W, &A, &B);

	f[0] = 1;
	for (i = 1; i <= H + W; ++i)
	{
		f[i] = f[i-1] * i % MOD;
		invf[i] = modpow(f[i], MOD-2);
	}

	for (i = B + 1; i <= W; ++i)
	{
		ans += nCr(H - A + i - 2, i - 1) * nCr(A + W - i - 1, W - i) % MOD;
	}
	printf("%lld\n", ans % MOD);

	return 0;
}

Measured memory_bytes: 3328
def c_rally():
    N = int(input())
    X = [int(i) for i in input().split()]

    x_sum = sum(X)
    option = (x_sum // N, (x_sum + N - 1) // N)
    return min(sum([(x - p)**2 for x in X]) for p in option)

print(c_rally())

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

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
  int K;
  cin >> K;
  long long ans=0;
  
  int A, B;
  for (int i=1; i<=K; i++){
    for (int j=1; j<=K; j++){
      for (int k=1; k<=K; k++){
        A = gcd(j,k);
        B = gcd(i,A);
        ans += B;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			String q = in.next();
			String[] targets = { "JOI", "IOI" };
			for (String target : targets) {
				int posi = q.lastIndexOf(target);
				int count = 0;
				while (posi >= 0) {
					count++;
					posi = q.lastIndexOf(target, --posi);
				}
				System.out.println(count);
			}
		}
	}
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    int n;
    cin>>n;
    int a[n];
    ffor(i,0,n) cin>>a[i];
    int next=1;
    int cnt=0;
    ffor(i,0,n)
    {
    	if(a[i]==next)
    	{
    		cnt++;
    		next++;
    	}
    }
    if(next==1) cout<<"-1";
    else cout<<n-cnt;
    return 0;
}



Measured memory_bytes: 1024
N = int(input())
A = []
temp1 = map(int, input().split())
temp2 = map(int, input().split())
#A[0] = [int(input()) for i in range(N)]
#A[1] = [int(input()) for i in range(N)]
A.append(list(temp1))
A.append(list(temp2))

dp = [[0 for i in range(N)] for j in range(2)]

dp[0][0] = A[0][0]
dp[1][0] = dp[0][0] + A[1][0]

for j in range(N):
    if j == 0: continue
    dp[0][j] = dp[0][j-1] + A[0][j]

for i in range(N):
    if i == 0: continue
    left = dp[1][i-1] + A[1][i]
    top = dp[0][i] + A[1][i]
    dp[1][i] = max(left, top)

print(dp[1][N-1])

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B)
{
    cout << (A % 2 == 1 && B % 2 == 1 ? YES : NO) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;


public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int n = sc.nextInt();
/*        int[] a = new int[n]
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
*/      
        int x = 0;
        int y = 0;
        long diff = 0;
        x= sc.nextInt();
        for(int i=0; i<n-1; i++){
            y= sc.nextInt();
//            System.out.print(y+" ");
            if(y<x){
                diff = diff+x-y;
            }else if(x<y){
                x=y;
            }
//            System.out.println(x);
        }
            System.out.println(diff);
    }
}

Measured memory_bytes: 59484