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;
long long read() {
  long long x = 0, f = 1, ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const long long MAXN = 1000000 + 10, MAXM = 1000000 + 10, INF = 0x3f3f3f3f3f3f;
long long head[MAXN], _next[MAXM], to[MAXM], weigh[MAXM], cnt;
void addedge(long long u, long long v, long long w) {
  cnt++;
  _next[cnt] = head[u];
  head[u] = cnt;
  to[cnt] = v;
  weigh[cnt] = w;
}
long long dfn[MAXN], low[MAXN], ins[MAXN], tot, id[MAXN], color, mush[MAXN];
stack<long long> s;
void tarjan(long long u) {
  low[u] = dfn[u] = ++tot;
  s.push(u);
  ins[u] = 1;
  for (long long i = head[u]; i; i = _next[i]) {
    long long v = to[i];
    if (!dfn[v])
      tarjan(v), low[u] = min(low[u], low[v]);
    else if (ins[v])
      low[u] = min(low[u], low[v]);
  }
  if (dfn[u] == low[u]) {
    long long v;
    color++;
    do {
      v = s.top();
      s.pop();
      ins[v] = 0;
      id[v] = color;
    } while (u != v);
  }
}
vector<pair<long long, long long> > g[MAXN];
queue<long long> q;
long long inq[MAXN], dist[MAXN];
void SPFA(long long s) {
  q.push(s);
  inq[s] = 1;
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    inq[u] = 0;
    for (register long long i = 0; i <= (long long)g[u].size() - 1; i++) {
      long long v = g[u][i].first;
      if (dist[v] < dist[u] + g[u][i].second) {
        dist[v] = dist[u] + g[u][i].second;
        if (!inq[v]) {
          inq[v] = 1;
          q.push(v);
        }
      }
    }
  }
}
long long calc(long long x) {
  long long tt = sqrt(2 * x + 0.25) - 0.5;
  return x + tt * x - (tt + 1) * (tt + 2) * tt / 6;
}
long long in[MAXN];
void topo(long long st) {
  dist[id[st]] = mush[id[st]];
  for (long long i = 1; i <= color; ++i)
    if (!in[i]) q.push(i);
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (register long long i = 0; i <= (long long)g[u].size() - 1; i++) {
      long long v = g[u][i].first;
      if (--in[v] == 0) q.push(v);
      dist[v] = max(dist[v], dist[u] + g[u][i].second);
    }
  }
}
long long dfs(long long u) {
  if (dist[u]) return dist[u];
  for (register long long i = 0; i <= (long long)g[u].size() - 1; i++)
    dist[u] = max(dist[u], g[u][i].second + dfs(g[u][i].first));
  return dist[u] += mush[u];
}
signed main() {
  long long n = read(), m = read();
  for (register long long i = 1; i <= m; i++) {
    long long u = read(), v = read(), w = read();
    addedge(u, v, w);
  }
  for (register long long i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  for (register long long u = 1; u <= n; u++) {
    for (long long i = head[u]; i; i = _next[i]) {
      long long v = to[i];
      if (id[u] == id[v]) {
        mush[id[u]] += calc(weigh[i]);
      }
    }
  }
  for (register long long u = 1; u <= n; u++) {
    for (long long i = head[u]; i; i = _next[i]) {
      long long v = to[i];
      if (id[u] == id[v]) continue;
      g[id[u]].push_back(make_pair(id[v], weigh[i]));
      in[id[v]]++;
    }
  }
  long long s = read(), ans = 0;
  for (register long long i = 1; i <= color; i++) ans = max(ans, dist[i]);
  printf("%lld\n", dfs(id[s]));
  return 0;
}