akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;
	
struct Dsu {
	int n;
	vector<int> p;
	vector<int> rank;

	int get(int v) {
		if (p[v] != v) {
			p[v] = get(p[v]);
		}
		return p[v];
	}

	int merge(int a, int b) {
		a = get(a);
		b = get(b);
		if (a == b) {
			return 0;
		}
		if (rank[a] < rank[b]) swap(a, b);
		p[b] = a;
		if (rank[a] == rank[b]) rank[a]++;
		return 1;
	}

	Dsu(int n_) {
		n = n_;
		p.resize(n);
		iota(p.begin(), p.end(), 0);
		rank.resize(n);
	}
};

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

	int n;
	cin >> n;
	vector<int> x(n);
	vector<int> y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	vector<int> ind(n);
	iota(ind.begin(), ind.end(), 0);
	sort(ind.begin(), ind.end(), [&](int i, int j) {
		return x[i] < x[j];
	});
	vector<tuple<int, int, int>> ed;
	for (int i = 0; i + 1 < n; i++) {
		ed.push_back(make_tuple(x[ind[i + 1]] - x[ind[i]], ind[i], ind[i + 1]));
	}
	sort(ind.begin(), ind.end(), [&](int i, int j) {
		return y[i] < y[j];
	});
	for (int i = 0; i + 1 < n; i++) {
		ed.push_back(make_tuple(y[ind[i + 1]] - y[ind[i]], ind[i], ind[i + 1]));
	}
	int ans = 0;
	Dsu cur(n);
	sort(ed.begin(), ed.end());
	for (auto t : ed) {
		int u, v;
		u = get<1>(t);
		v = get<2>(t);
		if (cur.merge(u, v)) {
			ans += get<0>(t);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cstring>
#include <map>

using namespace std;

typedef long long ll;

int N,M;
string ss[101];
map<char,int> equ;
char cs[101];
int co[101];
bool isHead[1001];
int cnt;
int nums[101];

// Mツ古つづ個閉カツ篠堋づ可青板篠堋づーツ環づィツ督鳴づづゥ
void check(){
    do{
        // ツ陛サツ津カツ篠ョツつェツ湘ーツ個渉づーツ鳴楪つスツつキツつゥツづつ、ツつゥツチツェツッツク
        int sum=0;
        bool ok=true;
        for(int i=0;i<M;i++){
            if(isHead[cs[i]]&&nums[i]==0){
                ok=false;
                break;
            }
            sum+=co[i]*nums[i];
        }
        if(ok&&sum==0)cnt++;
    }while(next_permutation(nums,nums+M));
}

void solve(){
    for(int s=(1<<M)-1;s<(1<<10);){
        int a=0;
        //vector<int> v;
        for(int i=0;i<10;i++){
            if((s>>i)&1){
                a++;
                nums[a-1]=i;
            }
        }
        check();
        //table[a].push_back(v);
        int bit=s;
        int x = bit & -bit, y = bit + x;
		bit = ((bit & ~y) / x >> 1) | y;
        s=bit;
    }
    //int a=table[M].size();
    //for(int i=0;i<table[M].size();i++){
    //    for(int j=0;j<M;j++)nums[j]=table[M][i][j];
    //    check();
    //}
}

//void prePro(){
//    for(int s=0;s<(1<<10);s++){
//        int a=0;
//        vector<int> v;
//        for(int i=0;i<10;i++){
//            if((s>>i)&1){
//                a++;
//                v.push_back(i);
//            }
//        }
//        table[a].push_back(v);
//    }
//}

int main(){
    std::ios_base::sync_with_stdio(0);
    //prePro();
    while(cin>>N&&N){
        cnt=0;
        equ.clear();
        memset(isHead,0,sizeof(isHead));
        for(int i=0;i<N;i++)cin>>ss[i];
        // ツ暗ェツ篠淞陛サツ津カツ篠ョツづーツ催ャツ青ャツつオツづつィツつュ
        for(int i=0;i<N;i++){
            int mul=1;
            for(int j=ss[i].size()-1;j>=0;j--){
                if(i==N-1)equ[ss[i][j]]-=mul;
                else equ[ss[i][j]]+=mul;
                if(j==0&&ss[i].size()!=1)isHead[ss[i][j]]=true;
                mul*=10;
            }
        }
        M=equ.size();
        int id=0;
        // ツ係ツ青板づ閉カツ篠堋づーツ禿シツづェツづつィツつュ
        for(map<char,int>::iterator it=equ.begin();it!=equ.end();it++){
            cs[id++]=it->first;
            co[id-1]=it->second;
        }
        solve();
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int x[10], y[10];
int main(void){
    scanf("%d %d %d %d", &x[1], &y[1], &x[2], &y[2]);
    x[3] = x[2] - (y[2]-y[1]);
    y[3] = y[2] + (x[2]-x[1]);
    x[4] = x[3] - (y[3]-y[2]);
    y[4] = y[3] + (x[3]-x[2]);
    printf("%d %d %d %d\n", x[3], y[3], x[4], y[4]);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
 
int main(void) {
    int prime[1000000],i,j,n,num;
    for(i = 0;i < 1000000;i++) prime[i] = 1;
    for(i = 2;i < 1000;i++){
        for(j = i * 2;j < 1000000;j += i) prime[j] = 0;
    }
    while(scanf("%d",&n) != EOF){
        num = 0;
        for(i = 2;i <= n;i++) if(prime[i]) num++;
        printf("%d\n",num);
    }
    return 0;
}


Measured memory_bytes: 5580
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  for (int i = K; i < N; ++i) {
    if (A[i] > A[i-K]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
    int a, b, c;
  	cin >> a >> b >> c;
  
  	if (a - b >= c) {
        cout << 0 << endl;
    } else {
    	cout << c - (a - b) << endl;
    }  
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        auto check = [](ll x) {
                int b = x % 10;
                x /= 10;

                while (x > 0) {
                        if (abs(x % 10 - b) > 1) {
                                return false;
                        } else {
                                b = x % 10;
                                x /= 10;
                        }
                }

                return true;
        };

        auto build = [](ll x) {
                string xs = to_string(x), s;
                
                int p = 0;
                REP(i, xs.size() - 1) {
                        if ((i == 0 || xs[i - 1] >= xs[i]) && xs[i] < xs[i + 1]) {
                                p = i;
                        }
                }

                int t = xs[p] - '0';
                s = xs.substr(0, p) + to_string(t + 1);
                
                FOR(i, p, xs.size() - 1) {
                        int l = s[s.size() - 1] - '0';
                        if (l == 0) {
                                s += '0';
                        } else {
                                s += (l - 1) + '0';
                        }
                }

                return stoll(s);
        };

        ll ans = 1;
        REP(i, k-1) {
                if (!check(ans + 1)) {
                        ans = build(ans);
                } else {
                        ans++;
                }
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {

	ll n, m,x;
	map<ll, ll> dic;
	cin >> n >> x >> m;

	vll sum(m+1, 0);
	vll flg(m + 1, 0);
	ll ans = x;
	ll cur = x;
	ll cnt=1;
	for(cnt=1;cnt<n;cnt++) {
		if (flg[cur]) {
			ll length = cnt - flg[cur];
			ans += sum[flg[cur] - 1];

			ans += (n - flg[cur]) / length * (sum[cnt-1] - sum[flg[cur] - 1]);

			ans+=sum[flg[cur]-1 + (n - flg[cur]) % length] - sum[flg[cur] - 1];
			break;
		}
		flg[cur] = cnt;
		cur = (cur * cur) % m;
		if (cur == 0) {
			ans += sum[cnt - 1];
			break;
		}
		else if (cur == 1) {
			ans += sum[cnt - 1] + n - cnt;
			break;
		}
		sum[cnt] = sum[cnt - 1] + cur;
	}
	if (ans == x) {
		cnt--;
		ans += sum[cnt];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

template<class T>
struct SegmentTree {
	using F = function<T(T, T)>;
	const T init;
	const F f;
	int sz;
	vector<T> seg;
	SegmentTree(int n, const T init, const F f) :
		init(init),
		f(f)
		{
			sz = 1;
			while(sz < n) sz <<= 1;
			seg.resize(sz << 1, init);
		}
	void update(int id) {
		while(id >>= 1) {
			seg[id] = f(seg[2 * id], seg[2 * id + 1]);
		}
	}
	void replace(int id, T x){
		id += sz;
		seg[id] = x;
		update(id);
	}
	// [l,r)
	T get(int l, int r){
		T L = init, R = init;
		for(l += sz, r += sz; l < r; l >>= 1, r>>= 1) {
			if(l & 1) L = f(L, seg[l++]);
			if(r & 1) R = f(seg[--r], R);
		}
		return f(L, R);
	}
	void debug(){
		int i = 1;
		for(int r = 2; r <= 2 * sz; r <<= 1) {
			while(i < r) {
				cout << seg[i++] << " ";
			}
			cout << "\n";
		}
	}
};

SegmentTree<int> cntx(300010, 0, [](int a, int b) {
	return max(a, b);
});
int main() {
	int h, w, m; cin >> h >> w >> m;
	pair<int, int> b[m]; for(auto& [y, x] : b) {
		cin >> y >> x;
		cntx.replace(x, cntx.get(x, x + 1) + 1);
	}
	sort(b, b + m);
	int now = 0;
	int ans = 0;
	for(int y = 1; y <= h; ++y) {
		vector<pair<int, int>> x;
		while(now < m and y == b[now].first) {
			x.emplace_back(b[now].second, 0);
			++now;
		}
		int sum = x.size();
		for(auto&[xx, cnt] : x) {
			cnt = cntx.get(xx, xx + 1);
			ans = max(ans, sum + cnt - 1);
			cntx.replace(xx, 0);
		}
		ans = max(ans, sum + cntx.get(0, 300010));
		for(auto&[xx, cnt] : x) {
			cntx.replace(xx, cnt);
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 13800
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int H, W;
char F[50][50];

bool bounds(int i, int j){
	return (i > -1 && i < H && j > -1 && j < W && F[i][j] == '#');
}

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d", &H, &W), cin.get();
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++) F[i][j] = cin.get();
		cin.get();
	}
	for(int i = 0; i < H; i++)
		for(int j = 0; j < W; j++){
			if(F[i][j] != '#'){
				int s = 0;
				if(bounds(i + 1, j)) s++;
				if(bounds(i - 1, j)) s++;
				if(bounds(i, j + 1)) s++;
				if(bounds(i, j - 1)) s++;
				if(bounds(i + 1, j + 1)) s++;
				if(bounds(i - 1, j + 1)) s++;
				if(bounds(i + 1, j - 1)) s++;
				if(bounds(i - 1, j - 1)) s++;
				F[i][j] = s + '0';
			}
		}
	for(int i = 0; i < H; i++){
		for(int j=  0; j < W; j++) printf("%c", F[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7; // 998244353
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	int N; cin >> N;
	VI D(N); REP(i, N) cin >> D[i];

	if (N >= 24) {
		cout << 0 << endl;
		return 0;
	}

	int ans = 0;
	REP(i, 1<<N) {
		int cnt = 30;
		VI t(25, 0);
		REP(j, N) t[(((i & 1 << j) ? D[j] : 24 - D[j]))%24]++;
		t[24] = 1;
		REP(j, 25) if (t[j] > 1) cnt = 0;
		int now = 0;
		REP(j, 25) {
			if (t[j]) {
				int d = j - now;
				d = min(d, 24 - d);
				cnt = min(cnt, d);
				now = j;
			}
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		System.out.println(toString(a & b));
		System.out.println(toString(a | b));
		System.out.println(toString(a ^ b));
	}
	
	static String toString(long x) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 32; i++) {
		    sb.append(x % 2);
		    x /= 2;
		}
	    return sb.reverse().toString();
	}
}



Measured memory_bytes: 26340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N, K;
int kotae = 0;
vector<int> E[100001];
int dfs(int A, int D) {
	int d = 1;
	for (int to : E[A]) {
		d = max(d, dfs(to, D + 1) + 1);
	}
	if (d >= K && D > 1) {
		kotae++;
		return 0;
	}
	else return d;
}

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


	cin >> N >> K;

	rep1(i, N) {
		int a;
		cin >> a;
		if (i != 1) E[a].pb(i);
		else if (a != 1) kotae++;
	}

	dfs(1, 0);
	co(kotae);

	Would you please return 0;
}

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

const int MAX_N = 100000;
int Q;
vector<bool> prime;
vector<bool> similar;
vector<int> cnt;

void make_prime_table(void) {
	prime.resize(MAX_N + 1, true);
	prime[0] = prime[1] = false;
	for (int i = 4; i <= MAX_N; i += 2) prime[i] = false;
	int sqrt_max = (int)sqrt((double)MAX_N);
	for (int i = 2; i <= sqrt_max; ++i) {
		if (prime[i]) {
			for (int j = i * i; j <= MAX_N; j += i)
				prime[j] = false;
		}
	}
}

void make_similar_table(void) {
	similar.resize(MAX_N + 1, false);
	for (int i = 1; i <= MAX_N; i += 2) {
		if (prime[i]) {
			int x = (i + 1) / 2;
			if (prime[x])
				similar[i] = true;
		}
	}
}

void make_cnt_table(void) {
	cnt.resize(MAX_N / 2 + 1, 0);
	cnt[0] = 0;
	for (int i = 1; i < MAX_N / 2 + 1; ++i) {
		cnt[i] = cnt[i - 1];
		int x = 2 * i - 1;
		if (similar[x])
			++cnt[i];
	}
}

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

	make_prime_table();
	make_similar_table();
	make_cnt_table();

	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int l, r;
		cin >> l >> r;
		int x1 = l / 2 + 1 - 1;
		int x2 = r / 2 + 1;
		int c = cnt[x2] - cnt[x1];
		cout << c << '\n';
	}
	return 0;
}


Measured memory_bytes: 896
N=int(input())
A=list(map(int,input().split()))

A.insert(0,0)
A.insert(N+1,0)
sum=0


for i in range(N+1):
    sum+=abs(A[i]-A[i+1])


for j in range(1,N+1):
    tmp=0
    tmp=abs(A[j-1]-A[j+1])-abs(A[j-1]-A[j])-abs(A[j]-A[j+1])
    print(sum+tmp)

Measured memory_bytes: 14048
n,t=map(int,input().split())
a=list(map(int,input().split()))
accum=[0]*n
accum[n-1]=a[n-1]
for i in reversed(range(1,n)):
    accum[i-1]=max(accum[i],a[i-1])
maxi=0
for i in range(n-1):
    maxi=max(maxi,accum[i+1]-a[i])
ans=0
d={}
for i in range(n):
    if a[i]-maxi>0:
        if a[i]-maxi in d:
            if d[a[i]-maxi]>0:
                d[a[i]-maxi]-=1
                ans+=1
    if a[i] not in d:
        d[a[i]]=1
    else:
        d[a[i]]+=1
print(ans)

Measured memory_bytes: 22804
#include <bits/stdc++.h>
using namespace std;
int main() {
     int a,b,c;
     cin >> a >> b >> c;
     if((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5)){
          cout << "YES" << endl;
     }else{
          cout << "NO" << endl;
     }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///////////////////////////////////////////////
struct Vertex {
	// edge information
	vector<int> edges_to; //to vertex number
	
	//for dijkstra
	bool done; //conform or not
	int cost; // now cost
	int from;
	
	bool operator<(const Vertex& another) const { // priority --> min
        return another.cost < cost; // order(cost)
    }
	
	bool operator==(const Vertex& another) const {
        return another.cost == cost; // order(cost)
    }
};

Vertex v[100002];
ll dp[100002][2] = {};

ll f(int i,int c){
	if (dp[i][c] >= 0) return dp[i][c];
	ll ret = 1;
	if (c==0){
		REP(j,v[i].edges_to.size()){
			int next = v[i].edges_to[j];
			if (v[i].cost >= v[next].cost) continue;
			ret = (ret * f(next,1)) % MOD;
		}
	}else{
		REP(j,v[i].edges_to.size()){
			int next = v[i].edges_to[j];
			if (v[i].cost >= v[next].cost) continue;
			ret = (ret * ((f(next,1) + f(next,0)) % MOD) ) % MOD;
		}
	}
	return dp[i][c] = ret;
}

int main(){
	int N;
	SCD(N);
	MM(dp);

	REP(i,N-1){
		int x,y; SCD2(x,y);
		v[x].edges_to.PB(y);
		v[y].edges_to.PB(x);
	}

	queue<int> Q;
	Q.push(1);
		
	while(Q.size() > 0){
		int now = Q.front(); Q.pop();
		v[now].done = true;
		REP(i,v[now].edges_to.size()){
			int next = v[now].edges_to[i];
			if (v[next].done == false){
				v[next].cost = v[now].cost + 1;
				Q.push(next);
				continue;
			}
		}
	}

	//PRINTD(f(1,0));
	//PRINTD(f(1,1));
	PRINTLLD((f(1,0) + f(1,1)) % MOD);
}


Measured memory_bytes: 15744
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL inf = 11234567890123;
std::vector<LL>V;
std::vector<std::vector<std::vector<LL>>>memo;

LL dp(LL l, LL r, LL k)
{
	if (r < l || k < 0) return -inf;
	if (k == 0) return 0;
	if (l == r) return std::max<LL>({ V[l],0 });
	if (memo[l][r][k] != -1) return memo[l][r][k];
	LL res1 = dp(l + 1, r, k - 1) + V[l];
	LL res2 = dp(l + 1, r, k - 2);
	LL res3 = dp(l, r - 1, k - 1) + V[r];
	LL res4 = dp(l, r - 1, k - 2);
	return memo[l][r][k] = std::max<LL>({ res1,res2,res3,res4,0 });
}

int main()
{
	LL N, K;
	in >> N >> K;
	V.resize(N);
	rep(i, N) in >> V[i];

	memo.resize(N, std::vector<std::vector<LL>>(N, std::vector<LL>(K + 1, -1)));
	out << dp(0, N - 1, K) << std::endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
int check1(int x, int y, string s){
  for(int i=x;i<y-2;i++){
    if(s.at(i)==s.at(i+1) && s.at(i)=='#'){
      return 0;
    }
  }
    return 1;
}
 
int check2(int x, int y,string s){
  for(int i=x-2;i<y-1;i++){
    if(s.at(i)==s.at(i+1) && s.at(i+1)==s.at(i+2) && s.at(i)=='.'){
      return 1;
    }
  }
  return 0;
}
int main(){
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S; cin >> S;
  if(check1(A,C,S)==0 || check1(B,D,S)==0){
    cout << "No" << endl;
    return 0;
  }
  if(C<D){
    cout << "Yes" << endl;
  }
  else if(check2(B,D,S)==1){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 900
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

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

    vector<int64_t> as(a);
    for (auto& v : as)
    {
        cin >> v;
    }
    vector<int64_t> bs(b);
    for (auto& v : bs)
    {
        cin >> v;
    }
    int64_t min_val = *min_element(as.begin(), as.end()) + *min_element(bs.begin(), bs.end());
    for (int i = 0; i < m; i++)
    {
        int64_t x, y, c;
        cin >> x >> y >> c;
        min_val = min(min_val, as[x - 1] + bs[y - 1] - c);
    }
    cout << min_val << endl;
}


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

int read()
{
	int ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=0;
	if(ch=='-')flag=1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10+ch-'0';
	if(flag)ans=-ans;
	return ans;
}

long long rell()
{
	long long ans=0;
	char ch=getchar();
	for(;(ch<'0' || ch>'9') && ch!='-';ch=getchar());
	bool flag=0;
	if(ch=='-')flag=1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())ans=ans*10ll+(long long)(ch-'0');
	if(flag)ans=-ans;
	return ans;
}

void writ(int n)
{
	char ch[25];
	int m=0;
	if(n<0)putchar('-'),n=-n;
	if(n==0)
	{
		putchar('0');
		return;
	}
	for(;n;n/=10)ch[m++]=n%10ll+'0';
	for(;m;)putchar(ch[--m]);
}

void wrll(long long n)
{
	char ch[25];
	int m=0;
	if(n<0)putchar('-'),n=-n;
	if(n==0)
	{
		putchar('0');
		return;
	}
	for(;n;n/=10ll)ch[m++]=n%10ll+'0';
	for(;m;)putchar(ch[--m]);
}
const int M=1<<18,big=0x3f3f3f3f;
int st[M],pv[M],p1[M],tot,f[M],size[M];
long long pg[M],mi=big;

void side(int u,int v,int k)
{
	pv[tot]=v;
	pg[tot]=k;
	p1[tot]=st[u];
	st[u]=tot++;
}

void ges(int fa,int u)
{
	//printf("ges %d %d\n",fa,u);
	size[u]=1;
	for(int i=st[u];~i;i=p1[i])if(pv[i]!=fa && f[pv[i]])
	{
		ges(u,pv[i]);
		size[u]+=size[pv[i]];
	}
}

int fi(int fa,int u,int n)
{
	for(int i=st[u];~i;i=p1[i])if(pv[i]!=fa && f[pv[i]])
	{
		int k=fi(u,pv[i],n);
		if(~k)return k;
	}
	if(size[u]>n/2)return u;else return -1;
}

long long query(int fa,int u,long long de)
{
	long long ans=de+de;
	if(de)mi=min(mi,de);
	for(int i=st[u];~i;i=p1[i])if(pv[i]!=fa && f[pv[i]])
	{
		ans+=query(u,pv[i],de+pg[i]);
	}
	return ans;
}

long long work(int u)
{
	//printf("work %d\n",u);
	ges(-1,u);
	//puts("RA");
	int si=size[u];
	u=fi(-1,u,size[u]);
	//puts("RA");
	long long ans=query(-1,u,0);
	for(int i=st[u];~i;i=p1[i])if(size[pv[i]]*2==si)mi=pg[i];
	//printf("work %d\n",(int)ans);
	/*f[u]=0;
	for(int i=st[u];~i;i=p1[i])if(f[pv[i]])
	{
		ans+=work(pv[i]);
	}*/
	return ans;
}

int main()
{
	int n=read();
	if(n==1)
	{
		puts("0");
		return 0;
	}
	tot=0;
	memset(st,-1,sizeof(st));
	for(int i=1;i<n;i++)
	{
		int u=read()-1,v=read()-1,k=read();
		side(u,v,k);
		side(v,u,k);
		//mi=min(mi,k);
	}
	/*for(int i=0;i<n;i++)
	{
		printf("i=%d st[i]=%d\n",i,st[i]);
	}*/
	memset(f,1,sizeof(f));
	wrll(work(0)-(long long)mi);
	puts("");
	return 0;
}


Measured memory_bytes: 10880
import sys
sys.setrecursionlimit(10**5)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    r=min(r,n-r)
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
n,k=map(int,input().split())
ans=[0]*k

for i in range(k):
  if n-k<i:
    print(0)
    continue
  ans = cmb(n-k+1,i+1)*cmb(k-1,i)
  print(ans%(10**9+7))

Measured memory_bytes: 127080
parseInt(x) = parse(Int,x)

function main()
	x = chomp(readline())
	d = Dict{Char,Int}()
	for i in 1:length(x)
		if haskey(d,x[i])
			d[x[i]] += 1
		else
			d[x[i]] = 1
		end
	end
	flg = 0
	for i in values(d)
		if i%2 != 0
			flg = 1
		end
	end
	if flg == 0
		print("Yes")
	else
		print("No")
	end
end
main()

Measured memory_bytes: 113316
#include <stdio.h>
typedef long long ll;
int main() {
	int n, t, time, pret = 0;
	ll x = 0;
	scanf("%d%d", &n, &t);
	for (int i = 0; i < n; i++) {
		scanf("%d", &time);
		if (time - pret < t) {
			x += time - pret;
		} else {
			x += t;
		}
		pret = time;
	}
	x += t;
	printf("%lld\n", x);
	return 0;
}

Measured memory_bytes: 128
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  printf("%d\n",(n+1)/2 );
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//



int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	string s;
	cin >> s;
	int len = s.size();
	int cnt = 0 , ans = 0;
	int pos = s.find("R");
	if(pos == -1)
		cout << "0\n";
	else{// 
		for(int i = pos ; i < len ; ++i){
			if(s[i] == 'R'){
				cnt++;
				ans = max(ans , cnt);
			}
			else 
				cnt = 0;
		}
		cout << ans << "\n";
	}
	
	
	
	
    return 0;
}




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



int main(){
	int N;
	cin>>N;
	
	long long S = 0;
	
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
		S+=A[i];
	}
	
	vector<long long> ans(N);
	long long a = 0;
	for(int i=0;i<N;i++){
		if(i%2==0)a+=A[i];
		else a-=A[i];
	}
	
	for(int i=0;i<N;i++){
		ans[i] = a;
		if(i%2==0){
			a-=A[i];
			a*=-1;
			a+=A[i];
		}
		else{
			a-=A[i];
			a*=-1;
			a+=A[i];
		}
	}
	
	for(int i=0;i<N;i++){
		if(i!=0)cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;
		
	
	return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
string t;
cin>>s>>t;
string ans="Yes";
if(t.size()==s.size()+1){
    rep(i,s.size()){
        if(s[i]!=t[i]){
            ans="No";
        }
    }
}
else{
    ans="No";
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3644
N, L = map(int, input().split())

taste = [int(L + i) for i in range(N)]

if 0 <= taste[0]:
    print(sum(taste) - taste[0])
else:
    if 0 <= taste[-1]:
        print(sum(taste))
    else:
        print(sum(taste) - taste[-1])



Measured memory_bytes: 2940
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val s = in.readInt
  val fEvn = (n:Int) => n / 2
  val fOdd = (n:Int) => 3 * n + 1

  def solve(s:Int):Int = {
    val set = mu.HashSet.empty[Int]
    def rec(acc:Int, i:Int):Int = {
      if(set.contains(acc)) i-1
      else {
        set += acc
        val n = if(acc % 2 == 0) fEvn(acc) else fOdd(acc)
        // println(n)
        rec(n, i+1)
      }
    }
    rec(s, 2)
  }

  val ans = solve(s)
  println(ans)
}

Measured memory_bytes: 25412
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());

        LinkedList<Integer> list = new LinkedList<Integer>();

        for (int i=0; i<n; i++) {
            String str = br.readLine();

            if (str.startsWith("insert")) {
                list.addFirst(Integer.parseInt(str.substring(str.indexOf(" ")+1)));
            }else if (str.equals("deleteFirst")) {
                list.pollFirst();
            }else if (str.equals("deleteLast")){
                list.pollLast();
            }else {
                list.remove((Integer)Integer.parseInt(str.substring(str.indexOf(" ")+1)));
            }
        }
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder sb = new StringBuilder();
        sb.append(list.poll());
        for (Integer s : list) {
            sb.append(" ");
            sb.append(s);
        }
        bw.write(sb.toString());
        bw.newLine();
        bw.close();

        br.close();
    }
}



Measured memory_bytes: 138328
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  int c = sc.nextInt();
  if(a+b <= b+c && a+b <= a+c){
      System.out.println(a+b);
  }
  else if(b+c <= a+b && b+c <= a+c){
      System.out.println(b+c);
  }
  else{
    System.out.println(a+c);
  }
}}

Measured memory_bytes: 21716
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

ll binom(ll n, ll k) {
    ll res = 1;
    if (n<k) return 0;
    for (int i=max(n-k,k)+1;i<=n;i++) res *= i;
    for (int i=min(n-k,k);i>0;i--) res /= i;
    return res;
}

int main(void) {
    string N;
    int K, c[4] = {1,9,81,729};
    cin >> N >> K;
    ll res = 0;
    int L = N.size();
    for (int i=K;i<L;i++) {
        res += c[K]*binom(i-1,i-K);
        // printf("%d-digit: %d\n",i,res);
    }
    int m = 0;
    for (int i=1;i<=L;i++) {
        // if (N[i-1] != '0') m++;
        if (i>1 && N[i-1] > '0') res += c[K-m]*((K>m)?binom(L-i,K-m):1);
        if (N[i-1] != '0') m++;
        for (int j=1;j<(N[i-1]-'0');j++) res += c[K-m]*((K>m)?binom(L-i,K-m):1);
        if (m == K) {
            res++;
            break;
        }
        // printf("%d-digit; %d-digit: %d\n",L,i,res);
    }
    cout << res << endl;

    return 0;
}


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

using namespace std;

int n;
long long int al[2010];
long long int dp[2][2010];
long long int z, w;

long long int ru(int side, int pos) {
  if (dp[side][pos] != -1) {
    return dp[side][pos];
  }

  if (pos == 0) {
    if (side == 0) {
      dp[side][pos] = labs(w - al[n - 1]);
    } else {
      dp[side][pos] = labs(z - al[n - 1]);
    }
  } else {
    dp[side][pos] = labs(al[pos - 1] - al[n - 1]);
  }

  for (int i = pos + 1; i < n; i++) {
    long long int ret = ru(side ^ 1, i);
    if (side == 0) {
      dp[side][pos] = max(dp[side][pos], ret);
    } else {
      dp[side][pos] = min(dp[side][pos], ret);
    }
  }

  return dp[side][pos];
}

int main() {

  scanf("%d %lld %lld", &n, &z, &w);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &al[i]);
    dp[0][i] = -1;
    dp[1][i] = -1;
  }

  printf("%lld\n", ru(0, 0));

  return 0;
}


Measured memory_bytes: 384
N=int(input())
if N==0: print(2)
elif N==1: print(1)
else:
  Ln_2=0
  Ln_1=2
  Ln=1
  for i in range(N-1):
    Ln_2=Ln_1
    Ln_1=Ln
    Ln=Ln_1+Ln_2
  print(Ln)
    
    


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

int main() {
  constexpr int64_t mod = 1000000007;
  int n;
  cin >> n;
  if (n == 3) {
    cout << 61 << endl;
    return 0;
  }
  vector<bool> forbidden(256);
  for (int i = 36; i < 40; i++) { // AGCX
    forbidden.at(i) = true;
  }
  for (int i = 32; i < 48; i++) { // AGXC
    if (i % 4 == 1) {
      forbidden.at(i) = true;
    }
  }
  for (int i = 0; i < 4; i++) { // XAGC
    forbidden.at(64 * i + 9) = true;
  }
  for (int i = 0; i < 4; i++) { // AXGC
    forbidden.at(16 * i + 9) = true;
  }
  for (int i = 132; i < 136; i++) { // GACX
    forbidden.at(i) = true;
  }
  for (int i = 0; i < 4; i++) { // XGAC
    forbidden.at(64 * i + 33) = true;
  }
  for (int i = 24; i < 28; i++) { // ACGX
    forbidden.at(i) = true;
  }
  for (int i = 0; i < 4; i++) { // XACG
    forbidden.at(64 * i + 6) = true;
  }
  vector<vector<int64_t>> dp(n + 1, vector<int64_t>(256));
  for (int i = 0; i < 256; i++) {
    if (forbidden.at(i)) continue;
    dp.at(4).at(i) = 1;
  }
  for (int i = 4; i < n; i++) {
    for (int j = 0; j < 256; j++) {
      for (int k = 0; k < 4; k++) {
        int t = (4 * j + k) % 256;
        if (forbidden.at(t)) continue;
        dp.at(i + 1).at(t) += dp.at(i).at(j);
        dp.at(i + 1).at(t) %= mod;
      }
    }
  }
  cout << accumulate(dp.at(n).begin(), dp.at(n).end(), 0LL) % mod << endl;
}


Measured memory_bytes: 512
from collections import deque
n,m = map(int,input().split())

adj = [[] for i in range(n)]
dist = [-1]*n
for i in range(m):
    a,b = map(int,input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)
    
q = deque()
dist[0] = 0
q.append(0)

while len(q) > 0:
    x = q.popleft()
    
    for f in adj[x]:
        if dist[f] != -1:
            continue
        
        dist[f] = dist[x] + 1
        q.append(f)
     
if dist[n-1] == 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 86232
#include  <stdio.h>

int main(){
  int A[100],n,i,j,k,min,temp,count=0;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

   for (i = 0; i < n - 1; i++) {
        min = A[i];                 
        k = i;                        
        for (j = i + 1; j < n; j++) {
            if (A[j] < min) {       
                min = A[j];        
                k = j;
            }
        }                           
        temp = A[i];                
        A[i] = A[k];
        A[k] = temp;
	if(i != k)count++;
    }

 for(i=0;i<n;i++){
   printf("%d",A[i]);
       if(i != n-1){
	printf(" ");
      }
    }
 
 printf("\n");
 
 printf("%d\n",count);
 
 return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
int s[100005][5];
int main()
{
    int n,first=0;
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= 3;j++)
        scanf("%d",&s[i][j]);
    for(int i = 1;i <= n;i++)
    {
        int a,b;
        a = (s[i][2]+s[i][3])-(s[i-1][2]+s[i-1][3]);
        if(a<0) a=-a;
        b = s[i][1]-s[i-1][1];
        if(a>b||(a-b)%2||a==0&&(b-4)%2)  {first = 1;break;}
    }
    if(first)  printf("No");
    else printf("Yes");
    return 0;
}
   


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
char s[20];
int main(){
    scanf("%s",s+1);
    for(int i=1;s[i];i+=2){
        if(!(s[i] == 'h' && s[i+1] == 'i')) return !printf("No");
    }
    printf("Yes");
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n];
		int b[] = new int[n];
		for(int i=0; i<n; i++) {
			a[i]=sc.nextInt();
		}

		ArrayList<Integer>ans = new ArrayList<>();
		for(int i=n-1; i>=0; i--) {
			int cnt = 0;
			int step = i+1;
			for(int j=i+step; j<n; j+=step) {
				if(b[j]==1) cnt++;
			}
			if((cnt%2) != a[i]) {
				b[i]=1;
				ans.add(i+1);
			}

		}
		System.out.println(ans.size());
		for(int i=0; i<ans.size(); i++) {
			System.out.print(ans.get(i) + (i<ans.size()-1 ? " " : "\n"));
		}
		sc.close();
	}
}


Measured memory_bytes: 64552
import math

# Check


def main():
    N = int(input())
    A = list(map(int, input().split()))
    even = 0
    zero = 0
    c = 0

    ans = 0
    for i in A:
        if i < 0:
            c += 1
        elif i == 0:
            even = 0
            c = 0
        else:
            if c % 2 != 0:
                even += 1
            c = 0
        ans += abs(i)

    if c != 0 and c % 2 != 0:
        even += 1

    if even % 2 == 0:
        print(ans)
    else:
        print(ans - min([abs(i) for i in A if abs(i) > 0]) * 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65108
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=10000000000000000LL;
int k;
ll a[100001];
ll cheak(ll s){
	ll u=s;
	for(int i=0;i<k;++i){
		u-=u%a[i];
	}
	return u;
}
ll reg1(ll l,ll r){
	if(l==r)return l;
	ll c=(l+r)/2;
	if(cheak(c)<2){
//		cout<<c<<endl;
		if(l+1==r)return c;
		return reg1(c,r);
	}
//	cout<<c<<endl;
	if(l+1==r)return l;
	return reg1(l,c);
}
ll reg2(ll l,ll r){
	if(l==r)return l;
	ll c=(l+r)/2;
	if(cheak(c)>2){
//		cout<<c<<endl;
		if(l+1==r)return c;
		return reg2(l,c);
	}
	if(l+1==r)return c+1;
	return reg2(c,r);
}
int main() {
	cin>>k;
	for(int i=0;i<k;++i){
		cin>>a[i];
	}
	ll mi=reg1(0,100000000000000);
	ll ma=reg2(0,100000000000000);
	if(cheak(mi+1)!=2||cheak(ma-1)!=2)cout<<-1<<endl;
	else cout<<mi+1<<" "<<ma-1<<endl;
	return 0;
}


Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(dead_code)]
#![macro_use]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::{HashSet, HashMap, BinaryHeap};

const MOD: i64 = 1e9 as i64 + 7;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn gcd(x: usize, y: usize)->usize{
    if y == 0{
        return x
    }
    gcd(y, x % y)
}

fn main() {
    input! {
        s: chars,
        t: chars,
    }
    let mut mp1: HashMap<char, char> = HashMap::new();
    let mut mp2: HashMap<char, char> = HashMap::new();
    let mut f = true;
    for (&i, j) in s.iter().zip(t){
        if mp1.contains_key(&i) && *mp1.get(&i).unwrap() != j{
            f = false;
            break;
        }
        if mp2.contains_key(&j) && *mp2.get(&j).unwrap() != i{
            f = false;
            break;
        }
        mp1.insert(i, j);
        mp2.insert(j, i);
    }
    println!("{}", if f {"Yes"} else {"No"});
}


Measured memory_bytes: 6396
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   string S;
   cin >> S;
   bool log[26];
   memset(log, false, sizeof(log));
   for (int i = 0; i < (int)S.size(); i++) {
      int id = S[i] - 'a';
      log[id] = true;
   }
   for (int i = 0; i < 26; i++) {
      char tmp = 'a';
      if (!log[i]) {
         char ans = tmp + i;
         cout << ans << endl;
         return 0;
      }
   }
   cout << "None" << endl;
   return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
int main(){
  char a[51],b[51];
  scanf("%s %s",a,b);
  for(int i=0;i<strlen(a);i++){
    printf("%c",a[i]);
    if(b[i]!='\0')printf("%c",b[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env ruby

if $0 == __FILE__
  gets
  ary = gets.split(' ').map &:to_i

  colors = Array.new(8) { 0 }
  any = 0

  ary.each do |i|
    if    i <= 399
      colors[0] = 1
    elsif i <= 799
      colors[1] = 1
    elsif i <= 1199
      colors[2] = 1
    elsif i <= 1599
      colors[3] = 1
    elsif i <= 1999
      colors[4] = 1
    elsif i <= 2399
      colors[5] = 1
    elsif i <= 2799
      colors[6] = 1
    elsif i <= 3199
      colors[7] = 1
    else
      any += 1
    end
  end

  base = colors.inject(&:+)

  min = [base,1].max
  max = base + any

  puts "#{min} #{max}"
end


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 3e2 + 10;

int n;
ll ar[N];
ll cur;

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

    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> ar[i];
        if (i > 2) cur ^= ar[i];
    }
    ll a = ar[1], b = ar[2];
    if (cur > a + b){
        cout << -1 << el;
        return 0;
    }
    ll anb = (a + b - cur) / 2LL;
    ll na = anb, nb = anb; // new a, new b
    if (na > a){
        cout << -1 << el;
        return 0;
    }
    for (ll i=50;i>=0;i--){
        ll bit = (1LL << i);
        if (cur & bit){
            if (na + bit < a) na += bit;
            else nb += bit;
        }
    }
    if (na == 0 || (na ^ nb) != cur || na + nb != a + b){
        cout << -1 << el;
        return 0;
    }
    cout << a - na << el;

    return 0;
}

Measured memory_bytes: 3652