akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int MOD=1e9+7, n,dp[310][310][310];
vector<int> g[310][4];

int solve(int i, int j, int k){	//R=i, G=j, B=k
	int &r=dp[i][j][k];
	if(r>=0) return r;
	int now=max({i,j,k});
	if(now==n+1) return r=1;
	int mn=min({i,j,k}), mid=mn^now^i^j^k;
	int can=1;
	
	if(SZ(g[now][1])){
		can&=g[now][1][0]>mid&&g[now][1].back()<=now;
	}
	
	if(SZ(g[now][2])){
		can&=g[now][2][0]>mn&&g[now][2].back()<=mid;
	}
	
	if(SZ(g[now][3])){
		can&=g[now][3].back()<=mn;
	}
	
	r=0;
	if(can){
		r+=solve(now+1,j,k); if(r>=MOD)r-=MOD;
		r+=solve(i,now+1,k); if(r>=MOD)r-=MOD;
		r+=solve(i,j,now+1); if(r>=MOD)r-=MOD;
	}
	return r;
}

int main(){FIN;
	memset(dp,-1,sizeof(dp));
	int q; cin>>n>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;
		g[r][x].pb(l);
	}
	fore(i,0,n+1) fore(j,0,4) sort(ALL(g[i][j]));
	cout << solve(0,0,0)*333333336ll%MOD << "\n";
}

Measured memory_bytes: 116736
N, X = map(int, input().split())
list_m = [0 for i in range(0,N)]
for i in range(0,N) :
    list_m[i] = int(input())

sum_m = sum(list_m)
min_m = min(list_m)

ans = N + (X - sum_m) // min_m
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LL long long
#define MX 5005

int main()
{
    int a, b, c;
    scanf("%d%d%d",&a,&b,&c);
    if (a==b) printf("%d\n",c);
    if (a==c) printf("%d\n",b);
    if (b==c) printf("%d\n",a);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> x(n),y(n);
    vector<int> xary,yary;
    for(int i=0; i<n; i++)
    {
        cin>>x[i]>>y[i];
        xary.push_back(x[i]);
        yary.push_back(y[i]);
    }
    sort(xary.begin(),xary.end());
    sort(yary.begin(),yary.end());
    ll ans=1LL*(xary[n-1]-xary[0])*(yary[n-1]-yary[0]);
    for(int xi=0;xi<n;xi++)
    {
        for(int xj=xi+1;xj<n;xj++)
        {
            for(int yi=0;yi<n;yi++)
            {
                for(int yj=yi+1;yj<n;yj++)
                {
                    int num = 0;
                    ll lx = xary[xi],rx=xary[xj];
                    ll by = yary[yi],uy=yary[yj];
                    for(int i=0;i<n;i++)
                    {
                        if(lx<=x[i] && x[i]<=rx && by<=y[i] && y[i] <= uy)
                            num++;
                    }
                    if(num>=k) ans=min(ans,1LL*(rx-lx)*(uy-by));
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	int N, A[100000], ans = 0, tmp = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> A[i];
	sort(A, A + N);
	for (int i = 1; i < N; ++i) {
		if (A[i - 1] == A[i]) ++tmp;
		else {
			if (tmp % 2 == 0) ++ans;
			tmp = 0;
		}
	}
	if (tmp % 2 == 0) ++ans;
	cout << ans;
}

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

int main() {

int a, b, c;

cin >> a >> b >> c;

int d = 3;

if (a != b && a != c && b != c) d = 3;

else if (a == b && a != c) d = 2;
else if (a == c && a != b) d = 2;
else if (b == c && a != b) d = 2;

else if (a == b && a == c) d = 1;

cout << d << endl;
}


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

int main(){
  ll N, A, B;
  cin >> N >> A >> B;
  ll count1, count2, count3;
  if((A - B) %2 == 0){
    count1 = abs(A - B)/2;
    cout << count1 << endl;
  }
  else{
    count1 = B - ((B - A)/2 + 1);
    count2 = (N - (B - A)/2) - A;
    cout << min(count1, count2) << endl;
  }
}

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

const int N = 1e5 + 10;
const int mo = 1e9 + 7;

char str[N];
int n, pw[N] = {1}, pre[N], suf[N], p[N], s[N];

int main() {
	scanf("%s", str + 1);
	for(int i = 1; i <= 1000; i ++) i = i - 1 + 1;
	n = strlen(str + 1);
	for(int i = 1; i <= n; i ++) { pw[i] = pw[i - 1] * 3ll % mo; }
	for(int i = 1; i <= n; i ++) {
		pre[i] = pre[i - 1] + (str[i] == 'A');
		p[i] = p[i - 1] + (str[i] == '?');
	}
	for(int i = n; i >= 1; i --) {
		suf[i] = suf[i + 1] + (str[i] == 'C');
		s[i] = s[i + 1] + (str[i] == '?');
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		if(str[i] == 'B') {
			(ans += 1ll * pre[i - 1] * suf[i + 1] % mo * pw[p[n]] % mo) %= mo;
			if(p[i]) (ans += 1ll * p[i] % mo * suf[i + 1] % mo * pw[p[n] - 1] % mo) %= mo;
			if(s[i]) (ans += 1ll * s[i] % mo * pre[i - 1] % mo * pw[p[n] - 1] % mo) %= mo;
			if(p[i] && s[i])
				(ans += 1ll * s[i] * p[i] % mo * pw[p[n] - 2] % mo) %= mo;
		} else if(str[i] == '?') {
			(ans += 1ll * pre[i - 1] * suf[i + 1] % mo * pw[p[n] - 1] % mo) %= mo;
			if(p[i - 1]) (ans += 1ll * p[i - 1] % mo * suf[i + 1] % mo * pw[p[n] - 2] % mo) %= mo;
			if(s[i + 1]) (ans += 1ll * s[i + 1] % mo * pre[i - 1] % mo * pw[p[n] - 2] % mo) %= mo;
			if(p[i - 1] && s[i + 1])
				(ans += 1ll * s[i + 1] * p[i - 1] % mo * pw[p[n] - 3] % mo) %= mo;
		}
	}
	printf("%d", ans);
	return 0;
}
//AtCoder - 4232


Measured memory_bytes: 2176
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,t;
	scanf("%d%d%d",&a,&b,&c);
	if(a < b)
	{
		t = a; a = b; b = t;
	}
	if(a < c)
	{
		t = a; a = c; c = t;
	}
	if(b < c)
	{
		t = b; b = c; c = t;
	}
	printf("%d\n",a*10+b+c);
	return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()
# n = INT()
# print(a, b)
if s == "SUN":
  print(7)
elif s == "MON":
  print(6)
elif s == "TUE":
  print(5)
elif s == "WED":
  print(4)
elif s == "THU":
  print(3)
elif s == "FRI":
  print(2)
elif s == "SAT":
  print(1)






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

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

using namespace std;
typedef long long ll;

int main() {
    int h, w;
    cin >> h >> w;


    rep(i, h) {
        rep(j, w) {
            string si;
            cin >> si;

            if (si == "snuke") {
                char c = 'A' + j;
                cout << c << i + 1;
            }
        }

    }
}

Measured memory_bytes: 3508
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

module Util =
    let strRev (s: string): string =
        s
        |> Seq.rev
        |> Seq.map string
        |> String.concat ""

    let inline roundup (x: ^a) (y: ^a): ^a =
        let one = LanguagePrimitives.GenericOne
        (x + y - one) / y

[<EntryPoint>]
let main _ =
    let s = read string |> Array.ofSeq
    let w = read int

    seq {
        for i in 0..w..Array.length s - 1 do
            yield s.[i]
    }
    |> String.Concat
    |> printfn "%s"
    0 // return an integer exit code


Measured memory_bytes: 12124
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI 3.1415926536
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    double r;
    cin >> r;
    printf("%4.10f\n", 2*r*PI);

}



Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
struct union_find{//rank,経路圧縮で高速化
  vector<long long> data;//そのノードがrootであれば-（集合のサイズ）を表し、そうでなければ親ノードidを示す。
  union_find(long long size):data(size,-1){}//コンストラクタ,size個のノードを作成し、-1で初期化
  long long root(long long a){//根を探す,経路圧縮
    return data[a] < 0 ? a : data[a]=root(data[a]);
  }
  bool find(long long a,long long b){//a,bが同じ集合に属するか調べる
    return root(a) == root(b);
  }
  bool unite(long long a,long long b){//小さい方の木の根に大きい方の根を上書きする
    a = root(a),b = root(b);
    if(a==b) return false;//根が同じなら終了,uniteが失敗したことを出力
    if(data[a]<data[b]) swap(a,b); //集合サイズの大きい方の根に低い方の根をつける
    data[b] += data[a];//集合サイズを統合
    data[a] = b;//bの親にaをつける
    return true;//unite成功を出力
  }
  long long size(long long a){//aが属する集合のサイズを出力
    return -data[root(a)];
  }
};
signed main(){
  int n,m;
  cin >> n >> m;
  vi a(m),b(m);
  REP(i,m) cin >> a.at(i) >> b.at(i);
  vl ans(m);
  ans.at(m-1) = n*(n-1)/2;
  union_find uf(n+1);
  RFOR(i,1,m){
    if(uf.find(a.at(i),b.at(i))){
      ans.at(i-1) = ans.at(i);
      continue;
    }
    ans.at(i-1) = ans.at(i) - uf.size(a.at(i))*uf.size(b.at(i));
    uf.unite(a.at(i),b.at(i));
  }
  for(auto i:ans){
    cout << i << endl;
  }
}


Measured memory_bytes: 4480
N = int(input())

Ss = []
for i in range(N):
    Ss.append(input())

M = int(input())
Ts = []
for i in range(M):
    Ts.append(input())

hs = {}

for s in Ss:
    if s in list(hs.keys()):
        hs[s] += 1
    else:
        hs[s] = 1

for t in Ts:
    if t in list(hs.keys()):
        hs[t] -= 1

print(max(max([i[1] for i in hs.items()]),0))


Measured memory_bytes: 3064
N,C = map(int,input().split())
x1=[]
v1=[]

for i in range(N):
    x,v = map(int,input().split())
    x1.append(x)
    v1.append(v)
x2 = [C-x for x in x1]
v2 = [v for v in v1]
x2.reverse()
v2.reverse()

res1 = 0
res2 = 0
s1 = 0
s2 = 0
r1 = [0]
r2 = [0]
for i in range(N):
    s1 += v1[i]
    s2 += v2[i]
    res1 = max(res1,s1-x1[i])
    res2 = max(res2,s2-x2[i])
    r1.append(res1)
    r2.append(res2)

vl1 = [0]*(N+1)
vl2 = [0]*(N+1)
for i in range(N):
    vl1[i+1] = v2[i]+vl1[i]
    vl2[i+1] = v1[i]+vl2[i]
for i in range(N):
    vl1[i+1] -= 2*x2[i]
    vl2[i+1] -= 2*x1[i]



ans = 0
for i in range(N+1):
    res = vl1[i]+r1[N-i]
    if res > ans:
        ans = res
    res = vl2[i]+r2[N-i]
    if res > ans:
        ans = res

print(ans)

Measured memory_bytes: 33236
#include <queue>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+9;
int n,lz,lf,k;
ll z[N],f[N];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i){
        ll x;
        scanf("%lld",&x);
        if(x==0)k--;
        else if(x>0)z[++lz]=x;
        else f[++lf]=-x;
    }
    sort(f+1,f+1+lf);
    ll sz=0,sf=0,mi=1e13,Z,F;
    Z=min(lz,k);
    sz=z[Z];
    F=k-Z;
    sf=f[F];
    for(;F<=lf&&F<=k;){
        ll sum=sz*2+sf;
        mi=mi<sum?mi:sum;
        sum=sz+sf*2;
        mi=mi<sum?mi:sum;
        F++;
        sf=f[F];
        Z--;
        sz=z[Z];
    }
    printf("%lld",mi);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define int long long
#define MOD 1000000007
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}

int getMax(int n) {
    int count = 0;
    while(n % 2 == 0) {
        count ++;
        n /= 2;
    }
    return count;
}
  
void solve() {
    int n, q;
    cin >> n;
    int a[n];
    int x = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        x ^= a[i];
    }
    for(int i = 0; i < n; i++) {
        cout << (a[i] ^ x) << " ";
    }
    cout << endl;

    
}
 
int32_t main() {
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}

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

int main()
{
    int i;
    int n; cin >> n;
    int64_t L, L_1=1, L_2=2;

    if (n == 1) cout << 1 << endl;
    else
    {
        for (i=2; i<=n; i++)
        {
            L = L_1 + L_2;
            L_2 = L_1;
            L_1 = L;
        }
        printf("%ld\n", L);
    }
}

Measured memory_bytes: 3652
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = pow(10,15);
ll k,x,m, n, h,r,c; string s;
const ll MOD= 1000000007;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
} 
ll d[100100]; vector<bool>  visit(100010,0);
vector<vector<pair<int,int>>> G;int an[100010];
void dfs(int s) {
    if (visit[s]) return;
    visit[s] = 1; pair<int, int> p;
    for (pair<int, int> i : G[s]) {
        p = i;
        if (p.second % 2 == 0) {
            an[p.first] = an[s];
        }
        else {
            an[p.first] = (an[s] + 1) % 2;
        }
        dfs(p.first);
    }
}
int main() {
    cin >> n; G.resize(n); int u, v, w;
    rep(i, n - 1) {
        cin >> u >> v >> w; u--; v--;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }an[0] = 0;
    dfs(0); 
    rep(i, n) cout << an[i] << endl;
}

Measured memory_bytes: 7424
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int main(void) {
	string s;
	cin >> s;
	ll n = 0, ans = 0, ten = 1;
	map<ll, ll> mp;
	mp[0] = 1;
	for (int i = s.size() - 1; i >= 0; i--) {
		n += (s[i] - '0') * ten;
		ten *= 10;
		ten %= 2019;
		n %= 2019;
		mp[n]++;
	}
	for (auto m : mp) {
		ans += (m.second - 1) * m.second / 2;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3852
import itertools
import math
n = int(input())

lst = [_ for _ in range(1, n+1)]
lst2 = list(itertools.product(lst, repeat=2))

lst3 = [math.gcd(_[0], _[1]) for _ in lst2]

lst4 = list(itertools.product(lst3, lst))

lst5 = [math.gcd(_[0], _[1]) for _ in lst4]

print(sum(lst5))

Measured memory_bytes: 716976
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)

//abbreviations
typedef long long ll;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vb vector<bool>

using namespace std;

const int vmax = 100100;
vi graph[vmax*2];
vb seen(vmax*2);
vi cnt(2,0);

void dfs(int v) {
  if(seen[v]) return;
  seen[v] = true; // v を訪問済にする
  cnt[v/vmax]++;

  // v から行ける各頂点 next_v について
  for (int next_v : graph[v]) {
    dfs(next_v); // 再帰的に探索
  }
}



int main(){
  int i = 0;
  int N = 0;
  ll ans = 0;
  cin>>N;
  rep(i,N){
    int x,y;
    cin >> x >> y;
    y += vmax;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  seen.assign(vmax*2,false);
  rep(i,vmax*2){
      if(seen[i])continue;
      cnt[0]=0;cnt[1]=0;
      dfs(i);
      ans+=(ll)cnt[0]*cnt[1];
  }
  ans-=N;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int a[N],b[N],sum,n;
const int MAXN = 100000;
int prime[MAXN + 1];

int p[2000],num=0;
void pr(int x)
{
	for (int i = 1; i * i <= x; i++)
	{
		if (x % i == 0)
		{
			p[num++] = i;
			if(x!=i*i)p[num++] = x/i;
		}
	}
	sort(p,p+num);
	//for(int i=0;i<num;i++)
    //    cout<<p[i]<<" ";
    //cout<<endl;
}
int judge(int gcd){

    /*
    int res=0;
    int num=sum/gcd;
    for(int i=0;i<n;i++){

        int agcd=a[i]%gcd;
        if(agcd==0){
            num-=a[i]/gcd;
        }
        else if(agcd>=gcd-agcd){
            res+=gcd-agcd;
            num-=((a[i]+gcd-1)/gcd);
        }
    }
    */
    //cout<<gcd<<"!!!"<<endl;
    for(int i=0;i<n;i++)
          b[i]=a[i];
    //cout<<endl;
    int res=0;
    int num=sum/gcd;
    for(int i=0;i<n;i++){

        int agcd=b[i]%gcd;
        //res+=agcd;
        num-=b[i]/gcd;
        b[i]=agcd;
    }
    //cout<<res<<"    1111   "<<num<<endl;
    if(num>=0){
        sort(b,b+n);
        for(int i=n-1;i>=0;i--){
            if(num<=0){
                res+=b[i];
            }
            else if(b[i]>0){
                 res+=gcd-b[i];
                 b[i]=0;
                 num--;
            }
            else break;
        }
    }
    //cout<<res<<"    2222   "<<num<<endl;
    if(num>0)
        res+=num*gcd;
        //cout<<res<<"    3333   "<<num<<endl;
    if(num<0)
        res+=abs(num)*gcd;
        //cout<<res<<"    4444   "<<num<<endl;
    //cout<<res<<endl;
    return res/2;

}
int main()
{
    int k;
    cin>>n>>k;
    sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sort(a,a+n);
    pr(sum);
    int ans=1;
    for(int i=num-1;i>=0;i--){
        if(judge(p[i])<=k){
            ans=p[i];
            break;
        }

    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    p = {1:2,7:3,4:4,5:5,3:5,2:5,9:6,6:6,8:7}
    a = list(map(int,input().split()))
    INF = float("inf")
    dp = [-INF for _ in range(N+1)]
    dp[0] = 0
    for i in range(N):
        for j in a:
            if i+p[j] <= N:
                dp[i+p[j]] = max(dp[i+p[j]],dp[i]+1)
    
    dp.reverse()
    use = []
    for i in a:
        use.append((i,p[i]))
        
    use.sort(key=lambda x:(-x[0],-x[1]))
    ans = []
    now = 0
    while now < N:
        for num,i in use:
            if (now+i <= N and dp[now+i] == dp[now]-1):
                ans.append(str(num))
                now += i
                break
    print("".join(ans))
    
if __name__ == "__main__":
    main()


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct RootedTree {
    RootedTree(int n, int root = 0) :
            mRoot(root) {
        mVertexTbl.resize(n);
    }

    void addEdge(int a, int b, long long int cost = 1) {
        mVertexTbl[a].child.push_back(pair<int, long long int>(b, cost));
        mVertexTbl[b].child.push_back(pair<int, long long int>(a, cost));
    }

    void build() {
        queue<tuple<int, int, long long int>> q;
        q.push(make_tuple(mRoot, -1, 0));
        while (!q.empty()) {
            auto t = q.front();
            q.pop();
            int index = get<0>(t);
            int parent = get<1>(t);
            long long int depth = get<2>(t);
            mVertexTbl[index].parent = parent;
            mVertexTbl[index].depth = depth;
            for (auto it = mVertexTbl[index].child.begin(); it != mVertexTbl[index].child.end();) {
                int nxt = (*it).first;
                if (nxt == parent) {
                    mVertexTbl[index].child.erase(it);
                    continue;
                }
                q.push(make_tuple(nxt, index, depth + (*it).second));
                ++it;
            }
        }
    }

    struct Vertex {
        vector<pair<int, long long int>> child;
        long long int depth = 0;
        int parent = -1;
    };

    int mRoot;
    vector<Vertex> mVertexTbl;
};

int main() {
    ll N;
    cin >> N;
    RootedTree tree(N);
    REP(i, N - 1) {
        ll a, b, w;
        cin >> a >> b >> w;
        a--;
        b--;
        tree.addEdge(a, b, w);
    }
    tree.build();
    REP(i, N) {
        cout << tree.mVertexTbl[i].depth % 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 9472
n = int(input().strip())
p = list(map(int, input().strip().split()))

for i in range(n):
    p[i]-=1
cnt=0
ans="YES"
for i,p_i in enumerate(p):
    if i==p_i:
        continue
    cnt+=1
    if cnt>1:
        ans="NO"
        break
    for j,p_j in enumerate(p):
        if i==p_j:
            p[j]=p_i
            p[i]=p_j
            break

print(ans)

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

int main()
{
  int64_t n,blue,red,x,y;
  cin>>n>>blue>>red;
  x=n/(blue+red)*blue;
  y=n%(blue+red);
  if(y>=blue)
    y=blue;
  cout<<x+y<<endl;
}

Measured memory_bytes: 3580
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
if n==0:
    print(0)
    exit()
elif n==1:
    print(1)
    exit()
def check(_n):        
    if _n>0:
        j=0
        while True:
            if pow(2,j)-2*(pow(2,j)-1)//3<=_n<=pow(2,j)+(pow(2,j)-1)//3:
                k=j
                break
            else:
                j+=2
    elif _n<0:
        j=1
        while True:
            if -1*pow(2,j)-2*(pow(2,j-1)-1)//3<=_n<=-1*pow(2,j)+(pow(2,j+1)-1)//3:
                k=j
                break
            else:
                j+=2
    else:
        return 0,0
    return _n-pow(-2,k),k
c=n
ans=0
while True:
    res=check(c)
    if c==0:
        ans+=c
        break
    else:
        ans+=pow(10,res[1])
        c=res[0]
print(ans)


Measured memory_bytes: 77376
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  string s;
  cin >> s;

  //even0 even1 odd0 odd1
  vector<int> nums;
  for(int i=0; i<4; i++) nums.push_back(0);
  for(int i=0; i<s.size(); i++){
      if(i%2 == 0){
        if(s.at(i) == '0') nums.at(0) +=1;
        if(s.at(i) == '1') nums.at(1) +=1;
      }else{
        if(s.at(i) == '0') nums.at(2) +=1;
        if(s.at(i) == '1') nums.at(3) +=1;
      }
  }

  int max = -1;
  int maxIdx;
  for(int i=0; i<4; i++){
    if(max < nums.at(i)){
      max = nums.at(i);
      maxIdx = i;
    }
  }


  //even is 0, even is 1, odd is 0, odd is 1
  int ans = 0;
  if(maxIdx == 0 || maxIdx == 3){
    ans += nums.at(1);
    ans += nums.at(2);
  }else{
    ans += nums.at(3);
    ans += nums.at(0);
  }

  cout << ans;
}


Measured memory_bytes: 512
from collections import deque

N = int(input())
units = set()
i = 0
while 6 ** i <= N:
    units.add(6 ** i)
    i += 1
i = 0
while 9 ** i <= N:
    units.add(9 ** i)
    i += 1
units = sorted(units)

mins = list(range(N + 1))
for i in range(1, len(units)):
    unit = units[i]
    for j in range(N):
        if j + unit < len(mins) and mins[j] + 1 < mins[j + unit]:
            mins[j + unit] = mins[j] + 1
print(mins[N])

Measured memory_bytes: 13032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine();
		for(int i = 0; i < n.Length; i++)
		{
			if(n[i] == '9')
			{
				WriteLine("Yes");
				return;
			}
		}
		WriteLine("No");
	}
}


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

const int limit=55;
int grid[limit][limit];
int w, h;
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

void dfs(int, int);

int main(){
  while(cin >> w >> h, w!=0 && h!=0){
    //グリッドに情報格納
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++) cin >> grid[i][j];
    }

    int cnt=0;
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        if(grid[i][j]==1){
          dfs(i, j);
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

void dfs(int y, int x){
  if(grid[y][x]==0) return;
  if(y<0 || y>=h || x<0 || x>=w) return;

  grid[y][x] = 0;

  for(int i=0; i<8; i++){
    int ny = y+dy[i], nx = x+dx[i];
    dfs(ny, nx);
  }
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define maxn 3010
#define inf 1000000007
#define ii pair<int,int>
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define lg2(x) 31 - __builtin_clz(x)
using namespace std;
typedef long long ll;
typedef long double ld;

string a,b;
int dp[maxn][maxn],ans;
ii p[maxn][maxn];

void backtrack(int i,int j){
    db(i)db(j)
    if(p[i][j]!=ii{0,0}) backtrack(p[i][j].f,p[i][j].s);
    if( a[i] == b[j] )
        cout << a[i];
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);

    //freopen("a.in","r",stdin);
    //freopen("a.out","w".stdout);

    cin >> a >> b;

    a = '&' + a;
    b = '&' + b;

    for(int i=1; i<a.size(); i++){
        for(int j=1; j<b.size(); j++){
            if( a[i] == b[j] ){
                dp[i][j] = dp[i-1][j-1] + 1;
                p[i][j] = ii{i-1,j-1};
            }
            if( dp[i][j] < dp[i][j-1] ){
                dp[i][j] = dp[i][j-1];
                p[i][j] = ii{i,j-1};
            }
            if( dp[i][j] < dp[i-1][j] ){
                dp[i][j] = dp[i-1][j];
                p[i][j] = ii{i-1,j};
            }
            ans = max( ans , dp[i][j] );
        }
    }

    for(int i=1; i<a.size(); i++)
        for(int j=1; j<b.size(); j++)
            if( dp[i][j] == ans ){
                backtrack(i,j);
                return 0;
            }

    return 0;
}


Measured memory_bytes: 106496
N = int(input())
indexes = [int(i) for i in input().split(" ")]
manzokuB = [int(i) for i in input().split(" ")]
manzokuC = [int(i) for i in input().split(" ")]
ans = 0
beforeIndex = -1
for index in indexes:
    ans += manzokuB[index - 1]
    if index == (beforeIndex + 1):
        ans += manzokuC[beforeIndex - 1]
    beforeIndex = index

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;

#define rep(i, n) for(i = 0;i < n;++i)
#define pb push_back
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)

struct edge{
  int to;
};

vector<edge> G[10000];
int v, e;

#define maxV 10000
int in[maxV] = {0};
int ord[maxV] = {0};
int topo[maxV] = {0}, topohd = 0;
void toposort(void){
  for(int i = 0;i < v;++i)for(int j = 0;j < G[i].size();++j)++in[G[i][j].to];
  queue<int> Q;
  for(int i = 0;i < v;++i)if(in[i] == 0)Q.push(i);
  for(;!Q.empty();){
    int now = Q.front(); Q.pop();
    topo[topohd++] = now;
    for(int i = 0;i < G[now].size();++i)if(--in[G[now][i].to] == 0)Q.push(G[now][i].to);
  }
  return;
}

signed main(void){
  int i, j;
  scanf("%d%d", &v, &e);
  rep(i, e){
    int2(a, b);
    G[a].pb((edge){b});
  }

  toposort();
  rep(i, v)printf("%d\n", topo[i]);

  return 0;
}

Measured memory_bytes: 3940
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("in.txt","r",stdin);
    ll n;
    while(scanf("%lld",&n)!=-1)
    {
    	ll ans=0;
    	for(int i=sqrt(n);i>=1;i--)
    	{
    		if(n%i==0)
    		{
    			ans+=i+n/i;
    			break;
    		}
    	}
    	printf("%lld\n",ans-2 );
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
#define PI 3.14159265358979323846
int main(){
	double a, b, x; cin >> a >> b >> x;
	double res;
	if (2*x <= a*a*b){
		res = 2*x/(a*b*b);
		//cout << 1;
	}
	else{
		res = a*a*a / (2*(a*a*b - x));
	}
	printf("%.12lf", 90 - atan(res) * 180 / PI);
	//getchar();
	//getchar();
	return 0;
}

Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 171 C - One Quadrillion and One Dalmatians
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/21
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;

long n;

void solve() {

    long d = n;
    int rem = n;
    vector<char> name;
    while(d > 26) {
        rem = d % 26;
        if (rem == 0)
            rem = 26;
        name.push_back('`'+rem);
        d = (d-rem)/26;
        // printf("%d,%d\n",d,rem);
    }
    name.push_back('`'+d);
    reverse(name.begin(), name.end());
    for (int i=0;i<name.size();i++) {
        printf("%c", name[i]);
    }
    printf("\n");

}

int main() {

    scanf("%ld", &n);

    solve();
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=2e5+5;
vector<int> a[N];
vector<int> b[N];
int d[N];
int dp(int k){
	if(d[k]!=-1)return d[k];
	if(a[k].size()==0)return (d[k]=0);
	else {
		int r=0;
		for(int i=0;i<a[k].size();i++){
			r=max(r,dp(a[k][i])+1);
		}
		return d[k]=r;
	}
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)d[i]=-1;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		a[y].push_back(x);
		b[x].push_back(y);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(b[i].size()==0){
			ans=max(ans,dp(i)+1);
		}
	}
	cout<<ans-1<<endl;
} 

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

int main(){
  int S, h, m, s;

  cin >> S;

  h = S / (3600);
  m = (S - 3600*h) / 60;
  s = S - 3600*h - 60*m; 
  
  cout << h << ":" << m << ":" << s << endl;  

}

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

int n, p[N];
ll ans;

int main() {// freopen("_in.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",p+i);
	if (p[1] != 0) {
		puts("-1");  return 0;
	}
	for (int i=1;i<=n;i++) if (p[i]) {
		if (p[i] > p[i-1] + 1) {puts("-1");  return 0;}
		else if (p[i] == p[i-1] + 1) ++ans;
		else ans += p[i];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int a=700;
    string S;
    cin >> S;
    for (int i = 0; i < S.size(); i++){
        if (S[i] == 'o'){
            a += 100;
        }
    }
    cout << a << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
   	string N;
    cin >> N;
  	string ans = "";
  	sort(N.begin(), N.end());
  	int table[26] = {0};
  	for(ll i = 0; i < N.size(); ++i){
     	table[N[i] - 'a']++;
    }
  	for(ll i = 0; i < 26; ++i){
     	if(table[i] == 0) {
          ans = 'a' + i;
          break;
        }
    }
  	
   if(ans == "") cout << "None" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	//	usage:  tp_abs<type name>(a);
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void ABC099D_GoodGrid();

#if 1
int main()
{
	ABC099D_GoodGrid();
	fflush(stdout);
	return 0;
}
#endif

class ABC099D_data {
public:
	int ix = 0;
	int jy = 0;
	int color = 0;
};

static int ABC099D_getDiff(std::vector<std::vector<int>>& gInfo, int diff[][31], int c1, int c2, int c3)
{
	int color[] = { c1, c2, c3 };

	int val = 0;
	for (int i = 0; i < 3; i++) {
		int size = gInfo[i].size();
		for (int j = 1; j < size; j++) {
			val += diff[j][color[i]] * gInfo[i][j];
		}
	}
	return val;
}

static void ABC099D_GoodGrid()
{
	int N, C;
	get2int(N, C);

	auto diff = new int[C + 1][30 + 1];
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			get1int(diff[i][j]);	//	1 - index
		}
	}
	std::vector<std::vector<int>> gInfo(3);
	
	for(int i = 0; i < 3; i++) gInfo[i].resize(C + 1, 0);

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			int tmp;
			get1int(tmp);
			gInfo[(i + j) % 3][tmp]++;
		}
	}

	int diffMin = 1000000000;
	for (int c1 = 1; c1 <= C; c1++) {
		for (int c2 = 1; c2 <= C; c2++) {
			if (c1 == c2) continue;
			for (int c3 = 1; c3 <= C; c3++) {
				if ((c2 == c3) || (c1 == c3)) continue;
				//	iwakan no min
				diffMin = std::min(diffMin, ABC099D_getDiff(gInfo, diff, c1, c2, c3));
			}
		}
	}
	printf("%d\n", diffMin);

	delete[] diff;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
ifstream in ("test.in" );
ofstream out("test.out");
 
const int DIM = 2e5 + 5;
const int INF = 0x3f3f3f3f;
 
map<int, bool> mmp[DIM];
 
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    long long k;
    cin >> k;
    
    for (int i = 2; i <= 50; ++i) {
        long long mnm, mxm;
        
        if (k % i == 0)
            mnm = mxm = (i - 1) + (k / i);
        else {
            mnm = (i - 1) + (k / i) - (k % i);
            mxm = (i - 1) + (k / i) - (k % i - 1) + i;
        }
        
        if (mnm >= 0 && mxm <= 1e16 + 1e3) {
            cout << i << endl;
            for (int j = 1; j <= k % i; ++j)
                cout << mxm << " ";
            for (int j = k % i + 1; j <= i; ++j)
                cout << mnm << " ";
            
            break;
        }
    }
    
    
    
    return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

string s;
int main()
{
	cin>>s;
	int ss=s.size();
	rep(i,ss)
	{
		rep2(j,i+1,ss)
		{
			if(s[i]=='C'&&s[j]=='F')
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
int main(){
    int n;
    std::cin >> n;
    VEC(int,a,n);
    std::vector<int> b(n);
    rep(i,n){
        b[a[i]-1]=i+1;
    }
    rep(i,n)std::cout << b[i] << " ";
    std::cout  << std::endl;
}

Measured memory_bytes: 1664
import java.util.Scanner;

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

		while (true) {
			int n, m;
			n = scan.nextInt();
			m = scan.nextInt();
			int[] taro = new int[n];
			int[] hanako = new int[m];

			int tsum = 0;
			int hsum = 0;

			int[] ttoh = new int[100000];
			int[] htot = new int[100000];

			int flag = 0;
			int set = 0;

			int sum = 200;

			
			int tresult = 0;
			int hresult = 0;

			if (n == 0 && m == 0)
				break;

			for (int i = 0; i < n; i++) {
				taro[i] = scan.nextInt();
				tsum += taro[i];
			}

			for (int i = 0; i < m; i++) {
				hanako[i] = scan.nextInt();
				hsum += hanako[i];
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if ((tsum - taro[i] + hanako[j]) == (hsum - hanako[j] + taro[i])) {
						flag = 1;
						ttoh[set] = taro[i];
						htot[set] = hanako[j];
						set++;
					}
				}
			}

			if (flag == 1) {
				for (int i = 0; i < set; i++) {
					if (sum > ttoh[i] + htot[i]) {
						sum = ttoh[i] + htot[i];
						tresult = ttoh[i];
						hresult = htot[i];
					}
				}
			}

			if (flag == 0) {
				System.out.println(-1);
			} else {
				System.out.println(tresult + " " + hresult);
			}

		}
	}

}

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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 2);

    long long sum = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
        sum += abs(A[i - 1] - A[i]);
    }
    sum += abs(A[N] - A[N + 1]);

    for (int i = 1; i <= N; i++)
    {
        long long ans = sum - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])) + abs(A[i - 1] - A[i + 1]);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
while a = gets do
  a = a.split.map(&:to_i)
  b = gets.split.map(&:to_i)
  h = 0
  c = 0
  4.times do |i|
    4.times do |j|
      c = c + 1 if a[i] == b[j] && i != j
    end
    h = h + 1 if a[i] == b[i]
  end
  puts "#{h} #{c}"
end

Measured memory_bytes: 6108
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
#include<unordered_map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
int myPow(int x,int n){
    int res=1;
    int cur=x;
    while(n>0){
        if(n&1){
            res*=cur;
        }
        cur*=cur;
        n/=2;
    }
    return res;
}
class Node{
    public:
    int no;
    vector<P> edge;
};
signed main(){
  int l;cin>>l;
  vector<Node> node(30);
  --l;
  int bit=1;
  int rem=inf;
  int m=0;
  int n=0;
  rep(i,20){
      if(bit*2-1<=l){
          node[i].edge.push_back({i+1,bit});
          node[i].edge.push_back({i+1,0});
          m+=2;
      }
      bit*=2;
      if(bit*2-1>l){
          rem=bit;
          n=i+1;
          break;
      }
  }
  //cout<<n+1<<endl;
  for(int i=n-1;i>=0;--i){
      int sum=node[i].edge[0].second;
      if(l-rem+1>=sum){
          node[i].edge.push_back({n,rem});
          ++m;
          rem+=sum;
      }
  }
  printf("%lld %lld\n",n+1,m);
  rep(i,n){
      for(const auto& val:node[i].edge){
          printf("%lld %lld %lld\n",i+1,val.first+1,val.second);
      }
  }
  return 0;
}

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

int main(){
    
    long long int n,T;
    cin >> n >> T;
    vector<long long int> t(n);
    for(int i=0; i<n; i++){
        cin >> t.at(i);
    }
    long long int ans=n*T;

    for(int i=1; i<n; i++){
        if(T-(t.at(i)-t.at(i-1))>0){
            ans-=T-(t.at(i)-t.at(i-1));
        }
    }
    cout << ans << endl;
}

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


#define mp make_pair
#define pb push_back
#define rep(i,port,sail) for(i=port;i<=sail;i++)
const int N = 100010;
typedef long long ll;
ll a[N][3],dp[N][3],w[N];
int main()
{
	int n,i,j,k,t;
	ll W;
	cin>>n;
	ll mx  =0;
	rep(i,1,n)rep(j,0,2)cin>>a[i][j];
	rep(j,0,2)dp[1][j]=a[1][j];
	rep(i,2,n){
		rep(j,0,2)
		{
			rep(k,0,2){
				if(j!=k)dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
			}
		}
	}
	rep(j,0,2)mx = max(mx,dp[n][j]);
	cout<<mx<<"\n";


	
	return 0;
}



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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

const int MAX_N = 501;
vi a(MAX_N);
vi rem(MAX_N);
int n, k;

int check(int g) {
    int j = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] % g) {
            rem[j++] = a[i] % g;
        }
    }
    sort(rem.begin(), rem.begin() + j);
    int i = 0; --j;
    ll ans = 0;
    while (i < j) {
        int diff = min(g - rem[j], rem[i]);
        rem[j] += diff;
        rem[i] -= diff;
        ans += diff;
        if (rem[i] == 0) {
            ++i;
        }
        if (rem[j] == g) {
            --j;
        }
    }
    return min(ans, (ll) k + 1);
}

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

    cin >> n >> k;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    vi div;
    for (int i = 1; i * i <= sum; ++i) {
        if (sum % i == 0) {
            div.push_back(i);
            if (i * i != sum)
                div.push_back(sum/i);
        }
    }
    sort(div.begin(), div.end(), greater<int>());
    int ans = 1;
    for (ui i = 0; i < div.size(); ++i) {
        if (check(div[i]) <= k) {
            ans = div[i];
            break;
        }
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
//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 count(a: &Vec<u32>, b: &Vec<u32>, v: u32) -> usize {
    let mut res = 0;
    let mut i = 0;
    let mut j = b.len() - 1;
    while i < a.len() && j < b.len() {
        if a[i] + b[j] >= v {
            res ^= a.len() - i;
            j -= 1;
        } else {
            i += 1;
        }
    }
    res
}

fn run() {
    input! {
        n: usize,
        a: [u32; n],
        b: [u32; n],
    }
    let mut a = a;
    let mut b = b;
    let mut ans = 0;
    for shift in (0..29).rev() {
        a.sort();
        b.sort();
        let cnt = count(&a, &b, 1 << shift) ^ count(&a, &b, 2 << shift) ^ count(&a, &b, 3 << shift);
        if (cnt & 1) == 1 {
            ans |= 1 << shift;
        }
        let mask = ((1 << shift) - 1) as u32;
        for (a, b) in a.iter_mut().zip(b.iter_mut()) {
            *a &= mask;
            *b &= mask;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 10360
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  string prefix,postfix;
  stack<int> st;


  for(int i=0;i<N;i++){
    if(S[i]==')'){
      if(st.empty()){
        prefix+="(";
      } else {
        st.pop();
      }
    } else {
      st.push(S[i]);
    }
  }
  while(!st.empty()){
    postfix += ")";
    st.pop();
  }
  cout << prefix + S + postfix <<endl;
  return 0;
}


Measured memory_bytes: 256