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;
vector<int> phnode[1000010];
int ph = 0;
int node[1000010];
int num[1000010];
int low[1000010];
bool chk[1000010];
int cnt = 0;
long long sccost[1000010];
vector<long long> cost[1000010];
vector<int> edge[1000010];
vector<long long> phcost[1000010];
vector<int> phedge[1000010];
vector<int> trace;
void dfs(int u) {
  chk[u] = true;
  low[u] = ++cnt;
  num[u] = cnt;
  bool isroot = true;
  trace.push_back(u);
  for (int i = 0; i < edge[u].size(); i++) {
    int v = edge[u][i];
    if (!chk[v]) dfs(v);
    if (low[u] > low[v]) {
      low[u] = low[v];
      isroot = false;
    }
  }
  if (isroot) {
    ph++;
    while (true) {
      int x = trace.back();
      trace.pop_back();
      node[x] = ph;
      phnode[ph].push_back(x);
      low[x] = 0x7fffffff;
      if (x == u) break;
    }
  }
}
void scc(int n) {
  for (int i = 1; i <= n; i++) {
    if (chk[i]) continue;
    dfs(i);
  }
}
int degree[1000010];
int phvisit[1000010];
long long dp[1000010];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    edge[x].push_back(y);
    cost[x].push_back(z);
  }
  scc(n);
  for (int i = 1; i <= ph; i++) {
    long long sum = 0;
    for (auto &u : phnode[i]) {
      for (int j = 0; j < cost[u].size(); j++) {
        auto &gap = cost[u][j];
        auto &nxt = edge[u][j];
        if (node[nxt] != i) {
          phedge[i].push_back(node[nxt]);
          phcost[i].push_back(gap);
          continue;
        }
        double tmp = (sqrt((double)gap * 8 + 1) - 1) / 2;
        long long f = (long long)round(tmp);
        if (gap - (f + 1) * (f + 2) / 2 >= 0)
          f = f + 1;
        else if (gap - f * (f + 1) / 2 < 0)
          f = f - 1;
        sum += gap + gap * f - f * (f + 1) * (f + 2) / 6;
      }
    }
    sccost[i] = sum;
  }
  int start;
  scanf("%d", &start);
  queue<int> q;
  q.push(node[start]);
  phvisit[node[start]] = 1;
  while (q.size()) {
    int here = q.front();
    q.pop();
    for (int i = 0; i < phedge[here].size(); i++) {
      int nxt = phedge[here][i];
      if (phvisit[nxt]) continue;
      phvisit[nxt] = 1;
      q.push(nxt);
    }
  }
  for (int i = 1; i <= ph; i++) {
    if (!phvisit[i]) continue;
    for (auto &v : phedge[i])
      if (phvisit[v]) degree[v]++;
  }
  for (int i = 1; i <= ph; i++) {
    if (!phvisit[i]) continue;
    if (degree[i] == 0) q.push(i);
  }
  long long ans = 0;
  while (q.size()) {
    int here = q.front();
    q.pop();
    dp[here] += sccost[here];
    if (ans < dp[here]) ans = dp[here];
    for (int i = 0; i < phedge[here].size(); i++) {
      int nxt = phedge[here][i];
      if (!phvisit[nxt]) continue;
      if (degree[nxt]-- == 1) q.push(nxt);
      if (dp[nxt] < dp[here] + phcost[here][i])
        dp[nxt] = dp[here] + phcost[here][i];
    }
  }
  printf("%lld\n", ans);
  return 0;
}