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.
Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.
You are given the sequence A and q questions where each question contains Mi.
Notes
You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:
solve(0, M)
solve(1, M-{sum created from elements before 1st element})
solve(2, M-{sum created from elements before 2nd element})
...
The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.
For example, the following figure shows that 8 can be made by A[0] + A[2].
<image>
Constraints
* n ≤ 20
* q ≤ 200
* 1 ≤ elements in A ≤ 2000
* 1 ≤ Mi ≤ 2000
Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.
Output
For each question Mi, print yes or no.
Example
Input
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35
Output
no
no
yes
yes
yes
yes
no
no
Submitted Solution:
```
cin = open(0).read().split('\n')
n = int(cin[0])
a = list(map(int, cin[1].split(' ')))
q = int(cin[2])
m = list(map(int, cin[3].split(' ')))
tmp = []
for i in range(2**n):
ret = 0
for j in range(n):
if (i>>j) & 1:
ret += a[j]
tmp.append(ret)
for mi in m:
if mi in tmp:
print('yes')
else:
print('no')
``` | instruction | 0 | 29,077 | 5 | 58,154 |
Yes | output | 1 | 29,077 | 5 | 58,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.
You are given the sequence A and q questions where each question contains Mi.
Notes
You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:
solve(0, M)
solve(1, M-{sum created from elements before 1st element})
solve(2, M-{sum created from elements before 2nd element})
...
The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.
For example, the following figure shows that 8 can be made by A[0] + A[2].
<image>
Constraints
* n ≤ 20
* q ≤ 200
* 1 ≤ elements in A ≤ 2000
* 1 ≤ Mi ≤ 2000
Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.
Output
For each question Mi, print yes or no.
Example
Input
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35
Output
no
no
yes
yes
yes
yes
no
no
Submitted Solution:
```
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
M = list(map(int,input().split()))
def bitsearch():
nums = [0] * (2 ** N)
for i in range(2 ** N):
num = 0
for j in range(N):
if (i >> j) & 1:
num += A[j]
nums[i] = num
for q in range(Q):
if M[q] in nums:
print("yes")
else:
print("no")
bitsearch()
``` | instruction | 0 | 29,078 | 5 | 58,156 |
Yes | output | 1 | 29,078 | 5 | 58,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.
You are given the sequence A and q questions where each question contains Mi.
Notes
You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:
solve(0, M)
solve(1, M-{sum created from elements before 1st element})
solve(2, M-{sum created from elements before 2nd element})
...
The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.
For example, the following figure shows that 8 can be made by A[0] + A[2].
<image>
Constraints
* n ≤ 20
* q ≤ 200
* 1 ≤ elements in A ≤ 2000
* 1 ≤ Mi ≤ 2000
Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.
Output
For each question Mi, print yes or no.
Example
Input
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35
Output
no
no
yes
yes
yes
yes
no
no
Submitted Solution:
```
n = int(input())
seq = list(map(int, input().split()))
q = int(input())
mlist = list(map(int, input().split()))
def check(i, m):
if m == 0:
return True
elif i >= n:
return False
res = check(i+1, m) + check(i+1, m - seq[i])
return res
for m in mlist:
if(check(0,m)):
print('yes')
else:
print('no')
``` | instruction | 0 | 29,079 | 5 | 58,158 |
No | output | 1 | 29,079 | 5 | 58,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.
You are given the sequence A and q questions where each question contains Mi.
Notes
You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:
solve(0, M)
solve(1, M-{sum created from elements before 1st element})
solve(2, M-{sum created from elements before 2nd element})
...
The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.
For example, the following figure shows that 8 can be made by A[0] + A[2].
<image>
Constraints
* n ≤ 20
* q ≤ 200
* 1 ≤ elements in A ≤ 2000
* 1 ≤ Mi ≤ 2000
Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.
Output
For each question Mi, print yes or no.
Example
Input
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35
Output
no
no
yes
yes
yes
yes
no
no
Submitted Solution:
```
def solve(m, A, i):
if m==0: return True
if i>n-1: return False
f1 = solve(m-A[i], A, i+1)
f2 = solve(m, A, i+1)
return f1 or f2
n = int(input())
A = list(map(int, input().split()))
input()
for m in map( int, input().split() ):
print( 'yes' if solve(m, A, 0) else 'no')
``` | instruction | 0 | 29,080 | 5 | 58,160 |
No | output | 1 | 29,080 | 5 | 58,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.
You are given the sequence A and q questions where each question contains Mi.
Notes
You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:
solve(0, M)
solve(1, M-{sum created from elements before 1st element})
solve(2, M-{sum created from elements before 2nd element})
...
The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.
For example, the following figure shows that 8 can be made by A[0] + A[2].
<image>
Constraints
* n ≤ 20
* q ≤ 200
* 1 ≤ elements in A ≤ 2000
* 1 ≤ Mi ≤ 2000
Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.
Output
For each question Mi, print yes or no.
Example
Input
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35
Output
no
no
yes
yes
yes
yes
no
no
Submitted Solution:
```
def solve(i, m):
if m == 0:
return True
if i == n:
return False
return solve(i+1, m) or solve(i+1, m-A[i])
if __name__ == "__main__":
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
for m in M:
if solve(0, m):
print("yes")
else:
print("no")
``` | instruction | 0 | 29,081 | 5 | 58,162 |
No | output | 1 | 29,081 | 5 | 58,163 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.
You are given the sequence A and q questions where each question contains Mi.
Notes
You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:
solve(0, M)
solve(1, M-{sum created from elements before 1st element})
solve(2, M-{sum created from elements before 2nd element})
...
The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.
For example, the following figure shows that 8 can be made by A[0] + A[2].
<image>
Constraints
* n ≤ 20
* q ≤ 200
* 1 ≤ elements in A ≤ 2000
* 1 ≤ Mi ≤ 2000
Input
In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.
Output
For each question Mi, print yes or no.
Example
Input
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35
Output
no
no
yes
yes
yes
yes
no
no
Submitted Solution:
```
# -*- coding: utf_8 -*-
from itertools import repeat
from itertools import combinations
def rec(s, i, total, m):
if total == m:
return 1
if len(s) == i or total > m:
return 0
return rec(s, i + 1, total, m) + rec(s, i + 1, total + s[i], m)
def loop(s, m):
for i in range(len(s)):
comb = list(combinations(s, i))
for c in comb:
if sum(c) == m:
return 1
return 0
if __name__ == "__main__":
n = int(input())
a = [int (x) for x in input().split()]
q = int(input())
m = [int (x) for x in input().split()]
for i in m:
#print("yes") if rec(a, 0, 0, i) > 0 else print("no")
print("yes") if loop(a, i) > 0 else print("no")
``` | instruction | 0 | 29,082 | 5 | 58,164 |
No | output | 1 | 29,082 | 5 | 58,165 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a of n integers.
You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
Input
The first line of input contains the integer n (3 ≤ n ≤ 10^{6}), the size of the array a.
Next line contains n space separated integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 2 ⋅ 10^{6}), representing the elements of the array a.
Output
Output a single integer, the maximum value of the expression given in the statement.
Examples
Input
3
2 4 6
Output
6
Input
4
2 8 4 7
Output
12
Note
In the first example, the only possible triplet is (1, 2, 3). Hence, the answer is 2 | (4 \& 6) = 6.
In the second example, there are 4 possible triplets:
1. (1, 2, 3), value of which is 2|(8\&4) = 2.
2. (1, 2, 4), value of which is 2|(8\&7) = 2.
3. (1, 3, 4), value of which is 2|(4\&7) = 6.
4. (2, 3, 4), value of which is 8|(4\&7) = 12.
The maximum value hence is 12.
Submitted Solution:
```
from random import randint
n = int(input())
A = list(map(int, input().split()))
ans = 0
for _ in range(100000):
x = randint(0, n - 1)
y = randint(0, n - 1)
z = randint(0, n - 1)
if len({x, y, z}) == 3:
ans = max(ans, A[x] | (A[y] & A[z]))
print(ans)
``` | instruction | 0 | 29,215 | 5 | 58,430 |
No | output | 1 | 29,215 | 5 | 58,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a of n integers.
You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
Input
The first line of input contains the integer n (3 ≤ n ≤ 10^{6}), the size of the array a.
Next line contains n space separated integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 2 ⋅ 10^{6}), representing the elements of the array a.
Output
Output a single integer, the maximum value of the expression given in the statement.
Examples
Input
3
2 4 6
Output
6
Input
4
2 8 4 7
Output
12
Note
In the first example, the only possible triplet is (1, 2, 3). Hence, the answer is 2 | (4 \& 6) = 6.
In the second example, there are 4 possible triplets:
1. (1, 2, 3), value of which is 2|(8\&4) = 2.
2. (1, 2, 4), value of which is 2|(8\&7) = 2.
3. (1, 3, 4), value of which is 2|(4\&7) = 6.
4. (2, 3, 4), value of which is 8|(4\&7) = 12.
The maximum value hence is 12.
Submitted Solution:
```
from random import randint
n = int(input())
A = list(map(int, input().split()))
ans = 0
for _ in range(10000):
x = randint(0, n - 1)
y = randint(0, n - 1)
z = randint(0, n - 1)
if len({x, y, z}) == 3:
ans = max(ans, A[x] | (A[y] & A[z]))
print(ans)
``` | instruction | 0 | 29,216 | 5 | 58,432 |
No | output | 1 | 29,216 | 5 | 58,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a of n integers.
You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
Input
The first line of input contains the integer n (3 ≤ n ≤ 10^{6}), the size of the array a.
Next line contains n space separated integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 2 ⋅ 10^{6}), representing the elements of the array a.
Output
Output a single integer, the maximum value of the expression given in the statement.
Examples
Input
3
2 4 6
Output
6
Input
4
2 8 4 7
Output
12
Note
In the first example, the only possible triplet is (1, 2, 3). Hence, the answer is 2 | (4 \& 6) = 6.
In the second example, there are 4 possible triplets:
1. (1, 2, 3), value of which is 2|(8\&4) = 2.
2. (1, 2, 4), value of which is 2|(8\&7) = 2.
3. (1, 3, 4), value of which is 2|(4\&7) = 6.
4. (2, 3, 4), value of which is 8|(4\&7) = 12.
The maximum value hence is 12.
Submitted Solution:
```
from sys import stdin
from sys import setrecursionlimit as SRL; SRL(10**7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())
cnt = [0]*(1<<21)
n = int(input())
a = list(rrd())
def insert(x,y):
if cnt[x|y]>=2:
return
if x==0:
cnt[y] += 1
insert(x&x-1,y|(x&-x))
insert(x&x-1,y)
def query(x):
ans = 0
for i in range(20,-1,-1):
if not x&(1<<i) and cnt[ans|(1<<i)]>=2:
ans |= (1<<i)
return x|ans
ans = 0
for i in range(n-1,-1,-1):
if n-i>=3:
ans = max(ans,query(a[i]))
insert(a[i],0)
print(ans)
``` | instruction | 0 | 29,217 | 5 | 58,434 |
No | output | 1 | 29,217 | 5 | 58,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a of n integers.
You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
Input
The first line of input contains the integer n (3 ≤ n ≤ 10^{6}), the size of the array a.
Next line contains n space separated integers a_1, a_2, ..., a_n (0 ≤ a_{i} ≤ 2 ⋅ 10^{6}), representing the elements of the array a.
Output
Output a single integer, the maximum value of the expression given in the statement.
Examples
Input
3
2 4 6
Output
6
Input
4
2 8 4 7
Output
12
Note
In the first example, the only possible triplet is (1, 2, 3). Hence, the answer is 2 | (4 \& 6) = 6.
In the second example, there are 4 possible triplets:
1. (1, 2, 3), value of which is 2|(8\&4) = 2.
2. (1, 2, 4), value of which is 2|(8\&7) = 2.
3. (1, 3, 4), value of which is 2|(4\&7) = 6.
4. (2, 3, 4), value of which is 8|(4\&7) = 12.
The maximum value hence is 12.
Submitted Solution:
```
from sys import stdin
from sys import setrecursionlimit as SRL; SRL(10**7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())
cnt = [0]*(1<<21)
n = int(input())
a = list(rrd())
def insert(x):
if cnt[x]>=2:
return
cnt[x] += 1
now = x
while now:
t = now&(-now)
now -= t
insert(x^t)
def query(x):
ans = 0
for i in range(20,-1,-1):
if not x&(1<<i) and cnt[ans|(1<<i)]>=2:
ans |= (1<<i)
return x|ans
ans = 0
for i in range(n-1,-1,-1):
ans = max(ans,query(a[i]))
insert(a[i])
print(ans)
``` | instruction | 0 | 29,218 | 5 | 58,436 |
No | output | 1 | 29,218 | 5 | 58,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628
Submitted Solution:
```
for _ in range(int(input())):
a,k = map(int,input().split())
i = 1
flag = 0
while i<k:
p = list(str(a))
m = int(min(p))*int(max(p))
a = a+ m
if m ==0:
break
i += 1
print (a)
``` | instruction | 0 | 29,279 | 5 | 58,558 |
Yes | output | 1 | 29,279 | 5 | 58,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628
Submitted Solution:
```
from sys import stdin,stdout
import math
from collections import defaultdict
import heapq
import os
import sys
from io import BytesIO, IOBase
def main():
t=int(input())
for _ in range(t):
a1,k=list(map(int,input().split()))
arr=list(str(a1))
k-=1
while k>0:
mn=min(arr)
mx=max(arr)
val=int(mn)*int(mx)
if val==0:
break
arr=int(''.join(arr))+val
arr=list(str(arr))
k-=1
print(''.join(arr))
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")
if __name__=="__main__":
main()
``` | instruction | 0 | 29,280 | 5 | 58,560 |
Yes | output | 1 | 29,280 | 5 | 58,561 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628
Submitted Solution:
```
t=int(input())
for _ in range(t):
a,k=map(int,input().split())
for _ in range(k-1):
b=a
mi=10
ma=-1
while(b):
v=b%10
mi=min(v,mi)
ma=max(ma,v)
b=b//10
c=mi*ma
if(c>0):
a=a+c
else:
break
print(a)
``` | instruction | 0 | 29,281 | 5 | 58,562 |
Yes | output | 1 | 29,281 | 5 | 58,563 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628
Submitted Solution:
```
def min_digit(a):
return min(map(int, str(a)))
def max_digit(a):
return max(map(int, str(a)))
def rec(a, k):
r = a
for i in range(k - 1):
p = min_digit(r) * max_digit(r)
r = r + p
if p == 0:
break
return r
t = int(input())
for i in range(t):
a, k = map(int, input().split())
print(rec(a, k))
``` | instruction | 0 | 29,282 | 5 | 58,564 |
Yes | output | 1 | 29,282 | 5 | 58,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628
Submitted Solution:
```
a = list(map(int,input().split()))
def maxi(n):
largest = 0
while (n):
r = n % 10
# Find the largest digit
largest = max(r, largest)
n = n // 10
return largest
def mini(n):
smallest = 9
while (n):
r = n % 10
# Find the smallest digit
smallest = min(r, smallest)
n = n // 10
return smallest
if len(a)==2:
a1=a[0]
k=a[1]
ak=a[0]
if k==1:
print(a1)
else:
for i in range(1, k):
ak+=mini(ak)*maxi(ak)
print(ak)
``` | instruction | 0 | 29,283 | 5 | 58,566 |
No | output | 1 | 29,283 | 5 | 58,567 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628
Submitted Solution:
```
t= int(input())
pop = 1
for i in range (t):
a,k = map(int,input().split())
for l in range (k-1):
if pop != 0:
s = str(a)
x = []
for m in range (len(s)):
x.append (s[m])
x.sort()
pop = int(x[0])
popl = int(x[-1])
a += pop*popl
print(a)
``` | instruction | 0 | 29,284 | 5 | 58,568 |
No | output | 1 | 29,284 | 5 | 58,569 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628
Submitted Solution:
```
n=int(input())
for _ in range(0,n):
i=list(map(int,input().split()))
a1=i[0]
d={}
if i[0] not in d:
d[i[0]]=[]
c=0
while(c<i[1]-2):
if i[0] in d:
if len(d[i[0]])!= 0:
y1=len(d[i[0]])-1
y2=d[i[0]].pop()
d[i[0]].append(y2)
c=y1
a1=y2
a1=a1+int(max(str(a1)))*int(min(str(a1)))
d[i[0]].append(a1)
c=c+1
print(a1)
``` | instruction | 0 | 29,285 | 5 | 58,570 |
No | output | 1 | 29,285 | 5 | 58,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The first line contains one integer t (1 ≤ t ≤ 1000) — the number of independent test cases.
Each test case consists of a single line containing two integers a_{1} and K (1 ≤ a_{1} ≤ 10^{18}, 1 ≤ K ≤ 10^{16}) separated by a space.
Output
For each test case print one integer a_{K} on a separate line.
Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a_{1} = 487
a_{2} = a_{1} + minDigit(a_{1}) ⋅ maxDigit(a_{1}) = 487 + min (4, 8, 7) ⋅ max (4, 8, 7) = 487 + 4 ⋅ 8 = 519
a_{3} = a_{2} + minDigit(a_{2}) ⋅ maxDigit(a_{2}) = 519 + min (5, 1, 9) ⋅ max (5, 1, 9) = 519 + 1 ⋅ 9 = 528
a_{4} = a_{3} + minDigit(a_{3}) ⋅ maxDigit(a_{3}) = 528 + min (5, 2, 8) ⋅ max (5, 2, 8) = 528 + 2 ⋅ 8 = 544
a_{5} = a_{4} + minDigit(a_{4}) ⋅ maxDigit(a_{4}) = 544 + min (5, 4, 4) ⋅ max (5, 4, 4) = 544 + 4 ⋅ 5 = 564
a_{6} = a_{5} + minDigit(a_{5}) ⋅ maxDigit(a_{5}) = 564 + min (5, 6, 4) ⋅ max (5, 6, 4) = 564 + 4 ⋅ 6 = 588
a_{7} = a_{6} + minDigit(a_{6}) ⋅ maxDigit(a_{6}) = 588 + min (5, 8, 8) ⋅ max (5, 8, 8) = 588 + 5 ⋅ 8 = 628
Submitted Solution:
```
t = int(input())
for _ in range(t):
a, K = map(int, input().split())
for i in range(K - 1):
if '0' in str(a):
print(a)
break
s = list(map(int, list(str(a))))
a += min(s) * max(s)
if i == K - 2:
print(a)
``` | instruction | 0 | 29,286 | 5 | 58,572 |
No | output | 1 | 29,286 | 5 | 58,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.
The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.
Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?
Constraints
* All values in input are integers.
* 1 \leq L, A, B < 10^{18}
* 2 \leq M \leq 10^9
* All terms in the arithmetic progression are less than 10^{18}.
Input
Input is given from Standard Input in the following format:
L A B M
Output
Print the remainder when the integer obtained by concatenating the terms is divided by M.
Examples
Input
5 3 4 10007
Output
5563
Input
4 8 1 1000000
Output
891011
Input
107 10000000000007 1000000000000007 998244353
Output
39122908
Submitted Solution:
```
L,A,B,M=map(int,input().split())
MOD=M
#n*n行列の積を繰り返し二乗法で求める
#単位行列
def imat(n):
ret=[[1 if i==j else 0 for j in range(n)] for i in range(n)]
return ret
#行列の積A*B
def prod_mat(amat,bmat):
res_mat = [[sum([amat[i][j]*bmat[j][k] for j in range(len(bmat))]) for k in range(len(bmat[0]))] for i in range(len(amat))]
return res_mat
def powmod_mat(amat,p):
if p==0:
return imat(len(amat))
else:
pow2=powmod_mat(amat,p//2)
if p%2==0:
res_mat=prod_mat(pow2,pow2)
else:
res_mat=prod_mat(amat,prod_mat(pow2,pow2))
for i in range(len(amat)):
for j in range(len(amat)):
res_mat[i][j]%=MOD
return res_mat
slist=[]
for d in range(1,19):
s=-(-(10**d-A)//B)
if s>=0:
slist.append(min(s,L))
else:
slist.append(0)
#print(slist)
dlist=[slist[0]]
for d in range(1,18):
dlist.append(slist[d]-slist[d-1])
#print(dlist)
mat=imat(3)
for d in range(18):
e=dlist[d]
pmat=powmod_mat([[10**(d+1),1,0],[0,1,B],[0,0,1]],e)
mat=prod_mat(pmat,mat)
for i in range(3):
for j in range(3):
mat[i][j]%=MOD
#init
vec=[[0],[A],[1]]
vec=prod_mat(mat,vec)
print(vec[0][0]%MOD)
``` | instruction | 0 | 29,800 | 5 | 59,600 |
Yes | output | 1 | 29,800 | 5 | 59,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.
The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.
Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?
Constraints
* All values in input are integers.
* 1 \leq L, A, B < 10^{18}
* 2 \leq M \leq 10^9
* All terms in the arithmetic progression are less than 10^{18}.
Input
Input is given from Standard Input in the following format:
L A B M
Output
Print the remainder when the integer obtained by concatenating the terms is divided by M.
Examples
Input
5 3 4 10007
Output
5563
Input
4 8 1 1000000
Output
891011
Input
107 10000000000007 1000000000000007 998244353
Output
39122908
Submitted Solution:
```
def matrix_product(X,Y,M):
XY = [[0]*3 for _ in range(3)]
for i in range(3):
for j in range(3):
for k in range(3):
XY[i][j] += X[i][k]*Y[k][j] % M
XY[i][j] %= M
return XY
def power(X,n,M):
res = [[1,0,0],[0,1,0],[0,0,1]]
if n == 0: return res
while n > 0:
if n & 1: res = matrix_product(res,X,M)
X = matrix_product(X,X,M)
n //= 2
return res
L, A, B, M = map(int,input().split())
X = [0,A,1]
for d in range(1,19):
if L == 0: break
l = (10**(d-1) - A + B-1) // B
r = (10**d - A) // B
if (10**d - A) % B == 0: r -= 1
if l < 0: l = 0
if r < 0: r = -1
C = min(r-l+1,L)
L -= C
Y = power([[10**d,0,0],[1,1,0],[0,B,1]],C,M)
next_X = [0,0,0]
for i in range(3):
for j in range(3):
next_X[i] += X[j] * Y[j][i] % M
next_X[i] %= M
X = next_X
print(X[0])
``` | instruction | 0 | 29,801 | 5 | 59,602 |
Yes | output | 1 | 29,801 | 5 | 59,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.
The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.
Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?
Constraints
* All values in input are integers.
* 1 \leq L, A, B < 10^{18}
* 2 \leq M \leq 10^9
* All terms in the arithmetic progression are less than 10^{18}.
Input
Input is given from Standard Input in the following format:
L A B M
Output
Print the remainder when the integer obtained by concatenating the terms is divided by M.
Examples
Input
5 3 4 10007
Output
5563
Input
4 8 1 1000000
Output
891011
Input
107 10000000000007 1000000000000007 998244353
Output
39122908
Submitted Solution:
```
L, A, B, M = map(int, input().split())
S = [0]*L
for i in range(L):
S[i] = A + B * i
mapS = map(str, S)
joinS = ''.join(mapS)
ans = int(joinS)
print(ans % M)
``` | instruction | 0 | 29,804 | 5 | 59,608 |
No | output | 1 | 29,804 | 5 | 59,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.
The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.
Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?
Constraints
* All values in input are integers.
* 1 \leq L, A, B < 10^{18}
* 2 \leq M \leq 10^9
* All terms in the arithmetic progression are less than 10^{18}.
Input
Input is given from Standard Input in the following format:
L A B M
Output
Print the remainder when the integer obtained by concatenating the terms is divided by M.
Examples
Input
5 3 4 10007
Output
5563
Input
4 8 1 1000000
Output
891011
Input
107 10000000000007 1000000000000007 998244353
Output
39122908
Submitted Solution:
```
l,a,b,m = map(int,input().split())
tlist = []
for i in range(l):
tlist.append(a+b*i)
str_tlist = [str(i) for i in tlist ]
conbined = "".join(str_tlist)
conbined = int(conbined)
print(conbined%m)
``` | instruction | 0 | 29,805 | 5 | 59,610 |
No | output | 1 | 29,805 | 5 | 59,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}.
The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds.
Consider the integer obtained by concatenating the terms written in base ten without leading zeros. For example, the sequence 3, 7, 11, 15, 19 would be concatenated into 37111519. What is the remainder when that integer is divided by M?
Constraints
* All values in input are integers.
* 1 \leq L, A, B < 10^{18}
* 2 \leq M \leq 10^9
* All terms in the arithmetic progression are less than 10^{18}.
Input
Input is given from Standard Input in the following format:
L A B M
Output
Print the remainder when the integer obtained by concatenating the terms is divided by M.
Examples
Input
5 3 4 10007
Output
5563
Input
4 8 1 1000000
Output
891011
Input
107 10000000000007 1000000000000007 998244353
Output
39122908
Submitted Solution:
```
import math
L, A, B, M = map(int, input().split())
ans = 0
keta = 0
ketasu = 0
for i in range(L):
ans += ((A+B*(L-i-1))*pow(10, keta))%M
ketasu = math.log10(A+B*(L-i-1))
if ketasu == int(ketasu):
keta += ketasu + 1
else:
keta += math.ceil(ketasu)
print(int(ans%M))
``` | instruction | 0 | 29,806 | 5 | 59,612 |
No | output | 1 | 29,806 | 5 | 59,613 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1 | instruction | 0 | 29,867 | 5 | 59,734 |
"Correct Solution:
```
def factorial(n):
if n == 1 or n == 0:
return int(1)
return int(n*factorial(n-1))
def nck(n,k):
return int(factorial(n)/(factorial(n-k)*factorial(k)))
ans = 0
ans2 = 0
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
for i in range(A,B+1):
ans = max(ans,sum(v[N-i:N])/i)
print("{:.7f}".format(ans))
for i in range(A,B+1):
if ans == sum(v[N-i:N])/i:
n = v.count(v[N-i])
k = i - len([p for p in v if p > v[N-i]])
ans2 += nck(n,k)
print(int(ans2))
``` | output | 1 | 29,867 | 5 | 59,735 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1 | instruction | 0 | 29,868 | 5 | 59,736 |
"Correct Solution:
```
nCr = {}
def cmb(n, r):
if r == 0 or r == n: return 1
if r == 1: return n
if (n,r) in nCr: return nCr[(n,r)]
nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
return nCr[(n,r)]
N,A,B = map(int,input().split())
v = sorted(list(map(int,input().split())),reverse=True)
if len(set(v)) == 1:
print(1)
print(1125899906842623)
exit()
m = sum(v[:A])/A
print(m)
if len(set(v[:A]))==1:
ans = 0
c = v.count(v[0])
for i in range(A,B+1):
if i <= c:
ans += cmb(c,i)
print(ans)
exit()
mi = min(v[:A])
n = v[:A].count(mi)
m = v.count(mi)
print(cmb(m,n))
``` | output | 1 | 29,868 | 5 | 59,737 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1 | instruction | 0 | 29,869 | 5 | 59,738 |
"Correct Solution:
```
def conb(a,b):
now=1
for i in range(b):
now=int(now*(a-i)/(i+1))
return now
N,A,B=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
line=V[A-1]
if V[0]==line:
ans=0
for i in range(A,min(V.count(V[0]),B)+1):
ans+=conb(V.count(V[0]),i)
print(V[0])
print(ans)
elif line>V[A]:
print(sum(V[:A])/A)
print(1)
else:
idx=V.index(line)
cnt=V.count(line)
print((sum(V[:idx])+line*(A-idx))/A)
print(conb(cnt,A-idx))
``` | output | 1 | 29,869 | 5 | 59,739 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1 | instruction | 0 | 29,870 | 5 | 59,740 |
"Correct Solution:
```
# ABC 057 D
import math
N, A, B = map(int,input().split())
v = sorted(list(map(int,input().split())))[::-1]
def nCr(n,r):
return (math.factorial(n)//(math.factorial(r)*math.factorial(n-r)))
a = sum(v[:A])/A
print(a)
s = 0
for k in range(N):
if v[A-1] == v[k]:
s += 1
t = 0
for k in range(A):
if v[A-1] == v[k]:
t += 1
u = 0
for k in range(A-1,B):
if v[A-1] == v[k]:
u += 1
if a != v[A-1]:
print(nCr(s,t))
else:
c = 0
for k in range(A,A+u):
c += nCr(s,k)
print(c)
``` | output | 1 | 29,870 | 5 | 59,741 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1 | instruction | 0 | 29,871 | 5 | 59,742 |
"Correct Solution:
```
from functools import reduce
from operator import mul
def cmb(n, r):
r = min(n - r, r)
if r == 0:
return 1
return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(r, 0, -1))
n,a,b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)
if v[0] == v[a-1]:
print(v[0])
c = v.count(v[a-1])
ans = 0
for i in range(a,min(c+1,b+1)):
ans += cmb(c,i)
print(ans)
else:
print(sum(v[:a]) / a)
c = v.count(v[a-1])
d = 0
for key,value in enumerate(v):
if value == v[a-1]:
d = key
break
print(cmb(c,a-d))
``` | output | 1 | 29,871 | 5 | 59,743 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1 | instruction | 0 | 29,872 | 5 | 59,744 |
"Correct Solution:
```
from statistics import mean
from collections import Counter
n,a,b=map(int,input().split())
v=sorted(list(map(int,input().split())),reverse=True)
avg=mean(v[:a])
print(avg)
p=Counter(v[:a])[v[a-1]]
q=Counter(v)[v[a-1]]
def n_func(n):
ans=1
for i in range(1,n+1):ans=(ans*i)
return ans
def nCr(n,r):
return (n_func(n)//n_func(r))//n_func(n-r)
if v[0]==v[a-1]:
print(sum([nCr(q,a+i) for i in range(0,min(b,q)-a+1)]))
else:
print(nCr(q,p))
``` | output | 1 | 29,872 | 5 | 59,745 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1 | instruction | 0 | 29,873 | 5 | 59,746 |
"Correct Solution:
```
import math
n,a,b =map(int,input().split())
v = list(map(int,input().split()))
v = sorted(v,key=lambda x:-x)
need = v[:a]
ti = min(need)
no = need.count(ti)
try:
ona = v[a:].count(ti)
except:
ona = 0
if ona == 0:
print(sum(need)/a)
print(1)
elif no == a:
ans = 0
for i in range(b+1-a):
if ona == -1:
break
ans += math.factorial(ona+no)/math.factorial(ona)/math.factorial(no)
ona -= 1
no += 1
print(sum(need)/a)
print(int(ans))
else:
print(sum(need)/a)
print(int(math.factorial(ona+no)/math.factorial(ona)/math.factorial(no)))
``` | output | 1 | 29,873 | 5 | 59,747 |
Provide a correct Python 3 solution for this coding contest problem.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1 | instruction | 0 | 29,874 | 5 | 59,748 |
"Correct Solution:
```
import math
from collections import Counter
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse = True)
cnt_v = Counter(v)
ave = []
for i in range(A, B+1):
ave.append(sum(v[0:i]) / i)
max_ave = max(ave)
ans = 0
for j in range(B-A+1):
temp = 1
if ave[j] == max_ave:
l = v[:A+j]
cnt_l = Counter(l)
for key, values in cnt_l.items():
temp *= (math.factorial(cnt_v[key]) // math.factorial(values) // math.factorial(cnt_v[key] - values))
ans += temp
print(max_ave)
print(ans)
``` | output | 1 | 29,874 | 5 | 59,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1
Submitted Solution:
```
n,a,b=map(int,input().split())
v=[int(i) for i in input().split()]
v.sort(reverse=True)
m=v[a-1]
mm=v.count(m)
cnt=0
for i in range(n):
if v[i]>m:
cnt+=1
else:
break
def fact(n):
if n==0 or n==-1:
return 1
return fact(n-1)*n
def comb(n,k):
return fact(n)//fact(n-k)//fact(k)
ans=0
#print('mm,cnt',mm,cnt)
for i in range(min(mm+cnt-a,b-a+cnt)+1):
ans+=comb(mm,a-cnt+i)
#print(i,ans)
if m!=v[0]:
ans=comb(mm,a-cnt)
print(sum(v[0:a])/a)
print(ans)
``` | instruction | 0 | 29,875 | 5 | 59,750 |
Yes | output | 1 | 29,875 | 5 | 59,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1
Submitted Solution:
```
def comb(left, right):
top = 1
for i in range(left, left - right, -1):
top *= i
bottom = 1
for i in range(1, right + 1):
bottom *= i
return top // bottom
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
v.sort()
min_set = v[-a:]
print(sum(min_set) / len(min_set))
if len(set(min_set)) == 1:
cnt = v.count(min_set[0])
result = 0
for i in range(a, min(cnt, b) + 1):
result += comb(cnt, i)
print(result)
else:
print(comb(v.count(min_set[0]), min_set.count(min_set[0])))
``` | instruction | 0 | 29,876 | 5 | 59,752 |
Yes | output | 1 | 29,876 | 5 | 59,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1
Submitted Solution:
```
N, A, B = map(int, input().split())
items = sorted(list(map(int, input().split())), reverse=True)
ans_lis = items[:A]
ans1 = sum(ans_lis)/A
print(ans1)
i = A
ans2 = 0
while i <= B:
if sum(items[:i])/i != ans1:
break
min_ = min(items[:i])
min_in_ans = items[:i].count(min_)
min_in_all = items.count(min_)
nCr = {}
def cmb(n, r):
if r == 0 or r == n: return 1
if r == 1: return n
if (n,r) in nCr: return nCr[(n,r)]
nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
return nCr[(n,r)]
ans2 += cmb(min_in_all, min_in_ans)
i += 1
print(ans2)
``` | instruction | 0 | 29,877 | 5 | 59,754 |
Yes | output | 1 | 29,877 | 5 | 59,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1
Submitted Solution:
```
N, A, B = map(int, input().split())
v = sorted(list(map(int, input().split())), reverse=True)
print(sum(v[:A]) / A)
x = v.count(v[A - 1])
y = v[:A].count(v[A - 1])
if v[0] != v[A - 1]:
u = 1
d = 1
for i in range(x, x - y, -1):
u *= i
for i in range(y, 0, -1):
d *= i
print(u // d)
else:
ans = 0
for i in range(A, min(B, x) + 1):
u = 1
d = 1
for j in range(x, x - i, -1):
u *= j
for j in range(i, 0, -1):
d *= j
ans += u // d
print(ans)
``` | instruction | 0 | 29,878 | 5 | 59,756 |
Yes | output | 1 | 29,878 | 5 | 59,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1
Submitted Solution:
```
import collections
from scipy.misc import comb
n,a,b = map(int, input().split(' '))
v = map(int, input().split(' '))
v = sorted(v, reverse=True)
select = v[:a]
result1 = sum(select)/len(select)
result2 = 0
v_cnt = collections.Counter(v)
for i in range(a,b+1):
select = v[:i]
if result1 == sum(select)/len(select):
select = collections.Counter(select)
buf = 1
for v_ in v_cnt:
buf *= comb(v_cnt[v_],select[v_])
result2 += buf
print(result1)
print(int(result2))
``` | instruction | 0 | 29,879 | 5 | 59,758 |
No | output | 1 | 29,879 | 5 | 59,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1
Submitted Solution:
```
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
# dp[i] := i個選ぶときの価値の最大値
# dq[i] := i個選ぶときの価値の最大値の個数
dp = [0] * (n + 1)
dq = [0] * (n + 1)
dq[0] = 1
for i in range(n):
val = v[i]
# i番目を選ぶとき
for j in range(n)[::-1]:
if dp[j + 1] == dp[j] + val:
dq[j + 1] += dq[j]
if dp[j + 1] < dp[j] + val:
dp[j + 1] = dp[j] + val
dq[j + 1] = 1
else:
continue
max_ans = 0
max_cnt = 10 ** 30
for i in range(a, b + 1):
if max_cnt * dp[i] > max_ans * i:
max_ans = dp[i]
max_cnt = i
ans = 0
for i in range(a, b + 1):
if max_cnt * dp[i] == max_ans * i:
ans += dq[i]
print(max_ans / max_cnt)
print(ans)
``` | instruction | 0 | 29,880 | 5 | 59,760 |
No | output | 1 | 29,880 | 5 | 59,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1
Submitted Solution:
```
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
# mod = 10**9+7
mod = 170141183460469231731687303715884105727
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split()) # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
def extgcd(a,b):
r = [1,0,a]
w = [0,1,b]
while w[2]!=1:
q = r[2]//w[2]
r2 = w
w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
r = r2
w = w2
return [w[0],w[1]]
def mod_inv(a,m):
x = extgcd(a,m)[0]
return x
def nCk(n,k):
res = 1
a=n-k
b=k
for i in range(1,a+b+1):
res = res*i%mod
for i in range(1,a+1):
res = res*mod_inv(i,mod)%mod
for i in range(1,b+1):
res = res*mod_inv(i,mod)%mod
return res
def main():
n,a,b = inpm()
v = inpl()
v.sort(reverse=True)
sumation = 0
for i in range(a):
sumation += v[i]
print(sumation/a)
if v[a-1] != v[a]:
print(1)
return
cnt = 1
left = 0
right = n-1
for i in range(a-1,n-1):
if v[i] == v[i+1]:
cnt += 1
else:
right = i
break
for i in range(a-1,0,-1):
if v[i] == v[i-1]:
cnt += 1
else:
left = i
break
number = right - left + 1
ans = 0
if v[0] == v[a-1]:
for e in range(a,min(b+1,number+1)):
ans += nCk(number,e)
print(ans)
else:
print(nCk(number,a-left+1))
if __name__ == "__main__":
main()
``` | instruction | 0 | 29,881 | 5 | 59,762 |
No | output | 1 | 29,881 | 5 | 59,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given N items.
The value of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values of selected items.
Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.
Constraints
* 1 \leq N \leq 50
* 1 \leq A,B \leq N
* 1 \leq v_i \leq 10^{15}
* Each v_i is an integer.
Input
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
Output
Print two lines.
The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.
Examples
Input
5 2 2
1 2 3 4 5
Output
4.500000
1
Input
4 2 3
10 20 10 10
Output
15.000000
3
Input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
Output
1000000000000000.000000
1
Submitted Solution:
```
t = 3099044504245996706400 # LCM(1..50)
N, A, B = map(int, input().split())
V = sorted([int(a) * t for a in input().split()])[::-1]
l, r = 0, 1<<200
while r - l > 1:
m = (l+r) // 2
VV = [v-m for v in V]
for i in range(1, len(VV)):
VV[i] += VV[i-1]
if max(VV[A-1:B]) >= 0:
l = m
else:
r = m
print(l/t)
print(V.count(V[B-1]) if V[B-1] > l else V.count(V[A-1]) if V[A-1] < l else 1 << V.count(l))
``` | instruction | 0 | 29,882 | 5 | 59,764 |
No | output | 1 | 29,882 | 5 | 59,765 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8 | instruction | 0 | 30,019 | 5 | 60,038 |
"Correct Solution:
```
from collections import Counter
n = int(input())
a = input().split()
# a = list(map(int, input().split()))
ans = ''
# t1, t2 = [], []
t1, t2 = Counter(), Counter()
for i in range(n):
t1.update(a[i])
t2.update(a[n-1-i])
t3 = t1 & t2
t1 -= t3
t2 -= t3
if t1 == t2:
ans += str(i+1) + ' '
print(ans[:-1])
``` | output | 1 | 30,019 | 5 | 60,039 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8 | instruction | 0 | 30,020 | 5 | 60,040 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from bisect import bisect_left, insort
N = int(input())
src = list(map(int,input().split()))
ans = []
A, B = [], []
for i in range(N):
a, b = src[i], src[-i-1]
addA = False
addB = False
if a != b:
j = bisect_left(B, a)
if j != len(B) and B[j] == a:
del B[j]
else:
addA = True
j = bisect_left(A, b)
if j != len(A) and A[j] == b:
del A[j]
else:
insort(B, b)
if addA:
insort(A, a)
if len(A) == len(B) == 0:
ans.append(i+1)
print(*ans)
``` | output | 1 | 30,020 | 5 | 60,041 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8 | instruction | 0 | 30,021 | 5 | 60,042 |
"Correct Solution:
```
import sys,queue,math,copy,itertools,bisect
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
A = LI()
A_sort = sorted(A)
A_num = [bisect.bisect_left(A_sort,a) for a in A]
ans = []
A_cnt = [0 for _ in range(N)]
cnt = 0
for i in range(N):
bf1 = A_cnt[A_num[i]]
bf2 = A_cnt[A_num[N-i-1]]
A_cnt[A_num[i]] += 1
A_cnt[A_num[N-i-1]] -= 1
cnt += (abs(A_cnt[A_num[i]]) - abs(bf1))
cnt += (abs(A_cnt[A_num[N-i-1]]) - abs(bf2))
if cnt == 0:
ans.append(i+1)
print (*ans)
``` | output | 1 | 30,021 | 5 | 60,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8
Submitted Solution:
```
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr1 = Counter()
ctr2 = Counter()
ans = []
for i in range(N):
ctr1.update([src[i]])
ctr2.update([src[-i-1]])
if ctr1 == ctr2:
ans.append(i+1)
print(*sorted(ans))
``` | instruction | 0 | 30,022 | 5 | 60,044 |
No | output | 1 | 30,022 | 5 | 60,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8
Submitted Solution:
```
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr1 = Counter()
ctr2 = Counter()
ans = []
for i in range(N):
ctr1[src[i]] += 1
ctr2[src[-i-1]] += 1
for k, v in ctr1.items():
if ctr2[k] != v:
break
else:
ans.append(i+1)
print(*ans)
``` | instruction | 0 | 30,023 | 5 | 60,046 |
No | output | 1 | 30,023 | 5 | 60,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8
Submitted Solution:
```
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr1 = Counter()
ctr2 = Counter()
ans = []
for i in range(N):
ctr1.update([src[i]])
ctr2.update([src[-i-1]])
if ctr1 == ctr2:
ans.append(i+1)
ctr1 = Counter()
ctr2 = Counter()
print(*sorted(ans))
``` | instruction | 0 | 30,024 | 5 | 60,048 |
No | output | 1 | 30,024 | 5 | 60,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8
Submitted Solution:
```
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr1 = Counter()
ctr2 = Counter()
ans = []
for i in range(N):
ctr1.update([src[i]])
ctr2.update([src[-i-1]])
if ctr1 == ctr2:
ans.append(i+1)
ctr1 = Counter()
ctr2 = Counter()
print(*ans)
``` | instruction | 0 | 30,025 | 5 | 60,050 |
No | output | 1 | 30,025 | 5 | 60,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem
Given two sequences of length $ N $, $ A $ and $ B $. First, the $ i $ item in the sequence $ A $ is $ a_i $, and the $ i $ item in the sequence $ B $ is $ b_i $.
Since a total of $ Q $ of statements of the following format are given, create a program that processes in the given order.
Each statement is represented by three integers $ x, y, z $.
* Set the value of the $ y $ item in the sequence $ A $ to $ z $. (When $ x = 1 $)
* Set the value of the $ y $ item in the sequence $ B $ to $ z $. (When $ x = 2 $)
* Find and report the smallest value in the $ z $ item from the $ y $ item in the sequence $ A $. (When $ x = 3 $)
* Find and report the smallest value in the $ z $ item from the $ y $ item in the sequence $ B $. (When $ x = 4 $)
* Change the sequence $ A $ to be exactly the same as the sequence $ B $. (When $ x = 5 $)
* Change the sequence $ B $ to be exactly the same as the sequence $ A $. (When $ x = 6 $)
Constraints
The input satisfies the following conditions.
* $ 2 \ le N \ le 2 \ times 10 ^ 5 $
* $ 2 \ le Q \ le 2 \ times 10 ^ 5 $
* $ 1 \ le a_i \ le 10 ^ 9 $
* $ 1 \ le b_i \ le 10 ^ 9 $
* $ 1 \ le x_i \ le 6 $
* $ 1 \ le y_i \ le N $ (when $ 1 \ le x_i \ le 4 $)
* $ y_i = -1 $ (when $ x_i = 5, 6 $)
* $ 1 \ le z_i \ le 10 ^ 9 $ (when $ x_i = 1, 2 $)
* $ y_i \ le z_i \ le N $ (when $ x_i = 3, 4 $)
* $ z_i = -1 $ (when $ x_i = 5, 6 $)
* All inputs are integers
Input
The input is given in the following format.
$ N $
$ a_ {1} $ $ a_ {2} $ ... $ a_ {N} $
$ b_ {1} $ $ b_ {2} $ ... $ b_ {N} $
$ Q $
$ x_1 $ $ y_1 $ $ z_1 $
$ x_2 $ $ y_2 $ $ z_2 $
...
$ x_Q $ $ y_Q $ $ z_Q $
Output
Every time a statement of $ x = 3 $ or $ x = 4 $ is given by input, the found value is output on one line.
Example
Input
5
1 3 5 7 9
6 2 3 2 6
10
1 3 4
3 4 5
4 2 3
5 -1 -1
2 3 8
3 2 5
4 3 3
1 1 1
6 -1 -1
3 1 5
Output
7
2
2
8
1
Submitted Solution:
```
N = int(input())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
Q = int(input())
for _ in range(Q):
x, y, z = map(int, input().split())
if x == 1:
a[y] = z
elif x == 2:
b[y] = z
elif x == 3:
print(min(a[y:z+1]))
elif x == 4:
print(min(b[y:z+1]))
elif x == 5:
a = b[:]
else:
b = a[:]
``` | instruction | 0 | 30,026 | 5 | 60,052 |
No | output | 1 | 30,026 | 5 | 60,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Problem
Given two sequences of length $ N $, $ A $ and $ B $. First, the $ i $ item in the sequence $ A $ is $ a_i $, and the $ i $ item in the sequence $ B $ is $ b_i $.
Since a total of $ Q $ of statements of the following format are given, create a program that processes in the given order.
Each statement is represented by three integers $ x, y, z $.
* Set the value of the $ y $ item in the sequence $ A $ to $ z $. (When $ x = 1 $)
* Set the value of the $ y $ item in the sequence $ B $ to $ z $. (When $ x = 2 $)
* Find and report the smallest value in the $ z $ item from the $ y $ item in the sequence $ A $. (When $ x = 3 $)
* Find and report the smallest value in the $ z $ item from the $ y $ item in the sequence $ B $. (When $ x = 4 $)
* Change the sequence $ A $ to be exactly the same as the sequence $ B $. (When $ x = 5 $)
* Change the sequence $ B $ to be exactly the same as the sequence $ A $. (When $ x = 6 $)
Constraints
The input satisfies the following conditions.
* $ 2 \ le N \ le 2 \ times 10 ^ 5 $
* $ 2 \ le Q \ le 2 \ times 10 ^ 5 $
* $ 1 \ le a_i \ le 10 ^ 9 $
* $ 1 \ le b_i \ le 10 ^ 9 $
* $ 1 \ le x_i \ le 6 $
* $ 1 \ le y_i \ le N $ (when $ 1 \ le x_i \ le 4 $)
* $ y_i = -1 $ (when $ x_i = 5, 6 $)
* $ 1 \ le z_i \ le 10 ^ 9 $ (when $ x_i = 1, 2 $)
* $ y_i \ le z_i \ le N $ (when $ x_i = 3, 4 $)
* $ z_i = -1 $ (when $ x_i = 5, 6 $)
* All inputs are integers
Input
The input is given in the following format.
$ N $
$ a_ {1} $ $ a_ {2} $ ... $ a_ {N} $
$ b_ {1} $ $ b_ {2} $ ... $ b_ {N} $
$ Q $
$ x_1 $ $ y_1 $ $ z_1 $
$ x_2 $ $ y_2 $ $ z_2 $
...
$ x_Q $ $ y_Q $ $ z_Q $
Output
Every time a statement of $ x = 3 $ or $ x = 4 $ is given by input, the found value is output on one line.
Example
Input
5
1 3 5 7 9
6 2 3 2 6
10
1 3 4
3 4 5
4 2 3
5 -1 -1
2 3 8
3 2 5
4 3 3
1 1 1
6 -1 -1
3 1 5
Output
7
2
2
8
1
Submitted Solution:
```
import copy
input()
a = list(map(int,input().split()))
b = list(map(int,input().split()))
q = int(input())
for _ in range(q):
[x,y,z] = map(int,input().split())
if x == 1:
a[y-1] = z
elif x == 2:
b[y-1] = z
elif x == 3:
print(min(a[y-1:z]))
elif x == 4:
print(min(b[y-1:z]))
elif x == 5:
a = copy.deepcopy(b)
elif x == 6:
b = copy.deepcopy(a)
``` | instruction | 0 | 30,027 | 5 | 60,054 |
No | output | 1 | 30,027 | 5 | 60,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two polynomials:
* P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
* Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit <image>.
Input
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
Output
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit <image>, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.
Examples
Input
2 1
1 1 1
2 5
Output
Infinity
Input
1 0
-1 3
2
Output
-Infinity
Input
0 1
1
1 0
Output
0/1
Input
2 2
2 1 6
4 5 -7
Output
1/2
Input
1 1
9 0
-5 2
Output
-9/5
Note
Let's consider all samples:
1. <image>
2. <image>
3. <image>
4. <image>
5. <image>
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
if n < m:
print('0/1')
elif n > m:
print(('-' if b[0] * a[0] < 0 else '') + 'Infinity')
else:
f = a[0] * b[0]
gd = gcd(abs(a[0]), abs(b[0]))
a[0] = abs(a[0]) // gd
b[0] = abs(b[0]) // gd
print(('-' if f < 0 else '') + str(a[0]) + '/' + str(b[0]))
``` | instruction | 0 | 30,361 | 5 | 60,722 |
Yes | output | 1 | 30,361 | 5 | 60,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two polynomials:
* P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and
* Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.
Calculate limit <image>.
Input
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly.
The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0).
The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
Output
If the limit equals + ∞, print "Infinity" (without quotes). If the limit equals - ∞, print "-Infinity" (without the quotes).
If the value of the limit equals zero, print "0/1" (without the quotes).
Otherwise, print an irreducible fraction — the value of limit <image>, in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.
Examples
Input
2 1
1 1 1
2 5
Output
Infinity
Input
1 0
-1 3
2
Output
-Infinity
Input
0 1
1
1 0
Output
0/1
Input
2 2
2 1 6
4 5 -7
Output
1/2
Input
1 1
9 0
-5 2
Output
-9/5
Note
Let's consider all samples:
1. <image>
2. <image>
3. <image>
4. <image>
5. <image>
You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
Submitted Solution:
```
n,m = map(int, input().split())
l = list(map(int, input().split()))
r = list(map(int, input().split()))
if n == m:
for i in range(2, min(abs(l[0]), abs(r[0]))+1):
while l[0]%i == 0 and r[0]%i == 0:
l[0]/=i
r[0]/=i
if r[0]>0:
print(str(int(l[0]))+'/'+str(int(r[0])))
elif r[0]<0 and l[0]>0:
print('-'+str(int(l[0]))+'/'+str(int(r[0]))[1:])
elif l[0]<0 and r[0]<0:
print(str(int(l[0]))[1:]+'/'+str(int(r[0]))[1:])
elif n>m:
if l[0]<0 and r[0]>0 or l[0]>0 and r[0]<0:
print('-Infinity')
else:
print("Infinity")
else:
print('0/1')
``` | instruction | 0 | 30,362 | 5 | 60,724 |
Yes | output | 1 | 30,362 | 5 | 60,725 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.