Problem:


Score : 100 points

Problem Statement

How many ways are there to choose two distinct positive integers totaling N, disregarding the order?

Constraints

1 \leq N \leq 10^6

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

4

Sample Output 1

1

There is only one way to choose two distinct integers totaling 4: to choose 1 and 3. (Choosing 3 and 1 is not considered different from this.)

Sample Input 2

999999

Sample Output 2

499999



Sample input:
4


Sample output:
1

Submission status: Runtime Error

Solution code:
a=int(input())

x=(a-2)/2
if int(x) ==x:
    print(x)
elif:
    print(int(x)+1)

Submission status: Runtime Error

Solution code:
a=int(input())
#b=int(input())
#c=int(input())
#d=int(input())
x=(a-2)/2
if int(x) ==x:
    print(x)
elif:
    print(x+1)

Submission status: Runtime Error

Solution code:
N=input()
if N%2==0:
    print((N)/2-1)
else:
    print((N-1)/2)

Submission status: Runtime Error

Solution code:
if N%2==0:
    print((N)/2-1)
else:
    print((N-1)/2)

Submission status: Runtime Error

Solution code:
 if N%2==0 :
    print((N)/2-1)
 else:
  print((N-1)/2)

Submission status: Runtime Error

Solution code:
print((int(input())-1//2)

Submission status: Runtime Error

Solution code:
n=int(input())
lists=list(map(int,input().split()))
a=lists.copy()
anslist=[0 for i in range(n+1)]
for j in lists:
    anslist[j]+=1
if anslist[0]!=1:
    print(0)
else:
    ans=1
    for j in range(n):
            for k in range(anslist[j+1]):
                ans=anslist[j]*ans
                ans=ans%(998244353)
    if a[0]!=0:
      print(0)
    else:
      print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
count=[0]*(m+1)
for i in a:
    count[i] += 1
if a[0]:
    print(0)
    exit()
for i in range(m):
    if count[i]==0 and count[i+1]:
        print(0)
        exit()

ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

Submission status: Runtime Error

Solution code:
print((int(input)-1)//2)

Submission status: Runtime Error

Solution code:

import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=[0] * (M + 1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif M<2:
    print(1)
    sys.exit()

if D[0]!=0 :
    print(0)
    sys.exit()

for i in range(2,M+1):
        ans *= countlist[i-1]**countlist[i]

print(ans%998244353)

Submission status: Runtime Error

Solution code:

import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=np.zeros(M+1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif countlist[1]==0 and M==1:
    print(1)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<M:
        ans=0
    else:
        break


print(int(ans%998244353))

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
D = list(map(int,input().split()))
ans=0

if D.count(0)!=1 :
    print(ans)
    sys.exit()
else:
    ans=1

for i in range(2,99999):
    mae=D.count(i-1)
    ato=D.count(i)

    if ato>0:
        ans *= mae**ato
    elif ato==0 and i<max(D):
        ans=0
    else:
        break
    
    ans%998244353


print(ans%998244353)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
D = list(map(int,input().split()))
ans=0

if D.count(0)==0 :
    print(ans)
    sys.exit()
else:
    ans=1

for i in range(2,99999):
    mae=D.count(i-1)
    ato=D.count(i)

    if ato>0:
        ans *= mae**ato
    elif ato==0 and i<max(D):
        ans=0
    else:
        break

print(ans%998244353)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
Bsi = np.argsort(B)
A2 = A[Bsi]
Bs = B[Bsi]
A2si = np.argsort(A2)
As = A2[A2si]
C = Bs-As
if any(C[C<0]):
    ans = 'No'
else:
    D = A2-As
    if any(D == 0):
        ans = 'Yes'
    elif all(As[1::]-Bs[:-1:] > 0):
        psum = A2si[0]
        for i,pi in enumerate(A2si[1:-1],1):
            psum += pi
            if psum == int(i*(i+1)/2):
                ans = 'Yes'
                break
        else:
            ans = 'No'
    else:
        ans = 'Yes'
        
print(ans)

Submission status: Runtime Error

Solution code:
n = input()
a = input().split(" ")
b = input().split(" ")

s_a = sorted(a)
s_b = sorted(b)

t_b = ["-1"]*len(s_b)

for i, v in enumerate(s_a):
    pos = a.index(v)
    if (pos == i):
        exit("Yes")
    else:
        t_b[pos] = s_b[i]

for i,v in enumerate(s_b):
    j = t_b.index(v)
    if (t_b[i] == s_b[j]):
        exit("Yes")

exit("No")

Submission status: Runtime Error

Solution code:
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanB
        #print('i=',i)#Debug
        if A[i] <= B[i]:
            continue
        elif i < n-1:
            for j in range(i+1,n):#scanA
                #print(f'i={i},j={j}')
                if A[j] <= B[i]:
                    A[j],A[i] = A[i],A[j]
                    count += 1
                    if count > n-2:
                        return 'No'
                    #print(f'swap:{count}')
                    #print(f'A:{A}')
                    #print(f'B:{B}')
                    break
                elif j == n-1:
                    return 'No'
        else:
            return 'No'
    
    return 'Yes'

                
#main

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

#print(f'A:{A}')
#print(f'B:{B}')

pair = list(zip(A,B))
pair.sort(key=itemgetter(1))#sortB

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(f'A:{ltA}')
#print(f'B:{ltB}')

#print(f'pair:{pair}')

print(calc(n,ltA,ltB))#for stdout

Submission status: Runtime Error

Solution code:
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanB
        #print('i=',i)#Debug
        if A[i] <= B[i]:
            continue
        elif i < n-1:
            for j in range(i+1,n):#scanA
                if A[j] <= B[i] and A[i] <= B[j]:
                    A[j],A[i] = A[i],A[j]
                    count += 1
                    if count > n-2:
                        return 'No'
                    #print(f'swap:{count}')
                    #print(f'A:{A}')
                    #print(f'B:{B}')
                    break
                elif j == n-1:
                    return 'No'
        else:
            return 'No'
    
    return 'Yes'

                
#main

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

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(1))#sortB

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(f'A:{ltA}')
#print(f'B:{ltB}')

#print(f'pair:{pair}')

print(calc(n,ltA,ltB))#for stdout

Submission status: Runtime Error

Solution code:
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanB
        print('i=',i)#Debug
        if A[i] <= B[i]:
            continue
        elif i < n-1:
            for j in range(i+1,n):#scanA
                if A[j] <= B[i] and A[i] <= B[j]:
                    A[j],A[i] = A[i],A[j]
                    count += 1
                    if count > n-2:
                        return 'No'
                    print(f'swap:{count}')
                    print(f'A:{A}')
                    print(f'B:{B}')
                    break
                elif j == n-1:
                    return 'No'
        else:
            return 'No'
    
    return 'Yes'

                
#main

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

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(1))#sortB

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(f'A:{ltA}')
#print(f'B:{ltB}')

#print(f'pair:{pair}')

print(calc(n,ltA,ltB))#for stdout

Submission status: Runtime Error

Solution code:
import heapq

INF = 2**62-1

def dijkstra(route_map, start_point):
    num_of_city = len(route_map)
    dist = [INF for _ in range(num_of_city)]

    dist[start_point] = 0
    heap_q = []
    heapq.heappush(heap_q, (0, start_point))
    while heap_q:
        prev_cost, src = heapq.heappop(heap_q)

        if dist[src] < prev_cost:
            continue

        for dest, cost in route_map[src].items():
            if dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost
                heapq.heappush(heap_q, (dist[dest], dest))
    return dist

n, m = list(map(int, input().split()))
route_map = [{} for _ in range(n)]

for i in range(m):
    u, v, a = list(map(int, input().split()))
    u, v = u - 1, v - 1
    if v in route_map[u].keys():
        a = min(a, route_map[u][v])
    route_map[u][v] = a

for i in range(n-1):
    u, v = i+1, i
    route_map[u][v] = 0

# ゴールまでの最短経路
dijkstra_result = dijkstra(route_map, 0)

if dijkstra_result[-1] != INF:
    print(dijkstra_result[-1])
else:
    print(-1)

Submission status: Runtime Error

Solution code:
n = input()
for i in range(n):
  x += i
  print(x)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
count1 = 0
count2 = 0

A_new = sorted(A)
B_new = sorted(B)
 
for i in range(N):
    if B_new[i] >= A_new[i]:
        count2 += 1
 
for i in range(N):
    for j in range(N):
        if A[i] == A_new[j] and B[i] == B_new[j] 
            count1 = 1
            break
        if A[i] == A_new[j] and B[i] < B_new[j]
            break
    if count1 == 1:
        break
 
if count1 == 1 and count2 == N:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    ans = 0.0

    for i in range(1, N+1):
        c = 0
        if i < K:
            c = math.ceil(math.log2(K) - math.log2(i))
        # print(i, c, (1.0 / (2 ** c)), 1.0/N)
        ans += (1.0 / (2 ** c)) * 1.0/N

    print("{0:.20f}".format(ans))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
path=[[0 if i==j or i==max(j-1,0) else float("inf") for i in range(N)] for j in range(N)]
for _ in range(M):
  l,r,c=map(int,input().split())
  path[l-1][r-1]=c
print(path)
seen=[]
dist=[float("inf")]*N
dist[0]=0
v=-1
while v!=N-1:
  v=-1
  for i in range(N):
    if i not in seen and v==-1:
      v=i
    if i not in seen and dist[i]<dist[v]:
      v=i
  seen.append(v)
  for i in range(N):
    dist[i]=min(dist[v]+path[v][i],dist[i])
    
if dist[N-1]==float("inf"):
  print(-1)
else:
  print(dist[N-1])

Submission status: Runtime Error

Solution code:
n = int(intput())
if(n%2 == 1):
  print(n//2)
else:
  print((n//2)-1)

Submission status: Runtime Error

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
elif D[1]==0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
        if d == cur:
            n2 += 1
        else:
            nn = (n1**n2)%998244353
            ans *= nn
            n1 = n2
            n2 = 1
            cur = d
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
elif D[1]==0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
        if d == cur:
            n2 += 1
        else:
            ans *= n1**n2
            ans %= 998244353                
            n1 = n2
            n2 = 1
            cur = d
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
elif D[1]==0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
        if d == cur:
            n2 += 1
        else:
            ans *= n1**n2
            n1 = n2
            n2 = 1
            cur = d
print(ans%998244353)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
	n = int(input())
	d = list(map(int,input().split()))
	z = defaultdict(int)
	for i in d:
		z[i] += 1
	mx = max(d)
	for i in range(mx+1):
		if z[i] == 0:
			print(0)
			return
	if(d[0]!=0 and z[0] != 1):
		print(0)
		return
	ans = 1
	for i in reversed(range(1,mx+1)):
		ans *= z[i-1]**z[i]
	print(ans%998244353)

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Runtime Error

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
	n = int(input())
	d = list(map(int,input().split()))
	z = defaultdict(int)
	for i in d:
		z[i] += 1
	mx = max(d)
	for i in range(mx+1):
		if z[i] == 0:
			print(0)
			return
	if(d[0]!=0):
		print(0)
		return
	ans = 1
	for i in reversed(range(1,mx+1)):
		ans *= z[i-1]**z[i]
	print(ans%998244353)

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Runtime Error

Solution code:
if (N == 0 or 1):
  print(0)
else:
  print((N-1)/2)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
from collections import defaultdict

def main():
        
    n = int(input())
    a = np.array(list(map(int, input().split())))
    b = np.array(list(map(int, input().split())))

    a_sort = np.sort(a)
    b_sort = np.sort(b)

    # 1. 回数関係なくそもそも不可能なやつ → no
    # 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
    # 2-b. サイクルが2以上にわけられるやつ → yes

    # 1
    if (a_sort > b_sort).any():
        print('No')
        exit()

    # 2-a
    if (a_sort[1:] <= b_sort[:-1]).any():
        print('Yes')
        exit()

    # 2-b （startをとりあえず1とかにする）
    d = defaultdict(int)
    for i in range(n):
        d[a[i]] = b[i]

    from_ = 1
    count = 0
    while True:
        count += 1
        from_ = d[from_]
        if from_ == 1:
            break

    if count != n:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n-1):#scanA
        Bmin = B[i]
        swapnum = i
        for j in range(i+1,n):
            if Bmin > B[j]:
                Bmin = B[j]
                swapnum = j            
        
        if A[i] > Bmin:
            return 'No'
        elif A[i+1] > Bmin:
            B[swapnum] = B[i]
            count += 1
    
    if count > n -2:
        return 'No'
    else:
        return 'Yes'

                
#main

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

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(0))#sortA

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(ltA)
#print(ltB)

#print(pair)

print(calc(n,ltA,ltB))

Submission status: Runtime Error

Solution code:
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n-1):#scanA
        if A[i] > B[i]:
            return 'No'
        
        Bmin = B[i]
        swapnum = i
        for j in range(i+1,n):
            if Bmin > B[j]:
                Bmin = B[j]
                swapnum = j            
        
        #A[i+1]<=Bminでなければ入れ替える。
        if A[i+1] > Bmin:
            B[swapnum] = B[i]
            count += 1
        
    if count > n -2:
        return 'No'
    else:
        return 'Yes'

                
#main

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

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(0))#sortA

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(ltA)
#print(ltB)

#print(pair)

print(calc(n,ltA,ltB))

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input().strip().split()))
D.sort()
# print(D)
 
def calc(arr):
  if arr[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(arr)):
    if arr[i] == 0:
      return 0
    if arr[i] == arr[i-1]:
      curCount += 1
    elif arr[i] == arr[i-1] + 1:
      preCount = curCount
      curCount = 1
    else:
      return 0
    result = result * preCount
    if result > 998244353:
      result = result % 998244353
    #print(pre, curCount, preCount, result)
  return result%998244353
 
print(calc(D))

Submission status: Runtime Error

Solution code:
= int(input())
if N // 2 == 0:
  ans = N / 2 - 1
else:
  ans = (N - 1) / 2
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

count1 = 0
count2 = 0

AB = []
AB_new = []
A_new = sorted(A)
B_new = sorted(B)

for i in range(N):
    AB.append([A[i],B[i]])
    AB_new.append([A_new[i],B_new[i]])
    
aaa = sorted(AB, key=lambda x:(x[0],x[1]))

for i in range(N):
    if B_new[i] >= A_new[i]:
        count2 += 1

for i in range(N):
    for j in range(N):
        if aaa[i] == AB_new[j]:
            count1 = 1
            break
        if AB_new[j][0] > aaa[i][0]:
            break
    if count1 == 1:
        break

if count1 == 1 and count2 == N:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanA
        Bmin = B[i]
        swapnum = i
        
        #B[i～n-1]の最小値を探す
        for j in range(i,n):
            if Bmin > B[j]:
                Bmin = B[j]
                swapnum = j
        #最小値がA[i]より小さければ並べ変えは不可能
        if A[i] > Bmin:
            return 'No'
        
        #最小値がB[i]でなければ入れ替える。
        if swapnum != i:
            B[swapnum] = B[i]
            count += 1
        
    if count > n -2:
        return 'No'
    else:
        return 'Yes'

                
#main

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

#print(A)
#print(B)

pair = list(zip(A,B))
pair.sort(key=itemgetter(0))#sortA

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(ltA)
#print(ltB)

#print(pair)

print(calc(n,ltA,ltB))

Submission status: Runtime Error

Solution code:
n = int(input())
print n//2

Submission status: Runtime Error

Solution code:
import collections

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

c = collections.Counter(d)

jug = True
for i in range(max(d) + 1):
    if i not in c:
        jug = False

c = sorted(c.items(), key=lambda x:x[0])

if c[0][0] != 0:
    jug = False

ans = 1

for i in range(1, len(c)):
    if c[i][0] < 0:
        jug == False
    m = c[i-1][1]
    r = c[i][1]
    ans *= m ** r
    ans %= 998244353
    if ans == 0:
        jug = False
    
if jug == False:
    print(0)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
alis = list(map(int, input().split()))
blis = list(map(int, input().split()))
alis.sort()
blis.sort()
for i in range(n):
    if alis[i] > blis[i]:
        print("No")
        sys.exit()


for i in range(n-1):
    if alis[i+1] > blis[i]:
        pass
    else:
        print("Yes")
        sys.exit()
print("No")

Submission status: Runtime Error

Solution code:
N=int(input())
if (N%2)=0:
  ans=N//2-1
else:
  ans=N//2
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(map(list,co(map(int,input().split())).items())))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  #if i!=n:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
if D[0] != 0 or 0 in D[1:]:
    print(0)
else:
    nums = []
    previous_num = D[0]
    previous_cnt = 1
    cnt = 1
    sum = 1
    for i in range(1,N):
        if D[i] != previous_num:
            if D[i] - previous_num != 1:
                print(0)
                sys.exit()
            previous_num = D[i]
            sum *= previous_cnt ** cnt
            previous_cnt = cnt
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            sum *= previous_cnt ** cnt
    
    print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
if D[0] != 0 or 0 in D[1:]:
    print(0)
else:
    nums = []
    previous_num = D[0]
    previous_cnt = 1
    cnt = 1
    sum = 1
    for i in range(1,N):
        if D[i] != previous_num:
            previous_num = D[i]
            sum *= previous_cnt ** cnt
            previous_cnt = cnt
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            sum *= previous_cnt ** cnt
    
    print(sum)

Submission status: Runtime Error

Solution code:
N = input()
N = N-1
print(N/2)

Submission status: Runtime Error

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

lin.sort()

if lin[0][0] != 0 or lin[0][1] > 1:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    
    point *= (lin[i-1][1]**lin[i][1])

print(point%998244353)

Submission status: Runtime Error

Solution code:
n=int(input())
listx=list(map(int,input().split()))
listx.sort()
x=1
if listx[0]!=0:
  x=0
else:
  for i in range(listx[-1]):
    x*=listx.count(int(i+1))+1
print(x)

Submission status: Runtime Error

Solution code:
n=int(input())
listx=list(map(int,input().split()))
listx.sort()
x=1
if listx[0]!=0:
  x=0
else:
  for i in range(listx[-1]):
    print(i+1)
    x*=listx.count(int(i+1))+1
print(x)

Submission status: Runtime Error

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

if lin[0][0] != 0 or lin[0][1] > 1:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0] +1 != lin[i][0]:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]

print(point%998244353)

Submission status: Runtime Error

Solution code:
def main():
  N=int(input())
  A=list(map(int,input().split()))
  B=list(map(int,input().split()))
  tmp={}
  for i in range(N):
    if not B[i] in tmp.keys():
      tmp[B[i]]=[]
    tmp[B[i]].append(A[i])
  A.sort()
  B.sort()
  for i in range(N):
    if A[i]>B[i]:
      print("No")
      return 0
  for i in range(N):
    if A[i] in tmp[B[i]]:
      print("Yes")
      return 0
    if i!=N-1:
      if B[i] >= A[i+1]:
        print("Yes")
        return 0
  print("No")
      
main()

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
mod = 998244353
ans = 1
if N == 1 and D[0] == 0:
    print(1)
elif len(set(D))==1:
    print(0)
elif D.count(0) != 1:
    print(0)
elif D[0] != 0:
    print(0)
else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    flag = True
    for i in range(1,max(D)+1):
        #print(cnt[i],tmp)
        if i != 1 and cnt[i] != tmp:
            flag = False
        c = (tmp**cnt[i]) % mod
        ans *= c % mod
        tmp = cnt[i]
        ans = ans % mod
    if flag:
        print(1)
    else:
        print(ans % mod)

Submission status: Runtime Error

Solution code:
N = int(input())

INF = 10 ※※ 8

L = []

for i in range(1,N):
  diff = N - i
  pair = set(i,diff)
  if len(pair) == 2 and pair not in L:
    L.append(pair)

print(len(L))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
a = int(input())
b = input().split()
c = input().split()

for i in range(a):
    b[i] = int(b[i])
    c[i] = int(c[i])

out = "Yes"

def check_max(l, num):
    max_num = 0
    max_i = -1

    l_sorted = sorted(l)
    num_list = [-1] * num
    num_list2 = [-1] * num

    for i in reversed(range(num)):
        for j in range(num):
            if l_sorted[i] == l[j]:
                if num_list[j] == -1:
                    num_list[j] = i+1
                    num_list2[i] = j
                    break

    return (num_list, list(reversed(num_list2)))

def checklist(l1, l2, num):
    result = True
    for i in range(num):
        if l1[i] > l2[i]:
            result = False
            break
    return result 


if out == "Yes":
    swap_num = 0

    num_list_b, num_list_b_index = check_max(b,a)
    num_list_c, num_list_c_index = check_max(c,a)



    for i in range(a-2):
        index1 = num_list_b_index[i]
        index2 = num_list_c_index[i]


        

        if b[index1] <= c[index2]:
            b[index1], b[index2] = b[index2], b[index1]

if not checklist(b, c, a):
    out = "No"
else:
    out = "Yes"

print(out)

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * N
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print(0)
        exit()
    ans = ans % mod
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * (N-1)
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print(0)
        exit()
    ans = ans % mod
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import collections
def main():
    n = int(stdin.readline().rstrip())
    D = [int(i) for i in input().split()]
    hash = collections,Counter(D)
    count = hash[0]
    for i in range(1, max(D)+1):
        count *= hash[i-1] ** hash[i]
    print(count%998244353)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
d=list(map(int,input().split()))
count=1
if d[0]!=0:
    count=0
for i in range(max(d)):
    count *= pow(i+1,d.count(i+1),99844353)
print(count)

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
D = list(sorted(list(map(int, input().split()))))

check = 0
if not check == D[0]:
    print(0)
    sys.exit()
countl = [0]
for d in D:
    if not check == d:
        check += 1
        countl.append(0)
        if not check == d:
            print(0)
            sys.exit()
    countl[-1] += 1
if not countl[0] == 1:
    print(0)
    sys.exit()

ans = 1
for i in range(len(countl) - 1):
    ans *= pow(countl[i], countl[i + 1], 998244353)
print(ans % 998244353)