akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		int n = Console.ReadLine().ToInt();
		var a = Input().ToInt();
		long rightsum = 0;
		for(int i = 0; i < n; i++)
			rightsum += a[i];
			
		long leftsum = 0;
		
		long min = 9999999999;
		for(int i = 0; i < n-1; i++)
		{
			leftsum += a[i];
			rightsum -= a[i];
			min = Math.Min(min, Math.Abs(leftsum - rightsum));
		}
		
		Console.WriteLine(min);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		int[] r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
	
}

Measured memory_bytes: 31452
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin, (x).end
#define sz(x) (int)(x).size()
#define rep1(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define get4(_1, _2, _3, _4, ...) _4
#define rep(...) get4(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long double a, b, x;
  cin >> a >> b >> x;
  long double h = x / (a * a);
  long double ans;
  if (h >= (b / 2)) {
    ans = atan(2 * (b - h) / a) * 180 / M_PI;
  } else {
    ans = atan(b / (2 * x / (a * b))) * 180 / M_PI;
  }
  cout << fixed << setprecision(15) << ans << '\n';
  return 0;
}


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

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

int main()
{
  int w, h;
  while (cin >> w >> h) {
    if ((w|h) == 0)
      break;

    int xs, ys, xg, yg;
    cin >> xs >> ys >> xg >> yg;
    --xs;
    --ys;
    --xg;
    --yg;

    int c;
    cin >> c;
    vector<vector<int> > block(h, vector<int>(w, -1));
    for (int i = 0; i < c; ++i) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      --x;
      --y;

      if (d == 0) {
	for (int j = 0; j < 4; ++j)
	  block[y][x+j] = block[y+1][x+j] = c;
      } else {
	for (int j = 0; j < 4; ++j)
	  block[y+j][x] = block[y+j][x+1] = c;
      }
    }

    string ans = "NG";
    queue<pair<int, int> > que;
    que.push(make_pair(xs, ys));
    vector<vector<int> > visited(h, vector<int>(w, 0));
    while (!que.empty()) {
      const pair<int, int> p = que.front();
      que.pop();

      if (p.second == yg && p.first == xg) {
	ans = "OK";
	break;
      }

      if (visited[p.second][p.first])
	continue;
      visited[p.second][p.first] = 1;

      for (int d = 0; d < 4; ++d) {
	int x = p.first + dx[d];
	int y = p.second + dy[d];
	if (x < 0 || w <= x || y < 0 || h <= y ||
	    block[p.second][p.first] != block[y][x] || visited[y][x])
	  continue;
	que.push(make_pair(x, y));
      }
    }

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

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

using namespace std;
using ll = long long;
const int mod = 998244353;

int fact[300010];

int myPow(int a, int r){
    if(r == 0) return 1;
    int half = myPow(a, r / 2);
    if(r & 1) return half * 1ll * half % mod * a % mod;
    else return half * 1ll * half % mod;
}

int comb(int n, int r){
    return fact[n] * 1ll * myPow(fact[r], mod - 2) % mod * myPow(fact[n - r], mod - 2) % mod;
}

int main(){
    int n, a, b, ans = 0;
    ll k;
    cin >> n >> a >> b >> k;

    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i - 1] * 1ll * i % mod;

    for(int x = 0; x <= n; x++){
        ll left = (k - a * 1ll * x);
        if(left % b != 0) continue;
        ll y = left / b;
        if(y > n || y < 0) continue;

        ans = (ans + comb(n, x) * 1ll * comb(n, y)) % mod;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;


int main() {
    int N;
    cin>>N;
    
    vector<int> v(N);
    for(int i=0;i<N;i++){
        cin>>v[i];
    }

    int ans = 100000000;
    for(int i=1;i<N;i++){
        int sum = accumulate(v.begin(), v.begin()+i, 0);
        int sum2 = accumulate(v.begin()+i, v.end(), 0);    
        ans = min(ans, abs(sum-sum2));
    }
    cout<<ans<<endl;
}


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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

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

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

    int cnt = b / k - (a - 1) / k;
    if (cnt) cout << "OK";
    else cout << "NG";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
using P = pair <int, int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<ll> T(n);
    rep(i,n) cin >>T[i];
    int m;
    cin >>m;
    vector<pair<ll,ll>> x(m);
    ll tot =0;
    rep(i,n)  tot+=T[i];
    rep(i,m) {
        ll a,b;
        cin >> a>>b;
        cout << tot - T[a-1] +b << endl;
    }
}

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

int n;

int dist(int i, int j) {
    int ans = j-i;
    if (ans <= 0) ans += n;
    return ans;
}

int mid(int i, int j) {
    auto d = dist(i,j);
    return (i+d/2)%n;
}

int ask(int i) {
    cout << i << endl;
    string ans; cin >> ans;
    if (ans[0] == 'V') exit(0);
    return string("MF").find(ans[0]);
}

int main() {
    cin >> n;
    int lo = 0, hi = 0;
    int vl = ask(0), vh = vl;
    while (true) {
        auto mi = mid(lo,hi);
        auto vm = ask(mi);
        if ((lo+vl+mi+vm)%2) {
            hi = mi, 
            vh = vm;
        }
        else {
            lo = mi;
            vl = vm;
        }
    }
    return 0;
}


Measured memory_bytes: 852
N = int(input())
A = [0]*(N+1)
B = [0]*N
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = int(0)
maxans = int(0)

for i in range(N+1):
    maxans += A[i]

for i in range(N):
    if A[i]>=B[i]:
        A[i] -=B[i]
    else:
        if A[i+1]+A[i]>=B[i]:
            A[i + 1] = A[i + 1] - (B[i] - A[i])
            A[i] = 0
        else:
            A[i] = 0
            A[i+1]= 0


for i in range(N+1):
    ans += A[i]

ans = maxans - ans

print(ans)



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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
const ll Mod = 1e9+7;
int n,m;
ll dp[1011][1011];
char a[1011][1011];

ll Solve(int i=0,int j=0)
{
    if(i > n || j > m || a[i][j]=='#')
        R 0;
    if(i == n-1 && j == m-1)
        R 1;

    ll &Res = dp[i][j];

    if(dp[i][j] != -1)
        R dp[i][j];

    Res = Solve(i+1,j);
    Res += Solve(i,j+1);

    Res = ((Res%Mod)+Mod)%Mod;
    R Res;
}

int main()
{

    SPEED;
    cin >> n >> m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin >> a[i][j];
        }
    }
    Mdp;

    cout << Solve() << endl;

    R 0;
}


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

#define DEBUG 1
 


int main() {
    int L,R,d;

    cin >> L >> R >> d;

    int count_d = 0;

    for(int i = L; i < R+1; i++){
        if(i % d == 0){
            count_d++;
        }
    }

    cout << count_d << endl;
  

    return 0;

 
}



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

int a[100005];
int main()
{
    int n;
    cin>>n;
    long long sum1=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i>1)
            sum1=sum1+fabs(a[i]-a[i-1]);
    }

    sum1=sum1+fabs(a[1])+fabs(a[n]);
   // cout<<sum1<<endl;
    for(int i=1;i<=n;i++)
    {
        long long sum=sum1;
        int w=0;
        if(i==1)
        {
            sum=sum-fabs(a[1])-fabs(a[1]-a[2])+fabs(a[2]);
            //sum=sum-fabs(a[1]-a[2])-fabs(a[n]-a[1])+fabs(a[2]-a[n]);
            cout<<sum<<endl;
            continue;
        }

        if(i==n)
        {
            sum=sum-fabs(a[i-1]-a[i])-fabs(a[i])+fabs(a[i-1]);
            cout<<sum<<endl;
            continue;
        }

        sum=sum-fabs(a[i-1]-a[i])-fabs(a[i]-a[i+1])+fabs(a[i-1]-a[i+1]);
        cout<<sum<<endl;
    }




    return 0;
}


Measured memory_bytes: 1664
A, B, H, M = map(int, input().split())

import math

alpha = math.radians(0.5*(60*H + M))
beta = math.radians(6*M)

c2 = A*A + B*B - 2*A*B* math.cos(beta - alpha)

c = math.sqrt(c2)
print(c)


Measured memory_bytes: 9524
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
  int n,k;
  cin>>n>>k;
  vector<bool> D(9,true);
  rep(i,k){
    int d;
    cin>>d;
    D[d]=false;
  }
  queue<int> que;
  que.push(0);
  vector<int> kouho;
  while(!que.empty()){
    int q=que.front();
    que.pop();
    rep(i,10) if(D[i]){
      int nq=q*10+i;
      //cout<<nq<<endl;
      if(nq==0) continue;
      if(nq>=n) kouho.push_back(nq);
      else que.push(nq);
    }
  }
  //for(auto num:kouho) cout<<num<<endl;
  sort(kouho.begin(),kouho.end());//保険
  cout<<kouho[0]<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c);
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define mod          1000000007

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

#define scan(x)      do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A ;
//bitset<32> bset1;
//bool ok = true;
//char ch;
string S, T, U;
ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

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

    //scan(n);
    cin>>S;
    i++;
    ans++;
    T=S[0];
    while(i<S.sz)
    {
        U=S[i];
        if(T!=U)
        {
            ans++;
            T=S[i];
            i++;
        }
        else
        {
            if((i+2)<=S.sz)
            {
                ans++;
                T=S[i];
                T+=S[i+1];
            }
            i+=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	if(s[s.size()-1]=='s'){
		s+="es";
	}
	else s+="s";
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3620
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
A = [ri() for _ in range(N)]
answer = 0
for i in range(N):
    answer += A[i]//2
    if A[i]%2 == 1 and i != N-1 and A[i+1] > 0:
        answer += 1
        A[i+1] -= 1

print(answer)
#00


Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string a,b;
  int i=0,ii=0,n=0,ans=0,iii=0,nn=0,iiii=0;
  cin >> a >> b;
  
  while(b[iii]){
    iii++;
  }  
  while(a[iiii]){
    iiii++;
  }
  while(a[i]){
    ii = 0;
    if(iiii - i < iii){
      break;
    }
    
  while(b[ii]){
    if(i < ii){
      break;
    }
      n = 0;
    nn = 0;
      while(b[ii + n]){
        if(!a[i + n]){
          n = 0;
         break;
        }
        if(!b[ii + n]){
          n = 0;
         break;
        }
        if(a[i + n] == b[ii + n]){
          nn++;
        }
        n++;
      }
      if(ans < nn){
        ans = nn;
      }
    ii++;
  }
    i++;
  }
  cout << (iii - ans);
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

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 INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

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

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

    
    int r;
    cin>>r;
    cout<<r*r<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int gcd(int a, int b) {
  return b != 0 ? gcd(b, a % b) : a;
}

int main(){
    int a,b;
    cin>>a>>b;
    out(gcd(a,b));
}



Measured memory_bytes: 3120
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

int main(){
    int N,M;
    int dp[MAX] = {0};

    cin >> N >> M;
    for(int i = 0;i < M;i++){
        int a;
        cin >> a;
        dp[a] = -1;
    }

    dp[0] = 1;
    
    for(int i = 0;i < N;i++){
        if(dp[i] <= 0)continue;
        if(dp[i+1] != -1){
            dp[i+1] = (dp[i+1] + dp[i]) % MOD;
        }
        if(dp[i+2] != -1){
            dp[i+2] = (dp[i+2] + dp[i]) % MOD;
        }
    }

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 640
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 int a, b, c;
 cin >> a >> b >> c;
 cout << min(a * b, c) << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll H;
    cin >> H;
    ll t = 1;
    ll ans = 0;
    while(H){
        ans += t;
        H /= 2;
        t *= 2;
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

const int maxn = 200000 + 5;
int a[maxn];

void solve()
{
    int n, K;
    cin >> n >> K;
    
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        cnt += (a[x] == 0);
        a[x]++;
    }
    
    cnt = max(0, cnt - K);
    sort(a, a + maxn);
    
    int ans = 0;
    for(int i = 0; i < maxn; i++)
    {
        if(cnt == 0)
        {
            break;
        }
        
        if(a[i] != 0)
        {
            cnt--;
            ans += a[i];
        }
    }
    
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    //freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    char a,b;
    cin>>a>>b;
    if(a=='H'){
        if(b=='H'){
            cout<<'H'<<endl;
        }else{

        cout<<'D'<<endl;
    }}else{if(b=='D'){
            cout<<'H'<<endl;
        }else{

        cout<<'D'<<endl;
    }

    }


}

Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#define MAX 1000

typedef struct Stack{
	int num[MAX];
	int top;
}Stack;

Stack S;

void push(int x){
	S.num[S.top++]=x;
	return;
}

int pop(){
	S.top--;
	return S.num[S.top];
}

int main(){
	char str[10];
	S.top=0;
	
	while(scanf("%s",str)!=EOF){
		
		if(isdigit(str[0]))
			push(atoi(str));
		
		else {
			int x=pop();  int y=pop();
			switch(str[0]){
				case '+':push(y+x);break;
				case '-':push(y-x);break;
				case '*':push(y*x);break;
			}
		}
	}
	
	printf("%d\n",S.num[0]);
	
	return 0;
	
}


Measured memory_bytes: 2060
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>
#include <chrono>

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	int ans = 0;
	string S; cin >> S;
	for(int i = 0; i < S.size(); ++i){
		int a = 0;
		for (int j = i; j < S.size(); ++j) {
			if (S[j] == 'A' || S[j] == 'T' || S[j] == 'G' || S[j] == 'C') a++;
			else break;
		}
		chmax(ans, a);
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
   ll h;
   cin >> h;

    ll attack = 1, count = 0;
   for(;;) {
       if (h > 0) {
           count += attack;
           attack *= 2;
           h = floor(h / 2);
       }
       else break;
   }
   cout << count << endl;
}

Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 平均気温の係数 */
	private static final double D = 0.006d;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), t = scanner.nextInt(), a = scanner.nextInt();
			Queue<Data> queue = new PriorityQueue<>();
			IntStream.range(0, n).forEach(i -> {
				int h = scanner.nextInt();
				queue.add(new Data(i + 1, Math.abs(t - h * D - a)));
			});
			System.out.println(queue.peek().index);
		}
	}

	private static class Data implements Comparable<Data> {
		int index;
		double h;

		Data(int index, double h) {
			super();
			this.index = index;
			this.h = h;
		}

		@Override
		public int compareTo(Data data) {
			return Double.compare(h, data.h);
		}
	}
}


Measured memory_bytes: 39112
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(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; }

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

int main () {
  string s;
  cin >> s;

  rep(b,1<<3) {
    string ans;
    ans += s[0];
    int val = s[0]-'0';
    rep(i,3) {
      if (b&(1<<i)) {
        ans += '+';
        ans += s[i+1];
        val += s[i+1]-'0';
      }
      else {
        ans += '-';
        ans += s[i+1];
        val -= s[i+1]-'0';
      }
    }
    if (val == 7) {
      ans += "=7";
      cout << ans << endl;
      return 0;
    }
  }
}

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

int main(){
    int N;
    int A;
    /* 以下は無くても大丈夫そう
    100 > N > 0 ;
    N2 >= A > 0 ;
    */
    cin >> N >> A;
    int x ;
    // NｘNのマス目からAの白マス分を引くだけ
    x = N * N - A ;
    cout << x << endl;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long n, std::string s){
    REP(i,0,n){
        REP(j,0,s.size()){
            if(s[j]=='Z') s[j]='A';
            else s[j]++;
        }
    }
    cout<<s<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	unsigned int N, K, X, Y; cin >> N >> K >> X >> Y;
    if (N < K) K = N;
	cout << X*K+Y*(N-K) << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
list($h, $n) = ints();
for ($i = 0; $i < $n; $i++) list($a[], $b[]) = ints();
$dp = array_fill(0, $h + 1, PHP_INT_MAX);
$dp[0] = 0;
for ($i = 1; $i <= $h; $i++)
    for ($j = 0; $j < $n; $j++) $dp[$i] = min($dp[$i], $b[$j] + $dp[max(0, $i - $a[$j])]);
echo $dp[$h];

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 5112
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
char s[SZ];
string g[4]={"dream","dreamer","erase","eraser"};
int main()
{
	cin>>s; int l=strlen(s);
	while(l>=5)
	{
		bool did=0;
		for(int i=0;i<4;i++)
		{
			int x=g[i].size();
			if(l<x) continue;
			bool ok=1;
			for(int j=0;j<x;j++)
			{
				if(g[i][j]==s[l-x+j]);else ok=0;
			}
			if(ok)
			{
				did=1; l-=x;
			}
		}
		if(!did) break;
	}
	if(l==0) puts("YES"); else puts("NO");
}


Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
using namespace std;


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


int main(){
  string s;
  cin >> s;
  int a = 0, b = 0, c = 0;
  rep(i, s.length()){
    if(s[i] == 'a') a++;
    if(s[i] == 'b') b++;
    if(s[i] == 'c') c++;
  }

  if(a == 1 && b == 1 && c == 1)  cout << "Yes" << endl;
  else cout << "No" << endl;

}


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

using namespace std;

typedef long long ll;
const int maxn = 100005;
const ll mod = 1e9 + 7;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int n, k;
struct edge { int to, nxt; } p[maxn << 1];
int head[maxn], cnt;

inline void addedge(int u, int v) {
    p[++cnt].to = v, p[cnt].nxt = head[u], head[u] = cnt;
    p[++cnt].to = u, p[cnt].nxt = head[v], head[v] = cnt;
}

ll ans;

inline void dfs(int x, int fa) {
    reg int tmp = 0;
    for (reg int i = head[x]; i; i = p[i].nxt) {
        reg int j = p[i].to;
        if (j == fa) continue;
        ans = ans * (k - 1 - (++tmp)) % mod;
        dfs(j, x);
    }
}

int main() {
    n = read(), k = read(); reg int u, v;
    for (reg int i = 1; i < n; i++) u = read(), v = read(), addedge(u, v);
    reg int tmp = 0; ans = k;
    for (reg int i = head[1]; i; i = p[i].nxt) {
        reg int j = p[i].to;
        if (j == 1) continue;
        ans = ans * (k - (++tmp)) % mod;
        dfs(j, 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3712
a=[]
b={}
n,m=map(int,input().split())
for _ in range(m):
	i,j=map(int,input().split())
	if i==1:
		a.append(j)
	elif j==n:
		b[i]=1
for i in a:
	if i in b:
		print('POSSIBLE')
		break
else:
	print('IMPOSSIBLE')

Measured memory_bytes: 18420
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


int main(){
	int n;
	scanf("%d", &n);
	char s[n+1];
	scanf("%s", s);
	char sw[3] = "SW";

	REP(x, 0, 4){
		std::string ans = "  ";
		ans[0] = sw[x/2];
		ans[1] = sw[x%2];
		REP(i, 1, n-1){
			if(ans[i]=='S'){
				if(s[i]=='o') ans += ans[i-1];
				else{
					if(ans[i-1]=='S') ans += 'W';
					else ans += 'S';
				}
			}else{
				if(s[i]=='x') ans += ans[i-1];
				else{
					if(ans[i-1]=='S') ans += 'W';
					else ans += 'S';
				}
			}
		}
		if(ans[n-1]=='S'){
			if(s[n-1]=='o' and ans[0]!=ans[n-2]) continue;
			if(s[n-1]=='x' and ans[0]==ans[n-2]) continue;
		}else{
			if(s[n-1]=='o' and ans[0]==ans[n-2]) continue;
			if(s[n-1]=='x' and ans[0]!=ans[n-2]) continue;
		}
		if(ans[0]=='S'){
			if(s[0]=='o' and ans[1]!=ans[n-1]) continue;
			if(s[0]=='x' and ans[1]==ans[n-1]) continue;
		}else{
			if(s[0]=='o' and ans[1]==ans[n-1]) continue;
			if(s[0]=='x' and ans[1]!=ans[n-1]) continue;
		}
		std::cout << ans << '\n';
		return 0;

	}	
	puts("-1");
	return 0;
}



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

using namespace std;

int main(){
  vector<int> v(5);
  for(int i = 0 ; i < 5 ; i++){
    cin >> v[i];
  }
  sort(v.rbegin(),v.rend());
  bool flg = false;
  for(auto x : v){
    if(flg){ cout << " "; }
    flg = true;
    cout << x;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define amari (x) x % 1000000007;

#define fillInt(xs, x)        \
  for (int i = 0; i < x; i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < x; i++) \
    scanf("%ld", &xs[i]);
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

long calc(string h, string rem, long res) {
  if (rem.empty() && h.empty()) return res;
  if (rem.empty()) return 0;
  string newH = h + rem.substr(0, 1);
  string newRem = rem.substr(1);
  long left =  calc("", newRem, res + stol(newH));
  long right = calc(newH, newRem, res);
  return left + right;
}

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

  string S;
  cin >> S;

  printf("%ld", calc("", S, 0L));
  
  return 0;
}

Measured memory_bytes: 256
S = input()
ans = [0 for _ in range(len(S))]
S = S + 'R'
L = 0
R = 0
id = 0
for i in range(len(S)-1):
    if S[i] =='R':
        L += 1
    else:
        R += 1
    if S[i] != S[i+1]:
        if S[i] == 'R':
            id = i
        else:
            ans[id] = (L+1)//2 + R//2
            ans[id+1] = L//2 + (R+1) // 2
            L = 0
            R = 0
print(' '.join([str(i) for i in ans]))


Measured memory_bytes: 10484
#include <iostream>


int main(void)
{
	int n=0;
	while(std::cin >> n){
		bool first=true;
		for(int i=0; i<10; i++)
			if(n & (1 << i))
			{
				if(first)
				{
					std::cout << (n&(1 << i)) << std::flush;
					first = false;
				}
				else
					std::cout << " " << (n&(1<<i)) << std::flush;
			}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<numeric>
#include<iomanip>
#include<map>
#include<random>
#include<cassert>
using namespace std;
#define ll long long int
#define ld long double
const ll Mod = 1000000007;
ll CaseN=1;
const ld PI = 22/7.0;

bool mycmp(string s,string t)
{
if(s.size()<t.size())
{
return true;	
}		
return false;
}


void solve()
{
	ll a,b,h;
	cin>>a>>b>>h;
	cout<<(a+b)*h/2<<endl;
 // cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;
    
return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();	
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    ll n; cin >> n;
    vector<ll> vec(n);
    map<int, int> mp;

		// vecへの格納、mapに回数を記録
    rep(i, n) {
        ll x; cin >> x;
        vec[i] = x;
        mp[x]++;
    }

		// totalの算出
		ll total = 0;
		for(const auto m: mp) {
			int freq = m.second;
			total += freq * (freq-1ll) / 2ll;
		}

		// vecの要素ごとに、totalから減算、再計算してcout
    rep(i, n) {
        int num = vec[i];
				int freq = mp[num];
        ll ans = total;
        ans -= (freq)*(freq-1ll)/2ll;
        ans += (freq-1ll)*(freq-2ll)/2ll;
        cout << ans << endl;
    }
}


Measured memory_bytes: 9088
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int P = sc.nextInt();
    int odd = 0;
    for (int i = 0; i < N; i++) {
      if (sc.nextInt()%2 == 1) odd++;
    }
    long ans = 1;
    while (N > 0) {
      ans *= 2;
      N--;
    }
    if (odd == 0) {
      System.out.println(P == 1 ? 0 : ans);
    } else {
      System.out.println(ans/2);
    }
  }
}


Measured memory_bytes: 21844
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let n: usize = read();
  let mut ls: Vec<u32> = read_vec();
  ls.sort();

  let mut ans = 0;

  for i in (1..n).rev() {
    let mut left = 0;
    let mut right = i - 1;

    while left < right {
      if ls[i] < ls[left] + ls[right] {
        ans += right - left;
        right -= 1;
      } else {
        left += 1;
      }
    }
  }

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


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

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

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
#define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

/*-----------------END TEMPLATE-----------------*/

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  int n, m;
  cin >> n >> m;
  int total = 0;
  vi a(n);
  rep(i, 0, n) {
    cin >> a[i];
    total += a[i];
  }

  int canBe = 0;

  for (auto x : a) {
    int kk = 4 * m * x;
    if (kk >= total) canBe++;
  }

  if (canBe >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

/*

0 1 2 3 4 5 6
      B B C C

1 2 3 4 5
    A A A
B B B
      C C

*/

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n, m; cin >> n >> m;
    vector<pair<ll, ll>> ab(n);
    vector<pair<ll, ll>> cd(m);
    rep(i, n) {
        ll a, b; cin >> a >> b;
        ab.at(i) = make_pair(a, b);
    }

    rep(i, m){
        ll c, d; cin >> c >> d;
        cd.at(i) = make_pair(c, d);
    }

    for(int i=0; i<n; i++){
        ll tmp = 1000000000;
        ll a = ab.at(i).first;
        ll b = ab.at(i).second;
        int id;
        for(int j=0; j<m; j++){
            ll c = cd.at(j).first;
            ll d = cd.at(j).second;
            if(tmp>(ll)abs(a-c)+(ll)abs(b-d)) {
                tmp = (ll)abs(a-c)+(ll)abs(b-d); 
                id = j+1; 
            }
        }
        cout << id << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))
cnt = 0

for i in range(n):
	minj = i
	for j in range(i, n):
		if li[j] < li[minj]:
			minj = j
	if li[i] != li[minj]:
		li[i], li[minj] = li[minj], li[i]
		cnt += 1

print(*li)
print(cnt)

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

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	ll ans = 0;
	for (ll i = 0; i < n; ++i)cin >> a[i];
	sort(a.rbegin(), a.rend());
	priority_queue<pair<ll, pair<ll, ll>>> pq;
	ans += a[0];
	pq.push({ a[1],{a[0],a[1]} });
	pq.push({ a[1],{a[0],a[1]} });
	for (ll i = 2; i < n; ++i) {
		auto p = pq.top();
		pq.pop();
		ans += p.first;
		pq.push({ a[i],{p.second.first,a[i]} });
		pq.push({ a[i],{p.second.second,a[i]} });
	}
	cout << ans << endl;
}


Measured memory_bytes: 11124
N, K = map(int, input().split())
A = list(map(int, input().split()))
b = sum([i for i in A[:K] if i <= 0])
bMax = b
w = sum([i for i in A[:K] if i >= 0])
wMin = w
for i in range(N-K):
    b = b - min(A[i], 0) + min(A[K+i], 0)
    w = w - max(A[i], 0) + max(A[K+i], 0)
    bMax = max(bMax, b)
    wMin = min(wMin, w)
print(sum(i for i in A if i >= 0) + max(bMax, -wMin))


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

#define printl(s) cout << s << endl;
#define printFix(n,i) cout << fixed << setprecision(i) << n << endl; return 0;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;

const ll modSeed = pow(10,9) + 7;
const int INF = 1'000'000'000;

template <typename T>
vector<T> getVector(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll N,ans;

int main(){
  ans = 0;
  cin >> N;
  vector<pii> points(N);
  vector<int> pass(N);
  rep(i,N){
    pass[i] = i;
  }
  rep(i,N){
    int x,y;
    cin >>x>>y;
    points[i] = make_pair(x,y);
  }
  double sum =0;
  double count=0;
  do{
    count++;
    for(int i=1;i<N;i++){
      double distX = points[pass[i]].first-points[pass[i-1]].first;
      double distY = points[pass[i]].second-points[pass[i-1]].second;
      sum += sqrt(distX*distX+distY*distY);
    }
  }while(next_permutation(pass.begin(),pass.end()));
  printFix(sum/count,10);
}


Measured memory_bytes: 3880
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>

using namespace std;

int main(void) {
	int N, T;
	cin >> N >> T;

	int min_price = 1000000001;
	int max_diff = 0;
	int cnt = 0;

	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if (A < min_price) {
			// 買う場所更新
			min_price = A;
		} else {
			// 売り場所候補
			if ((A - min_price) > max_diff) {
				// 売り場所更新
				max_diff = (A - min_price);
				cnt = 1;
			} else if ((A - min_price) == max_diff) {
				// 売れる組み合わせ複数
				cnt++;
			}
		}
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
T=list(int(input()) for _ in range(N))

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

ans=T[0]
for i in range(1, N):
	ans=ans*T[i]//gcd(ans, T[i])
print(ans)

Measured memory_bytes: 9104
#include <iostream>
#include <fstream>
#include <string> 
#include <cstring>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>

#define BIT(a) (1 << (a))

using namespace std;

long long MOD = 1000000007;

long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

vector<long long> a;

int main(void){
    int N;
    cin >> N;
    a = vector<long long> (N);
    long long max = 0;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        if (max < a[i]) max = a[i];
    }
    double mid;
    mid = (double)max/2;
    double min = 10000000000;
    long long ans;
    sort(a.begin(), a.end());
    for (int i = 0; i < N; i++){
        if (min > abs((double)a[i] - mid)){
            min = abs((double)a[i] - mid);
            ans = a[i];
        }
    }

    cout << max << " " << ans << endl;

    

    return 0;
}



Measured memory_bytes: 1024