n = int(input()) vt = [list(map(int,input().split())) for _ in range(n)] vt.sort(key=sum) dp = 1 for v,t in vt: dp |= (dp&(1<