UTPC Spring 2024 Open Contest
A. Skipping Songs
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Daisy the Great & AJR

Noah loves music and has various albums stored on discs. However, whenever he listens to his albums, he is very picky about the songs and skips around a lot. The disc always starts on the first song and rotates in order of the album. Once it gets past the end, it restarts from the beginning. Given how many songs Noah skips before listening to each song, print the list of songs in the order he listened to them.

Note: Whenever he decides on a song, he listens to it in its entirety before counting his skips to the next song.

Input

The first line will contain two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$) — the number of songs in the album and number of songs he listened to.

The next $$$n$$$ lines each contain the name of a song in the order of the album. Each name is guaranteed to be no more than 100 characters.

The last $$$m$$$ lines each contain a single integer $$$s_i$$$ ($$$1 \leq s_i \leq 10^9$$$) — the number of songs Noah skipped before listening to the $$$i$$$th song.

Output

The output should contain $$$m$$$ lines each containing the name of a single song in the order Noah listened to them.

Example
Input
12 7
Maybe Man
Touchy Feely Fool
Yes I'm A Mess
The Dumb Song
Inertia
Turning Out Pt. iii
Hole in the Bottom of My Brain
The DJ is Crying for Help
I Won't
Steve's Going to London
God is Really Real
2085
3
5
2
4
6
13
1
Output
The Dumb Song
Steve's Going to London
Maybe Man
Turning Out Pt. iii
Maybe Man
Yes I'm A Mess
Inertia

B. 6th heaven
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
凛として時雨, #5

Tommy is cataloging records in her music shop. She wants to arrange them onto a 1-dimensional shelf by record matrix number, but some of the ink has been scratched off. Given $$$n$$$ disks labeled $$$1$$$ to $$$n$$$, she has deduced the following $$$k$$$ relationships: in the $$$i$$$th relationship, she knows that two disks $$$a_i$$$ and $$$b_i$$$ are adjacent to each other. It is guaranteed that each unordered pair $$$(a_i, b_i)$$$ of disks is distinct. Given these $$$k$$$ conditions, determine how many ways she can catalog the disks mod $$$10^9+7$$$.

Input

The first line has two integers $$$n$$$ ($$$2\leq n \leq 10^5$$$) and $$$k$$$ ($$$1\leq k \leq 10^5$$$).

The next $$$k$$$ lines each contain two integers $$$a_i$$$ and $$$b_i$$$ ($$$1\leq a_i \lt b_i\leq n$$$).

Output

Please print $$$-1$$$ if arranging the disks given the current conditions is impossible, otherwise print the number of ways Tommy can catalog the disks, modulo $$$10^9+7$$$.

Examples
Input
7 3
1 3
2 3
1 2
Output
-1
Input
7 5
1 2
2 5
1 3
4 6
3 4
Output
4
Input
100 10
2 6
4 95
8 38
24 57
34 46
35 58
35 95
37 65
40 60
53 93
Output
764445383
Note

In the first sample test case, there is no way to arrange the disks given the conditions.

In the second sample test case, there are four valid sequences: $$$\{5, 2, 1, 3, 4, 6, 7\}, \{7, 5, 2, 1, 3, 4, 6\}, \{6, 4, 3, 1, 2, 5, 7\}$$$, and $$$\{7, 6, 4, 3, 1, 2, 5\}$$$.

C. A Noteworthy Debut
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Kessoku Band, Kessoku Band

After many years of songwriting and practicing, the up-and-coming UTBC (UT Beats Club) is finally ready to debut! In order to do so, they must choose some of their songs to record for their debut album.

Currently, they have written a total of $$$n$$$ songs, each with their own excitement level. The list of songs can be represented by an array $$$a$$$, where the $$$i$$$-th song in the array has an excitement level of $$$a_i$$$. In order for their album to be thematically coherent, UTBC has decided they want to choose a subarray$$$^†$$$ of songs from $$$a$$$ to put on the album.

UTBC doesn't want their debut to be a flop, so they want to choose which songs they put on their record album carefully. After extensive market research, they have discovered that audiences love an album that contains a song that stands out. In particular, a record album is considered noteworthy if it contains a song whose excitement level is strictly greater than the sum of the excitement levels of all the other songs on the album. For example, [3, 1, 1] is noteworthy because $$$3 \gt 1+1$$$, whereas [2, 2] and [1, 2, 3] are not.

Now UTBC wants to know, given the array $$$a$$$ of their songs, how many different possible noteworthy record albums could they produce as their debut album? Help them calculate this answer before they debut!

$$$^†$$$A subarray of $$$a$$$ is defined as a sequence of consecutive elements of $$$a$$$, i.e. the array $$$a_i,a_{i+1},\dots,a_j$$$ for some $$$1\leq i\leq j\leq n$$$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1\leq t\leq10^4)$$$. The description of the test cases follows.

The first line of each test case contains an integer $$$n$$$ $$$(1\leq n\leq 2\cdot 10^5)$$$ — the number of songs written by UTBC.

The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ $$$(1\leq a_i\leq10^9)$$$ — the excitement levels of the songs in the array.

It is guaranteed that the sum of the values of $$$n$$$ for all test cases does not exceed $$$2\cdot10^5$$$.

Output

For each test case output one integer — the number of different subarrays of songs that will produce a noteworthy record album.

Example
Input
5
1
1
2
1 2
3
3 1 1
4
1 5 2 1
5
1 3 5 10 12
Output
1
3
5
10
12
Note

For the first test case, the only noteworthy subarray is [1].

For the second test case, the noteworthy subarrays are [1], [2], [1, 2].

For the third test case, the noteworthy subarrays are [3], [1], [1], [3, 1], [3, 1, 1].

D. Counting Records
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Gracie's Corner, Gracie's Corner

Michael's favorite artist, Jackson, has recently started releasing new songs at an unprecedented rate. Michael wants to collect a physical copy of every record this artist releases, but his collection is getting too big. He already knows how many songs the artist releases over the first $$$n$$$ days, and wonders how many records he will have to buy on day $$$k$$$ if he continues to purchase every record.

Michael uses the function $$$f(x)$$$ to estimate the number of records released on day $$$x$$$. Michael already knows $$$f(x)$$$ for $$$1 \leq x \leq n$$$ as mentioned above. To compute future estimates, Michael uses the formula

$$$f(x) = \prod_{i=1}^{n}f(x-i)^{f(i)}$$$.

Given the values of $$$f(x)$$$ for $$$1 \leq x \leq n$$$, help Michael calculate his estimate $$$f(k)$$$, modulo $$$10^9 + 7$$$.

Input

The first line of input contains two space-separated integers, $$$n$$$ ($$$1 \leq n \leq 50$$$) and $$$k$$$ ($$$1 \leq k \leq 10^{18}$$$) — the number of days where we already know how many records were released on that day, and the day we would like to estimate, respectively.

The second line of input contains $$$n$$$ space-separated integers, where the $$$i^\text{th}$$$ number is $$$f(i)$$$ ($$$1 \leq f(i) \leq 10^9$$$) — the number of records purchashed on the $$$i^\text{th}$$$ day.

Output

Print a single integer $$$f(k) \bmod {10^9+7}$$$ — the estimate for the number of records purchased on day $$$k$$$.

Examples
Input
2 3
2 3
Output
72
Input
2 4
2 3
Output
139968

E. Is It Vinyl?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Cyndi Lauper, She's So Unusual

Vinny is having guests over for dinner, and wants to play some music to accompany her famed vindaloo. Vinny is, of course, an avid fan of old-school vinyls and cassettes, and owns a collection of songs in her attic.

Unfortunately, the attic doesn't have any lights, so Vinny can't find what she needs! Vinny is holding an object, but she can't tell what it is. She has identified $$$10$$$ points $$$(x_i, y_i)$$$ on the boundary of the object. If it's a vinyl, the object boundary is a circle. If it's a cassette, the object boundary is a rectangle. What is Vinny holding?

Input

The input consists of $$$10$$$ lines, each with two floats $$$x_i, y_i$$$ ($$$-100 \le x_i, y_i \le 100$$$) denoting a point on the boundary of the object.

The $$$10$$$ points are guaranteed to lie on a circle in the case of a vinyl, and a rectangle in the case of a cassette. Coordinates are given with up to $$$10$$$ decimal places. Points may deviate from the true circle or rectangle outline by at most $$$10^{-6}$$$.

If the points lie on a rectangle, the rectangle is guaranteed to be aligned with the $$$x$$$ and $$$y$$$ axes.

It is guaranteed that all points will be distinct (specifically, any two points will differ in at least one coordinate by at least $$$0.05$$$).

Output

Output "VINYL" if the object is a vinyl, and "CASSETTE" if the object is a cassette tape.

Examples
Input
0 2
3 3
-1 1
-2 -2
-1 -5
3 -7
6 -6
8 -2
6 2
7 1
Output
VINYL
Input
2.2 -2.2
2.2 3
2.2 1.5
3.8 3
4.5 1
4.5 1.2
4.5 1.9
4.5 -1
4.5 -2
4.5 -1.8
Output
CASSETTE
Note

The first sample test case looks like this, which is a vinyl:

The second sample test case looks like this, which is a cassette:

F. Lost in the Album Store
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The Clash, London Calling (Remastered)

George was perusing the local album store when he received an urgent message: a club was handing out free lollipops on Speedway! Determined to take advantage of such an opportunity, George decided to escape the album store as quickly as possible.

He found himself in row $$$n$$$ and column $$$m$$$, the southeast corner of the store, and wants to get to row $$$1$$$ column $$$1$$$, the exit in the northwest corner. In this store, each grid cell in row $$$i$$$ and column $$$j$$$ has a record of value $$$r_{i,j}$$$. When George takes a step in a direction, he considers shopping more and pauses for a time equal to the square of the sum of record values that are in front of him along the row or column in which he moved. For example, if George is in position $$$(i, j)$$$ and takes a step to position $$$(i - 1, j)$$$, he waits a time equal to $$$(\sum^{i-2}_{q=1} r_{q,j})^2$$$. Likewise, if he takes a step to position $$$(i, j - 1)$$$, he waits a time equal to $$$(\sum^{j-2}_{q=1} r_{i,q})^2$$$. George can move only towards the exit, so he can move only north or west.

What's the minimum time in which George can exit the album store?

Input

The first line contains two integers, $$$n$$$ and $$$m\ (1 \leq n, m \leq 1000)$$$ — the row and column George starts in.

The next $$$n$$$ lines each contain $$$m$$$ integers, with the $$$j^\text{th}$$$ element of the $$$i^\text{th}$$$ line denoting $$$r_{i,j}\ (0 \leq r_{i,j} \leq 50)$$$ — the value of the record in row $$$i$$$ and column $$$j$$$.

Output

Output a single integer, the minimum time required to reach the exit.

Example
Input
3 4
5 2 3 4
3 3 2 2
0 1 1 6
Output
5
Note

George starts at position $$$(3, 4)$$$, which is on the $$$6$$$.

He takes his first step to $$$(3, 3)$$$ and waits a time equal to $$$(1 + 0)^2 = 1$$$.

He takes his second step to $$$(3, 2)$$$ and waits a time equal to $$$0^2 = 0$$$.

He then takes a step to $$$(2, 2)$$$ and waits a time equal to $$$2^2 = 4$$$.

From here, he can take either path to $$$(1, 1)$$$, both of which have zero cost.

G. Making Records
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Shostakovich, Symphony No. 10

John is making $$$n$$$ records and he knows of $$$m$$$ unique songs. Each record must contain exactly one song. Further, each record has a value $$$b_i$$$ denoting that if the $$$i$$$th record is played, the $$$b_i$$$th record must be played next. John can assign any song to any record (there may be multiple records with the same song, or a song that isn't on any record), but each record must be assigned exactly one song. However, he wants to make sure that anyone who plays his records will not end up listening to the same song twice.

Formally, let $$$a_i$$$ be the song assigned to the $$$i$$$th record. For all $$$i$$$, $$$a_i \neq a_{b_i}$$$ must hold. Help John determine how many assignments of songs to records satisfy this condition. Two assignments are considered different if there is a record which has a different song assigned to it between the two assignments. Since this value may be large, output it modulo $$$10^9+7$$$.

Input

The first line of input will contain integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 2 \cdot 10^5$$$) — the number of records and the number of song choices, respectively.

The next line of input will contain $$$n$$$ space-separated integers $$$b_1 ... b_n$$$ ($$$1 \leq b_i \leq n$$$) — the record that must be played directly after the $$$i$$$th record.

Output

Output the number of valid assignments, modulo $$$10^9+7$$$.

Examples
Input
5 3
2 3 4 1 4
Output
36
Input
2 1
2 1
Output
0
Input
2 1
1 2
Output
0
Input
8 10
4 3 6 2 3 7 1 2
Output
43047450
Note

In the first sample, the 2nd record must be played after the first, the third record must be played after the second, the fourth must be played after the third, the first after the fourth, and the fourth after the fifth. This means that records 1, 2, 3, and 4 will cycle infinitely, and record 5 will only be played once if it is the first record played. An example of a valid assignment of songs to records is to assign song 1 to records 1 and 3, song 2 to records 2 and 5, and song 3 to record 4. Notice that with this assignment there were never be a song that is played twice in a row. It can be shown that there are exactly 36 assignments which satisfy this condition in this testcase.

In the second sample, there is only one song, so there is only one way to assign songs to records, but because record 2 is played after record 1, this assignment is invalid.

In the third sample, record 1 is played after itself, so all assignments of songs to records will be invalid.

H. Prefix Tower
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
Merzbrow

Charlie is writing a mixing software, which takes in an array of records $$$a$$$ with $$$n$$$ elements. Charlie also wants to mix the tracks together. He has devised this clever algorithm (that also produces great soundtracks) called the prefix mixing operation $$$p(a)$$$ as follows:

  • $$$a[i] := a[i - 1] \times a[i]\bmod {10^9 + 7}$$$, for each $$$1 \lt i \leq n$$$ in order.

For example, for the array $$$a = [5,7,10]$$$, the prefix operation would produce $$$p(a) = [5,35,350]$$$, since the multiplication is done in succession. The $$$k$$$-th prefix operation $$$p^{k}$$$ is the prefix operation applied $$$k$$$ times. For example, for $$$k=2$$$, $$$p^{2}(a)$$$ would be defined as $$$p(p(a))$$$, and $$$p^{3}(a) = p(p(p(a)))$$$.

Unfortunately, the current software rendering this transformation takes a long time to run, so Charlie needs your help to fix it. In order to do this, Charlie wants to know arbitrary elements for the array $$$p^{k_i}(a)$$$. Can you help him find them?

Input

The first line contains $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.

For each test case, the first line contains two integers $$$n$$$ and $$$q$$$ ($$$1\leq n, q \leq 1000$$$) — the number of elements in the array $$$a$$$ and the number of queries, respectively.

The next line contains $$$n$$$ space-separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i\leq 10^9$$$).

The next $$$q$$$ lines each contain two space-separated integers $$$k_i$$$ and $$$x_i$$$ ($$$1\leq k_i\leq 1000, 1\leq x_i\leq n$$$) — which is the $$$i$$$-th query asking for the answer of $$$p^{k_i}(a)[x_i]$$$.

It is guaranteed that the sum of all $$$q$$$ over all test cases is at most $$$1000$$$.

There is no additional bound on the sum of all $$$n$$$ or $$$x_i$$$.

Output

For each query in each test case, output one integer — the value of $$$p^{k_i}(a)[x_i]$$$

Example
Input
2
5 3
1 2 3 4 5
1 1
1 2
2 4
5 4
5 4 3 2 1
1 1
1 2
1 3
2 3
Output
1
2
288
5
20
60
6000
Note

For the first test case: $$$p^{1}(a) = [1, 2, 6, 24, 120]$$$ and $$$p^{2}(a) = [1, 2, 12, 288, 34560]$$$

I. Record Compression
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Glass Beach, Plastic Death

Amber wants to store her favorite songs on a vinyl record!

Amber's record can store $$$m$$$ bytes of data (it's a fancy digital record), and Amber has $$$n$$$ songs which she wants to store. Each of the $$$n$$$ songs has a title $$$s_i$$$, and it takes $$$|s_i|$$$ bytes to store the $$$i^\text{th}$$$ song. Additionally, Amber values different songs differently, so she assigns a value $$$v_i$$$ to the $$$i^\text{th}$$$ song. Moreover, Amber does not mind listening to the same song multiple times; that is, she may store the same song multiple times on her vinyl, and each time she stores the $$$i^\text{th}$$$ song, it will add the value $$$v_i$$$ to the total value of the record.

Amber would like to maximize the total value of the songs she stores on her digital vinyl. Given the size of her vinyl (in bytes), as well as the titles and values of each of her favorite songs, please help Amber figure out the maximum total value she can achieve by storing the optimal songs!

Input

The first line of input will contain two space-separated integers, $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 2 \cdot 10^5$$$) — the number of favorite songs Amber has and the size of her vinyl record in bytes.

The next $$$n$$$ lines will each describe one of Amber's favorite songs. The $$$i^\text{th}$$$ of these lines will contain a string $$$s_i$$$ ($$$1 \leq |s_i| \leq 2 \cdot 10^5$$$) consisting of lower and uppercase English letters, followed by a space, followed by an integer $$$v_i$$$ ($$$1 \leq v_i \leq 10^9$$$). It is guaranteed that $$$\sum_{i=1}^n |s_i| \leq 2 \cdot 10^5$$$.

Output

The output should consist of a single integer, the maximum total value that Amber can achieve by optimally storing her favorite songs on her vinyl record.

Examples
Input
3 7
Creep 1
HotelCalifornia 2
One 3
Output
6
Input
5 30
BohemianRhapsody 20
HeyJude 12
DancingQueen 19
PurpleHaze 23
commatose 52
Output
156
Note

In the first sample test case, Amber could store the song "One" twice using up six bytes of memory and earning a total value of six as well.

In the second sample test case, it is optimal for Amber to store the song "commatose" three times using up 27 bytes of memory, for a total value of $$$52 \cdot 3 = 156$$$.

J. Record The Record Record
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Michael Jackson, Thriller

Bob has just bought a record collection of $$$n$$$ records numbered from $$$1$$$ to $$$n$$$, and he can't wait to listen to them! On each of the next $$$n$$$ days, Bob will listen to some his records. He may listen to the same record multiple times, or on different days. A new record is a record that he has not listened to on previous days. Bob is very excited to start listening to his record collection, and he wants to know, what is the greatest number of new records he listens to in a single day? Help him answer this question!

Input

The first line will contain a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of records in Bob's collection and how many days he will listen to them.

Each of the next $$$n$$$ lines will begin with an integer $$$m$$$, followed by $$$m$$$ integers $$$r_1, \dots, r_m$$$ ($$$1 \leq m \leq 1000, 1 \leq r_i \leq n$$$) — the number of records he listened to that day and the records he listened to that day, respectively.

Output

Output a single integer — the maximum number of new records Bob will listen to in a single day.

Example
Input
3
1 1
2 1 3
3 1 2 3
Output
1
Note

On the first day, Bob listens to record 1, which is new.

On the second day, Bob listens to records 1 and 3, but only record 3 is new.

On the third day, Bob listens to records 1, 2, and 3, but only record 2 is new.

Bob listens to one new record each day, so the answer is 1.

K. Sample Heat
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Nujabes ft. Substantial and Pase Rock, Metaphorical Music

As a music producer, Mai has been trying to get her career off the ground! She has $$$n$$$ samples on a record disk. The disk is represented as a string $$$s$$$ of $$$n$$$ characters, where each sample is labeled with some lowercase character 'a'-'z'. As part of creating a beat, Mai will pick some substring of samples to use as the foundation of their beat. Mai prefers sounds that have a symmetric sound to them, so the substring she extracts must be a palindrome.

The heat of a substring of samples is the sum of the IDs used, where 'a' corresponds to a value of 1, 'b' corresponds to a value of 2, and so forth. If an ID appears multiple times, it is counted multiple times in this sum. Mai wants to compute how valuable the record is, so she wants to compute the sum of the heats of all distinct valid substring of samples. Please help her do so!

A palindrome is a string that reads the same forwards and backwards. For example, "aa" and "abacaba" are both palindromes, while "abb" and "utpc" are not.

Two substring are distinct if they have different lengths or at least one position differs between the two substring.

Input

The first line contains a single integer $$$n\ (1 \leq n \leq 10^5)$$$ — the number of samples.

The second line contains a single string $$$s$$$ of length $$$n$$$, comprising of only the characters 'a'-'z' — the representation of the samples on the disk.

Output

Output a single integer — the sum of the heats of each distinct palindromic substring.

Example
Input
5
aabaa
Output
15
Note

For the input "aabaa", the heats of the palindromic substrings are:

  • "a" with a heat of $$$1$$$
  • "b" with a heat of $$$2$$$
  • "aa" with a heat of $$$2$$$
  • "aba" with a heat of $$$4$$$
  • "aabaa" with a heat of $$$6$$$

L. Two Pizzas
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Guillermo Lago, Ciudades

Alice and Bob are tired of listening to records all day, so they decided to get food. Of course there is no better place to get food than at the Unlimited Topping Pizza Cafe (UTPC).

At the UTPC, every pizza is represented by a set of toppings arranged in a circle. Specifically, there are $$$n$$$ positions on the pizza, numbered from $$$1$$$ to $$$n$$$. Each topping has a tastiness value in the range $$$[1, 100]$$$, and each position on a pizza may contain up to two toppings (possibly none). It is well-known that if two toppings line on the same position of a pizza, they will no longer have any tastiness, so the tastiness of a pizza is defined as the sum of tastiness of all toppings on the pizza which do not share a position with any other topping.

This is both Alice's and Bob's first time visiting the UTPC, and they have a dilemma: They each have a pizza in mind (which contains at most one topping at each position), but can only afford to purchase one (the pizzas here are quite expensive). You, the chef, know how to solve the dilemma: by merging the two pizzas into one! First, you will rotate Bob's pizza by some amount so that each position in Bob's pizza is aligned with some position in Alice's pizza. Then, you will transfer all of Bob's toppings to the corresponding position on Alice's pizza. Since you want Alice and Bob to return in the future, you must find the maximum tastiness which a pizza can contain after merging Alice's and Bob's pizzas.

Input

The first line of input consists of a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of positions on each pizza.

The second line of input consists of $$$n$$$ space-separated integers $$$a_1, \dots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the toppings on Alice's pizza. If $$$a_i = 0$$$, then there is no topping at position $$$i$$$. Otherwise, $$$a_i$$$ represents the tastiness of the topping at position $$$i$$$.

Similarly, the third line consists of $$$n$$$ space-separated integers $$$b_1, \dots, b_n$$$ ($$$0 \leq b_i \leq 100$$$) — the toppings on Bob's pizza. If $$$b_i = 0$$$, then there is no topping at position $$$i$$$. Otherwise, $$$b_i$$$ represents the tastiness of the topping at position $$$i$$$.

Output

The output consists of a single integer — the maximum possible tastiness of the merged pizza.

Examples
Input
5
1 3 0 0 1
2 0 1 0 0
Output
6
Input
8
1 4 11 3 0 0 0 1
2 0 0 0 6 0 5 3
Output
29
Input
3
1 1 1
1 1 1
Output
0
Note

In the first sample, Alice and Bob have the following two pizzas in mind:

We can obtain a pizza with a tastiness of $$$6$$$ by rotating Bob's pizza twice clockwise relative to Alice's pizza as seen below:

The tastiness of this pizza is $$$1 + 3 + 2 = 6$$$ since that is the sum of the toppings which are in a position of their own.