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 E implements Runnable{
	public static void main(String[] args)throws Throwable {
		new Thread(null, new E(), "", 1L<<27).start();
	}
	
	public void run(){
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		cum=new long [(int)4e4];
		for(int i=1;i<cum.length;i++)
			cum[i]=cum[i-1]+i*(i+1)/2;
		
		
		n=sc.nextInt();
		m=sc.nextInt();
		adj=new int [n][];
		from=new int [m];
		to=new int [m];
		w=new int [m];
		int [] size=new int [n];
		for(int i=0;i<m;i++){
			from[i]=sc.nextInt()-1;
			to[i]=sc.nextInt()-1;
			w[i]=sc.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;
		
		tarjanSCC();
		adj2=new int [SCC][];
		compTot=new long [SCC];
		Arrays.fill(size, 0);
		int [] in=new int [n];
		for(int i=0;i<m;i++){
			int u=from[i];
			int v=to[i];
			if(comp[u]==comp[v]){
				
				int ans=((int)Math.sqrt(2*w[i]))-1;
				if((ans+1)*(ans+2)/2<=w[i])
					ans++;
				if((ans+1)*(ans+2)/2<=w[i])
					ans++;
				
				long c2=1L*w[i]*(ans+1)-cum[ans];
				compTot[comp[u]]+=c2;
			}
			else{
				size[comp[v]]++;
				in[comp[u]]++;
			}
		}
		for(int i=0;i<SCC;i++){
			adj2[i]=new int [size[i]];
			size[i]=0;
		}
		for(int i=0;i<m;i++)
			if(comp[from[i]]!=comp[to[i]])
				adj2[comp[to[i]]][size[comp[to[i]]]++]=i;
		
		mem=new long [SCC];
		Queue<Integer> q=new LinkedList<Integer>();
		for(int i=0;i<SCC;i++)
			if(in[i]==0)
				q.add(i);
		while(!q.isEmpty()){
			int u=q.poll();
			mem[u]+=compTot[u];
			for(int e : adj2[u]){
				int v=comp[from[e]];
				in[v]--;
				mem[v]=Math.max(mem[v], w[e]+mem[u]);
				if(in[v]==0)
					q.add(v);
			}
		}
		
		pw.println(mem[comp[sc.nextInt()-1]]);
		
		pw.flush();
		pw.close();
	}
	
	static long [] mem;
	
	
	static long dp(int i){
		if(mem[i]!=-1)
			return mem[i];
		long ans=0;
		for(int p : adj2[i])
			ans=Math.max(ans, w[p]+dp(comp[to[p]]));
		ans+=compTot[i];
		
		return mem[i]=ans;
	}
	
	
	static int V, counter, SCC, dfs_num[], dfs_low[];
	static boolean[] inSCC;
	static int [] stack;
	static int [] comp;
	static long [] compTot;
	static long [] cum;
	static int n,m,SP;
	static int [] from,to,w;
	static int [][] adj;
	static int [][] adj2;
	
	static void tarjanSCC()	 	//O(V + E)
	{
		V=n;
		dfs_num=new int [n];
		dfs_low=new int [n];
		inSCC=new boolean [n];
		stack=new int [n];
		comp=new int [n];
		
		for(int i = 0; i < V; ++i)
			if(dfs_num[i] == 0)
				tarjanSCC(i);
	}
	
	
	static void tarjanSCC(int u)
	{
		dfs_num[u] = dfs_low[u] = ++counter;
		stack[SP++]=u;
		
		for(int e: adj[u])
		{
			int v=to[e];
			if(dfs_num[v] == 0)
				tarjanSCC(v);
			if(!inSCC[v])
				dfs_low[u] = Math.min(dfs_low[u], dfs_low[v]);	
		}
		if(dfs_num[u] == dfs_low[u])
		{
			//SCC found
			while(true)
			{
				int v = stack[--SP];
				comp[v]=SCC;
				inSCC[v] = true;
				if(v == u)
					break;
			}
			SCC++;
		}	
	}	
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}