akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;


#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

ll a[maxn];

int qt[20];

int main()
{
  initFactorials();
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  sort(a, a + n, greater<int>());

  ll ans = 0;
  for(int i = 0; i < n; i++)
  {
    ll x1 = a[i];
    ll x2 = (exp(2, 2*n-2) * (i)) % mod;
    ll x3 = exp(2, 2*n-1);
    ans += (x1 * x2) % mod + (x1 * x3)  % mod ;
    ans %= mod; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8292
#include <stdio.h>
#include <string.h>

int main() {
  char s[101] = {0}, t[101] = {0};
  int i, j;
  int sl, tl;
  scanf("%s %s", s, t);
  sl = strlen(s);
  tl = strlen(t);

  for (i = 0; i < sl-1; i++) {
    for (j = i+1; j < sl; j++) {
      if (s[i] > s[j]) {
        char tmp;
        tmp = s[i];
        s[i] = s[j];
        s[j] = tmp;
      }
    }
  }

  for (i = 0; i < tl-1; i++) {
    for (j = i+1; j < tl; j++) {
      if (t[i] < t[j]) {
        char tmp;
        tmp = t[i];
        t[i] = t[j];
        t[j] = tmp;
      }
    }
  }

  if (strcmp(s, t) < 0) {
    puts("Yes");
  }
  else{
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,a,b;
    ll ans=0;
    cin>>n;
    vector<set<int>> v(n);
    vector<int> c(n),d(n);
    fr(i,n-1){
        cin>>a>>b;
        ++d[--a];++d[--b];
        v[a].insert(b);
        v[b].insert(a);
    }
    for(auto& i:c) cin>>i;
    sort(c.begin(),c.end());
    vector<bool> vis(n);
    vector<int> an(n);
    fr(i,n){
        int m=INT_MAX;
        fr(j,n) if(!vis[j]) m=min(m,d[j]);
        int k=0;
        for(;k<n;k++) if(!vis[k]&&d[k]==m) break;
        vis[k]=1;
        an[k]=c[i];
        ans+=d[k]*c[i];
        for(auto& j:v[k]){
            if(!vis[j]){
                v[j].erase(k);
                --d[j];
            }
        }
    }
    cout<<ans<<endl;
    for(auto i:an) cout<<i<<" ";
    cout<<endl;
}

Measured memory_bytes: 1920
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    from collections import deque
    import copy
    h,w=L()
    grid=[S() for i in range(h)]
    dist=[[-1]*w for i in range(h)]
    start=deque()
    for i in range(h):
        for j in range(w):
            if grid[i][j]=='.':
                start.append((i,j))
                #(h,w):tuple, immutable
                
                dist[i][j]=-2
                
    def bfs(start,dist):
        ans=0
        d=0
        search=deque()
        #c=0
        while start:
            #print("#####################")
            #c+=1
            #print(c,ans)
            sty,stx=start.popleft()
            search.append((sty,stx))
            new_dist=copy.deepcopy(dist)
            new_dist[sty][stx]=0
            while search:
                tmph,tmpw=search.popleft()
                #print("$$$",end="")
                #print(tmph,tmpw,end="")
                #print("$$$")
                d=new_dist[tmph][tmpw]
                
                for dy,dx in ((1,0),(0,1),(-1,0),(0,-1)):
                    new_h=tmph+dy
                    new_w=tmpw+dx
                    if new_h<0 or h<=new_h or new_w<0 or w<=new_w: continue
                    if new_dist[new_h][new_w]==-2:
                        new_dist[new_h][new_w]=d+1
                        search.append((new_h,new_w))
                        ans=max(ans,d+1)
                
                #for i in range(h):
                #    print("".join([str(a) if a>=0 else '#' if a==-1 else '.' for a in new_dist[i]]))
                #print("###")
        return ans
                
    print(bfs(start,dist)) 
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define ran 4044
int col[ran],num[ran];
int pos[3][ran];
int n;
int s1[ran][ran], s2[ran][ran];
int dp[ran][ran];
void upd(int&x,int y){
	if(x==-1 || x>y)x=y;
}
int main(){
	char s[9];
	scanf("%d",&n);
	for(int i=1; i<=n*2; i++){
		scanf("%s%d",s,&num[i]);
		col[i] = (*s == 'B' ? 1 : 2);
		pos[col[i]][num[i]] = i;
	}
	for(int i=1; i<=n*2; i++){
		for(int j=1; j<=n; j++){
			s1[i][j] = (i==1?0:s1[i-1][j]) + (col[i] == 1 && num[i] <= j);
			s2[i][j] = (i==1?0:s2[i-1][j]) + (col[i] == 2 && num[i] <= j);
		}
	}
	memset(dp,-1,sizeof(dp));
	dp[0][0] = 0;
	for(int i=0; i<=n; i++)for(int j=0; j<=n; j++){
		if(i<n){
			int P = pos[1][i+1];
			upd(dp[i+1][j], dp[i][j] + P - 1 - s1[P][i] - s2[P][j]);
		}
		if(j<n){
			int P = pos[2][j+1];
			upd(dp[i][j+1], dp[i][j] + P - 1 - s1[P][i] - s2[P][j]);
		}
	}
	printf("%d\n",dp[n][n]);
	return 0;
}


Measured memory_bytes: 191104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

ll dp[3005][5005];
int used[3005][3005];
vector<int> a;

ll dfs(int l, int r) {
	if (l == r) return 0;
	if (used[l][r]) return dp[l][r];
	used[l][r] = 1;
	ll res = -linf;
	maxs(res, a[l] - dfs(l + 1, r));
	maxs(res, a[r - 1] - dfs(l, r - 1));
	return dp[l][r] = res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	a.resize(n);
	rep(i, n) cin >> a[i];
	cout << dfs(0, n) << endl;
	return 0;
}

Measured memory_bytes: 152064
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    double a, b, h, m, C;
    scanf("%lf %lf %lf %lf", &a, &b, &h, &m);
    C=sqrt((a * a)+(b * b)-(2.0 * a * b * cos((M_PI * ((5.5 * m)-(30*h)))/180.0)));
    printf("%.10f" , C);
    return 0;
}

Measured memory_bytes: 2596
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MOD 1000000007

int n,m;
ll q[200005],h[200005];
ll sum=0;

int main()
{
	read(n),read(m);
	q[0]=0,h[n+1]=0;
	for(int i=1;i<=n;i++) q[i]=q[i-1]+1ll*i;
	for(int i=n;i>=1;i--) h[i]=h[i+1]+1ll*i;
	for(int i=m;i<=n;i++) sum=(sum+h[n-i+1]-q[i-1]+1)%MOD;
	printf("%lld\n",(sum+1)%MOD);
	return 0;
} 

Measured memory_bytes: 6836
D, G = map(int,input().split())
prob_list = [list(map(int,input().split())) for i in range(D)]

ans = 10000000000
point = 0
for i in range(2 ** D):
    prob = 0
    point = 0
    for j in range(D):
        if (i & (1 << j)):
            prob += prob_list[j][0]
            point += (j+1) * 100 * prob_list[j][0] + prob_list[j][1]
    if point >= G:
        ans = min(ans, prob)
    else:
        for k in reversed(range(D)):
            if (i & (1 << k)):
                continue
            for z in range(prob_list[k][0]):
                point += (k + 1) * 100
                prob += 1
                if point >= G:
                    ans = min(ans,prob)
        ans = min(ans, prob)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
int a,b,ans;
scanf("%d%d",&a,&b);
if(a<b)
ans=b-a;
else
ans=a-b+2;
b=-b;
if(a<b&&b-a+1<ans)
ans=b-a+1;
if(a>b&&a-b+1<ans)
ans=a-b+1;
if(a==b)
ans=1;
printf("%d\n",ans);
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[110];
int main(){
	ll n;
	cin>>n;
	ll ans=1000;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n-1;i++){
		if(a[i]<a[i+1])ans+=ans/a[i]*(a[i+1]-a[i]);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3620
# https://atcoder.jp/contests/abc133/tasks/abc133_c

L, R = map(int, input().split())

if (R - L) >= 2019:
    print(0)
    exit()

min_m = 2019

for i in range(L, R):
    for j in range(i + 1, R + 1):
        m = (i * j) % 2019

        min_m = min(min_m, m)

print(min_m)

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

int main(){
	string odd, even;
  	cin >> odd >> even;
  	int i = 0;
  	string ans="";
  	while(i < even.length()){
    	ans+=odd[i];
      	ans+=even[i];
      	i++;
    }
  	if(odd.length()-even.length()>0)ans+=odd[odd.length()-1];
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int n;
    long a,max = -4382989,min = 324325323,sum = 0;

    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%ld",&a);
        sum += a;
        if(a < min) min = a;
        if(a > max) max = a;
    }
    printf("%ld %ld %ld\n",min,max,sum);
    return 0;
    }


Measured memory_bytes: 2736
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
int n;
long long k,a[200007],it[800007],sum[200007],ans=0;
pair <long long,int> sv[200007];
void update(int x,int l,int r,int pos){
	if(l>pos || r<pos) return;
	if(l==r){
		it[x]=1;
		return;
	}
	int mid=(l+r)/2;
	update(x*2,l,mid,pos);
	update(x*2+1,mid+1,r,pos);
	it[x]=(it[x*2]+it[x*2+1]);
}
int get(int x,int l,int r,int L,int R){
	if(l>R || r<L || L>R) return 0;
	if(l>=L && r<=R) return it[x];
	int mid=(l+r)/2;
	return (get(x*2,l,mid,L,R)+get(x*2+1,mid+1,r,L,R));
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]-=k;
	}
	for(int i=1;i<=n;i++){
		 sum[i]=sum[i-1]+a[i];
		 sv[i]=mp(sum[i],i);
	}
	sort(sv+1,sv+1+n);
	for(int i=1;i<=n;i++){
		int pos=sv[i].se;
		long long val=sv[i].fi;
		if(val>=0) ans++;
		ans+=get(1,1,n,1,pos-1);
		update(1,1,n,pos);
	}
	cout<<ans;
}


Measured memory_bytes: 12800
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

n,m = readInts()
data = []
for i in range(n):
	data.append(readInts()[1:])

d = defaultdict(int)

for i in data:
	for j in i:
		d[j]+=1

ans = 0
for i in d:
	if d[i]==n:
		ans+=1

print(ans)

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(a>0&&c>0){
    c-=b;
    if(a>0&&c>0)
    a-=d;
  }
  if(0>=a)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

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



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

int main(){
    string s; cin >> s;
    string a(3,'A');
    string b(3,'B');
    if(s == a || s == b) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
package main

import "fmt"
import "os"
import "bufio"

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	instr := scanner.Text()

	for _, runeVal := range instr {
		if runeVal >= 'a' && runeVal <= 'z' {
			fmt.Print(string(runeVal - 'a' + 'A'))
		} else if runeVal >= 'A' && runeVal <= 'Z' {
			fmt.Print(string(runeVal - 'A' + 'a'))
		} else {
			fmt.Print(string(runeVal))
		}
	}
	fmt.Println("")
	return
}



Measured memory_bytes: 1080
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	cout << x - a - ((x - a) / b * b) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

int selectionSort(int a[], int n) {
    int count = 0;
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (a[j] < a[minj]) {
                minj = j;
            }
        }
        if (minj != i) {
            swap(a[i], a[minj]);
            count++;
        }
    }
    return count;
}

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

    int count = selectionSort(a, n);
    for (int i = 0; i < n; i++) {
        if (i > 0) printf(" ");
        printf("%d", a[i]);
    }
    printf("\n%d\n", count);
    return 0;
}


Measured memory_bytes: 2716
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<numeric>

#define REP(i, a) for(int i=0;i<(int)a;++i)
#define INF 1145141919;
typedef long long ll;
typedef long double ld;
using namespace std;

int H, W;
vector<ll> a;

void solver() {
    while (cin >> H >> W) {
        if (H == 0 && W == 0)break;
        REP(h, H) {
            REP(w, W) {
                if (h == 0 || h == H - 1)printf("#");
                else if (w == 0 || w == W - 1)printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
}

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

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

typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<=(b);i++) // no semicoron
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく



using namespace std;

int main(){
    //int i = 0; 宣言不要
    /*REP(i, 5){
        cout << i << endl;
    }*/

    ll X;

    cin >> X;

    ll fh = X / 500;
    ll f = (X % 500) / 5;

    ll ans = 1000 * fh + 5 * f;

    cout << ans << endl;




}

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

int main()
{
    int N;
    int Alice = 0, Bob = 0;
    vector<int> a;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end(), greater<int>());
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0)
        {
            Alice += a[i];
        }
        else
        {
            Bob += a[i];
        }
    }

    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
N = gets.chop.to_i
S = [0]
N.times do
  S << gets.chop.to_i
end

S.sort!

dp = Array.new(N + 1)
dp[0] = [{score: 0, sum: 0, list: Array.new(N+1, 0)}]

def score(v)
  v % 10 == 0 ? 0 : v
end

(1..N).to_a.each do |i|
  (1..N).to_a.each do |j|
    dp[i] = [] if dp[i] == nil

    max_o = nil
    max_score = -1
    dp[i-1].each do |o|
      next unless o[:list][j] == 0
      sum = S[j] + o[:sum]
      if score(sum) > max_score
        max_score = score(sum)
        max_o = o
      end
    end
    next if max_o.nil?
    new_sum = max_o[:sum] + S[j]
    new_score = score(new_sum)
    new_list = max_o[:list].dup
    new_list[j] = S[j]

    dp[i] << {score: new_score, sum: new_sum, list: new_list}
  end
  dp[i].uniq!
end

max = dp.flatten.max do |o|
        o[:score]
      end
p max[:score]

Measured memory_bytes: 7548
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long

using namespace std;

signed main(){
    int n, a;
    cin >> n;
    int A[n]={0};
    //nums.resize(n);
    for(int i=0;i<n-1;i++){
        cin >> a;
        A[a-1]++;
    }

    for(int i=0;i<n;i++){
        cout << A[i] << endl;
    }
    
    return 0;
}       

Measured memory_bytes: 5148
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
   int n;cin>>n;
   vector<int> a(n);
   map<int,int> mp;
   rep(i,n){
       int a;cin>>a;
       mp[a]++;
   }
   int res=mp.size();
   int tmp=0;
   for(auto&p:mp){
       int buf=p.second;buf--;//消すべきカード枚数
       if(tmp>buf){
           tmp-=buf;
       }else{
           buf-=tmp;
           tmp=buf;
       }
   }
   if((tmp+1)%2==0)res--;
   cout<<res<<endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;

    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }

    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }

    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

void solve(){
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N);
    REP(i,N) cin >> a[i];
    vector<ll> cum(N+1);
    REP(i,N) cum[i+1] = cum[i] + (a[i] - K);
    vector<ll> b = cum;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    BIT<ll> bit(N+10);
    ll ans = 0;
    for(int i=0;i<=N;i++){
        int idx = lower_bound(b.begin(), b.end(), cum[i]) - b.begin();
        ans += bit.sum(idx+1);
        bit.add(idx+1, 1);
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 6528
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();

        int[] l = new int[n];
        int bound = 0;
        int cnt = 1;
        for (int i = 0; i < n; i++) {
            bound += scan.nextInt();
            if (bound > x) {
                break;
            }
            cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 22868
n = int(input())
a = list(map(int, input().split()))  # �������l�����X�g�Ɋi�[
ans = 0

a.sort()
num = 0
#  �}�C�i�X�̌��������Ȃ�S�����ɂ��Ęa���Ƃ�
# ��Ȃ�S�������ɂ��Đ�Βl�������������

for i in range(n):
    if a[i] < 0:
        num += 1

# num�̓}�C�i�X�̐�
a = list(map(abs, a))
if num % 2 == 0:
    print(sum(a))
else:
    a.sort()
    print(sum(a) - a[0]*2)


Measured memory_bytes: 14332
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n; cin >> n;
	string s; cin >> s;
	if (n % 2 != 0) cout << "No";
	else
	{
		string sub = s.substr(n/2);
		if (s == sub + sub) cout << "Yes";
		else cout << "No";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;

int f[maxn];
int sum[maxn]; 
int n,m;
int Find(int x){
    return f[x]==x?x:f[x]=Find(f[x]);
}
void merge(int u,int v){
	int x = Find(u);
	int y = Find(v);
	if(x!=y){
		f[x] = y;
		sum[y] += sum[x];
	}
}
void Init(){
    for(int i = 1; i <= n;i++){
    	f[i] = i;
    	sum[i] = 1;
	}
}
int main(void){
	cin >> n >> m;
	Init();
	while(m--){
		int u,v;
		cin >> u >> v;
		merge(u,v);
	} 
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(f[i]==i){
			ans = max(ans,sum[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5088
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int A[333] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
    ____();
    int x;
    cin >> x;
    cout << A[x-1] << endl;
    return 0;
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A&lang=jp
# Graph: python3
#  2018.12.04 yonezawa

import sys
input = sys.stdin.readline
#import cProfile
def main():
    n = int(input())
    nmap = [[0 for i in range(n)] for i in range(n)]

    for _ in range(n):
        l = list(map(int,input().split()))
        a = l[0] - 1
        for i in l[2:]:
            nmap[a][i-1] = 1
    for i in nmap:
        print (*i)
        
if __name__ == '__main__':
    main()
    #pr = cProfile.Profile()
    #pr.runcall(main)
    #pr.print_stats()


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

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

int main(){
  int N;
  cin >> N;
  vector<pair<string, pair<int, int>>> p(N);
  for(int i = 0; i < N; i++) {
    cin >> p[i].first >> p[i].second.first;
    p[i].second.first = -p[i].second.first;
    p[i].second.second = i + 1;
  }
  sort(all(p));
  for(int i  = 0; i < N; i++) {
    cout << p[i].second.second << endl;
  }
  return 0;
}


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

using namespace std;

int main()
{
    string s;
    int k;

    cin >> k >> s;

    int n = s.length();

    string ans = "";

    if (n <= k)
        ans = s;
    else
        ans = s.substr(0, k) + "...";

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <windows.h>
using namespace std;
typedef long long LL;
const int mod = 1e9 + 7, MAX = 110;
int n, h[MAX], pw[MAX];
inline int add(int a, int b) {
	return a + b >= mod ? a + b - mod : a + b;
}
inline int sub(int a, int b) {
	return a >= b ? a - b : a - b + mod;
}
inline int mul(int a, int b) {
	return LL(a) * b % mod;
}
int pm(int a, LL b) {
	if (b == 0) return 1;
	if (b & 1) return mul(a, pm(a, b - 1));
	return pm(mul(a, a), b / 2);
}
pair<int, int> solve(int a, int b, int s) {
	if (b - a == 1) {
		int w = pm(2, h[a] - s);
		return make_pair(w, w);
	}
	int m = *min_element(h + a, h + b);
	vector <pair<int, int> > v;
	int i = a;
	while (i < b) {
		int j = i;
    	while (j < b && (h[i] == m) == (h[j] == m))
			j ++;
    	v.push_back(make_pair(i, j));
    	i = j;
	} 
	int fT = 1, fA = 2;
  	for (int i = 0; i < v.size(); i ++) {
		pair<int, int> p = v[i];
	    int x = p.first, y = p.second;
	    if (h[x] != m) {
	    	pair <int,int> g = solve(x, y, m);
	    	fT = mul(fT, add(g.first, g.second));
	    	fA = mul(fA, g.first);
	    } else {
	    	fT = mul(fT, pw[y - x]);
	    }
	}
	fT = sub(fT, fA);
	fA = mul(fA, pm(2, m - s - 1));
	fT = add(fT, fA);
	return make_pair(fA, fT);
}
int main(void) {
	cin >> n;
	//DWORD start_time = GetTickCount();
	for (int i = 0; i < n; i ++)
		cin >> h[i];
	pw[0] = 1;
	for (int i = 0; i < n; i ++)
		pw[i + 1] = mul(pw[i], 2);
	pair <int, int> g = solve(0, n, 0);
	cout << g.second << endl;
	//DWORD end_time = GetTickCount();
	//cout << "Time costed : " << (end_time - start_time)  << ".ms" << endl;
	return 0;
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split())) 
b = list(map(int, input().split())) 

x = [0] * M
y = [0] * M
c = [0] * M

ans = 10 ** 10
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
    p = a[x[i]-1] + b[y[i]-1] - c[i]
    if ans > p:
        ans = p
    
if ans > min(a) + min(b):
    ans = min(a) + min(b)

print(ans)

Measured memory_bytes: 23404
#N = int(input())
h1,m1,h2,m2, k = map(int,input().split())
#al = list(map(int,input().split()))



if m2 >= m1:
    hd = (h2 -h1) * 60
    md = m2 -m1
    timed = hd + md
else:
    hd = (h2 -h1) * 60
    md = 60 - m1 + m2
    timed = md + hd -60
print(timed - k)



Measured memory_bytes: 9172
#include<bits/stdc++.h>
#include <regex>
#include<ext/numeric>
#include<ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v)  (int)v.size()
#define WHITE -1
#define GREY   0
#define BLACK  1
#define CLR(a,v) memset(a,v,sizeof a)
#define PC(x) __builtin_popcount(x)
#define MP make_pair

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
//typedef unsigned int ui;

typedef complex<double> point;
//#define X real()
#define Y imag()
#define vec(a,b) ((b)-(a))
#define dot(a,b) ((conj(a)*(b)).real())
#define cross(a,b) ((conj(a)*(b)).imag())
#define colliner pointOnLine
#define same(a,b) (lengthSqr(vec(a,b))<EPS)
#define lengthSqr(v) (dot(v,v))

const double PI = acos(-1.0);

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

int DX[] = { 1, 1, -1, -1, 2, 2, -2, -2 };
int DY[] = { 2, -2, 2, -2, 1, -1, 1, -1 };

const int MAX = 1e5 + 5, MOD = 1e9 + 7, oo = (1 << 30);
const ll OO = 1ll << 60, MAXN = 1e15;
const double EPS = 1e-9;

int n, a[MAX];
ll preSum[MAX];

int main() {

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	sort(a, a + n);
	preSum[0] = a[0];
	for (int i = 1; i < n; ++i)
		preSum[i] = preSum[i - 1] + a[i];
	int s = 0;
	for (int i = 0; i < n - 1; ++i)
		if (2 * preSum[i] < a[i + 1])
			s = i + 1;
	printf("%d\n", n - s);
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define N 100009

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= 9; i++)
    {
        for(int j = 1; j <= 9; j++) if(i * j == n) return cout << "Yes\n", 0;
    }
    cout << "No\n";
}


Measured memory_bytes: 256
import sys

input=sys.stdin.readline

Q=int(input())
ques=[[] for i in range(0,Q)]
value=set([])
for i in range(0,Q):
    ques[i]=list(map(int,input().split()))
    if ques[i][0]==1:
        value.add(ques[i][1])

value=list(value)
value.sort()
n=len(value)
dic={}
for i in range(n):
    dic[value[i]]=0
    dic[value[i]]=i

#####segfunc######
def segfunc(x,y):
    return x+y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele =0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

index=dic[ques[0][1]]
update(index,1)
minx=ques[0][1]
minf=0
B=ques[0][2]
count=1
for i in range(1,Q):
    if ques[i][0]==2:
        print(minx,minf+B)
    else:
        a=ques[i][1]
        b=ques[i][2]
        index=dic[a]
        count+=1
        B+=b
        minf+=abs(a-minx)
        update(index,seg[index+num-1]+1)
        start=0
        end=n-1
        while end-start>1:
            test=(end+start)//2
            if query(0,test+1)>=(count+1)//2:
                end=test
            else:
                start=test

        if query(0,start+1)>=(count+1)//2:
            t=start
        else:
            t=end

        if value[t]>minx:
            if count%2==1:
                minf-=value[t]-minx
                minx=value[t]
            else:
                minf-=2*(value[t]-minx)
                minx=value[t]
        elif minx>value[t]:
            if count%2==1:
                minf-=value[t]-minx
                minx=value[t]
            else:
                minx=value[t]


Measured memory_bytes: 133540
#include <iostream>

using namespace std;

long MOD = 1000000007;

int main(){
    int N;
    string s1, s2;
    cin>>N;
    cin>>s1>>s2;

    long ans=1;
    int i = 0;
    bool pre_domino = (s1[i] == s2[i]);
    if(pre_domino == true){
        ans = 3;
        i+=1;
    }else{
        ans = 6;
        i+=2;
    }
    for(;i<N;){
        if(pre_domino == true){
            if(s1[i] == s2[i]){
                ans = ans * 2 % MOD;
                pre_domino = true;
                i+=1;
            }else{
                ans = ans * 2 % MOD;
                pre_domino = false;
                i+=2;
            }
        }else{
            if(s1[i] == s2[i]){
                ans = ans * 1 % MOD;
                pre_domino = true;
                i+=1;
            }else{
                ans = ans * 3 % MOD;
                pre_domino = false;
                i+=2;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	long long q1,b,c1,c2,q2;
	while(cin >> q1 , q1){
		cin >> b >> c1 >> c2 >> q2;
		
		b -= c1 * q2;
		while(b<0){
			b += c1;
			q2--;
		}
		while(q2 + (b/c2) < q1 && q2>0){
			q2--;
			b += c1;
		}
		if(q2 > 0){
			cout << q2 << " " << (b/c2) << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l) for(int i=0;i<l;i++)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define in(x) scanf("%d",&x)
#define out(x) printf("%d\n",x)
const int inf=0x3f3f3f3f;
//vector<int>vec;
int n,k,ans,lim,sum,p,si,mi;
signed main(){
	in(n),in(k);
	vector<int>vec(n);
	
	rep(i,n)in(vec[i]);
	ans=0;
	lim=min(n,k);
	for(int l=0;l<=lim;l++){
		for(int r=0;r<=lim-l;r++){
			sum=0;
			vector<int>t;
			for(int i=0;i<l;i++){
				sum+=vec[i];
				if(vec[i]<0)
				t.push_back(vec[i]);
			}
			for(int i=0;i<r;i++){
				sum+=vec[n-i-1];
				if(vec[n-i-1]<0)
				t.push_back(vec[n-i-1]);
			}
			sort(t.begin(),t.end());
			p=k-(l+r);
			si=t.size();
			mi=min(p,si);
			for(int i=0;i<mi;i++){
				sum-=t[i];
			}
			ans=max(ans,sum);
		}
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1e9;
const int MAX_N = 1500 + 9;
vector<pair<int, int> > g[MAX_N], Path;
int n, m, maxDist;
int dist[MAX_N][MAX_N];
bool used[MAX_N];

void read(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u, v, w;
        cin >> u >> v >> w;
        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }
}

void dijk(int s){
    for(int i = 1; i <= n; i++)
        dist[s][i] = INF;

    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
    dist[s][s] = 0; pq.push(make_pair(dist[s][s], s));
    while(!pq.empty()){
        int du = pq.top().first, u = pq.top().second; pq.pop();

        if(du != dist[s][u])
            continue;

        for(int i = 0, L = g[u].size(); i < L; i++){
            int v = g[u][i].first;
            int w = g[u][i].second;
            if(dist[s][v] > dist[s][u] + w){
                dist[s][v] = dist[s][u] + w;
                pq.push(make_pair(dist[s][v], v));
            }
        }
    }
}

void solve(){
    for(int i = 1; i <= n; i++)
        dijk(i);

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            maxDist = max(maxDist, dist[i][j]);

    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            if(dist[i][j] == maxDist)
                Path.push_back(make_pair(i, j));

    for(int i = 1; i <= n; i++)
        if(!used[i]){
            for(int j = 0, L = Path.size(); j < L; j++){
                int u = Path[j].first, v = Path[j].second;
                if(dist[u][i] + dist[i][v] == dist[u][v]){
                    used[i] = true;
                    break;
                }
            }
        }

    int res = 0;
    for(int i = 1; i <= n; i++)
        if(!used[i])    res++;

    cout << res << '\n';
    for(int i = 1; i <= n; i++)
        if(!used[i])    cout << i << '\n';
}

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



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

int main(){
    int N,L;
    cin >> N >> L;
  
   vector<string>str(N);
  
    for(int i=0; i<N; i++){
        cin>>str.at(i);
     }
    sort(str.begin(),str.end());

    for(int i=0; i<N; i++){
        cout<<str.at(i);
        }
    cout<<endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);
const ll MOD = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    ll n, m; cin >> n >> m;
    vector<bool> x(n, false), y(n, false);
    rep(i, 0, m){
        ll a, b; cin >> a >> b;
        if(a == 1) x[b-1] = true;
        if(b == n) y[a-1] = true;
    }
    bool f = false;
    rep(i, 0, n){
        // cout << x[i] << " " << y[i] << endl;
        if(x[i] && y[i]) f = true;
    }
    if(f) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	
	int n;
	cin >> n;
	vll a(n);
	rep(i,n)cin >> a[i];
	map<int,int> m;
	rep(i,n)m[a[i]]++;

	int all = 0;
	for(auto x:m){
		all += x.se*(x.se-1)/2;
	}
	rep(i,n){
		cout << all - m[a[i]]+1 << endl;
	}


	

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc159.contest.atcoder.jp/tasks/abc159_d

Measured memory_bytes: 12708
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAGIC = 350;

struct edge {
    int u, v;
    bool f;
    long long w;
};

int n, m, nn;
int p[N], P[N], w[N], W[N], U[N], L[N];
long long X[N], wgt[N], Wgt[N];
edge E[N];

bool read() {
    if (!(cin >> n >> m))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> X[i];

    for (int i = 0; i < m; ++i) {
        cin >> E[i].u >> E[i].v >> E[i].w;
        --E[i].u, --E[i].v;
        E[i].f = 1;
    }

    return true;
}

void init_dsu() {
    iota(p, p + n, 0);
    fill(w, w + n, 1);
    fill(U, U + n, 0);
    nn = 0;

    for (int i = 0; i < n; ++i) {
        wgt[i] = Wgt[i] = X[i];
        P[i] = p[i];
        W[i] = w[i];
    }
}

inline void mark(int i) {
    if (!U[i]) {
        U[i] = 1;
        L[nn++] = i;
    }
}

int getp(int v) {
    if (p[v] == v)
        return p[v];

    mark(v);
    return p[v] = getp(p[v]);
}

long long getw(int v) { return wgt[getp(v)]; }

void join(int u, int v) {
    if ((u = getp(u)) == (v = getp(v)))
        return ;

    if (w[u] < w[v])
        swap(u, v);

    p[v] = u;
    w[u] += w[u] == w[v];
    wgt[u] += wgt[v];
    mark(u);
    mark(v);
}

void rollback() {
    for (int j = 0; j < nn; ++j) {
        auto i = L[j];
        U[i] = 0;
        p[i] = P[i];
        w[i] = W[i];
        wgt[i] = Wgt[i];
    }

    nn = 0;
}

void fix() {
    for (int j = 0; j < nn; ++j) {
        auto i = L[j];
        U[i] = 0;
        P[i] = p[i];
        W[i] = w[i];
        Wgt[i] = wgt[i];
    }

    nn = 0;
}

void solve() {
    sort(E, E + m, [](const edge& e1, const edge& e2) {
        return e1.w < e2.w;
    });

    auto ans = 0;

    for (int t = m - 1; t >= 0; --t)
        if (t % MAGIC == 0) {
            auto l = t;
            auto r = min(m - 1, t + MAGIC - 1);
            init_dsu();

            for (int i = 0; i < m; ++i)
                if (i < l || (i > r && E[i].f))
                    join(E[i].u, E[i].v);

            fix();
            auto b = -1;

            for (int i = r; i >= l; --i) {
                if (b == -1)
                    for (int j = l; j <= i; ++j)
                        join(E[j].u, E[j].v);

                if (getw(E[i].u) < E[i].w) {
                    ++ans;
                    E[i].f = 0;
                    rollback();

                    for (int j = i + 1; j <= b; ++j)
                        join(E[j].u, E[j].v);

                    b = -1;
                    fix();
                } else {
                    if (b == -1)
                        b = i;
                }
            }
        }

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 7296
#include<iostream>
using namespace std;
int main()
{
    int x,a,b;
    int a1,b1;
    cin>>x>>a>>b;
    a1=x-a;
    b1=x-b;
    if(a1<0)
    {
        a1=-a1;
    }
    else{a1=a1;}
    if(b1<0)
    {
        b1=-b1;
    }
    else{b1=b1;}
    if(a1<b1)
    cout<<"A"<<endl;
    else
    cout<<"B"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define m (l+r)/2
#define lson k<<1
#define rson k<<1|1
const int mod=998244353;
const int N=2e5+5;
ll tree[N<<2];
ll s[N];
int lzy[N<<2];
void pushdown(int k,int l,int r)
{
    if(lzy[k]==0)return ;
    lzy[lson]=lzy[rson]=lzy[k];
    tree[lson]=((s[m]-s[l-1]+mod)%mod)*lzy[k]%mod;
    tree[rson]=((s[r]-s[m]+mod)%mod)*lzy[k]%mod;
    lzy[k]=0;
    return ;
}
ll query(int k,int ql,int qr,int l,int r)
{
    if(ql<=l&&qr>=r)return tree[k];
    ll res=0;
    pushdown(k,l,r);
    if(ql<=m)
        res+=query(lson,ql,qr,l,m);
    if(qr>m)
        res+=query(rson,ql,qr,m+1,r);
    tree[k]=tree[lson]+tree[rson];
    return res;

}
void modify(int k,int ql,int qr,int l,int r,int val)
{
    if(ql<=l&&r<=qr)
    {
        lzy[k]=val;
        tree[k]=((s[r]-s[l-1]+mod)%mod)*val%mod;
        return ;
    }
    pushdown(k,l,r);
    if(ql<=m)
        modify(lson,ql,qr,l,m,val);
    if(qr>m)
        modify(rson,ql,qr,m+1,r,val);
    tree[k]=(tree[lson]+tree[rson])%mod;
    return ;
}
int main()
{
    int n,q;
    int x,y,z;
    scanf("%d%d",&n,&q);
    s[1]=1;
    for(int i=2;i<=n;i++)
    {
        s[i]=(s[i-1]*10+1)%mod;
    }
    modify(1,1,n,1,n,1);
    while(q--)
    {
        scanf("%d%d%d",&x,&y,&z);
        x=n-x+1;
        y=n-y+1;
        swap(x,y);
        modify(1,x,y,1,n,z);
        printf("%lld\n",tree[1]);
    }
}


Measured memory_bytes: 11476
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def dfs(d,x,c):
        if d <= dp[x]:
            return
        dp[x] = d
        if not f[x]:
            f[x] = c
        for y in v[x]:
            dfs(d-1,y,c)
    n,m = LI()
    f = [0]*n
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    dp = defaultdict(lambda : -1)
    q = I()
    l = LIR(q)
    l = l[::-1]
    for x,d,c in l:
        x -= 1
        dfs(d,x,c)
    for i in f:
        print(i)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 121980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ll n,m,sum;
	cin>>n>>m;
	if(n>m/2) 
	{
		cout<<m/2<<endl;
		return 0;
	}
	sum+=n;
	m-=2*n;
	sum+=m/4;
	cout<<sum;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n=in();
	int i;
	for(i=0;i<n;i++){
		int h,m;
		scanf("%d:%d",&h,&m);
		int dis=abs(h*60-m*11);
		chmin(dis,720-dis);
//cout<<dis<<endl;
		if(dis<60)cout<<"alert"<<endl;
		else if(dis>=180)cout<<"safe"<<endl;
		else cout<<"warning"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0