akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int func(int,int *,int);
int main (){
    int n,s[100001],i,q,t,j,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&t);
        cnt+=func(n,s,t);
    }
    printf("%d\n",cnt);
    return 0;
}

int func(int n,int *s,int key){
    int left=0,right=n,mid;
    while(left<right){
        mid=(left+right)/2;
        if(key==s[mid]){
            return 1;
        }
        if(key>s[mid]){
            left=mid+1;
        }
        else if(key<s[mid]){
            right=mid;
        }
    }
    return 0;
}



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

int main()
{
  int N, X;
  cin >> N >> X;
  
  int cnt = 1, cood = 0;
  for (int i = 0; i < N; ++i)
  {
    int Li;
    cin >> Li;
    
    cood += Li;
    if (cood > X)
    {
      cout << cnt << endl;
      return 0;
    }
    
    ++cnt;
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll n,a,b,c,d;
 sc(n);sc(a);sc(b);sc(c);sc(d);
 char s[n+10];
 sc(s);
 a--;b--;c--;d--;
 if(c<d){
  rep(i,a,d-2){
   if(s[i]=='#'&&s[i+1]=='#'){
    pn;return 0;
   }
  }
  py;return 0;
 }
  
 rep(i,a,c-2){
  if(s[i]=='#'&&s[i+1]=='#'){
   pn;return 0;
  }
 }
 rep(i,b,d-2){
  if(s[i]=='#'&&s[i+1]=='#'){
   pn;return 0;
  }
 } 
 rep(i,b-1,d){
  if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
   py;return 0;
  }   
 }
 pn;
return 0;}

Measured memory_bytes: 3816
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	a := make([]int, N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	for i := 0; i < N; i++ {
		b[i] = getInt()
	}

	sum := 0
	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = a[i] - b[i]
		sum += d[i]
	}

	// out(d, sum)

	if sum < 0 {
		out(-1)
		return
	}

	sort.Ints(d)
	cnt := 0
	pos := len(d)
	rest := 0
	for i := 0; i < N; i++ {
		x := d[i]
		// out(x, rest, "cnt", cnt)
		if x >= 0 {
			// out("break", i)
			cnt += i
			break
		}
		for x < 0 {
			// out("---")
			if rest >= -x {
				rest += x
				break
			} else {
				x += rest
				pos--
				cnt++
				rest = d[pos]
				// out("rest", rest, cnt)
			}
		}
	}
	out(cnt)
}


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

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = n - 1; i >= 0; i--){
        int x = 1;
        while (x <= a[i]) x = (x << 1);
        int ok = - 1;
        int ng = i;
        while (abs(ok - ng) > 1){
            int mid = (ok + ng) / 2;
            if (a[mid] + a[i] <= x) ok = mid;
            else ng = mid;
        }
        if (ok != - 1 && a[ok] + a[i] == x){
            if (a[ok] != int(a[ok])) continue;
            a[ok] += 0.5;
            ans++;
        }
    }
    cout << ans << endl;
}

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

typedef long long int ll;

int main()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;
    ans =  min(a, k);
    k = k - min(a, k);
    k = k - min(b, k);
    ans -= min(c, k);

    cout << ans;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  string o,e;
  cin >> o >> e;
  int n=o.size();
  int m=e.size();
  if(n==m){
     rep(i,n){
        cout << o[i] << e[i];
     }
     cout << endl;
  }
  else if(n>m){
     rep(i,m){
        cout << o[i] << e[i];
     }
     cout << o[n-1] << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fop(i,a,b) for(int i = a;i < b;i++)
using namespace std;
int main(){
	int N,K;
	cin >> N >> K;
	int h[N];
	fop(i,0,N) cin >> h[i];
	int dp[N];
	fop(i,0,N){
		if(i == 0){
			dp[i] = 0;
		}else if(i == 1){
			dp[i] = abs(h[i] - h[i-1]);
		}else{
			dp[i] = INT_MAX;
			fop(j,max(0,i - K),i){
			dp[i] = min(dp[i],abs(h[i] - h[j])+ dp[j]);
		}
		}
	}
	cout << dp[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 4388
# 実装と発想がむずいにぶたん
# というか最初は誰でもO(1)を考えるよなこれ にぶたんはむしろ少数派では
# （実際ほかの解答を見たらみーーーんなatan使ってるし）
# でもこれを見た瞬間やるだけと言ってるヒトはちょっとよくわからん

import math

a, b, x = map(int, input().split())

l, r = 0.0, 90.0
if a * b / 2.0 > (x / a):
    # 半分未満の場合
    while l + 10 ** (-8) < r:
        theta = (l + r) / 2.0
        # 限界まで傾けたときの筒を横から見た時、水の入ってる部分はbを対辺とする直角三角形で、底辺をeとすると
        # tan(theta) = b / e -> e = b / tan(theta)
        # よって面積は (e * b)/2 -> (b/tan(theta)*b)/2
        e = b / math.tan(math.radians(theta))
        s2 = (e * b) / 2.0
        # 比較すべきは台形じゃなくてx/aだった
        if s2 > (x / a):
            l = theta
        else:
            r = theta
else:
    # 半分以上の場合
    while l + 10 ** (-8) < r:
        theta = (l + r) / 2.0
        # 限界まで傾けたときの筒を横から見た時、水の入っていない部分が直角三角形になる
        # 底辺がaなので、対辺をeとすると、tan(theta) = e/a -> e = a * tan(theta)
        # なので三角形の面積は (a * tan(theta) * a)/ 2
        # 同じくラジアンに変換して渡す
        s2 = (a * math.tan(math.radians(theta)) * a) / 2.0
        if (x / a) + s2 < a * b:
            l = theta
        else:
            r = theta
print(l)


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

int main(){
  long a,b,c,answer;
  cin >> a >> b;
  if((a+b)%2 == 0){
    cout << (a+b)/2 << endl;
  }
  else
    cout << "IMPOSSIBLE" << endl;
}
             
            
          
      
    


Measured memory_bytes: 256
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	int p,q,m;
	cin >> p >> q >> m;
	int a[p],b[q];
	int a1=INT_MAX;
	int b1=INT_MAX;
	for(int i = 0 ; i< p ;i++ ){
		cin >> a[i];
		a1 = min(a[i],a1);
	}
	for(int j = 0 ; j <q ; j++ ){
		cin >> b[j];
		b1 = min(b[j],b1);
	}
	int ans = INT_MAX;
	for(int i = 0 ; i < m ; i++ ){
		int x,y,z;
		cin >> x >> y >> z;
		x--;
		y--;
		ans = min({ans,a[x]+b[y]-z,a1+b1});
	}
	cout<<ans;
	
}


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

int main(){
  int N,k;
  cin>>N;
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin>>X.at(i);
  }
  sort(X.begin(),X.end());
  int mini=1000000000;
  for(int i=X.at(0); i<=X.at(N-1); i++){
    int c=0;
    for(int j=0; j<N; j++){
      k=abs(i-X.at(j));
      k*=k;
      c+=k;
    }
    mini=min(mini,c);
  }
  cout<<mini<<endl;
}

Measured memory_bytes: 3640
str = input()
count = 0
first_half, second_half = str[:len(str)//2], str[(len(str)+1)//2:]
if first_half == reversed(second_half):
    print(count)
else:
    for x in range(len(first_half)):
        if first_half[x] != second_half[len(second_half)-x-1]:
            count += 1
    print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;
  ll k;
  cin >> k;

  ll n = s.length();
  ll res = 0;
  char prev1 = '$';
  ll cnt = 0;
  for (ll i = 0; i < s.length(); i++) {

    if (s[i] == prev1) {
      cnt++;
    } else {
      res += (cnt / 2);
      prev1 = s[i];
      cnt = 1;
    }
  }
  if (cnt == n) {
    ll len = n * k;
    cout << (len / 2) << en;
    return 0;
  }

  res += (cnt / 2);

  if (k != 1) {

    if (s[n - 1] != s[0]) {
      res *= k;
    } else {
      if (cnt & 1) {

        ll cnt1 = 0;
        ll res2 = 1;
        char prev1 = '$';
        for (ll i = 1; i < s.length(); i++) {

          if (s[i] == prev1) {
            cnt1++;
          } else {
            res2 += (cnt1 / 2);
            prev1 = s[i];
            cnt1 = 1;
          }
        }
        res2 += (cnt1 / 2);

        res = res + res2 * (k - 1);
      } else {
        res *= k;
      }
    }
  }

  cout << res << en;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;

int main()
{
	while (1)
	{
		int n, m, p;
		cin >> n >> m >> p;
		if (n == 0) return 0;

		vi x(n);
		rep(i, 0, n) cin >> x[i];

		int sum = 0;
		rep(i, 0, n) sum += x[i];

		int ans;
		if (n < m)
			ans = 0;
		else
		{
			if (x[m - 1] == 0)
				ans = 0;
			else
				ans = sum * 100 * (100 - p) / 100 / x[m - 1];
		}
		cout << ans << endl;
		
	}
}

Measured memory_bytes: 2992
#include <iostream>

using namespace std;

int main() {
	int h, w, i, j;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	
	return 0;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool isprime(llint x){
	if(x<2)return false;
	else if(x==2)return true;
	else if(x%2==0)return false;
	else{
		for(int i=3;i*i<=x;i+=2){
			if(x%i==0)return false;
		}
	}
	return true;
}

void solve(){
	llint n;
	cin >> n;
	while(!isprime(n))n++;
	cout << n << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	A
# CreatedDate:  2020-02-22 17:51:25 +0900
# LastModified: 2020-02-22 20:24:45 +0900
#


import os
import sys
import heapq
def initial_signal(i,N):
    d = [float("inf") for _ in range(N)]
    d[i] = 0
    Q = []
    heapq.heappush(Q,(0,i))
    return d, Q

def dijkstra(i,adj,N):
    d,Q = initial_signal(i,N)
    while Q:
        u_value,u = heapq.heappop(Q)
        for v_value,v in adj[u]:
            if d[v]>d[u]+v_value:
                d[v]=d[u]+v_value
                heapq.heappush(Q,(d[v],v))
    print(d[-1])



def main():
    N = int(input())
    h = list(map(int,input().split()))
    adj = [[] for _ in range(N)]
    for i in range(N-2):
        adj[i].append((abs(h[i+1]-h[i]),i+1))
        adj[i].append((abs(h[i+2]-h[i]),i+2))
    adj[N-2].append((abs(h[N-1]-h[N-2]),N-1))
    dijkstra(0,adj,N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 48200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c=0,d=0;
  cin>>a>>b;
  if(a>b)c=b/2;
  if(a<b)c=a/2;
  for(int i=1;i<=c;i++){
    if(a%i==0&&b%i==0){
      d=i;
    }
  }
  if(a==b){
    cout<<a<<endl;
  }else {
cout <<d<<endl;
  }
  return 0;
}

Measured memory_bytes: 3088
//By Vlgd
#include<bits/stdc++.h>
#define EPS (1e-10)
#define equals(a,b) fabs((a)-(b))<EPS
using namespace std;
class Point{
public:
	double x,y;
	Point(double x=0,double y=0):x(x),y(y){}
	Point operator +(Point p){return Point(x+p.x,y+p.y);}
	Point operator -(Point p){return Point(x-p.x,y-p.y);}
	Point operator *(double a){return Point(a*x,a*y);}
	Point operator /(double a){return Point(x/a,y/a);}
	double norm(){return x*x+y*y;}
	double abs(){return sqrt(norm());}
	bool operator <(const Point &p){
		return x!=p.x?x<p.x:y<p.y;
	}
	bool operator ==(const Point &p){
		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
	}
};
class Circle{
public:
	Point c;
	double r;
	Circle(Point c=Point(),double r=0):c(c),r(r){}
};
typedef Point Vector;
struct Segment{Point p1,p2;};
typedef Segment Line;
int intersection(Circle c1,Circle c2){
	double dis=(c1.c-c2.c).abs();
	double R=c1.r+c2.r;
	if(dis>c1.r+c2.r) return 4;
	if(dis==c1.r+c2.r) return 3;
	if(dis>fabs(c1.r-c2.r)) return 2;
	if(dis==fabs(c1.r-c2.r)) return 1;
	else return 0; 
}
main(){
	int cx,cy,r;
	scanf("%d%d%d",&cx,&cy,&r);
	Point p1(cx,cy);
	Circle c1(p1,r);
	scanf("%d%d%d",&cx,&cy,&r);
	Point p2(cx,cy);
	Circle c2(p2,r);
	printf("%d\n",intersection(c1,c2));
} 


Measured memory_bytes: 3228
import java.util.*;

public class Main {
    static int max = 1000000;
    static int[] queue = new int[max];
    static int tail = 0; static int head = 0;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        init();
        int n = sc.nextInt();
        int m = sc.nextInt();
        HashMap<Integer,TreeSet<Integer>> graph = new HashMap<>();
        for (int i=1;i<=n;i++)graph.put(i,new TreeSet<Integer>());
        for (int i=0;i<m;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        //int[] depth = new int[n+1];
        //depth[1] = 0;
        boolean[] seen = new boolean[n+1];
        for (int i=0;i<=n;i++)seen[i]=false;
        enqueue(1);
        //int count = 1;
        int[] flag = new int[n+1];
        while (!isEmpty()){
            int v = dequeue();
            for (int a : graph.get(v)){
                if (!seen[a]){
                    seen[a]=true;
                    //depth[a]=count;
                    flag[a]=v;
                    enqueue(a);
                }
            }
            //count++;
        }
        System.out.println("Yes");
        for (int i=2;i<=n;i++)System.out.println(flag[i]);
    }

    static void init(){head = 0; tail = 0;}
    static boolean isEmpty(){return (head==tail);}
    static boolean isFull(){return (head == (tail+1)%max);}
    static public void enqueue(int v){
        if (isFull()){
            System.out.println("error: queue is full.");
            return;
        }
        queue[tail++] = v;
        if (tail == max) tail = 0;
    }
    static public int dequeue(){
        if (isEmpty()){
            System.out.println("error: queue is empty");
            return -1;
        }
        int res = queue[head];
        ++head;
        if (head == max) head = 0;
        return res;
    }
}


Measured memory_bytes: 100316
inp = input()
part1 = inp[0:int((len(inp)-1)/2)]
part2 = inp[int((len(inp)+1)/2):]


def isParin(S):
    n = len(S)
    flg = 0
    for i in range(int(n/2)):
        if S[i] != S[n-1-i]:
            flg += 1
    if flg == 0:
        return True
    else:
        return False


if isParin(inp):
    if part1 == part2:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3060
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [LIST() for i in range(N)]

match_id = [[0] * N  for i in range(N)]


cnt = 0
for i in range(N):
    for j in range(N):
        if i < j:
            match_id[i][j] = cnt
            cnt += 1

def toid(i, j):
    if i > j:
        i, j = j, i
    return match_id[i][j]

V = N * (N - 1) // 2
gout = [[] for _ in range(V)]
deg = [0] * V
for i in range(N):
    for j in range(N - 2):
        gout[toid(i, A[i][j]-1)].append(toid(i, A[i][j+1]-1))
        deg[toid(i, A[i][j+1]-1)] += 1

topo = [v for v in range(V) if deg[v] == 0]
day = [0] * V
q = deque(topo)
ans = 0
while q:
    v = q.popleft()
    for t in gout[v]:
        deg[t] -= 1
        if deg[t] == 0:
            q.append(t)
            day[t] = day[v] + 1
            ans = day[t]
if any(deg):
    # まだ1とかがある
    print(-1)
    exit()
print(ans + 1)










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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n)cin>>a[i];
	
	SORT(a); REV(a);
	ll ans = 0;
	ans += a[0];
	int count = 1;
	int now = 1;
	int pl = 0;
	while(count <= n-2){
		ans += a[now];
		pl++;
		if(pl == 2){
			pl = 0;
			now ++;
		}
		count ++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4752
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    if (N%2 == 1 || N/10 == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll sum0 = 0;
    for (ll i=10; i<=N; i*=5) {
        sum0 += N/i;
    }
    cout << sum0 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
K,S=map(int,input().split())
z=list(range(K+1))
ans=[]
for i in z:
  s_z=S-i
  if s_z<0:
    pass
  elif K<s_z:
    if (K+1)>(s_z-K):
      ans.append(2*K-s_z+1)
  else:
    ans.append(s_z+1)
print(sum(ans))

Measured memory_bytes: 3316
a=list(input().split(" "))
N=int(a[0])
M=int(a[1])

A=list(input().split(" "))
A = [int(i) for i in A]
goukei=0
for i in range(len(A)):
    goukei+=A[i]

if N-goukei >= 0:
    print(N-goukei)
else:
    print(-1)

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

int main()
{
    long long A, B, K;
    cin >> A >> B >> K;
    if (K > 1000000)
    {
        long long A1 = A - K;
        long long K1 = K - A;
        long long B1 = B;
        if (K1 > 0)
        {
            B1 = B - K1;
        }
        if (A1 < 0)
        {
            A1 = 0;
        }
        if (B1 < 0)
        {
            B1 = 0;
        }
        cout << A1 << " " << B1 << endl;
    }

    if (K <= 1000000)
    {
        for (long long i = 0; i < K; i++)
        {
            if (A > 0)
            {
                A--;
            }
            else if (A == 0 && B > 0)
            {
                B--;
            }
            else if (A == 0 && B == 0)
            {
                break;
            }
        }
        cout << A << " " << B << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long I, O, T, J, L, S, Z, ans = 0;
    cin >> I >> O >> T >> J >> L >> S >> Z;
    ans += O + (I & ~1) + (J & ~1) + (L & ~1);
    if ((I&1) && (J&1) && (L&1)) ans += 3;
    else if ((I&1) && (J&1) && L) ans += 1;
    else if ((J&1) && (L&1) && I) ans += 1;
    else if ((L&1) && (I&1) && J) ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i=(int)s;i<(int)n;i++)
int main() {
  int n,d,x[15][15],c=0; cin>>n>>d;
  rep(i,0,n) rep(j,0,d) cin>>x[i][j];
  rep(j,0,d) x[n][j]=x[0][j];
  rep(i,0,n){
    rep(j,i+1,n){
      double dis=0;
      rep(k,0,d) dis+=pow(abs(x[i][k]-x[j][k]),2);
      dis=sqrt(dis);
      if(dis==(int)dis) c++;
    }
  }
  cout<<c;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,ans=0;
  cin>>n;
  vector<int>a(n),b(n);
  rep(i,n){
    int x;
    cin>>x;
    a.at(i)=x;
  }
  rep(i,n){
    int x;
    cin>>x;
    b.at(i)=x;
  }
  rep(i,n){
    int cnt=0;
    rep(j,i+1){
      cnt+=a.at(j);
    }
    for (int k=i; k<n; k++) {
      cnt+=b.at(k);
    }
    if (cnt>ans) {
      ans=cnt;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    L = pow(2, N)
    Dist = [10 ** 20] * L
    
    Dist[0] = 0
    for _ in range(M):
        a, b = map(int, input().split())
        bit = 0
        C = [int(c) for c in input().split()]
        for c in C: bit += pow(2, c-1)
        for k in range(L):
            if Dist[k] < 10 ** 20: Dist[k | bit] = min(Dist[k | bit], Dist[k] + a)
    if Dist[L - 1] == 10 ** 20: print(-1)
    else: print(Dist[L - 1])



    return 0

if __name__ == "__main__":
    solve()

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 1e9  //
#define INFLL 4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define PB(a) push_back(a)
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

// a 0x61  z 0x7a  0 0x30

//------------------------------------------------------

int main() {
    int h, w;
    cin >> h >> w;

    int d[10][10];

    rep(i, 10) {

        rep(j, 10) {
            int c;
            cin >> c;
            d[i][j] = c;
        }
    }

    rep(k, 10) {

        rep(i, 10) {

            rep(j, 10) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int sum = 0;

    rep(i, h) {

        rep(j, w) {
            int a;
            cin >> a;
            if (a != -1) {
                sum += d[a][1];
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
	int n;
	std::cin >> n;
	switch (n){
	case 111:
		std::cout << 999;
		break;
	case 119:
		std::cout << 991;
		break;
	case 191:
		std::cout << 919;
		break;
	case 199:
		std::cout << 911;
		break;
	case 911:
		std::cout << 199;
		break;
	case 919:
		std::cout << 191;
		break;
	case 991:
		std::cout << 119;
		break;
	case 999:
		std::cout << 111;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
open Batteries;;

let rec card : int -> int -> int list -> int =fun a b l ->
  match l with
  | [] -> abs (a-b)
  | e :: rest ->
     card b (a+e) rest
    in
    
  let _ = read_line () in
  let lista = read_line () |> String.split_on_char ' ' |> List.map int_of_string in
  let l = List.rev(List.sort (Pervasives.compare) lista) in
  let diff = card 0 0 l in
  print_int diff
;;


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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    ll n,m; cin >> n >> m;
    VVL G(n+1);

    rep(i,m){
        ll a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<ll> q;
    vector<bool> seen(n+1, false);
    ll max = 0;

    rep2(i,1,n+1){
        if(seen[i]) continue;

        seen[i] = true;
        q.push(i);
        ll cnt = 1;

        while(!q.empty()){
            ll v = q.front();
            q.pop();

            for(auto w : G[v]){
                if(seen[w]) continue;
                seen[w] = true;
                q.push(w);
                cnt++;
            }
        }

        chmax(max, cnt);
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 16880
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
// computes 2 * area of the triangle p0-p1-p2
template <typename T>
T area2(const pair<T,T> p0, const pair<T,T> p1, const pair<T,T> p2) {
  return (p1.first - p0.first) * (p2.second - p0.second) - (p2.first - p0.first) * (p1.second - p0.second);
}
// computes 2 * area of the polygon
template <typename T>
T area2(const vector<pair<T,T>> &ps) {
  T x = 0;
  pair<T,T> zero(0,0);
  int n = ps.size();
  for(int i = 0; i < n; i++) {
    x += area2(zero, ps[i], ps[(i+1)%n]);
  }
  return x;
}
int main(int argc, char *argv[])
{
  for(int t = 1;; t++) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<pair<int,int>> ps;
    for(int i = 0; i < n; i++) {
      int x, y;
      cin >> x >> y;
      ps.push_back(make_pair(x,y));
    }
    int a2 = abs(area2(ps));
    cout << t << " " << (a2/2) << ((a2&1) ? ".5" : ".0") << endl;
  }
  return 0;
}

Measured memory_bytes: 3076
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
    if(v.empty()){
        os<<"{ }";
        return os;
    }
    os<<"{"<<v.front();
    for(auto itr=++v.begin();itr!=v.end();itr++){
        os<<", "<<*itr;
    }
    os<<"}";
    return os;
}

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int a; cin>>a;
    cout<<1-a<<endl;
}


Measured memory_bytes: 3632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            UnionFind uf = new UnionFind(n);

            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                int com = in.nextInt();
                int x = in.nextInt();
                int y = in.nextInt();

                if (com == 0) {
                    uf.union(x, y);
                } else {
                    out.println(uf.isConnected(x, y) ? 1 : 0);
                }
            }
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }

    static class UnionFind {
        int[] parent;

        public UnionFind(int size) {
            parent = new int[size];
            Arrays.fill(parent, -1);
        }

        public boolean union(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                if (parent[y] < parent[x]) {
                    int tmp = y;
                    y = x;
                    x = tmp;
                }
                parent[x] += parent[y];
                parent[y] = x;
                return true;
            }
            return false;
        }

        public boolean isConnected(int x, int y) {
            return root(x) == root(y);
        }

        public int root(int x) {
            return parent[x] < 0 ? x : (parent[x] = root(parent[x]));
        }

        public String toString() {
            return Arrays.toString(parent);
        }

    }
}

Measured memory_bytes: 58908
import java.util.Arrays;
import java.util.Scanner;
class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力


		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] A = new int[n];
		Pair[] pairs = new Pair[m];
	
		for(int i = 0;i < n;i++){
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		
		for(int i = 0;i < m;i++){
			Pair pair = new Pair();
			pair.from = sc.nextInt();
			pair.end = sc.nextInt();
			pairs[i] = pair;
		}
		Arrays.sort(pairs);
//		
//		for(int i = 0;i < m;i++){
//			System.out.println(pairs[i].end);
//		}
//		System.out.println();
		
		int index = 0;
		for(int i = 0;i < m;i++){
			int candidate = pairs[i].end;
			for(int j = 0;j < pairs[i].from;j++){
				if(A[index] < candidate){
					A[index] = candidate;
					index++;
					if(index >= n){
						allsum(A);
						return;
					}
	 			}else{
	 				break;
	 			}
			}	
		}
		
		allsum(A);
		
		
		

		
		
	}
	
	static void allsum(int[] A){
		long ans = 0;
		for(int i = 0;i < A.length;i++){
//			System.out.println(A[i]);
			ans += A[i];
		}
		System.out.print(ans);
	}


	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
}




Measured memory_bytes: 92072
n,*a = map(int,open(0).read().split())
b = [0]*(n+1)
for x in range(n,0,-1):
	b[x] = (sum(b[x::x])+a[x-1])%2
print(b.count(1))
for i in range(n+1):
	if b[i]:
		print(i,end=" ")

Measured memory_bytes: 8392
import copy


class Dice:
    def __init__(self, eyes: [int]):
        self.__eyes = eyes

    def top(self):
        return self.__eyes[0]

    def right(self):
        return self.__eyes[2]

    def roll_s(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[4]
        tmp[1] = self.__eyes[0]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[5]
        tmp[5] = self.__eyes[1]
        self.__eyes = tmp

    def roll_e(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[3]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[0]
        tmp[3] = self.__eyes[5]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[2]
        self.__eyes = tmp

    def roll_n(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[1]
        tmp[1] = self.__eyes[5]
        tmp[2] = self.__eyes[2]
        tmp[3] = self.__eyes[3]
        tmp[4] = self.__eyes[0]
        tmp[5] = self.__eyes[4]
        self.__eyes = tmp

    def roll_w(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[2]
        tmp[1] = self.__eyes[1]
        tmp[2] = self.__eyes[5]
        tmp[3] = self.__eyes[0]
        tmp[4] = self.__eyes[4]
        tmp[5] = self.__eyes[3]
        self.__eyes = tmp

    def turn_right(self):
        tmp = copy.copy(self.__eyes)
        tmp[0] = self.__eyes[0]
        tmp[1] = self.__eyes[3]
        tmp[2] = self.__eyes[1]
        tmp[3] = self.__eyes[4]
        tmp[4] = self.__eyes[2]
        tmp[5] = self.__eyes[5]
        self.__eyes = tmp

    def adjust_top(self, top: int):
        for _ in range(4):
            if self.top() is top:
                break
            self.roll_e()
        for _ in range(4):
            if self.top() is top:
                break
            self.roll_s()

    def adjust_front(self, front: int):
        for _ in range(4):
            if self.front() is front:
                break
            self.turn_right()

    def front(self):
        return self.__eyes[1]

    def roll(self, direction: str):
        if direction == 'N':
            self.roll_n()
        if direction == 'E':
            self.roll_e()
        if direction == 'S':
            self.roll_s()
        if direction == 'W':
            self.roll_w()


def resolve():
    eyes = list(map(int, input().split()))
    n = int(input())

    for _ in range(n):
        dice = Dice(eyes)
        top, front = map(int, input().split())
        dice.adjust_top(top)
        dice.adjust_front(front)
        print(dice.right())


resolve()



Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
int main() {
  int k=0, s=0, ans=0;
  cin >> k >> s;
  
  
  rep (i, k+1){
    for (int j=i; j<k+1; ++j){
      for (int l=j; l<k+1; ++l){
        
        if (i+j+l == s) {
          if (i == j || j ==l || i==l) {
            if (i==j && j==l) ++ans;
            else ans += 3;
          }
          else ans += 6;
          
        }
        
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
// ================
// Himanshu Lal
// MNIT Jaipur
// ================
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define INF 1e18
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll tp; cin>>tp; while(tp--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
void OJ(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
}
int main(){
    ll a,b;
    cin>>a>>b;
    ll mx=a*4,mn=a*2;
    if(mx<b or (b%2==1) or b<mn){
        cout<<"No";
    }else{
        cout<<"Yes";
    }
}

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

int mod = 1000000007;
long long dp[100005];;

long long gcd(long long a,long long b){

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

int main(){

 long long a,b;
 cin>>a>>b;

 if(a>0 && b>0)
    cout<<"Positive"<<endl;
 else if(a<0 && b>0)
    cout<<"Zero"<<endl;
 else if(a<0 && b<0) {

    a = -1*a;
    b = -1*b;

    long long diff = (a-b)+1;

   // cout<<diff<<endl;

    if(diff %2 == 1)
        cout<<"Negative"<<endl;
    else
       cout<<"Positive"<<endl;
 }


return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x>>s>>y;
	if(s=="+") cout<<x+y<<endl;
	else cout<<x-y<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

bool compare(const P& e1, const P& e2) {
    return(e1.second > e2.second);
}

int main(void) {
    int num, score;
    vector<P> v;
    map<int, int> m;
    while(scanf("%d,%d", &num, &score), num||score) {
        v.push_back(P(num, score));
    }
    sort(v.begin(), v.end(), compare);
    
    int rank = 0, before = -1;
    for(int r = 0; r < v.size(); r++) {
        if(v[r].second != before) rank++;
        before = v[r].second;
        m[v[r].first] = rank;
        //if(r + 1 < v.size() && v[r].second != v[r + 1].second) rank++;
    }
    int n;
    while(cin >> n) {
        cout << m[n] <<endl;
    }
    return(0);
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
    long long k; cin >> k;
    long double res = 100;
    int cnt = 0;
    while(res < k) {
        res *= 1.01;
        res = floor(res);
        cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
  int a[3];
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  sort(a, a+3);
  int da = a[1] - a[0];
  int db = a[2] - a[1];
  if (da % 2 == 0) {
    int ans = da/2 + db;
    printf("%d", ans);
  } else {
    int ans = da/2 + 2 + db;
    printf("%d", ans);
  }
  //printf("%d %d %d" ,a[0], a[1], a[2]);
  return 0;
}


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

ll mod = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<ll> dp(N+1, 0);
    dp[0] = 1;
    vector<int> pre(200001, -1);
    for (int i = 1; i <= N; i++) {
        int C;
        cin >> C;
        dp[i] += dp[i-1];
        if (pre[C] >= 1 && pre[C] <= i-2) dp[i] += dp[pre[C]];
        dp[i] %= mod;
        pre[C] = i;
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;
ll cnt[maxn];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	vector<ll>a(n);
	for (ll i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;

	ll ans = 0;
	for (ll i = 0; i < maxn; i++) ans += (cnt[i] * (cnt[i] - 1)) / 2;

	for (ll x : a) {
		ans -= (cnt[x] * (cnt[x] - 1)) / 2;
		cnt[x] --;
		ans += (cnt[x] * (cnt[x] - 1)) / 2;
		cout << ans << "\n";
		ans -= (cnt[x] * (cnt[x] - 1)) / 2;
		cnt[x] ++;
		ans += (cnt[x] * (cnt[x] - 1)) / 2;
	}



	return 0;
}

/*
5
2 6 15 5 10

4
2 6 15 5

*/

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define X first
#define Y second

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


char *p;
string s;



int calc(){
	if('0' <= p[0] && p[0] <= '9'){
		int v=0;
		for(; p[0] != ']'; ++p){
			v = v*10 + p[0] - '0';
		}
		return v/2+1;
	}
	vector<int> c;
	p++;
	for(;;){
		int v = calc();
		c.push_back(v);
		if(p[0] == ']') break;
	}
	p++;
	sort(c.begin(), c.end());

	int ret = 0;
	rep(i, (c.size()+1)/2 ){
		ret += c[i];
	}
	return ret;
}



int main(){
	int TT;
	cin >> TT;
	rep(T,TT){
		cin >> s;
		p = &(s[0]);
		cout << calc() << endl;



	}



	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define rep(N) for(int i=0;i<N;i++)
#define repj(N) for(int j=0;j<N;j++)
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define For(I,N) for(int I=0;I<N;I++)
#define cinone(N) int N;cin>>N;
#define scanfone(N) int N;cin>>N;
#define cinng(N,M) int N[M];for(int yiuytvnm=0;yiuytvnm<M;yiuytvnm++) cin>>N[yiuytvnm];
#define scanfng(N,M) int N[M];for(int qrwuoiq=0;qrwuoiq<M;qrwuoiq++) scanf("%d",&N[qrwuoiq]);
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int n;
char c[200005];

int main()
{
//	freopen("input.txt","r",stdin);
	scanf("%s",c);
	n=strlen(c);
	ll res=0;
	int sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=(c[i]=='B');
		res+=(c[i]=='W')*sum;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int n,x[2]={0};
  char s[101];
  scanf("%d",&n);
  scanf("%s",s);
  for(int i=0;i<n;i++){
    if(s[i] == 'I') x[0]++;
    else x[0]--;
    if(x[0]>x[1]) x[1]=x[0];
  }
  printf("%d\n",x[1]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
int main(){
    string s;
    cin >> s;
    ll q;
    cin >> q;
    ll temp,f;
    string c;
    vector<string>mae;
    vector<string>ushiro;
    ll iti;
    ll dotti = 1;
    string ans;
    //<queue>mae;
    //<stack>
    for(ll i = 0; i < q; i++){
        cin >> temp;
        if(temp == 1){
            dotti *= -1;
        }
        else{
            cin >> f;
            if(f==1){
                cin >> c;
                if(dotti == 1)mae.emplace_back(c);
                else ushiro.emplace_back(c);
            }
            else{
                cin >> c;
                if(dotti == -1)mae.emplace_back(c);
                else ushiro.emplace_back(c);

            }
        }
    }
    //if(dotti = -1)
    
   /*for(ll i = 0; i < q; i++){
       cin >> temp;
       if(temp == 1){
           string t(s.rbegin(),s.rend());
         s == t;
       }
       else{
           cin >> f;
           if(f == 1){
               cin >> c;
               string p  =c+s;
               s = p;
           }
           else if(f == 2){
               cin >> c;
               s += c;
           } 
       }
   }*/

   if(dotti == 1){
       for(ll i = mae.size()-1; i >= 0; i-- ){
           cout << mae[i];
       }
       for(ll i = 0; i < s.size(); i++){
           cout << s[i];
       }
       for(ll i = 0; i < ushiro.size(); i++){
           cout << ushiro[i];
       }
   }
   else{
       for(ll i = ushiro.size()-1; i >= 0; i-- ){
           cout << ushiro[i];
       }
       for(ll i = s.size()-1; i >= 0; i--){
           cout << s[i];
       }
       for(ll i = 0; i < mae.size(); i++){
           cout << mae[i];
       }

   }


}

Measured memory_bytes: 11760
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int i, n, x[100], y[100];
int distance(int k);int distance_infinit(void);

int main(void){
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    for (i = 0; i < n; i++){
        scanf("%d", &y[i]);
    }
    distance(1);
    distance(2);
    distance(3);
    distance_infinit();
    return 0;
}

int distance(int k){
    double sum = 0;
    for (i = 0; i < n; i++){
        sum += pow(fabs(x[i] - y[i]), k);
    }
    printf("%f\n", pow(sum, 1.0/k));
    return 0;
}

int distance_infinit(void){
    int max = 0;
    for (i = 0; i < n; i++){
        if (fabs(x[i] - y[i]) > max) max = fabs(x[i] - y[i]);
    }
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 3380
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(long long *)a>*(long long *)b)return 1;
    return -1;
}
int main(int argc, const char * argv[]) {
    int n;
    scanf("%d",&n);
    long long a[n];
    double ap[n];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        ap[i]=(double)a[i];
    }
    qsort(a,n,sizeof(long long),compare);
    if(a[0]==0){
        printf("0");
        return 0;
    }
    double t=ap[n-1];
    for(int i=n-2;i>=0;i--){
        t*=ap[i];
        if(t>1000000000000000000){
            printf("-1");
            return 0;
        }
    }
    unsigned long long ans=1;
    for(int i=0;i<n;i++){
        ans*=a[i];
    }
    if(ans>1000000000000000000){
        printf("-1");
    }else{
        printf("%lld",ans);
    }return 0;
}


Measured memory_bytes: 3896