Problem: We have a graph with N vertices and M edges, and there are two people on the graph: Takahashi and Aoki.

The i-th edge connects Vertex U_i and Vertex V_i. The time it takes to traverse this edge is D_i minutes, regardless of direction and who traverses the edge (Takahashi or Aoki).

Takahashi departs Vertex S and Aoki departs Vertex T at the same time. Takahashi travels to Vertex T and Aoki travels to Vertex S, both in the shortest time possible. Find the number of the pairs of ways for Takahashi and Aoki to choose their shortest paths such that they never meet (at a vertex or on an edge) during the travel, modulo 10^9 + 7.

Constraints

* 1 \leq N \leq 100 000
* 1 \leq M \leq 200 000
* 1 \leq S, T \leq N
* S \neq T
* 1 \leq U_i, V_i \leq N (1 \leq i \leq M)
* 1 \leq D_i \leq 10^9 (1 \leq i \leq M)
* If i \neq j, then (U_i, V_i) \neq (U_j, V_j) and (U_i, V_i) \neq (V_j, U_j).
* U_i \neq V_i (1 \leq i \leq M)
* D_i are integers.
* The given graph is connected.

Input

Input is given from Standard Input in the following format:


N M
S T
U_1 V_1 D_1
U_2 V_2 D_2
:
U_M V_M D_M


Output

Print the answer.

Examples

Input

4 4
1 3
1 2 1
2 3 1
3 4 1
4 1 1


Output

2


Input

3 3
1 3
1 2 1
2 3 1
3 1 2


Output

2


Input

8 13
4 2
7 3 9
6 2 3
1 6 4
7 6 9
3 8 9
1 2 2
2 8 12
8 6 9
2 5 5
4 2 18
5 3 7
5 1 515371567
4 8 6


Output

6

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.AbstractCollection;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemE solver = new ProblemE();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemE {
		final int MOD = (int) (1e9 + 7);

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			List<Edge>[] edges = new List[n];
			for (int i = 0; i < n; i++) {
				edges[i] = new ArrayList<>();
			}
			int m = in.nextInt();
			int s = in.nextInt() - 1;
			int t = in.nextInt() - 1;
			for (int i = 0; i < m; i++) {
				int a = in.nextInt() - 1;
				int b = in.nextInt() - 1;
				int c = in.nextInt();
				edges[a].add(new Edge(b, c));
				edges[b].add(new Edge(a, c));
			}

			long[] distS = new long[n];
			int[] waysS = new int[n];
			shortestPaths(s, edges, distS, waysS);
			long[] distT = new long[n];
			int[] waysT = new int[n];
			shortestPaths(t, edges, distT, waysT);

			int[] waysShortest = new int[n];
			for (int i = 0; i < n; i++) {
				if (distS[i] + distT[i] != distS[t]) {
					// Not on a shortest path.
					continue;
				}
				waysShortest[i] = (int) ((long) waysS[i] * waysT[i] % MOD);
			}

			long ans = (long) waysShortest[t] * waysShortest[t] % MOD;

			// Do not meet at a vertex.
			for (int i = 0; i < n; i++) {
				if (distS[i] + distT[i] != distS[t]) {
					// Not on a shortest path.
					continue;
				}
				if (distS[i] == distT[i]) {
					ans = (ans - (long) waysShortest[i] * waysShortest[i]) % MOD;
					if (ans < 0) {
						ans += MOD;
					}
				}
			}

			// Do not meet on an edge.
			for (int i = 0; i < n; i++) {
				for (Edge e : edges[i]) {
					int j = e.dst;
					if (distS[i] + e.length + distT[j] != distS[t]) {
						// Not on a shortest path.
						continue;
					}
					long l1 = distS[i];
					long r1 = distS[j];
					long l2 = distT[j];
					long r2 = distT[i];
					if (Math.max(l1, l2) < Math.min(r1, r2)) {
						long cur = (long) waysS[i] * waysT[j] % MOD * waysS[i] % MOD * waysT[j] % MOD;
						ans -= cur;
						if (ans < 0) {
							ans += MOD;
						}
					}
				}
			}

			out.println(ans);
		}

		private long[] shortestPaths(int s, List<Edge>[] edges, long[] dist, int[] ways) {
			final long infinity = Long.MAX_VALUE / 2;
			Arrays.fill(dist, infinity);
			dist[s] = 0;
			ways[s] = 1;
			PriorityQueue<Vertex> pq = new PriorityQueue<>();
			pq.offer(new Vertex(s, 0));
			while (!pq.isEmpty()) {
				Vertex ver = pq.poll();
				int v = ver.v;
				if (ver.dist != dist[v]) {
					continue;
				}
				for (Edge e : edges[v]) {
					int u = e.dst;
					if (dist[u] > dist[v] + e.length) {
						dist[u] = dist[v] + e.length;
						ways[u] = ways[v];
						pq.offer(new Vertex(u, dist[u]));
					} else if (dist[u] == dist[v] + e.length) {
						ways[u] += ways[v];
						if (ways[u] >= MOD) {
							ways[u] -= MOD;
						}
					}
				}
			}
			return dist;
		}

		class Vertex implements Comparable<Vertex> {
			int v;
			long dist;

			Vertex(int v, long dist) {
				this.v = v;
				this.dist = dist;
			}

			public int compareTo(Vertex o) {
				if (dist != o.dist) {
					return dist < o.dist ? -1 : 1;
				}
				return 0;
			}

		}

		class Edge {
			int dst;
			int length;

			Edge(int dst, int length) {
				this.dst = dst;
				this.length = length;
			}

		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}