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>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int readint() {
  int now = 0, f = 0;
  register char c = gc();
  for (; c < 48 || c > 57; c == '-' && (f = 1), c = gc())
    ;
  for (; c > 47 && c < 58; now = (now << 3) + (now << 1) + c - '0', c = gc())
    ;
  return f ? -now : now;
}
inline long long readll() {
  long long now = 0;
  int f = 0;
  register char c = gc();
  for (; c < 48 || c > 57; c == '-' && (f = 1), c = gc())
    ;
  for (; c > 47 && c < 58; now = (now << 3) + (now << 1) + c - '0', c = gc())
    ;
  return f ? -now : now;
}
int n, m, start, deg[1000005];
long long pre[1000005], pre_sz, pres[1000005], a[1000005], dp[1000005];
vector<pair<int, long long> > g[1000005], ng[1000005];
vector<int> order;
int dfn[1000005], low[1000005], instk[1000005], scc[1000005];
int index_ = 0, cnt = 0, st[1000005], top;
void tarjan(int x) {
  low[x] = dfn[x] = ++index_;
  st[++top] = x;
  instk[x] = 1;
  for (int i = 0; i < g[x].size(); ++i)
    if (!dfn[g[x][i].first])
      tarjan(g[x][i].first), low[x] = min(low[x], low[g[x][i].first]);
    else if (instk[g[x][i].first])
      low[x] = min(low[x], dfn[g[x][i].first]);
  if (dfn[x] == low[x]) {
    cnt++;
    while (st[top] != x) scc[st[top]] = cnt, instk[st[top--]] = 0;
    scc[st[top]] = cnt, instk[st[top--]] = 0;
  }
}
inline long long calc(long long x) {
  int l = 0, r = pre_sz;
  while (r - l > 1) {
    int mid = l + r >> 1;
    if (pre[mid] < x)
      l = mid;
    else
      r = mid;
  }
  long long ans = (l + 1) * x - pres[l];
  return ans;
}
signed main() {
  for (int i = 1; i < 1000005; ++i) pre[i] = i + pre[i - 1];
  pre_sz = 1000005 - 1;
  for (int i = 1; i <= pre_sz; ++i) pres[i] = pre[i] + pres[i - 1];
  n = readint(), m = readint();
  for (int i = 0; i < m; ++i) {
    int x = readint(), y = readint();
    long long c = readll();
    g[x].push_back({y, c});
  }
  start = readint();
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) tarjan(i);
  for (int u = 1; u <= n; ++u)
    for (auto [v, cost] : g[u])
      if (scc[u] == scc[v])
        a[scc[u]] += calc(cost);
      else
        ng[scc[u]].push_back({scc[v], cost}), deg[scc[v]]++;
  int head = 0, tail = 0, *que = new int[cnt << 1];
  for (int i = 1; i <= cnt; i++)
    if (!deg[i]) que[tail++] = i;
  while (head < tail) {
    int u = que[head++];
    order.push_back(u);
    for (auto [v, cost] : ng[u])
      if (!--deg[v]) que[tail++] = v;
  }
  reverse(order.begin(), order.end());
  for (auto &u : order) {
    for (auto [v, cost] : ng[u]) dp[u] = max(dp[u], dp[v] + cost);
    dp[u] += a[u];
  }
  printf("%lld\n", dp[scc[start]]);
  return 0;
}