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>
template <typename T>
void MACRO_VAR_Scan(T& t) {
  std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
  std::cin >> first;
  MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
  t.resize(n);
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {
  first.resize(n);
  MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T>
void MACRO_VEC_ROW_Scan(int p, T& t) {
  std::cin >> t[p];
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {
  std::cin >> first[p];
  MACRO_VEC_ROW_Scan(p, rest...);
}
template <typename T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <typename T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
void CHECKTIME(std::function<void()> f) {
  auto start = std::chrono::system_clock::now();
  f();
  auto end = std::chrono::system_clock::now();
  auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start))
                 .count();
  std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n";
}
template <class T>
std::vector<std::vector<T>> VV(int n) {
  return std::vector<std::vector<T>>(n);
}
template <class T>
std::vector<std::vector<T>> VV(int n, int m, T init = T()) {
  return std::vector<std::vector<T>>(n, std::vector<T>(m, init));
}
template <typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;
constexpr int INFINT_LIM = (1LL << 31) - 1;
constexpr ll INFLL = 1LL << 60;
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);
constexpr double EPS = 1e-9;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
struct StronglyConnectedComponent {
  int n;
  std::vector<std::vector<int>> g, rg;
  std::vector<bool> used;
  std::vector<int> vs;
  std::vector<int> cmp;
  StronglyConnectedComponent(int n) : n(n), g(n), rg(n), used(n), cmp(n) {}
  int operator[](int id) { return cmp[id]; }
  void addEdge(int from, int to) {
    g[from].emplace_back(to);
    rg[to].emplace_back(from);
  }
  void dfs(int v) {
    used[v] = true;
    for (auto& to : g[v]) {
      if (!used[to]) dfs(to);
    }
    vs.emplace_back(v);
  }
  void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (size_t i = 0; i < rg[v].size(); ++i) {
      if (!used[rg[v][i]]) rdfs(rg[v][i], k);
    }
  }
  int scc() {
    used.assign(n, false);
    vs.clear();
    for (size_t v = 0; v < n; ++v) {
      if (!used[v]) dfs(v);
    }
    used.assign(n, false);
    int k = 0;
    for (signed i = vs.size() - 1; i >= 0; --i) {
      if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
  }
  bool same(int u, int v) { return cmp[u] == cmp[v]; }
  std::vector<std::vector<int>> getDAG() {
    int N = scc();
    std::vector<std::vector<int>> res(N);
    std::vector<std::set<int>> set(N);
    for (int i = 0; i < int(n); ++i) {
      set[cmp[i]].insert(i);
    }
    for (int i = 0; i < int(N); ++i) {
      std::set<int> out;
      for (const auto& v : set[i]) {
        for (const auto& to : g[v]) {
          out.insert(cmp[to]);
        }
      }
      for (const auto& to : out) {
        if (i != to) res[i].emplace_back(to);
      }
    }
    return res;
  }
} scc(0);
std::vector<int> sp;
std::map<int, ll> mapmax;
inline ll calcMax(ll x) {
  auto it = std::upper_bound((sp).begin(), (sp).end(), x);
  it = std::prev(it);
  ll dis = std::distance(sp.begin(), it);
  return x * (dis + 1) - dis * (dis + 1) * (dis + 2) / 6;
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  {
    int p = 0;
    int t = 0;
    while ((t = p * (p + 1) / 2) < 400000001) {
      sp.emplace_back(t);
      ++p;
    }
  }
  int n, m, s;
  scanf("%d %d", &n, &m);
  std::vector<int> x(m), y(m), w(m);
  for (int i = 0; i < int(m); ++i) scanf("%d %d %d", &x[i], &y[i], &w[i]);
  scanf("%d", &s);
  for (int i = 0; i < int(m); ++i) --x[i], --y[i];
  --s;
  scc = StronglyConnectedComponent(n);
  for (int i = 0; i < int(m); ++i) {
    scc.addEdge(x[i], y[i]);
  }
  auto g(scc.getDAG());
  int N = g.size();
  std::vector<std::map<int, int>> e(N);
  std::vector<ll> VS(N, 0);
  for (int i = 0; i < int(m); ++i) {
    int cx = scc[x[i]], cy = scc[y[i]];
    if (cx == cy)
      VS[cx] += calcMax(w[i]);
    else
      CHMAX(e[cx][cy], w[i]);
  }
  std::vector<int> incnt(N, 0);
  {
    std::vector<bool> visited(N, false);
    std::queue<int> que;
    que.push(scc[s]);
    while (!que.empty()) {
      int now = que.front();
      que.pop();
      for (auto& to : g[now]) {
        ++incnt[to];
        if (visited[to]) continue;
        visited[to] = true;
        que.push(to);
      }
    }
  }
  std::vector<ll> max(N, 0);
  {
    std::queue<int> que;
    int S = scc[s];
    que.push(S);
    while (!que.empty()) {
      int now = que.front();
      que.pop();
      max[now] += VS[now];
      for (auto& to : g[now]) {
        CHMAX(max[to], max[now] + e[now][to]);
        --incnt[to];
        if (incnt[to] == 0) que.push(to);
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < int(N); ++i) CHMAX(ans, max[i]);
  std::cout << ans;
  std::cout << "\n";
  ;
  return 0;
}