#include <bits/stdc++.h>
#ifdef getchar
#undef getchar
#endif
#define getchar() (*_pinp?*_pinp++:(_inp[fread(_pinp=_inp, 1, 4096, stdin)]='\0', *_pinp++))
char _inp[4097], *_pinp=_inp;
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#ifdef putchar
#undef putchar
#endif
#define putchar(x) (*_pout++=(x), (_pout==_eout?(fwrite(_pout=_out, 1, 4096, stdout)):0))
#define flush() fwrite(_out, 1, _pout-_out, stdout)
char _out[4097], *_eout=_out+4096, *_pout=_out;
#define print(x) do{if(!x)putchar('0');else{x=x<0?(putchar('-'), -x):x;for(;x;x/=10)*_p++='0'+x%10;do putchar(*--_p);while(_p!=_buf);}}while(0)
char _buf[20], *_p=_buf;
using namespace std;
int N, M;
int A[100001];
enum {L, R};
struct node
{
node *link[2];
long long val, add, mul;
} pool[8000000], *nextpool=pool, *nil, *tree[100001];
inline node* alloc(node *orig)
{
*nextpool=*orig;
return nextpool++;
}
node* init(int begin, int end)
{
node *root=nextpool++;
int mid=(begin+end)/2;
if(begin==end)
root->link[L]=root->link[R]=nil;
else
{
root->link[L]=init(begin, mid);
root->link[R]=init(mid+1, end);
}
return root;
}
inline void down(node *root, int begin, int end)
{
if(root->add!=0 || root->mul!=0)
{
int mid=(begin+end)/2;
root->link[L]=alloc(root->link[L]);
if(begin==mid)
root->link[L]->val+=root->add*(mid-begin+1)+1LL*(mid-begin)*(mid-begin+1)/2*root->mul;
root->link[L]->add+=root->add;
root->link[L]->mul+=root->mul;
root->link[R]=alloc(root->link[R]);
if(mid+1==end)
root->link[R]->val+=root->add*(end-mid)+(1LL*(end-begin)*(end-begin+1)-1LL*(mid-begin)*(mid-begin+1))/2*root->mul;
root->link[R]->add+=root->add+1LL*(mid-begin+1)*root->mul;
root->link[R]->mul+=root->mul;
root->add=root->mul=0;
}
}
node* update(node *root, int begin, int end, int i, int j, int x, int y)
{
if(j<begin || end<i)
return root;
root=alloc(root);
if(i<=begin && end<=j)
{
if(begin==end)
root->val+=1LL*x*(end-begin+1)+(1LL*(end-i)*(end-i+1)-1LL*(begin-i-1)*(begin-i))/2*y;
root->add+=x+1LL*(begin-i)*y;
root->mul+=y;
}
else
{
down(root, begin, end);
int mid=(begin+end)/2;
root->link[L]=update(root->link[L], begin, mid, i, j, x, y);
root->link[R]=update(root->link[R], mid+1, end, i, j, x, y);
//root->val=root->link[L]->val+root->link[R]->val;
}
return root;
}
long long query(node *root, int begin, int end, int x)
{
root=alloc(root);
while(begin!=end)
{
int mid=(begin+end)/2;
if(mid>=x)
{
root->link[L]=alloc(root->link[L]);
if(root->add!=0 || root->mul!=0)
{
if(begin==mid)
root->link[L]->val+=root->add*(mid-begin+1)+1LL*(mid-begin)*(mid-begin+1)/2*root->mul;
root->link[L]->add+=root->add;
root->link[L]->mul+=root->mul;
root->add=root->mul=0;
}
end=mid;
root=root->link[L];
}
else
{
root->link[R]=alloc(root->link[R]);
if(root->add!=0 || root->mul!=0)
{
if(mid+1==end)
root->link[R]->val+=root->add*(end-mid)+(1LL*(end-begin)*(end-begin+1)-1LL*(mid-begin)*(mid-begin+1))/2*root->mul;
root->link[R]->add+=root->add+1LL*(mid-begin+1)*root->mul;
root->link[R]->mul+=root->mul;
root->add=root->mul=0;
}
begin=mid+1;
root=root->link[R];
}
}
return root->val;
}
int main()
{
nil=nextpool++;
nil->link[L]=nil->link[R]=nil;
scan(N);
for(int i=1; i<=N; i++)
scan(A[i]);
int a, b, c, d;
for(int i=1; i<=N; i++)
{
scan(a);
A[i]=a-A[i];
}
scan(M);
tree[0]=init(1, N);
for(int i=1; i<=M; i++)
{
scan(a);
scan(b);
scan(c);
scan(d);
tree[i]=update(tree[i-1], 1, N, a, b, c, d);
}
node *remember=nextpool;
for(int i=1; i<=N; i++)
{
nextpool=remember;
int lo=0, mid, hi=M+1;
while(lo<hi)
{
mid=(lo+hi)/2;
if(query(tree[mid], 1, N, i)>=A[i])
hi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xpbmtbTF0tPm11bCs9cm9vdC0+bXVsOwogICAgICAgIHJvb3QtPmxpbmtbUl09YWxsb2Mocm9vdC0+bGlua1tSXSk7CiAgICAgICAgaWYobWlkKzE9PWVuZCkKICAgICAgICAgICAgcm9vdC0+bGlua1tSXS0+dmFsKz1yb290LT5hZGQqKGVuZC1taWQpKygxTEwqKGVuZC1iZWdpbikqKGVuZC1iZWdpbisxKS0xTEwqKG1pZC1iZWdpbikqKG1pZC1iZWdpbisxKSkvMipyb290LT5tdWw7CiAgICAgICAgcm9vdC0+bGlua1tSXS0+YWRkKz1yb290LT5hZGQrMUxMKihtaWQtYmVnaW4rMSkqcm9vdC0+bXVsOwogICAgICAgIHJvb3QtPmxpbmtbUl0tPm11bCs9cm9vdC0+bXVsOwogICAgICAgIHJvb3QtPmFkZD1yb290LT5tdWw9MDsKICAgIH0KfQogCm5vZGUqIHVwZGF0ZShub2RlICpyb290LCBpbnQgYmVnaW4sIGludCBlbmQsIGludCBpLCBpbnQgaiwgaW50IHgsIGludCB5KQp7CiAgICBpZihqPGJlZ2luIHx8IGVuZDxpKQogICAgICAgIHJldHVybiByb290OwogICAgcm9vdD1hbGxvYyhyb290KTsKICAgIGlmKGk8PWJlZ2luICYmIGVuZDw9aikKICAgIHsKICAgICAgICBpZihiZWdpbj09ZW5kKQogICAgICAgICAgICByb290LT52YWwrPTFMTCp4KihlbmQtYmVnaW4rMSkrKDFMTCooZW5kLWkpKihlbmQtaSsxKS0xTEwqKGJlZ2luLWktMSkqKGJlZ2luLWkpKS8yKnk7CiAgICAgICAgcm9vdC0+YWRkKz14KzFMTCooYmVnaW4taSkqeTsKICAgICAgICByb290LT5tdWwrPXk7CiAgICB9CiAgICBlbHNlCiAgICB7CiAgICAgICAgZG93bihyb290LCBiZWdpbiwgZW5kKTsKICAgICAgICBpbnQgbWlkPShiZWdpbitlbmQpLzI7CiAgICAgICAgcm9vdC0+bGlua1tMXT11cGRhdGUocm9vdC0+bGlua1tMXSwgYmVnaW4sIG1pZCwgaSwgaiwgeCwgeSk7CiAgICAgICAgcm9vdC0+bGlua1tSXT11cGRhdGUocm9vdC0+bGlua1tSXSwgbWlkKzEsIGVuZCwgaSwgaiwgeCwgeSk7CiAgICAgICAgLy9yb290LT52YWw9cm9vdC0+bGlua1tMXS0+dmFsK3Jvb3QtPmxpbmtbUl0tPnZhbDsKICAgIH0KICAgIHJldHVybiByb290Owp9CiAKbG9uZyBsb25nIHF1ZXJ5KG5vZGUgKnJvb3QsIGludCBiZWdpbiwgaW50IGVuZCwgaW50IHgpCnsKICAgIHJvb3Q9YWxsb2Mocm9vdCk7CiAgICB3aGlsZShiZWdpbiE9ZW5kKQogICAgewogICAgICAgIGludCBtaWQ9KGJlZ2luK2VuZCkvMjsKICAgICAgICBpZihtaWQ+PXgpCiAgICAgICAgewogICAgICAgICAgICByb290LT5saW5rW0xdPWFsbG9jKHJvb3QtPmxpbmtbTF0pOwogICAgICAgICAgICBpZihyb290LT5hZGQhPTAgfHwgcm9vdC0+bXVsIT0wKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihiZWdpbj09bWlkKQogICAgICAgICAgICAgICAgICAgIHJvb3QtPmxpbmtbTF0tPnZhbCs9cm9vdC0+YWRkKihtaWQtYmVnaW4rMSkrMUxMKihtaWQtYmVnaW4pKihtaWQtYmVnaW4rMSkvMipyb290LT5tdWw7CiAgICAgICAgICAgICAgICByb290LT5saW5rW0xdLT5hZGQrPXJvb3QtPmFkZDsKICAgICAgICAgICAgICAgIHJvb3QtPmxpbmtbTF0tPm11bCs9cm9vdC0+bXVsOwogICAgICAgICAgICAgICAgcm9vdC0+YWRkPXJvb3QtPm11bD0wOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVuZD1taWQ7CiAgICAgICAgICAgIHJvb3Q9cm9vdC0+bGlua1tMXTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgcm9vdC0+bGlua1tSXT1hbGxvYyhyb290LT5saW5rW1JdKTsKICAgICAgICAgICAgaWYocm9vdC0+YWRkIT0wIHx8IHJvb3QtPm11bCE9MCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYobWlkKzE9PWVuZCkKICAgICAgICAgICAgICAgICAgICByb290LT5saW5rW1JdLT52YWwrPXJvb3QtPmFkZCooZW5kLW1pZCkrKDFMTCooZW5kLWJlZ2luKSooZW5kLWJlZ2luKzEpLTFMTCoobWlkLWJlZ2luKSoobWlkLWJlZ2luKzEpKS8yKnJvb3QtPm11bDsKICAgICAgICAgICAgICAgIHJvb3QtPmxpbmtbUl0tPmFkZCs9cm9vdC0+YWRkKzFMTCoobWlkLWJlZ2luKzEpKnJvb3QtPm11bDsKICAgICAgICAgICAgICAgIHJvb3QtPmxpbmtbUl0tPm11bCs9cm9vdC0+bXVsOwogICAgICAgICAgICAgICAgcm9vdC0+YWRkPXJvb3QtPm11bD0wOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJlZ2luPW1pZCsxOwogICAgICAgICAgICByb290PXJvb3QtPmxpbmtbUl07CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJvb3QtPnZhbDsKfQogCmludCBtYWluKCkKewogICAgbmlsPW5leHRwb29sKys7CiAgICBuaWwtPmxpbmtbTF09bmlsLT5saW5rW1JdPW5pbDsKICAgIHNjYW4oTik7CiAgICBmb3IoaW50IGk9MTsgaTw9TjsgaSsrKQogICAgICAgIHNjYW4oQVtpXSk7CiAgICBpbnQgYSwgYiwgYywgZDsKICAgIGZvcihpbnQgaT0xOyBpPD1OOyBpKyspCiAgICB7CiAgICAgICAgc2NhbihhKTsKICAgICAgICBBW2ldPWEtQVtpXTsKICAgIH0KICAgIHNjYW4oTSk7CiAgICB0cmVlWzBdPWluaXQoMSwgTik7CiAgICBmb3IoaW50IGk9MTsgaTw9TTsgaSsrKQogICAgewogICAgICAgIHNjYW4oYSk7CiAgICAgICAgc2NhbihiKTsKICAgICAgICBzY2FuKGMpOwogICAgICAgIHNjYW4oZCk7CiAgICAgICAgdHJlZVtpXT11cGRhdGUodHJlZVtpLTFdLCAxLCBOLCBhLCBiLCBjLCBkKTsKICAgIH0KICAgIG5vZGUgKnJlbWVtYmVyPW5leHRwb29sOwogICAgZm9yKGludCBpPTE7IGk8PU47IGkrKykKICAgIHsKICAgICAgICBuZXh0cG9vbD1yZW1lbWJlcjsKICAgICAgICBpbnQgbG89MCwgbWlkLCBoaT1NKzE7CiAgICAgICAgd2hpbGUobG88aGkpCiAgICAgICAgewogICAgICAgICAgICBtaWQ9KGxvK2hpKS8yOwogICAgICAgICAgICBpZihxdWVyeSh0cmVlW21pZF0sIDEsIE4sIGkpPj1BW2ldKQogICAgICAgICAgICAgICAgaGk9bWlkOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBsbz1taWQrMTsKICAgICAgICB9CiAgICAgICAgaW50IHY9bG89PU0rMT8tMTpsbzsKICAgICAgICBwcmludCh2KTsKICAgICAgICBwdXRjaGFyKCIgXG4iW2k9PU5dKTsKICAgIH0KICAgIGZsdXNoKCk7CiAgICByZXR1cm4gMDsKfQ==