message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4 | instruction | 0 | 2,321 | 14 | 4,642 |
"Correct Solution:
```
n = int(input())
c=0
for i in range(n):
s,e = map(int,input().split())
c += e-s+1
print(c)
``` | output | 1 | 2,321 | 14 | 4,643 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4 | instruction | 0 | 2,322 | 14 | 4,644 |
"Correct Solution:
```
n = int(input())
x = 0
for _ in range(n):
s, e = map(int, input().split())
x += e - s + 1
print(x)
``` | output | 1 | 2,322 | 14 | 4,645 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4 | instruction | 0 | 2,323 | 14 | 4,646 |
"Correct Solution:
```
N=int(input())
num=0
for i in range(N):
l,r=map(int,input().split())
num+=r-l+1
print(num)
``` | output | 1 | 2,323 | 14 | 4,647 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4 | instruction | 0 | 2,324 | 14 | 4,648 |
"Correct Solution:
```
ans=0
N=int(input())
for i in range(N):
a,b=map(int,input().split())
ans+=b-a+1
print(ans)
``` | output | 1 | 2,324 | 14 | 4,649 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4 | instruction | 0 | 2,325 | 14 | 4,650 |
"Correct Solution:
```
n=int(input())
ans=0
for i in range(n):
l,s=map(int,input().split())
ans+=s-l+1
print(ans)
``` | output | 1 | 2,325 | 14 | 4,651 |
Provide a correct Python 3 solution for this coding contest problem.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4 | instruction | 0 | 2,326 | 14 | 4,652 |
"Correct Solution:
```
N=int(input())
c=0
for i in range(N):
l,n=map(int,input().split())
m=n-l+1
c+=m
print(c)
``` | output | 1 | 2,326 | 14 | 4,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4
Submitted Solution:
```
n = int(input())
t = 0
for i in range(n):
l, r = map(int, input().split())
t += r-l+1
print(t)
``` | instruction | 0 | 2,327 | 14 | 4,654 |
Yes | output | 1 | 2,327 | 14 | 4,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4
Submitted Solution:
```
a=int(input())
ans=0
for i in range(a):
x,y=map(int,input().split())
ans+=y-x+1
print(ans)
``` | instruction | 0 | 2,330 | 14 | 4,660 |
Yes | output | 1 | 2,330 | 14 | 4,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4
Submitted Solution:
```
n=int(input())
s=0
for i in range(n):
l=list(map(int,input().split()))
s+=len(l)
print(s)
``` | instruction | 0 | 2,331 | 14 | 4,662 |
No | output | 1 | 2,331 | 14 | 4,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4
Submitted Solution:
```
N = int(input())
ans = 0
for i in range(N):
A, B = map(int, input().split())
ans = B - A +1
print(ans)
``` | instruction | 0 | 2,332 | 14 | 4,664 |
No | output | 1 | 2,332 | 14 | 4,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
Constraints
* 1≤N≤1000
* 1≤l_i≤r_i≤100000
* No seat is occupied by more than one person.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N
Output
Print the number of people sitting at the theater.
Examples
Input
1
24 30
Output
7
Input
2
6 8
3 3
Output
4
Submitted Solution:
```
N=int(input())
K=0
for i in N:
l,r = map(int,input().split())
K=(r-l+1)+K
print(K)
``` | instruction | 0 | 2,333 | 14 | 4,666 |
No | output | 1 | 2,333 | 14 | 4,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box. | instruction | 0 | 2,560 | 14 | 5,120 |
Tags: combinatorics, math
Correct Solution:
```
n,m = map(int,input().split())
print(pow(2**m-1, n, 10**9+7))
``` | output | 1 | 2,560 | 14 | 5,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box. | instruction | 0 | 2,561 | 14 | 5,122 |
Tags: combinatorics, math
Correct Solution:
```
d = input()
d = d.split()
n = int(d[0])
m = int(d[1])
w = pow(2,m,1000000007)-1
n = pow(w,n,1000000007)
print(n)
``` | output | 1 | 2,561 | 14 | 5,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box. | instruction | 0 | 2,562 | 14 | 5,124 |
Tags: combinatorics, math
Correct Solution:
```
n, m = map(int,input().split())
mod = 1000000007
ans = pow(2, m, mod)
ans -= 1
ans = pow(ans,n,mod)
print(ans)
``` | output | 1 | 2,562 | 14 | 5,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box. | instruction | 0 | 2,563 | 14 | 5,126 |
Tags: combinatorics, math
Correct Solution:
```
n,m=[int(i) for i in input().split()]
print(pow(2**m-1,n,10**9+7))
``` | output | 1 | 2,563 | 14 | 5,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box. | instruction | 0 | 2,564 | 14 | 5,128 |
Tags: combinatorics, math
Correct Solution:
```
a, b = list(map(int, input().split()))
mod = 10**9 + 7
print(pow(pow(2, b, mod)-1, a, mod))
``` | output | 1 | 2,564 | 14 | 5,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box. | instruction | 0 | 2,565 | 14 | 5,130 |
Tags: combinatorics, math
Correct Solution:
```
a = input('').split(' ')
n = int(a[0])
m = int(a[1])
M = 10**9+7
p = (pow(2,m,M)-1)%M
print(pow(p,n,M))
``` | output | 1 | 2,565 | 14 | 5,131 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box. | instruction | 0 | 2,566 | 14 | 5,132 |
Tags: combinatorics, math
Correct Solution:
```
n,m = [int(a) for a in input().split()]
mod = 10**9 + 7
ans = pow(pow(2,m, mod)-1, n, mod)
print(ans)
``` | output | 1 | 2,566 | 14 | 5,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box. | instruction | 0 | 2,567 | 14 | 5,134 |
Tags: combinatorics, math
Correct Solution:
```
n, m = [int(x) for x in input().split()]
x = -1
x += 2**m
mod = 7
mod += 10**9
r = pow(x, n, mod)
print(r)
``` | output | 1 | 2,567 | 14 | 5,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box.
Submitted Solution:
```
def mp():
return map(int, input().split())
def power(a, n, mod):
if n == 0:
return 1
elif n == 1:
return a % mod
elif n % 2 != 0:
return ((a % mod) * power(a, n - 1, mod)) % mod
return power(a * a % mod, n // 2, mod) % mod
n, m = mp()
print(power(power(2, m, 10 ** 9 + 7) - 1, n, 10 ** 9 + 7))
``` | instruction | 0 | 2,568 | 14 | 5,136 |
Yes | output | 1 | 2,568 | 14 | 5,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box.
Submitted Solution:
```
import sys, math
from heapq import heappush, heappop
readline = sys.stdin.readline
mr = lambda:map(int,readline().split())
n, k = mr()
tp = pow(pow(2,k,1000000007) - 1,n,1000000007)
print(tp)
``` | instruction | 0 | 2,569 | 14 | 5,138 |
Yes | output | 1 | 2,569 | 14 | 5,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box.
Submitted Solution:
```
MOD = 1000000007
n, m = map(int, input().split())
def power(x, y, p):
res = 1
x = x % p
while (y > 0):
if (y & 1):
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
x = power(2,m,MOD) - 1
# print(x)
b = str(n)
# print(b)
remainderB = 0
# print(b)
for i in range(len(b)):
remainderB = ((remainderB * 10 + ord(b[i]) - 48) % (MOD - 1))
y = power(x,remainderB,MOD)
print(y)
# print(x)
# y = powit(x,n)
# print(y)
``` | instruction | 0 | 2,570 | 14 | 5,140 |
Yes | output | 1 | 2,570 | 14 | 5,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box.
Submitted Solution:
```
from sys import stdin
#import nltk
import math
from collections import defaultdict
#stdin=open('input.txt','r')
I=stdin.readline
n,m=map(int,I().split())
mod=10**9+7
a=(pow(2,m,mod)-1+mod)%mod
b=pow(a,n,mod)
print(b)
``` | instruction | 0 | 2,571 | 14 | 5,142 |
Yes | output | 1 | 2,571 | 14 | 5,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box.
Submitted Solution:
```
n,m=map(int,input().split())
ans=0
if(n==1):
ans=(pow(2,n*m,1000000007)-1+1000000007)%1000000007
else :
ans=(pow(2,n*m,1000000007)-((n*pow(2,(n-1)*m,1000000007))%1000000007)+1000000007)%1000000007+1
ans=ans%1000000007
print(ans)
``` | instruction | 0 | 2,572 | 14 | 5,144 |
No | output | 1 | 2,572 | 14 | 5,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box.
Submitted Solution:
```
n, m = map(int, input().split())
print(((pow(2, m, 1000000007) - 1) * n) % (1000000007))
``` | instruction | 0 | 2,573 | 14 | 5,146 |
No | output | 1 | 2,573 | 14 | 5,147 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box.
Submitted Solution:
```
maximal = 1e9 + 7
def binpow (a, n):
if n==0:
return 1
if n%2 == 1:
return (binpow(a, n-1) * a) % maximal
else:
b = binpow(a, int(n/2)) % maximal
return (b*b) % maximal
n, m = map(int, input().split())
sf = (binpow(2, m) - 1 + maximal) % maximal
rez = binpow(sf, n)
print(str(int(rez)))
``` | instruction | 0 | 2,574 | 14 | 5,148 |
No | output | 1 | 2,574 | 14 | 5,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are n kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are m boxes. All of them are for different people, so they are pairwise distinct (consider that the names of m friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules:
* She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of n kinds, empty boxes are allowed);
* For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo 10^9+7.
See examples and their notes for clarification.
Input
The first line contains two integers n and m, separated by spaces (1 ≤ n,m ≤ 10^9) — the number of kinds of presents and the number of boxes that Alice has.
Output
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo 10^9+7
Examples
Input
1 3
Output
7
Input
2 2
Output
9
Note
In the first example, there are seven ways to pack presents:
\{1\}\{\}\{\}
\{\}\{1\}\{\}
\{\}\{\}\{1\}
\{1\}\{1\}\{\}
\{\}\{1\}\{1\}
\{1\}\{\}\{1\}
\{1\}\{1\}\{1\}
In the second example there are nine ways to pack presents:
\{\}\{1,2\}
\{1\}\{2\}
\{1\}\{1,2\}
\{2\}\{1\}
\{2\}\{1,2\}
\{1,2\}\{\}
\{1,2\}\{1\}
\{1,2\}\{2\}
\{1,2\}\{1,2\}
For example, the way \{2\}\{2\} is wrong, because presents of the first kind should be used in the least one box.
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
mod = 1000000009
print(pow( ( pow(2, m, mod) -1) , n, mod))
``` | instruction | 0 | 2,575 | 14 | 5,150 |
No | output | 1 | 2,575 | 14 | 5,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has n counters numbered from 1 to n. Some of them are connected by wires, and each of the counters has a special button.
Initially, all the counters contain number 0. When you press a button on a certain counter, the value it has increases by one. Also, the values recorded in all the counters, directly connected to it by a wire, increase by one.
Valera and Ignat started having a dispute, the dispute is as follows. Ignat thought of a sequence of n integers a1, a2, ..., an. Valera should choose some set of distinct counters and press buttons on each of them exactly once (on other counters the buttons won't be pressed). If after that there is a counter with the number i, which has value ai, then Valera loses the dispute, otherwise he wins the dispute.
Help Valera to determine on which counters he needs to press a button to win the dispute.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105), that denote the number of counters Valera has and the number of pairs of counters connected by wires.
Each of the following m lines contains two space-separated integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), that mean that counters with numbers ui and vi are connected by a wire. It is guaranteed that each pair of connected counters occurs exactly once in the input.
The last line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 105), where ai is the value that Ignat choose for the i-th counter.
Output
If Valera can't win the dispute print in the first line -1.
Otherwise, print in the first line integer k (0 ≤ k ≤ n). In the second line print k distinct space-separated integers — the numbers of the counters, where Valera should push buttons to win the dispute, in arbitrary order.
If there exists multiple answers, you are allowed to print any of them.
Examples
Input
5 5
2 3
4 1
1 5
5 3
2 1
1 1 2 0 2
Output
2
1 2
Input
4 2
1 2
3 4
0 0 0 0
Output
3
1 3 4 | instruction | 0 | 2,750 | 14 | 5,500 |
Tags: dfs and similar, graphs, greedy
Correct Solution:
```
from queue import Queue
n,m = map(int,input().split())
e = [[]for i in range(n+1)]
b = [0]*n
for i in range(m):
u,v = map(int,input().split())
e[u-1].append(v-1)
e[v-1].append(u-1)
ans = 0
q = Queue()
a = input().split()
ai = [-1]*n
c=0
mask = [False]*n
for i in a:
inti = int(i)
ai[c] = inti
if inti == 0:
q.put(c)
b[c]=1
c+=1
T=[]
while not q.empty():
i = q._get()
ans+=1
T.append(i+1)
for j in e[i]:
b[j]+=1
if b[j]== ai[j]:
q.put(j)
print(ans)
print(*T)
``` | output | 1 | 2,750 | 14 | 5,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input
A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.
Output
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Examples
Input
2
Output
3
Input
3
Output
7
Note
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | instruction | 0 | 2,753 | 14 | 5,506 |
Tags: implementation, math
Correct Solution:
```
n=int(input())
t=(n*n)+5
print(n*t//6)
``` | output | 1 | 2,753 | 14 | 5,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input
A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.
Output
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Examples
Input
2
Output
3
Input
3
Output
7
Note
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | instruction | 0 | 2,754 | 14 | 5,508 |
Tags: implementation, math
Correct Solution:
```
n=int(input())
if n==1:
print(1)
else:
num=n
for i in range(1,n):
num+=((i+1)*(n-i)-i)
print(num)
``` | output | 1 | 2,754 | 14 | 5,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input
A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.
Output
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Examples
Input
2
Output
3
Input
3
Output
7
Note
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | instruction | 0 | 2,756 | 14 | 5,512 |
Tags: implementation, math
Correct Solution:
```
n=int(input());print((n*((n**2)+5))//6)
``` | output | 1 | 2,756 | 14 | 5,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input
A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.
Output
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Examples
Input
2
Output
3
Input
3
Output
7
Note
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | instruction | 0 | 2,757 | 14 | 5,514 |
Tags: implementation, math
Correct Solution:
```
n=int(input());ans=0
if n==1:print(1)
else:
ans+=((n)*(n+1))//2
cnt=0
for i in range(n,0,-1):
ans+=cnt*(i-1)
cnt+=1
print(ans)
``` | output | 1 | 2,757 | 14 | 5,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input
A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.
Output
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Examples
Input
2
Output
3
Input
3
Output
7
Note
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | instruction | 0 | 2,758 | 14 | 5,516 |
Tags: implementation, math
Correct Solution:
```
n = int(input())
result = 0
i=0
while n != 0:
result += n + (n-1)*i
n -= 1
i+=1
print(result)
``` | output | 1 | 2,758 | 14 | 5,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input
A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.
Output
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Examples
Input
2
Output
3
Input
3
Output
7
Note
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | instruction | 0 | 2,759 | 14 | 5,518 |
Tags: implementation, math
Correct Solution:
```
n=int(input())
ans=0
for i in range(1,n):
ans+=(i*(n-i))
print(ans+n)
``` | output | 1 | 2,759 | 14 | 5,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | instruction | 0 | 2,936 | 14 | 5,872 |
Tags: implementation, sortings
Correct Solution:
```
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
# from __future__ import print_function # for PyPy2
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
# from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")
n, = gil()
s = Counter(gil())
m, = gil()
a, t = gil(), gil()
mo = [(s.get(a[i], 0), s.get(t[i], 0), i+1) for i in range(m)]
print(max(mo)[-1])
``` | output | 1 | 2,936 | 14 | 5,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | instruction | 0 | 2,937 | 14 | 5,874 |
Tags: implementation, sortings
Correct Solution:
```
"""
Codeforces Round #334 (Div. 2)
Problem 670 C. Cinema
@author yamaton
@date 2015-05-05
"""
import itertools as it
import functools
import operator
import collections
import math
import sys
def solve(n, m, xs, ys, zs):
cnt = collections.Counter(xs)
result = max((cnt[y], cnt[z], -i) for i, (y, z) in enumerate(zip(ys, zs), 1))
pp('result:', result)
_, _, neg = result
return (-neg)
def pp(*args, **kwargs):
return print(*args, file=sys.stderr, **kwargs)
def main():
n = int(input().strip())
xs = [int(i) for i in input().strip().split()]
m = int(input().strip())
ys = [int(i) for i in input().strip().split()]
zs = [int(i) for i in input().strip().split()]
assert len(xs) == n
assert len(ys) == len(zs) == m
result = solve(n, m, xs, ys, zs)
print(result)
if __name__ == '__main__':
main()
``` | output | 1 | 2,937 | 14 | 5,875 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | instruction | 0 | 2,938 | 14 | 5,876 |
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
langs = list(map(int, input().split()))
#langs = input()
m = int(input())
aud = list(map(int, input().split()))
sub = list(map(int, input().split()))
res=[]
d={}
for i in langs:
if i in d:
d[i]+=1
else:
d[i] = 1
for i in range(m):
x = 0
y = 0
if aud[i] in d:
x = d[aud[i]]
if sub[i] in d:
y = d[sub[i]]
res.append((x,y,i+1))
print(max(res)[2])
``` | output | 1 | 2,938 | 14 | 5,877 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | instruction | 0 | 2,939 | 14 | 5,878 |
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
languages = {}
s = input().split()
for i in s:
if i in languages:
languages[i] += 1
else:
languages[i] = 1
m = int(input())
audio = input().split()
subtitles = input().split()
bestm = 1
besta = 0
bests = 0
for i in range(m):
ad = audio[i]
sb = subtitles[i]
ac = 0
if ad in languages:
ac = languages[ad]
sc = 0
if sb in languages:
sc = languages[sb]
if ac > besta or ac == besta and sc > bests:
bestm = i + 1
besta = ac
bests = sc
print(bestm)
``` | output | 1 | 2,939 | 14 | 5,879 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | instruction | 0 | 2,940 | 14 | 5,880 |
Tags: implementation, sortings
Correct Solution:
```
def main():
from collections import Counter
input()
aa = Counter(map(int, input().split()))
m = int(input())
bb = list(map(aa.__getitem__, map(int, input().split())))
cc = list(map(aa.__getitem__, map(int, input().split())))
print(max(range(m), key=lambda i: (bb[i], cc[i])) + 1)
if __name__ == '__main__':
main()
``` | output | 1 | 2,940 | 14 | 5,881 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | instruction | 0 | 2,941 | 14 | 5,882 |
Tags: implementation, sortings
Correct Solution:
```
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
nF = int(input())
lang = list(map(int, input().split()))
sub = list(map(int, input().split()))
cnt = defaultdict(int)
for v in a:
cnt[v] += 1
print(max(range(nF), key=lambda x: (cnt[lang[x]], cnt[sub[x]])) + 1)
``` | output | 1 | 2,941 | 14 | 5,883 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | instruction | 0 | 2,942 | 14 | 5,884 |
Tags: implementation, sortings
Correct Solution:
```
def main():
n = int(input())
a = list(map(int, input().split()))
L = {}
for language in a:
if language not in L:
L[language] = 1
else:
L[language] += 1
m = int(input())
audio = list(map(int, input().split()))
subs = list(map(int, input().split()))
satisfaction = [(0, 0)] * m
for i in range(m):
satisfaction[i] = (L.get(audio[i], 0), L.get(subs[i], 0))
print(satisfaction.index(max(satisfaction)) + 1)
if __name__ == '__main__':
main()
``` | output | 1 | 2,942 | 14 | 5,885 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied. | instruction | 0 | 2,943 | 14 | 5,886 |
Tags: implementation, sortings
Correct Solution:
```
n = int(input())
lang_cnt = {}
for lang in input().split():
if lang not in lang_cnt:
lang_cnt[lang] = 0
lang_cnt[lang] += 1
m = int(input())
best_vp_cnt = -1
best_as_cnt = -1
best_movie = 0
audio = input().split()
subtitles = input().split()
for i in range(1, m + 1):
vp_cnt = lang_cnt.get(audio[i - 1], 0)
as_cnt = lang_cnt.get(subtitles[i - 1], 0)
if vp_cnt > best_vp_cnt:
best_vp_cnt = vp_cnt
best_as_cnt = as_cnt
best_movie = i
elif vp_cnt == best_vp_cnt and as_cnt > best_as_cnt:
best_vp_cnt = vp_cnt
best_as_cnt = as_cnt
best_movie = i
print(best_movie)
``` | output | 1 | 2,943 | 14 | 5,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
Submitted Solution:
```
parse_int = lambda: list(map(int, input().split()))
scientists = int(input())
sc_langs = parse_int()
films = int(input())
film_voice = parse_int()
film_sub = parse_int()
#print(film_voice)
#print(film_sub)
#ppl_in_lang = [0]*(10**9+5)
lang_decoder = dict()
lang_decoder.setdefault(0)
for _ in sc_langs:
if _ in lang_decoder.keys():
lang_decoder[_]+=1
else:
lang_decoder[_]=1
#print( lang_decoder)
film_good, film_ok = [0]*films, [0]*films
for _ in range(films):
try:
film_good[_] += (lang_decoder[film_voice[_]] or 0)
except KeyError:
pass
try:
film_ok[_] += (lang_decoder[film_sub[_] ] or 0)
except KeyError:
pass
best = 0
for _ in range(films):
if film_good[_] > film_good[best]: best = _
if (film_good[_] == film_good[best]) \
and (film_ok[_] > film_ok[best]): best = _
#print(film_good)
#print(film_ok)
print(best+1)
``` | instruction | 0 | 2,944 | 14 | 5,888 |
Yes | output | 1 | 2,944 | 14 | 5,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
Submitted Solution:
```
from collections import *
n=int(input())
d=Counter(map(int,input().split()))
m=int(input())
print(sorted((d[int(l[0])],d[int(l[1])],z+1)for z,l in enumerate(zip(input().split(),input().split())))[-1][2])
``` | instruction | 0 | 2,945 | 14 | 5,890 |
Yes | output | 1 | 2,945 | 14 | 5,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
Submitted Solution:
```
import traceback
import os
import sys
from io import BytesIO, IOBase
import math
from collections import defaultdict, Counter
from functools import lru_cache
from itertools import accumulate
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def geti():
return int(input())
def gets():
return input()
def getil():
return list(map(int, input().split()))
def getsl():
return input().split()
def get2d(nrows, ncols, n=0):
return [[n] * ncols for r in range(nrows)]
def get_acc(a):
return list(accumulate(a))
def get_ncr(n, r):
if n < r: return 0
return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def get_npr(n, r):
if n < r: return 0
return math.factorial(n) // math.factorial(r)
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
inf = float('inf')
mod = 10 ** 9 + 7
def main():
N = geti()
a = getil()
M = geti()
b = getil()
c = getil()
d = Counter(a)
p = max(range(M), key=lambda x: (d[b[x]], d[c[x]]))
return p+1
try:
ans = main()
print(ans)
except Exception as e:
print(e)
traceback.print_exc()
``` | instruction | 0 | 2,946 | 14 | 5,892 |
Yes | output | 1 | 2,946 | 14 | 5,893 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
Submitted Solution:
```
n = int(input())
a = [int(i) for i in input().split(' ')]
m = int(input())
b = [int(i) for i in input().split(' ')]
c = [int(i) for i in input().split(' ')]
d = {}
for i in range(n):
if a[i] not in d:
d[a[i]] = 1
else:
d[a[i]]+=1
p = [(d[b[i]] if b[i] in d else 0, d[c[i]] if c[i] in d else 0) for i in range(m)]
ans = 0
for i in range(1, m):
if p[ans]<p[i]:
ans = i
print(ans+1)
``` | instruction | 0 | 2,947 | 14 | 5,894 |
Yes | output | 1 | 2,947 | 14 | 5,895 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
Submitted Solution:
```
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
freq = Counter(a)
m = int(input())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
best_index = 0
best_score = (0, 0)
for i in range(m):
vs = freq[b[i]]
als = freq[c[i]]
if vs > best_score[0] or (vs == best_score[0] and als > best_score[1]):
best_index = i + 1
best_score = (vs, als)
print(best_index)
``` | instruction | 0 | 2,948 | 14 | 5,896 |
No | output | 1 | 2,948 | 14 | 5,897 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
Submitted Solution:
```
import bisect
from collections import defaultdict,Counter
import math
def solve(a,m,s):
mp=Counter(a)
pos=set()
Max=-1
for i in range(len(m)):
if m[i] in mp and mp[m[i]]>Max:
Max=mp[m[i]]
pos={i}
elif m[i] in mp and mp[m[i]]==Max:
pos.add(i)
else:
continue
if len(pos)==1:
for i in pos:
return (i+1)
Max=-1
for i in pos:
if mp[s[i]]>Max:
Max=mp[s[i]]
ans=i
if Max==-1:
for i in pos:
return (i+1)
return (ans+1)
``` | instruction | 0 | 2,949 | 14 | 5,898 |
No | output | 1 | 2,949 | 14 | 5,899 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
Submitted Solution:
```
from collections import defaultdict,Counter
import math
def solve(a,m,s):
mp=Counter(a)
pos=set()
Max=-1
for i in range(len(m)):
if m[i] in mp and mp[m[i]]>Max:
Max=mp[m[i]]
pos={i}
elif m[i] in mp and mp[m[i]]==Max:
pos.add(i)
else:
continue
if len(pos)==1:
for i in pos:
return m[i]
Max=-1
for i in pos:
if mp[s[i]]>Max:
Max=mp[s[i]]
ans=i
return m[ans]
n=int(input(''))
a=list(map(int,input('').split()))
_=int(input(''))
m=list(map(int,input('').split()))
s=list(map(int,input('').split()))
print(solve(a,m,s))
``` | instruction | 0 | 2,950 | 14 | 5,900 |
No | output | 1 | 2,950 | 14 | 5,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.
In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).
Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows.
The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.
The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie.
The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie.
It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.
Output
Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.
If there are several possible answers print any of them.
Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note
In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.
In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.
Submitted Solution:
```
n = int(input())
scientists = list(map(int, input().split()))
m = int(input())
voice = list(map(int, input().split()))
sub = list(map(int, input().split()))
freq = {scientists[i]: scientists.count(scientists[i]) for i in range(n)}
# print("Freq:", freq)
pop_lan = max(freq, key=freq.get)
# print("Popular lan:", pop_lan)
most_times = freq[pop_lan]
pop_lans = []
for key in freq:
if freq[key] == most_times:
pop_lans.append(key)
# print(pop_lans)
cool_films = []
for i in range(m):
if voice[i] in pop_lans:
cool_films.append(i)
# print(cool_films)
if len(cool_films) == 1:
print(cool_films[0]+1) # 1-based index
elif len(cool_films) == 0:
print(1)
else:
# print("Cool:", cool_films)
almost_cool = {ind: scientists.count(sub[ind]) for ind in cool_films}
# print("Almost", almost_cool)
print(max(almost_cool, key=almost_cool.get)+1)
"""
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
1 или 3
3
2 3 2
2
3 2
2 3
2
3
2 3 2
3
3 2 2
2 3 1
2
"""
``` | instruction | 0 | 2,951 | 14 | 5,902 |
No | output | 1 | 2,951 | 14 | 5,903 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.