Harryxun/stf_run huggingface dataset:
import sys

n, q = map(int, sys.stdin.readline().split())

near = [[] for _ in range(n+1)]
solved = [0] * n+1

child = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    near[a].append(b)
    near[b].append(a)

wait = [1]

while True:
    target = wait.pop()
    for nex in near[target]:
        if solved[nex] != 1:
            child[target].append(nex)
            wait.append(nex)
            solved[nex] = 1
        if len(wait) == 0:
            break

score = [0] * (n+1)
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    score[p] += x

wait = [1]

while True:
    target = wait.pop()
    for nex in child[target]:
        score[nex] += score[target]
        wait.append(nex)
    if len(wait) == 0:
        break

score.pop(0)

print(' '.join(map(str, score)))


### FIXED CODE ###

import sys

n, q = map(int, sys.stdin.readline().split())

child = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    child[a].append(b)

score = [0] * (n+1)
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    score[p] += x

wait = [1]

while True:
    target = wait.pop()
    for nex in child[target]:
        score[nex] += score[target]
        wait.append(nex)
    if len(wait) == 0:
        break

score.pop(0)

print(' '.join(map(str, score)))
# -*- coding: utf-8 -*-

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

ans = n - sum(a)

if ans < 0:
    return -1
else:
    return ans


### FIXED CODE ###

# -*- coding: utf-8 -*-

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

ans = n - sum(a)

if ans < 0:
    print(-1)
else:
    print(ans)
a=input()
b=input()
s,t,u=a+b,a-b,a*b
if s>t and s>u:
  print(s)
elif t>s and t>u:
  print(t)
else:
  print(u)


### FIXED CODE ###

a,b = map(int, input().split())
s,t,u=a+b,a-b,a*b
if s>=t and s>=u:
  print(s)
elif t>=s and t>=u:
  print(t)
else:
  print(u)
s = input().split()
print(int((s[0])+int(s[1]))/2)

### FIXED CODE ###

s = input().split()
N = int(s[0])
W = int(s[1])/2
print(int(N+W))
import math
N, M = map(int, input().split())
S = input()
T = input()
g = math.gcd(N, M)
flag = True
n = N / g
m = M / g
for k in range(g):
  flag *= (S[n*m*k] == T[n*m*k])
if flag == 0:
  out = -1
else:
  out = n * m * g
print(out)

### FIXED CODE ###

import fractions
N, M = map(int, input().split())
S = input()
T = input()
g = fractions.gcd(N, M)
n = N // g
m = M // g
out = n * m * g
for k in range(g):
  if S[k * n] != T[k * m]:
    out = -1
    break
print(out)
n = list(map(int, input().split()))

ans = set(n)
print(ans.count)


### FIXED CODE ###

n = list(int(x) for x in input().split(' '))

ans = set(n)
print(len(ans))
from math import sqrt


def dis(i, j):
    ret = float((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2)
    return sqrt(ret)


n = int(input())
xy = [list(map(float, input().split())) for i in range(n)]

p = list(permutations(range(n)))

sums = 0
for i in p:
    for j in range(len(i) - 1):
        sums += dis(xy[i[j]], xy[i[j + 1]])

print(sums / len(p))

### FIXED CODE ###

from itertools import permutations
from math import sqrt


def dis(i, j):
    ret = float((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2)
    return sqrt(ret)


n = int(input())
xy = [list(map(float, input().split())) for i in range(n)]

p = list(permutations(list(range(n))))
sums = 0

for i in p:
    for j in range(len(i) - 1):
        sums += dis(xy[i[j]], xy[i[j + 1]])

print(sums / len(p))
n, k = map(int, input().split())
A = list(map(int, input().split()))
L = [1]
def f(L):
    if A[L[-1]-1] not in L:
        L.append(A[L[-1]-1])
        return f(L)
    else:
        return L
P = f(L)
a = A[P[-1]-1]
j = P.index(a)
r = len(P)
l = r - j
print(P)
if k < j:
    print(P[k])
else:
    print(P[j+(k-j)%l])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n, k = map(int, input().split())
A = list(map(int, input().split()))
L = [1]
S = {1}

def f(L, S):
    last = L[-1]-1
    if A[last] not in S:
        L.append(A[last])
        S |= {A[last]}
        return f(L, S)
    else:
        return L
P = f(L, S)
a = A[P[-1]-1]
j = P.index(a)
r = len(P)
l = r - j

if k+1 <= j:
    print(P[k])
else:
    print(P[j+(k-j)%l])
n,v=[int(k) for k in input().split()]
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
mod=10**9+7  
dp=[[0 for i in range(v+1)] for j in range(n+1)]
for a in range(1,n+1):
  for b in range(1,v+1):
    if(li[a-1][0]<=b):
      dp[a][b]=max((li[a-1][1]+dp[a-1][b-li[a-1][0]]),dp[a-1][b])
    else:
      dp[a][b]=dp[a-1][b]
print(dp[n][v]%mod)      
      
  


### FIXED CODE ###

n,v=[int(k) for k in input().split()]
li=[]
for i in range(n):
  li.append([int(k) for k in input().split()])
  
dp=[[0 for i in range(v+1)] for j in range(n+1)]
for a in range(1,n+1):
  for b in range(1,v+1):
    if(li[a-1][0]<=b):
      dp[a][b]=max(li[a-1][1]+dp[a-1][b-li[a-1][0]],dp[a-1][b])
    else:
      dp[a][b]=dp[a-1][b]
print(dp[n][v])
import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
from random import randint
##import numpy as np
##sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():            
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
##def gcd(a,b): 
##    if a == 0: 
##        return b 
##    return gcd(b % a, a)
prime1=[]
def SieveOfEratosthenes(n): #list of primes upto n
    global prime1
    prime1 = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime1[p] == True): 
            for i in range(p * p, n+1, p): 
                prime1[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime1[p]: 
            f.append(p)
    return f

def lcm(a,b): 
    return (a*b) // math.gcd(a,b) 
for _ in range(1):
    n=inin()
    l=ain()
    f1,f2=0,0
    d=dd(int)
    lp=SieveOfEratosthenes(int(math.sqrt(max(l)+1))+1)
    for i in l:
        for j in lp:
            if(i%j==0):
                if(d[j]==1):
                    f1=1
                d[j]+=1
    if(max(list(d.values()))==n):f2=1
    if(f2):print("not coprime")
    else:
        if(f1):
            print("setwise coprime")
        else:
            print("pairwise coprime")
        
        
    
    
    

 
    
    
    
    
        
        
    
    
    
    


    




##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):             
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24 
##def kadane(a,size): 
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##       
##    for i in range(0, size): 
##        max_ending_here = max_ending_here + a[i] 
##        if (max_so_far < max_ending_here): 
##            max_so_far = max_ending_here 
##  
##        if max_ending_here < 0: 
##            max_ending_here = 0   
##    return max_so_far
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo 
##    else:
##        if(y > 0):return (x * temp * temp)%mo 
##        else:return ((temp * temp)//x )%mo


### FIXED CODE ###

import math
N=int(input())
m=10**6+1
M=[0]*m
g=0
for i in map(int,input().split()):M[i]+=1;g=math.gcd(g,i)
if g>1:print('not coprime')
elif all(sum(M[i::i])<=1 for i in range(2,m)):print('pairwise coprime')
else:print('setwise coprime')
s = raw_input()
if set(s) <= 2 and (s[0] != s[1] or s[2] != s[3]):
    print 'Yes'
else:
    print 'No'

### FIXED CODE ###

from itertools import groupby
if [len(list(e)) for k, e in groupby(raw_input()) if len(list(e)) >= 3]:
    print 'Yes'
else:
    print 'No'
n,k=map(int,input().split())
list_a=[]
for d in range(k):
  d=int(input())
  a=list(map(int,input().split()))
  list_a.extend(a)
ans=0
for i in range(1,n): 
 if list_a.count(i)==0:
      ans+=1
print(ans)
       

### FIXED CODE ###

n=str(input())
if n=="ABC":
  print("ARC")
else:
  print("ABC")
from time import time
from random import randrange

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

for i in range(n):
    if A[i] != B[i]:
        continue
    while time() - start < 1.8:
        j = randrange(n)
        if A[i] != B[j] and A[j] != B[i]:
            B[i], B[j] = B[j], B[i]
            break
    else:
        print("No")
        return

print("Yes")
print(*B)

### FIXED CODE ###

import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
from random import randrange
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    if Counter(A + B).most_common()[0][1] > n:
        print("No")
        return

    for i in range(n):
        if A[i] != B[i]:
            continue
        while 1:
            j = randrange(0, n)
            if A[i] != B[j] and A[j] != B[i]:
                B[i], B[j] = B[j], B[i]
                break
    print("Yes")
    print(*B)
resolve()
a = int(raw_input())
b = int(raw_input())

if a<=8 and b<=8:
    print "Yay!"
else:
    print ":("


### FIXED CODE ###

a, b = map(int, raw_input().split())

if a<=8 and b<=8:
    print "Yay!"
else:
    print ":("
def rec(v):
    if dp[v] != -1: return dp[v]
    res = 0
    for nv in es[v]:
        res = max(res, rec(nv) + 1)
    dp[v] = res
    return res


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

for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    es[x].append(y)

dp = [-1] * N

res = 0
for v in range(N):
    res = max(res, rec(v))
print(res)


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 9)


def rec(v):
    if dp[v] != -1:
        return dp[v]

    res = 0
    for nv in g[v]:
        res = max(res, rec(nv) + 1)
    dp[v] = res
    return res


N, M = map(int, input().split())
g = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1 for _ in range(N)]

ans = 0
for t in range(N):
    ans = max(ans, rec(t))
print(ans)
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
if a%10==0:
    a_q=a
else:
    a_q=(a//10+1)*10
if b%10==0:
    b_q=b
else:
    b_q=(b//10+1)*10
if c%10==0:
    c_q=c
else:
    c_q=(c//10+1)*10
if d%10==0:
    d_q=d
else:
    d_q=(d//10+1)*10
if e%10==0:
    e_q=e
else:
    e_q=(e//10+1)*10

r=[i for i in [a%10,b%10,c%10,d%10,e%10]  if i%10!=0]
r_min=min(r)

ans=a_q+b_q+c_q+d_q+e_q-10+r_min
print(ans)

### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
if a%10==0:
    a_q=a
else:
    a_q=(a//10+1)*10
if b%10==0:
    b_q=b
else:
    b_q=(b//10+1)*10
if c%10==0:
    c_q=c
else:
    c_q=(c//10+1)*10
if d%10==0:
    d_q=d
else:
    d_q=(d//10+1)*10
if e%10==0:
    e_q=e
else:
    e_q=(e//10+1)*10

r=[i for i in [a%10,b%10,c%10,d%10,e%10]  if i%10!=0]
if r==[]:
    r_min=10
else:
    r_min=min(r)

ans=a_q+b_q+c_q+d_q+e_q-10+r_min
print(ans)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
d = 0

if sum(a) < sum(b):
    res = -1
else:
    c = [a[i] - b[i] for i in range(n)]
    c1 = [i if i > 0 else 0 for i in c]
    c2 = sum([i if i < 0 else 0 for i in c])
    c3 = sum([1 if i < 0 else 0 for i in c])
    if c2 < 0:
      	c4 = sorted(c1, reverse=True)
        for i in range(n):
            d = d + c4[i]
            if d + c2 > 0:
                res = c3 + i
                break

print(res)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
d = 0

if sum(a) < sum(b):
    res = -1
else:
    c = [a[i] - b[i] for i in range(n)]
    c1 = [i if i > 0 else 0 for i in c]
    c2 = sum([i if i < 0 else 0 for i in c])
    c3 = sum([1 if i < 0 else 0 for i in c])
    if c2 < 0:
        c4 = sorted(c1, reverse=True)
        for i in range(n):
            d = d + c4[i]
            if d + c2 > 0:
                res = c3 + i + 1
                break

print(res)
imort math
x1,y1,x2,y2=map(float,input().split())
d=math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
print(d)

### FIXED CODE ###

import math
x1,y1,x2,y2=map(float,input().split())
d=math.sqrt(pow(x1-x2,2)+pow(y1-y2,2))
print(d)
import math

a, b = map(int, input().split())  # 複数数値入力

A = list()
B = list()

for i in range(1, int(math.log2(b))+2):
    tmp = b // (2 ** i) * 2 ** (i - 1)

    if b % (2 ** i) < (2 ** (i-1)):
        plus = 0
    else:
        plus = b % (2 ** i) - 2 ** (i-1) + 1

    B.append(tmp+plus)
if a == 1 or a == 0:
    A = [0]
else:
    for i in range(1, int(math.log2(a-1))+2):
        tmp = (a-1) // (2 ** i) * 2 ** (i - 1)

        if (a-1) % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = (a-1) % (2 ** i) - 2 ** (i-1) + 1

        A.append(tmp + plus)

ans = 0
for i in range(0, int(math.log2(b)) + 1):
    if i >= len(A):
        ans += (B[i]) % 2 * 10 ** i
    else:
        ans += (B[i] - A[i]) % 2 * 10 ** i

print(int(str(ans), 2))


### FIXED CODE ###

import math

a, b = map(int, input().split())  # 複数数値入力

A = list()
B = list()

if b == 0:
    B = [0]
elif b == 1:
    B = [1]
else:
    for i in range(1, int(math.log2(b))+2):
        tmp = b // (2 ** i) * 2 ** (i - 1)

        if b % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = b % (2 ** i) - 2 ** (i-1) + 1

        B.append(tmp + plus)

if a == 0:
    A = [0]
elif a == 1:
    A = [0]
else:
    for i in range(1, int(math.log2(a-1))+2):
        tmp = (a-1) // (2 ** i) * 2 ** (i - 1)

        if (a-1) % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = (a-1) % (2 ** i) - 2 ** (i-1) + 1

        A.append(tmp + plus)

if b == 0:
    print(0)
else:
    ans = 0
    for i in range(0, int(math.log2(b)) + 1):
        if i >= len(A):
            ans += (B[i]) % 2 * 10 ** i
        else:
            ans += (B[i] - A[i]) % 2 * 10 ** i

    print(int(str(ans), 2))
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    string S,T;
    cin>>S>>T;
    int N = S.length();
    int M = T.length();
    vector<vector<int>> dp(N+1, vector<int>(M+1,0));
    vector<vector<pair<int,int>>> prev(N+1, vector<pair<int,int>>(M+1, pair(-1,-1)));
    for(int i = 1;i < N+1;i++){
        for(int j = 1;j < M+1;j++){
            if(S[i-1] != T[j-1] || dp[i][j-1] != dp[i-1][j-1] || dp[i-1][j] != dp[i-1][j-1]){
                if(dp[i][j-1] > dp[i-1][j]){
                    dp[i][j] = dp[i][j-1];
                    prev[i][j] = pair(i,j-1);
                }else{
                    dp[i][j] = dp[i-1][j];
                    prev[i][j] = pair(i-1,j);
                }
            }else{
                dp[i][j] = dp[i-1][j-1]+1;
                prev[i][j] = pair(-2,-2);
            }
        }
    }

    pair<int,int> to = pair(N,M);
    string res = "";
    while(to != pair(-1,-1)){
        pair<int,int> p = prev[to.first][to.second];
        if(p == pair(-2,-2)){
            res += S[to.first-1];
            to = pair(to.first-1, to.second-1);
        }else{
            to = p;
        }
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
}

### FIXED CODE ###

import sys
sys.setrecursionlimit(3003)
def main():
    s = " "+input()
    N = len(s)-1

    t = " "+input()
    M = len(t)-1
    if N < M:
        N, M = M, N
        s, t = t, s
    # dp[i][j] := sのi文字目, tのj文字目までを使ったLCSの長さ
    dp = [[-1]*(M+1) for i in range(N+1)]
    dp[0] = [0]*(N+1)
    for i in range(N+1):
        dp[i][0] = 0
    for i in range(1, N+1):
        for j in range(1, M+1):
            
            if s[i] == t[j]:
                dp[i][j] = dp[i-1][j-1]+1
            elif s[i] != t[j]:
                if dp[i-1][j] > dp[i][j-1]:
                    dp[i][j] = dp[i-1][j]
                else:
                    dp[i][j] = dp[i][j-1]
    print(get(s, t, N, M, dp))

def get(s, t, i, j, dp):
    if i == 0 or j == 0:
        return ""

    if s[i]==t[j]:
        return get(s, t, i-1, j-1, dp) + s[i]
    elif s[i] != t[j]:
        if dp[i-1][j] > dp[i][j-1]:
            return get(s, t, i-1, j, dp)
        else:
            return get(s, t, i, j-1, dp)


if __name__ == "__main__":
    main()
N, L = map(int, input().split())
S = []
for l in range(L):
    S.append(str(input()))
S.sort()

sum_ = ''
for s in S:
    sum_ += s

print(sum_)

### FIXED CODE ###

N, L = map(int, input().split())
S = []
for _ in range(N):
    S.append(str(input()))
S.sort()

sum_ = ''
for s in S:
    sum_ += s

print(sum_)
n=int(input())
a=list(map(int,input().split())
mul=1
flag=0
for i in range(len(a)):
       mul=mul*a[i]
       if mul>10**18:
       		flag=1
			break
if flag==1:
	print(-1)
    continue
print(mul)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
mul=1
if a.count(0)>=1:
    print(0)
if a.count(0)==0:
    for i in range(len(a)):
        mul=mul*a[i]
        if mul>10**18:
            break
    
    if mul>10**18:
        print(-1)
    if mul<=10**18:
        print(mul)
K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

a = [A[i]-A[i-1] for i in range(1,N)]

b = A[0]+(K-A[N-1])

c = max(a,b)

print(K-c)


### FIXED CODE ###

k,n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
c = a[0] + (k - a[n-1])
for i in range(1,n):
  c = max(c,a[i] - a[i-1])
print(k-c)
n,*L = map(int,open(0).read().split())
sum1 = sum(L)
L.sort()
if sum1%10 != 0:
    print(sum1)
    exit()
i = 0

while sum1%10==0:
    if L[i] %10 != 0:
        sum1 -= L[i]
        if sum1 < 0:
            sum1 = 0
            break
        if not L:
            print(0)
            exit()
    i +=1
print(sum1)

### FIXED CODE ###

n = int(input())
li = []
for i in range(n):
    li.append(int(input()))
li.sort()
flag1 = False
flag2 = False
flag3 = False
if sum(li)%10 != 0:
    flag2 = True

for i in range(n):
    if (sum(li) - li[i])%10 != 0 and flag2 == False:
        flag1 = True
        break
    else:
        flag3 =True
    
if flag1:
    print (sum(li) - li[i])
elif flag2:   
    print(sum(li))
elif flag3:
    print(0)
X=input()
if X=="A":
  print("T")
elif X="T":
  print("A")
elif X="G":
  print("C")
else:
  print("G")

### FIXED CODE ###

X=input()
if X=="A":
  print("T")
elif X=="T":
  print("A")
elif X=="G":
  print("C")
else:
  print("G")
N = int(input())
inputted = list(map(int, input()))
S = inputted[0]
T = inputted[1]

answer = ''
for s, t in zip(S, T):
    answer += s + t

answer = ''.join([s + t for s, t in zip(S, T)])

print(answer)

### FIXED CODE ###

N = int(input())
inputted = input().split()
S = inputted[0]
T = inputted[1]

answer = ''
for s, t in zip(S, T):
    answer += s + t

answer = ''.join([s + t for s, t in zip(S, T)])

print(answer)
from operator import itemgetter

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

L.sort(key=itemgetter(2))

for x in range(101):
    for y in range(101):
        h = L[0][2] + abs(x-L[0][0]) + abs(y-L[0][1])
        for l in L: 
            if l[2] == 0:
                if h - (abs(x-l[0]) + abs(y-l[1])) > 0:
                    flag = 0
                    break
            else:
                if h == -1:
                    tmp = l[2] + abs(x-l[0]) + abs(y-l[1])
                h = l[2] + abs(x-l[0]) + abs(y-l[1])
                
                if tmp == h:
                    flag = 1
                    tmp = h
                else:
                    flag = 0
                    break
                
                
        if flag == 1:
            gx = x
            gy = y
            gh = h
            break
                
                    
    if flag == 1:
        break
        
print(gx, gy, gh)



### FIXED CODE ###

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

L.sort(key=lambda x:x[2])

for x in range(101):
    for y in range(101):
        h = L[-1][2] + abs(x-L[-1][0]) + abs(y-L[-1][1])
        for l in L: 
            if l[2] == 0:
                if h - (abs(x-l[0]) + abs(y-l[1])) > 0:
                    flag = 0
                    break
            else:

                if h == l[2] + abs(x-l[0]) + abs(y-l[1]):
                    flag = 1
                
                else:
                    flag = 0
                    break
                
                
        if flag == 1:
            gx = x
            gy = y
            gh = h
            break
                
                    
    if flag == 1:
        break
        
print(gx, gy, gh)
n = int(input())
s = 0
for i in range(n):
    a = list(input().split())

l = [0]
r = [0]
for m in range(n):
    l.append(a[m][0])
    r.append(a[m][1])

for p in range(1,n+1):
    s += int(r[p])-int(l[p])+1

print(s)

### FIXED CODE ###

n = int(input())
s = 0
a = [input().split() for i in range(n)]

l = [0]
r = [0]
for m in range(n):
    l.append(a[m][0])
    r.append(a[m][1])

for p in range(1,n+1):
    s += int(r[p])-int(l[p])+1

print(s)
Tmp = []
Tmp = input().rstrip().split(' ')

nN = int(Tmp[0])
nM = int(Tmp[1])

nF = [ 0 for i in range(nM)]

for i in range(nN):
  Tmp = input().rstrip().split(' ')
  nTmpN = int(Tmp[0])
  for j in range(nTmpN):
    nCnt = int(Tmp[j+1])
    nF[nCnt] += 1

nAns = 0
for i in range(nM):
  nTmpN = nF[i]
  if nTmpN == nN:
    nAns += 1

print(nAns)
  


### FIXED CODE ###

Tmp = []
Tmp = input().rstrip().split(' ')

nN = int(Tmp[0])
nM = int(Tmp[1])

nData = [[ 0 for i in range(2)] for j in range(nM)]

for i in range(nM):
    nData[i][0]=i+1

for i in range(nN):
	Tmp = input().rstrip().split(' ')
	nK = int(Tmp[0])
	nTmp =[ 0 for j in range(nK)]
	for j in range(nK):
		nTmp[j] = int(Tmp[j+1])
#	print(nTmp)
	for j in range(nM):
		if nData[j][0]  in nTmp:
			nData[j][1] += 1

nAns=0
for i in range(nM):    
    if nData[i][1]==nN:
        nAns += 1

print(nAns)
from math import *
num_digit = lambda n: int(log2(n)+1)    
A, B = [int(s) for s in input().split()]

ret = 0
N = (B-A)+1
nd = num_digit(B)
for i in range(nd):
    nb = int(pow(2, i+1) if i>0 else pow(2, i+2))
    nr = N%nb
    s = sum([(A+j) >> i for j in range(nr)])
    ret += ((s%2) << i)
    
print(ret)

### FIXED CODE ###

H, W = [int(s) for s in input().split()]
h, w = [int(s) for s in input().split()]
print((H-h)*(W-w))
from collections import Counter
N=int(input())
p=[]
dp=[[0]*100 for _ in range(100)]
dp[0][1]=1

for i in range(2,N+1):
    ti=i
    for j in range(2,i+1):
        while ti%j==0:
            p.append(j)
            ti//=j

cnt=Counter(p)

for i,v in enumerate(cnt.values()):
    for j in range(100):
        for k in range(1,v+2):
            dp[i+1][min(76,j*k)]+=dp[i][j]
    ans=dp[i+1][75]

print(ans)

### FIXED CODE ###

from collections import Counter
N=int(input())
p=[]
dp=[[0]*100 for _ in range(100)]
dp[0][1]=1

for i in range(2,N+1):
    ti=i
    for j in range(2,i+1):
        while ti%j==0:
            p.append(j)
            ti//=j

cnt=Counter(p)
ans=0
for i,v in enumerate(cnt.values()):
    for j in range(100):
        for k in range(1,v+2):
            dp[i+1][min(76,j*k)]+=dp[i][j]
    ans=dp[i+1][75]

print(ans)
while True:
  N,A,B,C,X = map(int,raw_input().split())
  if N == A == B == C == X == 0:break
  sum = 0
  Z = 0
  Y = [int(x) for x in raw_input().split()]
  if (X in Y) == True:
      Y.remove(X)
  while Z == 0:
      if sum == 10000:
          sum = -2
          Z = 1
      sum += 1
      X = (A*X+B)%C
      if X == Y[0]:
          Y.pop(0)
          if len(Y) == 0:
              Z = 1
  print sum

### FIXED CODE ###

while True:
  N,A,B,C,X = map(int,raw_input().split())
  if N == A == B == C == X == 0:break
  sum = 0
  Z = 0
  Y = [int(x) for x in raw_input().split()]
  if X == Y[0]:
      Y.pop(0)
      if len(Y) == 0:
          Z = 1
  while Z == 0:
      if sum == 10000:
          sum = -2
          Z = 1
      sum += 1
      X = (A*X+B)%C
      if X == Y[0]:
          Y.pop(0)
          if len(Y) == 0:
              Z = 1
  print sum