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;
inline long long read() {
  long long f = 1, w = 0;
  char x = 0;
  while (x < '0' || x > '9') {
    if (x == '-') f = -1;
    x = getchar();
  }
  while (x != EOF && x >= '0' && x <= '9') {
    w = (w << 3) + (w << 1) + (x ^ 48);
    x = getchar();
  }
  return w * f;
}
const long long N = 1e6 + 10;
long long n, num_edge, S;
long long m, num_Sdge, Time, Cnt, Top;
long long Low[N], Vis[N], Val[N], U[N];
long long head[N], Sead[N], Dfn[N], f[N];
long long V[N], D[N], Col[N], Dag[N], Stk[N];
struct Edge {
  long long next, to, dis;
} edge[N], Sdge[N];
inline long long SM(long long W) {
  long long X = (sqrt(1 + (W << 3)) - 1) / 2;
  return W * (X + 1) - X * (X + 1) * (X + 2) / 6;
}
inline void Add(long long from, long long to, long long dis) {
  edge[++num_edge].next = head[from];
  edge[num_edge].dis = dis;
  edge[num_edge].to = to;
  head[from] = num_edge;
}
inline void Sdd(long long from, long long to, long long dis) {
  Sdge[++num_Sdge].next = Sead[from];
  Sdge[num_Sdge].dis = dis;
  Sdge[num_Sdge].to = to;
  Sead[from] = num_Sdge;
}
inline void Tarjan(long long pos) {
  Dfn[pos] = Low[pos] = ++Time, Stk[++Top] = pos, Vis[pos] = 1;
  for (long long i = head[pos]; i; i = edge[i].next)
    if (!Dfn[edge[i].to])
      Tarjan(edge[i].to), Low[pos] = min(Low[edge[i].to], Low[pos]);
    else if (Vis[edge[i].to])
      Low[pos] = min(Dfn[edge[i].to], Low[pos]);
  if (Low[pos] == Dfn[pos]) {
    long long Now;
    ++Cnt;
    do Now = Stk[Top--], Vis[Now] = 0, Col[Now] = Cnt;
    while (Now != pos);
  }
}
signed main() {
  n = read(), m = read();
  for (long long i = 1; i <= m; i++)
    U[i] = read(), V[i] = read(), D[i] = read(), Add(U[i], V[i], D[i]);
  S = read();
  for (long long i = 1; i <= n; i++)
    if (!Dfn[i]) Tarjan(i);
  for (long long i = 1; i <= m; i++)
    if (Col[U[i]] == Col[V[i]]) Val[Col[U[i]]] += SM(D[i]);
  for (long long i = 1; i <= n; i++)
    for (long long j = head[i]; j; j = edge[j].next)
      if (Col[i] != Col[edge[j].to])
        Sdd(Col[i], Col[edge[j].to], edge[j].dis + Val[Col[edge[j].to]]),
            Dag[Col[edge[j].to]]++;
  queue<long long> Q;
  for (long long i = 1; i <= Cnt; i++) f[i] = -(1LL << 60);
  f[Col[S]] = Val[Col[S]];
  for (long long i = 1; i <= Cnt; i++)
    if (!Dag[i]) Q.push(i);
  while (Q.size()) {
    long long x = Q.front();
    Q.pop();
    for (long long i = Sead[x]; i; i = Sdge[i].next) {
      f[Sdge[i].to] = max(f[Sdge[i].to], f[x] + Sdge[i].dis);
      if (!(--Dag[Sdge[i].to])) Q.push(Sdge[i].to);
    }
  }
  long long Max = 0;
  for (long long i = 1; i <= Cnt; i++) Max = max(Max, f[i]);
  printf("%lld", Max);
  return 0;
}