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:
// practice with rainboy
import java.io.*;
import java.util.*;

public class CF894E extends PrintWriter {
	CF894E() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF894E o = new CF894E(); o.main(); o.flush();
	}

	static class L {
		L next; int e;
		L(L next, int e) {
			this.next = next; this.e = e;
		}
	}
	L[] ao, ai;
	int[] ii, jj, ww;
	int[] po, cc;
	int npo;
	int[] stack;
	void dfs1(int i) {
		int cnt = 0;
		stack[cnt++] = i;
		while (cnt > 0) {
			i = stack[cnt - 1];
			if (cc[i] == 0) {
				cc[i] = 1;
				for (L l = ao[i]; l != null; l = l.next) {
					int h = l.e;
					int j = jj[h];
					if (cc[j] == 0)
						stack[cnt++] = j;
				}
			} else {
				cnt--;
				if (cc[i] == 1) {
					po[npo++] = i;
					cc[i] = -1;
				}
			}
		}
	}
	void dfs2(int c) {
		int cnt = 0;
		cc[c] = c; stack[cnt++] = c;
		while (cnt > 0) {
			int j = stack[--cnt];
			for (L l = ai[j]; l != null; l = l.next) {
				int h = l.e;
				int i = ii[h];
				if (cc[i] == -1) {
					cc[i] = c; stack[cnt++] = i;
				}
			}
		}
	}
	long all(int w) {
		int n = (int) Math.sqrt(w << 1) - 1;
		while ((n + 1) * (n + 2) <= w << 1)
			n++;
		return (long) (n + 1) * w - (long) n * (n + 1) * (n + 2) / 6;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		ao = new L[n];
		ai = new L[n];
		ii = new int[m];
		jj = new int[m];
		ww = new int[m];
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			ww[h] = sc.nextInt();
			ii[h] = i;
			jj[h] = j;
			ao[i] = new L(ao[i], h);
			ai[j] = new L(ai[j], h);
		}
		int s = sc.nextInt() - 1;
		stack = new int[Math.max(m + 1, n)];
		po = new int[n];
		cc = new int[n];
		for (int i = 0; i < n; i++)
			if (cc[i] == 0)
				dfs1(i);
		for (int h = n - 1; h >= 0; h--) {
			int j = po[h];
			if (cc[j] == -1)
				dfs2(j);
		}
		L[] ao_ = new L[n];
		long[] ww_ = new long[n];
		for (int h = 0; h < m; h++) {
			int i = cc[ii[h]];
			int j = cc[jj[h]];
			if (i == j)
				ww_[i] += all(ww[h]);
			else
				ao_[i] = new L(ao_[i], h);
		}
		long[] dp = new long[n];
		Arrays.fill(dp, -1);
		dp[cc[s]] = 0;
		long ans = 0;
		for (int h = n - 1; h >= 0; h--) {
			int i = po[h];
			if (cc[i] == i && dp[i] >= 0) {
				dp[i] += ww_[i];
				if (ans < dp[i])
					ans = dp[i];
				if (ao_[i] == null)
					continue;
				for (L l = ao_[i]; l != null; l = l.next) {
					int h_ = l.e;
					int j = cc[jj[h_]];
					long w_ = dp[i] + ww[h_];
					if (dp[j] < w_)
						dp[j] = w_;
				}
			}
		}
		println(ans);
	}
}