akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include<unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
//#define mid (l + r >> 1)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For( i, j, k ) for(R int i = (j); i <= (k); ++i)
#define foR( i, j, k ) for(R int i = (j); i >= (k); --i)
#define Cross( i, j, k ) for(R int i = (j); i; i = (k))using namespace std;
typedef long long ll;
using namespace std;
const ll N = 1000011;
const ll Inf = 0x3f3f3f3f3f3f;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar ( x % 10 | 48 );
	}

	inline void wrn ( ll x ) { write(x); putchar (' '); }

	inline void wln ( ll x ) { write(x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x); wln (y); }

}

using namespace IO;

namespace Cesare {
	
	#define int long long
	
	ll n, Ans = 0, a[N], b[N], f[N], l[N];
	
	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)
	
	ll T[N << 2];
	
	inline void pushUp ( ll p ) { T[p] = T[ls(p)] + T[rs(p)]; }
	
	inline void Update ( ll p, ll l, ll r, ll x, ll k ) {
		if (l == r) return (void) (T[p] = k);
		if (mid >= x) Update(ls(p), l, mid, x, k);
		if (mid < x)  Update(rs(p), mid + 1, r, x, k); pushUp(p);
	}
	
	inline ll Query ( ll p, ll l, ll r, ll ul, ll ur, ll res = 0 ) {
		if (ul > ur) return 0;
		if (l >= ul && r <= ur) return T[p];
		if (mid >= ul) res += Query(ls(p), l, mid, ul, ur);
		if (mid < ur)  res += Query(rs(p), mid + 1, r, ul, ur);
		return res;
	}
	
	struct cmp{bool operator()(int a,int b){return a>b;}};
	
	int main() {
		Set (T, 0); n = read();
		For ( i, 1, n ) a[i] = read();
		
		int con=1,Ans=1;
		l[1]=f[1]=a[1];
		for(int i=2;i<=n;i++)
		{
			if(l[Ans]>=a[i])l[++Ans]=a[i];
			else l[upper_bound(l+1,l+Ans+1,a[i],cmp())-l]=a[i];
			if(f[con]<a[i])f[++con]=a[i];
			else f[lower_bound(f+1,f+con+1,a[i])-f]=a[i];
		} return wln(Ans), 0;
	}
	
}

signed main()
{
	return Cesare::main();
}

/*

*/



Measured memory_bytes: 39296
a,b = map(int,input().split())
li = []
for i in range(a):
    c,d = map(int,input().split())
    if b >= d:
        if li != []:
            if li[0] > c:li = [c,d]
        else:li = [c,d]
if li == []:print("TLE")
else:print(li[0])


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

using namespace std;

int main(){
  int n; cin >> n;
  int k; cin >> k;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  
  int dp[n+1]; memset(dp, 0, sizeof(dp));

  if (k > n) k = n;
    int i = 0;
  for (i = 0 ; i < k; i++){
      dp[i] = abs(arr[i] - arr[0]);
  }
      vector<int> num;
  for (; i < n; i++){
      num.clear();
      int c = INT_MAX;
      for (int j = 1; j <= k ; j++){
        int a = dp[i-j] + abs(arr[i-j] - arr[i]);
        // num.push_back(a);
        if (a < c) c = a;
      }
    dp[i] = c;
  }
  
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
  vector<vector<int> > dp(n+1,vector<int>(3,0));
  for(int i=0;i<n;i++){
    dp[i+1][0]=max(dp[i+1][0],max(dp[i][1]+a[i],dp[i][2]+a[i]));
    dp[i+1][1]=max(dp[i+1][1],max(dp[i][0]+b[i],dp[i][2]+b[i]));
    dp[i+1][2]=max(dp[i+1][2],max(dp[i][0]+c[i],dp[i][1]+c[i]));
  }
  cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}


Measured memory_bytes: 8064
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(var i=0;i<Arr.length;i++){
var arr=Arr[i].split("");
var a1=arr[0];
var a2=arr[1];
var a3=arr[2];
var a4=arr[3];
var a5=arr[4];
var a6=arr[5];
var a7=arr[6];
var a8=arr[7];
var a9=arr[8];
var d=0;
for(var j=0;j<2;j++){
   var s=(j==0)?"o":"x";
   var S=s+s+s;
   if(a1+a2+a3==S){console.log(s);break;}
   if(a4+a5+a6==S){console.log(s);break;}
   if(a7+a8+a9==S){console.log(s);break;}
   if(a1+a4+a7==S){console.log(s);break;}
   if(a2+a5+a8==S){console.log(s);break;}
   if(a3+a6+a9==S){console.log(s);break;}
   if(a1+a5+a9==S){console.log(s);break;}
   if(a3+a5+a7==S){console.log(s);break;}
   d++;
}
if(d==2)console.log("d");
}

Measured memory_bytes: 7644
N, K = map(int, input().split())

if K == 0:
    print(N * N)
    exit(0)

cnt = 0
for b in range(K + 1, N + 1):
    p = N // b
    r = N % b
    cnt += p * max(0, b - K)
    cnt += max(0, r - K + 1)
print(cnt)


Measured memory_bytes: 2940
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long X = sc.nextLong();
   long Y = sc.nextLong();

   int count = 0;
   long xx = 1;
   while(X*xx<=Y)
   {
     xx *=2;
     count++;
   }
   System.out.println(count);
 }
}

Measured memory_bytes: 22736
#include<stdio.h>
#include<map>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<utility>
#include<string.h>
#include<string>
#define n 200000
#define loop(i, a, b) for(int i=a; i<=b; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long lli;
typedef double llf;
bool visit[n + 50];
lli arr[n + 50], arr2[n + 50], a, b, c, d, e, f;
string str1, str2;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
vector<edge> V[n + 50];
void addedge(int a, int b, int c)
{
	edge temp;
	temp.from = a;
	temp.to = b;
	temp.weight = c;
}

////////////////////////////////////////

lli max(lli a, lli b)
{
	if(a > b) return a;
	else      return b;
}
void solve()
{
	cin >> a >> b >> c >> d >> e;
	lli ans = (a * d) + (b * e);
	for(int i=1; i <= max(d, e); i++)
	{
		lli temp = c * i * 2;
		temp += max(d - i, 0) * a;
		temp += max(e - i, 0) * b;
		ans = min(temp, ans);
//		cout << ans << '\n';
	}
	cout << ans;
}
int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 0, times - 1)
	{
		solve();
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 6400
#include <iostream>

using namespace std;

struct Card{
    char suit;
    int value;
};

void BubbleSort(Card *C, int n){
    for(int i = 0; i < n; i++){
        for(int j = n - 1; j > i; j--){
            if(C[j].value < C[j-1].value){
                Card tmp = C[j];
                C[j] = C[j-1];
                C[j-1]= tmp;
            }
        }
    }
}

void SelectionSort(Card *C, int n){
    for(int i = 0; i < n; i++){
        int mini = i;
        for(int j = i; j < n; j++) if(C[j].value < C[mini].value) mini = j;
        if(i != mini){
            Card tmp = C[i];
            C[i] = C[mini];
            C[mini] = tmp;
        }
    }
}

bool isStable(Card *C1, Card *C2, int n){
    for(int i = 0; i < n; i++) if(C1[i].suit != C2[i].suit) return false;
    return true;
}

int main(){
    int n, i;
    cin >> n;
    Card C1[n], C2[n];
    for(i = 0; i < n; i++){
        cin >> C1[i].suit >> C1[i].value;
        C2[i] = C1[i];
    }

    BubbleSort(C1, n);
    for(i = 0; i < n-1; i++) cout << C1[i].suit << C1[i].value << " ";
    cout << C1[i].suit << C1[i].value << endl;
    cout << "Stable" << endl;

    SelectionSort(C2, n);
    for(i = 0; i < n-1; i++) cout << C2[i].suit << C2[i].value << " ";
    cout << C2[i].suit << C2[i].value << endl;
    if(isStable(C1, C2, n)) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    
    return 0;
}


Measured memory_bytes: 3096
N,T=map(int,input().split())
c_t=[]
mincos=1001
for c,t in zip(range(N),range(N)):
    c,t=map(int,input().split())
    if t<=T:
        if c<mincos:
            mincos=c

print("TLE" if mincos>1000 else mincos)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC097B
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());

            int ans = 1;
            for(int i = 2; i < X; i++)
            {
                if (i * i > X) break;

                for (int p = 2; Math.Pow(i, p) <= X; p++)
                {
                    int now = (int)Math.Pow(i, p);
                    if (now > ans) ans = now;
                }

            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#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 INF LLONG_MAX/2
#define PI acos(-1.0)
//#define MOD 1000000007

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;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
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;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n,ans=0;
    cin>>n;
    REP(i,1,n+1){
        REP(j,1,n+1){
            REP(k,1,n+1){
                ans += gcd(gcd(i,j),k);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    char s1[n+1],s2[n+1],s3[2*n+1];
    scanf("%s%s",s1,s2);
    int k=0;
    for(int i=0;i<n;i++){
        s3[k]=s1[i];
        k++;
        s3[k]=s2[i];
        k++;
    }
    for(int i=0;i<k;i++){
        printf("%c",s3[i]);
    }
    return 0;
}


Measured memory_bytes: 128
from collections import deque
S = deque(list(input()))
Q = int(input())

flag = False
for _ in range(Q):
    q = list(input().split())
    if q[0] == '1':
        flag = True if flag is False else False
    else:
        if flag is False:
            if q[1] == '1':
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if q[1] == '1':
                S.append(q[2])
            else:
                S.appendleft(q[2])

if flag is True:
    S.reverse()
print(''.join(S))


Measured memory_bytes: 8676
import java.util.Scanner;
 
public class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
 
    while (true)
    {
      int operand1 = sc.nextInt();
      char operator = sc.next().charAt(0);
      int operand2 = sc.nextInt();

      switch(operator)
      {
      case '+':
        System.out.println(operand1 + operand2);
        break;
      case '-':
        System.out.println(operand1 - operand2);
        break;
      case '*':
        System.out.println(operand1 * operand2);
        break;
      case '/':
        System.out.println(operand1 / operand2);
        break;
      case '?':
        return;
      }
    }
  }
}


Measured memory_bytes: 26292
#include<cstdio>
#include<algorithm>
#include<cmath>
#define N 1005
#define cmax(_i,_j) ((_i)<(_j)?(_i)=(_j):0)
#define cmin(_i,_j) ((_i)>(_j)?(_i)=(_j):0)
using namespace std;
namespace runzhe2000
{
	long long x[N], y[N], z[N], v[N]; long long ans = 0;
	void main()
	{
		int n, m; scanf("%d%d",&n,&m);
		for(int i = 1; i <= n; i++)scanf("%lld%lld%lld",&x[i],&y[i],&z[i]);
		for(int i = 0; i < 8; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				v[j] = 0;
				i & 1 ? v[j] += x[j] : v[j] -= x[j];
				i & 2 ? v[j] += y[j] : v[j] -= y[j];
				i & 4 ? v[j] += z[j] : v[j] -= z[j];
			}
			sort(v+1,v+1+n);
			long long r = 0;
			for(int j = 1, k = n; j <= m; j++, k--) r += v[k];
			if(ans < r) ans = r;
		}
		printf("%lld\n",ans);
	}
}
int main()
{
	runzhe2000::main();
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;

int main() {
	int X;
	cin >> X;
	int ans = 0;
	ans += 1000 * (X / 500);
	X %= 500;
	ans += 5 * (X / 5);
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

#define MOD 1000000007
#define INF 1000000000

string S;

int main()
{
    cin >> S;
    if(S.size() < 4) {
        printf("No\n");
        return 0;
    }
    if(S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I') {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }


int main() {
	int a,b;
	cin >> a >> b;
	if (a > 12) {
		put(b);
	}
	else if (a > 5) {
		put(b / 2);
	}
	else {
		put(0);
	}
	return 0;
}



Measured memory_bytes: 256
S = list(input())

S.sort()

if S[0] != 'a':
    print('a')
elif S[0] == 'a':
    for i in range(len(S)-1):
        if ord(S[i+1]) - ord(S[i]) == 0 or ord(S[i+1]) - ord(S[i]) == 1:
            pass
        else:
            res = ord(S[i]) + 1
            print(chr(res))
            exit()
            
    res = ord(S[-1]) + 1

    if S[0] == 'a' and S[-1] == 'z':
        print('None')
    elif S[0] != 'a':
        print('a')
    else:
        print(chr(res))


Measured memory_bytes: 9880
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
 
 
int main() {
    int A, B, T;
    cin >> A >> B >> T ;

    int ans=0;
    for (int i = A; i < T+1 ; i +=A){
        ans += B;

    }
    
    cout << ans << endl;
    }


    


Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				max = Math.max(max, Math.abs(a[i] - a[j]));
			}
		}

		pr.println(max);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  int Ans=0;
  int subAns=0;
  for(int i=0; i<N-1; i++){
    if(H.at(i)>=H.at(i+1)){
      subAns++;
      Ans=max(Ans, subAns);
    }
    else{
      subAns=0;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N=3e2+100;
ll dp[N][N][N];
ll a[N];
map <int,int> mp;
int32_t main(){
    ll n,k;
    cin >> n >> k;
    vector <int> b;
    b.pb(0);
    for (int i=1;i<=n;i++){
        cin >> a[i];
        b.pb(a[i]);
    }
    sort(b.begin(),b.end());
    for (int i=0;i<b.size();i++){
        mp[b[i]]=i;
    }
    memset(dp,69,sizeof dp);
    for (int i=0;i<=k;i++){
        dp[0][i][0]=0;
    }
    for (int i=0;i<n;i++){
        for (int j=0;j<=k;j++){
            for (int l=0;l<b.size();l++){
                //cout << i << " " << j << " " << l << " " << dp[i][j][l] << endl;
                if (j>0){
                    dp[i+1][j-1][l]=min(dp[i+1][j-1][l],dp[i][j][l]);
                }
                if (l>=mp[a[i+1]]){
                    dp[i+1][j][mp[a[i+1]]]=min(dp[i+1][j][mp[a[i+1]]],dp[i][j][l]);
                }
                else{
                    dp[i+1][j][mp[a[i+1]]]=min(dp[i+1][j][mp[a[i+1]]],dp[i][j][l]+a[i+1]-b[l]);
                }

            }
        }
    }
    ll mi=1e15+100;
    for (int i=0;i<=k;i++){
        for (int j=0;j<N;j++){
            mi=min(mi,dp[n][i][j]);
        }

    }
    cout << mi;
}


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

using namespace std;

int main(void)
{
	int n;
	cin>>n;
	int a[n];
	long long ans = 0;
	for(int i = 0 ; i < n; i++){
		cin>>a[i];
	}
	int pre;
	pre = a[0];
	for(int i = 1; i < n; i++){
		if(pre > a[i]){
			ans += pre - a[i];
		}
		else {
			pre = a[i];
		}
		//cout<<"i = "<<i<<", pre = "<< pre<<endl;
	}
	
	cout<<ans<<endl;
	
	return 0;
}



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

int main(int argc, char* argv[])
{
	int N;
	int K;
	cin>>N;
	cin>>K;
	int i;
	int minDist = 0;
	int x;
	for (i=0;i<N;i++){
		cin>>x;
		if (x<K-x){
			minDist += 2*x;
		}else{
			minDist +=2*(K-x);
		}
	}
	cout<<minDist<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

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

int main() {
  ll n; cin >> n;
  Vl a(n);
  rep(i, 0, n) cin >> a[i];

  ll ans = a[0];
  rep(i, 1, n) ans = gcd(ans, a[i]);

  cout << ans << endl;

  return 0;
}


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

int main() {
    int N,K,Q;
    cin >>N>>K>>Q;
    vector<int>data(N,K-Q);
    vector<int>data2(Q);
    for(int i=0;i<Q;i++){
        cin>>data2[i];
        data[data2[i]-1]+=1;
    }
    for(int i=0;i<N;i++){
        if(data[i]<=0)cout<<"No"<<endl;
        else cout <<"Yes"<<endl;
    }
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
const int N = 405;
const int INF = 1e9 + 7; 
using namespace std;

int n, ans, a[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
	n = read <int> (), ans = INF;
	for(int i = 1; i <= n; i++) a[i] = read <int> ();
	for(int res, i = -100; i <= 100; i++)
	{
		res = 0;
		for(int j = 1; j <= n; j++) res += abs(a[j] - i) * abs(a[j] - i);
		ans = min(ans, res); 
	}
	printf("%d\n", ans); 
	return 0; 
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    ll A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;
    write(abs(A - B) > (V - W)* T ? "NO" : "YES");
}


Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}

int n, m;
int a, b;
map<int, int> deg;
int main() {
  GI(n);
  GI(m);

  FORN(i, m) {
    GI(a);
    GI(b);
    deg[a]++;
    deg[b]++;
  }

  FOR1(i, n) {
    printf("%d\n", deg[i]);
  }
    
  return 0;
}


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

int main()
{
  long n,m;
  cin>>n>>m;
  vector<pair<long, long> > pairs(n);
  
  for(int i=0;i<n;i++){
    long a,b;
    cin>>a>>b;
    pairs[i]=make_pair(a,b);
  }
  
  sort(pairs.begin(),pairs.end());
  
  long quantity=0;;
  long money=0;
  for(int i=0;i<n;i++){
    if(pairs[i].second+quantity<=m){
      quantity+=pairs[i].second;
      money+=pairs[i].first*pairs[i].second;
    }else{
      money+=pairs[i].first*(m-quantity);
      break;
    }
      
  }
  cout<<money<<endl;  
  return 0;
}

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

typedef long long ll;
const int MAX = 5000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    int N, K;
    cin >> N >> K;
    COMinit();
    int redBalls = N - K;
    int blueBalls = K;
    for (int i = 1; i <= K; i++)
    {
        ll redCount = COM(redBalls + 1, i);
        ll blueCount = COM(blueBalls - 1, i - 1);
        cout << (redCount * blueCount) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
    int n,i,j,k,l,cnt=0;
    while(scanf("%d",&n)!=EOF){
        cnt=0;
        for(i=0;i<=9;i++){
            for(j=0;j<=9;j++){
                for(k=0;k<=9;k++){
                    for(l=0;l<=9;l++){
                        if(i+j+k+l==n)
                            cnt++;
                    }
                }
            }
        }
        printf("%d\n",cnt);
    }

    return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

int main() {
    int n;
    long long *a;
    cin >> n;
    a = new long long[n];
    long long ans = 0;
    long long sum = 0;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int flag = -1;
    if (a[0] > 0)   flag = 1;
    else if (a[0] == 0) flag = 0;

    for (int i = 0; i < n; i++) {
        sum += a[i];

        if (flag > 0 || flag == 0) {
            if (sum <= 0) {
                while (sum <= 0) {
                    sum++;
                    ans++;
                }
            }
            flag = -1;
        }
        else if (flag < 0) {
            if (sum >= 0) {
                while (sum >= 0) {
                    sum--;
                    ans++;
                }
            }
            flag = 1;
        }
    }

    if (a[0] > 0)   flag = -1;
    else if (a[0] == 0) flag = 0;
    else    flag = 1;

    long long ans2 = 0;
    sum = 0;

    for (int i = 0; i < n; i++) {
        sum += a[i];

        if (flag > 0) {
            if (sum <= 0) {
                while (sum <= 0) {
                    sum++;
                    ans2++;
                }
            }
            flag = -1;
        }
        else if (flag <= 0) {
            if (sum >= 0) {
                while (sum >= 0) {
                    sum--;
                    ans2++;
                }
            }
            flag = 1;
        }
    }

    cout << min(ans, ans2) << endl;
    delete[] a;
    
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
SET = [0,0,0,0,0,0]
judge = [[2,1,3],[1,3,2],[3,2,1],[2,3,1],[3,1,2],[1,2,3]]
for _ in range(0,N):
    ID = [1, 2, 3]
    amida = [int(x) for x in input().split()]
    for j in range(1,len(amida)):
        if amida[j] == 0:
            ID[0],ID[1] = ID[1],ID[0]
            #print(ID)
        elif amida[j] == 1:
            ID[1],ID[2] = ID[2],ID[1]
            #print(ID)

    for i in range(0,len(judge)):
        if ID == judge[i]:
            SET[i] += 1

#print(SET)

if ((SET[5] > 0) or (SET[0] > 1) or (SET[1] > 1) or (SET[2] > 1) or
        ((SET[0] > 0) and (SET[1] > 0) and (SET[4] > 0)) or
        ((SET[0] > 0) and (SET[2] > 0) and (SET[4] > 0)) or
        ((SET[0] > 0) and (SET[2] > 0) and (SET[4] > 0)) or
        ((SET[0] > 0) and (SET[1] > 0) and (SET[3] > 0)) or
        ((SET[0] > 0) and (SET[2] > 0) and (SET[3] > 0)) or
        ((SET[1] > 0) and (SET[2] > 0) and (SET[4] > 0)) or
        ((SET[3] > 0) and (SET[4] > 0)) or
        (SET[3] > 2) or (SET[4] > 2)):
    print("yes")
else:
    print("no")







Measured memory_bytes: 5624
import java.util.Scanner;
 

public class Main {
	
	private static final String[] WEEKS = {"SUN","MON","TUE","WED","THU","FRI","SAT" };
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String line = sc.nextLine();
        int i = 0;
        for (; i < WEEKS.length; i++) {
        	if (line.equals(WEEKS[i])) break;
        }
        
        System.out.println(WEEKS.length - i);
        sc.close();
	}
	
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
char s[20];
int main(){
	scanf("%s",s+1);
	for (int i=1;i<=4;i++)putchar(s[i]);
	putchar(' ');
	for (int i=5;i<=12;i++)putchar(s[i]);
	puts("");
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)

	S, T := next(), next()

	if len(S) < len(T) && S == T {
		fmt.Println("Yes")
		return
	}

	s := strings.Split(S, "")
	t := strings.Split(T, "")

	sort.Strings(s)
	sort.Strings(t)
	if len(s) < len(t) && strings.HasPrefix(strings.Join(t, ""), strings.Join(s, "")) {
		fmt.Println("Yes")
		return
	}

	sort.Sort(sort.Reverse(sort.StringSlice(t)))
	for i := 0; i < min(len(s), len(t)); i++ {
		if s[i] == t[i] {
			continue
		}
		if s[i] < t[i] {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i

}

func min(n, m int) int {
	if n <= m {
		return n
	}
	return m
}


Measured memory_bytes: 640
S = input()
N = len(S)
S_inv = S[::-1]

if S == S_inv and S[:int((N-1)/2)] == S_inv[int((N+1)/2):] and S[int((N+1)/2):] == S_inv[:int((N-1)/2)]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>

int main()
{
	int N, Ap, An;
	std::cin >> N;
	std::cin >> Ap;
	int result = 0;
	for (int i = 1; i < N; i++) {
 		std::cin >> An;
		if (An == Ap) {
			result += 1;
			i++;
			std::cin >> An;
		}
		Ap = An;
	}
	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
double k[maxn];
ll a[maxn];
ll ans = 0;
int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	multiset<ll>st;
	for (int i = 0; i < n; i++){
		auto it = st.lower_bound(a[i]);
		if (it == st.begin()) st.insert(a[i]);
		else {
			it--;
			st.erase(it);
			st.insert(a[i]);
		}
	}
	cout << st.size() << endl;
	return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)

#include <valarray>

typedef double number;
typedef valarray<number> point;
const int dim = 2;

number dot(const point& a, const point& b) {
  return (a * b).sum();
}
point cross(const point& a, const point& b) {
  return a.cshift(+1)*b.cshift(-1)
       - a.cshift(-1)*b.cshift(+1);
}
number dist2(const point& a, const point& b) {
  return dot(a-b, a-b);
}


struct min_ball {
  point center;
  number radius2;
  void add(const point& p) {
    ps.push_back(p);
  }
  void compile() {
    m = 0;
    center.resize(dim, 0);
    radius2 = -1;
    make_ball(ps.end());
  }
  template <class OUT>
  void support(OUT out) {
    copy(ps.begin(), supp_end, out);
  }
  min_ball() {
    for (int i = 0; i <= dim; ++i) {
      c[i].resize(dim, 0);
      v[i].resize(dim, 0);
    }
  }
private:
  list<point> ps;
  list<point>::iterator supp_end;
  int m;
  point v[dim+1], c[dim+1];
  number z[dim+1], r[dim+1];
  void pop() { --m; }
  void push(const point& p) {
    if (m == 0) {
      c[0] = p; r[0] = 0;
    } else {
      number e = dist2(p, c[m-1]) - r[m-1];
      point delta = p - c[0];
      v[m] = p - c[0];
      for (int i = 1; i < m; ++i)
        v[m] -= v[i] * dot(v[i], delta) / z[i];
      z[m] = dot(v[m], v[m]);
      c[m] = c[m-1] + e*v[m]/z[m]/2;
      r[m] = r[m-1] + e*e/z[m]/4;
    }
    center  = c[m];
    radius2 = r[m]; ++m;
  }
  void make_ball(list<point>::iterator i) {
    supp_end = ps.begin();
    if (m == dim + 1) return;
    for (list<point>::iterator k = ps.begin(); k != i; ) {
      list<point>::iterator j = k++;
      if (dist2(*j, center) > radius2) {
        push(*j); make_ball(j); pop();
        move_to_front(j);
      }
    }
  }
  void move_to_front(list<point>::iterator j) {
    if (supp_end == j) ++supp_end;
    ps.splice (ps.begin(), ps, j);
  }
};

valarray<number> d[100];

signed main(){
  lli n;
  min_ball ball;

  cin>>n;
  REP(i,0,n){
    double x,y;
    cin>>x>>y;

    d[i] = {x,y};
    ball.add(d[i]);
  }
  ball.compile();

  cout<<setprecision(20);
  cout<<sqrt(ball.radius2)<<endl;

  return 0;

}

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

int main() {
  int X, Y,answer = 0;
  cin >> X >> Y;
  for(int i = 0; i <= X; i++){
      int a = 2 * i + 4 * (X - i);
      if(a == Y) {
          cout << "Yes" << endl;
          answer = 1;
          break;
      }
  }
  if(answer == 0) cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

vector<int> len;
vector<map<int, int> > value;

int dfs(string& s, int& k)
{
    if(isdigit(s[k])){
        int ret = 0;
        while(k < s.size() && isdigit(s[k])){
            ret *= 10;
            ret += s[k] - '0';
            ++ k;
        }
        return ret;
    }

    char c = s[k];
    k += 2;
    int a = dfs(s, k);
    ++ k;

    if(a == -1 || value[c].find(a) == value[c].end())
        return -1;
    else
        return value[c][a];
}

bool substitute (string& s)
{
    char a=s[0];
    int eq=s.find('='),idx=2;
    int i=dfs(s,idx);
    if(i==-1 || len[a]<=i) return false;
 
    idx=eq+1;
    int res=dfs(s,idx);
    if(res == -1)
        return false;
    value[a][i]=res;
    return true;
}

int solve(vector<string>& s)
{
    len.assign(128, 0);
    value.assign(128, map<int, int>());

    int n = s.size();
    for(int i=0; i<n; ++i){
        if(s[i].find('=') == string::npos){
            int k = 2;
            len[s[i][0]] = dfs(s[i], k);
        }else{
            if(!substitute(s[i]))
                return i + 1;
        }
    }

    return 0;
}

int main()
{
    for(;;){
        vector<string> s;
        for(;;){
            string t;
            cin >> t;
            if(t == ".")
                break;
            s.push_back(t);
        }

        if(s.empty())
            return 0;

        cout << solve(s) << endl;
    }
}

Measured memory_bytes: 1340
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{Write, BufWriter};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: usize,
        b: usize,
    }
    println!("{}", min(n * a, b));
}


Measured memory_bytes: 4352
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

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

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

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

	cout << r*r << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(n);
	
	int A, B;
	for (int i = 0; i < m; i++) {
		cin >> A >> B;
		a[A - 1]++;
		a[B - 1]++;
	}

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

	return 0;

}

Measured memory_bytes: 256
n=int(input())
s=[input()  for i in  range(n)]

ac=s.count("AC")
tle=s.count("TLE")
wa=s.count("WA")
re=s.count("RE")

print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))


Measured memory_bytes: 16272
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
ll cnt[200010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[200010];
    rep(i, N) cin >> A[i];
    rep(i, N) {
        cnt[A[i]]++;
    }
    ll sum = 0;
    rep(i, N + 1) sum += cnt[i] * (cnt[i] - 1) / 2;
    rep(i, N) {
        cout << sum - (cnt[A[i]] - 1) << endl;
    }


    return 0;
}


Measured memory_bytes: 5904
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	//1
	int N,M;
	cin>>N>>M;
	if(N==0)exit(0);
	int A[100],W[10]={0,0,0,0,0,0,0,0,0,0};
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
	}
	for(int i=0;i<M;i++)
	{
		cin>>W[i];
	}

	vector<int>diffs;
	for(int i0=0;i0<3;i0++)
		for(int i1=0;i1<3;i1++)
			for(int i2=0;i2<3;i2++)
				for(int i3=0;i3<3;i3++)
					for(int i4=0;i4<3;i4++)
						for(int i5=0;i5<3;i5++)
							for(int i6=0;i6<3;i6++)
								for(int i7=0;i7<3;i7++)
									for(int i8=0;i8<3;i8++)
										for(int i9=0;i9<3;i9++)
	{
		int W_L=0,W_R=0;
		if(i0==1)W_L=W_L+W[0];
		else if(i0==2)W_R=W_R+W[0];
		if(i1==1)W_L=W_L+W[1];
		else if(i1==2)W_R=W_R+W[1];
		if(i2==1)W_L=W_L+W[2];
		else if(i2==2)W_R=W_R+W[2];
		if(i3==1)W_L=W_L+W[3];
		else if(i3==2)W_R=W_R+W[3];
		if(i4==1)W_L=W_L+W[4];
		else if(i4==2)W_R=W_R+W[4];
		if(i5==1)W_L=W_L+W[5];
		else if(i5==2)W_R=W_R+W[5];
		if(i6==1)W_L=W_L+W[6];
		else if(i6==2)W_R=W_R+W[6];
		if(i7==1)W_L=W_L+W[7];
		else if(i7==2)W_R=W_R+W[7];
		if(i8==1)W_L=W_L+W[8];
		else if(i8==2)W_R=W_R+W[8];
		if(i9==1)W_L=W_L+W[9];
		else if(i9==2)W_R=W_R+W[9];

		int diff=abs(W_L-W_R);
		diffs.push_back(diff);
	}
	sort(diffs.begin(),diffs.end());
	diffs.erase(unique(diffs.begin(),diffs.end()),diffs.end());

	//2,3
	vector<int>Y;
	bool first=true;
	for(int i=0;i<N;i++)
	{
		vector<int>X;
		bool flag=false;
		for(int j=0;j<diffs.size();j++)
		{
			int diff=diffs.at(j);
			X.push_back(diff+A[i]);
			if(diff>=A[i])
			{
				X.push_back(diff-A[i]);
			}
			else
			{
				X.push_back(A[i]-diff);
			}
			if(diff==A[i])
			{
				flag=true;
			}
		}
		if(flag==false)
		{
			sort(X.begin(),X.end());
			X.erase(unique(X.begin(),X.end()),X.end());

			if(first==true)
			{
				first=false;
				Y=X;
			}
			else
			{
				vector<int>result;
				set_intersection(Y.begin(),Y.end(),
								X.begin(),X.end(),
								inserter(result,result.end()));
				Y=result;
			}
		}
	}
	if(first==true)
	{
		cout<<0<<endl;
	}
	else
	{
		if(Y.size()==0)
		{
			cout<<-1<<endl;
		}
		else
		{
			cout<<Y[0]<<endl;
		}
	}
}
int main()
{
	while(true)
	{
		solve();
	}
}



Measured memory_bytes: 3932
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
    string s;
    cin>>s;
    string t="";
    rep(i,s.size()){
        if(s[i]!='x')t+=string{s[i]};
        //xしか挿入出来ないのでそもそもxを除いた文字列が回文でなければならない
    }
    rep(i,t.size()/2){
        if(t[i]!=t[t.size()-1-i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    if(!t.size()){//xのみで構成される場合
        cout<<0<<endl;
        return 0;
    }
    vector<int>pre(t.size(),0),post(t.size(),0);
    int j=0,i=0;
    while(j<=t.size()/2){
        if(s[i]!='x')++j;
        else pre[j]++;
        ++i;
    }j=0,i=s.size()-1;
    while(j<=t.size()/2){
        if(s[i]!='x')++j;
        else post[j]++;
        --i;
    }
    int ans=0;
    rep(i,j+1)ans+=abs(pre[i]-post[i]);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair


int main(){
    int N; cin>>N;
    string s; cin>>s;
    
    
    int top[10]; FILL(top,10,0);
    int mid[10][10]; FILL2(mid,10,10,0);
    map<int,int> mp;
    
    int ans = 0;
    REP(i,N){
        int t = ctoi(s[i]);
        if(top[t]==0){
            top[t] = 1;
            for(int j=i+1;j<N;++j){
                int m = ctoi(s[j]);
                if(mid[t][m]==0){
                    mid[t][m] = 1;
                    for(int k=j+1;k<N;++k){
                        int lst = ctoi(s[k]);
                        int num = 100*t+10*m+lst;
                        if(mp[num]==0){
                            mp[num] = 1;
                            ++ans;
                        }
                    }
                }
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
N = int(input())
A = [int(input()) for i in range(N)]
maxind = A.index(max(A))
maxa = max(A)
A = sorted(A)
ans = [maxa]*maxind
ans.append(A[-2])
[ans.append(i) for i in [maxa]*(N-maxind-1)]
print(*ans,sep="\n")

Measured memory_bytes: 19204
#include "bits/stdc++.h"
using ll = long long;
using namespace std;
int main(){
ll n;
cin>>n;
vector<ll> d(n);
for(int i=0;i<n;i++){
  cin>>d[i];
}

sort(d.begin(),d.end());
ll t1 = d[(n/2)-1];
ll t2 = d[(n/2)];
if(t1==t2){
  cout<<0<<endl;
  return 0;
}
cout<<t2-t1<<endl;



return 0;

}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
int n, l[44]; char c[12];
int main() {
	while (scanf("%d", &n), n) {
		for (int i = 0; i < n; i++) scanf("%s", c), l[i] = strlen(c);
		for (int i = 0; i < n; i++) {
			int s = 0, v = 0;
			for (int j = i; j < n && s < 5; j++) {
				v += l[j];
				if (3 % (s + 1) == 0) {
					if (v > 5) break;
					else if (v == 5) s++, v = 0;
				}
				else {
					if (v > 7) break;
					else if (v == 7) s++, v = 0;
				}
			}
			if (s == 5) {
				printf("%d\n", i + 1); break;
			}
		}
	}
}

Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1000000007;
ll ans,cnt[300];
char s[1234567];
int main(){
    int n; cin >> n;
    cin >> s;
    for (int i=0;i<n;i++) cnt[s[i]-'a']++;
    ans=1;
    for (int i=0;i<26;i++) ans=ans*(cnt[i]+1)%M;
    printf("%lld\n",(ans+M-1)%M);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];
    sort(ALL(a));
    cout<<a[N-1]-a[0]<<endl;
}


Measured memory_bytes: 256