n=int(input())list1=input().split()x,g=int(1),int(1)to=int(0)while x!=0 and g!=0: x,g=map(int,input().split()) to=to+(int(list1[x-1])*g)print(to)