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

#define MAX 2 * 100000 + 20

using namespace std;

int main(){
    int n;
    cin >> n;
    int members[MAX] = {};
    for(int i = 0;i < n;i++){
        int t;
        if(i == n - 1) continue;
        cin >> t;
        members[t - 1]++;
    }
    for(int i = 0;i < n;i++){
        cout << members[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long n,a,b;cin>>n>>a>>b;
    long long c=b-a;
    if((b-a)%2==0){
        cout<<(b-a)/2<<endl;
        return 0;
    }else{
        long long res=min(n-b,a-1);
        res+=1+(c-1)/2;
        cout<<res<<endl;
        return 0;
    }
    //なんでこれがシバかれるのかがまったくもって分からない
}


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

int main(){
    long S, j = 0, ans = 0;
    cin >> S;
    while(pow(10, j) <= S) j++;
    j--;
    for(long bit = 0; bit < (1<<j); bit++){
        long A = S, k = -1;
        for(long i = 0; i < j; i++){
            if((1<<i) & bit){
                ans += A % (long)(pow(10, i - k));
                A = A / (long)(pow(10, i - k));
                k = i;
            }
        }
        ans += A;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4056
#include<iostream>
#include <cstddef>
#include<set>
#include<stack>
#include <deque>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<cmath>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#define  ll  long long
#define ull unsigned long long
#define  sl(a)  scanf("%lld",&a)
#define  si(a)  scanf("%d",&a)
#define mem(n,m) memset(n,m,sizeof(n))
#define PI acos(-1)
#define pb    push_back
#define pf    push_front
#define vll   vector<ll>
#define pll   pair<ll,ll>
#define mp  make_pair
#define vpll vector< pair <ll,ll> >
#define vplpll vector<pair<ll,pair<ll,ll> > >
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S(X) ( (X) * (X) )
#define forab(i, a, b) for(i = a; i <= b; i++)
#define forn(i, n) for(i = 0; i < n; i++)
#define print(a,b) printf("Case %lld: %lld\n",a,b)
using namespace std;
ll powd(ll a,ll b){if(b==1){return a;}if(b%2==1){return powd(a,b-1)*a;}else{ll x=powd(a,b/2); return x*x;}}
ll powm(ll a,ll b,ll m){if(b==0){return 1;}if(b==1){return a%m;}if(b%2==1){return ((powm(a,b-1,m)%m)*(a%m))%m;}else{ll x=powm(a,b/2,m); return ((x%m)*(x%m))%m;}}
ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b,a%b);}
typedef multiset<ll> mlset;
typedef set<ll> mset;
typedef struct node* pnode;
ll a[200005],b[200005];
int main()
{
    ll n,m,k;
    sl(n);
    sl(m);
    sl(k);
    for(ll i=1;i<=n;i++)
    {
        sl(a[i]);
        a[i]=a[i]+a[i-1];
    }
    for(ll j=1;j<=m;j++)
    {
        sl(b[j]);
        b[j]=b[j-1]+b[j];
    }
    ll ans=0,j=m;
    for(ll i=0;i<=n;i++)
    {
        if(a[i]>k)
            break;
        while(b[j]+a[i]>k)
        {
            j--;
        }
        ans=max(ans,i+j);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6888
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
using namespace std;

int main(void){
    string S;
    cin >> S;
    
    int n=S.size();
    char c=S[n-1];
    string ans=S;
    
    if(c == 's'){
        ans += "es";
    }
    else {
        ans += "s";
    }
    
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

int main() {
	int N, W; cin >> N >> W;
	vector<int> w(N + 1), v(N + 1);
	for (int i = 1; i <= N; ++i) cin >> w[i] >> v[i];
	vector<vector<long long> > dp(N + 1, vector<long long>(W + 1));
	for (int i = 1; i <= N; ++i) {
		for (int j = 0; j <= W; ++j) {
			if (j < w[i]) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	cout << dp[N][W] << endl;

	return 0;
}

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

Measured memory_bytes: 35640
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

int N, M;
vector<vector<bool>> adj;
vector<int> out;
vector<double> dp;
vector<double> probability;

double solve_dp() {
    dp.assign(N, 0);

    for (int i = N - 2; i >= 0; i--) {
        double sum = 0;

        for (int j = i + 1; j < N; j++)
            if (adj[i][j])
                sum += dp[j] + 1;

        dp[i] = sum / out[i];
    }

    return dp[0];
}

void solve_probability() {
    probability.assign(N, 0);
    probability[0] = 1;

    for (int i = 0; i < N; i++)
        for (int j = i + 1; j < N; j++)
            if (adj[i][j])
                probability[j] += probability[i] / out[i];
}

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

    cout << fixed << setprecision(12);

    cin >> N >> M;
    adj.assign(N, vector<bool>(N, false));
    out.assign(N, 0);

    for (int i = 0; i < M; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        adj[s][t] = true;
        out[s]++;
    }

    double base = solve_dp();
    double best = base;
    solve_probability();

    for (int s = 0; s < N; s++) {
        if (out[s] <= 1)
            continue;

        double worst = 0;

        for (int t = s + 1; t < N; t++)
            if (adj[s][t])
                worst = max(worst, dp[t]);

        double save = (worst - (dp[s] - 1)) / (out[s] - 1);
        best = min(best, base - probability[s] * save);
    }

    cout << best << '\n';
}


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

long long INF = 1e18;

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    int s;
    for (int i = 1; i <= 1000;i++){
            s = k * i;
            if( a<=s&&s<=b){
                    cout << "OK" << endl;
                    return 0;

            }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
	long long n,m,nd;
	cin>>n>>m;
	nd=n*2;
	if(nd>m) cout<<m/2;
	else if(nd==m) cout<<n;
	else
	{
		m-=nd;
		m/=4;
		cout<<n+m;
	}
	cout<<endl;
	return 0;
}

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int ll
void solve()
{
    int s;
    cin>>s;
    vector<int> v(s+1);
    v[0]=1;
    for(int i=3;i<=s;i++){
        for(int j=3;j<=i;j++){
            v[i]=(v[i]+v[i-j])%(1000000007);
        }
    }
    cout<<v[s]<<"\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
typedef long long ll;
const int MAXN = 5 + 100;
const int MAXV = 5 + 1000;
const ll INF = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
int N,W;
int w[MAXN], v[MAXN];
ll memo[MAXN][MAXN*MAXV];

ll dp(int i, int val) {
    if(val <= 0) return 0LL;
    if(i == N) {
        if(val > 0) {
            return INF;
        } else {
            return 0LL;
        }
    }
    ll& ans = memo[i][val];
    if(ans == -1LL) {
        ans = min(dp(1 + i, val), w[i] + dp(1 + i, val - v[i]));
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N >> W;
    foi(i,0,N) {
        cin >> w[i] >> v[i];
    }
    memset(memo, -1, sizeof memo);
    for(int val = MAXV * MAXN; val >= 0; --val) {
        if(dp(0, val) <= W) {
            cout << val << '\n';
            return 0;
        }
    }
    assert(false);
    return 0;
}


Measured memory_bytes: 86784
n,m=map(int,input().split())
inf=float("inf")

r=lambda n:range(n)
l=[[inf if i!=j else 0 for j in r(n)] for i in r(n)]
a,b,c=[None]*m,[None]*m,[None]*m

for i in r(m):
  a[i],b[i],c[i]=map(int,input().split())
  a[i]-=1
  b[i]-=1
  l[a[i]][b[i]]=c[i]
  l[b[i]][a[i]]=c[i]

for k in r(n):
  for i in r(n):
    for j in r(n):
      l[i][j]=min(l[i][j],l[i][k]+l[k][j])

ans=m
for i in r(m):
  f=False
  for j in r(n):
    if l[j][a[i]]+c[i]==l[j][b[i]]:
      f=True
  if f:ans-=1
print(ans)

Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    ll n;
    cin >> n;
    ll m = n;
    bool f = true;
    while (m >= 10)
    {
        if (m % 10 != 9)
        {
            f = false;
            break;
        }
        m /= 10;
    }
    if (f)
    {
        if (n < 10)
        {
            cout << n << endl;
        }
        else
        {
            int sum = 0;
            while (n >= 10)
            {
                sum += 9;
                n /= 10;
            }
            cout << sum + n << endl;
        }
    }
    else
    {
        int sum = 0;
        while (n >= 10)
        {
            sum += 9;
            n /= 10;
        }
        cout << sum + n - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
class aoj
{
    static void Main()
    {
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            string[] b = a.Split(' ');
            int c = int.Parse(b[0]),d=int.Parse(b[1]),n=int.Parse(b[2]);
            double e = (double)c / (double)d;
            string f = e.ToString();
            string[] g = f.Split('.');
            if (g.Length == 1)
            {
                Console.WriteLine("0"); goto stop;
            }
            int k = 0;
            char[] h = new char[n];
            h=g[1].ToCharArray();
            for(int i = 0; i < h.Length; i++)
            {
                if (i < n)
                {
                    int l = (int)(h[i] - '0');
                    k += l;
                }
                else
                    break;
            }
            Console.WriteLine(k);
            stop:;
        }
    }
}

Measured memory_bytes: 9204
n = int(input())
x = list( map(int, input().split()))
MOD = 10**9 + 7

def make_mod_inv(l,p): # lまでの逆元を作る
    mod_inv = [0, 1] + [0] * (l+3) # inv[n] = n^(-1) mod p, 0! = 1　だけど便宜上inv[0]=0にしてる
    for i in range(2, l+5):
        mod_inv[i] = -mod_inv[p % i] * (p // i) % p
    return mod_inv

mod_inv = make_mod_inv(n-1,MOD)

ans = 0

factorial = 1
for i in range(2,n):
    factorial = (factorial * i%MOD) %MOD

p = [0]*(n-1)
p[0] = 1 * factorial%MOD

for i in range(1,n-1):
    p[i] = p[i-1] + factorial*mod_inv[i+1]
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])%MOD*p[i]
    ans %= MOD

print(int(ans))

Measured memory_bytes: 15376
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

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

	ll cnt = 0;
	if (N & 1) {
		cout << 0 << endl; return 0;
	}
	else {
		for (ll i = 10; i <= N; i *= 5) {
 			cnt += N / i;
		}
	}

	cout << cnt << endl;
}	

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

int main(){
  int n;
  string a,b,c;
  cin >> n >> a >> b >> c;
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[i]==b[i] && b[i]==c[i]){ans+=0;}
    else if(a[i]!=b[i] && b[i]!=c[i] && c[i]!=a[i]){ans+=2;}
    else{ans+=1;}
  }
  cout << ans << endl;
}

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

int main(){
    int L,R;
    cin >> L >> R;
    int m = 2019;
    int mi = 2019;
    for(long long i=L;i<=R;i++){
        for(long long j=i+1;j<=R;j++){
            int ans = i*j % m;
            mi = min(mi,ans);
            if(mi == 0)break;
        }
        if(mi == 0)break;
    }
    cout << mi << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<utility>
#include<vector>
using namespace std;

int solve(){
  string s; cin >> s;
  int a = count(s.begin(), s.end(), 'A');
  cout << (a && 3-a ? "Yes" : "No") << endl;
}

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


Measured memory_bytes: 256
def main():
    n = int(input())
    ans = -1
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            a = i
            b = n // i
            if ans == -1:
                ans = a + b - 2
            else:
                ans = min(ans,a + b - 2)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}

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


int main() {
    ll a,b; cin >> a >> b;
    vector<pair<long long, long long> > p = prime_factorize(gcd(a,b));

    cout << p.size() + 1<< endl;

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    double sum=0;
    for(int i=0;i<N;i++){
        double X;
        string U;
        cin >> X >> U; 
        if(U=="BTC"){  sum += X * 380000; }
        else{ sum += X; }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}



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

	vector<vector<int>> s(m);

	for (int i = 0; i < m; i++){
		int k;
		cin >> k;
		s[i].resize(k);
		for (int j = 0; j < k; j++){
			cin >> s[i][j];
			s[i][j]--;
		}
	}

	vector<int> p(m);
	for (int i = 0; i < m; i++){
		cin >> p[i];
	}

	int ans = 0;
	for (int bit = 0; bit < (1 << n); bit++){
		vector<int> on;
		for (int i = 0; i < n; i++){
			if (bit & (1 << i)){
				on.push_back(i);
			}
		}

		int ok = true;
		for (int i = 0; i < m; i++){
			int oncnt = 0;
			
			for (int j = 0; j < s[i].size(); j++){
				bool tmpok = false;
				for (int k = 0; k < on.size(); k++){
					if (s[i][j] == on[k]){
						tmpok = true;
					}
				}
				if (!tmpok)continue;
				oncnt++;
			}
			if (oncnt % 2 != p[i]){
				ok = false;
				break;
			}
		}
		if (ok){
			ans++;
		}
	}

	cout << ans << endl;

}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

map<int,int> factor(int m){
    map<int,int> vec;
    int end=pow(m,0.5)+2;
    reps(i,2,end){
        while(m%i==0){
            m/=i;
            vec[i]++;
        }
    }
    if(m!=1)vec[1]=1;
    return vec;
}

ll fac[MAX],inv[MAX],finv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    int n,m;
    cin>>n>>m;
    if(m==1){
        cout<<1<<endl;
        return 0;
    }
    ll ans=1;
    COMinit();
    map<int,int> vec=factor(m);
    for(auto iter:vec){
        ans*=COM(iter.second+n-1,n-1);
        ans%=MOD;
    }
    cout<<ans<<endl;
    
}

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

int main(){
  string s;
  cin>>s;
  
  int i=0,a,b;
  while(1){
    if(s.at(i)=='A'){
      a=i;
      break;
    }
    i++;
  }
  i=s.size()-1;
  while(1){
    if(s.at(i)=='Z'){
      b=i;
      break;
    }
    i--;
  }
  
  cout<<b-a+1<<endl;
}

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

using std::cin;
using std::cout;
using std::endl;

int digit(int n, int d) {
	int m = (int)(n/pow(10,d)) * pow(10,d);
	return (n - m)/pow(10,d-1);
}

int check_digit(int n) {
	for (int i = 15; i > 0; i--) {
		if (digit(n, i) > 0) {
			return i;
		}
	}
	return 1;
}

bool check_ruel(int n) {
	int d = check_digit(n);
	for (int i = 1; i < d; i++) {
		if ((digit(n,i) - digit(n,i+1)) != 1) {
			return false;
		}
	}
	return true;
}

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

	std::vector<int> nums(N);
	for (int i = 0; i < N; i++ ) {
		cin >> nums[i];
	}

	int maxp = -1;
	int pro;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			pro = nums[i] * nums[j];

			if (check_ruel(pro)) {
				if (pro > maxp) {
					maxp = pro;
				}
			}
		}
	}

	cout << maxp << endl;

	return 0;
}

Measured memory_bytes: 3284
import java.util.*;
public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] array = new long[n];
        long ans1 = 0;
        long ans2 = 0;



        for(int i = 1;i <= n;i++){//AN-Nを格納
            array[i-1] = sc.nextInt() - i;
        }

        Arrays.sort(array);//昇順ソート　降順は Arrays.sort(array,Collections.reverseOrder());

        long median1 = array[n/2];



        for(int i = 0;i < n;i++){//i=0,1,2,,,,n-1 で動作
            ans1 += Math.abs(array[i] - median1);
        }

        System.out.println(ans1);

    }
}

Measured memory_bytes: 64524
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    ans += b[i]
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int a, b, c;

signed main(){
	scanf("%ld %ld %ld", &a, &b, &c);
	if(a+b >= c-1){
		printf("%ld\n", b + c);
	}else{
		printf("%ld\n", a + b + 1 + b);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
ll X,Y,Z,K;
vector<ll> A(1005),B(1005),C(1005);
int main() {
	cin>>X>>Y>>Z>>K;
	rep(i,X)cin>>A[i];
	rep(i,Y)cin>>B[i];
	rep(i,Z)cin>>C[i];
	sort(all(A),greater<ll>());
	sort(all(B),greater<ll>());
	sort(all(C),greater<ll>());
	vector<ll> ans1;
	rep(i,X)rep(j,Y){
		ans1.push_back(A[i]+B[j]);
	}
	sort(all(ans1),greater<ll>());

	vector<ll> ans2 = {};
	int N = min(K,ll(ans1.size()));
	rep(i,N){
		ans2.push_back(ans1[i]);
	}
	sort(all(ans2),greater<ll>());


	vector<ll> ans3 = {};
	rep(i,ans2.size())rep(j,Z){
		ans3.push_back(ans2[i]+C[j]);
	}
	sort(all(ans3),greater<ll>());


	rep(i,K){
		cout<<ans3[i]<<endl;
	}
	//print(ans1);print(ans2);print(ans3);
}

Measured memory_bytes: 43400
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, M;
    cin >> N >> M;
    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    int X[M];
    for (int i = 0; i < M; i++) {
        cin >> X[i];
    }

    sort(X, X + M);

    int diff[M - 1];
    for (int i = 0; i < M - 1; i++) {
        diff[i] = X[i + 1] - X[i];
    }

    sort(diff, diff + M - 1);

    int ret = 0;

    for (int i = 0; i < M - N; i++) {
        ret += diff[i];
    }

    cout << ret << endl;

    return 0;
}

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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
    n: usize,
    a: [[usize; n]; 2]
    }
    let mut dp = vec![vec![0; n + 1]; 3];
    for i in 0..2 {
        for j in 0..n {
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) + a[i][j]
        }
    }
    let ans = dp[2][n];
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;
long long t[100005], h[100005], vv[100005];
long long mt[100005], mh[100005];
long long rmt[100005], rmh[100005];
long long x[100005], v[100005];

int main(){
    
    int N;
    long long C;
    cin >> N >> C;
    rep(i, N) cin >> x[i] >> v[i];

    t[0]=0;
    mt[0] =0;
    h[0]=0;
    mh[0]=0;
    rmt[0]=0;
    rmh[0]=0;


    rep(i, N) {
        t[i+1] = t[i]+ v[i];
        mt[i+1] = max(mt[i], t[i+1]-x[i]);
        rmt[i+1] = max(rmt[i], t[i+1]-2*x[i]);
        h[i+1] = h[i] + v[N-i-1];
        mh[i+1] = max(mh[i], h[i+1]-(C-x[N-1-i]));
        rmh[i+1] = max(rmh[i], h[i+1]-2*(C-x[N-1-i]));
    }

    //rep(i, N+1) cout << mt[i] << endl;
    //rep(i, N+1) cout << mh[i] << endl;
    //rep(i, N+1) cout << rmt[i] << endl;
    //rep(i, N+1) cout << rmh[i] << endl;

    long long thmax=0, htmax=0, ans=0;
    ans = max(mt[N], mh[N]);

    rep(i, N-1){
        //時計
        //t = max(t, ll[i] - xx[i]);
        //半時計
        //h = max(h, ll[N-1] + ll[N-2-i] - xx[N-1-i]);
        //時計,半時計
        thmax = max((rmt[i+1] + mh[N-i-1]), thmax);
        //半時計,時計
        htmax = max((rmh[i+1] + mt[N-i-1]), htmax);
    }
    ans = max(ans, thmax);
    ans = max(ans, htmax);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
ll a[100002],b[100002],c[100002],n,dp[100002][4];
ll solve(int idx,int prev){
		if(dp[idx][prev]!=-1) return dp[idx][prev];
		if(idx == n)
		return 0;
	
	ll ans = INT_MIN;
	
	if(prev == 0) {
		ans=max(ans,b[idx] + solve(idx+1,1));
		ans=max(ans,c[idx] + solve(idx+1,2));
	
	}
	else	if(prev == 1) {
		ans=max(ans,a[idx] + solve(idx+1,0));
		ans=max(ans,c[idx] + solve(idx+1,2));
		
	}
	else	if(prev == 2) {
			ans = max(ans, b[idx] + solve(idx + 1, 1));
		ans = max(ans, a[idx] + solve(idx + 1, 0));
	
	}else{
		ans = max(ans, c[idx] + solve(idx + 1, 2));
		ans = max(ans, b[idx] + solve(idx + 1, 1));
		ans = max(ans, a[idx] + solve(idx + 1, 0));
	}
		
	return dp[idx][prev]=ans;
}
int main() {

cin>>n;
for(int j=0;j<n;j++) cin>>a[j]>>b[j]>>c[j];
memset(dp,-1,sizeof(dp));
// ll ans;
cout<<(ll)solve(0,3);
	return 0;
}

Measured memory_bytes: 16828
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= (int)b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
int l, r;
int main()
{
	read(l), read(r);
	if(r - l + 1 >= 2019) { puts("0"); return 0;}
	ll ans = 1000000000;
	rep(i, l, r - 1)
		rep(j, i + 1, r) ans = min(ans, 1ll * i * j % 2019);
	printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  int D;
  cin >> N >> D;
  double A[N][D];
  int out=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin >> A[i][j];
    }
  }
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      double kotae=0;
      for(int J=0;J<D;J++){
        kotae=kotae+pow(A[i][J]-A[j][J],2);
      }
      kotae=pow(kotae,0.5);
      int a=static_cast<int>(kotae);
      if(kotae-a==0){
        out++;
      }
    }
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;string s;
    cin>>n>>s;
    string s1=s,s2=s;
    int ans=INF;
    int W=0,B=0;
    vector<int> black(n+1),white(n+1);
    for(int i=0;i<n;i++){
        if(s[i]=='.'){
            W++;
            white[i+1]=white[i]+1;
            black[i+1]=black[i];
        }
        else{
            B++;
            white[i+1]=white[i];
            black[i+1]=black[i]+1;
        }
    }
    ans = min(W,B);
    int w=0,b=0;
    REP(i,n){
        ans=min(ans,black[i]+W-white[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2324
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int a, b, q; readV(a, b, q);
  long[] s; readC(a, s);
  long[] t; readC(b, t);

  auto ss = s.assumeSorted, ts = t.assumeSorted;

  auto nearest(R)(long x, R y, bool d)
  {
    if (d) {
      auto r = y.lowerBound(x);
      return !r.empty ? r.back : -1;
    } else {
      auto r = y.upperBound(x);
      return !r.empty ? r.front : -1;
    }
  }

  auto calc(R)(long x, R s, R t)
  {
    auto r = 10L^^18;

    foreach (i; 0..4) {
      auto x1 = nearest(x, s, i&1);
      if (x1 == -1) continue;
      auto x2 = nearest(x1, t, (i>>1)&1);
      if (x2 == -1) continue;
      r = min(r, (x-x1).abs+(x1-x2).abs);
    }

    return r;
  }

  foreach (_; 0..q) {
    long x; readV(x);
    writeln(min(calc(x, ss, ts), calc(x, ts, ss)));
  }
}


Measured memory_bytes: 5756
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

int cmp (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n, x;
  scanf ("%" SCNi32 "%" SCNi32, &n, &x);
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  qsort (a, n, sizeof (i32), cmp);
  i32 *dp = (i32 *) calloc (x + 1, sizeof (i32));
  for (i32 i = 0; i <= x; ++i) {
    dp[i] = i;
  }
  const i32 mod = 1000000007;
  for (i32 i = 0; i < n; ++i) {
    for (i32 j = x; j >= 0; --j) {
      dp[j] = ((i64) i * dp[j] + dp[j % a[i]]) % mod;
    }
  }
  printf ("%" PRIi32 "\n", dp[x]);
}

int main (void) {
  run ();
  return 0;
}


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

#define fto(i, x, y) for(auto i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(auto i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(auto i = (x); i <= (y); i += a)
#define ftoit(it, var) for (auto it = var.begin(); it != var.end(); ++it)

#define ii pair<int, int>
#define mp make_pair
#define ff first
#define ss second

#define vi vector<int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>

#define eb emplace_back
#define ef emplace_front
#define lb lower_bound
#define ub upper_bound

#define oo 1000000007
#define OO 1000000000000000007LL

using namespace std;

#define Pro "tmp"
#define maxN 1000007

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    
    string s;
    cin >> s;

    s[k-1] = s[k-1]-'A'+'a';
    cout << s << endl;
    
    return 0;
}

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

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

    int count=0, max_count = 0;

    for(int i=0; i<s.size(); i++) {
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            count++;
        }
        else {
            count = 0;
        }
        max_count = max(max_count, count);
    }

    cout << max_count << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;


using ll = long long;

ll gcd(ll x,ll y)
{
    ll t;
    while (x%y!=0)
    {
        t=y;
        y=x%y;
        x=t;
    }
    return y;
}

int main()
{
    Phuong_;
    ll a,b;
    cin >> a >> b;
    cout << (a*b)/gcd(a,b);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int k, a, b;
    cin >> k >> a >> b;
    
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n, k;
    cin>>n>>k;
    if(k == 1) cout<<0<<endl;
    else 
        cout<<(n - k )<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

int d[2001][2001];
int ans[2001];

int main()
{
	int n, x, y;
	cin >> n >> x >> y;
	memset(d, 0x3f, sizeof d);
	Rep(i, n) d[i][i] = 0;
	Rep(i, n) {
		queue<int> q;
		q.push(i);
		while(!q.empty()) {
			int u = q.front(); q.pop();
			if(u > 1 && d[i][u-1] > d[i][u]) {
				d[i][u-1] = d[i][u] + 1;
				q.push(u-1);
			}
			if(u < n && d[i][u+1] > d[i][u]) {
				d[i][u+1] = d[i][u] + 1;
				q.push(u+1);
			}
			if(u == x && d[i][y] > d[i][x]) {
				d[i][y] = d[i][x] + 1;
				q.push(y);
			}
			if(u == y && d[i][x] > d[i][y]) {
				d[i][x] = d[i][y] + 1;
				q.push(x);
			}
		}
		for(int j = i+1; j <= n; ++j) ++ans[d[i][j]];
	}
	Rep(i, (n-1)) cout << ans[i] << '\n';
	return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace  std ;
typedef long l ;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<int> >vii ;
typedef pair<int,int> pi ;
int main()
{
    ll a,b,i,j,n,c,d,k,t,m,q,x,y;
    cin>>n ;
  c = 0 ;
  for(i=1 ; i<=n ; i=i+1)
  {
    stringstream temp ;
    temp<<i ;
    string str;
    temp>>str ;
    if(str.size()%2)
    {
      c++ ;
    }
  }
  cout<<c ;
}

Measured memory_bytes: 256
from heapq import heappush, heappushpop
import sys

input = sys.stdin.readline

Q = int(input())

update_count = 0
al = []
sl = 0
ar = []
sr = 0
b = 0
for _ in range(Q):
    # print(f'al:{al}, sl:{sl}')
    # print(f'ar:{ar},sr:{sr}')
    # print(f'b:{b}')
    # print()
    s = tuple(map(int, input().split()))
    if s[0] == 1:
        # 更新クエリ
        b += s[2]
        if update_count % 2 == 0:  # 左に追加
            x = heappushpop(ar, s[1])  # 右に追加してから,最小値を吐かせる
            sr += s[1] - x
            sl += x
            x *= (-1)
            heappush(al, x)  # 左に追加
        else:  # 右に追加
            x = heappushpop(al, -s[1])  # 左に追加してから,最小値を吐かせる
            x *= (-1)
            sl += s[1] - x
            sr += x
            heappush(ar, x)  # 右に追加
        update_count += 1
        # 左キューalの最大値が中央値になっている
        # 左キューにheappushする際,負値に変換したので,heappopで最大値*(-1)が求まる
    else:
        # 求値クエリ
        x = -al[0]  # 中央値
        cnt_l = (update_count + 1) // 2
        cnt_r = update_count - cnt_l
        print(x, (cnt_l * x - sl) + (sr - cnt_r * x) + b)


Measured memory_bytes: 11296
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
ll n, m;
vector<ll> vec[200100];
bool tsuka[200100];

void dfs(ll x){
    tsuka[x] = true;
    for (ll i = 0; i < vec[x].size(); i++){
        if (tsuka[vec[x][i]]) continue;
        dfs(vec[x][i]);
    }
}

int main(void){
    // Your code here!
    cin >> n >> m;
    for (ll i = 0; i < n + m; i++) tsuka[i] = false;
    for (ll i = 0; i < n; i++){
        ll k;
        cin >> k;
        for (ll j = 0; j < k; j++){
            ll l;
            cin >> l;
            l--;
            vec[i].push_back(n + l);
            vec[n + l].push_back(i);
        }
    }
    dfs(0);
    bool ans = true;
    for (ll i = 0; i < n; i++) {
        if (!tsuka[i]) ans = false;
    }
    cout << (ans ? "YES" : "NO") << endl;
}


Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define ll long long
ll f(int,ll);
int N;
ll X;
vector<ll> a;
vector<ll> p;
int main(){
  cin >> N >> X;
  a.resize(N);
  p.resize(N);
  a[0] = 1;
  p[0] = 1;
  for(int i=1;i<N;i++){
    a[i] = a[i-1] * 2 + 3;
    p[i] = p[i-1] * 2 + 1;
  }

  cout << f(N,X) << endl;
  return 0;
}


ll f(int N,ll X){
  if(N==0){
    if(X<=0){
      return 0;
    }
    else{
      return 1;
    }
  }
  else if(X<=(1 + a[N-1])){
    return f(N-1,X-1);
  }
  else{
    return p[N-1] + 1 + f(N-1,X-2-a[N-1]);
  }
}


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

int main(){
   
    int n;
    cin>>n;
    int temp,count=0;
    for(int i=1;i<=n;++i){
        cin>>temp;
        if((i&1)&&(temp&1))count++;
    }
    cout<<count;
    return 0;
}





Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

vector<int> solve(vector<vector<int>> &neig, int n)
{
	vector<int> parent(n + 1), vis(n + 1);
	for (int i = 1; i <= n; i++)
	{
		if (vis[i])
		{
			continue;
		}
		queue<int> q;
		q.push(i);
		vis[i] = 1;
		parent[i] = i;
		while (!q.empty())
		{
			int cur = q.front();
			q.pop();
			for (int v : neig[cur])
			{
				if (!vis[v])
				{
					vis[v] = 1;
					q.push(v);
					parent[v] = parent[cur];
				}
			}
		}
	}
	return parent;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, l;
	cin >> n >> k >> l;
	vector<vector<int>> n1, n2;
	for (int i = 0; i <= n; i++)
	{
		vector<int> t1, t2;
		n1.pb(t1);
		n2.pb(t2);
	}
	while (k--)
	{
		int u, v;
		cin >> u >> v;
		n1[u].pb(v);
		n1[v].pb(u);
	}
	while (l--)
	{
		int u, v;
		cin >> u >> v;
		n2[u].pb(v);
		n2[v].pb(u);
	}
	vector<int> v1 = solve(n1, n);
	vector<int> v2 = solve(n2, n);
	map<pi, int> u;
	for (int i = 1; i <= n; i++)
	{
		u[{v1[i], v2[i]}]++;
	}
	for (int i = 1; i <= n; i++)
	{
		cout << u[{v1[i], v2[i]}] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 30192
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int K;
	cin >> K;

	cout << 50 << endl;

	int H = K / 50;
	int W = K % 50;

	rep(i, 0, 50)
	{
		if (i < W)
		{
			cout << 49 + H + 1 << " ";
		}
		else
		{
			cout << 49 + H - W << " ";
		}
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}




 
    
void test_case() {

    int k;
    cin >>k;

    int val = k+k;

    queue<ll> q;
    fo(i,1,9) {
        q.push(i);;
    }
    ll ans;
    set<ll> st;
    while(val-- || st.size() <= k) {
        ans = q.front();
        st.insert(ans);
        q.pop();

        if(ans%10 != 0) {
            q.push(ans*10 + ans%10 - 1);
        }
        q.push(ans*10 + ans % 10 );
        if(ans%10 != 9) {
            q.push(ans*10 + ans%10 + 1);
        }
        

        
        // cout<<ans<<" ";
    }

    vecl arr(all(st));

    // for(auto it : arr) {
    //     cout<<it<<" ";
    // }

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

   // cout<<ans<<endl;









}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 17148
import sys

mod = 10**9 + 7

def solve():
    m, n = map(int, input().split())

    ans = modpow(m, n, mod)

    print(ans)

def modpow(x, y, mod):
    res = 1

    while y:
        if y & 1:
            res = (res * x) % mod

        x = (x * x) % mod
        y >>= 1

    return res

if __name__ == '__main__':
    solve()

Measured memory_bytes: 7700
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long K, long long N, std::vector<long long> A){
    A.push_back(A[0]+K);
    ll ans = 0;
    REP(i, N){
        ans = max(ans, A[i+1]-A[i]);
    }
    cout<<K-ans<<endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 4864
program prob6
    implicit none
    integer(16)::N,i,j,ans,tmp,k,ans2
    integer(16),allocatable::A(:),gg(:)
    read(*,*) N
    allocate(A(N),gg(N))
    do i = 1, N
        read(*,*) A(i)
    end do

    call heapsort(n,A)

    ans = 0
    ans2 = 0

    if(mod(n,2) == 1)then
        do i = n/2+2,n
            ans = ans + 2*A(i)
        end do
        do i = 1, n/2
            ans = ans - 2*A(i)
        end do

        ans = ans - min(A(n/2+1) - A(n/2),A(n/2+2) - A(n/2+1))
    else if(n == 2) then
        ans = A(2)-A(1)
    else
        do i = n/2+2, n
            ans = ans + 2*A(i)
        end do
        do i = 1, n/2-1
            ans = ans - 2*A(i)
        end do

        ans = ans + A(n/2+1) - A(n/2)
    end if

    write(*,*) ans

    stop
contains
    subroutine heapsort(n,array)
        implicit none
        integer(16),intent(in) :: n
        integer(16),intent(inout) :: array(1:n)
       
        integer ::i,k,j,l
        double precision :: t
       
        if(n.le.0)then
           write(6,*)"Error, at heapsort"; stop
        endif
        if(n.eq.1)return
      
        l=n/2+1
        k=n
        do while(k.ne.1)
           if(l.gt.1)then
              l=l-1
              t=array(L)
           else
              t=array(k)
              array(k)=array(1)
              k=k-1
              if(k.eq.1) then
                 array(1)=t
                 exit
              endif
           endif
           i=l
           j=l+l
           do while(j.le.k)
              if(j.lt.k)then
                 if(array(j).lt.array(j+1))j=j+1
              endif
              if (t.lt.array(j))then
                 array(i)=array(j)
                 i=j
                 j=j+j
              else
                 j=k+1
              endif
           enddo
           array(i)=t
        enddo
      
        return
    end subroutine heapsort
end program

Measured memory_bytes: 4368