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;
void _dbg(string) { cout << endl; }
template <class H, class... T>
void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cout << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
using P = pair<int, int>;
class SCC {
 private:
  vector<vector<P>> &G;
  vector<vector<P>> &rG;
  vector<bool> used;
  vector<int> vs;
  int n;
  void dfs(int v) {
    used[v] = true;
    for (auto to : G[v])
      if (!used[to.first]) dfs(to.first);
    vs.push_back((v));
  }
  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    group.back().push_back((v));
    for (auto to : rG[v])
      if (!used[to.first]) {
        rdfs(to.first, k);
      }
  }

 public:
  vector<int> cmp;
  vector<vector<int>> group;
  int gc = 0;
  SCC(vector<vector<P>> &g, vector<vector<P>> &r) : G(g), rG(r) {
    n = G.size();
    used = vector<bool>(n, false);
    cmp.resize(n);
    for (int i = (int)(0); i < (int)(n); i++)
      if (!used[i]) dfs(i);
    fill((used).begin(), (used).end(), false);
    for (int i = vs.size() - 1; i >= 0; i--)
      if (!used[vs[i]]) {
        group.push_back((vector<int>()));
        rdfs(vs[i], gc++);
      }
  }
  inline bool same(int i, int j) { return cmp[i] == cmp[j]; }
  inline int operator[](int i) { return cmp[i]; }
};
unordered_map<int, long long> weight_cache;
inline long long calc_weight(int v) {
  if (weight_cache.count(v)) return weight_cache[v];
  long long l = 0, r = v;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (mid * (mid + 1) / 2 <= v)
      l = mid;
    else
      r = mid;
  }
  long long ret = l * (l + 1) * (2 * l + 1) / 6 + (v - l * (l + 1) / 2) * r;
  return weight_cache[v] = ret;
}
int main() {
  for (int i = (int)(0); i < (int)(30); i++) calc_weight(i);
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<P>> g(n), rg(n);
  for (int i = (int)(0); i < (int)(m); i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    g[a].push_back((make_pair((b), (c))));
    rg[b].push_back((make_pair((a), (c))));
  }
  int s;
  scanf("%d", &s);
  s--;
  SCC scc(g, rg);
  int gn = scc.gc;
  vector<long long> val(gn, 0);
  for (int i = (int)(0); i < (int)(n); i++) {
    int grp = scc.cmp[i];
    for (auto &p : g[i])
      if (scc.cmp[p.first] == grp) val[grp] += calc_weight(p.second);
  }
  vector<long long> dp(gn, 0);
  for (int i = (int)(scc.cmp[s]); i < (int)(gn); i++)
    if (i == scc.cmp[s] || dp[i] > 0) {
      dp[i] += val[i];
      for (auto v : scc.group[i]) {
        for (auto &p : g[v]) {
          int to = scc.cmp[p.first];
          if (to != i) {
            dp[to] = max(dp[to], dp[i] + p.second);
          }
        }
      }
    }
  cout << *max_element((dp).begin(), (dp).end()) << endl;
  return 0;
}