akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template<typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; }
    ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; }
    ModInt& operator*=(ModInt rhs) { x = (unsigned long long) x * rhs.x % mod; return *this; }
    ModInt& operator/=(ModInt rhs) { x = (unsigned long long) x * rhs.inv().x % mod; return *this; }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) { s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a) { s >> a.x; return s; }
};

using mint = ModInt<1000000007>;

mint fact[202020];
mint factinv[202020];

void init() {
    fact[0] = 1;
    for (int i = 1; i < 202020; i++) {
        fact[i] = fact[i - 1] * i;
    }
    factinv[202020 - 1] = fact[202020 - 1].inv();
    for (int i = 202020 - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * (i + 1);
    }
    assert(factinv[0] == 1);
}

mint ncr(int n, int r) {
    return fact[n] * factinv[r] * factinv[n - r];
}

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

    init();
    int n, m, k;
    cin >> n >> m >> k;
    mint ans = ncr(n * m - 2, k - 2);

    mint coe = 0;
    for (int i = 1; i < n; i++) {
        coe += 1ll * i * m * m * (n - i);
    }
    for (int i = 1; i < m; i++) {
        coe += 1ll * i * n * n * (m - i);
    }
    cout << ans * coe << endl;
}

Measured memory_bytes: 1792
n = int(input())
s = [input() for _ in range(n)]   
import math

base = []
for i in s:
    base.append(''.join(sorted(i)))
    
base_dict = {}
for i in base:
    if i not in base_dict:
        base_dict[i] = 1
    else:
        base_dict[i] += 1

ans = 0
for key, value in base_dict.items():
    temp = 0
    if value != 1:
        temp = math.factorial(value) // (math.factorial(2) * math.factorial(value-2))
    ans += temp
    
print(ans)

Measured memory_bytes: 30856
#include<iostream>
using namespace std;
 
int main(){
 
int n,m,b[1000],a[1000][1000],SUM[1000];
 
for(int i=1;i<1000;i++){
SUM[i]=0;
}
 
cin>>n>>m;
 
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
 
cin>>a[i][j];
 
}
}
 
for(int i=1;i<=m;i++){
cin>>b[i];
}
 
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
SUM[i] += a[i][j]*b[j];
}
cout<<SUM[i]<<endl;
}
 
return 0;
}


Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<double, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int q;
	cin >> q;
	ll sm_f = 0, sm_b = 0, sum = 0;

	priority_queue<int, vi, less<int>> pq_f;
	priority_queue<int, vi, greater<int>> pq_b;

	while (q--) {

		int query;
		cin >> query;

		if (query == 1) {
			int a, b;
			cin >> a >> b;
			
			pq_b.push(a);
			sm_b += a;

			sm_f += pq_b.top();
			sm_b -= pq_b.top();
			pq_f.push(pq_b.top());
			pq_b.pop();

			if (pq_f.size() > pq_b.size() + 1) {
				sm_f -= pq_f.top();
				sm_b += pq_f.top();
				pq_b.push(pq_f.top());
				pq_f.pop();
			}
			sum += b;
		}

		else {
			cout << pq_f.top() << " ";
			if (pq_f.size() > pq_b.size())cout << sm_b - sm_f + pq_f.top() + sum << endl;
			else cout << sm_b - sm_f + sum << endl;
		}
	}	
}

Measured memory_bytes: 4204
s = input()
n = len(s)
cnt = 0
for i in range(n):
  if cnt == 0 and s[i] == 'C':
    cnt += 1
  elif cnt == 1 and s[i] == 'F':
    cnt += 1
    break
if cnt >= 2:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<stack>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	bool flag = true;
	int conl = 0, conr = 0;
	int sum = 0, maximum = 0;
	vector<string> S;
	vector<pair<int,int>> num;
	vector<pair<int,pair<int,int>>> hoge;
	vector<pair<int,pair<int,int>>> fuga;
	
	cin>>N;
	
	S.resize(N);
	num.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>S[i];
		
		stack<bool> st;
		
		for(int j = 0; j < S[i].size(); j++){
			if(S[i][j] == '(') { sum++;
				st.push(true);
			} else {
				if(st.size()) {
					st.pop();
				} else {
					num[i].first++;
				}
				
			}
		}
		
		num[i].second = st.size();
		
		if(num[i].first || num[i].second) flag = false;
		
		 if(!num[i].first) {
			 conl += num[i].second;
		}
		
		if(!num[i].second) {
			conr += num[i].first;
		}
		
		if(num[i].first && num[i].second) {
			if(num[i].first - num[i].second < 0) hoge.push_back({num[i].second,num[i]});
			if(num[i].first - num[i].second > 0) fuga.push_back({num[i].first,num[i]});
			if(num[i].first - num[i].second == 0) maximum = max(maximum, num[i].second );
		}
	}
	
	if(!sum) {
		cout<<"No"<<endl;
		return 0;
	}
	
	if(flag) {
		cout<<"Yes"<<endl;
		return 0;
	}
	
	sort(hoge.begin(), hoge.end());
	sort(fuga.begin(), fuga.end());
	
	
	for(int i = 0; i < hoge.size(); i++){
		if(conl < hoge[i].first) {
			if(maximum == 0)cout<<"No"<<endl;
			else cout<<"Yes"<<endl;
			return 0;
		}
		
		conl += hoge[i].second.second - hoge[i].second.first;
	}
	
	
	for(int i = 0; i < fuga.size(); i++){
		if(conr < fuga[i].first) {
			cout<<"No"<<endl;
			return 0;
		}
		
		conr += fuga[i].second.first - fuga[i].second.second;
	}
	
	if(conr == conl && conr >= maximum) {
		cout<<"Yes"<<endl;
		return 0;
	}
	
	cout<<"No"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 41864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int[] A = new int[n];
		int tem = 0;
		int end = 0;
		for(int i=0;i<n;i++) {
			A[i] = sc.nextInt();
		}
		
		while(end == 0) {
			for(int j=0;j<n;j++) {
				if(A[j]%2 == 0) {
					tem+=1;
					A[j]/=2;
				}
				else {
					end+=1;
					break;
				}
			}
		}
		System.out.printf("%d\n",tem/n);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

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

  // 偶数
  int ans=0;
  ans = n * (n-1) / 2;

  // 奇数
  ans += m * (m-1) / 2;

  cout << ans << endl;
}

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

typedef long long ll;
#define REP(i, n) for(int i=0;i<n;i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define EACH(it, list) for(auto it = list.begin(); it!=list.end(); it++)
#define EXIST(s, a) (s.find(a)!=s.end())
#define PB push_back
#define itr iterator

typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
#ifndef LOCAL
#define EVAL 1
#endif

#ifndef EVAL
#include <template.h>
#endif

int main(){
        int n, m, c;
        scanf("%d%d%d", &n, &m, &c);
        map<int, vector<pair<int, ll>>> road;
        ll sum = 0;
        REP(i, m){
                int a, b;
                ll d;
                scanf("%d%d%lld", &a, &b, &d);
                a--; b--;
                road[a].PB(pil(b, d));
                road[b].PB(pil(a, d));
                sum+=d;
        }

        priority_queue<pli, vector<pli>, greater<pli>> q;
        q.push(pli(0, 0));
        set<int> reach;
        vector<pil> cand;
        while(q.size()){
                pli top = q.top(); q.pop();
                int i = top.second;
                if(EXIST(reach, i)) continue;
                reach.insert(i);
                cand.PB(pil(i, top.first));
                EACH(it, road[i]){
                        if(!EXIST(reach, it->first)){
                                q.push(pli(top.first+it->second, it->first));
                        }
                }
        }

        ll mincost = LLONG_MAX;
        reach.clear();
        EACH(it, cand){
                int i = it->first;
                EACH(it2, road[i]){
                        if(EXIST(reach, it2->first)){
                                sum-=it2->second;
                        }
                }
                reach.insert(i);
                ll cost = it->second * c + sum;
                if(mincost>cost) mincost=cost;
        //      printf("%d %lld*%d+%lld=%lld\n", i, it->second, c, sum, cost);
        }
        printf("%lld\n", mincost);
}

Measured memory_bytes: 28740
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <tuple>
 
using namespace std;
 
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(n, a) for(int i = 0; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES" : "NO")
#define mod(a, b) (b + (a % b)) % b
#define MOD (ll)1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
void solve(){
    int n;
    cin >> n;
    vi c(n + 1);
    cina(1, n + 1, c);
    vi dp(n + 1, 0);
    c[0] = INT_MAX;
    for(int i = 2; i <= n; i++){
        dp[i] = min(dp[i - 1] + abs(c[i] - c[i - 1]), dp[i - 2] + abs(c[i] - c[i - 2]));
    }
    cout << dp[n];
}
 
int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 1024
from statistics import median

def main():
    N = int(input())
    strs = input()
    As = [int(num) for num in strs.split()]
    nums = [a - i for i, a in enumerate(As, 1)]
    m = int(median(nums))
    print(sum([abs(a - m) for a in nums]))

if __name__ == '__main__':
    main()

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

int n, u;
string s;

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    cin >> s;
    n = s.size();
    if (s.front() == '0' || s.back() == '1')
		cout << "-1\n";
	else {
		for (int i = 0; i < n / 2; ++i) {
			if (s[i] != s[n - i - 2])  {
				cout << "-1\n";
				return 0;
			}
		}
		cout << 1 << ' ' << 2 << '\n';
		for (int i = 1; i < n - 1; i++) {
			cout << u + 1 << ' ' << i + 2 << '\n';
			if (s[i] == '1') 
				u = i + 1;
		}
	}
}


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

using namespace std;

long long int m,a,r,c,h,n,res;

int main()
{
    cin>>n;
    string s;
    for (int i=1;i<=n;i++)
    {
        cin>>s;
        switch (s[0]) {
            case 'M' : m++;
            break;
            case 'A' : a++;
            break;
            case 'R' : r++;
            break;
            case 'C' :c++;
            break;
            case 'H' : h++;
            break;
        }
    }
    res+=m*a*r;
    res+=m*a*c;
    res+=m*a*h;
    res+=m*r*c;
    res+=m*r*h;
    res+=m*c*h;
    res+=a*r*c;
    res+=a*r*h;
    res+=a*c*h;
    res+=r*c*h;
    cout<<res;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#define in(a) a=read()
#define REP(i,k,n) for(int i=k;i<=n;i++)
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    for(;!isdigit(ch);ch=getchar())
        if(ch=='-')
            f=-1;
    for(;isdigit(ch);ch=getchar())
       x=x*10+ch-'0';
    return x*f;
}
int main(){
    char ch[100010];
    int n,m;
    in(n);
    scanf("%s",ch+1);
    in(m);
    REP(i,1,n){
    	if(ch[i]!=ch[m])  cout<<"*";
    	else  cout<<ch[i];
    }
	return 0;
}

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

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


int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for (auto&& i : a) cin >> i;

    vector<int> b;
    rep(i, n) {
        rep(j, a[i]) b.push_back(i + 1);
    }

    rep(i, h) {
        if (i & 1) {
            for (int j = i*w + w - 1; j >= i * w; j--) {
                cout << b[j] << " \n"[j == i*w];
            }
        }
        else {
            FOR(j, i*w, i*w + w) {
                cout << b[j] << " \n"[j == i*w + w - 1];
            }
        }
    }

    return 0;
}

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

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

int a[100010];
int N;

int main() {
	int count = 0;

	cin >> N;

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

	int i = 1;
	while(i != 2) {
		if (a[i] == -1) {
			count = -1;
			break;
		}

		const int t = i;
		i = a[i];
		a[t] = -1;
		count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 640
<?php
$n = fgets(STDIN);
$a = explode(" ", fgets(STDIN));
$sum = 0;
for($i = 0; $i < $n; $i++){
  for($j = 0; $j < $i; $j++){
    $sum += $a[$i]*$a[$j];
  }
}
printf("%d", $sum);


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

using int64 = long long;
using uint64 = unsigned long long;

constexpr int64 MOD = 998244353;
constexpr int MAX_N = 300005;

int64 factorial[MAX_N];

int64 powMod(int64 a, int64 n)
{
    int64 res = 1, p = a % MOD;
    while (n > 0)
    {
        if (n & 1)
        {
            (res *= p) %= MOD;
        }
        (p *= p) %= MOD;
        n >>= 1;
    }
    return res;
}

int64 choose(int x, int y)
{
    if (y > x) return 0;
    int64 res = (factorial[x] * powMod(factorial[y], MOD - 2)) % MOD;
    (res *= powMod(factorial[x - y], MOD - 2)) %= MOD;
    return res;
}

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

    int64 N, A, B, K;
    cin >> N >> A >> B >> K;

    factorial[0] = 1;
    for (int n = 1; n <= N; n++)
    {
        (factorial[n] = n * factorial[n - 1]) %= MOD;
    }

    int64 ans = 0;
    for (int64 acnt = 0; acnt <= N; acnt++)
    {
        if (K - acnt * A < 0 or (K - acnt * A) % B != 0) continue;
        int64 bcnt = (K - acnt * A) / B;

        (ans += (choose(N, acnt) * choose(N, bcnt) % MOD)) %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include <numeric>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
    i64 n, m;

    scanf("%lld %lld", &n, &m);

    if (llabs(n - m) >= 2)
    {
        printf("0\n");
        return 0;
    }

    vector<i64> facto(max(n, m) + 1);

    facto[0] = 1;

    for (int i = 1; i <= max(n,m); i++)
        facto[i] = (facto[i - 1] * i) % 1000000007;
  
    i64 res = (facto[n] * facto[m]) % 1000000007;

    if (n == m)
        res = (res * 2) % 1000000007;

    printf("%lld\n", res);

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	ll x, y;
	cin >> x >> y;

	ll res = INF;

	if (x <= y) res = min(res, y - x);
	if (-x <= y) res = min(res, y + x + 1);
	if (x <= -y) res = min(res, -y - x + 1);
	if (-x <= -y) res = min(res, -y + x + 2);

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

struct edge{ll to; ll cost;};
ll V;
vector<ll> d;
vector<vector<edge>> G;

void dijkstra(ll s){
    priority_queue<P,vector<P>,greater<P>> que;
    d = vector<ll>(V,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p = que.top();que.pop();
        ll v = p.second;
        if(d[v]<p.first)continue;
        for(edge e:G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h,w;cin>>h>>w;
    V=10;G=vector<vector<edge>>(10);
    rep(i,10){
        rep(j,10){
            ll c;cin>>c;
            G[j].push_back({i,c});
        }
    }
    dijkstra(1);
    ll ans = 0;
    rep(i,h)rep(j,w){
        ll a;cin>>a;
        if(a==-1)continue;
        ans += d[a];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
let rec input n xs
    = if n = 0 then
          xs
      else
          let l = Scanf.scanf "%d " (fun l -> l) in
          input (n-1) (l :: xs)

let rec solve xs n res
    = if n <= 0 then
        Printf.printf "%d\n" res
      else
        solve xs (n-2) (res + (List.nth xs (n-1)))

let _ =
    let n = Scanf.scanf "%d " (fun n -> 2 * n) in
    let xs = input n [] in
    let xs = List.sort compare xs in
    let l = (List.length xs) - 1 in
    solve xs l 0


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
char a,b;
cin >> a >> b;
  bool A_flag , B_flag;
 if((a == 'H'&& b == 'H')||(a == 'D' && b == 'D')){
cout << 'H' << endl;
 }else{
cout << 'D' << endl;
 } 

    return 0;
}


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

bool comp(int a[], int b[], const int n)
{
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    int p[n], q[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];

    int a[n];
    for (int i = 0; i < n; i++) a[i] = i + 1;
    int x, y;
    x = y = 0;
    bool p_match = false, q_match = false;

    while (!p_match || !q_match)  {
        if (!p_match && !comp(p, a, n)) x++;
        else p_match = true;
        if (!q_match && !comp(q, a, n)) y++;
        else q_match = true;

        /*printf("x = %d, y = %d\n", x, y);
        for (int i = 0; i < n; i++) cout << a[i] << " ";
        cout << "\n"; */

        next_permutation(a, a + n);
    }
    cout << abs(x - y) << "\n";
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func solution(n, r int) int {
	if n >= 10 {
		return r
	}
	return r + 100*(10-n)
}

func main() {
	var n, r int
	fmt.Scan(&n, &r)
	fmt.Println(solution(n, r))
}


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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair
# define int long long

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e7 + 5;

typedef long long ll;

int n, a, ans;

bool check(int x, int k)
{
      int mul = 1;
      for(int i = 1; i <= k; i ++)
      {
            mul *= x;
            if(mul >= n) return true;
      }
      return false;
}

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

      ans = n;

      for(int k = 2; k <= 41; k ++)
      {
            int res = a * (k - 1), l = 0, r = 1e6 + 1, mid;

            while(r - l > 1)
            {
                  int md = (l + r) >> 1;
                  if(check(md, k))
                        r = md;
                  else
                        l = md;
            }

            if(check(l, k)) r = l;

            for(int i = 0; i < k; i ++)
            {
                  int mul = 1, fl = 0;
                  for(int j = 1; j <= i; j ++)
                  {
                        mul *= (r - 1);
                        if(mul >= n) fl = 1;
                  }
                  for(int j = i + 1; j <= k; j ++)
                  {
                        mul *= r;
                        if(mul >= n) fl = 1;
                  }
                  if(fl) mid = i;
            }

            for(int i = 1; i <= mid; i ++)
                  res += (r - 1);
            for(int i = mid + 1; i <= k; i ++)
                  res += r;
            ans = min(ans, res);
      }

      cout << ans << endl;
}


Measured memory_bytes: 256
//
// Created by misclicked on 3/7/20.
//

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

#define ONLINE_JUDGE
#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    ios_base::sync_with_stdio(false);
    cin.tie();
#endif
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = (a / (b + c)) * b;
    if ((a % (b + c)) > b) {
        ans += b;
    } else {
        ans += a % (c + b);
    }
    cout << ans << endl;
}

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

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int i;
    int ans=0;
    int count=0;
    if(K <= A){
        ans = K;
        cout << ans << endl;
    }
    else if(K <= A+B){
        ans = A;
        cout << ans << endl;
    }else{
        ans = A - (K-A-B);
        cout << ans << endl;
    }
}

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

int main() {
    for( ; ; ) {
        int h, w;
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        string s = "", t = "#";
        for(int i=0; i<w; i++) s += '#';
        for(int j=0; j<w-2; j++) t += '.';
        t += '#';
        cout << s << endl;
        for(int i=0; i<h-2; i++) cout << t << endl;
        cout << s << endl;
        cout << endl;
    }
}


Measured memory_bytes: 3140
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn solve(a: &[usize]) -> i32 {
    let n = a.len();
    let mut pos = 0;
    for cnt in 0..n {
        if pos == 1 {
            return cnt as i32;
        }
        pos = a[pos];
    }
    -1
}

fn main() {
    input! {
        n: usize,
        a_: [usize; n],
    }
    let a = a_.iter().map(|e| e - 1).collect::<Vec<_>>();
    println!("{}", solve(&a));
}


Measured memory_bytes: 3616
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
	int i, N, D, count = 0;
	double ans, x, y;
	cin >> N >> D;
	for (i = 0; i < N; ++i) {
		cin >> x >> y;
		ans = sqrt(x * x + y * y);
		if (ans <= D) {
			++count;
		}
	}
	cout << count;
}

Measured memory_bytes: 3764
# 37

N, M = map(int, input().split())
C_L = [int(x) for x in input().split()]

# dp[i] = i円の支払う時のコインの最小枚数
dp = [float("Inf")] * (N+1)
dp[0] = 0
for i in range(1, N+1):
    for j in range(M):
        _c = C_L[j]
        if i >= _c:
            dp[i] = min(dp[i-_c] + 1, dp[i])

print(dp[N])



Measured memory_bytes: 7276
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	int max_a = a[n - 1];
	vector<bool> eratos(max_a + 1, true);
	for (int i = 0; i < n; i++)
	{
		if (eratos[a[i]] == false)
			continue;

		if (i > 0 && a[i] == a[i - 1])
			eratos[a[i]] = false;

		for (int j = 2 * a[i]; j <= max_a; j += a[i])
		{
			eratos[j] = false;
		}
	}

	int res = 0;
	for (int i = 0; i < n; i++)
	{
		if (eratos[a[i]] == true)
			res++;
	}
	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

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

int main() {

  int n;
  cin >> n;
  
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int ans = 0;
  REP(i,n) {
    if (i % 2 == 0) ans += a[i];
    else ans -= a[i];
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  vector<ll> p(n);
  ll now=0;
  rep(i,n){
    ll x;
    cin>>x;
    now+=x;
    p[i]=now;
  }

  ll sum=now;
  ll ans=1000000000000000000;
  rep(i,n-1){
    ans=min(ans,abs(sum-2*p[i]));
  }

  cout << ans << endl;

}


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

class program{
    public static void Main(string[] args){
        string[] input = Console.ReadLine().Split(' ');
      	int ans = int.Parse(input[0]) - int.Parse(input[1]);
      if(int.Parse(input[1]) == 1) Console.WriteLine(0);  
      else if(ans < 0)Console.WriteLine(0);
      else Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
S = input()
N = len(S)
BstartS_count = 0
WstartS_count = 0

for i in range(N):
    if i % 2 == 0:
        if S[i] == "0":
            WstartS_count += 1
        else:
            BstartS_count += 1
    else:
        if S[i] == "1":
            WstartS_count += 1
        else:
            BstartS_count += 1

output = BstartS_count
if WstartS_count < output:
    output = WstartS_count

print(output)

Measured memory_bytes: 3188
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    int sum = 0;
    int minAbsT = MOD;
    int minT = MOD;
    rep(i, N) {
        int taste = L + (i + 1) - 1;
        sum += taste;
        if (abs(taste) < minAbsT) {
            minAbsT = abs(taste);
            minT = taste;
        }
    }

    int ans = sum - minT;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[205],s=0;
    cin>>n;n*=2;
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i+=2) s+=a[i];
    cout<<s<<endl;;
    return 0;
    }


Measured memory_bytes: 256
#include <iostream>

typedef long long ll;

using namespace std;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a > b) cout << 0 << endl;
    else if (n == 1) cout << (a == b) << endl;
    else cout << (a + b * (n - 1)) - (b + a * (n - 1)) + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   string s;
           cin>>s;
           int n=s.size();
           int ans=0;
           string t="CODEFESTIVAL2016";
           rep(i,0,n){
             if(s[i]!=t[i])ans++;
           }
           cout<<ans<<endl;
}

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

int main() {
  int a;
  cin >> a;
  int ans = a + a * a + a * a * a;
  cout << ans << '\n';
  
  return 0;
}

Measured memory_bytes: 3632
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D
sample_input = list(range(3))
# sample_input[0] = '''\\//'''
# sample_input[1] = '''\\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\'''
# sample_input[2] = ''''''

sample_input[0] = '''\\\\//'''
sample_input[1] = '''\\\\///\\_/\\/\\\\\\\\/_/\\\\///__\\\\\\_\\\\/_\\/_/\\'''
sample_input[2] = ''''''

give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main
# a list of tuples (h, l, r)
# h = the hight
# l, r = max of heights of points which is left (right) or equal to this point
terrain_data = []

str_input = input()
list_input = list(str_input)

height = 0
left_max_height = 0
terrain_data.append([height,left_max_height, None])
for path in list_input:
    if path == '/':
        height += 1
    elif path == '\\':
        height -= 1
    left_max_height = max(left_max_height, height)
    terrain_data.append([height,left_max_height, None])

right_max_height = None # dealt as negative infinity
for index in range(len(terrain_data)-1, -1, -1):
    height = terrain_data[index][0]
    if right_max_height is None:
        right_max_height = height
    else:
        right_max_height = max(right_max_height, height)
    terrain_data[index][2] = right_max_height

pool_left = -1
pool_right = -1
area = 0
areas = []
prev_depth = 0
for data in terrain_data:
    depth = min(data[1], data[2]) - data[0]
    area += (prev_depth + depth)/2
    if depth == 0:
        if pool_left < pool_right:
            areas.append(int(area))
            area = 0
        pool_right += 1
        pool_left = pool_right
    else:
        pool_right += 1
    prev_depth = depth

print(sum(areas))
output = str(len(areas)) + ' '
for a in areas:
    output += str(a) + ' '
print(output[:-1])

Measured memory_bytes: 10284
/*
khôi luoi document nên mình làm thay khôi.
also for some reason dùng x^2+c các ban se bi TLE on test "4", ngay ca voi x0 và c random.
-normie-
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "birds.inp"
#define FILE_OUT "birds.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define endl "\n"
#define bi BigInt
typedef long long ll;
#define pi 3.1415926535897
//------START-----------//
struct cmp
{
	int operator()(pll a, pll b)
	{
		return (a.se>b.se);
	}
};
struct graph{
	private:
	vector<vector<pll>> gt;
	vector<ll> dist;
	priority_queue<pll,vector<pll>,cmp> bruh;
	ll n;
	
	void proc(pll cur)
	{
		ll v=cur.fi,t=cur.se;
		if (t>dist[v]) return;
		for (auto g: gt[v])
			if (dist[g.fi]>dist[v]+g.se)
		{
			dist[g.fi]=dist[v]+g.se;
			bruh.push({g.fi,dist[v]+g.se});
		}
	}
	public:
	graph (ll n)
	{
		this->n=n;
		for (ll i=0;i<n;i++)
		{
			gt.push_back({});
			dist.push_back(0);
		}
	}
	void addEdge (ll a, ll b, ll c)
	{
		gt[a].push_back({b,c});
	}
	vector<ll> dijkstra(ll s)
	{
		for (ll i=0;i<n;i++)
		{
			dist[i]=1e18;
		}
		dist[s]=0;
		bruh.push({s,0});
		while(bruh.size())
		{
			auto toproc(bruh.top());
			bruh.pop();
			proc(toproc);
		}
		return dist;
	}
};
//------END-----------//
ll n,m,k,c[501],arr[100001],dy[100001],t,t1,i,j,res;
vector<ll> gt[51];
int main()
{
	cin>>n>>m;
	graph gr(n+1);
	for (i=1;i<n;i++) gr.addEdge(i+1,i,0);
	for (i=0;i<m;i++)
	{
		ll a,b,c;
		cin>>a>>b>>c;
		gr.addEdge(a,b,c);
	}
	vector<ll> res=gr.dijkstra(1);
	if (res[n]==1e18) cout<<-1; else cout<<res[n];
}

Measured memory_bytes: 11056
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int h1,m1,s1;
	int h2,m2,s2;
	int h,m,s;
	
	for(int i=0;i<3;i++){
		scanf("%d %d %d %d %d %d",&h1,&m1,&s1,&h2,&m2,&s2);
		h = 0;
		m = 0;
		if(s1>s2){
			m--;
			s = (60-s1)+s2;
		}
		else
		s = s2-s1;
		if(m+m2-m1<0){
			h--;
			m = m+(60-m1)+m2;
		}
		else
		m = m+m2-m1;
		h = h+h2-h1;
		printf("%d %d %d\n",h,m,s);
	}
}

Measured memory_bytes: 3204
#include <iostream>

int main() {
    int q, a, b;
    std::cin >> q >> a >> b;

    for (int i = a; i <= b; ++i) {
        if (i % q == 0) {
            std::cout << "OK" << std::endl;
            return 0;
        }
    }
    std::cout << "NG" << std::endl;
    return 0;
}


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

vector<int> e[100010];
int n, k;
int p[100010];
int ans;

int f(int x){
	int ret = 0;
	for(auto &i : e[x]){
		ret = max(ret, f(i));
	}
	ret++;
	if(x == 1) return 0;
	if(ret == k){
		if(p[x] != 1) ans++;
		return 0;
	}
	return ret;
}

int main(){
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d", &x);
		if(i == 1 && x != 1) ans = 1;
		if(i != 1) e[x].push_back(i);
		p[i] = x;
	}
	f(1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10752
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int max(int a,int b){
    return a>b?a:b;}
int main() {
	// your code goes here
	int n; cin >> n;
	vector<vector<int>> v(n,vector<int>(3,0));
	for(int i=0;i<n;i++){
	    for(int j=0;j<3;j++){
	        cin >> v[i][j];
	    }
	}
	vector<vector<int>> ans(n,vector<int>(3,0));
	ans[0][0]=v[0][0];ans[0][1]=v[0][1];ans[0][2]=v[0][2];
	for(int i=1;i<n;i++){
	    ans[i][0]=max(v[i][0]+ans[i-1][1],v[i][0]+ans[i-1][2]);
	    ans[i][1]=max(v[i][1]+ans[i-1][0],v[i][1]+ans[i-1][2]);
	    ans[i][2]=max(v[i][2]+ans[i-1][1],v[i][2]+ans[i-1][0]);
	}
	int maxi = max(ans[n-1][0],ans[n-1][1]);
	cout << max(maxi,ans[n-1][2]);
	return 0;
}


Measured memory_bytes: 11136
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut a = a;
    let m = 60;
    let mut cnt = vec![0; m];
    for &a in a.iter() {
        for (i, c) in cnt.iter_mut().enumerate() {
            *c += (a >> i) & 1;
        }
    }
    let mut mask = !0usize;
    for (i, c) in cnt.iter().enumerate() {
        if *c % 2 == 1 {
            mask ^= 1 << i;
        }
    }
    for a in a.iter_mut() {
        *a &= mask;
    }
    let mut u = 0;
    loop {
        let v = *a.iter().max().unwrap();
        if v == 0 {
            break;
        }
        u = std::cmp::max(u, u ^ v);
        for a in a.iter_mut() {
            *a = std::cmp::min(*a, *a ^ v);
        }
    }
    let ans = !mask + 2 * u;
    println!("{}", ans);
}

fn main() {
    run();
}


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

using namespace std;

#define int long long

const int mod = 1e9+7;

int n;
int f[1000001];

int sub(int a,int b)
{
	int c = ((a - b)%mod + mod)%mod;
	return c;
}

int add(int a,int b)
{
	int c = (a + b)%mod;
	return c;
}

int mul(int a,int b)
{
	int c = (a * b)%mod;
	return c;
}

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

	cin >> n;
	f[0] = 1, f[1] = n; 
	int sum = f[0] + f[1];
	for (int i=2;i<=n;i++)
	{
		f[i] = add(add(mul(n-1,n-1), sub(sum,f[i-2])), (n - i + 1));
		sum = add(sum,f[i]);
	}	
	cout << f[n];
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <string.h>

int main(void){
  int st, l, r, n, i, ans;
  char s[3];
  while(1){
    scanf("%d",&n);
    if(n == 0){
      break;
    }
    ans = 0;
    st = l = r = 0;
    for(i = 0;i < n;i++){
      scanf("%s",&s);
      if(!strcmp(s,"lu")){
	l = 1;
      }else if(!strcmp(s,"ru")){
	r = 1;
      }else if(!strcmp(s,"ld")){
	l = 0;
      }else if(!strcmp(s,"rd")){
	r = 0;
      }else{
	printf("error\n");
      }
      if(st != l && st != r){
	st = l;
	ans++;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

template <typename T>
class Seg_Tree{
public: // 0-index
	vector<T> dat;
	T initial,M;
	int n;
	T unite(T a,T b){//
		return (a + b) % M;
	}
	Seg_Tree(int n0_=1,T initial_=1,T M_=1){
		initsize(n0_,initial_,M_);
	}
	void initsize(int n0,T initial_,T M_){
		M = M_;
		initial = initial_;
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=initial;
				break;
			}
			k*=2;
		}
	}
 
	//i banme wo x nisuru
	void update(int i,T x){
		i += n-1;
		dat[i] = x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = unite(dat[i*2+1],dat[i*2+2]);
		}
	}
 
	//[a,b)
	T query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return initial;
		if(a<=l && r<=b)return dat[k];
		else{
			T vl = query0(a,b,k*2+1,l,(l+r)/2);
			T vr = query0(a,b,k*2+2,(l+r)/2,r);
			return unite(vl,vr);
		}
	}
 
	//return [a,b)
	T query(int a,int b){
		return query0(a,b,0,0,n);
	}
};



int main(){

	ll N,K;
	cin >> N >> K;

	ll mod = 998244353;

	vector<ll> l(K),r(K);
	FOR(i,0,K) cin >> l[i] >> r[i];


	Seg_Tree<ll> sg;
	sg.initsize(N+2,0,mod);

	sg.update(1,1);

	FOR(i,2,N+1){
		ll sum = 0;
		FOR(j,0,K){
			ll dl = l[j];
			ll dr = r[j];
			sum += sg.query(i-dr,i-dl+1);
		}
		sg.update(i,sum);
	}
	cout << sg.query(N,N+1) << endl;
}


Measured memory_bytes: 7488
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll n, x, a, an, cnt = 0;
	cin >> n >> x;
	cin >> a;
	n--;
	while (n--){
		cin >> an;
		if (a + an > x){
			cnt += a + an - x;
			if (a > x){
				a = x;
				an = 0;
			}
			else{
				an = x - a;
			}
		}
		a = an;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

static const int N_MAX = 100000;
static const int UNKNOWN = -1;

int scores[N_MAX][3];
long mem[N_MAX][3];
int N;

long getScore(int day, int act){
    if(mem[day][act] != UNKNOWN){
        return mem[day][act];
    }
    long score = scores[day][act];
    if(day < N-1){
        score += max(getScore(day+1, (act+1)%3), getScore(day+1, (act+2)%3));
    }
    mem[day][act] = score;
    return score;
}

int main(){
    for(int i=0;i<N_MAX;i++){
        for(int j=0;j<3;j++){
            mem[i][j] = UNKNOWN;
        }
    }
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> scores[i][0] >> scores[i][1] >> scores[i][2];
    }
    cout << max(getScore(0, 0), max(getScore(0, 1), getScore(0, 2))) << endl;
    return 0;
}


Measured memory_bytes: 11648
def choose(n, a):
    x = 1; y = 1
    for i in range(a):
        x = x * (n-i) % mod
        y = y * (i+1) % mod
    return x * pow(y, mod-2, mod) % mod

mod = 10 ** 9 + 7

n, a, b = map(int, input().split())


ans = pow(2, n, mod)
ans -= 1
ans -= choose(n, a)
ans -= choose(n, b)

print(ans % mod)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef long long int ll;

int num[4]={};

int main(){
	string s; cin >> s;
	string k="KUPC";
	for(int i=0;i<s.size();i++){
		for(int j=0;j<4;j++){
			if(s[i]==k[j])num[j]++;
		}
	}
	cout << min(min(num[0],num[1]),min(num[2],num[3])) << endl;
}


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

int main() {
	// your code goes here
	string s = "";
	cin>>s;
	int len = s.size();
	if(s[len-1] == 's'){
		s += "es";
	}
	else
		s += 's';
	cout<<s<< endl;
	return 0;
}

Measured memory_bytes: 3592
def main() :
    H,W = map(int,input().split())
    if (H == 1 or W == 1) :
        print(1)
        return

    odd_reach = -1
    even_reach = -1
    if (H % 2 == 1) :
        odd_reach = (H // 2 + 1)
        even_reach = (H // 2 )
    else :
        odd_reach = (H // 2)
        even_reach = (H // 2)

    # print("odd_reach : ", odd_reach, ",even_reach : ", even_reach)
    reachable = 0
    if (W % 2 == 1) :
        odd_row = (W // 2) + 1
        even_row = (W // 2)
        reachable = odd_reach * odd_row
        reachable += even_reach * even_row
    else :
        odd_row = (W // 2) 
        even_row = (W // 2) 
        reachable = odd_reach * odd_row
        reachable += even_reach * even_row

    # print("odd_row : ", odd_row, ",even_row : ", even_row)
    print(reachable)


main()

Measured memory_bytes: 3064