akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm> 
using namespace std;



int main() {
	int S[110], T[110],TT[110], x, cun=0, s1, t1, A, tt, q;
	string s, t;

	cin >> s >> t;

	for (int i = 0; i < s.size(); i++) {
		S[i] = s[i] - 'a';
	}
	for (int i = 0; i < t.size(); i++) {
		T[i] = t[i] - 'a';
	}
	s1 = s.size();
	t1 = t.size(); 
	tt = t1;
	sort(S, S + s1);
	sort(T, T + t1);
	for (int i = 0; i <t.size() / 2; i++) {
		A = T[i];
		T[i]=T[t1-1];
		T[t1-1] = A;
		t1--;
	}
	x = min(s1, tt);
	for (int i = 0; i < x; i++) {
		if (S[i] < T[i]) {
			cout << "Yes" << endl;
			return 0;
		}
		if (S[i] == T[i])cun++;
	}
	
	if (cun == x) {
		if (s.size() < t.size()) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <cassert>
#include <algorithm>
using namespace std;

int main() {
	int temp;
	vector<int> a;
	int n,x;
	int x_remaining;
	int time = 0;

	cin >> n >> x;

	for (int i = 0; i < n; i++) {
		cin >> temp;
		a.push_back(temp);
	}

	x_remaining = x - accumulate(a.begin(), a.end(), 0);
	time = n;


	cout << time+(x_remaining / *min_element(a.begin(), a.end()));

//	while((x_remaining -= *min_element(a.begin(), a.end())) > 0){
//		time++;
//	}
	
	
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

e = input()
num =int(input())

a = []

for i in range(len(e)) :
    for j in range(i+1,i+6):
        if e[i:j] not in a:
            a.append(e[i:j])

b = list(set(a))
b.sort()
print(b[num-1])


Measured memory_bytes: 21496
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	int N; scanf("%d", &N);
	bool ret = false;
	for (int i = 1; i <= 9; i++){
		for (int j = 1; j <= 9; j++){
			if (N == i*j){
				ret = true;
				break;
			}
		}
	}
	if (ret){
		printf("Yes");

	}
	else{
		printf("No");
	}

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    vector<int> key(n,0);
    int push = 1;
    int count = 0;
    while(1){
        if(push == 2){
            break;
        }else if(key.at(push-1) == 1){
            count = -1;
            break;
        }
        count++;
        key.at(push-1) = 1;
        push = a.at(push-1);
        //cout << "push=" << push << endl;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> a(m),b(m);
  for(Int i=0;i<m;i++) cin>>a[i]>>b[i];
  using P = pair<Int, Int>;
  vector<P> v;
  for(Int i=0;i<m;i++){
    a[i]--;b[i]--;
    v.emplace_back(a[i],b[i]);
  }
  sort(v.begin(),v.end());
  Int ans=0,nxt=n+1;
  for(Int i=0;i<m;i++){
    Int a,b;
    tie(a,b)=v[i];
    if(nxt<=a){
      ans++;
      nxt=n+1;
    }
    chmin(nxt,b);
  }
  if(nxt!=n+1) ans++;
  cout<<ans<<endl;
  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] m = new int[n];

        int cnt = 0;
        int total = 0;
        for (int i = 0; i < n; i++) {
            m[i] = sc.nextInt();
            cnt++;
            total += m[i];
        }

        Arrays.sort(m);

        while (total + m[0] <= x) {
            total += m[0];
            cnt++;
        }

        System.out.print(cnt);
    }
}


Measured memory_bytes: 23124
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        string S = ReadLine();
        int ans = 0;
        switch (S)
        {
            case "SAT": ans = 1; break;
            case "FRI": ans = 2; break;
            case "THU": ans = 3; break;
            case "WED": ans = 4; break;
            case "TUE": ans = 5; break;
            case "MON": ans = 6; break;
            case "SUN": ans = 7; break;
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 11104
c, d = gets.split.map(&:to_i)

def gcd(a, b)
  if a%b == 0
    b
  else
    gcd(b, a%b)
  end
end

def lc(a, b)
  a*b/gcd(a,b)
end

gcd(c,d)
puts lc(c,d)



Measured memory_bytes: 1788
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int a, b;
    std::string s, t, u;
    std::cin >> s >> t >> a >> b >> u;

    if (s == u) std::cout << a - 1 << ' ' << b << std::endl;
    else std::cout << a << ' ' << b - 1 << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
	int a ;
	scanf ("%d",&a);
	char n[10000];
	scanf ("%s",n);
	for (int i = 0 ; n[i] != 0 ; i++) {
		if (n[i]+a>'Z') {
			n[i] = n[i] - 26;
		}
		printf("%c",n[i] +a);
	}
	return 0;
}

Measured memory_bytes: 1668
package main

import (
  "fmt"
)

func sumInt(a ...int) int {s := 0; for _, v := range a {s += v}; return s}
func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var n, m int 
  fmt.Scan(&n, &m)
  a := make([]int, m)
  for i := 0; i < m; i++ {
    fmt.Scan(&a[i])
  }
  s := sumInt(a...)
  res := -1
  res = maxInt(res, n - s)
  fmt.Println(res)
}

Measured memory_bytes: 2460
#include <iostream>
#include <algorithm>
#include <utility>

int n;
std::pair<long long,int> x[200010];
long long ans[200010];
int main(){
  std::cin>>n;
  for(int i=0;i<n;++i){
    std::cin>>x[i].first;
    x[i].second=i;
  }
  std::sort(x,x+n);
  
  auto result1=x[n/2];
  auto result2=x[n/2-1];
  for(int i=0,check=n/2;i<n;++i)
    if(i<check)
      ans[x[i].second]=result1.first;
    else
      ans[x[i].second]=result2.first;
  
  for(int i=0;i<n;++i)
    std::cout<<ans[i]<<std::endl;
  return 0;
}


Measured memory_bytes: 6912
#!/usr/bin/env python3
import sys
from bisect import bisect_right


def solve(A: int, B: int, Q: int, s: "List[int]", t: "List[int]", x: "List[int]"):
    b, d = bisect_right(s, x), bisect_right(t, x)
    INF = 10e11
    ret = INF

    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            ret = min(ret, d1, d2)
    print(ret)


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    INF = 10e11
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    s = [-INF] + [int(next(tokens)) for _ in range(A)] + [INF]  # type: "List[int]"
    t = [-INF] + [int(next(tokens)) for _ in range(B)] + [INF]  # type: "List[int]"

    for x in range(Q):
        x = int(input())
        solve(A, B, Q, s, t, x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e9+7;

int main() {
    cout << fixed << setprecision(10);
    
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];

    sort(a.begin(), a.end());
    // sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    // b.emplace_back(INF);
    // c.emplace_back(INF);

    ll ans = 0;
    rep(i, n) {
        int tb = b[i];
        int l, r;

        // aにいくつtbより小さい数があるか探す
        l = -1;
        r = n;
        while(l+1 < r) {
            int ci = (l+r) / 2;
            if (a[ci] < tb) {
                l = ci;
            } else {
                r = ci;
            }
        }
        // cout << "l r " << l <<" " << r << endl;
        int a_low = l+1;

        // cにいくつtbより大きい数があるか探す
        l = -1;
        r = n;
        while(l+1 < r) {
            int ci = (l+r) / 2;
            if (c[ci] <= tb) {
                l = ci;
            } else {
                r = ci;
            }
        }
        int c_big = n-r;

        // cout << i << " " << a_low << " " << c_big << endl;

        ans += ll(a_low) * c_big;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  string S; cin >> S;
  if(N%2!=0){
    cout << "No" << endl;
    return 0;
  }
  rep(i,N/2){
    if(S[i]!=S[i+N/2]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
/*

Author : 5hifaT

github:https://github.com/jspw

linkedin : https://www.linkedin.com/in/mehedi-hasan-shifat-2b10a4172/

Stackoverflow : https://stackoverflow.com/story/jspw 


*/

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <bitset>
#include <set>
#include <map>
#include <iterator>

using namespace std;
#define ll long long
#define ull unsigned long long

//Sort array in discending order (n to 1)
bool decSort(ll a, ll b)
{
    return a > b;
}

//find the maximum element of a array
ll max_of_array(ll a[], ll n)
{
    ll mx = a[0];
    for (ll i = 0; i < n; i++)
    {
        if (a[i] > mx)
            mx = a[i];
    }
    return mx;
}

//find the minimum element of a array
ll min_of_array(ll a[], ll n)
{
    ll mn = a[0];
    for (ll i = 0; i < n; i++)
    {
        if (a[i] < mn)
            mn = a[i];
    }
    return mn;
}

bool isPrime(ll n)
{
    if (n == 1)
        return false;
    if (n == 2)
        return true;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

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

ll lcm(ll a, ll b)
{
    return (a * b) / gcd(a, b);
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string str;
    cin >> str;
    if (str[0] == 'R' && str[1] == 'R' && str[2] == 'R')
        cout << 3 << endl;

    else if (str[0] == 'R' && str[1] == 'R' || str[1] == 'R' && str[2] == 'R')
        cout << 2 << endl;

    else if (str[0] == 'R' || str[1] == 'R' || str[2] == 'R')
        cout << 1 << endl;
    else
        cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long k=sc.nextLong();
		
		
		if(a>=k)System.out.println(a-k+" "+b);
		else System.out.println(0+" "+Math.max(0,b-k+a));
	}
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long t[100010];
long long p;
struct p {
long long x, y;
}He[100010];
int main () {
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>t[i];
}
cin>>m;
for(int i=1;i<=m;i++){
cin>>He[i].x>>He[i].y;
}
for(int i=1;i<=m;i++){
long long sum=0;
for(int j=1;j<He[i].x;j++)
{
sum+=t[j];
}
sum+=He[i].y;
for(int j=He[i].x+1;j<=n;j++)
{
sum+=t[j];
}
cout<<sum<<endl;
}
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 5100000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  int X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<ll> A(X),B(Y),C(Z);
  for(int i=0;i<X;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<Y;i++){
    cin>>B.at(i);
  }
  for(int i=0;i<Z;i++){
    cin>>C.at(i);
  }
  vector<ll> AB;
  for(int i=0;i<X;i++){
    for(int j=0;j<Y;j++){
      AB.push_back(A.at(i)+B.at(j));
    }
  }
  sort(AB.begin(),AB.end());
  reverse(AB.begin(),AB.end());
  sort(C.begin(),C.end());
  reverse(C.begin(),C.end());

  ll left=-1;
  ll right=30000000003;

  while(left+1<right){
    ll x=(left+right)/2;
    ll count=0;
    ll j=Z-1;
    for(ll i=0;i<X*Y&&j>=0;i++){
      while(AB.at(i)+C.at(j)<x){
        j--;
        if(j<0){
          break;
        }
      }
      count+=j+1;
    }
    if(count<K){
      right=x;
    }else{
      left=x;
    }
  }
  ll x=left+1;
  vector<ll> ans;
  for(int i=0;i<X*Y;i++){
    for(int j=0;j<Z;j++){
      if(AB.at(i)+C.at(j)>=x){
        ans.push_back(AB.at(i)+C.at(j));
      }else{
        break;
      }
    }
  }
  sort(ans.begin(),ans.end());
  reverse(ans.begin(),ans.end());
  ll n=ans.size();
  for(int i=0;i<n;i++){
    cout<<ans.at(i)<<endl;
  }
  for(int i=0;i<K-n;i++){
    cout<<x-1<<endl;
  }
}


Measured memory_bytes: 10480
nx = input().split()
n = int(nx[0])
x = int(nx[1])
a = input().split()
for i in range(n):
	a[i] = int(a[i])

a = sorted(a)
c = 0
for i in range(n-1):
	x = x - a[i]
	c += 1
	if x < 0:
		c -= 1
		break

if x == a[n-1]:
	c += 1
	
print(c)

Measured memory_bytes: 3060
#include <stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b && c != a )
		printf("Yes");
	else if (b == c && a != b)
		printf("Yes");
	else if (c == a && b != c)
		printf("Yes");
	else
		printf("No");
	return (0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    set<string>a;
    for(int i=0;i<n;i++)
    {
      cin>>s;
      a.insert(s);
    }
    cout<<a.size()<<endl;
  return 0;
}


Measured memory_bytes: 19072
N,M=map(int,input().split())
A=[]
for i in range(N):
    a=list(map(int,input().split()))
    A.extend(a[1:])
    
U=0
for i in range(len(A)):
    if A.count(i)==N:
        U+=1
if N>1:
    print(U)
else:
    print(len(A))

Measured memory_bytes: 3060
# dp[i][j] := i 列目まで見て、i 列目を使うとして、
#             j 列無視した場合の min

N, K = map(int, input().split())
H = [0] + list(map(int, input().split())) + [0]
N += 1
inf = 10**18
dp = [[inf]*(K+1) for _ in range(N+1)]
dp[0][0] = 0
for i, h in enumerate(H[1:], 1):
    for j in range(K+1):
        for k in range(K+1):  # k 列無視する
            if i-k-1 < 0 or j-k < 0:
                continue
            h_p = H[i-k-1]
            dp[i][j] = min(dp[i][j], dp[i-k-1][j-k] + max(0, h - h_p))

#for d in dp:
#    print(d)
print(min(dp[-1]))


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

const unsigned long int modulo = 1000000007;

class Tree {
public:
    Tree(){
        this->id = ++(this->nNodes);
    }
    int getColorsMod(const unsigned int colors, const unsigned int depth, const unsigned int parentId) const {
        unsigned int tmpColors = colors;
        unsigned long int colorsMod = tmpColors % modulo;
        if(depth>0){
            tmpColors = this->nColors - 1;
        }
        for(auto &child : children){
            if(child->id != parentId){
                colorsMod *= child->getColorsMod(--tmpColors, depth+1, this->id);
                colorsMod %= modulo;
            }
        }
        return colorsMod;
    }
    void registerChild(const Tree &tree){
        this->children.emplace_back(&tree);
    }
    static void setNColors(const unsigned int nColors){
        Tree::nColors = nColors;
    }
private:
    unsigned int id;
    static unsigned int nNodes;
    static unsigned int nColors;
    std::vector<const Tree *> children;
};

unsigned int Tree::nNodes = 0;
unsigned int Tree::nColors = 0;

int main(int argc, char *argv[]){
    unsigned int N, K;
    std::cin >> N >> K;

    Tree tree[N];
    Tree::setNColors(K);
    unsigned int a,b;
    for(int i=1; i<N; ++i){
        std::cin >> a >> b;
        tree[--a].registerChild(tree[--b]);
        tree[b].registerChild(tree[a]);
    }
    std::cout << tree[0].getColorsMod(K,0,0) << std::endl;
    return 0;
}


Measured memory_bytes: 9344
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> pairs;
  
  REP(i,n){
    int a;
    cin >> a;
    a--;
    
    auto p = make_pair(a,i);
    pairs.push_back(p);
  }
    
  sort(pairs.begin(), pairs.end());
  
  REP(i,n){
    cout << pairs[i].second+1;
    if(i != n-1){
      cout << " ";
    }
  }
  
}

Measured memory_bytes: 4296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll q, a, b, c, d, cs[100008], ct[100008];
string s, t;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> s >> t >> q;
	cs[0] = 0;
	ct[0] = 0;
	for(ll i = 0; i < s.size(); i++){
		cs[i+1] = (s[i] == 'A')? 1 : 2;
		cs[i+1] += cs[i];
	}
	for(ll i = 0; i < t.size(); i++){
		ct[i+1] = (t[i] == 'A')? 1 : 2;
		ct[i+1] += ct[i];
	}
	
	rep(j, 1, q){
		cin >> a >> b >> c >> d;
		if((cs[b]-cs[a-1])%3 == (ct[d]-ct[c-1])%3){
			print("YES")
		}
		else{
			print("NO")
		}
	}
	
	return 0;
}

Measured memory_bytes: 2512
#include<stdio.h>

int main(void)
{
  int n,i,sum=0,temp;
  scanf("%d",&n);
  temp = n;
  while(temp != 0)
    {
      sum = sum + (temp % 10);
      temp = temp / 10;
    }
  if(n % sum == 0)
    {
      printf("Yes\n");
    }
  else
    {
      printf("No\n");
    }
  return 0;
}


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

int gcd(int p, int q) {
  if (p % q == 0) return q;
  return gcd(q, p % q);
}

int main() {
  int k;
  cin >> k;
  int sum = 0;
  for(int h = 1; h <= k; h++) {
    for(int i = 1; i <= k; i++) {
      for(int j = 1; j <= k; j++) {
        sum += gcd(h, gcd(i, j));
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>

using namespace std;

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

    int dp[n];
    dp[0] = 0;
    dp[1] = abs(stones[1]-stones[0]);
    for(int i = 2 ; i < n ; i++) {
        int cost1 = abs(stones[i]-stones[i-1]);
        int cost2 = abs(stones[i] - stones[i-2]);
        dp[i] = min(cost2+dp[i-2] , cost1+dp[i-1]);
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
	int n;
	cin>>n;
	long long ans=0;
	vector<int> a(n,0);
	vector<long long> b(n+1,0ll);
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		a[i]=tmp;
		b[tmp]++;
	}

	for(int i=0;i<=n;i++){
		ans+=((b[i]*b[i]-b[i])/2);
	}

	for(int i=0;i<n;i++){
		if(b[a[i]]>1){
			// cout<<b[a[i]]<<"\n";
			cout<<ans-(b[a[i]]-1)<<"\n";
		}
		else
			cout<<ans<<"\n";
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 4992
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<b)return 0; a=b; return 1;}



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

    ll n;
    cin>>n;
    ll a[n];
    ll cnt[n]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
        cnt[a[i]]++;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += cnt[i] * (cnt[i] - 1)/2;
    }
    for(int i=0;i<n;i++){
        ll ret = ans - cnt[a[i]]*(cnt[a[i]]-1)/2;
        ret += (cnt[a[i]]-1) * (cnt[a[i]]-2)/2;
        cout << ret << "\n";
    }
    
    
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20,M=3500;
ll n,a,b,c;
int main()
{
	cin>>n;
	if(n%2)
	{
		bool flag=true;
		for(ll a=1;a<=M&&flag;a++)
		{
			for(ll b=1;b<=M&&flag;b++)
			{
				ll x=-a*b*n;
				ll y=n*b+a*n-4*a*b;
				ll c=x/y;
				if(y&&x%y==0&&c>0)
					printf("%lld %lld %lld\n",a,b,c),flag=false;
			}
		}
	}
	else
		cout<<n<<' '<<n<<' '<<n/2<<endl;	

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
int h[200000],dp[200000];

int min_cost(int j)
{
	if(j==1)
		return 0;
	if(dp[j]==-1)
	{
		int a = INT_MAX;
		for (int i = 1; i <= k ; ++i)
		{
			int g = j-i;
			if(g<1)
				break;
			a = min(a,min_cost(g)+abs(h[g]-h[j]));
		}
		dp[j] = a;
	}
	return dp[j];
}

int main()
{
	
	cin>>n>>k;
	for (int i = 1; i <= n; ++i)
	{
		dp[i] = -1;
		cin>>h[i];
	}

	cout<<min_cost(n)<<endl;
	
	return 0;
}

Measured memory_bytes: 5760
n=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

Measured memory_bytes: 8804
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    mod = 10 ** 9 + 7
    N = int(input())

    dp = [1] * (N + 1)
    dp[0] = 1
    D = {}
    pre = -1
    for n in range(N):
        c = int(input())
        dp[n + 1] = dp[n]
        if pre == c:
            dp[n] = 0
            continue
        r = D.setdefault(c, 0)
        dp[n + 1] = (dp[n + 1] + r) % mod
        D[c] = r + dp[n]
        pre = c
    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 71000
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE    
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf   
    ll n; 
    cin>>n; 
    map<string,ll>mp;
    while(n--){
     string str; 
     cin>>str; 
     mp[str]++;
    }
    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl; 
    //printclock;
    return 0;
}
    

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

using namespace std;

int main() {
	int N, M;
	double A[105];
	cin >> N >> M;

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

	sort(A, A + N);
	s /= (4.0*M);
	bool flag = true;
	for (int i = N - 1; i > N - 1 - M; i--) {
		flag = A[i] >= s;
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 1e8;

int main() {
  int n, q;
  cin >> n >> q;
  while (q--) {
    int v, w;
    cin >> v >> w;
    if (n == 1) cout << min(v, w) << "\n";
    else {
      while (v != w) {
        if (v > w) v = (v + n - 2) / n;
        else w = (w + n - 2) / n;
      }
      cout << v << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

using namespace std;

typedef long long LL;

const int N=2e5,M=1e7;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

pair<int,int>p[N];
int s[N],nd[N],id[N],node;
int head[N],nxt[M],to[M],tot;
int dfn[N],low[N],st[N],rt[N],top,cnt,scc;bool in[N];

inline void link(int a,int b) { to[++tot]=b,nxt[tot]=head[a],head[a]=tot; }

inline void dfs(int k) {
	dfn[k]=low[k]=++cnt;
	in[st[++top]=k]=true;
	for (int i=head[k];i;i=nxt[i])
		if (!dfn[to[i]])
			dfs(to[i]),low[k]=min(low[k],low[to[i]]);
		else if (in[to[i]]) low[k]=min(low[k],dfn[to[i]]);
	if (low[k]==dfn[k]) {
		rt[k]=++scc;in[k]=false;
		while (st[top]!=k) rt[st[top]]=scc,in[st[top--]]=false;
		top--;
	}
}

#define lc (i<<1)
#define rc (lc|1)
inline void build(int i,int l,int r) {
	nd[i]=++node;
	if (l==r) id[s[p[l].second]^l]=node;
	else {
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
	}
}
inline void init(int i,int l,int r) {
	if (l==r) return;
	int mid=(l+r)>>1;
	link(nd[i],nd[lc]);
	link(nd[i],nd[rc]);
	init(lc,l,mid);
	init(rc,mid+1,r);
}
inline void add(int i,int l,int r,int L,int R,int k) {
	if (L<=l&&r<=R) link(k,nd[i]);
	else {
		int mid=(l+r)>>1;
		if (L<=mid) add(lc,l,mid,L,R,k);
		if (mid<R) add(rc,mid+1,r,L,R,k);
	}
}
int main()
{
	int n=gi(),i,m=0,l,r,mid,L,R;
	for (i=1;i<=n;i++)
		p[++m]=make_pair(gi(),i),p[++m]=make_pair(gi(),i);
	sort(p+1,p+1+m);
	for (i=1;i<=m;i++) s[p[i].second]^=i;
	l=0,r=p[m].first-p[1].first;

	build(1,1,m);
	while (l!=r) {
		mid=(l+r+1)>>1;
		
		tot=cnt=scc=0;
		for (i=1;i<=node;i++) head[i]=dfn[i]=0;

		init(1,1,m);
		for (i=1,L=R=1;i<=m;i++) {
			while (p[i].first-p[L].first>=mid) L++;
			if (L<i) add(1,1,m,L,i-1,id[i]);
			while (R<m&&p[R+1].first-p[i].first<mid) R++;
			if (i<R) add(1,1,m,i+1,R,id[i]);
		}

		for (i=1;i<=node;i++) if (!dfn[i]) dfs(i);
		for (i=1;i<=m;i++) if (rt[id[i]]==rt[id[s[p[i].second]^i]]) break;
		
		if (i<=m) r=mid-1;
		else l=mid;
	}
	cout<<l<<endl;
	return 0;
}


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

int main(){
   ll x;
   cin >> x;
   for(ll i=0;i<=200;i++){
      ll b=0;
      bool flag = true;
      while((pow(i,5)-pow(b,5) != x)&&(pow(i,5)+pow(b,5) != x)){
         b++;
         if((pow(i,5)-pow(b,5) < x)&&(pow(i,5)+pow(b,5) > x)){
            break;
         }
      }
      if((pow(i,5)-pow(b,5) == x)){
         cout << i << ' ' << b << endl;
         return 0;
      }
      if((pow(i,5)+pow(b,5) == x)){
         cout << i << ' ' << -b << endl;
         return 0;
      }
   }
   return 0;  
}

Measured memory_bytes: 4064
#include <iostream>
#include <cmath>

int main()
{
  int X;
  int max = 1;

  std::cin >> X;

  for ( int i = 2; i < X; ++i ) {
    for ( int j = i*i; j <= X; j*=i ) {
      if ( j > max ) max = j;
    }
  }

  std::cout << max << "\n";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a;a%=b;return gcd(b,a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
int nxt[1<<17];
int mod;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solveforthiscase(const int & test)
{
cin>>n;
string s;
cin>>s;
for(int i=1;i<(1<<17);i++)
nxt[i]=nxt[i%(__builtin_popcount(i))]+1; 
int rem1=0,rem2=0;
int cnt=0;
for(int i=0;i<n;i++)
if(s[i]=='1') cnt++;
a=cnt+1;
b=cnt-1;
mod=a;
for(int i=n-1;i>=0;i--)
{
  int id=n-1-i;
  if(s[i]=='1')
  rem1+=power(2,id);
  rem1%=mod;  
}
mod=b;
if(mod>0)
{
for(int i=n-1;i>=0;i--)
{
  int id=n-1-i;
  if(s[i]=='1')
  rem2+=power(2,id);
  rem2%=mod;  
}
}
vector<int> ans;
for(int i=n-1;i>=0;i--)
{
    int id=n-1-i;
    if(s[i]=='1' && b==0)
    ans.pb(0);
    else if(s[i]=='1' && b)
    {
    mod=b;
    temp=rem2;
    rem2=rem2+b-power(2,id);
    rem2%=b;
    ans.pb(nxt[rem2]+1);
    rem2=temp;
    }
    else if(s[i]=='0')
    {
        mod=a;
        temp=rem1;
        rem1=rem1+power(2,id);
        rem1%=mod;
        ans.pb(nxt[rem1]+1);
        rem1=temp;
    }
}
reverse(all(ans));
for(auto x:ans)
cout<<x<<'\n';
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t start, end;
    start = clock(); 
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    solveforthiscase(i);
    end = clock(); 
    long double t_t = (long double)(end - start) /(long double)(CLOCKS_PER_SEC); 
    cerr << (long double)t_t*1000<< " ms ";
}


Measured memory_bytes: 5048
#include<iostream>
#define INF (1 << 30)
using namespace std;

int number[101];

int main() {
    int N, min_cost = INF, sub_cost;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> number[i];
    for (int num = -100; num <= 100; num++) {
        sub_cost = 0;
        for (int i = 0; i < N; i++) sub_cost += (num - number[i]) * (num - number[i]);
        if (min_cost > sub_cost) min_cost = sub_cost;
    }
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h,w;
    cin >> h >> w;
    vvint a(h,vint(w));
    REP(i,h){
        REP(j,w){
            cin >> a[i][j];
        }
    }
    REP(i,h){
        REP(j,w){
            int b;
            cin >> b;
            a[i][j] -= b;
        }
    }
    vector<vector<vector<bool> > > dp(h,vector<vector<bool> >(w,vector<bool>(80*(h+w),false)));
    dp[0][0][abs(a[0][0])] = true;
    int ma = 80*(h+w);
    REP(i,h){
        REP(j,w){
            int now = abs(a[i][j]);
            if(i>0){
                REP(k,ma){
                    if(k+now<ma&&dp[i-1][j][k]){
                        dp[i][j][k+now] = true;
                    }
                    if(abs(k-now)<=ma&&dp[i-1][j][k]){
                        dp[i][j][abs(k-now)] = true;
                    }
                }
            }
            if(j>0){
                REP(k,ma){
                    if(k+now<ma&&dp[i][j-1][k]){
                        dp[i][j][k+now] = true;
                    }
                    if(abs(k-now)<=ma&&dp[i][j-1][k]){
                        dp[i][j][abs(k-now)] = true;
                    }
                }
            }
        }
    }
    int ans = INF;
    REP(i,ma){
        if(dp[h-1][w-1][i]){
            ans = i;
            break;
        }
    }
    
    cout << ans  << endl;
    return 0;
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};



int main(){
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;++i){
        if(i%3!=0 and i%5!=0)
            sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3624
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

class UnionFind(n: Int) {
    private val rank = IntArray(n) { 0 }
    private val parent = IntArray(n) { -1 }

    fun find(x: Int): Int {
        if (parent[x] < 0) {
            return x
        }
        parent[x] = find(parent[x])
        return parent[x]
    }

    fun unite(x: Int, y: Int) {
        val x1 = find(x)
        val y1 = find(y)
        if (x1 == y1) {
            return
        }
        if (rank[x1] < rank[y1]) {
            parent[y1] += parent[x1]
            parent[x1] = y1
        } else {
            parent[x1] += parent[y1]
            parent[y1] = x1
            if (rank[x1] == rank[y1]) {
                rank[x1]++
            }
        }
    }

    fun same(x: Int, y: Int): Boolean {
        return find(x) == find(y)
    }

    fun size(x: Int): Int {
        return -parent[find(x)]
    }
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val q = sc.nextInt()
    val uf = UnionFind(n)
    for (_i in 0 until q) {
        val t = sc.nextInt()
        val u = sc.nextInt()
        val v = sc.nextInt()
        if (t == 0) {
            uf.unite(u, v)
        } else {
            println(if (uf.same(u, v)) 1 else 0)
        }
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 58404
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i(0);i<n;i++)
typedef long long ll;

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

    int a = A / 0.08;
    int b = B / 0.1;
    int aa = (A+1) / 0.08;
    int bb = (B+1) / 0.1 - 1;

    if((A / 0.08) - a > 0) a++;
    if(((A+1) / 0.08) - aa == 0) aa--;

    int ans = max(a,b);

    if(aa < b || bb < a) cout << "-1" << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#define llint long long
#define inf 1000000000

using namespace std;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

struct edge{
	int to, cap, rev;
	edge(){}
	edge(int a, int b, int c){
		to = a, cap = b, rev = c;
	}
};

llint n, m;
llint x[1005], y[1005];
vector<edge> G[2005];
vector<int> vecx[1005], vecy[1005];
UnionFind uf(1005);
set<llint> s;

int S, T;
bool used[2005];

int dfs(int v, int f)
{
	used[v] = true;
	if(v == T) return f;
	
	int ret;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i].to] || G[v][i].cap <= 0) continue;
		ret = dfs(G[v][i].to, min(f, G[v][i].cap));
		if(ret > 0){
			G[v][i].cap -= ret;
			G[G[v][i].to][G[v][i].rev].cap += ret;
			return ret;
		}
	}
	return 0;
}

void add_edge(int s, int t, int cap)
{
	G[s].push_back(edge(t, cap, G[t].size()));
	G[t].push_back(edge(s, 0, G[s].size()-1));
}

int main(void)
{
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> x[i] >> y[i];
	
	for(int i = 1; i <= m; i++){
		vecx[x[i]].push_back(i);
		vecy[y[i]].push_back(i);
	}
	uf.init();
	for(int i = 1; i <= n; i++){
		for(int j = 1; j < vecx[i].size(); j++){
			uf.unite(vecx[i][j-1], vecx[i][j]);
		}
		for(int j = 1; j < vecy[i].size(); j++){
			uf.unite(vecy[i][j-1], vecy[i][j]);
		}
	}
	for(int i = 1; i <= m; i++) s.insert(uf.root(i));
	llint ansy = m - s.size();
	
	S = 2*n+1, T = 2*n+2;
	for(int i = 1; i <= m; i++){
		add_edge(x[i], n+y[i], 1);
	}
	for(int i = 1; i <= n; i++){
		add_edge(S, i, 1);
		add_edge(n+i, T, 1);
	}
	
	int ansx = 0, flow;
	while(1){
		for(int i = 1; i <= T; i++) used[i] = false;
		flow = dfs(S, inf);
		if(flow <= 0) break;
		ansx += flow;
	}
	ansx = m - ansx;
	
	cout << ansx << " " << ansy << endl;
	
	return 0;
}


Measured memory_bytes: 3448
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    else:
        for i, _ in enumerate(range(a)):
            if i % 2 == 0:
                if b % 2 == 1:
                    print('#.' * (b // 2) + '#')
                else:
                    print('#.' * (b // 2))
            else:
                if b % 2 == 1:
                    print('.#' * (b // 2) + '.')
                else:
                    print('.#' * (b // 2))
        print()


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <iterator>
#include <cmath>
#include <stack>
#include <functional>
using namespace std;

 
int main()
{
  vector<int> height;

  for(int i = 0; i < 10; i++) {
    int temp;
    cin >> temp;
    height.push_back(temp);
  }
  sort(height.begin(), height.end(), greater<int>());

  for(int i = 0; i < 3; i++)
    cout << height[i] << endl;

  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む
 
int main() {
    using std::cout;
    using std::endl;
    using std::cin;
    using std::string;

    int a, b;
    cin >> a >> b;


    if ((a*b)%2 == 1) {
        cout << "Odd" << endl;
    } else {
        cout << "Even" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <functional>
 
using namespace std;
using ll=long long int;
 
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if (m % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }
 
    vector<int> used(n, 0);
    function<int(int)> dfs = [&](int v) {
        used[v] = 1;
        int out = 0;
        for (int u: g[v]) {
            if (used[u] == 1) continue;
            if (used[u] == 2 || !dfs(u)) {
                cout << v+1 << " " << u+1 << "\n";
                out++;
            } else {
                cout << u+1 << " " << v+1 << "\n";
            }
        }
        used[v] = 2;
        return out%2;
    };

    dfs(0);
 
    return 0;
}


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

int main()
{
    int N;
    cin >> N;

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

    long ans = 0;

    int num = 0;
    for (int i = 1; i < N; i++)
    {
        num = A.at(i) - A.at(i - 1);
        if (num < 0)
        {
            A.at(i) += abs(num);
            ans += abs(num);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

// PMAMP :)
// INL , IIWOIL

int main()
{
    jaldi
    set<int> s;
    for(int i=0;i<3;i++){int x; cin>>x; s.insert(x);}
    s.size()==2 ? cout<<"Yes":cout<<"No";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
C = [int(input()) for _ in range(N)]

mod = 10**9+7
newC = [C[0]]
for c in C:
    if newC[-1] == c:
        continue
    newC.append(c)

N = len(newC)
L = [0]*(N+1)
L[0] = 1
idx = [-1]*(max(newC)+1)
for i in range(N):
    if idx[newC[i]] >= 0:
        L[i+1] += L[idx[newC[i]]]
        
    L[i+1] += L[i]
    L[i+1] %= mod
    idx[newC[i]] = i+1

print(L[-1])

Measured memory_bytes: 26028
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int h,w,a,b;
char s[1010][1010];

void solve(){
    cin >> h >> w >> a >> b;
    rep(i,h){
        rep(j,w) s[i][j]='0';
    }
    rep(i,b){
        rep(j,a){
            s[i][j]='1';
        }
    }
    Rep(i,b,h){
        Rep(j,a,w){
            s[i][j]='1';
        }
    }
    rep(i,h){
        rep(j,w) cout << s[i][j];
        cout << "" << endl;
    }
}

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

Measured memory_bytes: 2176
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

class Main{
	static int n;
	static long ans = 1000000000;
	static int[] memo;
	static int[] dp;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] P = new int[M];
		int[] Y = new int[M];
		int[] count = new int[N];				//県ごとの市の生まれた順番を記憶
		Map<Integer, Integer> map = new TreeMap<>();
		for(int i = 0;i < M;i++){
			P[i] = sc.nextInt();
			Y[i] = sc.nextInt();
			map.put(Y[i], i);
		}
		int num;
		int index = 0;
		for(Integer value :map.values()){
			index = value;			//初期の順番
			num = P[index]-1;
			if(count[num] == 0){				//もしその県にまだ何も生まれてなかったら
				count[num] = 1;
				Y[index] = count[num];			//順番(1番目)を記憶
			}else{
				count[num]++;
				Y[index] = count[num];			//順番を記憶
			}
		}
		
		for(int i = 0;i < M;i++){
			System.out.println(String.format("%06d%06d", P[i],Y[i]));
		}


	}
}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 148740
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int main(){
    // FILE;
    SPEED;
    int n;
    cin>>n;
    
    unordered_map<int,int> m1;

    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                m1[i*i+j*j+k*k+i*j+i*k+k*j]++;
            }
        }
    }

    for(int i=1;i<=n;i++)cout<<m1[i]<<endl;

}


Measured memory_bytes: 5060