akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
	vector<int> hash(100005);
	int n;
	cin >> n;
	ll s= 0;
	for(int i = 0; i < n; ++i){
		int tmp;
		cin >> tmp;
		s += tmp;
		++hash[tmp];
	}
	int q;
	cin >> q;
	while(q--){
		int x, y;
		cin >> x >> y;
		s += (y-x)*hash[x];
		hash[y] += hash[x];
		hash[x] = 0;
		cout<<s<<"\n";
	}

}


Measured memory_bytes: 3648
#include <iostream>
#include <sstream>

using namespace std;

const int findMax(const int aval, const int bval, const int cval)
{
	int retval = aval;
	if(retval < bval)
	{
		retval = bval;
		if(retval < cval)
		{
			retval = cval;
		}
	}
	else if(retval < cval)
	{
		retval = cval;
	}
	return retval;
}

int main(int argc, char** argv)
{
	int Aval, Bval;
	cin >> Aval >> Bval;
	// cout << Aval << " " << Bval << endl;
    const int sumVal = Aval + Bval;
    const int subVal = Aval - Bval;
    const int mulVal = Aval * Bval;
    cout << findMax(sumVal, subVal, mulVal) << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = []

for i in range(n):
    s.append(int(input()))


new_s = sorted(s)

if(sum(new_s) % 10 == 0):
    for i in range(n):
        if(new_s[i] % 10 != 0):
            new_s[i] = 0
            break

if(sum(new_s) % 10 == 0):
    print(0)
else:
    print(sum(new_s))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	long h[n+1];
	for(int i = 1; i <= n; i++)
		cin>>h[i];
	int t[n+1] = {0};
	for(int i = 0; i < m; i++){
		int a,b;
		cin>>a>>b;
		if(h[a] != h[b]){
		    if(h[a] < h[b])
			    t[a] = 1;
			else
			    t[b] = 1;
		}
		else{
			t[a] = 1;
			t[b] = 1;
		}
	}
	int count = 0;
	for(int i = 1; i <= n; i++){
		if(!t[i]){
			count++;
		}
	}
	cout<<count;
}

Measured memory_bytes: 4800
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
int n;
int a[300009];
int s[300009];

bool judge(ll mid,ll k){
  int idx=upper_bound(a,a+n,mid)-a;
  ll sum=s[idx]+mid*(n-idx);
  if(sum>=mid*k)return 1;
  else return 0;
}

int main(){
  cin>>n;
  rep(i,n){
    int x;
    cin>>x;
    a[x-1]++;
  }
  sort(a,a+n);
  for(int i=0;i<n;i++){
    s[i+1]=s[i]+a[i];
  }

  int ans=n;
  for(int i=1;i<=n;i++){
    while(1){
      if(judge(ans,i))break;
      else ans--;
    }
    cout<<ans<<endl;
  }

  return(0);

}


Measured memory_bytes: 3200
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (A, B): (Vec<i64>, Vec<i64>) = {
        let (mut A, mut B) = (vec![], vec![]);
        for _ in 0..N {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            A.push(iter.next().unwrap().parse().unwrap());
            B.push(iter.next().unwrap().parse().unwrap());
        }
        (A, B)
    };

    let C = {
        let mut C = A.iter().map(|&a| a).zip(B.iter().map(|&b| b)).collect::<Vec<_>>();
        C.sort_by_key(|&(a, b)| b);
        C
    };

    let (ans, _) = C.iter().fold(("Yes", 0), |(res, t), &(a, b)| if a + t <= b { (res, t + a) } else { ("No", t + a) });

    println!("{}", ans);
}

Measured memory_bytes: 12736
#minimazation
n,m=map(int,input().split())
counter=0

lists=list(map(int,input().split()))
mini=min(lists)
for some in lists:
  if some!=mini:
    counter+=1
if counter%(m-1)==0:
  print(counter//(m-1))
else:
  print(counter//(m-1)+1)

Measured memory_bytes: 14004
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int n, j, num = 0;
    cin >> n;
    vector<int>    height(n, 0);
    for(int i = 0; i < n; i++)
        cin >> height.at(i);

    for(int i = 0; i < n;) {
        if(height.at(i) == 0) {
            i++; continue;
        }
        for(j = i; j < n; j++) {
            if(height.at(j) == 0) {
                 break;
            }
        }

        for(int k = i; k < j; k++) {
            height.at(k)--;
        }
        num++;
    }

    cout << num << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,x,ans=INF;
	cin >> N >> x;
	vector<ll> a(N),b(N);
	FOR(i,0,N){
		cin >> a[i];
		b[i] = a[i];
	}
	FOR(xx,0,N+1){
		ll ansp = xx*x;
		FOR(j,0,N){
			ll k = (j-xx+N)%N;
			b[j] = min(b[j],a[k]);
			ansp += b[j];
		}
		ans = min(ans,ansp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
d=read()
c=list(reads())
s=[[]for i in range(d) ]
for i in range(d):
    s[i]=list(reads())
t=[[]for i in range(d)]
for i in range(d):
    t[i]=read()
    t[i]-=1
contestcount=26
last=[0 for i in range(contestcount)]
score=0
for i in range(d):
    score+=s[i][t[i]]
    last[t[i]]=i+1
    for j in range(contestcount):
        score-=c[j]*(i+1-last[j])
    print(score)

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

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var a = ReadInt();
            WriteLine(n * n - a);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <string>
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
typedef long long  ll;
const int MAXN = 2e5 + 5;
int a[MAXN];

int main(){
    faster
    int n; cin >> n;
    vector<int> f(n);
    vector<int> s(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
        f[i] = i + a[i];
        s[i] = i - a[i];
    }
    map<int, int> mp;
    for(int i = 0;i < n;i++)
        mp[s[i]]++;
    ll ans = 0;
    for(int i = 0;i < n;i++){
        auto it  = mp.find(f[i]);
        if(it != mp.end()) ans += mp[f[i]];
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 14300
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define PI atan(1.0)*4

int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int n;
  cin>>n;
  using P = pair<int,int>;
  vector<P> vec(n);
  rep(i,n) cin>>vec[i].first>>vec[i].second;

  int l = min(sx,tx);
  int r = max(sx,tx);
  int u = max(sy,ty);
  int d = min(sy,ty);

  auto in = [&](int p, int q){
    return l<=p && p<=r && d<=q && q<=u;
  };

  if( (l==sx && u==sy) || (l==tx && u==ty) ){
    rep(i,n) if( in(vec[i].fi, vec[i].se) ) vec[i].second = d + (u - vec[i].second);
  }
  sort(all(vec));

  vector<int> v;
  rep(i,n) if( in(vec[i].fi, vec[i].se) ) v.pb(vec[i].se);

  vector<int> dp(v.size()+1, INF);
  rep(i,v.size()){
    int idx = lower_bound(all(dp), v[i]) - dp.begin();
    dp[idx] = v[i];
  }

  int lis = lower_bound(all(dp), INF) - dp.begin();

  double ans = (r-l + u-d)*100.0 + (PI*5 - 20)*lis;

  if(lis == min(r-l+1, u-d+1)) ans += PI*5;

  printf("%.15f\n", ans);

  return 0;
}


Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int N, int x, int[] A)
        {
            int ans = 0;
            Array.Sort(A);
            for (int i = 0; i < N; ++i)
            {
                int a = A[i];
                if ((x > a && i < N - 1) || x == a)
                {
                    x -= a;
                    ++ans;
                }
            }
            return ans;
        }
        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int[] A = ReadInts();
            Console.WriteLine(Solve(V[0], V[1], A));
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;

    vector<int> t(n);
    for(int i = 0; i < n; i++)
    cin >> t[i];

    int m;
    cin >> m;

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

    for(int i = 0; i < m; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            if(p[i] - 1 == j){
                sum += x[i];
            }
            else
            {
                sum += t[j];
            }
            
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

long long GCD(long long m,long long n){
    if(n == 0) return m;
    else return GCD(n,m % n);
}

signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(GCD(a,b) == 1) cout << "YES" << endl;
    else if(c % GCD(a,b) == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())
alphabets = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

for i in range(len(S)):
    index = alphabets.index(S[i])
    moved = index+N
    if 25 < moved:
        moved = moved-26
    S[i] = alphabets[moved]
print(*S,sep="")

Measured memory_bytes: 4724
using System;
using System.Linq;

class Program {
  static void Main() {
    int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int a = arr[0];
    int b = arr[1];
    int c = arr[2];
    int d = arr[3];
    Console.WriteLine(Math.Max(a * b, c * d));
  }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N=1e5+5;


void init();
void work();
int ca=1;
int main(){
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
//    init();
//    int T;cin>>T;
//    while(T--)
    work();
    return 0;
}
void work(){
    int n;cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum;
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<iostream>
#include<stack>
#include<algorithm>
#define MAX 1400

using namespace std;

struct Rectangle{int height; int pos;};

int getLargestRectangle(int size, int buffer[]){
	stack<Rectangle> S;
	int maxv = 0;
	buffer[size] = 0;

	for(int i = 0; i <= size; i++){
		Rectangle rect;
		rect.height = buffer[i];
		rect.pos = i;
		if(S.empty()){
			S.push(rect);
		}else{
			if(S.top().height < rect.height){
				S.push(rect);
			}else if(S.top().height > rect.height){
				int target = i;
				while(!S.empty() && S.top().height >= rect.height){
					Rectangle pre = S.top(); S.pop();
					int area = pre.height * (i - pre.pos);
					maxv= max(maxv, area);
					target = pre.pos;
				}
				rect.pos = target;
				S.push(rect);
			}
		}
	}
	return maxv;
}

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

int getLargestRectangle(){
	for(int j = 0; j < W; j++){
		for(int i = 0; i < H; i++){
			if(buffer[i][j]){
				T[i][j] = 0;
			}else{
				T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
			}
		}
	}

	int maxv = 0;
	for(int i = 0; i < H; i++){
		maxv = max(maxv, getLargestRectangle(W, T[i]));
	}

	return maxv;
}

int main(){
	scanf("%d %d", &H, &W);
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			scanf("%d", &buffer[i][j]);
		}
	}
	cout << getLargestRectangle() << endl;

	return 0;
}

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

const int maxn = 2000;
int n, m, fa[maxn + 3], dep[maxn + 3], u[maxn + 3], v[maxn + 3], w[maxn + 3], ans;
int b[maxn + 3][maxn + 3], g[maxn + 3][2], tot, lft[maxn + 3], rht[maxn + 3], wei[maxn + 3];
bool vis[maxn + 3], res[maxn + 3];
vector<int> G[maxn + 3], D[maxn + 3], V[maxn + 3];
vector<pair<int, int> > S[maxn + 3];

void add(int u, int v) {
	G[u].push_back(v);
}

void dfs(int u, int pa = 0) {
	for (int i = 0, v; i < G[u].size(); i++) {
		v = G[u][i];
		if (v == pa) continue;
		dep[v] = dep[u] + 1;
		fa[v] = u;
		dfs(v, u);
	}
}

void add_lim(int u, int v, int w) {
	lft[++tot] = u, rht[tot] = v, wei[tot] = w;
}

void solve(int u, int pa = 0) {
	g[u][0] = g[u][1] = -1;
	for (int i = 1; i <= m; i++) {
		b[u][i] = -1;
	}
	for (int i = 0, v; i < G[u].size(); i++) {
		v = G[u][i];
		if (v == pa) continue;
		solve(v, u);
		for (int j = 1; j <= m; j++) {
			if (b[u][j] == -1) {
				b[u][j] = b[v][j];
			}
		}
	}
	for (int i = 0; i < S[u].size(); i++) {
		pair<int, int> x = S[u][i];
		b[u][x.first] = x.second;
	}
	int cnt = 0;
	for (int i = 1; i <= m; i++) {
		cnt += b[u][i] != -1;
	}
	if (cnt < 2) {
		ans += cnt;
	} else {
		ans += 2;
		int p = 0;
		for (int i = 0, v; i < G[u].size(); i++) {
			v = G[u][i];
			if (v == pa) continue;
			if (g[v][0] == -1) continue;
			if (~b[u][g[v][0]] && ~b[u][g[v][1]]) {
				p = v;
				break;
			}
		}
		if (p) {
			g[u][0] = g[p][0];
			g[u][1] = g[p][1];
		} else {
			int x = 0, y = 0;
			for (int i = 1; i <= m; i++) {
				if (b[u][i] == -1) continue;
				if (!x) {
					x = i;
				} else if (x && !y) {
					y = i;
				}
			}
			g[u][0] = x, g[u][1] = y;
			add_lim(x, y, b[u][x] ^ b[u][y] ^ 1);
		}
	}
}

void color(int u) {
	vis[u] = true;
	for (int i = 0, v; i < D[u].size(); i++) {
		v = D[u][i];
		if (vis[v]) continue;
		res[v] = res[u] ^ V[u][i];
		color(v);
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d %d", &u, &v);
		add(u, v), add(v, u);
	}
	dfs(1);
	for (int i = 1; i <= m; i++) {
		scanf("%d %d", &u[i], &v[i]);
		int x = u[i], y = v[i];
		while (x != y) {
			if (dep[x] < dep[y]) swap(x, y);
			x = fa[x];
		}
		w[i] = x;
		if (u[i] != w[i]) {
			S[u[i]].push_back(make_pair(i, 0));
		}
		if (v[i] != w[i]) {
			S[v[i]].push_back(make_pair(i, 1));
		}
		S[w[i]].push_back(make_pair(i, -1));
	}
	solve(1);
	printf("%d\n", ans);
	for (int i = 1; i <= tot; i++) {
		D[lft[i]].push_back(rht[i]), V[lft[i]].push_back(wei[i]);
		D[rht[i]].push_back(lft[i]), V[rht[i]].push_back(wei[i]);
	}
	for (int i = 1; i <= m; i++) {
		if (!vis[i]) color(i);
	}
	for (int i = 1; i <= m; i++) {
		if (!res[i]) {
			printf("%d %d\n", u[i], v[i]);
		} else {
			printf("%d %d\n", v[i], u[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
#define N (17) 
using namespace std;
int m,n;
double neko[N][N];
double mem[N][1<<N];
int used[N][1<<N];

double dfs(int pos,int bit){
  if(pos==n) return 1;
  if(used[pos][bit]++) return mem[pos][bit];

  double res=0;
  for(int i=0;i<m;i++){
    if(bit&(1<<i))continue;
    double r=0,t=1;
    for(int j=pos;j<=n;j++){
      r+=t*(1-neko[i][j])*dfs(j,bit|(1<<i));
      t*=neko[i][j];
    }
    res = max(res,r);
  }
  return mem[pos][bit] = res;
}

int main(){

  cin>>m>>n;
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++)cin>>neko[i][j];
    neko[i][n] = 0;
  }

  printf("%.10f\n",dfs(0,0));
  return 0;
}

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

int main(){
    int x, y;
    char a[110], b[110], c[110];
    scanf("%s %s %s", a, b, c);
    
    x = strlen(a); 
    y = strlen(b);

    if((a[x-1]==b[0])&&(b[y-1]==c[0])){
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        sc.nextLine();
        String [][] S = new String [H][W];
        final int height = H;
        final int width = W;
        int [][] number = new int [H][W];
        String[]tmp = new String[H];
       

        for (int i = 0; i < H ; i++){
            tmp[i] = sc.nextLine();
        }
            
        //set Tiles
        for (int i = 0; i < H ; i++){
            String[] str = tmp[i].split("");
            for (int j = 0; j <W ; j++){
                
                S[i][j] = str[j];
            }
        }
        //print mine number
        for (int i = 0; i < H ; i++){
            for(int j = 0; j < W; j ++){
                if( S[i][j].equals("#") ){
                    System.out.print(S[i][j]);    
                }else{
                    number[i][j] = countMine(i , j, height, width, S );
                    System.out.print(number[i][j]);
                }
            }
            System.out.println();
        }
        sc.close();
    }
    
    public static int countMine( int h, int w, int height, int width, String[][] S){
        int count = 0;
        for (int i = h - 1; i <=  h + 1; i++){
            if( i < 0 || i >= height ){
                continue;
            }
            for (int j = w - 1; j <= w + 1; j++){

                if( j < 0 || j >= width){
                    continue;
                }
                if ( S[i][j].equals("#")){
                   count++;
               }
            }
        }
        return count;
    }
}

Measured memory_bytes: 22868
# TODO D - Cake 123
# https://atcoder.jp/contests/abc123/tasks/abc123_d

X, Y, Z, K = map(int, raw_input().split())

A = sorted(map(int,raw_input().split()), reverse=True)
B = sorted(map(int,raw_input().split()), reverse=True)
C = sorted(map(int,raw_input().split()), reverse=True)

AB = sorted([a+b for a in A for b in B], reverse=True)
ABC = sorted([ab + c for ab in AB[:K] for c in C], reverse=True)

for i in ABC[:K]:
    print '{}'.format(i)


Measured memory_bytes: 163648
import math

n = int(input())
v_list = [int(i) for i in input().split()] 
c_list = [int(i) for i in input().split()] 

i = 0
sum = 0

while i < n:
  diff = v_list[i] - c_list[i]
  if diff > 0:
    sum += diff
  i+=1 
  
print(sum)

Measured memory_bytes: 3060
N,K = map(int,input().split())
sunuke = [False]*N
ans = 0

for i in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for j in A:
        sunuke[j-1] = True
        
for person in sunuke:
    if not person:
        ans += 1

print(ans)

Measured memory_bytes: 9128
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<cmath>
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long arr[124];
    for(long long i=0;i<=122;i++){
    	arr[i]=i*i*i*i*i;
    }
//    long long a=120*120*120*120*120-119*119*119*119*119;
//    cout<<a<<endl;
    long long x;
    cin>>x;
    for(int i=0;i<=122;i++){
    	for(int j=i;j<=122;j++){
    		if(arr[j]-arr[i]==x){
    			cout<<j<<" "<<i<<endl;
    			return 0;
    		}
    		if(arr[j]+arr[i]==x){
    			cout<<j<<" "<<'-'<<i<<endl;
    			return 0;
    		}
    	}
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int N;
int main(){
	cin>>N;
  	for (int i=0;i<N;i++){
		int a; cin>>a;
      	if (a %2 == 0 && (!(a%3 == 0 || a%5 == 0))){
          	cout<<"DENIED";
          	return 0;
        }
    }
  cout<<"APPROVED";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};


int main(){
	ll n,k; cin >> n >> k;
	vl a(n); rep(i,n) cin >> a[i], a[i] -= k;
	REP(i,1,n) a[i] += a[i-1];
	vpl b(n);
	rep(i,n) b[i].first = a[i], b[i].second = i;
	sort(all(b));
	ll now = -inf;
	ll id = 0;
	ll num = n+1;
	rep(i,n){
		if(now == b[i].first) a[b[i].second] = id;
		else{
			id++;
			if(b[i].first >= 0) chmin(num,id);
			now = b[i].first;
			a[b[i].second] = id;
		}
	}
	BinaryIndexedTree<ll> bit(n+1);
	rep(i,n){
		bit.add(a[i],1);
	}
	ll ans = 0;
	rep(i,n){
		ans += n-i - bit.sum(num-1);
		num = a[i];
		bit.add(a[i],-1);
	}
	cout << ans << endl;
}

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

      int a = sc.nextInt();
      String s;
      int count = 0;

      for (int i = 1;i<=a ;i++ ) {
        s = String.valueOf(i);
        if(s.length()%2==0){
          count++;
        }
      }
      System.out.println(a-count);
}
}


Measured memory_bytes: 27092
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int k;
    cin >> k;
    vector<int> a(k);
    forn(i, 0, k) cin >> a[i];
    reverse(all(a));
    ll mn = 2, mx = 2;
    if (a[0] != 2) {
        cout << "-1\n";
        return 0;
    }
    forn(i, 1, k) {
        if (mn % a[i])
            mn += a[i] - mn % a[i];
        mx += a[i - 1] - mx % a[i - 1];
        --mx;
        mx -= mx % a[i];
        //cerr << mn << ' ' << mx << '\n';
    }
    mx += a.back() - 1;
    if (mn > mx) {
        cout << "-1\n";
        return 0;
    }
    cout << mn << ' ' << mx << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1e4;
constexpr int NIL = -1;
struct Node { int p = NIL, l = NIL, r = NIL; };
vector<Node> T(MAX);
vi D(MAX), H(MAX);
inline void setDepth(int u, int d) {
	if(u == NIL) return;
	D[u] = d;
	setDepth(T[u].l, d + 1);
	setDepth(T[u].r, d + 1);
}
inline int setHeight(int u) {
	int h1 = 0, h2 = 0;
	if(T[u].l != NIL) h1 = setHeight(T[u].l) + 1;
	if(T[u].r != NIL) h2 = setHeight(T[u].r) + 1;
	return H[u] = max(h1, h2);
}
inline int getSibling(int u) {
	if(T[u].p == NIL) return NIL;
	if(T[T[u].p].l != u && T[T[u].p].l != NIL)
		return T[T[u].p].l;
	if(T[T[u].p].r != u && T[T[u].p].r != NIL)
		return T[T[u].p].r;
	return NIL;
}
int main() {
	int n; cin >> n;
	int v;
	rep(i, 0, n) {
		cin >> v;
		cin >> T[v].l >> T[v].r;
		if(T[v].l != NIL) T[T[v].l].p = v;
		if(T[v].r != NIL) T[T[v].r].p = v;
	}
	int root;
	rep(i, 0, n) if(T[i].p == NIL) { root = i; break; }
	setDepth(root, 0);
	setHeight(root);
	rep(u, 0, n) {
		cout << "node " << u << ": "
			<< "parent = " << T[u].p << ", "
			<< "sibling = " << getSibling(u) << ", ";
		int deg = 0;
		if(T[u].l != NIL) ++deg;
		if(T[u].r != NIL) ++deg;
		cout << "degree = " << deg << ", "
			<< "depth = " << D[u] << ", "
			<< "height = " << H[u] << ", ";
		if(T[u].p == NIL) P("root");
		else if(T[u].l == NIL && T[u].r == NIL) P("leaf");
		else P("internal node");
	}
	return 0;
}

Measured memory_bytes: 3288
#include <stdio.h>

int main()
{
  int i,j,n,Adj[100][100],u,k,v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      Adj[i][j]=0;
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      Adj[u][v]=1;
    }
  }
 
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",Adj[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 636
N = int(input())
if N < 10:
  print(N)
elif N < 100:
  print(9)
elif N < 1000:
  print(9 + (N-99))
elif N < 10000:
  print(909)
elif N < 100000:
  print(909 + (N-9999))
else:
  print(90909)

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

int main() {
  vector<int> aa;
  for (int k = 0; k < 3; k++) {
    int t;
    cin >> t;
    aa.push_back(t);
  }
  sort(aa.begin(), aa.end());
  int ans = 0;
  for (int k = 0; k < 2; k++) {
    ans += aa[k+1] - aa[k];
  }
  cout << ans << endl;

}

Measured memory_bytes: 764
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  vector<int> arr(N);
  for(int i=0;i<N;++i){
    cin>>arr[i];
  }
  sort(arr.begin(), arr.end());
  int ans = 0;
  for(int i=0;i<K;++i){
    ans += arr[i];
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3632
s = input()
if s == s[::-1]:
    print('0')
else:
    left = s[:len(s) // 2]
    right = s[len(s) // 2 + (1 if len(s) % 2 else 0):][::-1]
    res = 0
    for a, b in zip(left, right):
        if a != b:
            res += 1
    print(res)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

int main(){
  FIO;
  // ifstream cin("input");
  string a,b;
  cin>>a>>b;
  int flag=0;
  for(int i=0;i<a.size();i++){
    if(a[i]!=b[i]){
      flag=1;
      break;
    }
  }
  if(flag==0){
    if(a.size()+1 == b.size()){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;  
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int bingo[5][5],v[5][5],n,b[15];
	memset(v,0,sizeof(v));
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			cin>>bingo[i][j];
	cin>>n;
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++){
		for(int j=1;j<=3;j++){
			for(int k=1;k<=3;k++){
				if(bingo[j][k]==b[i]) v[j][k]=1;
			}
		}
	}
	bool f=false;
	int m,x;
	for(int i=1;i<=3;i++){
		m=0;x=0;
		for(int j=1;j<=3;j++){
			if(v[i][j]==1) m++;
			if(m==3){
				f=true;
				break;
			}
			if(v[j][i]==1) x++;
			if(x==3){
				f=true;
				break;
			}
		}
	}
	if(v[1][1]==1&&v[2][2]==1&&v[3][3]==1||v[1][3]==1&&v[2][2]==1&&v[3][1]==1) f=true;
	if(f) cout<<"Yes";
	else cout<<"No";
	return 0;
} 

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

int main(void){
    int x;
    scanf("%d",&x);

    int num = x-1;
    int flag = 1;
    while (flag){
        num++;
        if(num<2){
            continue;
        }else if(num == 2){
            break;
        }else if(num % 2 == 0){
            continue;
        }
        int i;
        double sqrtnum = sqrt(num);
        for(i = 3; i <= sqrtnum; i += 2){
            if(num % i == 0){
                flag = 1;
                break;
            }else{
                flag = 0;
            }
        }
        if(flag) continue;
        else break;
    }

    printf("%d\n",num);
    
    return 0;
}

Measured memory_bytes: 128
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

int n,m,k;
char g[10][10];
signed main(){
    FastIO;
    cin>>n>>m>>k;
    rep(i,1,n) rep(j,1,m) cin>>g[i][j];
    int ans=0;
    rep(i,1,(1<<n)) rep(j,1,(1<<m)){
        int cnt=0;
        rep(r,1,n){
            rep(c,1,m) if(i&(1<<(r-1)) and j&(1<<(c-1))){
                cnt+=(g[r][c]=='#');
            }
        }
//        if(cnt==k) cout<<i<<' '<<j<<endl;
        ans+=(cnt==k);
    }
    cout<<ans;
    return 0;
}


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

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

    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
        cout << "No" << endl;
        return 0;
    }

    if(s[0] == s[1]){
        if(s[2] == s[3]){
            cout << "Yes" << endl;
            return 0;
        }
        else cout << "No" << endl;
        return 0;
    }

    if(s[0] == s[2]){
        if(s[1] == s[3]){
            cout << "Yes" << endl;
            return 0;
        }
        else cout << "No" << endl;
        return 0;
    }

    if(s[1] == s[2]){
        if(s[0] == s[3]){
            cout << "Yes" << endl;
            return 0;
        }
        else cout << "No" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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 main(void){
    int N,M; cin >> N >> M;
    int ans = 1, m=M;
    while(m){ans *= 2; m--;}
    cout << ans*(100*(N-M) + 1900*M) << endl;
    return 0;
}

Measured memory_bytes: 256
s=list(input())
k1=int(input())
l1=set()
for i in range(len(s)):
    l1.add(s[i])
a1=[]
for i in range(len(l1)):
    a1.append(l1.pop())
a1.sort()
for i in range(len(a1)):
    str=a1[i]
    l2=set()
    for j in range(len(s)):
        if s[j]==str:
            l2.add(s[j])
            str2=s[j]
            for k in range(j+1,min(len(s),j+7)):
                str2+=s[k]
                l2.add(str2)
    if len(l2)>=k1:
        l3=sorted(l2)
        ans=l3[k1-1]
        break
    else:
        k1-=len(l2)
print(ans)


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

long long int chmin(long long int a, long long int b)
{
	if (a > b)
		return b;
	else
		return a;
}

// void chmin(long long int a[], long long int b)
// {
// 	if ()
// }

int main(int argc, char const *argv[])
{
	long long int n;
	scanf("%lld", &n);
	long long int *dp = (long long int*)malloc(n * sizeof(long long int));
	long long int *h = (long long int*)malloc(n * sizeof(long long int));
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &h[i]);
	}
	dp[0] = 0;
	dp[1] = llabs(h[1] - h[0]);
	for (int i = 2; i < n; ++i)
		dp[i] = chmin(dp[i - 1] + llabs(h[i] - h[i-1]), dp[i - 2] + llabs(h[i] - h[i - 2]));
	free(h);
	printf("%lld", dp[n-1]);
	free(dp);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      int n,m;
      cin >> n >> m;
      int x[m];
      rep(i,m)cin >> x[i];
      ll ans=inf;
      sort(x,x+m);
      int dif[m-1];
      rep(i,m-1){
        dif[i]=x[i+1]-x[i];
      }
      sort(dif,dif+m-1);
      reverse(dif,dif+m-1);
      ans=x[m-1]-x[0];
      if(n>=m){
       cout << 0 << endl;
        return 0;
      }
      rep(i,n-1){
        ans-=dif[i];
      }
      cout << ans << endl;
      return 0;}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) sort(v.begin(),v.end())
#define ALL(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n,m;
    cin >> n;
    vector<string> s(n);
    map<string, int> mp;
    rep(i,n){
        cin >> s[i];
        mp[s[i]]++;
    }
    cin >> m;
    vector<string> t(m);
    rep(i,m){
        cin >> t[i];
        mp[t[i]]--;
    }
    vector<int> b;
    for(auto x:mp){
        b.pb(x.second);
    }
    ALL(b);
    if(b[0] > 0){
        cout << b[0] << endl;
        return 0;
    }else{
        cout << '0' << endl;
        return 0;
    }
}

Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
list=[]
for hh in h:
  list.append(t-0.006*hh)
ans=[]
for l in list:
  ans.append(abs(a-l))
print(ans.index(min(ans))+1)
        

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
#define ls int len=s.size()
#define ls1 int len1=s1.size()
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%I64d",&x)
#define reps(i,n) for(int i=1;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=n-1;i>=0;i--)
typedef long long int LL;
typedef long long int ll;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include<stack>
#include<ctime>
void g(int t){if(t){g((t-1)/26);putchar(65+(t-1)%26);}}

const int M=2*1e5+100;
int f[M],f1[M],r[M],r1[M];

void init(int n){
    rep(i,n){
        f[i]=i;f1[i]=i;
        r[i]=r1[i]=0;
    }
}
int find(int x){
    return f[x]==x?x:f[x]=find(f[x]);
}
int find1(int x){
    return f1[x]==x?x:f1[x]=find1(f1[x]);
}
void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;

    if(r[x]<r[y]) f[x]=y;
    else{
        f[y]=x;
        if(r[x]==r[y]) r[x]++;
    }
}
void unite1(int x,int y){
    x=find1(x);y=find1(y);
    if(x==y) return;
    if(r1[x]<r1[y]) f1[x]=y;
    else{
        f1[y]=x;
        if(r1[x]==r1[y]) r1[x]++;
    }
}

map<pair<int,int>,int>mp;

int main()
{
#ifdef LOCAL
    freopen("data.h", "r", stdin);
    //freopen("1.h","w",stdout);
#endif
    int n,K,L;
    scanf("%d%d%d",&n,&K,&L);
    init(n);
    rep(i,K){
        int v,u;
        scanf("%d%d",&v,&u);
        unite(v,u);
    }
    rep(i,L){
        int v,u;
        scanf("%d%d",&v,&u);
        unite1(v,u);
    }
    mp.clear();
    for(int i=1;i<=n;i++){
        mp[make_pair(find(i),find1(i))]++;
    }

    for(int i=1;i<=n;i++){
        printf("%d ",mp[make_pair(find(i),find1(i))]);
    }
    cout<<endl;
}


Measured memory_bytes: 15104
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for j in range(N):
    ans += bisect.bisect_left(A, B[j]) * (N - bisect.bisect_right(C, B[j]))
print(ans)

Measured memory_bytes: 23228
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define change(a,b) do{ll c=a; a=b; b=c;}while(0)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        change(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  string S;
  cin>>S;
  if(S=="hi")cout<<"Yes"<<endl;
  else if(S=="hihi")cout<<"Yes"<<endl;
  else if(S=="hihihi")cout<<"Yes"<<endl;
  else if(S=="hihihihihi")cout<<"Yes"<<endl;
  else if(S=="hihihihi")cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  // 入力
  string S;
  cin >> S;
  long int Q;
  cin >> Q;

  int T;
  int F;
  string C;
  
  long int is_hanten = 0;
  for (long int i=0; i<Q; i++) {
    cin >> T;
    if (T == 1) {
      is_hanten++;
    } else {  // T == 2
      cin >> F >> C;
      if ( (F == 1 && is_hanten%2 == 0) || (F == 2 && is_hanten%2 == 1) ) {
        S.insert(0, C);
      } else {  // F == 2
        S.append(C);
      }
    }
  }
  
  if (is_hanten%2 == 1) {
    reverse(S.begin(), S.end());
  }

  cout << S << endl;
  
  return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define ll int
#define N 100000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
        * @author :: Sawlani
        *
        */

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

  ll a[n+1];
   f(i,1,n) cin >> a[i];

   sort(a+1,a+n+1);

   f(i,2,n)
   {
      if(a[i]==a[i-1])
      {
        cout << "NO" ;
        return 0;
      } 

   }
   cout << "YES";
   return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

int main(void){
  int X,Y;
  cin >>X>>Y;
  cout <<X+Y/2<<endl;
  return 0;
}


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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X; 
    int res = 0;
    for (int a = 0; a <= A; a++) {
        for (int  b = 0; b <= B; b++) {
            for (int c = 0; c <= C; c++) {
                int sum = 500 * a + 100 * b + 50 * c;
                if (sum == X) {
                    res++;
                }
            }
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    int nlist[4] = {0, 3, 5, 7};
    auto dp = make_v(str.size() + 1, 2, 8, 2, 0LL);
    dp[0][1][0][0] = 1;
    REP(i, 0, str.size()) {
        REP(j, 0, 2) {
            int mx = (j ? str[i] - '0' : 9);
            REP(a, 0, 2) {
                for (int k = a; k < 4 && nlist[k] <= mx; k++) {
                    for (int t = 0; t < 8; t++) {
                        int at = t;
                        if (k > 0) {
                            at |= 1 << (k - 1);
                        }
                        dp[i + 1][j && (nlist[k] == mx)][at][a || k > 0] += dp[i][j][t][a];
                    }
                }
            }
        }
    }
    /*
    REP(i, 0, str.size() + 1) {
        REP(j, 0, 2) {
            REP(k, 0, 8) {
                REP(a, 0, 2) {
                    cout << dp[i][j][k][a] << " \n"[a == 1];
                }
            }
            cout << endl;
        }
    }
    **/

    int ans = 0;
    REP(i, 0, 2) {
        ans += dp[str.size()][i][7][1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256