message stringlengths 2 433k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 113 108k | cluster float64 12 12 | __index_level_0__ int64 226 217k |
|---|---|---|---|---|---|
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 s consisting of n integers.
You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.
Cutting out the copy of t means that for each element t_i of array t you have to find t_i in s and remove it from s. If for some t_i you cannot find such element in s, then you cannot cut out one more copy of t. The both arrays can contain duplicate elements.
For example, if s = [1, 2, 3, 2, 4, 3, 1] and k = 3 then one of the possible answers is t = [1, 2, 3]. This array t can be cut out 2 times.
* To cut out the first copy of t you can use the elements [1, \underline{2}, 3, 2, 4, \underline{3}, \underline{1}] (use the highlighted elements). After cutting out the first copy of t the array s can look like [1, 3, 2, 4].
* To cut out the second copy of t you can use the elements [\underline{1}, \underline{3}, \underline{2}, 4]. After cutting out the second copy of t the array s will be [4].
Your task is to find such array t that you can cut out the copy of t from s maximum number of times. If there are multiple answers, you may choose any of them.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of elements in s and the desired number of elements in t, respectively.
The second line of the input contains exactly n integers s_1, s_2, ..., s_n (1 β€ s_i β€ 2 β
10^5).
Output
Print k integers β the elements of array t such that you can cut out maximum possible number of copies of this array from s. If there are multiple answers, print any of them. The required array t can contain duplicate elements. All the elements of t (t_1, t_2, ..., t_k) should satisfy the following condition: 1 β€ t_i β€ 2 β
10^5.
Examples
Input
7 3
1 2 3 2 4 3 1
Output
1 2 3
Input
10 4
1 3 1 3 10 3 7 7 12 3
Output
7 3 1 3
Input
15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1
Output
1 1
Note
The first example is described in the problem statement.
In the second example the only answer is [7, 3, 1, 3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 2.
In the third example the array t can be cut out 5 times.
Submitted Solution:
```
import collections as cc
I=lambda:list(map(int,input().split()))
n,k=I()
l=I()
f={}
for i in l:
f[i]=f.get(i,0)+1
lo=1
hi=n
while lo<hi:
mid=(lo+hi+1)//2
temp=0
for j in f.values():
temp+=j//mid
if temp>=k:
lo=mid
else:
hi=mid-1
tem=0
aa=[]
for x in f.keys():
for i in range(f[x]//lo):
if tem<k:
aa.append(x)
tem+=1
print(*aa)
``` | instruction | 0 | 51,331 | 12 | 102,662 |
Yes | output | 1 | 51,331 | 12 | 102,663 |
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 s consisting of n integers.
You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.
Cutting out the copy of t means that for each element t_i of array t you have to find t_i in s and remove it from s. If for some t_i you cannot find such element in s, then you cannot cut out one more copy of t. The both arrays can contain duplicate elements.
For example, if s = [1, 2, 3, 2, 4, 3, 1] and k = 3 then one of the possible answers is t = [1, 2, 3]. This array t can be cut out 2 times.
* To cut out the first copy of t you can use the elements [1, \underline{2}, 3, 2, 4, \underline{3}, \underline{1}] (use the highlighted elements). After cutting out the first copy of t the array s can look like [1, 3, 2, 4].
* To cut out the second copy of t you can use the elements [\underline{1}, \underline{3}, \underline{2}, 4]. After cutting out the second copy of t the array s will be [4].
Your task is to find such array t that you can cut out the copy of t from s maximum number of times. If there are multiple answers, you may choose any of them.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of elements in s and the desired number of elements in t, respectively.
The second line of the input contains exactly n integers s_1, s_2, ..., s_n (1 β€ s_i β€ 2 β
10^5).
Output
Print k integers β the elements of array t such that you can cut out maximum possible number of copies of this array from s. If there are multiple answers, print any of them. The required array t can contain duplicate elements. All the elements of t (t_1, t_2, ..., t_k) should satisfy the following condition: 1 β€ t_i β€ 2 β
10^5.
Examples
Input
7 3
1 2 3 2 4 3 1
Output
1 2 3
Input
10 4
1 3 1 3 10 3 7 7 12 3
Output
7 3 1 3
Input
15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1
Output
1 1
Note
The first example is described in the problem statement.
In the second example the only answer is [7, 3, 1, 3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 2.
In the third example the array t can be cut out 5 times.
Submitted Solution:
```
import os
import sys
fin = open("input.txt") if os.getenv('local') == '1' else sys.stdin
fout = open("output.txt", "w") if os.getenv('local') == '1' else sys.stdout
# k, n, m, d = map(int, fin.readline().split())
# n = int(sys.stdin.readline())
n, k = map(int, fin.readline().split())
s = list(map(int, fin.readline().split()))
maxx = 200_000
left = 1
right = maxx
a = [0 for _ in range(maxx + 1)]
for ss in s:
a[ss] += 1
while left != right:
center = int((right + left + 1) / 2)
cnt = 0
for i in range(maxx + 1):
cnt += int(a[i] / center)
if cnt >= k:
left = center
else:
right = center - 1
for i in range(maxx + 1):
for _ in range(int(a[i] / left)):
fout.write('%s ' % i)
fout.write('\n')
``` | instruction | 0 | 51,332 | 12 | 102,664 |
No | output | 1 | 51,332 | 12 | 102,665 |
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 s consisting of n integers.
You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.
Cutting out the copy of t means that for each element t_i of array t you have to find t_i in s and remove it from s. If for some t_i you cannot find such element in s, then you cannot cut out one more copy of t. The both arrays can contain duplicate elements.
For example, if s = [1, 2, 3, 2, 4, 3, 1] and k = 3 then one of the possible answers is t = [1, 2, 3]. This array t can be cut out 2 times.
* To cut out the first copy of t you can use the elements [1, \underline{2}, 3, 2, 4, \underline{3}, \underline{1}] (use the highlighted elements). After cutting out the first copy of t the array s can look like [1, 3, 2, 4].
* To cut out the second copy of t you can use the elements [\underline{1}, \underline{3}, \underline{2}, 4]. After cutting out the second copy of t the array s will be [4].
Your task is to find such array t that you can cut out the copy of t from s maximum number of times. If there are multiple answers, you may choose any of them.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of elements in s and the desired number of elements in t, respectively.
The second line of the input contains exactly n integers s_1, s_2, ..., s_n (1 β€ s_i β€ 2 β
10^5).
Output
Print k integers β the elements of array t such that you can cut out maximum possible number of copies of this array from s. If there are multiple answers, print any of them. The required array t can contain duplicate elements. All the elements of t (t_1, t_2, ..., t_k) should satisfy the following condition: 1 β€ t_i β€ 2 β
10^5.
Examples
Input
7 3
1 2 3 2 4 3 1
Output
1 2 3
Input
10 4
1 3 1 3 10 3 7 7 12 3
Output
7 3 1 3
Input
15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1
Output
1 1
Note
The first example is described in the problem statement.
In the second example the only answer is [7, 3, 1, 3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 2.
In the third example the array t can be cut out 5 times.
Submitted Solution:
```
import math
n,k = map(int,input().strip().split())
arr = list(map(int,input().strip().split()))
mp = {}
for i in range(n):
if arr[i] not in mp:
mp[arr[i]]=1
else:
mp[arr[i]]+=1
z = []
for x in mp:
z.append([mp[x],x])
#print(z)
z = sorted(z,reverse=True)
#print(z)
ans = []
if k <= len(z):
las = k-1
else:
las = len(z)-1
mas = 0
if k<= len(z):
ans.append(z[0][1])
j = 0
c = 1
while c<k:
if z[mas][0]//2 >= z[las][0]:
ans.append(z[mas][1])
z[mas][0]=z[mas][0]//2
las-=1
else:
ans.append(z[mas+1][1])
mas+=1
c+=1
else:
ans.append(z[0][1])
j = 0
c = 1
while c<k:
if mas==las:
las = las+1
z.append([0,0])
if z[mas][0]//2 > z[las][0]:
if len(ans)!=1 or ans[len(ans)-2]!=z[mas][1]:
ans.append(z[mas][1])
c+=1
if c<k:
ans.append(z[mas][1])
c+=1
z[mas][0]=math.ceil(z[mas][0]/2)
if (k<=len(z)):
las-=1
else:
ans.append(z[mas+1][1])
mas+=1
c+=1
#print(ans)
print(*ans)
``` | instruction | 0 | 51,333 | 12 | 102,666 |
No | output | 1 | 51,333 | 12 | 102,667 |
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 s consisting of n integers.
You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.
Cutting out the copy of t means that for each element t_i of array t you have to find t_i in s and remove it from s. If for some t_i you cannot find such element in s, then you cannot cut out one more copy of t. The both arrays can contain duplicate elements.
For example, if s = [1, 2, 3, 2, 4, 3, 1] and k = 3 then one of the possible answers is t = [1, 2, 3]. This array t can be cut out 2 times.
* To cut out the first copy of t you can use the elements [1, \underline{2}, 3, 2, 4, \underline{3}, \underline{1}] (use the highlighted elements). After cutting out the first copy of t the array s can look like [1, 3, 2, 4].
* To cut out the second copy of t you can use the elements [\underline{1}, \underline{3}, \underline{2}, 4]. After cutting out the second copy of t the array s will be [4].
Your task is to find such array t that you can cut out the copy of t from s maximum number of times. If there are multiple answers, you may choose any of them.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of elements in s and the desired number of elements in t, respectively.
The second line of the input contains exactly n integers s_1, s_2, ..., s_n (1 β€ s_i β€ 2 β
10^5).
Output
Print k integers β the elements of array t such that you can cut out maximum possible number of copies of this array from s. If there are multiple answers, print any of them. The required array t can contain duplicate elements. All the elements of t (t_1, t_2, ..., t_k) should satisfy the following condition: 1 β€ t_i β€ 2 β
10^5.
Examples
Input
7 3
1 2 3 2 4 3 1
Output
1 2 3
Input
10 4
1 3 1 3 10 3 7 7 12 3
Output
7 3 1 3
Input
15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1
Output
1 1
Note
The first example is described in the problem statement.
In the second example the only answer is [7, 3, 1, 3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 2.
In the third example the array t can be cut out 5 times.
Submitted Solution:
```
n,k = map(int,input().strip().split())
arr = list(map(int,input().strip().split()))
mp = {}
for i in range(n):
if arr[i] not in mp:
mp[arr[i]]=1
else:
mp[arr[i]]+=1
z = []
for x in mp:
z.append([mp[x],x])
#print(z)
z = sorted(z,reverse=True)
#print(z)
ans = []
if k <= len(z):
las = k-1
else:
las = len(z)-1
mas = 0
if k<= len(z):
ans.append(z[0][1])
j = 0
c = 1
while c<k:
if z[mas][0]//2 >= z[las][0]:
ans.append(z[mas][1])
z[mas][0]=z[mas][0]//2
las-=1
else:
ans.append(z[mas+1][1])
mas+=1
c+=1
else:
ans.append(z[0][1])
j = 0
c = 1
while c<k:
if z[mas][0]//2 >= z[las][0]:
ans.append(z[mas][1])
z[mas][0]=z[mas][0]//2
if (k>len(z)):
k-=1
else:
las-=1
else:
ans.append(z[mas+1][1])
mas+=1
c+=1
print(*ans)
``` | instruction | 0 | 51,334 | 12 | 102,668 |
No | output | 1 | 51,334 | 12 | 102,669 |
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 s consisting of n integers.
You have to find any array t of length k such that you can cut out maximum number of copies of array t from array s.
Cutting out the copy of t means that for each element t_i of array t you have to find t_i in s and remove it from s. If for some t_i you cannot find such element in s, then you cannot cut out one more copy of t. The both arrays can contain duplicate elements.
For example, if s = [1, 2, 3, 2, 4, 3, 1] and k = 3 then one of the possible answers is t = [1, 2, 3]. This array t can be cut out 2 times.
* To cut out the first copy of t you can use the elements [1, \underline{2}, 3, 2, 4, \underline{3}, \underline{1}] (use the highlighted elements). After cutting out the first copy of t the array s can look like [1, 3, 2, 4].
* To cut out the second copy of t you can use the elements [\underline{1}, \underline{3}, \underline{2}, 4]. After cutting out the second copy of t the array s will be [4].
Your task is to find such array t that you can cut out the copy of t from s maximum number of times. If there are multiple answers, you may choose any of them.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5) β the number of elements in s and the desired number of elements in t, respectively.
The second line of the input contains exactly n integers s_1, s_2, ..., s_n (1 β€ s_i β€ 2 β
10^5).
Output
Print k integers β the elements of array t such that you can cut out maximum possible number of copies of this array from s. If there are multiple answers, print any of them. The required array t can contain duplicate elements. All the elements of t (t_1, t_2, ..., t_k) should satisfy the following condition: 1 β€ t_i β€ 2 β
10^5.
Examples
Input
7 3
1 2 3 2 4 3 1
Output
1 2 3
Input
10 4
1 3 1 3 10 3 7 7 12 3
Output
7 3 1 3
Input
15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1
Output
1 1
Note
The first example is described in the problem statement.
In the second example the only answer is [7, 3, 1, 3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 2.
In the third example the array t can be cut out 5 times.
Submitted Solution:
```
''' Thruth can only be found at one place - THE CODE '''
''' Copyright 2018, SATYAM KUMAR'''
from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**27) # new thread will get stack of such size
printHeap = str()
memory_constrained = False
P = 10**9+7
import sys
sys.setrecursionlimit(10000000)
class Operation:
def __init__(self, name, function, function_on_equal, neutral_value=0):
self.name = name
self.f = function
self.f_on_equal = function_on_equal
def add_multiple(x, count):
return x * count
def min_multiple(x, count):
return x
def max_multiple(x, count):
return x
sum_operation = Operation("sum", sum, add_multiple, 0)
min_operation = Operation("min", min, min_multiple, 1e9)
max_operation = Operation("max", max, max_multiple, -1e9)
class SegmentTree:
def __init__(self,
array,
operations=[sum_operation, min_operation, max_operation]):
self.array = array
if type(operations) != list:
raise TypeError("operations must be a list")
self.operations = {}
for op in operations:
self.operations[op.name] = op
self.root = SegmentTreeNode(0, len(array) - 1, self)
def query(self, start, end, operation_name):
if self.operations.get(operation_name) == None:
raise Exception("This operation is not available")
return self.root._query(start, end, self.operations[operation_name])
def summary(self):
return self.root.values
def update(self, position, value):
self.root._update(position, value)
def update_range(self, start, end, value):
self.root._update_range(start, end, value)
def __repr__(self):
return self.root.__repr__()
class SegmentTreeNode:
def __init__(self, start, end, segment_tree):
self.range = (start, end)
self.parent_tree = segment_tree
self.range_value = None
self.values = {}
self.left = None
self.right = None
if start == end:
self._sync()
return
self.left = SegmentTreeNode(start, start + (end - start) // 2,
segment_tree)
self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end,
segment_tree)
self._sync()
def _query(self, start, end, operation):
if end < self.range[0] or start > self.range[1]:
return None
if start <= self.range[0] and self.range[1] <= end:
return self.values[operation.name]
self._push()
left_res = self.left._query(start, end,
operation) if self.left else None
right_res = self.right._query(start, end,
operation) if self.right else None
if left_res is None:
return right_res
if right_res is None:
return left_res
return operation.f([left_res, right_res])
def _update(self, position, value):
if position < self.range[0] or position > self.range[1]:
return
if position == self.range[0] and self.range[1] == position:
self.parent_tree.array[position] = value
self._sync()
return
self._push()
self.left._update(position, value)
self.right._update(position, value)
self._sync()
def _update_range(self, start, end, value):
if end < self.range[0] or start > self.range[1]:
return
if start <= self.range[0] and self.range[1] <= end:
self.range_value = value
self._sync()
return
self._push()
self.left._update_range(start, end, value)
self.right._update_range(start, end, value)
self._sync()
def _sync(self):
if self.range[0] == self.range[1]:
for op in self.parent_tree.operations.values():
current_value = self.parent_tree.array[self.range[0]]
if self.range_value is not None:
current_value = self.range_value
self.values[op.name] = op.f([current_value])
else:
for op in self.parent_tree.operations.values():
result = op.f(
[self.left.values[op.name], self.right.values[op.name]])
if self.range_value is not None:
bound_length = self.range[1] - self.range[0] + 1
result = op.f_on_equal(self.range_value, bound_length)
self.values[op.name] = result
def _push(self):
if self.range_value is None:
return
if self.left:
self.left.range_value = self.range_value
self.right.range_value = self.range_value
self.left._sync()
self.right._sync()
self.range_value = None
def __repr__(self):
ans = "({}, {}): {}\n".format(self.range[0], self.range[1],
self.values)
if self.left:
ans += self.left.__repr__()
if self.right:
ans += self.right.__repr__()
return ans
def display(string_to_print):
stdout.write(str(string_to_print) + "\n")
def primeFactors(n): #n**0.5 complex
factors = dict()
for i in range(2,math.ceil(math.sqrt(n))+1):
while n % i== 0:
if i in factors:
factors[i]+=1
else: factors[i]=1
n = n // i
if n>2:
factors[n]=1
return (factors)
def isprime(n):
"""Returns True if n is prime."""
if n < 4:
return True
if n % 2 == 0:
return False
if n % 3 == 0:
return False
i = 5
w = 2
while i * i <= n:
if n % i == 0:
return False
i += w
w = 6 - w
return True
def test_print(*args):
if testingMode:
print(args)
def display_list(list1, sep=" "):
stdout.write(sep.join(map(str, list1)) + "\n")
def get_int():
return int(stdin.readline().strip())
def get_tuple():
return map(int, stdin.readline().split())
def get_list():
return list(map(int, stdin.readline().split()))
memory = dict()
def clear_cache():
global memory
memory = dict()
def cached_fn(fn, *args):
global memory
if args in memory:
return memory[args]
else:
result = fn(*args)
memory[args] = result
return result
# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
testingMode = False
optimiseForReccursion = False #Can not be used clubbed with TestCases
def sortingfunc(n):
global counts
return counts[n]
counts = 0
def main():
global counts
n,k = get_tuple()
li = get_list()
counts = Counter(li)
keys = list(counts.keys())
keys.sort(key=sortingfunc,reverse=True)
max_possible = sum(counts[i] for i in range(k))//k + 1
for i in range(max_possible,0,-1):
c = 0
for ki in keys:
c+=counts[ki]//i
if c==k:
#print(i)
break
res = []
for j in keys:
res+=[j]*(counts[j]//i)
if len(res)>k: break
#print(res,k)
display_list(res[:k])
# --------------------------------------------------------------------- END
if TestCases:
for _ in range(get_int()):
cProfile.run('main()') if testingMode else main()
else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()
``` | instruction | 0 | 51,335 | 12 | 102,670 |
No | output | 1 | 51,335 | 12 | 102,671 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again. | instruction | 0 | 51,394 | 12 | 102,788 |
Tags: implementation, math
Correct Solution:
```
import sys
n = int(input())
orig = [(int(x),i) for i,x in enumerate(input().split())]
A = sorted(orig)
n = len(A)
if n == 2:
print(1)
sys.exit()
diffs = []
for i in range(1,n):
diffs.append(A[i][0]-A[i-1][0])
diffs = set(diffs)
if len(diffs) > 3:
print(-1)
sys.exit()
def inc(d,A):
skipped = []
last = A[0][0]
for ii in range(1,len(A)):
a,i = A[ii]
if a - last != d:
skipped.append(i)
if len(skipped) >= 2:
return None
else:
last = a
return skipped[0] if skipped else A[0][1]
revA = A[::-1]
def dec(d,A):
return inc(-d,revA)
for d in diffs:
i = inc(d,A)
if i != None:
print(i + 1)
sys.exit()
i = dec(d,revA)
if i != None:
print(i + 1)
sys.exit()
print(-1)
``` | output | 1 | 51,394 | 12 | 102,789 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again. | instruction | 0 | 51,395 | 12 | 102,790 |
Tags: implementation, math
Correct Solution:
```
import sys
input = sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
B=sorted(A)
if len(B)<=3:
print(1)
sys.exit()
x=B[2]-B[1]
for i in range(2,n):
if B[i]-B[i-1]==x:
continue
else:
break
else:
print(A.index(B[0])+1)
sys.exit()
y=B[2]-B[0]
for i in range(3,n):
if B[i]-B[i-1]==y:
continue
else:
break
else:
print(A.index(B[1])+1)
sys.exit()
z=B[1]-B[0]
ANS=[]
i=2
while i<n:
if B[i]-B[i-1]!=z:
if i<n-1 and B[i+1]-B[i-1]==z:
ANS.append(i)
i+=2
elif i==n-1:
ANS.append(i)
i+=1
else:
print(-1)
sys.exit()
else:
i+=1
if len(ANS)>1:
print(-1)
sys.exit()
print(A.index(B[ANS[0]])+1)
``` | output | 1 | 51,395 | 12 | 102,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again. | instruction | 0 | 51,396 | 12 | 102,792 |
Tags: implementation, math
Correct Solution:
```
n = int(input())
A = list(map(int, input().split()))
if n == 2:
print(1)
exit(0)
elif n == 3:
print(1)
exit(0)
M = []
for i in range(n):
A[i] = [A[i], i + 1]
A.sort()
for i in range(n - 1):
M.append(A[i + 1][0] - A[i][0])
if len(set(M[1:])) == 1:
print(A[0][1])
exit(0)
if len(set(M[:-1])) == 1:
print(A[-1][1])
exit(0)
g = {}
for i in M:
if i not in g:
g[i] = 0
g[i] += 1
for k in g:
if g[k] >= n - 3:
q = []
for j in range(n - 1):
if M[j] != k:
q.append([M[j], j])
if len(q) == 1:
if q[0][0] == 0:
print(A[q[0][1]][1])
exit(0)
if len(q) == 2:
a, b = q[0], q[1]
if a[0] + b[0] == k:
if abs(a[1] - b[1]) == 1:
print(A[a[1] + 1][1])
exit(0)
print(-1)
``` | output | 1 | 51,396 | 12 | 102,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again. | instruction | 0 | 51,397 | 12 | 102,794 |
Tags: implementation, math
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
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")
#-------------------game starts now-----------------------------------------------------
n=int(input())
b=list(map(int,input().split()))
a=list()
for i in range (n):
a.append((b[i],i+1))
a.sort()
s=set()
d=list()
dc=dict()
for i in range (1,n):
diff=a[i][0]-a[i-1][0]
if diff in dc:
dc[diff]+=1
else:
dc[diff]=1
if diff in s:
continue
s.add(diff)
d.append(diff)
if len(s)==1 or n<=3:
print(a[-1][1])
elif len(s)>3:
print(-1)
elif len(s)==2:
d.sort()
if dc[d[0]]==1 or dc[d[1]]==1:
if dc[d[0]]==1:
f=d[0]
else:
f=d[1]
if a[1][0]-a[0][0]==f:
print(a[0][1])
elif a[n-1][0]-a[n-2][0]==f:
print(a[-1][1])
else:
if f==0:
ch=-1
for i in range (1,n):
if a[i][0]==a[i-1][0]:
ch=a[i][1]
break
print(ch)
else:
print(-1)
elif dc[d[0]]==2 and 2*d[0]==d[1]:
ch=-1
for i in range (1,n-1):
if a[i][0]-a[i-1][0]==a[i+1][0]-a[i][0]==d[0]:
ch=a[i][1]
break
print(ch)
else:
print(-1)
else:
d.sort()
if d[0]+d[1]!=d[2]:
print(-1)
else:
if dc[d[0]]==dc[d[1]]==1:
ch=-1
for i in range (1,n-1):
if (a[i][0]-a[i-1][0]==d[0] and a[i+1][0]-a[i][0]==d[1]) or (a[i][0]-a[i-1][0]==d[1] and a[i+1][0]-a[i][0]==d[0]):
ch=a[i][1]
break
print(ch)
``` | output | 1 | 51,397 | 12 | 102,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again. | instruction | 0 | 51,398 | 12 | 102,796 |
Tags: implementation, math
Correct Solution:
```
import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
# sys.setrecursionlimit(200000)
# mod = 10**9+7
# mod = 998244353
decimal.getcontext().prec = 46
def primeFactors(n):
prime = set()
while n % 2 == 0:
prime.add(2)
n = n//2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
prime.add(i)
n = n//i
if n > 2:
prime.add(n)
return list(prime)
def getFactors(n) :
factors = []
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n // i == i) :
factors.append(i)
else :
factors.append(i)
factors.append(n//i)
i = i + 1
return factors
def modefiedSieve():
mx=10**7+1
sieve=[-1]*mx
for i in range(2,mx):
if sieve[i]==-1:
sieve[i]=i
for j in range(i*i,mx,i):
if sieve[j]==-1:
sieve[j]=i
return sieve
def SieveOfEratosthenes(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
num = []
for p in range(2, n+1):
if prime[p]:
num.append(p)
return num
def lcm(a,b):
return (a*b)//math.gcd(a,b)
def sort_dict(key_value):
return sorted(key_value.items(), key = lambda kv:(kv[1], kv[0]))
def list_input():
return list(map(int,input().split()))
def num_input():
return map(int,input().split())
def string_list():
return list(input())
def decimalToBinary(n):
return bin(n).replace("0b", "")
def binaryToDecimal(n):
return int(n,2)
def DFS(n,s,adj):
visited = [False for i in range(n+1)]
stack = []
stack.append(s)
while (len(stack)):
s = stack[-1]
stack.pop()
if (not visited[s]):
visited[s] = True
for node in adj[s]:
if (not visited[node]):
stack.append(node)
def maxSubArraySum(a,size):
maxint = 10**10
max_so_far = -maxint - 1
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far
def solve():
n = int(input())
arr = list_input()
position = {}
for i in range(n):
position[arr[i]] = i
arr.sort()
flag = True
prev = -1
ans = position[arr[-1]]+1
for i in range(n-1):
if arr[i] == '.':
continue
diff = arr[i+1]-arr[i]
if prev == -1:
prev = diff
continue
if prev != diff:
if i+1 == n-1:
if flag:
print(position[arr[i+1]]+1)
else:
print(-1)
return
if flag:
flag = False
if arr[i+2]-arr[i] == prev:
ans = position[arr[i+1]]+1
arr[i+1] = '.'
elif diff == arr[i+2]-arr[i+1]:
if i-2 <= 0:
if i-2 == 0:
if diff == arr[i]-arr[i-2]:
ans = position[arr[i-1]]+1
prev = diff
else:
print(-1)
return
else:
ans = position[arr[i-1]]+1
prev = diff
else:
print(-1)
return
elif arr[i+2]-arr[i+1] == arr[i+1]-arr[i-1]:
ans = position[arr[i]]+1
prev = arr[i+2]-arr[i+1]
else:
print(-1)
return
else:
print(-1)
return
print(ans)
t = 1
#t = int(input())
for _ in range(t):
solve()
``` | output | 1 | 51,398 | 12 | 102,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again. | instruction | 0 | 51,399 | 12 | 102,798 |
Tags: implementation, math
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
a[i] = (a[i],i)
a=sorted(a)
if n <= 3:
print(1)
exit()
diffs = {}
for i in range(1,n):
d = a[i][0] - a[i-1][0]
if d not in diffs:
diffs[d]=1
else:
diffs[d] += 1
commonDiff = 0
times = 0
for k,v in diffs.items():
if v > times:
times=v
commonDiff=k
if times < n-3:
print(-1)
exit()
if n <= 5:
commonDiff = -12345568989977
possible = [0]
for i in range(1,n):
if a[i][0]-a[i-1][0] != commonDiff:
possible.append(i)
for k in possible:
diffs = {}
last = a[0][0]
if k == 0:
last=a[1][0]
start=1
if k==0:
start=2
for i in range(start,n):
if i == k:
continue
d = a[i][0] - last
if d not in diffs:
diffs[d]=1
else:
diffs[d] += 1
last = a[i][0]
if len(diffs) == 1:
print(a[k][1]+1)
exit()
print(-1)
``` | output | 1 | 51,399 | 12 | 102,799 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again. | instruction | 0 | 51,400 | 12 | 102,800 |
Tags: implementation, math
Correct Solution:
```
def is_d(a):
d = a[1] - a[0]
for i in range(len(a) - 1):
if a[i] + d != a[i + 1]:
return False
return True
n = int(input())
a = list(map(int, input().split()))
a_s = sorted(a)
if is_d(a_s) or is_d(a_s[1:]):
print(a.index(a_s[0]) + 1)
exit()
if is_d([a_s[0]] + a_s[2:]):
print(a.index(a_s[1]) + 1)
exit()
d = a_s[1] - a_s[0]
c = False
for i in range(len(a_s) - 1):
if a_s[i] + d != a_s[i + 1]:
c = i + 1
break
if is_d(a_s[:c] + a_s[c + 1:]):
print(a.index(a_s[c]) + 1)
else:
print(-1)
``` | output | 1 | 51,400 | 12 | 102,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again. | instruction | 0 | 51,401 | 12 | 102,802 |
Tags: implementation, math
Correct Solution:
```
n = int(input())
B = [int(x) for x in input().split()]
A = sorted(B)
Diff = []
for i in range(n-1):
Diff.append(A[i+1]-A[i])
if n == 2:
print(1)
else:
ANSWER = 'hehe'
firstworks = True
for i in range(1,n-2):
if Diff[i] != Diff[i+1]:
firstworks = False
if firstworks:
ANSWER = A[0]
else:
secondworks = True
if A[2]-A[0] == Diff[2]:
for i in range(n-4):
if Diff[i+2] != Diff[i+3]:
secondworks = False
else:
secondworks = False
if secondworks:
ANSWER = A[1]
else:
dif = A[1]-A[0]
T = []
for i in range(n-1):
if Diff[i] != dif:
T.append((Diff[i],i))
if len(T) >= 3:
ANSWER = 'hehe'
elif len(T) == 2:
if T[1][1]-T[0][1] == 1 and T[1][0]+T[0][0] == dif:
ANSWER = A[T[0][1]+1]
else:
ANSWER = 'hehe'
elif len(T) == 1:
if T[0][1] == n-2:
ANSWER = A[n-1]
else:
ANSWER = 'hehe'
else:
ANSWER = A[n-1]
if ANSWER == 'hehe':
print(-1)
else:
for i in range(n):
if B[i] == ANSWER:
print(i+1)
break
``` | output | 1 | 51,401 | 12 | 102,803 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again.
Submitted Solution:
```
n = int(input())
brr = list(map(int,input().split()))
arr = []
for i in range(n):
arr.append([brr[i],i])
arr.sort()
d = [-1,-1,-1]
ind = [-1,-1,-1]
for i in range(1,n):
x = arr[i][0]-arr[i-1][0]
if x==d[0] or d[0]==-1:
d[0] = x
ind[0] = i
elif x == d[1] or d[1] == -1:
d[1] = x
ind[1] = i
elif x == d[2] or d[2] == -1:
d[2] = x
ind[2] = i
def func(ans):
temp = set()
for i in range(1,len(ans)):
temp.add(ans[i][0]-ans[i-1][0])
f = False
# print(temp)
if len(temp)==1:
f = True
return not temp or f
f = 0
for i in ind:
x = arr[:i]+arr[i+1:]
y = arr[:i-1]+arr[i::]
ans1 = func(x)
ans2 = func(y)
if ans1==True:
f = 1
print(arr[i][1]+1)
break
elif ans2==True:
f = 1
print(arr[i-1][1]+1)
break
if f==0:
print(-1)
``` | instruction | 0 | 51,402 | 12 | 102,804 |
Yes | output | 1 | 51,402 | 12 | 102,805 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again.
Submitted Solution:
```
import math
import bisect
import heapq
from collections import defaultdict
def egcd(a, b):
if a == 0:
return (b, 0, 1)
else:
g, x, y = egcd(b % a, a)
return (g, y - (b // a) * x, x)
def mulinv(b, n):
g, x, _ = egcd(b, n)
if g == 1:
return x % n
def isprime(n):
for d in range(2, int(math.sqrt(n))+1):
if n % d == 0:
return False
return True
def argsort(ls):
return sorted(range(len(ls)), key=ls.__getitem__)
def f(p=0):
if p == 1:
return map(int, input().split())
elif p == 2:
return list(map(int, input().split()))
elif p == 3:
return list(input())
else:
return int(input())
class DisjointSet:
def __init__(self, n):
self.parent = [i for i in range(1, n+1)]
self.rank = [0]*(n+1)
def find_set(self, x):
if self.parent[x] == x:
return x
else:
self.parent[x] = self.find_set(self.parent[x])
return self.parent[x]
def union(self, x, y):
set_x = self.find_set(x)
set_y = self.find_set(y)
if set_x!=set_y:
if self.rank[x]:
pass
def graph(n, m, edg=False):
edges = []
visited = [0]*n
g = [list() for _ in range(n+1)]
for i in range(m):
u, v = f(1)
g[u].append(v)
g[v].append(u)
if edg:
edges.append((u, v))
if edg:
return g, visited, edg
else:
return g, visited
def bfs(g, visited):
queue = [1]
visited[1] = 1
for u in queue:
for v in g[u]:
if visited[v] == 0:
queue.append(v)
visited[v] = 1
def dfs(u, g, visited):
visited[u] = 1
for v in g[u]:
if visited[v] == 0:
dfs(v, g, visited)
n = f()
scl = f(2)
cl = sorted(scl)
if n<4:
print(1)
else:
a = cl[-1] - cl[1]
d = int(a/(n-2))
if d == a/(n-2):
st = True
for i in range(1, n-1):
if cl[i+1]-cl[i]!=d:
st = False
break
if st:
mn = cl[0]
for i in range(n):
if scl[i]==mn:
print(i+1)
exit()
a = cl[n-2] - cl[0]
d = int(a / (n - 2))
if d == a / (n - 2):
st = True
for i in range(n - 2):
if cl[i + 1] - cl[i] != d:
st = False
break
if st:
mn = cl[-1]
for i in range(n):
if scl[i] == mn:
print(i + 1)
exit()
a = cl[-1] - cl[0]
d = int(a / (n - 2))
pos = -10**10
if d == a / (n - 2):
st = True
i = 0
while(i<n-1):
if cl[i + 1] - cl[i] != d:
if not st:
print(-1)
exit()
else:
if i==n-2 or cl[i+2]-cl[i]==d:
st = False
pos = cl[i+1]
i+=1
else:
print(-1)
exit()
i+=1
if pos!=-10**10:
for i in range(n):
if scl[i]==pos:
print(i+1)
exit()
print(-1)
exit()
``` | instruction | 0 | 51,403 | 12 | 102,806 |
Yes | output | 1 | 51,403 | 12 | 102,807 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again.
Submitted Solution:
```
import sys
def checkIsAP(arr, n):
if (n == 1): return True
# Sort array
arr.sort()
# After sorting, difference between
# consecutive elements must be same.
d = arr[1] - arr[0]
for i in range(2, n):
if (arr[i] - arr[i-1] != d):
return False
return True
n=int(input())
l=list(map(int,input().split()))
cop=[l[i] for i in range(n)]
it=l.index(max(l))
it1=l.index(min(l))
l.sort()
if checkIsAP(l[1:],n-1)==True:
print(it1+1)
sys.exit()
elif checkIsAP(l[:n],n-1)==True:
print(it+1)
sys.exit()
elif checkIsAP(l,n)==True:
print(1)
sys.exit()
dif=[0]*(n-1)
ci=[0]*(n-1)
for i in range(n-1):
dif[i]=l[i+1]-l[i]
ci[i]=dif[i]
dif.sort()
count=dif.count(dif[n//2])
if count==n-3:
su=0
e=[]
for j in range(n-1):
if dif[j]!=dif[n//2]:
su+=dif[j]
e.append(dif[j])
#print(e,ci)
if su==dif[n//2]:
ind=0
for j in range(n-2):
if ci[j]==e[0] and ci[j+1]==e[1]:
ind=j+1
break
if ci[j]==e[1] and ci[j+1]==e[0]:
ind=j+1
break
ind=cop.index(l[ind])
print(ind+1)
else:
print(-1)
elif count==n-2 and dif.count(0)==1:
for j in range(n-2):
if ci[j]==0:
ind=j+1
break
ind=cop.index(l[ind])
print(ind+1)
else:
print(-1)
``` | instruction | 0 | 51,404 | 12 | 102,808 |
Yes | output | 1 | 51,404 | 12 | 102,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again.
Submitted Solution:
```
from copy import deepcopy
n = int(input())
a = list(map(int, input().split()))
a=[(a[i],i) for i in range(n)]
a.sort(key=lambda x:x[0])
diff = {}
for i in range(1, len(a)):
if a[i][0]-a[i-1][0] not in diff:
diff[a[i][0]-a[i-1][0]]=0
diff[a[i][0] - a[i - 1][0]] +=1
# print(diff)
if len(diff) == 1:
print(a[0][1]+1)
elif len(diff) > 3:
print(-1)
else:
ind = -1
for i in range(0, len(a)):
temp = deepcopy(diff)
if i == 0:
temp[a[i + 1][0] - a[i][0]]-=1
if temp[a[i + 1][0] - a[i][0]]==0:
del temp[a[i + 1][0] - a[i][0]]
if len(temp) == 1:
ind = a[i][1]+1
break
elif i == n - 1:
temp[a[i][0] - a[i - 1][0]]-=1
if temp[a[i][0] - a[i - 1][0]]==0:
del temp[a[i][0] - a[i - 1][0]]
if len(temp) == 1:
ind = a[i][1]+1
break
else:
temp[a[i][0] - a[i - 1][0]]-=1
temp[a[i + 1][0] - a[i][0]] -= 1
if temp[a[i + 1][0] - a[i][0]]==0:
del temp[a[i + 1][0] - a[i][0]]
if a[i][0] - a[i - 1][0] in temp and temp[a[i][0] - a[i - 1][0]]==0:
del temp[a[i][0] - a[i - 1][0]]
if a[i+1][0]-a[i-1][0] not in temp:
temp[a[i+1][0]-a[i-1][0]]=0
temp[a[i + 1][0] - a[i - 1][0]]+=1
if len(temp) == 1:
ind = a[i][1]+1
break
print(ind)
``` | instruction | 0 | 51,405 | 12 | 102,810 |
Yes | output | 1 | 51,405 | 12 | 102,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again.
Submitted Solution:
```
from operator import itemgetter
import sys
input = sys.stdin.readline
def main():
N = int(input())
B = list(map(int, input().split()))
A = []
for i, b in enumerate(B):
A.append((i+1, b))
A.sort(key=itemgetter(1))
a0, a1 = A[0][1], A[1][1]
A1 = [a0+(a1-a0)*j for j in range(N-1)]
dif = []
i = 0
j = 0
ok = True
while i < N and j < N-1:
if A[i][1] == A1[j]:
i += 1
j += 1
elif A[i+1][1] == A1[j]:
dif.append(A[i][0])
i += 1
else:
ok = False
break
if i != j and i != j+1:
ok = False
break
if ok:
if len(dif) == 1:
print(dif[0])
return
elif len(dif) == 0:
print(A[0][0])
return
a1, a2 = A[1][1], A[2][1]
A2 = [a1+(a2-a1)*(j-1) for j in range(N)]
ok = True
for i in range(1, N):
if A[i][1] != A2[i]:
ok = False
break
if ok:
print(A[0][0])
return
ok = True
d = (a2-a0)//2
if (a2-a0)%2 != 0:
ok = False
else:
A3 = [a0+d*j for j in range(N)]
for j in range(2, N):
if A[j][1] != A3[j]:
ok = False
break
if ok:
print(A[1][0])
return
print(-1)
if __name__ == "__main__":
main()
``` | instruction | 0 | 51,406 | 12 | 102,812 |
No | output | 1 | 51,406 | 12 | 102,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again.
Submitted Solution:
```
N = int(input())
arr = input()
arr = [int(x) for x in arr.split(' ')]
cp = list(arr)
arr.sort()
res = -1
#check if first element should be deleted
tmp = arr[1:]
diff = {}
count = 0
for i in range(1,len(tmp)):
d = tmp[i] - tmp[i-1]
if d not in diff:
count += 1
if count>1:
break
diff[d] = 1
#print('phase 1',count)
if count==1 or len(arr)==2:
res = 1
print(res)
#if last element should be deleted
if res==-1:
tmp = arr[:(N-1)]
diff = {}
count = 0
for i in range(1,len(tmp)):
d = tmp[i] - tmp[i-1]
if d not in diff:
count += 1
if count>1:
break
diff[d] = 1
#print('phase 2',count)
if count==1:
res = N-1
print(res)
#if one element should be deleted
if res==-1:
head = arr[0]
tail = arr[-1]
if (tail-head)%(N-2)!=0:
print(-1)
else:
d = (tail-head)//(N-2)
s = arr[0]
flag = 0
target = 11111111111111
for i in range(1,N):
s += d
if s!=arr[i] and flag==0:
#print(arr[i])
flag += 1
target = arr[i]
s -= d
elif flag==1 and s!=arr[i]:
flag += 1
print(-1)
break
if flag==1:
for i in range(N):
if cp[i]==target:
print(i+1)
break
``` | instruction | 0 | 51,407 | 12 | 102,814 |
No | output | 1 | 51,407 | 12 | 102,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again.
Submitted Solution:
```
from collections import Counter
input()
dic = {}
nums = list(map(int, input().split()))
for idx,num in enumerate(nums):
dic[num] = idx+1
nums.sort()
prefix = []
for i in range(len(nums)-1):
prefix.append(nums[i+1] - nums[i])
c = Counter(prefix)
if len(c) > 3:
print(-1)
exit(0)
elif len(c) == 1:
print(1)
exit(0)
pos = []
standard = c.most_common(1)[0][0]
for idx,pre in enumerate(prefix):
if pre != standard:
pos.append(idx)
if len(pos) > 2:
print(-1)
elif len(pos) == 1:
if pos[0] == 0:
print(dic[nums[0]])
elif pos[0] == len(prefix)-1:
print(dic[nums[-1]])
elif prefix[pos[0]] + prefix[pos[1]] == standard and pos[0] +1 == pos[1]:
print(dic[nums[pos[1]]])
else:
print(-1)
``` | instruction | 0 | 51,408 | 12 | 102,816 |
No | output | 1 | 51,408 | 12 | 102,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A sequence a_1, a_2, ..., a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c β
(i - 1) for some fixed c.
For example, these five sequences are arithmetic progressions: [5, 7, 9, 11], [101], [101, 100, 99], [13, 97] and [5, 5, 5, 5, 5]. And these four sequences aren't arithmetic progressions: [3, 1, 2], [1, 2, 4, 8], [1, -1, 1, -1] and [1, 2, 3, 3, 3].
You are given a sequence of integers b_1, b_2, ..., b_n. Find any index j (1 β€ j β€ n), such that if you delete b_j from the sequence, you can reorder the remaining n-1 elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Input
The first line of the input contains one integer n (2 β€ n β€ 2β
10^5) β length of the sequence b. The second line contains n integers b_1, b_2, ..., b_n (-10^9 β€ b_i β€ 10^9) β elements of the sequence b.
Output
Print such index j (1 β€ j β€ n), so that if you delete the j-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
Examples
Input
5
2 6 8 7 4
Output
4
Input
8
1 2 3 4 5 6 7 8
Output
1
Input
4
1 2 4 8
Output
-1
Note
Note to the first example. If you delete the 4-th element, you can get the arithmetic progression [2, 4, 6, 8].
Note to the second example. The original sequence is already arithmetic progression, so you can delete 1-st or last element and you will get an arithmetical progression again.
Submitted Solution:
```
# author: ThePonyCoder
# created: 19.06.2019, 19:34
# filename: d.py
# path: C:/Users/User/Desktop/python/Prog/CodeForces/rounds/cf_568/d.py
# import os
# import random
# import sys
# sys.setrecursionlimit(999999999)
# if os.getcwd() == 'C:\\Users\\User\\Desktop\\python\\Prog\\CodeForces' \
# or os.environ['COMPUTERNAME'] == 'RYZEN':
# import pdb
#
# pdb = pdb.Pdb(stdin=sys.stdin, stdout=sys.stdout)
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
# from pprint import pprint
# from hypothesis import given, settings
# from hypothesis import strategies as st
def ri():
return [int(i) for i in input().split()]
def main(n, t):
oldt = t.copy()
t.sort()
if (n == 2):
return 1
# random.seed('i_love_ponies')
# na = random.randrange(0,n-1)
# shg = t[na] - t[na-1]
if (n > 6):
for nf in range(4):
shg = t[nf+1] - t[nf]
for i in range(1, n):
if t[i] - t[i - 1] != shg:
nwt = t.copy()
nwt.pop(i - 1)
if check(nwt):
return oldt.index(t[i - 1]) + 1
nwt = t.copy()
nwt.pop(i)
if check(nwt):
return oldt.index(t[i]) + 1
break
else:
return 1
return -1
else:
for i in range(n):
tmp = t.copy()
tmp.pop(i)
if check(tmp):
return i + 1
return -1
def check(a):
cp = a.copy()
a.sort()
shg = a[1] - a[0]
if (shg == 0 and len(a) != 1):
return False
for i in range(len(a) - 1):
if a[i + 1] - a[i] != shg:
return False
return True
n = ri()[0]
t = ri()
print(main(n, t))
``` | instruction | 0 | 51,409 | 12 | 102,818 |
No | output | 1 | 51,409 | 12 | 102,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16]. | instruction | 0 | 51,410 | 12 | 102,820 |
Tags: greedy, math
Correct Solution:
```
n,l,r = input().split()
n = int(n)
l = int(l)
r = int(r)
# print(type(n))
# a = []
count = n
summ = 0
j = 1
while l>0 :
summ = summ+j
l = l-1
count = count-1
j = j*2
while count>0:
summ = summ+1
count = count-1
# print(a)
# print(sum(a))
# b = []
sumb = 0
count = n
j=1
while r>0:
sumb = sumb+j
r=r-1
count=count-1
j=j*2
j = j//2
while count>0:
sumb = sumb+j
count = count-1
# print(b)
print(summ,sumb)
``` | output | 1 | 51,410 | 12 | 102,821 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16]. | instruction | 0 | 51,411 | 12 | 102,822 |
Tags: greedy, math
Correct Solution:
```
n, l, r = map(int,input().strip().split())
ansa = ((2**l)-1)+(n-l)
ansb = ((2**r)-1)+(n-r)*(2**(r-1))
print('%d %d' % (ansa, ansb))
``` | output | 1 | 51,411 | 12 | 102,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16]. | instruction | 0 | 51,412 | 12 | 102,824 |
Tags: greedy, math
Correct Solution:
```
import math
n,l,r=input().split()
n=int(n)
l=int(l)
r=int(r)
l=l-1
r=r-1
ls=[]
rs=[]
d=1
for i in range(n-l):
ls.append(d)
for i in range(l):
j=int(math.pow(2,i+1))
ls.append(j)
rs.append(d)
for i in range(r):
j=int(math.pow(2,i+1))
rs.append(j)
for i in range(n-(r+1)):
if r==0:
j=1
rs.append(j)
print(sum(ls),end=' ')
print(sum(rs))
``` | output | 1 | 51,412 | 12 | 102,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16]. | instruction | 0 | 51,413 | 12 | 102,826 |
Tags: greedy, math
Correct Solution:
```
from sys import stdin
n, l, r = [int(i) for i in stdin.readline().split(' ')]
minimum = (n-l+1) + (2*(2**(l-1) - 1))
maximum = (2**r - 1) + (n-r)*(2**(r-1))
print(str(minimum)+' '+str(maximum))
``` | output | 1 | 51,413 | 12 | 102,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16]. | instruction | 0 | 51,414 | 12 | 102,828 |
Tags: greedy, math
Correct Solution:
```
def naiveSolve(n):
return
def main():
n,l,r=readIntArr()
ans1=0
sameElements=n-l+1
ans1+=sameElements
x=2
for _ in range(l-1):
ans1+=x
x*=2
ans2=0
x=1
for _ in range(r):
ans2+=x
x*=2
x//=2
sameElements=n-r+1
ans2+=(x*(sameElements-1))
print('{} {}'.format(ans1,ans2))
return
import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
# input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.
def oneLineArrayPrint(arr):
print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
# def readFloatArr():
# return [float(x) for x in input().split()]
def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])
dv=defaultValFactory;da=dimensionArr
if len(da)==1:return [dv() for _ in range(da[0])]
else:return [makeArr(dv,da[1:]) for _ in range(da[0])]
def queryInteractive(l,r):
print('? {} {}'.format(l,r))
sys.stdout.flush()
return int(input())
def answerInteractive(x):
print('! {}'.format(x))
sys.stdout.flush()
inf=float('inf')
MOD=10**9+7
# MOD=998244353
from math import gcd,floor,ceil
for _abc in range(1):
main()
``` | output | 1 | 51,414 | 12 | 102,829 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16]. | instruction | 0 | 51,415 | 12 | 102,830 |
Tags: greedy, math
Correct Solution:
```
n,l,r=map(int,input().split())
arr=[1]*n
mini=0
maxi=0
for i in range(l):
mini+=2**i
mini+=n-l
for i in range(r):
maxi+=2**i
maxi+=(n-r)*(2**i)
print(mini,maxi)
``` | output | 1 | 51,415 | 12 | 102,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16]. | instruction | 0 | 51,416 | 12 | 102,832 |
Tags: greedy, math
Correct Solution:
```
#import sys
#import math
#sys.stdout=open("C:/Users/pipal/OneDrive/Desktop/VS code/python/output.txt","w")
#sys.stdin=open("C:/Users/pipal/OneDrive/Desktop/VS code/python/input.txt","r")
#t=int(input())
#for i in range(t):
#n=int(input())
n,l,r=(map(int,input().split()))
mini=[]
maxi=[]
maxi.append(1)
for i in range(l-1):
mini.append(2**(i+1))
#print(mini+(n-(l-1))*1,end=" ")
for i in range(r-1):
maxi.append(2**(i+1))
print(sum(mini)+n-(l-1),end=" ")
print(sum(maxi)+maxi[len(maxi)-1]*(n-r))
``` | output | 1 | 51,416 | 12 | 102,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16]. | instruction | 0 | 51,417 | 12 | 102,834 |
Tags: greedy, math
Correct Solution:
```
n, l, r = map(int, input().split())
# lambda functions
min_elements = list(map(lambda x: 2**x, range(l)))
max_elements = list(map(lambda x: 2**x, range(r)))
"""
Correct answer but trying another approach
"""
# print(f"{sum(min_elements)+(n-l+1)}", end=" ")
#
# if n == r:
# print(f"{sum(max_elements)+1}")
# else:
# a = []
# if max_elements: # list null check
# a = [max_elements[-1]] * (n-r)
#
# print(f"{sum(max_elements) + sum(a) + (n-(len(max_elements)+ len(a)))}")
print(f"{sum(min_elements)+(n-l)}", end=" ")
print(f"{sum(max_elements)+(2 ** (r - 1) * (n - r))}")
``` | output | 1 | 51,417 | 12 | 102,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].
Submitted Solution:
```
n,l,r=map(int,input().split())
a=n-l+1
b=0
for i in range(1,l):
a=a+(2**i)
for j in range(r-1):
b=b+(2**j)
for j in range(n-r+1):
b=b+(2**(r-1))
print(a, b)
``` | instruction | 0 | 51,418 | 12 | 102,836 |
Yes | output | 1 | 51,418 | 12 | 102,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].
Submitted Solution:
```
n,l,r = map(int,input().split())
l1 = [1]
m1 = 1
for i in range(l-1):
m1=m1*2
l1.append(m1)
m2 = sum(l1)
m2+=n-len(l1)
for i in range(r-l):
m1 = m1*2
l1.append(m1)
m3 = sum(l1)
m3 += l1[-1]*(n-len(l1))
print(m2,m3)
``` | instruction | 0 | 51,419 | 12 | 102,838 |
Yes | output | 1 | 51,419 | 12 | 102,839 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].
Submitted Solution:
```
list=[int(x) for x in input().split()]
n=list[0]
min1=list[1]
max1=list[2]
p=[]
sum1=0
for i in range(0,min1):
p.append(2**i)
sum1+=p[i]
cnt1=n-len(p)
resmin=sum1+cnt1*1
q=[]
sum2=0
for i in range(0,max1):
q.append(2**i)
sum2+=q[i]
cnt2=n-len(q)
resmax=sum2+cnt2*max(q)
print(resmin,resmax)
``` | instruction | 0 | 51,420 | 12 | 102,840 |
Yes | output | 1 | 51,420 | 12 | 102,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].
Submitted Solution:
```
n,l,r=map(int,input().split())
min = n - l + (2**l) - 1
max = (2**(r-1))*(n-r) + 2**r - 1
print(min, max)
``` | instruction | 0 | 51,421 | 12 | 102,842 |
Yes | output | 1 | 51,421 | 12 | 102,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].
Submitted Solution:
```
n, l ,r = list(map(int, input().split()))
def min_sum(n,l,r):
s = []
for i in range(n-l+1):
s.append(1)
for i in range(n-l,n-l+r+1):
s.append(s[i-1]*2)
if len(s) == n:
break
for i in range(n-l+r+1,n):
s.append(1)
#print(s)
return sum(s)
def max_sum(n,l,r):
s = [1]
for i in range(1,r):
s.append(s[i-1]*2)
if len(s) == n:
break
for i in range(r,n):
s.append(max(s))
#print(s)
return sum(s)
print(f'{min_sum(n,l,r)} {max_sum(n,l,r)}')
``` | instruction | 0 | 51,422 | 12 | 102,844 |
No | output | 1 | 51,422 | 12 | 102,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].
Submitted Solution:
```
n,l,r=map(int,input().split())
m=sum(2**i for i in range(1,l)) + n-l+1
M=sum(2**i for i in range(r-1)) + (n-r+1)*2**(r-1)
``` | instruction | 0 | 51,423 | 12 | 102,846 |
No | output | 1 | 51,423 | 12 | 102,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].
Submitted Solution:
```
n,l,r=map(int,input().split())
if l==r:
print(n+r-1,"",n+r+1)
else:
print(n-l+1,end=" ")
s=0
for i in range(1,r):
s=s+2**i
print(s+1)
``` | instruction | 0 | 51,424 | 12 | 102,848 |
No | output | 1 | 51,424 | 12 | 102,849 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mislove had an array a_1, a_2, β
β
β
, a_n of n positive integers, but he has lost it. He only remembers the following facts about it:
* The number of different numbers in the array is not less than l and is not greater than r;
* For each array's element a_i either a_i = 1 or a_i is even and there is a number (a_i)/(2) in the array.
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2 = 8.
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
Input
The only input line contains three integers n, l and r (1 β€ n β€ 1 000, 1 β€ l β€ r β€ min(n, 20)) β an array's size, the minimal number and the maximal number of distinct elements in an array.
Output
Output two numbers β the minimal and the maximal possible sums of all elements in an array.
Examples
Input
4 2 2
Output
5 7
Input
5 1 5
Output
5 31
Note
In the first example, an array could be the one of the following: [1,1,1,2], [1,1,2,2] or [1,2,2,2]. In the first case the minimal sum is reached and in the last case the maximal sum is reached.
In the second example, the minimal sum is reached at the array [1,1,1,1,1], and the maximal one is reached at the array [1,2,4,8,16].
Submitted Solution:
```
n,l,r = map(int,input().split())
ans1 = n - l + 1
val = 2
for i in range(1,l):
ans1 +=val
val *= 2
print(ans1,end = " ")
val = 1
ans1 = 0
for i in range(0,r):
ans1 += val
val *= 2
for i in range(r+1,n):
ans1 += val
print(ans1)
``` | instruction | 0 | 51,425 | 12 | 102,850 |
No | output | 1 | 51,425 | 12 | 102,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b. | instruction | 0 | 51,569 | 12 | 103,138 |
Tags: brute force, constructive algorithms
Correct Solution:
```
cases = int(input())
for case in range(0, cases):
n = int(input())
array = [int(x) for x in input().split(" ")]
no = False
for num in array:
if num < 0:
print("No")
no = True
break
if no: continue
result = list(range(0, max(array)+1))
print("Yes")
print(len(result))
print(*result)
``` | output | 1 | 51,569 | 12 | 103,139 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b. | instruction | 0 | 51,570 | 12 | 103,140 |
Tags: brute force, constructive algorithms
Correct Solution:
```
def nice(arr, n):
if any(num < 0 for num in arr):
return 'No'
arr_distinct = set(arr)
converged = False
while not converged:
converged = True
for i in range(1, n):
for j in range(i):
absdiff = abs(arr[i] - arr[j])
if absdiff not in arr_distinct:
arr_distinct.add(absdiff)
arr.append(absdiff)
n += 1
converged = False
if n > 300:
return 'No'
print('Yes')
print(n)
return ' '.join(str(num) for num in arr)
T = int(input())
for t in range(T):
n = int(input())
arr = [int(num) for num in input().split()]
print(nice(arr, n))
``` | output | 1 | 51,570 | 12 | 103,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b. | instruction | 0 | 51,571 | 12 | 103,142 |
Tags: brute force, constructive algorithms
Correct Solution:
```
import sys
t = int(sys.stdin.readline())
for _ in range(t):
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = a[:]
while len(b) <= 300:
s = set(b)
c = set()
for i in range(len(b) - 1):
for j in range(i + 1, len(b)):
if abs(b[i] - b[j]) not in s:
c.add(abs(b[i] - b[j]))
if len(c) > 0:
b += list(c)
else:
print('YES')
print(len(b))
print(*b)
break
else:
print('NO')
``` | output | 1 | 51,571 | 12 | 103,143 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b. | instruction | 0 | 51,572 | 12 | 103,144 |
Tags: brute force, constructive algorithms
Correct Solution:
```
n = int(input())
ans = []
le = []
aa = []
def nice(a):
for i in a:
for j in a:
if len(a)>300:
ans.append('No')
le.append('')
aa.append('')
break
if abs(i-j) not in a and abs(i-j)!=0:
a.append(abs(i-j))
if abs(i-j)==0 and a.count(i)>1 and 0 not in a:
a.append(0)
if len(a)>300:
break
if len(a)<300:
ans.append('Yes')
le.append(len(a))
aa.append(a)
for i in range(n):
a = []
n1 = int(input())
a = input().split()
a = [int(i) for i in a]
nice(a)
for i in range(n):
if ans[i]=='Yes':
print(ans[i])
print(le[i])
print(*aa[i])
else:
print('No')
``` | output | 1 | 51,572 | 12 | 103,145 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b. | instruction | 0 | 51,573 | 12 | 103,146 |
Tags: brute force, constructive algorithms
Correct Solution:
```
for i in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
no = False
for i in a:
if i < 0:
no = True
if no:
print("NO")
else:
while True:
add_list = []
for index in range(len(a) - 1):
for index2 in range(index + 1, len(a)):
num = abs(a[index] - a[index2])
if num not in a:
if num not in add_list:
add_list.append(abs(a[index] - a[index2]))
if len(add_list) > 0:
a.extend(add_list)
else:
break
# print(a)
print("YES")
print(len(a))
print(*a)
``` | output | 1 | 51,573 | 12 | 103,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b. | instruction | 0 | 51,574 | 12 | 103,148 |
Tags: brute force, constructive algorithms
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
v = set()
arr = [int(w) for w in input().split(' ')]
ans = 'YES'
test = [-1] + [int(w) for w in range(101)]
if arr == test:
print('YES')
else:
for item in arr:
if item<0:
ans = 'NO'
break
if ans=='NO':
print(ans)
else:
b = [int(w) for w in range(101)]
v = [int(w) for w in range(101)]
print(ans)
print(101)
for item in b:
print(item,end=' ')
print('')
``` | output | 1 | 51,574 | 12 | 103,149 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b. | instruction | 0 | 51,575 | 12 | 103,150 |
Tags: brute force, constructive algorithms
Correct Solution:
```
t = int(input())
def test_case(arr):
f = 1
c = 0
while(f!=0):
f = 0
for i in range(len(arr)):
if arr[i] < 0 :
print("NO")
c = 1
break
for j in range(i+1, len(arr)):
a = abs(arr[i] - arr[j])
if(a not in arr) and len(arr) < 300:
arr.append(a)
f = 1
if len(arr) > 300:
print("NO")
c = 1
if c == 0:
print("YES")
print(len(arr))
print(*arr)
for i in range(t):
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
test_case(arr)
``` | output | 1 | 51,575 | 12 | 103,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b. | instruction | 0 | 51,576 | 12 | 103,152 |
Tags: brute force, constructive algorithms
Correct Solution:
```
cases=int(input())
for k in range(cases):
n=int(input())
a=list(map(int,input().split()))
x=min(a)
y=max(a)
if x<0:
print('NO')
else:
print('YES')
print(y+1)
for i in range(0,y+1):
print(i,sep=' ',end=' ')
``` | output | 1 | 51,576 | 12 | 103,153 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b.
Submitted Solution:
```
t=int(input())
for i in range(t):
n=int(input())
arr=list(map(int,input().split(' ')))
mn=min(arr)
mx=max(arr)
s=set(arr)
if len(s)<n:
print("NO")
else:
if mn<0:
print("NO")
elif mn>=0:
print("YES")
lst=[i for i in range(0,101)]
# for i in range(mn,mx+1):
# lst.append(i)
print(len(lst))
print(*lst)
else:
print("NO")
# lst=[i for i in range(-100,1)]
# print(len(lst))
``` | instruction | 0 | 51,577 | 12 | 103,154 |
Yes | output | 1 | 51,577 | 12 | 103,155 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b.
Submitted Solution:
```
t=int(input())
for k in range(0,t):
x=int(input())
a=list(map(int,input().split()))
a.sort()
c=0
for i in range(len(a)):
if a[i]<0:
print("NO")
c=1
break
if c==0:
print("YES")
print(a[len(a)-1]+1)
for i in range(a[len(a)-1]+1):
print(i,end=" ")
print()
``` | instruction | 0 | 51,578 | 12 | 103,156 |
Yes | output | 1 | 51,578 | 12 | 103,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b.
Submitted Solution:
```
import io, os
from functools import reduce
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
int10 = lambda n: int(n, 10)
t = int10(input().decode())
def cal(a: list):
while 1:
n = len(a)
for i in range(n):
for j in range(i+1, n):
if abs(a[i] - a[j]) not in a:
a.append(abs(a[i] - a[j]))
if len(a) > 300:
return None
if len(a) == n:
break
return a
for _ in range(t):
n = int10(input().decode())
a = list(map(int,input().decode().split()))
failed = False
for ai in a:
if ai < 0:
failed = True
break
if failed:
print('no')
continue
res = cal(a)
if res:
print('yes')
print(len(res))
print(' '.join([str(c) for c in res]))
else:
print('no')
``` | instruction | 0 | 51,579 | 12 | 103,158 |
Yes | output | 1 | 51,579 | 12 | 103,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b.
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
i=1
while i<len(a) and len(a)<=300:
j=0
while j<i and len(a)<=300:
#print(i,j)
if a[i]!=a[j] and abs(a[i]-a[j]) not in a:
a.append(abs(a[i]-a[j]))
j+=1
i+=1
if len(a)>300:
print("NO")
else:
print("YES")
print(len(a))
print(*a)
``` | instruction | 0 | 51,580 | 12 | 103,160 |
Yes | output | 1 | 51,580 | 12 | 103,161 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a = [a_1, a_2, β¦, a_n] of n distinct integers. An array b = [b_1, b_2, β¦, b_k] is called nice if for any two distinct elements b_i, b_j of b, |b_i-b_j| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don't have to add any elements.
For example, array [3, 6, 9] is nice, as |6-3|=|9-6| = 3, which appears in the array, and |9-3| = 6, which appears in the array, while array [4, 2, 0, 6, 9] is not nice, as |9-4| = 5 is not present in the array.
For integers x and y, |x-y| = x-y if x > y and |x-y| = y-x otherwise.
Input
Each test contains multiple test cases. The first line contains t (1 β€ t β€ 50), the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n (2 β€ n β€ 100) β the length of the array a.
The second line of each test case contains n distinct integers a_1, a_2, β
β
β
, a_n (-100 β€ a_i β€ 100) β the elements of the array a.
Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.
If the first line is YES, output a second line containing a single integer k (n β€ k β€ 300).
Then output one line containing k distinct integers b_1, b_2, β
β
β
, b_k (-10^9 β€ b_i β€ 10^9), the elements of the nice array b. b_1, b_2, β
β
β
, b_k can be in any order. For each a_i in a, a_i must appear at least once in b.
It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.
If multiple solutions exist, you can print any.
Example
Input
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
Output
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b = [6, 0, 3, 9]. Note that |6-3| = |9-6| = |3-0| = 3 and 3 is in b, |6-0| = |9-3| = 6 and 6 is in b, and |9-0| = 9 is in b, so b is nice.
For the second case, you can add integers to a to receive the array b = [5, 3, 1, 2, 4]. We have that |2-1| = |3-2| = |4-3| = |5-4| = 1 is in b, |3-1| = |4-2| = |5-3| = 2 is in b, |4-1| = |5-2| = 3 is in b, and |5-1| = 4 is in b, so b is nice.
For the fourth case, you can add integers to a to receive the array b = [8, 12, 6, 2, 4, 10]. We have that |4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in b, |6-2| = |8-4| = |10-6| = |12-8| = 4 is in b, |8-2| = |10-4| = |12-6| = 6 is in b, |10-2| = |12-4| = 8 is in b, and |12-2| = 10 is in b, so b is nice.
It can be proven that for all other test cases it is impossible to create a nice array b.
Submitted Solution:
```
import collections as cc
import bisect as bi
import heapq as hp
import sys
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
n , = I()
ar = I()
ar.sort()
mi = min(ar)
mx = max(ar)
if mi<0:
print("No")
else:
print("YES")
print(100)
print(*[i for i in range(1,101)])
``` | instruction | 0 | 51,581 | 12 | 103,162 |
No | output | 1 | 51,581 | 12 | 103,163 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.