import sys import heapq def main(): input = sys.stdin.read().split() ptr = 0 N, M, C = map(int, input[ptr:ptr+3]) ptr +=3 A = list(map(int, input[ptr:ptr+N])) ptr +=N ops = [] sum_A = [] for _ in range(M): L = int(input[ptr])-1 # 0-based R = int(input[ptr+1])-1 ptr +=2 ops.append((L, R)) s = sum(A[L:R+1]) sum_A.append(s) # Initial gain is sum_A[j] - C heap = [] for j in range(M): gain = sum_A[j] - C if gain > 0: heapq.heappush(heap, (-gain, j)) selected = [False]*M parities = [0]*N # 0: even, 1: odd total = 0 X = 0 while heap: neg_gain, j = heapq.heappop(heap) gain = -neg_gain if selected[j]: continue current_gain = sum_A[j] - C - 2 * sum(A[i] * parities[i] for i in range(ops[j][0], ops[j][1]+1)) if current_gain <=0: continue # Select this operation total += current_gain X +=1 selected[j] = True # Flip the parities L, R = ops[j] for i in range(L, R+1): parities[i] ^=1 print(total) if __name__ == '__main__': main()