message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00 | instruction | 0 | 8,494 | 20 | 16,988 |
Tags: *special
Correct Solution:
```
from math import sqrt
f = lambda x: sqrt(abs(x))
g = lambda x: x**3*5
arr = []
for _ in range(11):
arr.append(int(input()))
arr.reverse()
for e in arr:
r = f(e)+g(e)
if 400 < r:
print("f(%d) = " % (e) + "MAGNA NIMIS!")
continue
print("f(%d) = %.2f" % (e, r))
``` | output | 1 | 8,494 | 20 | 16,989 |
Provide tags and a correct Python 3 solution for this coding contest problem.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00 | instruction | 0 | 8,497 | 20 | 16,994 |
Tags: *special
Correct Solution:
```
import math
def f(t):
return math.sqrt(abs(t)) + 5 * t ** 3
a = [int(input()) for _ in range(11)]
for i, t in reversed(list(enumerate(a))):
y = f(t)
if y > 400:
print('f(', t, ') = MAGNA NIMIS!', sep='')
else:
print('f(', t, ') = %.2f' % y, sep='')
``` | output | 1 | 8,497 | 20 | 16,995 |
Provide tags and a correct Python 3 solution for this coding contest problem.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00 | instruction | 0 | 8,498 | 20 | 16,996 |
Tags: *special
Correct Solution:
```
from math import sqrt, pow
def f(x):
sign = 1 if x > 0 else -1 if x < 0 else 0
aresult = sqrt(abs(x))
bresult = pow(x, 3)*5
result = bresult + aresult
# result *= sign
return result
arr = []
for i in range(11):
x = int(input())
arr.append(x)
for x in reversed(arr):
result = f(x)
print(f"f({x}) = ", end="")
if result >= 400:
print("MAGNA NIMIS!")
else:
print(f"{result:.2f}")
``` | output | 1 | 8,498 | 20 | 16,997 |
Provide tags and a correct Python 3 solution for this coding contest problem.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00 | instruction | 0 | 8,499 | 20 | 16,998 |
Tags: *special
Correct Solution:
```
from math import sqrt as s
def main():
inp = list()
for _ in range(11):
inp.append(int(input()))
for num in reversed(inp):
result = s(abs(num)) + num * num * num * 5
print(f"f({num}) = ", end = '', sep = '')
if result >= 400:
print('MAGNA NIMIS!')
else:
print('%.2f' % result)
if __name__ == '__main__':
main()
``` | output | 1 | 8,499 | 20 | 16,999 |
Provide tags and a correct Python 3 solution for this coding contest problem.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00 | instruction | 0 | 8,500 | 20 | 17,000 |
Tags: *special
Correct Solution:
```
from math import sqrt
a = []
for i in range(11):
a.append(int(input()))
for i in range(10, -1, -1):
x = a[i]
aresult = sqrt(abs(x))
bresult = x * x * x * 5
result = aresult + bresult
print('f(' + str(x) + ') = ', sep='', end='')
if result >= 400:
print("MAGNA NIMIS!")
else:
print('%.2f' % result)
``` | output | 1 | 8,500 | 20 | 17,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, β¦, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers in a way that would make the resulting expression's value as large as possible. To find out which symbols were available the teacher has given Barbara a string s which contained that information.
<image>
It's easy to notice that Barbara has to place n - 1 symbols between numbers in total. The expression must start with a number and all symbols must be allowed (i.e. included in s). Note that multiplication takes precedence over addition or subtraction, addition and subtraction have the same priority and performed from left to right. Help Barbara and create the required expression!
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the amount of numbers on the paper.
The second line of the input contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 9), where a_i is the i-th element of a.
The third line of the input contains the string s (1 β€ |s| β€ 3) β symbols allowed in the expression. It is guaranteed that the string may only consist of symbols "-", "+" and "*". It is also guaranteed that all symbols in the string are distinct.
Output
Print n numbers separated by n - 1 symbols β a mathematical expression with the greatest result. If there are multiple equally valid results β output any one of them.
Examples
Input
3
2 2 0
+-*
Output
2*2-0
Input
4
2 1 1 2
+*
Output
2+1+1+2
Note
The following answers also fit the first example: "2+2+0", "2+2-0", "2*2+0". | instruction | 0 | 8,562 | 20 | 17,124 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
# Author: yumtam
# Created at: 2020-12-28 23:43
from itertools import groupby, product
def main():
n = int(input())
ar = [int(t) for t in input().split()]
ops = set(input())
if len(ops) == 1:
ans = [ops.pop()] * (n-1)
elif ops == {'+', '-'}:
ans = ['+'] * (n-1)
elif ops == {'*', '-'}:
ans = ['*'] * (n-1)
if 0 in ar:
idx = ar.index(0)
if idx > 0:
ans[idx-1] = '-'
else:
ans = ['?'] * (n-1)
def solve(l, r):
while l < r:
if ar[l] == 1:
ans[l] = '+'
else:
break
l += 1
while l < r:
if ar[r] == 1:
ans[r-1] = '+'
else:
break
r -= 1
if l == r:
return
A = ar[l:r+1]
S = max(sum(A), 2*(r+1-l))
P = 1
for x in A:
P *= x
if P >= S:
for j in range(l, r):
ans[j] = '*'
return
nums = []
conns = []
cl = []
i = l
for ones, it in groupby(A, key=lambda x: x==1):
if ones:
L = len(list(it))
conns.append(L)
cl.append(i)
i += L
else:
p = 1
for x in it:
p *= x
if i < r: ans[i] = '*'
i += 1
nums.append(p)
# print(nums)
# print(conns)
# print(cl)
best_seq = 0
best_val = sum(A)
for seq in range(2**len(conns)):
i = 0
cur = 0
prod = nums[i]
for h in range(len(conns)):
op = seq & (1 << h)
if op:
prod *= nums[i+1]
else:
cur += prod + conns[i]
prod = nums[i+1]
i += 1
cur += prod
if cur > best_val:
best_val = cur
best_seq = seq
for h in range(len(conns)):
op = best_seq & (1 << h)
ch = '*' if op else '+'
for i in range(cl[h]-1, cl[h]+conns[h]):
ans[i] = ch
l = 0
for i in range(n):
if ar[i] == 0:
if i > 0:
ans[i-1] = '+'
if i < n-1:
ans[i] = '+'
if l < i-1:
solve(l, i-1)
l = i+1
if l < n-1:
solve(l, n-1)
res = [None] * (2*n-1)
res[::2] = ar
res[1::2] = ans
print(*res, sep='')
main()
``` | output | 1 | 8,562 | 20 | 17,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, β¦, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers in a way that would make the resulting expression's value as large as possible. To find out which symbols were available the teacher has given Barbara a string s which contained that information.
<image>
It's easy to notice that Barbara has to place n - 1 symbols between numbers in total. The expression must start with a number and all symbols must be allowed (i.e. included in s). Note that multiplication takes precedence over addition or subtraction, addition and subtraction have the same priority and performed from left to right. Help Barbara and create the required expression!
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the amount of numbers on the paper.
The second line of the input contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 9), where a_i is the i-th element of a.
The third line of the input contains the string s (1 β€ |s| β€ 3) β symbols allowed in the expression. It is guaranteed that the string may only consist of symbols "-", "+" and "*". It is also guaranteed that all symbols in the string are distinct.
Output
Print n numbers separated by n - 1 symbols β a mathematical expression with the greatest result. If there are multiple equally valid results β output any one of them.
Examples
Input
3
2 2 0
+-*
Output
2*2-0
Input
4
2 1 1 2
+*
Output
2+1+1+2
Note
The following answers also fit the first example: "2+2+0", "2+2-0", "2*2+0". | instruction | 0 | 8,563 | 20 | 17,126 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
s = input()
usable = []
if "+" in s:
usable.append(0)
if "*" in s:
usable.append(1)
if "-" in s:
usable.append(2)
usable = tuple(usable)
if len(usable) == 1:
ans = [s] * (n-1)
ansPr = []
for i in range(n - 1):
ansPr.append(str(a[i]))
ansPr.append(ans[i])
ansPr.append(str(a[n - 1]))
print("".join(ansPr))
elif usable == (0,1) or usable == (0,1,2): # +, *
ans = ["+"] * (n - 1)
curIndex = 0
while curIndex < n:
curCpy = curIndex
while curIndex < n and a[curIndex] != 0:
curIndex += 1
left = curCpy
right = curIndex
while left < right and a[left] == 1:
left += 1
while right > left and a[right - 1] == 1:
right -= 1
curCur = left
nonOneProd = []
oneLength = []
while curCur < right:
curProd = 1
while curCur < right and a[curCur] != 1:
if curProd < 2 * (right - left):
curProd *= a[curCur]
curCur += 1
nonOneProd.append(curProd)
if curCur == right:
break
curOneLength = 0
while curCur < right and a[curCur] == 1:
curOneLength += a[curCur]
curCur += 1
oneLength.append(curOneLength)
curAllProd = 1
index = 0
while curAllProd < 2 * (right - left) and index < len(nonOneProd):
curAllProd *= nonOneProd[index]
index += 1
if curAllProd >= 2 * (right - left) or len(nonOneProd) == 1:
for i in range(left, right - 1):
ans[i] = "*"
else:
maskLen = len(oneLength)
bestMask = 0
bestAns = 0
for i in range(1 << maskLen):
curAns = 0
curProd = nonOneProd[0]
for j in range(maskLen):
if i & (1 << j):
curProd *= nonOneProd[j + 1]
else:
curAns += curProd
curAns += oneLength[j]
curProd = nonOneProd[j + 1]
curAns += curProd
if curAns > bestAns:
bestAns = curAns
bestMask = i
curOneCount = 0
for i in range(left, right - 1):
if a[i] != 1 and a[i+1] == 1:
curOneCount += 1
if a[i] != 1 and a[i + 1] != 1:
ans[i] = "*"
elif bestMask & (1 << (curOneCount - 1)):
ans[i] = "*"
while curIndex < n and a[curIndex] == 0:
curIndex += 1
ansPr = []
for i in range(n - 1):
ansPr.append(str(a[i]))
ansPr.append(ans[i])
ansPr.append(str(a[n - 1]))
print("".join(ansPr))
elif usable == (1,2): # -, *
ans = ["-"] * (n - 1)
firstZero = True
for i in range(n - 1):
ans[i] = "*"
if a[i + 1] == 0 and firstZero:
ans[i] = "-"
firstZero = False
ansPr = []
for i in range(n - 1):
ansPr.append(str(a[i]))
ansPr.append(ans[i])
ansPr.append(str(a[n - 1]))
print("".join(ansPr))
elif usable == (0,2): # +, -
ans = ["+"] * (n-1)
ansPr = []
for i in range(n - 1):
ansPr.append(str(a[i]))
ansPr.append(ans[i])
ansPr.append(str(a[n - 1]))
print("".join(ansPr))
``` | output | 1 | 8,563 | 20 | 17,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, β¦, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers in a way that would make the resulting expression's value as large as possible. To find out which symbols were available the teacher has given Barbara a string s which contained that information.
<image>
It's easy to notice that Barbara has to place n - 1 symbols between numbers in total. The expression must start with a number and all symbols must be allowed (i.e. included in s). Note that multiplication takes precedence over addition or subtraction, addition and subtraction have the same priority and performed from left to right. Help Barbara and create the required expression!
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the amount of numbers on the paper.
The second line of the input contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 9), where a_i is the i-th element of a.
The third line of the input contains the string s (1 β€ |s| β€ 3) β symbols allowed in the expression. It is guaranteed that the string may only consist of symbols "-", "+" and "*". It is also guaranteed that all symbols in the string are distinct.
Output
Print n numbers separated by n - 1 symbols β a mathematical expression with the greatest result. If there are multiple equally valid results β output any one of them.
Examples
Input
3
2 2 0
+-*
Output
2*2-0
Input
4
2 1 1 2
+*
Output
2+1+1+2
Note
The following answers also fit the first example: "2+2+0", "2+2-0", "2*2+0". | instruction | 0 | 8,564 | 20 | 17,128 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
# n = 10
# A = [random.randint(0, 9) for i in range(10)]
# symbols = ["+", "*"]
n = int(input())
A = list(map(int, input().split()))
symbols = list(input())
def solve1(array):
# "+" or "*"
# 2+1+1+1+1+1+2
# 2*1*1*1*2
j = 0
# we need to break everything into components deprived of 0s
solution = []
first = True
while (j < len(array)):
i = j
if not first:
solution.append("+")
first = False
if array[j] == 0:
j += 1
while (j < len(array) and array[j] == 0):
j += 1
j -= 1
solution.extend(list("+".join(["0"] * (j - i + 1))))
else:
j += 1
while (j < len(array) and array[j] != 0):
j += 1
j -= 1
sol = solve11(array[i:j + 1])
solution.extend(sol)
j += 1
return "".join(list(map(str, solution)))
def solve11(array):
count = 0
first_different_from_one_prefix = 0
for i in range(len(array)):
if array[i] != 1:
break
else:
first_different_from_one_prefix = i + 1
array = array[first_different_from_one_prefix:]
first_part = "+".join(["1"] * (first_different_from_one_prefix))
first_different_from_one_suffix = len(array) - 1
for i in range(len(array) - 1, -1, -1):
if array[i] != 1:
break
else:
first_different_from_one_suffix = i - 1
second_part = "+".join(["1"] * (len(array) - 1 - first_different_from_one_suffix))
array = array[:first_different_from_one_suffix + 1]
SOLUTION = []
if len(array) > 0:
for i in range(0, len(array)):
if array[i] > 2:
count += 1
# Question is : is it better to use a * or a + at given empty space ?
# if subproblem contains more than 20 numbers it's always better to use *
if count >= 20:
SOLUTION.extend(list("*".join(list(map(str, array)))))
SOLUTION = SOLUTION[::-1]
else:
# we need dp here
DP = [0 for i in range(len(array))]
DP_PARENTS = [-1 for i in range(len(array))]
DP[0] = array[0]
for i in range(0, len(array)):
if array[i] == 1:
DP[i] = DP[i - 1] + 1
DP_PARENTS[i] = i - 1
continue
else:
PROD = 1
for k in range(i - 1, -2, -1):
PROD *= array[k + 1]
if k == -1:
if DP[i] < PROD:
DP[i] = PROD
DP_PARENTS[i] = k
elif DP[i] < DP[k] + PROD:
DP[i] = DP[k] + PROD
DP_PARENTS[i] = k
# we need to construct the solution
current = len(array) - 1
while (current != -1):
k = DP_PARENTS[current]
for i in range(current, k, -1):
SOLUTION.append(array[i])
SOLUTION.append("*")
SOLUTION.pop()
SOLUTION.append("+")
current = k
SOLUTION.pop()
RESULT = ""
SOLUTION = list(map(str, SOLUTION[::-1]))
parts = [first_part, "".join(SOLUTION), second_part]
parts = [part for part in parts if part != ""]
return "+".join(parts)
# print(solve11([7, 8, 3, 8, 6, 3, 3, 6, 5, 5, 7, 3, 8, 8, 7, 7, 4, 3, 3, 3]))
# print(solve11([6, 4, 8, 7, 9, 9, 8, 6, 8, 1, 6, 6, 8, 3, 5, 3, 4, 4, 1, 3]))
# print("hum")
def solve2(array):
# "-" or "*"
# 2+1*5-0*2*6*1*1
# when meet zero take -
# after 0 take *
current = 0
solution = []
first_zero = None
array = list(map(str, array))
while (current < len(array) and array[current] != '0'):
current += 1
if current == len(array):
if array[-1] == '0':
return "*".join(array[:-1]) + "-0"
else:
return "*".join(array)
else:
if current != 0:
return "*".join(array[0:current]) + "-" + "*".join(array[current:])
else:
return "*".join(array[current:])
MY_SOLUTION = None
if len(symbols) == 1:
MY_SOLUTION = symbols[0].join(list(map(str, A)))
if len(symbols) == 2:
if "+" in symbols and "-" in symbols:
MY_SOLUTION = "+".join(list(map(str, A)))
if "+" in symbols and "*" in symbols:
MY_SOLUTION = solve1(A)
if "*" in symbols and "-" in symbols:
MY_SOLUTION = solve2(A)
if len(symbols) == 3:
MY_SOLUTION = solve1(A)
print(MY_SOLUTION)
``` | output | 1 | 8,564 | 20 | 17,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, β¦, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers in a way that would make the resulting expression's value as large as possible. To find out which symbols were available the teacher has given Barbara a string s which contained that information.
<image>
It's easy to notice that Barbara has to place n - 1 symbols between numbers in total. The expression must start with a number and all symbols must be allowed (i.e. included in s). Note that multiplication takes precedence over addition or subtraction, addition and subtraction have the same priority and performed from left to right. Help Barbara and create the required expression!
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the amount of numbers on the paper.
The second line of the input contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 9), where a_i is the i-th element of a.
The third line of the input contains the string s (1 β€ |s| β€ 3) β symbols allowed in the expression. It is guaranteed that the string may only consist of symbols "-", "+" and "*". It is also guaranteed that all symbols in the string are distinct.
Output
Print n numbers separated by n - 1 symbols β a mathematical expression with the greatest result. If there are multiple equally valid results β output any one of them.
Examples
Input
3
2 2 0
+-*
Output
2*2-0
Input
4
2 1 1 2
+*
Output
2+1+1+2
Note
The following answers also fit the first example: "2+2+0", "2+2-0", "2*2+0". | instruction | 0 | 8,565 | 20 | 17,130 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
#!/usr/bin/env python3
from itertools import accumulate, groupby
from functools import reduce
def prod(a):
return reduce(lambda x,y: min(x*y,10**6),a,1)
def solve_positive(a):
if a == '': return '+'
b = [''.join(v) for _,v in groupby(a, key=lambda x: x == '1')]
if b[0][0] == '1':
return '+' * len(b[0]) + solve_positive(a[len(b[0]):])
if b[-1][0] == '1':
return solve_positive(a[:-len(b[-1])]) + '+' * len(b[-1])
p = [prod(map(int,x)) for x in b[::2]]
q = [len(x) for x in b[1::2]]
k = len(p)
if prod(p) >= 10**6:
return '+' + '*' * (len(a)-1) + '+'
dp = [0] * k
go = [k] * k
for i in range(k)[::-1]:
dp[i] = prod(p[i:])
for j in range(i+1,k):
ndp = prod(p[i:j]) + q[j-1] + dp[j]
if ndp > dp[i]:
dp[i], go[i] = ndp, j
offset = [0] + list(accumulate(map(len,b)))
res = ['*'] * (len(a)-1)
i = go[0]
while i < k:
a = offset[2*i-1]-1
b = offset[2*i]
res[a:b] = '+' * (b-a)
i = go[i]
return '+' + ''.join(res) + '+'
def solve(a,ops):
n = len(a)
if len(ops) == 1: return ops * (n-1)
if sorted(ops) == list('+-'): return '+' * (n-1)
if sorted(ops) == list('*-'):
k = a.index('0') if '0' in a else n
if k == 0 or k == n: return '*' * (n-1)
return '*' * (k-1) + '-' + '*' * (n-k-1)
return ''.join(map(solve_positive,a.split('0')))[1:-1]
n = int(input())
a = ''.join(input().split())
ops = input()
b = solve(a,ops) + '\n'
for i in range(n):
print(a[i], end='')
print(b[i], end='')
``` | output | 1 | 8,565 | 20 | 17,131 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, β¦, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers in a way that would make the resulting expression's value as large as possible. To find out which symbols were available the teacher has given Barbara a string s which contained that information.
<image>
It's easy to notice that Barbara has to place n - 1 symbols between numbers in total. The expression must start with a number and all symbols must be allowed (i.e. included in s). Note that multiplication takes precedence over addition or subtraction, addition and subtraction have the same priority and performed from left to right. Help Barbara and create the required expression!
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the amount of numbers on the paper.
The second line of the input contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 9), where a_i is the i-th element of a.
The third line of the input contains the string s (1 β€ |s| β€ 3) β symbols allowed in the expression. It is guaranteed that the string may only consist of symbols "-", "+" and "*". It is also guaranteed that all symbols in the string are distinct.
Output
Print n numbers separated by n - 1 symbols β a mathematical expression with the greatest result. If there are multiple equally valid results β output any one of them.
Examples
Input
3
2 2 0
+-*
Output
2*2-0
Input
4
2 1 1 2
+*
Output
2+1+1+2
Note
The following answers also fit the first example: "2+2+0", "2+2-0", "2*2+0". | instruction | 0 | 8,566 | 20 | 17,132 |
Tags: constructive algorithms, dp, greedy
Correct Solution:
```
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
ops = input().strip()
if len(ops) == 1:
print(ops.join(map(str, a)))
elif '+' in ops and '*' in ops:
seqs = [[a[0]]]
output = []
# split into seqs of all 0's or non 0's
# every seq in seqs is a list of all 0's or non 0's
for i in range(1,n):
if a[i] == 0:
if seqs[-1][-1] == 0:
seqs[-1].append(a[i])
else:
seqs.append([a[i]])
else:
if seqs[-1][-1] == 0:
seqs.append([a[i]])
else:
seqs[-1].append(a[i])
for seq in seqs:
if seq[0] == 0:
# all 0
output.append('+'.join(map(str,seq)))
else:
# if prod >= 2*n, using addition is never optimal
prod = 1
for i in seq:
prod *= i
if prod >= 2 * n:
break
if prod >= 2 * n:
new_seq = ''
l = 0
r = len(seq) - 1
for i in range(len(seq)):
if seq[i] != 1:
l = i
break
for i in range(len(seq)-1,-1,-1):
if seq[i] != 1:
r = i
break
if l != 0:
new_seq += '+'.join('1'*l) + '+'
new_seq += '*'.join(map(str,seq[l:r+1]))
if r != len(seq)-1:
new_seq += '+' + '+'.join('1' * (len(seq) - 1 - r))
output.append(new_seq)
continue
# prod < 2*n so max length of seq after combining 1's is 2*log(2*n)
# use dp to find optimal operations
b = []
lst = -1
for i in seq:
if i == 1:
if lst != 1:
b.append([-1,1])
else:
b[-1][-1] += 1
else:
b.append([0,i])
lst = i
# + -> 0 | * -> 1
last_state = [[None]*2 for i in range(len(b)+1)]
dp = [[-10**9]*2 for i in range(len(b)+1)]
dp[0][0] = 0
dp[0][1] = 0
for i in range(len(b)):
# find state with mx val with i-1 elements used
mx = None
state = None
if dp[i][0] > dp[i][1]:
mx = dp[i][0]
state = [i,0]
else:
mx = dp[i][1]
state = [i,1]
# add
if mx + b[i][1] > dp[i+1][0]:
dp[i+1][0] = mx + b[i][1]
last_state[i+1][0] = ['+', state]
# multiply
prod = 1
for j in range(i,len(b)):
if b[j][0] == 0:
prod *= b[j][1]
if mx + prod > dp[j+1][1]:
dp[j+1][1] = mx + prod
last_state[j+1][1] = ['*', state]
# go in reverse to reconstruct sequence
solved_seq = []
state = None
if dp[len(b)][1] > dp[len(b)][0]:
state = [len(b),1]
else:
state = [len(b),0]
while state[0] != 0:
next_state = last_state[state[0]][state[1]][1]
operation = last_state[state[0]][state[1]][0]
for i in range(state[0] - 1, next_state[0]-1,-1):
# will add extra operation at end of output, but we can remove it later
if b[i][0] == -1:
solved_seq.append(operation.join('1' * b[i][1]) + operation)
else:
solved_seq.append(str(b[i][1]) + operation)
if operation == '*':
solved_seq[-1] = solved_seq[-1][:-1] + '+'
state = next_state
# remove extra operation at beg(was at end but we reversed)
output.append(''.join(solved_seq)[-2::-1])
print('+'.join(output))
elif '+' in ops:
print('+'.join(map(str,a)))
elif '*' in ops:
if 0 in a:
output = []
all_mult = 0
for i in range(n-1):
if a[i+1] == 0 and not all_mult:
output.extend([a[i],'-'])
all_mult = 0
else:
output.extend([a[i],'*'])
output.append(a[-1])
print(*output,sep='')
else:
print('*'.join(map(str, a)))
``` | output | 1 | 8,566 | 20 | 17,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, β¦, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers in a way that would make the resulting expression's value as large as possible. To find out which symbols were available the teacher has given Barbara a string s which contained that information.
<image>
It's easy to notice that Barbara has to place n - 1 symbols between numbers in total. The expression must start with a number and all symbols must be allowed (i.e. included in s). Note that multiplication takes precedence over addition or subtraction, addition and subtraction have the same priority and performed from left to right. Help Barbara and create the required expression!
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the amount of numbers on the paper.
The second line of the input contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 9), where a_i is the i-th element of a.
The third line of the input contains the string s (1 β€ |s| β€ 3) β symbols allowed in the expression. It is guaranteed that the string may only consist of symbols "-", "+" and "*". It is also guaranteed that all symbols in the string are distinct.
Output
Print n numbers separated by n - 1 symbols β a mathematical expression with the greatest result. If there are multiple equally valid results β output any one of them.
Examples
Input
3
2 2 0
+-*
Output
2*2-0
Input
4
2 1 1 2
+*
Output
2+1+1+2
Note
The following answers also fit the first example: "2+2+0", "2+2-0", "2*2+0".
Submitted Solution:
```
import sys,io,os,math
def printlist(n):
sys.stdout.write(" ".join(map(str,n)) + "\n")
def printf(n):
sys.stdout.write(str(n)+"\n")
def printns(n):
sys.stdout.write(str(n))
def intinp():
return int(sys.stdin.readline())
def strinp():
return sys.stdin.readline()
def arrinp():
return list(map(int,sys.stdin.readline().strip().split()))
def mulinp():
return map(int,sys.stdin.readline().strip().split())
def flush():
return stdout.flush()
def solve():
n=intinp()
arr=arrinp()
arr.sort(reverse=True)
s=strinp()
count=[s.count('*'),s.count('+'),s.count('-')]
ans=''+str(arr[0])
for i in range(1,n):
if(count[0]>0 and arr[i]!=1 and arr[i]!=0):
ans=ans+str('*')+str(arr[i])
continue
if(count[1]>0):
ans=ans+str('+')+str(arr[i])
continue
if(count[2]>0):
ans=ans+str('-')+str(arr[i])
print(ans)
def main():
solve()
main()
``` | instruction | 0 | 8,569 | 20 | 17,138 |
No | output | 1 | 8,569 | 20 | 17,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw n numbers a_1, a_2, β¦, a_n without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers in a way that would make the resulting expression's value as large as possible. To find out which symbols were available the teacher has given Barbara a string s which contained that information.
<image>
It's easy to notice that Barbara has to place n - 1 symbols between numbers in total. The expression must start with a number and all symbols must be allowed (i.e. included in s). Note that multiplication takes precedence over addition or subtraction, addition and subtraction have the same priority and performed from left to right. Help Barbara and create the required expression!
Input
The first line of the input contains a single integer n (1 β€ n β€ 10^5) β the amount of numbers on the paper.
The second line of the input contains n integers a_1, a_2, β¦, a_n (0 β€ a_i β€ 9), where a_i is the i-th element of a.
The third line of the input contains the string s (1 β€ |s| β€ 3) β symbols allowed in the expression. It is guaranteed that the string may only consist of symbols "-", "+" and "*". It is also guaranteed that all symbols in the string are distinct.
Output
Print n numbers separated by n - 1 symbols β a mathematical expression with the greatest result. If there are multiple equally valid results β output any one of them.
Examples
Input
3
2 2 0
+-*
Output
2*2-0
Input
4
2 1 1 2
+*
Output
2+1+1+2
Note
The following answers also fit the first example: "2+2+0", "2+2-0", "2*2+0".
Submitted Solution:
```
def plus(L):
res = ''
for X in L:
if X!=0:
res += str(X) + '+'
return res[:-1]
def mult(L):
res = ''
for X in L:
if X != 0 and X != 1:
res += str(X) + '*'
return res[:-1]
def sub(index, irt):
res = 0
if irt == 0:
return 0
if index[irt] == 0:
return sub(index,irt-1)
print(irt)
res = (str(irt)+'-') *(index[irt])
for i in range(irt-1,0,-1):
res += (str(i)+'-')*index[i]
return res[:-1]
index = {i:0 for i in range(10)}
num = input()
L = list(map(int, input().split()))
exp = input()
for X in L:
index[X] += 1
if exp == '-':
print(sub(index,9))
elif exp == '+':
print(plus(L))
elif exp == '*':
if index[0] == 0:
print("YESS")
print(mult(L))
else:
print(0)
elif exp == '+-' or exp == '-+':
x = '-0' * index[0]
print(plus(L)+x)
elif exp == '-*' or exp == '*-':
x = '*1'*index[1]+'-0'*index[0]
print(mult(L)+x)
else:
x = mult(L)+ '+1'*index[1]+ '+0'*index[0]
print(x)
``` | instruction | 0 | 8,570 | 20 | 17,140 |
No | output | 1 | 8,570 | 20 | 17,141 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai β€ ai + 1 β€ 2Β·ai for any positive integer i (i < n).
Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will get an expression consisting of n summands. The value of the resulting expression is the sum of all its elements. The task is to add signs "+" and "-" before each number so that the value of expression s meets the limits 0 β€ s β€ a1. Print a sequence of signs "+" and "-", satisfying the given limits. It is guaranteed that the solution for the problem exists.
Input
The first line contains integer n (1 β€ n β€ 105) β the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β the original array.
It is guaranteed that the condition ai β€ ai + 1 β€ 2Β·ai fulfills for any positive integer i (i < n).
Output
In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 β€ s β€ a1. If there are multiple solutions, you are allowed to print any of them.
Examples
Input
4
1 2 3 5
Output
+++-
Input
3
3 3 5
Output
++- | instruction | 0 | 8,609 | 20 | 17,218 |
Tags: greedy, math
Correct Solution:
```
n=int(input())
a=list(map(int,input().split(' ')))
temp_sgn=1
sgns=[]
curr_sum=0
for i in range(n):
if(curr_sum>=a[n-i-1]):
sgns.append(1)
sgns.append(-1)
curr_sum-=a[n-i-1]
else:
sgns.append(-1)
sgns.append(1)
curr_sum-=a[n-i-1]
curr_sum*=-1
sgns.reverse()
ans=[]
for i in range(2*n):
if(i%2==0):
ans.append(temp_sgn*sgns[i])
else:
temp_sgn*=sgns[i]
for x in ans:
if(x==1):
print('+',end='')
else:
print('-',end='')
``` | output | 1 | 8,609 | 20 | 17,219 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai β€ ai + 1 β€ 2Β·ai for any positive integer i (i < n).
Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will get an expression consisting of n summands. The value of the resulting expression is the sum of all its elements. The task is to add signs "+" and "-" before each number so that the value of expression s meets the limits 0 β€ s β€ a1. Print a sequence of signs "+" and "-", satisfying the given limits. It is guaranteed that the solution for the problem exists.
Input
The first line contains integer n (1 β€ n β€ 105) β the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β the original array.
It is guaranteed that the condition ai β€ ai + 1 β€ 2Β·ai fulfills for any positive integer i (i < n).
Output
In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 β€ s β€ a1. If there are multiple solutions, you are allowed to print any of them.
Examples
Input
4
1 2 3 5
Output
+++-
Input
3
3 3 5
Output
++- | instruction | 0 | 8,611 | 20 | 17,222 |
Tags: greedy, math
Correct Solution:
```
#!/usr/bin/python3
n = int(input())
a = list(map(int, input().split()))
s = a[-1]
ans = ['+']
for v in reversed(a[:-1]):
if s > 0:
s -= v
ans.append('-')
else:
s += v
ans.append('+')
if 0 <= s <= a[-1]:
print(''.join(reversed(ans)))
else:
s = -a[-1]
ans = ['-']
for v in reversed(a[:-1]):
if s > 0:
s -= v
ans.append('-')
else:
s += v
ans.append('+')
if 0 <= s <= a[-1]:
print(''.join(reversed(ans)))
else:
s = a[-1]
ans = ['+']
for v in reversed(a[:-1]):
if s >= 0:
s -= v
ans.append('-')
else:
s += v
ans.append('+')
if 0 <= s <= a[-1]:
print(''.join(reversed(ans)))
else:
s = -a[-1]
ans = ['-']
for v in reversed(a[:-1]):
if s >= 0:
s -= v
ans.append('-')
else:
s += v
ans.append('+')
print(''.join(reversed(ans)))
``` | output | 1 | 8,611 | 20 | 17,223 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has found a piece of paper with an array written on it. The array consists of n integers a1, a2, ..., an. Vasya noticed that the following condition holds for the array ai β€ ai + 1 β€ 2Β·ai for any positive integer i (i < n).
Vasya wants to add either a "+" or a "-" before each number of array. Thus, Vasya will get an expression consisting of n summands. The value of the resulting expression is the sum of all its elements. The task is to add signs "+" and "-" before each number so that the value of expression s meets the limits 0 β€ s β€ a1. Print a sequence of signs "+" and "-", satisfying the given limits. It is guaranteed that the solution for the problem exists.
Input
The first line contains integer n (1 β€ n β€ 105) β the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 β€ ai β€ 109) β the original array.
It is guaranteed that the condition ai β€ ai + 1 β€ 2Β·ai fulfills for any positive integer i (i < n).
Output
In a single line print the sequence of n characters "+" and "-", where the i-th character is the sign that is placed in front of number ai. The value of the resulting expression s must fit into the limits 0 β€ s β€ a1. If there are multiple solutions, you are allowed to print any of them.
Examples
Input
4
1 2 3 5
Output
+++-
Input
3
3 3 5
Output
++- | instruction | 0 | 8,615 | 20 | 17,230 |
Tags: greedy, math
Correct Solution:
```
n = int(input())
t = list(map(int, input().split()))
t.reverse()
s, p = 0, [0] * n
for i, j in enumerate(t):
if s > 0:
p[i] = 1
s -= j
else: s += j
p.reverse()
if s < 0: print(''.join('-+'[i] for i in p))
else: print(''.join('+-'[i] for i in p))
``` | output | 1 | 8,615 | 20 | 17,231 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the length of the sequence. Next n lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.
Output
If the answer exists, print in the first line "YES" (without the quotes). Next n lines must contain the sequence of positive integers β a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them.
If there is no answer, print a single line "NO" (without the quotes).
Examples
Input
3
?
18
1?
Output
YES
1
18
19
Input
2
??
?
Output
NO
Input
5
12224
12??5
12226
?0000
?00000
Output
YES
12224
12225
12226
20000
100000 | instruction | 0 | 8,658 | 20 | 17,316 |
Tags: binary search, brute force, greedy, implementation
Correct Solution:
```
def solve(s, t, i, l):
if i == l:
return False
if s[i] == "?":
if solve(s, t, i + 1, l):
s[i] = t[i]
return True
elif t[i] == "9":
return False
s[i] = nxt[t[i]]
for j in range(i, l):
if s[j] == "?":
s[j] = "0"
return True
elif s[i] > t[i]:
for j in range(i, l):
if s[j] == "?":
s[j] = "0"
return True
elif s[i] < t[i]:
return False
else:
return solve(s, t, i + 1, l)
n = int(input())
a = [list(input()) for _ in range(n)]
p = ["0"]
nxt = {str(x): str(x + 1) for x in range(9)}
for i, ai in enumerate(a):
if len(p) > len(ai):
print("NO")
break
if len(p) < len(ai):
if a[i][0] == "?":
a[i][0] = "1"
for j in range(len(ai)):
if a[i][j] == "?":
a[i][j] = "0"
elif not solve(a[i], p, 0, len(ai)):
print("NO")
break
p = a[i]
else:
print("YES")
print("\n".join("".join(line) for line in a))
``` | output | 1 | 8,658 | 20 | 17,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the length of the sequence. Next n lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.
Output
If the answer exists, print in the first line "YES" (without the quotes). Next n lines must contain the sequence of positive integers β a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them.
If there is no answer, print a single line "NO" (without the quotes).
Examples
Input
3
?
18
1?
Output
YES
1
18
19
Input
2
??
?
Output
NO
Input
5
12224
12??5
12226
?0000
?00000
Output
YES
12224
12225
12226
20000
100000
Submitted Solution:
```
def restore_seq(num_list):
result = []
flag = False
for i in range(len(num_list)):
if '?' not in num_list[i]:
if num_list[i] > num_list[i-1]:
result.append(num_list[i])
continue
else:
return False
this_string = num_list[i]
list_format = []
for c in num_list[i]:
list_format.append(c)
if i == 0: # if it is the first number, just make a at least as possible
for j in range(len(num_list[0])):
if j == 0 and this_string[j] == '?':
list_format[j] = '1'
else:
if this_string[j] == '?':
list_format[j] = '0'
else:
list_format[j] = this_string[j]
result.append(''.join(list_format))
continue
else:
# if current num's length is shorter than previous one, simple
# False
last_string = result[i-1]
if len(this_string) < len(last_string):
return False
# if current num's length's longer, set every ? smallerst:
elif len(this_string) > len(last_string):
for k in range(len(this_string)):
if k == 0 and this_string[k] == '?':
list_format[k] = '1'
else:
if this_string[k] == '?':
list_format[k] = '0'
else:
list_format[k] = this_string[k]
result.append(''.join(list_format))
continue
else: # if the current number's length equals with previous one
maxpossible = ''
for index in range(len(this_string)):
if this_string[index] == '?':
maxpossible += '9'
else:
maxpossible += this_string[index]
if int(maxpossible) <= int(last_string):
return False
# turn list_format's ? to be same with last string
for m in range(len(this_string)):
if this_string[m] == '?':
list_format[m] = last_string[m]
minpossible = ''
for index in range(len(this_string)):
if index == 0 and this_string[index] == '?':
minpossible += '1'
elif this_string[index] == '?':
minpossible += '0'
else:
minpossible += this_string[index]
if int(minpossible) > int(last_string):
result.append(minpossible)
continue
# if list_format is same as last string, then plus 1 to the first ? which is not 9
# and turn ? behind to 0
if ''.join(list_format) == last_string:
for index in range(len(this_string)-1, -1, -1):
if this_string[index] == '?' and list_format[index] != '9':
list_format[index] = str(int(list_format[index])+1)
break
for the_index in range(index+1, len(this_string)):
if this_string[the_index] == '?':
list_format[the_index] = '0'
result.append(''.join(list_format))
continue
#####################################################################
for index in range(len(list_format)):
if list_format[index] == last_string[index]:
continue
elif int(list_format[index]) < int(last_string[index]):
for the_index in range(index-1, -1, -1):
if this_string[the_index] == '?' and list_format[the_index] != '9':
list_format[the_index] = str(
int(list_format[the_index])+1)
break
for z in range(the_index+1, len(this_string)):
if this_string[z] == '?':
list_format[z] = '0'
result.append(''.join(list_format))
break
else:
for the_index in range(index+1, len(this_string)):
if this_string[the_index] == '?':
list_format[the_index] = '0'
result.append(''.join(list_format))
break
return result
################################################
num_list = []
n = int(input())
for i in range(n):
num_list.append(input())
result = restore_seq(num_list)
if result:
print('YES')
for item in result:
print(item)
else:
print('NO')
``` | instruction | 0 | 8,659 | 20 | 17,318 |
No | output | 1 | 8,659 | 20 | 17,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the length of the sequence. Next n lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.
Output
If the answer exists, print in the first line "YES" (without the quotes). Next n lines must contain the sequence of positive integers β a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them.
If there is no answer, print a single line "NO" (without the quotes).
Examples
Input
3
?
18
1?
Output
YES
1
18
19
Input
2
??
?
Output
NO
Input
5
12224
12??5
12226
?0000
?00000
Output
YES
12224
12225
12226
20000
100000
Submitted Solution:
```
n = int(input())
ni = [input() for i in range(n)]
miss = 0
if ni[0].find("?") != -1:
ni[0] = ni[0][0].replace("?","1")+ni[0][1:].replace("?","0")
ni[0]=int(ni[0])
for num in range(1,n):
lol = ni[num].find("?")
lol1 = ni[num].rfind("?")
if lol != -1:
if len(ni[num])==len(str(ni[num-1])):
if (str(ni[num][:lol])>str(ni[num-1])[:lol] or
str(ni[num][lol1+1:])>str(ni[num-1])[lol1+1:]):
ni[num] = (str(ni[num])[:lol]+str(ni[num-1])[lol:lol1+1]
+str(ni[num])[lol1+1:])
else:
if len(str(int(str(ni[num-1])[lol1:lol1+1])+1))==1:
ni[num] = (str(ni[num])[:lol]+str(ni[num-1])[lol:lol1]+
str(int(str(ni[num-1])[lol1:lol1+1])+1)+str(ni[num])[lol1+1:])
else:
miss = 0
break
elif len(ni[num]) > len(str(ni[num-1])):
ni[num] = ni[num][0].replace("?","1")+ni[num][1:].replace("?","0")
else:
miss = 1
break
ni[num] = int(ni[num])
if ni[num-1] >= ni[num]:
miss = 1
break
if miss == 1:
print("NO")
else:
print("YES")
for num in range(n):
print(ni[num])
``` | instruction | 0 | 8,661 | 20 | 17,322 |
No | output | 1 | 8,661 | 20 | 17,323 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
Input
The first line of the input contains integer n (1 β€ n β€ 105) β the length of the sequence. Next n lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.
Output
If the answer exists, print in the first line "YES" (without the quotes). Next n lines must contain the sequence of positive integers β a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them.
If there is no answer, print a single line "NO" (without the quotes).
Examples
Input
3
?
18
1?
Output
YES
1
18
19
Input
2
??
?
Output
NO
Input
5
12224
12??5
12226
?0000
?00000
Output
YES
12224
12225
12226
20000
100000
Submitted Solution:
```
length = int(input())
number_list = []
for _ in range(length):
number = input()
number_list.append(number)
for i in range(len(number_list[0])):
if number_list[0][i] == "?":
if i == 0:
number_list[0] = "1" + number_list[0][i+1:]
else:
number_list[0] = number_list[0][:i] + "0" +number_list[0][i+1:]
answer = "YES"
for current in range(1,length):
prev = current - 1
if len(number_list[current])<len(number_list[prev]):
answer = "NO"
print ("NO")
break
elif len(number_list[current])>len(number_list[prev]):
for i in range(len(number_list[current])):
if (number_list[current][i] == "?"):
if i == 0:
number_list[current] = "1" + number_list[current][i+1:]
else:
number_list[current] = number_list[current][:i]+"0"+number_list[current][i+1:]
elif len(number_list[current])==len(number_list[prev]):
position = -1
for i in range(len(number_list[current])):
if position == -1 and number_list[prev][i]>number_list[current][i]:
answer="NO"
print("NO")
break
elif number_list[current][i] > number_list[prev][i]:
position = i
if answer == "YES":
for i in range(len(number_list[current])):
if i < position and number_list[current][i] == "?":
if number_list[current][:i] > number_list[prev][:i]:
number_list[current] = number_list[current][:i]+"0"+number_list[current][i+1:]
else:
number_list[current] = number_list[current][:i] +number_list[prev][i] + number_list[current][i + 1:]
elif i>position and number_list[current][i] == "?":
number_list[current] = number_list[current][:i] +"0"+ number_list[current][i+1:]
elif i==position and number_list[current][i]=="?":
number_list[current] = number_list[current][:i] + str(min(int(number_list[prev][i])+1,9))+ number_list[current][i + 1:]
if answer == "YES":
print("YES")
for item in number_list:
print(int(item))
``` | instruction | 0 | 8,662 | 20 | 17,324 |
No | output | 1 | 8,662 | 20 | 17,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was solving arithmetical problems. He wrote down an expression a + b = c in his notebook. When the teacher checked Vasya's work it turned out that Vasya had solved the problem incorrectly. Now Vasya tries to find excuses. He says that he simply forgot to write down several digits in numbers a, b and c, but he can't remember what numbers they actually were. Help Vasya, find such numbers x, y and z, with which the following conditions are met:
* x + y = z,
* from the expression x + y = z several digits can be erased in such a way that the result will be a + b = c,
* the expression x + y = z should have the minimal length.
Input
The first and only input line contains the expression a + b = c (1 β€ a, b, c β€ 106, a, b and c don't contain leading zeroes) which is the expression Vasya wrote down.
Output
Print the correct expression x + y = z (x, y and z are non-negative numbers without leading zeroes). The expression a + b = c must be met in x + y = z as a subsequence. The printed solution should have the minimal possible number of characters. If there are several such solutions, you can print any of them.
Examples
Input
2+4=5
Output
21+4=25
Input
1+1=3
Output
1+31=32
Input
1+1=2
Output
1+1=2
Submitted Solution:
```
n=input()
l=list(n.split("+"))
l[1]=l[1].split("=")
l.append((l[1][1]))
l[1]=(l[1][0])
for i in range(10):
if l[2] in str(int(str(i)+l[0])+int(l[1])):
l[2]=str(int(str(i)+l[0])+int(l[1]))
l[0]=str(int(str(i)+l[0]))
break;
elif l[2] in str(int(l[0]+str(i))+int(l[1])):
l[2]=str(int(l[0]+str(i))+int(l[1]))
l[0]=str(int(l[0]+str(i)))
break;
a=l[0]+'+'+l[1]+'='+l[2]
print(a)
``` | instruction | 0 | 8,684 | 20 | 17,368 |
No | output | 1 | 8,684 | 20 | 17,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was solving arithmetical problems. He wrote down an expression a + b = c in his notebook. When the teacher checked Vasya's work it turned out that Vasya had solved the problem incorrectly. Now Vasya tries to find excuses. He says that he simply forgot to write down several digits in numbers a, b and c, but he can't remember what numbers they actually were. Help Vasya, find such numbers x, y and z, with which the following conditions are met:
* x + y = z,
* from the expression x + y = z several digits can be erased in such a way that the result will be a + b = c,
* the expression x + y = z should have the minimal length.
Input
The first and only input line contains the expression a + b = c (1 β€ a, b, c β€ 106, a, b and c don't contain leading zeroes) which is the expression Vasya wrote down.
Output
Print the correct expression x + y = z (x, y and z are non-negative numbers without leading zeroes). The expression a + b = c must be met in x + y = z as a subsequence. The printed solution should have the minimal possible number of characters. If there are several such solutions, you can print any of them.
Examples
Input
2+4=5
Output
21+4=25
Input
1+1=3
Output
1+31=32
Input
1+1=2
Output
1+1=2
Submitted Solution:
```
from heapq import heappush, heappop
equation = input()
fi, rest = equation.split('+')
se, td = rest.split('=')
lx = len(fi)
ly = len(se)
lz = len(td)
h = []
max_len = max(lx, ly, lz)
fi = fi[::-1]
se = se[::-1]
td = td[::-1]
a = [[[''for _ in range(max_len + 1)] for _ in range(max_len + 1)] for _ in range(max_len + 1)]
b = [[[''for _ in range(max_len + 1)] for _ in range(max_len + 1)] for _ in range(max_len + 1)]
c = [[[''for _ in range(max_len + 1)] for _ in range(max_len + 1)] for _ in range(max_len + 1)]
h = []
ans = None
heappush(h, (0, 0, 0, 0, 0))
while h:
cost, px, py, pz, carry = heappop(h)
if px == lx and py == ly and pz == lz:
if carry == 1:
c[px][py][pz] = c[px][py][pz] + '1'
ans = a[px][py][pz][::-1] + '+' + b[px][py][pz][::-1] + '=' + c[px][py][pz][::-1]
print(ans)
break
if px == lx:
if py == ly:
last = int(td[pz:][::-1])
last -= carry
if last > 0:
c[px][py][lz] = c[px][py][pz] + td[pz:]
cost += len(str(last))
else:
c[px][py][lz] = c[px][py][pz]
a[px][py][lz] = a[px][py][pz]
b[px][py][lz] = b[px][py][pz] + str(last)[::-1]
heappush(h, (cost + len(str(last)), px, py, lz, 0))
elif pz == lz:
last = int(se[py:][::-1])
last += carry
c[px][ly][pz] = c[px][py][pz] + str(last)[::-1]
a[px][ly][pz] = a[px][py][pz]
b[px][ly][pz] = b[px][py][pz] + se[py:]
heappush(h, (cost + len(str(last)), px, ly, pz, 0))
else:
cy = ord(se[py]) - ord('0')
cz = ord(td[pz]) - ord('0')
if (cy + carry) % 10 == cz:
a[px][py + 1][pz + 1] = a[px][py][pz]
b[px][py + 1][pz + 1] = b[px][py][pz] + se[py]
c[px][py + 1][pz + 1] = c[px][py][pz] + td[pz]
heappush(h, (cost, px, py + 1, pz + 1, (cy + carry) // 10))
else:
# first case:
cc = (cy + carry) % 10
a[px][py + 1][pz] = a[px][py][pz]
b[px][py + 1][pz] = b[px][py][pz] + se[py]
c[px][py + 1][pz] = c[px][py][pz] + chr(cc + ord('0'))
heappush(h, (cost + 1, px, py + 1, pz, (cy + carry) // 10))
# second case:
a[px][py][pz + 1] = a[px][py][pz]
if cz == 0 and carry == 1:
cc = 9
else:
cc = cz - carry
carry = 0
b[px][py][pz + 1] = b[px][py][pz] + chr(cc + ord('0'))
c[px][py][pz + 1] = c[px][py][pz] + td[pz]
heappush(h, (cost + 1, px, py, pz + 1, carry))
continue
if py == ly:
if pz == lz:
last = int(fi[px:][::-1])
last += carry
c[lx][py][pz] = c[px][py][pz] + str(last)[::-1]
a[lx][py][pz] = a[px][py][pz] + fi[px:]
b[lx][py][pz] = b[px][py][pz]
heappush(h, (cost + len(str(last)), lx, py, pz, 0))
else:
cx = ord(fi[px]) - ord('0')
cz = ord(td[pz]) - ord('0')
# first case
if (cx + carry) % 10 == cz:
a[px + 1][py][pz + 1] = a[px][py][pz] + fi[px]
b[px + 1][py][pz + 1] = b[px][py][pz]
c[px + 1][py][pz + 1] = c[px][py][pz] + td[pz]
heappush(h, (cost, px + 1, py, pz + 1, (cx + carry) // 10))
else:
cc = (cx + carry) % 10
a[px + 1][py][pz] = a[px][py][pz] + fi[px]
b[px + 1][py][pz] = b[px][py][pz]
c[px + 1][py][pz] = c[px + 1][py][pz] + chr(ord('0') + cc)
heappush(h, (cost + 1, px + 1, py, pz, (cx + carry) // 10))
if cz == 0 and carry == 1:
cc = 9
else:
cc = cz - carry
carry = 0
a[px][py][pz + 1] = a[px][py][pz] + chr(ord('0') + cc)
b[px][py][pz + 1] = b[px][py][pz]
c[px][py][pz + 1] = c[px][py][pz] + td[pz]
heappush(h, (cost + 1, px, py, pz + 1, carry))
continue
if lz == pz:
cx = ord(fi[px]) - ord('0')
cy = ord(se[py]) - ord('0')
cc = (cx + cy + carry) % 10
carry = (cx + cy + carry) // 10
a[px + 1][py + 1][pz] = a[px][py][pz] + fi[px]
b[px + 1][py + 1][pz] = b[px][py][pz] + se[py]
c[px + 1][py + 1][pz] = c[px][py][pz] + chr(ord('0') + cc)
heappush(h, (cost + 1, px + 1, py + 1, pz, carry))
continue
cx = ord(fi[px]) - ord('0')
cy = ord(se[py]) - ord('0')
cz = ord(td[pz]) - ord('0')
if (cx + cy + carry) % 10 == cz:
a[px + 1][py + 1][pz + 1] = a[px][py][pz] + fi[px]
b[px + 1][py + 1][pz + 1] = b[px][py][pz] + se[py]
c[px + 1][py + 1][pz + 1] = c[px][py][pz] + td[pz]
heappush(h, (cost, px + 1, py + 1, pz + 1, (cx + cy + carry) // 10))
else:
# first case
cc = (cx + cy + carry) % 10
a[px + 1][py + 1][pz] = a[px][py][pz] + fi[px]
b[px + 1][py + 1][pz] = b[px][py][pz] + se[py]
c[px + 1][py + 1][pz] = c[px][py][pz] + chr(ord('0') + cc)
heappush(h, (cost + 1, px + 1, py + 1, pz, (cx + cy + carry) // 10))
# second case
if (cx + carry) <= cz:
cc = cz - (cx - carry)
else:
cc = (cz + 10) - (cx + carry)
a[px + 1][py][pz + 1] = a[px][py][pz] + fi[px]
b[px + 1][py][pz + 1] = b[px][py][pz] + chr(ord('0') + cc)
c[px + 1][py][pz + 1] = c[px][py][pz] + td[pz]
heappush(h, (cost + 1, px + 1, py, pz + 1, (cc + cx + carry) // 10))
# third case
if (cy + carry) <= cz:
cc = cz - (cy + carry)
else:
cc = (cz + 10) - (cy + carry)
a[px][py + 1][pz + 1] = a[px][py][pz] + chr(ord('0') + cc)
b[px][py + 1][pz + 1] = b[px][py][pz] + se[py]
c[px][py + 1][pz + 1] = c[px][py][pz] + td[pz]
heappush(h, (cost + 1, px, py + 1, pz + 1, (cc + cx + carry) // 10))
``` | instruction | 0 | 8,685 | 20 | 17,370 |
No | output | 1 | 8,685 | 20 | 17,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya was solving arithmetical problems. He wrote down an expression a + b = c in his notebook. When the teacher checked Vasya's work it turned out that Vasya had solved the problem incorrectly. Now Vasya tries to find excuses. He says that he simply forgot to write down several digits in numbers a, b and c, but he can't remember what numbers they actually were. Help Vasya, find such numbers x, y and z, with which the following conditions are met:
* x + y = z,
* from the expression x + y = z several digits can be erased in such a way that the result will be a + b = c,
* the expression x + y = z should have the minimal length.
Input
The first and only input line contains the expression a + b = c (1 β€ a, b, c β€ 106, a, b and c don't contain leading zeroes) which is the expression Vasya wrote down.
Output
Print the correct expression x + y = z (x, y and z are non-negative numbers without leading zeroes). The expression a + b = c must be met in x + y = z as a subsequence. The printed solution should have the minimal possible number of characters. If there are several such solutions, you can print any of them.
Examples
Input
2+4=5
Output
21+4=25
Input
1+1=3
Output
1+31=32
Input
1+1=2
Output
1+1=2
Submitted Solution:
```
n=input()
l=list(n.split("+"))
l[1]=l[1].split("=")
l.append((l[1][1]))
l[1]=(l[1][0])
l1=l;
for i in range(1000000):
if l[2] in str(int(str(i)+l[0])+int(l[1])):
l[2]=str(int(str(i)+l[0])+int(l[1]))
l[0]=str(int(str(i)+l[0]))
break;
elif l[2] in str(int(l[0]+str(i))+int(l[1])):
l[2]=str(int(l[0]+str(i))+int(l[1]))
l[0]=str(int(l[0]+str(i)))
break;
for i in range(1000000):
if l1[2] in str(int(str(i)+l[1])+int(l[0])):
l1[2]=str(int(str(i)+l[1])+int(l[0]))
l1[1]=str(int(str(i)+l[1]))
break;
elif l1[2] in str(int(l[1]+str(i))+int(l[0])):
l1[2]=str(int(l[1]+str(i))+int(l[0]))
l1[1]=str(int(l[1]+str(i)))
break;
if int(l[2])<int(l1[2]):
a=l[0]+'+'+l[1]+'='+l[2]
else:
a=l1[0]+'+'+l1[1]+'='+l1[2]
print(a)
``` | instruction | 0 | 8,686 | 20 | 17,372 |
No | output | 1 | 8,686 | 20 | 17,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO | instruction | 0 | 9,086 | 20 | 18,172 |
Tags: brute force, dp, greedy, implementation, math
Correct Solution:
```
from collections import Counter
n=int(input())
a=[int(o) for o in input().split()]
d=dict(Counter(a))
j=0
reserve=[]
resul=[-1]*n
for i in range(n):
if d[a[i]]==1:
if j%2==0:
resul[i]="A"
else:
resul[i]="B"
j+=1
elif d[a[i]]>2:
resul[i]="A"
reserve.append(i)
else:
resul[i]="A"
if j%2==0:
print("YES")
print("".join(resul))
else:
if reserve:
resul[reserve[0]]="B"
print("YES")
print("".join(resul))
else:
print("NO")
``` | output | 1 | 9,086 | 20 | 18,173 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO | instruction | 0 | 9,087 | 20 | 18,174 |
Tags: brute force, dp, greedy, implementation, math
Correct Solution:
```
from collections import Counter
if __name__ == '__main__':
n = int(input())
sarr = list(map(int, input().split()))
dct = Counter(sarr)
if dct.most_common(1)[0][1] == 1:
if n % 2:
print('NO')
else:
print('YES')
print(''.join(['A' if i % 2 else 'B' for i in range(n)]))
exit(0)
occ = list(filter(lambda o: o[1] == 1, dct.most_common()))
if not occ:
print('YES')
print(''.join(['A' for i in range(n)]))
exit(0)
hn = None
ndct = {}
if len(occ) % 2:
cmn = dct.most_common(1)[0]
if cmn[1] < 3:
print('NO')
exit(0)
hn = cmn[0]
for i, o in enumerate(occ):
if i % 2:
ndct[o[0]] = 'B'
rez = [None for _ in range(n)]
for i, s in enumerate(sarr):
if s in ndct:
rez[i] = 'B'
else:
rez[i] = 'A'
if hn:
rez[sarr.index(hn)] = 'B'
print('YES')
print(''.join(rez))
``` | output | 1 | 9,087 | 20 | 18,175 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO | instruction | 0 | 9,088 | 20 | 18,176 |
Tags: brute force, dp, greedy, implementation, math
Correct Solution:
```
from collections import Counter
n = int(input())
s = list(map(int, input().split()))
cn = Counter(s)
ones = set()
triple = set()
for key in cn.keys():
if cn[key] == 1:
ones.add(key)
if cn[key] >= 3:
triple.add(key)
l_1 = len(ones)
l_3 = len(triple)
if (l_1 % 2 != 0) and (l_3 == 0):
print('NO')
else:
print('YES')
st = ''
for x in s:
if (x in ones) and len(ones) > (l_1 // 2 + l_1 % 2):
st += 'B'
ones.remove(x)
elif (l_1 % 2 != 0) and (x in triple):
st += 'B'
triple.clear()
else:
st += 'A'
print(st)
``` | output | 1 | 9,088 | 20 | 18,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO | instruction | 0 | 9,089 | 20 | 18,178 |
Tags: brute force, dp, greedy, implementation, math
Correct Solution:
```
n=int(input())
l=list(map(int,input().split()))
from collections import Counter,defaultdict
c=Counter(l)
l1=[]
for i in c:
if c[i]==1:
l1.append(i)
a=0
d=defaultdict(int)
for i in l1:
if a==0:
d[i]="A"
a=1
else:
d[i]="B"
a=0
if len(l1)%2==0:
ans=''
for i in l:
if c[i]>1:
d[i]="A"
for i in l:
ans+=d[i]
print("YES")
print(ans)
else:
s=''
ans=''
for i in l:
if c[i]>2:
s=i
break
if s!='':
x=0
for i in l:
if c[i]>1:
if i==s and x==0:
ans+="B"
x+=1
else:
ans+="A"
else:
ans+=d[i]
print("YES")
print(ans)
else:
print("NO")
``` | output | 1 | 9,089 | 20 | 18,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO | instruction | 0 | 9,090 | 20 | 18,180 |
Tags: brute force, dp, greedy, implementation, math
Correct Solution:
```
n=int(input())
s=list(map(int,input().split()))
num1=0
b=['A']*n
cnt={}
fst={}
for i in range(len(s)):
if(s[i]) in cnt:
cnt[s[i]]+=1
else:
cnt[s[i]]=1
fst[s[i]]=i
for i in range(len(s)):
if(cnt[s[i]]==1):
if(num1%2==1):
b[i]='B';
num1+=1
if(num1%2==1):
res=False
for i in range(len(s)):
if(cnt[s[i]]>2):
b[i]='B'
res=True
break
else:
res=True
if(res):
print('YES')
s1=''
for i in b:
s1+=i
print(s1)
else:
print('NO')
``` | output | 1 | 9,090 | 20 | 18,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO | instruction | 0 | 9,091 | 20 | 18,182 |
Tags: brute force, dp, greedy, implementation, math
Correct Solution:
```
from collections import deque
n = int(input())
arr = list(map(int, input().split(" ")))
dic = {}
for i in arr:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
seta = set()
setb = set()
a = 0
b = 0
dic_ans = {}
ones = set()
twos = set()
more = set()
for i in dic:
if dic[i] == 1:
ones.add(i)
elif dic[i] == 2:
twos.add(i)
else:
more.add(i)
for i in ones:
if a < b:
a += 1
seta.add(i)
dic_ans[i] = deque(["A"])
elif b < a:
b += 1
setb.add(i)
dic_ans[i] = deque(["B"])
else:
a += 1
seta.add(i)
dic_ans[i] = deque(["A"])
for i in twos:
# if a == b:
setb.add(i)
dic_ans[i] = deque(["B", "A"])
seta.add(i)
a+=1
b += 1
# else:
for i in more:
if a < b:
a += 1
seta.add(i)
dic_ans[i] = deque(["A"])
for k in range(dic[i]-1):
dic_ans[i].append("B")
elif b < a:
b += 1
setb.add(i)
dic_ans[i] = deque(["B"])
for k in range(dic[i]-1):
dic_ans[i].append("A")
else:
seta.add(i)
dic_ans[i] = deque()
for k in range(dic[i]):
dic_ans[i].append("A")
# print(*dic_ans)
# print(a,b)
if a == b:
ans = ""
for i in arr:
ans += dic_ans[i].pop()
print("YES")
print(ans)
else:
print("NO")
#100
#9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14
``` | output | 1 | 9,091 | 20 | 18,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO | instruction | 0 | 9,092 | 20 | 18,184 |
Tags: brute force, dp, greedy, implementation, math
Correct Solution:
```
n=int(input())
s=list(map(int,input().split()))
ct={}
a=[0]*(101)
for i in range(n):
ct[s[i]]=ct.get(s[i],0)+1
for i in ct:
a[ct[i]]+=1
if a[1]%2==0:
c='A'
print('YES')
ans=''
for i in range(n):
if ct[s[i]]==1:
ans=ans+c
c='A' if c=='B' else 'B'
else:
ans=ans+'A'
print(ans)
else:
f=0
for i in range(3,101):
if a[i]>0:
f=i
break
if f:
p=0
c='A'
ans=''
print('YES')
for i in range(n):
if ct[s[i]]==1:
ans=ans+c
c='A' if c=='B' else 'B'
elif ct[s[i]]==f and p==0:
ans=ans+'B'
p=1
else:
ans=ans+'A'
print(ans)
else:
print('NO')
``` | output | 1 | 9,092 | 20 | 18,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO | instruction | 0 | 9,093 | 20 | 18,186 |
Tags: brute force, dp, greedy, implementation, math
Correct Solution:
```
from collections import Counter
n=int(input())
s=list(map(int,input().split()))
sm=Counter(s)
su=set()
for i in sm.keys():
if sm[i]==1:
su.add(i)
j=-1
i=0
while i<n and j==-1:
if sm[s[i]]>=3:j=i
i+=1
if len(su)%2==1:
if j==-1:print("NO")
else:
print('YES')
cnt=0
ch=""
i=0
while i<n:
if (s[i] in su and cnt<len(su)//2) or i==j :
ch+="A"
if i!=j:cnt+=1
else:
ch+="B"
i+=1
print(ch)
else:
print('YES')
cnt=0
ch=""
i=0
while i<n:
if s[i] in su and cnt<len(su)//2:
ch+="A"
cnt+=1
else:
ch+="B"
i+=1
print(ch)
``` | output | 1 | 9,093 | 20 | 18,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO
Submitted Solution:
```
num = int(input())
multiset = [int(x) for x in input().split(' ')]
non_multiset = set(multiset)
help_dict = dict()
good = True
add = False
add_num = 0
count = 0
for x in non_multiset:
if multiset.count(x) == 1:
if good:
help_dict[x] = 'A'
else:
help_dict[x] = 'B'
good = not good
count += 1
if multiset.count(x) >= 3:
add = True
add_num = x
if count % 2 == 1:
if add:
first = True
print('YES')
res = ''
for x in multiset:
if multiset.count(x) == 1:
res += help_dict[x]
elif x == add_num and first:
res += 'B'
first = False
else:
res += 'A'
print(res)
else:
print('NO')
else:
print('YES')
res = ''
for x in multiset:
if multiset.count(x) == 1:
res += help_dict[x]
else:
res += 'A'
print(res)
``` | instruction | 0 | 9,094 | 20 | 18,188 |
Yes | output | 1 | 9,094 | 20 | 18,189 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO
Submitted Solution:
```
from collections import deque
n = int(input())
arr = list(map(int, input().split(" ")))
dic = {}
for i in arr:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
a = 0
b = 0
dic_ans = {}
ones = set()
twos = set()
more = set()
for i in dic:
if dic[i] == 1:
ones.add(i)
elif dic[i] == 2:
twos.add(i)
else:
more.add(i)
for i in ones:
if a < b:
a += 1
dic_ans[i] = deque(["A"])
elif b < a:
b += 1
dic_ans[i] = deque(["B"])
else:
a += 1
dic_ans[i] = deque(["A"])
for i in twos:
dic_ans[i] = deque(["B", "A"])
a+=1
b += 1
for i in more:
if a < b:
a += 1
dic_ans[i] = deque(["A"])
for k in range(dic[i]-1):
dic_ans[i].append("B")
elif b < a:
b += 1
dic_ans[i] = deque(["B"])
for k in range(dic[i]-1):
dic_ans[i].append("A")
else:
dic_ans[i] = deque()
for k in range(dic[i]):
dic_ans[i].append("A")
if a == b:
ans = ""
for i in arr:
ans += dic_ans[i].pop()
print("YES")
print(ans)
else:
print("NO")
``` | instruction | 0 | 9,095 | 20 | 18,190 |
Yes | output | 1 | 9,095 | 20 | 18,191 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO
Submitted Solution:
```
n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
cnt1 = 0
q = list()
for i in a:
if i not in q:
q.append(i)
if a.count(i) == 1:
cnt += 1
elif a.count(i) > 2:
cnt1 += 1
if cnt % 2 == 1 and cnt1 == 0:
print('NO')
else:
nums = list()
g = list()
ans = ''
f = True
q = False
for i in a:
if a.count(i) == 1:
if f:
ans += 'A'
f = False
else:
ans += 'B'
f = True
elif a.count(i) == 2:
ans += 'A'
else:
if cnt % 2 == 1:
if not q:
ans += 'B'
q = True
else:
ans += 'A'
else:
ans += 'A'
print('YES')
print(ans)
``` | instruction | 0 | 9,096 | 20 | 18,192 |
Yes | output | 1 | 9,096 | 20 | 18,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
d={}
m=10000000000
count1=0
p=0
t=0
for i in a:
d[i]=d.get(i,0)+1
if d[i]<m:
m=d[i]
if m>=2:
print('YES')
print('A'*n)
else:
s='A'*n
for i in range(n):
if d[a[i]]==1 and count1%2==0:
s=s[:i]+'B'+s[i+1:]
count1+=1
elif d[a[i]]==1:
count1+=1
if count1%2==0:
print('YES')
print(s)
else:
for i in range(n):
if d[a[i]]>2:
k=a[i]
s=s[:i]+'A'+s[i+1:]
t=1
break
if t==1:
for p in range(i+1,n):
if a[p]==k:
s=s[:p]+'B'+s[p+1:]
print('YES')
print(s)
if t==0:
print('NO')
``` | instruction | 0 | 9,097 | 20 | 18,194 |
Yes | output | 1 | 9,097 | 20 | 18,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO
Submitted Solution:
```
from collections import Counter
def main():
_ = int(input())
multiset = [int(c) for c in input().split()]
cnt = Counter(multiset)
res_a = []
res_b = []
minus1 = []
plus1 = []
for k, v in cnt.items():
if v == 1:
plus1.append(k)
while cnt[k] >= 2:
if cnt[k] == 3:
minus1.append(k)
res_a.append(k)
res_b.append(k)
cnt[k] -= 2
count = 0
for i, k in enumerate(minus1):
count += 1
if i % 2 == 0:
res_a.append(k)
else:
res_b.append(k)
if count % 2 == 0:
for i, k in enumerate(plus1):
if i % 2 == 0:
res_a.append(k)
else:
res_b.append(k)
else:
if len(plus1) % 2 == 0:
print('NO')
else:
res_a.append(plus1[0])
for i, k in enumerate(plus1[1:]):
if i % 2 == 0:
res_a.append(k)
else:
res_b.append(k)
res = []
for e in multiset:
if e in res_a:
res.append('A')
res_a.remove(e)
else:
res.append('B')
res_b.remove(e)
print('YES')
print(''.join(res))
if __name__ == '__main__':
main()
``` | instruction | 0 | 9,098 | 20 | 18,196 |
No | output | 1 | 9,098 | 20 | 18,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO
Submitted Solution:
```
n=int(input())
s1=0
s2=0
s=['A']*100
dic={}
lis=list(map(int,input().split()))
length=len(lis)
count=0
flag=0
backup=-1
for i in lis:
dic[i]=dic.get(i,0)+1
for i in dic:
if dic[i]==1:
count+=1
if dic[i]>2:
flag=1
backup=i
if count%2==1:
if flag==0:
print("NO")
exit()
lis2=[]
for i in dic:
if dic[i]==1:
lis2.append(i)
if backup!=-1:
lis2.append(backup)
for i in lis2:
if s1==0 or s1==s2:
s[i]='A'
s1+=1
continue
if s2+1==s1:
s[i]='B'
s2+=1
continue
print("YES")
flag2=0
for i in lis:
if i==backup and flag2==0:
print(s[i],end="")
flag2=1
if s[i]=='A':
s[i]='B'
else:
s[i]='A'
continue
print(s[i],end="")
``` | instruction | 0 | 9,099 | 20 | 18,198 |
No | output | 1 | 9,099 | 20 | 18,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO
Submitted Solution:
```
n=int(input())
s=[int(x) for x in input().split()]
L=[0]*105
G=[]
#H=[]
for i in range(0,len(s)):
L[s[i]]=L[s[i]]+1
for i in range(0,len(L)):
if(L[i]==1):
G.append(i)
if(L[i]>1):
#H.append(i)
L[i]='A'
#print(G)
#print(L[:10])
if(len(G)%2!=0):
print('NO')
else:
print('YES')
for j in range(0,len(G)//2):
L[G[j]]='A'
for j in range(len(G)//2,len(G)):
L[G[j]]='B'
for j in range(0,len(s)):
print(L[s[j]],end="")
print(" ")
``` | instruction | 0 | 9,100 | 20 | 18,200 |
No | output | 1 | 9,100 | 20 | 18,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two multisets a and b (one of which may be empty) in such a way that the quantity of nice numbers in multiset a would be the same as the quantity of nice numbers in multiset b (the quantity of numbers to appear exactly once in multiset a and the quantity of numbers to appear exactly once in multiset b).
Input
The first line contains a single integer n~(2 β€ n β€ 100).
The second line contains n integers s_1, s_2, ... s_n~(1 β€ s_i β€ 100) β the multiset s.
Output
If there exists no split of s to satisfy the given requirements, then print "NO" in the first line.
Otherwise print "YES" in the first line.
The second line should contain a string, consisting of n characters. i-th character should be equal to 'A' if the i-th element of multiset s goes to multiset a and 'B' if if the i-th element of multiset s goes to multiset b. Elements are numbered from 1 to n in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4
3 5 7 1
Output
YES
BABA
Input
3
3 5 1
Output
NO
Submitted Solution:
```
from collections import Counter
def read():
return [int(v) for v in input().split()]
def main():
n = read()[0]
a = read()
c = Counter(a)
d = [[], []]
s = ''
k = 0
for i in a:
s += 'AB'[k]
if c[i] == 1:
d[k].append(i)
k = 1 - k
if len(d[0]) == len(d[1]):
print('YES\n{}'.format(s))
else:
print('NO')
if __name__ == '__main__':
main()
``` | instruction | 0 | 9,101 | 20 | 18,202 |
No | output | 1 | 9,101 | 20 | 18,203 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image> <image>
*The two images are equivalent, feel free to use either one.
Input
The input contains a single integer a (-100 β€ a β€ 100).
Output
Output the result β an integer number.
Example
Input
1
Output
1 | instruction | 0 | 9,313 | 20 | 18,626 |
Tags: *special, math
Correct Solution:
```
a=int(input())
print(2-a*a)
``` | output | 1 | 9,313 | 20 | 18,627 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image> <image>
*The two images are equivalent, feel free to use either one.
Input
The input contains a single integer a (-100 β€ a β€ 100).
Output
Output the result β an integer number.
Example
Input
1
Output
1 | instruction | 0 | 9,314 | 20 | 18,628 |
Tags: *special, math
Correct Solution:
```
x = int(input())
print(2-(x**2))
``` | output | 1 | 9,314 | 20 | 18,629 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image> <image>
*The two images are equivalent, feel free to use either one.
Input
The input contains a single integer a (-100 β€ a β€ 100).
Output
Output the result β an integer number.
Example
Input
1
Output
1 | instruction | 0 | 9,315 | 20 | 18,630 |
Tags: *special, math
Correct Solution:
```
n = int(input())
print(2-int(n)**2)
``` | output | 1 | 9,315 | 20 | 18,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image> <image>
*The two images are equivalent, feel free to use either one.
Input
The input contains a single integer a (-100 β€ a β€ 100).
Output
Output the result β an integer number.
Example
Input
1
Output
1 | instruction | 0 | 9,316 | 20 | 18,632 |
Tags: *special, math
Correct Solution:
```
number=int(input())
print(2-(number)**2)
``` | output | 1 | 9,316 | 20 | 18,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image> <image>
*The two images are equivalent, feel free to use either one.
Input
The input contains a single integer a (-100 β€ a β€ 100).
Output
Output the result β an integer number.
Example
Input
1
Output
1 | instruction | 0 | 9,318 | 20 | 18,636 |
Tags: *special, math
Correct Solution:
```
(N,) = [int(x) for x in input().split()]
print(2 - N * N)
``` | output | 1 | 9,318 | 20 | 18,637 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image> <image>
*The two images are equivalent, feel free to use either one.
Input
The input contains a single integer a (-100 β€ a β€ 100).
Output
Output the result β an integer number.
Example
Input
1
Output
1 | instruction | 0 | 9,319 | 20 | 18,638 |
Tags: *special, math
Correct Solution:
```
import math
import sys
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input().strip()
return(list(s[:len(s)]))
def invr():
return(map(int,input().split()))
n=inp()
print(2-n**2)
``` | output | 1 | 9,319 | 20 | 18,639 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image> <image>
*The two images are equivalent, feel free to use either one.
Input
The input contains a single integer a (-100 β€ a β€ 100).
Output
Output the result β an integer number.
Example
Input
1
Output
1 | instruction | 0 | 9,320 | 20 | 18,640 |
Tags: *special, math
Correct Solution:
```
#!/bin/python
from collections import Counter
from copy import deepcopy
from heapq import nlargest, nsmallest
import itertools
import math
#import os
import random
#import sys
x = int(input())
print(2 - x * x)
exit(0)
``` | output | 1 | 9,320 | 20 | 18,641 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:
x2 + 2bx + c = 0 where b, c are natural numbers.
Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equations can have a common root.
Petya is interested in how many different real roots have all the equations of the type described above for all the possible pairs of numbers b and c such that 1 β€ b β€ n, 1 β€ c β€ m. Help Petya find that number.
Input
The single line contains two integers n and m. (1 β€ n, m β€ 5000000).
Output
Print a single number which is the number of real roots of the described set of equations.
Examples
Input
3 3
Output
12
Input
1 2
Output
1
Note
In the second test from the statement the following equations are analysed:
b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1
b = 1, c = 2: x2 + 2x + 2 = 0; No roots
Overall there's one root
In the second test the following equations are analysed:
b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1
b = 1, c = 2: x2 + 2x + 2 = 0; No roots
b = 1, c = 3: x2 + 2x + 3 = 0; No roots
b = 2, c = 1: x2 + 4x + 1 = 0; The roots are <image>
b = 2, c = 2: x2 + 4x + 2 = 0; The roots are <image>
b = 2, c = 3: x2 + 4x + 3 = 0; The roots are x1 = - 3, x2 = - 1
b = 3, c = 1: x2 + 6x + 1 = 0; The roots are <image>
b = 3, c = 2: x2 + 6x + 2 = 0; The roots are <image>
b = 3, c = 3: x2 + 6x + 3 = 0; The roots are <image> Overall there are 13 roots and as the root - 1 is repeated twice, that means there are 12 different roots.
Submitted Solution:
```
n,m=map(int,input().split())
s=[]
for i in range (1,n+1):
for j in range (1,i*i+1):
s.append(-i+pow((i*i-j),1/2))
s.append(-i-pow((i*i-j),1/2))
print(len(set(s)))
``` | instruction | 0 | 9,470 | 20 | 18,940 |
No | output | 1 | 9,470 | 20 | 18,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:
x2 + 2bx + c = 0 where b, c are natural numbers.
Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equations can have a common root.
Petya is interested in how many different real roots have all the equations of the type described above for all the possible pairs of numbers b and c such that 1 β€ b β€ n, 1 β€ c β€ m. Help Petya find that number.
Input
The single line contains two integers n and m. (1 β€ n, m β€ 5000000).
Output
Print a single number which is the number of real roots of the described set of equations.
Examples
Input
3 3
Output
12
Input
1 2
Output
1
Note
In the second test from the statement the following equations are analysed:
b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1
b = 1, c = 2: x2 + 2x + 2 = 0; No roots
Overall there's one root
In the second test the following equations are analysed:
b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1
b = 1, c = 2: x2 + 2x + 2 = 0; No roots
b = 1, c = 3: x2 + 2x + 3 = 0; No roots
b = 2, c = 1: x2 + 4x + 1 = 0; The roots are <image>
b = 2, c = 2: x2 + 4x + 2 = 0; The roots are <image>
b = 2, c = 3: x2 + 4x + 3 = 0; The roots are x1 = - 3, x2 = - 1
b = 3, c = 1: x2 + 6x + 1 = 0; The roots are <image>
b = 3, c = 2: x2 + 6x + 2 = 0; The roots are <image>
b = 3, c = 3: x2 + 6x + 3 = 0; The roots are <image> Overall there are 13 roots and as the root - 1 is repeated twice, that means there are 12 different roots.
Submitted Solution:
```
b1, c1 = map(int, input().split())
count = set()
for b in range(1, b1 + 1):
for c in range(1, c1 + 1):
if b**2 > c:
count.add(2*b*b + (b*b - c)**0.5)
count.add(2*b*b - (b*b - c)**0.5)
elif b**2 == c:
count.add(2*b*b)
else:
pass
print(len(count))
``` | instruction | 0 | 9,471 | 20 | 18,942 |
No | output | 1 | 9,471 | 20 | 18,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:
x2 + 2bx + c = 0 where b, c are natural numbers.
Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equations can have a common root.
Petya is interested in how many different real roots have all the equations of the type described above for all the possible pairs of numbers b and c such that 1 β€ b β€ n, 1 β€ c β€ m. Help Petya find that number.
Input
The single line contains two integers n and m. (1 β€ n, m β€ 5000000).
Output
Print a single number which is the number of real roots of the described set of equations.
Examples
Input
3 3
Output
12
Input
1 2
Output
1
Note
In the second test from the statement the following equations are analysed:
b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1
b = 1, c = 2: x2 + 2x + 2 = 0; No roots
Overall there's one root
In the second test the following equations are analysed:
b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1
b = 1, c = 2: x2 + 2x + 2 = 0; No roots
b = 1, c = 3: x2 + 2x + 3 = 0; No roots
b = 2, c = 1: x2 + 4x + 1 = 0; The roots are <image>
b = 2, c = 2: x2 + 4x + 2 = 0; The roots are <image>
b = 2, c = 3: x2 + 4x + 3 = 0; The roots are x1 = - 3, x2 = - 1
b = 3, c = 1: x2 + 6x + 1 = 0; The roots are <image>
b = 3, c = 2: x2 + 6x + 2 = 0; The roots are <image>
b = 3, c = 3: x2 + 6x + 3 = 0; The roots are <image> Overall there are 13 roots and as the root - 1 is repeated twice, that means there are 12 different roots.
Submitted Solution:
```
a, b= map(int, input().split())
c = (a*b)//2
print (c)
``` | instruction | 0 | 9,472 | 20 | 18,944 |
No | output | 1 | 9,472 | 20 | 18,945 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:
x2 + 2bx + c = 0 where b, c are natural numbers.
Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equations can have a common root.
Petya is interested in how many different real roots have all the equations of the type described above for all the possible pairs of numbers b and c such that 1 β€ b β€ n, 1 β€ c β€ m. Help Petya find that number.
Input
The single line contains two integers n and m. (1 β€ n, m β€ 5000000).
Output
Print a single number which is the number of real roots of the described set of equations.
Examples
Input
3 3
Output
12
Input
1 2
Output
1
Note
In the second test from the statement the following equations are analysed:
b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1
b = 1, c = 2: x2 + 2x + 2 = 0; No roots
Overall there's one root
In the second test the following equations are analysed:
b = 1, c = 1: x2 + 2x + 1 = 0; The root is x = - 1
b = 1, c = 2: x2 + 2x + 2 = 0; No roots
b = 1, c = 3: x2 + 2x + 3 = 0; No roots
b = 2, c = 1: x2 + 4x + 1 = 0; The roots are <image>
b = 2, c = 2: x2 + 4x + 2 = 0; The roots are <image>
b = 2, c = 3: x2 + 4x + 3 = 0; The roots are x1 = - 3, x2 = - 1
b = 3, c = 1: x2 + 6x + 1 = 0; The roots are <image>
b = 3, c = 2: x2 + 6x + 2 = 0; The roots are <image>
b = 3, c = 3: x2 + 6x + 3 = 0; The roots are <image> Overall there are 13 roots and as the root - 1 is repeated twice, that means there are 12 different roots.
Submitted Solution:
```
def fuck(a):
k=[]
for b in range(1,a[0]+1):
for c in range(1,a[1]+1):
if((2*b)**2-4*c<0):
break
else:
s1=-2*b+((((2*b)**2)-4*c)**0.5)
y=2
s2=(-2*b-(((2*b)**2)-4*c)**0.5)
z1=s1/y
z2=s2/y
k.append(z1)
k.append(z2)
return k
def h(k):
n=len(k)
if n==0 or n==1:
return n
j=0
for i in range(0,n-1):
if(k[i]!=k[i+1]):
k[j]=k[i]
j+=1
k[j]=k[n-1]
j+=1
return j
if __name__=='__main__':
a=[int(x) for x in input().split()]
s=fuck(a)
print(h(s))
``` | instruction | 0 | 9,473 | 20 | 18,946 |
No | output | 1 | 9,473 | 20 | 18,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
<image>
He ate coffee mix without water again, so right now he's really messed up and can't think.
Your task is to help him by telling him what to type.
Input
The first and only line of input contains an integer s (0 β€ s β€ 99), Tavas's score.
Output
In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.
Examples
Input
6
Output
six
Input
99
Output
ninety-nine
Input
20
Output
twenty
Note
You can find all you need to know about English numerals in <http://en.wikipedia.org/wiki/English_numerals> . | instruction | 0 | 9,474 | 20 | 18,948 |
Tags: brute force, implementation
Correct Solution:
```
import math
def need_to_name_it(num):
"""Returns something"""
abc = {0: "zero", 10: "ten", 1: "one", 11: "eleven", 2: "two", 12: "twelve", 20: "twenty", 3: "three",
13: "thirteen",
30: "thirty", 4: "four", 14: "fourteen", 40: "forty", 5: "five", 15: "fifteen", 50: "fifty", 6: "six",
16: "sixteen", 60: "sixty", 7: "seven", 17: "seventeen", 70: "seventy", 8: "eight", 18: "eighteen",
80: "eighty",
9: "nine", 19: "nineteen", 90: "ninety"}
if num not in abc.keys():
s = abc[(n // 10) * 10] + '-' + abc[n % 10]
else:
s = abc[n]
return s
def get_int():
return map(int, input().split())
n = int(input())
print(need_to_name_it(n))
``` | output | 1 | 9,474 | 20 | 18,949 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.