Problem:


Score : 100 points

Problem Statement

We have N+M balls, each of which has an integer written on it.

It is known that:  

The numbers written on N of the balls are even.

The numbers written on M of the balls are odd.

Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.

It can be shown that this count does not depend on the actual values written on the balls.

Constraints

0 \leq N,M \leq 100

2 \leq N+M

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the answer.

Sample Input 1

2 1

Sample Output 1

1

For example, let us assume that the numbers written on the three balls are 1,2,4.

If we choose the two balls with 1 and 2, the sum is odd;

If we choose the two balls with 1 and 4, the sum is odd;

If we choose the two balls with 2 and 4, the sum is even.

Thus, the answer is 1.

Sample Input 2

4 3

Sample Output 2

9

Sample Input 3

1 1

Sample Output 3

0

Sample Input 4

13 3

Sample Output 4

81

Sample Input 5

0 3

Sample Output 5

3



Sample input:
2 1


Sample output:
1

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import Counter

lines = stdin.readlines()

n = int(lines[0].rstrip())
a = [int(x) for x in lines[1].rstrip().split()]

count = Counter(a)
c = {k:v for k,v in filter(lambda kv: kv[1]>1, count.items())}
res = []
for k in range(n):
    part_res = 0
    for i in c.keys():
        if not i == a[k]:
            quant = c[i]
        else:
            quant = c[i] - 1
        if quant > 1:
            part_res += int((quant * (quant - 1)) / 2)
    res.extend([part_res])

for j in range(len(res)):
    print(res[j])

Submission status: Runtime Error

Solution code:
l=int(input())
print((l/3)**3)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
li = list(map(int, input().split()))
def calc(a):
    return int(a*(a-1)*0.5)
for k in range(n):
	dic = collections.Counter(li)
	dic[li[k]] -=1
	data2 = map(calc, list(dic.values()))
	print(sum(data2))

Submission status: Runtime Error

Solution code:
h, w, k = map(int, input().split())

a = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        a[i][j] = int(s[j])

best_result = h * w + 1000

for m in range(2 ** (h - 1)):
    mask = m
    num_splits = 0
    splits = []
    i = 0
    while mask > 0:
        if (mask % 2) == 1:
            num_splits += 1
            splits.append(i)
        i += 1
        mask = mask // 2

    #print('mask = ', m, 'splits = ', splits, 'num_splits =', num_splits)

    counts = [0 for j in range(num_splits + 1)]
    current_counts = [0 for j in range(num_splits + 1)]
    result = num_splits

    for j in range(w):
        if result >= best_result:
            break
        split_index = 0
        success = True
        current_counts[0] = 0

        for i in range(h):
            if a[i][j] == 1:
                counts[split_index] += 1
                if counts[split_index] > k:
                    success = False

            current_counts[split_index] += a[i][j]

            if split_index < num_splits and i == splits[split_index]:
                split_index += 1
                current_counts[split_index] = 0

        if not success:
            result += 1
            #print('not success j = ', j, 'result = ', result, 'counts = ', counts)
            for x in range(num_splits + 1):
                counts[x] = current_counts[x]
            

    best_result = min(best_result, result)

print(best_result)

Submission status: Runtime Error

Solution code:
a = input().split()

odd = int(a[0])
mean = int(a[1])
arr[0]*odd+mean
t = 0
c = 0

for i in range(0,odd+mean):
  if(i%2==0):
    arr[i] = i
  else:
    arr[i] = i
    
for i in range(0,odd+mean):
  for j in range(0,odd+mean):
    t = 0
    t = arr[i] + arr[j]
    if(t%2==0):
      c = c + 1
    else:
      continue
print(c)

Submission status: Runtime Error

Solution code:
N = int(input("N="))
M = int(input("M="))

Submission status: Runtime Error

Solution code:
n=int(input())
a=(input().split())
for i in range(n):
    x=0
    for j in range(n):
        for k in range(n):
            if j>k:
                if a[j]==a[k] and j!=i and k!=i:
                    x=x+1
    print(x)

Submission status: Runtime Error

Solution code:
S = int(input())
a = S//3
b = a * 0.8
c = a * 1.2
ans = a * b * c
ans = ans * 1.0416666666666666
print("{0:.7f}".format(ans))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
input = sys.stdin.readline

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
L = list(map(int, input().split()))
M = [0] *(N+1)
cnt = [0] *(N+1)

for i in L:
    cnt[i] += 1
    C = cnt[i]
    if C == 2:
        M[i] = 2
    elif C > 2:
        M[i] *= C
        M[i] //= (C-2)     
ans = sum(M)//2

for i in range(N):
    B = cnt[L[i]]
    if B == 2:
        print(ans - 1)
    elif B > 2:
        print(ans -combinations_count(B,2) +combinations_count(B-1,2))
    else:
        print(ans)

Submission status: Runtime Error

Solution code:
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
import math
input_line = input().split()

N = int(input_line[0])
M = int(input_line[1])
counter = 0 
counter += combinations_count(N,2) 
counter += combinations_count(M,2)
        
print(counter)

Submission status: Runtime Error

Solution code:
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


x=0
y=0
n, m = map(int, input().split())
if n>=2:
	x = combination(n,2)
if m>=2:
	y = combination(m,2)
print(x+y)

Submission status: Runtime Error

Solution code:
import sys
import os
import math


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.buffer.readline().rstrip())
    A = list(map(int, sys.stdin.buffer.readline().split()))
    P = set(A)

    for n in range(N):
        ary = A[n + 1:] + A[:-len(A) + n]
        tmp = 0
        for p in P:
            t = ary.count(p)
            tmp += (t * (t - 1)) // 2

        print(tmp)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A

# counter ver
A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return math.factorial(j) // math.factorial(2) // math.factorial(j - 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))

Submission status: Runtime Error

Solution code:
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
import math
input_line = input().split()

N = int(input_line[0])
M = int(input_line[1])
counter = 0 

counter = math.factorial(N) / math.factorial(N - 2)* math.factorial(2) + math.factorial(M) / math.factorial(M - 2)* math.factorial(2)
        
print(combinations_count(N,2)+ combinations_count(M,2))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

list1 = []
list2 = []

count = 0
C = 0
o = 0
b = 0
G = 0

for i in range(1, N + 1):
    list1.append(i * 2)
    if i >= 2:
        C = sum(list1)
        list1.remove(list1[o])
        o += 1
    if C % 2 == 0:
        count += 1
    C = 0

for q in range(1, M + 1):
    list2.append((q * 2) - 1)
    if q >= 2:
        G = sum(list2)
        list2.remove(list2[b])
        b += 1
    if G % 2 == 0:
        count += 1
    G = 0

for w in list1:
    for e in list2:
        total = w + e
        if total % 2 == 0:
            count += 1

print(count)

Submission status: Runtime Error

Solution code:
import math
def j(n):
    return math.factorial(n) // (2*math.factorial(n-2))
n,m = map(int,raw_input().split())
if n == 1 and m == 1: 
    print 0
else:
    print j(n)+j(m)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
import math
import collections
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def get_result(key, c):
    ans = 0
    for d in c.items():
        if d[0] == key:
            value = d[1]-1
        else:
            value = d[1]
        if value > 1:
            ans += combinations_count(value, 2)
    return int(ans)
ans = {}
tmp = a.copy()
tmp.sort()
c = collections.Counter(tmp)
for k in range(n):
    key = a[k]
    if key in ans:
        print(ans[key])
    else:
        ans[key] = get_result(key, c)
        print(ans[key])

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import mul
from functools import reduce


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n = int(input())
nums = list(map(int, input().split()))
d = Counter(nums)
# for num in nums:
#     if not d.get(num):
#         d[num] = 1
#     else:
#         d[num] += 1

combination_d = {}

for num in nums:
    counter = 0
    if combination_d.get(num):
        print(combination_d[num])
        continue

    nums.count(num)

    for key in d.keys():
        if key == num:
            if d[key]-1 >= 2:
                counter += cmb(d[key]-1, 2)
        else:
            if d[key] >= 2:
                counter += cmb(d[key], 2)
    
    combination_d[num] = counter
    print(counter)

Submission status: Runtime Error

Solution code:
import collections
import math

#****************************************************************
def comb(n):
    if n < 2:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
#****************************************************************

N = int(input())
A = list(map(int, input().split()))

c = collections.Counter(A)
dict_ans = {i:0 for i in c.keys()}
full_ans = sum(list(map(comb, c.values())))

for i in c.keys():
    target = c.copy()
    target[i] -= 1
    if target[i] == 0:
        dict_ans[i] = full_ans
    else:
        dict_ans[i] = sum(list(map(comb, target.values())))

for i in A:
    print(dict_ans[i])

Submission status: Runtime Error

Solution code:
#include<stdio.h>

long int multiplyNumbers(int n) {
    if (n>=1)
        return n*multiplyNumbers(n-1);
    else
        return 1;
}

int main(){
	long int N, M;
	scanf("%ld %ld", &N, &M);
	long int c1 = multiplyNumbers(N)/((multiplyNumbers(N-2))*multiplyNumbers(2));
	long int c2 = multiplyNumbers(M)/((multiplyNumbers(M-2))*multiplyNumbers(2));
	printf("%d", c1+c2);
	return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

# res = [] # solution for each key in A
res_list = {} # solution for each value in A

# counter ver
A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return math.factorial(j) // math.factorial(2) // math.factorial(j - 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  cnt = combs[m]

  n = s
  n -= cnt # the only inaccurate entry
  n += ncr(A_c[m] - 1)
  res_list[m] = n

res = ''
for k in range(N):
  res += '\n' + str(res_list[A[k]])
print(res[1:])
# print('\n'.join([str(s) for s in res]))

Submission status: Runtime Error

Solution code:
L= int(input())
A = (L/3)*(L/3)*(L/3)
print (A)

Submission status: Runtime Error

Solution code:
def cmb(n):
	if n<=1:
		return 0
	else:
		return int(n*(n-1)*0.5)
N = int(input())
A = [int(x) for x in input().split()]
ans=[0]*N
lists={}
k=0
for i in range(N):
  if not A[i] in lists:
    l=cmb(A.count(A[i]))
    m=cmb(A.count(A[i])-1)-l
    k+=l
    lists[A[i]]=m
    ans[i]=m
  else:
    ans[i]=lists[A[i]]
    
for i in range(N):
  ans[i]+=k
  print(ans[i])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = [0] * N
for i in range(N):
  count[A[i] - 1]  += 1
  
nanimo = 0 
for i in range(N):
  nanimo += count[i] * (count[i] - 1) // 2
for i in range(N):
  tekito = count[A[i] - 1]
  if tekito == 1:
    s = nanimo
  else:
    s = nanimo -  ((tekito * (tekito - 1) //2) - ((tekito - 1) * (tekito - 2) //2))
  print(s)

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
a=0
list1 = list(map(int, input().split()))
c = collections.Counter(list1)
for i in range(N):
    a+=int(c[i+1]*(c[i+1]-1)/2)
for i in range(N):
    if c[list1[i]]!=0:
        print(a-c[list1[i]]+1)
    else:
        print(a)

Submission status: Runtime Error

Solution code:
import math
N = (int(input()))
items = list(map(int,input().split()))
for i in range(len(items)):    
    rest = items[:i] + items[i+1:]
    rest_unique = sorted(set(rest))
    out = 0
    for j in rest_unique:
        cnt = sum([1 for x in rest if x == j])
        if cnt >= 2:
            out = out + math.factorial(cnt)/math.factorial(cnt-2)/2
    print(int(out))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A

# counter ver
A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return math.factorial(j) // math.factorial(2) // math.factorial(j - 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  cnt = combs[m]

  n = s
  n -= cnt # the only inaccurate entry
  n += ncr(A_c[m] - 1)
  res_list[m] = n

for k in range(N):
  print(res_list[A[k]])
# print('\n'.join([str(s) for s in res]))

Submission status: Runtime Error

Solution code:
import math
def combination(n, r):
    if n <= 0:
        return 0
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

n, m= input().split(" ")
n = int(n)
m = int(m)

print(combination(n, 2) + combination(m,2))

Submission status: Runtime Error

Solution code:
import math

def inputlist(): return [int(i) for i in input().split()]

def kumiawase(num):
    r = 2
    if num != 1 or num != 0:
        return math.factorial(num) // (math.factorial(num - r) * math.factorial(r))
    else:
        return 0

def main():
    N, M = inputlist()
    print(kumiawase(N) + kumiawase(M))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import Counter

lines = stdin.readlines()

n = int(lines[0].rstrip())
a = [int(x) for x in lines[1].rstrip().split()]

c = Counter(a)

res = []
for k in range(n):
    part_res = 0
    for i in c.keys():
        if not i == a[k]:
            quant = c[i]
        else:
            quant = c[i] - 1
        if quant > 1:
            part_res += int((quant * (quant - 1)) / 2)
    res.extend([part_res])

for j in range(len(res)):
    print(res[j])

Submission status: Runtime Error

Solution code:
def factorial(n):
    if n == 1:
        return 1
    else:
        return n * factorial(n-1)
a,b=map(int, input().split())
cnt=0
if a>1:
    cnt=(factorial(a)/((factorial(a-2))*2))
if b>1:
    cnt=(factorial(b)/((factorial(b-2))*2))+cnt
print(int(cnt))

Submission status: Runtime Error

Solution code:
mport itertools

n,m = map(int, input().split())
print(len(list(itertools.combinations(range(m),2))) + len(list(itertools.combinations(range(n),2))))

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())

if a <= 1 & b <= 1:
    print("0")
    exit()
if a <= 1:
    print(combinations_count(b, 2))
    exit()
if b <= 1:
    print(combinations_count(a, 2))
    exit()
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

print(combinations_count(a, 2) + combinations_count(b, 2))

Submission status: Runtime Error

Solution code:
def factorial(n):
    if n == 1:
        return 1
    else:
        return n * factorial(n-1)
a,b=map(int, input().split())
cnt=0
if a>0:
    cnt=(factorial(a)/((factorial(a-2))*2))
if b>0:
    cnt=(factorial(b)/((factorial(b-2))*2))+cnt
print(int(cnt))

Submission status: Runtime Error

Solution code:
n = int(input())
nums = list(map(int, input().split()))

values = {}
for i in nums:
  if i in values: values[i] += 1
  else: values[i] = 1

sums={} # 各値ごとの組み合わせ数
subsums={} # 各値ごとの組み合わせ数（ボールがないとき版
allsum = 0
for k,v in values.items():
  sums[k] = v * (v - 1) / 2
  undersum = (v - 2) * (v - 1) / 2 if v > 1 else 0
  subsums[k] = sums[k] - undersum
  allsum += sums[k]

# res={} # 各値のない時版 + 他の合計
# for k,v in sums.items():

for i in nums:
  print(int(allsum - subsums[i]))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())

def fac(n):
  if n == 0:
    return 1
  else:
    return n * fac(n-1)

def binom(n,k):
  if n==0:
    return 0
  else:
    return fac(n) // (fac(n-k) * fac(k))

print(binom(n,2) + binom(m,2))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = [0] * N
#answer = [-1] * N
#p = [0] * N
for i in range(N):
  count[i]  = A.count(i + 1)
  
nanimo = 0 
for i in range(N):
  nanimo += count[i] * (count[i] - 1) // 2
for i in range(N):
  tekito = count[A[i] - 1]
  if tekito == 2:
    s = nanimo - 1
  elif tekito == 1:
    s = nanimo
  else:
    s = nanimo -  ((tekito * (tekito - 1) //2) - ((tekito - 1) * (tekito - 2) //2))
  print(s)

Submission status: Runtime Error

Solution code:
import math

def inputlist(): return [int(i) for i in input().split()]

def kumiawase(num):
    r = 2
    if num != 1:
        return math.factorial(num) // (math.factorial(num - r) * math.factorial(r))
    else:
        return 0

def main():
    N, M = inputlist()
    print(kumiawase(N) + kumiawase(M))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)

for k in range(N):
  sum_k = 0
  temp_c = c.copy()
  temp_c[A[k]] -= 1
  for v in temp_c.values():
    if v > 1:
      sum_k += factorial(v) / 2 / factorial(v - 2)
  print(int(sum_k))

Submission status: Runtime Error

Solution code:
import math
def combination(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

n, m= input().split(" ")
n = int(n)
m = int(m)

print(combination(n, 2) + combination(m,2))

Submission status: Runtime Error

Solution code:
import math

def inputlist(): return [int(i) for i in input().split()]

def kumiawase(num):
    r = 2
    return math.factorial(num) // (math.factorial(num - r) * math.factorial(r))

def main():
    N, M = inputlist()
    print(kumiawase(N) + kumiawase(M))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
 
def resolve():
    n = int(input())
    a = [int(x) for x in input().split()]
 
    for k in range(n):
        # 初期化
        ak = [x for x in a] # deep copy
        del ak[k]
        kumi = 0
        ended = []
 
        # loop
        for i in range(n - 1):
            a0 = ak[i] # i番目の要素を検査
            if a0 in ended:
                continue
            cnt = ak.count(a0)
            if cnt >= 2:
                kumi += kumiawase(cnt ,2)
            ended.append(a0)
        print(kumi)
 
def kumiawase(n, r):
    return math.factorial(n) // (r * math.factorial(n - r))
 
resolve()

Submission status: Runtime Error

Solution code:
import decimal

L=int(input())

#decimal.getcontext().prec = 6
x = decimal.Decimal(L / 3)

V=decimal.Decimal(x*x*x)

print("{:.24f}".format(V))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if M == 0 and N == 0:
    print(0)
elif M == 0:
    print(cmb(N, 2))
elif N == 0:
    print(cmb(M, 2))
elif M <= 1 and N <= 1:
    print(0)
else:
    a = cmb(M, 2)
    b = cmb(N, 2)
    print(a + b)

Submission status: Runtime Error

Solution code:
import itertools


def main():
    n = int(input())
    a = [int(i) for i in input().split(" ")]
    for i, j in enumerate(a):
        print(len([k for k in itertools.combinations([l for k, l in enumerate(a) if k != i], 2) if k[0] == k[1]]))


main()

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N,M = (int(x) for x in input().split())
a = int(comb(N, 2)) + int(comb(M, 2))
print(a)

Submission status: Runtime Error

Solution code:
import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
N = I()
A = LI()
_123 = [0]*N
_123count = [0]*N
for x in A:
    _123[x-1] += 1
_123copy = copy.copy(_123)
_123copy.sort(reverse=True)
_count = {}
for i,x in enumerate(_123copy):
    if x==0:
        break
    if x==1:
        _123count[i] = 0
    elif i!=0 and _123copy[i]==_123copy[i-1]:
        _123count[i] = _123count[i-1]
    else:
        _123count[i] = math.factorial(x)//((math.factorial(x-2))*(math.factorial(2)))
        _count[x] = _123count[i]
_sum = sum(_123count)
for x in A:
    temp = _123[x-1]-1
    if temp<=0:
        print(_sum)
    elif temp==1:
        print(_sum-1)
    else:
        if (temp+1) in _count:
            tempminus = _count[temp+1]
        else:
            tempminus = math.factorial(temp+1)//((math.factorial(temp-1))*(math.factorial(2)))
            _count[temp+1] = tempminus
        if (temp) in _count:
            tempplus = _count[temp]
        else:
            tempplus = math.factorial(temp)//((math.factorial(temp-2))*(math.factorial(2)))
            _count[temp] = tempplus
        print(_sum-tempminus+tempplus)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if M == 0:
    print(cmb(N, 2))
elif N == 0:
    print(cmb(M, 2))
elif M <= 1 and N <= 1:
    print(0)
else:
    a = cmb(M, 2)
    b = cmb(N, 2)
    print(a + b)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input().split()
 
for i in range(n):
  b = a[:]
  del b[i]
  k = 0
  c = set(b)
  for t in c:
    num = b.count(t)
    for i in range(num):
      k += i
  print(k)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
l=[int(x) for x in input().split()]
for k in range(n):
  L=l.pop(k)
  ans=0
  for i in range(n+1):
    c=l.count(i)
    if c>1:
      ans=ans+math.factorial(c) // (math.factorial(c- 2) * 2)
  print(ans)
  l.insert(k,L)

Submission status: Runtime Error

Solution code:
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1 or n == 0:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1 or n == 0:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Submission status: Runtime Error

Solution code:
import math
a, b = map(int, input().split())
# b = int(input())

if a < 2:
    s = ((math.factorial(b))/(math.factorial(b-2)))/2
    print(int(s))
elif b < 2:
    f = ((math.factorial(a))/(math.factorial(a-2)))/2
    print(int(f))
else:
    f = ((math.factorial(a))/(math.factorial(a-2)))/2
    s = ((math.factorial(b))/(math.factorial(b-2)))/2
    c = f+s
    print(int(c))

Submission status: Runtime Error

Solution code:
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1 or 0:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1 or 0:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Submission status: Runtime Error

Solution code:
    main()
import math
n,m=map(int,input().split())
def cc(n,r):
    return int(math.factorial(n)/(math.factorial(n-r)*math.factorial(r)))
if n>=2:
    if m>=2:
        print(cc(n,2)+cc(m,2))
    else:
        print(cc(n,2))
else:
    if m>=2:
        print(cc(m,2))
    else:
        print(0)

Submission status: Runtime Error

Solution code:
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import copy

a = input()
a=int(a)
ball=[]
mydict={}
DPdict={}
temp=input().split(" ")
for i in range(a):
    if not (temp[i] in mydict):
        mydict[temp[i]]=1
    else:
        mydict[temp[i]]+=1
    ball.append(temp[i])

for i in range(len(ball)):
    rettemp=0
    if i in DPdict:
        print(int(DPdict[i]))
        continue
    for j in mydict.keys():

        if ball[i]==j:
            rettemp+=(mydict[j]-1)*(mydict[j]-2)/2
        else :
            rettemp+=(mydict[j]-1)*(mydict[j])/2
    DPdict[i]=rettemp
    print(int(rettemp))

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import Counter

def main():

    input = stdin.readline

    N = int(input())

    A = [0] * N

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

    all_case = 0

    num_all = Counter(A) 

    for k in num_all.values():
        all_case += (k * (k-1)) // 2

    for i in A:
        ans = all_case - (num_all[i] - 1)
        print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from scipy.special import comb

gusu, kisu = input().split()
gusu = int(gusu) # 個数
kisu = int(kisu) # 個数
gusu_num = comb(gusu, 2, exact=True)
kisu_num = comb(kisu, 2, exact=True)
print(gusu_num + kisu_num)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
def cmd(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))



a = cmb(N+M, 2)
b = cmb(N, 1)
c = cmb(M, 1)
if N==0:
    print(a)
elif M==0:
    print(a)
else:
    print(int(a-(b*c)))

Submission status: Runtime Error

Solution code:
m,n=map(int,input())
print(m*(m-1)+n*(n-1))

Submission status: Runtime Error

Solution code:
import math
N,M=map(int,input().split())
def kumiawase(n):
    a=math.factorial(n)
    r=math.factorial(2)
    return a / (r*math.factorial(n-2))
print(int(kumiawase(M)+kumiawase(N)))

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)

x = (N-1)/2
y = (N+3)/2

a = S[:x]
b = S[y:N]

if a == reversed(a) and b == reversed(b):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
sum = int(input())
print((sum/3)*(sum/3)*(sum/3))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
c = [A.count(i + 1) for i in range(N)]
ans = [c[i] * (c[i] - 1) // 2 for i in range(N)]
s = sum(ans)

for val in A:
  m = c[val - 1] - 1
  print(s - m)

Submission status: Runtime Error

Solution code:
import math
n, m = input().split()
m = int(m)
n = int(n)
mNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
nNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

Submission status: Runtime Error

Solution code:
import math
a = int(input())
b = int(input())

if a<2:
    s = ((math.factorial(b))/(math.factorial(b-2)))/2
    print(s)
elif b<2:
    f = ((math.factorial(a))/(math.factorial(a-2)))/2
    print(f)
else:
    f = ((math.factorial(a))/(math.factorial(a-2)))/2
    s = ((math.factorial(b))/(math.factorial(b-2)))/2
    c = f+s
    print(c)

Submission status: Runtime Error

Solution code:
import math

N, M = map(int, input().split())

def comb(n, r):
    if n == 0:
        return 0
    if r == 0:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N + M < 2:
    print(0)
elif N == 1 and M == 1:
    print(0)
else:
    ans = comb(N, 2) + comb(M, 2)
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_set = list(set(A))
Ad = {a_set: A.count(a_set) for a_set in A_set}
score_sum = sum([(x>1) * x * (x-1) / 2 for x in list(Ad.values())])
Ad_score = {ad_key: score_sum - (ad_value -1) * (ad_value > 0) for ad_key, ad_value in Ad.items()}
A_out = [str(int(Ad_score[a])) for a in A]

print('\n'.join(A_out))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
k = []
q = []
for i in range(n):
    t = a[i]
    if t in k:
        q[k.index(t)] += 1
    else:
        k.append(t)
        q.append(1)
M = 0
for i in q:
    if i > 1:
        M += i*(i-1)//2
for i in range(n):
    w = a[i]
    if w in k:
        m = q[k.index(w)]
        print(M-m+1)
    else:
        print(M)

Submission status: Runtime Error

Solution code:
import math
 
def comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a_list = list(map(int, input().split()))
a_list.append(n + 100)

for i in range(len(a_list) - 1):
  tmp_list = a_list[:]
  del tmp_list[i]
  tmp_list.sort()
  count = 0
  tmp_count = 0
  for j in range(1, len(tmp_list)):
    if tmp_list[j] == tmp_list[j - 1]:
      tmp_count += 1
    else:
      if tmp_count >= 1:
      	count += comb(tmp_count + 1, 2)
      tmp_count = 0
  print(count)

Submission status: Runtime Error

Solution code:
#N 2*n M 2*m+1
#gugu ki ki
N = int(input())
M = int(input())
x = N*(N-1)/2
y = M*(M-1)/2
print(int(x+y))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if M <= 1 and N <= 1:
    print(0)
elif M == 2 and N == 2:
    print(2)
elif M == 2:
    print(cmb(N, 2)+1)
elif N == 2:
    print(cmb(M, 2)+1)
elif M == 0:
    print(cmb(N, 2))
elif N == 0:
    print(cmb(M, 2))
else:
    a = cmb(M, 2)
    b = cmb(N, 2)
    print(a + b)

Submission status: Runtime Error

Solution code:
n=int(input())
l=n/3
print(l*l*l)

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
x = a[0]
y = a[1]
z = 1
if(x is not z){
    c = (combinations_count(x, 2));
}
else{
    c = 0;
}
if(y is not z){
    d = (combinations_count(y, 2));
}
else{
    d = 0;
}
print(c + d)