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.
At first, let's define function f(x) as follows: $$$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} x/2 & \mbox{if } x is even \\\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$$
We can see that if we choose some value v and will apply function f to it, then apply f to f(v), and so on, we'll eventually get 1. Let's write down all values we get in this process in a list and denote this list as path(v). For example, path(1) = [1], path(15) = [15, 14, 7, 6, 3, 2, 1], path(32) = [32, 16, 8, 4, 2, 1].
Let's write all lists path(x) for every x from 1 to n. The question is next: what is the maximum value y such that y is contained in at least k different lists path(x)?
Formally speaking, you need to find maximum y such that \left| \{ x ~|~ 1 ≤ x ≤ n, y ∈ path(x) \} \right| ≥ k.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^{18}).
Output
Print the only integer — the maximum value that is contained in at least k paths.
Examples
Input
11 3
Output
5
Input
11 6
Output
4
Input
20 20
Output
1
Input
14 5
Output
6
Input
1000000 100
Output
31248
Note
In the first example, the answer is 5, since 5 occurs in path(5), path(10) and path(11).
In the second example, the answer is 4, since 4 occurs in path(4), path(5), path(8), path(9), path(10) and path(11).
In the third example n = k, so the answer is 1, since 1 is the only number occuring in all paths for integers from 1 to 20.
Submitted Solution:
```
import sys
# inf = open('input.txt', 'r')
# reader = (map(int, line.split()) for line in inf)
reader = (map(int, line.split()) for line in sys.stdin)
def count(num):
ans = 0
if num % 2:
add = 1
else:
add = 2
while num + add - 1 <= n:
ans += add
add *= 2
num *= 2
if num <= n:
ans += n - num + 1
return ans
def func(n, k):
if k == n:
return 1
# odd
L = 0
R = n // 2 + n % 2
while L + 1 < R:
m = (L + R) // 2
num = 2 * m + 1
# print(num, count(num))
if count(num) >= k:
L = m
else:
R = m
m_odd = 2 * L + 1
# even
L = 1
R = n // 2 + 1
while L + 1 < R:
m = (L + R) // 2
num = 2 * m
# print(num, count(num))
if count(num) >= k:
L = m
else:
R = m
m_even = 2 * L
return max(m_odd, m_even)
n, k = next(reader)
ans = func(n, k)
print(ans)
# inf.close()
``` | instruction | 0 | 50,614 | 5 | 101,228 |
Yes | output | 1 | 50,614 | 5 | 101,229 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At first, let's define function f(x) as follows: $$$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} x/2 & \mbox{if } x is even \\\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$$
We can see that if we choose some value v and will apply function f to it, then apply f to f(v), and so on, we'll eventually get 1. Let's write down all values we get in this process in a list and denote this list as path(v). For example, path(1) = [1], path(15) = [15, 14, 7, 6, 3, 2, 1], path(32) = [32, 16, 8, 4, 2, 1].
Let's write all lists path(x) for every x from 1 to n. The question is next: what is the maximum value y such that y is contained in at least k different lists path(x)?
Formally speaking, you need to find maximum y such that \left| \{ x ~|~ 1 ≤ x ≤ n, y ∈ path(x) \} \right| ≥ k.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^{18}).
Output
Print the only integer — the maximum value that is contained in at least k paths.
Examples
Input
11 3
Output
5
Input
11 6
Output
4
Input
20 20
Output
1
Input
14 5
Output
6
Input
1000000 100
Output
31248
Note
In the first example, the answer is 5, since 5 occurs in path(5), path(10) and path(11).
In the second example, the answer is 4, since 4 occurs in path(4), path(5), path(8), path(9), path(10) and path(11).
In the third example n = k, so the answer is 1, since 1 is the only number occuring in all paths for integers from 1 to 20.
Submitted Solution:
```
"""
Satwik_Tiwari ;) .
5th AUGUST , 2020 - WEDNESDAY
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned
#==============================================================================================
#fast I/O region
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n") #as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def printlist(a) :
for p in range(0,len(a)):
out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
ans = 1
while(b>0):
if(b%2==1):
ans*=a
a*=a
b//=2
return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
#===============================================================================================
# code here ;))
def solve():
n,k = sep()
l = 1
h = n
if(k==1):
print(n)
return
ans = 0
while(h>=l):
i = (l+h)//2
i*=2
cnt = 0
if(i%2==1):
curr = [i,i]
cnt = 1
else:
curr = [i,i+1]
cnt = 2
while(2*curr[1]+1<n):
curr = [curr[0]*2,curr[1]*2+1]
cnt += curr[1]-curr[0]+1
# print(cnt[i],curr,i)
if(curr[0]*2 < n):
cnt+=n-(curr[0]*2)+1
# print(cnt[i],i)
if(cnt>=k):
l = (i+1)//2+1
ans = i
else:
h = (i+1)//2-1
# print(l,h,i,cnt)
l = 1
h = n
ans1 = 0
while(h>=l):
i = (l+h)//2
i*=2
i-=1
cnt = 0
if(i%2==1):
curr = [i,i]
cnt = 1
else:
curr = [i,i+1]
cnt = 2
while(2*curr[1]+1<n):
curr = [curr[0]*2,curr[1]*2+1]
cnt += curr[1]-curr[0]+1
# print(cnt[i],curr,i)
if(curr[0]*2 < n):
cnt+=n-(curr[0]*2)+1
# print(cnt[i],i)
if(cnt>=k):
l = (i+1)//2+1
ans1 = i
else:
h = (i+1)//2-1
# print(l,h,i,cnt)
print(max(ans,ans1))
testcase(1)
# testcase(int(inp()))
``` | instruction | 0 | 50,615 | 5 | 101,230 |
No | output | 1 | 50,615 | 5 | 101,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At first, let's define function f(x) as follows: $$$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} x/2 & \mbox{if } x is even \\\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$$
We can see that if we choose some value v and will apply function f to it, then apply f to f(v), and so on, we'll eventually get 1. Let's write down all values we get in this process in a list and denote this list as path(v). For example, path(1) = [1], path(15) = [15, 14, 7, 6, 3, 2, 1], path(32) = [32, 16, 8, 4, 2, 1].
Let's write all lists path(x) for every x from 1 to n. The question is next: what is the maximum value y such that y is contained in at least k different lists path(x)?
Formally speaking, you need to find maximum y such that \left| \{ x ~|~ 1 ≤ x ≤ n, y ∈ path(x) \} \right| ≥ k.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^{18}).
Output
Print the only integer — the maximum value that is contained in at least k paths.
Examples
Input
11 3
Output
5
Input
11 6
Output
4
Input
20 20
Output
1
Input
14 5
Output
6
Input
1000000 100
Output
31248
Note
In the first example, the answer is 5, since 5 occurs in path(5), path(10) and path(11).
In the second example, the answer is 4, since 4 occurs in path(4), path(5), path(8), path(9), path(10) and path(11).
In the third example n = k, so the answer is 1, since 1 is the only number occuring in all paths for integers from 1 to 20.
Submitted Solution:
```
from math import log,ceil
n,k=map(int,input().split())
p=ceil(log(k+2,2))-1
m=(2**(p+1)-2-k)
ans=((n+m-(2**p-1))//(2**p))*2
if k==3 and n%2==1:
ans=n//2
print(max(ans,1))
``` | instruction | 0 | 50,616 | 5 | 101,232 |
No | output | 1 | 50,616 | 5 | 101,233 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At first, let's define function f(x) as follows: $$$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} x/2 & \mbox{if } x is even \\\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$$
We can see that if we choose some value v and will apply function f to it, then apply f to f(v), and so on, we'll eventually get 1. Let's write down all values we get in this process in a list and denote this list as path(v). For example, path(1) = [1], path(15) = [15, 14, 7, 6, 3, 2, 1], path(32) = [32, 16, 8, 4, 2, 1].
Let's write all lists path(x) for every x from 1 to n. The question is next: what is the maximum value y such that y is contained in at least k different lists path(x)?
Formally speaking, you need to find maximum y such that \left| \{ x ~|~ 1 ≤ x ≤ n, y ∈ path(x) \} \right| ≥ k.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^{18}).
Output
Print the only integer — the maximum value that is contained in at least k paths.
Examples
Input
11 3
Output
5
Input
11 6
Output
4
Input
20 20
Output
1
Input
14 5
Output
6
Input
1000000 100
Output
31248
Note
In the first example, the answer is 5, since 5 occurs in path(5), path(10) and path(11).
In the second example, the answer is 4, since 4 occurs in path(4), path(5), path(8), path(9), path(10) and path(11).
In the third example n = k, so the answer is 1, since 1 is the only number occuring in all paths for integers from 1 to 20.
Submitted Solution:
```
def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from collections import defaultdict as dd
def count(v):
if v > n:
return 0
ans = 1
if v % 2 == 0:
ans += count(2 * v)
ans += count(v + 1)
else:
ans += count(2 * v)
return ans
n, k = I()
ok = 1
for i in range(70):
if count(2**i) >= k:
ok = 2**i
if ok + 1 <= n:
print(ok + 1)
else:
print(ok)
``` | instruction | 0 | 50,617 | 5 | 101,234 |
No | output | 1 | 50,617 | 5 | 101,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At first, let's define function f(x) as follows: $$$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} x/2 & \mbox{if } x is even \\\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$$
We can see that if we choose some value v and will apply function f to it, then apply f to f(v), and so on, we'll eventually get 1. Let's write down all values we get in this process in a list and denote this list as path(v). For example, path(1) = [1], path(15) = [15, 14, 7, 6, 3, 2, 1], path(32) = [32, 16, 8, 4, 2, 1].
Let's write all lists path(x) for every x from 1 to n. The question is next: what is the maximum value y such that y is contained in at least k different lists path(x)?
Formally speaking, you need to find maximum y such that \left| \{ x ~|~ 1 ≤ x ≤ n, y ∈ path(x) \} \right| ≥ k.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^{18}).
Output
Print the only integer — the maximum value that is contained in at least k paths.
Examples
Input
11 3
Output
5
Input
11 6
Output
4
Input
20 20
Output
1
Input
14 5
Output
6
Input
1000000 100
Output
31248
Note
In the first example, the answer is 5, since 5 occurs in path(5), path(10) and path(11).
In the second example, the answer is 4, since 4 occurs in path(4), path(5), path(8), path(9), path(10) and path(11).
In the third example n = k, so the answer is 1, since 1 is the only number occuring in all paths for integers from 1 to 20.
Submitted Solution:
```
#from sys import stdin, stdout
import math
#from collections import deque
#input = stdin.readline
def f(cap, num):
if num % 2 == 0:
num //= 2
even = 1
else:
even = 0
k = math.floor(math.log2(cap / num))
facts = 2**k
return facts - 1 + min(facts, cap - num * facts + 1) - even
def getAns(cap, num):
#oddSol
k = math.floor(math.log2(num))
effB = 2**k
odd = math.floor((cap - (num - effB))/(effB))
#evenSol
num += 1
k = math.floor(math.log2(num))
effB = 2**k
even = math.floor((cap - (num - effB))/(effB) * 2)
if even % 2 == 1:
even += 1
if f(cap, even) < num - 1:
even -= 2
if odd % 2 == 0:
odd += 1
if f(cap, odd) < num - 1:
odd -= 2
return max(odd, even)
asdf = [int(x) for x in input().split(' ')]
a = asdf[0]
b = asdf[1]
print(getAns(a,b))
``` | instruction | 0 | 50,618 | 5 | 101,236 |
No | output | 1 | 50,618 | 5 | 101,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0.
The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor".
In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9).
Input
The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105).
Output
Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output.
Examples
Input
3 2
Output
6
Note
Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).
Submitted Solution:
```
n,m=map(int,input().split());MOD=1000000007;o=1;m=pow(2,m,MOD)-1
for i in range(n):o=o*(m-i)%MOD
print(o)
``` | instruction | 0 | 50,775 | 5 | 101,550 |
No | output | 1 | 50,775 | 5 | 101,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.
An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself.
Input
The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries.
q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.
Output
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
Examples
Input
1
12
Output
3
Input
2
6
8
Output
1
2
Input
3
1
2
3
Output
-1
-1
-1
Note
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.
8 = 4 + 4, 6 can't be split into several composite summands.
1, 2, 3 are less than any composite number, so they do not have valid splittings.
Submitted Solution:
```
from sys import stdin, stdout, setrecursionlimit
import threading
# tail-recursion optimization
# In case of tail-recusion optimized code, have to use python compiler.
# Otherwise, memory limit may exceed.
# declare the class Tail_Recursion_Optimization
class Tail_Recursion_Optimization:
def __init__(self, RECURSION_LIMIT, STACK_SIZE):
setrecursionlimit(RECURSION_LIMIT)
threading.stack_size(STACK_SIZE)
return None
class SOLVE:
def solve(self):
R = stdin.readline
#f = open('input.txt');R = f.readline
W = stdout.write
ans = []
for i in range(int(R())):
n = int(R())
if n in [1, 2, 3, 5, 7, 11]:
ans.append('-1')
else:
if not n%2:
if not n%4:
ans.append(str(n//4))
else:
ans.append(str(1 + (n-6)//4))
else:
n -= 9
if not n%4:
ans.append(str(1 + n//4))
else:
ans.append(str(2+(n-6)//4))
W('\n'.join(ans))
return 0
def main():
s = SOLVE()
s.solve()
#Tail_Recursion_Optimization(10**7, 2**26) # recursion-call size, stack-size in byte
threading.Thread(target=main).start()
``` | instruction | 0 | 51,010 | 5 | 102,020 |
Yes | output | 1 | 51,010 | 5 | 102,021 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.
You are given Q queries.
In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
Constraints
* 1≤Q≤10^5
* 1≤l_i≤r_i≤10^5
* l_i and r_i are odd.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
Q
l_1 r_1
:
l_Q r_Q
Output
Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.
Examples
Input
1
3 7
Output
2
Input
4
13 13
7 11
7 11
2017 2017
Output
1
0
0
1
Input
6
1 53
13 91
37 55
19 51
73 91
13 49
Output
4
4
1
1
1
2
Submitted Solution:
```
n=7**6;P=[0,0]+[1]*n;S=[0]*n
for i in range(2,n):
for j in range(2*i,n,i):P[j]=0
S[i]+=(P[i]==P[(i+1)//2]==1)+S[i-1]
for _ in "_"*int(input()):l,r=map(int,input().split());print(S[r]-S[l-1])
``` | instruction | 0 | 51,152 | 5 | 102,304 |
Yes | output | 1 | 51,152 | 5 | 102,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.
You are given Q queries.
In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
Constraints
* 1≤Q≤10^5
* 1≤l_i≤r_i≤10^5
* l_i and r_i are odd.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
Q
l_1 r_1
:
l_Q r_Q
Output
Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.
Examples
Input
1
3 7
Output
2
Input
4
13 13
7 11
7 11
2017 2017
Output
1
0
0
1
Input
6
1 53
13 91
37 55
19 51
73 91
13 49
Output
4
4
1
1
1
2
Submitted Solution:
```
import math
q=int(input())
N=[0]*(10**5+1)
N[3]=1
N[2]=1
S=[]
for i in range(5,10**5+1,2):
flag=True
for j in range(3,int(math.sqrt(i))+1,2):
if i%j==0:
flag=False
break
if flag:
N[i]=1
X=[0]*(10**5+1)
X[2]=1
cnt=0
for i in range(3,10**5+1,2):
if N[i]==1 and N[(i+1)//2]==1:
cnt+=1
X[i]=cnt
Q=[]
for i in range(q):
l,r=map(int,input().split())
print(X[r]-X[l-2])
``` | instruction | 0 | 51,153 | 5 | 102,306 |
Yes | output | 1 | 51,153 | 5 | 102,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.
You are given Q queries.
In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
Constraints
* 1≤Q≤10^5
* 1≤l_i≤r_i≤10^5
* l_i and r_i are odd.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
Q
l_1 r_1
:
l_Q r_Q
Output
Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.
Examples
Input
1
3 7
Output
2
Input
4
13 13
7 11
7 11
2017 2017
Output
1
0
0
1
Input
6
1 53
13 91
37 55
19 51
73 91
13 49
Output
4
4
1
1
1
2
Submitted Solution:
```
from itertools import accumulate as ac
m=101000
num=[1]*m
num[0]=num[1]=0
for i in range(2,int(m**0.5)+1):
if not num[i]:
continue
for j in range(i*2,m,i):
num[j]=0
a=[0]*m
for i in range(m):
if i%2==0:
continue
if num[i] and num[(i+1)//2]:
a[i]=1
csum=[0]+a
csum=list(ac(csum))
#print(csum)
q=int(input())
for i in range(q):
l,r=map(int,input().split())
print(csum[r+1]-csum[l])
``` | instruction | 0 | 51,155 | 5 | 102,310 |
Yes | output | 1 | 51,155 | 5 | 102,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.
You are given Q queries.
In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
Constraints
* 1≤Q≤10^5
* 1≤l_i≤r_i≤10^5
* l_i and r_i are odd.
* All input values are integers.
Input
Input is given from Standard Input in the following format:
Q
l_1 r_1
:
l_Q r_Q
Output
Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.
Examples
Input
1
3 7
Output
2
Input
4
13 13
7 11
7 11
2017 2017
Output
1
0
0
1
Input
6
1 53
13 91
37 55
19 51
73 91
13 49
Output
4
4
1
1
1
2
Submitted Solution:
```
Q=int(input())
LR=[]
L,R=0,0
for i in range(Q):
l,r=map(int,input().split())
L,R=max(L,l),max(R,r)
LR.append([l,r])
M=R+1
lst=[0 for i in range(M)]
sosuu=set([2])
count=0
for i in range(3,M,2):
flag=0
for m in sosuu:
if i%m==0:
flag=1
break
if not flag:
sosuu.add(i)
if (i+1)//2 in sosuu:
count+=1
lst[i]=count
for l,r in LR:
print(lst[r]-lst[max(l-2,0)])
``` | instruction | 0 | 51,156 | 5 | 102,312 |
No | output | 1 | 51,156 | 5 | 102,313 |
Provide a correct Python 3 solution for this coding contest problem.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714 | instruction | 0 | 51,226 | 5 | 102,452 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
'import sys'
'import math'
n=int(input())
A=[int(i) for i in input().split()]
A.sort()
ans=0.0
for i in range(1,n):
cd = int(A[i])-int(A[i-1])
if i==n-1:
ab=int(A[n-3])+int(A[n-4])
elif i==n-2:
ab=int(A[n-1])+int(A[n-4])
else:
ab=int(A[n-1])+int(A[n-2])
ans=max(ans,ab/cd)
print(ans)
``` | output | 1 | 51,226 | 5 | 102,453 |
Provide a correct Python 3 solution for this coding contest problem.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714 | instruction | 0 | 51,227 | 5 | 102,454 |
"Correct Solution:
```
n = int(input())
S = list(map(int, input().split()))
res = 0.0;
S.sort()
for d in range(n-1):
c = d+1
a = n-1
b = n-2
if d == n-3:
b = d-1
elif d == n-2:
a = d-2
b = d-1
res = max(res, 1.0*(S[a]+S[b])/(S[c]-S[d]))
print(res)
``` | output | 1 | 51,227 | 5 | 102,455 |
Provide a correct Python 3 solution for this coding contest problem.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714 | instruction | 0 | 51,228 | 5 | 102,456 |
"Correct Solution:
```
n = int(input())
a = sorted(map(int,input().split()))
b = [(a[i + 1] - a[i], i) for i in range(n -1)]
b.sort(key = lambda x:x[0])
if b[0][1] < n - 2:print((a[-1] + a[-2]) / b[0][0])
elif b[0][1] == n - 3:
if b[1][1] == n - 2:print(max((a[-1] + a[-2]) / b[2][0], (a[-1] + a[-4]) / b[0][0], (a[-3] + a[-4]) / b[1][0]))
else:print(max((a[-1] + a[-2]) / b[1][0], (a[-1] + a[-4]) / b[0][0]))
else:
if b[1][1] == n - 3:print(max((a[-1] + a[-2]) / b[2][0], (a[-1] + a[-4]) / b[1][0], (a[-3] + a[-4]) / b[0][0]))
else:print(max((a[-1] + a[-2]) / b[1][0], (a[-3] + a[-4]) / b[0][0]))
``` | output | 1 | 51,228 | 5 | 102,457 |
Provide a correct Python 3 solution for this coding contest problem.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714 | instruction | 0 | 51,229 | 5 | 102,458 |
"Correct Solution:
```
n = int(input())
li = list(map(int,input().split()))
li2 = li.copy()
so0 = sorted(li)
diffs = dict()
for i in range(len(li)-1):
diffs[i]= so0[i+1]-so0[i]
soDiffs = sorted(diffs.items(),key=lambda pair: pair[1])
# print(soDiffs)
ma = 0
for idx,diff in soDiffs:
so= so0.copy()
d=so[idx]
c=so[idx+1]
# print(c,d)
so.remove(c)
so.remove(d)
a,b = so[-2:]
exp = (a+b)/(c-d)
# print(exp)
if exp > ma:
ma = exp
else:
print(ma)
break
``` | output | 1 | 51,229 | 5 | 102,459 |
Provide a correct Python 3 solution for this coding contest problem.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714 | instruction | 0 | 51,230 | 5 | 102,460 |
"Correct Solution:
```
n = int(input())
a = [int(num) for num in input().split()]
ans = 0.0
a.sort()
for i in range(n - 2):
ans = max(ans, (a[n - 1] + a[n - 2]) / (a[i + 1] - a[i] + 0.0))
ans = max(ans, (a[n - 1] + a[n - 4]) / (a[n - 2] - a[n - 3] + 0.0))
ans = max(ans, (a[n - 3] + a[n - 4]) / (a[n - 1] - a[n - 2] + 0.0))
print('%.8f' % (ans))
``` | output | 1 | 51,230 | 5 | 102,461 |
Provide a correct Python 3 solution for this coding contest problem.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714 | instruction | 0 | 51,231 | 5 | 102,462 |
"Correct Solution:
```
import copy
n = int(input())
data = list(map(int, input().split()))
data.sort()
data1 = copy.copy(data)
A = data1.pop()
B = data1.pop()
n_1 = n-2
min = 100000000
for i in range(n_1 - 1) :
if data1[i+1] - data1[i] < min :
min = data1[i+1] - data1[i]
C = data1[i+1]
D = data1[i]
ans_1 = (A+B) / (C-D)
data2 = copy.copy(data)
min = 100000000
for i in range(n - 1) :
if data2[i+1] - data2[i] < min :
min = data2[i+1] - data2[i]
C = data2[i+1]
D = data2[i]
data2.remove(C)
data2.remove(D)
A = data2.pop()
B = data2.pop()
ans_2 = (A+B) / (C-D)
print(max(ans_1, ans_2))
``` | output | 1 | 51,231 | 5 | 102,463 |
Provide a correct Python 3 solution for this coding contest problem.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714 | instruction | 0 | 51,232 | 5 | 102,464 |
"Correct Solution:
```
n = int(input())
alst = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
for j in range(i + 1, n):
c = alst[j]
d = alst[i]
if j <= n - 3:
a, b = alst[n - 1], alst[n - 2]
elif i >= n - 2:
a, b = alst[n - 3], alst[n - 4]
elif j == n - 1 and i == n - 3:
a, b = alst[n - 2], alst[n - 4]
elif j == n - 2 and i == n - 3:
a, b = alst[n - 1], alst[n - 4]
elif j == n - 1 and i == n - 4:
a, b = alst[n - 2], alst[n - 3]
elif j == n - 2 and i == n - 4:
a, b = alst[n - 1], alst[n - 3]
ans = max(ans, (a + b) / (c - d))
print(ans)
``` | output | 1 | 51,232 | 5 | 102,465 |
Provide a correct Python 3 solution for this coding contest problem.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714 | instruction | 0 | 51,233 | 5 | 102,466 |
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
e = LI()
d = defaultdict(int)
for i in e:
d[i] += 1
for i in d.values():
if i != 2:
print("no")
break
else:
print("yes")
return
#B
def B():
n = I()
a = LI()
a.sort()
ans = -float("inf")
for c in range(n):
for d in range(c):
m = a[c]-a[d]
for i in range(n)[::-1]:
if i != c and i != d:
e = i
break
for i in range(e)[::-1]:
if i != c and i != d:
b = i
break
ans = max(ans, (a[e]+a[b])/m)
print(ans)
return
#C
def C():
return
#D
def D():
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#I
def I_():
return
#J
def J():
return
#Solve
if __name__ == "__main__":
B()
``` | output | 1 | 51,233 | 5 | 102,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714
Submitted Solution:
```
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
a.reverse()
# i = 0, j = 1
ans = (a[2]+a[3]) / (a[0]-a[1])
# i = 0, j = 2
ans = max(ans, (a[1]+a[3]) / (a[0]-a[2]))
# i = 0, j >= 3
for j in range(3, N):
ans = max(ans, (a[1]+a[2])/(a[0]-a[j]))
# i = 1, j = 2
ans = max(ans, (a[0]+a[3]) / (a[1]-a[2]))
# i = 1, j >= 3
for j in range(3, N):
ans = max(ans, (a[0]+a[2])/(a[1]-a[j]))
# i >= 2
for i in range(2, N):
for j in range(i+1, N):
ans = max(ans, (a[0]+a[1])/(a[i]-a[j]))
print(ans)
``` | instruction | 0 | 51,234 | 5 | 102,468 |
Yes | output | 1 | 51,234 | 5 | 102,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714
Submitted Solution:
```
n = int(input())
a = sorted(list(map(int, input().split())))
ans = -0.1
for j in range(n):
for i in range(j):
C = a[j]
D = a[i]
k = n - 1
while k == j or k == i:
k -= 1
A = a[k]
k -= 1
while k == j or k == i:
k -= 1
B = a[k]
ans = max(ans, (A + B) / (C - D))
print(ans)
``` | instruction | 0 | 51,235 | 5 | 102,470 |
Yes | output | 1 | 51,235 | 5 | 102,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714
Submitted Solution:
```
n = int(input())
*A, = map(int, input().split())
A.sort(reverse=1)
ans = 0
for i in range(n):
for j in range(i+1, n):
p = q = 0
while p in [i, j]:
p += 1
while q in [i, j, p]:
q += 1
ans = max(ans, (A[p]+A[q])/(A[i]-A[j]))
print("%.6f" % ans)
``` | instruction | 0 | 51,236 | 5 | 102,472 |
Yes | output | 1 | 51,236 | 5 | 102,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714
Submitted Solution:
```
n = int(input())
a = sorted(map(int,input().split()))
b = [(a[i + 1] - a[i], i) for i in range(n -1)]
b.sort(key = lambda x:x[0])
if b[0][1] < n - 2:print((a[-1] + a[-2]) / c)
elif b[0][1] == n - 3:
if b[1][1] == n - 2:print(max((a[-1] + a[-2]) / b[2][0], (a[-1] + a[-4]) / b[0][0], (a[-3] + a[-4]) / b[1][0]))
else:print(max((a[-1] + a[-2]) / b[1][0], (a[-1] + a[-4]) / b[0][0]))
else:
if b[1][1] == n - 3:print(max((a[-1] + a[-2]) / b[2][0], (a[-1] + a[-4]) / b[1][0], (a[-3] + a[-4]) / b[0][0]))
else:print(max((a[-1] + a[-2]) / b[1][0], (a[-3] + a[-4]) / b[0][0]))
``` | instruction | 0 | 51,237 | 5 | 102,474 |
No | output | 1 | 51,237 | 5 | 102,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
N different natural numbers are given. If you select four different ones and set them as $ A $, $ B $, $ C $, $ D $, the following formula
$ \ Frac {A + B} {C --D} $
I want to find the maximum value of.
Given N different natural numbers, choose 4 different from them and create a program to find the maximum value of the above formula.
Input
The input is given in the following format.
N
a1 a2 ... aN
The number N (4 ≤ N ≤ 1000) of natural numbers is given in the first line. The value ai (1 ≤ ai ≤ 108) of each natural number is given in the second line. However, the same natural number does not appear more than once (ai ≠ aj for i ≠ j).
Output
Outputs the maximum value of the above formula as a real number for a given N natural numbers. However, the error must not exceed plus or minus 10-5.
Examples
Input
10
1 2 3 4 5 6 7 8 9 10
Output
19.00000
Input
5
22 100 42 3 86
Output
9.78947
Input
6
15 21 36 10 34 5
Output
18.00000
Input
4
100000 99999 8 1
Output
28571.285714
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
print((a[0]+a[1]) / (a[len(a)-2]-a[len(a)-1]))
``` | instruction | 0 | 51,238 | 5 | 102,476 |
No | output | 1 | 51,238 | 5 | 102,477 |
Provide a correct Python 3 solution for this coding contest problem.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3 | instruction | 0 | 51,292 | 5 | 102,584 |
"Correct Solution:
```
n=int(input())
U=[n-1-i for i in range(n)]
ind='0'+str(n)+'b'
for i in range(2**n):
compare=[int(j) for j in format(i,ind)]
disp=[U[j] for j in range(n) if compare[j]==1]
disp.reverse()
print(i,end=":")
if len(disp)!=0:
print(" "+' '.join(map(str,disp)),end="")
print()
``` | output | 1 | 51,292 | 5 | 102,585 |
Provide a correct Python 3 solution for this coding contest problem.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3 | instruction | 0 | 51,293 | 5 | 102,586 |
"Correct Solution:
```
n = int(input())
ans = []
for i in range(1<<n):
ret = []
ret.append('%d:' % i)
for j in range(n):
if i >> j & 1:
ret.append(j)
ans.append(' '.join(map(str, ret)))
print('\n'.join(ans))
``` | output | 1 | 51,293 | 5 | 102,587 |
Provide a correct Python 3 solution for this coding contest problem.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3 | instruction | 0 | 51,294 | 5 | 102,588 |
"Correct Solution:
```
n = int(input())
for i in range(2**n):
if i == 0:
print("0:")
continue
else:
print("{}: ".format(i), end="")
l = []
for j in range(n):
if i & (1 << j) != 0:
l.append(j)
print(*l)
``` | output | 1 | 51,294 | 5 | 102,589 |
Provide a correct Python 3 solution for this coding contest problem.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3 | instruction | 0 | 51,295 | 5 | 102,590 |
"Correct Solution:
```
if __name__ == "__main__":
bit = int(input())
print(f"0:")
for d in range(1, 2 ** bit):
print(f"{d}: ", end="")
print(" ".join([str(elem) for elem in range(bit) if d & (1 << elem)]))
``` | output | 1 | 51,295 | 5 | 102,591 |
Provide a correct Python 3 solution for this coding contest problem.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3 | instruction | 0 | 51,296 | 5 | 102,592 |
"Correct Solution:
```
n = int(input())
masks = [1 << x for x in range(n)]
for i in range(1 << n):
sub = [idx for idx, mask in enumerate(masks) if i & mask != 0b00]
print('{}: {}'.format(i, ' '.join(map(str, sub)))) if len(sub) != 0 else print(f'{i}:')
``` | output | 1 | 51,296 | 5 | 102,593 |
Provide a correct Python 3 solution for this coding contest problem.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3 | instruction | 0 | 51,297 | 5 | 102,594 |
"Correct Solution:
```
n = int(input())
print('0:')
for x in range(1, 2**n):
bits = [i for i, b in enumerate(f'{x:b}'[::-1]) if b == '1']
print(f'{x}: {" ".join(map(str, bits))}')
``` | output | 1 | 51,297 | 5 | 102,595 |
Provide a correct Python 3 solution for this coding contest problem.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3 | instruction | 0 | 51,298 | 5 | 102,596 |
"Correct Solution:
```
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
SIZE = 19
POW = [1]*SIZE
for i in range(1,SIZE):
POW[i] = POW[i-1]*2
N = int(input())
print("0:")
index = 1
for state in range(1,POW[N]):
print("%d:"%(index),end="")
for loop in range(N):
if state & POW[loop] != 0:
print(" %d"%(loop),end="")
print()
index += 1
``` | output | 1 | 51,298 | 5 | 102,597 |
Provide a correct Python 3 solution for this coding contest problem.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3 | instruction | 0 | 51,299 | 5 | 102,598 |
"Correct Solution:
```
n=int(input())
m=2**n
for i in range(m):
temp=[0 for i in range(n)]
j=i
count=0
while j>0:
if j%2==1:
temp[count]=1
#print(count,temp[count])
j//=2
count+=1
temp2=[]
for k in range(n):
if temp[k]==1:
temp2.append(k)
print(i,end="")
if i!=0:
print(":",end=" " )
print(*temp2)
else:
print(":")
``` | output | 1 | 51,299 | 5 | 102,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Bitset II - Enumeration of Subsets I
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_11_A&lang=jp
"""
n = int(input())
print('0:')
for x in range(1, 2**n):
bits = [i for i, b in enumerate(f'{x:b}'[::-1]) if b == '1']
print(f'{x}: {" ".join(map(str, bits))}')
``` | instruction | 0 | 51,300 | 5 | 102,600 |
Yes | output | 1 | 51,300 | 5 | 102,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3
Submitted Solution:
```
n = int(input())
nn = pow(2, n)
for i in range(nn):
if i == 0:
print("0:")
else:
bin_str = "0" + str(n) + "b"
bin_i = format(i, bin_str)
ilist = list(bin_i)
tmplist = []
for j, bini in enumerate(ilist):
if bini == '1':
tmplist.append(n - j - 1)
tmplist.sort()
tmp_str = ' '.join(str(tmp) for tmp in tmplist)
print(str(i) + ": " + tmp_str)
``` | instruction | 0 | 51,301 | 5 | 102,602 |
Yes | output | 1 | 51,301 | 5 | 102,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3
Submitted Solution:
```
#!/usr/bin/env python3
# Bitset 2 - Enumeration of Subsets 1
def subset(n):
for i in range(2**n):
yield [v for v in range(n) if i & (1 << v) > 0]
def run():
n = int(input())
for i, vs in enumerate(subset(n)):
print("{}:{}".format(i, "".join([" {}".format(v) for v in vs])))
if __name__ == '__main__':
run()
``` | instruction | 0 | 51,302 | 5 | 102,604 |
Yes | output | 1 | 51,302 | 5 | 102,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Print all subsets of a set $S$, which contains $0, 1, ... n-1$ as elements. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.
Constraints
* $1 \leq n \leq 18$
Input
The input is given in the following format.
$n$
Output
Print subsets ordered by their decimal integers. Print a subset in a line in the following format.
$d$: $e_0$ $e_1$ ...
Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Seprate two adjacency elements by a space character.
Example
Input
4
Output
0:
1: 0
2: 1
3: 0 1
4: 2
5: 0 2
6: 1 2
7: 0 1 2
8: 3
9: 0 3
10: 1 3
11: 0 1 3
12: 2 3
13: 0 2 3
14: 1 2 3
15: 0 1 2 3
Submitted Solution:
```
n = int(input())
# a = list(map(int, input()split()))
for i in range(1<<n):
ans = []
_i = i
cnt = 0
while i:
if i&1:
ans.append(cnt)
cnt += 1
i=i>>1
print(f'{_i}:',end = '')
if _i == 0:
print()
else:print("",*ans)
``` | instruction | 0 | 51,303 | 5 | 102,606 |
Yes | output | 1 | 51,303 | 5 | 102,607 |
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 consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the maximum possible value of <image>.
Examples
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
Note
In the first example you can choose a sequence b = {1, 2}, so the sum <image> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
Submitted Solution:
```
import bisect
n,m = map(int,input().split())
a = [int(x) for x in input().split()]
b = []
otv = 0
for i in range(0,1<<(n//2 + n%2)):
t = 0
k = i
for j in range(20):
if k & 1:
t += a[j]
k = k >> 1
b.append(t%m)
b.sort()
for i in range(0,1<<(n//2)):
t = 0
k = i
for j in range(20):
if k & 1:
t += a[(n//2 + n%2) + j]
k = k >> 1
t = t % m
k = bisect.bisect_left(b,m - t - 1)
if k < len(b):
t2 = b[k]
if t2 > m - t - 1:
if k - 1 >= 0:
t2 = b[k - 1]
else:
t2 = b[-1]
otv = max(otv,(t + t2)%m,(t + b[-1])%m)
print(otv % m)
``` | instruction | 0 | 51,850 | 5 | 103,700 |
Yes | output | 1 | 51,850 | 5 | 103,701 |
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 consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the maximum possible value of <image>.
Examples
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
Note
In the first example you can choose a sequence b = {1, 2}, so the sum <image> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
Submitted Solution:
```
import bisect
n,M= tuple(map(int,input().split()))
nums = list(map(int,input().split()))
r1,r2 = [],[]
def dfs(index,last,sum,check):
if index == last:
if check == 1:
r1.append(sum)
else:
r2.append(sum)
return
dfs(index+1,last,sum,check)
dfs(index+1,last,(sum+nums[index])%M,check)
dfs(0,n//2,0,1)
dfs(n//2,n,0,2)
s1 = set()
s2 = set()
for i in r1:
s1.add(i)
for i in r2:
s2.add(i)
r1 = sorted(list(s1))
r2 = sorted(list(s2))
ans = 0
for x in r1:
p = bisect.bisect_left(r2,M-x)
ans = max(ans,x+r2[p-1])
print(ans)
``` | instruction | 0 | 51,851 | 5 | 103,702 |
Yes | output | 1 | 51,851 | 5 | 103,703 |
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 consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the maximum possible value of <image>.
Examples
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
Note
In the first example you can choose a sequence b = {1, 2}, so the sum <image> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
Submitted Solution:
```
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
import bisect
a1,a2=[],[]
n1=n//2
def sums1(i,sum=0):
if i==n1:
a1.append(sum)
else:
sums1(i+1,(sum+a[i])%m)
sums1(i+1,sum)
def sums2(i,sum=0):
if i==n:
a2.append(sum)
else:
sums2(i+1,(sum+a[i])%m)
sums2(i+1,sum)
sums1(0)
sums2(n1)
ans=0
end=len(a2)-1
a1=sorted(set(a1))
for i in a2:
j=bisect.bisect_left(a1,m-i)
if ans<a1[j-1]+i:
ans=a1[j-1]+i
print(ans)
``` | instruction | 0 | 51,852 | 5 | 103,704 |
Yes | output | 1 | 51,852 | 5 | 103,705 |
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 consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the maximum possible value of <image>.
Examples
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
Note
In the first example you can choose a sequence b = {1, 2}, so the sum <image> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
Submitted Solution:
```
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
import bisect
a1,a2=[],[]
n1=n//2
def sums1(i,sum=0):
if i==n1:
a1.append(sum)
else:
sums1(i+1,(sum+a[i])%m)
sums1(i+1,sum)
def sums2(i,sum=0):
if i==n:
a2.append(sum)
else:
sums2(i+1,(sum+a[i])%m)
sums2(i+1,sum)
sums1(0)
sums2(n1)
ans=0
end=len(a2)-1
a1=sorted(set(a1))
a2=sorted(set(a2))
for i in a2:
j=bisect.bisect_left(a1,m-i)
ans=max(ans,a1[j-1]+i)
print(ans)
``` | instruction | 0 | 51,853 | 5 | 103,706 |
Yes | output | 1 | 51,853 | 5 | 103,707 |
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 consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the maximum possible value of <image>.
Examples
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
Note
In the first example you can choose a sequence b = {1, 2}, so the sum <image> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
Submitted Solution:
```
def Anal(A, i, r, m, S):
if i == len(A):
S.add(r)
else:
Anal(A, i+1, (r+A[i])%m, m, S)
Anal(A, i+1, r, m, S)
n, m = map(int, input().split())
A = list(map(int, input().split()))
x = set()
y = set()
Anal(A[n//2:], 0, 0, m, x)
Anal(A[:n//2], 0, 0, m, y)
x = list(x)
y = list(y)
y.sort()
x.sort()
print(max(x[-1], y[-1]))
``` | instruction | 0 | 51,854 | 5 | 103,708 |
No | output | 1 | 51,854 | 5 | 103,709 |
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 consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the maximum possible value of <image>.
Examples
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
Note
In the first example you can choose a sequence b = {1, 2}, so the sum <image> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
Submitted Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
if(n==10 and m==1000):
print(999)
exit(0)
sum=[]
for i in range (len(a)):
for j in range (i,len(a)+1):
if(a[i:j]!=[]): sum.append(a[i:j])
def SumOfArray(nums):
sum=0
for i in nums:
sum+=i
return sum
res=[]
for i in sum:
res.append(SumOfArray(i)%m)
print(max(res))
``` | instruction | 0 | 51,855 | 5 | 103,710 |
No | output | 1 | 51,855 | 5 | 103,711 |
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 consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the maximum possible value of <image>.
Examples
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
Note
In the first example you can choose a sequence b = {1, 2}, so the sum <image> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
Submitted Solution:
```
n, m = map(int, input().split())
if n > 0:
*a, = map(int, input().split())
a = [a[i] % m for i in range(n)]
s = [0 for i in range(n)]
for i in range(n):
s[i] = a[i]
for j in range(i):
s[i] = max(s[i], (s[j] + a[i]) % m)
if n > 0:
print(max(s))
else:
print(0)
``` | instruction | 0 | 51,856 | 5 | 103,712 |
No | output | 1 | 51,856 | 5 | 103,713 |
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 consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of <image> is maximized. Chosen sequence can be empty.
Print the maximum possible value of <image>.
Input
The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the maximum possible value of <image>.
Examples
Input
4 4
5 2 4 1
Output
3
Input
3 20
199 41 299
Output
19
Note
In the first example you can choose a sequence b = {1, 2}, so the sum <image> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example you can choose a sequence b = {3}.
Submitted Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
s = []
t = []
def dfs(cur,sum):
if cur == int(n/2):
s.append(sum%m)
return
dfs(cur+1,sum)
dfs(cur+1,sum+a[cur])
return
def dfs2(cur, sum):
if cur == n:
t.append(sum%m)
return
dfs2(cur+1, sum)
dfs2(cur+1, sum + a[cur])
return
dfs(0, 0)
dfs2(int(n/2), 0)
ans = 0
s = sorted(s)
t = sorted(t)
for i in range(len(s)):
tmp = s[i]
pos = -1
for j in range(len(t)):
if t[j] > m - tmp:
pos = j
break
if j == len(t) - 1:
pos = j + 1
break
pos = j
if pos != 0:
pos -= 1
if t[pos] + tmp <= m:
ans = max(ans, t[pos] + tmp)
print(ans)
``` | instruction | 0 | 51,857 | 5 | 103,714 |
No | output | 1 | 51,857 | 5 | 103,715 |
Provide a correct Python 3 solution for this coding contest problem.
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Constraints
* 1 \leq M \leq N \leq 100
* 1 \leq A_i \leq 1000
* A_i are distinct.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
A_1 ... A_N
Output
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Examples
Input
4 1
5 4 2 1
Output
Yes
Input
3 2
380 19 1
Output
No
Input
12 3
4 56 78 901 2 345 67 890 123 45 6 789
Output
Yes | instruction | 0 | 51,932 | 5 | 103,864 |
"Correct Solution:
```
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=a[::-1]
if b[m-1]<sum(a)/(4*m):
print("No")
elif True:
print("Yes")
``` | output | 1 | 51,932 | 5 | 103,865 |
Provide a correct Python 3 solution for this coding contest problem.
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Constraints
* 1 \leq M \leq N \leq 100
* 1 \leq A_i \leq 1000
* A_i are distinct.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
A_1 ... A_N
Output
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Examples
Input
4 1
5 4 2 1
Output
Yes
Input
3 2
380 19 1
Output
No
Input
12 3
4 56 78 901 2 345 67 890 123 45 6 789
Output
Yes | instruction | 0 | 51,933 | 5 | 103,866 |
"Correct Solution:
```
N,M=map(int, input().split())
A=list(map(int, input().split()))
A.sort(reverse=True)
if A[M-1]<sum(A)/4/M:
print('No')
else:
print('Yes')
``` | output | 1 | 51,933 | 5 | 103,867 |
Provide a correct Python 3 solution for this coding contest problem.
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Constraints
* 1 \leq M \leq N \leq 100
* 1 \leq A_i \leq 1000
* A_i are distinct.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
A_1 ... A_N
Output
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Examples
Input
4 1
5 4 2 1
Output
Yes
Input
3 2
380 19 1
Output
No
Input
12 3
4 56 78 901 2 345 67 890 123 45 6 789
Output
Yes | instruction | 0 | 51,934 | 5 | 103,868 |
"Correct Solution:
```
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A = sorted(A)[::-1]
print("Yes" if A[M-1] >= sum(A)/(4*M) else "No")
``` | output | 1 | 51,934 | 5 | 103,869 |
Provide a correct Python 3 solution for this coding contest problem.
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Constraints
* 1 \leq M \leq N \leq 100
* 1 \leq A_i \leq 1000
* A_i are distinct.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
A_1 ... A_N
Output
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Examples
Input
4 1
5 4 2 1
Output
Yes
Input
3 2
380 19 1
Output
No
Input
12 3
4 56 78 901 2 345 67 890 123 45 6 789
Output
Yes | instruction | 0 | 51,935 | 5 | 103,870 |
"Correct Solution:
```
a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
if c[-b]>=(sum(c)/(4*b)):
print("Yes")
else:
print("No")
``` | output | 1 | 51,935 | 5 | 103,871 |
Provide a correct Python 3 solution for this coding contest problem.
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Constraints
* 1 \leq M \leq N \leq 100
* 1 \leq A_i \leq 1000
* A_i are distinct.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
A_1 ... A_N
Output
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Examples
Input
4 1
5 4 2 1
Output
Yes
Input
3 2
380 19 1
Output
No
Input
12 3
4 56 78 901 2 345 67 890 123 45 6 789
Output
Yes | instruction | 0 | 51,936 | 5 | 103,872 |
"Correct Solution:
```
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = sum(a)/(4*M)
print("Yes" if a[M-1] >= c else "No")
``` | output | 1 | 51,936 | 5 | 103,873 |
Provide a correct Python 3 solution for this coding contest problem.
We have held a popularity poll for N items on sale. Item i received A_i votes.
From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Constraints
* 1 \leq M \leq N \leq 100
* 1 \leq A_i \leq 1000
* A_i are distinct.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
A_1 ... A_N
Output
If M popular items can be selected, print `Yes`; otherwise, print `No`.
Examples
Input
4 1
5 4 2 1
Output
Yes
Input
3 2
380 19 1
Output
No
Input
12 3
4 56 78 901 2 345 67 890 123 45 6 789
Output
Yes | instruction | 0 | 51,937 | 5 | 103,874 |
"Correct Solution:
```
[N,M]=list(map(int,input().split()))
A=list(map(int,input().split()))
print(["No","Yes"][int(len(list(filter(lambda Ai:Ai>=sum(A)/4/M,A)))>M-1)])
``` | output | 1 | 51,937 | 5 | 103,875 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.