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

import itertools
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)] 
u=[]
for i in range(1,m+1):
  for k in range(n):
    u.append(i)
a=list(itertools.combinations(u,n))
ans=[]

for i in range(len(a)):
  c=0
  for k in range(len(l)):
    if a[i][l[k][1]-1]-a[i][l[k][0]-1]==l[k][2]:
      c+=l[k][3]
  ans.append(c)
print(max(ans))

### FIXED CODE ###

import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

from itertools import combinations_with_replacement as cwr
n,m,q=mp()
l=[lmp() for i in range(q)]
ans=0


for i in cwr(range(1,m+1),n):
    s=0
    for a,b,c,d in l:
        if i[b-1]-i[a-1]==c:
            s+=d
    ans=max(ans,s)
print(ans)
### BUGGY CODE ###

def nCr(n,r):
  dividend = 1
  divisor = 1
  MOD = 10**9+7
  d1 = n
  for i in range(1,r+1):
    dividend *= d1
    divisor *= i
    d1 -= 1
    dividend %= MOD
    divisor %= MOD

  return (dividend * pow(divisor, MOD-2, MOD)) % MOD


N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
mod = 10**9+7

ans = 0
for i in range(K-1, N):
  ans += A[i] * nCr(i, K-1) % mod
  ans %= mod

A = A[::-1]
for i in range(K-1, N):
  ans -= A[i] * nCr(i, K-1) % mod
  ans %= mod

print(ans)

### FIXED CODE ###

class Combination:
  def __init__(self, n_max, mod=10**9+7):
    self.mod = mod
    self.modinv = self.make_modinv_list(n_max)
    self.fac, self.facinv = self.make_factorial_list(n_max)

  def __call__(self, n, r):
    return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

  def make_factorial_list(self, n):
    # 階乗のリストと階乗のmod逆元のリストを返す O(n)
    # self.make_modinv_list()が先に実行されている必要がある
    fac = [1]
    facinv = [1]
    for i in range(1, n+1):
      fac.append(fac[i-1] * i % self.mod)
      facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
    return fac, facinv

  def make_modinv_list(self, n):
    # 0からnまでのmod逆元のリストを返す O(n)
    modinv = [0] * (n+1)
    modinv[1] = 1
    for i in range(2, n+1):
      modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
    return modinv

N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
MOD = 10**9+7

comb = Combination(10**5+1)

ans = 0
for i in range(N-K+1):
  ans -= A[i] * comb(N - i - 1, K - 1) % MOD
  ans %= MOD

A = A[::-1]
for i in range(N-K+1):
  ans += A[i] * comb(N - i - 1, K - 1) % MOD
  ans %= MOD

print(ans % MOD)
### BUGGY CODE ###

n = int(input())
h_l = list(map(int,input().split()))
cnt = 0
for i in range(n):
    h_i = h_l[i]
    cnt += sum([1 for j in range(i,n) if((j-i)==(h_l[j]+h_i))])
            

print(cnt)

### FIXED CODE ###

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

#Ai + i 
#j-Aj
ans = 0
cnt = [0]*(n+1)
for i in range(n-1):
    j=i+1
    a = mp[i]+i
    if(a<=n):
        cnt[a] += 1 
    b = j-mp[j]
    if(b<0):
        continue
    ans += cnt[b]
    

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

def CHK():
    N = int(input())
    A = list(map(int,input().split()))
    L=[]
    cnt = 0
    for i in range(N):
        L.append(i + A[i])
        R = i - A[i]
        cnt += L.count(R)
    print(cnt)

CHK()

### FIXED CODE ###

from collections import Counter

def CHK():
    N = int(input())
    A = list(map(int,input().split()))
    L=[]
    R=[]
    cnt = 0
    for i in range(N):
        L.append(i + A[i])
    L_Cnt=Counter(L)

    for i in range(N):
        chk = i -A[i]
        cnt += L_Cnt[chk]
    print(cnt)

CHK()
### BUGGY CODE ###

n = int(input())
# 文字列内の文字を辞書順ソート
strings = [''.join(sorted(list(input()))) for i in range(n)]
# 重複文字列（＝元の文字列はアナグラムで一致する）と重複度の辞書
dictionaries = [[e, strings.count(e)] for e in set(strings) if strings.count(e) > 1]
sum = 0
for d in dictionaries :
    q = d[1]
    sum += int(q * (q+1) / 2) - q
print(sum)

### FIXED CODE ###

n = int(input())
# 文字列内の文字を辞書順ソートしたリストを辞書順ソート
strings = sorted([''.join(sorted(list(input()))) for i in range(n)])
strings.append('XXXXXXXXXX')

ans = 0
s = 0
for i in range(1,n+1) :
    if strings[i] == strings[i-1] :
        s += 1
    else:
        s += 1
        ans += s * (s - 1)
        s = 0
print(int(ans/2))
### BUGGY CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(N-K+1):
    s = (sum(p[i : i + K]) + K) / 2
    if s > ans:
        ans = s
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
p = [int(x) for x in input().split()]
s = sum(p[0 : K])
ans = sum(p[0 : K])
f = N-K+1
for i in range(1, f):
    s = s - p[i-1] + p[i + K - 1]
    if ans <= s:
        ans = s
print((ans + K) / 2)
### BUGGY CODE ###

H,W,D = map(int,input().split())
grid = [[0]*W for _ in range(H)]
for h in range(H):
    grid[h] = list(map(int, input().split()))
number_yx = [[0,0] for _ in range(H*W+1)]
for y in range(H):
    for x in range(W):
        number_yx[grid[y][x]] = [y,x]
fromto_cost = [[0]*(1+H*W) for _ in range(1+H*W)]
for mod_group in range(D):
    # 剰余ごとにスタートを決定
    start = mod_group+1
    previous = start
    fromto_cost[start][start] = 0
    previous_y, previous_x = number_yx[previous]
    cost = 0
    while previous+D <= (H*W):
        Next = previous+D 
        Next_y, Next_x = number_yx[Next]
        cost += abs(Next_y-previous_y) + abs(Next_x-previous_x)
        fromto_cost[start][Next] = cost

        previous = Next
        previous_y,previous_x = Next_y,Next_x

Q = int(input())
ans_ls = [0] * Q
for i in range(Q):
    start, goal = map(int,input().split())
    mod = start % D
    base = mod
    if base == 0:
        base = D 
    base_to_goal = fromto_cost[base][goal]
    base_to_start = fromto_cost[base][start]
    ans_ls[i] = base_to_goal - base_to_start
for ans in ans_ls:
    print(ans)



### FIXED CODE ###

from collections import defaultdict
H,W,D = map(int,input().split())
grid = [[0]*W for _ in range(H)]
for h in range(H):
    grid[h] = list(map(int, input().split()))
number_yx = [[0,0] for _ in range(H*W+1)]
for y in range(H):
    for x in range(W):
        number_yx[grid[y][x]] = [y,x]
fromto_cost = defaultdict(lambda: defaultdict(int))
for mod_group in range(D):
    # 剰余ごとにスタートを決定
    start = mod_group+1
    previous = start
    fromto_cost[start][start] = 0
    previous_y, previous_x = number_yx[previous]
    cost = 0
    while previous+D <= (H*W):
        Next = previous+D 
        Next_y, Next_x = number_yx[Next]
        cost += abs(Next_y-previous_y) + abs(Next_x-previous_x)
        fromto_cost[start][Next] = cost

        previous = Next
        previous_y,previous_x = Next_y,Next_x

Q = int(input())
ans_ls = [0] * Q
for i in range(Q):
    start, goal = map(int,input().split())
    mod = start % D
    base = mod
    if base == 0:
        base = D 
    base_to_goal = fromto_cost[base][goal]
    base_to_start = fromto_cost[base][start]
    ans_ls[i] = base_to_goal - base_to_start
for ans in ans_ls:
    print(ans)
### BUGGY CODE ###

#ABC116D-VariousSushi.py

INPUT1 = [int(n) for n in input().split()]

N, K = INPUT1[0], INPUT1[1]
Parameters = []
Score, Test = 0, 0
flag1, flag2 = 0, 0
t, d = [], []


for i in range(N):
    INPUT2 = [int(m) for m in input().split()]
    Parameters.append((INPUT2[0], INPUT2[1]))


Parameters = sorted(Parameters, key=lambda x: x[1], reverse=True)

def SumScore(List, K):
    taste = 0
    kind = []
    for i in range(K):
        taste += List[i][1]
        kind.append(List[i][0])
    return taste + len(set(kind))**2

def SearchNew(List, K):
    kind = []
    newkind = -1
    for i in range(K):
        kind.append(List[i][0])
    kindset = set(kind)
    for i in range(len(List)-K):
        if List[K+i][0] not in kindset:
            newkind = K+i
            break
    return newkind

def SearchDouble(List, K):
    result = -1
    leftkind = []
    for j in range(K):
        leftkind.append(List[j][0])
    for i in range(K):
        testkind = List[K-1-i][0]
        leftkind.pop(K-1-i)
        if testkind in leftkind:
            result = K-1-i
            break
    return result

Score = SumScore(Parameters, K)

for t in Parameters:
    i = SearchNew(Parameters, K)
    j = SearchDouble(Parameters, K)
    Parameters[i], Parameters[j] = Parameters[j], Parameters[i]
    Test = SumScore(Parameters, K)
    if Score <= Test:
        Score = Test

print(Score)


### FIXED CODE ###

#ABC116D-VariousSushi.py

from sys import stdin
#from numpy import sum

input = stdin.readline

N, K = list(map(int, input().split()))
List1= []
kind = set()
point1, point2 = 0, 0

INPUT = [tuple(map(int, input().split())) for _ in range(N)]

INPUT.sort(key = lambda x: -x[1])

for ti, di in INPUT[:K]:
    point1 += di
    if ti in kind:
        List1.append(di)
    kind.add(ti)

point2 = len(kind)

Score = point1 + point2**2
Test = Score

List1POP = List1.pop

for ti, di in INPUT[K:]:
    if 0 >= len(List1):
        break
    if ti in kind:
        continue
    Test = Test - List1POP() + di + 2 * point2 + 1
    point2 += 1
    kind.add(ti)
    Score = max(Score, Test)

print(Score)
### BUGGY CODE ###

def main():
  _max = max
  s = input()
  t = input()
  slen = len(s)
  tlen = len(t)
  dp = [[0 for j in range(tlen + 1)] for i in range(slen + 1)]
  for i in range(slen):
    dpi = dp[i]
    dpi1 = dp[i + 1]
    si = s[i]
    for j in range(tlen):
      j1 = j + 1
      if si == t[j]:
        dpi1[j1] = _max(dpi[j] + 1, dpi1[j], dpi[j1])
      else:
        dpi1[j1] = _max(            dpi1[j], dpi[j1])
  result = ''
  i = slen
  j = tlen
  while i > 0 and j > 0:
    if dp[i - 1][j] == dp[i][j]:
      i -= 1
    elif dp[i][j - 1] == dp[i][j]:
      j -= 1
    else:
      result = s[i - 1] + result
      i -= 1
      j -= 1
  print(result)
main()

### FIXED CODE ###

s = input()
t = input()
slen = len(s)
tlen = len(t)
dp = [[0 for j in range(tlen + 1)] for i in range(slen + 1)]
for i in range(slen):
  for j in range(tlen):
    if s[i] == t[j]:
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])
result = ''
i = slen
j = tlen
while i > 0 and j > 0:
  if dp[i - 1][j] == dp[i][j]:
    i -= 1
  elif dp[i][j - 1] == dp[i][j]:
    j -= 1
  else:
    result = s[i - 1] + result
    i -= 1
    j -= 1
print(result)
### BUGGY CODE ###

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

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

res = [0]
tmp = 0

tf = [False for i in range(n)]
tf[0] = True

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp]:
        start = tmp
        break
    else:
        res = res + [tmp]
        tf[tmp] = True

lenret = len(res)
stridx = res.index(start)

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)


### FIXED CODE ###

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

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

res = [0]
tmp = 0

tf = [-1 for i in range(n)]
tf[0] = 0

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp] != -1:
        start = tmp
        break
    else:
        res.append(tmp)
        tf[tmp] = i+1

lenret = i+1
stridx = tf[start]

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)
### BUGGY CODE ###

from fractions import gcd
import sys

input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7


def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0


def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception("modular inverse does not exist")
    else:
        return x % m


n = int(input())
if n == 1:
    print(1)
    exit()
A = list(map(int, input().split()))
lcm = A[0]
for i in range(n):
    g = gcd(lcm, A[i])
    lcm = lcm * A[i] // g
ans = 0
for i in range(n):
    gyaku = modinv(A[i],mod)
    ans += lcm * gyaku
    ans %= mod
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
from fractions import gcd
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def gyaku(a):
    return pow(a,mod-2,mod)
if n==1:
    print(1)
else:
    gya=[0]*(n)
    g=A[0]
    l=A[0]
    gya[0]=gyaku(A[0])
    for i in range(n-1):
        g=gcd(l,A[i+1])
        l*=(A[i+1]//g)
        gya[i+1]=gyaku(A[i+1])
    ans=0
    for i in range(n):
        ans+=l*gya[i]
        ans%=mod
    print(ans)
### BUGGY CODE ###

import numpy as np

N, Q = map(int,input().split())
S = input()

atgc_list= []

flag = 0
for i in range (len(S)):
    if S[i]=='A':
        flag = 1
    if flag == 1 and S[i] == 'C':
        atgc_list.append(i)
    if S[i] in ['T','G']:
        flag = 0
        
atgc_list_np = np.array(atgc_list)

for j in range (Q):
    l, r = map(int,input().split())
    low = np.sum(l>(atgc_list_np))
    high = np.sum(r>(atgc_list_np))
    print(high - low)




### FIXED CODE ###

N, Q = map(int,input().split())
S = input()

atgc_list= []

flag = 0
memo =0

for i in range (len(S)):
    if S[i]=='A':
        flag = 1
    elif flag == 1 and S[i] == 'C':
        memo+=1
        flag = 0
    elif S[i] in ['T','G','C']:
        flag = 0
    atgc_list.append(memo)
        

for j in range (Q):
    l, r = map(int,input().split())
    low = atgc_list[l-1]
    high = atgc_list[r-1]
    print(high - low)
### BUGGY CODE ###

def mv(nodes,mvinfo):
    dists=set()
    for node in nodes:
        dists=dists | set(mvinfo[node-1])
    return list(dists)


N,M=[int(e) for e in input().split(' ')]

# 1step
mv1=[[] for n in range(N)]

for i in range(M):
    u,v=[int(e) for e in input().split(' ')]
    mv1[u-1].append(v)
S,T=[int(e) for e in input().split(' ')]

# 1step to 3steps
mv3=[]
for i in range(N):
    mv3.append(mv(mv(mv1[i],mv1),mv1))

# search
for i in range(1,1+N):
    if i==1:
        dists=mv3[S-1]
    else:
        dists=mv(dists,mv3)
    
    if T in dists:
        break
else:
    i=-1
print(i)



### FIXED CODE ###

#import queue
from collections import deque
INF=-1

N,M=[int(e) for e in input().split(' ')]

to=[[] for _ in range(N)]

for i in range(M):
    u,v=[int(e) for e in input().split(' ')]
    to[u-1].append(v-1)
S,T=[int(e)-1 for e in input().split(' ')]

dist=[[INF for i in range(3)] for j in range(N)]

q=deque([])
q.append([S,0])

dist[S][0]=0

while(q):
    v,l=q.popleft()
    for v_to in to[v]:
        nl=(l+1)%3
        if dist[v_to][nl] != INF:
            continue
        dist[v_to][nl]=dist[v][l]+1
        q.append([v_to,nl])
ans=dist[T][0]
if ans == INF:
    ans = -1
else:
    ans=ans//3

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

N, P = map(int, input().split())
ans = 1
def main(n, p):
  global ans
  for i in range(2, int(p**(2/n))):
    t = i**n
    if p % t == 0:
      ans *= i
      return main(n, p//t)
  return ans

print(main(N, P))


### FIXED CODE ###

N, P = map(int, input().split())
ans = 1
def main(n, p):
  if n == 1:
    return P
  global ans
  for i in range(2, int(p**(2/n))):
    t = i**n
    if p % t == 0:
      ans *= i
      return main(n, p//t)
  return ans

print(main(N, P))
### BUGGY CODE ###

# 未完成
import numpy as np
N = int(input())
x = np.zeros(N)
y = np.zeros(N)

for i in range(N):
    x[i], y[i] = map(int, input().split())
ans = 0
for m in range(N):
    for p in range(N):
        if m == p:
            continue
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = 0
        for r in range(N):
            for q in range(N):
                if r == q:
                    continue
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans_kari += 1
        if ans_kari > ans:
            ans = ans_kari

print("{}".format(int(N-ans)))


### FIXED CODE ###

# 未完成

import sys
N = int(input())
x = [0]*N
y = [0]*N
kouholist = []
ans = N
if N == 1:
    print(1)
    sys.exit()

for i in range(N):
    x[i], y[i] = map(int, input().split())
for m in range(N):
    for p in range(N):
        if m == p:
            continue
        diff_x = x[m] - x[p]
        diff_y = y[m] - y[p]
        ans_kari = N
        for r in range(N):
            for q in range(N):
                if x[q] - x[r] == diff_x and y[q] - y[r] == diff_y:
                    ans_kari -= 1
        if ans_kari < ans:
            ans = ans_kari

print("{}".format(ans))
### BUGGY CODE ###

N=input()
ls=[int(s) for s in input().split()]
ans=1
flag=1
for e in ls:
  ans*=e
if ans>10**18:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

N=input()
ls=[int(s) for s in input().split()]
ans=1
flag=1
for e in ls:
  ans*=e
  if ans>10**18:
    flag=0
    break
zeroflag=1
for e in ls:
  if e==0:
    zeroflag=0
if flag==1:
  print(ans)
else:
  print(-1*zeroflag)
### BUGGY CODE ###

import math

def isprime(n):
    if(n<2):
        return False
    for i in range(2,int(n**0.5)+1):
        if(n%i==0):
            return False
    return True

def primelist(n):
    return [i for i in range(n) if isprime(i)]

def factor(n):
    f = {}
    for p in primelist(int(n**0.5)+1):
        while(n % p == 0):
            f[p] = f.get(p, 0) + 1
            n //= p
    if(n != 1):
        f[n] = 1
    return f

# mの各素因数を振り分ける
# 各素因数p(^a)について，nつに振り分ける
# (n+a)! / (n!a!)
n,m=map(int, input().split())
f = factor(m)
ans = 1
for k,v in f.items():
    ans *= (math.factorial(n-1+v)//(math.factorial(n-1)*math.factorial(v)))
    ans %= (int(1e9+7))

print(ans)


### FIXED CODE ###

import math

def factorize(n):
    ret={}
    i = 2
    while n >= i**2:
        cnt = 0
        while n % i == 0:
            n //= i
            cnt += 1
        if cnt != 0:
            ret[i] = cnt
        i += 1
    if n != 1:
        ret[n] = 1
    return ret

def combination(n,r):
    ret = 1
    r = min(r, n-r)
    for i in range(n-r+1, n+1):
        ret *= i
    for i in range(1, r+1):
        ret //= i
    return ret


# mの各素因数を振り分ける
# 各素因数p(^a)について，nつに振り分ける
# n-1+a C n-1 
n,m=map(int, input().split())
f = factorize(m)
ans = 1
for k,v in f.items():
    ans *= combination(n-1+v, v)
    ans %= (int(1e9+7))
print(ans)
### BUGGY CODE ###

S = input()
Q = int(input())
F=0
l=""
r=""
for i in range(Q):
  q=list(map(str,input().split()))
  if q[0]=="1":
    F+=1
  else:
    if q[1]=="1":
      if F%2==0:
        l += q[2]
      else:
        r += q[2]
    else:
      if F%2==0:
        r += q[2]
      else:
        l += q[2]  
if F%2==0:
  print(l[::-1]+S+r)
else:
  print(r[::-1]+S[::-1]+l)

### FIXED CODE ###

from collections import deque
S = input()
Q = int(input())
F=0
d=deque(S)
for i in range(Q):
  q=list(map(str,input().split()))
  if q[0]=="1":
    F+=1
    F%=2
  else:
    if q[1]=="1":
      if F==0:
        d.appendleft(q[2])
      else:
        d.append(q[2])
    else:
      if F==0:
        d.append(q[2])
      else:
        d.appendleft(q[2])  
d=list(d)
if F%2==0:
  print("".join(d))
else:
  print("".join(d[::-1]))
### BUGGY CODE ###

def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    count = [0 for _ in range(10**5)]
    for i in range(n):
        count[a[i] - 1] += 1

    q = int(input())
    for _ in range(q):
        b, c = list(map(int, input().split()))
        count[c - 1] += count[b - 1]
        count[b - 1] = 0
        total = 0
        for i in range(10**5):
            if count[i] == 0:
                continue
            total += count[i] * (i + 1)
        print(total)


if 'unittest' not in globals():
    resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    total = 0
    count = [0 for _ in range(10**5)]
    for i in range(n):
        count[a[i] - 1] += 1
        total += a[i]

    q = int(input())
    for _ in range(q):
        b, c = list(map(int, input().split()))
        count_b = count[b - 1]
        count[b - 1] = 0
        count[c - 1] += count_b

        total -= count_b * (b - c)
        print(total)


if 'unittest' not in globals():
    resolve()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
answer=1
for i in range(n):
    answer*=a[i]
    if answer>10**18:
        answer=-1
if a.count(0)>0:
    answer=0
print(answer)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
answer=1
for i in range(n):
    answer*=a[i]
    if answer>10**18:
        answer=-1
        break
if a.count(0)>0:
    answer=0
print(answer)
### BUGGY CODE ###

#りゅうせいの解答3
N = int(input())
task_list = [list(map(int, input().split())) for i in range(N)]

task_list.sort(key=lambda task_list: task_list[1])
time = 0
flag = True

for j in range(N):
    x = task_list.pop(0)
    time += x[0]
    if time > x[1]:
        flag = False
        break

if flag:
    print("Yes")

else:
    print("No")




#りゅうせいの解答2 正解
# N = int(input())
# task_list = [list(map(int, input().split())) for i in range(N)]
#
# task_list.sort(key=lambda task_list: task_list[1])
# time = 0
# flag = True
#
# for i in range(N):
#     x = task_list[i]
#     time += x[0]
#     if time > x[1]:
#         flag = False
#         break
#
# if flag:
#     print("Yes")
#
# else:
#     print("No")




#りゅうせいの解答1　実行時エラー(exit(1)が原因）、実行時間超過
# N = int(input())
# task_list = [list(map(int,input().split())) for i in range(N)]
#
# task_list.sort(key= lambda task_list: task_list[1])
# time = 0
#
# while(len(task_list)):
#     x = task_list.pop(0)
#     time += x[0]
#     if time > x[1]:
#         print("No")
#         exit(1)
#
#     else:
#         continue
#
# print("Yes")

### FIXED CODE ###

N = int(input())
task_list = [list(map(int, input().split())) for i in range(N)]

task_list.sort(key=lambda task_list: task_list[1])
time = 0
flag = True

for i in range(N):
    x = task_list[i]
    time += x[0]
    if time > x[1]:
        flag = False
        break

if flag:
    print("Yes")

else:
    print("No")




#りゅうせいの解答1　実行時エラー、実行時間超過
# N = int(input())
# task_list = [list(map(int,input().split())) for i in range(N)]
#
# task_list.sort(key= lambda task_list: task_list[1])
# time = 0
#
# while(len(task_list)):
#     x = task_list.pop(0)
#     time += x[0]
#     if time > x[1]:
#         print("No")
#         exit(1)
#
#     else:
#         continue
#
# print("Yes")
### BUGGY CODE ###

N=int(input())

def func(x,y,n=N):
    R=0
    for i in range(1,n+1):
        Len=len(str(i))
        up=int(str(i)[0])
        down=int(str(i)[Len-1])
        if up==x and down==y:
            R+=1
    return R

ans=0

for j in range(10):
    for k in range(10):
        ans+=func(j,k)*func(k,j)

print(ans)

### FIXED CODE ###

import copy

N=int(input())

def arrange(List,n=N):  #先頭がup末尾がdownの総数をList[up][down]に入れる;Listは10×10で0が入ってる
    for i in range(1,n+1):
        Len=len(str(i))
        up=int(str(i)[0])
        down=int(str(i)[Len-1])
        List[up][down]+=1
    return List

original=[]
component=[]
for x in range(10):
    component.append(0)
for y in range(10):
    original.append(copy.deepcopy(component))


L=arrange(original)

ans=0

for j in range(10):
    for k in range(10):
        ans+=L[j][k]*L[k][j]

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

N = int(input())
word = []
count = 0
for i in range (0,N):
    word.append(sorted(input()))
    for j in range (0, i):
        if word[j] == word[i]:
            count = count + 1
            
print(count)



### FIXED CODE ###

n = int(input())
d = {}
ans = 0


for i in range (0,n):
    temp = 0
    linp =  sorted(input())
    inp = ''.join(linp)
    if inp in d:
        ans = ans + d[inp]
        d[inp] = d[inp] + 1
    else:
        d[inp] = 1
print(ans)