akhauriyash/Code-Regression huggingface dataset:
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<long long,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

bool ok(long long key,long long index,vector<int> &V){
    if(V.at(index) > key) return true;
    else if(V.at(index) <= key) return false;
}
long long binary_search(long long key,long long size,vector<int> &V){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        bool hantei = ok(key,mid,V);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1) return 0;
    return V.at(left);
}

//leftは条件を満たさない最大の値、rightは条件を満たす最小の値になっている

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

    int X;cin >>X;
    cout << lcm(360,X)/X << endl;
}


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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

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

const int N = 1000 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

char g[N][N];
int n, m;
pint st, ed;

bool OK(int x, int y) {
	if (x <= 0 || x > n || y <= 0 || y > m)
		return 0;
	else
		return 1;
}

int tms, idx[N][N];

void DFS(int x, int y, int c) {
	idx[x][y] = c;
	for (int d = 0; d < 4; d++) {
		int nx = x + dx[d];
		int ny = y + dy[d];
		if (OK(nx, ny) && g[nx][ny] == '.' && !idx[nx][ny])
			DFS(nx, ny, c);
	}
}

vector<int> a[N * N];
int dis[N * N];
bool inQ[N * N];

int main() {
	ios::sync_with_stdio(0);

	cin >> n >> m;
	cin >> st.fi >> st.se;
	cin >> ed.fi >> ed.se;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> g[i][j];

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (!idx[i][j] && g[i][j] == '.')
				DFS(i, j, ++tms);

	for (int x = 1; x <= n; x++)
		for (int y = 1; y <= m; y++) {
			if (g[x][y] != '.') continue;
			for (int dx = -2; dx <= 2; dx++)
				for (int dy = -2; dy <= 2; dy++) {
					int nx = x + dx;
					int ny = y + dy;
					if (OK(nx, ny) && g[nx][ny] == '.' && idx[nx][ny] != idx[x][y]) {
						a[idx[nx][ny]].push_back(idx[x][y]);
						a[idx[x][y]].push_back(idx[nx][ny]);
					}
				}
		}

	queue<int> q;
	memset(dis, 0x3f, sizeof(dis));
	dis[idx[st.fi][st.se]] = 0;
	inQ[idx[st.fi][st.se]] = 1;
	q.push(idx[st.fi][st.se]);

	while (!q.empty()) {
		auto u = q.front();
		q.pop();
		for (auto v: a[u]) {
			if (dis[v] > dis[u] + 1) {
				dis[v] = dis[u] + 1;
				if (!inQ[v]) {
					inQ[v] = 1;
					q.push(v);
				}
			}
		}
		inQ[u] = 0;
	}

	if (dis[idx[ed.fi][ed.se]] == INF)
		cout << -1 << endl;
	else
		cout << dis[idx[ed.fi][ed.se]] << endl;

	return 0;
}


Measured memory_bytes: 58188
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    count = Counter(A)
    L = len(count)
    if L<=K:
        print(0)
    else:
        B = list(count.values())
        B.sort()
        print(sum(B[:L-K]))



if __name__ == '__main__':
    main()

Measured memory_bytes: 34260
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int ans=3;
        if(a==b)ans--;
        if(a==c)ans--;
        if(b==c)ans--;
        System.out.println(ans==0?1:ans);

    }
    
 
}

Measured memory_bytes: 21716
//Volume1-0102
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//initialization
        int[][] mat = null;
        String[] s;
        int n,i,j,
            row_sum,
            clm_sum;

        //input
        Scanner sc = new Scanner(System.in);
        while((n = Integer.parseInt(sc.nextLine())) != 0){
        	mat = new int[n+1][n+1];
        	for(i=0;i<n;i++){
        		s = sc.nextLine().split("\\s");
        		for(j=0;j<n;j++){
        			mat[i][j] = Integer.parseInt(s[j]);
        		}
        	}

        	//calculation
        	for(i=0;i<n+1;i++){
        		row_sum = 0;
        		clm_sum = 0;
        		for(j=0;j<n;j++){
        			row_sum += mat[i][j];
        			clm_sum += mat[j][i];
        		}
        		mat[j][i] = clm_sum;
        		mat[i][j] = row_sum;
        	}

        	//output
        	for(i=0;i<n+1;i++){
        		for(j=0;j<n+1;j++){
        			System.out.printf("%5d",mat[i][j]);
        		}
        		System.out.println();
        	}
        }
	}
}

Measured memory_bytes: 23568
import java.util.*;

class Main{

    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();

	int[] A = new int[N+1];

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

	A[i] = sc.nextInt();

  }

	A[N] = N+2;

	int[] B = new int[N];

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

	B[i] = sc.nextInt();

  }

	int[] C = new int[N-1];

	for(int i=0; i<N-1; i++){

	C[i] = sc.nextInt();

  }
	
	int ans = 0;

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

	ans += B[A[i]-1];	

	if((A[i+1]-A[i])==1){

	ans += C[A[i]-1];

   }

  }
	
	System.out.println(ans);

 }
}

Measured memory_bytes: 23636
#include <iostream>


using namespace std;

int n,A[50];


int slove(int i,int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res=slove(i+1,m)||slove(i+1,m-A[i]);
    return res;
}


int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        int value;
        cin>>value;
        if(slove(0,value)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int n,m,a[111111],memo[111111];
int dp(int x){
  if(memo[x]!=-1) return memo[x];
  int sum=0;
  if(x==n) return 1;
  if(a[x+1]==0) sum+=dp(x+1);
  if(x+2<=n&&a[x+2]==0) sum+=dp(x+2);
  return memo[x]=sum%1000000007;
}
int main(){
  memset(memo,-1,sizeof(memo));
  cin>>n>>m;
  int b;
  for(int i=0;i<m;i++){
    cin>>b;
    a[b]=1;
  }
  cout<<dp(0)<<endl;
  return(0);
}


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

int main() {
  int a,b,c;
  cin >>a>>b>>c;
  int dai=max({a,b,c});
  int shou=min({a,b,c});
  int naka=a+b+c-dai-shou;
  int kotae=(shou*naka)/2;
  cout<<kotae<<endl;
  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++)

int main(){
  int64_t H;
  cin >> H;

  int i = 0;
  while(H != 0){
    H /= 2;
    i++;
  }

  cout << (int64_t)pow(2, i) - 1 << endl;

}


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

static const int N = 100;

int main() {
  int n, p[N+1], m[N+1][N+1];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i-1] >> p[i];
  }

  for (int i = 1; i <= n; i++) m[i][i] = 0;
  for (int l = 2; l <= n; l++) {
    for (int i = 1; i <= n-l+1; i++) {
      int j = i + l - 1;
      m[i][j] = (1<<21);
      for (int k = i; k <= j-1; k++) {
        m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
int n;
int a[maxn], b[maxn];
pair<int, int> c[maxn];
int32_t main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[i].first = a[i] + b[i];
		c[i].second = i;
	}
	sort(c, c + n);
	reverse(c, c + n);
	int res1 = 0;
	int res2 = 0;
	for(int i = 0; i < n; i += 2) {
		res1 += a[c[i].second];
	}
	for(int i = 1; i < n; i += 2) {
		res2 += b[c[i].second];
	}
	cout << res1 - res2 ;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
int n;
string s;
ll ans = 0;

void solve(ll x,ll y){
    if(x==n+1){
        ans += y;
        return;
    }
    ll cur = 0;
    for(ll i=x;i<=n;i++){
        cur = (10*cur) + (s[i]-'0');
        solve(i+1,y+cur);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n+2];
    for(int i=1;i<=n;i++)cin>>a[i];
    if(n%2==0){
        for(int i=n;i>=2;i-=2)cout<<a[i]<<" ";
        for(int i=1;i<=n-1;i+=2)cout<<a[i]<<" ";
    }
    if(n&1){
        for(int i=n;i>=1;i-=2)cout<<a[i]<<" ";
        for(int i=2;i<=n-1;i+=2)cout<<a[i]<<" ";
    }
}


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

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

int main(){
  int n,m;
  cin >> n >> m;
  map<int,int> sc;
  int  ans = 0,flag = 1;
  rep(i, m){
    int s,c;
    cin >> s >> c;
    if(sc.count(s)){
      if(sc.at(s)==c)continue;
      else {
        flag = 0;
        break;
      }
    }else{
      if(s==1&&c==0&&n>1){
        flag = 0;
        break;
      }
      sc[s] = c;
      ans += pow(10,n-s)*c;
    }
  }
  if(!sc.count(1))ans += pow(10,n-1);
  if(m==0&&n==1) ans = 0;
  if(!flag) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll A[3][3];
  rep(i,3)rep(j,3) cin>>A[i][j];
  ll n;cin>>n;
  lvector B(n,0);rep(i,n) cin>>B[i];
  for(ll b:B) rep(i,3)rep(j,3) if(A[i][j]==b) A[i][j]=-1;
  bool bingo=false;
  if(A[0][0]==-1&&A[0][1]==-1&&A[0][2]==-1) bingo=true;
  else if(A[0][0]==-1&&A[1][0]==-1&&A[2][0]==-1) bingo=true;
  else if(A[1][0]==-1&&A[1][1]==-1&&A[1][2]==-1) bingo=true;
  else if(A[0][1]==-1&&A[1][1]==-1&&A[2][1]==-1) bingo=true;
  else if(A[2][0]==-1&&A[2][1]==-1&&A[2][2]==-1) bingo=true;
  else if(A[0][2]==-1&&A[1][2]==-1&&A[2][2]==-1) bingo=true;
  else if(A[0][0]==-1&&A[1][1]==-1&&A[2][2]==-1) bingo=true;
  else if(A[0][2]==-1&&A[1][1]==-1&&A[2][0]==-1) bingo=true;
  if(bingo) print("Yes");else print("No");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MaxN = 100005;

int n, i, j, vt;
int pas[MaxN];
vector<int> ans;

main(){
	cin >> n;
	for(i=0;i<n;i++)
		cin >> pas[i];
	for(i=n-1;i>=0;i--){
		for(j=0;j<n;j++){
			if(pas[j]==i){
				vt = j;
				break;
			}
		}
		for(j=0;j<vt;j++)
			ans.push_back(1);
		for(j=vt;j<i;j++){
			ans.push_back(1);
			ans.push_back(n-1);
		}
		for(j=i;j<n;j++)
			ans.push_back(1);
		for(j=vt;j<i;j++)
			swap(pas[j], pas[j+1]);
	}
	cout << ans.size() << endl;
	for(i=0;i<ans.size();i++)
		cout << ans[i] << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ifor(i,n) for(i=0;i<n;i++)
#define ll long long
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll int i,n,t,p=INT_MAX,j=0,x,a=0,b,l=0,r=0,y;
     string s,m;
     cin>>a>>b;
     p=a*b;
     if(a==1 || b==1){
        cout<<1<<endl;
             }
     else if(p&1){
        cout<<p/2+1<<endl;
     }
     else{
        cout<<p/2<<endl;
     }

     return EXIT_SUCCESS;
}




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

int main(void){
    int k, n;
    int ans, d;
    
    std::cin >> k >> n;
    std::vector<int> a(n);
    for(int i = 0; i < n; i++){
        std::cin >> a[i];       
    }
    ans = 1001001000;
    for(int i = 0; i < n; i++){
        d = k - a[i+1] + a[i];
        //std::cout << i+1 << ":" << a[i+1] << std::endl;
        //std::cout << i << ":"<< a[i] << std::endl;
        //std::cout << d << std::endl;
        if(d < ans){
            ans = d;
        }
    }
    d = a[n-1] - a[0];
    if(d < ans){
        ans = d;
    }
    //std::cout << d << std::endl;

    std::cout << ans << std::endl;

    
    //std::cout << std::endl;
    

}

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

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rept(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.bigin(),v.end()

using namespace std;

int main(){
    ll h;
    ll n=1;
    ll ans=1;
    cin>>h;
    if(h>1){
        while(h>0){
            h=h/2;
            if(n!=1){
                ans+=n;
            } 
            n*=2;
        }
    }
    else{
        ans=1;
    }
    cout<<ans;

}



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

using namespace std;
typedef long long ll;

ll x;

int main()
{

    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> x;

    for(ll a = 0; a <= 140; ++a){
        for(ll b = 0; b <= a; ++b){
            ll pa = a * a * a * a * a;
            ll pb = b * b * b * b * b;

            if(pa - pb == x) {
                cout << a << " " << b;
                return 0;
            }
            else if(pa + pb == x){
                cout << a << " " << -b;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3652
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N=II()
A=LI()
L=[0]*N
TM=A[0]
for i in range(N):
  TM=max(TM,A[i])
  L[i]=TM-A[i]
  
  #print(L[i],TM,A[i])
ans=sum(L)
print(ans)

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


using namespace std;


int A, B;


int main()
{

	cin >> A;
	cin >> B;



	vector<int> a = vector<int>();


	int s = B * 10;

	for (int i = s; ; i++) {
		if (i / 10 == B) {
			a.push_back(i);
		}
		else {
			break;
		}
	}
	for (int i = s-1; ; i--) {
		if (i / 10 == B) {
			a.push_back(i);
		}
		else {
			break;
		}
	}

	int ans = -1;
	for (unsigned i = 0; i < a.size() && ans==-1; i++) {
		if (a[i] * 8 / 100 == A) {
			ans = a[i];
		}
	}

	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 256
n , y = map(int, input().split())

i = y//10000
j = y//5000
k = y//1000

for p in range(i+1):
  for q in range(j+1):
    if (n-p-q)>=0 and (p*10000)+(q*5000)+((n-p-q)*1000)==y:
      print(p, q, n-p-q)
      exit()
    
print(-1, -1, -1)

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

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  string s;
  cin >> s;
  vector<int> v(26, 0);
  rep(i, s.size()){
    v[s[i] - 'a']++;
  }
  rep(i, v.size()){
    if(v[i] % 2 != 0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

#include <vector>
#include <utility>

class UnionFind {
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	std::vector<int> m_parent;

public:
	//作るときはm_parentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) : m_parent(N, -1) {}

	//Aがどのグループに属しているか調べる
	// 再帰関数
	int root(int A) {
		if (m_parent[A] < 0) {
			// 自分が親の場合
			return A;
		}
		// 自分の親を取り出して直接つないでおく
		m_parent[A] = root(m_parent[A]);
		// /親を返す 
		return m_parent[A];
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -m_parent[root(A)];
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		const int rootA = root(A);
		const int rootB = root(B);

		if (rootA == rootB) {
			// すでにくっついてるからくっつけない
			return false;
		}

		//大きい方に小さいほうをくっ付ける(計算量のため)
		int big = rootA;
		int small = rootB;
		if (size(rootA) < size(rootB)) std::swap(big, small);

		// 最初は-1 + -1で-2になるだろう
		m_parent[big] += m_parent[small];
		m_parent[small] = big;

		return true;
	}
};

int main() {
	ull N, M;
	cin >> N >> M;
	vector<pair<ull, ull>> vec(M);
	for (auto&& p : vec) {
		ull a, b;
		cin >> a >> b;
		p = make_pair(a - 1, b - 1);
	}

	// 計算を行うが逆に行う
	// 最後の不便度は、常に2Cnなのでn*(n-1)/2である。
	vector<ull> ans(M);
	UnionFind uni(N);
	ans[M - 1] = N * (N - 1) / 2;

	for (size_t i = M - 1; i >= 1; i--) {
		ans[i - 1] = ans[i];
		if (uni.root(vec[i].first) != uni.root(vec[i].second)) {
			// 初めてつながる場合
			// 不便度は掛け算の文だけ減る。
			ans[i - 1] -= (ull)uni.size(vec[i].first) * (ull)uni.size(vec[i].second);
		}
		(void)uni.connect(vec[i].first, vec[i].second);
	}

	// 出力はそのままでよい
	for (const auto& a : ans) {
		cout << a << endl;
	}

	return 0;

}



Measured memory_bytes: 4096
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
ll evaluate(VV& S, ll d, V& prev, V& C, ll j) {
    ll temp = 0;
    temp += S[d][j];
    rep(k, 26) {
        if (j == k) {
            continue;
        }
        temp -= C[k] * (d - prev[k]);
    }
    return temp;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll d;
    cin >> d;
    V C(26);
    rep(i, 26) cin >> C[i];
    VV S(d, V(26));
    rep(i, d) { rep(j, 26) cin >> S[i][j]; }
    ll width = 100;
    vector<tuple<ll, V, V>> vec;
    V temp;
    rep(i, 26) temp.push_back(-1);
    V temp2;
    vec.push_back({0, temp, temp2});
    rep3(i, 0, d) {
        priority_queue<tuple<ll, V, V>> q;
        for (auto j : vec) {
            ll score = get<0>(j);
            V prev = get<1>(j);
            V history = get<2>(j);
            rep(k, 26) {
              bool f=false;
                for(int g=history.size()-1,h=0;h<15&&g>=0;h++,g--){
                    if(!history.empty()&&history[g]==k){
                      f=true;
                      break;
                    }
                }
                if(f)continue;
                ll value = evaluate(S, i, prev, C, k);
                ll prev2 = prev[k];
                
                prev[k] = i;
                history.push_back(k);
                q.push({score + value, prev, history});
                history.pop_back();
                prev[k] = prev2;
            }
        }
        vec.clear();
        for (ll j = 0; j < width && !q.empty(); j++) {
            vec.push_back(q.top());
            q.pop();
        }
    }
    for (auto i : get<2>(vec[0])) {
        cout << i + 1 << endl;
    }
}


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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int n;
  cin >> n;
  vector<P> even, odd;
  {
    map<int, int> _even, _odd;
    rep(i, n) {
      int v;
      cin >> v;
      if (i%2) _odd[v]++;
      else _even[v]++;
    }
    for(auto kv : _even) {
      even.emplace_back(kv.second, kv.first);
    }
    for(auto kv : _odd) {
      odd.emplace_back(kv.second, kv.first);
    }
  }
  even.emplace_back(0, 0);
  odd.emplace_back(0, 0);
  sort(even.begin(), even.end(), greater<P>());
  sort(odd.begin(), odd.end(), greater<P>());
  if (even[0].second != odd[0].second) {
    cout << n - even[0].first - odd[0].first << endl;
  } else {
    cout << n - max(even[0].first + odd[1].first, even[1].first + odd[0].first) << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 6140
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;


int main(){

  string str;
  cin >> str;
  int n = str.length();
  if (n <= 1) cout<< 0;
  else{
  int c1 = 0, c2 = 0;
    for(int i = 0; i < n; i++){
      if((int)str[i] - 48 != i%2) c1++;
      else c2++;
    }

    int ans = c1 < c2? c1 : c2;
    cout << ans;
  }
}


Measured memory_bytes: 512
def get_gcd(a, b):
  m = max(a, b)
  n = min(a, b)
  while(True):
    if n == 0:
      return m
    r = m % n
    m = n
    n = r

N = int(input())
A_list = list(map(int, input().split()))

a = A_list.pop()

while(len(A_list) > 0):
  b = A_list.pop()
  a = get_gcd(a, b)
  
print(a)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
int a[500009];
int b[500009];
int c[500009];

int main()
{
    int n,i,j;

    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        b[i] = a[i];
    }
    sort(b,b+n);
    for(i=0; i<n-1; i++)
    {
        c[b[i]] = b[n-1];
    }
    c[b[n-1]] = b[n-2];
    for(i=0; i<n; i++)
    {

            cout<<c[a[i]];
        cout<<endl;
    }

}


Measured memory_bytes: 4992
/* Life is all about calculated risks.
    But man am I bad at math. */

#include <bits/stdc++.h> 
#define ll long long int
#define INF (ll)1e12
#define MOD 1000000007

#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;

using namespace std;

ll f(ll stones);

ll n,k;
ll a[110];

vector<ll> dp(100100,-1);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k;
    for(ll i=1; i<=n; i++)
    {
        cin>>a[i];
    }

    if(f(k))
    {
        cout<<"First"<<endl;
    }
    else
    {
        cout<<"Second"<<endl;
    }

    return 0;
}

ll f(ll stones)
{
    if(dp[stones] != -1)
    {
        return dp[stones];
    }

    ll sum = 1;
    for(ll i=1; i<=n; i++)
    {
        if(a[i] <= stones)
        {
            sum = sum & f(stones - a[i]);
            continue;
        }
        break;
    }

    return dp[stones] = !sum;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

struct UnionFind {

	vi data;

	UnionFind(int n = 0) {
		data.assign(n, -1);
	}

	int find(int k) {
		if (data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int k) { return -data[find(k)]; }

};

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

	UnionFind uf(n);

	while (m--) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		uf.unite(a, b);
	}
	
	int ans = 0;
	rep(i, n)ans = max(ans, uf.size(i));
	cout << ans << endl;

}

Measured memory_bytes: 4044
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
int arr[N + 5][3];
int dp[N + 5][3];

int calc(int x,int y) {
	if(x == -1) return 0;
	int &res = dp[x][y];
	if(res != -1) return res;
	res = arr[x][y];
	for(int i = 0;i < 3;i++) {
		if(i == y) continue;
		res = max(res,arr[x][y] + calc(x - 1,i));
	}
	return res;
}

void hora(int tc) {
	int n;
	cin>>n;
	memset(dp,-1,sizeof dp);
	for(int i = 0;i < n;i++) for(int j = 0;j < 3;j++) cin>>arr[i][j];
	cout<<max(calc(n - 1,0), max(calc(n - 1,1), calc(n - 1,2)));
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 10368
#include<stdio.h>

int main(){
  int N,i,j,l,c,d,e;
  long b,m,p[100005][3];
  int elist[100][3],nel=0;
  scanf("%d",&N);
  scanf("%ld",&m);
  for(i=0;i<N;i++){
    scanf("%ld",&p[i][0]);
    p[i][1]=-1;
    p[i][2]=1;
  }
  l=1;
  while(l==1){
    l=0;
    for(i=0;i<N;i++){
      if(p[i][2]==1){
        c=i;
        for(j=i+1;j<N;j++){
          if(p[j][2]==1){
            l=1;
            i=j;
            d=j;
            e=-1;
            while(1){
              elist[nel][0]=c;
              elist[nel][1]=d;
              elist[nel][2]=e;
              nel++;
              if(e>=i){
                i=e;
              }
              if(c==-1){
                if(d==-1){
                  p[e][1]=-1;
                  nel++;
                  break;
                }
                p[e][1]=d;
                p[d][2]=0;
                e=d;
                d=p[e][1];
              }else if(d==-1){
                p[e][1]=c;
                p[c][2]=0;
                e=c;
                c=p[e][1];
              }else if(p[c][0]>p[d][0]){
                if(e!=-1){
                  p[e][1]=c;
                  p[c][2]=0;
                }
                e=c;
                c=p[e][1];
              }else{
                if(e!=-1){
                  p[e][1]=d;
                  p[d][2]=0;
                }
                e=d;
                d=p[e][1];
              }
            }
            break;
          }
        }
      }
    }
  }
  d=c;
  for(j=0;j<m;j++){
    b=p[c][0]>>1;
    l=p[c][1];
    while(1){
      e=p[d][1];
      if(e==-1){
        p[c][1]=-1;
        break;
      }
      if(p[e][0]<=b){
        p[c][1]=e;
        break;
      }
      d=e;
    }
    p[c][0]=b;
    if(e!=l){
      p[d][1]=c;
      d=c;
      c=l;
    }
  }
  m=0;
  for(i=0;i<N;i++){
    m+=p[i][0];
  }
  printf("%ld",m);
  return(0);
}

Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = int64_t;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10, 9) + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
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; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
//cout << setprecision(15) << std::fixed;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = n / (a + b);
    ll p = (n % (a + b));
    if (p > a) p = a;
    print((ans * a) + p);

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int x[20],y[20],vx[20],vy[20];
signed main(){
	int n,ans=INF;
	cin>>n;
	f(i,n)cin>>x[i];
	f(i,n)cin>>y[i];
	f(i,mypow(2,n,mod)){
		int z=i,sum=0,zz[20]={};
		bool use[20]={};
		vector<P> v={};
		f(j,n){
			vx[j]=x[j];
			vy[j]=y[j];
			zz[j]=j;
			use[j]=z%2;
			z/=2;
			if(use[j])v.push_back({y[j],j});
			else v.push_back({x[j],j});
		}
		sort(all(v));
		f(j,n){
			int vj;
			if(abs(j-v[j].S)%2!=use[v[j].S]){
				for(int k=j+1;v[k].F==v[j].F;k++){
					if(abs(j-v[k].S)%2==use[v[k].S]){
						for(int l=k;l>j;l--){
							swap(v[l].S,v[l-1].S);
						}
						break;
					}
				}
			}
			f(k,n){
				if(zz[k]==v[j].S){
					vj=k;
					break;
				}
			}
			if(abs(j-v[j].S)%2!=use[v[j].S]){
				/*f(k,n){
					cout<<(int)use[k]<<" ";
				}
				cout<<endl<<j<<" "<<vj<<" "<<v[j].S<<endl;*/
				goto loop;
			}
			else{
				if(j>vj){
					for(int k=vj;k<j;k++){
						swap(vx[k],vy[k+1]);
						swap(vy[k],vx[k+1]);
						swap(zz[k],zz[k+1]);
						sum++;
					}
				}
				else{
					for(int k=vj;k>j;k--){
						swap(vx[k],vy[k-1]);
						swap(vy[k],vx[k-1]);
						swap(zz[k],zz[k-1]);
						sum++;
					}
				}
			}
		}
		ans=min(ans,sum);
		loop:;
	}
	if(ans==INF)puts("-1");
	else cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

typedef pair<double,string> PDS;

bool my_greater(PDS a, PDS b){
  if(a.first==b.first){
    return (a.second > b.second);
  }else{
    return a.first < b.first;
  }
}

void solve(int n){
  vector<PDS> vp(n);

  string L;
  double P,A,B,C,D,E,F,S,M;
  for(int i=0;i<n;i++){
    cin>>L>>P>>A>>B>>C>>D>>E>>F>>S>>M;
    double res=(F*S*M-P)/(A+B+C+(D+E)*M);
    vp[i]=mp(res,L);
  }

  sort(all(vp),my_greater);
  reverse(all(vp));
  for(int i=0;i<n;i++){
    cout<<vp[i].second<<endl;
  }
}

int main(){
  int n;
  while(cin>>n,n){
    solve(n);
    cout<<"#"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3112
K,A,B=map(int,input().split())

if A+2>=B or K-1<A:
    print(1+K)
else:
    if (K-A+1)%2==0:
        print(A+((K-A+1)//2)*(B-A))
    else:
        print(A+((K-A+1)//2)*(B-A)+1)


Measured memory_bytes: 9080
/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2017-08-20	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
int len;
int f[200050],nExt[200050];
char str[200050];
set<int> ch[26];
void laboras()
{
	int st=len;
	set<int>::iterator it;
	for(int i=0;i<=len;i++) f[i]=2147483647;
	for(int i=len-1;0<=i;i--)
	{
		for(int j=0;j<26;j++)
		{
			it=ch[j].lower_bound(i+1);
			if(it==ch[j].end())
			{
				f[i]=2;
				nExt[i]=len;
			}
			else if(f[*it]+1<f[i])
			{
				f[i]=f[*it]+1;
				nExt[i]=*it;
			}
		}
	}
	for(int i=0;i<26;i++)
	{
		it=ch[i].lower_bound(0);
		if(it==ch[i].end())
		{
			putchar('a'+i);
			st=len;
			break;
		}
		if(f[*it]<f[st])
			st=*it;
	}
	while(st<len)
	{
		putchar(str[st]);
		if(nExt[st]==len)
		{
			for(int i=0;i<26;i++)
			{
				if(ch[i].lower_bound(st+1)==ch[i].end())
				{
					putchar('a'+i);
					break;
				}
			}
			break;
		}
		st=nExt[st];
	}
	return;
}
int main()
{
	scanf("%s",str);
	len=strlen(str);
	for(int i=0;i<len;i++)
		ch[str[i]-'a'].insert(i);
	laboras();
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 11392
k,s = map(int,input().split())
Xm = k
Ym = k
Zm = k #使わない
count = 0
for i in range(Xm+1):
  for j in range(Ym+1):
    if 0<= s - (i+j) <= k:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <stdio.h>

int main(){

	int a,b,c,temp;

	scanf("%d %d %d",&a,&b,&c);

	if(a > c){
		temp = a;
		a = c;
		c = temp;
	}
	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}
	if(b > c){
		temp = b;
		b = c;
		c = temp;
	}

	printf("%d %d %d\n",a,b,c);

	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;
using pi = pair<int, int>;
using vp = vector<pi>;

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

#define P (1'000'000'007)


// With size

class UnionFind {
public:
    int uncon; 
    UnionFind(int n) {
        for (int i = 0; i < n; i++) {
            _parent.push_back(i);
            _size.push_back(1);
        }

        uncon = n * (n - 1) / 2;
    }

    int find(int index) {
        if (is_root(index)) return index;
        return _parent[index] = find(_parent[index]);
    }

    bool is_root(int index) {
        return _parent[index] == index;
    }

    bool has_same_root(int lhs, int rhs) {
        return find(lhs) == find(rhs);
    }

    void unite(int lhs, int rhs) {
        int l = find(lhs);
        int r = find(rhs);
        if (has_same_root(l, r)) return;
        int ls = _size[l]; int rs = _size[r];
        uncon -= (rs + ls) * (rs + ls - 1) / 2 - rs * (rs - 1) / 2 - ls * (ls - 1) / 2;
        _size[l] += rs;
        _parent[r] = l;
    }

    int size(int index) {
        return _size[find(index)];
    }

private:
    vector<int> _parent;
    vector<int> _size;
};

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

    vp vb;

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        vb.push_back(make_pair(a, b));
    }

    reverse(all(vb));

    vi ans;
    UnionFind uf(n);

    for (auto p: vb) {
        ans.push_back(uf.uncon);
        uf.unite(p.first, p.second);
    }

    reverse(all(ans));

    for (auto x: ans) {
        cout << x << endl;
    }
    
    return 0;
}


Measured memory_bytes: 8108
from collections import defaultdict
import math
n = int(input())
a = list(map(int,input().split()))
max_a = 10**6 +1 
a = sorted(a)
dic = defaultdict(lambda: False)

count = 0 
for i in range(n):
    ai = a[i]
    if dic[ai] == True:
        count+=1
    else:
        for j in range(1,math.ceil(max_a/ai)):
            dic[j*ai] = True
        if (i+1) < n and a[i]==a[i+1]:
            count+=1
print(n-count)

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

int n;
int *A;
int *C, *B;

void bucketSort(int *A) {
    for (int i = 0; i < n; ++i) {
        C[A[i]]++;
    }
    for (int j = 1; j < 10000; ++j) {
        C[j] = C[j] + C[j-1];
    }


    for (int k = 0; k < n ; k++) {
        B[C[A[k]] - 1] = A[k];
        C[A[k]]--;
    }
}

int main() {
    cin >> n;
    A = new int[n];
    C = new int [10000];
    B = new int [n];

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

    bucketSort(A);

    for (int j = 0; j < n; ++j) {
        if (j) cout << " ";
        cout << B[j] ;
    }
    cout << endl;

    return 0;
}




Measured memory_bytes: 18768
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << (min(b,d) - max(a,c) < 0 ? 0 : min(b,d) - max(a,c)) << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<vector<ll>> matrix;//matrix A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
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;}
#define MOD 1000000007 //998244353


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

    // solution comes here

    ll H,W;
    cin >> H >> W;
    matrix ans(H, vl(W, 0));
    vs S(H+1);
    rep(i, H) cin >> S[i];

    rep(i, H) {
        ll cnt=1;
        rep(j, W) {
            if(S[i][j]=='#'){
                cnt=1;
                continue;
            }
            if(S[i][j]==S[i][j+1]) cnt++;
            else {
                for(ll x=0; x<cnt; x++){
                    ans[i][j-x] += cnt;
                }
                cnt=1;
            }
        }
    }

    ll res=0;
    rep(j, W) {
        ll cnt=1;
        rep(i, H) {
            if(S[i][j]=='#'){
                cnt=1;
                continue;
            }
            if(S[i][j]==S[i+1][j]) cnt++;
            else {
                for(ll x=0; x<cnt; x++){
                    ans[i-x][j] += cnt;
                    chmax(res, ans[i-x][j]);
                }
                cnt=1;
            }
        }
    }

    cout << res-1 << nl;
}

Measured memory_bytes: 35840
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7
;int num[maxn];
int main()
{    
	string stra; 
	string strb;   
	cin>>stra>>strb;  
	int len=stra.size();  
	memset(num,-1,sizeof(num)); 
	for(int i=0;i<len;i++)  
	{      
		if(num[stra[i]]==-1)   
		{    
			num[stra[i]]=strb[i];   
		}      
		else     
		{         
			if(num[stra[i]]!=strb[i])      
			{        
				cout<<"No"<<endl;      
				return 0;        
			}        
		}   
	}   
	memset(num,-1,sizeof(num)); 
	for(int i=0;i<len;i++)  
	{     
		if(num[strb[i]]==-1)    
		{     
			num[strb[i]]=stra[i];   
		}     
		else     
		{     
			if(num[strb[i]]!=stra[i])     
			{        
				cout<<"No"<<endl;    
				return 0;      
			}   
		}
	}   
	cout<<"Yes"<<endl;   
	return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]
dp = [-1]*(n+2)#dp[k]はk-1段目に到達する方法
dp[0] = 0
dp[1] = 1
mod = 10**9+7
for i in a:
    dp[i+1] = 0
for i in range(n+2):
    if dp[i] == -1:#already visited or prepared
        dp[i] = (dp[i-1]+dp[i-2])
#print(dp)
print(dp[n+1]%mod)

Measured memory_bytes: 460020
#[allow(unused_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)*}
    };
}
 
#[allow(unused_macros)]
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)*}
    };
}
 
#[allow(unused_macros)]
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")
    };
}
fn main() {
    input! {
        _n: usize,
        str: chars,
    }

    let mut count = 1;
    let mut bef = str[0];

    for ch in str.iter().skip(1) {
        if bef != *ch {
            count = count + 1;
            bef = *ch;
        }
    }

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long n;
	cin>>n;
	string ans="";
	while(n>0){
		n--;
		ans+=('a'+(n%26));
		n-=n%26;
		n/=26;
	}
	reverse(ans.begin(), ans.end());
	cout<<ans;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
using ipair = pair<int,int>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
const int MOD=1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){ 
    
    double d,s,t;cin>>d>>t>>s;
    if(d/s<=t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3716