import numpy as np # https://maspypy.com/%E6%95%B0%E5%AD%A6%E3%83%BBnumpy-%E9%AB%98%E9%80%9F%E3%83%95%E3%83%BC%E3%83%AA%E3%82%A8%E5%A4%89%E6%8F%9Bfft%E3%81%AB%E3%82%88%E3%82%8B%E7%95%B3%E3%81%BF%E8%BE%BC%E3%81%BF n, m, x = map(int, input().split()) c_list = list(map(int, input().split())) aby_list = [tuple(map(int, input().split())) for _ in range(m)] colors = np.zeros((n, 5), dtype=np.int32) for i, c in enumerate(c_list): colors[i, c - 1] = 1 score = np.zeros((n, 5), dtype=np.int32) for a, b, y in aby_list: score[a - 1, b - 1] += y fft_len = 1 while 2 * fft_len < 2 * n - 1: fft_len *= 2 fft_len *= 2 h = np.zeros((fft_len, 5), dtype=np.int32) for c in range(5): Fsc = np.fft.rfft(score[:, c], fft_len) Fco = np.fft.rfft(colors[::-1, c], fft_len) h[:, c] = np.rint(np.fft.irfft(Fsc * Fco, fft_len)).astype(np.int32) hs = h.sum(axis=1) res = n * x for j in range(n - 1, -1, -1): res = max(res, hs[j] + (n - 1 - j) * x) print(res)