Palindromi
문제
You are given a sequence of characters 0 or 1, indexed by numbers . Initially every character represents a string of length one. During a concatenation two words and are chosen, deleted, and replaced by the string such that the characters of are written after the characters of .
The initial strings are concatenated to one final string using a sequence of concatenations. The -th of those concatenation is described by a pair of indexes , which denotes that the string containing -th character and the string containing -th character are to be concatenated. It is guaranteed that characters with indexes and are not in the same string.
Palindromic value of some string is defined as the total number of unique substrings of which are palindromes. We define palindromes as strings that are the same when read left to right and right to left. A substring of a string is defined as a string obtained by erasing zero or more characters from the beginning and/or ending of the string.
For every concatenation print the palindromic value of the resulting string.
입력
The first line contains an integer (1 ≤ n ≤ 100\,000), number of characters.
In the second line there is a string of characters 0 and 1 which represent the initial strings.
The -th of following lines contains two integers and (1 ≤ a_i , b_i ≤ n, ) representing the -th concatenation.
출력
Print lines, the palindromic values of words obtained after each concatenation.
힌트
Clarification of the third example:
Newly created strings after every concatenation are: 00, 10, 00, 100, 1000, 001000 and 00100010. Their respective palindromic values are given in the example output. E. g. the palindromic value of 00100010 is 8 because the string contains 8 palindromic substring: 0, 00, 000, 10001, 0100010, 1, 010 and 00100.
예제
예제 1
3 010 1 2 2 3
2 3
예제 2
5 00111 4 1 1 5 2 1 3 1
2 3 4 5
예제 3
8 10010000 7 5 4 2 3 6 1 3 6 8 5 3 1 2
2 2 2 3 4 6 8