N=int(input()) A=list(map(int,input().split())) from atcoder.segtree import * def op(x,y): return x+y STA=SegTree(op,0,A) STS=SegTree(op,0,[0]*(N+1)) Q=int(input()) ans=0 for _ in range(Q): x,y,l,r=map(int,input().split()) l-=1 x-=1 s=STS.prod(0,x+1) ans+=(y-STA.get(x))*s STA.set(x,y) ans+=STA.prod(l,r) STS.set(l,STS.get(l)+1) STS.set(r,STS.get(r)-1) print(ans)