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 long long MAXN = 1e6 + 7;
vector<long long> g[MAXN];
vector<pair<long long, long long>> gg[MAXN];
set<pair<long long, long long>> ans;
vector<long long> gt[MAXN];
vector<long long> g2[MAXN];
vector<pair<long long, long long>> gt2[MAXN];
vector<long long> topsort;
bool visited[MAXN];
long long color[MAXN];
long long cost[MAXN];
long long vis[MAXN];
long long dp[MAXN];
void topDfs(long long v) {
  visited[v] = true;
  for (long long to : g[v])
    if (!visited[to]) topDfs(to);
  topsort.push_back(v);
}
void dfs(long long v, long long clr) {
  color[v] = clr;
  for (long long to : gt[v])
    if (color[to] == -1) dfs(to, clr);
}
void getTopsort2(long long v) {
  vis[v] = 1;
  for (long long u : g2[v])
    if (!vis[u]) getTopsort2(u);
  topsort.push_back(v);
}
long long t(long long n) { return n * (n + 1) / 2; }
long long sumt(long long n) { return n * (n + 1) * (n + 2) / 6; }
long long f(long long w) {
  long long left = 0, right = 1e5;
  while (left != right - 1) {
    long long m = (left + right) >> 1;
    if (t(m) > w) {
      right = m;
    } else {
      left = m;
    }
  }
  return w * left - sumt(left) + w;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b, w;
    cin >> a >> b >> w;
    --a;
    --b;
    g[a].push_back(b);
    gt[b].push_back(a);
    gg[a].push_back({b, w});
  }
  for (long long i = 0; i < n; i++) {
    color[i] = -1;
    visited[i] = false;
  }
  for (long long i = 0; i < n; i++)
    if (!visited[i]) topDfs(i);
  long long clr = 0;
  for (long long i = topsort.size() - 1; i >= 0; --i)
    if (color[topsort[i]] == -1) {
      dfs(topsort[i], clr);
      ++clr;
    }
  for (long long v = 0; v < n; ++v)
    for (pair<long long, long long> pr : gg[v])
      if (color[v] != color[pr.first]) {
        g2[color[v]].push_back({color[pr.first]});
        gt2[color[pr.first]].push_back({color[v], pr.second});
      } else
        cost[color[v]] += f(pr.second);
  topsort.clear();
  long long s;
  cin >> s;
  --s;
  s = color[s];
  getTopsort2(s);
  reverse(topsort.begin(), topsort.end());
  dp[s] = cost[s];
  for (long long i = 0; i < n; ++i) dp[i] = (long long)(1e18);
  for (long long v : topsort) {
    dp[v] = cost[v];
    for (pair<long long, long long> pr : gt2[v])
      if (dp[pr.first] != (long long)(1e18))
        dp[v] = max(dp[v], dp[pr.first] + pr.second + cost[v]);
  }
  long long ans = -1;
  for (long long i = 0; i < n; ++i)
    if (dp[i] != (long long)(1e18)) ans = max(ans, dp[i]);
  cout << ans;
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}