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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 1000005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void file_put() {
  freopen("filename.in", "r", stdin);
  freopen("filename.out", "w", stdout);
}
long long sum(long long x) {
  long long y = 2 * x;
  y = floor(sqrt(y * 1.0)) - 3;
  y = ((y) > (0) ? (y) : (0));
  while ((y + 1) * (y + 2) / 2 <= x) y++;
  return -(y * y + 2 * y - 6 * x) * (y + 1) / 6;
}
const int _N = 1e6 + 5, _M = 1e6 + 5;
struct Tu {
  int head[_N], nxt[_M], e[_M], n, tot;
  long long v[_N], w[_M];
  void Init(int _n) { n = _n, memset(head, 0, sizeof(head)), tot = 0; }
  void I(int x, int y, long long _w) {
    e[++tot] = y, w[tot] = _w;
    nxt[tot] = head[x], head[x] = tot;
  }
};
struct Tarjan {
  int id[_N], dfn[_N], low[_N], s[_N], n, r, t, tot;
  bool in[_N];
  void dfs(Tu &A, int x) {
    dfn[x] = low[x] = ++t, in[x] = 1, s[++r] = x;
    for (int i = A.head[x], y; i; i = A.nxt[i])
      if (!dfn[y = A.e[i]])
        dfs(A, y), low[x] = ((low[x]) < (low[y]) ? (low[x]) : (low[y]));
      else if (in[y])
        low[x] = ((low[x]) < (dfn[y]) ? (low[x]) : (dfn[y]));
    if (low[x] == dfn[x]) {
      ++tot;
      while (r && s[r + 1] != x) id[s[r]] = tot, in[s[r--]] = 0;
    }
  }
  void solve(Tu &A, Tu &B) {
    n = A.n;
    memset(dfn, 0, sizeof(dfn));
    memset(low, 0, sizeof(low));
    memset(in, 0, sizeof(in));
    r = tot = t = 0;
    for (int x = (1); x <= (n); ++x)
      if (!dfn[x]) dfs(A, x);
    B.Init(tot);
    memset(B.v, 0, sizeof(B.v));
    for (int x = (1); x <= (n); ++x)
      for (int i = A.head[x]; i; i = A.nxt[i])
        if (id[x] == id[A.e[i]])
          B.v[id[x]] += sum(A.w[i]);
        else
          B.I(id[x], id[A.e[i]], A.w[i]);
  }
};
bool vis[N];
long long dp[N], w;
Tu A, B;
Tarjan T;
int n, m, x, y, s0;
void dfs(int x, int p) {
  if (vis[x]) return;
  vis[x] = 1;
  for (int i = B.head[x]; i; i = B.nxt[i]) {
    if (B.e[i] == p) continue;
    dfs(B.e[i], x);
    dp[x] = ((dp[x]) > (dp[B.e[i]] + B.w[i]) ? (dp[x]) : (dp[B.e[i]] + B.w[i]));
  }
  dp[x] += B.v[x];
}
int main() {
  scanf("%d%d", &n, &m);
  memset(vis, 0, sizeof(vis));
  A.Init(n);
  for (int i = (1); i <= (m); ++i) {
    scanf("%d%d%I64d", &x, &y, &w);
    A.I(x, y, w);
  }
  T.solve(A, B);
  scanf("%d", &s0);
  dfs(T.id[s0], 0);
  printf("%I64d\n", dp[T.id[s0]]);
  return 0;
}