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 JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Rustam Musin (PloadyFree@gmail.com)
 */
public class Main implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 1<<28).start();
    }

    @Override
    public void run() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        int n;
        int[][] g;
        int[][] gr;
        int[] order;
        int orderSize;
        boolean[] visited;
        int[] gToComp;
        long[] compCost;
        long[] dp;
        int m;
        int[] eFrom;
        int[] eTo;
        int[] eWeight;
        long[] eTotalWeight;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.readInt();
            m = in.readInt();
            int[] inDegree = new int[n];
            int[] outDegree = new int[n];
            eFrom = new int[m];
            eTo = new int[m];
            eWeight = new int[m];
            eTotalWeight = new long[m];
            for (int e = 0; e < m; e++) {
                int from = in.readInt() - 1;
                int to = in.readInt() - 1;
                int weight = in.readInt();
                eFrom[e] = from;
                eTo[e] = to;
                eWeight[e] = weight;
                outDegree[from]++;
                inDegree[to]++;
            }
            prepareCosts();

            g = new int[n][];
            gr = new int[n][];
            for (int i = 0; i < n; i++) {
                g[i] = new int[outDegree[i]];
                gr[i] = new int[inDegree[i]];
            }
            for (int e = 0; e < m; e++) {
                g[eFrom[e]][--outDegree[eFrom[e]]] = e;
                gr[eTo[e]][--inDegree[eTo[e]]] = e;
            }

            int s = in.readInt() - 1;

            buildNewGraph();
            dp = new long[n];
            Arrays.fill(dp, -1);
            long res = go(gToComp[s]);
            out.print(res);
        }

        void dfs1(int v) {
            visited[v] = true;
            for (int e : g[v]) {
                if (!visited[eTo[e]]) {
                    dfs1(eTo[e]);
                }
            }
            order[orderSize++] = v;
        }

        void dfs2(int v, int c) {
            visited[v] = true;
            gToComp[v] = c;
            for (int e : gr[v]) {
                if (!visited[eFrom[e]]) {
                    dfs2(eFrom[e], c);
                }
            }
        }

        void buildNewGraph() {
            order = new int[n];
            orderSize = 0;
            visited = new boolean[n];
            for (int i = 0; i < n; i++) {
                if (!visited[i]) {
                    dfs1(i);
                }
            }

            Arrays.fill(visited, false);
            gToComp = new int[n];
            int compCount = 0;
            for (int i = 0; i < n; i++) {
                int v = order[n - 1 - i];
                if (!visited[v]) {
                    dfs2(v, compCount++);
                }
            }

            compCost = new long[compCount];
            int[] degree = new int[compCount];
            for (int e = 0; e < m; e++) {
                int fromComp = gToComp[eFrom[e]];
                int toComp = gToComp[eTo[e]];
                if (fromComp == toComp) {
                    compCost[fromComp] += eTotalWeight[e];
                } else {
                    degree[fromComp]++;
                }
            }

            int[][] newG = new int[compCount][];
            for (int i = 0; i < compCount; i++) {
                newG[i] = new int[degree[i]];
            }
            for (int e = 0; e < m; e++) {
                int fromComp = gToComp[eFrom[e]];
                int toComp = gToComp[eTo[e]];
                eFrom[e] = fromComp;
                eTo[e] = toComp;
                if (fromComp != toComp) {
                    newG[fromComp][--degree[fromComp]] = e;
                }
            }

            n = compCount;
            g = newG;
        }

        long go(int v) {
            if (dp[v] != -1) {
                return dp[v];
            }
            dp[v] = compCost[v];
            for (int e : g[v]) {
                dp[v] = Math.max(dp[v], compCost[v] + eWeight[e] + go(eTo[e]));
            }
            return dp[v];
        }

        void prepareCosts() {
            Integer[] order = new Integer[m];
            for (int i = 0; i < m; i++) {
                order[i] = i;
            }
            Arrays.sort(order, Comparator.comparingInt(i -> eWeight[i]));
            long sum = 0;
            for (int i = 0, l = 0; i < m; i++) {
                int e = order[i];
                while ((l + 1L) * (l + 2L) / 2 <= eWeight[e]) {
                    l++;
                    sum += l * (l + 1L) / 2;
                }
                eTotalWeight[e] = (l + 1L) * eWeight[e] - sum;
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(long i) {
            writer.print(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}