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[] arg) {
		new Thread(null, new a(), "", 1L<<27).start();
	}
	long[] vs;
	ArrayList<Edge>[] g;
	long[] memo;
	public void run() {
		try {
			JoltyScanner in = new JoltyScanner(System.in);
			PrintWriter out = new PrintWriter(System.out);
			int n = in.nextInt();
			int m = in.nextInt();
			int[] from = new int[m];
			int[] to = new int[m];
			int[] weight = new int[m];
			int[] size = new int[n];
			for(int i = 0; i < m; i++) {
				int v1 = in.nextInt()-1;
				int v2 = in.nextInt()-1;
				int w = in.nextInt();
				from[i] = v1;
				to[i] = v2;
				weight[i] = w;
				size[v1]++;
			}
			int[][] adj = new int[n][];
			for(int i = 0; i < n; i++) {
				adj[i] = new int[size[i]*2];
				size[i] = 0;
			}
			for(int i = 0; i < m; i++) {
				int v1 = from[i];
				int v2 = to[i];
				int w = weight[i];
				int idx = size[from[i]];
				adj[v1][idx] = v2;
				adj[v1][idx+1] = w;
				size[from[i]] += 2;
			}
			from = null;
			to = null;
			weight = null;
			size = null;
			SCC scc = new SCC(n, adj);
			scc.go();
			int[] map = scc.map;
			g = scc.compressSCC();
			adj = null;
			memo = new long[g.length]; Arrays.fill(memo, -1);
			out.println(solve(map[in.nextInt()-1]));
			out.close();
		} catch(Exception e) {
			e.printStackTrace();
			System.out.println(1/0);
		}
	}
	long solve(int v) {
		long ret = memo[v];
		if(ret != -1) return ret;
		ret = vs[v];
		for(Edge e : g[v]) {
			ret = Math.max(ret, vs[v]+e.w+solve(e.to));
		}
		return memo[v] = ret;
	}
	class SCC {
	  int n;
	  int[][] adj;
	  @SuppressWarnings("unchecked")
	  SCC(int n, int[][] adj) {
	    this.n = n;
	    this.adj = adj;
	  }
	  int index;
	  boolean[] visited;
	  int[] indices;
	  int[] lowlink;
	  ArrayDeque<Integer> stack;
	  int[] map;
	  int sccSize;
	  int[] go() {
	    index = 1;
	    indices = new int[n];
	    lowlink = new int[n];
	    visited = new boolean[n];
	    map = new int[n];
	    stack = new ArrayDeque<Integer>();
	    for (int curr = 0; curr < n; ++curr)
	      if (indices[curr] == 0)
	        dfs(curr);

	    return map;
	  }

	  void dfs(int node) {
	    indices[node] = lowlink[node] = index++;
	    stack.push(node);
	    visited[node] = true;

	    for(int i = 0; i < adj[node].length; i+=2) {
	      int next = adj[node][i];
	      if (indices[next] == 0) {
	        dfs(next);
	        lowlink[node] = Math.min(lowlink[node], lowlink[next]);
	      } else if (visited[next]) {
	        lowlink[node] = Math.min(lowlink[node], indices[next]);
	      }
	    }

	    if (lowlink[node] == indices[node]) {
	      int next;
	      do {
	        next = stack.pop();
	        visited[next] = false;
	        map[next] = sccSize;
	      } while (next != node);
	      sccSize++;
	    }
	  }
	  ArrayList<Edge>[] compressSCC() {
		ArrayList[] ret = new ArrayList[sccSize];
		for(int i = 0; i < sccSize; i++) ret[i] = new ArrayList<Edge>();
	    int[] added = new int[sccSize];
	    Arrays.fill(added, -1);
	    vs = new long[sccSize];
	    for(int i = 0; i < adj.length; i++) {
	    	for(int j = 0; j < adj[i].length; j+=2) {
	    		int to = adj[i][j];
	    		int w = adj[i][j+1];
	    		if(map[i] == map[to]) {
	    			vs[map[i]] += get(w);
	    		} else {
	    			ret[map[i]].add(new Edge(map[to], w));
	    		}
	    	}
	    }
	    adj = null;
	    return ret;
	  }
	}
	long get(long w) {
		long n = (long)((-1+Math.sqrt(1+8*w))/2);
		long n1 = n+1;
		return w*n1 - ((((n*n1)>>1) + n*n1*(2*n+1)/6)>>1);
		
	}
	class Edge {
		int to;
		long w;
		public Edge(int a, long b) {
			to = a;
			w = b;
		}
	}
	//@
	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++];
		}
	}
}