#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int N,M,X; cin>>N>>M>>X; vector> c(5,vector(N)); rep(j,N){ int t; cin>>t; c[t-1][j] = 1; } vector> t(5,vector(N)); rep(i,M){ int x,y,z; cin>>x>>y>>z; x--,y--; t[y][N-1-x] += z; } vector ans(N); rep(i,5){ auto tt= convolution_ll(c[i],t[i]); rep(j,N){ ans[j] += tt[N-1+j]; } } rep(i,N)ans[i] += X * i; long long aa = 0; rep(i,N)aa = max(aa,ans[i]); aa = max(aa,(long long)N*X); cout<