TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import numpy as np

n = int(input())

a = np.array(list(map(int, input().split())))
d = [0] * n
s = {}

for i in a:
  d[i-1] += 1
  
sum = 0
for k in d:
  if k>1:
    sum += (k*(k-1))//2

for i in range(n):
  nd = d[a[i]]
  ans = sum-(nd*(nd-1))//2
  nd -= 1
  if nd>1:
    ans += (nd*(nd-1))//2
  print(ans)


import numpy as np

n = int(input())

a = np.array(list(map(int, input().split())))
d = [0] * (n+1)
s = {}

for i in a:
  d[i] += 1
  
sum = 0
for k in d:
  if k>1:
    sum += (k*(k-1))//2

for i in range(n):
  nd = d[a[i]]
  ans = sum-(nd*(nd-1))//2
  nd -= 1
  if nd>1:
    ans += (nd*(nd-1))//2
  print(ans)


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
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

ans = 0
for a in d:
    n = d[a]
    ans += n * (n-1) // 2

print(ans)
for a in A:
    n = d[a]
    if n >= 2:
        print(ans - n + 1)
    else:
        print(ans)

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

ans = 0
for a in d:
    n = d[a]
    ans += n * (n-1) // 2

for a in A:
    n = d[a]
    if n >= 2:
        print(ans - n + 1)
    else:
        print(ans)


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n=int(input())
a=list(map(int, input().split()))
import collections
import math
def combinations_count(n, r):
    if(n<=1):
        answer=0
    else:
        answer=math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    return answer

table=collections.Counter(a)
keytable=collections.Counter(a).keys()
c=[]

for key in keytable:
    c.append(table[key])
print(c)
ca=[]
for j in range(len(c)):
    ca.append(combinations_count(c[j], 2))
print(ca)
sums=sum(ca)
print(sum)
print(keytable)
print(table)
for i in range(len(a)):
    keynum=list(keytable).index(a[i])
    answer=sums-ca[keynum]+combinations_count(c[keynum]-1, 2)
    print(answer)

n=int(input())
a=list(map(int, input().split()))
import collections
import math
def combinations_count2(n):
    if(n<=1):
        answer=0
    else:
        answer=n*(n-1)/2
    return answer

table=collections.Counter(a)
keytable=table.keys()
c=[]

for key in keytable:
    c.append(table[key])
#print(c)
ca=[]
for j in range(len(c)):
    ca.append(c[j]*(c[j])/2)
#print(ca)
sums=sum(ca)
#print(sum)

#print(table)
for i in range(len(a)):
    keynum=list(keytable).index(a[i])
    answer=sums-ca[keynum]+(c[keynum]-1)*(c[keynum]-2)/2
    print(int(answer))

n=int(input())
a=list(map(int, input().split()))
import collections
import math
def combinations_count2(n):
    if(n<=1):
        answer=0
    else:
        answer=n*(n-1)/2
    return answer

table=collections.Counter(a)
keytable=table.keys()
sums=0
for value in table.values():
    sums+=combinations_count2(value)
#print(ca)
#print(sum)

#print(table)
for i in range(len(a)):
    answer=sums-table[a[i]]+1
    print(int(answer))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math
import collections
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


def combinations_count(n, r):
	if n < 2:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

_ = int(input())
ns = input().split(" ")
cs = collections.Counter(ns)

c = 0
for n in ns:
	for k, v in cs.items():
		if v==1:
			c += 0
		elif n==k:
#			c += combinations_count(v-1, 2)
			c += cmb(v-1, 2)
		else:
#			c += combinations_count(v, 2)
			c += cmb(v, 2)
	print(c)
	c = 0

N = int(input())
A = [int(a)-1 for a in input().split()]
X = [0] * N
for a in A:
	X[a] += 1
s = 0
for x in X:
	s += x * (x-1) // 2
print(s)
for a in A:
	print(s - (X[a] - 1))


import sys
input = sys.stdin.readline
import math
import collections

def combinations_count(n, r):
	if n < 2:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

_ = int(input())
ns = input().split(" ")
cs = collections.Counter(ns)

c = 0
for n in ns:
	for k, v in cs.items():
		if v==1:
			c += 0
		elif n==k:
#			c += math.factorial(v-2)
			c += combinations_count(v-1, 2)
		else:
#			c += math.factorial(v-1)
			c += combinations_count(v, 2)
	print(c)
	c = 0


N = int(input())
A = [int(a)-1 for a in input().split()]
X = [0] * N
for a in A:
	X[a] += 1
s = 0
for x in X:
	s += x * (x-1) // 2
for a in A:
	print(s - (X[a] - 1))


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
print(c.items())
all=0
for i,j in c.items():
    all += j*(j-1)//2
for i in range(N):
    print(all-(a.count(a[i])-1))

from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
print(c.items())
all=0
for i,j in c.items():
    all += j*(j-1)//2
for i in range(N):
    print(all-(c[a[i]]-1))

from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
#print(c.items())
all=0
for i,j in c.items():
    all += j*(j-1)//2
for i in range(N):
    print(all-(c[a[i]]-1))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import sys
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
N = II()
A = list(MI())
ans = 0
cum = {}
def couple_combination(n):
    if n >= 2:
        return int(n * (n - 1) / 2)
    else:
        return 0
for unique in list(set(A)):
    cum_count = A.count(unique)
    cum[unique] = cum_count
    ans += couple_combination(cum_count)
for i in A:
    print(ans - cum[i])


import sys
from collections import defaultdict
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
N = II()
A = list(MI())
ans = 0
cum = defaultdict(int)
def couple_combination(n):
    if n >= 2:
        return int(n * (n - 1) / 2)
    else:
        return 0
for v in A:
    cum[v] += 1
for v in cum.values():
    ans += couple_combination(v)
for v in A:
    print(max(0,ans - cum[v] + 1))


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
for x in a:
  c = d[x] - 1
  print(c * (c-1) // 2)

from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
for x in a:
  c = d[x] - 1
  print(c * (c-1) // 2)a

from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
  
s = 0
for k,v in d.items():
  s += v * (v-1) // 2
for x in a:
  c = d[x] - 1
  print(s - c)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)

all_c = 0		
idx = B[0]
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	
    all_c += tmp1
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)			
  tmp2 = int((idx_count-1)*(idx_count-2)/2)		
  all_c += tmp1
  idx_set.append([idx, tmp1, tmp2])
#print(idx_set)
idx_sum_set = []
for i in range(len(idx_set)):
  all_c += idx_set[i][1]
for i in range(len(idx_set)):
  tmp = all_c-idx_set[i][1]+idx_set[i][2]
  idx_sum_set.append([idx_set[i][0], tmp])    

for i in range(N):
  j = int(len(idx_sum_set)/2)
  while 1:
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
      break
    elif A[i] > idx_sum_set[j][0]:
      j = j + int((len(idx_sum_set)-j)/2)
    elif A[i] < idx_sum_set[j][0]:
      j = int(j/2)



import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.zeros(N+1)

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


all_c = 0
for i in range(1,N+1):
  all_c += int(B[i]*(B[i]-1)/2)			
for i in range(N):
  if B[A[i]] != 0:
    print(int(all_c-(B[A[i]]-1)))


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b0=list(a[1:])
c0=Counter(b0)
d0=0
for i in c0:
    d0+=(c0[i])*(c0[i]-1)/2
print(d0)
for j in range(1,n-1):
    b=list(a[0:j])+list(a[j+1:])
    c=Counter(b)
    d=0
    for j in c:
        d+=(c[j])*(c[j]-1)/2
    print(d)
b2=list(a[:-1])
c2=Counter(b2)
d2=0
for k in c2:
    d2+=(c2[k])*(c2[k]-1)/2
print(d2)


from copy import copy
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a_counter=Counter(a)
ans=0
for i in a_counter:
    ans+=(a_counter[i])*(a_counter[i]-1)//2
for j in a:
    true_ans=copy(ans)
    true_ans=true_ans-((a_counter[j])*(a_counter[j]-1)//2-(a_counter[j]-1)*(a_counter[j]-2)//2)
    print(true_ans)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
ans = np.zeros(N)
total = 0
for i in range(N):
  ans[A[i] - 1] += 1
for i in range(N):
  total += ans[i] * (ans[i] - 1) // 2
for i in range(N):
  print(total - max(ans[A[i]-1]-1,0))
  

import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[i] = A.count(i + 1)
total = 0
for k in range(N):
  tmp = number[k]
  total += tmp * (tmp-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)


import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(str, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[i] = A.count(str(i + 1)
total = 0
for k in range(N):
  tmp = number[k]
  total += tmp * (tmp-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)


import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(str, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[i] = A.count(str(i + 1))
total = 0
for k in range(N):
  tmp = number[k]
  total += tmp * (tmp-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)


impot numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[A[i]-1] += 1
total = 0
for k in range(N):
  total += number[k] * (number[k]-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)


import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(str, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[i] = A.count('i + 1')
total = 0
for k in range(N):
  tmp = number[k]
  total += tmp * (tmp-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)


import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(int, input().split()))
number = np.zeros(N, dtype = int)
total = 0

dic = {}
a = sorted(A)
now_key = a[0]
value = 1
dic[now_key] = 1
for i in range(1,N):
  if a[i] == now_key:
    value += 1
  else:
    dic[now_key] = value
    if value >= 2:
      total += value * (value-1) // 2
    now_key = a[i]
    value = 1
dic[now_key] = value
if value >= 2:
  total += value * (value-1)//2
for j in A:
  print(total - dic[j] + 1)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import copy

N=int(input())

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

#print(A)

mama=dict()
papa=dict()
papa[0]=0
papa[1]=0
papa[2]=1
for i in range(3,N/2):
    papa[i]=int(i*papa[i-1]/2)
for i in range(N):

    if(A[i] in mama):
        print(mama[A[i]])
        continue
    
    AA=copy.deepcopy(A)
    ai=A[i]
    del AA[i]
    #print(AA)
    Aset=set(AA)
    count=0
    
    for i in Aset:
        aa=AA.count(i)
        if(aa in papa):
            count+=papa[aa]
            continue
        #print(i,aa)
        aiu=int((aa*(aa-1))/2)
        count+=aiu
        papa[aa]=aiu
    print(count)
    mama[ai]=count


from collections import Counter
N=int(input())
A=list(map(int,input().split()))

parent=dict()
An=set(A)
parecou=0
aaa=Counter(A)
for i in aaa.values():
    parecou+=int((i*(i-1)/2))




for i in range(N):
    anko=aaa[A[i]]
    print(parecou-int((anko*(anko-1)/2))+int(((anko-2)*(anko-1)/2)))
    


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import itertools

if __name__ == "__main__":
    N = int(input())
    A = input().split()
    all = len(tuple(filter(lambda t: t[0] == t[1], itertools.combinations(A, 2))))
    for x in range(N):
        count = A.count(A[x])
        tmp = tuple(["0" for _ in range(count)])
        result = tuple(filter(lambda t: t[0] == t[1], itertools.combinations(tmp, 2)))
        print(all-len(result))


import sys
import itertools
from collections import Counter
sys.setrecursionlimit(10**8)
if __name__ == "__main__":
    N = int(input())
    A = input().split()
    counter = Counter(A)
    result = 0
    for c in counter.values():
        result += c*(c-1)//2
    for a in A:
        k = counter[a]
        print(result - k*(k-1)//2 + (k-1)*(k-2)//2)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math

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

n = int(input())
a = sorted(map(int,input().split()))
cnt = []
cnt1 = 1
for i in range(1,n):
    if a[i] == a[i-1]:
        cnt1 += 1
        if i == n-1:
            cnt.append(cnt1)
    else:
        cnt.append(cnt1)
        cnt1 = 1
        if i == n-1:
            cnt.append(cnt1)

cnt_s = set(cnt)
cmb_patern = {}

for c in cnt_s:
    if c not in cmb_patern.keys():
        if c >= 3:
            cmb_patern[c] = [combinations_count(c,2), combinations_count(c-1,2)]
        elif c == 2:
            cmb_patern[c] = [1,0]
        else:
            continue

cmb = [0] * len(cnt)

for i in range(len(cnt)):
    if cnt[i] >= 2:
        cmb[i] = cmb_patern[cnt[i]][0]

cmb_all = sum(cmb)

for i in range(len(cnt)):
    if cnt[i] == 1:
        print(cmb_all)
    elif cnt[i] == 2:
        print(cmb_all - 1)
        print(cmb_all - 1)
    else:
        ans = cmb_all - cmb[i] + cmb_patern[cnt[i]][1]
        for j in range(cnt[i]):
            print(ans)


import math

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

n = int(input())
a = sorted(map(int,input().split()))
cnt = []
cnt1 = 1
for i in range(1,n):
    if a[i] == a[i-1]:
        cnt1 += 1
        if i == n-1:
            cnt.append(cnt1)
    else:
        cnt.append(cnt1)
        cnt1 = 1
        if i == n-1:
            cnt.append(cnt1)

cmb = {}

for i in range(len(cnt)):
    if cnt[i] >= 2:
        cmb[cnt[i]] = combinations_count(cnt[i],2)

cmb_all = sum(cmb.values())

for i in range(len(cnt)):
    if cnt[i] == 1:
        print(cmb_all)
    elif cnt[i] == 2:
        print(cmb_all - 1)
        print(cmb_all - 1)
    else:
        ans = cmb_all - cmb[cnt[i]] + combinations_count(cnt[i]-1, 2)
        for j in range(cnt[i]):
            print(ans)


import math

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

n = int(input())
a = list(map(int,input().split()))
a1 = sorted(a)
cnt = {}
cnt1 = 1
for i in range(1,n):
    if a1[i] == a1[i-1]:
        cnt1 += 1
        if i == n-1:
            cnt[a1[i]] = cnt1
    else:
        cnt[a1[i-1]] = cnt1
        cnt1 = 1
        if i == n-1:
            cnt[a1[i]] = cnt1


cmb = {}
cmb[1] = 0
cmb_all = 0
for i in cnt.values():
    if i == 1:
        continue
    else:
        cmb1 = combinations_count(i,2)
        cmb_all += cmb1
        cmb[i] = cmb1

for i in a:
    cnt1 = cnt[i]
    if cnt1 == 1:
        print(cmb_all)
    else:
        ans = cmb_all + cmb[cnt1] * ((cnt1-2)/cnt1 - 1)
        print(int(ans))



Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
def main():
  import sys
  input = sys.stdin.readline
  import numpy as np
  from collections import Counter

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

  tmp = np.array(list(c.values()))
  l1= tmp*(tmp-1)//2
  l2= (tmp-1)*((tmp-1)-1)//2
  S = np.sum(l1)

  for a in A:
    r = list(c).index(a)
    sum = S + l2[r] -l1[r]
    print(int(sum))

if __name__ == '__main__':
  main()


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

import collections 
c=collections.Counter(A)
sum=0
for i in c:
  sum+=c[i]*(c[i]-1)//2  
for a in A:
  print(sum - c[a]*(c[a]-1)//2 + (c[a]-1)*(c[a]-2)//2)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))

from collections import Counter
c=Counter(A)

ANS=0	# max combination
for i in C.values():
    ANS+=i*(i-1)//2     # 6+1+1 = 8
 
for a in A:
    k=C[a]      # 4 2 4 2 2 4 2 4
 
    print(ANS-(k*(k-1)//2)+((k-1)*(k-2)//2)) # different from max combination
                # 8 - 6 + 3
                # 5

n=int(input())
a=list(map(int,input().split()))
 
from collections import Counter
c=Counter(a)
 
max_c=0			# max combination
for i in c.values():
    max_c+=i*(i-1)//2     # 6+1+1 = 8
 
for num in a:
    k=c[num]      # 4 2 4 2 2 4 2 4
 
    print(ans-(k*(k-1)//2)+((k-1)*(k-2)//2)) # different from max combination
                # 8 - 6 + 3
                # 5

n=int(input())
a=list(map(int,input().split()))
 
from collections import Counter
c=Counter(a)
 
max_c=0			# max combination
for i in c.values():
    max_c+=i*(i-1)//2     # 6+1+1 = 8
 
for num in a:
    k=c[num]      # 4 2 4 2 2 4 2 4
 
    print(max_c-(k*(k-1)//2)+((k-1)*(k-2)//2)) # different from max combination
                # 8 - 6 + 3
                # 5

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = 8
a = list(map(int, '1 2 1 4 2 1 4 1'.split()))
count_dict = {}
total_sum = 0
for i in a:
    if i not in count_dict:
        count_dict[i] = a.count(i)
        total_sum += (a.count(i))*(a.count(i)-1)//2
for i in a:
    print(total_sum - (a.count(i)*(a.count(i)-1)//2) + (a.count(i)-1)*(a.count(i)-2)//2)

import collections
n = int(input())
a = list(map(int, input().split()))
cnt = collections.Counter(a)
total = 0
for key in cnt.keys():
    total += cnt[key]*(cnt[key]-1) // 2
for i in a:
    ans = total
    ans -= cnt[i] * (cnt[i]-1) / 2
    ans += (cnt[i]-1) * (cnt[i]-2) / 2
    print(ans)

n = int(input())
a = list(map(int, input().split()))
diff_dict = {}
total_sum = 0
for i in a:
    if i not in diff_dict:
        temp = (count_dict[i])*(count_dict[i]-1)//2
        diff_dict[i] = temp-(count_dict[i]-1)*(count_dict[i]-2)//2
        total_sum += temp
for i in a:
    print(total_sum - diff_dict[i])

import collections
n = int(input())
a = list(map(int, input().split()))
cnt = collections.Counter(a)
total = 0
for key in cnt.keys():
    total += cnt[key]*(cnt[key]-1) // 2
for i in a:
    ans = total
    ans -= cnt[i] * (cnt[i]-1) / 2
    ans += (cnt[i]-1) * (cnt[i]-2) / 2
    print(int(ans))

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math
import collections
def calc_combi2(n):
    if n<=1:
        return 0
    return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))
n=int(input())
data=list(map(int,input().split()))
data_cnt=collections.Counter(data)
count=0
for i in data_cnt.values():
    if 2<=i:
        count+=calc_combi2(i)
for i in data:
    if i<=1:
        print(count)
    else:
        ans=count+(calc_combi2(data_cnt[i]-1)-calc_combi2(data_cnt[i]))
        print(int(ans))

import math
import collections
def calc_combi2(n):
    if n<=1:
        return 0
    return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))
n=int(input())
data=list(map(int,input().split()))
data_cnt=collections.Counter(data)
ans=[0]*n
count=0
for i in data_cnt.values():
    count+=calc_combi2(i)
for a,b in data_cnt.items():
    if 2<=b:
        ans[a]=int(count-b+1)
for i in data:
    print(ans[i-1])

import math
import collections
def calc_combi2(n):
    if n<=1:
        return 0
    return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))
n=int(input())
data=list(map(int,input().split()))
data_cnt=collections.Counter(data)
count=0
ans=collections.Counter()
for i in data_cnt.values():
    count+=calc_combi2(i)
for a,b in data_cnt.items():
    if 2<=b:
        ans[a]=int(count-b+1)
    else:
        ans[a]=int(count)
for i in data:
    print(ans[i])

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
l = list(map(int,input().split()))
if len(set(l))==len(l):
    for i in range(len(l)):
        print(0)
elif len(set(l))==1:
    for i in range(n):
        print((n*(n-1)//2)-n+1)
else:
    d = {}
    for i in l:
        if i in d:
            d[i]+=1
        else:
            d[i] = 1
    for i in l:
        d[i] -= 1
        print(sum(set(d.values())))
        d[i] += 1

n = int(input())
l = list(map(int,input().split()))
if len(set(l))==len(l):
    for i in range(len(l)):
        print(0)
elif len(set(l))==1:
    for i in range(len(l)):
        print(n+1)
else:
    for k in range(len(l)):
        tp = l.pop(k)
        print(sum(set([l.count(i) for i in l])))
        l.insert(k,tp)

n = int(input())
l = list(map(int,input().split()))
if len(set(l))==len(l):
    for i in range(len(l)):
        print(0)
elif len(set(l))==1:
    for i in range(len(l)):
        print(n+1)
else:
    kp = list(set(l))
    print(kp)
    dt = {}
    for i in range(len(kp)):
        tp = kp[i]
        l.remove(kp[i])
        dt[tp]= sum(set([l.count(i) for i in l]))
        l.insert(i,tp)
        print(dt)
    for i in l:
        print(dt[i])


n = int(input())
l = list(map(int,input().split()))
d = {}
for i in l:
    if i in d:
        d[i]+=1
    else:
        d[i] = 1
cp = 0
for i in d.values():
    cp+= i*(i-1)//2
for i in l:
    print(cp-d[i]+1)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
 = int(input())
import numpy as np

A = list(map(int, input().split()))
dp = np.zeros((N,N), dtype=np.int32)
for i in range(N):
  tmp = [0]*(A[i]-1)+[1]+[0]*(N-A[i])
  tmp = np.array(tmp, dtype=np.int32)
  dp[i] = tmp+dp[i-1]

dp = np.array(dp)
ans = []
for i in range(N):
  if i > 0 and i < N-1:
    tmp = dp[N-1] - dp[i] + dp[i-1]
    tmp = tmp*(tmp-1)//2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
  if i == 0:
    tmp = dp[N-1] - dp[i]
    tmp = tmp*(tmp-1)//2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
  if i == N-1:
    tmp = dp[N-2]
    tmp = tmp*(tmp-1)//2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
for i in ans:
  print(i)

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

from collections import defaultdict
c = defaultdict(int)
cm = set()
c2 = list()
num = 0
for i in range(N):
  c[A[i]] += 1
  cm.add(A[i])
for i in list(cm):
  num += c[i]*(c[i]-1)//2
for i in range(N):
  ans = num - c[A[i]] + 1
  c2.append(ans)

for cs in c2:
  print(cs)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import sys
input = lambda: sys.stdin.readline().rstrip()

def choose2(n):
    return n*(n-1)//2

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

Cnt = [(a-1) for a in A]

tot = 0
for i in range(n):
    tot += choose2(Cnt[i])

for i in range(n):
    ans = tot
    ans -= choose2(Cnt[A[i]])
    ans += choose2(Cnt[A[i]]-1)
    print(ans)

import sys
input = lambda: sys.stdin.readline().rstrip()

def choose2(n):
    return n*(n-1)//2

n = int(input())
A = list(map(int, input().split()))
A = [a-1 for a in A]
  
Cnt = [0]*n
for i in range(n):
  Cnt[A[i]] += 1
    
tot = 0
for i in range(n):
    tot += choose2(Cnt[i])

for i in range(n):
    ans = tot
    ans -= choose2(Cnt[A[i]])
    ans += choose2(Cnt[A[i]]-1)
    print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
b=[0] * 2000000
ans = 0
for i in range(len(a)):
    b[a[i]-1] += 1

for i in range(mx):
    if(b[i] == 0 or b[i] == 1):
        ans += 0
    else:
        ans = ans + int(b[i] * (b[i]-1)/2)
ans1 = 0


for i in range(len(a)):
    ans1 = ans
    if(b[a[i]-1] >2):
        ans1 = ans1 -int((b[a[i]-1]-(b[a[i]-1]-1))/2)+ int(((b[a[i]-1]-1) * (b[a[i]-1]-2))/2)
        print(int(ans1))
    elif(b[a[i]-1] == 2):
        print(int(ans1-1))
    elif(b[a[i]-1] < 2):
        print(int(ans1))

import math
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
b=[0] * 2000000
ans = 0
for i in range(len(a)):
    b[a[i]-1] += 1

for i in range(mx):
    if(b[i] == 0 or b[i] == 1):
        ans += 0
    else:
        ans = ans + int(b[i] * (b[i]-1)/2)
ans1 = 0


for i in range(len(a)):
    ans1 = ans
    if(b[a[i]-1] >2):
        ans1 = ans1 -int((b[a[i]-1]*(b[a[i]-1]-1))/2) + int(((b[a[i]-1]-1) * (b[a[i]-1]-2))/2)
        print(int(ans1))
    elif(b[a[i]-1] == 2):
        print(int(ans1-1))
    elif(b[a[i]-1] < 2):
        print(int(ans1))

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
K = list(map(int,input().split()))
A = [0]*N
print(A)
for i in range(N):
    A[K[i]-1] += 1
r = 0
for k in range(N):
    r += 0.5*(A[k]*(A[k]-1))
An =[]
for j in range(N):
    D = A[K[j]-1]-1
    An.append(int(r-(0.5*(D+1)*(D))+(0.5*D*(D-1))))
for i in range(len(An)):
    print(An[i])

N = int(input())
K = list(map(int,input().split()))
A = [0]*N
for i in range(N):
    A[K[i]-1] += 1
r = 0
for k in range(N):
    r += 0.5*(A[k]*(A[k]-1))
An =[]
for j in range(N):
    D = A[K[j]-1]-1
    An.append(int(r-(0.5*(D+1)*(D))+(0.5*D*(D-1))))
for i in range(len(An)):
    print(An[i])

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
d = {}
aa = [0]
for i in range(1,n):
	aa.append(aa[-1]+i)
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i]+=1
s = 0
for i in d:
	s+=aa[d[i]-1]
dd = {}
for i in d:
	if i not in dd:
		if d[i]!=1:
			dd[i] = (s-aa[d[i]-1]+aa[d[i]-2])
		else:
			dd[i] = 0
print(dd)
for i in a:
	print(dd[i])

n = int(input())
a = list(map(int,input().split()))
d = {}
aa = [0,0]
for i in range(1,n):
	aa.append(aa[-1]+i)
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i]+=1
s = 0
for i in d:
	s+=aa[d[i]]
dd = {}
for i in d:
	if i not in dd:
		dd[i] = (s-aa[d[i]]+aa[d[i]-1])
for i in a:
	print(dd[i])

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import sys
import numpy as np


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = np.array(list(map(int, input().split())))
    List = np.unique(A)
    count = np.bincount(A)
    # print(count)

    dic = {}
    Ans = 0
    for l in List:
        n = count[l]
        num = n * (n - 1) // 2
        Ans += num
        dic[l] = num
    B = np.empty(N, dtype=np.int)
    for l in List:
        n = count[l] - 1
        num = n * (n - 1) // 2
        B = np.where(A == l, int(Ans - dic[l] + num), B)
    print(*B, sep="\n")


main()


import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    total = 0
    for k, v in C.items():
        if v > 1:
            total += v * (v - 1) // 2

    for a in A:
        v = C[a]
        if v > 1:
            print(total - v * (v - 1) // 2 + (v - 1) * (v - 2) // 2)
        else:
            print(total)


main()


Verdicts: Time Limit Exceeded

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
ans = 0

for i in counter.values():
	ans = i * (i - 1) // 2

for j in A:
	cnt = counter[j]
	if cnt <= 1:
		print(ans)
	else:
		print(ans - cnt + 1)

from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
ans = 0

for i in counter.values():
	ans += i * (i - 1) // 2

for j in A:
	cnt = counter[j]
	if cnt <= 1:
		print(ans)
	else:
		print(ans - cnt + 1)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    uq = list(set(A))
    ans_hash = {}
    num_hash = {}
    for u in uq:
        ans = 0
        a = A[:]
        i = a.index(u)
        del a[i]
        val = Counter(a).values()
        print("val: %s", val)
        for num in val:
            if num in num_hash:
                ans += num_hash[num]
            else:
                num_hash[num] = num * (num - 1) // 2
                ans += num_hash[num]
        ans_hash[u] = ans
    for n in A:
        if n in ans_hash:
            print(ans_hash[n])
        else:
            a = A[:]
            i = a.index(n)
            del a[i]
            val = Counter(a).values()
            for num in val:
                if num in num_hash:
                    ans += num_hash[num]
                else:
                    num_hash[num] = num * (num - 1) // 2
                    ans += num_hash[num]
            ans_hash[n] = ans
            print(ans_hash[n])


if __name__ == '__main__':
    main()


from collections import Counter

def choose(n):
    return n * (n - 1) // 2


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    cnt = 0
    for c in C.values():
        cnt += choose(c)

    for a in A:
        ans = cnt
        ans -= choose(C[a])
        ans += choose(C[a] - 1)
        print(ans)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N=int(input())
list1=list(map(int,input().split()))
list2=[0]*N

for i in range(N):
    list2[i]=list1.count(i+1)

def choose2(n):
    return n*(n-1)/2

total=0
for i in list2:
    total+=choose2(i)


for i in list1:
    ans=total-(list2[i-1]-1)
    print(ans)

from collections import Counter

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

dic1=Counter(list1)

def choose2(n):
    return n*(n-1)/2

sum=0
for key in dic1:
    sum+=choose2(dic1[key])

for i in list1:
    print(int(sum-dic1[i]+1))

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter

def cmb(n, r, mod=10**9+7):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**5 * 2 + 1
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )



N = int(input())
ball_com = [0] * (N + 1)
balls = list(map(int, input().split()))
balls_counter = Counter(balls)
for key , val in balls_counter.items():
    ball_com[key - 1] = cmb(val, 2)

cmb_sum = sum(ball_com)
for ball in balls:
    print(cmb_sum - ball_com[ball - 1] + cmb(balls_counter[ball] - 1, 2))


from collections import Counter

def cmb(n, r, mod=10**9+7):
    return n * (n - 1) // 2



N = int(input())
ball_com = [0] * (N + 1)
balls = list(map(int, input().split()))
balls_counter = Counter(balls)
for key , val in balls_counter.items():
    ball_com[key - 1] = cmb(val, 2)

cmb_sum = sum(ball_com)
for ball in balls:
    print(cmb_sum - ball_com[ball - 1] + cmb(balls_counter[ball] - 1, 2))


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))

import math

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


count = 0
kaisuu = []
sum = 0
kaisuu = [0 for _ in range(n)]
for num in range(1,max(a)+1):
    count = 0
    for i in range(n):
        if a[i] == num:
            count += 1
    
    kaisuu[num] = count
    sum += count + (count - 1)//2



for k in range(n):
    ans = sum - kaisuu[a[k]] + 1
    print(ans)
    

import collections

#start = time.time()



x=int(input())
a=list(map(int,input().split()))
 
c=collections.Counter(a)
#print(c)

num=0
for i in c.values():
    num += i*(i-1)/2
    
for i in range(x):
    print(int(num-c[a[i]]+1))

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
M=int(input())
N=list(input().split())
print(N)
check=[0,0,0,0,0,0,0,0,0,0]
for i in range(M):
    check[int(N[i])]+=1
num=0
for i in range(M):
    num+=check[i]*(check[i]-1)//2
for i in range(M):
    print(num-(check[int(N[i])]-1))

M=int(input())
N=list(input().split())
print(N)
check=[0]*M
for i in range(M):
    check[int(N[i])-1]+=1
num=0
for i in range(M):
    num+=check[i]*(check[i]-1)//2
for i in range(M):
    print(num-(check[int(N[i])-1]-1))

M=int(input())
N=list(input().split())
check=[0]*M
for i in range(M):
    check[int(N[i])-1]+=1
num=0
for i in range(M):
    num+=check[i]*(check[i]-1)//2
for i in range(M):
    
    print(num-(check[int(N[i])-1]-1))
    #else:
       # print(num-1)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n=int(input())
l=list(map(int,input().split()))

d = [0]*n
ans=0
 
for a in l:
    d[a-1] += 1
  
for a in d:
  ans+=a*(a-1)//2
  
print(ans)
  

# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 22:04:16 2020

@author: liang
"""

N = int(input())
A = [int(x) for x in input().split()]
d = [0]*N

for a in A:
    d[a-1] += 1
#print(d)
score = 0
for  a in d:
    score += a*(a-1)//2
#print(score)
for a in A:
    print(score - d[a-1] + 1)


Verdicts: Wrong Answer

Accepted
Problem: We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares.  The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.  We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.  How many times do we need to cut the bar so that every block after the cuts has K or less white squares?

Submission attempts (in order):

import sys

ans = sys.maxsize
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

for h in range(1 << (H - 1)):
    g = 0
    ids = [-1 for _ in range(H)]
    for i in range(H):
        ids[i] = g
        if (h >> i) & 1:
            g += 1

    g += 1
    c = [[[0] * W] for _ in range(g)]
    for i in range(H):
        for j in range(W):
            c[ids[i]][j] = c[ids[i]][j] + (s[i][j] == '1')

    num = g - 1
    now = [0 for _ in range(g)]


    def add(j):
        for i in range(g):
            now[i] += c[i][j]

        for i in range(g):
            if now[i] > K:
                return False

        return True


    if num >= ans:
        continue

    for j in range(W):
        if not add(j):
            num += 1
            if num >= ans:
                continue
            now = [0 for _ in range(g)]
            if not add(j):
                num = sys.maxsize
                break

    ans = min(ans, num)

print(ans)



import sys

ans = sys.maxsize
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

for h in range(1 << (H - 1)):
    g = 0
    ids = [-1 for _ in range(H)]
    for i in range(H):
        ids[i] = g
        if (h >> i) & 1:
            g += 1

    g += 1
    num = g - 1

    if num >= ans:
        continue

    c = [[0] * W for _ in range(g)]
    for i in range(H):
        for j in range(W):
            c[ids[i]][j] = c[ids[i]][j] + (s[i][j] == '1')

    now = [0 for _ in range(g)]


    def add(j):
        for i in range(g):
            now[i] += c[i][j]

        for i in range(g):
            if now[i] > K:
                return False

        return True


    for j in range(W):
        if not add(j):
            num += 1
            if num >= ans:
                continue
            now = [0 for _ in range(g)]
            if not add(j):
                num = sys.maxsize
                break

    ans = min(ans, num)

print(ans)


Verdicts: Runtime Error

Accepted
Problem: We have a chocolate bar partitioned into H horizontal rows and W vertical columns of squares.  The square (i, j) at the i-th row from the top and the j-th column from the left is dark if S_{i,j} is `0`, and white if S_{i,j} is `1`.  We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.  How many times do we need to cut the bar so that every block after the cuts has K or less white squares?

Submission attempts (in order):
h,w,k = list(map(int,input().split()))
arr = [[int(i) for i in input()] for _ in range(h)]

from itertools import product
ans = [0]*(2**(h-1))

for idx,cond in enumerate(product((True,False),repeat=h-1)):
    div = sum(cond)
    spl = [arr[0][:]]
    for i in range(h-1):
        if h_cond[i]:
            spl.append(arr[i+1][:])
        else:
            spl[-1] = [spl[-1][j] + arr[i+1][j] for j in range(w)]
    num = len(spl)
    cnt = [0]*num
    
    for v in range(w):
        tmp = [spl[i][v] for i in range(num)]
        if max(tmp) > k:
            break
        if max([cnt[i] + tmp[i] for i in range(num)]) > k:
            div += 1
            cnt = tmp[:]
        else:
            cnt  = [cnt[i] + tmp[i] for i in range(num)]
    else:    
        ans = min(ans,div)
            
print(min(ans))

h,w,k = list(map(int,input().split())); arr = [[int(i) for i in input()] for _ in range(h)]

from itertools import product
ans = 2000

for cond in product([True,False],repeat=(h-1)):
    cut = sum(cond)
    splits = [arr[0][:]]
    for i in range(1,h):
        if cond[i-1]:
            splits.append(arr[i][:])
        else:
            splits[-1] = [splits[-1][j]+arr[i][j] for j in range(w)]
    
    check = [max(i) for i in splits]
    if max(check) > k:
        break
    count = [i[0] for i in splits]
    
    div = cut
    for j in range(1,w):
        addarr = [count[i]+splits[i][j] for i in range(cut+1)]
        if max(addarr) > k:
            div += 1
            count = [splits[i][j] for i in range(cut+1)]
        else:
            count = addarr[:]
    ans = min(ans,div)
        
print(ans)

Verdicts: Runtime Error

Accepted