akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskC {
        static long modpow(long a , int b){
            a%=1000000007;
            long ans = 1;
            while (b>0){
                if ((b&1)>0) ans=ans*a%1000000007;
                b>>=1;
                a=a*a%1000000007;
            }
            return ans;
        }
        static long sol(long a){
            if (a==1) return 1;
            long ans = sol(a/2);
            return ans+ans+1;
        }
        public void solve(int testNumber, InputReader in, PrintWriter out){
            int h =in.nextInt();
            int n = in.nextInt();
            int sum = 0;
            for (int i = 0; i <n; i++) {
                sum+=in.nextInt();
            }
            if (sum >= h) System.out.println("Yes");
            else System.out.println("No");






        }




    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt(){return  Integer.parseInt(next());}
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

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

using namespace std;
typedef long long ll;


int H,W;
vector<vector<char> > a;





int main()
{
    cin >> H >> W;
    a.assign(H,vector<char>(W, '.'));
    
    rep(i,H){
        rep(j,W) cin >> a[i][j];
    }
    
    rep(i,H){
        rep(j,W){
            if (a[i][j] == '.') {
                int h = 0;
                rep(k,H) if (a[k][j] != '#') h++;
                if(h==H) rep(k,H) a[k][j] = 'd';
                
                int w = 0;
                rep(k,W) if (a[i][k] != '#') w++;
                if(w==W) rep(k,W) a[i][k] = 'd';
                
            }
        }
    }
    /*
    cout << endl;
    rep(i,H){
        rep(j,W){
            cout << a[i][j];
        }
        cout << endl;
    }
    cout << endl;
    */
    rep(i,H){
        int aa = 0;
        rep(j,W){
            if (a[i][j] != 'd') {
                cout << a[i][j];
                aa += 1;
            }
        }
        if(aa >= 1) cout << endl;
        
    }
    
    
    
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <cstring>
#include <iomanip>
#include <bits/stdc++.h>

using namespace std;

long long knapSack(int W, long long wt[], long long val[], int n) 
{ 
    int i, w; 
    long long K[n + 1][W + 1]; 
  
    // Build table K[][] in bottom up manner 
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
                K[i][w] = max( 
                    val[i - 1] + K[i - 1][w - wt[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        } 
    } 
  
    return K[n][W]; 
}

int main(){
	int n{};
	int W{};
	cin>>n>>W;
	long long wt[n]{};
	long long val[n]{};
	for(int i{}; i<n; i++){
		cin>>wt[i]>>val[i];
	}
	long long ans{};
	ans=knapSack(W,wt,val,n);
	cout<<ans<<endl;
}

Measured memory_bytes: 82504
s = input()
n = len(s)

t = 'gp' * (n//2)
if n% 2== 1:
    t += 'g'

ans = 0
for i in range(n):
    if s[i] == 'g' and t[i] == 'p':
        ans += 1
    elif s[i] == 'p' and t[i] == 'g':
        ans -= 1
print(ans)

Measured memory_bytes: 66744
#include <stdio.h>

int main(void)
{
  int n, r;

  scanf("%d %d", &n, &r);

  int a, b, c;
  int flag=0;
  for (int x=0; x <= 2000; x++) {
    for (int y=0; y <= 2000; y++) {
      int snt = r - (10000*x + 5000*y);
      int mai = n-(x+y);
      snt /= 1000;
      if ( snt == mai && mai >= 0) {
        a=x;
        b=y;
        c=n-(x+y);
        flag=1;
      }
      }
  }

  if (flag == 0) {
    a = -1;
    b = -1;
    c = -1;
  }
  printf("%d %d %d\n", a,b,c);
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N=int(input())
pts = []
for _ in range(N):
    x,y=map(int,input().split())
    pts.append((x,y))

iNE=None
maxNE=-1e12
iNW=None
maxNW=-1e12
iSE=None
maxSE=-1e12
iSW=None
maxSW=-1e12

for i in range(N):
    p = pts[i]
    NE = p[0] + p[1]
    NW = -p[0] + p[1]
    SE = p[0] - p[1]
    SW = -p[0] - p[1]
    if NE > maxNE:
        maxNE = NE
        iNE = i
    if SE > maxSE:
        maxSE = SE
        iSE = i
    if NW > maxNW:
        maxNW = NW
        iNW = i
    if SW > maxSW:
        maxSW = SW
        iSW = i

d1 = abs(pts[iNE][0]-pts[iSW][0])+abs(pts[iNE][1]-pts[iSW][1])
d2 = abs(pts[iNW][0]-pts[iSE][0])+abs(pts[iNW][1]-pts[iSE][1])

print(max(d1,d2))


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

std::string S;
int K;

int main() {
  std::cin >> K;
  std::cin >> S;

  if (S.size() <= K) {
    std::cout << S << std::endl;
  }
  else {
    std::cout << S.substr(0, K) << "..." << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3632
import math
from collections import defaultdict
N,P = [int(x) for x in input().split()]
#%%
def trial_division(n):
    #素因数を格納するリスト
    factor = defaultdict(int)
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor[num]+=1
    #リストが空ならそれは素数
    if not factor:
        return {n:1}
    else:
        factor[n] += 1
        return factor

divs_of_p = trial_division(P)
ans = 1
for key in divs_of_p:
    if(divs_of_p[key]>=N):
        ans *= key**(divs_of_p[key]//N)
print(ans)


Measured memory_bytes: 3316
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        long n = sc.nextLong();

        long ans = Long.MAX_VALUE;
        for (long i = 1; i*i <= n; i++) {
            if (n % i == 0) {
                ans = Math.min(i-1 + n/i-1, ans);
            }
        }
        System.out.println(ans);
    }
}



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

int main() {
  while (true) {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0)
      break;
    else {
      if (x < y)
        cout << x << " " << y << endl;
      else
        cout << y << " " << x << endl;
    }
  }
  return 0;
}



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

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

        static long Solve(string S)
        {
            int N = S.Length;
            long[] sums = new long[N + 1];
            sums[N] = 0;
            for (int i = N - 1; i >= 0; --i)
            {
                long sum = 0;
                for (int j = 0; i + j < N; ++j)
                {
                    int k = Math.Max(N - i - j - 2, 0);
                    sum += long.Parse(S.Substring(i, j + 1)) * (1L << k) + sums[N - j];
                }
                sums[i] = sum;
            }
            return sums[0];
        }
        static void Main(string[] args)
        {
            string S = Read();
            Console.WriteLine(Solve(S));
        }
    }
}


Measured memory_bytes: 11220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		int tasu = a + b;
		int hiku = a - b;
		int kakeru = a * b;

		System.out.println(Math.max(tasu, Math.max(hiku, kakeru)));
	}

}


Measured memory_bytes: 22100
fun main(args:Array<String>){
    val line1 = readLine()!!.trim().split(' ').map(String::toInt)
    val line2 = readLine()!!.trim().split(' ').map(String::toInt)
    val n = line1[0]
    val x = line1[1]
    val list = line2.sorted()
    var sum = 0
    var counter = 0
    for(ai in list){
        sum += ai
        if(sum>x)break
        counter++
    }
    if(sum<x)counter--
    println(counter)
    return
}

Measured memory_bytes: 38336
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  int W,N,cnt = 0;
  while(cin>>W,W){
    cin>>N;
    vector<int> w(N);
    vector<int> v(N);
    long long dp[1001][1001];
    memset(dp,0,sizeof(dp));
    
    rep(i,N)scanf("%d,%d",&v[i],&w[i]);

    for(int i = N-1 ; i >= 0 ; i --){
      rep(j,W+1){
	if(j < w[i]) dp[i][j] = dp[i+1][j];
	else dp[i][j] = max(dp[i+1][j] , dp[i+1][j - w[i]]+v[i]);
      }                     
    }

    cout<<"Case "<<++cnt<<":"<<endl;
    cout<<dp[0][W]<<endl;
    for(int i = W ; ; i--){
      if(dp[0][i] != dp[0][W]){
	cout<<i+1<<endl;
	break;
      }
    }
  }

  return 0;
}

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

struct node {
    node():p(-1),s(-1),l(-1),r(-1),d(-1),h(-1){}
    int p, s, l, r, d, h;
};

int setdh(node t[], int id, int d) {
    if(id==-1) return 0;
    t[id].d=d;
    t[id].h=max(setdh(t, t[id].l, d+1), setdh(t, t[id].r, d+1));
    return t[id].h+1;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    node t[25];
    cin>>n;
    for(int i=0; i<n; i++) {
        int id, l, r;
        cin>>id>>l>>r;
        t[id].l=l;
        t[id].r=r;
        if(l!=-1) t[l].p=id;
        if(r!=-1) t[r].p=id;
        if(l!=-1&&r!=-1) {
            t[l].s=r;
            t[r].s=l;
        }
    }
    int root;
    for(root=0; root<n&&t[root].p!=-1; root++);
    setdh(t, root, 0);
    for(int i=0; i<n; i++) {
        int deg = 0;
        if(t[i].l!=-1) deg++;
        if(t[i].r!=-1) deg++;
        const char *type;
        if(t[i].p==-1) type=", root\n";
        else if(deg==0) type=", leaf\n";
        else type=", internal node\n";
        cout<<"node "<<i<<": parent = "<<t[i].p<<", sibling = "<<t[i].s<<", degree = "<<deg<<", depth = "<<t[i].d<<", height = "<<t[i].h<<type;
    }
    return 0;
}

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

int main()
{
    int a,b,k,i,j;
    vector<int>V;
    cin>>a>>b>>k;
    for(i=min(a,b);i>0;i--){
        if(a%i==0 && b%i==0){
            V.push_back(i);
        }
    }
    cout<<V[k-1]<<endl;
    return 0;
}


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

int main()
{
ll n ;
cin >> n ;
if(n%2){
  cout << 0 << endl;
  return 0;
}
n/=2;
ll a=5;
while(a<=n){
  ans+=n/a;
  a*=5;
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define POWER(num)		(num) * (num)

int main(void)
{
	int input[3];
	int i, j, swap;
	int no;
	
	scanf("%d", &no);
	for (i = 0; i < no; i++){
		scanf("%d %d %d", &input[0], &input[1], &input[2]);
		for (j = 1; j < 3; j++){
			if (input[0] < input[j]){
				swap = input[0];
				input[0] = input[j];
				input[j] = swap;
			}
		}
		if (POWER(input[0]) == POWER(input[1]) + POWER(input[2])){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
import sys

from collections import deque
# q = deque(); q.append(x); q.appendleft(x); q.pop() -> x; q.popleft() -> x
from collections import defaultdict
# d = defaultdict(lambda: []); d[key] -> []
import heapq
# hq = []; heapq.heappush(hq, x); heapq.heappop(hq) -> x; heapq.heappushpop(hq, x) -> x
import bisect
# i = bisect.bisect_left([1,2,3,4], 1.5); i = bisect.bisect_right([4,3,2,1], 1.5)

#import numpy as np
#from scipy.misc import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    X = i2nn()
    if N >= M:
        print(0)
        return
    X.sort()
    D = [X[i]-X[i-1] for i in range(1, M)]
    D.sort()
    n = sum(D[:M-N])
    print(n)

main()


Measured memory_bytes: 56232
#include <bits/stdc++.h>
    #define ll long long
    #define sz(a) int((a).size())
    #define fr(i,n) for(int i=0;i<n;i++) 
    #define rf(i,n) for(int i=1;i<=n;i++)
    #define jdb(i,v) for(__typeof(v.begin())i=v.begin(); i!=v.end();i++)
    #define present(c,a) (find(all(c),a) != c.end())
    #define spresent(c,a) (c.find(a)!=c.end())
    #define no(s,c) s.count(c)  
    #define pb push_back 
    #define eb emplace_back
    #define mp make_pair
    #define all(c) (c).begin(),(c).end()
    #define MAX INT_MAX 
    using namespace std;
    #define f first
    #define s second
    int backtrack(int,int);
    int M = 1000000007;
    int v[100001];
    int dp[100001];
    int n,k;
    int main() 
    { 
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cin>>n>>k;
        fr(i,n)
        cin>>v[i];
        cout<<backtrack(2,0)<<endl;
        return 0; 
    }

    int backtrack(int j,int sum)
    {
        dp[0]=0;
        dp[1]=abs(v[1]-v[0]);
        while(j<n)
        {
            int sum=INT_MAX;
            rf(i,k)
                {
                    if(j>=i)
                    sum = min(sum,dp[j-i]+abs(v[j]-v[j-i]));
                    else
                        break;
                }    
                dp[j]=sum;
            j++;
        }
        return dp[n-1];
    }

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

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    vector<ll> B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];

    ll sum = 0;
    int bidx = 0;
    while (bidx < M){
        if(sum + B[bidx] > K) break;
        sum += B[bidx++];
    }
    int ans = bidx;
    bidx--;
    rep(i, N){
        sum += A[i];
        while (sum > K && bidx >= 0) sum -= B[bidx--];
        if(sum > K) break;
        ans = max(ans, i+2+bidx);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6360
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

struct mint{ // auto MOD int
  ll x;
  mint(ll x=0) : x((x%MOD+MOD)%MOD){}  //コンストラクタ
  mint operator-() const { return mint(-x); } //符号変換
  mint operator+(const mint &a) const { return mint(*this) += a; } //算術演算子
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  mint pow(ll n) const {  //繰り返し累乗
    if(!n) return 1;
    mint a = pow(n>>1);
    a *= a;
    if(n&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD-2); } // for prime mod
  mint& operator+=(const mint a){ if((x+=a.x) >= MOD) x-=MOD;  return *this; } //代入演算子
  mint& operator-=(const mint a){ if((x+=MOD-a.x) >= MOD) x-=MOD;  return *this; }
  mint& operator*=(const mint a){ (x *= a.x) %= MOD;  return *this; }
  mint& operator/=(const mint a){ return (*this) *= a.inv(); }
  friend ostream& operator<<(ostream &stout, const mint &tmp){ stout << tmp.x; return stout; }
};

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> a(n); rep(i,n) cin >> a[i];
  mint ans = 0;
  rep(k,60){
    ll x = 0;
    rep(i,n) if(a[i]>>k & 1) ++x;
    mint now = x*(n-x);
    ans += now*mint(2).pow(k);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 5484
n=int(input())
l=list(map(int,input().split()))
s=0
for i,a in enumerate(l):
    for j,b in enumerate(l[i+1:]):
        for c in l[i+j+1:]:
            if a==b or b==c or c==a:
                continue
            if a+b>c and b+c>a and c+a>b:
                s+=1
print(s)


Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
using Graph = vector<vector<ll>>;
Graph G;
ll n,q;
void dfs(ll v,ll p,vector<ll> &res){
    if(p!=-1) res[v]+=res[p];
    for(auto nv:G[v]){
        if(nv==p) continue;
        dfs(nv,v,res);
    }
    return;
}



int main(){
    cin >> n >> q;
    G.assign(n, vector<ll>());
    for(ll i=0;i<n-1;i++){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> c(n,0);
    for(ll i=0;i<q;i++){
        ll p,x;
        cin >> p >> x;
        p--;
        c[p]+=x;
    }
    dfs(0,-1,c);
    for(ll i=0;i<n;i++){
        cout << c[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 25172
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] input = Arrays.stream(scanner.nextLine().split("")).mapToInt(Integer::parseInt).toArray();

        int opLength = input.length - 1;
        int opEnd = opLength - 1;

        for (int bit = 0; bit < (1<<opLength); bit++) {
            StringBuffer sb = new StringBuffer(2 *input.length - 1);
            sb.append(input[0]);
            long sum = input[0];

            for (int i = 0; i < opLength ; i++) {
                if ((bit & (1<<(opLength - 1 - i))) > 0) {
                    sum += input[i + 1];
                    sb.append("+");
                    sb.append(input[i + 1]);
                } else {
                    sum -= input[i + 1];
                    sb.append("-");
                    sb.append(input[i + 1]);
                }
            }

            if (sum == 7) {
                sb.append("=7");
                System.out.println(sb.toString());
                break;
            }
        }
    }
}


Measured memory_bytes: 28880
#include <stdio.h>
#include <string.h>
#include <algorithm>

#define INF 123456789

int N, Ma, Mb, a[41], b[41], c[41];
int dp[2][4123][4123], ans = INF;

int main()
{
	scanf("%d%d%d", &N, &Ma, &Mb);
	for (int i = 0; i < N; ++i) { scanf("%d%d%d", &a[i], &b[i], &c[i]); }

	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j <= 40 * 100; ++j)
		{
			for (int k = 0; k <= 40 * 100; ++k)
			{
				dp[i][j][k] = INF;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int i = 0; i < 40; ++i)
	{
		for (int j = 0; j <= 40 * 100; ++j)
		{
			for (int k = 0; k <= 40 * 100; ++k)
			{
				if (dp[i % 2][j][k] == INF) continue;
				dp[(i + 1) % 2][j][k] = std::min(dp[(i + 1) % 2][j][k], dp[i % 2][j][k]);
				dp[(i + 1) % 2][j + a[i]][k + b[i]] = std::min(dp[(i + 1) % 2][j + a[i]][k + b[i]], dp[i % 2][j][k] + c[i]);
			}
		}
	}
	for (int j = 1; j <= 40 * 100; ++j)
	{
		for (int k = 1; k <= 40 * 100; ++k)
		{
			if (j * Mb == k * Ma)
			{
				ans = std::min(ans, dp[N % 2][j][k]);
			}
		}
	}
	ans = (ans == INF ? -1 : ans);

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

Measured memory_bytes: 131200
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let x_max = 1e5 as usize;
    let mut uf = UnionFind::new(x_max * 2);
    let n: usize = sc.read();
    for _ in 0..n {
        let x = sc.read::<usize>() - 1;
        let y = sc.read::<usize>() - 1;
        uf.unite(x, y + x_max);
    }

    let mut x_count = vec![0; x_max * 2];
    let mut y_count = vec![0; x_max * 2];
    for i in 0..x_max {
        let x = i;
        let y = i + x_max;

        x_count[uf.find(x)] += 1;
        y_count[uf.find(y)] += 1;
    }

    let mut sum = 0;
    for root in 0..(2 * x_max) {
        let x_count = x_count[root];
        let y_count = y_count[root];
        sum += x_count * y_count;
    }

    println!("{}", sum - n);
}

pub struct UnionFind {
    parent: Vec<usize>,
    sizes: Vec<usize>,
    size: usize,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).map(|i| i).collect::<Vec<usize>>(),
            sizes: vec![1; n],
            size: n,
        }
    }

    pub fn find(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        } else {
            let px = self.parent[x];
            self.parent[x] = self.find(px);
            self.parent[x]
        }
    }

    pub fn unite(&mut self, x: usize, y: usize) -> bool {
        let parent_x = self.find(x);
        let parent_y = self.find(y);
        if parent_x == parent_y {
            return false;
        }

        let (large, small) = if self.sizes[parent_x] < self.sizes[parent_y] {
            (parent_y, parent_x)
        } else {
            (parent_x, parent_y)
        };

        self.parent[small] = large;
        self.sizes[large] += self.sizes[small];
        self.sizes[small] = 0;
        self.size -= 1;
        return true;
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12540
/*
 * main.c
 *
 *  Created on: 2016/07/23
 *      Author: たけぱん
 */


#include <stdio.h>

int main(void){
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if(a==5&&b==5&&c==7){
		printf("YES\n");
	}else if(a==5&&b==7&&c==5){
		printf("YES\n");
	}else if(a==7&&b==5&&c==5){
		printf("YES\n");
	}else  {
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
// https://atcoder.jp/users/machikane
// https://atcoder.jp/contests/abc076/tasks/abc076_c
// C - Dubious Document 2
// sのうち長さ|t|の部分文字列を見る
// その部分文字列の?を置換してtにできるならばOK
// sのうちその部分文字列をtに置換して，さらに?をaに置換したものを解候補に追加
// aに置換するのは 条件と関係ない?はaに置換するとより辞書順が小さくなるからである
// 解候補をソートして辞書順最小のものを選ぶ

#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int INF = 1234567890;
constexpr int MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
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;
}
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    string s, t;
    vector<string> acceptables;
    cin >> s >> t;
    // 正規表現で探索するため .に置換
    replace(s.begin(), s.end(), '?', '.');

    // sから連続に|t|文字切り出した文字列を見る
    for (int start = 0; start < s.size() - t.size()+1; start++)
    {
        // 切り出した文字列
        string s_sub = s.substr(start, t.size());
        regex s_sub_regex = regex(s_sub);
        // 切り出した文字列とtが一致するか確認 ?(.)はなんでもOK
        if (regex_match(t, s_sub_regex))
        {
            // sの切り出した部分をtに置き換える
            string s_replaced = s;
            s_replaced.replace(start, t.size(), t);
            // 残りの?をaに置き換える
            replace(s_replaced.begin(), s_replaced.end(), '.', 'a');
            // 答え候補に追加
            acceptables.push_back(s_replaced);
        }
        cerr << s_sub << endl;
    }

    sort(acceptables.begin(), acceptables.end());

    cout << (!acceptables.empty() ? acceptables[0] : "UNRESTORABLE") << endl;
}


Measured memory_bytes: 256
#include<cstdio>

long long r[90];
int n;

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

    r[0] = 2;
    r[1] = 1;
    for (int i = 2; i <= n; i++) {
        r[i] = r[i - 1] + r[i - 2];
    }

    printf("%lld", r[n]);
}

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

typedef long long ll;
const ll maxn = 1e18;

int main() {
	/* freopen("input.in", "r", stdin);
	freopen("output.o", "w", stdout); */
	ll h, w;
	scanf("%lld %lld", &h, &w);
	ll a1, a2, a3;
	ll ans = maxn;
	ll totarea = h * w;
	for (ll i = 1; i <= h; i++) {
		a1 = i * w;
		ll tmp = totarea - a1;
		if (tmp % 2 == 0) {
			a2 = tmp / 2;
			a3 = tmp / 2;
		} else {
			ll diff = min(h-i, w);
			a2 = (tmp - diff) / 2;
			a3 = a2 + diff;
		}
		ll minn = min(min(a1, a2), a3);
		ll maxx = max(max(a1, a2), a3);
		ans = min(ans, maxx - minn);
	}
	ll pls;
	pls = h;
	h = w;
	w = pls;
	for (ll i = 1; i <= h; i++) {
		a1 = i * w;
		ll tmp = totarea - a1;
		if (tmp % 2 == 0) {
			a2 = tmp / 2;
			a3 = tmp / 2;
		} else {
			ll diff = min(h-i, w);
			a2 = (tmp - diff) / 2;
			a3 = a2 + diff;
		}
		ll minn = min(min(a1, a2), a3);
		ll maxx = max(max(a1, a2), a3);
		ans = min(ans, maxx - minn);
	}
	printf("%lld", ans);
}


Measured memory_bytes: 256
n = int(input())
p = []
for i in range(n):
    a = input()
    p.append(a)
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    if p[i] == 'AC':
        ac += 1
    elif p[i] == 'WA':
        wa += 1
    elif p[i] == 'TLE':
        tle += 1
    else:
        re += 1
ans = 'AC x'
print(ans,str(ac), sep = ' ',)
ans = 'WA x'
print(ans,str(wa), sep = ' ')
ans = 'TLE x'
print(ans,str(tle), sep = ' ')
ans = 'RE x'
print(ans,str(re), sep = ' ')

Measured memory_bytes: 16320
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから

void solve(){
  int r;
  cin>>r;
  cout<<3*r*r;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int x, y;
  cin >> x >> y;
  for (int i = 0; i <= x; i++) {
    int j = x - i;
    if (2 * i + 4 * j == y) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 3652
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];

	std::map<int,int> map;
	rep(i,n) map[a[i]]++;

	if(map.size()>2) {
		print("No");
		return 0;
	}
	if(map.size()==2) {
		auto x = *map.begin();
		auto y = *map.rbegin();
		if(x.first>=x.second && x.first+1<=x.second+y.second/2 && x.first+1==y.first && x.first+1<n) {
			print("Yes");
		} else {
			print("No");
		}
		return 0;
	}
	auto x = *map.begin();
	if(x.first+1==n || x.first*2<=n) {
		print("Yes");
	} else {
		print("No");
	}

	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
	if(m1 != m2)
		cout << "1";
	else 
		cout << "0";
    cout << '\n';
	
    return 0;
}






Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String[] args) 
    {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int r = s.nextInt();
        if(n<=10)
        {
            System.out.println(r+100*(10-n));
        }
        else
            System.out.println(r);
    }
}

Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main{

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int taroScore = 0, hanakoScore = 0;
        int n = Integer.parseInt(br.readLine());
        while (n-- > 0) {
            String[] st = br.readLine().split(" ");
            String taro = st[0];
            String hanako = st[1];
            Integer comp = taro.compareTo(hanako);
            if (comp > 0) {
                taroScore += 3;
            } else if (comp < 0) {
                hanakoScore += 3;
            } else {
                taroScore++;
                hanakoScore++;
            }
        }
        bw.append(taroScore + " " + hanakoScore + "\n");
        bw.flush();
    }
}


Measured memory_bytes: 25272
def solve(s):
    l=len(s)
    S=[0]*(l+1)
    S[1]=1
    for i in range(1,l):
        if s[i]!=s[i-1]:
            S[i+1]=S[i]+1
        else:
            if i==1:
                S[i+1]=S[i]
            else:
                S[i+1]=S[i-2]+2
    return S[-1]

s=input()
print(solve(s))

Measured memory_bytes: 41712
// Problem : C - Good Sequence
// Contest : AtCoder Regular Contest 087
// URL : https://atcoder.jp/contests/arc087/tasks/arc087_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define size(x) (int)x.size()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n, ans = 0;
map<int, int> cnt;

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1, x; i <= n; i++) {
		cin >> x;
		cnt[x]++;
	}
	for (auto x : cnt) {
		int v = x.first, c = x.second;
		if (c >= v) {
			ans += min(c, c - v);
		} else {
			ans += c;
		}
	}
	cout << ans;
}


Measured memory_bytes: 4736
#include "stdio.h"

int main(void)
{
    char coffee[6];
    scanf("%s",coffee);
    if(coffee[2] == coffee[3])
    {
        if(coffee[4] == coffee[5])
        {
            printf("Yes");
        }

        else
        {
            printf("No");
        }
    }

    else
    printf("No");

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 int A[200005],B[100005],dp[100005][1],i,n,sum,say,k,m1,m2;

int main()
{
	
	
	
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&A[i] );
		if(A[i]<=m2 ){
		continue;	
		}
		else if(A[i]>m2 && A[i]<m1){
		m2=A[i];	
		}
		else{
		m2=m1; m1=A[i];	
		}
		
	}
	for(i=1;i<=n;i++){
		
		if(A[i]==m1 ){
		printf("%d\n",m2);
		}
		
		else{
		printf("%d\n",m1);
		}
		
	}



	
	return 0;
}

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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 単項演算子
	constexpr ModInt& operator++()
	{
		if (integer_ + 1 == mod_) integer_ = 0;
		else integer_++;
		return *this;
	}

	constexpr ModInt& operator--()
	{
		if (integer_ == 0) integer_ = mod_ - 1;
		else integer_--;
		return *this;
	}

	constexpr ModInt operator+()
	{
		return *this;
	}

	constexpr ModInt operator-()
	{
		if (integer_ == 0) return ModInt(0ll);
		else return ModInt(mod_ - integer_);
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}

	static constexpr int64_t mod{mod_};
};
using Mint = ModInt<>;

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int64_t> C(N);
	for (auto& e: C) scanf("%lld", &e);
	std::sort(C.rbegin(), C.rend());
	std::vector<Mint> two_pow(N + 1);
	two_pow[0] = Mint(1);
	for (int i{1}; i <= N; i++)
		two_pow[i] = Mint(2) * two_pow[i - 1];
	Mint ans{};
	for (int i{}; i < N; i++)
		ans += two_pow[N - i - 1] * Mint(C[i] % Mint::mod) * (Mint(i) * two_pow[std::max(0, i - 1)] + two_pow[i]);
	ans *= two_pow[N];
	std::cout << ans << std::endl;

	return 0;
}

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


int main(void){
    // Your code here!

    int n,m,x;
    
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> A(n, vector<int> (m));
    
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++){
            cin>>A[i][j];
        }
    }
    
    int minv = 10e8;
    
    for(int i=0; i<(1<<n); i++){
            vector<int> al(m,0);
            int sum=0;
            for(int j=0;j<n;j++){
                if((i>>j) & 1) {
                    for(int k=0;k<m;k++) {
                        al[k] += A[j][k];
                    }
                    sum += c[j];
                }
            }
            int ct=0;
            for(int k=0;k<m;k++) {
                if(al[k]>=x) ct++;
            }
            if(ct==m) minv = min(sum, minv);
    }
    
    if(minv!=10e8) cout<<minv<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define __ ios_base::sync_with_stdio(false); cin.tie(NULL);

void scan(ll &n) { scanf("%lld",&n) ; }
void scan(ll &n, ll &m) { scanf("%lld%lld",&n,&m) ; }
void scan(vector<ll> &v) { ll n = v.size() ; for(ll i=0 ;i<n;i++) scanf("%lld",&v[i]) ; }


void solve() {

    ll n , i ;
    ll mx = 0  , ans = 0 ;

    cin>> n ;
    for (i =0  ;i< n; i++) {
        ll x  ;
        cin >> x ;
        mx = max(x,mx) ;
        ans += ( mx - x) ;
    }
    cout << ans << endl ;
}

int main() {

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

	ll t = 1 ;
	//cin >> t ;
	for (ll cz = 1 ;cz <= t ; cz++) {
       // cout << "Case " <<cz <<": " ;
        solve() ;
	}
    return 0 ;
}







Measured memory_bytes: 3612
import sys
n,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
fib = [1,1]
for i in range(n):
    fib.append((fib[i]+fib[i+1])%1000000007)
if m == 0:
    print(fib[n]%1000000007)
    sys.exit()
answer = fib[a[0]-1]
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        answer = 0
    else:
        answer = answer * fib[a[i+1]-a[i]-2] % 1000000007
answer = answer * fib[n-a[m-1]-1] % 1000000007
print(answer)


Measured memory_bytes: 55768
import java.io.*;

class Main{	
	public static void main(String[] args){
		int a, b;
		String buf;
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			String[] ab = br.readLine().split(" ");
			a = Integer.parseInt(ab[0]);
			b = Integer.parseInt(ab[1]);
			
			if(a > b){
				System.out.println("a > b");
			} else if ( a < b ){
				System.out.println("a < b");
			} else if ( a == b ){
				System.out.println("a == b");
			}
		} catch(Exception e){
		}
	}
}

Measured memory_bytes: 24384
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

//union find
struct UnionFind {
    vector<ll> parent;
    vector<ll> usize;
 
    UnionFind(int n) : parent(n), usize(n, 1LL){
        rep(i, n)parent[i]=i;
    }
    
    int root(int x){
        if(parent[x] == x) return x;
        else return parent[x] = root(parent[x]);
    }
    
    bool issame(int x, int y){
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
 
        if(x == y)return false;
 
        if(parent[x] > parent[y]) swap(x, y);

        usize[x] += usize[y];
        parent[y] = x;
 
        return true;
    }
    
    int size(int x) {
        return usize[root(x)];
    }
};
 
int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);

    ll Friend[100010] = {};

    rep(i, m){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        uf.merge(a, b);
        Friend[a]++;
        Friend[b]++;
    }

    vector<vector<ll>> Block(n);
    rep(i, k){
        ll c, d;
        cin >> c >> d;
        c--, d--;
        Block[c].push_back(d);
        Block[d].push_back(c);
    }

    rep(i, n){
        ll num_block = 0;
        rep(j, Block[i].size()){
            if(uf.issame(i, Block[i][j]))num_block++;
        }

        cout << uf.size(i) - 1 - Friend[i] - num_block << " ";
    }
    // rep(i, n)cout << uf.size(i)-1 - Friend[i] - Block[i] << " ";
}

Measured memory_bytes: 9088
#include<stdio.h>
int swap(int*a,int*b){int t=*a;*a=*b;*b=t;return 1;}
int main(void)
{
  int n,a[100],i,j,c;
  for(;;){
    scanf("%d",&n);if(!n)break;c=0;
    for(i=0;i<n;i++)scanf("%d",a+i);
    for(i=n-1;i;i--)for(j=0;j<i;j++)if(a[j]>a[j+1])c+=swap(a+j,a+j+1);
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<P> pp = new ArrayList<>();
        int k = 0;
        for (int i = 0;i < n;++i){
            int[] ps = {sc.nextInt(),sc.nextInt(),sc.nextInt()};
            Arrays.sort(ps);
            P p = new P(ps[0],ps[1],ps[2]);
            if(pp.contains(p)){
                ++k;
            }
            else pp.add(p);
        }
        System.out.println(k);
    }

    static class P{
        int p1,p2,p3;

        public P(int p1,int p2,int p3){
            this.p1 = p1;this.p2 = p2;this.p3 = p3;
        }

        @Override
        public boolean equals(Object obj) {
            P p = (P)obj;
            if(p.p1 == this.p1&&p.p2 == this.p2&&p.p3 == this.p3)return true;
            return false;
        }
    }

}



Measured memory_bytes: 35396
#include<bits/stdc++.h>
using namespace std;
const int maxn = 101;
char res[maxn];
int n;
vector < int > p;
vector < int > red, blue;
string inp = "RRBBRB";
 
bool ask(int i){
    /*int r = 0;
    for(int j = i ; j < i + n ; ++j)
        if(inp[j - 1] == 'R') r++;
        else r--;
    return r > 0;*/
    cout << "? ";
    for(int j = i ; j < i + n ; ++j)
        cout << j << ' ';
    cout << '\n';
    cout << flush;
    string s;
    cin >> s;
    return s[0] == 'R';
}
 
bool ask2(int i, int x){
    //return inp[x - 1] == 'R';
    cout << "? ";
    for(int j = i ; j < i + n - 1; ++ j)
        cout << j << ' ';
    cout << x << '\n';
    cout << flush;
    string s;
    cin >> s;
    return s[0] == 'R';
}
 
bool ask3(int i){
    //return inp[i - 1] == 'R';
    cout << "? ";
    for(int i = 0 ; i < n / 2 ; ++i)
        cout << red[i] << ' ' << blue[i] << ' ';
    cout << i << '\n';
    cout << flush;
    string s;
    cin >> s;
    return s[0] == 'R';
}
 
void print(){
    cout << "! ";
    for(int i = 1 ; i <= 2 * n ; ++i)
        cout << res[i];
    cout << '\n';
    cout << flush;
}
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    srand(time(NULL));
    cin >> n;
    bool rep = ask(1);
    int lo = 2 , hi = n;
    int good = 1;
    while(lo <= hi){
        int mid = (lo + hi) >> 1;
        if(ask(mid) == rep){
            good = mid ;
            lo = mid + 1;
        }
        else hi = mid - 1;
    }
    res[good] = 'R'; res[good + n] = 'B';
    if(!rep) swap(res[good], res[good + n]);
    for(int i = 1 ; i < good ; ++i){
        if(ask2(good + 1, i)) res[i] = 'R', red.push_back(i);
        else res[i] = 'B', blue.push_back(i);
    }
    for(int i = good + n + 1; i <= 2 * n ; ++i){
        if(ask2(good + 1, i)) res[i] = 'R', red.push_back(i);
        else res[i] = 'B', blue.push_back(i);
    }
    for(int i = good + 1 ; i < good + n ; ++i){
        if(ask3(i)) res[i] = 'R';
        else res[i] = 'B';
    }
    print();
    return 0;
}

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

int main(){
  int N, L;
  cin >> N >> L;
  
  int ans = 0;
  for(int i=0; i<N; i++){
    ans += L+i;
  }

  if (L>0){
    ans -= L;
  } else if (L+N-1<0){
    ans -= L+N-1;
  } 

  cout << ans << endl;
}

Measured memory_bytes: 256
function main()
    N = pread(Int)
    a = readvec(Int, N)
    asum = zeros(Int, N)
    asum[1] = a[1]
    for i in 2:N
        asum[i] = (asum[i-1]+a[i])
    end
    c = 0
    for i in 1:N
        c += a[i] * ((asum[N]-asum[i]) % (10^9+7))
        c %= 10^9+7
    end
    println(c)
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 210972
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll mod = 1e9;

ll n;
ll uf[100005], us[100005];

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	/*
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
	*/

	cin >> n;
	ll maf = 0, mas = 0;
	forn(i, 0, n)
	{
		ll a;
		cin >> a;
		if (i % 2)
			us[a]++;
		else
			uf[a]++;
		if(uf[maf] < uf[a])
			maf = a;
		if (us[mas] < us[a])
			mas = a;
	}
	ll sum = n;
	ll lef = 0, les = 0;
	forn(i, 0, 1e5)
	{
		if (i != mas)
			lef = max(lef, uf[i]);
		if (i != maf)
			les = max(les, us[i]);
	}
	sum = max(us[mas] + lef, uf[maf] + les);
	sum = n - sum;
	cout << sum;
	return 0;
}

Measured memory_bytes: 1792