#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using _TYPE = int;
typedef tree< _TYPE, null_type, less< _TYPE >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int n, m, k;
int satisfaction[20];
vector<pair<int, int>> offers[20];
int dp[20][1 << 18];

int solve(int index, int mask) {
    if(index == n) {
        int cntOn = 0;
        for(int i = 0; i <= 21; i++) {
            if(mask & (1 << i))
                cntOn++;
        }
        if(cntOn == m)
            return 0;
        return (int) -1e9;
    }
    int &rt = dp[index][mask];
    if(rt != -1)
        return rt;
    rt = (int) -1e9;
    // try not taking me and go to next one
    rt = max(rt, solve(index + 1, mask));
    // try taking me and if I have offer dont use me as an offer, and Im not taken
    if(!(mask & (1 << index)))
        rt = max(rt, solve(index + 1, mask | (1 << index)) + satisfaction[index]);
    //If I have an offer with another one, try take me with the offers I have and maximize
    if((int) offers[index].size() && (!(mask & (1 << index)))) {
        //loop through all other dishes I have offer with
        for(auto p : offers[index]) {
            int toTake = p.first, cost = p.second;
            //if the dish I'm connected with is still NOT taken
            if(!(mask & (1 << toTake))) {
                //next two lines: mark me as taken, and mark the dish I'm connected to as taken so as to take the offer
                int x = mask | (1 << toTake);
                x = x | (1 << index);
                rt = max(rt, solve(index + 1, x) + cost + satisfaction[index] + satisfaction[toTake]);
            }
        }
    }
    return rt;
}

int main() {
    IO;
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++)
        cin >> satisfaction[i];
    for(int i = 0; i < k; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        offers[--u].push_back({--v, c});
    }
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using _TYPE = int;
typedef tree< _TYPE, null_type, less< _TYPE >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int MAX = (int) 18;
ll dp[MAX + 1][1 << MAX];
int cost[MAX][MAX];
int inp[MAX];
ll ans = 0;
int fir = -1;
int n, m, k;

ll solve(int prev, int mask) {
    if(__builtin_popcount(mask) == m)
        return 0;
    ll &rt = dp[prev][mask];
    if(rt != -1)
        return rt;
    for(int i = 0; i < n; i++) {
        //If the current item at prev i has been already taken
        if(mask & (1 << i))
            continue;
        rt = max(rt, 1LL * solve(i, mask | (1 << i)) + inp[i] * 1LL + cost[prev][i] * 1LL);
    }
    return rt;
}

// void build(int index, int mask) {
//     if(__builtin_popcount(mask) == m)
//         return;
//     ll &rt = dp[index][mask];
//     for(int i = 0; i < n; i++) {
//         //If the current item at index i has been already taken
//         if(mask & (1 << i))
//             continue;
//         int newMask = mask | (1 << i);
//         bool done = false;
//         if(__builtin_popcount(newMask) == m && (i == fir))
//              done = true;
//         ll a = solve(i, newMask) + inp[i] * 1LL;
//         if(a == rt) {
//             if(fir == -1)
//                 fir = i;
//             ans += inp[i] * 1LL + cost[index][i] * 1LL;
//             int xy = (1 << i);
//             int aa = mask & xy;
//             if(done)
//                 ans -= cost[index][i] * 1LL;
//             cout << index << " " << i << " " << mask << " " << inp[i] * 1LL + cost[index][i] * 1LL
//                        << " " << aa << endl;
//             build(i, newMask);
//             return;
//         }
//     }
// }

int main() {
    IO;
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++)
        cin >> inp[i];
    for(int i = 0; i < k; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        cost[a - 1][b - 1] = c;
    }
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i < n; i++)
       //Try to make item (i) the first one you chose and then go and compute all other possible computations
       ans = max(ans, solve(i, 1 << i) + inp[i]);
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod 100000007
using namespace std;

ll n,m,d,a[25],u,v,w,dp[5][262150][25],val[25],sum,ans,add[25][25];
int main (){
	ios::sync_with_stdio(false);
	cin >> n >> m >> d;
	val[0]=1;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (i != 0)
		val[i]=val[i-1]*2;
	}
	for (int i=1;i<=d;i++){
		cin >> u >> v >> w;
		add[u-1][v-1]+=w;
	}
	for (int i=0;i<=1;i++){
		for (int j=0;j<262144;j++){
			for (int k=0;k<n;k++){
				dp[i][j][k]=-1e18;
			}
		}
	}
	for (int i=0;i<n;i++){
		dp[1][val[i]][i]=a[i];
	}
	for (int i=2;i<=m;i++){
		for (int j=0;j<262144;j++){
			for (int k=0;k<n;k++){
				for (int l=0;l<n;l++){
					if ((j&val[k]) != 0 && (val[l]&j) == 0)
					dp[i%2][j+val[l]][l]=max(dp[i%2][j+val[l]][l],dp[(i-1)%2][j][k]+add[k][l]+a[l]);
				}
			}
		}
	}
	for (int i=0;i<262144;i++){
		for (int j=0;j<n;j++){
			ans=max(ans,dp[m%2][i][j]);
		}
	}
	cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod 100000007
using namespace std;

ll n,m,d,a[25],u,v,w,dp[25][262150],val[25],sum,ans;
vector <pll> edge[25];
int main (){
	ios::sync_with_stdio(false);
	cin >> n >> m >> d;
	val[0]=1;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (i != 0)
		val[i]=val[i-1]*2;
	}
	for (int i=1;i<=d;i++){
		cin >> u >> v >> w;
		edge[u-1].pb(mp(v-1,w));
	}
	for (int i=0;i<=m;i++){
		for (int j=0;j<262144;j++){
			dp[i][j]=-1e18;
		}
	}
	dp[0][0]=0;
	for (int i=1;i<=m;i++){
		for (int j=0;j<262144;j++){
			for (int k=0;k<n;k++){
				if ((j&val[k]) == 0){
					sum=dp[i-1][j]+a[k];
					for (int l=0;l<edge[k].size();l++){
						if ((j&val[edge[k][l].x]) != 0)
						sum+=edge[k][l].y;
					}
					dp[i][j+val[k]]=max(dp[i][j+val[k]],sum);
				}
			}
		}
	}
	for (int i=0;i<262144;i++){
		ans=max(ans,dp[m][i]);
	}
	cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod 100000007
using namespace std;

ll n,m,d,a[25],u,v,w,dp[262150][25],val[25],sum,ans,add[25][25],masknum[262150];
int main (){
	ios::sync_with_stdio(false);
	cin >> n >> m >> d;
	val[0]=1;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (i != 0)
		val[i]=val[i-1]*2;
	}
	for (int i=1;i<=d;i++){
		cin >> u >> v >> w;
		add[u-1][v-1]+=w;
	}
	for (int i=0;i<262144;i++){
		for (int j=0;j<n;j++){
			dp[i][j]=-1e18;
			if ((i&val[j]) > 0)
			masknum[i]++;
		}
	}
	for (int i=0;i<n;i++){
		dp[val[i]][i]=a[i];
	}
	for (int j=0;j<262144;j++){
		for (int k=0;k<n;k++){
			for (int l=0;l<n;l++){
				if ((j&val[k]) != 0 && (val[l]&j) == 0)
				dp[j+val[l]][l]=max(dp[j+val[l]][l],dp[j][k]+add[k][l]+a[l]);
			}
		}
	}
	for (int i=0;i<262144;i++){
		for (int j=0;j<n;j++){
			if (masknum[i] == m)
			ans=max(ans,dp[i][j]);
		}
	}
	cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod 100000007
using namespace std;

ll n,m,d,a[25],u,v,w,dp[5][262150][25],val[25],sum,ans,add[25][25];
int main (){
	ios::sync_with_stdio(false);
	cin >> n >> m >> d;
	val[0]=1;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (i != 0)
		val[i]=val[i-1]*2;
	}
	for (int i=1;i<=d;i++){
		cin >> u >> v >> w;
		add[u-1][v-1]+=w;
	}
	for (int i=0;i<=1;i++){
		for (int j=0;j<262144;j++){
			for (int k=0;k<n;k++){
				dp[i][j][k]=-1e18;
			}
		}
	}
	dp[0][0][0]=0;
	for (int i=1;i<=m;i++){
		for (int j=0;j<262144;j++){
			for (int k=0;k<n;k++){
				for (int l=0;l<n;l++){
					if (((j&val[k]) != 0 || i == 1) && (val[l]&j) == 0)
					dp[i%2][j+val[l]][l]=max(dp[i%2][j+val[l]][l],dp[(i-1)%2][j][k]+add[k][l]+a[l]);
				}
			}
		}
	}
	for (int i=0;i<262144;i++){
		for (int j=0;j<n;j++){
			ans=max(ans,dp[m%2][i][j]);
		}
	}
	cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xmod 100000007
using namespace std;

ll n,m,d,a[25],u,v,w,dp[25][262150],val[25],sum,ans;
vector <pll> edge[25];
int main (){
	ios::sync_with_stdio(false);
	cin >> n >> m >> d;
	val[0]=1;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if (i != 0)
		val[i]=val[i-1]*2;
	}
	for (int i=1;i<=d;i++){
		cin >> u >> v >> w;
		edge[v-1].pb(mp(u-1,w));
	}
	for (int i=0;i<=m;i++){
		for (int j=0;j<262144;j++){
			dp[i][j]=-1e18;
		}
	}
	dp[0][0]=0;
	for (int i=1;i<=m;i++){
		for (int j=0;j<262144;j++){
			for (int k=0;k<n;k++){
				if ((j&val[k]) == 0){
					sum=dp[i-1][j]+a[k];
					for (int l=0;l<edge[k].size();l++){
						if ((j&val[edge[k][l].x]) != 0)
						sum+=edge[k][l].y;
					}
					dp[i][j+val[k]]=max(dp[i][j+val[k]],sum);
				}
			}
		}
	}
	for (int i=0;i<262144;i++){
		ans=max(ans,dp[m][i]);
	}
	cout << ans << "\n";
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;

int main() { boost;
	int n, m, k;
	cin >> n >> m >> k;

	vector <ll> a(n);
	vector <vector <ll> > dp((1 << n), vector <ll> (n, INT_MIN));

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dp[(1 << i)][i] = a[i];
	}

	vector <vector <ll> > bonus(n, vector <ll> (n, 0));
	for (int i = 0; i < k; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		bonus[x - 1][y - 1] = c;
	}

	ll ans = INT_MIN;
 	for (int mask = 0; mask < (1 << n); mask++) {
 		bool ok = (__builtin_popcount(mask) == m);

 		for (int i = 0; i < n; i++) {
 			if (ok) {
 				ans = max(ans, dp[mask][i]);
 			}
 			for (int j = 0; j < n; j++) {
 				if (mask & (1 << j)) {
 					continue;
 				}
 				int nmask = mask | (1 << j);
 				dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + bonus[i][j] + a[j]);
 			}
 		}
 	}

 	cout << ans << "\n";

 	return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define frp freopen("input.txt", "r", stdin); \
            freopen("output.txt", "w", stdout);

bool GetBit(int num, int i) {
    return (num & (1 << i));
}

int SetBit(int num, int i) {
    return (num | (1 << i));
}

int main() { //frp
    int n, m, k;
    cin >> n >> m >> k;

    vector <int> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector <vector <long long> > bonus(n, vector <long long> (n));

    for (int i = 0; i < k; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        bonus[x - 1][y - 1] = c;
    }

    vector <vector <long long> > dp((1 << n), vector <long long> (n));

    for (int i = 0; i < n; i++) {
        dp[(1 << i)][i] = a[i];
    }

    long long ans = 0;

    for (int mask = 1; mask < (1 << n); mask++) {

        bool equal = (__builtin_popcount(mask) == m);

        for (int i = 0; i < n; i++) {
            if (equal) {
                ans = max(ans, dp[mask][i]);
            }
            for (int j = 0; j < n; j++) {
                if (GetBit(mask, j)) {
                    continue;
                }
                int nmask = SetBit(mask, j);
                dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + bonus[i][j] + a[j]);
            }
        }
    }

    cout << ans;

    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define frp freopen("input.txt", "r", stdin); \
            freopen("output.txt", "w", stdout);

bool GetBit(int num, int i) {
    return (num & (1 << i));
}

int SetBit(int num, int i) {
    return (num | (1 << i));
}

int main() { //frp
    int n, m, k;
    cin >> n >> m >> k;

    vector <int> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector <vector <long long> > g(20, vector <long long> (20));

    for (int i = 0; i < k; k++) {
        int x, y, c;
        cin >> x >> y >> c;
        g[x - 1][y - 1] += c;
    }

    vector <vector <long long> > dp((1 << n), vector <long long> (n));

    for (int i = 0; i < n; i++) {
        dp[(1 << i)][i] = a[i];
    }

    long long ans = (int)-1e9;

    for (int mask = 1; mask < (1 << n); mask++) {

        bool equal = (__builtin_popcount(mask) == m);

        for (int i = 0; i < n; i++) {
            if (equal) {
                ans = max(ans, dp[mask][i]);
            }
            for (int j = 0; j < n; j++) {
                if (!GetBit(mask, j)) {
                    continue;
                }
                int nmask = SetBit(mask, j);
                dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + g[i][j] + a[j]);
            }
        }
    }

    cout << ans;

    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define frp freopen("input.txt", "r", stdin); \
            freopen("output.txt", "w", stdout);

bool GetBit(int num, int i) {
    return (num & (1 << i));
}

int SetBit(int num, int i) {
    return (num | (1 << i));
}

const long long INF = (long long)1e18;

int main() { //frp
    int n, m, k;
    cin >> n >> m >> k;

    vector <long long> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector <vector <long long> > bonus(n, vector <long long> (n));

    for (int i = 0; i < k; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        bonus[x - 1][y - 1] = c;
    }

    vector <vector <long long> > dp((1 << n), vector <long long> (n, -INF));

    for (int i = 0; i < n; i++) {
        dp[(1 << i)][i] = a[i];
    }

    long long ans = -INF;

    for (int mask = 1; mask < (1 << n); mask++) {

        bool equal = (__builtin_popcount(mask) == m);

        for (int i = 0; i < n; i++) {
            if (equal) {
                ans = max(ans, dp[mask][i]);
            }
            for (int j = 0; j < n; j++) {
                if (GetBit(mask, j)) {
                    continue;
                }
                int nmask = SetBit(mask, j);
                dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + bonus[i][j] + a[j]);
            }
        }
    }

    cout << ans;

    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define frp freopen("input.txt", "r", stdin); \
            freopen("output.txt", "w", stdout);

bool GetBit(int num, int i) {
    return (num & (1 << i));
}

int SetBit(int num, int i) {
    return (num | (1 << i));
}

int main() { //frp
    int n, m, k;
    cin >> n >> m >> k;

    vector <long long> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector <vector <long long> > bonus(n, vector <long long> (n));

    for (int i = 0; i < k; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        bonus[x - 1][y - 1] = c;
    }

    vector <vector <long long> > dp((1 << n), vector <long long> (n));

    for (int i = 0; i < n; i++) {
        dp[(1 << i)][i] = a[i];
    }

    long long ans = 0;

    for (int mask = 1; mask < (1 << n); mask++) {

        bool equal = (__builtin_popcount(mask) == m);

        for (int i = 0; i < n; i++) {
            if (equal) {
                ans = max(ans, dp[mask][i]);
            }
            for (int j = 0; j < n; j++) {
                if (GetBit(mask, j)) {
                    continue;
                }
                int nmask = SetBit(mask, j);
                dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + bonus[i][j] + a[j]);
            }
        }
    }

    cout << ans;

    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define frp freopen("input.txt", "r", stdin); \
            freopen("output.txt", "w", stdout);

bool GetBit(int num, int i) {
    return (num & (1 << i));
}

int SetBit(int num, int i) {
    return (num | (1 << i));
}

int main() { //frp
    int n, m, k;
    cin >> n >> m >> k;

    vector <int> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector <vector <long long> > bonus(n, vector <long long> (n));

    for (int i = 0; i < k; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        bonus[x - 1][y - 1] += c;
    }

    vector <vector <long long> > dp((1 << n), vector <long long> (n));

    for (int i = 0; i < n; i++) {
        dp[(1 << i)][i] = a[i];
    }

    long long ans = 0;

    for (int mask = 1; mask < (1 << n); mask++) {

        bool equal = (__builtin_popcount(mask) == m);

        for (int i = 0; i < n; i++) {
            if (equal) {
                ans = max(ans, dp[mask][i]);
            }
            for (int j = 0; j < n; j++) {
                if (GetBit(mask, j)) {
                    continue;
                }
                int nmask = SetBit(mask, j);
                dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + bonus[i][j] + a[j]);
            }
        }
    }

    cout << ans;

    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define frp freopen("input.txt", "r", stdin); \
            freopen("output.txt", "w", stdout);

bool GetBit(int num, int i) {
    return (num & (1 << i)) != 0;
}

int SetBit(int num, int i) {
    return (num | (1 << i));
}

int main() { //frp
    int n, m, k;
    cin >> n >> m >> k;

    vector <int> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector <vector <int> > g(20, vector <int> (20));

    for (int i = 0; i < k; k++) {
        int x, y, c;
        cin >> x >> y >> c;
        g[x - 1][y - 1] += c;
    }

    vector <vector <long long> > dp((1 << n), vector <long long> (n));

    for (int i = 0; i < n; i++) {
        dp[(1 << i)][i] = a[i];
    }

    long long ans = 0;

    for (int mask = 1; mask < (1 << n); mask++) {

        bool equal = (__builtin_popcount(mask) == m);

        for (int i = 0; i < n; i++) {
            if (equal) {
                ans = max(ans, dp[mask][i]);
            }
            for (int j = 0; j < n; j++) {
                if (!GetBit(mask, j)) {
                    continue;
                }
                int nmask = SetBit(mask, j);
                dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + g[i][j] + a[j]);
            }
        }
    }

    cout << ans;

    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define frp freopen("input.txt", "r", stdin); \
            freopen("output.txt", "w", stdout);

bool GetBit(int num, int i) {
    return (num & (1 << i)) != 0;
}

int SetBit(int num, int i) {
    return (num | (1 << i));
}

int main() { //frp
    int n, m, k;
    cin >> n >> m >> k;

    vector <int> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector <vector <int> > g(20, vector <int> (20));

    for (int i = 0; i < k; k++) {
        int x, y, c;
        cin >> x >> y >> c;
        g[x - 1][y - 1] = c;
    }

    vector <vector <int> > dp((1 << n), vector <int> (n, 0));
    int ans = 0;

    for (int mask = 0; mask < (1 << n); mask++) {

        bool equal = (__builtin_popcount(mask) == m);

        for (int i = 0; i < n; i++) {
            if (!GetBit(mask, i)) {
                continue;
            }
            if (equal) {
                ans = max(ans, dp[mask][i]);
            }
            for (int j = 0; j < n; j++) {
                if (!GetBit(mask, j)) {
                    continue;
                }
                int nmask = SetBit(mask, j);
                dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + g[i][j] + a[j]);
            }
        }
    }

    cout << ans;

    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;

int main() { boost;
	int n, m, k;
	cin >> n >> m >> k;

	vector <ll> a(n);
	vector <vector <ll> > dp((1 << n), vector <ll> (n, INT_MIN));

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		dp[(1 << i)][i] = a[i];
	}

	vector <vector <ll> > bonus(n, vector <ll> (n, 0));
	for (int i = 0; i < k; i++) {
		ll x, y, c;
		cin >> x >> y >> c;
		bonus[x - 1][y - 1] = c;
	}

 	for (int mask = 0; mask < (1 << n); mask++) {
 		for (int i = 0; i < n; i++) {
 			if (mask & (1 << i)) {
 			 	for (int j = 0; j < n; j++) {
					if (!(mask & (1 << j))) {
					 	int nmask = mask | (1 << j);

					 	dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + bonus[i][j] + a[j]);
					}
				}
 			}
 		}
 	}

 	ll ans = INT_MIN;
 	for (int mask = 0; mask < (1 << n); mask++) {
 		for (int i = 0; i < n; i++) {
 			if (__builtin_popcount(mask) == m)
 				ans = max(ans, dp[mask][i]);
 		}
 	}

	cout << ans << "\n";

 	return 0;
}


/*|In The Name of Allah|*/
/* Dear GCC compiler:
*
* If my code doesn't compile, this doesn't mean it's wrong.
* It just mean that you don't understand what I want.
* Here's my safety pig, I hope my code compile and get accepted.
* _._ _..._ .-',     _.._(`))
*'-. `     '  /-._.-'    ',/
*   )         \            '.
*  / _    _    |             \
* |  a    a    /              |
* \   .-.                     ;
*  '-('' ).-'       ,'       ;
*     '-;           |      .'
*        \           \    /
*        | 7  .__  _.-\   \
*        | |  |  ``/  /`  /
*       /,_|  |   /,_/   /
*          /,_/      '`-'
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace  __gnu_pbds;
long long  mood=1e14;

long long power(long long x, long long y,long long mood){
if (y == 0)
	return 1;
long long ret = power(x , y >> 1,mood) %mood ;
if (y % 2 == 0)
	return (ret * ret) % mood;
else
	return (x * (ret * ret % mood)) % mood;
}

pair<int, int> norm(pair<int, int> p)
{
	if(p.first < 0)
	{
		p.first *= -1;
		p.second *= -1;
	}
	else if (p.first == 0 && p.second < 0)
	{
		p.second *= -1;
	}
	int d = __gcd(abs(p.first), abs(p.second));
	p.first /= d;
	p.second /= d;
	return p;
}

/*

int parent[N], sz[N];
int n, m, components;

void init(){
  iota(parent, parent+N, 0);
  fill(sz, sz+N, 1);
  components = N;
}

int find(int u){
  if(parent[u] == u)  return u;
  return parent[u] = find(parent[u]);
}

void join(int u, int v){
  u = find(u), v = find(v);
  if(u == v)  return;
  if(sz[u] < sz[v]) swap(u, v);
  parent[v] = u;
  sz[u] += sz[v];
  --components;
}
int dst[N];
int vis[N];
int parent[N];
vector<vector<pair<int,ll>>>v(N);
void dikstra(){
	set<pair<ll,ll>>s;
	clr(dst,oo);
	clr(vis,0);
	clr(parent,-1);
	dst[1]=0;
	parent[1]=-1;
	s.insert( mp(0,1 ) );
	while(!s.empty()){

		pair<ll,ll> x=*s.begin();
		s.erase(s.begin());
		ll u=x.sc;
		ll d=x.fr;
		if (vis[u])continue;
		vis[u]=1;
		for (int i=0;i<v[u].size();i++){
			ll to=v[u][i].fr;
			ll cost=v[u][i].sc;
			if (vis[to]||d+cost>=dst[to])continue;
			dst[to]=d+cost;
			parent[to]=u;
			s.insert(mp(d+cost,to));
		}
	}

return;
}
void primeFactors(int n)
{
	while (n % 2 == 0){
		n = n/2;
	}

	for (int i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n % i == 0){
			cout << i << " ";
			n = n/i;
		}
	}
	if (n > 2){

	}
}

void Theaf(){
isPrime[0]=1;
isPrime[1]=1;
for (int i=2;i*i<=N;i++){
	if (isPrime[i]==1)continue;
	for (int cnt=2;i*cnt<=N;cnt++)isPrime[ cnt*i ]=1;
}

}
void dfs_EdgeClassification(int node)
{
	start[node] = timer++;

	rep(i, adj[node])
	{
		int child = adj[node][i];
		if (start[child] == -1)	// Not visited Before. Treed Edge
			dfs_EdgeClassification(child);
		else {
			if(finish[child] == -1)// then this is ancestor that called us and waiting us to finish. Then Cycle. Back Edge
				anyCycle = 1;
			else if(start[node] < start[child])	// then you are my descendant
				;	// Forward Edge
			else
				;	// Cross Edge
		}
	}

	finish[node] = timer++;
}

vectorll factorization(ll n) 	 max n is 1e12
{	// O( sqrt(n) )

	vectorll primes;

	for (ll i = 2; i  i * i <= n; ++i)	 Improve start by i = 3.
		while (n % i == 0)
			primes.push_back(i), n /= i;	 Get every prime inside n.	n  i^j	is a new number

	 Two ways to prove that n will be prime number if n  1
	 1) Think in n  pi^x as a NEW sub-problem. If we went to its sqrt and % applied, then we are facing a prime number
	 2) Prove that, for any n either all its primes before sqrt(n), or only the biggest prime after sqrt(n).
	if (n  > 1)
		primes.push_back(n);

	return primes;
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

	ordered_set X;
	X.insert(1);
	X.insert(2);
	X.insert(4);
	X.insert(8);
	X.insert(16);

	0 1 2 3 4
	1 2 4 8 16
	cout<<*X.find_by_order(1)<<endl; // 2
	cout<<*X.find_by_order(2)<<endl; // 4
	cout<<*X.find_by_order(4)<<endl; // 16
	cout<<(end(X)==X.find_by_order(6))<<endl; // true

	cout<<X.order_of_key(-5)<<endl;  // 0
	cout<<X.order_of_key(1)<<endl;   // 0
	cout<<X.order_of_key(3)<<endl;   // 2
	cout<<X.order_of_key(4)<<endl;   // 2
	cout<<X.order_of_key(400)<<endl; // 5

int t = 0;

ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

*/
const double Eps =(1e-7);
int dcmp(double x,double y){ return fabs(x-y)<=Eps? 0: x<y ?-1:1; }
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_setpair;
typedef long long  ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> pii;
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define el	'\n'
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define lp1(i,n) for(int i = 1;i <= int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define SS stringstream
#define ll long long
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
const long long  P = (31);
const long long  key2 = 59;
int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, 1, 1, -1 };
int kx[] = { 2, 2, 1, -1, -2, -2, 1, -1 };
int ky[] = { 1, -1, 2, 2, 1, -1, -2, -2 };
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b % a, a);}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int setBit(int num,int idx,int val){return val?(num|(1<<idx)): (num&(~(1<<idx)));}
int getBit(int num,int idx){return 	((num>>idx)&1)==1;}

ll const N = 5e6+9, mod = 1e14+7 ,  oo = 1e16+7;

//------------------------------------------------------------------------------------

int n,m,k;
int happy[N];
ll dp[1<<19][19];
map<pii,int>rules;
ll solve(int mask,int prev){
ll &ret=dp[mask][prev];
if (ret!=-1)return ret;
if (bits(mask)==m)return 0;
ret=-oo;
lp(i,n){
ll s=0;
int nmask=mask;
if (!getBit(nmask,i)){
	nmask=setBit(nmask,i,1);
	s+=happy[i];
	s+=rules[ mp(prev,i) ];
	ret=max(ret,solve(nmask,i)+s);
}
}
return ret;
}

int main()
{
	fastIO;
	cin>>n>>m>>k;
	lp(i,n)cin>>happy[i];
	lp(i,k){
		int x,y,c;
		cin>>x>>y>>c;
		x--;
		y--;
	rules[mp(x,y)]=c;
	}
	clr(dp,-1);
	cout<<(ll)solve(0,n);
/*
*/
return 0;
}


/*|In The Name of Allah|*/
/* Dear GCC compiler:
*
* If my code doesn't compile, this doesn't mean it's wrong.
* It just mean that you don't understand what I want.
* Here's my safety pig, I hope my code compile and get accepted.
* _._ _..._ .-',     _.._(`))
*'-. `     '  /-._.-'    ',/
*   )         \            '.
*  / _    _    |             \
* |  a    a    /              |
* \   .-.                     ;
*  '-('' ).-'       ,'       ;
*     '-;           |      .'
*        \           \    /
*        | 7  .__  _.-\   \
*        | |  |  ``/  /`  /
*       /,_|  |   /,_/   /
*          /,_/      '`-'
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace  __gnu_pbds;
long long  mood=1e14;

long long power(long long x, long long y,long long mood){
if (y == 0)
	return 1;
long long ret = power(x , y >> 1,mood) %mood ;
if (y % 2 == 0)
	return (ret * ret) % mood;
else
	return (x * (ret * ret % mood)) % mood;
}

pair<int, int> norm(pair<int, int> p)
{
	if(p.first < 0)
	{
		p.first *= -1;
		p.second *= -1;
	}
	else if (p.first == 0 && p.second < 0)
	{
		p.second *= -1;
	}
	int d = __gcd(abs(p.first), abs(p.second));
	p.first /= d;
	p.second /= d;
	return p;
}

/*

int parent[N], sz[N];
int n, m, components;

void init(){
  iota(parent, parent+N, 0);
  fill(sz, sz+N, 1);
  components = N;
}

int find(int u){
  if(parent[u] == u)  return u;
  return parent[u] = find(parent[u]);
}

void join(int u, int v){
  u = find(u), v = find(v);
  if(u == v)  return;
  if(sz[u] < sz[v]) swap(u, v);
  parent[v] = u;
  sz[u] += sz[v];
  --components;
}
int dst[N];
int vis[N];
int parent[N];
vector<vector<pair<int,ll>>>v(N);
void dikstra(){
	set<pair<ll,ll>>s;
	clr(dst,oo);
	clr(vis,0);
	clr(parent,-1);
	dst[1]=0;
	parent[1]=-1;
	s.insert( mp(0,1 ) );
	while(!s.empty()){

		pair<ll,ll> x=*s.begin();
		s.erase(s.begin());
		ll u=x.sc;
		ll d=x.fr;
		if (vis[u])continue;
		vis[u]=1;
		for (int i=0;i<v[u].size();i++){
			ll to=v[u][i].fr;
			ll cost=v[u][i].sc;
			if (vis[to]||d+cost>=dst[to])continue;
			dst[to]=d+cost;
			parent[to]=u;
			s.insert(mp(d+cost,to));
		}
	}

return;
}
void primeFactors(int n)
{
	while (n % 2 == 0){
		n = n/2;
	}

	for (int i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n % i == 0){
			cout << i << " ";
			n = n/i;
		}
	}
	if (n > 2){

	}
}

void Theaf(){
isPrime[0]=1;
isPrime[1]=1;
for (int i=2;i*i<=N;i++){
	if (isPrime[i]==1)continue;
	for (int cnt=2;i*cnt<=N;cnt++)isPrime[ cnt*i ]=1;
}

}
void dfs_EdgeClassification(int node)
{
	start[node] = timer++;

	rep(i, adj[node])
	{
		int child = adj[node][i];
		if (start[child] == -1)	// Not visited Before. Treed Edge
			dfs_EdgeClassification(child);
		else {
			if(finish[child] == -1)// then this is ancestor that called us and waiting us to finish. Then Cycle. Back Edge
				anyCycle = 1;
			else if(start[node] < start[child])	// then you are my descendant
				;	// Forward Edge
			else
				;	// Cross Edge
		}
	}

	finish[node] = timer++;
}

vectorll factorization(ll n) 	 max n is 1e12
{	// O( sqrt(n) )

	vectorll primes;

	for (ll i = 2; i  i * i <= n; ++i)	 Improve start by i = 3.
		while (n % i == 0)
			primes.push_back(i), n /= i;	 Get every prime inside n.	n  i^j	is a new number

	 Two ways to prove that n will be prime number if n  1
	 1) Think in n  pi^x as a NEW sub-problem. If we went to its sqrt and % applied, then we are facing a prime number
	 2) Prove that, for any n either all its primes before sqrt(n), or only the biggest prime after sqrt(n).
	if (n  > 1)
		primes.push_back(n);

	return primes;
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

	ordered_set X;
	X.insert(1);
	X.insert(2);
	X.insert(4);
	X.insert(8);
	X.insert(16);

	0 1 2 3 4
	1 2 4 8 16
	cout<<*X.find_by_order(1)<<endl; // 2
	cout<<*X.find_by_order(2)<<endl; // 4
	cout<<*X.find_by_order(4)<<endl; // 16
	cout<<(end(X)==X.find_by_order(6))<<endl; // true

	cout<<X.order_of_key(-5)<<endl;  // 0
	cout<<X.order_of_key(1)<<endl;   // 0
	cout<<X.order_of_key(3)<<endl;   // 2
	cout<<X.order_of_key(4)<<endl;   // 2
	cout<<X.order_of_key(400)<<endl; // 5

int t = 0;

ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

*/
const double Eps =(1e-7);
int dcmp(double x,double y){ return fabs(x-y)<=Eps? 0: x<y ?-1:1; }
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_setpair;
typedef long long  ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> pii;
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define el	'\n'
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define lp1(i,n) for(int i = 1;i <= int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define SS stringstream
#define ll long long
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
const long long  P = (31);
const long long  key2 = 59;
int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, 1, 1, -1 };
int kx[] = { 2, 2, 1, -1, -2, -2, 1, -1 };
int ky[] = { 1, -1, 2, 2, 1, -1, -2, -2 };
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b % a, a);}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int setBit(int num,int idx,int val){return val?(num|(1<<idx)): (num&(~(1<<idx)));}
int getBit(int num,int idx){return 	((num>>idx)&1)==1;}

ll const N = 5e6+9, mod = 1e14+7 ,  oo = 1e14+7;

//------------------------------------------------------------------------------------

int n,m,k;
int happy[N];
ll dp[1<<19][19];
map<pii,int>rules;
ll solve(int mask,int prev){
ll &ret=dp[mask][prev];
if (ret!=-1)return ret;
if (bits(mask)==m)return 0;
ret=0;
lp(i,n){
ll s=0;
int nmask=mask;
if (!getBit(nmask,i)){
	nmask=setBit(nmask,i,1);
	s+=happy[i];
	s+=rules[ mp(prev,i) ];
	ret=max(ret,solve(nmask,i)+s);
}
}
return ret;
}

int main()
{
	fastIO;
	cin>>n>>m>>k;
	lp(i,n)cin>>happy[i];
	lp(i,k){
		int x,y,c;
		cin>>x>>y>>c;
		x--;
		y--;
	rules[mp(x,y)]=c;
	}
	clr(dp,-1);
	cout<<(ll)solve(0,0);
/*
*/
return 0;
}


/*|In The Name of Allah|*/
/* Dear GCC compiler:
*
* If my code doesn't compile, this doesn't mean it's wrong.
* It just mean that you don't understand what I want.
* Here's my safety pig, I hope my code compile and get accepted.
* _._ _..._ .-',     _.._(`))
*'-. `     '  /-._.-'    ',/
*   )         \            '.
*  / _    _    |             \
* |  a    a    /              |
* \   .-.                     ;
*  '-('' ).-'       ,'       ;
*     '-;           |      .'
*        \           \    /
*        | 7  .__  _.-\   \
*        | |  |  ``/  /`  /
*       /,_|  |   /,_/   /
*          /,_/      '`-'
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace  __gnu_pbds;
long long  mood=1e14;

long long power(long long x, long long y,long long mood){
if (y == 0)
	return 1;
long long ret = power(x , y >> 1,mood) %mood ;
if (y % 2 == 0)
	return (ret * ret) % mood;
else
	return (x * (ret * ret % mood)) % mood;
}

pair<int, int> norm(pair<int, int> p)
{
	if(p.first < 0)
	{
		p.first *= -1;
		p.second *= -1;
	}
	else if (p.first == 0 && p.second < 0)
	{
		p.second *= -1;
	}
	int d = __gcd(abs(p.first), abs(p.second));
	p.first /= d;
	p.second /= d;
	return p;
}

/*

int parent[N], sz[N];
int n, m, components;

void init(){
  iota(parent, parent+N, 0);
  fill(sz, sz+N, 1);
  components = N;
}

int find(int u){
  if(parent[u] == u)  return u;
  return parent[u] = find(parent[u]);
}

void join(int u, int v){
  u = find(u), v = find(v);
  if(u == v)  return;
  if(sz[u] < sz[v]) swap(u, v);
  parent[v] = u;
  sz[u] += sz[v];
  --components;
}
int dst[N];
int vis[N];
int parent[N];
vector<vector<pair<int,ll>>>v(N);
void dikstra(){
	set<pair<ll,ll>>s;
	clr(dst,oo);
	clr(vis,0);
	clr(parent,-1);
	dst[1]=0;
	parent[1]=-1;
	s.insert( mp(0,1 ) );
	while(!s.empty()){

		pair<ll,ll> x=*s.begin();
		s.erase(s.begin());
		ll u=x.sc;
		ll d=x.fr;
		if (vis[u])continue;
		vis[u]=1;
		for (int i=0;i<v[u].size();i++){
			ll to=v[u][i].fr;
			ll cost=v[u][i].sc;
			if (vis[to]||d+cost>=dst[to])continue;
			dst[to]=d+cost;
			parent[to]=u;
			s.insert(mp(d+cost,to));
		}
	}

return;
}
void primeFactors(int n)
{
	while (n % 2 == 0){
		n = n/2;
	}

	for (int i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n % i == 0){
			cout << i << " ";
			n = n/i;
		}
	}
	if (n > 2){

	}
}

void Theaf(){
isPrime[0]=1;
isPrime[1]=1;
for (int i=2;i*i<=N;i++){
	if (isPrime[i]==1)continue;
	for (int cnt=2;i*cnt<=N;cnt++)isPrime[ cnt*i ]=1;
}

}
void dfs_EdgeClassification(int node)
{
	start[node] = timer++;

	rep(i, adj[node])
	{
		int child = adj[node][i];
		if (start[child] == -1)	// Not visited Before. Treed Edge
			dfs_EdgeClassification(child);
		else {
			if(finish[child] == -1)// then this is ancestor that called us and waiting us to finish. Then Cycle. Back Edge
				anyCycle = 1;
			else if(start[node] < start[child])	// then you are my descendant
				;	// Forward Edge
			else
				;	// Cross Edge
		}
	}

	finish[node] = timer++;
}

vectorll factorization(ll n) 	 max n is 1e12
{	// O( sqrt(n) )

	vectorll primes;

	for (ll i = 2; i  i * i <= n; ++i)	 Improve start by i = 3.
		while (n % i == 0)
			primes.push_back(i), n /= i;	 Get every prime inside n.	n  i^j	is a new number

	 Two ways to prove that n will be prime number if n  1
	 1) Think in n  pi^x as a NEW sub-problem. If we went to its sqrt and % applied, then we are facing a prime number
	 2) Prove that, for any n either all its primes before sqrt(n), or only the biggest prime after sqrt(n).
	if (n  > 1)
		primes.push_back(n);

	return primes;
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

	ordered_set X;
	X.insert(1);
	X.insert(2);
	X.insert(4);
	X.insert(8);
	X.insert(16);

	0 1 2 3 4
	1 2 4 8 16
	cout<<*X.find_by_order(1)<<endl; // 2
	cout<<*X.find_by_order(2)<<endl; // 4
	cout<<*X.find_by_order(4)<<endl; // 16
	cout<<(end(X)==X.find_by_order(6))<<endl; // true

	cout<<X.order_of_key(-5)<<endl;  // 0
	cout<<X.order_of_key(1)<<endl;   // 0
	cout<<X.order_of_key(3)<<endl;   // 2
	cout<<X.order_of_key(4)<<endl;   // 2
	cout<<X.order_of_key(400)<<endl; // 5

int t = 0;

ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

*/
const double Eps =(1e-7);
int dcmp(double x,double y){ return fabs(x-y)<=Eps? 0: x<y ?-1:1; }
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_setpair;
typedef long long  ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> pii;
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define el	'\n'
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define lp1(i,n) for(int i = 1;i <= int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define SS stringstream
#define ll long long
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
const long long  P = (31);
const long long  key2 = 59;
int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, 1, 1, -1 };
int kx[] = { 2, 2, 1, -1, -2, -2, 1, -1 };
int ky[] = { 1, -1, 2, 2, 1, -1, -2, -2 };
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b % a, a);}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int setBit(int num,int idx,int val){return val?(num|(1<<idx)): (num&(~(1<<idx)));}
int getBit(int num,int idx){return 	((num>>idx)&1)==1;}

ll const N = 5e6+9, mod = 1e14+7 ,  oo = 1e16+7;

//------------------------------------------------------------------------------------

int n,m,k;
int happy[N];
ll dp[1<<19][19];
map<pii,int>rules;
ll solve(int mask,int prev){
ll &ret=dp[mask][prev];
if (ret!=-1)return ret;
if (bits(mask)==m)return 0;
ret=-oo;
lp(i,n){
ll s=0;
int nmask=mask;
if (!getBit(nmask,i)){
	nmask=setBit(nmask,i,1);
	s+=happy[i];
	s+=rules[ mp(prev,i) ];
	ret=max(ret,solve(nmask,i)+s);
}
}
return ret;
}

int main()
{
	fastIO;
	cin>>n>>m>>k;
	lp(i,n)cin>>happy[i];
	lp(i,k){
		int x,y,c;
		cin>>x>>y>>c;
		x--;
		y--;
	rules[mp(x,y)]=c;
	}
	clr(dp,-1);
	cout<<(ll)solve(0,0);
/*
*/
return 0;
}


/*|In The Name of Allah|*/
/* Dear GCC compiler:
*
* If my code doesn't compile, this doesn't mean it's wrong.
* It just mean that you don't understand what I want.
* Here's my safety pig, I hope my code compile and get accepted.
* _._ _..._ .-',     _.._(`))
*'-. `     '  /-._.-'    ',/
*   )         \            '.
*  / _    _    |             \
* |  a    a    /              |
* \   .-.                     ;
*  '-('' ).-'       ,'       ;
*     '-;           |      .'
*        \           \    /
*        | 7  .__  _.-\   \
*        | |  |  ``/  /`  /
*       /,_|  |   /,_/   /
*          /,_/      '`-'
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace  __gnu_pbds;
long long  mood=1e14;

long long power(long long x, long long y,long long mood){
if (y == 0)
	return 1;
long long ret = power(x , y >> 1,mood) %mood ;
if (y % 2 == 0)
	return (ret * ret) % mood;
else
	return (x * (ret * ret % mood)) % mood;
}

pair<int, int> norm(pair<int, int> p)
{
	if(p.first < 0)
	{
		p.first *= -1;
		p.second *= -1;
	}
	else if (p.first == 0 && p.second < 0)
	{
		p.second *= -1;
	}
	int d = __gcd(abs(p.first), abs(p.second));
	p.first /= d;
	p.second /= d;
	return p;
}

/*

int parent[N], sz[N];
int n, m, components;

void init(){
  iota(parent, parent+N, 0);
  fill(sz, sz+N, 1);
  components = N;
}

int find(int u){
  if(parent[u] == u)  return u;
  return parent[u] = find(parent[u]);
}

void join(int u, int v){
  u = find(u), v = find(v);
  if(u == v)  return;
  if(sz[u] < sz[v]) swap(u, v);
  parent[v] = u;
  sz[u] += sz[v];
  --components;
}
int dst[N];
int vis[N];
int parent[N];
vector<vector<pair<int,ll>>>v(N);
void dikstra(){
	set<pair<ll,ll>>s;
	clr(dst,oo);
	clr(vis,0);
	clr(parent,-1);
	dst[1]=0;
	parent[1]=-1;
	s.insert( mp(0,1 ) );
	while(!s.empty()){

		pair<ll,ll> x=*s.begin();
		s.erase(s.begin());
		ll u=x.sc;
		ll d=x.fr;
		if (vis[u])continue;
		vis[u]=1;
		for (int i=0;i<v[u].size();i++){
			ll to=v[u][i].fr;
			ll cost=v[u][i].sc;
			if (vis[to]||d+cost>=dst[to])continue;
			dst[to]=d+cost;
			parent[to]=u;
			s.insert(mp(d+cost,to));
		}
	}

return;
}
void primeFactors(int n)
{
	while (n % 2 == 0){
		n = n/2;
	}

	for (int i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n % i == 0){
			cout << i << " ";
			n = n/i;
		}
	}
	if (n > 2){

	}
}

void Theaf(){
isPrime[0]=1;
isPrime[1]=1;
for (int i=2;i*i<=N;i++){
	if (isPrime[i]==1)continue;
	for (int cnt=2;i*cnt<=N;cnt++)isPrime[ cnt*i ]=1;
}

}
void dfs_EdgeClassification(int node)
{
	start[node] = timer++;

	rep(i, adj[node])
	{
		int child = adj[node][i];
		if (start[child] == -1)	// Not visited Before. Treed Edge
			dfs_EdgeClassification(child);
		else {
			if(finish[child] == -1)// then this is ancestor that called us and waiting us to finish. Then Cycle. Back Edge
				anyCycle = 1;
			else if(start[node] < start[child])	// then you are my descendant
				;	// Forward Edge
			else
				;	// Cross Edge
		}
	}

	finish[node] = timer++;
}

vectorll factorization(ll n) 	 max n is 1e12
{	// O( sqrt(n) )

	vectorll primes;

	for (ll i = 2; i  i * i <= n; ++i)	 Improve start by i = 3.
		while (n % i == 0)
			primes.push_back(i), n /= i;	 Get every prime inside n.	n  i^j	is a new number

	 Two ways to prove that n will be prime number if n  1
	 1) Think in n  pi^x as a NEW sub-problem. If we went to its sqrt and % applied, then we are facing a prime number
	 2) Prove that, for any n either all its primes before sqrt(n), or only the biggest prime after sqrt(n).
	if (n  > 1)
		primes.push_back(n);

	return primes;
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

	ordered_set X;
	X.insert(1);
	X.insert(2);
	X.insert(4);
	X.insert(8);
	X.insert(16);

	0 1 2 3 4
	1 2 4 8 16
	cout<<*X.find_by_order(1)<<endl; // 2
	cout<<*X.find_by_order(2)<<endl; // 4
	cout<<*X.find_by_order(4)<<endl; // 16
	cout<<(end(X)==X.find_by_order(6))<<endl; // true

	cout<<X.order_of_key(-5)<<endl;  // 0
	cout<<X.order_of_key(1)<<endl;   // 0
	cout<<X.order_of_key(3)<<endl;   // 2
	cout<<X.order_of_key(4)<<endl;   // 2
	cout<<X.order_of_key(400)<<endl; // 5

int t = 0;

ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

*/
const double Eps =(1e-7);
int dcmp(double x,double y){ return fabs(x-y)<=Eps? 0: x<y ?-1:1; }
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_setpair;
typedef long long  ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> pii;
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define el	'\n'
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define lp1(i,n) for(int i = 1;i <= int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define SS stringstream
#define ll long long
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
const long long  P = (31);
const long long  key2 = 59;
int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, 1, 1, -1 };
int kx[] = { 2, 2, 1, -1, -2, -2, 1, -1 };
int ky[] = { 1, -1, 2, 2, 1, -1, -2, -2 };
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b % a, a);}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int setBit(int num,int idx,int val){return val?(num|(1<<idx)): (num&(~(1<<idx)));}
int getBit(int num,int idx){return 	((num>>idx)&1)==1;}

ll const N = 5e6+9, mod = 1e14+7 ,  oo = 1e14+7;

//------------------------------------------------------------------------------------

int n,m,k;
int happy[N];
ll dp[1>>18][18];
map<pii,int>rules;
ll solve(int mask,int prev){
ll &ret=dp[mask][prev];
if (ret!=-1)return ret;
if (bits(mask)==m)return 0;
ret=0;
lp(i,n){
ll s=0;
int nmask=mask;
if (!getBit(nmask,i)){
	nmask=setBit(nmask,i,1);
	s+=happy[i];
	s+=rules[ mp(prev,i) ];
	ret=max(ret,solve(nmask,i)+s);
}
}
return ret;
}

int main()
{
	fastIO;
	cin>>n>>m>>k;
	lp(i,n)cin>>happy[i];
	lp(i,k){
		int x,y,c;
		cin>>x>>y>>c;
		x--;
		y--;
	rules[mp(x,y)]=c;
	}
	clr(dp,-1);
	cout<<(ll)solve(0,0);
/*
*/
return 0;
}


/*|In The Name of Allah|*/
/* Dear GCC compiler:
*
* If my code doesn't compile, this doesn't mean it's wrong.
* It just mean that you don't understand what I want.
* Here's my safety pig, I hope my code compile and get accepted.
* _._ _..._ .-',     _.._(`))
*'-. `     '  /-._.-'    ',/
*   )         \            '.
*  / _    _    |             \
* |  a    a    /              |
* \   .-.                     ;
*  '-('' ).-'       ,'       ;
*     '-;           |      .'
*        \           \    /
*        | 7  .__  _.-\   \
*        | |  |  ``/  /`  /
*       /,_|  |   /,_/   /
*          /,_/      '`-'
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace  __gnu_pbds;
long long  mood=1e14;

long long power(long long x, long long y,long long mood){
if (y == 0)
	return 1;
long long ret = power(x , y >> 1,mood) %mood ;
if (y % 2 == 0)
	return (ret * ret) % mood;
else
	return (x * (ret * ret % mood)) % mood;
}

pair<int, int> norm(pair<int, int> p)
{
	if(p.first < 0)
	{
		p.first *= -1;
		p.second *= -1;
	}
	else if (p.first == 0 && p.second < 0)
	{
		p.second *= -1;
	}
	int d = __gcd(abs(p.first), abs(p.second));
	p.first /= d;
	p.second /= d;
	return p;
}

/*

int parent[N], sz[N];
int n, m, components;

void init(){
  iota(parent, parent+N, 0);
  fill(sz, sz+N, 1);
  components = N;
}

int find(int u){
  if(parent[u] == u)  return u;
  return parent[u] = find(parent[u]);
}

void join(int u, int v){
  u = find(u), v = find(v);
  if(u == v)  return;
  if(sz[u] < sz[v]) swap(u, v);
  parent[v] = u;
  sz[u] += sz[v];
  --components;
}
int dst[N];
int vis[N];
int parent[N];
vector<vector<pair<int,ll>>>v(N);
void dikstra(){
	set<pair<ll,ll>>s;
	clr(dst,oo);
	clr(vis,0);
	clr(parent,-1);
	dst[1]=0;
	parent[1]=-1;
	s.insert( mp(0,1 ) );
	while(!s.empty()){

		pair<ll,ll> x=*s.begin();
		s.erase(s.begin());
		ll u=x.sc;
		ll d=x.fr;
		if (vis[u])continue;
		vis[u]=1;
		for (int i=0;i<v[u].size();i++){
			ll to=v[u][i].fr;
			ll cost=v[u][i].sc;
			if (vis[to]||d+cost>=dst[to])continue;
			dst[to]=d+cost;
			parent[to]=u;
			s.insert(mp(d+cost,to));
		}
	}

return;
}
void primeFactors(int n)
{
	while (n % 2 == 0){
		n = n/2;
	}

	for (int i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n % i == 0){
			cout << i << " ";
			n = n/i;
		}
	}
	if (n > 2){

	}
}

void Theaf(){
isPrime[0]=1;
isPrime[1]=1;
for (int i=2;i*i<=N;i++){
	if (isPrime[i]==1)continue;
	for (int cnt=2;i*cnt<=N;cnt++)isPrime[ cnt*i ]=1;
}

}
void dfs_EdgeClassification(int node)
{
	start[node] = timer++;

	rep(i, adj[node])
	{
		int child = adj[node][i];
		if (start[child] == -1)	// Not visited Before. Treed Edge
			dfs_EdgeClassification(child);
		else {
			if(finish[child] == -1)// then this is ancestor that called us and waiting us to finish. Then Cycle. Back Edge
				anyCycle = 1;
			else if(start[node] < start[child])	// then you are my descendant
				;	// Forward Edge
			else
				;	// Cross Edge
		}
	}

	finish[node] = timer++;
}

vectorll factorization(ll n) 	 max n is 1e12
{	// O( sqrt(n) )

	vectorll primes;

	for (ll i = 2; i  i * i <= n; ++i)	 Improve start by i = 3.
		while (n % i == 0)
			primes.push_back(i), n /= i;	 Get every prime inside n.	n  i^j	is a new number

	 Two ways to prove that n will be prime number if n  1
	 1) Think in n  pi^x as a NEW sub-problem. If we went to its sqrt and % applied, then we are facing a prime number
	 2) Prove that, for any n either all its primes before sqrt(n), or only the biggest prime after sqrt(n).
	if (n  > 1)
		primes.push_back(n);

	return primes;
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

	ordered_set X;
	X.insert(1);
	X.insert(2);
	X.insert(4);
	X.insert(8);
	X.insert(16);

	0 1 2 3 4
	1 2 4 8 16
	cout<<*X.find_by_order(1)<<endl; // 2
	cout<<*X.find_by_order(2)<<endl; // 4
	cout<<*X.find_by_order(4)<<endl; // 16
	cout<<(end(X)==X.find_by_order(6))<<endl; // true

	cout<<X.order_of_key(-5)<<endl;  // 0
	cout<<X.order_of_key(1)<<endl;   // 0
	cout<<X.order_of_key(3)<<endl;   // 2
	cout<<X.order_of_key(4)<<endl;   // 2
	cout<<X.order_of_key(400)<<endl; // 5

int t = 0;

ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

*/
const double Eps =(1e-7);
int dcmp(double x,double y){ return fabs(x-y)<=Eps? 0: x<y ?-1:1; }
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_setpair;
typedef long long  ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> pii;
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define el	'\n'
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define lp1(i,n) for(int i = 1;i <= int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define SS stringstream
#define ll long long
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
const long long  P = (31);
const long long  key2 = 59;
int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, 1, 1, -1 };
int kx[] = { 2, 2, 1, -1, -2, -2, 1, -1 };
int ky[] = { 1, -1, 2, 2, 1, -1, -2, -2 };
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b % a, a);}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int setBit(int num,int idx,int val){return val?(num|(1<<idx)): (num&(~(1<<idx)));}
int getBit(int num,int idx){return 	((num>>idx)&1)==1;}

ll const N = 5e6+9, mod = 1e14+7 ,  oo = 1e14+7;

//------------------------------------------------------------------------------------

int n,m,k;
int happy[N];
ll dp[1<<18][19];
map<pii,int>rules;
ll solve(int mask,int prev){
ll &ret=dp[mask][prev];
if (ret!=-1)return ret;
if (bits(mask)==m)return 0;
ret=0;
lp(i,n){
ll s=0;
int nmask=mask;
if (!getBit(nmask,i)){
	nmask=setBit(nmask,i,1);
	s+=happy[i];
	s+=rules[ mp(prev,i) ];
	ret=max(ret,solve(nmask,i)+s);
}
}
return ret;
}

int main()
{
	fastIO;
	cin>>n>>m>>k;
	lp(i,n)cin>>happy[i];
	lp(i,k){
		int x,y,c;
		cin>>x>>y>>c;
		x--;
		y--;
	rules[mp(x,y)]=c;
	}
	clr(dp,-1);
	cout<<(ll)solve(0,0);
/*
*/
return 0;
}


/*|In The Name of Allah|*/
/* Dear GCC compiler:
*
* If my code doesn't compile, this doesn't mean it's wrong.
* It just mean that you don't understand what I want.
* Here's my safety pig, I hope my code compile and get accepted.
* _._ _..._ .-',     _.._(`))
*'-. `     '  /-._.-'    ',/
*   )         \            '.
*  / _    _    |             \
* |  a    a    /              |
* \   .-.                     ;
*  '-('' ).-'       ,'       ;
*     '-;           |      .'
*        \           \    /
*        | 7  .__  _.-\   \
*        | |  |  ``/  /`  /
*       /,_|  |   /,_/   /
*          /,_/      '`-'
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace  __gnu_pbds;
long long  mood=1e14;

long long power(long long x, long long y,long long mood){
if (y == 0)
	return 1;
long long ret = power(x , y >> 1,mood) %mood ;
if (y % 2 == 0)
	return (ret * ret) % mood;
else
	return (x * (ret * ret % mood)) % mood;
}

pair<int, int> norm(pair<int, int> p)
{
	if(p.first < 0)
	{
		p.first *= -1;
		p.second *= -1;
	}
	else if (p.first == 0 && p.second < 0)
	{
		p.second *= -1;
	}
	int d = __gcd(abs(p.first), abs(p.second));
	p.first /= d;
	p.second /= d;
	return p;
}

/*

int parent[N], sz[N];
int n, m, components;

void init(){
  iota(parent, parent+N, 0);
  fill(sz, sz+N, 1);
  components = N;
}

int find(int u){
  if(parent[u] == u)  return u;
  return parent[u] = find(parent[u]);
}

void join(int u, int v){
  u = find(u), v = find(v);
  if(u == v)  return;
  if(sz[u] < sz[v]) swap(u, v);
  parent[v] = u;
  sz[u] += sz[v];
  --components;
}
int dst[N];
int vis[N];
int parent[N];
vector<vector<pair<int,ll>>>v(N);
void dikstra(){
	set<pair<ll,ll>>s;
	clr(dst,oo);
	clr(vis,0);
	clr(parent,-1);
	dst[1]=0;
	parent[1]=-1;
	s.insert( mp(0,1 ) );
	while(!s.empty()){

		pair<ll,ll> x=*s.begin();
		s.erase(s.begin());
		ll u=x.sc;
		ll d=x.fr;
		if (vis[u])continue;
		vis[u]=1;
		for (int i=0;i<v[u].size();i++){
			ll to=v[u][i].fr;
			ll cost=v[u][i].sc;
			if (vis[to]||d+cost>=dst[to])continue;
			dst[to]=d+cost;
			parent[to]=u;
			s.insert(mp(d+cost,to));
		}
	}

return;
}
void primeFactors(int n)
{
	while (n % 2 == 0){
		n = n/2;
	}

	for (int i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n % i == 0){
			cout << i << " ";
			n = n/i;
		}
	}
	if (n > 2){

	}
}

void Theaf(){
isPrime[0]=1;
isPrime[1]=1;
for (int i=2;i*i<=N;i++){
	if (isPrime[i]==1)continue;
	for (int cnt=2;i*cnt<=N;cnt++)isPrime[ cnt*i ]=1;
}

}
void dfs_EdgeClassification(int node)
{
	start[node] = timer++;

	rep(i, adj[node])
	{
		int child = adj[node][i];
		if (start[child] == -1)	// Not visited Before. Treed Edge
			dfs_EdgeClassification(child);
		else {
			if(finish[child] == -1)// then this is ancestor that called us and waiting us to finish. Then Cycle. Back Edge
				anyCycle = 1;
			else if(start[node] < start[child])	// then you are my descendant
				;	// Forward Edge
			else
				;	// Cross Edge
		}
	}

	finish[node] = timer++;
}

vectorll factorization(ll n) 	 max n is 1e12
{	// O( sqrt(n) )

	vectorll primes;

	for (ll i = 2; i  i * i <= n; ++i)	 Improve start by i = 3.
		while (n % i == 0)
			primes.push_back(i), n /= i;	 Get every prime inside n.	n  i^j	is a new number

	 Two ways to prove that n will be prime number if n  1
	 1) Think in n  pi^x as a NEW sub-problem. If we went to its sqrt and % applied, then we are facing a prime number
	 2) Prove that, for any n either all its primes before sqrt(n), or only the biggest prime after sqrt(n).
	if (n  > 1)
		primes.push_back(n);

	return primes;
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

	ordered_set X;
	X.insert(1);
	X.insert(2);
	X.insert(4);
	X.insert(8);
	X.insert(16);

	0 1 2 3 4
	1 2 4 8 16
	cout<<*X.find_by_order(1)<<endl; // 2
	cout<<*X.find_by_order(2)<<endl; // 4
	cout<<*X.find_by_order(4)<<endl; // 16
	cout<<(end(X)==X.find_by_order(6))<<endl; // true

	cout<<X.order_of_key(-5)<<endl;  // 0
	cout<<X.order_of_key(1)<<endl;   // 0
	cout<<X.order_of_key(3)<<endl;   // 2
	cout<<X.order_of_key(4)<<endl;   // 2
	cout<<X.order_of_key(400)<<endl; // 5

int t = 0;

ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

*/
const double Eps =(1e-7);
int dcmp(double x,double y){ return fabs(x-y)<=Eps? 0: x<y ?-1:1; }
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_setpair;
typedef long long  ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> pii;
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define el	'\n'
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define lp1(i,n) for(int i = 1;i <= int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define SS stringstream
#define ll long long
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
const long long  P = (31);
const long long  key2 = 59;
int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, 1, 1, -1 };
int kx[] = { 2, 2, 1, -1, -2, -2, 1, -1 };
int ky[] = { 1, -1, 2, 2, 1, -1, -2, -2 };
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b % a, a);}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int setBit(int num,int idx,int val){return val?(num|(1<<idx)): (num&(~(1<<idx)));}
int getBit(int num,int idx){return 	((num>>idx)&1)==1;}

ll const N = 5e6+9, mod = 1e14+7 ,  oo = 1e14+7;

//------------------------------------------------------------------------------------

int n,m,k;
int happy[N];
ll dp[N][20];
map<pii,int>rules;
ll solve(int mask,int prev){
ll &ret=dp[mask][prev];
if (ret!=-1)return ret;
if (bits(mask)==m)return 0;
ret=0;
lp(i,n){
ll s=0;
int nmask=mask;
if (!getBit(nmask,i)){
	nmask=setBit(nmask,i,1);
	s+=happy[i];
	s+=rules[ mp(prev,i) ];
	ret=max(ret,solve(nmask,i)+s);
}
}
return ret;
}

int main()
{
	fastIO;
	cin>>n>>m>>k;
	lp(i,n)cin>>happy[i];
	lp(i,k){
		int x,y,c;
		cin>>x>>y>>c;
		x--;
		y--;
	rules[mp(x,y)]=c;
	}
	clr(dp,-1);
	cout<<(ll)solve(0,0);
/*
*/
return 0;
}


/*|In The Name of Allah|*/
/* Dear GCC compiler:
*
* If my code doesn't compile, this doesn't mean it's wrong.
* It just mean that you don't understand what I want.
* Here's my safety pig, I hope my code compile and get accepted.
* _._ _..._ .-',     _.._(`))
*'-. `     '  /-._.-'    ',/
*   )         \            '.
*  / _    _    |             \
* |  a    a    /              |
* \   .-.                     ;
*  '-('' ).-'       ,'       ;
*     '-;           |      .'
*        \           \    /
*        | 7  .__  _.-\   \
*        | |  |  ``/  /`  /
*       /,_|  |   /,_/   /
*          /,_/      '`-'
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace  __gnu_pbds;
long long  mood=1e14;

long long power(long long x, long long y,long long mood){
if (y == 0)
	return 1;
long long ret = power(x , y >> 1,mood) %mood ;
if (y % 2 == 0)
	return (ret * ret) % mood;
else
	return (x * (ret * ret % mood)) % mood;
}

pair<int, int> norm(pair<int, int> p)
{
	if(p.first < 0)
	{
		p.first *= -1;
		p.second *= -1;
	}
	else if (p.first == 0 && p.second < 0)
	{
		p.second *= -1;
	}
	int d = __gcd(abs(p.first), abs(p.second));
	p.first /= d;
	p.second /= d;
	return p;
}

/*

int parent[N], sz[N];
int n, m, components;

void init(){
  iota(parent, parent+N, 0);
  fill(sz, sz+N, 1);
  components = N;
}

int find(int u){
  if(parent[u] == u)  return u;
  return parent[u] = find(parent[u]);
}

void join(int u, int v){
  u = find(u), v = find(v);
  if(u == v)  return;
  if(sz[u] < sz[v]) swap(u, v);
  parent[v] = u;
  sz[u] += sz[v];
  --components;
}
int dst[N];
int vis[N];
int parent[N];
vector<vector<pair<int,ll>>>v(N);
void dikstra(){
	set<pair<ll,ll>>s;
	clr(dst,oo);
	clr(vis,0);
	clr(parent,-1);
	dst[1]=0;
	parent[1]=-1;
	s.insert( mp(0,1 ) );
	while(!s.empty()){

		pair<ll,ll> x=*s.begin();
		s.erase(s.begin());
		ll u=x.sc;
		ll d=x.fr;
		if (vis[u])continue;
		vis[u]=1;
		for (int i=0;i<v[u].size();i++){
			ll to=v[u][i].fr;
			ll cost=v[u][i].sc;
			if (vis[to]||d+cost>=dst[to])continue;
			dst[to]=d+cost;
			parent[to]=u;
			s.insert(mp(d+cost,to));
		}
	}

return;
}
void primeFactors(int n)
{
	while (n % 2 == 0){
		n = n/2;
	}

	for (int i = 3; i <= sqrt(n); i = i + 2)
	{
		while (n % i == 0){
			cout << i << " ";
			n = n/i;
		}
	}
	if (n > 2){

	}
}

void Theaf(){
isPrime[0]=1;
isPrime[1]=1;
for (int i=2;i*i<=N;i++){
	if (isPrime[i]==1)continue;
	for (int cnt=2;i*cnt<=N;cnt++)isPrime[ cnt*i ]=1;
}

}
void dfs_EdgeClassification(int node)
{
	start[node] = timer++;

	rep(i, adj[node])
	{
		int child = adj[node][i];
		if (start[child] == -1)	// Not visited Before. Treed Edge
			dfs_EdgeClassification(child);
		else {
			if(finish[child] == -1)// then this is ancestor that called us and waiting us to finish. Then Cycle. Back Edge
				anyCycle = 1;
			else if(start[node] < start[child])	// then you are my descendant
				;	// Forward Edge
			else
				;	// Cross Edge
		}
	}

	finish[node] = timer++;
}

vectorll factorization(ll n) 	 max n is 1e12
{	// O( sqrt(n) )

	vectorll primes;

	for (ll i = 2; i  i * i <= n; ++i)	 Improve start by i = 3.
		while (n % i == 0)
			primes.push_back(i), n /= i;	 Get every prime inside n.	n  i^j	is a new number

	 Two ways to prove that n will be prime number if n  1
	 1) Think in n  pi^x as a NEW sub-problem. If we went to its sqrt and % applied, then we are facing a prime number
	 2) Prove that, for any n either all its primes before sqrt(n), or only the biggest prime after sqrt(n).
	if (n  > 1)
		primes.push_back(n);

	return primes;
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

	ordered_set X;
	X.insert(1);
	X.insert(2);
	X.insert(4);
	X.insert(8);
	X.insert(16);

	0 1 2 3 4
	1 2 4 8 16
	cout<<*X.find_by_order(1)<<endl; // 2
	cout<<*X.find_by_order(2)<<endl; // 4
	cout<<*X.find_by_order(4)<<endl; // 16
	cout<<(end(X)==X.find_by_order(6))<<endl; // true

	cout<<X.order_of_key(-5)<<endl;  // 0
	cout<<X.order_of_key(1)<<endl;   // 0
	cout<<X.order_of_key(3)<<endl;   // 2
	cout<<X.order_of_key(4)<<endl;   // 2
	cout<<X.order_of_key(400)<<endl; // 5

int t = 0;

ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

*/
const double Eps =(1e-7);
int dcmp(double x,double y){ return fabs(x-y)<=Eps? 0: x<y ?-1:1; }
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_setpair;
typedef long long  ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> pii;
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define el	'\n'
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define lp1(i,n) for(int i = 1;i <= int(n);i++)
#define rlp(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rng(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define SS stringstream
#define ll long long
#define clr(x, y) memset(x, y, sizeof(x))
#define foreach(it,x) for(__typeof__((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
const long long  P = (31);
const long long  key2 = 59;
int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, 1, 1, -1 };
int kx[] = { 2, 2, 1, -1, -2, -2, 1, -1 };
int ky[] = { 1, -1, 2, 2, 1, -1, -2, -2 };
ll gcd(ll a, ll b){if (a == 0)return b;return gcd(b % a, a);}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int setBit(int num,int idx,int val){return val?(num|(1<<idx)): (num&(~(1<<idx)));}
int getBit(int num,int idx){return 	((num>>idx)&1)==1;}

ll const N = 5e6+9, mod = 1e14+7 ,  oo = 1e14+7;

//------------------------------------------------------------------------------------

int n,m,k;
int happy[N];
ll dp[N];
vector<pair<int,pii>>rules;
ll solve(int mask){
ll &ret=dp[mask];
if (ret!=-1)return ret;
ret=0;
if (bits(mask)==m){
	ll sum=0;
	vector<int>vis1;
	vector<int>vis2;
	lp(i,n)if (getBit(mask,i)==1)sum+=happy[i];
	lp(i,n)vis2.pb(0);
	lp(i,n)vis1.pb(0);
	lp(i,k){
	int cost=rules[i].fr;
	int x=rules[i].sc.fr;
	int y=rules[i].sc.sc;
	if (getBit(mask,y)&&getBit(mask,x)&&vis1[y]==0&&vis2[x]==0){
	vis1[y]=1;
	vis2[x]=1;
	sum+=cost;
	}
	}
	return sum;
}

lp(i,n){
int nmask=mask;
if (!getBit(nmask,i)){
	nmask=setBit(nmask,i,1);
	ret=max(ret,solve(nmask));

}
}
return ret;
}

int main()
{
	cin>>n>>m>>k;
	lp(i,n)cin>>happy[i];
	lp(i,k){
		int x,y,c;
		cin>>x>>y>>c;
		x--;
		y--;
		rules.pb(mp(c,mp(x,y)));
	}
	sort(all(rules));
	reverse(all(rules));
	clr(dp,-1);
	cout<<solve(0);
/*
*/
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
}
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

// If I need to find (x / a) % b, I need to use this function:
//    (x / a) % b = (x * inv(a, b)) % b
ll inv(ll a, ll b) {
  if (a != 1) {
    return b - (inv(b % a, a) * b) / a;
  }
  return 1;
}

inline int Pow(int a, int k) {
  int s = 1;
  for(; k; k >>= 1) {
    k & 1 ? s = 1LL * s * a % MOD : 0;
    a = 1LL * a * a % MOD;
  }
  return s;
}

// Init variables here
const int N = 1e6 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);
}

void output() {

}

void preprocess() {

}

void debug() {
  if (true) {

  }
}

void solve() {
  preprocess();
  string line; getline(cin, line);
  int prev = 0;
  for (char &ch : line) {
    int cur = 0;
    FOR(i, 0, 8) {
      if (ch & (1 << (8 - i - 1))) {cur |= (1 << i);}
    }
    cout << (prev - cur + 256) % 256 << endl;
    prev = cur;
  }
  //debug();
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

#undef int
int main() {
#define int long long
  ios_base::sync_with_stdio(false);
  cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--)
  {
    input();
    solve();
    output();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>

using namespace std;
struct elem{
    int num;
    int integ;
};
bool compare(int f, int l){
    return (f < l);
}

int main()
{
    char c = getchar();
    int d = 0;
    while (c != '\n' && c != EOF){
        int m = c;
        int n = 0;
        for (int i = 0; i < 8; i++){
            n *= 2;
            n += m % 2;
            m /= 2;
        }
        if (d - n < 0){
            printf("%d", d - n + 256);
        }else{
            printf("%d", (d - n) % 256);
        }
        puts("");
        d = n;
        c = getchar();
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    string a;
    getline(cin, a);
    vector<int> x(a.length());
    for(int i=0; i<a.length(); i++){
		x[i]=a[i]-0;
		int z=0;
		for(int y=0; y<8; y++){
			z*=2;
			z+=x[i]%2;
			x[i]/=2;
		}
		x[i]=z;
    }
    cout << (256 - x[0])%256 << '\n';
    for(int i=1; i<a.length(); i++){
		cout << (x[i-1]-x[i]+256)%256 << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
	string s;
	getline(cin, s);
	int arr[8], cur = 0, prev = 0;
	for(int i = 0; i < s.size(); i++){
		memset(arr, 0, sizeof(arr));
		int tmp = (int)s[i];
		//printf("%d\n", tmp);
		for(int j = 7; j >= 0; j--){
			if(tmp >= (int)pow(2, j)) arr[j] = 1;
			tmp %= (int)pow(2, j);
			//printf("%d\n", tmp);
			if(tmp == 0) break;
		}
		/*for(int j = 0; j < 8; j++){
			printf("%d", arr[j]);
		}*/
		for(int j = 0; j < 8; j++){
			cur += arr[j]*(int)pow(2, 7-j);
		}
		if(prev-cur >= 0) printf("%d\n", (prev-cur)%256);
		else printf("%d\n", 256+prev-cur);
		prev = cur;
		cur = 0;
	}
}


#include <bits/stdc++.h>

#define int long long
#define make(T, n) T n; cin >> n
#define VI vector<int>
#define f(n) for (signed i = 0; i < n; i++)
#define VII vector<VI>
#define g(n) for (int j = 0; j < n; j++)
#define makev(name, n) VI name(n); f(n) cin >> name[i]
#define ALL(q) q.begin(), q.end()
#define RALL(q) q.rbegin(), q.rend()
#define pb(n) push_back(n)
#define fe(n) for (const auto &x: n)
#define pii std::pair<int, int>
#define ld long double
#define FOR(i, n) for (int i = 0; i < n; i++)
#define mp(a, b) make_pair(a, b)

#define M7 1000000007
#define M9 1000000009
#define MFFT 998244353
#define INF 2000000000000000001

using namespace std;

void solve() {
    string s;
    getline(cin, s);
    VI v(s.size());
    f(s.size()) v[i] = s[i];
    vector<unsigned char> c(s.size(), 0);
    int res = 0;
    f(s.size()) {
        g(8) {
            int t = ((bool) (v[i] & (1 << j))) * (1 << (7 - j));
            c[i] += t;
        }
        cout << (int)(res - c[i] + 256) % 256 << "\n";
        res = c[i];
    }

}

signed main(signed argc, char **argv) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (argc > 1 && (string) argv[1] == "local") {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        solve();
        while (cin.peek() != EOF) {
            if (isspace(cin.peek()))
                cin.get();
            else {
                cout << '\n';
                solve();
            }
        }
    } else {
        //freopen("sum.in", "r", stdin);
        //freopen("sum.out", "w", stdout);
        solve();
    }
}


/*I wanna be the very best, like no one ever was...*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int f(int x) {
	int ret = 0;
	for(int i = 0, j = 7; i < 8; i ++, j --) {
		if((x >> i) & 1) ret |= 1 << j;
	}
	return ret;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	string s;
	getline(cin, s);
	int prev = 0;
	for(char c : s) {
		int rev = f(c);
		cout << (prev - rev + 256) % 256 << "\n";
		prev = rev;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
char str[202];
int main()
{
    gets(str);
    for(int i=0; str[i]; i++)
    {
        int s;
        if(!i)s= 0;
        else s= str[i-1];

        int sum= 0;
        for(int j=0, k=7; j<8; j++, k--)
        if(s&(1<<(j)))sum+= (1<<(k));

        for(int j=0; j<256; j++)
        {
            int p= ((sum-j)+256)%256;
            int t= 0;
            for(int l=0, k=7; l<8; l++, k--)
            if(p&(1<<(l)))t+= (1<<(k));

            if(t==str[i])
            {
                printf("%d\n", j);
                break;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define allr(x) (x.rbegin()),(x.rend())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif

string str;

ll reverse(ll n){
	ll res = 0ll;
	for(int i = 0;i<8;++i){
		res <<= 1;
		if(n & 1) res^= 1;
		n >>= 1;
	}
	return res;
}
ll mod(ll n){
	 n = n%256;
	 if(n < 0) return n + 256;
	 else return n;
}

void test_case(){
	getline(std :: cin,str);
	const int N = str.length();
	int prev = 0;
	for(int i = 0;i<N;++i){
		int val1 = reverse(str[i]);
		int val2 = mod(prev - val1);
		cout << val2 << endl;
		prev = val1;
	}
}

int main(){
	FAST_IO;
	int tt;
	//cin >> tt;
	tt = 1;
	for(int i = 0;i<tt;++i){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


/* BAAHUBALI7781  */

#include <bits/stdc++.h>
using namespace std;

 void fileioe(){
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt","w",stderr);
}
#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif

#define SOT(n) SieveOfEratosthenes(n)
#define fioe() fileioe()
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define zrep(i, a, b) for (ll i=b; i>=(a); i--)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//

                void solve()
                {
                    string s;
                    getline(cin,s);
                    int l=s.length();
                    vector<int> v(l);
                    rep(i,0,l)
                    {
                        v[i]=s[i]-0;
                        int z=0;
                        rep(j,0,8)
                        {
                            z*=2;
                            z+=s[i]%2;
                            s[i]/=2;
                        }
                        v[i]=z;
                    }
                cout<<(256-v[0])%256<<endl;
                rep(i,1,l){
                cout<<(v[i-1]-v[i]+256)%256<<endl;

                    }
                }
                int main(){
                        hs;
                       // fioe();
                        ll t;
                        t=1;
                        //cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0;
}


/* BAAHUBALI7781  */

#include <bits/stdc++.h>
using namespace std;

 void fileioe(){
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt","w",stderr);
}
#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif

#define SOT(n) SieveOfEratosthenes(n)
#define fioe() fileioe()
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define zrep(i, a, b) for (ll i=b; i>=(a); i--)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//

                void solve()
                {
                    string s;
                    getline(cin,s);
                    int l=s.length();
                    vector<int> v(l);
                    rep(i,0,l)
                    {
                        v[i]=s[i]-0;
                        int z=0;
                        rep(j,0,8)
                        {
                            z*=2;
                            z+=s[i]%2;
                            s[i]/=2;
                        }
                        v[i]=z;
                    }
                cout<<(256-v[0])%256<<endl;
                rep(i,1,l){
                cout<<(v[i-1]-v[i]+256)%256<<endl;

                    }
                }
                int main(){
                        hs;
                        fioe();
                        ll t;
                        t=1;
                        //cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include "math.h"
#include "unordered_map"
#include <set>
#include <time.h>
#include <deque>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <memory.h>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

/*
 * ">" =  1000,
"<"  =  1001,
"+"  =  1010,
"-"  =  1011,
"."  =  1100,
","  =  1101,
"["  =  1110,
"]"  =  1111.
 */
const int Mod = 256;

ll powmod(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) {
            res *= a;
            res %= Mod;
        }
        b >>= 1;
        a = a * a;
        a %= Mod;
    }
    return res;
}

int to_decimal(string s) {
    reverse(s.begin(), s.end());
    int res = 0;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] == '1')
            res += pow(2, i);
    }
    return res;
}

string to_binary(int n) {
    string res = "";
    for (int i = 0; i < 8; i++) {
        if (n & (1 << i)) {
            res += '1';
        } else
            res += '0';
    }
    reverse(res.begin(), res.end());
    return res;
}

int get_the_reversed_number(int n) {
    string s = to_binary(n);
    int res = 0;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] == '1') res += pow(2, i);
    }
    return res ;
}

void solve() {
    string s;
//    cin >> s;
    getline(cin , s);
    int last = 0;
    int n = (int) s.size();
    for (int i = 0; i < n; i++) {
        int asci = (int) s[i];
        string binary = to_binary(asci);
        string reversed = "";
        for (int j = ((int) binary.size() - 1); j >= 0; j--) {
            reversed += binary[j];
        }
        int decimal = to_decimal(reversed);
        int cur = ((last - decimal) % 256 + 256) % 256;
        cout << cur << endl;
        last = decimal;
    }

}

int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef  unsigned long long ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
string getBinary(int num){
    string ans ;
    while (num){
        if(num%2==1){
            ans='1'+ans;
        }else{
            ans='0'+ans;
        }
        num/=2;
    }
    while (ans.size()!=8){
        ans='0'+ans;
    }
    return ans;
}
ll fpow(int base , int p ){
    if(p==0)return 1;
    ll ans = fpow(base, p/2);
    ans*=ans;
    if(p%2==1){
        ans*=base;
    }
    return ans;
}

int getDecimal(string bin){
    int num = 0;
    int n = bin.size();
    int b =0;
    for(int i =n-1 ; i>=0; i--){
        if(bin[i]=='1'){
            num+=fpow(2,b);
        }
        b++;
    }
    return num;
}
int main(){
    string str;
    getline (std::cin,str);
    int n =str.size();
    int lastResulut = 0;
    for(int i = 0;i<n ;i++){
       int num = str[i];
       string bin = getBinary(num);
       reverse(bin.begin(),bin.end());
       int ss = getDecimal(bin);
       int ans = lastResulut-getDecimal(bin) ;
       while (ans<0)ans+=256;
       ans%=256;
       cout<<ans<<endl;
       lastResulut=ss;
    }
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <fstream>
#include <list>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define _DEBUG
#define vec vector
#define pb push_back
#define en '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef long double ld;
typedef unsigned int ui;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vi2;
typedef vector<vector<ll>> vll2;
typedef vector<vector<ll>> matrix;
typedef vec<vec<vec<int>>> vi3;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define for1(i,n) for(int i = 1;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define REP(a,i,b) for (int i = a;i<b;i++);

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

const int inf = 2000000000;
const ll linf = 5000000000000000000;
const ld LDINF = 2e18;
template<typename T> void print(vector<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        cout << a[i] << ' ';
}

template<typename T> void print(deque<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        cout << a[i] << ' ';
}

template<typename T> void print(vector<vector<T>>& a)
{
    for (int i = 0; i < a.size(); i++)
    {
        for (int j = 0; j < a[i].size(); j++)
            cout << a[i][j] << ' ';
        cout << en;
    }
}

template <typename T> void input(vector<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
    for (int i = 0; i < a.size(); i++)
        cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
    for (int i = 0; i < a.size(); i++)
        for (int j = 0; j < a[i].size(); j++)
            cin >> a[i][j];
}

ll mod =  1190494759;
int mod1 = 1e9 +7;
ll p = 103;

ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

matrix mult(matrix &A, matrix &B){
    int n = A.size(), m = B[0].size();
    matrix C(n, vec<ll>(m, 0));
    for0(i, n){
        for0(j, m){
            for0(k, A[0].size()){
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= mod;
            }
        }
    }
    return C;
}

ll BinPow(ll a, ll n){
    if(n == 1)
        return a;
    if(n == 0)
        return 1;
    if(n % 2 == 0){
        ll d =BinPow(a, n/2);
        return d * d % mod;
    }
    else
        return a * BinPow(a, n-1) % mod;
}

struct event{
    int num, type, x;
};

bool cmp(event &a, event &b){
    if(a.x == b.x){
        return a.type > b.type;
    }
    return a.x < b.x;
}

ll toDec(string &num){
    reverse(all(num));
    ll ans = 0;
    ll st = 1;
    for(char ch : num){
        ll bit = ch-'0';
        ans += st * bit;
        st *=2;
    }
    return ans;
}

int GetVal(int n){
    bitset<8> bit = n;
    string num;
    for(int i = 0;i < 8; i++){
        if(bit[i])
            num.push_back('1');
        else
            num.push_back('0');
    }
    return toDec(num);
}

void solve()
{
    int last = 31;
    string str;
    getline(cin, str);
    for(int i = 0; i < str.length(); i++){
        int itog = GetVal(last);
        int rever = GetVal(int(str[i]));
        int x = itog - rever;
        if(x < 0)
            x += 256;
        cout << x << en;
        last = int(str[i]);
    }
}

int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

#ifdef DEBUG
     freopen("input.txt", "r", stdin);
     freopen("input.txt", "r", stdin);
#endif
   // freopen("graph.in", "r", stdin);
   // freopen("graph.out", "w", stdout);

    int tst = 1;
  //  cin >> tst;
    while(tst--)
        solve();

}