Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys


def solve():
    MOD = 998244353
    N, *d_l = map(int, open(0).read().split())
    ans = 1
    
    if d_l[0] != 0:
        print(0)
        sys.exit()
    
    d_max = max(d_l)
    count_l = [d_l.count(1)]
    for i in range(2, d_max+1):
        if count_l[i-2] == 0:
            print(0)
            sys.exit()
        count_l.append(d_l.count(i))
    
    for i in range(1, d_max):
        ans = ans * count_l[i-1] ** count_l[i]
    
    print(ans%MOD)


if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
import collections


def solve():
    MOD = 998244353
    N, *d_l = map(int, open(0).read().split())
    ans = 1
    
    if d_l[0] != 0:
        print(0)
        sys.exit()
    
    d_max = max(d_l)
    count_dic = collections.Counter(d_l)
    if count_dic[0] != 1:
        print(0)
        sys.exit()
    
    for i in range(2, d_max+1):
        ans *= count_dic[i-1] ** count_dic[i]
    
    print(ans%MOD)


if __name__ == '__main__':
    solve()
### BUGGY CODE ###

N,M,R=map(int,input().split())
r=list(map(int,input().split()))
for i in range(R):
  r[i] -= 1

g = [ [1001001001] * N for _ in range(N) ]
for i in range(N):
  g[i][i] = 0

for _ in range(M):
  A,B,C=map(int,input().split())
  A-=1
  B-=1
  g[A][B] = C
  g[B][A] = C

for k in range(N):
  for i in range(N):
    for j in range(N):
      g[i][j] = min(g[i][j], g[i][k] + g[k][j])
memo = {}

def f(s, l, c):
  if s + 1 == 1 << R:
    return c
  if (s,l) in memo:
    return memo[s,l];
  res = 1001001001
  for i in range(R):
    if (s >> i & 1) == 0:
      x = f(s | (1 << i), i, c + g[r[l]][r[i]])
      res = min(res, x)
  memo[s, l] = res
  return res

ans = min([ f(1 << i, i, 0) for i in range(R) ]) 
print(ans)

### FIXED CODE ###

import itertools

N,M,R=map(int,input().split())
r=list(map(int,input().split()))
for i in range(R): r[i] -= 1

g = [ [1001001001] * N for _ in range(N) ]
for i in range(N):
  g[i][i] = 0

for _ in range(M):
  A,B,C=map(int,input().split())
  A-=1
  B-=1
  g[A][B] = C
  g[B][A] = C

def md(beg):
  d = [1001001001] * N
  done = [False] * N
  d[beg] = 0
  while True:
    cur = 1001001001
    pos = -1
    for i in range(N):
      if not done[i] and cur > d[i]:
        cur = d[i]
        pos = i
    if pos == -1:
      break
    done[pos] = True
    for i in range(N):
      d[i] = min(d[i], d[pos] + g[pos][i])
  return d

for i in range(R):
  g[r[i]] = md(r[i])

ans = 1001001001
for p in itertools.permutations(r):
  cur = 0
  for i in range(1, R):
    cur += g[p[i-1]][p[i]]
  ans = min(ans, cur)
print(ans)
### BUGGY CODE ###

from bisect import insort_left
N, M=map(int, input().split())
A=[]
Y=[[] for _ in range(N)] #県
for i in range(M):
  p,y=map(int, input().split())
  A.append((p,y))
  insort_left(Y[p-1],y)

for i in range(M):
  p,y=A[i]
  y=str(Y[p-1].index(y)+1)
  p=str(p)
  ans="0"*(6-len(p))+p+"0"*(6-len(y))+y
  print(ans)

### FIXED CODE ###


N, M=map(int, input().split())
#A=[]
Y=[[] for _ in range(N)] #県
for i in range(M):
  p,y=map(int, input().split())
  #A.append((p,y))
  Y[p-1].append([y,i+1])

for i in range(N):
  if Y[i]:
    Y[i].sort(key=lambda x: x[0])
#indexは時間かかる
ans=[]
for i in range(N):
  for j,L in enumerate(Y[i]):
    p,y,n=i+1, L[0],L[1]
    ans.append((n,p,j+1))
ans=sorted(ans)
for n,p,y in ans:
  a=(6-len(str(p)))*"0"+str(p)+(6-len(str(y)))*"0"+str(y)
  print(a)
### BUGGY CODE ###

nk = list(map(int,input().split()))
p = list(map(int,input().split()))

sumseq = [0] * (nk[0] - nk[1] + 1)
for i in range(nk[0]):
    p[i] = (p[i] + 1) / 2 

for i in range(nk[0] - nk[1] + 1):
    sumseq[i] = sum(p[i:i + nk[1]])


print(max(sumseq))

### FIXED CODE ###

nk = list(map(int,input().split()))
p = list(map(int,input().split()))
ans = [0] * (nk[0] + nk[1])
 
zeros = [0] * nk[1]
 
seq4search = zeros + p
 
for i in range(nk[1], nk[0] + nk[1]):
    seq4search[i] = (seq4search[i] + 1) / 2
    ans[i] = ans[i-1] + seq4search[i] - seq4search[i - nk[1]] 
 
print(max(ans))
### BUGGY CODE ###

def even(S,F,C,c):
    if (F==1 and c%2==0) or (F==2 and c%2==1):
        return C+S
    else:
        return S+C

S=input()
Q=int(input())
c=0
for i in range(Q):
    T=list(map(str,input().split()))
    if len(T)==1:
        c+=1
    else:
        S=even(S,int(T[1]),T[2],c)
        
if c%2==1:
    S=S[::-1]
print(S)

### FIXED CODE ###

S=input()
Q=int(input())
c=0
left=""
right=""
for i in range(Q):
    T=list(map(str,input().split()))
    if len(T)==1:
        c+=1
    else:
        if (T[1]=="1" and c%2==0) or (T[1]=="2" and c%2==1):
            left+=T[2]
        else:
            right+=T[2]

if c%2==0:
    ans=left[::-1]+S+right
else:
    ans=right[::-1]+S[::-1]+left
print(ans)
### BUGGY CODE ###

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

def DFS(G, W, Wlist, visit, node):
	for i in G.graph[node]:
		if visit[i] == 0:
			visit[i] = 1
			DFS(G, W, Wlist, visit, i)
			W[node] += W[i]
			Wlist += [W[i]]
			# Wlist.append(W[i])

#処理内容
def main():
	#入力
	N = int(input())
	G = Graph()
	for i in range(N - 1):
		a, b = getlist()
		a -= 1; b -= 1
		G.add_edge(a, b)
		G.add_edge(b, a)

	#DFS
	W = [1] * N
	Wlist = []
	visit = [0] * N
	visit[0] = 1
	DFS(G, W, Wlist, visit, 0)
	# print(W)
	# print(Wlist)
	for i in range(N):
		Wlist += [N - W[i]]
		# Wlist.append(N - W[i])

	# print(Wlist)
	pow2 = pow(2, N - 1, con)
	ans_up = N * (pow2 - 1)
	for i in Wlist:
		ans_up -= pow(2, i, con) - 1
		ans_up %= con

	# print(ans_up)

	ans = ans_up * pow(pow2 * 2, con - 2, con)
	print(ans % con)

if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
from collections import deque
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

def DFS(G, W, Wlist, visit, node):
	for i in G.graph[node]:
		if visit[i] == 0:
			visit[i] = 1
			DFS(G, W, Wlist, visit, i)
			W[node] += W[i]
			Wlist.append(W[i])

class BFS(object):
	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = deque(); self.Q.append(s)
		self.dist = [INF] * N; self.dist[s] = 0
		self.prev = [None] * N; self.prev[s] = -1
		self.order = []
		while self.Q:
			v = self.Q.popleft()
			self.order.append(v)
			for i in self.g[v]:
				if self.dist[i] == INF:
					self.dist[i] = self.dist[v] + 1
					self.prev[i] = v
					self.Q.append(i)


#処理内容
def main():
	#入力
	N = int(input())
	G = Graph()
	Nedge = [0] * N
	for i in range(N - 1):
		a, b = getlist()
		a -= 1; b -= 1
		G.add_edge(a, b)
		G.add_edge(b, a)
		Nedge[a] += 1; Nedge[b] += 1

	W = [1] * N
	#葉の場合の処理
	# for i in range(N):
	# 	if Nedge[i] == 1:
	# 		W[i] = 1

	BF = BFS(G, 0, N)

	for i in range(N - 1, 0, -1):
		v = BF.order[i]
		W[BF.prev[v]] += W[v]

	Wlist = []
	for i in range(N):
		for j in G.graph[i]:
			if j != BF.prev[i]:
				Wlist.append(W[j])
	for i in range(N):
		Wlist.append(N - W[i])

	pow2 = pow(2, N - 1, con)
	ans_up = N * (pow2 - 1)
	for i in Wlist:
		ans_up -= pow(2, i, con) - 1
		ans_up %= con

	ans = ans_up * pow(pow2 * 2, con - 2, con)
	print(ans % con)

if __name__ == '__main__':
	main()
### BUGGY CODE ###

n = int(input())
x = [int(i) for i in input().split()]
a = x.copy()
x.sort()
n_dict = {i: x.index(a[i]) for i in range(n)}
for num in n_dict.values():
    if num < n//2:
        print(x[int(n//2)])
    else:
        print(x[int(n//2)-1])

### FIXED CODE ###

n = int(input())
x = [int(i) for i in input().split()]
y = x.copy()
y.sort()
y_e = y[n//2]
y_o = y[n//2 - 1]
for xx in x:
    if xx >= y_e:
        print(y_o)
    else:
        print(y_e)
### BUGGY CODE ###

N, M = map(int, input().split())
lst_a = [int(input()) for _ in range(M)]
MOD = 10**9 + 7

dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 0 if 1 in lst_a else 1
for i in range(2, N+1):
    dp[i] = 0 if i in lst_a else dp[i-1] + dp[i-2]
    dp[i] %= MOD
ans = dp[N] % MOD

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
set_a = set([int(input()) for _ in range(M)])
MOD = 10**9 + 7

dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 0 if 1 in set_a else 1
for i in range(2, N+1):
    dp[i] = 0 if i in set_a else dp[i-1] + dp[i-2]
ans = dp[N] % MOD

print(ans)
### BUGGY CODE ###

import fractions
from functools import reduce

def lcm(a, b):
    return (a * b) // fractions.gcd(a, b)
def lcm_list(l):
    return reduce(lcm, l, 1)

n = int(input())
a = list(map(int, input().split()))
f = 0
for j in range(n):
    f += (lcm_list(a) - 1) % a[j]
print(f)


### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int, input().split()))
f = 0
ans = np.cumsum(a) - n
print(ans[-1])
### BUGGY CODE ###

N, K = input().split()
N = int(N)
K = int(K)
scores = [int(s) for s in input().split()]
sums = []
for i in range (K-1, N):
    c = 1
    j = i
    for i in range(j,i-K,-1):
        c *= scores[j]
        j -= 1
    sums.append(c)

for i in range(N-K):
    if sums[i] < sums[i+1]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N, K = input().split()
N = int(N)
K = int(K)
scores = [int(s) for s in input().split()]
sums = []
k = K-1
for i in range(k,N-1):
    if(scores[i-k] < scores[i+1]):
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

x,y,z,k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

ab = sorted(a+b for a in aa for b in bb)[:-k-1:-1]
abc = sorted(s+c for s in ab[:k] for c in cc)[:-k-1:-1]
print(*abc, sep='\n')


### FIXED CODE ###

x,y,z,k = map(int, input().split())
aa = sorted(list(map(int, input().split())))
bb = sorted(list(map(int, input().split())))
cc = sorted(list(map(int, input().split())))

ab = sorted(a+b for a in aa for b in bb)[:-k-1:-1]
abc = sorted(s+c for s in ab[:k] for c in cc)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

n,p= map(int,input().split())
for i in range(int(p**(1/n))+1,0,-1):
    if p%(i**n)==0:
        print(i)
        exit()

### FIXED CODE ###

n,p= map(int,input().split())
for i in range(round(p**(1/n)),0,-1):
    if p%(i**n)==0:
        print(i)
        exit()
### BUGGY CODE ###

def breaknumbeer(n):

    ans = 0
    maxcount = 0
    for i in range(n):
        count = 0
        w = i
        while w % 2 == 0:
            w = w / 2
            count += 1
        if count >= maxcount:
            ans = i

    return ans

def main():
    n = int(input())
    print(breaknumbeer(n))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def breaknumbeer(n):

    ans = 1

    while ans <= n:
        ans *= 2

    return int(ans / 2)

def main():
    n = int(input())
    print(breaknumbeer(n))

if __name__ == '__main__':
    main()
### BUGGY CODE ###

mod = 10**9+7
S = input()

dp = [[0] * 13 for i in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
    if S[len(S)-i-1] == '?':
        c = range(10)
    else:
        c = [int(S[len(S)-i-1])]

    for d in c:
        for j in range(13):
            dp[i+1][(j+d*10**i) % 13] += dp[i][j]

    for k in range(13):
        dp[i+1][k] = dp[i+1][k] % mod

    # print(dp)

print(dp[len(S)][5])


### FIXED CODE ###

mod = 10**9+7
S = [int(x) if x != "?" else -1 for x in input()]

dp = [[0] * 13 for i in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
    if S[i] == -1:
        for d in range(10):
            for j in range(13):
                dp[i+1][(j*10+d) % 13] += dp[i][j]
    else:
        d = S[i]
        for j in range(13):
            dp[i+1][(j*10+d) % 13] += dp[i][j]

    for k in range(13):
        dp[i+1][k] = dp[i+1][k] % mod

    # print(dp)

print(dp[len(S)][5])
### BUGGY CODE ###

N=int(input())
sisterN=[]
SISTERn=[]
SISterN=[]
for n in range(N):
    _=int(input())
    if _<30000:
        _s= _
        if sisterN.count(_s)==1:
            sisterN.remove(_s)
        else:
            sisterN.append(_s)
    elif 30001<_<70000:
        _m= _
        if SISterN.count(_m)==1:
            SISterN.remove(_m)
        else:
            SISterN.append(_m)
    elif 70001<_:
        _b= _
        if SISTERn.count(_b)==1:
            SISTERn.remove(_b)
        else:
            SISTERn.append(_b)

print(len(sisterN)+len(SISTERn)+len(SISterN))



### FIXED CODE ###

N=int(input())
S=set()

for n in range(N):
    _=int(input())
    if _ in S:
        S.remove(_)
    else:
        S.add(_)

print(len(S))
### BUGGY CODE ###

S = input()
mod2019 = [0]*len(S)

for i in range(len(S)):
    mod2019[i] = int(S[i:])%2019

mod2019.append(0)

answer = 0
count = [0 for _ in range(2020)]


for i in range(len(S)+1):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)

### FIXED CODE ###

S = input()
mod2019 = [0]*len(S)

mod2019[-1] = int(S[-1])
keta_mod = 1
for i in range(len(S)-2,-1,-1):
    keta_mod = (keta_mod*10)%2019
    mod2019[i] = (mod2019[i+1] + int(S[i])*keta_mod)%2019

mod2019.extend([0])

answer = 0
count = [0 for _ in range(2020)]

for i in range(len(S)+1):
    answer += count[mod2019[i]]
    count[mod2019[i]] += 1
print(answer)
### BUGGY CODE ###

n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
i=0
j=0
count=0
for i in range(n):
  for j in range(i+1,n):
    if data[i]==data[j]:
      count=count+1
print(count)

### FIXED CODE ###

n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
i=0
j=0
count=1
decount=0
for i in range(n-1):
  if data[i]==data[i+1]:
    count=count+1
  else:
    decount=decount+(count-1)*count/2
    count=1
decount=decount+(count-1)*count/2
print(int(decount))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)

n,q = map(int,input().split())
tree = {i : [] for i in range(n)}
for i in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append(b)
  tree[b].append(a)
score = [0 for _ in range(n)]
for i in range(q):
  p,x = map(int,input().split())
  score[p-1] += x
  
def dfs(parent,node,s):
  for n in tree[node]:
    if n == parent:
      continue
    score[n] += score[node]
    dfs(node,n,s)

dfs(-1,0,0)
  
print(*score)
 

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,q = map(int,input().split())
tree = {i : [] for i in range(n)}
for i in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  tree[a].append(b)
  tree[b].append(a)
score = [0 for _ in range(n)]
for i in range(q):
  p,x = map(int,input().split())
  score[p-1] += x
  
def dfs(parent,node,s):
  for n in tree[node]:
    if n == parent:
      continue
    score[n] += score[node]
    dfs(node,n,s)

dfs(-1,0,0)
  
print(*score)
### BUGGY CODE ###

x,y = map(int,raw_input().split())
if y>x:
    tmp = x
    x = y
    y = tmp
i=2
ans = 1
while i<=x:
    if x % i ==0:
        if y % i==0:
            ans = i
    i+=1
print ans

### FIXED CODE ###

x,y = map(int,raw_input().split())
if x==y:
    print x
else:
    if y>x:
        tmp = x
        x = y
        y = tmp
    i=2
    ans = 1
    al = []
    while i*i<=x:
        if x % i ==0:
            if y % i==0:
                al.append(i)
                x = x/i
                y = y/i
                continue
        i+=1
    if len(al)!=0:
        for j in al:
            ans *= j
    print ans
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
n=sum(A)
for _ in range(int(input())):
    B,C=map(int,input().split())
    n=n-A.count(B)*(B-C)
    A=[C if i==B else i for i in A]
    print(n)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
s=sum(A)
num=[0]*100001
for i in A:
    num[i]+=1
for _ in range(int(input())):
    B,C=map(int,input().split())
    s+=(C-B)*num[B]
    num[C]+=num[B]
    num[B]=0
    print(s)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    mod = 10**9 + 7

    n,k = map(int, input().split())
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(n-1):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)

    def dfs(v, par, k):
        if par == -1:
            kk = k-1
        else:
            kk = k-2

        res = 1
        if v == 0:
            res *= k

        for i in range(len(adj[v])):
            nv = adj[v][i]
            if  nv == par:
                continue
            res *= kk * dfs(nv, v, k)
            res %= mod
            kk -= 1
        return res

    res = dfs(0, -1, k)
    print(res)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    mod = 10**9 + 7

    n,k = map(int, input().split())
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(n-1):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)

    def dfs(v, par, k):
        if par == -1:
            kk = k-1
        else:
            kk = k-2

        res = 1
        if v == 0:
            res *= k

        for i in range(len(adj[v])):
            nv = adj[v][i]
            if  nv == par:
                continue
            res *= kk * dfs(nv, v, k)
            res %= mod
            kk -= 1
        return res

    res = dfs(0, -1, k)
    print(res)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

L, R = map(int, input().split())
min = 2019

for i in range(L, R+1):
	if min == 0:
		break
	for j in range(i+1, R+1):
		num = i * j % 2019
		if j > i and num < min:
			min = num

print(min)

### FIXED CODE ###

L, R = map(int, input().split())
min = 2019

if R -L >= 2019:
	min = 0
else:

	for i in range(L, R+1):
		for j in range(i+1, R+1):
			num = i * j % 2019
			if j > i and num < min:
				min = num

print(min)
### BUGGY CODE ###

S = input()
counter = 0
ans_bf = len(S)
while True:
    len_bf = len(S)
    for i in range(0,(len_bf-1)):
        if (S[i] == '0' and S[i+1] == '1') or(S[i] == '1' and S[i+1] == '0') :
            S = S[:i]+S[i+2:]
            break
    if len_bf == len(S):
        break
print(ans_bf - len(S))


### FIXED CODE ###

import collections
S = input()
col_S = collections.Counter(S) 
print(min(col_S['0'],col_S['1'])*2)
### BUGGY CODE ###

# place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = map(int, input().split())
rmult = 0
bmult = 0
total = 0
it = 1
ended = ''
while n > total:
    total += a
    bmult += 1
    ended = 'b'
    if n > total:
        total += b
        rmult += 1
        ended = 'r'
if ended == 'b':
    numofb = a * bmult - (total - n)
else:
    numofb = a * bmult
print(numofb)


### FIXED CODE ###

# place A blue balls first,
# then place B red balls after
# go until you get to N
n, a, b = map(int, input().split())
x = max(n // (a + b) - 2, 1)
while a * x + b * x < n:
    temp = a * x + b * x
    x += 1
temp = a * x + b * x
if temp - b >= n:
    temp = temp - b
    endsWithA = True
else:
    endsWithA = False
if endsWithA:
    print(a * x - (temp - n))
else:
    print(a * x)
### BUGGY CODE ###

import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]
A = []
B = []
for i in range(n):
    a,b = map(int, stdin.readline().rstrip().split())
    A.append(a)
    B.append(b)

now = 0

for i in range(n):
    small = B.index(min(B))
    now += A[small]
    if now > min(B):
        print("No")
        exit()
    else:
        B[small] = INF

print("Yes")


### FIXED CODE ###

import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#w = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(n)]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
now = 0

for i in range(n):
    now += ab[i][0]
    if now > ab[i][1]:
        print("No")
        exit()

print("Yes")
### BUGGY CODE ###

R, G, B, N = map(int, input().split())
counter = 0
R, G, B = sorted([R, G, B])[::-1]

r = 0
while r * R <= N:
  g = 0
  if B == 1:
    counter += (N - r*R)//G + 1
    r += 1
    continue
  while r*R + g*G <= N:
    b = (N - r*R - g*G)/B
    if b == int(b):
      counter += 1
      g += 1
  r += 1
print(counter)

### FIXED CODE ###

R, G, B, N = map(int, input().split())
counter = 0
if R < G:
  R, G = G, R
if G < B:
  G, B = B, G
if R < G:
  R, G = G, R
r = 0
while r * R <= N:
  g = 0
  if B == 1:
    counter += (N - r*R)//G + 1
    r += 1
    continue
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b < 0:
      break
    elif b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)
### BUGGY CODE ###

H, W, D = map(int, input().split())

A = [False] * (H * W + 1)

for i in range(H):
    l = list(map(int, input().split()))
    for j in range(W):
        A[l[j]] = (i, j)

Q = int(input())

for i in range(Q):
    L, R = map(int, input().split())
    cost = 0
    start = False
    while L != R:
        start = A[L]
        stop  = A[L+D]
        cost += abs(start[0] - stop[0]) + abs(start[1] - stop[1])
        start = stop
        L += D
    print(cost, flush=True)


### FIXED CODE ###

# speed-test
# https://abc089.contest.atcoder.jp/submissions/2206669

h,w,d = map(int,input().split())
 
dic = {}
for i in range(h):
    a = input().split()
    for j in range(w):
        dic[int(a[j])] = (i+1,j+1)
        
q = int(input())
c = [0]*(h*w+1)
for i in range(d+1,h*w+1):
    pi,pj = dic[i]; qi,qj = dic[i-d]
    c[i] = c[i-d] + abs(pi-qi) + abs(pj-qj)
    
for i in range(q):
    l,r = map(int,input().split())
    print(c[r]-c[l])
### BUGGY CODE ###

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

ans=3*(10**9)
for i in range(N-1):
  l=(numpy.cumsum(A))[i]
  D=abs(l-(sum(A)-l))
  if ans > D:
    ans=D
  if l >= (sum(A)//2)+1:
    break

print(ans) 

### FIXED CODE ###

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

def getNearestValue(list, num):
  idx = np.abs(np.asarray(list) - num).argmin()
  return list[idx]

a=(np.cumsum(A))
l=getNearestValue(a, sum(A)/2)

ans=abs(sum(A)-2*l)
print(ans)