Processing math: 100%

Problem A Balanced Paths

You are given an undirected tree with n nodes. The nodes are numbered 1 through n. Each node is labeled with either '(' or ')'. Let l[uv] denote the string obtained by concatenating the labels of the nodes on the simple path from u to v. (Note that the simple path between two nodes is uniquely determined on a tree.) A balanced string is defined as follows:

Calculate the number of the ordered pairs of the nodes (u, v) such that l[uv] is balanced.

Input

The input consists of a single test case. The input starts with an integer n(2n105), which is the number of nodes of the tree. The next line contains a string of length n, each character of which is either '(' or ')'. The x-th character of the string represents the label of the node x of the tree. Each of the following n1 lines contains two integers ai and bi (1ai,bin), which represents that the node ai and the node bi are connected by an edge. The given graph is guaranteed to be a tree.

Output

Display a line containing the number of the ordered pairs (u, v) such that l[uv] is balanced.

Sample Input 1

2
()
1 2

Output for the Sample Input 1

1

Sample Input 2

4
(())
1 2
2 3
3 4

Output for the Sample Input 2

2

Sample Input 3

5
()())
1 2
2 3
2 4
1 5

Output for the Sample Input 3

4