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 E894 implements Runnable{
	
	int n;
	int N;
	int componentCount;
	int[] stack;
	boolean[] stacked;
	int[] low;
	HashMap<Integer, LinkedList<Integer>> compSet;
	int[] comp;
	int[] d;
	int[] f;
	int adj[][];
	
	int[] from,to,size;
	long[] w;
	
	long[] componentMushrooms;
	
	int[][] graph;
	int[] inDegree;

	void dfs(){
		N = 1;
		stack = new int[n];
		SP = 0;
		int n = adj.length;
		stacked = new boolean[n];
		d = new int[n];
		low = new int[n];
		comp = new int[n];
		componentCount = 0;
		
		for(int i = 0; i < n; i++) if(d[i] == 0) visit(i);
	}
	
	int SP;

	void visit(int u){
		stack[SP++] = u;
		stacked[u] = true;
		d[u] = N++;
		low[u] = d[u];
		for(int e:adj[u]){
			int v = to[e];
			if(d[v] == 0){
				visit(v);
				low[u] = Math.min(low[u], low[v]);
			}else if(stacked[v]){
				low[u] = Math.min(low[u], d[v]);
			}
		}
		if(low[u] == d[u]) {
			while(true){
				int v = stack[--SP];
				comp[v] = componentCount;
				stacked[v] = false;
				if(v == u) break;
			}
			componentCount++;
		}
	}
	
	
	
	
	long totalMushrooms(long n){
		long left = 0;
		long right = n;
		while(left < right-1){
			long mid = (left+right)/2;
			if((mid*(mid+1))/2 <= n) left = mid;
			else right = mid;
		}
		return (left+1)*n - (left*(left+1)*(left+2))/6;
	}
	
	long totalMush(long n){
		long k = (long)Math.floor((Math.sqrt(1+8*n)-1)/2);
		return (k+1)*n - (k*(k+1)*(k+2))/6;
	}

	private void solve() throws Exception {
		n = nextInt();
		int m = nextInt();
	
		adj = new int[n][];
		from = new int[m];
		to = new int[m];
		size = new int[n];
		w = new long[m];
		for(int i = 0; i < m; i++) {
			from[i] = nextInt()-1;
			to[i] = nextInt()-1;
			w[i] = nextInt();
			size[from[i]]++;
		}
		
		for(int i = 0; i < n; i++) {
			adj[i] = new int[size[i]];
			size[i] = 0;
		}
		for(int i = 0; i < m; i++) adj[from[i]][size[from[i]]++] = i;
		
		int s = nextInt()-1;
		dfs();
		
		componentMushrooms = new long[componentCount];
		graph = new int[componentCount][];
		inDegree = new int[componentCount];

		
		Arrays.fill(size, 0);
		
		for(int e = 0; e < m; e++){
			int u = from[e];
			int v = to[e];
			if(comp[v] == comp[u]) componentMushrooms[comp[u]] += totalMush(w[e]);
			else{
				size[comp[u]]++;
				inDegree[comp[v]]++;
			}
		}
		
		for(int i = 0; i < componentCount; i++){
			graph[i] = new int[size[i]];
			size[i] = 0;
		}
		
		for(int e = 0; e < m; e++){
			int u = from[e];
			int v = to[e];
			if(comp[v] != comp[u]) graph[comp[u]][size[comp[u]]++] = e;
		}
		out.println(longestPath(comp[s]));
	}
	
	
	
	long longestPath(int s){
		long[] pd = new long[componentCount];
		Arrays.fill(pd, -(1L<<60));
		pd[s] = componentMushrooms[s];
		LinkedList<Integer> queue = new LinkedList<Integer>();		
		for(int i = 0; i < componentCount; i++)	if(inDegree[i] == 0) queue.addLast(i);		
		long res = pd[s];
		while(!queue.isEmpty()){
			int u = queue.removeFirst();
			res = Math.max(res, pd[u]);
			for(int e : graph[u]){
				int v = comp[to[e]];
				if(pd[u] >= 0) pd[v] = Math.max(pd[v], pd[u] + w[e] + componentMushrooms[v]);
				if(--inDegree[v] == 0) queue.addLast(v);
			}
		}
		return res;
	}

	public static void main(String[] args) {
		new Thread(null,new E894(),"",1<<28).start();
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private float nextFloat() throws IOException {
		return Float.parseFloat(nextToken());
	}

	private String nextLine() throws IOException {
		return new String(in.readLine());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(in.readLine());
		}
		return tokenizer.nextToken();
	}
	
	class Edge{
		int v;
		long w;
		
		public Edge(int v, long w){
			this.v = v;
			this.w = w;
		}
	}


}