CodeEff/ECCO huggingface dataset:
# Original solution
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7


N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
Ka = sum(B)-sum(A)
Kb = Ka
for a,b in zip(A,B):
    if a > b:
        Kb -= a-b
    else:
        if (b-a)%2:
            Ka -= (b-a+1)//2
            Kb -= 1
        else:
            Ka -= (b-a)//2
print(('Yes' if Ka >= 0 and Kb >= 0 else 'No'))




# Optimized solution
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7


N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
Ka = sum(B)-sum(A)
Kb = Ka
for a,b in zip(A,B):
    if a < b:
        Ka -= (b-a+1)//2
print(('Yes' if Ka >= 0 and Kb >= 0 else 'No'))
# Original solution
import sys
def main():
    input = sys.stdin.readline
    N=int(eval(input()))
    *A,=list(map(int, input().split()))
    *B,=list(map(int, input().split()))

    asum=sum(A)
    bsum=sum(B)
    asmall=0
    bsmall=0
    for a,b in zip(A,B):
        asmall+=(max(0, b-a)+1)//2
        bsmall+=max(0, a-b)
    t=bsum-asum
    print(('Yes' if t>=max(asmall,bsmall) else 'No'))

if __name__ == '__main__':
    main()

# Optimized solution
import sys
def main():
    input = sys.stdin.readline
    N=int(eval(input()))
    *A,=list(map(int, input().split()))
    *B,=list(map(int, input().split()))

    opa=opb=0
    for a,b in zip(A,B):
        if a>=b:
            opb+=a-b
        else:
            if (b-a)&1==0:
                opa+=(b-a)//2
            else:
                opa+=(b-a)//2 + 1
                opb+=1

    print(('Yes' if opa>=opb else 'No'))

if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
N = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sub = sorted(b[i] - a[i] for i in range(N))
odd = len([x for x in sub if x > 0 and x % 2 == 1])
plus = sum(x for x in sub if x > 0)
minus = sum(x for x in sub if x < 0)
print((('No', 'Yes')[plus + minus * 2 >= odd]))


# Optimized solution
#!/usr/bin/env python3
N = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ds = [b[i] - a[i] for i in range(N)]
p = sum(x // 2 for x in ds if x > 0)
m = sum(-x for x in ds if x < 0)
print((('No', 'Yes')[m <= p]))
# Original solution
n=int(eval(input()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
for a,b in zip(A,B):
   if a>b:count -=a-b
   elif b>a:count +=(b-a)//2

print(("Yes" if count>=0 else "No"))

# Optimized solution
n=int(eval(input()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count=0
all=sum(B)-sum(A)
for a,b in zip(A,B):
   if a>b:count -=a-b
   elif b>a:count +=(b-a)//2

print(("Yes" if count>=0 else "No"))
# Original solution
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))

    n_2 = 0
    n_1 = 0
    for a, b in zip(A, B):
        if a > b:
            n_1 += (a - b)
        elif a < b:
            n_2 += (b - a + 1) // 2

    diff = sum(B) - sum(A)
    if diff < 0:
        ans = "No"
    elif n_1 <= diff and n_2 <= diff:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys

input = sys.stdin.readline


def main():
    N = int(eval(input()))
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))

    n_2 = 0
    n_1 = 0
    for a, b in zip(A, B):
        if a > b:
            n_1 += (a - b)
        elif a < b:
            n_2 += (b - a + 1) // 2

    diff = sum(B) - sum(A)
    if n_1 <= diff and n_2 <= diff:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n=I()
  l1=LI()
  l2=LI()

  sm1=sum(l1)
  sm2=sum(l2)

  nm=sm2-sm1
  if nm<0:
    return 'No'

  nm1=0
  for i in range(n):
    a=l1[i]
    b=l2[i]

    if a<b:
      _a=(b-a+1)//2
      l1[i]+=_a*2
      nm1+=_a

  nm2=0
  for i in range(n):
    a=l1[i]
    b=l2[i]

    if a>b:
      _a=a-b
      nm2+=_a

  # print(nm,nm2)
  if nm<max(nm1,nm2):
    return 'No'

  return 'Yes'

# main()
print((main()))


# Optimized solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n=I()
  a=LI()
  b=LI()

  sm1=sum(a)
  sm2=sum(b)

  cnt=sm2-sm1
  need=0
  for i in range(n):
    need+=max(0,(b[i]-a[i]+1)//2)

  if cnt<need:
    return 'No'
  return 'Yes'

# main()
print((main()))
# Original solution
def judge(a, b):
    if a+b <= 9:
        return a+b
    return a+b-9

n = int(eval(input()))
ans = 0
key = 0
for i in range(n):
    a, b = list(map(int, input().split()))
    if a == 0:
        ans += b
        continue
    for j in range(b):
        if key + a <= 9:
            ans += 1
        else:
            ans += 2
        key = judge(key, a)
print((ans-1))

# Optimized solution
n = int(eval(input()))
d, c = 0, 0

for i in range(n):
    p, q = list(map(int, input().split()))
    d = d + q
    c = c + p*q

print(((d-1)+(c-1)//9))
# Original solution
def sum_lr(l, r, cnt):
    cnt += 1
    lr = l + r
    if lr < 10:
        l = lr
        return l, cnt
    else:
        l = lr // 10
        r = lr % 10
        return sum_lr(l, r, cnt)

from collections import defaultdict
aaa = defaultdict(lambda:{})
for l in range(10):
    for r in range(10):
        aaa[l][r] = sum_lr(l,r,0)
        

def dc_compression(d, c, ret, cnt):
    if c == 1:
        ret.append((d, 1))
        return ret, cnt
    
    if c % 2 == 1:
        ret.append((d, 1))
        c -= 1
    d, tmp_cnt = aaa[d][d]
    c = c // 2
    cnt += tmp_cnt * c
    #print(d, c, ret, cnt)
    return dc_compression(d, c, ret, cnt)
    
    
    
        

M = int(eval(input()))

nums = []
l = 0
cnt = 0
import sys
input = sys.stdin.readline
for _ in range(M):
    d, c = list(map(int, input().split()))
    tmp_nums, tmp_cnt= dc_compression(d,c,[], 0)
    nums += tmp_nums
    cnt += tmp_cnt
    
#print(nums)    
    
for d, c in nums:
    l, tmp_cnt = aaa[l][d]
    cnt += tmp_cnt

print((cnt-1))

# Optimized solution
def sum_lr(l, r, cnt):
    cnt += 1
    lr = l + r
    if lr < 10:
        l = lr
        return l, cnt
    else:
        l = lr // 10
        r = lr % 10
        return sum_lr(l, r, cnt)

from collections import defaultdict
aaa = defaultdict(lambda:{})
for l in range(10):
    for r in range(10):
        aaa[l][r] = sum_lr(l,r,0)
        

def dc_compression(d, c, ret, cnt):
    if c == 1:
        ret.append((d, 1))
        return ret, cnt
    
    if c % 2 == 1:
        ret.append((d, 1))
        c -= 1
    d, tmp_cnt = aaa[d][d]
    c = c // 2
    cnt += tmp_cnt * c
    #print(d, c, ret, cnt)
    return dc_compression(d, c, ret, cnt)
    
    
    
        

M = int(eval(input()))

nums = []
l = 0
cnt = 0
import sys
input = sys.stdin.readline
for _ in range(M):
    d, c = list(map(int, input().split()))
    tmp_nums, tmp_cnt= dc_compression(d,c,[], 0)
    for t,_ in tmp_nums:
        nums.append(t)
    
    cnt += tmp_cnt
    
#print(nums)    
    
for d in nums:
    l, tmp_cnt = aaa[l][d]
    cnt += tmp_cnt

print((cnt-1))
# Original solution
import sys
input = sys.stdin.readline

def main():
    M = int(eval(input()))
    wa = 0
    ans = 0
    for _ in range(M):
        d, c = [int(x) for x in input().split()]
        for _ in range(c):
            wa += d
            ans += 1
            if wa >= 10:
                ans += 1
                wa = wa % 10 + 1
    
    print((ans - 1))

    



if __name__ == '__main__':
    main()



# Optimized solution
import sys
input = sys.stdin.readline

def main():
    M = int(eval(input()))
    count = 0
    wa = 0
    for _ in range(M):
        d, c = [int(x) for x in input().split()]
        count += c
        wa += d * c
    
    print((count - 1 + ((wa - 1) // 9)))
    



if __name__ == '__main__':
    main()
# Original solution
M = int(eval(input()))
D = []
C = []
for i in range(M):
    d,c = list(map(int,input().split()))
    D.append(d)
    C.append(c)

ans = 0
n = D[0]
C[0] -= 1
for i in range(M):
    c = C[i]
    d = D[i]
    while c != 0:
        if c%2==0:
            ans += c//2*((2*d)//10+1)
            d = (2*d)//10+(2*d)%10
            c //= 2
        else:
            ans += c//2*((2*d)//10+1)
            ans += (n+d)//10+1
            n = (n+d)//10+(n+d)%10
            d = (2*d)//10+(2*d)%10
            c //= 2
print(ans)

# Optimized solution
M = int(eval(input()))
D = 0
S = 0
for i in range(M):
    c,d = list(map(int,input().split()))
    D += d
    S += c*d
print((D-1+(S-1)//9))
# Original solution
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(eval(input()))
n, s = 0, 0
for i in range(m):
  d, c = [int(i) for i in input().split()]
  n += c
  s += d * c
while s >= 10:
  s -= 9
  n += 1
print((n - 1))

# Optimized solution
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(eval(input()))
n, s = 0, 0
for i in range(m):
  d, c = [int(i) for i in input().split()]
  n += c
  s += d * c
print((n + (s - 1) // 9 - 1))
# Original solution
m=int(eval(input()))
d,c=[],[]
ans=-1
for i in range(m):
  dd,cc=list(map(int,input().split()))
  d.append(dd)
  c.append(cc)
  ans+=cc
a=0
ds=lambda n:sum(list(map(int,list(str(n)))))
for i in range(m):
  if d[i]*c[i]+a<10:a+=d[i]*c[i]
  else:
    if c[i]*d[i]>9:
      ci,di=c[i],d[i]
      while ci*di>9:
        cd=(0--10//di)
        ci,di,cci,ddi=ci//cd,ds(cd*di),ci-(ci//cd*cd),di
        ans+=ci
        if ddi*cci+a>9:ans+=1
        a=ds(ddi*cci+a)
      if di*ci+a>9:ans+=1
      a=ds(di*ci+a)
    else:
      ans+=1
      a=ds(a+c[i]*d[i])
print(ans)

# Optimized solution
m=int(eval(input()))
d,c=[],[]
ans=-1
for i in range(m):
  dd,cc=list(map(int,input().split()))
  d.append(dd)
  c.append(cc)
  ans+=cc
a=0
for i in range(m):
  a+=d[i]*c[i]
  dd=(a-1)//9
  ans+=dd
  a-=dd*9
print(ans)
# Original solution
def main():
    M = int(eval(input()))
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    dc_sum = 0
    for i in range(M):
        d = dc[i][0]
        c = dc[i][1]
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print((ans - 1 + dc_sum//9 - 1))
    else:
        print((ans - 1 + dc_sum//9))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    M = int(eval(input()))
    ans = 0
    dc_sum = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print((ans - 1 + dc_sum//9 - 1))
    else:
        print((ans - 1 + dc_sum//9))


if __name__ == '__main__':
    main()
# Original solution
def main():
    M = int(eval(input()))
    ans = 0
    dc_sum = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print((ans - 1 + dc_sum//9 - 1))
    else:
        print((ans - 1 + dc_sum//9))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    import sys
    input = sys.stdin.buffer.readline
    M = int(eval(input()))
    ans = 0
    dc_sum = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print((ans - 1 + dc_sum//9 - 1))
    else:
        print((ans - 1 + dc_sum//9))


if __name__ == '__main__':
    main()
# Original solution

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


ans = 0
M = inp()
zan_all = deque()
for m in range(M):
    d,c = inpl()
    zan = []

    while True:
        if c == 1:
            zan_all.appendleft(d)
            break
        elif c%2 == 0:
            if d == 0:
                ans += c
                break
            elif d <= 4:
                ans += c//2
                d *= 2
                c //= 2
            else:
                ans += c
                d = d*2 - 9
                c //= 2
        else:
            zan_all.appendleft(d)
            c -= 1


for i in range(1,len(zan_all)):
    d = zan_all[i] + zan_all[i-1]
    if d >= 10:
        zan_all[i] = d - 10 + 1
        ans += 2
    else:
        zan_all[i]   = d
        ans += 1

print(ans)


# Optimized solution

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


ans = 0
M = inp()
zan = []
for m in range(M):
    d,c = inpl()

    while True:
        if c == 1:
            zan.append(d)
            break
        elif c%2 == 0:
            if d == 0:
                ans += c
                break
            elif d <= 4:
                ans += c//2
                d *= 2
                c //= 2
            else:
                ans += c
                d = d*2 - 9
                c //= 2
        else:
            zan.append(d)
            c -= 1

zan.reverse()

bx = zan[0]
for x in zan[1:]:
    d = x + bx
    if d >= 10:
        bx = d - 10 + 1
        ans += 2
    else:
        bx = d
        ans += 1

print(ans)
# Original solution
import sys
input=sys.stdin.readline
cha=[0,2,4,6,8,1,3,5,7,9]
m=int(eval(input()))
ans=0
from collections import deque
l=deque()
for _ in range(m):
    d,c=list(map(int,input().split()))
    while c>1:
        if c%2:
            c-=1
            l.append(d)
        c//=2
        ans+=c if d<5 else c*2
        d=cha[d]
    l.append(d)

k=len(l)
while k>1:
    a=l.pop()
    b=l.pop()
    x=a+b
    ans+=1
    if x>9:
        s=str(x)
        l.append(int(s[0]))
        l.append(int(s[1]))
    else:
        l.append(x)
        k-=1
print(ans)


# Optimized solution
import sys
input=sys.stdin.readline
cha=[0,2,4,6,8,1,3,5,7,9]
m=int(eval(input()))
ans=0
l=[]
for _ in range(m):
    d,c=list(map(int,input().split()))
    while c>1:
        if c%2:
            c-=1
            l.append(d)
        c//=2
        ans+=c if d<5 else c*2
        d=cha[d]
    l.append(d)

k=len(l)
while k>1:
    a=l.pop()
    b=l.pop()
    x=a+b
    ans+=1
    if x>9:
        s=str(x)
        l.append(int(s[0]))
        l.append(int(s[1]))
    else:
        l.append(x)
        k-=1
print(ans)
# Original solution
import itertools
import os
import sys

from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]


def test(n):
    round = {str(n)}
    ret = 0
    while round:
        next_round = set()
        for n in round:
            for i in range(len(n) - 1):
                s = n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2:]
                if len(s) > 1:
                    next_round.add(s)
        round = next_round
        print(round)
        ret += 1
    print(('test:', ret))
    print()


@lru_cache(maxsize=None)
def solve(n):
    n = str(n)
    if len(n) == 1:
        return 0, int(n)
    num = 0
    ret = 0
    for c in str(n):
        ret += 1
        num += int(c)
        while num >= 10:
            ret += 1
            num = num % 10 + 1
    return ret - 1, num


# ans = 0
# num = 0
# for d, c in DC:
#     if d == 0:
#         ans += c
#         n = num + d * c
#         ans += n // 10
#         num = n % 10
#     if d == 1:
#         ans += c
#         n = num + d * c
#         ans += n // 10
#         num = n % 10
#     if d == 2:
#         ans += c
#         n1 = c // 5
#
#         n
#         n = num + d * c
#         ans += c
#         ans += n // 10
#         num = n % 10

memo = [[None] * 11 for _ in range(10)]
for i, j in itertools.product(list(range(10)), list(range(11))):
    memo[i][j] = solve(str(i) * j)


def kurikaesi(d, c):
    if c < 10:
        return memo[d][c]
    cnt, n1 = memo[d][10]
    ret = cnt * (c // 10)
    c2, n2 = kurikaesi(n1, c // 10)
    c3, n3 = memo[d][c % 10]
    ret += c2
    ret += c3
    c4, n4 = solve(str(n2) + str(n3))
    ret += c4
    return ret, n4


#
# n = ''
# for d, c in DC:
#     n += str(d) * c
# test(n)
# print(solve(n))

ans = 0
num = 0
for d, c in DC:
    cnt, n = kurikaesi(d, c)
    ans += cnt
    c2, n2 = solve(str(num) + str(n))
    ans += c2
    num = n2
print((ans - 1))


# Optimized solution
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 桁数*9 + 総和が 9 ずつ減る
M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

s = 0
l = 0
for d, c in DC:
    l += c
    s += d * c
ans = (l * 9 + s - 1) // 9 - 1
print(ans)
# Original solution
M = int(eval(input()))
now = 0
ans = 0

for _ in range(M):
    d, c = list(map(int, input().split()))
    for _ in range(c):
        now += d
        ans += 1
        if now >= 10:
            now = now // 10 + now % 10
            ans += 1

print((ans - 1))

# Optimized solution
M = int(eval(input()))
DC = [tuple(map(int, input().split())) for _ in range(M)]

D = 0
C = 0
for d, c in DC:
    D += d * c
    C += c

ans = C - 1
ans += (D - 1) // 9
print(ans)
# Original solution
import sys
input = sys.stdin.readline

from collections import deque

q = deque()

def calc(d, c):
    if c&1:
        q.append(d)
    if c == 1:
        return 0
    d *= 2
    if d >= 10:
        return c//2 * 2 + calc(1+d%10, c//2)
    return c//2 + calc(d, c//2)
    

def main():
    M = int(eval(input()))
    ans = 0
    for i in range(M):
        d, c = list(map(int, input().split()))
        ans += calc(d, c)
    
    num = q.popleft()
    while len(q) > 0:
        t = q.popleft()
        num += t
        if num >= 10:
            num = 1 + num%10
            ans += 1
        ans += 1
    
    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
import sys
input = sys.stdin.readline

from collections import deque

q = deque()

def calc(d, c):
    if c&1:
        q.append(d)
    if c == 1:
        return 0
    d *= 2
    c>>=1
    if d >= 10:
        return c * 2 + calc(1+d%10, c)
    return c + calc(d, c)
    

def main():
    M = int(eval(input()))
    ans = 0
    for i in range(M):
        d, c = list(map(int, input().split()))
        ans += calc(d, c)
    
    num = q.popleft()
    while len(q) > 0:
        t = q.popleft()
        num += t
        if num >= 10:
            num = 1 + num%10
            ans += 1
        ans += 1
    
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
M = int(eval(input()))
dc = [[int(i) for i in input().split()] for _ in range(M)]

digit = [0] * 10
for d, c in dc :
    digit[d] += c

ret = digit[0]
digit[0] = 0
while sum(digit) != 1 :
    for a in range(1, 10) :
        for b in range(1, 10) :
            if a + b >= 10 :
                na = (a + b) // 10
                nb = (a + b) % 10
                if a == b :
                    x = digit[a] // 2
                    digit[na] += x
                    digit[nb] += x
                    digit[a] -= 2 * x
                else :
                    x = min(digit[a], digit[b])
                    digit[na] += x
                    digit[nb] += x
                    digit[a] -= x
                    digit[b] -= x
                ret += x
            else :
                if a == b :
                    x = digit[a] // 2
                    digit[a+b] += x
                    digit[a] -= 2 * x
                else :
                    x = min(digit[a], digit[b])
                    digit[a+b] += x
                    digit[a] -= x
                    digit[b] -= x

for d, c in dc :
    if d != 0 :
        ret += c
        
print((ret - 1))

# Optimized solution
M = int(eval(input()))
dc = [[int(i) for i in input().split()] for _ in range(M)]

ret = 0
s = 0
for d, c in dc :
    s += d * c
    t = s // 10
    ret += t
    s %= 10
    s += t
    
while s >= 10 :
    t = s // 10
    ret += t
    s %= 10
    s += t

for d, c in dc :
    ret += c
        
print((ret - 1))
# Original solution
#順番考えなくていいかとりあえず試す
#配列をタプルに変更
m = int(eval(input()))
nm = []
for i in range(m):
    di,ci = list(map(int, input().split( )))
    nm.append((di,ci))
cnt = 0
tmp = 0
while nm:
    ci,di = nm.pop()
    while di:
        cnt += 1
        #print(di,cnt)
        tmp += ci
        di-=1
        if tmp>=10:
            tmp = str(tmp)
            tmp2 = int(tmp[0])+int(tmp[1])
            cnt += 1
            #print(di,cnt)
            tmp = tmp2
print((cnt-1))
    

# Optimized solution
#繰り上がりごとに各桁の総和は9減る
#9*最初の桁数+最初の総和がそれで減る
#それは順番によらない

m = int(eval(input()))
sm=  0
d = []
c = []
for i in range(m):
    di,ci = list(map(int, input().split( )))
    d.append(di)
    c.append(ci)
    sm += di*ci

x = sum(c)*9 + sm
y =  x%9
if y==0:
    y = 9
    
print(((x-y)//9-1))
# Original solution
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

M, = list(map(int, sys.stdin.readline().rstrip().split(" ")))

def too_slow(d_pairs):
    ds = []
    for d, c in d_pairs:
        for _ in range(c):
            ds.append(d)
    d, c = 0, 0
    for next_d in ds:
        c += 1
        d += next_d
        if d >= 10:
            d = d % 10 + 1
            c += 1
    return c-1


def contract_list(ds):
    d, c = 0, -1
    for next_d, next_c in ds:
        c += next_c
        c += 1
        d += next_d
        if d >= 10:
            d = d % 10 + 1
            c += 1
        # print(d, c)
    return d, c

def contract_pair(d, orig_c):
    c = 0
    ds = [(d, c)]
    for _ in range(int(math.log(orig_c, 2)) + 1):
        d = d + d
        c = c*2 +1
        if d >= 10:
            d = d % 10 + 1
            c += 1
        ds.append((d, c))
    # print(ds)

    ds_for_calc = []
    for i, b in enumerate(reversed(bin(orig_c)[2:])):
        # print(bin(orig_c), b)
        if b == "1":
            ds_for_calc.append(ds[i])
    # print("for_cal", ds_for_calc)

    return contract_list(ds_for_calc)


ds_for_calc = []
orig_ds = []
for _ in range(M):
    d, c = list(map(int, sys.stdin.readline().rstrip().split(" ")))
    orig_ds.append((d, c))
    ds_for_calc.append(contract_pair(d, c))
    # print(ds_for_calc[-1])
# print("last_list", ds_for_calc)
answer = contract_list(ds_for_calc)[1]
# print(too_slow(orig_ds), answer)
# assert too_slow(orig_ds) == answer
print(answer)

exit(0)


# Optimized solution
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

M, = list(map(int, sys.stdin.readline().rstrip().split(" ")))
total_sum = 0
total_digits = 0
for _ in range(M):
    d, c = list(map(int, sys.stdin.readline().rstrip().split(" ")))
    total_digits += c
    total_sum += d*c
answer = ((total_sum-1) // 9) + total_digits -1
print(answer)
exit(0)