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.util.*;
import java.io.*;
import java.math.BigInteger;
public class B implements Runnable{
	public static void main (String[] args) throws IOException {
		
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int m=sc.nextInt();
		int []from=new int [m],to=new int [m],w=new int [m];
		for(int i=0;i<m;i++)
		{
			from[i]=sc.nextInt()-1;
			to[i]=sc.nextInt()-1;
			w[i]=sc.nextInt();
		}
		adj=packU(n, from, to, w);
		prefix=new long [14143];
		for(int i=1;i<prefix.length;i++)
			prefix[i]=i*1L*(i+1)/2+prefix[i-1];
		s=sc.nextInt()-1;
		new Thread(null, new B(), "_cf", 1 << 28).start();}
static int n,s;
/*	static int getA(int x)
	{
		int ans=-1;
		int lo=0,hi=14142;
		while(lo<=hi)
		{
			int a=lo+hi>>1;
			int sum=a*(a+1)/2;
			if(sum>x)
			{
				ans=a;
				hi=a-1;
			}
			else
				lo=a+1;
		}
		return ans;
	}*/
	static int getA(int x)
	{
		int ans=(int) (Math.sqrt(2*x+0.25)-0.5);
		return ans+1;
	}
	static edge[][]adj;
	static int counter,SCC;
	static Stack stack;
	static int []dfsNum,dfsLow,scc,sizes;
	static long []gain,prefix;
	static boolean []inScc;
		
		public static void SCC(int u)
		{
			stack.add(u);
			dfsNum[u]=dfsLow[u]=++counter;
			for(edge nxt:adj[u])
			{	
				int v=nxt.node;
				if(dfsNum[v]==0)
					SCC(v);
				if(!inScc[v])
					dfsLow[u]=Math.min(dfsLow[u], dfsLow[v]);
			}
			
			if(dfsLow[u]==dfsNum[u])
			{
				long g=0;
				ArrayList<Integer> nodes=new ArrayList();
				
				while(true)
				{
					int v=stack.pop();
					scc[v]=SCC;
					nodes.add(v);
					
					inScc[v]=true;
					if(u==v)
						break;
				}
				for(int v:nodes)
					for(edge nxt:adj[v])
					{
						if(scc[nxt.node]!=scc[v])
							continue;
						int c=nxt.cost;
						
						int a=getA(c);
						g+=c*1L*a-prefix[a-1];
						
					}
				
				gain[SCC++]=g;
			}
		}
	public void run() 
	{
		
		
		SCC=0;
		stack=new Stack();
		dfsNum=new int [n];
		dfsLow=new int [n];
		inScc=new boolean[n];
		gain=new long [n];
		scc=new int [n];
		for(int i=0;i<n;i++)
			if(dfsNum[i]==0)
				SCC(i);
	
		ArrayList<edge> []DAG=new ArrayList[SCC];
		long []val=new long[n];
		for(int i=0;i<SCC;i++)
		{
			DAG[i]=new ArrayList();
			val[i]=gain[i];
		}
		int []deg=new int [SCC];
		long ans=0;
	
		
		
		Queue q=new Queue();
		q.add(s);
		boolean []inQueue=new boolean[n];
		inQueue[s]=true;
		
		
		while(!q.isEmpty())
		{
			int u=q.poll();
			for(edge nxt:adj[u])
			{
				int v=nxt.node;
				if(scc[u]!=scc[v])
				{
					DAG[scc[u]].add(new edge(scc[v],nxt.cost));
					deg[scc[v]]++;
				}
				if(!inQueue[v])
				{
					inQueue[v]=true;
					q.add(v);
				}
			}
		}
		q=new Queue();
		q.add(scc[s]);
		while(!q.isEmpty())
		{
			int u=q.poll();
			ans=Math.max(ans, val[u]);
			for(edge nxt:DAG[u])
			{	
				int v=nxt.node;
				val[v]=Math.max(val[v], gain[v]+val[u]+nxt.cost);
				if(--deg[v]==0)
					q.add(v);
			}	

		}
		System.out.println(ans);

	
	
	}
	static class Queue
	{
		int back,front;
		int []a;
		int size=0;
		public Queue()
		{
			
			a=new int [n];
		}
		public int poll()
		{
			size--;
			return a[back++];
		}
		public void add(int x)
		{
			size++;
			a[front++]=x;
		}
		public boolean isEmpty()
		{
			return size==0;
		}
	}
	static class Stack
	{
		int top;
		int []a;
		
		public Stack()
		{
			top=-1;
			a=new int [n];
		}
		public int pop()
		{
			return a[top--];
		}
		public void add(int x)
		{
			a[++top]=x;
		}
		public boolean isEmpty()
		{
			return top==-1;
		}
	}
	 static edge[][] packU(int n, int[] from, int[] to,int []w) {
	        edge[][] g = new edge[n][];
	        int[] p = new int[n];
	        for (int f : from)
	            p[f]++;
	        
	        for (int i = 0; i < n; i++)
	            g[i] = new edge[p[i]];
	        for (int i = 0; i < from.length; i++) {
	            g[from[i]][--p[from[i]]] = new edge(to[i],w[i]);
	      
	        }
	        return g;
	    }
	static class edge
	{
		int node,cost;
		edge(int a,int b){
			node=a;
			cost=b;
		}
	}
	
	static class Scanner {
        StringTokenizer st;
        BufferedReader br;
 
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }
 
        public Scanner(String file) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(file));
        }
 
        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
 
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        public String nextLine() throws IOException {
            return br.readLine();
        }
        public boolean ready() throws IOException {return br.ready();}
        public double nextDouble() throws IOException {return Double.parseDouble(next());}
       
    }

}