Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import fractions as math

def lcm(x,y):
    return (x * y) // math.gcd(x,y)

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

    nmlcm = lcm(n,m)
    nn = nmlcm // n
    mm = nmlcm // m

    for i in range(lcm(n,m)):
        if i%nn == 0 and i%mm == 0 and s[i//nn] != t[i//mm]:
            print(-1)
            return
    print(nmlcm)

if __name__ == "__main__":
    main()


Fixed submission:
import fractions as math

def lcm(x,y):
    return (x * y) // math.gcd(x,y)

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

    nmlcm = lcm(n,m)
    nn = nmlcm // n
    mm = nmlcm // m
    nnmmlcm = lcm(nn,mm)

    for i in range(nmlcm // nnmmlcm):
        #print(nnmmlcm*i)
        if s[nnmmlcm*i//nn] != t[nnmmlcm*i//mm]:
            print(-1)
            return
    print(nmlcm)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import fractions as math

def lcm(x,y):
    return (x * y) // math.gcd(x,y)

if __name__ == "__main__":
    main()

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

    nmlcm = lcm(n,m)
    nn = nmlcm // n
    mm = nmlcm // m

    for i in range(lcm(n,m)):
        if i%nn == 0 and i%mm == 0 and s[i//nn] != t[i//mm]:
            print(-1)
            return
    print(nmlcm)


Fixed submission:
import fractions as math

def lcm(x,y):
    return (x * y) // math.gcd(x,y)

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

    nmlcm = lcm(n,m)
    nn = nmlcm // n
    mm = nmlcm // m
    nnmmlcm = lcm(nn,mm)

    for i in range(nmlcm // nnmmlcm):
        #print(nnmmlcm*i)
        if s[nnmmlcm*i//nn] != t[nnmmlcm*i//mm]:
            print(-1)
            return
    print(nmlcm)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))

if n == 2:
    if l[0] == l[1]:
        print(1)
    else:
        print(0)
else:
    a = []
    b = []
    for i in range(n):
        if i % 2 == 0:
            a.append(l[i])
        else:
            b.append(l[i])

    da = {}
    for e in a:
        if e not in da:
            da[e] = (1,e)
        else:
            da[e] = (da[e][0]+1,da[e][1])

    db = {}
    for e in b:
        if e not in db:
            db[e] = (1,e)
        else:
            db[e] = (db[e][0]+1,db[e][1])

    la = list(reversed(sorted(list(da.values()))))
    lb = list(reversed(sorted(list(db.values()))))
    #print(la)
    #print(lb)

    la[-1] = (0,-1)
    lb[-1] = (0,-1)

    if la[0][1] == lb[0][1]:
        ans = n- (la[0][0] + max(la[1][0],lb[1][0]))
    else:
        ans = n - (la[0][0] + lb[0][0])
    print(ans)


Fixed submission:
n = int(input())
l = list(map(int, input().split()))

if n == 2:
    if l[0] == l[1]:
        print(1)
    else:
        print(0)
else:
    a = []
    b = []
    for i in range(n):
        if i % 2 == 0:
            a.append(l[i])
        else:
            b.append(l[i])

    da = {}
    for e in a:
        if e not in da:
            da[e] = (1,e)
        else:
            da[e] = (da[e][0]+1,da[e][1])

    db = {}
    for e in b:
        if e not in db:
            db[e] = (1,e)
        else:
            db[e] = (db[e][0]+1,db[e][1])

    da[-1] = (0,-1)
    db[-1] = (0,-1)

    la = list(reversed(sorted(list(da.values()))))
    lb = list(reversed(sorted(list(db.values()))))
    #print(la)
    #print(lb)



    if la[0][1] == lb[0][1]:
        ans = n- (la[0][0] + max(la[1][0],lb[1][0]))
    else:
        ans = n - (la[0][0] + lb[0][0])
    print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = list(map(int, input().spit()))

cs = []
cs.append("." * (b+2))
for i in range(a):
  s = "." + input() + "."
  cs.append(s)
cs.append("." * (b+2))

ans = True
for i in range(a):
  for j in range(b):
    if cs[i][j] == "#":
      if cs[i-1][j] == "." and cs[i][j-1] == "." and cs[i+1][j] == "." and cs[i][j+1] == ".":
        ans = False
        break
    if not ans:
      break
  if not ans:
    break
if ans:
  print("Yes")
else:
  print("No")

Fixed submission:
a,b = list(map(int, input().split()))

cs = []
cs.append("." * (b+2))
for i in range(a):
  s = "." + input() + "."
  cs.append(s)
cs.append("." * (b+2))

ans = True
for i in range(a):
  for j in range(b):
    if cs[i][j] == "#":
      if cs[i-1][j] == "." and cs[i][j-1] == "." and cs[i+1][j] == "." and cs[i][j+1] == ".":
        ans = False
        break
    if not ans:
      break
  if not ans:
    break
if ans:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
mat = []
 
for i in range(3):
  a = list(map(int, input().split()))
 
ans = False
if mat[1][0] - mat[0][0] == mat[1][1] - mat[0][1] and mat[1][1] - mat[0][1] == mat[1][2] - mat[0][2]:
  if mat[2][0] - mat[0][0] == mat[2][1] - mat[0][1] and mat[2][1] - mat[0][1] == mat[2][2] - mat[0][2]:
    ans = True
 
if ans:
  print("Yes")
else:
  print("No")

Fixed submission:
mat = []
 
for i in range(3):
  a = list(map(int, input().split()))
  mat.append(a)
  
ans = False
if mat[1][0] - mat[0][0] == mat[1][1] - mat[0][1] == mat[1][2] - mat[0][2]:
  if mat[2][0] - mat[0][0] == mat[2][1] - mat[0][1] and mat[2][1] - mat[0][1] == mat[2][2] - mat[0][2]:
    ans = True
 
if ans:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
mat = []

for i in range(3):
  a = list(map(int, input().split()))

ans = False
if mat[1][0] - mat[0][0] == mat[1][1] - mat[0][1] == mat[1][2] - mat[0][2]:
  if mat[2][0] - mat[0][0] == mat[2][1] - mat[0][1] == mat[2][2] - mat[0][2]:
    ans = True

if ans:
  print("Yes")
else:
  print("No")
  


Fixed submission:
mat = []
 
for i in range(3):
  a = list(map(int, input().split()))
  mat.append(a)
  
ans = False
if mat[1][0] - mat[0][0] == mat[1][1] - mat[0][1] == mat[1][2] - mat[0][2]:
  if mat[2][0] - mat[0][0] == mat[2][1] - mat[0][1] and mat[2][1] - mat[0][1] == mat[2][2] - mat[0][2]:
    ans = True
 
if ans:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
l = [n]
if k==1:
    print(0)
    exit
else:
    while abs(l[-1]-k) not in l:
        l.append(abs(l[-1]-k))
    print(min(l))

Fixed submission:
n,k = map(int, input().split())
print(min(n%k,k-(n%k)))
Buggy python submission (verdict: Runtime Error):
import math
h,w = map(int, input().split())
print(1 if h==1 or w==1 else math.ceil(h*w/2) )

Fixed submission:
a =[list(map(int, input().split())) for i in range(3)] 
n=int(input())
ans = 'No'
for i in range(n):
    d = int(input())
    for i in range(3):
        for j in range(3):
            if d == a[i][j]:
                a[i][j]=0

if a[0][0] == 0 and a[1][1] == 0 and a[2][2]==0:
    ans = 'Yes'
elif a[0][2] == 0 and a[1][1] == 0 and a[2][0]==0:
    ans = 'Yes'
else: 
    for l in a:
        if sum(l)==0:
            ans = 'Yes'
            break
    for l in zip(*a):
        if sum(l)==0:
            ans = 'Yes'
            break
        

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
ss = sorted(set(s))
l = []
for i in ss:
    l.append([i, s.count(i)])
l = sorted(l, key = lambda x:(-x[1],x[0]))
for i in l:
    if i[1]==l[0][1]:
        print(i[0])

Fixed submission:
import collections
n = int(input())
l = []
s = collections.Counter([input() for i in range(n)])
mn = 0
for i in s.most_common():
    if i[1] >= mn:
        mn = i[1]
        l.append(i[0])
    else:
        break
for i in sorted(l):
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
ss = sorted(set(s))
d = []
for i in ss:
    d.append([i,0])
for i in s:
    d[ss.index(i)][1]+=1
d = sorted(d, key = lambda x:(-x[1],x[0]))
for i in d:
    if i[1]==d[0][1]:
        print(i[0])
    else:
        break

Fixed submission:
import collections
n = int(input())
l = []
s = collections.Counter([input() for i in range(n)])
mn = 0
for i in s.most_common():
    if i[1] >= mn:
        mn = i[1]
        l.append(i[0])
    else:
        break
for i in sorted(l):
        print(i)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]
ss = sorted(set(s))
l = len(ss)
if len(s)==l:
    for i in ss:
        print(s)
else:
    d = []
    for i in ss:
        d.append([i,0])
    for i in s:
        d[ss.index(i)][1]+=1
    d = sorted(d, key = lambda x:(-x[1],x[0]))
    for i in d:
        if i[1]==d[0][1]:
            print(i[0])

Fixed submission:
import collections
n = int(input())
l = []
s = collections.Counter([input() for i in range(n)])
mn = 0
for i in s.most_common():
    if i[1] >= mn:
        mn = i[1]
        l.append(i[0])
    else:
        break
for i in sorted(l):
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
ss = sorted(set(s))
l = len(ss)
d = []
for i in ss:
    d.append([i,0])
for i in s:
    d[ss.index(i)][1]+=1
d = sorted(d, key = lambda x:(-x[1],x[0]))
for i in range(l):
    if d[i][1]==d[0][1]:
        print(d[i][0])

Fixed submission:
import collections
n = int(input())
l = []
s = collections.Counter([input() for i in range(n)])
mn = 0
for i in s.most_common():
    if i[1] >= mn:
        mn = i[1]
        l.append(i[0])
    else:
        break
for i in sorted(l):
        print(i)
Buggy python submission (verdict: Time Limit Exceeded):
h = int(input())
m = [h]
ans = 0
while(sum(m)>0):
    for i in range(len(m)):
        while m[i]>0:
            if m[i]==1:
                ans += 1
                m[i]=0
            elif m[i]>1:
                ans+= 1
                m[i]/=2
                m.append(m[i])
print(ans)

Fixed submission:
import math
h = int(input())
ans = 1

for i in range(1,int(math.sqrt(10**12))):
    if  h > ans:
        ans+= 2**i
    else:
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
ans=1
for i in range(1,n):
    if min(p[0:i])>p[i]:
        ans+=1
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
m = 200001
for i in p:
    if i<m:
        ans+=1
        m=i
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())
if a==0 or b==0 or (a<0 and b>0):
    print(0)
elif b<0 and (b-a)%2==0:
    print('Negative')
else:
    print('Positive')

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
m = 200001
for i in p:
    if i<m:
        ans+=1
        m=i
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())
if b==0 or (a<=0 and b>=0):
    print(0)
elif (a<0 and (0-a)%2==1) or (a<0 and b<0 and (b-a)%2==0):
    print('Negative')
else:
    print('Positive')

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
m = 200001
for i in p:
    if i<m:
        ans+=1
        m=i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
ans = n
for i in range(1,n):
    if i> n- p[i]:
        ans -=1
    else:
        for j in range(i+1):
            r = True
            if p[i]>p[j]:
                ans -=1
                break
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
m = 200001
for i in p:
    if i<m:
        ans+=1
        m=i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
ans = n
for i in range(n):
    for j in range(i+1):
        if p[i]>p[j]:
            ans -=1
            break
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
m = 200001
for i in p:
    if i<m:
        ans+=1
        m=i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(0,n):
    if p[i]==min(p[:i+1]):
        ans+=1
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
m = 200001
for i in p:
    if i<m:
        ans+=1
        m=i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
x = int(input())
l = [0,1,2,3,4,5]
k = x%100
n = x//100
ans = '0'
if n*5>=k:
    c = list(itertools.combinations_with_replacement(l,n))
    for i in c:
        if sum(i)==k:
            ans = '1'
            break
print(ans)

Fixed submission:
import itertools
x = int(input())
k = x%100
n = x//100
ans = 0
if n*5>=k and n!=0:
    ans = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
x = int(input())
l = [0,1,2,3,4,5]
k = x%100
n = x//100
ans = '0'
c = list(itertools.product(l,repeat = n))
for i in c:
    if sum(i)==k:
        ans = '1'
        break
print(ans)

Fixed submission:
import itertools
x = int(input())
k = x%100
n = x//100
ans = 0
if n*5>=k and n!=0:
    ans = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
x = int(input())
l = [0,1,2,3,4,5]
k = x%100
n = x//100
ans = '0'
c = list(itertools.combinations_with_replacement(l,n))
for i in c:
    if sum(i)==k:
        ans = '1'
        break
print(ans)

Fixed submission:
import itertools
x = int(input())
k = x%100
n = x//100
ans = 0
if n*5>=k and n!=0:
    ans = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int, input().split())
al = [int(input()) for i in range(q)]
for i in range(n):
    print('Yes' if k-(q-al.count(i+1))>0 else 'No')

Fixed submission:
n,k,q = map(int, input().split())
ans = [0]*n
for i in range(q):
    w = int(input())
    ans[w-1]+=1
for i in range(n):
        print('Yes' if ans[i]>=q-k+1 else 'No')

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int, input().split())
a = [int(input()) for i in range(q)]
if k>q:
    for i in range(n):
        print('Yes')
else:
    for i in range(1,n+1):
        print('Yes' if k-len(a)+a.count(i)>0 else 'No')

Fixed submission:
n,k,q = map(int, input().split())
ans = [0]*n
for i in range(q):
    w = int(input())
    ans[w-1]+=1
for i in range(n):
        print('Yes' if ans[i]>=q-k+1 else 'No')

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int, input().split())
a = [int(input()) for i in range(q)]
if k>q:
    for i in range(n):
        print('Yes')
else:
    for i in range(1,n+1):
        if i not in a:
            print('No')
        else:
            print('Yes' if k-len(a)+a.count(i)>0 else 'No')

Fixed submission:
n,k,q = map(int, input().split())
ans = [0]*n
for i in range(q):
    w = int(input())
    ans[w-1]+=1
for i in range(n):
        print('Yes' if ans[i]>=q-k+1 else 'No')

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int, input().split())
p = [k]*n
for i in range(q):
    w = int(input())
    for j in range(n):
        if j!= w-1:
            p[j]-=1
for i in p:
    print('Yes' if i>0 else 'No')

Fixed submission:
n,k,q = map(int, input().split())
ans = [0]*n
for i in range(q):
    w = int(input())
    ans[w-1]+=1
for i in range(n):
        print('Yes' if ans[i]>=q-k+1 else 'No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
a2 = sorted(set(a), reverse = True)
for i in a:
    print(a2[0] if i!=a2[0] else a2[1])

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
a2 = sorted(a, reverse = True)
for i in a:
    print(a2[0] if i!=a2[0] else a2[1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
print(max(a[1:]))
for i in range(1,n-1):
    print(max(max(a[:i]),max(a[i+1:])))
print(max(a[:n-1]))

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
a2 = sorted(a, reverse = True)
for i in a:
    print(a2[0] if i!=a2[0] else a2[1])
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
cn = [i for i in range(1,n+1)]
for i in range(m):
    l,r = map(int, input().split())
    lr = [i for i in range(l,r+1)]
    cn = set(cn)&set(lr)
print(len(cn))

Fixed submission:
n,m = map(int, input().split())
fn = 1
ln = n
for i in range(m):
    l,r = map(int, input().split())
    fn = max(fn,l)
    ln = min(ln,r)    
print(ln-fn+1 if ln-fn>=0 else 0)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,m = map(int, input().split())
d = [0]*n
for i in range(m):
    l,r = map(int, input().split())
    for i in range(l-1,r):
        d[i]+=1
count = 0
for i in d:
    if i == m:
        count+=1       
print(count)

Fixed submission:
n,m = map(int, input().split())
fn = 1
ln = n
for i in range(m):
    l,r = map(int, input().split())
    fn = max(fn,l)
    ln = min(ln,r)    
print(ln-fn+1 if ln-fn>=0 else 0)
Buggy python submission (verdict: Runtime Error):
import math
fp = 10
ans = 0
for i in range(5):
    a = int(input())
    ans+= math.ceil(a/10)*10
    if a%10!=0:
    fp =  min(fp, a%10)
print(ans+fp-10 if fp@!=10 else ans )

Fixed submission:
import math
m = [int(input()) for i in range(5)]
n = 10
ans = 0
for i in m:
    ans+= math.ceil(i/10)*10
    if i%10!=0:
        n = min(n, i%10)
print(ans-10+n)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
while True:
    a = sorted(a)
    ec = 0
    for i in range(len(a)-1,-1,-1):
        if a[i]%2==0 and ec==0:
            a[i]/=2
            ec+=1
        elif a[i]%2==0:
            a[i]*=3
    if ec ==1:
        cnt+=1
    else:
        break        
print(cnt)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(len(a)-1,-1,-1):
    if a[i]%2==0:
        while(a[i]%2==0):
            cnt+=1
            a[i]/=2
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int, input().split())
ans = 0
if a==b:
    ans = 0
else:
    for i in range(k):
        a1 = b+c
        b1 = c+a
        c1 = a+b
        a = a1
        b = b1
        c = c1
    if abs(a-b)>=10**18:
        ans = 'Unfair'
    else:
        ans = a-b
print(ans)

Fixed submission:
a,b,c,k = map(int, input().split())
print(0 if a==b else a-b if k%2==0 else b-a)
Buggy python submission (verdict: Runtime Error):
x = int(input())
ans = 1
for i in range(2,x+1):
    j = 2
    while i **j <= x:
        ans = max(ans, i**j)
        j+=1
print(ans)

Fixed submission:
a,b,c,d = map(int, input().split())
print('Yes' if (abs(a-b)<=d and abs(c-b)<=d) or abs(a-c)<=d else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
for i in range(2,n+1):
    ans*=i
ans = ans % (pow(10,9)+7)
print(ans)

Fixed submission:
n = int(input())
ans = 1
p = pow(10,9)+7
for i in range(2,n+1):
    ans = (i * ans)%p
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
x1 = math.ceil(n/1.08)
print(':(' if math.floor(x1*1.08) != n else x1)

Fixed submission:
n,a,b = map(int, input().split())
s = input()
p = a+b
cnt = 0
bcnt = 0
for i in range(n):
    if s[i] == 'a' and cnt < p:
        print('Yes')
        cnt+=1
    elif s[i] == 'b' and cnt < p and bcnt < b:
        print('Yes')
        cnt+=1
        bcnt+=1
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
l = sorted(list(map((int, input().split()))))
ans = 0
if l[0]%2!=0 and l[1]%2!=0 and l[2]%2!=0:
    ans += l[0]*l[1]
print(ans)

Fixed submission:
l = sorted(list(map(int, input().split())))
ans = 0
if l[0]%2!=0 and l[1]%2!=0 and l[2]%2!=0:
    ans += l[0]*l[1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int, input().split())
ans = 1
for i in range(a,b+1):
    ans*=i
print('Positive' if ans>0 else 'Zero' if ans == 0 else 'Negative')

Fixed submission:
a,b = map(int, input().split())
if a>0:
    print('Positive')
elif b<0:
    if (b-a)%2==0:
        print('Negative')
    else:
        print('Positive')
else:
    print('Zero')
Buggy python submission (verdict: Runtime Error):
H,W = [int(i) for i in input().split()]

h1 = H//2
h2 = H-h1

w2 = W//2
w1 = W-w2

if H==1 or W==1:
  print(1)
else:
  print(h2*w1+h1*w2)

Fixed submission:
N,M,C = [int(i) for i in input().split()]

B = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for i in range(N)]

rez = [0]*N

for i in range(M):
  for j in range(N):
    rez[j] += B[i]*A[j][i]

count = 0
for i in rez:
  if i+C>0:
    count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
a,b = [int(i) for in input().split()]

res = int(str(a)+str(b))**0.5
if int(res)==res:
  print("Yes")
else:
  print("No")


Fixed submission:
a,b = [int(i) for i in input().split()]

res = int(str(a)+str(b))**0.5
if int(res)==res:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    for e in a:
        d[e] += 1
    sm = 0
    xd = defaultdict(int)
    for k in d:
        if d[k] >= 2:
            xd[k] = factorial(d[k]) // (2 * factorial(d[k]-2))
        sm += xd[k]
    for e in a:
        d[e] -= 1
        sm -= xd[e]
        x = 0
        if d[e] >= 2:
            x = factorial(d[e]) // (2 * factorial(d[e]-2))
        print(sm + x)
        sm += xd[e]
        d[e] += 1


    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""


"""


Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    for e in a:
        d[e] += 1
    sm = 0
    xd = defaultdict(int)
    for k in d:
        if d[k] >= 2:
            xd[k] = (d[k] * (d[k] - 1)) // 2
        sm += xd[k]
    for e in a:
        d[e] -= 1
        sm -= xd[e]
        x = 0
        if d[e] >= 2:
            x = (d[e] * (d[e] - 1)) // 2
        print(sm + x)
        sm += xd[e]
        d[e] += 1


    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""


"""
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
from math import sqrt, gcd, factorial, tan, pi, sin, cos
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]

MOD = 998244353

def solve():
    n = int(input())
    d = [int(x) for x in input().split()]
    f = [0] * n
    for e in d:
        f[e] += 1
    
    ok = f[0] == 1
    z = 0
    ans = 1
    for i in range(1, n):
        if (f[i] == 0): z = 1
        if (z and f[i]): ok = 0
        ans *= pow(f[i-1], f[i], MOD)
        ans %= MOD
    print(ans * ok)




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)

"""



Fixed submission:
# -*- coding: utf-8 -*-
import sys
# from collections import defaultdict, deque
# from math import sqrt, gcd, factorial, tan, pi, sin, cos
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]

MOD = 998244353

def solve():
    n = int(input())
    d = [int(x) for x in input().split()]
    f = [0] * n
    for e in d:
        f[e] += 1
    
    ok = f[0] == 1 and d[0] == 0
    z = 0
    ans = 1
    for i in range(1, n):
        if (f[i] == 0): z = 1
        if (z and f[i]): ok = 0
        ans *= pow(f[i-1], f[i], MOD)
        ans %= MOD
    print(ans * ok)




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)

"""