akhauriyash/Code-Regression huggingface dataset:
//============================================================================
// Name        : MergeSort.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int n_comparison = 0;

void writeVector(const vector<int>& A){
	for(int i=0; i<A.size()-1; i++){
		cout << A.at(i) << " ";
	}
	cout << A.at(A.size()-1);
	//cout << "\n";
}

void Merge(vector<int>& A, int left, int mid, int right){
	//cout << "Merge([";
	//writeVector(A);
	//cout << "], " << left << ", " << mid << ", " << right << ")\n";
	int n1 = mid - left;
	int n2 = right - mid;

	vector<int> L(n1+1);
	vector<int> R(n2+1);

	for(int i=0; i<n1; i++){
		L.at(i) = A.at(left + i);
	}
	L.at(n1) = pow(10, 9) + 1;
	//cout << "L: ";
	//writeVector(L);

	for(int i=0; i<n2; i++){
		R.at(i) = A.at(mid + i);
	}
	R.at(n2) = pow(10, 9) + 1;
	//cout << "R: ";
	//writeVector(R);

	int i = 0, j = 0;
	for(int k=left; k<right; k++){
		if(L.at(i) <= R.at(j)){
			//cout << "i: " << i << "\n";
			A.at(k) = L.at(i);
			i++;
			n_comparison ++;
		}else{
			//cout << "j: " << j << "\n";
			A.at(k) = R.at(j);
			j++;
			n_comparison ++;
		}
	}
	//writeVector(A);
}

void MergeSort(vector<int>& A, int left, int right){
	//cout << "MergeSort([";
	//writeVector(A);
	//cout << "], " << left << ", " << right << ")\n";
	if(left+1 < right){
		int mid = (left + right)/2;
		MergeSort(A, left, mid);
		MergeSort(A, mid, right);
		Merge(A, left, mid, right);
	}
}

int main() {
	int n, input;
	cin >> n;
	vector<int> A;
	for(int i=0; i<n; i++){
		cin >> input;
		A.push_back(input);
	}

	MergeSort(A, 0, n);
	writeVector(A);
	cout << "\n";
	cout << n_comparison << "\n";

	return 0;
}



Measured memory_bytes: 6752
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX],ans[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);

    ll x,y;
    cin>>x>>y;
    if((x%2)!=(y%2)){
        cout<<"IMPOSSIBLE"<<endl;
    }
    else{
        cout<<(x+y)/2<<endl;
    }




    return 0;
}


Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

void first() {
	print("First"); exit(0);
}
void second() {
	print("Second"); exit(0);
}
void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	if (N & 1) {
		int sum = 0;
		REP(i, N)sum += A[i];
		if (sum & 1) {
			first();
		}
		else second();
	}
	else {
		int sum = 0;
		REP(i, N)sum += A[i];
		int mn = 1e18;
		REP(i, N)chmin(mn, A[i]);
		if (mn & 1) {
			first();
		}
		else {
			if (sum & 1)first();
			else second();
		}
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}




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

using namespace std;

int main()
{
	int t; cin >> t;
	bool approved = true;
	while (t--) {
		int a; cin >> a;
		if (a % 2 == 0) {
			if (a % 3 != 0 && a % 5 != 0) {
				approved = false;
			}
		}
	}
	if (approved) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
const ll maxn=2e5+10;


int main() {
	fast;
	int t,n,i,j,k;
	cin>>i>>j>>k;
	cout<<k<<" "<<i<<" "<<j<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

int daycount(int y, int m, int d) {
	int res = 0;
	
	y--;
	res += y / 3 * 590;
	y %= 3;
	res += y * 195;
	
	if (y == 2) res += 20 * (m - 1) + d;
	else {
		if (m & 1) {
			res += 39 * (m / 2);
		}
		else {
			res += 20 + 39 * (m/ 2 - 1);
		}
		res += d;
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		int y, m, d;
		scanf("%d %d %d", &y, &m, &d);
		if (debug) printf("@ ");
		
		cout << daycount(1000, 1, 1) - daycount(y, m, d) << endl;
		
	}
	return 0;
}


Measured memory_bytes: 3144
s = input()
t = input()


# def judge(s, t):
#     s = sorted(s)
#     t = sorted(t)[::-1]
#     N = len(s)
#     M = len(t)
#
#     org_t = sorted(t)
#     if s == org_t:
#         return False
#
#     if N < M and s[:N] == org_t[:N]:
#         return True
#
#     min_len = min(N, M)
#     for a, b in zip(s[:min_len], t[:min_len]):
#         if a == b:
#             continue
#         return a < b
#     # M の方が小さくて途中まで同じだったら最終的にFalse
#     return False

# if judge(s, t):
#     print('Yes')
# else:
#     print('No')

s = ''.join(sorted(s))
t = ''.join(sorted(t))[::-1]
if s < t:
    print('Yes')
else:
    print('No')


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int ans[400*400+1];

struct UnionFind {
    vector<int> v;
    UnionFind(int N) :v(N, -1) {}
    int root(int x) {
        if (v[x] < 0) return x;
        else return v[x] = root(v[x]);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (v[x] > v[y]) swap(x, y);
        v[x] += v[y];
        v[y] = x;
    }
    int size(int x) {
        return -v[root(x)];
    }
};

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

bool ok(int h, int w, int x, int y) {
    return 0 <= x and x < w and 0 <= y and y < h;
}

ll kuro[400*400+2];
ll siro[400*400+2];

int main() {
    int H, W;
    cin >> H >> W;
    string s[500];
    rep(i, H) cin >> s[i];

    UnionFind uf(H*W);
    rep(r, H) rep(c, W) {
        if (s[r][c] == '#') {
            rep(d, 4) {
                int nr = r + dy[d], nc = c + dx[d];
                if (ok(H, W, nc, nr) and s[nr][nc] == '.') uf.unite(r*W+c, nr*W+nc);
            }
        }
    }

    //cout << uf.same(0, 2) << endl;

    rep(r, H) rep(c, W) {
        if (s[r][c] == '.') siro[uf.root(r*W+c)]++;
        else kuro[uf.root(r*W+c)]++;
    }

    ll ret = 0;
    rep(r, H) rep(c, W) {
        ret += siro[r*W+c]*kuro[r*W+c];
    }
    cout << ret << endl;
}


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

int main() {
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	rep(i,n) cout << s[i] << t[i];
	return 0;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int64_t N;
    cin >> N;

    int64_t dp[61][3] = {0};
    dp[60][0] = 1;

    for(int d=59; d>=0; d--){
        for(int s=0; s<=2; s++){
            for(int k=0; k<=2; k++){
                int s2 = min(2, 2*s + nth_bit(N, d) - k);
                if(s2 >= 0) add(dp[d][s2], dp[d+1][s]);
            }
        }
    }

    int64_t ans = (dp[0][0] + dp[0][1] + dp[0][2]) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stack>

using namespace std;

int main() {

    string x;
    stack<char> st;
    cin >> x;
    
    for (int i = 0; i < x.size(); i++) {
    	char ch = x[i];

    	if(ch=='S') {
    		st.push(ch);
    	}else if(ch=='T') {
    		if(!st.empty()){
				if(st.top()=='S'){
					st.pop();
				}else{
					st.push(ch);
				}
			}else{
				st.push(ch);
			}

    	}
    }

    cout<<st.size()<<endl;

    return 0;

 }




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

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

	vector<long long> aArray(n);
	for (int i = 0; i < n; ++i) {
		cin >> aArray[i];
	}

	sort(aArray.begin(), aArray.end());

	vector<pair<int, long long>> bcArray(m);
	for (int i = 0; i < m; ++i) {
		cin >> bcArray[i].first >> bcArray[i].second;
	}

	sort(bcArray.begin(), bcArray.end(), [](pair<int, long long> x, pair<int, long long> y) {return x.second > y.second; });

	const size_t numOfBCArray = bcArray.size();
	int aMinIndex = 0;
	long long aMin = aArray[0];
	bool isFinished = false;
	for (int i = 0; i < numOfBCArray; ++i) {
		for (int j = 0; j < bcArray[i].first; ++j) {
			if (aMin < bcArray[i].second) {
				aArray[aMinIndex] = bcArray[i].second;
				if (aMinIndex == n - 1) {
					isFinished = true;
					break;
				}
				++aMinIndex;
				aMin = aArray[aMinIndex];			}
			else {
				isFinished = true;
				break;
			}
		}
		if (isFinished) {
			break;
		}
	}

	long long ret = 0;
	for (int j = 0; j < n; ++j) {
		ret += aArray[j];
	}

	cout << ret << endl;

	return 0;
}

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

typedef long long ll;
#define int         ll
typedef vector<int> vi;
#define test        int t; cin >> t; while(t--)
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
const int mod = 1000000007;
map<char,int> mp;
map<int,char> mp1;
int give(char ch1, char ch2) {
    int r = 0, g = 0, b = 0;

    if (ch1 == 'R') r++;
    if (ch1 == 'G') g++;
    if (ch1 == 'B') b++;


    if (ch2 == 'R') r++;
    if (ch2 == 'G') g++;
    if (ch2 == 'B') b++;

    if (r == 1 && g == 1) return 2;
    if (r == 1 && b == 1) return 1;
    if (g == 1 && b == 1) return 0;
}

int32_t main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    mp['R']=0;mp['G']=1;mp['B']=2;
    mp1[0]='R';mp1[1]='G';mp1[2]='B';

    int n;
    string s;
    cin >> n >> s;

    int cnt = 0;

    vector<vector<int>> dp(n + 1, vector<int>(3));
    int r = 0, g = 0, b = 0;

    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == 'R') {
            r++;
        } else if (s[i] == 'G') {
            g++;
        } else {
            b++;
        }
        dp[i][0] = r;
        dp[i][1] = g;
        dp[i][2] = b;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n - 1; ++j) {

            if (s[i] == s[j]) continue;

            int d = j - i;
            int ch = give(s[i], s[j]);
            int num = 0;

            num += dp[j + 1][ch];

            if (j + d < n && s[j+d]==mp1[ch]) {
                num--;
                cnt += num;
            } else {
                cnt += num;
            }
        }
    }

    cout << cnt;
    return 0;
}

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

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

using namespace std;
using lint=long long;

int main(){
	int n;
	lint k; scanf("%d%lld",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	a.emplace_back(2e5+1);
	a.emplace_back(2e5+1);
	n+=2;

	vector<int> next(n);
	{
		vector<int> first(2e5+2,-1);
		rep(i,n) if(first[a[i]]==-1) first[a[i]]=i;

		vector<int> nearest(2e5+2,-1);
		for(int i=n-1;i>=0;i--){
			if(nearest[a[i]]==-1){
				next[i]=(first[a[i]]+1)%n;
			}
			else if(nearest[a[i]]==n-1){
				next[i]=0;
			}
			else{
				next[i]=next[nearest[a[i]]+1];
			}
			nearest[a[i]]=i;
		}
	}

	int per;
	for(int p=next[0],t=1;;p=next[p],t++) if(p==0) { per=t; break; }

	int p=0;
	rep(i,(k-1)%per) p=next[p];

	// simulate
	vector<int> ans;
	vector<bool> used(2e5+2);
	for(;p<n;p++){
		if(!used[a[p]]){
			ans.emplace_back(a[p]);
			used[a[p]]=true;
		}
		else{
			while(1){
				int x=ans.back();
				ans.pop_back();
				used[x]=false;
				if(x==a[p]) break;
			}
		}
	}
	rep(i,ans.size()) printf("%d%c",ans[i],i+1<ans.size()?' ':'\n');

	return 0;
}


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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define rrep(i,a,b)	for(int i=(int)a;i>=(int)b;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LL long long
const int MX = 1e5+1;
const int MOD = 1e9+7;

int main()
{
	FASTIO;
	LL a,b,c;
	cin>>a>>b>>c;
	if(b>=c)
		cout<<b+c;
	else if(a+b<c)
		cout<<2*b+a+1;
	else
		cout<<b+c;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int a,b,x;
    scanf("%d%d%d",&a,&b,&x);
    double checker=(1.0*x)/(1.0*pow(a,2));
    if (checker<((1.0*b)/(2.0)))
    {
        double angle1=atan2(2*x,a*pow(b,2));
        angle1=angle1*180/3.141592653589793;
        cout<<fixed<<setprecision(10)<<(90.0-angle1)<<endl;
        return 0;
    }
    double val1=1.0*(a/2.0);
    double val2=1.0*(b-1.0*(x/(1.0*pow(a,2))));
    double angle=atan2(val1,val2);
    angle=angle*180/3.141592653589793;
    cout<<fixed<<setprecision(10)<<(90.0-angle)<<endl;
    return 0;
}

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    VI v(n);
    rep(i, n) cin >> v[i];
    sort(ALL(v));
    if (v[n - 1] - v[0] > 1)
    {
        cout << "No" << endl;
        return 0;
    }
    int low = v[0];
    int high = v[n - 1];
    if (high == low && low == n - 1)
    {
        cout << "Yes" << endl;
        return 0;
    }
    int highnum = 0;
    int lownum = 0;
    rep(i, n)
    {
        if (v[i] == high)
            highnum++;
    }
    lownum = n - highnum;
    cerr << high << " " << low << " " << highnum << " " << lownum << endl;
    if (high - lownum <= 0)
    {
        cout << "No" << endl;
        return 0;
    }
    if (2 * (high - lownum) <= highnum)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

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;
}

int main(){
    ll K;
    cin >> K;
    vector<ll> A(K);
    rep(i,K){
        cin >> A[i];
    }
    reverse(A.begin(),A.end());
    ll lb=2,ub=2;
    bool can=true;
    rep(i,K){
        lb=(lb+A[i]-1)/A[i]*A[i];
        ub=(ub/A[i]+1)*A[i];
        if (lb==ub){
            can=false;
            break;
        }
        ub--;
    }
    if (can){
        cout << lb << ' ' << ub << endl;
    }
    else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
struct no
{  int p,l,r;
};
no a[1000];
int n,root;
int max(int a,int b)//比大小 
{  if(a>=b)  return a;
   else return b;
}
int de(int u)//求深度 
{  int d=0;
   if(u==root) return 0;
   while(a[u].p!=-1)
   {  u=a[u].p;
	  d++;
   }
   return d;
}
int pp(int u)//求父结点 
{  if(a[u].p!=-1)  return a[u].p;
   else return -1;
}
int hh(int u)//求高度 
{  if(u==-1)  return 0;
   if(a[u].l==-1&&a[u].r==-1) return 1;
   return max(hh(a[u].l),hh(a[u].r))+1;
}
int bro(int u)//求兄弟结点 
{  int t=u;
   if(a[u].p!=-1)  u=a[u].p;
   else return -1;
   if(a[u].l==t&&a[u].r!=-1)  return a[u].r;
   else if(a[u].l!=t&&a[u].r!=-1)  return a[u].l;
   else if(a[u].l==t&&a[u].r==-1)  return -1;
   else if(a[u].r==t&&a[u].l==-1)  return -1;
}
int kind(int u)
{  if(u==root)  return 1;//根 
   else if(a[u].p!=-1&&(a[u].l!=-1||a[u].r!=-1)) return 2;//内部
   else if(a[u].l==-1&&a[u].r==-1)   return 3;//叶 
}
int gg(int u)
{  if(a[u].l==-1&&a[u].r==-1)  return 0;
   else if(a[u].l!=-1&&a[u].r!=-1)  return 2;
   else return 1;
}
int main()
{  int i,t,v,r,l;
   scanf("%d",&n);
   for(i=0;i<n;i++)
     a[i].p=-1;
   for(i=0;i<n;i++)
   {  scanf("%d%d%d",&v,&l,&r);
      a[v].l=l;
      a[v].r=r;
      if(l!=-1)  a[l].p=v;
      if(r!=-1)  a[r].p=v;
   }
   for(i=0;i<n;i++)//求根结点 
     if(a[i].p==-1)  root=i;
   for(i=0;i<n;i++)
   {  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "
      ,i,pp(i),bro(i),gg(i),de(i),hh(i)-1);
      if(kind(i)==1)  printf("root\n");
      else if(kind(i)==2)  printf("internal node\n");
      else if(kind(i)==3)  printf("leaf\n");
   }
   return 0;
} 


Measured memory_bytes: 2732
#include <stdio.h>

int main(void){
    int N,L;
    scanf("%d %d",&N,&L);
    int taste=0;
    if(L<=0 && L+N-1>=0){
        for(int i=1;i<=N;i++){
            taste+=L+i-1;
        }
    }
    else if(L+N-1<0){
        for(int i=1;i<=N-1;i++){
            taste+=L+i-1;
        }
    }
    else{
        for(int i=2;i<=N;i++){
            taste+=L+i-1;
        }
    }
    printf("%d\n",taste);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
map<char, int> used;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	used[s[0]]++;
	used[s[1]]++;
	used[s[2]]++;
	if(used['A'] && used['B'])cout << "Yes"; else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define INF 1 << 30
using namespace std;

int dis(int a, int b, int n){
  //  printf("%d\n", n);
  int ax = a % n, ay = a / n;
  int bx = b % n, by = b / n;
  //  printf("%d %d %d %d\n", ax, ay, bx, by);
  return abs(ax-bx) + abs(ay-by);
}

int main(){
  int n, a, b, c, d, res = INF;
  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  a--;b--;c--;d--;
  for(int i = 1; i <= n; i++)
    res = min(res, dis(a, b, i) + dis(c, d, i));
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1188
import java.util.*;
//import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(a==0 && b==0) break;
            for(int i=0;i<a;i++){
                for(int j=0;j<b;j++) System.out.print("#");
                System.out.println();
            }
            System.out.println();
        }
        sc.close();
    }
}


Measured memory_bytes: 35104
import sys
input = sys.stdin.readline

N = int(input())
H = list(map(int, input().split()))

H = H[::-1]
ans = 'Yes'
for i in range(N-1):
    #print(i, H[i], H[i+1])
    if H[i] < H[i+1]:
        if H[i] == H[i+1] - 1:
            H[i+1] -= 1
            continue
        else:
            ans = 'No'

print(ans)

Measured memory_bytes: 14168
a, b, c, x, y = [int(item) for item in input().split()]
c *= 2

gA_B = x * a + y * b
gAB = max(x,y) * c
if y > x:
  gAB_B = x * c + (y-x) * b
else:
  gAB_B = gAB
if x > y:
  gA_AB = (x-y) * a + y * c
else:
  gA_AB = gAB
  
print(min(gA_B, gAB, gA_AB, gAB_B))
  

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

int color[maxn], p[maxn], vis[maxn];
int head[maxn], cnt;
vector<int> r, b;

int n;

struct node {
    int v, next;
} e[maxn << 1];

void init() {
    cnt = 0;
    memset(head, -1, sizeof(head));
}

void add(int u, int v) {
    e[cnt].v = v;
    e[cnt].next = head[u];
    head[u] = cnt++;
}

void dfs(int u, int c) {
    color[u] = c;
    if (c == 1) r.push_back(u);
    else b.push_back(u);
    for (int i = head[u]; ~i; i = e[i].next) {
        int v = e[i].v;
        if (!color[v]) dfs(v, -c);
    }
}

void solve() {
    int pos = 1;
    for (int i = 1; i <= n; i++) {
        if (!p[i]) {
            while (vis[pos]) {
                pos++;
            }
            p[i] = pos;
            vis[pos] = 1;
        }
    }
}

int main(void) {
    FAST_IO;
    init();
    
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        add(u, v);
        add(v, u);
    }
    dfs(1, 1);
    if (r.size() > b.size()) {
        swap(r, b);
    }
    if (r.size() <= n / 3) {
        int k = 0;
        for (auto &x : r) {
            k++;
            if (k * 3 > n) break;
            p[x] = k * 3;
            vis[k * 3] = 1;
        }
        solve();
    } else {
        int k = -1;
        for (auto &x : r) {
            k++;
            if (k * 3 + 1 > n) break;
            p[x] = k * 3 + 1;
            vis[k * 3 + 1] = 1;
        }
        k = -1;
        for (auto &x : b) {
            k++;
            if (k * 3 + 2 > n) break;
            p[x] = k * 3 + 2;
            vis[k * 3 + 2] = 1;
        }
        solve();
    }
    for (int i = 1; i <= n; i++) {
        cout << p[i] << " ";
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 15348
import java.util.Scanner;
public class Main
{
	public static void main(String args[])
	{
		int i=1, n;
		Scanner input = new Scanner(System.in);
		while(true)
		{
			n = input.nextInt();
			if(n == 0){
				break;
			}
			else {
				System.out.println("Case " + i + ": " + n);
			}
			i++;
		}
	}
}

Measured memory_bytes: 44856
sp = gets.chomp
t = gets.chomp
n = sp.size
m = t.size

if n < m
  puts "UNRESTORABLE"
else
  res = -1
  i = 0
  while i <= n - m
    cnt = 0
    while cnt < m && (sp[i + cnt] == "?" || sp[i + cnt] == t[cnt])
      cnt += 1
    end
    
    if cnt == m
      res = i
    elsif sp[i] == "?"
      sp[i] = "a"
    end
    i += 1
  end
  
  if res == -1
    puts "UNRESTORABLE"
  else
    res = sp[0...res] + t + sp[(res + m)...n]
    res.gsub!(/\?/, "a")
    puts res
  end
end

Measured memory_bytes: 14372
n = input()
a = input()
b = input()
c = input()
cnt = 0
for i,j,k in zip(a,b,c):
    if i == k:
        pass
        if i == j:
            pass
        else:
            cnt += 1
    else:
        cnt += 1
        if i == j:
            pass
        else:
            if j == k:
                pass
            else:
                cnt += 1
print(cnt)


Measured memory_bytes: 2940
def collatz(n):
	c = 1
	check = [n]
	while(True):
		c += 1
		if n & 1 == 0:
			n = n // 2
			if n in check:
				break
			check.append(n)
		else:
			n = (n * 3) + 1
			if n in check:
				break
			check.append(n)
	return c
n = int(input())
print(collatz(n))

Measured memory_bytes: 9088
//
//  main.cpp
//  ABC123
//
//  Created by hiroaki on 2019/04/16.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v;
int set(int food){
    v.push_back(10-food%10);
    int r =food+(10-food%10);
    return r;
}
int main() {
//    int a,b,c,d,e,k;
//    cin >>a>>b>>c>>d>>e>>k;
//    int flag = 0;
//    if (abs(a-b)>k) {
//        flag = 1;
//    }
//    if (abs(a-c)>k) {
//        flag = 1;
//    }
//    if (abs(a-d)>k) {
//        flag = 1;
//    }
//    if (abs(a-e)>k) {
//        flag = 1;
//    }
//    if (abs(b-c)>k) {
//        flag = 1;
//    }
//    if (abs(b-d)>k) {
//        flag = 1;
//    }
//    if (abs(b-e)>k) {
//        flag = 1;
//    }
//    if (abs(c-d)>k) {
//        flag = 1;
//    }
//    if (abs(c-e)>k) {
//        flag = 1;
//    }
//    if (abs(d-e)>k) {
//        flag = 1;
//    }
//    if(flag==1){
//        cout<<":("<<endl;
//    }else{
//        cout<<"Yay!"<<endl;
//    }
    int a,b,c,d,e;
    cin >>a>>b>>c>>d>>e;
//    int set(int food){
//        v.push_back(10-food%10);
//        food=food+(10-food%10);
//        return food;
//    }
    if (a%10!=0) {
        a=set(a);
    }
    if (b%10!=0) {
        b=set(b);
    }
    if (c%10!=0) {
        c=set(c);
    }
    if (d%10!=0) {
        d=set(d);
    }
    if (e%10!=0) {
        e=set(e);
    }
    int maxv=0;
    if(v.size()>0){
        maxv=*max_element(v.begin(), v.end());
    }
    cout<<a+b+c+d+e-maxv<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<long,long> ll;

ll arr[100003];
long pref1[100003], pref2[100003], pref3[100003], pref4[100003];
long mx1[100003], mx2[100003], mx3[100003], mx4[100003];

const long SMALL = -1e18;

int main()
{
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	int n; long c; 
	scanf("%d %lld", &n, &c);
	for(int i = 1; i <= n; i++)
	{
		scanf("%lld %lld", &arr[i].fi, &arr[i].se);
	}
	sort(arr, arr+n);
	for(int i = 0; i <= n+1; i++)
		mx1[i] = mx2[i] = mx3[i] = mx4[i] = SMALL;

	for(int i = 1; i <= n; i++)
	{
		pref1[i] = pref1[i-1] + arr[i].se;
		pref3[i] = pref3[i-1] + arr[i].se;
	}
	for(int i = 1; i <= n; i++)
	{
		pref1[i] -= arr[i].fi;
		pref3[i] -= 2*arr[i].fi;
		mx1[i] = max(mx1[i-1], pref1[i]);
		mx3[i] = max(mx3[i-1], pref3[i]);
	}
	for(int i = n; i >= 1; i--)
	{
		pref2[i] = pref2[i+1] + arr[i].se;
		pref4[i] = pref4[i+1] + arr[i].se;
	}
	for(int i = n; i >= 1; i--)
	{
		pref2[i] -= c-arr[i].fi;
		pref4[i] -= 2*(c-arr[i].fi);
		mx2[i] = max(mx2[i+1], pref2[i]);
		mx4[i] = max(mx4[i+1], pref4[i]);
	}
	// for(int i = 1; i <= n; i++) printf("%lld ", pref1[i]); printf("\n");
	// for(int i = 1; i <= n; i++) printf("%lld ", pref2[i]); printf("\n");
	// for(int i = 1; i <= n; i++) printf("%lld ", pref3[i]); printf("\n");
	// for(int i = 1; i <= n; i++) printf("%lld ", pref4[i]); printf("\n");

	long res = 0;
	res = max(res, mx1[n]);
	res = max(res, mx2[1]);
	for(int i = 1; i < n; i++)
	{
		res = max(res, mx1[i]+mx4[i+1]);
		res = max(res, mx2[i+1]+mx3[i]);
	}
	printf("%lld\n", res);
}





Measured memory_bytes: 8064
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
	Scanner sc= new Scanner(System.in);
	
	String str = sc.next();
	String line = str.substring(str.indexOf("A"), str.lastIndexOf("Z"));
	System.out.println(line.length()+1);
	
	}
}


Measured memory_bytes: 26576
#include<stdio.h>
int main(void)
{
	int a, b,c, p;
	scanf("%d %d", &a, &p);
	b = 3 * a;
	c = b + p;
	if (c % 2 == 0)
		printf("%d", c / 2);
	else
		printf("%d", (c - 1) / 2);
	return 0;

}

Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <algorithm>

bool is_included(const std::vector<int> & src, int value) {
    int left { 0 };
    int right { static_cast<int>(src.size()) };

    while (left < right) {
        const auto mid { (left + right) / 2 };
        if (src[mid] == value) {
            return true;
        }
        if (value < src[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }

    return false;
}

long solve(const std::vector<int> & s, const std::vector<int> & t) {
    return std::count_if(t.begin(), t.end(), [&] (int v) { return is_included(s, v); });
}

int main() {
    int n;
    std::cin >> n;
    std::vector<int> s;
    for (int i = 0; i < n; ++i) {
        int si;
        std::cin >> si;
        s.push_back(si);
    }

    int q;
    std::cin >> q;
    std::vector<int> t;
    for (int i = 0; i < q; ++i) {
        int ti;
        std::cin >> ti;
        t.push_back(ti);
    }

    std::cout << solve(s, t) << std::endl;
    return 0;
}




Measured memory_bytes: 3552
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    ll cnt=0;
    ll f=5;
    int chet=1;
    while (f<=n&&chet<=26)
    {
        ll q=n/f;
        if (n%2==0)
        cnt+=(q)/2;
        else
            cnt+=(q+1)/2;
        f*=5;
        chet++;
    }
    ll cnt2=0;
    f=2;
    chet=1;
    if (n%2==0){
    while (f<=n&&chet<64)
    {
        cnt2+=n/f;
        f*=2;
        chet++;
    } }
    cout<<min(cnt2,cnt);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (__typeof(n) i = 0; i < n; i++)
#define repo(i, n) for (__typeof(n) i = 1; i <= n; i++)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define a(a)         \
    for (auto i : a) \
        cout << i << " ";
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main()
{

    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll l = 0, r = 0;
    rep(i, n)
    {
        if (s[i] == 'R')
            r++;
        else
            l++;
    }
    if (r > l)
        c("Yes") else c("No")
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(){
    long long N;
    cin >> N;
    long long ans = 1e18;
 for(long long (i)=1;i*i<=N;(i)++){
     if( N%i == 0 ) {
      long long j = N/i ;
      ans = min(ans,i+j-2);
     }
 }
  
 cout << ans << endl;
}


Measured memory_bytes: 256
import math
import sys
from itertools import permutations
input = sys.stdin.readline

p = 1000000007
n = int(input())
v = list(map(int, input().split()))

s = sum(v)
ss = 0
for i in range(n):
    ss += (v[i] * v[i])

ans = (s*s - ss) // 2
print(ans % p)

Measured memory_bytes: 91976
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int n = sc.nextInt();
			if (n == 0) break;
			int five = 0;
			int two = 0;
			for (int i = 1; i <= n; i++)
			{
				two += factorization(i, 2);
				five += factorization(i, 5);
			}
			System.out.println(Math.min(five, two));
		}
	}
	private static int factorization(int n, int a)
	{
		int count = 0;
		while (n % a == 0)
		{
			count++;
			n /= a;
		}
		return count;
	}
}

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

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

long modpow(long a, long n, long mod){
	if (n == 0) {
		return 1;
	}
	long answer;
	if (n%2 == 0) {
		answer = modpow(a, n/2, mod);
		answer *= answer;
	} else {
		answer = modpow(a, n-1, mod);
		answer *= a;
	}
	answer %= mod;
	return answer;
}

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  qsort(a, n, sizeof(long), cmpnum);
  long mod = pow(10,9)+7;
  long i_max,i_min;
  long max,min;
  long set = 1;
  long margin = 0;
  long max_sum = 0;
  long min_sum = 0;
  for (i_max = n-k; i_max >= 0; i_max--) {
    i_min = n-1-i_max;
    a[i_max] = (a[i_max]+mod)%mod;
    max = set*a[i_max];
    max %= mod;
    max_sum += max;
    max_sum %= mod;
    a[i_min] = (a[i_min]+mod)%mod;
    min = set*a[i_min];
    min %= mod;
    min_sum += min;
    min_sum %= mod;
    if (i_max == 0) {
      break;
    }
    margin++;
    set *= k+margin-1;
    set %= mod;
    set *= modpow(margin,mod-2,mod);
    set %= mod;
  }
  long ans = max_sum-min_sum+mod;
  ans %= mod;
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 1660
using System;

namespace ITP1_1_A
{
    class Program
    {
        
        static void Main(string[] args)
        {
            string Line = Console.ReadLine();

            char[] cs = Line.ToCharArray();

            for (int i = 0; i < cs.Length; i++)
            {
                if (char.IsUpper(cs[i]))
                {
                    cs[i] = char.ToLower(cs[i]);
                }
                else if (char.IsLower(cs[i]))
                {
                    cs[i] = char.ToUpper(cs[i]);
                }
            }
            string outputLine = new string(cs);

            Console.WriteLine(outputLine);
        }
    }
}



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

int main()
{
  char o[255],e[255];
  int i=0;

  std::cin >> o >>e;

  while(1){
    if(o[i]=='\0')
      break;
    printf("%c",o[i]);
    if(e[i]=='\0')
      break;
    printf("%c", e[i]);
    i++;
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int arr[3];

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

    sort(arr, arr+3);

    if (arr[2] == arr[1]+arr[0]) cout << "Yes";
    else cout << "No";

    return 0;
}



Measured memory_bytes: 256
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    int xx,yy,zz;
    xx = z;
    yy = x;
    zz = y;

    cout << xx << " " << yy << " " << zz << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DFlippingSigns solver = new DFlippingSigns();
        solver.solve(1, in, out);
        out.close();
    }

    static class DFlippingSigns {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            long answer = 0;
            int negative = 0;
            for (long x : a) {
                if (x < 0) {
                    negative++;
                }
            }

            long min = Long.MAX_VALUE;
            for (long x : a) {
                answer += Math.abs(x);
                min = Math.min(min, Math.abs(x));
            }
            if (negative % 2 == 1) {
                answer -= 2 * min;
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 41960
#include <iostream>

using namespace std;

int main(){
    int n;
    int score1=0, score2=0;
    cin >> n;
    
    for(int i=0;i<n;i++){
        string str1, str2;
        int l, l1, l2;
        cin >> str1 >> str2;
        l1 = str1.size();
        l2 = str2.size();
        
        if(l1==l2){
            for(int j=0;j<l2;j++){
                if(str1[j]==str2[j]){
                    if(j==l2-1){
                        score1 += 1;
                        score2 += 1;
                        break;
                    }
                    continue;
                }
                else if(str1[j] > str2[j]){
                    score1 += 3;
                    break;
                }
                else{
                    score2 += 3;
                    break;
                }
            }
        }
        
        else if(l1 > l2){
            for(int j=0;j<l2;j++){
                if(str1[j]==str2[j]){
                    if(j==l2-1){
                        score1 += 3;
                        break;
                    }
                    continue;
                }
                else if(str1[j] > str2[j]){
                    score1 += 3;
                    break;
                }
                else{
                    score2 += 3;
                    break;
                }
            }
        }
        
        else{
            for(int j=0;j<l1;j++){
                if(str1[j]==str2[j]){
                    if(j==l1-1){
                        score2 += 3;
                        break;
                    }
                    continue;
                }
                else if(str1[j] > str2[j]){
                    score1 += 3;
                    break;
                }
                else{
                    score2 += 3;
                    break;
                }
            }
        }
        //cout << score1 << " " << score2 << endl;
    }
    cout << score1 << " " << score2 << endl;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  int A, B;
  cin >> A >> B;
  int C, D;
  cin >> C >> D;
  int E, F;
  cin >> E >> F;

  double conc = -1.0;
  int ans_water;
  int ans_suger;
  repp(a, 0, 30) {
    repp(b, 0, 15) {
      if (a == 0 && b == 0)
        continue;
      int water = 100 * A * a + 100 * B * b;
      if (water > F)
        break;

      int max_suger = min(F - water, water * E / 100);

      repp(c, 0, max_suger) {
        if (c * C > max_suger)
          break;
        int d = (max_suger - C * c) / D;
        int suger = c * C + d * D;

        double conc_temp = (double)suger / (suger + water);
        if (chmax(conc, conc_temp)) {
          ans_water = water;
          ans_suger = suger;
        }
      }
    }
  }
  cout << ans_water + ans_suger << ' ' << ans_suger << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	int n;
	cin>>n;
	int a,b;
	long long int sum=0;
	cin >> a;
	rep(i,n-1){
		cin >> b;
		a=max(a,b);
		sum+=a-b;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  int ans = 0;
  
  for(int i = 1; i <= n; i++){
    if(i <= k){
      ans += x;
    } else {
      ans += y;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)

int main(){
    int N;
    cin >> N;
    string s,t;
    cin >> s >> t;
    int pop = 0;
    rep(i,N){
        if(s.substr(i,N-i) == t){
            cout << s.size() + pop << endl;
            return 0;
        }
        else t.pop_back(),++pop;
    }
    cout << 2*N << endl;
}

Measured memory_bytes: 256