akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int f(int a){
    if(a%4==2) return a+1;
    if(a%4==1) return 1;
    if(a%4==0) return a;
    return 0;
}

signed main(){
    int A,B;
    cin >> A >> B;
    
    int ans = f(B)^f(A-1);
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;


const int maxn = 8;
vector<int>g[maxn];
int dp[1<<maxn][maxn];
int n,m;
int solve(int msk,int prv){
	if( msk + 1 == 1<< n )return 1;
	int &ans = dp[msk][prv];
	if( ans != -1 )return ans;
	ans = 0;
	for(auto v:g[prv]){
		if( msk >> v & 1 ) continue;
		ans += solve(msk|1<<v,v);
	}
	return ans;
}
int32_t main(){
	IOS
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		--u,--v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	memset(dp,-1,sizeof(dp));
	cout << solve(1<<0,0);
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 3660
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int k[20];
vector<int>s[20];
int p[20];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			s[i].push_back(read());
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	int ans = 0;
	for (int t = 0; t < (1 << n); t++) {
		bool l = true;
		for (int i = 0; i < m; i++) {
			int sum = 0;
			for (int j = 0; j < k[i]; j++) {
				if (t & (1 << (s[i][j]-1))) {
					sum++;
				}
			}
			if (sum % 2 != p[i]) {
				l = 0;
			}
		}
		if (l) {
			ans += l;
		}
	}
	cout << ans << endl;
}

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

int main(){
    ll q,h,s,d,n;
    cin >> q >> h >> s >> d >> n;
    h = min(h,2*q);
    s = min(s,2*h);
    if(2*s<=d){
        cout << s*n << endl;
        
    }else {
        if(n%2==0){
            cout << d*n/2 << endl;
            
        }else{
            cout << d*(n/2)+s << endl;
            
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=998244353;
signed main(){
    int n;
    string s;
    cin>>n>>s;
    cout<<(s.substr(0,n/2)==s.substr(n/2,n/2)&&n%2==0?"Yes":"No")<<endl;
}


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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  string s;
  cin >> s;

  vector<int> dp(1<<26, 1e7);
  dp[0] = 0;
  int hash = 0, n = (int)s.size();

  for (int i = 0; i < n; ++i) {
    hash ^= (1<<(s[i] - 'a'));
    for (int j = 0; j < 26; ++j) {
      dp[hash] = min(dp[hash], 1 + dp[hash ^ (1<<j)]);
    }
  }

  cout << max(1, dp[hash]) << '\n';
}






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

namespace zyt
{
	typedef long long ll;
	const int N = 1e5 + 10;
	int n, a[N], b[N];
	int defeat(int &a, int &b)
	{
		int tmp = min(a, b);
		a -= tmp, b -= tmp;
		return tmp;
	}
	int work()
	{
		scanf("%d", &n);
		for (int i = 1; i <= n + 1; i++)
			scanf("%d", a + i);
		for (int i = 1; i <= n; i++)
			scanf("%d", b + i);
		ll ans = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			ans += defeat(a[i], b[i - 1]);
			ans += defeat(a[i], b[i]);
		}
		printf("%lld", ans);
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 896
#include <stdio.h>

int main(void) {
	
	int w,h,x,y,r;
	int temp;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	
	if((x < 0) || (y < 0)){
		printf("No\n");
		return 0;
	}
	if((w - (x + r) < 0) || ((x - r) < 0)){
		printf("No\n");
		return 0;
	}
	if((h - (y + r) < 0) || ((y - r) < 0)){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const int MAXN = 400*400;

int h,w;
vector<string> s;
vector<vector<int> > ch;

void dfs(int x,int y,bool is_black,int num){
    ch[x][y] = num;
    for(int i = -1; i <= 1; i++){
        if(i!=0 && 0<=x+i && x+i<h){
            if(is_black && ch[x+i][y]<0 &&  s[x+i][y] == '.') dfs(x+i,y,false,num);
            if(!is_black && ch[x+i][y]<0 &&  s[x+i][y] == '#') dfs(x+i,y,true,num);
        }
    }
    for(int i = -1; i <= 1; i++){
        if(i!=0 && 0<=y+i && y+i<w){
            if(is_black && ch[x][y+i]<0 &&  s[x][y+i] == '.') dfs(x,y+i,false,num);
            if(!is_black && ch[x][y+i]<0 &&  s[x][y+i] == '#') dfs(x,y+i,true,num);
        }
    }
}

int main()
{
    cin >> h >> w;
    s.resize(h);
    ch.resize(h);
    for(int i = 0; i < h; i++){
        ch[i].resize(w,-1);
    }
    for(int i = 0; i < h; i++){
        cin >> s[i];
    }

    int num = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(ch[i][j]<0 && s[i][j] == '#'){
                dfs(i,j,true,num);
                num++;
            }
        }
    }

    vector<ll> black(MAXN+1),white(MAXN+1);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '.' && ch[i][j]>0) white[ch[i][j]]++;
            if(s[i][j] == '#' && ch[i][j]>0) black[ch[i][j]]++;
        }
    }

    // for(int i = 0; i < h; i++){
    //     for(int j = 0; j < w; j++){
    //         cout << ch[i][j] << " ";
    //     }printf("\n");
    // }

    ll ans = 0;
    for(int i = 1; i <= MAXN; i++){
        ans += white[i]*black[i];
    }
    cout << ans << endl;



    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int sum = 0, hi = 0;
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        sum += p;
        hi = max(hi, p);
    }
    cout << (sum - hi/2) << endl;
    return 0;
}


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

#define DEBUG 0

#define lli unsigned long long int
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;


int main(){
	lli n;
	vector<lli> v;

	lli ans=0;

	cin>>n;

	for(lli i=0;i<n;i++){
		lli tmp;
		cin>>tmp;
		ans += (tmp-1);
	}

	cout<<ans<<endl;

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
LL a[200001];
vector<LL>v;
vector<LL>v2;
int main(){
    cin>>N;
    REP(i,N){
        cin>>a[i];
        if(i%2==0){
           v.push_back(a[i]);
        }else{
           v2.push_back(a[i]);
        }
    }
    reverse(v2.begin(),v2.end());
    v.insert(v.begin(),v2.begin(),v2.end());
    if(N%2==0){
    }else{
       reverse(v.begin(),v.end());
    }
    REP(i,v.size()){
        cout<<v[i];
        if(i!=v.size()-1){
           cout<<" ";
        }else{
           cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6236
N = int(input())
a = list(map(int, input().split()))
num = list(set(a))

if len(num) == 1 and num[0] == 0:
    print('Yes')
elif N % 3 == 0:
    if len(num) == 3:
        s = a.count(num[0])
        t = a.count(num[1])
        u = a.count(num[2])
        if s == t and t == u and u == s and num[0] ^ num[1] == num[2]:
            print('Yes')
        else:
            print('No')
    elif len(num) == 2:
        if a.count(max(num)) == a.count(0) * 2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 60784
#include <iostream>

char a[50][50], b[50][50];

int main() {
	int n, m;
	std::cin >> n >> m;

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			std::cin >> a[i][j];
	for (int i = 0; i < m; ++i)
		for (int j = 0; j < m; ++j)
			std::cin >> b[i][j];
	
	for (int i = 0; i <= n - m; ++i) {
		for (int j = 0; j <= n - m; ++j) {
			bool isMatch = true;

			for (int k = 0; k < m; ++k)
				for (int l = 0; l < m; ++l)
					isMatch &= (a[i + k][j + l] == b[k][l]);

			if (isMatch) {
				std::cout << "Yes" << std::endl;
				return 0;
			}
		}
	}

	std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
	int X, A, B;
	scanf("%d %d %d", &X, &A, &B);

	int min = A < B ? A : B;
	int max = A > B ? A : B;
	printf("%d %d\n", min, max-(X-min) < 0 ? 0 : (max-(X-min)));

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
double s[12];
double to[12];
int b[12];
int h[12];
int f[12];
int a[12];
int p[12];
int t[12];
double v[12];
int sz[12];
double ret[12];
int w[12];
double eps=1e-9;
double nx(double a){
	return (double)((int)(a+1));
}
int y[12];
int main(){
	int T;scanf("%d",&T);
	while(T--){
		int n;scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d%d",b+i,h+i);
		}
		sz[0]=b[0];
		for(int i=1;i<n;i++){
			sz[i]=b[i]-b[i-1];
		}
		sz[n]=100-b[n-1];
		b[n]=100;
		int m;scanf("%d",&m);
		for(int i=0;i<m;i++){
			scanf("%d%d",f+i,a+i);
		}
		int l;scanf("%d",&l);
		for(int i=0;i<l;i++){
			w[i]=0;
			scanf("%d%d",p+i,t+i);
		}
		for(int i=0;i<n+1;i++)v[i]=s[i]=0;
		for(int i=0;i<m;i++){
			for(int j=0;j<n+1;j++){
				if(f[i]<b[j]){
					y[i]=j;
					v[j]+=(double)a[i]/30/sz[j];
					break;
				}
			}
		}
		double now=0;
		while(1){
			bool yet=false;
			for(int i=0;i<n+1;i++)if(s[i]<50.0-eps)yet=true;
			if(!yet)break;
			double next=9999999;
			for(int i=0;i<n+1;i++)if(s[i]<50.0-eps&&v[i]>eps)next=min(next,(nx(s[i])-s[i])/v[i]);
			for(int i=0;i<n+1;i++)to[i]=min(50.0,s[i]+next*v[i]);
			
			for(int i=0;i<l;i++){
				if(!w[i]&&now<=t[i]&&t[i]<=now+next){
		//		printf("%f %d\n",now+next,i);
					for(int j=0;j<n+1;j++){
						if(p[i]<b[j]){
							ret[i]=s[j]+(to[j]-s[j])*(t[i]-now)/next;
							break;
						}
					}
					w[i]=1;
				}
			}
			for(int i=0;i<n+1;i++)s[i]=to[i];
			for(int i=0;i<n+1;i++)v[i]=0;
			for(int i=0;i<m;i++){
				double hm=9999999;
				double nm=s[y[i]];
				int L,R;
				for(int j=y[i];j>=0;j--){
					hm=min(hm,s[j]);
					L=j;
					if(j&&h[j-1]>eps+s[j])break;
				}
				for(int j=y[i];j<n+1;j++){
					hm=min(hm,s[j]);
					R=j;
					if(j<n&&h[j]>eps+s[j])break;
				}
				int ht=0;
				for(int j=L;j<=R;j++)if(hm+eps>s[j])ht+=sz[j];
				for(int j=L;j<=R;j++)if(hm+eps>s[j])v[j]+=(double)a[i]/30/ht;
			}
			now+=next;
		}
		for(int i=0;i<l;i++)if(!w[i])ret[i]=50;
		for(int i=0;i<l;i++)printf("%.12f\n",ret[i]);
	}
}

Measured memory_bytes: 1064
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] d = new int[N];
        for(int i = 0; i < N; i++){
            d[i] = sc.nextInt();
        }
        
        int ans = 0;
        for(int i = 0; i < N; i++){
            if(i == N - 1) break;
            for(int j = i + 1; j < N; j++){
                ans += d[i] * d[j];
            }
        }

        System.out.println(ans);
    }
}

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

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

const int maxn = 2 * (i64)1e5 + 1000;
i64 n, k, a[maxn];
vi pot;
vi neg;
vi zero;

bool chk(i64 p) {
    i64 c = 0;
    for (i64 x : neg) {
        if (p == 0) c += n - int(neg.size());
        else if (p > 0) {
            i64 b = -(p / (-x));
            c += n - (lower_bound(all(neg), b) - neg.begin());
        } else {
            i64 b = (-p - x - 1) / (-x);
            c += pot.end() - lower_bound(all(pot), b);
        }
    }
    if (p >= 0) c += n * int(zero.size());
    for (i64 x : pot) {
        if (p == 0) c += n - int(pot.size());
        else if (p > 0) {
            i64 b = p / x;
            c += int(neg.size()) + int(zero.size()) + (upper_bound(all(pot), b) - pot.begin());
        } else if (p < 0) {
            i64 b = -((-p + x - 1) / x);
            c += upper_bound(all(neg), b) - neg.begin();
        }
    }
    forn(i, n) if (a[i] * a[i] <= p) c--;
    c /= 2;
    if (c >= k) return true;
    else return false;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif

	cin >> n >> k;
	forn(i, n) {
        cin >> a[i];
        if (a[i] > 0) pot.eb(a[i]);
        else if (a[i] == 0) zero.eb(a[i]);
        else if (a[i] < 0) neg.eb(a[i]);
	}
	sort(all(pot));
	sort(all(zero));
	sort(all(neg));
	i64 l = -(i64)1e18, r = (i64)1e18, ans = -1;
	while (l <= r) {
        i64 mid = (r - l) / 2 + l;
     //   cerr << l << " " << r << " " << mid << endl;
        if (chk(mid)) {
            r = mid - 1;
            ans = mid;
        } else {
            l = mid + 1;
        }
	}
	cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back

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

//-----------------------------------------------------------------------

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

    int n,m,a;
    while(cin>>n>>m>>a,n+m+a)
    {
        vector<P> v;
        REP(i,m){
            int h,p,q;
            cin>>h>>p>>q;
            v.pb(P(h,p));
        }
        sort(v.rbegin(),v.rend());

        REP(i,m){
            int pos=v[i].second;
            if(a==pos) a=pos+1;
            else if(a==pos+1) a=pos;
        }
        cout<<a<<endl;
    }
} 


Measured memory_bytes: 3232
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

struct node{
    int key;
    node* left;
    node* right;
};

node* nil;

void link(node* l, node* r){
    l->right = r;
    r->left = l;
}

void init(){
    nil = (node*)malloc(sizeof(node));
    nil->right = nil;
    nil->left = nil;
}

node* search(int key){
    node* cur = nil->right;
    while(cur != nil && cur->key != key){
        cur = cur -> right;
    }
    return cur;
}

void insert(int key){
    node* x = (node*)malloc(sizeof(node));
    x->key = key;

    link(x,nil->right);
    link(nil,x);
}

void deletenode(node* cur){
    if(cur == nil)
        return;
    link(cur->left,cur->right);
    free(cur);
}

void deleteFirst(){
    deletenode(nil->right);
}

void deleteLast(){
    deletenode(nil->left);
}

void deleteKey(int key){
    deletenode(search(key));
}

void printlist(){
    node* cur;
    for(cur = nil->right; cur->right != nil; cur = cur->right){
        printf("%d ",cur->key);
    }
    printf("%d\n",cur->key);
}

int main() {
    char cmd[25];
    init();
    int kase;
    int key;
    scanf("%d",&kase);

    while(kase--){
        scanf("%s",cmd);
        if(cmd[0] == 'i'){
            scanf("%d",&key);
            insert(key);
        }else if(cmd[0] == 'd'){
            if(strlen(cmd) <= 6){
                scanf("%d",&key);
                deleteKey(key);
            }
            if(strlen(cmd) > 6){
                if(cmd[6] == 'F'){
                    deleteFirst();
                } else if(cmd[6] == 'L'){
                    deleteLast();
                }
            }
        }
    }
    printlist();
    return 0;
}


Measured memory_bytes: 34460
using System;
using System.Collections.Generic;
using System.Linq;

public class PrintARectangle
{
    //??????H cm ?????? W cm ???????????¢?????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int i;
        int k;
        int l;
        string[] strRectangleData;
        List<string> strRectangleList = new List<string>();
        /*---??£?¨???¨---*/

        /*??\???(H W)?????????{H W ????????????0?????´?????????}*/
        for(i = 0;;i++) {
            strRectangleList.Add(Console.ReadLine());
            strRectangleData = strRectangleList[i].Split(' ');
            if (strRectangleData[0] == "0" && strRectangleData[1] == "0"){
                break;
            }
        }

        /*????????????int?????§??´???*/
        int[,] intRectangleData = new int[strRectangleList.Count, 2];

        for (i = 0; i < strRectangleList.Count - 1; i++) {
            strRectangleData = strRectangleList[i].Split(' ');
            intRectangleData[i,0] = int.Parse(strRectangleData[0]);
            intRectangleData[i, 1] = int.Parse(strRectangleData[1]);
            }

        /*????????¢???[#]??§??¨???*/
        for (i = 0; i < strRectangleList.Count - 1; i++) {
            for (k = 0; k < intRectangleData[i, 0]; k++) {
                for (l = 0; l < intRectangleData[i, 1]; l++) {
                    Console.Write("#");
                }
                Console.Write("\n");
            }
            Console.Write("\n");
        }
    }
}

Measured memory_bytes: 8948
h,w,d=map(int,input().split())
l=[[0,0]]+[[]for _ in range(h*w)]
for i in range(h):
    for j,a in enumerate(map(int,input().split())):
        l[a]=[i,j]
for i in range(h*w+1):
    if i<d:
        l[i].append(0)
    else:
        a,b=l[i]
        x,y,v=l[i-d]
        l[i].append(abs(x-a)+abs(y-b)+v)
l=[a[2]for a in l]
for _ in range(int(input())):
    a,b=map(int,input().split())
    print(l[b]-l[a])

Measured memory_bytes: 19436
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
  	cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << a[n - 1] - a[0] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	vector<ll> coun(50);
	for (int i = 0; i < 50; i++){
		for (int j = 0; j < n; j++){
			if (a[j] & (1LL<<i)) coun[i]++;
		}
	}

	ll ans = 0;
	bool used = false;
	for (int i = 49; i >= 0; i--){
		if ((1LL<<i) & k || used){
			if (coun[i] < n - coun[i]){
				ans += (1LL<<i)*(n-coun[i]);
			}else{
				ans += (1LL<<i)*coun[i];
				used = true;
			}
		}
		else ans += (1LL<<i)*(coun[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
class Main {
    public static void main (String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        for(int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if('a' <= c && c <= 'z') System.out.print((char)(c - 32));
            else if('A' <= c && c <= 'Z') System.out.print((char)(c + 32));
            else System.out.print(c);
        }
        System.out.println();
    }
}


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたコンストラクター・スタブ
		Scanner scanner = new Scanner(System.in);

		int cn = scanner.nextInt();
		int okashi = scanner.nextInt();
		int[] a = new int[cn];
		for(int i = 0; i < cn; i++) {
			a[i] = scanner.nextInt();
		}

		Arrays.sort(a);

		int i,all = 0;
		for(i = 0; i < cn; i++) {
			all += a[i];
			if(okashi < all) {
				break;
			}
		}
		if(all < okashi) {
			i--;
		}
		System.out.println(i);
		scanner.close();

	}

}

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

using namespace std;

int main(){
    string s;
    cin>>s;
    string m;
    for (int i=0; i<s.size(); i++) {
        if (i%2==0) {
            m += s.at(i);
        }
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
    char str[4];
    int num;
    bool flag = true;

    cin >> num ;
    for (int i=0;i<4;i++){
        str[i] = num % 10;
        num /= 10;
    }

    for (int i=0;i<3;i++){
        if (str[i] == str[i+1]) flag = false;
    }

    if (flag)   cout << "Good" << endl;
    else        cout << "Bad"  << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  int cnt;

  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;
  int  cnt;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int64 N, c500, c5, r, g;
  
  get_N(&N);

  c500 = N/500;
  r = N - (c500 * 500);

  c5 = r/5;

  g = c500*1000 + c5*5;
    
  printf("%lld", g);
  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int i,j,k,n,m,x,y,t,b[10];
int main(){
  scanf("%d",&n);
  m=n;
  for (i=n;i;i++){
    x=i;bool flag=0;
    memset(b,0,sizeof b);
    b[x%10]=1;
    while (x){if (!b[x%10]){flag=1;break;}x/=10;}
    if (!flag){printf("%d\n",i);return 0;}
  }
}

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

vector<ll> ans(200005, 0);
vector<vector<int>> child(200005, vector<int>());

void dfs(int v, int p){
    rep(i, child[v].size()){
        if(child[v][i] == p) continue;
        
        ans[child[v][i]] += ans[v];
        
        dfs(child[v][i], v);
    }
}


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

    int N,Q;
    cin >> N >> Q;
    
    rep(i,N-1){
        ll a,b;
        cin >> a >> b;
        child[a-1].push_back(b-1);
        child[b-1].push_back(a-1);
    }
    
    rep(i,Q){
        int p,x;
        cin >> p >> x;
        ans[p-1] += x;
    }
    
    dfs(0, -1);
    
    rep(i,N){
        cout << ans[i] << ' ';
    }

    return 0;
}


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

void Main()
{
  string N;
  cin >> N;
  for (auto &s : N)
  {
    if (s == '7')
    {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
  return;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 3132
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    vector<ll> a(3);
    rep(0, i, 3)
    {
        cin >> a.at(i);
    }
    sort(all(a));
    if (a.at(0) + a.at(1) == a.at(2))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define ll long long
#define ull unsigned long long
using namespace std;

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

	ll n;
	cin >> n;
	vector<ll> V(n);
	for (ll &v : V) cin >> v;
	vector<ll> DP(n);
	DP.at(0) = 0;
	DP.at(1) = abs(V.at(1) - V.at(0));

	for (ll i = 2; i < n; i++){
		DP.at(i) = min(DP.at(i - 1) + abs(V.at(i) - V.at(i - 1)),
						 DP.at(i - 2) + abs(V.at(i) - V.at(i - 2)));
	}


	cout << DP.back();
	return 0;
}


Measured memory_bytes: 1792
// #include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
void solve(){
    string s, t;
    cin>>s>>t;
    int r=0;
    for(int i=0;i<s.size();++i){
      r+= (s[i]!=t[i]);
    }
    cout << r << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
} 

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

int main() {
  static const double pi = 3.141592653589793;
  int A, B, H, M;
  double a, b, c, ans;
  cin >> A >> B >> H >> M;
  a = ((H*60) + M);
  b = M*12;
  
 if(H*5 > M)
   c = (a - b)/360;
  else 
    c = (b - a)/360;
  
  ans = A*A + B*B -2*A*B*cos(c*pi);
  ans = sqrt(ans);
  
  cout << fixed << setprecision(12);
  cout << ans << endl;
}




Measured memory_bytes: 4228
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int f[N],ans[N];
char s[N];
int main(){
	int n,sum=0,s1,s2,sum1=0,sum2=0,d1=1,d2=1;scanf("%d%s",&n,s);
	for(int i=0;s[i];i++)sum+=(s[i]^=0x30);s1=sum-1,s2=sum+1;
	f[0]=1;for(int i=1;i<=s2;i++)f[i]=1+f[i%__builtin_popcount(i)];
	if(s1)for(int i=n-1;~i;i--)(sum1+=s[i]*d1)%=s1,(sum2+=s[i]*d2)%=s2,d1=d1*2%s1,d2=d2*2%s2;
	else for(int i=n-1;~i;i--)(sum2+=s[i]*d2)%=s2,d2=d2*2%s2;
	d1=d2=1;
	for(int i=n-1;~i;i--){
		if(s[i])ans[i]=s1?f[(sum1-d1+s1)%s1]:0;
		else ans[i]=f[(sum2+d2)%s2];
		d2=d2*2%s2;if(s1)d1=d1*2%s1;
	}
	for(int i=0;i<n;i++)printf("%d\n",ans[i]);
	return 0;
}

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

int main() {
  cin.tie(0);
  int n;
  cin >> n;
  vector<int>x(n);
  vector<int>y(n);
  vector<ll>h(n);
  rep(i,n) cin >> x[i] >> y[i] >> h[i];
  
  vector<int>ans_x;
  vector<int>ans_y;
  vector<ll>ans_h;
  rep(cx,101){
    rep(cy,101){
      set<ll>st;
      ll H;
      rep(i,n){
        if(h[i]==0)continue;
        int X = abs(cx-x[i]);
        int Y = abs(cy-y[i]);
        H = X + Y + h[i];
        st.insert(H);
      }
      if(st.size()==1){
        ans_x.push_back(cx);
        ans_y.push_back(cy);
        ans_h.push_back(H);
      }
    }
  }
  
  rep(i,ans_x.size()){
    bool can = true;
    rep(j,n){
      if(h[j]!=max((ll)0,ans_h[i]-abs(x[j]-ans_x[i])-abs(y[j]-ans_y[i]))){
        can = false;
        break;
      }
    }
    if(can){
      cout << ans_x[i] << " "<< ans_y[i] << " "<< ans_h[i] << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int k;
  cin >> k;
  ll ans = 0;
  rep1(j,k){
    ll a = j;
    ll d = j;
    ll n = k/j;
    ll sum = n*(2*a+(n-1)*d)/2;
    ans += sum;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(){
  int N,n;
  int odd=0;
  int exp[200],index=0;
   scanf("%d",&N);

   if(N==0)printf("0");
   while(N!=0){
     if(N<0)
       n=N-N/4*4+4;
     else
       n=N;
     exp[index++]=n%4;
     N=(N-n%4)/4+(n%4/2);
   }
   
   if(index){
     if(exp[--index]/2)
       printf("1");
     printf("%d",exp[index]%2);
   }
   while(index--)
     printf("%d%d",exp[index]/2,exp[index]%2);
     printf("\n");
   return 0;
}


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

template <class T>
T gcd(T a, T b){
	if(a < b)swap(a, b);
	while(b){
		a = a % b;
		swap(a, b);
	}
	return a;
}

template <class T>
T lcm(T a, T b){
	return a*b/gcd(a,b);
}

class Solution {
public:
	void solve() {
		int n;
		long long m;
		cin >> n >> m;
		vector<long long> a(n, 0);
		for(int i=0; i<n; i++)cin >> a[i];
		sort(a.begin(), a.end());
		a.erase( unique(a.begin(), a.end()), a.end());
		reverse(a.begin(), a.end());
		int x = 0;
		long long y = a[0];
		while(!(y & 1)){
			x++;
			y >>= 1;
		}
		m >>= x-1;
		long long z = 1;
		for(int i=0; i < n; i++){
			a[i] >>= x;
			z = lcm(z, a[i]);
			if(!(a[i] & 1)|| z > m){
				cout <<"0\n";
				return;
			}
		}
		cout << (m+z)/(2*z) << "\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db long double
#define pii pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline ll rd()
{
	ll x=0;char c=gc();while(!isdigit(c))c=gc();
	while(isdigit(c))x=x*10+c-48,c=gc();return x;
}
const int N=200005,inf=1e9+7;
int n,S,T,tt,cc,nn,hd[N],q[N],d[N],iter[N],a[N],vis[N];pii ans[N];
struct E{int v,nxt,w;}e[N*8];
inline void add(int u,int v,int w){e[++cc]=(E){v,hd[u],w};hd[u]=cc;e[++cc]=(E){u,hd[v],0};hd[v]=cc;}
inline bool bfs(int S)
{
	rep(i,1,tt)d[i]=inf,iter[i]=hd[i];
	int ql=0,qr=0;q[++qr]=S;d[S]=0;
	while(ql<qr)
	{
		int x=q[++ql];
		for(int i=hd[x],y;i;i=e[i].nxt)if(e[i].w&&d[y=e[i].v]==inf){d[y]=d[x]+1;q[++qr]=y;}
	} 
	return d[T]<inf;
}
int dfs(int x,int f)
{
	if(x==T||!f)return f;int sf=0;
	for(int&i=iter[x];i;i=e[i].nxt)if(e[i].w&&d[e[i].v]==d[x]+1)
	{
		int w=dfs(e[i].v,min(f,e[i].w));
		if(w)
		{
			e[i].w-=w;e[i^1].w+=w;
			f-=w;sf+=w;if(!f)break;
		}
	} 
	return sf;
}
void dfs(int x)
{
	for(int i=hd[x];i;i=e[i].nxt)if(e[i].v!=S&&!vis[e[i].v-n])
	{
		nn++;int t=e[i].v-n;vis[t]=1;
		ans[t]=mp(x,a[t]);dfs(a[t]);
	} 
}
int main()
{
	n=rd();S=n+n;T=n+n+1;tt=T;cc=1;
	rep(i,1,n-1)
	{
		int m=rd();
		rep(j,1,m)add(rd(),n+i,1);
		add(S,i+1,1);add(n+i,T,1);
	}
	int f=0;
	while(bfs(S))f+=dfs(S,inf);
	if(f!=n-1){puts("-1");return 0;}
	for(int i=n+1;i<n+n;i++)for(int j=hd[i];j;j=e[j].nxt)if(e[j].w&&e[j].v<=n)a[i-n]=e[j].v;
	dfs(1);
	if(nn<n-1){puts("-1");return 0;}
	rep(i,1,n-1)printf("%d %d\n",ans[i].X,ans[i].Y);
	return 0;
}


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

bool odd(int x) {
    int cnt = 0;
    while (x) {
        cnt++;
        x /= 10;
    }
    if (cnt % 2 == 0) return false;
    return true;
}

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (odd(i)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstring>

using namespace std;

int main(void){
  char words[128][128];
  int n, ans = 1;
  
  cin >> n;
  cin >> words[0];
  for (int i=1; i<n; i++){
    cin >> words[i];
    if (words[i][0] != words[i-1][strlen(words[i-1])-1]) ans = 0;
    for (int j=i-1; j>=0; j--){
      if (strcmp(words[i], words[j])==0) ans = 0;
    }
    //cout << ans << endl;
  }
  cout << (ans?"Yes":"No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    const int N = 101000;

    vector<bool> isPrime(N + 1, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i <= N; ++i) {
        if (isPrime[i]) {
            for (int j = i + i; j <= N; j += i) {
                isPrime[j] = false;
            }
        }
    }

    vector<int> cnts(N + 1, 0);
    for (int i = 1; i <= N; ++i) {
        cnts[i] = cnts[i - 1];
        if ((i & 1) && isPrime[i] && isPrime[(i + 1) / 2]) {
            cnts[i] += 1;
        }
    }


    int q;
    cin >> q;
    while (q-- > 0) {
        int l, r;
        cin >> l >> r;
        int res = cnts[r] - cnts[l - 1];
        cout << res << '\n';
    }



    return 0;
}

Measured memory_bytes: 3664
def insertion_sort(a, n)
  puts a.join(' ')

  for i in 1...n
    v = a[i]
    j = i-1
    while 0 <= j && v < a[j]
      a[j+1] = a[j]
      j -= 1
    end
    a[j+1] = v
    puts a.join(' ')
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)

insertion_sort(a, n)

Measured memory_bytes: 8740
#include<bits/stdc++.h>
using namespace std;
int x[20][20];
int main(){
	int n,d;
	cin>>n>>d;
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin>>x[i][j];
		}
	}
	int ans=0;
	double sum;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			sum=0;
			for(int k=0;k<d;k++){
				sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			sum=sqrt(sum);
			int tmp=sum;
			if(sum-tmp==0){
			//	cout<<i<<" "<<j<<endl;
			//	cout<<"sum:"<<sum<<"tmp:"<<tmp<<endl;
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, r;
	int gcd, lcm;
	int x, y;

	while (cin >> a >> b){
		x = a;
		y = b;
		if (b > a){
			c = a;
			a = b;
			b = c;
		}

		while(1){
			r = a % b;
			if (r == 0){
				break;
			}
			a = b;
			b = r;
		}
		gcd = b;
		x /= gcd;
		y /= gcd;

		cout << gcd << " " << x * y * gcd << endl;
	}

	return 0;
}

Measured memory_bytes: 3104
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()
	ans := a + min(b/a, 1) - 1
	fmt.Println(ans)
}


Measured memory_bytes: 640
import scala.io.StdIn.readLine
object Main extends App {
  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val paths = Array.fill(m)( readLine.split(" ").map(_.toInt) match {
    case Array(a, b) => Path(a, b)
  } )
  case class Path(v1: Int, v2: Int)

  println(solve(Array.range(1, n + 1), paths, 1))

  def solve(nodes: Array[Int], paths: Array[Path], start: Int): Int = {
    if (nodes.size == 1) 1
    else {
      val newNodes = nodes.filter(_ != start)
      val (release, hold) = paths partition {
        case Path(a, b) => (a == start) || (b == start)
      }
      (0 /: (release map {
        case Path(a, b) => solve(newNodes, hold, if (a == start) b else a)
      }))(_ + _)
    }
  }
}


Measured memory_bytes: 35924
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> h;

    REP(i, N)
    {
        int a;
        cin >> a;
        h.pb(a);
    }

    int ans = 0;
    while (true)
    {
        if (*max_element(h.begin(), h.end()) == 0)
            break;

        int i = 0;
        while (i < N)
        {
            if (h.at(i) == 0)
                i++;
            else
            {
                ans++;
                while (i < N && h.at(i) > 0)
                {
                    h.at(i)--;
                    i++;
                }
            }
        }
    }

    cout << ans;
}

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

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

        int[] array = new int[3];
        for (int i = 0; i < 3; ++i) {
            array[i] = scanner.nextInt();
        }
        Arrays.sort(array);

        System.out.println(array[0] + " " + array[1] + " " + array[2]);
    }
}


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

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


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

int main() {
  int a,b,c,d;
  cin>>a>>b;
  vector<int> vec(b);
  for(int i=0;i<b;i++){
    cin>>vec.at(i);
  }
  for(int i=a;i<100000;i++){
    c=i;
    while(c>0&&d==0){
      for(int j=0;j<b;j++){
        if(c%10==vec.at(j)){
          d++;
          break;
        }
      }
      c/=10;
    }
    if(d==0){
      cout<<i<<endl;
      return 0;
    }
    d=0;
  }    
}

Measured memory_bytes: 256
<?php

    $x = in_int();

    $cnt500 = floor($x / 500);
    $cnt5 = floor(($x - ($cnt500 * 500)) / 5);

    out(($cnt500 * 1000) + ($cnt5 * 5));
    
    /**
    * お手伝い関数さんたち
    */
    function in() {
        return trim(fgets(STDIN));
    }
    function in_int() {
        return (int)in();
    }
    function in_vals() {
        return explode(' ', in());
    }
    function in_ints() {
        return array_map('intval', in_vals());
    }
    function out($s) {
        echo $s . PHP_EOL;
    }
    function yes() {
        out('Yes');
    }
    function no() {
        out('No');
    }
    function factorial($n) { // 階乗
        if ($n > 0) {
            return $n *= factorial($n - 1);
        }
        return 1;
    }
    function is_palindrome($s) {  // 回文か
        return $s == strrev($s);
    }



Measured memory_bytes: 4728
//use std::io::{stdout, Write, BufWriter}
use std::ops::Range;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }

    let gcd = gcd(c, d);
    let glm = gcd * (c / gcd) * (d / gcd);
    println!("{}",
         (b - a + 1) - multiples(a..b, c) - multiples(a..b, d) + multiples(a..b, glm)
    );
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
// calculates how many n's mulptiles are included in interval r, inclusive both ends.
fn multiples(r: Range<i64>, n: i64) -> i64 {
    (r.end / n) - ((r.start + n - 1)/ n) + 1
}


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

int n,a[100005];

int main() {
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    for(int i=1;i<=n;i++) {
        if(i+1>a[i+1]) {
            int j=0;
            while(a[j+i+1]==i)++j;
            if((a[i]-i)%2 || j%2) cout<<"First";
            else cout<<"Second";
            return 0;
        }
    }
}

Measured memory_bytes: 3996
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    L = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        a = L[i]
        for j in range(i + 1, n):
            b = L[j]
            for k in range(j + 1, n):
                c = L[k]
                if len(set([a, b, c])) != 3:
                    continue
                if 2 * max(a, b, c) < sum([a, b, c]):
                    ans += 1
    print(ans)
resolve()

Measured memory_bytes: 68928
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<ll> t(n), a(n);

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

  ll num = 1;
  ll T = t[0];
  ll A = a[0];
  for(int i = 1; i < n; ++i) {
    num = max((T + t[i] - 1) / t[i], (A + a[i] - 1) / a[i]);
    T = t[i] * num;
    A = a[i] * num;
  }
  cout << num * a[n - 1] + num * t[n - 1]  << endl;
}

Measured memory_bytes: 256
def main():
    N, M = (int(i) for i in input().split())
    G = [[] for i in range(N)]
    for i in range(M):
        x, y = (int(i)-1 for i in input().split())
        G[x].append(y)
        G[y].append(x)
    ans = 0
    from itertools import permutations
    for p in permutations(range(1, N)):
        j = 0
        # print(p)
        for i in range(N-1):
            if p[i] in G[j]:
                j = p[i]
            else:
                break
        else:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39408