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;
const long long inf = 0x3f3f3f3f;
const double eps = 1e-6;
const long long mod = 1000000007;
namespace fastio {
char in[100000];
long long itr = 0, llen = 0;
char get() {
  if (itr == llen) llen = fread(in, 1, 100000, stdin), itr = 0;
  if (llen == 0) return EOF;
  return in[itr++];
}
char out[100000];
long long itr2 = 0;
void put(char c) {
  out[itr2++] = c;
  if (itr2 == 100000) {
    fwrite(out, 1, 100000, stdout);
    itr2 = 0;
  }
}
long long clear() {
  fwrite(out, 1, itr2, stdout);
  itr2 = 0;
  return 0;
}
long long getint() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = get();
  while (c != '-' && (c < '0' || c > '9')) c = get();
  if (c == '-') ng = 1, c = get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = get();
  return ng ? -r : r;
}
string getstr() {
  string ret = "";
  char ch = get();
  while (ch == ' ' || ch == '\n') ch = get();
  while (ch != ' ' && ch != '\n') ret.push_back(ch), ch = get();
  return ret;
}
void putstr(string s) {
  for (long long i = 0; i < s.size(); i++) put(s[i]);
}
void putint(long long x) {
  if (x == 0) {
    put('0');
    return;
  }
  char c[40];
  long long pos = 0;
  while (x) {
    c[pos++] = '0' + x % 10;
    x /= 10;
  }
  for (long long i = pos - 1; i >= 0; i--) put(c[i]);
}
}  // namespace fastio
using namespace fastio;
long long n, m;
vector<pair<long long, long long> > g[1000005];
long long dfn[1000005], lowlink[1000005], cnt = 1;
vector<pair<long long, long long> > ng[1000005];
long long sccval[1000005], mem[1000005], vis[1000005];
vector<long long> all;
void dfs(long long x) {
  lowlink[x] = dfn[x] = cnt++;
  vis[x] = 1;
  all.push_back(x);
  for (long long i = 0; i < g[x].size(); i++) {
    long long to = g[x][i].first;
    if (!dfn[to])
      dfs(to), lowlink[x] = min(lowlink[x], lowlink[to]);
    else if (vis[to])
      lowlink[x] = min(lowlink[x], lowlink[to]);
  }
  if (dfn[x] == lowlink[x]) {
    while (1) {
      long long T = all.back();
      all.pop_back();
      lowlink[T] = dfn[x];
      vis[T] = 0;
      if (T == x) break;
    }
  }
}
long long dfs2(long long x) {
  if (mem[x] != -1) return mem[x];
  long long ret = sccval[x];
  for (long long i = 0; i < ng[x].size(); i++) {
    ret = max(ret, ng[x][i].second + dfs2(ng[x][i].first) + sccval[x]);
  }
  return mem[x] = ret;
}
long long memory[1000005], ini1[1000005], ini[1000005];
long long Get(long long x) {
  if (memory[x] != 0 || x == 0) memory[x];
  long long ret = 0;
  for (long long i = 1; i <= x; i++) {
    ret += i * (i + 1);
    memory[i] = ret;
  }
  return ret;
}
long long calc(long long w) {
  long long l = 0, r = 20000, ans = 0;
  while (l <= r) {
    long long mid = l + r >> 1;
    if (ini1[mid] > w)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return 1ll * w * (r + 1) - ini[r];
}
signed main() {
  for (long long i = 1; i <= 1000005; i++) {
    ini1[i] = ini1[i - 1] + i;
  }
  for (long long i = 1; i <= 1000005; i++) {
    ini[i] = ini[i - 1] + ini1[i];
  }
  n = getint();
  m = getint();
  for (long long i = 0; i < m; i++) {
    long long x = getint(), y = getint(), z = getint();
    g[x].push_back(make_pair(y, z));
  }
  long long s = getint();
  dfs(s);
  for (long long i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < g[i].size(); j++) {
      long long to = g[i][j].first, val = g[i][j].second;
      if (lowlink[to] == lowlink[i]) {
        sccval[lowlink[to]] += calc(val);
      } else {
        ng[lowlink[i]].push_back(make_pair(lowlink[to], val));
      }
    }
  }
  memset(mem, -1, sizeof(mem));
  long long ans = dfs2(1);
  cout << ans << endl;
  return 0;
}