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;
template <typename T>
inline int len(const T &a) {
  return a.size();
}
struct edge {
  int v, u, w;
};
constexpr int maxn = 1e6 + 10;
int n, m;
edge es[maxn];
vector<int> g[maxn], ig[maxn];
vector<int> order;
int gp[maxn], mark[maxn];
void dfs(int v) {
  mark[v] = 1;
  for (auto &u : g[v]) {
    if (!mark[u]) {
      dfs(u);
    }
  }
  order.push_back(v);
}
void sfd(int v, int root) {
  gp[v] = root;
  mark[v] = 2;
  for (auto &u : ig[v]) {
    if (mark[u] != 2) {
      sfd(u, root);
    }
  }
}
void scc() {
  for (int i = 0; i < n; ++i) {
    if (!mark[i]) {
      dfs(i);
    }
  }
  reverse(order.begin(), order.end());
  for (auto &v : order) {
    if (mark[v] != 2) {
      sfd(v, v);
    }
  }
}
vector<pair<int, int>> ng[maxn];
long long val[maxn], dp[maxn];
void run_dp(int v) {
  mark[v] = 1;
  for (auto &u : ng[v]) {
    if (mark[u.first] != 2) {
      run_dp(u.first);
    }
    dp[v] = max(dp[v], dp[u.first] + u.second + val[v]);
  }
  mark[v] = 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int v, u, w;
    cin >> v >> u >> w;
    g[--v].push_back(--u);
    ig[u].push_back(v);
    es[i] = {v, u, w};
  }
  scc();
  for (int i = 0; i < m; ++i) {
    if (gp[es[i].v] == gp[es[i].u]) {
      int low = 0, high = 1e5;
      while (high - low > 0) {
        int mid = (low + high + 1) >> 1;
        if ((1ll * mid * (mid + 1)) / 2 < es[i].w) {
          low = mid;
        } else {
          high = mid - 1;
        }
      }
      val[gp[es[i].v]] +=
          1ll * (low + 1) * es[i].w - (1ll * low * (low + 1) * (low + 2)) / 6;
    } else {
      ng[gp[es[i].v]].push_back({gp[es[i].u], es[i].w});
    }
  }
  for (int i = 0; i < n; ++i) {
    dp[i] = val[i];
  }
  int start;
  cin >> start;
  --start;
  memset(mark, 0, sizeof(mark));
  run_dp(gp[start]);
  cout << dp[gp[start]];
}