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 int n, m;
vector<pair<long long int, long long int> > a[2000000];
stack<long long int> sr;
bool is[1000005];
long long int sl[30005];
long long int s;
long long int sur[30005];
long long int co[1000005];
long long int disc[1000005];
long long int low[10000005];
long long int ch[1000005];
vector<long long int> p[1000005];
vector<pair<long long int, long long int> > b[1000005];
long long int t = 1;
long long int cr = 1;
long long int c[1000005];
long long int sol[1000005];
void tarjan(long long int u) {
  sr.push(u);
  is[u] = true;
  disc[u] = t;
  low[u] = t;
  t++;
  long long int v;
  for (long long int i = 0; i < a[u].size(); i++) {
    v = a[u][i].first;
    if (disc[v] == 0) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else {
      if (is[v]) low[u] = min(low[u], disc[v]);
    }
  }
  if (low[u] == disc[u]) {
    while (sr.top() != u) {
      v = sr.top();
      is[v] = false;
      co[v] = cr;
      sr.pop();
    }
    v = sr.top();
    is[v] = false;
    co[v] = cr;
    sr.pop();
    cr++;
  }
}
long long int solu(long long int w) {
  long long int l = 0;
  long long int r = 20000;
  long long int mid;
  while (l < r) {
    mid = (l + r + 1) >> 1;
    if (sur[mid] >= w)
      r = mid - 1;
    else
      l = mid;
  }
  while (sur[l + 1] < w) l++;
  l++;
  while (sur[l - 1] > w) l--;
  long long int u, v, q;
  v = w;
  u = l;
  q = sl[l - 1];
  return v * u - q;
}
long long int best_path(long long int u) {
  vector<long long int> q;
  for (long long int i = 1; i < cr; i++)
    if (ch[i] == 0) q.push_back(i);
  long long int ind = 0;
  long long int v;
  while (ind < q.size()) {
    v = q[ind];
    sol[v] = c[v];
    for (long long int i = 0; i < b[v].size(); i++) {
      sol[v] = max(sol[v], b[v][i].second + sol[b[v][i].first] + c[v]);
    }
    for (long long int i = 0; i < p[v].size(); i++) {
      ch[p[v][i]]--;
      if (ch[p[v][i]] == 0) q.push_back(p[v][i]);
    }
    ind++;
  }
  return sol[u];
}
int main() {
  sl[1] = 1;
  sur[1] = 1;
  for (long long int i = 2; i <= 20000; i++) {
    sur[i] = (i * (i + 1)) / 2;
    sl[i] = sl[i - 1] + sur[i];
  }
  long long int u, v, w;
  scanf("%lld %lld", &n, &m);
  for (long long int i = 0; i < m; i++) {
    scanf("%lld %lld %lld", &u, &v, &w);
    u--;
    v--;
    a[u].push_back(make_pair(v, w));
  }
  scanf("%lld", &s);
  s--;
  tarjan(s);
  for (long long int i = 0; i < n; i++) {
    if (co[i] > 0) {
      for (long long int j = 0; j < a[i].size(); j++) {
        v = a[i][j].first;
        w = a[i][j].second;
        if (co[v] == co[i])
          c[co[i]] += solu(w);
        else {
          b[co[i]].push_back(make_pair(co[v], w));
          ch[co[i]]++;
          p[co[v]].push_back(co[i]);
        }
      }
    }
  }
  cout << best_path(co[s]) << endl;
  return 0;
}