akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int n, x, s = 0;
	char p;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> p >> x;
	    if(p == '(')s += x;
		else s -= x;
		if(s < 0){
			cout << "NO" << endl;
			return 0;
		}
	}
	if(s == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}

vector<ll> divv(ll n);
int main() {
    ll n,r,g,b;

    cin>>r>>g>>b>>n;
    ll mr = (n/r) + 1;
    ll mg = (n/g) + 1;
    ll s =  0;

    rep(i, mr+1) {
        ll u = n;
        u -= i * r;
        if(u<0) continue;
        if(u==0){
            s++;
            continue;
        }
        rep(j, mg+1){
            ll uu = u;
            uu -= j * g;
            if(uu<0) continue;
            if(uu==0){
                s++;
                continue;
            }
            ll aa = uu % b;
            if(aa == 0) s++;
        }

    }
    pr(s);
    
    return 0;
}

vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n){
          v.push_back(n/i);
      }
    }
  }
  sort(alll(v));
  return v;
}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(a, b);
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int x,y,a;

int main(){
	scanf("%d%d",&x,&y);
	for(int i = 0;i <= x;i++){
		if(i*2 + (x-i)*4 == y) return puts("Yes"),0;
	}
	puts("No");
}


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

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

    vector<vector<int>> G(N);    // 隣接リスト表現によるグラフ
    vector<pair<int, int>> E_in; // 辺の入力の順番を保持する

    for (int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        pair<int, int> p = make_pair(a, b);
        E_in.emplace_back(p);
    }

    queue<int> que;
    vector<int> used(N, 0);
    vector<int> parent(N, 0); // 親との間にある辺の数値
    int max_color = 0;
    map<pair<int, int>, int> E_num; // 辺への割り振った番号を保持する
    que.emplace(0); // 最初のものは何でも良いので0からにする
    used[0] = 1;
    while (que.size() != 0) {
        int state = que.front(); // 現在の状態

        que.pop();
        int color_num = 0;
        for (auto next : G[state]) {
            if (used[next] != 1) {
                color_num++;
                used[next] = 1;
                if (color_num == parent[state]) {
                    // 親との間にある辺と番号が被らないようにする
                    color_num++;
                }
                pair<int, int> p = make_pair(state, next);
                E_num[p] = color_num; //辺彩色
                parent[next] = color_num;
                que.push(next); //次の状態をqueueへ格納
            }
        }
        max_color = max(max_color, color_num);
    }

    cout << max_color << "\n";
    for (auto i : E_in) {
        cout << E_num[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 16596
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> plus, minus;
    rep(i,n){
        cin >> a[i];
        if(a[i] >= 0) plus.push_back(a[i]);
        else minus.push_back(a[i]);
    }
    int ps = plus.size(), ms = minus.size();
    bool canPositive = false;
    if(ps > 0){
        if(n == k){
            if(ms%2 == 0) canPositive = true;
            else canPositive = false;
        }
        else{
            canPositive = true;
        }
    }
    else{
        if(k%2 == 0) canPositive = true;
        else canPositive = false;
    }
    mint ans = 1;
    if(canPositive){
        sort(plus.begin(), plus.end());
        sort(minus.rbegin(), minus.rend());
        if(k%2 == 1){
            ans *= plus[ps-1];
            plus.pop_back();
            --ps;
        }
        vector<ll> positivePair;
        for(int i = ps-1; i >= 0; i-=2){
            if(i-1 >= 0) positivePair.push_back(plus[i] * plus[i-1]);
        }
        for(int j = ms-1; j >= 0; j-=2){
            if(j-1 >= 0) positivePair.push_back(minus[j] * minus[j-1]);
        }
        sort(positivePair.rbegin(), positivePair.rend());
        rep(i,k/2) ans *= positivePair[i];
    }
    else{
        vector<P> absA;
        rep(i,n){
            if(a[i] >= 0) absA.push_back(P(a[i], a[i]));
            else absA.push_back(P(-a[i], a[i]));
        }
        sort(absA.begin(), absA.end());
        rep(i,k) ans *= absA[i].second;
    }
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 8384
sx, sy, tx, ty = map(int, input().split())

# 1回目の行きの最短経路
for i in range(ty-sy):
    print('U', end='')

for i in range(tx-sx):
    print('R', end='')

# 1回目の帰りの最短経路
for i in range(ty-sy):
    print('D', end='')

for i in range(tx-sx):
    print('L', end='')

# 2回目の行きの最短経路
print('L', end='')
for i in range(ty-sy+1):
    print('U', end='')

for i in range(tx-sx+1):
    print('R', end='')

print('D', end='')

# 2回目の帰りの最短経路
print('R', end='')
for i in range(ty - sy + 1):
    print('D', end='')

for i in range(tx - sx + 1):
    print('L', end='')

print('U', end='')


Measured memory_bytes: 4468
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;

int main()
{
    vector<int> A;
    for (int i=0; i<3; i++) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());

    int ans = 0;
    for (int i=1; i<3; i++) {
        ans += abs(A[i]-A[i-1]);
    }
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*
*   创 建 者： badcw
*   创建日期： 2019/12/28
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

ll n, m, v, p;
ll a[maxn];
#define X first
#define Y second
#define int ll

ll has[maxn];

int check(int idx) {
    int need = a[idx] + m;
    int needv = m * v;
    int rank = 1;
    for (int i = 1; i <= n; ++i) {
        if (i <= idx) {
            has[i] = 0;
            needv -= m;
        } else if (need < a[i]) {
            has[i] = 0;
            needv -= m;
            rank ++;
        } else {
            has[i] = m - (need - a[i]);
            needv -= (need - a[i]);
        }
    }
    if (rank > p) return 0;
    if (needv <= 0) return 1;
    for (int i = n; i >= 1; --i) {
        if (has[i]) {
            needv -= has[i];
            rank ++;
        }
        if (rank > p) return 0;
        if (needv <= 0) return 1;
    }
    return 0;
}

signed main(int argc, char* argv[]) {
    scanf("%lld%lld%lld%lld", &n, &m, &v, &p);
    for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
    sort(a + 1, a + 1 + n);
    int l = 1, r = n;
    int res = 0;
    while (l <= r) {
        int mid = l + r >> 1;
        if (check(mid)) {
            res = mid;
            r = mid - 1;
        } else l = mid + 1;
    }
    printf("%lld\n", n - res + 1);
    return 0;
}

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

# 0~N枚 => N+1, 合計の最大値はN*50
dp = [[[0] * (N*50+50) for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

# i枚目でk枚を選択、合計がk
for i in range(N) :
    for j in range(N) :
        for k in range(N*50):
            # 選択しない場合
            dp[i + 1][j][k] += dp[i][j][k]
            
            # 選択する場合
            dp[i + 1][j + 1][k + X[i]] += dp[i][j][k]

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][i*A]
    
print(ans)

Measured memory_bytes: 93404
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 400010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, a, b;
    cin >> n;
  if (n == 1) {
    cout << "Hello World";
  }
  else {
    cin >> a >> b;
    cout << a+b;
  }
   
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cctype>
#include<cstring>
using namespace std;



int main() {
	char s[202]; cin >> s;
	char p[101]; cin >> p;
	char s1[202];
	for (int i = 0; i < strlen(s); i++)s1[i] = s[i];

	strcat(s, s1);
	if (strstr(s, p))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF (ll)1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

void solve(int n) {
	vi v(n, 0);
	vi dist(n + 1, INF);
	vector<vector<bool>> dp(n + 1, vector<bool>(n, false));
	rep(i, n) {
		cin >> v[i];
	}
	for (int l = 2; l <= n; l += 2) {
		for (int i = 0; i + l <= n; i++) {
			bool b = false;
			if (l != 2) {
				for (int j = 2; j<l; j += 2) {
					if (dp[j][i] && dp[l - j][i + j])
						b = true;
				}
			}
			int dif = abs(v[i] - v[i + l - 1]);
			if (dif <= 1&&(l==2?1:dp[l-2][i+1]))b = true;
			if (b)dp[l][i] = true;
			//cout << l << " " << i << " " << dp[l][i] << endl;
		}
	}
	int pos = 0;
	deque<pii> q;
	q.push_back({ 0,0 });
	while (!q.empty()) {
		pii p = q.front(); q.pop_front();
		if (p.sc < dist[p.fs]) {
			dist[p.fs] = p.sc;
			if (p.fs == n) {
				cout << n - p.sc << endl;
				return;
			}
			for (int i = 2; i < n + 1; i += 2) {
				if (dp[i][p.fs]) {
					q.push_front({ p.fs + i,p.sc });
				}
			}
			q.push_back({ p.fs + 1 ,p.sc + 1 });
		}
	}

}

int main(void) {
	int n;
	while (cin >> n, n) {
		solve(n);
	}
}




Measured memory_bytes: 3012
N, *A = map(int, open(0).read().split())
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = 0
    for a in A:
        if a & mask:
            cnt += 1
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)


Measured memory_bytes: 136732
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    vector<string> s(n);
    for(auto& elem : s)  cin >> elem;

    map<string, lint> mp;
    for(lint i=0; i<n; i++) {
        mp[s[i]]++;
    }

    lint mx = -1;
    for(auto e : mp) {
        mx = max(mx, e.second);
    }

    vector<string> ans;
    for(auto e : mp) {
        if(e.second == mx)  ans.push_back(e.first);
    }

    sort(ans.begin(), ans.end());
    for(auto& e : ans)  cout << e << endl;
}

Measured memory_bytes: 28404
import sys
import itertools
import queue
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, K = read_values()
    R = N % K
    print(min(R, K - R))

if __name__ == "__main__":
    main()


Measured memory_bytes: 20536
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;
 
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;
}
using namespace std;

void solve(){
 int n;
 cin>>n;
 vector<int>l(n);
 rep(i,n){
   cin>>l[i];
 }
 sort(l.begin(),l.end());
 int ans=0;
 rep(i,n-2){
   for(int j=i+1;j<n-1;++j){
     int x=l[i]+l[j];
     auto itr=lower_bound(l.begin()+j+1,l.end(),x);
     ans+=distance(l.begin()+j+1,itr);
   }
 }
 cout<<ans<<"\n";
 return;
}
 
signed main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
  cout<<fixed<<setprecision(20);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	long long a[n], dp[n];
	for( int i=0; i<n; ++i )
		scanf("%lld",a+i), dp[i] = 1000000000000000000;
	dp[n-1] = 0;
	for( int i=n-1; i>=0; --i )
		for( int j=2; j>=1; --j )
			if( i+j <= n-1 )
				dp[i] = min(dp[i], dp[i+j] + abs(a[i]-a[i+j]));
	printf("%lld\n", dp[0] );
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <math.h>

typedef long long int ll;

using namespace std;

int main()
{
  ll A;
  string N, M, ans;
  cin >> A;
  cin >> N >> M;

  for (ll i = 0; i < N.size(); i++) {
    ans += N.at(i);
    ans += M.at(i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			s[i] = '9';
		}
		else if (s[i] == '9') {
			s[i] = '1';
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    int n; cin>>n;
    vector<ll> evn;
    vector<ll> odd;
    rep(i,0,n){
        ll x; cin>>x;
        if(i%2==0) evn.push_back(x);
        else odd.push_back(x);
    }
    reverse(all(odd));
    rep(i,0,evn.size()){
        odd.push_back(evn[i]);
    }
    if(n%2==1)reverse(all(odd));
    for(auto &i:odd) cout<<i<<" ";
    cout<<endl;
}

Measured memory_bytes: 4712
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
    int a, b, k;
    vector<int> l;
    
    cin >> a >> b >> k;

    for(int i = 1; i <= min(a, b); i++){
        if(a % i == 0){
            if(b % i == 0){
                l.push_back(i);
            }
        }
    }

    sort(l.rbegin(), l.rend());

    cout << l[k-1] << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
# input
    n = int(input())
    d = list(map(int, input().split()))

    ans = 0
    for i in range(n-1):
        for j in range(i+1, n):
            ans += d[i] * d[j]
    print(ans)

if __name__ == '__main__':
    main()


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

int factorial(int n){
  if(n==0) return 1;
  else return n*factorial(n-1);
}

int func(vector<int> p){
  int a = 1;
  vector<int> f(p.size());
  rep(i,p.size()-1){
    f[p[i]-1] = 1;
    int c = 0;
    rep(j,p[i]-1){
      if(f[j]==0) c++;
    }
    a+=c*factorial(p.size()-1-i);
  }
  return a;
}

int main(){
  int n;
  cin >>n;
  vector<int> p(n),q(n);
  rep(i,n) cin >>p[i];
  rep(i,n) cin >>q[i];
  int a=func(p);
  int b=func(q);
  cout << abs(a-b) << endl;
  return 0;
}

Measured memory_bytes: 256
<?php

$s=new Scanner();

$str=$s->next();

out::println(substr($str,0,1).(string)(strlen($str)-2).(substr($str,strlen-1)));






class Scanner
{
 private $arr = [];
 private $count = 0;
 private $pointer = 0;
 public function next() {
   if ($this->pointer >= $this->count) {
       $str = trim(fgets(STDIN));
       $this->arr = explode(' ', $str);
       $this->count = count($this->arr);
       $this->pointer = 0;
     }
      $result = $this->arr[$this->pointer];
      $this->pointer++;
      return $result;
  }
 public function hasNext(){
      return $this->pointer < $this->count;
  }
 public function nextInt(){
      return (int)$this->next();
  }
 public function nextDouble(){
      return (double)$this->next();
  }
}

#改行ありの標準出力クラス
class out
{
 public static function println($str = ""){
  echo $str . PHP_EOL;
 }
}

Measured memory_bytes: 3828
import java.util.*;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		Map<Integer, Boolean> A = new TreeMap<Integer, Boolean>();
		boolean ans = true;
      	int N = sc.nextInt();
		for (int i = 0; i < N; i++) {
			int temp = sc.nextInt();
			if (!A.containsKey(temp)) {
				A.put(temp, true);
			} else {
				ans = false;
				break;
			}
		}
		System.out.println(ans ? "YES" : "NO");
	}
}

Measured memory_bytes: 100060
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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 n,m;
    cin>>n>>m;
    vector<int>a(100005,0);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        a.at(x)++;
        a.at(y)++;
    }
    for(int i=0;i<100005;i++){
        if(a.at(i)%2==1){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;






    return 0;
}


Measured memory_bytes: 640
from collections import Counter
from itertools import product


def solve(LIST):
    S = 24
    slvtmp = [i for i, li in enumerate(LIST * 2) if li == 1]
    for i in range(1, len(slvtmp)):
        S = min(S, slvtmp[i] - slvtmp[i - 1])
    return S


n = int(input())
d = Counter(list(map(int, input().split())) + [0])

if any(d[num] > (2 - (num in {0, 12})) for num in d):
    print(0)
    exit()

ans, cnt = [0] * 24, []
for num in d:
    if (num in {0, 12}) and d[num] == 1:
        ans[num] = 1 
    elif d[num] == 2:
        ans[num], ans[24 - num] = 1, 1
    elif d[num] == 1:
        cnt.append(num)

s = 0
if len(cnt) == 0:
    s = max(s, solve(ans))
for bit in product([1, -1], repeat=len(cnt)):
    tmp = ans[:]
    for bi, ci in zip(bit, cnt):
        tmp[(ci - 12) * bi + 12] = 1
    s = max(s, solve(tmp))
print(s)


Measured memory_bytes: 74328
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int[] a=new int[n];
		int cnt=0;
		for(int i=0;i<n;i++) {
			a[i]=scanner.nextInt();
			if(a[i]%2==0) {
				cnt++;
			}
		}
		System.out.println((cnt==n)?"second":"first");
	}
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 24232
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
signed main()
{
    int a[100005];
    for(int i=0; i<100005; i++)
        a[i]=0;
    int n,q;
    cin>>n;
    int ans=0;

    for(int i=0; i<n; i++)
    {
        int c;
        cin>>c;
        a[c]++;
        ans+=c;
    }
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        int cha=c-b;
        ans+=cha*a[b];
        if(a[b]==0)
           {  cout<<ans<<endl;
               continue;
           }
        else
        {
            a[c]+=a[b];
            a[b]=0;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4400
"use strict";
function main(input) {
    const args = input.split('\n');

    const N = parseInt(args[0]);
    const A = parseInt(args[1]);
    const B = parseInt(args[2]);
    const C = parseInt(args[3]);
    const D = parseInt(args[4]);
    const E = parseInt(args[5]);

    const station = [A, B, C, D, E];
    let max_traf = Math.min(...station);
    console.log(Math.ceil(N / max_traf) + 4);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
//hpの解答例
int main(){
  int h,w;
  cin >> h >> w;
  string board[50];
  for(int i=0;i<h;i++) cin >> board[i];
  const int dx[8] = {1,0,-1,0,1,-1,-1,1};
  const int dy[8] = {0,1,0,-1,1,1,-1,-1};

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(board[i][j] == '#') continue;
      int num=0;
      for(int d=0;d < 8;d++){
        const int ni = i+dy[d];
        const int nj = j+dx[d];
     
        if(ni < 0 or h <= ni) continue;//範囲外
        if(nj < 0 or w <= nj) continue;//範囲外
        if(board[ni][nj] == '#') num++;
      }
    
    board[i][j] = char(num + '0');
    }
  }
  for(int i=0;i<h;i++) cout << board[i] << endl;
}
  
  


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

int main()
{
    long long L, R;
    std::cin >> L >> R;

    if (R - L >= 2019) {
        std::cout << 0 << std::endl;
        return 0;
    }

    long long l = L % 2019;
    long long r = R % 2019;

    long long min = 2019;
    for (long long i = l; i <= r; ++i) {
        if (i >= 2019)
            i -= 2019;
        for (long long j = i + 1; j <= r; ++j) {
            //std::cout << i << " " << j << std::endl;
            if (j >= 2019)
                j -= 2019;
            min = std::min(min, (i * j) % 2019);
        }
    }

    std::cout << min << std::endl;

    return 0;
}

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

using namespace std;

#define N 110000

struct Node {
    int l, r;
    bool operator < (Node u) {
        return r < u.r;
    }
}a[N];

int main() {
    int n, m;
    while (scanf("%d%d", &n, &m) == 2) {
        int res = 0, l, r;
        for (int i = 0; i < m; ++i) scanf("%d%d", &a[i].l, &a[i].r);
        sort(a, a + m);
        if (m > 0) res = 1;
        l = a[0].l; r = a[0].r;
        int i = 1;
        while (i < m) {
            if (a[i].r < r || a[i].l >= r) {
                l = a[i].l; r = a[i].r;
                res++;
            }
            ++i;
        }
        printf("%d\n", res);
    }
    return 0;
}


Measured memory_bytes: 1024
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

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

vector<long long> vertexs[200000];
int dist[200000];
int canwin[200000];
int dfs_dist(int now) {
    canwin[now] = 0;
    for (auto x : vertexs[now]) {
        if (dist[x] == -1) {
            dist[x] = dist[now] + 1;
            canwin[now] = max(canwin[now], dfs_dist(x));
        }
    }
    return canwin[now] + 1;
}
int dist2[200000];
int dfs(int now) {
    for (auto x : vertexs[now]) {
        if (dist2[x] == -1) {
            dist2[x] = dist2[now] + 1;
            dfs(x);
        }
    }
    return 0;
}
void solve() {
    long long n;
    cin >> n;
    int s, e;
    cin >> s >> e;
    s--; e--;
    REP(i, n) {
        dist[i] = -1;
        dist2[i] = -1;
    }
    REP(i, n-1) {
        long long a, b;
        cin >> a >> b;
        a--; b--;
        vertexs[a].push_back(b);
        vertexs[b].push_back(a);
    }
    dist[e] = 0;
    dfs_dist(e);
    dist2[s] = 0;
    dfs(s);
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        if (dist[i] > dist2[i]) {
            long long cost = dist[i] + canwin[i];
            ans = max(ans, cost);
        }
    }
    ans--;
    cout << ans << endl;
}

int main() {
    init();
    solve();
}

Measured memory_bytes: 12672
#include <stdio.h>
#include <stdlib.h>

typedef struct _node {
	int value;
	int forward;
	int backward;
	int chldNum;
	int *chldHead;
} node;

node *allocNode(int u, int k) {
	node *p = (node *)malloc(sizeof(node));
	p->value = u;
	p->forward = 0;
	p->backward = 0;
	p->chldNum = k;
	p->chldHead = k > 0 ? (int *)malloc(sizeof(int) * k) : NULL;
	return p;
}

void terminate(node **top, int n) {
	int i;
	for (i = 0; i < n; i++)	free(top[i]->chldHead);
	free(top);
}

void dfs(node **top, int u, int *time) {
	int i;
	node *p = top[u];
	if (p->forward > 0) return;
	p->forward = ++(*time);
	for (i = 0; i < p->chldNum; i++) {
		dfs(top, p->chldHead[i], time);
	}
	p->backward = ++(*time);
}

int main() {
	int i, j, u, k, n, v, time;
	node **top;

	scanf("%d", &n);
	top = (node **)malloc(sizeof(node *) * n);
	for (i = 0; i < n; i++) {
		scanf("%d %d", &u, &k);
		top[i] = allocNode(u, k);
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			top[i]->chldHead[j] = v - 1;
		}
	}

	time = 0;
	for (i = 0; i < n; i++)	if (top[i]->forward == 0) dfs(top, i, &time);

	for (i = 0; i < n; i++)
		printf("%d %d %d\n", top[i]->value, top[i]->forward, top[i]->backward);

	terminate(top, n);

	return 0;
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];

    sort(all(a));
    sort(all(c));

    ll ans=0;
    rep(i,n){
        ll x=lower_bound(all(a),b[i])-a.begin();
        ll y=c.end()-upper_bound(all(c),b[i]);
        ans+=x*y;
    }

    cout<<ans<<endl;
}




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

using namespace std;

#define ll long long 
#define Fastest ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

int main()
{
    int a, b, c;
    
    cin >> a>> b >> c;
    
    int coun = 0;
    
    for(int i = 100; i >= 1; i--)
    {
		if((a%i == 0) && (b%i == 0))
		{
			coun++;
		}
		if(coun == c) 
		{
			cout << i << endl;
			return 0;
		}
	}
    
    
    return 0;	
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
 
int n;
 
struct tup{
    int x, y, z;
}a[300005];
 
map<int,int> mp[300005];
int dp[300005];
 
bool input(){
    int m, nn, A, B;
    scanf("%d %d %d %d",&m,&nn,&A,&B);
    if(m + nn + A + B == 0) return 0;
    n = m + nn;
    for(int i=1; i<=m; i++){
        scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].z);
    }
    int a = A, b = B, C = ~(1<<31), M = (1<<16)-1;
    for(int i=m+1; i<=n; i++){
      a = 36969 * (a & M) + (a >> 16);
      b = 18000 * (b & M) + (b >> 16);
      ::a[i].x = (C & ((a << 16) + b)) % 1000000;
      a = 36969 * (a & M) + (a >> 16);
      b = 18000 * (b & M) + (b >> 16);
      ::a[i].y = (C & ((a << 16) + b)) % 1000000;
      a = 36969 * (a & M) + (a >> 16);
      b = 18000 * (b & M) + (b >> 16);
      ::a[i].z = (C & ((a << 16) + b)) % 1000000;
    }
    for(int i=0; i<=n; i++){
        mp[i].clear();
    }
    return 1;
}
 
bool trial(int m, int y, int z){
    auto it = mp[m].lower_bound(y);
    if(it == mp[m].begin()) return 0;
    it--;
    return (z > it->second);
}
 

void add(int x, int y, int z){
	auto it = mp[x].lower_bound(y);
	auto it2 = mp[x].upper_bound(y);
	if(it2 != mp[x].begin()){
		it2--;
		if(it2->second <= z) return;
	}
	while(it != mp[x].end() && it->second >= z){
		mp[x].erase(it);
		it = mp[x].lower_bound(y);
	}
	mp[x].insert(make_pair(y, z));
}

void solve(){
    sort(a + 1, a + n + 1, [&](const tup &a, const tup &b){
        return a.x < b.x;
    });
    mp[0].insert(make_pair(-1, -1));
    for(int i=1; i<=n;){
        int e = i;
        while(e <= n && a[e].x == a[i].x) e++;
        for(int j=i; j<e; j++){
            int s = 0, e = i;
            while(s != e){
                int m = (s+e+1) / 2;
                if(trial(m, a[j].y, a[j].z)) s = m;
                else e = m-1;
            }
            dp[j] = s + 1;
        }
        for(int j=i; j<e; j++){
            add(dp[j], a[j].y, a[j].z);
        }
        i = e;
    }
    printf("%d\n",*max_element(dp+1,dp+n+1));
}
 
int main(){
    while(input()){
        solve();
    }
}

Measured memory_bytes: 24244
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
long long mod_inv(long long a, long long mod = MOD) {
  a %= mod;
  if (__gcd(a, mod) != 1) return -1;
  long long b = mod, x = 1, y = 0;
  while (b > 0) {
    long long tmp = a / b;
    a -= tmp * b;
    swap(a, b);
    x -= tmp * y;
    swap(x, y);
  }
  x %= mod;
  if (x < 0) x += mod;
  return x;
}

struct nCk {
  vector<long long> fact;

  nCk(int val = 10000000, long long mod = MOD) : mod(mod) {
    fact.resize(val + 1);
    fact[0] = 1;
    FOR(i, 1, val + 1) fact[i] = fact[i - 1] * i % mod;
    fact_inv.resize(val + 1);
    fact_inv[val] = mod_inv(fact[val], mod);
    for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i % mod;
  }

  long long query(int n, int k) {
    if (n < 0 || n < k || k < 0) return 0;
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod;
  }

private:
  long long mod;
  vector<long long> fact_inv;
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  map<int, int> mp;
  vector<int> a(n + 1);
  REP(i, n + 1) {
    cin >> a[i];
    ++mp[a[i]];
  }
  int same;
  for (same = 1; same <= n; ++same) {
    if (mp[same] == 2) break;
  }
  int l, r;
  for (l = 0; l < n + 1; ++l) {
    if (a[l] == same) break;
  }
  for (r = n; r >= 0; --r) {
    if (a[r] == same) break;
  }
  int sum = l + n - r;
  nCk nck(n + 1);
  REP(i, n + 1) cout << (nck.query(n + 1, i + 1) - nck.query(sum, i) + MOD) % MOD << '\n';
  return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
#define fi first
#define se second
#define bug cout<<"--------------"<<endl
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=5e6+10;
int h,w,n;
struct ppo{
    int x1,y1,x2,y2;
    bool operator <(const ppo &r)const {
        if(x1==r.x1&&y1==r.y1&&x2==r.x2) return y2<r.y2;
        if(x1==r.x1&&y1==r.y1) return x2<r.x2;
        if(x1==r.x1) return y1<r.y1;
        return x1<r.x1;
    }
}q[maxn];
map<ppo,int>f;
int tot;
bool check(int x,int y){
    if(x<1||x>h||y<1||y>w) return 1;
    return 0;
}
void solve(int x1,int y1,int x2,int y2){
    if(check(x1,y1)||check(x2,y2)) return;
    ppo u=ppo{x1,y1,x2,y2};
    if(!f[u]){
        q[++tot]=u;
    }
    f[u]++;
}
ll ans[10];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
    cin>>h>>w>>n;
    for(int i=1,a,b;i<=n;i++){
        cin>>a>>b;
        solve(a,b,a+2,b+2);
        solve(a,b-1,a+2,b+1);
        solve(a,b-2,a+2,b);
        solve(a-1,b,a+1,b+2);
        solve(a-1,b-1,a+1,b+1);
        solve(a-1,b-2,a+1,b);
        solve(a-2,b,a,b+2);
        solve(a-2,b-1,a,b+1);
        solve(a-2,b-2,a,b);
    }
    ll ret=0;
    for(int i=1;i<=tot;i++){
       // cout<<q[i].x1<<" "
        ans[f[q[i]]]++;
        ret++;
    }
    ans[0]=1ll*(h-2)*(w-2)-ret;
    for(int i=0;i<10;i++) cout<<ans[i]<<" ";
	return 0;
}


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


static const int INFTY = 100'007;


int main(){
	int n,m;
	cin >> n >> m;
	vector<int> to[n];
	rep(i,m){
		int a,b;
		cin >> a >> b;
		a--;b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	queue<int> q;
	vector<int> dist(n,INFTY);
	vector<int> pre(n,-1);
	q.push(0);
	dist[0] = 0;
	while(!q.empty()){
		int v = q.front(); q.pop();
		for(int u: to[v]){
			if(dist[u] != INFTY) continue;
			dist[u] = dist[v] + 1;
			pre[u] = v;
			q.push(u);
		}
	}
	cout << "Yes" << endl;
	rep(i,n){
		if(i == 0) continue;
		cout << ++pre[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 10480
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vec A(n);
    rep(i,n) cin>>A[i];
    sort(all(A));
    vector<int> is_prime(1000001,1),Q;
    for(int i=0;i<n;i++){
        if(i>0&&A[i-1]==A[i]) continue;
        if(is_prime[A[i]]){
            for(int j=2*A[i];j<=1000000;j+=A[i]) is_prime[j]=0;
            if(i<n-1&&A[i]==A[i+1]) continue;
            Q.push_back(A[i]);
        }
    }
    cout<<Q.size();
}

Measured memory_bytes: 9752
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <iostream>
#include <cstdint>

class BubbleSort {
 public:
  BubbleSort() noexcept;
  ~BubbleSort() noexcept;
  void Main(std::istream &input_stream) noexcept;

 private:
  void Sort() noexcept;
  bool ShouldSwap(const int index_target) noexcept;
  void SwapWithLeftNext(const int32_t index_target) noexcept;
  void Load(std::istream &input_stream) noexcept;
  void Print() noexcept;

 private:
  BubbleSort(const BubbleSort &obj) noexcept = delete;
  BubbleSort &operator=(const BubbleSort &obj) noexcept = delete;
  BubbleSort(BubbleSort &&obj) = delete;
  BubbleSort &operator=(BubbleSort &&obj) = delete;

 private:
  int32_t count_;
  int32_t values_[100];
  int32_t swapped_count_;
};

BubbleSort::BubbleSort() noexcept : count_(0), values_{-1}, swapped_count_{0} {}

BubbleSort::~BubbleSort() noexcept {}

void BubbleSort::Main(std::istream &input_stream) noexcept {
  Load(input_stream);
  Sort();
  Print();
}

void BubbleSort::Sort() noexcept {
  bool should_scan = true;
  int32_t index_unsorted_head = 0;
  while (should_scan) {
    should_scan = false;
    for (int index_target = count_ - 1; index_target >= index_unsorted_head + 1; --index_target) {
      if (ShouldSwap(index_target)) {
        SwapWithLeftNext(index_target);
        should_scan = true;
      }
    }
    ++index_unsorted_head;
  }
}

bool BubbleSort::ShouldSwap(const int index_target) noexcept {
  return (values_[index_target - 1] > values_[index_target]);
}

void BubbleSort::SwapWithLeftNext(const int index_target) noexcept {
  const int32_t cvalue = values_[index_target];
  values_[index_target] = values_[index_target - 1];
  values_[index_target - 1] = cvalue;
  ++swapped_count_;
}

void BubbleSort::Load(std::istream &input_stream) noexcept {
  input_stream >> count_;
  for (int32_t index = 0; index < count_; ++index) {
    input_stream >> values_[index];
  }
}

void BubbleSort::Print() noexcept {
  for (int32_t index = 0; index < count_; ++index) {
    if (index != 0) {
      std::cout << " ";
    }
    std::cout << values_[index];
  }
  std::cout << std::endl;
  std::cout << swapped_count_ << std::endl;
}

int main(int32_t argc, char *argv[]) {
  BubbleSort *bubble_sort = new BubbleSort();
  bubble_sort->Main(std::cin);
  delete bubble_sort;
  return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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 (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int n,m;
    cin >> n >> m;
    VVI es(n);
    int a,b;
    REP(i,0,m) {
        cin >> a >> b;
        --a; --b;
        es[a].push_back(b);
        es[b].push_back(a);
    }
    VI par(n, -1);
    deque<PII> q;
    q.pb(0, -1);
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        int idx = p.first, prev = p.second;
        //cerr << idx << ", " << prev << endl;
        //if (par[idx] == -1) par[idx] = prev;
        for (int dst: es[idx]) {
            if (dst == prev) continue;
            if (par[dst] > -1) continue;
            par[dst] = idx;
            q.pb(dst, idx);
        }
    }
    bool bo = false;
    REP(i,1,n) if (par[i] == -1) {
        bo = true;
        break;
    }
    if (bo) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    REP(i,1,n) cout << par[i] + 1 << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 10588
package main

import "fmt"

func scanNums(l int) [][]int {
	nums := make([][]int, 2)
	var n, sum int
	for i := 0; i < 2; i++ {
		nums[i] = make([]int, l)
		sum = 0
		for j := 0; j < l; j++ {
			fmt.Scan(&n)
			sum += n
			nums[i][j] = sum
		}
	}
	return nums
}

func main() {
	var n int
	fmt.Scan(&n)
	nums := scanNums(n)

	max := nums[0][0] + nums[1][n-1]
	var total int
	for i := 1; i < n; i++ {
		total = nums[0][i] + nums[1][n-1] - nums[1][i-1]
		if total > max {
			max = total
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 512