size = 1 << 20 class StarrySkyTree: def __init__(self): self.seg_max = [0] * (2 * size - 1) self.seg_add = [0] * (2 * size - 1) def add(self, a, b, x, k=0, l=0, r=size): if not r: r = size if r <= a or b <= l: return if a <= l and r <= b: self.seg_add[k] += x return self.add(a, b, x, k * 2 + 1, l, (l + r) / 2) self.add(a, b, x, k * 2 + 2, (l + r) / 2, r) self.seg_max[k] = max(self.seg_max[k * 2 + 1] + self.seg_add[k * 2 + 1], self.seg_max[k * 2 + 2] + self.seg_add[k * 2 + 2]) def get_max(self, a, b, k=0, l=0, r=size): if r <= a or b <= l: return 0 if a <= l and r <= b: return self.seg_max[k] + self.seg_add[k] left = self.get_max(a, b, k * 2 + 1, l, (l + r) / 2) right = self.get_max(a, b, k * 2 + 2, (l + r) / 2, r) return max(left, right) + self.seg_add[k] N = int(input()) sst = StarrySkyTree() for i, t in enumerate(input().split()): sst.add(i, i + 1, int(t) - 3 * i) M = int(input()) LRD = [tuple(map(int, input().split())) for _ in range(M)] for i in range(M): sst.add(LRD[i][0] - 1, LRD[i][1], LRD[i][2]) print(max(0, sst.get_max(0, N - 1)) + 3 * (N - 1))