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;
struct SCC {
  vector<bool> in_stack;
  vector<int> stack;
  int top, comp_cnt, time_stamp;
  vector<int> delta;
  vector<int> eta;
  void dfs(vector<int>* G, int v, vector<int>& C) {
    stack[top++] = v;
    in_stack[v] = 1;
    delta[v] = eta[v] = ++time_stamp;
    for (int i = (0); i < (((int)(G[v]).size())); i++) {
      if (delta[G[v][i]] == 0) {
        dfs(G, G[v][i], C);
        eta[v] = min(eta[v], eta[G[v][i]]);
      } else if (delta[G[v][i]] < delta[v] && in_stack[G[v][i]])
        eta[v] = min(eta[v], delta[G[v][i]]);
    }
    if (delta[v] == eta[v]) {
      while (top > 0 && delta[v] <= delta[stack[top - 1]]) {
        --top;
        in_stack[stack[top]] = 0;
        C[stack[top]] = comp_cnt;
      }
      ++comp_cnt;
    }
  }
  int lmSCCTarjanAlgo(vector<int>* G, int n, vector<int>& C) {
    in_stack = vector<bool>(n, 0);
    C = vector<int>(n, 0);
    delta = vector<int>(n, 0);
    eta = vector<int>(n, 0);
    stack = vector<int>(n, 0);
    top = comp_cnt = time_stamp = 0;
    for (int i = (0); i < (n); i++)
      if (delta[i] == 0) dfs(G, i, C);
    return comp_cnt;
  }
  vector<vector<int> > getDAG(vector<int>* G, int n, vector<int>& C) {
    int comp_cnt = lmSCCTarjanAlgo(G, n, C);
    vector<vector<int> > result = vector<vector<int> >(comp_cnt);
    for (int i = (0); i < (n); i++) {
      for (int j = (0); j < (((int)(G[i]).size())); j++) {
        int u = G[i][j];
        if (C[i] != C[u]) {
          result[C[i]].push_back(C[u]);
        }
      }
    }
    for (int i = (0); i < (comp_cnt); i++) {
      sort(result[i].begin(), result[i].end());
      result[i].erase(unique(result[i].begin(), result[i].end()),
                      result[i].end());
    }
    return result;
  }
};
vector<int> G[1000100];
vector<long long> M[1000100];
vector<int> GC[1000100];
long long getAll(long long m) {
  if (m == 0) return 0;
  if (m == 1) return 1;
  long long left = 1, right = m, idx;
  while (left <= right) {
    long long mid = (left + right) / 2;
    if ((mid) * (mid + 1) / 2 <= m) {
      idx = mid;
      left = mid + 1;
    } else
      right = mid - 1;
  }
  return m * (idx + 1) - idx * (idx + 1) * (idx + 2) / 6;
}
long long CM[1000100];
long long BEST[1000100];
int DEG[1000100];
int LAB[1000100];
long long ADD[1000100];
bool POS[1000100];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (m); i++) {
    int a, b;
    long long mush;
    scanf("%d%d%I64d", &a, &b, &mush);
    --a;
    --b;
    G[a].push_back(b);
    M[a].push_back(mush);
  }
  int start;
  scanf("%d", &start);
  --start;
  SCC scc;
  vector<int> comp;
  vector<vector<int> > dag = scc.getDAG(G, n, comp);
  for (int v = (0); v < (n); v++) {
    for (int i = (0); i < (((int)(G[v]).size())); i++) {
      int u = G[v][i];
      if (comp[u] == comp[v]) CM[comp[v]] += getAll(M[v][i]);
    }
  }
  for (int v = (0); v < (n); v++) GC[comp[v]].push_back(v);
  queue<int> q;
  for (int i = (0); i < (((int)(dag).size())); i++) {
    for (int v : dag[i]) {
      ++DEG[v];
    }
  }
  for (int i = (0); i < (((int)(dag).size())); i++) {
    if (DEG[i] == 0) q.push(i);
  }
  int label = 1;
  long long result = 0;
  POS[comp[start]] = true;
  while (!q.empty()) {
    ++label;
    int cv = q.front();
    q.pop();
    if (POS[cv]) BEST[cv] += CM[cv];
    result = result > BEST[cv] ? result : BEST[cv];
    ;
    if (POS[cv]) {
      for (int v : GC[cv]) {
        for (int i = (0); i < (((int)(G[v]).size())); i++) {
          int u = G[v][i];
          if (comp[u] != comp[v]) {
            int cu = comp[u];
            if (LAB[cu] != label) {
              LAB[cu] = label;
              ADD[cu] = 0;
            }
            ADD[cu] = ADD[cu] > M[v][i] ? ADD[cu] : M[v][i];
            ;
          }
        }
      }
    }
    for (int cu : dag[cv]) {
      --DEG[cu];
      POS[cu] |= POS[cv];
      if (DEG[cu] == 0) q.push(cu);
      BEST[cu] = BEST[cu] > ADD[cu] + BEST[cv] ? BEST[cu] : ADD[cu] + BEST[cv];
      ;
    }
  }
  cout << result << endl;
}