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

#define int long long

using namespace std;

int n, m, v, p, a[100005];

bool check(int s){
	if(a[s] + m < a[p]) return 0;
	int op = 0;
	for(int i = p; i < s; i++){
		op += (a[s] + m) - a[i];
	}
	op += ((p - 1) * m) + ((n - s + 1) * m);
	if(op >= m * v){
		return 1;
	}
	return 0;
}

main(){
	cin >> n >> m >> v >> p;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}                              
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	int l = 1, r = n, ans = 0; 
	while(l <= r){
		int mid = (l + r) / 2;
		if(check(mid)){
			l = mid + 1;
			ans = mid;  
		}
		else {
			r = mid - 1;
		}
	}
	cout <<	ans;
}

Measured memory_bytes: 1024
ABC = [int(i) for i in input().split()]

r = [ABC[0] % 2, ABC[1] % 2, ABC[2] % 2]
count = 0

if r.count(0) == 2:
    count += 1
    for i in range(3):
        if r.index(1) == i:
            continue
        ABC[i] += 1
elif r.count(1) == 2:
    count += 1
    for i in range(3):
        if r.index(0) == i:
            continue
        ABC[i] += 1
    
m = max(ABC)
for i in ABC:
    count += (m - i) / 2

print(int(count))

Measured memory_bytes: 3064
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;
const ll INF = 1LL << 60;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2); return sq*sq; } else { return N*RS(N, P - 1); } } //power(repeat-square,fast)
ll nPr(ll n, ll r) { ll ans = 1; rep(i, r) { ans = ans * (n - i); } return ans; } //permutation
ll nCr(ll n, ll r) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1); bunshi = bunshi * (n - i); } return bunshi / bunbo; } //combination
ll RS(ll N, ll P, ll Mod) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination

int main(void) {
  int L,R; cin >> L >> R;
  if (R-L >= 2019){
    cout << 0 << "\n";
    return 0;
  }
  int res = 9999;
  for (int i = L; i <= R; i++){
    for (int j = i+1; j <= R; j++){
      chmin(res,(i%2019)*(j%2019)%2019);
    }
  }
  
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  int k=0,l=0;
  rep(i,n){
    if(i%2==0&&s[i]=='0'){k++;}
    if(i%2==1&&s[i]=='1'){k++;}
    if(i%2==0&&s[i]=='1'){l++;}
    if(i%2==1&&s[i]=='0'){l++;}}
  cout<<n-max(k,l)<<endl;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val (n, c, k) = readLine()?.split(" ")?.map { it.toLong() } ?: return
    val tList = (0 until n).map {
        readLine()?.toLong()!!
    }.sorted()

    var i = 0
    var bus = 0

    while (i < n) {
        val endLimit = tList[i++] + k
        var count = 1L
        while (i < n && tList[i] <= endLimit && count < c) {
            count++
            i++
        }
        bus++
    }

    println(bus)
}

Measured memory_bytes: 47012
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <stdio.h>
using namespace std;

double width(vector<pair<int, int> > p, double x) {
  vector<long double> a;
  for(int i = 0; i < p.size(); i++) {
    pair<int, int> s, t;
    s = p[i]; t = p[(i+1)%p.size()];
    if(s.first == x) a.push_back(s.second);
    else if((s.first < x && x < t.first) || (s.first > x && x > t.first)) {
      int x0 = s.first, y0 = s.second;
      int x1 = t.first, y1 = t.second;
      /*if(s.first > x) {
	swap(x0, x1);
	swap(y0, y1);
	}*/
      a.push_back(y0 + (y1-y0)*(x-x0)/(long double)((x1-x0)));
    }
  }
  return *(max_element(a.begin(), a.end())) - *(min_element(a.begin(), a.end()));
}

int main() {
  int m, n;
  while(true) {
    cin >> m >> n;
    if(!m) break;
    vector<pair<int, int> > p1(m), p2(n);
    set<int> allX;
    for(int i = 0; i < m; i++) {
      cin >> p1[i].first >> p1[i].second;
      allX.insert(p1[i].first);
    }
    for(int i = 0; i < n; i++) {
      cin >> p2[i].first >> p2[i].second;
      allX.insert(p2[i].first);
    }
    allX.insert(-1000);
    allX.insert(1000);
    int start, goal;
    start = max(*(min_element(p1.begin(), p1.end())),*(min_element(p2.begin(), p2.end()))).first;
    goal = min(*(max_element(p1.begin(), p1.end())), *(max_element(p2.begin(), p2.end()))).first;
    long double sum = 0;
    //cout << start << " " << goal << endl;
    for(auto itr = allX.begin(); itr != allX.end(); itr++) {
      auto next = itr;
      next++;
      if(*itr >= start && *itr <= goal && *next >= start && *next <= goal) {
	//cout << "x: " << *itr << " next: " << *next << endl;
	long double m = (*itr + *next)/2.0;
	long double a = width(p1, *itr)*width(p2, *itr);
	long double b = width(p1, *next)*width(p2, *next);
	long double c = width(p1, m)*width(p2, m);
	sum += (*next-*itr)/6.0*(a+4*c+b);
      }
    }
    printf("%Lf\n", sum);
  }
  return 0;
}


      
  

Measured memory_bytes: 3048
import java.util.Scanner;


 class  Main {
    static public  void  main (String[] av){
     int  b;
     int sum=0;
        Scanner sc =new Scanner(System.in);
        int n =sc.nextInt();
        int a[]= new int[n];
        int v;
        for(int  i=0;i<n;i++){
            v=sc.nextInt();
            a[i]=v;
        }
        
int n2=sc.nextInt();
for (int i=0;i<n2;i++){
    int x=sc.nextInt();
    for (int j=0;j<n;j++){
    if (a[j]==x){
        sum++;
        break;
    }
}
}
System.out.println(sum);


        }

}


Measured memory_bytes: 67860
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <iterator>
#include <numeric>
#include <set>
using namespace std;
typedef long long ll;

ll mod=1e9+7;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	printf("%d\n",mod_pow(k,n) );
}


Measured memory_bytes: 3228
#include<vector>
template<class T>
std::vector<T> factorize(T N){
    std::vector<T> factor;
    for(unsigned i=2;i*i<=N;++i)
        while(N%i==0){
            factor.push_back(i);
            N/=i;
        }
    if(N>1) factor.push_back(N);
    return factor;
}
#include<iostream>
int main(){
    using namespace std;
    int N;
    cin>>N;
    cout<<N<<":";
    vector<int> v=factorize(N);
    for(auto a:v) cout<<' '<<a;
    cout<<endl;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll c=0;
	for(ll i=0;i<n;i++){
		if(a[i]%2!=0 && (i+1)%2!=0){
			c++;
		}
	}
	
	cout<<c;
	
	return 0;
}

Measured memory_bytes: 3628
/*
	Name: Prathamesh Shendarkar
	My Motto: IS TO NEVER GIVE UP
	My Belief: If you are not able to solve a particular question don't copy and paste a solution, 
			   no one is going to look into your account and tell you that, oh my look he has solved so many questions, 
			   remeber you are cheating on yourself, Just try to solve that question after some time or some days, 
			   or look upon a solution and check for the intiution or approach they have used, 
			   But never mug up there solution. 
			   Go for Learning don't copy plz.
*/

#include<bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define len(s) s.length()
#define loopa(i,a,b) for( i=a;i<=b;i++)
#define loop(i,n)    for( i=0;i<n;i++)
#define pool(i,n)    for( i=n-1;i>=0;i--)
#define poop(i,a,b) for( i=a;i>=b;i--)
#define on cout<<endl
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return 0
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001

typedef long long  ll;
typedef long double  ldo;
typedef double  db ;
using namespace std;

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

//ll exp(ll x,ll y){ 
//	ll res=1;
//	x=x%mod;
//	while(y>0) 
//	{ 
//		if(y&1) 
//			res=(res*x)%mod; 
//		y = y>>1;
//		x=(x*x)%mod; 
//	} 
//	return res; 
//} 

ll check_prime(ll n){
	for(ll i = 2;i<=ceil(sqrt(n));i++){
		if(n%i == 0){
			return 0;
		}
	}
	return 1;
}

bool check_princi(vector<ll> v){
	ll n = v.size();
	for(ll i = 1;i<n - 1;i++){
		if(v[i - 1] + v[i + 1] < v[i]){
			return false;
		}
	}
	return true;
}

int main(){
    fastio;
	ll n;
	cin >> n;
	set<string> s;
	for(ll i = 0;i<n;i++){
		string d;
		cin >> d;
		s.insert(d);
	}
    cout << s.size() << "\n";
}




Measured memory_bytes: 19252
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;

vector<int> adj[maxn];
int has[maxn];

bool flex[maxn];
int pari[maxn];

int lb[maxn], rb[maxn];

int ans[maxn];

int n, k;

bool solve(int u, int p)
{
	for(int v : adj[u])
	{
		if(v == p) continue;
		if(!solve(v, u)) return false;
	}
	lb[u] = -1e9, rb[u] = 1e9;
	bool allflex = true;
	pari[u] = -1;
	for(int v : adj[u])
	{
		if(v == p) continue;
		if(flex[v]) continue;
		allflex = false;
		if(pari[v] != -1 && pari[u] == -1)
		{
			pari[u] = 1-pari[v];
		}
		else if(pari[v] != -1 && pari[u] == pari[v])  return false;
		// if(u == 8649) printf("has %d %d as a child\n", lb[v], rb[v]);
		lb[u] = max(lb[u], lb[v]-1);
		rb[u] = min(rb[u], rb[v]+1); 	
	}
	// printf("fin %d: [%d, %d] (%d)\n", u, lb[u], rb[u], pari[u]);
	// if(u == 8649) printf("has = %d, lb = %d, rb = %d, par = %d\n", u, lb[u], rb[u], pari[u]);
	if(lb[u]> rb[u]) return false;
	if(has[u] != -1)
	{
		if(!(lb[u]<= has[u] && has[u]<= rb[u])) return false;
		if(pari[u] != -1 && has[u]%2 != pari[u]) return false;
		pari[u] = has[u]%2;
		lb[u] = rb[u] = has[u];
		return true;
	}
	if(allflex) flex[u] = true;
	return true;
}

void recon(int u, int p)
{
	if(p)
	{
		if(lb[u]<= ans[p]-1 && ans[p]-1<= rb[u]) ans[u] = ans[p]-1;
		else if (lb[u]<= ans[p]+1 && ans[p]+1<= rb[u]) ans[u] = ans[p]+1;
		// else printf("prblem at %d, [%d, %d] p = %d, ans[p] = %d\n", u, lb[u], rb[u], p, ans[p]);
	}
	for(int v : adj[u])
	{
		if(v == p) continue;
		recon(v, u);
	}
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i<= n-1; i++)
	{
		int u, v; scanf("%d %d", &u, &v);
		adj[u].pb(v); adj[v].pb(u);
	}
	for(int i = 1; i<= n; i++) has[i] = -1;
	scanf("%d", &k);
	for(int i = 1; i<= k; i++)
	{
		int v, p; scanf("%d %d", &v, &p);
		has[v] = p;
	}
	if(!solve(1, 0))
	{
		puts("No"); return 0;
	}
	// printf("finished sovling\n");
	ans[1] = lb[1];
	recon(1, 0);
	// printf("%d %d\n", lb[1], rb[1]);
	// printf("%d\n", has[1]);
	puts("Yes");
	for(int i = 1; i<= n; i++) printf("%d\n", ans[i]);
}

Measured memory_bytes: 16256
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define N 9

struct data{
  int f[N];
  int move;
  string path;

  bool operator < (const data &p) const {
    for(int i = 0;i < N;i++){
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char where[4] = {'u', 'l', 'd', 'r'};

bool isTarget(data);
string bfs(data);

int main(){
  data a;
  int i;
  string c;

  for(i = 0;i < N;i++){
    cin >> a.f[i];
    if(a.f[i] == 0){
      a.f[i] = N;
      a.move = i;
    }
  }
  c = bfs(a);
  cout << c.size() << endl;

  return 0;
}

bool isTarget(data p){
  int i;
  
  for(i = 0;i < N;i++){
    if(p.f[i] != (i + 1)) return 0;
  }
    return 1;
}

string bfs(data p){
  queue<data> Q;
  map<data,bool> V;
  data x,y;
  int px,py,tx,ty,i;
  p.path = "";
  Q.push(p);
  V[p] = 1;

  while(!Q.empty()){
    x = Q.front(); Q.pop();
    if(isTarget(x)) return x.path;
    px = x.move / (N/3);
    py = x.move % (N/3);
    for(i = 0;i < 4;i++){
      tx = px + dx[i];
      ty = py + dy[i];
      if(tx < 0 || ty < 0 || tx >= (N/3) || ty >= (N/3)) continue;
      y = x;
      swap(y.f[x.move],y.f[tx * (N/3) + ty]);
      y.move = tx * (N/3) + ty;
      if(!V[y]){
	V[y] = 1;
	y.path += where[i];
	Q.push(y);
      }
    }
  }
  return "unsolvable";
}



Measured memory_bytes: 30516
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

string cube[6] = {
	"..rr....",
	"..rr....",
	"ggyybbww",
	"ggyybbww",
	"..oo....",
	"..oo...."
};

void g(int *a, int *b, vector<string> &tmp){
	for(int i = 0; i < 8; i++) b[i] = a[i];
	rotate(b, b+6, b+8);
	for(int i = 0; i < 8; i++){
		int x2 = b[i] % 8, y2 = b[i] / 8;
		int x1 = a[i] % 8, y1 = a[i] / 8;
		tmp[y2][x2] = cube[y1][x1];
	}
}

void h(int *a, int *b, vector<string> &tmp){
	for(int i = 0; i < 4; i++) b[i] = a[i];
	rotate(b, b+3, b+4);
	for(int i = 0; i < 4; i++){
		int x2 = b[i] % 8, y2 = b[i] / 8;
		int x1 = a[i] % 8, y1 = a[i] / 8;
		tmp[y2][x2] = cube[y1][x1];
	}
}

void f(char c){
	vector<string> tmp(6, "........");
	if( c == 'U' ){
		{
			int a[8] = {16,17,18,19,20,21,22,23}, b[8];
			g(a, b, tmp);
		}
		{
			int a[4] = {10,11,3,2}, b[4];
			h(a, b, tmp);
		}
	}else if( c == 'F' ){
		{
			int a[8] = {17,25,34,35,28,20,11,10}, b[8];
			g(a, b, tmp);
		}
		{
			int a[4] = {26,27,19,18}, b[4];
			h(a, b, tmp);
		}
	}else if( c == 'R' ){
		{
			int a[8] = {19,27,35,43,30,22,3,11}, b[8];
			g(a, b, tmp);
		}
		{
			int a[4] = {28,29,21,20}, b[4];
			h(a, b, tmp);
		}
	}else if( c == 'D' ){
		{
			int a[8] = {31,30,29,28,27,26,25,24}, b[8];
			g(a, b, tmp);
		}
		{
			int a[4] = {42,43,35,34}, b[4];
			h(a, b, tmp);
		}
	}else if( c == 'B' ){
		{
			int a[8] = {21,29,43,42,24,16,2,3}, b[8];
			g(a, b, tmp);
		}
		{
			int a[4] = {30,31,23,22}, b[4];
			h(a, b, tmp);
		}
	}else if( c == 'L' ){
		{
			int a[8] = {10,2,23,31,42,34,26,18}, b[8];
			g(a, b, tmp);
		}
		{
			int a[4] = {24,25,17,16}, b[4];
			h(a, b, tmp);
		}
	}
	
	for(int y = 0; y < 6; y++){
		for(int x = 0; x < 8; x++){
			if( tmp[y][x] != '.' ){
				cube[y][x] = tmp[y][x];
			}
		}
	}
}

int main(){
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++) f(s[i]);
	
	for(int y = 0; y < 6; y++){
		cout << cube[y] << endl;
	}
}

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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var A = int.Parse(inputs[0]);
        var B = int.Parse(inputs[1]);
        var C = int.Parse(inputs[2]);

        var values = new int[3] { A, B, C };
        values = values.OrderByDescending(v => v).ToArray();
        var ans = values[0] * 10 + values[1] + values[2];
        Console.WriteLine(ans);
    }

}



Measured memory_bytes: 13268
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000009;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[310][310];
int at[310];
int sh[310];
int main(){
    int a,b;scanf("%d%d",&a,&b);
    for(int i=0;i<a;i++)for(int j=0;j<b;j++){scanf("%d",&p[i][j]);p[i][j]--;}
    for(int i=0;i<a;i++){
        sh[p[i][0]]++;
    }
    int ret=0;
    for(int i=0;i<b;i++)ret=max(ret,sh[i]);
    while(1){
        for(int i=0;i<b;i++){
            if(sh[i]>=ret){
                sh[i]=-1;
            }
        }
        for(int i=0;i<b;i++)if(sh[i]!=-1)sh[i]=0;
            bool en=false;
        for(int i=0;i<a;i++)for(int j=0;j<b;j++){
            if(sh[p[i][j]]!=-1){
                sh[p[i][j]]++;break;
            }
            if(j==b-1)en=true;
        }
        if(en)break;
        int tmp=0;
        for(int i=0;i<b;i++){
            tmp=max(tmp,sh[i]);
        }

        ret=min(ret,tmp);
    }
    printf("%d\n",ret);
}

Measured memory_bytes: 512
/*ITP1_3_D.c*/
#include<stdio.h>
int main(void){
   int a,b,c,d,i,j;
   scanf("%d %d %d",&a,&b,&c);
   j=0;
   for(i=a;i<=b;i++){
      d=c % i;
      if(d==0){
         j++;
      }
   }
   printf("%d\n",j);
   return 0;
}

Measured memory_bytes: 1860
program main
  implicit none
  integer(8) :: X,Y,Z,K
  integer:: tot, tot2
  integer(8),allocatable :: A(:),B(:),C(:)
  integer(8),allocatable :: AB(:),ABC(:)
  integer(8),allocatable :: AB2(:),C2(:)
  integer :: i1,i2,i3,i
  read(*,*) X,Y,Z,K
  allocate(A(X),B(Y),C(Z))
  read(*,*) A(:)
  read(*,*) B(:)
  read(*,*) C(:)

  allocate( AB(X*Y) )
  tot=X*Y
  i = 0
  do i1 = 1,X
     do i2 = 1,Y
           i = i + 1
           AB(i) = A(i1) + B(i2) 
     end do
  end do
  allocate(AB2(tot))
  call hsort(int(tot,8), AB)
  tot2 =(tot-max(tot-K,1) + 1)*Z
  allocate(ABC( tot2 ) )
  i=0
  do i1 = tot,max(tot-K,1),-1
     do i2 = 1,Z
        i = i + 1
        ABC(i) = AB(i1) + C(i2)
     end do
  end do
  call hsort(int(tot2,8), ABC)
  do i = 1,K
     write(*,'(i0)') ABC(tot2-i+1)
  end do
  stop
contains
  
  subroutine hsort(n, x)
    implicit none
    integer(8), intent(IN) :: n
    integer(8), intent(INOUT) :: x(n)
    ! local
    integer(8) k
    integer(8) :: tmp,tmp2
    ! external subroutine
    !external mkheap

    do k = n/2, 1, -1
       tmp = x(k)
       call mkheap(n, x, k, n, tmp)
    enddo

    do k = n, 2, -1
       tmp = x(k)
       x(k) = x(1)

       call mkheap(n, x, int(1,8), k-1, tmp)
    end do

    return
  end subroutine hsort

  subroutine mkheap(n, x, root, leaf, val)
    implicit none
    integer(8), intent(IN)    :: n, root, leaf
    integer(8), intent(INOUT) :: x(1:n)
    integer(8), intent(IN)    :: val
    ! local
    integer(8) :: i, j
    integer(8) :: tmp

    i = root
    j = i * 2

    do
       if (j > leaf) exit

       if (j < leaf) then
          if (x(j) < x(j+1)) j = j + 1
       end if

       if (x(j) > val) then
          x(i) = x(j)
          i = j
          j = i * 2
       else
          j = leaf + 1
       endif
    end do

    x(i) = val

    return
  end subroutine mkheap
  recursive function iqsort(ix) result(ires)
    integer(8), allocatable :: ires(:)
    integer(8), intent(in)  :: ix(:)
    integer(8) :: k
    if (size(ix) <= 1) then 
       ires = ix
    else  
       k = ix(size(ix) / 2)
       ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
    end if
  end function iqsort
end program main


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

vi adj[101010];
vi color, color2;

void depth(int i, int d) {
    if (color[i] != -1) return;
    color[i] = d;
    for (int a: adj[i]) {
        depth(a, d + 1);
    }
}

void depth2(int i, int d) {
    if (color2[i] != -1) return;
    color2[i] = d;
    for (int a: adj[i]) {
        depth2(a, d + 1);
    }
}


int initb, initw;

void c(int i, int v) {
    if (((i == 0 && v != initb) || (i == 1 && v != initw)) && color[v] != -1) return;
    color[v] = i;
    for (int a: adj[v]) {
        if (color[a] == -1) {
            c(i, a);
        }
    }
}

int main() {
    int n;
    cin >> n;
    
    color.assign(101010, -1);
    color2.assign(101010, -1);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    depth(0, 0);
    depth2(n - 1, 0);
    int d = color[n - 1];
    for (int i = 0; i < 101010; i++) {
        if (color[i] == d / 2 && color2[i] == d - d / 2) initb = i;
        if (color[i] == d / 2 + 1 && color2[i] == d - (d / 2 + 1)) initw = i;
    }
    
    color.assign(101010, -1);
    color[initb] = 0;
    color[initw] = 1;
    c(0, initb);
    c(1, initw);
    
    int cntb = 0, cntw = 0;
    for (int i = 0; i < 101010; i++) {
        if (color[i] == 0) cntb++;
        else if (color[i] == 1) cntw++;
    }
    
    cout << (cntb > cntw ? "Fennec" : "Snuke") << endl;
}


Measured memory_bytes: 10496
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#define INF 0x7FFFFFFF

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;

int main(void){
	int n, m, l, k, a, h, inp, r[100], t[100][101], d[100][100], ans, i, j, x, y, z;
	priority_queue<PP,vector<PP>,greater<PP> > que; // 時間 残り時間 町の番号
	while(1){
		scanf("%d%d%d%d%d%d",&n,&m,&l,&k,&a,&h);
		if(n + m + l + k + a + h == 0)
			break; 
		memset(r,0,sizeof(r)); 
		for(i = 0;i < l;i++){  
			scanf("%d",&inp);  
			r[inp] = 1; 
		}
		memset(d,-1,sizeof(d));
		for(i = 0;i < k;i++){
			scanf("%d%d%d",&x,&y,&z);
			d[x][y] = z;
			d[y][x] = z;
		}
		memset(t,-1,sizeof(t));
		t[a][m] = 0;
		que.push(PP(0,P(m,a)));
		while(que.size()){
			x = que.top().first, y = que.top().second.first,z = que.top().second.second;
//			printf("t[%d][%d] = %d\n",z,y,t[z][y]);
			que.pop();
			if(r[z]){
				for(i = y + 1;i <= m;i++){
					if(t[z][i] == -1 || t[z][i] > x + i - y){
						t[z][i] = x + i - y;
						que.push(PP(x + i - y,P(i,z)));
					}
				}
			}
			for(i = 0;i < n;i++){
				if(d[z][i] != -1 && d[z][i] <= y && (t[i][y - d[z][i]] == -1 || t[i][y - d[z][i]] > x + d[z][i])){
					t[i][y - d[z][i]] = x + d[z][i];
					que.push(PP(x + d[z][i],P(y - d[z][i],i)));
				}
			}
		}
		ans = -1;
		for(i = 0;i <= m;i++){
			if(t[h][i] != -1 && (ans == -1 || t[h][i] < ans)) ans = t[h][i];
		}
		if(ans != -1)
			printf("%d\n",ans);
		else
			printf("Help!\n");

	}
	return 0;
}

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

int main()
{
	int a,b,sum=0;
	cin>>a>>b;
	if(b==1)
	{
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<100;i++)
	{
		sum=a*i-(i-1);
		if(sum>=b)
		{
			cout<<i<<endl;
			return 0;
		}
	}
}

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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
  ll ans = 0;
  int left;
  ll minxy = min(X, Y);
  if(X > Y){
    left = 0;
  }else if(X < Y){
    left = 1;
  }else{
    left = 2;
  }
  if(A + B > 2*C){
    if(left == 2){
      ans = C * X * 2;
    }else if(left == 0){
      // A is left
      if(A >= 2*C){
        ans = C * X * 2;
      }else{
        ans = C * minxy * 2 + A * (X - minxy);
      }
    }else{
      // B is left
      if(B >= 2*C){
        ans = C * Y * 2;
      }else{
        ans = C * minxy * 2 + B * (Y - minxy);
      }
    }
  }else{
    ans = A*X + B*Y;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//long long使う！！！！！！
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;

ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}

const ll big=998244353;
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x);
    ll t=exp(x,y/2);
    return (t*t);
}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

typedef pair<int,int> p;



int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    int x,n;cin >> x >> n;
    vector<int> p(n);
    int ans=100000000;
    vector<bool> al(105,true);
    rep(i,n){
        cin >> p[i];
        al[p[i]]=false;
    }
    rep(i,105){
        if(al[i]&&abs(i-x)<abs(x-ans))ans=i;
        if(al[i]&&abs(i-x)==abs(x-ans))ans=min(ans,i);
    }
    cout << ans << endl;
}

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

using namespace std;

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

    vector<int> v;

    for(int i = 0; i < N; ++i){
        cin >> A;
        v.push_back(A);
    }


    int maxp = 0, maxv = (K-v[N-1]) + v[0];
    for(int i = 1; i < N; ++i){
        if ( maxv < (v[i] - v[i-1])){
            maxp = i;
            maxv = v[i] - v[i-1];
        }
    }

    // cout << maxp << " " << maxv << endl;

    int ans = 0;
    for(int i = 0; i < N-1; ++i){
        int s = i, e = i;
        s += maxp;
        e += maxp+1;
        s %= N;
        e %= N;
        // cout << e << " " << s << endl;
        if (s == 0){
            ans += min(abs(v[e] - (v[s]+K) ), abs(v[e] - v[s]));
        }
        else if (e == 0){
            ans += min(abs(v[e]+K - v[s] ), abs(v[e] - v[s]));
        }
        else{
            ans += abs(v[e] - v[s]);
        }
    }

    cout << ans << endl;

    return 0;
}

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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll L;
  cin >> n >> L;
  VLL a(n);
  rep(i,n) cin >> a[i];
  rep(i,n-1){
    if( a[i] + a[i+1] >= L) {
      cout << "Possible" << endl;
      rep(front,i) cout << front+1 << endl;
      for(int back = n-1; back > i+1; back--) cout << back << endl;
      cout << i+1 << endl;
      return 0;
    }
  }

  cout << "Impossible" << "\n";


  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
struct bebek{
	long long idx,score;
	string s;
};
long long n;
bebek arr[100005];
bool cmp(bebek a,bebek b){
	if(a.s==b.s)return a.score>b.score;
	return a.s<b.s;
}
int main(){
	cin>>n;
	for(int i =1;i<=n;i++){
		cin>>arr[i].s>>arr[i].score;
		arr[i].idx=i;
	}
	sort(arr+1,arr+n+1,cmp);
	for(int i =1;i<=n;i++){
		cout<<arr[i].idx<<endl;
	}
}

Measured memory_bytes: 2560
#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 DP[305][305];
int w[305];

int solve(int l, int r){
    if(DP[l][r]>-1) return DP[l][r];
    if(r<=l+1) return DP[l][r] = 0;
    if((abs(w[l]-w[r-1])<=1)&&(solve(l+1, r-1)==r-l-2)) return DP[l][r] = r-l;
    for(int i=1;l+i<=r-1;++i){
        DP[l][r] = max(DP[l][r], solve(l, l+i)+solve(l+i, r));
    }
    return DP[l][r];
}

int main() {
    int N;
    vector<int> ansarr;
    while(true){
        for(int i=0;i<305;++i){
            for(int j=0;j<305;++j){
                DP[i][j] = -1;
            }
        }
        cin>>N;
        if(N==0) break;
        for(int i=0;i<N;++i){
            cin>>w[i];
        }
        ansarr.push_back(solve(0, N));
    }
    for(int i=0;i<ansarr.size();++i){
        cout<<ansarr[i]<<endl;
    }
}




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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

int n;

void read() {
    cin >> n;
}

const int N = 1e6 + 10;
int dp[N][2][2];

void run() {
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int flag0 = 0; flag0 <= 1; flag0++) {
            for (int flag1 = 0; flag1 <= 1; flag1++) {
                for (int nxtVal = 0; nxtVal <= 9; nxtVal++) {
                    add(dp[i + 1][flag0 | (nxtVal == 0)][flag1 | (nxtVal == 9)], dp[i][flag0][flag1]);
                }
            }
        }
    }
}

void write() {
    cout << dp[n][1][1] << endl;
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
    read();
    run();
    write();
    return 0;
}

Measured memory_bytes: 19220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int n, m;cin>>n>>m;
    char gap = 'A'-'a';
    string s;cin>>s;
    s[m-1]-=gap;
    co(s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,t,a;
vector<int> v[100010];
int dist[100010][2];
queue<int> q;
int res=0;
int main()
{
	cin >>n>>t>>a;
	t--,a--;
	for (int i=0;i<n-1;i++)
	{
		int x,y;
		cin >>x>>y;
		x--,y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for (int i=0;i<n;i++) dist[i][0]=dist[i][1]=1e9;
	dist[t][0]=dist[a][1]=0;
	q.push(t); q.push(0);
	q.push(a); q.push(1);
	while (!q.empty())
	{
		int x=q.front(); q.pop();
		int y=q.front(); q.pop();
		for (int i=0;i<v[x].size();i++)
		{
			int xi=v[x][i];
			if (dist[xi][y]>dist[x][y]+1)
			{
				dist[xi][y]=dist[x][y]+1;
				q.push(xi); q.push(y);
			}
		}
	}
	for (int i=0;i<n;i++)
	{
		if (dist[i][0]<dist[i][1])
		{
			res=max(res,(dist[i][0]==dist[i][1] ? dist[i][1] : dist[i][1]-1));
			//cout <<i<<" "<<dist[i][0]<<" "<<dist[i][1]<<" "<<res<<" ##\n";
		}
	}
	cout <<res;
	return 0;
} 

Measured memory_bytes: 7288
import numpy as np
n,d=map(int,input().split())
x=[]
ans=0
for _ in range(n):
    *r,=map(int,input().split())
    x.append(r)
x=np.array(x)
for i in range(1,n):
    for j in range(i):
        d=x[i]-x[j]
        d2=d*d
        y=np.sqrt(sum(d2))
        if y.is_integer():
            ans += 1
print(ans)



Measured memory_bytes: 12396
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

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

    vector<ll> power_of_two(n+1);
    power_of_two[0] = 1;
    for(int i = 1; i <= n; ++i) power_of_two[i] = power_of_two[i-1] * 2 % mod;

    ll res = 0;
    for(int i = 0; i < n; ++i){
        int len = n - i - 1;
        ll sum = 1;
        if(len > 0){
            sum = power_of_two[len - 1] * (len + 2) % mod;
        }
        sum = sum * power_of_two[n - len - 1] % mod;
        sum = sum * c[i] % mod;
        chadd(res, sum);
    }
    res = res * power_of_two[n] % mod;
    cout << res << endl;
}

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

for h in range(1, 3501):
    for n in range(1, 3501):
        a = 4 * h * n - h * N - n * N
        if a == 0:
            break
        w = int((h * n * N) / a)
        if w > 0 and 4 / N == 1 / h + 1 / n + 1 / w:
            print(h, n, w)
            exit()


Measured memory_bytes: 41068
import math

def facts(n):
    sqrt_n = int(math.sqrt(n))
    fs = []
    fs_rev = []
    
    for i in range(1, sqrt_n + 1):
        if n % i == 0:
            fs.append(i)
            if n != i ** 2:
                fs_rev.append(n // i)
    
    fs.reverse()
    return fs_rev + fs

n, k = map(int, input().split())
ll = list(map(int, input().split()))
s = sum(ll)
fs = facts(s)

for f in fs:
    ll_f = list(map(lambda x: x % f, ll))
    ll_f.sort(reverse = True)
    ignore = sum(ll_f) // f
    keep = sum(ll_f[ignore:])

    if keep <= k:
        print(f)
        break

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

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

using namespace std;

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

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


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

	int n, m;
	ll k;
	cin >> n >> m >> k;
	vector<ll> sum_a(n);
	for (int i = 0; i < n; i++)
	{
		ll a;
		cin >> a;
		sum_a[i] = (i == 0 ? 0 : sum_a[i - 1]) + a;
	}
	int res = 0;
	ll sum_b = 0;
	for (int i = 0; i <= m; i++)
	{
		ll b = 0;
		if (i != 0)
			cin >> b;
		sum_b += b;
		ll residual = k - sum_b;
		if (residual < 0)
			continue;
	
		auto idx = upper_bound(sum_a.begin(), sum_a.end(), residual);
		int num_a = idx - sum_a.begin();
		int num_b = i;
		res = max(res, num_a + num_b);
	}
	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 4764
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<long long,long long>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  int k,n;
  cin >> n >> k;
  vector <ll> a;
  vector <ll> b;
  vector <P> c; 
  REP(i,n){
    ll x,y;
    cin >> x >> y;
    a.pb(x);
    b.pb(y);
    c.pb(mk(x,y));
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ll mi = (a[a.size()-1]-a[0])*(b[b.size()-1]-b[0]);
  //cout << mi << endl;
  REP(i,a.size()){
    for(int j = i+1;j < a.size();j++){
      REP(d,b.size()){
	for(int l = d+1;l < b.size();l++){
	  int num = 0;
	  ll x1 = a[i],x2 = a[j];
	  ll y1 = b[d] , y2 = b[l];
	  //cout << x1 << "  " << y1 << "  " << x2 << "  " << y2 <<  "  " <<  endl;
	  REP(o,n){
	    if(c[o].first >= x1 && c[o].first <= x2 && c[o].second >= y1 && c[o].second <= y2){
	      num++;
	    }
	  }  
	  //cout << 12 << endl;
	  if(k <= num)
	    mi = min(mi, (x2-x1)*(y2-y1));
	  //cout << (x2-x1)*(y2-y1)  << endl;
	}
      }
    }
  }
  cout << mi << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7




n, k, l = map(int, input().split())

table1 = [-1] * n
table2 = [-1] * n
def find(x, table):
    if table[x] < 0:
        return x
    table[x] = find(table[x], table)
    return table[x]


def union(x, y, table):
    r1 = find(x, table)
    r2 = find(y, table)
    if r1 == r2:
        return
    d1 = table[r1]
    d2 = table[r2]
    if d1 <= d2:
        table[r2] = r1
        if d1 == d2:
            table[r1] -= 1
    else:
        table[r1] = r2



for i in range(k):
    u, v = map(int, input().split())
    union(u - 1, v - 1, table1)


for i in range(l):
    u, v = map(int, input().split())
    union(u - 1, v - 1, table2)


f = defaultdict(int)
for i in range(n):
    f[(find(i, table1), find(i, table2))] += 1



print(*[f[(find(j, table1), find(j, table2))] for j in range(n)])

Measured memory_bytes: 118872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<double> v(N);
  rep(i,N)cin >> v[i];
  double sum = 0;
  rep(i,N) sum += 1.0/v[i];
  cout << 1.0/sum << endl;
  return 0;
}


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

void func147b() {
  string s;
  int i, j;
  cin>>s;
  int answer = 0;
  for (i = 0; i < s.length(); i++) {
    j = s.length()-i-1;
    if ((s[i] != s[j])&&(i < j)) answer++;
  }
  cout<<answer<<"\n";
}

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

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

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

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n; cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll money = 1000;
    rep(i,n-1){
        if(a[i+1] > a[i]){
            ll k = money / a[i];
            money %= a[i];
            money += k * a[i+1];
        }
    }
    cout << money << endl;
}

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

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

template <int Mod>
class ModInt {
 public:
  ModInt() : n_(0) {}
  ModInt(long long n) : n_(n % Mod) {
    if (n_ < 0) {
      // In C++, (-n)%m == -(n%m).
      n_ += Mod;
    }
  }
  ModInt& operator+=(const ModInt& m) {
    n_ += m.n_;
    if (n_ >= Mod) {
      n_ -= Mod;
    }
    return *this;
  }
  ModInt& operator++() { return (*this) += 1; }
  ModInt& operator-=(const ModInt& m) {
    n_ -= m.n_;
    if (n_ < 0) {
      n_ += Mod;
    }
    return *this;
  }
  ModInt& operator--() { return (*this) -= 1; }
  ModInt& operator*=(const ModInt& m) {
    n_ *= m.n_;
    n_ %= Mod;
    return *this;
  }
  ModInt& operator/=(const ModInt& m) {
    *this *= m.inverse();
    return *this;
  }
  ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; }
  ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; }
  ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; }
  ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; }
#define DEFINE_BINARY_OPERATOR(op) \
  bool operator op(const ModInt& m) const { return n_ op m.n_; }
  DEFINE_BINARY_OPERATOR(!=);
  DEFINE_BINARY_OPERATOR(<);
  DEFINE_BINARY_OPERATOR(<=);
  DEFINE_BINARY_OPERATOR(==);
#undef BOP
  ModInt pow(int n) const {
    // a * b ^ n = answer.
    ModInt a = 1, b = *this;
    while (n != 0) {
      if (n & 1) {
        a *= b;
      }
      n /= 2;
      b *= b;
    }
    return a;
  }
  ModInt inverse() const {
    // Compute the inverse based on Fermat's little theorem. Note that this only
    // works when n_ and Mod are relatively prime. The theorem says that
    // n_^(Mod-1) = 1 (mod Mod). So we can compute n_^(Mod-2).
    return pow(Mod - 2);
  }
  long long value() const { return n_; }

  static ModInt factorial(int n) {
    for (int i = factorial_.size(); i <= n; ++i) {
      factorial_.push_back(i == 0 ? 1 : factorial_.back() * i);
    }
    return ModInt<Mod>::factorial_[n];
  }
  static ModInt combination(int n, int k) {
    return factorial(n) / factorial(n - k) / factorial(k);
  }

 private:
  long long n_;
  static std::vector<ModInt> factorial_;
};

template<int Mod>
std::vector<ModInt<Mod>> ModInt<Mod>::factorial_ = std::vector<ModInt<Mod>>();

template <int Mod>
std::ostream& operator<<(std::ostream& out, const ModInt<Mod>& m) {
  out << m.value();
  return out;
}

using namespace std;

using mint = ModInt<998244353>;

int main() {
  int N, M, K;
  cin >> N >> M >> K;

  mint cnt = 0;
  for (int k = 0; k <= K; ++k) {
    cnt += mint(M) * mint(M - 1).pow(N - 1 - k) * mint::combination(N - 1, k);
  }
  cout << cnt << endl;
}


Measured memory_bytes: 5300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  int a,b;
  string u;
  cin >> s >> t >> a >> b >> u;
  if(s == u) {
    a--;
  }
  else {
    b--;
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class WeightedUnionFind:
    """ 重み付きUnion-Find木 """

    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    def find(self, x):
        """ 検索 """
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w):
        """ 併合 """
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = - w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        """ 同じ集合に属するか """
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        """ xからyへのコスト """
        return self.weight[x] - self.weight[y]

N, M = MAP()
wuf = WeightedUnionFind(N)
for i in range(M):
    l, r, d = MAP()
    # 既に同じ集合にあるなら、距離が正しいか確認
    if wuf.same(l, r):
        if wuf.diff(l, r) != d:
            No()
            exit()
    else:
        wuf.union(l, r, d)
Yes()


Measured memory_bytes: 11600
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


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

	int M;
	scanf("%d",&M);

	int Q[M];
	for(int i = 0; i < M; i++)scanf("%d",&Q[i]);
	sort(Q,Q+M);

	int left = 0,right,m,count = 0;

	for(int i = 0; i < M; i++){
		right = N-1;
		m = (left+right)/2;

		while(left <= right){
			if(S[m] == Q[i]){
				count++;
				left= m+1;
				break;
			}else if(S[m] > Q[i]){
				right = m-1;
			}else{ //S[m] < Q[i]
				left = m+1;
			}
			m = (left+right)/2;
		}
	}
	printf("%d\n",count);
}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (ll)1e9+7
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define MIN(X,Y) ((X)<(Y)?(X):(Y))


int fact(int x)
{
    ll res = 1;
    for(int i=1;i<=x;i++){
        res *= i;
        res %= MOD;
    }
    return res;
}


int main()
{
    int x;
    cin>>x;
    cout<<fact(x)<<endl;
    return 0;
}

Measured memory_bytes: 256