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;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
template <class T>
inline T bigMod(T p, T e, T M) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
template <class T>
inline string int2String(T a) {
  ostringstream str;
  str << a;
  return str.str();
}
const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
const int maxn = 1e6 + 6;
vector<pair<int, int> > g[maxn];
int Time, cntSCC;
bool onStack[maxn];
int discoverTime[maxn], min_discoverTime[maxn];
int sccRoot[maxn];
stack<int> Stack;
void dfs_SCC(int u) {
  onStack[u] = 1;
  Stack.push(u);
  min_discoverTime[u] = discoverTime[u] = Time++;
  for (const auto& next : g[u]) {
    if (discoverTime[next.first] == -1) dfs_SCC(next.first);
    if (onStack[next.first]) {
      min_discoverTime[u] =
          min(min_discoverTime[next.first], min_discoverTime[u]);
    }
  }
  if (min_discoverTime[u] == discoverTime[u]) {
    while (true) {
      const int v = Stack.top();
      Stack.pop();
      onStack[v] = 0;
      sccRoot[v] = u;
      if (u == v) break;
    }
  }
}
struct edge {
  int x, y, c;
  edge() {}
  edge(int _x, int _y, int _c) { x = _x, y = _y, c = _c; }
} E[maxn];
vector<pair<int, int> > dag[maxn];
long long mx[maxn], totall_mushrooms[maxn];
const int maxN = 2e4;
long long sum[maxN];
long long calculate(long long w) {
  long long lo = 0, hi = maxN - 1, mid, ret = 0;
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    if (w - sum[mid] > 0)
      ret = mid, lo = mid + 1;
    else
      hi = mid - 1;
  }
  return (ret + 1) * w - ((ret * (ret + 1) * (ret + 2)) / 6);
}
long long dfs_DP(int curr) {
  if (~mx[curr]) return mx[curr];
  mx[curr] = 0;
  for (const auto& next : dag[curr]) {
    mx[curr] = max(mx[curr], dfs_DP(next.first) + next.second);
  }
  return mx[curr] += totall_mushrooms[curr];
}
int main() {
  sum[0] = 0;
  for (int i = int(1); i < int(maxN); i++) sum[i] = sum[i - 1] + i;
  int x, y, c;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = int(0); i < int(m); i++) {
    scanf("%d%d%d", &x, &y, &c), x--, y--;
    E[i] = edge(x, y, c);
    g[x].push_back(make_pair(y, c));
  }
  int k;
  scanf("%d", &k), k--;
  memset(onStack, 0, sizeof(onStack));
  memset(min_discoverTime, -1, sizeof(min_discoverTime));
  memset(discoverTime, -1, sizeof(discoverTime));
  Time = cntSCC = 0;
  dfs_SCC(k);
  for (int i = int(0); i < int(m); i++) {
    x = E[i].x;
    y = E[i].y;
    c = E[i].c;
    if (discoverTime[x] == -1 || discoverTime[y] == -1) continue;
    if (sccRoot[x] == sccRoot[y]) {
      totall_mushrooms[sccRoot[x]] += calculate(c);
    } else {
      dag[sccRoot[x]].push_back(make_pair(sccRoot[y], c));
    }
  }
  memset(mx, -1, sizeof(mx));
  long long res = dfs_DP(sccRoot[k]);
  printf("%lld\n", res);
  return 0;
}