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:
A = np.zeros((N+1,S+1,3),dtype=np.int16)

Submission status: Runtime Error

Solution code:
import numpy as np
N,S = map(int,input().split())
list = np.int32(input().split())
A = [[[0,0,0]for i in range(S+1)]for j in range(N+1)]
A[0][0][0] = 1
for i in range(N):
    for j in range(S+1):
        A[i+1][j][0] += A[i][j][0]
        A[i+1][j][0] %= 998244353
        A[i+1][j][1] += A[i][j][0] + A[i][j][1]
        A[i+1][j][1] %= 998244353
        A[i+1][j][2] += A[i][j][0] + A[i][j][1] + A[i][j][2]
        A[i+1][j][2] %= 998244353
        if list[i] + j <= S:
            A[i+1][list[i]+j][1] += A[i][j][0] + A[i][j][1]
            A[i+1][list[i]+j][1] %= 998244353
            A[i+1][list[i]+j][2] += A[i][j][0] + A[i][j][1]
            A[i+1][list[i]+j][2] %= 998244353
print(A[N][S][2] % 998244353)

Submission status: Runtime Error

Solution code:
import math
def comb(a, b):
  return math.factorial(a) / (math.factorial(a - b) * math.factorial(b))
print(comb(n + m, 2) - n * m)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from itertools import product
 
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
 
i = 0
while i < len(S):
  if '1' in S[i]:
    i += 1
  else:
    del S[i]
H = len(S)
 
C = [[int(s[i]) for s in S] for i in range(W)]#列を一括りにする
 
total = sum(sum(c) for c in C)#すべての値の合計を算出
 
if total <= K:
  answer = 0
else:
  answer = H * W
  for X in product([False, True], repeat=H-1):#Hは行数
    #あるXについて一回目のfor文が回る
    ans = sum(X)#Trueの数を換算
    if ans > answer:
      continue
    M = [[0]]
    for i, x in enumerate(X):
      if x:#Trueなら実行
        M.append([])#Trueの数の配列が作成される
      M[-1].append(i+1)#一番最後にその番目をappendする
    print('M{}'.format(M))
    D = [0] * len(M)#初期値を設定
    for c in C:
      print('c{}'.format(c))
      for k, m in enumerate(M):
        print('m{}'.format(m))
        D[k] += sum(c[i] for i in m)#k番目の要素に足していく
        #Dにどんどん代入することによってどの列まで足すことができるか算出することができる
      print('D1{}'.format(D))
      if any(d > K for d in D):#一つでもKを超えていたら
        ans += 1
        if ans > answer:
          break
        D = [sum(c[i] for i in m) for m in M]#Dの更新(1番最初のDに戻る)
        print('D2{}'.format(D))
        if any(d > K for d in D):#一つでもKを超えていたら
          ans = answer + 1#ansの更新
          break
    answer = min(answer, ans)

print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
  import math
  def comb(n, r):
  	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))
  base = comb(n+m, n * 2) + comb(n+m, m * 2)
  print(base)

Submission status: Runtime Error

Solution code:
 import math
 def comb(n, r):
 	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
 base = comb(n+m, n * 2) + comb(n+m, m * 2)
 print(base)

Submission status: Runtime Error

Solution code:
N = int(input())

input_1 = input()
input_2 = input_1.split()

for k in range(N):
    A = map(int, input_2)

    def equal(num):
        return num / 1
    A = [equal(x) for x in A]

    ans = 0

    A.remove(A[k])

    for l in range(N - 1):
        for m in range(N - 1):
            if A[l] == A[m]:
                ans += 1
        
        ans -= 1

    ans = ans / 2

    print(int(ans))

Submission status: Runtime Error

Solution code:
import math

num=int(input())
target=list(map(int, input().split()))
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))

for i in range(num):
    A=target.copy()
    A.pop(i)
    B=[x for x in set(A) if A.count(x) > 1]
    out=0 
    for j in B:
        base = comb(A.count(j),2)
        out=out+base
    print(out)

Submission status: Runtime Error

Solution code:
n=int(input())
n=n/3
x=n**3
print ("{0:.6f}".format(x))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
H,W,K = map(int,input().split())
A = [0]*H
for i in range(H):
    A[i] = input()
s = 10000
for i in range(2**(H-1)):
    count = 0
    B = [0]*H
    for j in range(H-1):
        if (i >> j & 1):
            B[j] = 1
            count += 1
    C = [0]*(count + 1)
    for j in range(W):
        a = [0]*(count + 1)
        n = 0
        for k in range(H):
            a[n] += int(A[k][j])
            C[n] += int(A[k][j])
            if B[k] == 1:
                n += 1      
        if max(C) > K:
            count += 1
            C[:] = a[:]
    if s > count:
        s = count
print(s)

Submission status: Runtime Error

Solution code:
n=int(input())
m=int(input())
print((n*(n-1)+m*(m-1))//2)

Submission status: Runtime Error

Solution code:
n=int(input())
m=int(input())
c=int((n*(n-1))//2)
d=int((m*(m-1))//2)
print(c+d)

Submission status: Runtime Error

Solution code:
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=int(input(0))
if m>1:
    d=int((m*(m-1))/2)
else:
    d=int(input(0))
print(c+d)

Submission status: Runtime Error

Solution code:
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=int(0)
if m>1:
    d=int((m*(m-1))/2)
else:
    d=int(0)
print(c+d)
return 0

Submission status: Runtime Error

Solution code:
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=int(0)
if m>1:
    d=int((m*(m-1))/2)
else:
    d=int(0)
print(c+d)

Submission status: Runtime Error

Solution code:
n=int(input())
m=int(input())
if n>1:
    c=int((n*(n-1))/2)
else:
    c=0
if m>1:
    d=int((m*(m-1))/2)
else:
    d=0
print(c+d)

Submission status: Runtime Error

Solution code:
n=int(input())
m=int(input())
c=0
d=0
if n>1:
    c=int((n*(n-1))/2)
if m>1:
    d=int((m*(m-1))/2)
print(c+d)

Submission status: Runtime Error

Solution code:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
 
n, m = input().split(" ")
 
print(comb(n, 2) + comb(m, 2))

Submission status: Runtime Error

Solution code:
MOD = 998244353


class DP:

    def __init__(self, X, Y, Z):
        self._X = X
        self._Y = Y
        self._Z = Z
        self._list = [0] * (X * Y * Z)
    
    def get(self, x, y, z):
        return self._list[x*(self._Y*self._Z) + y*self._Z + z]
    
    def set(self, x, y, z, v):
        self._list[x*(self._Y*self._Z) + y*self._Z + z] = v


def solve():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))

    # dp = [[[0 for _ in range(3)] for _ in range(S+1)] for _ in range(N+1)]
    dp = DP(N+1, S+1, 3)

    # dp[0][0][0] = 1
    dp.set(0, 0, 0, 1)

    for i in range(0, N):
        for s in range(0, S+1):
            # dp[i+1][s][0] = dp[i][s][0]
            dp.set(i+1, s, 0, dp.get(i, s, 0))
            if s - A[i] >= 0:
                # dp[i+1][s][1] = (dp[i][s][1] + dp[i][s][0] + dp[i][s-A[i]][1] + dp[i][s-A[i]][0]) % MOD
                dp.set(i+1, s, 1, (dp.get(i, s, 1) + dp.get(i, s, 0) + dp.get(i, s-A[i], 1) + dp.get(i, s-A[i], 0)) % MOD)
                # dp[i+1][s][2] = (dp[i][s][2] + dp[i][s][1] + dp[i][s][0] + dp[i][s-A[i]][1] + dp[i][s-A[i]][0]) % MOD
                dp.set(i+1, s, 2, (dp.get(i, s, 2) + dp.get(i, s, 1) + dp.get(i, s, 0) + dp.get(i, s-A[i], 1) + dp.get(i, s-A[i], 0)) % MOD)
            else:
                # dp[i+1][s][1] = (dp[i][s][1] + dp[i][s][0]) % MOD
                dp.set(i+1, s, 1, (dp.get(i, s, 1) + dp.get(i, s, 0)) % MOD)
                # dp[i+1][s][2] = (dp[i][s][2] + dp[i][s][1] + dp[i][s][0]) % MOD
                dp.set(i+1, s, 2, (dp.get(i, s, 2) + dp.get(i, s, 1) + dp.get(i, s, 0)) % MOD)

    # print(dp[N][S][2])
    print(dp.get(N, S, 2))


solve()

Submission status: Runtime Error

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

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

return comb(n, 2) + comb(m, 2)

Submission status: Runtime Error

Solution code:
import math

 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())

n,m,K=IA()
a=["" for i in range(0,n)]
for i in range(0,n):
    a[i]=input()

ans=n*m+1
for k in range(0,1<<(n-1)):
    res=0
    temp=[]
    for j in range(0,(n-1)):
        if (k&(1<<(j)))!=0:
            temp.append(j)
            res+=1
    le=len(temp) 
    if le==0:
        temp.append(n-1)
        
    if temp[le-1]!=n-1:
        temp.append(n-1)
    le=len(temp) 
    #print(k)  
    #print(temp)


    
    sum1=[0 for i in range(0,11)]
    flag=0
    for j in range(0,m):
        last=0
        for t in range(0,le):
            for w in range(last,temp[t]+1):
                ## print(str(w)+" "+str(j))
                if a[w][j]=='1':
                    sum1[t]+=1
            last=temp[t]+1
            if sum1[t]>K:
                
                res+=1
                last=0
                sum1=[0 for i in range(0,11)]
                for t1 in range(0,le):
                    for w1 in range(last,temp[t1]+1):
                        if a[w1][j]=='1':
                            sum1[t1]+=1
                    if sum1[t]>K:
                        flag=1
                        res=n*m+1
                        break
                    last=temp[t]+1
                    
                break
        if flag==1:break
       
    ans=min(res,ans)
                
            
    
print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
list = input().rstrip().split(" ")
gusu = int(list[0])
kisu = int(list[1])
#奇数奇数の場合
kiki = int(comb(kisu, 2, exact=True))
#偶数偶数の場合
gugu = int(comb(gusu, 2, exact=True))
print(kiki + gugu)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
print(n*(n-1)//2 + m*(m-1)//2a)

Submission status: Runtime Error

Solution code:
import math
import functools
from operator import add

def main():
    h,w,k = tuple([int(t)for t in input().split()])

    s = [[int(i) for i in list(input())] for _ in range(h)]
    
    cusum = [accumelist(s_) for s_ in s]

    candidates = []

    for i in range(1<<(h-1)):
        subcu = divide(cusum,i)
        subs = divide(s,i)

        subcusum = []

        rowsum = []

        for sub_ in subcu:
            subcusum.append(functools.reduce((lambda a,b:list(map(add,a,b))),sub_))

        for sub_ in subs:
            rowsum.append(functools.reduce((lambda a,b:list(map(add,a,b))),sub_))


        cutnum = 0

        temp = [0]*len(subcusum)

        for j in range(w):
            for l in range(len(subcusum)):
                if subcusum[l][j]-temp[l]>k:
                    if rowsum[l][j]>k:
                        cutnum+=10000
                    temp = [x[j-1] for x in subcusum]
                    cutnum+=1
                    break
        
        candidates.append(cutnum+bin(i).count('1'))

    print(min(candidates))
            
def divide(s,i):
    subs = []
    counter = 0
    pos = 0
    while i!= 0:
        counter +=1
        if i%2==1:
            subs.append(s[pos:counter])
            pos = counter
        i >>=1
 
    subs.append(s[pos:])
    return subs

def accumelist(s):
    if s == []:
        return []
    res = [s[0]]
    for i in range(1,len(s)):
        res.append(res[i-1]+s[i])

    return res

def _add_(a,b):
    return map(add,a,b)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
L = map(int, input())

l = L/3

l*l*l

print('{:.0f}'.format(l*l*l))

Submission status: Runtime Error

Solution code:
import math
import functools
from operator import add

def main():
    h,w,k = tuple([int(t)for t in input().split()])

    s = [[int(i) for i in list(input())] for _ in range(h)]
    
    cusum = [accumelist(s_) for s_ in s]

    candidates = []

    for i in range(1<<(h-1)):
        subcu = divide(cusum,i)
        subcusum = []

        for sub_ in subcu:
            subcusum.append(functools.reduce((lambda a,b:list(map(add,a,b))),sub_))

        cutnum = 0
        j=0
        temp = [0]*len(subcusum)

        while j<w:
            for l in range(len(subcusum)):
                pos = 0
                if subcusum[l][j]-temp[l]>k:
                    pos = j
                    j-=1
                    if j-pos==0:
                        cutnum+=10000
                    temp = [x[j-1] for x in subcusum]
                    cutnum+=1
                    break
            j+=1
        
        candidates.append(cutnum+bin(i).count('1'))

    print(min(candidates))
            
def divide(s,i):
    subs = []
    counter = 0
    pos = 0
    while i!= 0:
        counter +=1
        if i%2==1:
            subs.append(s[pos:counter])
            pos = counter
        i >>=1
 
    subs.append(s[pos:])
    return subs

def accumelist(s):
    if s == []:
        return []
    res = [s[0]]
    for i in range(1,len(s)):
        res.append(res[i-1]+s[i])

    return res

def _add_(a,b):
    return map(add,a,b)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
a,b=int(input().split())
print((a*(a-1))//2+(b*(b-1))//2)

Submission status: Runtime Error

Solution code:
from scipy import special

def main():
    n, m = map(int, input().split())

    ans = 0
    ans += special.comb(n, 2)
    ans += special.comb(m, 2)

    print(int(ans))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from scipy import special

def main():
    n, m = map(int, input().split())

    ans = 0
    ans += special.comb(n, 2)
    ans += special.comb(m, 2)

    print(int(ans))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from scipy.special import comb

a,b = map(int,input().split()) #a even b odd
x = 0

x = comb(a, 2, exact=True) + comb(b, 2, exact=True)
    

print(x)

Submission status: Runtime Error

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

ncount = 0 if n < 2 else n*(n-1)/2
mcount = 0 if m < 2 else m*(m-1)/2

print(str(ncount + mcount))

Submission status: Runtime Error

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

n, m = [int(i) for i in input().split(" ")]

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m; cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
  count=n*(n-1)//2
  countt=m*(m-1)//2
print(count+countt)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
print((M(M-1)+N(N-1))/2)

Submission status: Runtime Error

Solution code:
def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
ans=0
B=set(A)
L=[0]*N
for i in range(N):
    L[A[i]-1]+=1
for i in B:
    ans+=Comb(L[i-1],2)
for i in range(N):
    pri=ans
    pri=ans-L[A[i]-1]+1
    print(pri)

Submission status: Runtime Error

Solution code:
def nCr(n, r): 
  return (fact(n) / (fact(r)  
                * fact(n - r))) 
  
# Returns factorial of n 
def fact(n): 
  res = 1  
  for i in range(2, n+1): 
	res = res * i 
  return res
n, m = list(map(int, input().split()))

print(nCr(n + m, n) * nCr(n + m - 1, n - 1) + nCr(n + m, m) * nCr(n + m - 1, m - 1))

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
O=1
P=1
while N>1,M>1:
  O=O*N,M=P*M
  N-=1,M-=1
print(O+P)

Submission status: Runtime Error

Solution code:
N,M=input()
O=1,P=1
while N>1,M>1:
  O=O*N,P=P*M
  N-=1,M-=1
print(O+P)

Submission status: Runtime Error

Solution code:
print(pow(int(input()), 3)/27)

Submission status: Runtime Error

Solution code:
N=input()
M=input()
O=1
P=1
while N>1:
  O=O*N
  N-=1
while M>1:
  P=P*M
  M-=1
print(O+P)

Submission status: Runtime Error

Solution code:
N=input()
M=input()
O=N/2
P=N//2
Q=M/2
R=M//2
if O=P:
  N=O
elif O!=P:
  N=P
if Q=R:
  M=Q
elif Q!=R:
  M=R
print(N+M)

Submission status: Runtime Error

Solution code:
def main(N, M):
  retrun N*(N-1) + M*(M-1)

Submission status: Runtime Error

Solution code:
def hirohidus(N, M):
  retrun N*(N-1) + M*(M-1)

Submission status: Runtime Error

Solution code:
Answer = N*(N-1) + M*(M-1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def comb(n):
    if n == 1:
        return 0
    else:
        return int(n*(n-1)/2)

n = int(input())
AS = list(map(int,input().split()))

origin = list(set(AS))
num = []
for i in origin:
    num.append(AS.count(i))
comb_list = [-1]*(max(num)+1)
all_num = 0
for i in num:
    if comb_list[i] == -1:
        all_num += comb(i)
        comb_list[i] = comb(i)
    else:
        all_num += comb_list[i]
    
for i in range(n):
    j = num[origin.index(AS[i])]
    ans = all_num - (j-1)
    print(ans)

Submission status: Runtime Error

Solution code:

def main():
    from itertools import product

    H,W,K = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    i = 0
    while i < len(S):
        if '1' in S[i]:
            i += 1
        else:
            del S[i]
    H = len(S)
 
    S = [[int(s[i]) for s in S] for i in range(W)]

    if sum(sum(s) for s in S)<=K:
        print(0)
    else:
        answer = (H-1) * (W-1)
        for X in product([False,True], repeat=H-1):
            ans = np.sum(X)
            if ans >= answer:
                continue
            M = [[0]]
            for i, x in enumerate(X):
                if x:
                    M.append([])
                M[-1].append(i+1)
            D = [0]*len(M)
            for s in S:
                for k, m in enumerate(M):
                    D[k] += sum(s[i] for i in m)
                if any(d > K  for d in D):
                    ans += 1
                    if ans >= answer:
                        break
                    for k, m in enumerate(M):
                        D[k] = sum(s[i] for i in m)
                    
                    if any(d > K for d in D):
                        ans = answer + 1
                        break

            answer = min(answer,ans)

        print(answer)

main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 0
if a>=2:
    ans += a*(a-1)//2
if b>=2:
    ans += b*(b-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
list = input().rstrip().split(" ")
kisu = int(list[1])
gusu = int(list[0])
#奇数奇数の場合
kiki = kisu * (kisu - 1
#偶数偶数の場合

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
s = list(map(int,input().split()))
ans = {}
#各番号がいくつずつあるのかを整理
#keyに番号、valueにその番号が書かれてあるボールの数
for i in range(n):
    if not s[i] in ans.keys():
        ans[s[i]] = 1
    else:
        ans[s[i]] += 1
#iC2の総和
answer = 0
for i in ans.values():
    answer += i*(i-1)//2
#answer-nC2+(n-1)C2 = answer-n+1
#nはans[s[i]],よって以下の出力で求められる
for i in range(n):
    print(answer-ans[s[i]]+1)

Submission status: Runtime Error

Solution code:
l = int(input())
a = l/3
print(round(a**3,13))

Submission status: Runtime Error

Solution code:
import numpy
import copy
N = int(input())
E= list(map(int,input().split()))
ans = [0 for _ in range(N)]
unique = numpy.unique(E)
#for s in range(len(unique)):
#unique = int(unique)
uniqueNum = [0 for _ in range(len(unique))]

uniqueAns = [0 for _ in range(len(unique))]

y =0
for t in range(len(unique)):
    uniqueNum[t] = E.count(unique[t])
for g in range(len(unique)):
    uni = copy.copy(uniqueNum)
    uni[g] = uni[g] -1
    for h in range(len(unique)):
        y = y + uni[h] * (uni[h]-1)/2
    uniqueAns[g] =  y
for k in range(N):
    for w in range(len(uni)):
        if unique[w] == E[k]:
            ans[k] = uniqueAns[w]
            break
for i in range(N):
    print(int(ans[i]))

Submission status: Runtime Error

Solution code:
def main():
    import numpy as np
    h,w,k = map(int,input().split())
    l = [list(input()) for i in range(h)]

    def check(lis):
        lis.append(h)
        num = [0]*(len(lis))
        ans = 0
        for i in range(w):
            ch = 0
            num2 = [0]*(len(lis))
            for j in range(h):
                
                if l[j][i] == "1":
                    if j <= lis[ch]:
                        num2[ch] += 1
                    else:
                        ch += 1
                        num2[ch] += 1
            if max(num2) > k:
                return float("INF")
            else:
                for i in range(len(num)):
                    num[i] += num2[i]
                    if num[i] > k:
                        ans += 1
                        num = num2
                        break 
            
            
        return ans

    ans = 10**9

    for i in range(2**(h-1)):
        count = 0
        lis1 = []
        for j in range(h-1):
            if (i >> j) & 1:
                lis1.append(j)
                count += 1
        
        ans = min(ans,count+check(lis1))
        
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
a,=b=map(int,input().split())
print(a*(a-1)/2+b*(b-1)/2)

Submission status: Runtime Error

Solution code:
a,b=map(input().split())
ans=a*(a-1)/2+b*(b-1)/2
print (ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
print(N(N+1)/2+M(M+1)/2)

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

res = 999999999999999999

H, W, K = [int(i) for i in input().split()]
arr = []
for _ in range(H):
  arr.append([int(v) for v in input()])

arr = np.array(arr)
  
for p in itertools.product([0, 1], repeat = H-1):
  sp = np.zeros((sum(p)+1, W), int)
  row = 0
  sp[0] += arr[0]
  for j in range(H-1):
    if p[j]:
      row += 1
    sp[row] += arr[j+1]
  if np.max(sp) > K:
    continue
  
  sum_arr = np.zeros(len(sp), int)
  cut_cnt = sum(p)
  for c in range(W):
    sum_arr += sp[:, c]
    if max(sum_arr) > K:
      sum_arr = sp[:, c]
      cut_cnt += 1
  if cut_cnt < res:
    res = cut_cnt
print(res)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

def main():
    h,w,k = tuple([int(t)for t in input().split()])

    s = [[int(i) for i in list(input())] for _ in range(h)]
    
    s = np.array(s)

    candidates = []

    for i in range(1<<h):
        s_subs = divide(s,i)
        cutnum = 0
        pos = 0
        subsum = np.array([0]*len(s_subs))
        j = 0
        while j<w:
            temp = np.array([np.sum(s_[:,j]) for s_ in s_subs])
            if any([s_>k for s_ in temp]):
                cutnum = -1-bin(i).count('1')
                break

            subsum = subsum+temp
            if any([s_>k for s_ in subsum]):
                cutnum+=1
                subsum = np.array([0]*len(s_subs))
                j-=1
            
            j+=1

        candidates.append((bin(i).count('1')+cutnum))

    print(min([t for t in candidates if t>=0]))

def divide(s,i):
    subs = []
    counter = 0
    pos = 0
    while i!= 0:
        counter +=1
        if i%2==1:
            subs.append(s[pos:counter])
            pos = counter
        i >>=1

    subs.append(s[pos:])
    return subs
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n,m = (int(x) for x in input('').split(''))
sum = (n * (n - 1) / 2) + (m * (m - 1) / 2)
print(sum)

Submission status: Runtime Error

Solution code:
import math

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

ans = n*(n-1)//2 + m(m-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
 
count = [0]*(N+2)
for i in range(N):
    id = A[i]
    count[id] = count[id]+1
 
sumN = long(0)
for i in range(N+1):
    sumN = sumN + long(long(count[i]*(count[i]-1))/2)
 
for i in range(N):
    id = A[i]
    sumz = sumN - (count[id] - 1)
    print(sumz)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
A = list(map(int, input().split()))
 
for i in range(len(A)):
  if i==0:
    A_temp = A[1:]
  elif i==len(A)-1:
    A_temp = A[0:len(A)-1]
  else:
    A_temp = A[:i] + A[i+1:] 
  c = collections.Counter(A_temp)
  
  co = 0
  for k in c.values():
    if k != 1 and k != 0:
      Mcon = int(k*(k-1)/2)
      co += Mcon
  print(co)

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 j * (j-1) // 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 c2(x):
    return x * (x - 1) // 2
 
 
n = int(input())
a = list(map(lambda i: int(i) - 1, input().split()))
b = list(a.count(i) for i in range(n))
# c = list(c2(b[i]) for i in range(n))
# d = list(c2(b[i] - 1) for i in range(n))
c = list(c2(i) for i in b)
d = list(c2(i - 1) for i in b)
 
s = sum(c)
# for k in range(n):
#     i = a[k]
#     ans = s - c[i] + d[i]
#     print(ans)
for i in a:
    print(s - c[i] + d[i])

Submission status: Runtime Error

Solution code:
l = int(input())
A = input().split(" ")
unique = set(A)
def combination(number):
  if number <= 1:
    return 0
  else:
    return int(number * (number - 1) / 2)
def caluculate(string):
  data = memo[string]
  if data <= 1:
    return(0)
  else:
    return(data - 1) 
total = 0
memo = {}
for i in unique:
  times = A.count(i)
  memo[i] = times
  total += combination(times)
for i in A:
  print(total - caluculate(i))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

input_1 = input()
input_2 = input_1.split()

A = map(int, input_2)

def equal(num):
    return num
A = [equal(x) for x in A]

ans = 0

for l in range(N):
    ans += A.count(A[l]) - 1

ans = ans / 2
re = ans

for k in range(N):
    ans -= A.count(A[k]) - 1

    print(int(ans))

    ans = re

Submission status: Runtime Error

Solution code:
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
L = 0
R = 0
ret = 0

while R < N:
  if L > R:
    R = L
  if sum(A[L:R + 1]) < S:
    R += 1
  elif sum(A[L:R + 1]) > S:
    L += 1
  elif sum(A[L:R + 1]) == S:
    ret += (L + 1) * (N - R - 1) % MOD
    R += 1
print(ret)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

n = int(input())
a = list(map(int,input().split()))
b = a.copy()
b = set(b)
b = list(b)
c = []
ans = []

for i in range(len(b)):
    c.append(a.count(b[i]))
print(b)
print(c)
d = []
for i in range(len(b)):
    num = 0
    for j in range(len(b)):
        if i == j:
            num += int(((c[j]-1)*(c[j]-2))/2)
        else:
            num += int(((c[j])*(c[j]-1))/2)
    d.append(num)
print(d)

for i in range(n):
    for j in range(len(b)):
        if a[i] == b[j]:
            print(d[j])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import itertools
H, W, K = map(int, input().split())

S = [0]*H
for i in range(H):
  S[i] = input()
Sdivs = []
mcnt = 1100
for b in itertools.product([0, 1], repeat=H-1):
  start = 0
  end = 1
  Sdivs=[]
  for a in b:
    if a==1:
      Sdivs.append(S[start:end])
      start = end
    end += 1
  Sdivs.append(S[start:end])
  cnt = sum(b)
  ones_cum = [0]*len(Sdivs)
  ones = [0]*len(Sdivs)
  mark1,mark2 = False,False
  ws = [0]
  for w in range(1,W):
    if mark2 == True:
      #print(mark)
      break
    for i,Sdiv in enumerate(Sdivs):
      #print(w)
      for s in Sdiv:
        ones_cum[i] += s[w-1]=='1'
        ones[i] += s[w-1]=='1'
      if ones_cum[i] > K:
        mark1 = True
        if w-1 == ws[-1]:
          mark2 = True
        ws.append(w-1)
      #print(ones_cum,ws)
    if mark1 == True:
      mark1 = False
      ones_cum = ones
    ones = [0]*len(Sdivs)
  if mark2 == True:
    continue
  cnt += len(ws)-1
  mcnt = min(mcnt,cnt)
print(mcnt)

Submission status: Runtime Error

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