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.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10 | instruction | 0 | 76,025 | 20 | 152,050 |
Tags: implementation, math
Correct Solution:
```
x = int(input())
for _ in range(x):
num = int(input())
divisor = int('1' + '0'*(len(str(num))-1))
out = []
while num >9:
a = str(num//divisor) + '0'*(len(str(num))-1)
if int(a)!=0:
out.append(a)
num = num%divisor
divisor //=10
if num!=0:
out.append(str(num))
print(len(out))
print(' '.join(out))
``` | output | 1 | 76,025 | 20 | 152,051 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10 | instruction | 0 | 76,026 | 20 | 152,052 |
Tags: implementation, math
Correct Solution:
```
def to_list(s):
return list(map(lambda x: int(x), s.split(' ')))
def solve(s):
if len(s) == 1:
print(1)
print(s)
if len(s) > 1:
answers = []
n = len(s)
for i in range(n):
number = str(int(s[i])*10**(n-i-1))
if number != '0':
answers.append(number)
print(len(answers))
print(' '.join(answers))
t = int(input())
for i in range(t):
s = input()
solve(s)
``` | output | 1 | 76,026 | 20 | 152,053 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10 | instruction | 0 | 76,027 | 20 | 152,054 |
Tags: implementation, math
Correct Solution:
```
n = int(input())
for i in range(n):
d = input()
ld = len(d)
res = [int(d[n] + ''.join([(ld - n - 1) * str(0)])) if int(d[n]) != 0 else 0 for n in range(ld)]
res = list(filter(lambda x: x != 0, res))
print(len(res))
print(*res)
``` | output | 1 | 76,027 | 20 | 152,055 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10 | instruction | 0 | 76,028 | 20 | 152,056 |
Tags: implementation, math
Correct Solution:
```
t = int(input())
for i in range(t):
n = input()
lst = []
for j in range(len(n)):
if n[j] != '0':
lst.append(n[j] + '0' * (len(n) - 1 - j))
print(len(lst))
print(*lst)
``` | output | 1 | 76,028 | 20 | 152,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10 | instruction | 0 | 76,029 | 20 | 152,058 |
Tags: implementation, math
Correct Solution:
```
t = int(input())
a = []
for i in range(t):
i = int(input())
a.append(i)
for i in a:
b = []
k = 0
d = 10
for j in range(6):
if i % d != 0:
b.append(i % d)
i = i - i % d
k += 1
d *= 10
print(k)
print(' '.join(map(str, b)))
``` | output | 1 | 76,029 | 20 | 152,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
Submitted Solution:
```
t=int(input())
for i in range(t):
n=int(input())
s=str(n)
count=0
list1=[]
for i in range(len(s)):
if(s[i]!='0'):
count=count+1
p=len(s)-i-1
list1.append(int(s[i])*(10**p))
print(count)
for i in list(list1):
print(i,end=" ")
print()
``` | instruction | 0 | 76,030 | 20 | 152,060 |
Yes | output | 1 | 76,030 | 20 | 152,061 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
Submitted Solution:
```
t = int(input())
for i in range(t):
n = input()
ls = []
lenn = len(n)
for j in range(lenn):
if n[j] != '0':
ls.append(n[j]+'0'*(lenn-j-1))
print(len(ls))
print(*ls)
``` | instruction | 0 | 76,031 | 20 | 152,062 |
Yes | output | 1 | 76,031 | 20 | 152,063 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
Submitted Solution:
```
from sys import stdin, stdout
"""
n = stdin.readline()
arr = [int(x) for x in stdin.readline().split()]
stdout.write(str(summation))
"""
for test in range(int(stdin.readline())) :
n = int (stdin.readline())
arr = []
div = 10
while n>9 :
k = n%div
n = n-k
arr.append(k)
div = div*10
arr.append(n)
ans = []
for i in range(len(arr)) :
if arr[i]!=0 :
ans.append(arr[i])
print(len(ans))
print(*ans, sep=" ")
``` | instruction | 0 | 76,032 | 20 | 152,064 |
Yes | output | 1 | 76,032 | 20 | 152,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
Submitted Solution:
```
t = int(input())
s = ""
for i in range(t):
n = input()
x = 0
for j in range(len(n)):
if n[j] != "0" :
s = s + n[j] +"0"*(len(n)-j-1) + " "
x += 1
print(x)
print(s)
s = ""
``` | instruction | 0 | 76,033 | 20 | 152,066 |
Yes | output | 1 | 76,033 | 20 | 152,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
Submitted Solution:
```
t=int(input())
for i in range(t):
num=int(input())
c=0
l=[]
mul=1
while num>0:
if num%10==0:
l.append(num)
c+=1
break
c+=1
r=num%10
l.append(r*mul)
num=num//10
mul*=10
l=list(map(str,l))
print(c)
print(" ".join(l))
``` | instruction | 0 | 76,034 | 20 | 152,068 |
No | output | 1 | 76,034 | 20 | 152,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
Submitted Solution:
```
for o in range(int(input())):
n=int(input())
l=[]
while(n!=0):
s=len(str(n))
if(s==1):
d=1
else:
d=int("1"+'0'*(s-1))
l.append(str(n-(n%d)))
n=n%d
for i in range(0,len(l)):
print(l[i],end=" ")
print()
``` | instruction | 0 | 76,035 | 20 | 152,070 |
No | output | 1 | 76,035 | 20 | 152,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
Submitted Solution:
```
list1=[]
for i in range(1,11):
list1.append(i)
arr=list1
var=10
for i in range(0,10):
for j in range(0,10):
tmp=var*list1[j]
arr.append(tmp)
var=var*10
num=int(input())
for i in range(0,num):
final=[]
count=0
n=int(input())
if(n==1):
print(1+"/n"+1)
while(n>0):
for i in range(0,len(arr)):
if(arr[i]>n):
final.append(arr[i-1])
n=n-arr[i-1]
count+=1
break
print(count)
print(final)
``` | instruction | 0 | 76,036 | 20 | 152,072 |
No | output | 1 | 76,036 | 20 | 152,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from 1 to 9 (inclusive) are round.
For example, the following numbers are round: 4000, 1, 9, 800, 90. The following numbers are not round: 110, 707, 222, 1001.
You are given a positive integer n (1 β€ n β€ 10^4). Represent the number n as a sum of round numbers using the minimum number of summands (addends). In other words, you need to represent the given number n as a sum of the least number of terms, each of which is a round number.
Input
The first line contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Then t test cases follow.
Each test case is a line containing an integer n (1 β€ n β€ 10^4).
Output
Print t answers to the test cases. Each answer must begin with an integer k β the minimum number of summands. Next, k terms must follow, each of which is a round number, and their sum is n. The terms can be printed in any order. If there are several answers, print any of them.
Example
Input
5
5009
7
9876
10000
10
Output
2
5000 9
1
7
4
800 70 6 9000
1
10000
1
10
Submitted Solution:
```
T=int(input())
while T>0:
n=int(input())
a=str(n)
l=list(a)
for j in range(len(l)):
l[j]=int(l[j])*(10**(len(l)-j-1))
for i in l:
if i!=0:
print(int(i),end=" ")
print()
T-=1
``` | instruction | 0 | 76,037 | 20 | 152,074 |
No | output | 1 | 76,037 | 20 | 152,075 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 76,189 | 20 | 152,378 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n = int(input())
As = list(map(float, input().split()))
B = list(x - int(x) for x in As if x - int(x) > 0.000)
l = len(B)
if l == 0:
print('{:.3f}'.format(0))
exit(0)
S = sum(x for x in B)
ll = l if l % 2 == 0 else l + 1
ans = 1e10
for i in range(max(0, l - n), (n if l > n else l) + 1):
ans = min(ans, abs(i - S))
print('{:.3f}'.format(ans))
``` | output | 1 | 76,189 | 20 | 152,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 76,190 | 20 | 152,380 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n = int(input())
As = list(map(float, input().split()))
B = list(x - int(x) for x in As if x - int(x) > 0.000)
l = len(B)
if l == 0:
print('{:.3f}'.format(0))
exit(0)
S = sum(x for x in B)
ans = 1e10
for i in range(max(0, l - n), min(l,n) + 1):
ans = min(ans, abs(i - S))
print('{:.3f}'.format(ans))
``` | output | 1 | 76,190 | 20 | 152,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 76,191 | 20 | 152,382 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n, k, s = int(input()), 0, 0
for i in input().split():
j = int(i[-3: ])
if j == 0: k += 1
else: s += j
c = s // 1000 + int(s % 1000 > 500)
a, b = max(0, n - k), min(2 * n - k, n)
if a <= c <= b: s = abs(c * 1000 - s)
else: s = min(abs(a * 1000 - s), abs(b * 1000 - s))
print(str(s // 1000) + '.' + str(s % 1000).zfill(3))
``` | output | 1 | 76,191 | 20 | 152,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 76,192 | 20 | 152,384 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n = int(input())
arr = list(map(float, input().split()))
arr = sorted([x - int(x) for x in arr if x - int(x) != 0])
o = 2 * n - len(arr)
arr_sum = sum(arr)
res = int(2e9)
for i in range(n + 1):
if i + o >= n:
res = min(res, abs(i - arr_sum))
print("%.3f" % res)
``` | output | 1 | 76,192 | 20 | 152,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 76,193 | 20 | 152,386 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n = int(input())
l = list(map(float, input().split()))
l = sorted([x - int(x) for x in l if x - int(x) != 0])
o = 2*n - len(l)
su = sum(l)
ans = 0xFFFFFFFFFFFFFFF
for i in range(n + 1):
if i + o >= n:
ans = min(ans, abs(i-su))
print("%.3f" % ans)
``` | output | 1 | 76,193 | 20 | 152,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 76,194 | 20 | 152,388 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
n, t = int(input()), [int(i[-3: ]) for i in input().split()]
k, s = t.count(0), sum(t)
c = s // 1000 + int(s % 1000 > 500)
a, b = max(0, n - k), min(2 * n - k, n)
if a <= c <= b: s = abs(c * 1000 - s)
else: s = min(abs(a * 1000 - s), abs(b * 1000 - s))
print(str(s // 1000) + '.' + str(s % 1000).zfill(3))
``` | output | 1 | 76,194 | 20 | 152,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 76,195 | 20 | 152,390 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
from sys import *
import math
def numline(f = int):
return map(f, input().split())
n = int(input())
a = list(filter(lambda x: x != 0, numline(lambda s: int(s.split('.')[1]))))
# print(' '.join(map(str, a)))
c0 = min(2 * n - len(a), len(a))
s = sum(a) - 1000 * min(n, len(a))
ans = abs(s)
for i in range(c0):
s += 1000
ans = min(ans, abs(s))
print('{}.{:0>3}'.format(ans // 1000, ans % 1000))
``` | output | 1 | 76,195 | 20 | 152,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
* choose indexes i and j (i β j) that haven't been chosen yet;
* round element ai to the nearest integer that isn't more than ai (assign to ai: β ai β);
* round element aj to the nearest integer that isn't less than aj (assign to aj: β aj β).
Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference.
Input
The first line contains integer n (1 β€ n β€ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 β€ ai β€ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces.
Output
In a single line print a single real number β the required difference with exactly three digits after the decimal point.
Examples
Input
3
0.000 0.500 0.750 1.000 2.000 3.000
Output
0.250
Input
3
4469.000 6526.000 4864.000 9356.383 7490.000 995.896
Output
0.279
Note
In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | instruction | 0 | 76,196 | 20 | 152,392 |
Tags: dp, greedy, implementation, math
Correct Solution:
```
from sys import *
s1=stdin.readline().strip()
n=int(s1)
s1=stdin.readline().strip()
a=list(map(float,s1.split()))
b=[]
for i in range (2*n):
if int(a[i])!=a[i]:
b.append(round(1000*(a[i]-int(a[i]))))
m=len(b)
r=0
for i in range (m):
r=r+b[i]
if m<=n:
if r>=1000*m:
r=r-1000*m
else:
r=min(r-1000*(r//1000),1000-r+1000*(r//1000))
else:
if r>=n*1000:
r=r-1000*n
else:
if r<=1000*(m-n):
r=1000*(m-n)-r
else:
r=min(r-1000*(r//1000),1000-r+1000*(r//1000))
r=r/1000
print("%.3f"%r)
``` | output | 1 | 76,196 | 20 | 152,393 |
Provide a correct Python 3 solution for this coding contest problem.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow | instruction | 0 | 76,592 | 20 | 153,184 |
"Correct Solution:
```
for _ in range(int(input())):
a = int(input())
b = int(input())
s = a + b
if s >= 10 ** 80:
print('overflow')
else:
print(s)
``` | output | 1 | 76,592 | 20 | 153,185 |
Provide a correct Python 3 solution for this coding contest problem.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow | instruction | 0 | 76,593 | 20 | 153,186 |
"Correct Solution:
```
n = int(input())
for i in range(n):
a = int(input())
b = int(input())
c = str(a+b)
if len(c) > 80:
print("overflow")
else:
print(c)
``` | output | 1 | 76,593 | 20 | 153,187 |
Provide a correct Python 3 solution for this coding contest problem.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow | instruction | 0 | 76,594 | 20 | 153,188 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import math
BIG_NUM = 100000000000000000000000000000000000000000000000000000000000000000000000000000000
def main():
n = int(input())
for _ in range(n):
a = int(input())
b = int(input())
if a >= BIG_NUM or b >= BIG_NUM or a + b >= BIG_NUM:
print("overflow")
else:
print(a+b)
if __name__ == "__main__":
main()
``` | output | 1 | 76,594 | 20 | 153,189 |
Provide a correct Python 3 solution for this coding contest problem.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow | instruction | 0 | 76,595 | 20 | 153,190 |
"Correct Solution:
```
if __name__ == '__main__':
N = int(input())
for _ in range(N):
a = input()
b = input()
c = str(int(a) + int(b))
if len(a) > 80 or len(b) > 80 or len(c) > 80:
print("overflow")
else:
print(c)
``` | output | 1 | 76,595 | 20 | 153,191 |
Provide a correct Python 3 solution for this coding contest problem.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow | instruction | 0 | 76,596 | 20 | 153,192 |
"Correct Solution:
```
N=int(input())
for i in range(N):
a=int(input())
b=int(input())
retval=a+b
if len(str(retval))>80:
print("overflow")
else:
print(retval)
``` | output | 1 | 76,596 | 20 | 153,193 |
Provide a correct Python 3 solution for this coding contest problem.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow | instruction | 0 | 76,597 | 20 | 153,194 |
"Correct Solution:
```
import sys
import re
def line():return sys.stdin.readline().strip()
N = input()
while True:
try:
a = int(line())
b = int(line())
if a + b >= 10 ** 80:
print("overflow")
else:
print(a + b)
except:
break
``` | output | 1 | 76,597 | 20 | 153,195 |
Provide a correct Python 3 solution for this coding contest problem.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow | instruction | 0 | 76,598 | 20 | 153,196 |
"Correct Solution:
```
# -*- coding:utf-8 -*-
def main():
for i in range(int(input())):
a=int(input())+int(input())
if a>=10**80:
print("overflow")
else:
print(a)
if __name__ == '__main__':
main()
``` | output | 1 | 76,598 | 20 | 153,197 |
Provide a correct Python 3 solution for this coding contest problem.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow | instruction | 0 | 76,599 | 20 | 153,198 |
"Correct Solution:
```
n = int(input())
for i in range(n):
a = int(input())
b = int(input())
if (a + b) < (10 ** 80):
print(a + b)
else:
print("overflow")
``` | output | 1 | 76,599 | 20 | 153,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
Submitted Solution:
```
n=int(input())
for _ in range(n):
a=input()
b=input()
s=int(a)+int(b)
if len(a)>80 or len(b)>80 or len(str(s))>80:
print("overflow")
continue
else:
print(s)
``` | instruction | 0 | 76,600 | 20 | 153,200 |
Yes | output | 1 | 76,600 | 20 | 153,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
Submitted Solution:
```
def overflow(s):
if len(s) > 80:
print('overflow')
else:
print(s)
def string_sum(la, lb):
d = abs(len(la) - len(lb))
if len(la) > len(lb):
lb = "0" * d + lb
else:
la = "0" * d + la
ls = []
carry = 0
for a, b in zip(la[::-1], lb[::-1]):
s = int(a) + int(b) + carry
ls.append(str(s % 10))
carry = s // 10
if carry == 1:
ls.append('1')
return ''.join(ls[::-1])
n = int(input())
while n > 0:
one = input()
two = input()
overflow(string_sum(one, two))
n -= 1
``` | instruction | 0 | 76,601 | 20 | 153,202 |
Yes | output | 1 | 76,601 | 20 | 153,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
Submitted Solution:
```
# ?????ΒΆ??????????Β±???????????????Β°??????
import sys
def main():
n = int(sys.stdin.readline().strip())
for _ in range(n):
x = sys.stdin.readline().strip()
y = sys.stdin.readline().strip()
if len(x) > 80 or len(y) > 80:
print('overflow')
else:
ans = int(x) + int(y)
if len(str(ans)) > 80:
print('overflow')
else:
print(ans)
if __name__ == '__main__':
main()
``` | instruction | 0 | 76,602 | 20 | 153,204 |
Yes | output | 1 | 76,602 | 20 | 153,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
Submitted Solution:
```
n=int(input())
for i in range(n):
a=int(input())
b=int(input())
if a+b>=10**80:print("overflow")
else:print(a+b)
``` | instruction | 0 | 76,603 | 20 | 153,206 |
Yes | output | 1 | 76,603 | 20 | 153,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
Submitted Solution:
```
import math
a=int(input())
b=int(input())
c=a+b
for x in range(80):
c=math.floor(c/10)
if(c>=1):
print("overflow")
else:
print(a+b)
``` | instruction | 0 | 76,604 | 20 | 153,208 |
No | output | 1 | 76,604 | 20 | 153,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
Submitted Solution:
```
n=int(input())
for _ in range(n):
s=int(input())+int(input())
print('overflow' iflen(str(s))>80 else s)
``` | instruction | 0 | 76,605 | 20 | 153,210 |
No | output | 1 | 76,605 | 20 | 153,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
Submitted Solution:
```
upper = 10**80
n = int(input())
for i in range(n):
n1 = int(input())
if n1 >= upper:
print("overflow")
continue
n2 = int(input())
if n2 >= upper:
print("overflow")
continue
print( n1 + n2 if n1+n2 < upper else "overflow")
``` | instruction | 0 | 76,606 | 20 | 153,212 |
No | output | 1 | 76,606 | 20 | 153,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647.
Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers.
If given integers or the sum have more than 80 digits, print "overflow".
Input
Input consists of several datasets. In the first line, the number of datasets N (1 β€ N β€ 50) is given. Each dataset consists of 2 lines:
The first integer
The second integer
The integer has at most 100 digits.
Output
For each dataset, print the sum of given integers in a line.
Example
Input
6
1000
800
9999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
1
99999999999999999999999999999999999999999999999999999999999999999999999999999999
0
100000000000000000000000000000000000000000000000000000000000000000000000000000000
1
100000000000000000000000000000000000000000000000000000000000000000000000000000000
100000000000000000000000000000000000000000000000000000000000000000000000000000000
Output
1800
10000000000000000000000000000000000000000
overflow
99999999999999999999999999999999999999999999999999999999999999999999999999999999
overflow
overflow
Submitted Solution:
```
upper = 10**81
n = int(input())
for i in range(n):
n1 = int(input())
if n1 >= upper:
print("overflow")
continue
n2 = int(input())
if n2 >= upper:
print("overflow")
continue
print( n1 + n2 if n1+n2 < upper else "overflow")
``` | instruction | 0 | 76,607 | 20 | 153,214 |
No | output | 1 | 76,607 | 20 | 153,215 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | instruction | 0 | 76,839 | 20 | 153,678 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
T = 1
MAX = 3*(10**5) + 10
for t in range(1, T + 1):
# print('Case #' + str(t) + ': ', end = '')
# n = int(input())
a, b, c, d = map(int, input().split())
a_, b_,c_, d_ = a, b, c, d
if a == 0 and b == 0:
if abs(c - d) > 1:
print("NO")
continue
if c > d:
print("YES")
ans = ("2 " * (c - d > 0) + "3 2 " * d)
else:
print("YES")
ans = ("3 " * (d - c > 0) + "2 3 " * c)
elif d == 0 and c == 0:
if abs(a - b) > 1:
print("NO")
continue
if a > b:
print("YES")
ans = ("0 " * (a - b > 0) + "1 0 " * b )
else:
print("YES")
ans = ("1 " * (b - a > 0) + "0 1 " * a )
else:
if b < a or c < d:
print("NO")
continue
b -= a
c -= d
minval = min(b, c)
b -= minval
c -= minval
if b > 1 or c > 1:
print("NO")
continue
print("YES")
ans = ('1 '*b + '0 1 ' * a + '2 1 ' * minval + '2 3 ' * d + '2 ' * c)
print(ans)
x = list(map(int, ans.split()))
# print(x.count(0) , a_ , x.count(1) , b_ , x.count(3), c_ , x.count(4) , d_)
assert(x.count(0) == a_ and x.count(1) == b_ and x.count(2) == c_ and x.count(3) == d_)
for i in range(1, len(x)):
assert(abs(x[i] - x[i - 1]) == 1)
``` | output | 1 | 76,839 | 20 | 153,679 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | instruction | 0 | 76,840 | 20 | 153,680 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def smp(): return map(str, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def remadd(x, y): return 1 if x%y else 0
def ceil(a,b): return (a+b-1)//b
def isprime(x):
if x<=1: return False
if x in (2, 3): return True
if x%2 == 0: return False
for i in range(3, int(sqrt(x))+1, 2):
if x%i == 0: return False
return True
a, b, c, d = mp()
if (a+c)%2!=(b+d)%2:
if abs(a+c-b-d)!=1:
print("NO")
else:
if a+c>b+d:
ml = []
n = a+b+c+d
for i in range(n):
if i%2:
if b>0:
ml.append(1)
b-=1
else:
ml.append(3)
else:
if a>0:
ml.append(0)
a-=1
else:
ml.append(2)
else:
ml = []
n = a+b+c+d
for i in range(n):
if i%2==0:
if b>0:
ml.append(1)
b-=1
else:
ml.append(3)
else:
if a>0:
ml.append(0)
a-=1
else:
ml.append(2)
t = True
for i in range(1, n):
if ml[i]-ml[i-1] not in [-1, 1]:
t = False
break
if t:
print("YES")
print(*ml)
else:
print("NO")
else:
if a+c!=b+d:
print("NO")
else:
arr1 = []
arr2 = []
n = a+b+c+d
a1, b1, c1, d1 = a, b, c, d
for i in range(n):
if i%2==0:
arr1.append(0 if a>0 else 2)
a-=1
arr2.append(1 if b1>0 else 3)
b1-=1
else:
arr1.append(1 if b>0 else 3)
b-=1
arr2.append(0 if a1>0 else 2)
a1 -= 1
t1 = True
t2 = True
for i in range(1, n):
if abs(arr1[i]-arr1[i-1])!=1:
t1 = False
if abs(arr2[i]-arr2[i-1])!=1:
t2 = False
if not t1 and not t2: break
if t1:
print("YES")
print(*arr1)
elif t2:
print("YES")
print(*arr2)
else:
print("NO")
``` | output | 1 | 76,840 | 20 | 153,681 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | instruction | 0 | 76,841 | 20 | 153,682 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
def printres(res):
print("YES")
print(' '.join(map(str, res)))
def main():
cc = [int(a) for a in input().split()]
nz = []
for i,c in enumerate(cc):
if c > 0:
nz.append(i)
if len(nz) == 1:
if cc[nz[0]] == 1:
printres([nz[0]])
else:
print("NO")
return
elif len(nz) == 2:
if nz[1] != nz[0] + 1:
print("NO")
return
df = cc[nz[1]] - cc[nz[0]]
if abs(df) > 1:
print("NO")
return
if df == 1:
printres([nz[1]] + [nz[0], nz[1]] * cc[nz[0]])
elif df == 0:
printres([nz[0], nz[1]] * cc[nz[0]])
else:
printres([nz[0], nz[1]] * cc[nz[1]] + [nz[0]])
return
elif len(nz) == 3:
if nz[2] != nz[1] +1 or nz[1] != nz[0] + 1:
print("NO")
return
df = cc[nz[0]] + cc[nz[2]] - cc[nz[1]]
if abs(df) > 1:
print("NO")
return
if df == 1:
printres([nz[0], nz[1]] * cc[nz[0]] + [nz[2], nz[1]] * (cc[nz[2]] -1) + [nz[2]])
elif df == 0:
printres([nz[0], nz[1]] * cc[nz[0]] + [nz[2], nz[1]] * cc[nz[2]])
else:
printres([nz[1]] + [nz[0], nz[1]] * cc[nz[0]] + [nz[2], nz[1]] * cc[nz[2]])
return
else:
df = cc[0] - cc[1] + cc[2] - cc[3]
if abs(df) > 1:
print("NO")
return
y = min(cc[1] - cc[0], cc[2] - cc[3])
if y < 0:
print("NO")
return
base = [0,1] * cc[0] + [2, 1] * y + [2, 3] * cc[3]
if df == 1:
printres(base + [2])
elif df == 0:
printres(base)
else:
printres([1] + base)
return
if __name__ == "__main__":
main()
``` | output | 1 | 76,841 | 20 | 153,683 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | instruction | 0 | 76,842 | 20 | 153,684 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
a, b, c, d = map(int, input().split())
p = 0
e = []
if a > b:
if c == 0 and d == 0 and a == (b + 1):
for j in range(a + b):
if j % 2 == 0:
e.append(0)
else:
e.append(1)
else:
p = 1
else:
if d > c:
if a == 0 and b == 0 and d == (c + 1):
for j in range(c + d):
if j % 2 == 0:
e.append(3)
else:
e.append(2)
else:
p = 1
else:
g = []
f = []
i = []
for j in range(2 * a):
if j % 2 == 0:
g.append(0)
else:
g.append(1)
for j in range(2 * d):
if j % 2 == 0:
f.append(2)
else:
f.append(3)
b += -a
c += -d
if abs(b - c) > 1:
p = 1
else:
if abs(b - c) == 0:
for j in range(b + c):
if j % 2 == 0:
i.append(2)
else:
i.append(1)
if b == c + 1:
for j in range(2 * c):
if j % 2 == 0:
i.append(2)
else:
i.append(1)
g.insert(0, 1)
elif c == b + 1:
for j in range(2 * b):
if j % 2 == 0:
i.append(2)
else:
i.append(1)
f.append(2)
e = g + i + f
if p == 1:
print("NO")
else:
print("YES")
print(*e)
``` | output | 1 | 76,842 | 20 | 153,685 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | instruction | 0 | 76,843 | 20 | 153,686 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
import sys
input = sys.stdin.readline
a,b,c,d = map(int, input().split())
res=0
str1=[]
str2=[]
str3=[]
if (a>0):
str1.append("0 ")
a-=1;
if (d>0):
str2.append("3 ")
d=d-1
res=0
while(a>0):
if(b>0):
str1.append("1 0 ")
a-=1
b-=1
else :
res=-1
break
while(d>0):
if(c>0):
str2.append("2 3 ")
c-=1
d-=1
else :
res=-1
break
if(len(str1)!=0 and len(str2)!=0 and (b==0 or c==0)):
res=-1
if(len(str1)==0 and len(str2)!=0 and (c==0 and b!=0)):
res=-1
if(len(str1)!=0 and len(str2)==0 and (b==0 and c!=0)):
res=-1
while(b>0 and c>0):
str3.append("1 2 ")
b-=1
c-=1
if(b>0):
if(len(str1)!=0 ):
str4=["1 "]
str4.extend(str1)
str1=str4
b-=1
if(b>0 and len(str3)==0):
str1.append("1 ")
b-=1
if(b>0):
if(len(str2)==0 and len(str3)!=0):
str3.append("1 ");
b-=1;
if(b>0):
res=-1;
if(c>0):
if(len(str2)!=0):
str2.append("2 ")
c-=1
if(len(str3)==0 and c>0):
str3.append("2 ")
c-=1
if(c>0):
if(len(str1)==0 and len(str3)!=0 and str3[0]!="2 "):
str4=["2 "]
str4.extend(str3)
str3=str4
c-=1
if(c>0):
res=-1
ans=""
if(res==0):
str1.extend(str3)
str1.extend(str2)
print("YES")
ans=ans.join(str1)
print(ans)
else :
print("NO")
``` | output | 1 | 76,843 | 20 | 153,687 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | instruction | 0 | 76,844 | 20 | 153,688 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
"""
Satwik_Tiwari ;) .
6th Sept , 2020 - Sunday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned
#==============================================================================================
#fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n") #as stdout.write always print sring.
def testcase(t):
for pp in range(t):
solve(pp)
def printlist(a) :
for p in range(0,len(a)):
out(str(a[p]) + ' ')
def google(p):
print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) : # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
#===============================================================================================
# code here ;))
def solve(case):
a,b,c,d = sep()
# if(a>b):
# print('NO')
# return
# if(d>c):
# print('NO')
# return
#
left = []
right = []
mid = []
for i in range(min(a,b)):
left.append(0)
left.append(1)
a-=1
b-=1
for i in range(min(c,d)):
right.append(2)
right.append(3)
c-=1
d-=1
for i in range(min(c,b)):
mid.append(2)
mid.append(1)
c-=1
b-=1
if(b>0):
left.insert(0,1)
b-=1
if(c>0):
right.append(2)
c-=1
if(a>0):
left.append(0)
a-=1
if(d>0):
right.insert(0,3)
d-=1
if(a>0 or b>0 or c>0 or d>0):
print('NO')
else:
f = True
ans = left+mid+right
# print(ans)
for i in range(1,len(ans)):
if(abs(ans[i]-ans[i-1]) == 1):
continue
else:
f = False
break
if(f):
print('YES')
print(' '.join(str(ans[i]) for i in range(len(ans))))
else:
print('NO')
testcase(1)
# testcase(int(inp()))
``` | output | 1 | 76,844 | 20 | 153,689 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | instruction | 0 | 76,845 | 20 | 153,690 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
from sys import stdin
#####################################################################
def iinput(): return int(stdin.readline())
def sinput(): return input()
def minput(): return map(int, stdin.readline().split())
def linput(): return list(map(int, stdin.readline().split()))
#####################################################################
a = linput()
ref = [0,1,2,3]
x = sum(a)
for i in range(4):
b = a[:]
seq = []
for j in range(x):
b[i] -= 1
seq.append(ref[i])
if(i == 0): i = 1
elif(i == 3): i = 2
elif(i == 1):
if(b[0] > 0): i = 0
else: i = 2
else:
if(b[3] > 0): i = 3
else: i = 1
if(max(b) == 0 and min(b) == 0):
print('YES')
print(*seq)
exit()
print('NO')
``` | output | 1 | 76,845 | 20 | 153,691 |
Provide tags and a correct Python 3 solution for this coding contest problem.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests. | instruction | 0 | 76,846 | 20 | 153,692 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
a, b, c, d = [int(x) for x in input().split()]
res = [0 for _ in range(a)]
res+= [2 for _ in range(c)]
if a+c<b+d:
ind=0
else:
ind=1
while (b>0):
res.insert(ind, 1)
ind+=2
b-=1
while (d>0):
res.insert(ind, 3)
ind+=2
d-=1
tr = True
for i in range(1, len(res)):
if abs(res[i-1]-res[i])!=1:
print ('NO')
tr = False
break
if tr:
print ('YES')
print (*res)
``` | output | 1 | 76,846 | 20 | 153,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
Submitted Solution:
```
a,b,c,d = [int(x) for x in input().split()]
dn = {0: a, 1: b, 2: c, 3: d}
total = a+b+c+d
flag = 1
for i in range(4):
if dn[i] == 0:
continue
soln = []
soln.append(i)
td = dn.copy()
td[i]-=1
last = i
for j in range(total-1):
if td.get(last-1, 0):
soln.append(last-1)
td[last-1]-=1
last = last-1
elif td.get(last+1, 0):
soln.append(last+1)
td[last+1]-=1
last = last+1
else:
break
if len(soln) == total:
print("YES")
for i in soln:
print(i, end=' ')
print()
flag = 0
break
if flag:
print("NO")
``` | instruction | 0 | 76,847 | 20 | 153,694 |
Yes | output | 1 | 76,847 | 20 | 153,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
Submitted Solution:
```
from sys import stdin
input = stdin.readline
a, b, c, d = map(int, input().split())
if abs(a + c - b - d) > 1:
print("NO")
exit(0)
ans = [-1]
for i in range(a + c):
if i < c:
ans.append(2)
ans.append(-1)
else:
ans.append(0)
ans.append(-1)
def check(lst):
pre = -1
for i in lst:
if pre != -1 and abs(pre - i) != 1:
return False
pre = i
return True
if a + c <= b + d:
i = 0
while i // 2 < b + d:
if i // 2 < d:
ans[i] = 3
else:
ans[i] = 1
i += 2
if check(ans[:a + b + c + d]):
print("YES")
print(*ans[:a + b + c + d])
else:
print("NO")
else:
i = 2
while i // 2 - 1 < b + d:
if i // 2 - 1 < d:
ans[i] = 3
else:
ans[i] = 1
i += 2
if check(ans[1:a + b + c + d + 1]):
print("YES")
print(*ans[1:a + b + c + d + 1])
else:
print("NO")
``` | instruction | 0 | 76,848 | 20 | 153,696 |
Yes | output | 1 | 76,848 | 20 | 153,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
Submitted Solution:
```
import sys
ip=lambda :sys.stdin.readline().rstrip()
a,b,c,d=map(int,ip().split())
ans=[-1]*(a+b+c+d)
if a-b>1 or d-c>1:
print("NO")
elif a-b==1:
if c or d:
print("NO")
else:
print("YES")
print('0 1 '*b,end="")
print('0')
elif d-c==1:
if a or b:
print("NO")
else:
print("YES")
print('3 2 '*c,end="")
print('3')
else:
ct1,ct2=b-a,c-d
if abs(ct1 - ct2)>1:
print("NO")
sys.exit(0)
else:
print("YES")
end=""
if ct1>ct2:
print('1 ',end="")
ct1-=1
elif ct2>ct1:
end='2'
print('0 1 '*a,end="")
print('2 1 '*ct1,end="")
print('2 3 '*d,end="")
print(end)
``` | instruction | 0 | 76,849 | 20 | 153,698 |
Yes | output | 1 | 76,849 | 20 | 153,699 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
Submitted Solution:
```
#######################################################################################################################
# Author: BlackFyre
# Language: PyPy 3.7
#######################################################################################################################
from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353
# setrecursionlimit(3000)
def inp(): return stdin.readline().strip()
def iinp(): return int(inp())
def out(var, end="\n"): stdout.write(str(var) + "\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def smp(): return map(str, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(m, val) for j in range(n)]
def remadd(x, y): return 1 if x % y else 0
def ceil(a, b): return (a + b - 1) // b
def def_value(): return 0
a = lmp()
a = [0]+a+[0]
b = a.copy()
n = sum(a)
f2 = False
for kkk in range(4):
a = b.copy()
if a[kkk+1]>0:
ans = l1d(n,-1)
ans[0]=kkk
a[kkk+1]-=1
i=1
flg = False
while i<n:
if a[ans[i-1]]>0:
ans[i]=ans[i-1]-1
a[ans[i-1]]-=1
elif a[ans[i-1]+2]>0:
ans[i]=ans[i-1]+1
a[ans[i-1]+2]-=1
else:
flg=True
break
i+=1
if not flg:
print("YES")
print(*ans)
f2 = True
break
if not f2: print("NO")
``` | instruction | 0 | 76,850 | 20 | 153,700 |
Yes | output | 1 | 76,850 | 20 | 153,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1. More formally, a sequence s_1, s_2, β¦, s_{n} is beautiful if |s_i - s_{i+1}| = 1 for all 1 β€ i β€ n - 1.
Trans has a numbers 0, b numbers 1, c numbers 2 and d numbers 3. He wants to construct a beautiful sequence using all of these a + b + c + d numbers.
However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
Input
The only input line contains four non-negative integers a, b, c and d (0 < a+b+c+d β€ 10^5).
Output
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line.
Otherwise, print "YES" (without quotes) in the first line. Then in the second line print a + b + c + d integers, separated by spaces β a beautiful sequence. There should be a numbers equal to 0, b numbers equal to 1, c numbers equal to 2 and d numbers equal to 3.
If there are multiple answers, you can print any of them.
Examples
Input
2 2 2 1
Output
YES
0 1 0 1 2 3 2
Input
1 2 3 4
Output
NO
Input
2 2 2 3
Output
NO
Note
In the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to 1. Also, there are exactly two numbers, equal to 0, 1, 2 and exactly one number, equal to 3.
It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
Submitted Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
a,b,c,d=map(int,input().split())
a1,b1,c1,d1=a,b,c,d
#we can create the 2 blocks and then consider the sequence in the middle
b-=a
c-=d
a=0
d=0
if b<0 or c<0:
print("NO")
else:
if abs(b-c)<=1:
print("YES")
block1=[]
block2=[]
block3=[]
for s in range(a1):
block1.append("0")
block1.append("1")
for s in range(d1):
block3.append("2")
block3.append("3")
for s in range(min(b,c)):
block2.append("2")
block2.append("1")
b-=1
c-=1
for s in range(c):
block3.append("2")
for s in range(b):
block1=["1"]+block1
outy=block1+block2+block3
print(" ".join(outy))
else:
print("NO")
``` | instruction | 0 | 76,852 | 20 | 153,704 |
No | output | 1 | 76,852 | 20 | 153,705 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.