Problem: Petya has a simple graph (that is, a graph without loops or multiple edges) consisting of n vertices and m edges.

The weight of the i-th vertex is a_i.

The weight of the i-th edge is w_i.

A subgraph of a graph is some set of the graph vertices and some set of the graph edges. The set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices. 

The weight of a subgraph is the sum of the weights of its edges, minus the sum of the weights of its vertices. You need to find the maximum weight of subgraph of given graph. The given graph does not contain loops and multiple edges.

Input

The first line contains two numbers n and m (1 ≤ n ≤ 10^3, 0 ≤ m ≤ 10^3) - the number of vertices and edges in the graph, respectively.

The next line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) - the weights of the vertices of the graph.

The following m lines contain edges: the i-e edge is defined by a triple of integers v_i, u_i, w_i (1 ≤ v_i, u_i ≤ n, 1 ≤ w_i ≤ 10^9, v_i ≠ u_i). This triple means that between the vertices v_i and u_i there is an edge of weight w_i. It is guaranteed that the graph does not contain loops and multiple edges.

Output

Print one integer — the maximum weight of the subgraph of the given graph.

Examples

Input


4 5
1 5 2 2
1 3 4
1 4 4
3 4 5
3 2 2
4 2 2


Output


8


Input


3 3
9 7 8
1 2 1
2 3 2
1 3 3


Output


0

Note

In the first test example, the optimal subgraph consists of the vertices {1, 3, 4} and has weight 4 + 4 + 5 - (1 + 2 + 2) = 8. In the second test case, the optimal subgraph is empty.

Solution (in JAVA):

Solution:
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;

public class G2 {
/*
3 2
1 10 1
1 2 5
2 3 9
 */

	static long res;
	static int N,M;
	static long nodeW[];
	static long edgeW[][];
	static boolean takeE[][];
	static ArrayList<Integer> adj[];
	static long INF;
	public static void main(String[] args) {
		JS in = new JS();
		//take any edge who's sum is >= both nodes on the end
		N = in.nextInt();
		M = in.nextInt();
		Dinic g = new Dinic(N+M);
		nodeW = new long[N];
		INF = 1_000_000_000_000_000L;
		for(int i = 0; i < N; i++) {
			nodeW[i] = in.nextLong();
			g.add(i, g.t, nodeW[i], 0);
		}
		adj = new ArrayList[N];
		for(int i = 0; i < N; i++) adj[i] = new ArrayList<Integer>();
		edgeW = new long[N][N];
		long rev = 0;
		for(int i = 0; i < M; i++) {
			int a = in.nextInt()-1;
			int b = in.nextInt()-1;
			adj[a].add(b);
			adj[b].add(a);
			long w = in.nextLong();
			rev += w;
			g.add(N+i, a, INF, 0);
			g.add(N+i, b, INF, 0);
			g.add(g.s, N+i, w, 0);
			edgeW[a][b] = edgeW[b][a] = w;
		}
		System.out.println(rev-g.flow());

	}
	
	static class Dinic {
		static class Edge {
			int v1, v2; Edge rev;
			long cap,flow;
			Edge(int V1, int V2, long Cap, long Flow) { v1 = V1; v2 = V2; cap = Cap; flow = Flow; }
		}
		
		ArrayDeque<Integer> q;  ArrayList<Edge>[] adj;
		int n, s, t;
		long oo = 1_000_000_000_000_000L;
		boolean[] blocked;  int[] dist;
		public Dinic (int N) {
			n = N; s = n++; t = n++;  blocked = new boolean[n];
			dist = new int[n];  q = new ArrayDeque<Integer>();
			adj = new ArrayList[n];  for(int i = 0; i < n; ++i)  adj[i] = new ArrayList<Edge>();
		}
		// Specifying flow can represent minimum flow for circulation.
		void add(int v1, int v2, long cap, long flow) {
			Edge e = new Edge(v1, v2, cap, flow);  Edge rev = new Edge(v2, v1, 0, 0);
			adj[v1].add(rev.rev = e);  adj[v2].add(e.rev = rev);
		}

		//#
		// Only needed if you need remove function
		void remove(int v1, int v2) {
			Edge e;
			for(int i = 0; i < adj[v1].size(); i++) {
				e = adj[v1].get(i);
				if(e.v2 == v2 && e.cap != 0)  adj[v1].remove(i--);
			}

			for(int i = 0; i < adj[v2].size(); i++) {
				e = adj[v2].get(i);
				if(e.v2 == v1 && e.cap == 0)  adj[v2].remove(i--);
			}
		}
		//$
		
		boolean bfs() {
			q.clear();  Arrays.fill(dist, -1);  dist[t] = 0;  q.add(t);
			
			while(!q.isEmpty()) {
				int node = q.poll();
				if(node == s)   return true;
				for(Edge e : adj[node]) {
					if(e.rev.cap > e.rev.flow && dist[e.v2] == -1) {
						dist[e.v2] = dist[node] + 1;  q.add(e.v2);
					}
				}
			}
			return dist[s] != -1;
		}
		
		long dfs(int pos, long min) {
			if(pos == t)  return min;
			long flow = 0;
			for(Edge e : adj[pos]) {
				long cur = 0;
				if(!blocked[e.v2] && dist[e.v2] == dist[pos]-1 && e.cap - e.flow > 0) {
					cur = dfs(e.v2, Math.min(min-flow, e.cap - e.flow));
					e.flow += cur;  e.rev.flow = -e.flow;  flow += cur;
				}
				if(flow == min)  return flow;
			}
			blocked[pos] = flow != min;
			return flow;
		}
		long flow() {
			clear();  long ret = 0;
			while(bfs()) {  Arrays.fill(blocked, false);  ret += dfs(s, oo);  }
			return ret;
		}
		void clear() {  for(ArrayList<Edge> edges : adj)  for(Edge e : edges)  e.flow = 0;  }
		// Convert the given graph into a graph to test for circulation
		Dinic circulation() {
			int[] delta = new int[n];
			for(int node = 0; node < n; ++node) {
				for(Edge e : adj[node]) {
					if(e.cap > 0 && e.flow > 0) {
						delta[e.v1] -= e.flow;  delta[e.v2] += e.flow;
					}
				}
			}
			
			Dinic d = new Dinic(n);
			for(int i = 0; i < n; ++i) 
				if(delta[i] > 0)  d.add(d.s, i, delta[i], 0);
				else if(delta[i] < 0)  d.add(i, d.t, -delta[i], 0);
			
			for(int node = 0; node < n; ++node)
				for(Edge e : adj[node])
					if(e.cap > 0 && e.cap - e.flow > 0)  d.add(e.v1, e.v2, e.cap - e.flow, 0);
			
			return d;
		}

		/* Vertex cover on bipartite graph (L, R):
		Find nodes in S side of S/T min cut (bfs(); dist[i] == -1)
		L1 = L & S, L2 = L - S, R1 = R & S, R2 = R - S
		Let B be the set of vertices in R2 that have neighbors in L1
		C = L2 | R1 | B
		Maximum independent set is the complement nodes */
		//#
		ArrayList<Integer> vertexCover() {
			BitSet leftNodes = new BitSet();
			BitSet rightNodes = new BitSet();
			BitSet minCut = new BitSet();
			for(Edge e : adj[s])
				if(e.v1 == s)
					leftNodes.set(e.v2);
			for(Edge e : adj[t])
				if(e.v1 == t)
					rightNodes.set(e.v2);
			bfs();
			for(int i = 0; i < s; ++i)
				if(dist[i] == -1)
					minCut.set(i);

			BitSet l1 = new BitSet(); l1.or(leftNodes); l1.and(minCut);
			BitSet l2 = new BitSet(); l2.or(leftNodes); l2.andNot(minCut);
			BitSet r1 = new BitSet(); r1.or(rightNodes); r1.and(minCut);
			BitSet r2 = new BitSet(); r2.or(rightNodes); r2.andNot(minCut);

			BitSet b = new BitSet();
			for(int bit = r2.nextSetBit(0); bit >= 0; bit = r2.nextSetBit(bit+1)) {
				for(Edge e : adj[bit]) {
					if(e.v1 == bit && l1.get(e.v2)) {
						b.set(bit);
						break;
					}
				}
			}

			BitSet c = new BitSet(); c.or(l2); c.or(r1); c.or(b);
			ArrayList<Integer> ret = new ArrayList<Integer>();
			for(int bit = c.nextSetBit(0); bit >= 0; bit = c.nextSetBit(bit+1)) 
				ret.add(bit);
			return ret;
		}//$
	}
	
	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;
		
		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}
		
		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}
		
		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}				
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}
		
		public int nextInt() {
			return (int)nextLong();
		}
		
		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}
		
		public double nextDouble() {
		    while(c!='.'&&c!='-'&&(c <'0' || c>'9')) c = nextChar();
		    boolean neg = c=='-';
		    if(neg)c=nextChar();
		    boolean fl = c=='.';
		    double cur = nextLong();
		    if(fl) return neg ? -cur/num : cur/num;
		    if(c == '.') {
			double next = nextLong();
			return neg ? -cur-next/num : cur+next/num;
		    }
		    else return neg ? -cur : cur;
		}
		
		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}
		
		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
	
}