akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    l = [list(map(int, input().split())) for _ in range(N)]
    dp = [[0]*3 for _ in range(N+1)]
    dp[1][0] = l[0][0]
    dp[1][1] = l[0][1]
    dp[1][2] = l[0][2]
    
    for i in range(1, N):
        for j in range(3):
            a = (j+1)%3
            b = (j+2)%3
            dp[i+1][j] = max(dp[i][a], dp[i][b]) + l[i][j]
    print(max(dp[N]))


if __name__ == '__main__':
    main()

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

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

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

    int n, m; cin >> n >> m;
    char c[n]; rep(i, n) c[i] = 'a';
    rep(i, m) {
      int s; char x; cin >> s >> x;
      if(c[s-1] == 'a') c[s-1] = x;
      else if(c[s-1] != x) {
	cout << -1 << endl;
	return 0;
      }
    }
    if(n > 1 && c[0] == 'a') {
      c[0] = '1';
    }
    if(n > 1 && c[0] == '0') {
      cout << -1 << endl;
      return 0;
    }
    rep(i, n) {
      if(c[i] == 'a') cout << 0;
      else cout << c[i];
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        int min = x - k + 1;
        int max = x + k - 1;
        if (min < -1000000) {
            min = -1000000;
        }
        if (max > 1000000) {
            max = 1000000;
        }
        for (int i = min; i <= max; i++) {
            System.out.print(i);
            if (i != max) {
                System.out.print(" ");
            }
        }
        System.out.println("");
        sc.close();
    }
}


Measured memory_bytes: 22612
using System;

namespace HowManyDivisors
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int c = int.Parse(str[2]);

            int answer = 0;

            for (int i = a; i <= b; i++)
            {
                if (c % i == 0)
                {
                    answer++;
                }
            }

            Console.WriteLine(answer);

        }
    }
}

Measured memory_bytes: 9100
import math

A, B = map(int, input().split())

a_p = math.ceil(A/4)
b_p = math.floor(B/4)

ans = 0

for i in range(A, 4*a_p):
    ans = ans ^ i
for j in range(b_p*4, B+1):
    ans = ans ^ j
print(ans)

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

int main() {
    int n;
    std::cin >> n;
    std::vector<int> x(n), y(n), h(n);
    for (int i = 0; i < n; i++) std::cin >> x[i] >> y[i] >> h[i];
    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            std::set<int> candidates;
            int lim = 1000100000;
            for (int i = 0; i < n; i++) {
                if (h[i] == 0) {
                    lim = std::min(lim, abs(x[i] - cx) + abs(y[i] - cy));
                } else {
                    candidates.insert(h[i] + abs(x[i] - cx) + abs(y[i] - cy));
                }
            }
            if (candidates.size() == 1 && *candidates.begin() <= lim) {
                std::cout << cx << " " << cy << " " << *candidates.begin() << std::endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int horieyui(const void* x, const void* y) {
	const char* a = (const char*)x, *b = (const char*)y;
	size_t aa = strlen(a), bb = strlen(b);
	if (aa != bb) return aa > bb ? -1 : 1;
	return strcmp(a, b);
}

int h, w;
char data[10][21];

char visited[10][21];

int candidateCount;
char candidates[10 * 20 * 8 * 10 * 20][10 * 20 + 1];

int main(void) {
	while (scanf("%d%d", &h, &w) == 2 && (h|w) != 0) {
		int i, j;
		int found;
		for (i = 0; i < h; i++) {
			if (scanf("%31s", data[i]) != 1) return 1;
		}
		candidateCount = 0;
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				int dx, dy;
				for (dy = -1; dy <= 1; dy++) {
					for (dx = -1; dx <= 1; dx++) {
						if (dx != 0 || dy != 0) {
							int p = 0;
							int y = i, x = j;
							memset(visited, 0, sizeof(visited));
							while (!visited[y][x]) {
								visited[y][x] = 1;
								if(p > 0) strcpy(candidates[candidateCount], candidates[candidateCount - 1]);
								candidates[candidateCount][p] = data[y][x];
								candidates[candidateCount][p + 1] = '\0';
								candidateCount++;
								p++;
								y += dy;
								x += dx;
								if (y < 0) y += h;
								if (x < 0) x += w;
								if (y >= h) y -= h;
								if (x >= w) x -= w;
							}
						}
					}
				}
			}
		}
		qsort(candidates, candidateCount, sizeof(*candidates), horieyui);
		found = 0;
		for (i = 1; i < candidateCount; i++) {
			if (strlen(candidates[i]) < 2) break;
			if (strcmp(candidates[i - 1], candidates[i]) == 0) {
				puts(candidates[i]);
				found = 1;
				break;
			}
		}
		if (!found) puts("0");
	}
	return 0;
}



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

using namespace std;

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

	int x, z;

	x = k - a;
	z = x - b;

	if (k <= a) {
		cout << k;
	}
	else if (x <= b) {
		cout << a;
	}
	else if (z > 0) {

		cout <<a + (-1 * z);
	}else {
             cout << a;
	}
}

Measured memory_bytes: 3644
#include<stdio.h>
int n,a[100];
void pr(){
    for(int i=0;i<n;i++){
        printf("%d",a[i]);
        if(i==n-1) printf("\n");
        else printf(" ");
    }
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    pr();
    for(int i=1;i<n;i++){
        int key=a[i];
        int j;
        for(j=i-1;j>=0&&a[j]>key;j--){
            a[j+1]=a[j];
        }
        a[j+1]=key;
        pr();
    }
    return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
signed main()
{
  int x=0,y=0,z=0,n=0,m=0;
  string s;
  std::cin >> s;
  rep(i,s.size()){
    if(i%2==0){
      std::cout << s[i];
    }
  }
}


Measured memory_bytes: 512
#include<stdio.h>
main()
{

    int a,b,c,d;

    while(scanf("%d %d",&a,&b)!=EOF){

    if(a<b)
        printf("a < b\n");
    else if(a>b)
        printf("a > b\n");
    else
        printf("a == b\n");
    }

    return 0;




}



Measured memory_bytes: 2036
S=input()

tmp=S.split()

L=int(tmp[0])
R=int(tmp[1])

R=min(L+2019,R)

flag=False
result=1000000000000
for i in range(L,R+1):
    for j in range(i+1,R+1):
        if i>=j:
            flag=True
            break
        n=(i*j)%2019
        if result>n:
            result=n
    if(flag):
        break



print(result)

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

#define MAX 100005

int main() {
    long long N, A, B;
    long long X[MAX];
    long long ans = 0;

    scanf("%lld %lld %lld", &N, &A, &B);
    for (int i = 0; i < N; i++) scanf("%lld", &X[i]);

    for (int i = 1; i < N; i++) {
        ans += min(A * (X[i] - X[i-1]), B);
    }

    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int a,b,c,d, A[100], B[100], C[100][100], D[100][100][100];
string s, t, r;




int main(){
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(i == 3) cout << "8";
		else cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func min(ints ...int) int {
	res := math.MaxInt64
	for _, i := range ints {
		if i <= res {
			res = i
		}
	}
	return res
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	n, _ := strconv.Atoi(readLine(sc))
	a, _ := strconv.Atoi(readLine(sc))
	b, _ := strconv.Atoi(readLine(sc))
	c, _ := strconv.Atoi(readLine(sc))
	d, _ := strconv.Atoi(readLine(sc))
	e, _ := strconv.Atoi(readLine(sc))

	fmt.Println(4 + int(math.Ceil(float64(n)/float64(min(a, b, c, d, e)))))
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int H;

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

void swap(int *a, int *b){
  int temp;

  temp = *a;
  *a = *b;
  *b = temp;

}

void maxHeapify(int *A, int i){
  int l, r, largest;

  l = left(i);
  r = right(i);

  if(l <= H && A[l] > A[i]){
    largest = l;
  }else{
    largest = i;
  }

  if(r <= H && A[r] > A[largest]){
    largest = r;
  }

  if(largest != i){
    swap(&A[i], &A[largest]);
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int *A){
  int i;

  for(i = H/2; i > 0; i--){
    maxHeapify(A, i);
  }

}


int main(){
  int i;
  int *A;

  scanf("%d", &H);

  A = malloc(sizeof(int) * (H+1));

  for(i=1; i<=H; i++){
    scanf("%d", &A[i]);
  }

  buildMaxHeap(A);

  for(i=1; i<=H; i++){
    printf(" %d", A[i]);
  }

  printf("\n");

  return 0;
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int N,i,j,a;
int64_t ans=0,cnt=0;
map<int,int> mp;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>N;
  REP(i,N){
    cin>>a;
    mp[a]++;
  }
  for(auto itr=mp.begin(); itr!=mp.end();++itr) {
    j = (itr->second);
    if(j%2==0){
      ans+=(j-2)/2;
      cnt++;
    }else{
      ans+=(j-1)/2;
    }
  }
  ans+=(cnt+1)/2;
  cout<<N - 2*ans<<endl;
  return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
	
		Scanner scan = new Scanner(System.in);
		
		String s = scan.next();
		String[] str = s.split("");
		
			if (str[0].equals(str[1]) || str[0].equals(str[2]) || str[1].equals(str[2])) {
			System.out.println("No");
			return;
			}
		
		System.out.println("Yes");
		
	}	
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
typedef pair<double,double> P; // x, y
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    double A, B, H, M; cin >> A >> B >> H >> M;
    P a;//時針
    P b;//分針
    double beta = -M_PI*M/30.0;
    b.first = B * sin(beta); // あってそう
    b.second = B * cos(beta); //あってなさそう
    
    double alpha = -M_PI*(60.0*H+M)/360.0;
    a.first = A * sin(alpha);
    a.second = A * cos(alpha);
    
    // cerr << "(" <<  a.first << ", " << a.second << endl;
    // cerr << "(" <<  b.first << ", " << b.second << endl;
    cout << fixed << setprecision(10) << hypot(a.first - b.first, a.second - b.second) << endl;
    return 0;
}


Measured memory_bytes: 4100
N=int(input())
A=list(map(int,input().split()))
D={}
for a in A:
  if(a in D):
    D[a]+=1
  else:
    D[a]=1
    
if(max(D)-min(D)>1):
  print("No")
  exit()
  
if(len(D)==2):
  B=max(D)
  if(B-D[B-1]>0 and D[B]>=2*(B-D[B-1])):
    print("Yes")
  else:
    print("No")
  
else:
  B=max(D) # 常に同じ色の人がいる
  if(N>=2*B):
    print("Yes")
    exit()
  
  B=max(D)+1 # 全員違う色
  if(B==N):
    print("Yes")
    exit()
  print("No")
  
  
  

Measured memory_bytes: 17396
def read():
    L, R = list(map(int, input().strip().split()))
    return L, R+1


def solve(L, R):
    if R - L > 2019:
        return 0
    numlist = []
    for i in range(L, R, 1):
        numlist.append(i % 2019)
    minimum = 9999999
    for i in numlist:
        for j in numlist:
            if i < j and (i*j) % 2019 < minimum:
                minimum = (i*j) % 2019
    return minimum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 39024
import kotlin.math.max

const val MOD = 1000000007L

fun main() {
    var (n, a, b) = readLine()!!.split(" ").map { it.toInt() }
    if (b < a) {
        val c = b
        b = a
        a = c
    }
    val pow2 = LongArray(n + 1)
    pow2[0] = 1L
    for (j in 1..n) {
        pow2[j] = (2L * pow2[j - 1]) % MOD
    }
    if (a == 1) {
        println(pow2[n])
    } else {
        val dp = Array(n + 1) { LongArray(b + 1) }
        val dpOverall = LongArray(n + 1)
        dp[0][0] = 1L
        dpOverall[0] = 1L
        var answer = pow2[n - b]
        //println("\tanswer = $answer")
        for (j in 1..n) {
            for (k in 1..b) {
                dp[j][k] = when (k) {
                    1 -> if (j == 1) 1L else {
                        var res = 0L
                        for (j2 in max(0, j - a) until j - 1) {
                            res += dpOverall[j2]
                        }
                        res
                    }
                    2 -> dp[j - 1][1]
                    else -> (2L * dp[j - 1][k - 1]) - (if (j >= 2 && k >= 2) dp[j - 2][k - 2] else 0L) + (if (j >= a + 1 && k >= a + 1) dp[j - 1 - a][k - 1 - a] else 0L)
                }
                dp[j][k] %= MOD
                if (k != b) {
                    dpOverall[j] += dp[j][k]
                }
                //println("dp[$j][$k] = ${dp[j][k]}")
                if (k == b) {
                    answer += pow2[n - j] * dp[j][b]
                    answer %= MOD
                } else if (j + max(a, b - k) <= n) {
                    answer += pow2[n - (j + max(a, b - k))] * dp[j][k]
                    answer %= MOD
                }
                //println("\tanswer = $answer")
            }
            dpOverall[j] %= MOD
        }
        answer += MOD
        answer %= MOD
        println(answer)
    }
}

Measured memory_bytes: 275988
import sys
input = sys.stdin.readline
from collections import defaultdict
N,K = map(int,input().split())
A = list(map(int,input().split()))

#N = 2*10**5
#K = 10**12
#A = [(i % 200000) + 1 for i in range(N)]

def answer(N,K,A):
    s = []
    for i in range(N*K):
        a = A[i%N]
        if a in s:
            s = s[:s.index(a)]
        else:
            s.append(a)
    return s

def solve(N,K,A):
    B = A * 2
    NA = [-1]*N
    d = {}
    for i, b in enumerate(B):
        if b in d:
            if NA[d[b]%N] == -1:
                NA[d[b]%N] = i - d[b]+1
            d[b] = i 
        else:
            d[b] = i

    L = 57
    ds = [NA]
    for i in range(L):
        pre = ds[-1]
        temp = [pre[j] + pre[(pre[j]+j)%N] for j in range(N)]
        ds.append(temp)

    cnt = 0
    i = 0

    L -= 1
    NA = ds[L]
    while True:
        add = NA[i]
        nxt = ((i + add)%N)
        if cnt + add > N*K:
            L -= 1
            if L < 0:
                break
            NA = ds[L]
            continue
        cnt += add
        i = nxt


    s = []
    NA = ds[0]
    while cnt < N*K:
        a = A[i%N]
        add = NA[i%N]
        if add + cnt > N*K:
            s.append(a)
            i = (i+1) % N
            cnt += 1
        else:
            i = (i+add) % N
            cnt += add

    return s
print(*solve(N,K,A))

#import random
#N,K = 2*10**5,2*10**5
#A = [random.randint(1,2*10**5) for i in range(N)]
#solve(N,K,A)
#exit()
#for i in range(100):
#    import random
#    N,K = 100,100
#    A = [random.randint(1,10) for i in range(N)]
#    s1 = answer(N,K,A)
#    s2 = solve(N,K,A)
#    if s1 != s2:
#        print(N,K,A)
#        print(s1)
#        print(s2)
#        break


Measured memory_bytes: 427660
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var ans = 0;
        for (int i = 1; i <= n; i += 2)
        {
            var x = 0;
            for (int j = 1; j <= i; j++)
            {
                if (i % j == 0)
                {
                    x++;
                }
            }
            if (x == 8)
            {
                ans++;
            }
        }

        Console.WriteLine(ans);
    }
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

bool solve(vector<ll> &v, ll num, ll k) {
    ll n = v.size();
    vector<ll> m_array(n);
    rep(i, n) { m_array[i] = v[i] % num; }
    sort(m_array.begin(), m_array.end());

    vector<ll> l_sum(n), r_sum(n);
    l_sum[0] = m_array[0];
    repd(i, 1, n) { l_sum[i] = l_sum[i - 1] + m_array[i]; }
    r_sum[n - 1] = num - m_array[n - 1];
    repb(i, n - 1) { r_sum[i] = r_sum[i + 1] + (num - m_array[i]); }
    if (l_sum[n - 1] <= k || r_sum[0] <= k) {
        return true;
    }

    ll k_min = mod;
    rep(i, n - 1) { k_min = min(k_min, max(l_sum[i], r_sum[i + 1])); }

    /*
    cout << "num: " << num << endl;
    rep(i, n) { cout << l_sum[i] << " "; }
    cout << endl;
    rep(i, n) { cout << r_sum[i] << " "; }
    cout << endl;

    cout << "k_min: " << k_min << endl;
    cout << endl;
    */

    return k_min <= k;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) { cin >> a[i]; }

    ll sum = 0;
    rep(i, n) { sum += a[i]; }

    vector<ll> div;
    for (ll i = 1; i * i <= sum; i++) {
        ;
        if (sum % i == 0) {
            div.push_back(i);
            div.push_back(sum / i);
        }
    }

    ll ans = 0;
    sort(div.begin(), div.end());

    for (auto d : div) {
        if (solve(a, d, k)) {
            ans = d;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3676
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	var a_pos, b_pos, c_pos int
	cur := "a"
	a := next()
	b := next()
	c := next()

	for {
		if cur == "a" {
			if len(a)-1 < a_pos {
				fmt.Println("A")
				break
			}
			cur = string(a[a_pos])
			a_pos++
		} else if cur == "b" {
			if len(b)-1 < b_pos {
				fmt.Println("B")
				break
			}
			cur = string(b[b_pos])
			b_pos++
		} else if cur == "c" {
			if len(c)-1 < c_pos {
				fmt.Println("C")
				break
			}
			cur = string(c[c_pos])
			c_pos++
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

template<typename t1, class t2>
void input(t1 count,t2* array) {
	for(t1 i = 0;i < count;i++) {
		cin >> array[i];
	}
}

template<typename t1, class t2>
void output(t1 count,t2* array) {
	for(t1 i = 0;i < count;i++) {
		cout << array[i];
		if(i != count - 1) cout << " ";
	}
}

int main(int argc,char** argv) {
	int n,a[100];
	cin >> n;
	input(n,a);
	int count = 0;
	for(int i = 0;i < n;i++) {
		int m = i;
		for(int j = i+1;j < n;j++) if(a[j] < a[m]) m = j;
		if(m != i) {
			swap(a[i],a[m]);
			count++;
		}
	}
	output(n,a);
	cout << endl << count << endl;
}



Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int A;
	int B;
	cin >> A;
	cin >> B;

	int lval = max(A, B);
	int ans = 0;
	if (lval < 10) {
		ans = A * B;
		cout << ans << endl;
	}
	else {
		ans = -1;
		cout << ans << endl;
	}

	return  0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		String[] a = new String[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.toBinaryString(sc.nextLong());
		}
		sc.close();

		int[] cnt1 = new int[40];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < a[i].length(); j++) {
				if (a[i].charAt(j) == '1') {
					cnt1[a[i].length() - 1 - j]++;
				}
			}
		}

		long[][] val = new long[40][2];
		char[] bit0 = new char[40];
		long base = 1;
		for (int i = 0; i < 40; i++) {
			if (cnt1[i] < n - cnt1[i]) {
				bit0[i] = '1';
			} else {
				bit0[i] = '0';
			}
			val[i][0] = base * cnt1[i];
			val[i][1] = base * (n - cnt1[i]);
			base *= 2;
		}

		char[] k2 = Long.toBinaryString(k).toCharArray();
		char[] bitk = new char[40];
		Arrays.fill(bitk, '0');
		for (int i = 0; i < k2.length; i++) {
			bitk[k2.length - 1 - i] = k2[i];
		}

		long ans = 0;
		char[] bit = new char[40];
		System.arraycopy(bit0, 0, bit, 0, bit.length);

		boolean flg = false;
		for (int i = bit.length - 1; i >= 0; i--) {
			if (bit[i] < bitk[i]) {
				ans = Math.max(ans, calc(val, bit));
				break;
			} else if (bit[i] > bitk[i]) {
				bit[i] = '0';

			} else if (bit[i] == '1' && bitk[i] == '1') {
				if (!flg) {
					boolean flg2 = true;
					for (int j = i; j >= 0; j--) {
						if (bit[j] < bitk[j]) {
							break;
						}
						if (bit[j] > bitk[j]) {
							flg2 = false;
							break;
						}
					}
					if (flg2) {
						flg = true;
					}
				}
				if (flg) {
					ans = Math.max(ans, calc(val, bit));
				}
				bit[i] = '0';
				ans = Math.max(ans, calc(val, bit));
				bit[i] = '1';
			}
		}
		ans = Math.max(ans, calc(val, bit));
		System.out.println(ans);
	}

	static long calc(long[][] val, char[] bit) {
		long ret = 0;
		for (int i = 0; i < bit.length; i++) {
			ret += val[i][bit[i] - '0'];
		}
		return ret;
	}
}


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

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

     cout<<endl;
    }

      return 0;
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#define debug(x)   cerr<<#x<<" = "<<x<<endl
#else
#define debug(x) 
#endif
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define pii pair<int,int>
#define endl '\n'
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
const int inf = 1e18 + 5;
signed main()
{
    #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif 
    IOS
    int n,k; cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    int ans = 0;
    for(int i=0;i<max(0LL,n-k);i++) ans += arr[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('\n');

  (function(x) {
    // ????????????????????????
    console.log(Math.pow(x, 3));

  })(parseInt(inputs[0], 10)); // ??°?????????

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15800
n = int(input())
d = list(map(int,input().split()))

arc_list = list()
abc_list = list()

harf_num = int(n/2)

d.sort()
abc_list = d[:harf_num]
arc_list = d[harf_num:]

abc_max = max(abc_list)
arc_min = min(arc_list)

print(arc_min - abc_max)

Measured memory_bytes: 14396
#include<stdio.h>
#include<iostream>
using namespace std;
long long int N[10001]={};
int main(){

int n,q;

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

//sort(N,N+1000000);

int c=0,w[50001]={};
cin>>q;
for(int i=0;i<q;i++)
{cin>>y;
for(int j=0;j<n;j++)
	if(N[j]==y){c++;break;}}
cout<<c<<endl;

return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
constexpr int INF = (1<<30) - 1;
constexpr ll LLINF = (1ll<<60);

using vint = vector<int>;
int simulation(int sx, int sy, map<int, set<Pi>> row, map<int, set<Pi>> col) {
        int ret = 1;    
        
        auto getd = [&](int y, int x) {
                return (row[y].lower_bound(Pi(x, -INF))->second);
        };

        int dir = getd(sy, sx);
        //cout << sx << " " << sy << " " << (char)dir << endl;

        //cout << "A:" << row[sy].size() << " " << col[sx].size() << endl;
        row[sy].erase(Pi(sx, dir));
        col[sx].erase(Pi(sy, dir));
        //cout << "B:" << row[sy].size() << " " << col[sx].size() << endl;
        int x = sx, y = sy;
        while (true) {
                //cout << "    " << x << " " << y << endl;
                //find
                int nx, ny, nd;
                if (dir == '^') {
                        auto pos = col[x].lower_bound(Pi(y, -INF));
                        if (pos == begin(col[x])) return (ret);
                        --pos;
                        nx = x, ny = pos->first;
                        nd = pos->second;
                        ret++;
                } else if (dir == '>') {
                        auto pos = row[y].lower_bound(Pi(x, -INF));
                        if (pos == end(row[y])) return (ret);
                        nx = pos->first, ny = y;
                        nd = pos->second;
                        ret++;
                } else if (dir == '<') {
                        auto pos = row[y].lower_bound(Pi(x, -INF));
                        if (pos == begin(row[y])) return (ret);
                        pos--;
                        nx = pos->first, ny = y;
                        nd = pos->second;
                        ret++;
                } else {
                        auto pos = col[x].lower_bound(Pi(y, -INF));
                        if (pos == end(col[x])) return (ret);
                        nx = x, ny = pos->first;
                        //cout << "                " << nx << " " << ny << endl;
                        nd = pos->second;
                        ret++;
                }
                row[ny].erase(Pi(nx, nd));
                col[nx].erase(Pi(ny, nd));
                y = ny, x = nx, dir = nd;
        }
        return (ret);
}

int main() {
        int N; cin >> N;
        vint X(N), Y(N), D(N);

        map<int, set<Pi>> row, col;
        for (int i = 0; i < N; i++) {
                int x, y;
                char d; cin >> x >> y >> d;
                tie(X[i], Y[i], D[i]) = tie(x, y, d);
                row[y].insert(Pi(x, d));
                col[x].insert(Pi(y, d));
        }
        
        int maxv = 0;
        for (int i = 0; i < N; i++) {
                //cout << X[i] << " " << Y[i] << endl;
                int val = simulation(X[i], Y[i], row, col);
                maxv = max(maxv, val);
                //cout << val << endl;
        }

        cout << maxv << endl;   
        return (0);
}



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

int op(int a, int b){ return max(a,b); }
int e() { return 0; }

int main(){
    int n,k; cin>>n>>k;
  	const int MAX_A = 300005;
    segtree<int, op, e> dp(MAX_A);
    rep(i,n){
        int a; cin>>a;
        int l = max(0, a-k);
      	int r = min(MAX_A, a+k+1);
      	int now = dp.prod(l,r) + 1;
        dp.set(a, now);
    }
    int ans = dp.prod(0,MAX_A);
  	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Payment | diff Payment.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Payment.cpp && ./a.out

/*

 7/5/2020

 5:00-

 */

int N;

void solve() {
  cout<<(1000-(N%1000))%1000<<endl;
}

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

  cin>>N;
  solve();

  return 0;
}


Measured memory_bytes: 3648
from collections import deque
n = int(input())
a = list(map(int,input().split()))
b = deque()
for i in range(n):
    if i % 2 == 0:
        b.appendleft(a[i])
    else:
        b.append(a[i])
if n % 2 == 0:
    print(*reversed(b))
else:
    print(*b)


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

using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<LL> A,B;
  int a,b;
  for(int i = 1; i <= N + 1; ++i) {
    cin >> a;
    A.push_back(a);
  }
  for(int i = 1; i <= N; ++i) {
    cin >> b;
    B.push_back(b);
  }

  LL cnt = 0;
  for(int i = 0; i < N; ++i) {
    cnt += min(A[i], B[i]);
    B[i] -= min(A[i], B[i]);
    cnt += min(A[i+1], B[i]);
    A[i+1] -= min(A[i+1], B[i]);
  }

  cout << cnt << endl;

  return 0;
}

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

string s;
bool avail[28];

int main() {
    //freopen("dword.inp", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> s;
    int cnt = 26;
    memset(avail, true, sizeof(avail));
    for (int i=0; i<s.size(); ++i) {
        if (avail[s[i]-'a']) {
            avail[s[i]-'a'] = false;
            --cnt;
        }
    }
    if (cnt>0) {
        for (int i=0; i<26; ++i)
            if (avail[i]) {
                cout << s + char(i+'a');
                return 0;
            }
    }
    for (int i=s.size()-1; i>=0; --i) {
        int MIN = 27;
        for (int j=s.size()-1; j>i; --j) {
            if (s[j]>s[i])
                MIN = min(MIN, s[j]-'a');
        }
        if (MIN!=27) {
            cout << s.substr(0, i) + char(MIN+'a');
            return 0;
        }
    }
    cout << -1;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

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

  // for (int i = 1; i <= n; i++) {
  //   cout << i << ": " << n / i << ' ' << n % i << (n / i == n % i ? "**" :
  //   "")
  //        << endl;
  // }

  set<ll> sl;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      sl.insert(i - 1);
      sl.insert(n / i - 1);
    }
  }

  ll ans = 0;
  for (auto it = sl.begin(); it != sl.end(); it++) {
    ll v = *it;
    if (v == 0) continue;
    if (n / v == n % v) ans += v;
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int n,a,b;
    cin>>n>>a>>b;
    int ans=Bigmod(2LL,n,MOD)-1;
    ans+=MOD;
    int nema=1,nemb=1,denoma=1,denomb=1;
    for(int i=n-a+1;i<=n;i++){
        nema=((nema%MOD)*(i%MOD))%MOD;
    }
    for(int i=1;i<=a;i++){
        denoma=((denoma%MOD)*(i%MOD))%MOD;
    }
    for(int i=n-b+1;i<=n;i++){
        nemb=((nemb%MOD)*(i%MOD))%MOD;
    }
    for(int i=1;i<=b;i++){
        denomb=((denomb%MOD)*(i%MOD))%MOD;
    }
    int nca=((nema%MOD)*((Bigmod(denoma,MOD-2,MOD)+MOD)%MOD)%MOD);
    int ncb=((nemb%MOD)*((Bigmod(denomb,MOD-2,MOD)+MOD)%MOD)%MOD);
    ans=((ans%MOD)-((nca%MOD)+(ncb%MOD))%MOD)%MOD;
    ans+=MOD;
    ans%=MOD;
    cout << ans << endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using Point = pair<int, int>;

struct RightCollision
{
    bool operator()(const Point a, const Point b) const
    {
        return make_pair(a.first + a.second, a.first) < make_pair(b.first + b.second, b.first);
    }
};

struct LeftCollision
{
    bool operator()(const Point a, const Point b) const
    {
        return make_pair(a.first - a.second, a.first) < make_pair(b.first - b.second, b.first);
    }
};

struct DownCollision
{
    bool operator()(const Point a, const Point b) const
    {
        return a < b;
    }
};

set<Point, RightCollision> SR;
set<Point, LeftCollision> SL;
set<Point, DownCollision> SD;
vector<Point> GU, GD, GL, GR;

const int UnReachable = numeric_limits<int>::max();

int Solve()
{
    int result = UnReachable;
    SR.clear();
    SL.clear();
    SD.clear();
    for (auto p : GR)
        SR.insert(p);
    for (auto p : GL)
        SL.insert(p);
    for (auto p : GD)
        SD.insert(p);
    for (auto p : GU)
    {
        {
            auto it = SR.lower_bound(p);
            if (it != SR.begin())
            {
                --it;
                if (it->first + it->second == p.first + p.second)
                    result = min(result, (p.first - it->first) * 10);
            }
        }
        {
            auto it = SL.upper_bound(p);
            if (it != SL.end())
            {
                if (it->first - it->second == p.first - p.second)
                    result = min(result, (it->first - p.first) * 10);
            }
        }
        {
            auto it = SD.upper_bound(p);
            if (it != SD.end())
            {
                if (it->first == p.first)
                    result = min(result, (it->second - p.second) * 5);
            }
        }
    }
    return result;
}

void Rotate()
{
    vector<Point> NU, ND, NL, NR;
    for (auto p : GU)
        NL.push_back(make_pair(-p.second, p.first));
    for (auto p : GL)
        ND.push_back(make_pair(-p.second, p.first));
    for (auto p : GD)
        NR.push_back(make_pair(-p.second, p.first));
    for (auto p : GR)
        NU.push_back(make_pair(-p.second, p.first));
    GU = move(NU);
    GL = move(NL);
    GD = move(ND);
    GR = move(NR);
}

int n, i, x, y, ans;
char c;
int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for (i = 1; i <= n; ++i)
    {
        cin >> x >> y >> c;
        (c == 'U' ? GU : c == 'D' ? GD : c == 'L' ? GL : GR).push_back(make_pair(x, y));
    }
    ans = UnReachable;
    ans = min(ans, Solve());
    for (i = 0; i < 3; ++i)
    {
        Rotate();
        ans = min(ans, Solve());
    }
    if (ans == UnReachable)
        cout << "SAFE";
    else
        cout << ans;
}

Measured memory_bytes: 17624
A, B = map(int, input().split())
A -= 1
B -= 1

ret = [[i // 50] * 100 for i in range(100)]

x, y = 0, 0
while A :
    ret[y][x] = 1
    A -= 1
    x += 2
    if x >= 100 :
        x = 0
        y += 2
        
x, y = 0, 51
while B :
    ret[y][x] = 0
    B -= 1
    x += 2
    if x >= 100 :
        x = 0
        y += 2
        
print(100, 100)
for y in range(100) :
    print(''.join(['#' if ret[y][x] == 0 else '.' for x in range(100)]))

Measured memory_bytes: 38896
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	n := sint64()
	a := map[int64]int64{}
	for ; n > 0; n-- {
		a[sint64()]++
	}
	totalSum := int64(0)
	for k, v := range a {
		totalSum += k*v
	}
	q := sint64()
	for ; q > 0; q-- {
		b := sint64()
		c := sint64()
		count := a[b]
		totalSum += (c-b)*count
		printf("%d\n", totalSum)
		delete(a, b)
		a[c] += count
	}
}


Measured memory_bytes: 9152
import sys
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))

N = II()
A = LI()

from collections import Counter
S = Counter(A)
result = sum(list(map(lambda x: int(x*(x-1)/2), S.values())))

for a in A:
	n = S[a]
	print(result-n+1)

Measured memory_bytes: 85324
#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int n, k;
vector<int> g[100100];

void dfs(int v, int par, int &ans, int limit) {
    if (limit < 0) return;
    ans++;
    forit (it, g[v]) {
        int to = *it;
        if (to != par) {
            dfs(to, v, ans, limit - 1);
        }
    }
}

int solve(int v, int lim) {
    int ans = 0;
    dfs(v, -1, ans, lim);
    return ans;
}

int solve(int a, int b, int limit) {
    int ans = 0;
    dfs(a, b, ans, limit);
    return ans;
}

int main(){
    
    cin >> n >> k;
    for (int i = 0, x, y; i < n - 1; i++) {
        cin >> x >> y;
        x--; y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    
    int ans = n - 1;
    
    if (k % 2 == 0) {
        for (int i = 0; i < n; i++) {
            ans = min(ans, n - solve(i, k / 2));
        }
    } else {
        for (int i = 0; i < n; i++) {
            forit (it, g[i]) {
                int x = i, y = *it;
                if (x > y) continue;
                ans = min(ans, n - solve(x, y, k / 2) - solve(y, x, k / 2));
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2688
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  deque<int> deq;
  rep(i, n) {
    int a;
    scanf("%d", &a);
    if (i % 2 == (n - 1) % 2)
      deq.push_front(a);
    else
      deq.push_back(a);
  }
  for (auto x : deq) printf("%d ", x);
  printf("\n");
}

Measured memory_bytes: 2944
n,k=[int(j) for j in input().split()]
l=[[] for i in range(n)]

for i in range(n-1):
    a,b=[int(j)-1 for j in input().split()]
    l[a].append(b)
    l[b].append(a)

s=set([0])
ans=k
mod=10**9+7
from collections import deque
q=deque([(0,k-1)])
while q:
    x,y=q.popleft()
    j=0
    for i in l[x]:
        if i in s:
            continue
        s.add(i)
        if y-j<=0:
            print(0)
            exit()
        ans*=y-j
        ans=ans%mod
        q.append((i,k-2))
        j+=1
print(ans)



Measured memory_bytes: 37500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] strlist = str.split(" ");
		long a = Long.parseLong(strlist[0]);
		long b = Long.parseLong(strlist[1]);
		long x = Long.parseLong(strlist[2]);

		long ax = a / x;
		long bx = b / x;
		long answer = 0;

		if(a % x == 0){
			answer = bx - ax + 1;
		}else{
			answer = bx - ax;
		}


		System.out.println(answer);

	}

}


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

int main() {

	char s_dash[51];
	char s[51];
	char t[51];

	int i = 0;
	int j = 0;
	int k = 0;
	int l = 0;
	int m = 0; // iは文章中の位置、jは検索文字列中の位置
	int flag = 0;
	int len_s = 0;
	int len_t = 0;

	scanf("%s", s_dash);
	scanf("%s", t);
	
	//printf("%s", s_dash);

	strcpy(s, s_dash);


	len_s = strlen(s_dash);
	len_t = strlen(t);

	//printf("%d\n", len_s);
	//printf("%d\n", len_t);
	//printf("%d", i);

	while (i <= (len_s - len_t)) {
		//printf("%d", i);
		j = 0;
		while (j < len_t && (s_dash[i+j] == t[j] || s_dash[i+j] == '?')) {
			//printf("%d", j);
			j += 1;
			if (j == len_t) {
				k = i;
				flag = 1;
			}
		}
		i++;
	}

	if (flag == 0) {
		printf("UNRESTORABLE\n");
	}
	
	if (flag == 1) {
		for (m = k; m < k+len_t; m++) {
			s[m] = t[m-k];
		}


		for (l = 0; l < len_s; l++) {
			if (s[l] == '?') {
				s[l] = 'a';
			}
		}
		printf("%s\n", s);
	}

	return 0;

}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;


int main() {
  int a;
  int ans=0;
  cin>>a;
  rep(i,a+1)ans+=i;
  cout<<ans<<endl;
  return 0;
  }
  

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <cassert>
#include <string.h>
#include <tuple>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<=b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pair_t;
#define MOD 1000003

//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();
///(10-(n%10))%10  10-(1桁目)取得 12->8 20->0

#define Ru(n)  ( ((n)+9)/10*10  ) //切りあげ
#define Rd(n)  ( ((n)-10)/10*10 +10 )	切り捨て


int gcd(int a,int b);
size_t length(const std::string& str) {
	return str.length();
}
bool comp(const pair_t &a, const pair_t &b) {
	return a.first < b.first;
}

int main() {
	double w,h,x,y;
	cin>>w>>h>>x>>y;

	if(x==w/2 && y==h/2){
		cout<<w*h/2.0;
		cout<<" " <<1<<endl;
	}
	else{
		cout<<w*h/2.0;
		cout<<" "<< 0<<endl;
	}
}


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


Measured memory_bytes: 256