Problem: Ralph is going to collect mushrooms in the Mushroom Forest. 

There are m directed paths connecting n trees in the Mushroom Forest. On each path grow some mushrooms. When Ralph passes a path, he collects all the mushrooms on the path. The Mushroom Forest has a magical fertile ground where mushrooms grow at a fantastic speed. New mushrooms regrow as soon as Ralph finishes mushroom collection on a path. More specifically, after Ralph passes a path the i-th time, there regrow i mushrooms less than there was before this pass. That is, if there is initially x mushrooms on a path, then Ralph will collect x mushrooms for the first time, x - 1 mushrooms the second time, x - 1 - 2 mushrooms the third time, and so on. However, the number of mushrooms can never be less than 0.

For example, let there be 9 mushrooms on a path initially. The number of mushrooms that can be collected from the path is 9, 8, 6 and 3 when Ralph passes by from first to fourth time. From the fifth time and later Ralph can't collect any mushrooms from the path (but still can pass it).

Ralph decided to start from the tree s. How many mushrooms can he collect using only described paths?

Input

The first line contains two integers n and m (1 ≤ n ≤ 106, 0 ≤ m ≤ 106), representing the number of trees and the number of directed paths in the Mushroom Forest, respectively.

Each of the following m lines contains three integers x, y and w (1 ≤ x, y ≤ n, 0 ≤ w ≤ 108), denoting a path that leads from tree x to tree y with w mushrooms initially. There can be paths that lead from a tree to itself, and multiple paths between the same pair of trees.

The last line contains a single integer s (1 ≤ s ≤ n) — the starting position of Ralph. 

Output

Print an integer denoting the maximum number of the mushrooms Ralph can collect during his route. 

Examples

Input

2 2
1 2 4
2 1 4
1


Output

16

Input

3 3
1 2 4
2 3 3
1 3 8
1


Output

8

Note

In the first sample Ralph can pass three times on the circle and collect 4 + 4 + 3 + 3 + 1 + 1 = 16 mushrooms. After that there will be no mushrooms for Ralph to collect.

In the second sample, Ralph can go to tree 3 and collect 8 mushrooms on the path from tree 1 to tree 3.

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class A implements Runnable{
	public static void main (String[] args) {new Thread(null, new A(), "_cf", 1 << 27).start();}

	Edge[][] adj, sccAdj;
	ArrayDeque<Integer> dq;
	int[] low, num, scc, vis;
	long[] sccSum;
	int time, idx;
	
	public void run() {
		JoltyScanner js = new JoltyScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = js.nextInt();
		int m = js.nextInt();
		adj = new Edge[n][];
		low = new int[max(n, m)];
		num = new int[max(n, m)];
		scc = new int[max(n, m)];
		vis = new int[max(n, m)];
		for(int i = 0; i < m; i++) {
			int u = js.nextInt()-1;
			int v = js.nextInt()-1;
			low[i] = u;
			num[i] = v;
			vis[i] = js.nextInt();
			scc[u]++;
		}
		
		for(int i = 0; i < n; i++)
			adj[i] = new Edge[scc[i]];

		Arrays.fill(scc, 0);
		
		for(int i = 0; i < m; i++) {
			int u = low[i];
			int v = num[i];
			adj[u][scc[u]++] = new Edge(v, vis[i]);
		}
		
		int q = js.nextInt()-1;
		
		Arrays.fill(low, 0);
		Arrays.fill(num, -1);
		Arrays.fill(scc, 0);
		Arrays.fill(vis, 0);
		dq = new ArrayDeque<>();
		time = 0; idx = 0;
		
		for(int i = 0; i < n; i++)
			if(num[i] == -1)
				scc(i);
		
		sccAdj = new Edge[idx][];
		Arrays.fill(low, 0);
		Arrays.fill(num, 0);
		int pos = 0;
		sccSum = new long[idx];
		for(int i = 0; i < n; i++) {
			for(Edge e : adj[i]) {
				if(scc[i] == scc[e.v]) {
					sccSum[scc[i]] += e.total;
				}
				else {
					num[scc[i]]++;
					low[scc[e.v]]++;
				}
			}
		}
		for(int i = 0; i < idx; i++) {
			sccAdj[i] = new Edge[num[i]];
		}
		Arrays.fill(num, 0);
		for(int i = 0; i < n; i++) {
			for(Edge e : adj[i]) {
				if(scc[i] != scc[e.v]) {
					sccAdj[scc[i]][num[scc[i]]++] = new Edge(scc[e.v], (int)e.we);
				}
			}
		}
		
		Arrays.fill(num, 0);//num = new int[idx];
		pos = 0;
		
		for(int i = 0; i < idx; i++) {
			if(low[i] == 0) {
				num[pos++] = i;
			}
		}
		
		for(int i = 0; i < idx; i++) {
			int now = num[i];
			for(Edge e : sccAdj[now]) {
				low[e.v]--;
				if(low[e.v] == 0) {
					num[pos++] = e.v;
				}
			}
		}
		
		//go in reverse top sorted order
		for(int i = idx-1; i >= 0; i--) {
			int now = num[i];
			long add = 0;
			for(Edge e : sccAdj[now]) {
				add = Math.max(add, e.we + sccSum[e.v]);
			}
			sccSum[now] += add;
			if(scc[q] == now) break;
		}
		
		out.println(sccSum[scc[q]]);
		
		
		out.close();
	}
	
	int max (int a,int b) {
		return Math.max(a, b);
	}
	
	long getCost (long ti) {
		//oeis
		double R = Math.round(Math.sqrt(2 * ti));
		double tans = ((6 * ti+1)*R-R*R*R)/6;
		return (long)(tans + .1);
	}
	
	void scc (int u) {
		low[u] = num[u] = time++;
		vis[u] = 1;
		dq.addLast(u);
		
		for(Edge v : adj[u]) {
			if(num[v.v] == -1) {
				scc(v.v);
			}
			if(vis[v.v] == 1) {
				low[u] = Math.min(low[u], low[v.v]);
			}
		}
		
		if(low[u] == num[u]) {
			while(true) {
				int v = dq.pollLast();
				vis[v] = 2;
				scc[v] = idx;
				if(u == v) break;
			}
			idx++;
		}
		
	}
	
	class Edge {
		int v;
		long we, total;
		Edge (int a, int b) {
			v = a;
			we = b;
			total = getCost(we);
		}
	}
	
	class JoltyScanner 
	{
		public static final int BUFFER_SIZE = 1 << 16;
		public static final char NULL_CHAR = (char) -1;
		byte[] buffer = new byte[BUFFER_SIZE];
		int bufferIdx = 0, size = 0;
		char c = NULL_CHAR;
		BufferedInputStream in;
		public JoltyScanner(InputStream in) 
		{
			this.in = new BufferedInputStream(in, BUFFER_SIZE);
			c = nextChar();
		}
		public int nextInt() 
		{
			while(c < '0' || c > '9')
				c = nextChar();
			int res = 0;
			while(c >= '0' && c <= '9') {
				res = (res << 3) + (res << 1) + c - '0';
				c = nextChar();
			}
			return res;
		}
		public char nextChar() 
		{
			while (bufferIdx == size) 
			{
				try 
				{
					size = in.read(buffer);
				} catch (Exception e) 
				{
					return NULL_CHAR;
				}
				bufferIdx = 0;
			}
			return (char) buffer[bufferIdx++];
		}
	}
}