akhauriyash/Code-Regression huggingface dataset:
import itertools 
def take_solve(take):
    result=float("inf")
    for x,y,z in itertools.permutations(take):
        result=min(result,abs(x-a)+abs(y-b)+abs(z-c))
    return result

n,a,b,c=[int(x) for x in input().split()]
l=[]
for _ in range(n):
    l.append(int(input()))
from collections import defaultdict
d=defaultdict(int)
def ans(takes):
    takes=sorted(takes)
    key=str(takes)
    if key in d.keys():
        return d[key]
    m=len(takes)
    result=float("inf")
    if m==3:
        result=min(result,take_solve(takes)+10*(n-m))
    else:
        for i,j in itertools.combinations(list(range(m)),2):
            next_take=[takes[x] for x in range(m) if not x in (i,j)]
            next_take.append(takes[i]+takes[j])
            result=min(result,ans(next_take))
        for i,j,k in itertools.combinations(list(range(m)),3):
            result=min(result,take_solve((takes[i],takes[j],takes[k]))+10*(n-m))
    d[key]=result
    return result
print(ans(l))

Measured memory_bytes: 59996
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    string N;
    int K;
    cin >> N >> K;
    set<int> D;
    rep(i, 0, K) {
        int x;
        cin >> x;
        D.insert(x);
    }
    int mini = 0, mini2 = 1;
    rep(i, 0, 10){
        if (D.count(mini)){
            mini++;
        }
        else{
            break;
        }
    }
    rep(i, 0, 10){
        if (D.count(mini2)){
            mini2++;
        }
        else{
            break;
        }
    }
    
    int m = N.size();
    vector<int> n(m + 1, 0);
    rep(i, 1, m + 1){
        n.at(i) = N.at(i - 1) - '0';
    }
    bool can = false;
    
    rep(i, 1, m + 1){
        if(D.count(n.at(i))){
            while(D.count(n.at(i))){
                SKIP:
                n.at(i)++;
                if (n.at(i) == 10){
                    n.at(i) = mini;
                    n.at(i - 1)++;
                    if (D.count(n.at(i - 1))){
                        i--;
                        goto SKIP;
                    }
                }
            }
            rep(j, i + 1, m + 1){
                n.at(j) = mini;
            }
            break;
        }
    }
    SKIP1:
    if (n.at(0) != 0){
        cout << mini2;
    }
    rep(i, 1, m + 1){
        cout << n.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    char op;
    cin>>a>>op>>b;
    while(op!='?')
    {int c;
        if(op=='+')c=a+b;
        else if(op=='-')c=a-b;
        else if(op=='/')c=a/b;
        else if(op=='*')c=a*b;
        cout<<c<<"\n";
    cin>>a>>op>>b;
    }
    return 0;
}



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

using namespace std;

int main(int argc, char *argv[]) {
    string S;
    cin >> S;
    int N = S.size();
    
    string orig = S;
    reverse(S.begin(), S.end());
    bool ok(true);
    if (orig == S) {
        string n1 = orig.substr(0, (N - 1) / 2);
        string n1orig = n1;
        reverse(n1.begin(), n1.end());
        if (n1 == n1orig) {
            string n3 = orig.substr((N + 3) / 2 - 1);
            string n3orig = n3;
            reverse(n3.begin(), n3.end());
            if (n3 != n3orig) {
                ok = false;
            }
        } else {
            ok = false;
        }
    } else {
        ok = false;
    }

    cout << ((ok) ? "Yes" : "No") << endl;

    return 0;
}


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

int main()
{
  ll k, n;
  cin >> n >> k;
  vector<double> p(n);
  rep(i, n)
  {
    cin >> p[i];
    p[i] = 0.5 * p[i] + 0.5;
    // cout << p[i] << " ";
  }
  // cout << endl;
  double mx = 0;
  double sum = 0;
  rep(i, n - k + 1)
  {
    if (!sum)
      rep(j, k) sum += p[j];
    else
      sum = sum - p[i - 1] + p[i + k - 1];
    // printf("i: %d sum: %lf mx: %lf\n", i, sum, mx);
    mx = max(mx, sum);
  }
  printf("%lf\n", mx);
  return 0;
}

Measured memory_bytes: 1792
import java.awt.TexturePaint;
import java.awt.event.ComponentAdapter;
import java.io.BufferedReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int first = Integer.parseInt(sc.next()); 
		int second = Integer.parseInt(sc.next()); 
		if(first<second) {
			System.out.println(0);
		}else {
			System.out.println(10);
		}
	}
}

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

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    int mini = 1001001001;
    ll sum = 0;
    rep(i,n) {
      int a;
      cin >> a;
      if (a < 0) cnt++;
      a = abs(a);
      sum += a;
      mini = min(mini, a);
    }
    if (cnt%2 == 0) cout << sum << endl;
    else cout << sum-mini*2 << endl;
    return 0;
}

Measured memory_bytes: 3616
fn main() {
    let i = read::<i32>();
    match i {
        22 => println!("Christmas Eve Eve Eve"),
        23 => println!("Christmas Eve Eve"),
        24 => println!("Christmas Eve"),
        25 => println!("Christmas"),
        _ => {},
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Partition solver = new Partition();
        solver.solve(1, in, out);
        out.close();
    }

    static class Partition {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long m = in.nextLong();
            long result = 0;
            for (long i = m; 1 <= i; i--) {
                long base = i * (n - 1);
                long diff = m - base;
                if (diff < i) {
                    continue;
                }
                if (diff % i == 0) {
                    result = Math.max(result, i);
                    break;
                }
            }
            out.println(result);
        }

    }
}



Measured memory_bytes: 35948
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long n, a, b, c, d, e, sum = 0, num = 0; cin >> n >> a;
	long long test[201] = { 0 }, dp[201] = { 0 }, dpp[201] = { 0 };
	long long cc[201] = { 0 }, dd[201] = { 0 }, ee[201] = { 0 };
	for (int h = 0; h < n; h++) {
		cin >> b; test[h] = b;
	}
	for (int h = 0; h < a; h++) {
		cin >> c >> d >> e;
		cc[h] = c; dd[h] = d; ee[h] = e;
	}
	for (int h = 0; h < n; h++) {
		long long ma = 0, mi = 100000;
		for (int i = 0; i < a; i++) {
			if (cc[i] <= test[h] && test[h] <= dd[i]) {
				ma = max(ma, ee[i]);
				mi = min(mi, ee[i]);
			}
		}
		dp[h] = ma; dpp[h] = mi;
	}
	long long su[201] = { 0 }, nu[201] = { 0 };
	//su[0] = dp[0]; nu[0] = dpp[0];
	for (int h = 1; h < n; h++) {
		su[h] = max(abs(dp[h - 1] - dp[h]) + su[h - 1], abs(dpp[h - 1] - dp[h]) + nu[h - 1]);
		nu[h] = max(abs(dp[h - 1] - dpp[h]) + su[h - 1], abs(dpp[h - 1] - dpp[h]) + nu[h - 1]);
		//cout << su[h] << ' ' << nu[h] << endl;
	}
	cout << max(su[n - 1], nu[n - 1]) << endl;
	cin >> n;
}


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

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

const int N = 201000;
typedef pair<int,int> pii;
pii b[N]; int st[N];
int n, R, C, tp, tot;

inline int get(int x, int y) {
	if(x and x != R and y and y != C) return -1;
	if(y == 0) return x;
	if(x == R) return R + y;
	if(y == C) return R + C + (R-x);
	return R + C + R + (C-y);
}

int main() {
//	freopen("in","r",stdin);
	read(R), read(C), read(n);
	for(int i=1,x,y,t1,t2;i<=n;++i) {
		read(x), read(y), t1 = get(x, y);
		read(x), read(y), t2 = get(x, y);
		if(t1 == -1 or t2 == -1) continue;
		b[++tot] = pii(t1, i);
		b[++tot] = pii(t2, i);
	}
	sort(b+1, b+tot+1);
	for(int i=1;i<=tot;++i)
		if(tp and st[tp] == b[i].second) --tp;
		else st[++tp] = b[i].second;
	puts(tp ? "NO" : "YES");
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int w, d, h[2][10], m[10][10];
bool used[2][10];

void debug(){
	puts("[debug]");
	printf("  ");
	for(int x=0 ; x < w ; x++ ){
		printf("%2d", h[0][x]);
	}
	puts("");
	for(int y=0 ; y < d ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( x == 0 ){
				printf("%2d", h[1][y]);
			}
			printf("%2d", m[y][x]);
		}
		puts("");
	}
	puts("");
}

// m[y][0..w-1] に height 以上の高さのブロックが存在するかどうか.
bool is_higher_y(int y, int height){
	for(int x=0 ; x < w ; x++ ){
		if( height <= m[y][x] ) return true;
	}
	return false;
}

// m[0..d-1][x] に height 以上の高さのブロックが存在するかどうか.
bool is_higher_x(int x, int height){
	for(int y=0 ; y < d ; y++ ){
		if( height <= m[y][x] ) return true;
	}
	return false;
}

int main(){
	while( cin >> w >> d, w || d ){
		// 初期化
		for(int i=0 ; i < 10 ; i++ ){
			used[0][i] = used[1][i] = false;
			for(int j=0 ; j < 10 ; j++ ){
				m[i][j] = 0;
			}
		}
		
		// 入力
		for(int i=0 ; i < w ; i++ ){
			cin >> h[0][i];
		}
		for(int i=0 ; i < d ; i++ ){
			cin >> h[1][i];
		}
		sort(h[0], h[0] + w);
		sort(h[1], h[1] + d);
		reverse(h[0], h[0] + w);
		reverse(h[1], h[1] + d);
		
		int ans = 0;
		for(int y=0 ; y < d ; y++ ){
			// h[1][y] と同じ高さのものを h[0][0..w-1] から探す.
			bool flag = false;
			for(int x=0 ; x < w ; x++ ){
				if( used[0][x] ) continue;
				
				if( h[1][y] == h[0][x] ){
					flag = true;
					m[y][x] = h[1][y];
					ans += h[1][y];
					used[1][y] = used[0][x] = true;
				}
				if( flag ) break;
			}
			if( !used[1][y] ){
				for(int x=0 ; x < w ; x++ ){
					if( h[1][y] == h[0][x] ){
						flag = true;
						m[y][x] = h[1][y];
						ans += h[1][y];
						used[1][y] = used[0][x] = true;
					}
					if( flag ) break;
				}
			}
		}
		// h[0][0..w-1] でまだ確定していないブロックを探す.
		for(int x=0 ; x < w ; x++ ){
			if( used[0][x] ) continue;
			
			bool flag = false;
			for(int y=0 ; y < d ; y++ ){
				if( is_higher_y(y, h[0][x]) ){
					flag = true;
					m[y][x] = h[0][x];
					ans += h[0][x];
					used[0][x] = true;
				}
				if( flag ) break;
			}
		}
		// h[1][0..d-1] でまだ確定していないブロックを探す.
		for(int y=0 ; y < d ; y++ ){
			if( used[1][y] ) continue;
			
			bool flag = false;
			for(int x=0 ; x < w ; x++ ){
				if( is_higher_x(x, h[1][y]) ){
					flag = true;
					m[y][x] = h[1][y];
					ans += h[1][y];
					used[1][y] = true;
				}
				if( flag ) break;
			}
		}
		//debug();
		cout << ans << endl;
	}
}

Measured memory_bytes: 1180
from collections import Counter
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

e = Counter(v[::2]).most_common() + [(0, 0)]#最も多いものは書き換えない
#print(e)　コーナーケース対応、要素が超少ない場合
o = Counter(v[1::2]).most_common() + [(0, 0)]
#print(o)
if e[0][0] != o[0][0]:#最多が偶奇で異なるなら、偶奇の最多を引く
    print(n - e[0][1] - o[0][1])
else:#最多が偶奇で同じなら、最多の次を検討して、最も書換を少なくする
    print(n - max(e[0][1]+o[1][1], e[1][1]+o[0][1]))


Measured memory_bytes: 20572
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: i64,
        a: [i64; n],
    }

    let mut cs = vec![0];
    for ai in a {
        let last = cs.last().copied().unwrap();
        cs.push((last + ai) % m);
    }

    let mut cnt = HashMap::new();
    let mut ans = 0i64;
    for a in cs {
        let entry = cnt.entry(a).or_insert(0i64);
        ans += *entry;
        *entry += 1;
    }

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


Measured memory_bytes: 7680
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

#define INF (1<<30)

int n;
int a[100001];
int gcdl[100001];
int gcdr[100001];

int main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	gcdl[0] = 0;
	gcdr[0] = 0;
	for(int i = 1; i<n; i++){
		gcdl[i] = __gcd(gcdl[i-1],a[i-1]);
		gcdr[i] = __gcd(gcdr[i-1],a[n-i]);
	}
	int ans = 1;
	for(int i = 0;i < n;i++){
		int now = __gcd(gcdl[i],gcdr[n-i-1]);
		ans = max(ans, now);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


vector<int> bfs(int s,vector< vector<int> > G){
  int n=G.size();
  vector<int> dp(n,-1);
  queue<int> que;
  dp[s]=0;
  que.emplace(s);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int u:G[v]){
      if(~dp[u]) continue;
      dp[u]=dp[v]+1;
      que.emplace(u);
    }
  }
  return dp;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,x,y;
  cin>>n>>x>>y;
  x--;y--;

  vector<vector<int>> G(n);
  for(int i=0;i+1<n;i++){
    G[i+0].emplace_back(i+1);
    G[i+1].emplace_back(i+0);
  }
  G[x].emplace_back(y);
  G[y].emplace_back(x);

  vector<int> cnt(n,0);
  for(int v=0;v<n;v++)
    for(int d:bfs(v,G)) cnt[d]++;

  for(int i=1;i<n;i++) cout<<cnt[i]/2<<newl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll h, w, n;
    cin >> h >> w >> n;
    map<pair<ll, ll>, ll> count;
    REP(i, n){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        for(ll da = -1; da <= 1; ++da){
            for(ll db = -1; db <= 1; ++db){
                if(a + da >= 1 && a + da < h - 1 && b + db >= 1 && b + db < w - 1){
                    count[make_pair(a + da, b + db)]++;
                }
            }
        }
    }

    vector<ll> ans(10, 0);
    ans.at(0) = (h - 2) * (w - 2);
    for(auto it = count.begin(); it != count.end(); ++it){
        ans.at(it->second)++;
        ans.at(0)--;
    }

    REP(i, 10){
        cout << ans.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 56448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Console.ReadLine();
		
		long n = p.ToLong();
		if(n % 2 == 1)
		{
			Console.WriteLine(0);
			return;
		}
		//for(int i = 0; i < (n/2); i++)
		
		long r = 0;
		for(int k = 0;;k++)
		{
			long q = (long)Math.Pow(5,k);
			if(q > n)
			{
				break;
			}
			r += n / (10 * q);
		}
		Console.WriteLine(r);
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

int dp[100010][26];
signed main() {
	
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	int ans=0,prev=0;
	for(int i=0;i<n;i++)
	{
		int c;
		cin>>c;
		if(c>=prev)
			prev=c,ans++;
	}
	cout<<ans;
	return  0;


}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc074/tasks/arc083_a
# C - Sugar Water
import math
w_A, w_B, s_C, s_D, limit_E, max_F = list(map(int, input().split()))

# それ以上溶かすことができるか
# それ以上重量を増やせるか

# 取りうる水の組み合わせ
w_A_list = [w_A * x * 100 for x in range(math.floor(max_F / (w_A * 100)) + 1)]
w_B_list = [w_B * x * 100 for x in range(math.floor(max_F / (w_B * 100)) + 1)]

# 最悪で3000*3000
w_list = []
for a in w_A_list:
    for b in w_B_list:
        if a + b <= max_F:
            w_list.append(a + b)
w_list = list(set(w_list))  # 3000以下

# 取りうる水の組み合わせ
s_C_list = [s_C * x  for x in range(math.floor(max_F / s_C) + 1)]
s_D_list = [s_D * x  for x in range(math.floor(max_F / s_D) + 1)]

# 最悪で3000*3000
s_list = []
for c in s_C_list:
    for d in s_D_list:
        if c + d <= max_F:
            s_list.append(c + d)
s_list = list(set(s_list))  # 3000以下

max_d = -float('inf')
for w in w_list:
    for s in s_list:
        limit_s = w * limit_E / 100
        if w + s <= max_F and w + s != 0 and s <= limit_s:
            d = (s / (w + s)) * 100
            if d > max_d:
                max_d = d
                ans_ws, ans_s = w + s, s

ans = ' '.join([str(ans_ws), str(ans_s)])
print(ans)


Measured memory_bytes: 12584
#include<cstdio>

using namespace std;

int syutu[30];

void saiki(int m,int n,int atnum){
	
	int flg=0;
	//printf("%d %d %d\n",m,n,atnum);
	
	for(int i=n;i>0;i--){
		if(i>m){
			continue;
		}
		
		syutu[atnum]=i;
		saiki(i,n-i,atnum+1);
		syutu[atnum]=-1;
		flg=1;
	}
	
	if(flg==0){
		printf("%d",syutu[0]);
		for(int i=1;i<30;i++){
			if(syutu[i]==-1){
				break;
			}
			printf(" %d",syutu[i]);
		}
		puts("");
	}
}

int main(){
	
	while(1){
		int n;
		scanf("%d",&n);
		
		if(n==0){
			return 0;
		}
		
		for(int i=0;i<30;i++){
			syutu[i]=-1;
		}
		saiki(n,n,0);
	}
}

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

int main() {
	string S;
	cin >> S;
	if (S[0] == '7' || S[1] == '7' || S[2] == '7') {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}


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

#define llint long long int

using namespace std;

int main(){
    int N, M;

    cin >> N >> M;

    vector<pair<int, int>> AB(N);

    for(int i = 0; i < N; i ++){
        int A, B;

        cin >> A >> B;

        AB[i] = make_pair(A, B);
    }
    sort(AB.begin(), AB.end());

    int j = 0;
    multiset<int> B;
    int ans = 0;

    for(int i = 1; i <= M; i ++){
        for(; j < N; j ++){
            if(AB[j].first != i){
                break;
            }
            B.insert(AB[j].second);
        }
        if(B.size() > 0){
            auto itr = B.end();
            itr --;

            ans += *(itr);

            B.erase(itr);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int x = Integer.parseInt(in.next());
            int tmp = 0;
            int lcnt = 0;
            int rcnt = 0;
            for (int i = 0; i < m; i++) {
                tmp = Integer.parseInt(in.next());
                if (tmp < x) {
                    lcnt++;
                } else {
                    rcnt++;
                }
            }
            int ans = Math.min(lcnt, rcnt);

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21588
#include <stdio.h>
#include <string.h>
 
int main(void){
  int i,j = 0;
  char w[11], t[1001];
 
  scanf("%s", w);
 
  do{
    scanf("%s",t);
    if(!strcmp(t,"END_OF_TEXT")) break;
      for(i=0;t[i]!='\0';i++)
        if(t[i]<91) t[i] += 32;
    if( !strcmp(w,t) ) j++;
  }while(1);
 
  printf("%d\n",j);
 
  return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main() {
  IN(ll,A);
  IN(ll,B);
  IN(ll,K);
  if(A >= K)
    cout << A-K << " " << B << endl;
  else if(A+B >= K)
    cout << 0 << " " << A+B-K << endl;
  else
    cout << 0 << " " << 0 << endl;
  
}



Measured memory_bytes: 256
fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let t = read::<String>().chars().collect::<Vec<_>>();

    yn(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long read()
{
	char ch=getchar();long long f=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9')
	{f=(f<<1)+(f<<3)+ch-'0';
	ch=getchar();}
	return f;
}
struct node
{
	int from;
	int to;
	int next;
}edge[300005];
int head[100005],tot,fa[100005],son[100005],size[100005],dep[100005],n;bool vis[100005];
void add(int u,int v)
{
	edge[tot].from=u;
	edge[tot].to=v;
	edge[tot].next=head[u];
	head[u]=tot++;
}
void dfs1(int x)
{
	size[x]=1;
	for(int i=head[x];i!=-1;i=edge[i].next)
	{
		if(edge[i].to!=fa[x])
		{
			dep[edge[i].to]=dep[x]+1;
			fa[edge[i].to]=x;
			dfs1(edge[i].to);
			size[x]+=size[edge[i].to];
		}
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	n=read();
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		add(u,v);
		add(v,u);
	}
	dfs1(1);
	int move=(dep[n]-1)/2+1;
	move--;
	int now=n;
	while(move--)
	{
		now=fa[now];
	}
	if(size[now]>=n-size[now])
	printf("Snuke");
	else
	printf("Fennec");
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int maxN = 100000;
int cnt[100000];
int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);

       int t=1;
       //cin>>t;
       while(t--)
       {
               int n;
               cin>>n;
               int a[10001];
               memset(a,0,sizeof(a));
               for(int x=1;x<=100;++x)
               {
                    for(int y=1;y<=100;++y)
                    {
                         for(int z=1;z<=100;++z)
                         {
                              if(x*x+y*y+z*z+x*y+y*z+x*z<=10000)
                                   a[x*x+y*y+z*z+x*y+y*z+x*z]++;
                         }
                    }
               }
               for(int i=1;i<=n;++i)
                    cout<<a[i]<<"\n";
       }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const ll MAX_N = 1e5 + 10;

ll par[MAX_N], sz[MAX_N];

ll find(ll x) {
    if(par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

ll comp;

void merge(ll x, ll y) {
    x = find(x), y = find(y);
    if(x == y) {return;}
    comp --;
    if(sz[x] < sz[y]) {swap(x, y);}
    par[y] = x;
    sz[x] += sz[y];
}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    comp = n;
    for(ll i = 1; i <= n; i ++) {
        par[i] = i;
        sz[i] = 1;
    }
    for(ll i = 0; i < m; i ++) {
        ll a, b, c;
        cin >> a >> b >> c;
        merge(a, b);
    }
    cout << comp << endl;
    return 0;
}



Measured memory_bytes: 5164
n = int(input())
a = [0]
a += [int(_) for _ in input().split()]
a += [0]

b = []
total = 0
pos = 0
for i in range(n + 1):
  b += [abs(a[i] - a[i + 1])]
  total += b[i]
  pos = a[i + 1]

for i in range(1, n + 1):
  #sum = total - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a [i]) + abs(a[i - 1] - a[i + 1])
  sum = total - b[i - 1] - b[i] + abs(a[i - 1] - a[i + 1])

  print(sum)
  

Measured memory_bytes: 14048
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int h, w, K;
    scanf("%d%d%d", &h, &w, &K);
    char s[h][w];
    rep(i, h)rep(j, w) scanf(" %c", &s[i][j]);
    vector<vector<int>> sum(w, vector<int>(h+1, 0));
    rep(i, w){
        sum[i][0] = 0;
        rep(j, h) sum[i][j+1] = sum[i][j] + (s[j][i] == '1');
    }

    int ans = mod;
    rep(S, 1<<(h-1)){
        vector<int> b = {0};
        rep(i, h-1)if(S>>i & 1) b.push_back(i+1);
        b.push_back(h);

        int tmp = (int)b.size()-2;
        vector<int> cnt(b.size()-1, 0);
        auto check = [&](int r){
            rep(i, b.size()-1){
                if(cnt[i] + sum[r][b[i+1]]-sum[r][b[i]] > K) return false;
            }
            return true;
        };

        int l = 0;
        while(l < w){
            int r = l;
            while(r < w && check(r)){
                rep(i, b.size()-1) cnt[i] += sum[r][b[i+1]]-sum[r][b[i]];
                ++r;
            }
            if(r == l){
                tmp = -1;
                break;
            }
            if(r < w) ++tmp;
            l = r;
            fill(cnt.begin(), cnt.end(), 0);
        }

        if(tmp < 0) continue;
        chmin(ans, tmp);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define STEP(i, n, step) for(int i=0; i < n; i+=step)
#define RANGE(n) for(int _=0; _<n ; _++)
#define FOR(i, m, n) for(int i = m; i < n; i++)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
const int INT_INF = 1 << 29;

const int MAX = 100010;
const int MOD = 998244353;

using Graph = vector<vector<int>>;

int A[MAX], B[MAX], dp[MAX];

vector<bool> seen;

void dfs(const Graph &G, int v){
  seen[v] = true;
  for(auto next_v: G[v]){
    if(seen[next_v]) continue;
    dfs(G, next_v);
  }
}

void solve() {
  int N, M,counter=0;
  cin >> N >> M;
  Graph G(N+1);
  REP(i,M){
    int a,b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  seen.assign(N,false);
  for(int i=1; i<=N; i++){
    if(seen[i]) continue;
    counter++;
    dfs(G,i);
  }

  cout << counter-1 << endl;

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


Measured memory_bytes: 9596
#![allow(non_snake_case, unused_imports)]

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

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,VecDeque,BinaryHeap};
// Module for v1.15.1
use std::ascii::AsciiExt;

// Functions

// Main
fn main(){

    input!{
        _N: usize,
        K: usize,
        mut S: chars,
    }

    S[K-1] = S[K-1].to_ascii_lowercase();

    println!("{}", S.into_iter().collect::<String>());
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(){

  int N,i,j,a,count,A[100];
  count=0;
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=N-1;i++){
    for(j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	a=A[j];
	A[j]=A[j-1];
	A[j-1]=a;
	count++;
      }
    }
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }  
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 2704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int cnt=0;
string  w[12];
string ans;

	while(!cin.eof()){
		ans = "G";
		rep(i,8)  cin >> w[i];
		if(cin.eof()) break;
		rep(i,8) rep(j,8) if(w[i][j] == '1'){
			if(w[i][j+1]=='1' &&  w[i][j+2]=='1' && w[i][j+3]=='1'){
				ans = "C";  break; }
			if(w[i][j+1] =='1' && w[i+1][j+1]=='1' &&  w[i+1][j]=='1' ){
				ans = "A";  break; }
			if(w[i+1][j-1]=='1' && w[i+1][j]=='1' && w[i+2][j-1]=='1'){
				ans = "D";  break; }
			if(w[i][j+1]=='1' && w[i+1][j+1]=='1' && w[i+1][j+2]=='1'){
				ans = "E";  break; }
			if(w[i+1][j]=='1' && w[i+1][j+1]=='1' && w[i+2][j+1]=='1'){
				ans = "F";  break; }
			if(w[i][j+1]=='1' && w[i+1][j-1]=='1' && w[i+1][j]=='1' ){
				ans = "G";  break; }
			if(w[i+1][j]=='1' && w[i+2][j]=='1' && w[i+3][j]=='1' ){
				ans = "B";  break; }
			}
		cout <<  ans << endl;
//		cnt++; if(cnt>40) break;
	}
	return 0;
	
	
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(a,x.size()) cout << x[a] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2e5;

int n, k, m, r;

bool check(ll x, vll s) {
    s.push_back(x);
    sort(rall(s));
    ll sum = 0;
    rep(i,k) sum += s[i];
    return sum >= (ll)k*r;
}

int main() {
    int n; cin >> n;
    bool first = false;
    rep(i,n) {
        int x; cin >> x;
        if (x&1) first = true;
    }
    if (first) cout << "first" << endl;
    else cout << "second" << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define N 100009
#define ll long long
#define ff first
#define ss second
#define mod 998244353
using namespace std;
ll n, m, v, p, a[100009], pp[100009];
int main() {
    cin>>n>>m>>v>>p;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    sort(a + 1, a + n + 1);
    for(int i=1;i<=n;i++) {
        //cout<<a[i]<<" ";
        pp[i] = a[i] + pp[i - 1];
    }
    //cout<<endl;
    ll ans = p;
    for(int i=n-p;i>=1;i--) {
        ll curv = v - i;
        if(p > curv) {
            if(a[i] + m >= a[n - p + 1]) {
                ans++;
                continue;
            }
            else
                break;
        }
        curv -= p;
        curv++;
        curv *= m;
        ll val = a[i] + m;
        if(a[n - p + 1] > val) {
            break;
        }
        ll sum = pp[n - p + 1] - pp[i];
        ll add = 1ll * (n - p - i + 1) * val - sum;
        //cout<<i<<" "<<add<<" "<<curv<<endl;
        if(add < curv) {
            break;
        }
        ans++;
    }
    cout<<ans;
}


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

int main() {
	string c;
	cin >> c;
	
	string aeiou = "aeiou";
	
	if(aeiou.find(c) == string::npos) cout << "consonant";
	else cout << "vowel";

	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
 int N, A, B;
 
 cin >> N;

 if (N ==1)
 {
   cout << "Hello World" << endl;
 }
 else
 {
   cin >> A >> B;
   cout  << A+B << endl;
 } 

  return(0);
}

Measured memory_bytes: 256
N,K=map(int,input().split())
p=list(map(int,input().split()))
sum=0
v=[]
for i in range(K):
    sum+=p[i]
v.append(sum)
for i in range(K,N):
    sum+=p[i]
    sum-=p[i-K]
    v.append(sum)
M=0
for i in range(N+1-K):
    M=max(M,v[i])
print((M+K)/2)


Measured memory_bytes: 32184
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	string S;
	cin >> S;
	int i=0,j=S.size()-1;
	int ret=0;
	while(i<j)
	{
		if(S[i]!=S[j]){
			ret++;
		}
		i++;
		j--;
	}
	cout << ret << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
#define all(v) v.begin(),v.end()
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(pair<int,int> &a,pair<int,int> &b)
{
	if(a.first!=b.first)
	   return a.first<b.first;
	else
		return a.second>b.second;
}
void printQ(deque<int> q)
{
	for(int i=0;i<q.size();i++)
	{
		cout<<q[i]<<" ";
	}
	cout<<endl;
}

int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;cin>>n;
	string s,t;cin>>s>>t;
	string ans="";
	for(int i=0;i<n;i++)
	{
		ans+=s[i];
		ans+=t[i];
	}
	cout<<ans<<endl;
	return 0;
}






















Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 200010

struct UF {
	vector<int> par, rank;
	
	void init(int n){
		par = rank = vector<int>(n, 0);
		for(int i = 0; i < n; i++){
			par[i] = i;
		}
	}
	
	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}
	
	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		
		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = par[x];
			if(rank[x] == rank[y]) rank[y]++;
		}
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
};


int main(){
	ll n, m[2];
	cin>>n>>m[0]>>m[1];
	UF uf[2];
	rep(i, 2){
		uf[i].init(n);
		rep(j, m[i]){
			int u, v;
			cin>>u>>v; u--; v--;
			uf[i].unite(u, v);
		}
	}
	map<P, ll> cnt;
	rep(i, n) ++cnt[P(uf[0].find(i), uf[1].find(i))];
	rep(i, n) cout<<cnt[P(uf[0].find(i), uf[1].find(i))]<<" "; cout<<endl;
	return 0;
}


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


int n, m;
int am[15];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    memset(am, -1, sizeof(am));

    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int poz, cif;
        cin >> poz >> cif;

        if (am[poz] != -1 && am[poz] != cif) {
            cout << -1;
            return 0;
        }
        am[poz] = cif;
    }

    if (am[1] == 0) {
        if (n == 1)
            cout << 0;
        else
            cout << -1;
        return 0;
    }

    for (int i = 1; i <= n; i++) {
        if (am[i] == -1) {
            if (i == 1 && n > 1)
                cout << 1;
            else
                cout << 0;
        }
        else {
            cout << am[i];
        }
    }


    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] nd = sc.intarr;
            int n = nd[0];
            int d = nd[1];

            var list = new List<List<int>>();

            int count = 0;

            for(int i=0; i<n; i++)
            {
                list.Add(sc.intarr.ToList());
            }

            for(int i=0; i<n; i++)
            {
                for(int j=i+1; j<n; j++)
                {
                    int sum = 0;
                    for(int m=0; m<d; m++)
                    {
                        sum += Math.Abs((list[i][m] - list[j][m]) * (list[i][m] - list[j][m]));
                    }
                    double sq = Math.Sqrt(sum);
                    if (sq % 1 == 0)
                    {
                        count++;
                    }
                }
            }
            wr.wri(count);

        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int N;
    string S;
    int K;
    cin >> N >> S >> K;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] != S[K-1])
        {
            S[i] = '*';
        }
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long long int N, A[112345], B[112345];
long long int ans = 0;

int main(void)
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) { scanf("%d%d", &A[i], &B[i]); }

	for (int i = N - 1; i >= 0; --i)
	{
		int res = ans;
		if (A[i] % B[i] != 0)
		{
			B[i] = (B[i] * (A[i] / B[i]) > 0 ? B[i] * (A[i] / B[i]) + B[i] : B[i]);
			ans += (B[i] - A[i]);
		}
		if (i > 0)
		{
			A[i - 1] += ans;
		}
	}

	// TLE
	/*for (int i = N - 1; i >= 0; --i)
	{
		int res = ans;
		if (A[i] % B[i] != 0)
		{
			B[i] = (B[i] * (A[i] / B[i]) > 0 ? B[i] * (A[i] / B[i]) + B[i] : B[i]);
			ans += (B[i] - A[i]);
		}
		for (int j = 0; j <= i; ++j)
		{
			A[j] += ans - res;
		}
	}*/

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

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

struct State { int tx, ty, kx, ky, cost; };
int X, Y;
int d[52][52];
bool used[52][52][52][52];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> X >> Y, X) {
        int tx, ty, kx, ky;
        cin >> tx >> ty >> kx >> ky;
        for (int i=0; i<=Y+1; ++i) {
            for (int j=0; j<=X+1; ++j) {
                if (i==0 || i==Y+1 || j==0 || j==X+1) d[i][j] = 1;
                else cin >> d[i][j];
            }
        }
        memset(used, false, sizeof used);
        queue<State> q;
        q.push((State){tx, ty, kx, ky, 0});
        int res = -1;
        while ( ! q.empty()) {
            State s = q.front(); q.pop();
            if (used[s.tx][s.ty][s.kx][s.ky]) continue;
            used[s.tx][s.ty][s.kx][s.ky] = true;
            if (s.tx == s.kx && s.ty == s.ky) {
                res = s.cost;
                break;
            }
            for (int i=0; i<4; ++i) {
                if (d[s.ty+dy[i]][s.tx+dx[i]] && d[s.ky-dy[i]][s.kx-dx[i]]) continue;
                int tx2 = s.tx, ty2 = s.ty;
                if ( ! d[s.ty+dy[i]][s.tx+dx[i]]) {
                    tx2 += dx[i];
                    ty2 += dy[i];
                }
                int kx2 = s.kx, ky2 = s.ky;
                if ( ! d[s.ky-dy[i]][s.kx-dx[i]]) {
                    kx2 -= dx[i];
                    ky2 -= dy[i];
                }
                q.push((State){tx2, ty2, kx2, ky2, s.cost+1});
            }
        }
        if (res < 0) {
            cout << "NA" << endl;
        } else {
            cout << res << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 9296