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 MAX_N = 1000000;
int my_scc[MAX_N], sccno, N;
bool visited[MAX_N];
long long cost[MAX_N];
stack<int> topo;
vector<int> g[MAX_N], revg[MAX_N];
void dfs(int u) {
  visited[u] = true;
  for (const auto& v : g[u])
    if (!visited[v]) dfs(v);
  topo.push(u);
}
void dfs2(int u) {
  visited[u] = true;
  my_scc[u] = sccno - 1;
  for (const auto& v : revg[u])
    if (!visited[v]) dfs2(v);
}
void kosaraju() {
  memset(visited, false, sizeof visited);
  for (int u = (int)0; u < (int)N; ++u) {
    if (!visited[u]) dfs(u);
    for (const auto& v : g[u]) revg[v].push_back(u);
  }
  memset(visited, false, sizeof visited);
  sccno = 0;
  while (topo.size()) {
    int u = topo.top();
    topo.pop();
    if (!visited[u]) {
      ++sccno;
      dfs2(u);
    }
  }
}
const int MAX_SQ = 14150;
vector<pair<int, long long>> newg[MAX_N];
long long prefixsum[MAX_SQ], memo[MAX_N];
tuple<int, int, int> edges[MAX_N];
inline long long gauss(long long k) { return (k * (1LL + k)) >> 1; }
long long getidx(long long val) {
  int low = 0, high = MAX_SQ, mid, best;
  while (low <= high) {
    mid = (low + high) >> 1;
    if (gauss(mid) > val) {
      high = mid - 1;
      best = mid;
    } else
      low = 1 + mid;
  }
  return best;
}
long long dp(int u) {
  if (~memo[u]) return memo[u];
  long long ans = 0LL;
  for (const pair<int, long long> p : newg[u])
    ans = max(ans, p.second + dp(p.first));
  return memo[u] = ans + cost[u];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(memo, -1, sizeof memo);
  prefixsum[0] = 0LL;
  for (int i = (int)1; i < (int)MAX_SQ; ++i)
    prefixsum[i] = prefixsum[i - 1] + gauss(i);
  int m, s, u, v, c;
  cin >> N >> m;
  for (int i = (int)0; i < (int)m; ++i) {
    cin >> u >> v >> c;
    --u;
    --v;
    get<0>(edges[i]) = u;
    get<1>(edges[i]) = v;
    get<2>(edges[i]) = c;
    g[u].push_back(v);
  }
  kosaraju();
  long long idx;
  for (int i = (int)0; i < (int)m; ++i) {
    u = get<0>(edges[i]);
    v = get<1>(edges[i]);
    c = get<2>(edges[i]);
    if (my_scc[u] == my_scc[v]) {
      idx = getidx(c);
      cost[my_scc[u]] += ((idx * (long long)c) - prefixsum[idx - 1]);
    } else
      newg[my_scc[u]].push_back({my_scc[v], c});
  }
  cin >> s;
  cout << dp(my_scc[s - 1]);
  return 0;
}