message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 42 109k | cluster float64 5 5 | __index_level_0__ int64 84 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.
Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input
A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.
Output
Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.
Examples
Input
4
Output
8
Input
6
Output
28
Input
2
Output
0
Note
In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.
In the third example, it is impossible to perform even a single transformation.
Submitted Solution:
```
def fun_with_integers_linear2_solve():
n = int(input())
ans = 0
for i in range(2, n):
cant = n // i
ans += (cant * (cant + 1) // 2 - 1)
print(ans * 4)
fun_with_integers_linear2_solve()
``` | instruction | 0 | 62,301 | 5 | 124,602 |
Yes | output | 1 | 62,301 | 5 | 124,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.
Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input
A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.
Output
Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.
Examples
Input
4
Output
8
Input
6
Output
28
Input
2
Output
0
Note
In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.
In the third example, it is impossible to perform even a single transformation.
Submitted Solution:
```
class IntegersFun():
def __init__(self, n):
self.n = n
def get_value(self):
sm = 0
for i in range(2,self.n+1):
for j in range(2*i, self.n+1, i):
sm += 4*j/i
return int(sm)
n = int(input())
print(IntegersFun(n).get_value())
``` | instruction | 0 | 62,302 | 5 | 124,604 |
Yes | output | 1 | 62,302 | 5 | 124,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.
Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input
A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.
Output
Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.
Examples
Input
4
Output
8
Input
6
Output
28
Input
2
Output
0
Note
In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.
In the third example, it is impossible to perform even a single transformation.
Submitted Solution:
```
def fun_with_integers_sqrt_solve():
n = int(input())
ans = 0
l = 2
while l < n:
r = n // (n // l)
cant = n // l
ans += (cant * (cant + 1) // 2 - 1) * (r - l + 1)
l = r + 1
print(ans * 4)
fun_with_integers_sqrt_solve()
``` | instruction | 0 | 62,303 | 5 | 124,606 |
Yes | output | 1 | 62,303 | 5 | 124,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.
Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input
A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.
Output
Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.
Examples
Input
4
Output
8
Input
6
Output
28
Input
2
Output
0
Note
In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.
In the third example, it is impossible to perform even a single transformation.
Submitted Solution:
```
n=int(input())
print(sum([sum([k for k in range(2,n//j+1)]) for j in range(2,n//2+1)])*4)
``` | instruction | 0 | 62,304 | 5 | 124,608 |
Yes | output | 1 | 62,304 | 5 | 124,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.
Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input
A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.
Output
Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.
Examples
Input
4
Output
8
Input
6
Output
28
Input
2
Output
0
Note
In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.
In the third example, it is impossible to perform even a single transformation.
Submitted Solution:
```
#https://codeforces.com/contest/1062/problem/D
import math
n = int(input())
arr = [0] * (n+1)
for i in range(2,n+1):
count = 0
print("i:",i)
for j in range(2, math.floor(i/2) +1):
print(j)
if (i%j == 0):
score = int(i/j)
if score !=1:
count += 4 * score
arr[i] = arr[i-1] + count
print(arr)
print(arr[-1])
``` | instruction | 0 | 62,305 | 5 | 124,610 |
No | output | 1 | 62,305 | 5 | 124,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.
Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input
A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.
Output
Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.
Examples
Input
4
Output
8
Input
6
Output
28
Input
2
Output
0
Note
In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.
In the third example, it is impossible to perform even a single transformation.
Submitted Solution:
```
from math import sqrt, floor
n = int(input())
xx = [d*(n//d-1) for d in range(2, 2+floor(sqrt(n)))]
print(sum(xx)*4)
``` | instruction | 0 | 62,306 | 5 | 124,612 |
No | output | 1 | 62,306 | 5 | 124,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.
Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input
A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.
Output
Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.
Examples
Input
4
Output
8
Input
6
Output
28
Input
2
Output
0
Note
In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.
In the third example, it is impossible to perform even a single transformation.
Submitted Solution:
```
n=int(input())
ans=0
if(n==2 or n==3):
print(0)
else:
i=4
while(i<=n):
j=i//2
#print(j)
ans+=(2*j*(j+1))
ans-=4
i+=2
#print((2*j*(j+1)))
print(ans)
``` | instruction | 0 | 62,307 | 5 | 124,614 |
No | output | 1 | 62,307 | 5 | 124,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increases by |x| points and you are not allowed to transform a into b nor b into a anymore.
Initially, you have a score of 0. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input
A single line contains a single integer n (2 ≤ n ≤ 100 000) — the given integer described above.
Output
Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 0.
Examples
Input
4
Output
8
Input
6
Output
28
Input
2
Output
0
Note
In the first example, the transformations are 2 → 4 → (-2) → (-4) → 2.
In the third example, it is impossible to perform even a single transformation.
Submitted Solution:
```
#https://codeforces.com/contest/1062/problem/D
import math
n = int(input())
arr = [0] * (n+1)
for i in range(2,n+1):
count = 0
for j in range(2, math.floor(i**0.5) +2):
if (i%j == 0):
score = int(i/j)
if score !=1:
count += 4 * score
arr[i] = arr[i-1] + count
#print(arr)
print(arr[-1])
``` | instruction | 0 | 62,308 | 5 | 124,616 |
No | output | 1 | 62,308 | 5 | 124,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This problem was deleted from the contest, because it was used previously at another competition.
Input
Output
Examples
Input
1 1
1 2 100
Output
6
Submitted Solution:
```
n, m = map(int, input().split())
l, r, p = map(int, input().split())
def gcd(x,y):
if x == 0 or y == 0:
return max(x, y)
elif x > y:
return gcd(y, x % y)
elif x < y:
return gcd(x, y % x)
else:
return x
# определяем возможные вектора наблюдения
vectors = set()
for i in range(1, r + 1):
for j in range(r + 1):
if l ** 2 <= i ** 2 + j ** 2 <= r ** 2:
k = gcd(i, j)
x = i // k
y = j // k
vectors.add((x,y))
# считаем полное число пар
pairs = 0
for x, y in vectors:
a = n + 1 - x
a = 0 if a < 0 else a
b = m + 1 - y
b = 0 if b < 0 else b
c = n + 1 - y
c = 0 if c < 0 else c
d = m + 1 - x
d = 0 if d < 0 else d
pairs += (a * b + c * d) % p
pairs = pairs % p
print(pairs)
``` | instruction | 0 | 62,669 | 5 | 125,338 |
No | output | 1 | 62,669 | 5 | 125,339 |
Provide a correct Python 3 solution for this coding contest problem.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000 | instruction | 0 | 62,886 | 5 | 125,772 |
"Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = [0] * 100001
for i in a:
l[i] += 1
s = sum(a)
for _ in range(q):
b, c = map(int, input().split())
s += (c - b) * l[b]
l[c] += l[b]
l[b] = 0
print(s)
``` | output | 1 | 62,886 | 5 | 125,773 |
Provide a correct Python 3 solution for this coding contest problem.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000 | instruction | 0 | 62,887 | 5 | 125,774 |
"Correct Solution:
```
import collections
n=int(input())
l=list(map(int, input().split()))
q=int(input())
s=sum(l)
d=collections.Counter(l)
for i in range(q):
a,b=map(int, input().split())
s=s-(a*d[a])
s=s+(b*d[a])
d[b]=d[b]+d[a]
d[a]=0
print(s)
``` | output | 1 | 62,887 | 5 | 125,775 |
Provide a correct Python 3 solution for this coding contest problem.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000 | instruction | 0 | 62,888 | 5 | 125,776 |
"Correct Solution:
```
N=int(input())
A=list(map(int,input().split()))
dp=[0]*(10**5+1)
cnt=0
Q=int(input())
for a in A:
cnt+=a
dp[a]+=1
for i in range(Q):
b,c=map(int,input().split())
a=dp[b]
cnt+=(c-b)*a
dp[c]+=a
dp[b]=0
print(cnt)
``` | output | 1 | 62,888 | 5 | 125,777 |
Provide a correct Python 3 solution for this coding contest problem.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000 | instruction | 0 | 62,889 | 5 | 125,778 |
"Correct Solution:
```
import collections
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
Q = int(input())
T = collections.Counter(A)
for i in range(Q):
b, c = map(int, input().split())
S += T[b]*(c-b)
T[c] += T[b]
T[b] = 0
print(S)
``` | output | 1 | 62,889 | 5 | 125,779 |
Provide a correct Python 3 solution for this coding contest problem.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000 | instruction | 0 | 62,890 | 5 | 125,780 |
"Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
arr=[0]*(10**5+1)
for i in a:
arr[i]+=1
s=sum(a)
for i in range(int(input())):
b,c=map(int,input().split())
arr[c]+=arr[b]
s=s+arr[b]*c-arr[b]*b
arr[b]=0
print(s)
``` | output | 1 | 62,890 | 5 | 125,781 |
Provide a correct Python 3 solution for this coding contest problem.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000 | instruction | 0 | 62,891 | 5 | 125,782 |
"Correct Solution:
```
#abc171d
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
d=(10**5+100)*[0]
res=sum(A)
for x in A:
d[x]+=1
for i in range(Q):
b,c=map(int,input().split())
res+=d[b]*(c-b)
d[c]+=d[b]
d[b]=0
print(res)
``` | output | 1 | 62,891 | 5 | 125,783 |
Provide a correct Python 3 solution for this coding contest problem.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000 | instruction | 0 | 62,892 | 5 | 125,784 |
"Correct Solution:
```
N=int(input())
*A,=map(int,input().split())
A.sort()
Q=int(input())
bc=[list(map(int,input().split()))for _ in range(Q)]
from collections import*
C=Counter(A)
ans=sum(A)
for b,c in bc:
C[b],C[c],ans=0,C[c]+C[b],ans-b*C[b]+c*C[b]
print(ans)
``` | output | 1 | 62,892 | 5 | 125,785 |
Provide a correct Python 3 solution for this coding contest problem.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000 | instruction | 0 | 62,893 | 5 | 125,786 |
"Correct Solution:
```
import collections
n=int(input())
a=[int(i) for i in input().split()]
c = collections.Counter(a)
suma=sum(a)
q=int(input())
for i in range(q):
x,y=map(int,input().split())
print(suma+c[x]*(y-x))
suma+=c[x]*(y-x)
c[y]+=c[x]
c[x]=0
``` | output | 1 | 62,893 | 5 | 125,787 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000
Submitted Solution:
```
n=int(input())
a_list=list(map(int,input().split()))
cnt = [0] * int(1e5 + 10)
sum=0
for i in a_list:
cnt[i] +=1
sum+=i
q=int(input())
ans=0
for j in range(q):
x,y=map(int,input().split())
sum+=(y-x)*cnt[x]
cnt[y]+=cnt[x]
cnt[x]=0
print(sum)
``` | instruction | 0 | 62,894 | 5 | 125,788 |
Yes | output | 1 | 62,894 | 5 | 125,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
q = int(input())
A = [0]*1000000
for i in a:
A[i] += 1
ans = sum(a)
for i in range(q):
b, c = map(int, input().split())
ans = ans+((c-b)*(A[b]))
print(ans)
A[c] += A[b]
A[b] = 0
``` | instruction | 0 | 62,895 | 5 | 125,790 |
Yes | output | 1 | 62,895 | 5 | 125,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000
Submitted Solution:
```
n=int(input())
A=list(map(int,input().split()))
q=int(input())
coun=[0]*10**5
A_=sum(A)
for i in A:
coun[i-1]+=1
for _ in range(q):
b,c=map(int,input().split())
A_+=(c-b)*coun[b-1]
coun[c-1]+=coun[b-1]
coun[b-1]=0
print(A_)
``` | instruction | 0 | 62,896 | 5 | 125,792 |
Yes | output | 1 | 62,896 | 5 | 125,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000
Submitted Solution:
```
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
num=[0]*100001
for i in A:
num[i]+=1
for _ in range(int(input())):
B,C=map(int,input().split())
s+=(C-B)*num[B]
num[C]+=num[B]
num[B]=0
print(s)
``` | instruction | 0 | 62,897 | 5 | 125,794 |
Yes | output | 1 | 62,897 | 5 | 125,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000
Submitted Solution:
```
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
dict_a = dict()
for a in A:
if not (a in dict_a):
dict_a[a] = 1
else:
dict_a[a] += 1
Q = int(input())
B = []
C = []
sums = []
for i in range(Q):
b, c = list(map(int, input().split()))
B.append(b)
C.append(c)
for b, c in zip(B, C):
if (b in dict_a):
num = dict_a[b]
if not (c in dict_a):
dict_a[c] = num
else:
dict_a[c] += num
dict_a.pop(b)
keys = dict_a.keys()
vals = dict_a.values()
sumval = 0
for k, v in zip(keys, vals):
sumval += k * v
print(sumval)
``` | instruction | 0 | 62,898 | 5 | 125,796 |
No | output | 1 | 62,898 | 5 | 125,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000
Submitted Solution:
```
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
B, C = list(map(int, input().split()))
if B not in A:
print(sum_)
continue
sum_ = 0
for j in range(len(A)):
if A[j] == B:
A[j] = C
sum_ += A[j]
print(sum_)
``` | instruction | 0 | 62,899 | 5 | 125,798 |
No | output | 1 | 62,899 | 5 | 125,799 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000
Submitted Solution:
```
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
ans = [0]*(10**5)
for i in range (len(A)):
ans[A[i]] += 1
maxlen = max(max(A),max(max(BC)))
for i in range(Q):
ans[BC[i][1]] += ans[BC[i][0]]
ans[BC[i][0]] = 0
S = 0
for i in range(maxlen+1):
S += ans [i]*i
print(S)
``` | instruction | 0 | 62,900 | 5 | 125,800 |
No | output | 1 | 62,900 | 5 | 125,801 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}.
You will now successively do the following Q operations:
* In the i-th operation, you replace every element whose value is B_{i} with C_{i}.
For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
Constraints
* All values in input are integers.
* 1 \leq N, Q, A_{i}, B_{i}, C_{i} \leq 10^{5}
* B_{i} \neq C_{i}
Input
Input is given from Standard Input in the following format:
N
A_{1} A_{2} \cdots A_{N}
Q
B_{1} C_{1}
B_{2} C_{2}
\vdots
B_{Q} C_{Q}
Output
Print Q integers S_{i} to Standard Output in the following format:
S_{1}
S_{2}
\vdots
S_{Q}
Note that S_{i} may not fit into a 32-bit integer.
Examples
Input
4
1 2 3 4
3
1 2
3 4
2 4
Output
11
12
16
Input
4
1 1 1 1
3
1 2
2 1
3 5
Output
8
4
4
Input
2
1 2
3
1 100
2 100
100 1000
Output
102
200
2000
Submitted Solution:
```
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
B, C = map(int, input().split())
while B in A:
A[A.index(B)] = C
print(sum(A))
``` | instruction | 0 | 62,901 | 5 | 125,802 |
No | output | 1 | 62,901 | 5 | 125,803 |
Provide a correct Python 3 solution for this coding contest problem.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1 | instruction | 0 | 62,902 | 5 | 125,804 |
"Correct Solution:
```
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
for i in range(0, 10**n):
if len(str(i)) == n and all(str(i)[s-1] == str(c) for s,c in sc):
print(i)
break
else:
print(-1)
``` | output | 1 | 62,902 | 5 | 125,805 |
Provide a correct Python 3 solution for this coding contest problem.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1 | instruction | 0 | 62,903 | 5 | 125,806 |
"Correct Solution:
```
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for j in range(m)]
for i in range(0 if n == 1 else 10**(n - 1), 10**n):
if all(str(i)[s - 1] == str(c) for s, c in sc):
print(i)
break
else:
print(-1)
``` | output | 1 | 62,903 | 5 | 125,807 |
Provide a correct Python 3 solution for this coding contest problem.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1 | instruction | 0 | 62,904 | 5 | 125,808 |
"Correct Solution:
```
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
ret = -1
for i in range(10**n+1):
x = str(i)
if len(x)!=n:
continue
flg = True
for s,c in sc:
if x[s-1]!=str(c):
flg = False
if flg:
ret = x
break
print(ret)
``` | output | 1 | 62,904 | 5 | 125,809 |
Provide a correct Python 3 solution for this coding contest problem.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1 | instruction | 0 | 62,905 | 5 | 125,810 |
"Correct Solution:
```
import sys
n,m=map(int,input().split())
l=[0]*n
o=0
for i in sys.stdin:
s,c=map(int,i.split())
if s==1 and c==0 and n!=1:
o=-1
break
elif l[s-1]==0 or l[s-1]==c:
l[s-1]=c
else:
o=-1
break
if o==0:
if l[0]==0 and n>1:
l[0]=1
o=''.join([str(i) for i in l])
print(o)
``` | output | 1 | 62,905 | 5 | 125,811 |
Provide a correct Python 3 solution for this coding contest problem.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1 | instruction | 0 | 62,906 | 5 | 125,812 |
"Correct Solution:
```
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
ans = '1'
if n == 1:
ans = '0'
for i in range(n-1):
ans += '0'
while len(ans) == n:
if all([ans[s-1] == str(c) for s, c in sc]):
print(ans)
exit()
ans = str(int(ans)+1)
print(-1)
``` | output | 1 | 62,906 | 5 | 125,813 |
Provide a correct Python 3 solution for this coding contest problem.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1 | instruction | 0 | 62,907 | 5 | 125,814 |
"Correct Solution:
```
n,m=map(int,input().split())
a=["0"]*n
for i in range(m):
s,c=map(int,input().split())
if a[s-1]=="0":
a[s-1]=c
elif a[s-1]!=c:
print(-1)
exit()
if n>1 and a[0]==0:
print(-1)
exit()
if n>1 and a[0]=="0":
a[0]=1
print(*a,sep="")
``` | output | 1 | 62,907 | 5 | 125,815 |
Provide a correct Python 3 solution for this coding contest problem.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1 | instruction | 0 | 62,908 | 5 | 125,816 |
"Correct Solution:
```
n,m = map(int,input().split())
sc = [list(map(int,input().split()))for _ in range(m)]
for i in range(1000):
ok = True
x = str(i)
if len(x) !=n:continue
for s,c in sc:
if int(x[s-1]) !=c:
ok = False
if ok:
print(i)
exit(0)
print(-1)
``` | output | 1 | 62,908 | 5 | 125,817 |
Provide a correct Python 3 solution for this coding contest problem.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1 | instruction | 0 | 62,909 | 5 | 125,818 |
"Correct Solution:
```
n, m = map(int, input().split())
sc = [[int(x) for x in input().split()] for _ in range(m)]
ans = -1
for i in range(10**n):
if len(str(i)) != n:
continue
x = str(i)
for s, c in sc:
if int(x[s-1]) != c:
break
else:
print(i)
exit()
print(-1)
``` | output | 1 | 62,909 | 5 | 125,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1
Submitted Solution:
```
N,M=map(int,input().split())
sc=[tuple(map(int,input().split())) for m in range(M)]
for i in range(10**N):
if len(str(i))==N and all(str(i)[s-1]==str(c) for s,c in sc):
print(i)
break
else:
print(-1)
``` | instruction | 0 | 62,910 | 5 | 125,820 |
Yes | output | 1 | 62,910 | 5 | 125,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1
Submitted Solution:
```
n,m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
for i in range(1000):
k = str(i)
if len(k) == n and all([k[s-1]==str(c) for s,c in sc]):
print(k)
exit()
print(-1)
``` | instruction | 0 | 62,911 | 5 | 125,822 |
Yes | output | 1 | 62,911 | 5 | 125,823 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1
Submitted Solution:
```
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]
lb = 10 ** (N - 1) if N > 1 else 0
for n in range(lb, 10 ** N):
flag = True
for s, c in X:
flag &= n // (10 ** (N - s)) % 10 == c
if flag:
print(n)
break
else:
print(-1)
``` | instruction | 0 | 62,912 | 5 | 125,824 |
Yes | output | 1 | 62,912 | 5 | 125,825 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1
Submitted Solution:
```
n, m = map(int, input().split())
lst = []
for i in range(m):
s, c = map(int, input().split())
lst.append([s, c])
ans = -1
for j in range(10 ** n):
if len(str(j)) != n:
continue
for i in range(m):
if int(str(j)[lst[i][0]-1]) != lst[i][1]:
break
else:
ans = j
break
print(ans)
``` | instruction | 0 | 62,913 | 5 | 125,826 |
Yes | output | 1 | 62,913 | 5 | 125,827 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1
Submitted Solution:
```
f=lambda:map(int,input().split())
n,m=f()
l=[0]*n
b=[0]*n
l[0]=1
for _ in range(m):
s,c=f()
s-=1
if b[s] and l[s]!=c or s==c==0:
print(-1)
exit()
l[s]=c
b[s]=1
print(*l,sep='')
``` | instruction | 0 | 62,914 | 5 | 125,828 |
No | output | 1 | 62,914 | 5 | 125,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1
Submitted Solution:
```
n, m = map(int, input().split())
temp = list(['?'] * n)
# print(temp)
for _ in range(m):
s, c = map(int, input().split())
if (s == 1 and c == 0):
print(-1)
exit()
if (temp[s-1] == '?'):
temp[s - 1] = str(c)
elif (temp[s - 1] == str(c)):
pass
else:
print(-1)
exit()
if (temp[0] == '?'):
temp[0] = '1'
ans01 = ''.join(temp)
ans02 = ans01.replace('?', '0')
print(ans02)
``` | instruction | 0 | 62,915 | 5 | 125,830 |
No | output | 1 | 62,915 | 5 | 125,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1
Submitted Solution:
```
N, M=map(int, input().split())
lst=[None]*M
for i in range(M):
lst[i]=tuple(map(int, input().split()))
#print(N, M, lst)
digit=[]
for _ in range(N):
digit.append([])
for val in lst:
digit[val[0]-1].append(val[1])
#print(digit)
num=0
if N==3 and 0 in digit[0]:
print(-1)
elif N==2 and 0 in digit[1]:
print(-1)
else:
for i in range(N):
if len(set(digit[i]))>=2:
print(-1)
break
elif digit[i]:
num+=digit[i][0]*10**(N-i-1)
else:
print(num)
``` | instruction | 0 | 62,916 | 5 | 125,832 |
No | output | 1 | 62,916 | 5 | 125,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print `-1`.
* The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)
* The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)
Constraints
* All values in input are integers.
* 1 \leq N \leq 3
* 0 \leq M \leq 5
* 1 \leq s_i \leq N
* 0 \leq c_i \leq 9
Input
Input is given from Standard Input in the following format:
N M
s_1 c_1
\vdots
s_M c_M
Output
Print the answer.
Examples
Input
3 3
1 7
3 2
1 7
Output
702
Input
3 2
2 1
2 3
Output
-1
Input
3 1
1 0
Output
-1
Submitted Solution:
```
n,m = map(int, input().split())
theNumber = [-1 for x in range(n)]
valid = True
for i in range(m):
if (valid):
s,c = map(int, input().split())
if (s == 1 and c == 0):
valid = False
elif theNumber[s-1] != -1 and theNumber[s-1] != c:
valid = False
else:
theNumber[s-1] = c
else:
break
if (not valid):
print(-1)
else:
num = list(map(lambda x: 0 if x==-1 else x, theNumber))
if (num[0] == 0):
num[0] = 1
print(''.join(map(str, num)))
``` | instruction | 0 | 62,917 | 5 | 125,834 |
No | output | 1 | 62,917 | 5 | 125,835 |
Provide a correct Python 3 solution for this coding contest problem.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6 | instruction | 0 | 63,017 | 5 | 126,034 |
"Correct Solution:
```
while True:
try:
s = input()
except EOFError:
break
a, b, n = map(int, s.split())
a %= b
x = 0
for i in range(n):
a *= 10
if a >= b:
q, a = divmod(a, b)
x += q
print(x)
``` | output | 1 | 63,017 | 5 | 126,035 |
Provide a correct Python 3 solution for this coding contest problem.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6 | instruction | 0 | 63,018 | 5 | 126,036 |
"Correct Solution:
```
import sys
for a, b, n in (map(int, l.split()) for l in sys.stdin.readlines()):
if a >= b:
a %= b
a *= 10
ans = 0
for _ in [0]*n:
d, m = divmod(a, b)
ans += d
a = m*10
print(ans)
``` | output | 1 | 63,018 | 5 | 126,037 |
Provide a correct Python 3 solution for this coding contest problem.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6 | instruction | 0 | 63,019 | 5 | 126,038 |
"Correct Solution:
```
while True:
try: x = input()
except: break
a, b, n = map(int, x.split())
s = 0
for _ in range(n):
a *= 10
s += (a // b) % 10
print(s)
``` | output | 1 | 63,019 | 5 | 126,039 |
Provide a correct Python 3 solution for this coding contest problem.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6 | instruction | 0 | 63,020 | 5 | 126,040 |
"Correct Solution:
```
while True:
try:
a,b,n=map(int,input().split())
ans = 0
for i in range(n):
a*=10
ans+=(a//b)%10
print(ans)
except EOFError:
break
``` | output | 1 | 63,020 | 5 | 126,041 |
Provide a correct Python 3 solution for this coding contest problem.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6 | instruction | 0 | 63,021 | 5 | 126,042 |
"Correct Solution:
```
a = []
b = []
n = []
while True:
try:
tmp = list(input().split())
a.append(int(tmp[0]))
b.append(int(tmp[1]))
n.append(int(tmp[2]))
except EOFError:
break
for i in range(len(a)):
s = 0
for j in range(n[i]):
f = a[i]*(10**(j+1))
s += (f//b[i])%10
print(s)
``` | output | 1 | 63,021 | 5 | 126,043 |
Provide a correct Python 3 solution for this coding contest problem.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6 | instruction | 0 | 63,022 | 5 | 126,044 |
"Correct Solution:
```
while True:
try:
a, b, n = map(int, input().split())
ans = 0
#10倍して1の位の数を足していく
for i in range(n):
a *= 10
ans += (a // b) % 10
print(ans)
except EOFError:
break
``` | output | 1 | 63,022 | 5 | 126,045 |
Provide a correct Python 3 solution for this coding contest problem.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6 | instruction | 0 | 63,023 | 5 | 126,046 |
"Correct Solution:
```
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
for line in readlines():
a, b, n = map(int, line.split())
a %= b
res = 0
for i in range(n):
d, a = divmod(10*a, b)
res += d
write("%d\n" % res)
solve()
``` | output | 1 | 63,023 | 5 | 126,047 |
Provide a correct Python 3 solution for this coding contest problem.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6 | instruction | 0 | 63,024 | 5 | 126,048 |
"Correct Solution:
```
import sys
for l in sys.stdin:
a,b,n=map(int,l.split(" "))
print(sum(map(int,list(str((a%b)*10**n//b)))))
``` | output | 1 | 63,024 | 5 | 126,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Assume that a, b, and n are all positive integers. Let f (i) be the i-th fraction of the fraction a / b (0 ≤ f (i) ≤ 9). At this time, let s be the sum of f (i) from i = 1 to n.
s = f (1) + f (2) + ... + f (n)
Create a program that reads a, b, n, outputs s, and exits.
Input
The input consists of multiple datasets. For each dataset, three integers a (1 ≤ a ≤ 1000), b (1 ≤ b ≤ 10000), n (1 ≤ n ≤ 100) are given on one line, separated by blanks.
The number of datasets does not exceed 100.
Output
Prints s on one line for each dataset.
Example
Input
1 2 3
2 3 4
5 4 3
4 3 2
Output
5
24
7
6
Submitted Solution:
```
import re
while True:
try:
a,b,n = map(int, input().strip().split())
u = str((float(a)/b))
v = list(re.sub(r'[^\.]*\.', '', u))[:n]
w = sum(map(int,v))
print(w)
except EOFError:
break
``` | instruction | 0 | 63,025 | 5 | 126,050 |
Yes | output | 1 | 63,025 | 5 | 126,051 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.