Two arrays and , both with elements, are given along with the definition of the following function:
long long f(int A[], int B[], int n){
long long sum = 0;
for(int i = 1; i <= n; i++)
for(int j = i+1; j <= n; j++)
if(B[i] == B[j]) sum += __gcd(A[i], A[j]);
return sum;
}
Gya-chan, being very eager to open her presents, wakes up in the middle of the night hoping to find them already under the tree. To her surprise, she runs into Santa Claus on her way to the tree. Upset that he was caught, Santa decides to challenge her.
Task
Santa Claus gives Gya-chan questions in the form , and she has to tell the value returned by the function if is replaced with . Santa's updates are permanent, meaning that after each operation, the changes made to array will persist.
Input data
The first line contains two numbers, , representing the number of elements in the two arrays, and , the number of questions. The next two lines contain numbers each, the first line containing the elements of array , and the second containing the elements of array . The last lines contain the questions given by Santa Claus.
Output data
There will be lines, the first one designating the initial value of the function, and the next lines containing the answers after each modification.
Constraints and clarifications
- ,
- after each operation
- Bahoi wants to mess up the problem, but it is completely forbidden!!! The number of distinct elements of array is .
DO NOTYou get 5 points if you guess the value of# Points Constraints 1 13 2 12 , 3 19 4 25 5 31 No additional constraints
Example 1
stdin
3 2
2 3 2
2 2 1
3 2
2 1
stdout
1
4
2
Explanation
Before the first modification, the value returned by the function will be .
After the first modification, the value returned will be .
Example 2
stdin
10 4
1 10 9 2 3 10 9 9 1 8
2 2 2 4 2 1 3 1 1 2
5 4
4 1
6 3
8 3
stdout
16
11
14
11
19