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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n from 1 to 10^{18} without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.
What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25.
Input
The first line contains an integer n (1 β€ n β€ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero.
Output
If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number.
Note that you can swap only adjacent digits in the given number.
Examples
Input
5071
Output
4
Input
705
Output
1
Input
1241367
Output
-1
Note
In the first example one of the possible sequences of moves is 5071 β 5701 β 7501 β 7510 β 7150.
Submitted Solution:
```
def check():
res = 0
if (cnt[0]>1):
res += 1
if (cnt[0]>0 and cnt[5]>0):
res += 2
if (cnt[5]>0 and (cnt[2]>0 or cnt[7]>0)):
res += 4
return res
num = int(input())
cnt = []
str = []
for i in range(10):
cnt.append(0)
#print("cnt's length is ",len(cnt))
while num != 0:
i = num%10
# print("num =",num," i = ",i)
str.append(i)
cnt[i]+=1
num //= 10
k = check()
ans = 40
if (k==0):
print("-1")
if (k&1==1):#00
tmp = index = 0
cok = 2
for i in str :
if i==0 :
tmp += index
cok -= 1
index += 1
if cok == 0:
break
ans = min(ans,tmp-1)
if k&2==2:#50
index = 0
zero = five = -1
for i in str :
if i==0 and zero == -1 :
zero = index
elif i==5 and five == -1 :
five = index
index += 1
if zero < five :
ans = min(ans,zero+five-1)
else :
ans = min(ans,zero+five)
if k&4==4:#25 or 75
index = 0
five = tos = -1
for i in str :
if i==5 and five == -1:
five = index
elif tos == -1 and ( i==2 or i==7 ):
tos = index
index += 1
if five < tos :
ans = min(ans,five+tos-1)
else :
if five == len(str)-1:
index = five-1
while index >=0 and ( index == tos or str[index]==0 ):
index -= 1;
else :
# print("index = ",index)
if index != -1:
tmp = five-1-index
if index < tos:
tos -= 1
tmp += five + tos
if index != five-1:
tmp -= 1
# print(tox , index , five , tmp)
ans = min(ans,tmp)
else :
ans = min(ans,five+tos)
if k!=0 :
print(ans)
``` | instruction | 0 | 82,343 | 20 | 164,686 |
No | output | 1 | 82,343 | 20 | 164,687 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n from 1 to 10^{18} without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.
What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25.
Input
The first line contains an integer n (1 β€ n β€ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero.
Output
If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number.
Note that you can swap only adjacent digits in the given number.
Examples
Input
5071
Output
4
Input
705
Output
1
Input
1241367
Output
-1
Note
In the first example one of the possible sequences of moves is 5071 β 5701 β 7501 β 7510 β 7150.
Submitted Solution:
```
def solve1():
n = m
try:
x = n.index('0')
n = n[x] + n[:x] + n[x+1:]
x += len(n) - len(n.rstrip('0'))
y = n.index('5')
return x + y - 1
except:
return float('inf')
def solve2():
n = m
try:
x = n.index('0')
y = n.find('0', x+1)
return x + y - 1
except:
return float('inf')
def solve3():
n = m
try:
x = n.index('5')
n = n[x] + n[:x] + n[x+1:]
x += len(n) - len(n.rstrip('0'))
y = n.index('2')
return x + y - 1
except:
return float('inf')
def solve4():
n = m
try:
x = n.index('5')
n = n[x] + n[:x] + n[x+1:]
x += len(n) - len(n.rstrip('0'))
y = n.index('7')
return x + y - 1
except:
return float('inf')
m = input()[::-1]
x = min(
solve1(),
solve2(),
solve3(),
solve4()
)
if x == float('inf'):
print(-1)
else:
print(x)
``` | instruction | 0 | 82,344 | 20 | 164,688 |
No | output | 1 | 82,344 | 20 | 164,689 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n from 1 to 10^{18} without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.
What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25.
Input
The first line contains an integer n (1 β€ n β€ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero.
Output
If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number.
Note that you can swap only adjacent digits in the given number.
Examples
Input
5071
Output
4
Input
705
Output
1
Input
1241367
Output
-1
Note
In the first example one of the possible sequences of moves is 5071 β 5701 β 7501 β 7510 β 7150.
Submitted Solution:
```
s = input().strip()[::-1]
print(s)
def find(a, b):
if a not in s or b not in s: return 40
i = s.index(a)
if(a == b):
if b not in s[i+1:]: return 40
j = s.index(b, i+1)
else: j = s.index(b)
return i + j - 1 + (1 if i > j else 0)
t = min(find('0', '0'), find('5', '2'), find('0', '5'), find('5', '7'))
print(t if t < 40 else -1)
``` | instruction | 0 | 82,345 | 20 | 164,690 |
No | output | 1 | 82,345 | 20 | 164,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n from 1 to 10^{18} without leading zeroes.
In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.
What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25.
Input
The first line contains an integer n (1 β€ n β€ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero.
Output
If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number.
Note that you can swap only adjacent digits in the given number.
Examples
Input
5071
Output
4
Input
705
Output
1
Input
1241367
Output
-1
Note
In the first example one of the possible sequences of moves is 5071 β 5701 β 7501 β 7510 β 7150.
Submitted Solution:
```
k = input()
zeroes = [-1, -1]
five = -1
two = -1
seven = -1
for i in range(len(k)):
if k[i] == '0':
zeroes[zeroes.index(min(zeroes))] = i
elif k[i] == '2':
two = i
elif k[i] == '5':
five = i
elif k[i] == '7':
seven = i
if len(k) == 3 and k[:2] == '50' and k[-1] != '5' and k[-1] != '0':
print(2)
elif k == '5020' or k == '5070':
print(1)
elif k[-2:] == '25' or k[-2:] == '00' or k[-2:] == '50' or k[-2:] == '75':
print(0)
elif k[-2:] == '52' or k[-2:] == '05' or k[-2:] == '57':
print(1)
elif k == '505':
print(1)
elif k == '500':
print(0)
elif len(k) != 4 and ((k[:3] == '502' and two == 2) or (k[:3] == '507' and seven == 2)):
print((len(k)))
elif (len(k) == 4) and (k[:3] == '502' or k[:3] == '507'):
print(4)
elif k[:2] == '50' and five == 0 and min(zeroes) == -1 and (seven != -1 or two != -1):
print(2 * len(k) - max(two, seven) - 1)
elif k[:2] == '50' and five == 0 and min(zeroes) != -1 and (seven != -1 or two != -1):
print(min((len(k) * 2 - zeroes[0] - zeroes[1] - 3), (1 + len(k))))
else:
ch = []
fl = 0
if min(zeroes) > -1:
fl = 1
ch.append(len(k) * 2 - zeroes[0] - zeroes[1] - 3)
if five != -1 and max(zeroes) > -1:
fl = 1
if five < (max(zeroes)):
ch.append(2 * len(k) - max(zeroes) - five - 3)
else:
ch.append(2 * len(k) - max(zeroes) - five - 2)
if five != -1:
if two != -1:
fl = 1
if two < five:
ch.append(2 * len(k) - two - five - 3)
else:
ch.append(2 * len(k) - two - five - 2)
if seven != -1:
fl = 1
if seven < five:
ch.append(2 * len(k) - seven - five - 3)
else:
ch.append(2 * len(k) - seven - five - 2)
if fl:
print(min(ch))
else:
print(-1)
``` | instruction | 0 | 82,346 | 20 | 164,692 |
No | output | 1 | 82,346 | 20 | 164,693 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Try guessing the statement from this picture:
<image>
You are given a non-negative integer d. You have to find two non-negative real numbers a and b such that a + b = d and a β
b = d.
Input
The first line contains t (1 β€ t β€ 10^3) β the number of test cases.
Each test case contains one integer d (0 β€ d β€ 10^3).
Output
For each test print one line.
If there is an answer for the i-th test, print "Y", and then the numbers a and b.
If there is no answer for the i-th test, print "N".
Your answer will be considered correct if |(a + b) - a β
b| β€ 10^{-6} and |(a + b) - d| β€ 10^{-6}.
Example
Input
7
69
0
1
4
5
999
1000
Output
Y 67.985071301 1.014928699
Y 0.000000000 0.000000000
N
Y 2.000000000 2.000000000
Y 3.618033989 1.381966011
Y 997.998996990 1.001003010
Y 998.998997995 1.001002005 | instruction | 0 | 82,603 | 20 | 165,206 |
Tags: binary search, math
Correct Solution:
```
import math
t = int(input())
for _ in range(t):
d = int(input())
delta = d * d - 4 * d
if delta < 0 :
print("N")
else :
b = (-d + math.sqrt(delta)) / (-2)
a = (-d - math.sqrt(delta)) / (-2)
if a >= 0 and b >= 0 :
print("Y",a,b)
else :
print("N")
``` | output | 1 | 82,603 | 20 | 165,207 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | instruction | 0 | 82,926 | 20 | 165,852 |
Tags: dp, greedy, implementation
Correct Solution:
```
m,s=[int(x) for x in input().split()]
def func(m,s):
if s==0 and m==1:
print("0 0")
return
if s==0 or s>m*9:
print("-1 -1")
return
#min
a=[0]*m
j=m-1
sumx=s
while sumx>0:
if (sumx>9):
sumx-=9
a[j]=9
j-=1
else:
a[j]=sumx
sumx=0
break
if j!=0:
a[j]-=1
a[0]=1
for i in a:
print(i,end='')
print(" ",end='')
a=[0]*m
sumx=s
j=0
while sumx>0:
if (sumx>9):
sumx-=9
a[j]=9
j+=1
else:
a[j]=sumx
sumx=0
break
for i in a:
print(i,end='')
print()
func(m,s)
``` | output | 1 | 82,926 | 20 | 165,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | instruction | 0 | 82,927 | 20 | 165,854 |
Tags: dp, greedy, implementation
Correct Solution:
```
import math
def facts(n):
ans = []
for i in range(1, int(math.sqrt(n)+1)):
if(n%i==0):
ans.append(i)
ans.append(n//i)
ans = sorted(list(dict.fromkeys(ans)))
if(ans[-1]==n):
ans = ans[:-1]
return ans
m,s = map(int, input().split())
if(m==1 and s==0):
print(0,0)
elif(s==0 or m*9 < s):
print(-1,-1)
elif(s==1 and m>1):
print(int(10**(m-1)) ,int(10**(m-1)))
else:
arr = [1]+[0 for i in range(m-1)]
arrs = [0 for i in range(m)]
s1, s2 = s-1, 0
pnt1, pnt2 = -1, 0
while(s1):
while(arr[pnt1]<9 and s1):
arr[pnt1]+=1
s1-=1
pnt1-=1
while(s2<s):
while(arrs[pnt2]<9 and s2<s):
arrs[pnt2]+=1
s2+=1
pnt2+=1
for i in range(len(arr)):
arr[i] = str(arr[i])
arrs[i] = str(arrs[i])
print(''.join(arr), ''.join(arrs))
``` | output | 1 | 82,927 | 20 | 165,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | instruction | 0 | 82,928 | 20 | 165,856 |
Tags: dp, greedy, implementation
Correct Solution:
```
import collections
import itertools
from functools import lru_cache
import sys
import math
##################################################################
#Helper
def helper():
pass
##################################################################
#Solver
def solve():
m, s = map(int, input().split(' '))
if s > 9 * m:
print('-1 -1')
return
if s == 0:
if m>1:
print('-1 -1')
return
else:
print('0 0')
return
# Make Smallest
lo = [0 for i in range(m)]
lo[0] = 1
sm,curr = 1,m-1
while (curr >= 1 and sm < s):
left = s-sm
if left >= 9:
lo[curr] = 9
sm += 9
curr -= 1
else:
lo[curr] = left
sm+=left
break
if sm < s:
left = s - (sm - 1)
lo[0] = left
mini = ''.join(list(map(str, lo)))
# Make Largest
hi = [0 for i in range(m)]
if s <= 9:
hi[0] = s
maxi = ''.join(list(map(str, hi)))
print(mini, maxi)
return
hi[0] = 9
sm, curr, = 9, 1
while (curr < m and sm < s):
left = s - sm
if left > 9:
hi[curr] = 9
curr += 1
sm += 9
else:
hi[curr] = left
sm += left
break
maxi = ''.join(list(map(str, hi)))
print(mini, maxi)
#################################################################
#Driver
t = 1
for _ in range(t):
solve()
################################################################
``` | output | 1 | 82,928 | 20 | 165,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | instruction | 0 | 82,929 | 20 | 165,858 |
Tags: dp, greedy, implementation
Correct Solution:
```
m,s=map(int,input().split())
if s>9*m or (s<1 and m!=1): print(-1,-1)
else: print(int(10**(m-1)+((s-1)%9+1)*10**((s-1)//9))-1,int(10**m-(9-(s-1)%9)*10**(m-(s-1)//9-1)))
``` | output | 1 | 82,929 | 20 | 165,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | instruction | 0 | 82,930 | 20 | 165,860 |
Tags: dp, greedy, implementation
Correct Solution:
```
m, n = (int(i) for i in input().split())
if((n == 0 and m != 1) or n > 9*m):
print(-1, -1)
else:
maxnum = ""
n1 = n
for i in range(m):
maxnum += str(min(n1, 9))
n1 -= min(n1, 9)
minnum = ""
if(n >= m):
for i in range(m - 1):
minnum += str(min(n - 1, 9))
n -= min(n - 1, 9)
minnum += str(n)
print(minnum[::-1], maxnum)
else:
a = ""
for i in range(m - 1):
a += str(min(n - 1, 9))
n -= min(n - 1, 9)
print(str(n) + a[::-1], maxnum)
``` | output | 1 | 82,930 | 20 | 165,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | instruction | 0 | 82,931 | 20 | 165,862 |
Tags: dp, greedy, implementation
Correct Solution:
```
m, s = map(int, input().rstrip().split(" "))
if m == 1 and s == 0:
print("0 0")
elif s == 0 or (s/m) > 9:
print("-1 -1")
else:
sum1 = s - 1
minimum = ""
maximum = ""
for i in range(m):
x = min(9, s)
s -= x
maximum += str(x)
for i in range(m - 1):
x = min(9, sum1)
sum1 -= x
minimum = str(x) + minimum
minimum = str(sum1 + 1) + minimum
print(minimum, maximum)
``` | output | 1 | 82,931 | 20 | 165,863 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | instruction | 0 | 82,932 | 20 | 165,864 |
Tags: dp, greedy, implementation
Correct Solution:
```
m,s=[int(x) for x in input().split()]
if s>9*m:
print('-1 -1')
elif s==0 and m!=1:
print('-1 -1')
else:
L=[]
for i in range(0,m):
k=9
while s-k<0:
k=k-1
if k==0:
break
K=str(k)
L.append(K)
s=s-k
MAX=('').join(L)
N=L[::-1]
if N[0]=='0':
for n in range(0,m):
if N[n]!='0':
N[n]=str(int(N[n])-1)
N[0]='1'
break
MIN=('').join(N)
print('%s %s'%(MIN,MAX))
``` | output | 1 | 82,932 | 20 | 165,865 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Examples
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | instruction | 0 | 82,933 | 20 | 165,866 |
Tags: dp, greedy, implementation
Correct Solution:
```
def sumDigits(S):
return sum(int(ch) for ch in S)
def soln(m, s):
sOrig = s
maxStr = []
for _ in range(m):
curr = min(s, 9)
s -= curr
maxStr.append(str(curr))
maxVal = int("".join(maxStr))
if len(str(maxVal)) != m or s != 0:
return '-1 -1'
minStr = maxStr[::-1]
if minStr[0] == '0':
for i, ch in enumerate(minStr):
if ch != '0':
minStr[0] = '1'
minStr[i] = str(int(ch) - 1)
break
minVal = int("".join(minStr))
if len(str(minVal)) != m or sumDigits(minStr) != sOrig:
return '-1 -1'
# assert(len(str(minVal)) == m and sumDigits(str(minVal)) == sOrig)
# assert(len(str(maxVal)) == m and sumDigits(str(maxVal)) == sOrig)
return f'{minVal} {maxVal}'
def main():
m, s = [int(x) for x in input().split(' ')]
result = soln(m, s)
print(result)
def randomTest():
for m in range(1, 101):
for s in range(901):
soln(m, s)
if __name__ == '__main__':
main()
# randomTest()
``` | output | 1 | 82,933 | 20 | 165,867 |
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 | 83,489 | 20 | 166,978 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
a,b,c,d=map(int,input().split())
x1=b-a
x2=c-d
if b==0 and a==0 and abs(c-d)<=1:
if c<=d:
print("YES")
if d==1 and c==0:ans=[3]
else:ans=[3,2]*c+[3]*(d-c)
print(*ans)
else:
print("YES")
if c==1 and d==0:ans=[2]
else:ans=[2,3]*d+[2]*(c-d)
print(*ans)
elif c==0 and d==0 and abs(a-b)<=1:
if a<=b:
print("YES")
if b==1 and a==0:ans=[1]
else:ans=[1,0]*a+[1]*(b-a)
print(*ans)
else:
print("YES")
if a==1 and b==0:ans=[0]
else:ans=[0,1]*b+[0]*(a-b)
print(*ans)
elif b<a or c<d:
print("NO")
elif a==b and c==d:
print("YES")
ans=[0,1]*a+[2,3]*c
print(*ans)
elif x1==x2:
print("YES")
ans=[1,0]*a+[1,2]*x1+[3,2]*d
print(*ans)
elif x1==x2+1:
print("YES")
ans=[1]+[0,1]*a+[2,1]*x2+[2,3]*d
print(*ans)
elif x1+1==x2:
print("YES")
ans=[0,1]*a+[2,1]*x1+[2,3]*d+[2]
print(*ans)
else: print("NO")
``` | output | 1 | 83,489 | 20 | 166,979 |
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 | 83,490 | 20 | 166,980 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
def printit(s):
print("YES")
print(*s)
exit()
def solve(j,i):
tt = sum(j)
jj = []
for nn in j:
jj.append(nn)
s = []
while(1):
if(i==4 or jj[i]==0):
break
s.append(i)
jj[i]-=1
if(i>0 and jj[i-1]>0):
i-=1
else:
i+=1
if(len(s)==tt):
printit(s)
l = list(map(int,input().split()))
for i in range(0,4):
solve(l,i)
print("NO")
``` | output | 1 | 83,490 | 20 | 166,981 |
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 | 83,491 | 20 | 166,982 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
import sys
readline = sys.stdin.readline
def check(A, B, C, D):
N = A+B+C+D
if not (A+C == N//2 or A+C == -(-N//2)):
return False
even = [2]*C + [0]*A
odd = [3]*D + [1]*B
ans = [None]*N
flag = (B+D == -(-N//2))
for i in range(N):
if (i%2 == 0) == flag:
ans[i] = odd[i//2]
else:
ans[i] = even[i//2]
if all(abs(a2-a1) == 1 for a1, a2 in zip(ans, ans[1:])):
return ans
return False
A, B, C, D = map(int, readline().split())
ans = check(A, B, C, D)
if ans == False:
print('NO')
else:
print('YES')
print(*ans)
``` | output | 1 | 83,491 | 20 | 166,983 |
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 | 83,492 | 20 | 166,984 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
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")
##########################################################
from collections import Counter
import bisect
import math
def nCk(n, k):
res = 1
for i in range(1, k + 1):
res = res * (n - i + 1) // i
return res
#for _ in range(int(input())):
#n=int(input())
#n,k=map(int, input().split())
#arr=list(map(int, input().split()))
from collections import deque
import heapq
from collections import Counter
# g=[[] for i in range(n+1)]
# sys.setrecursionlimit(10**6)
#for _ in range(int(input())):
#n=int(input())
#n,m=map(int,input().split())
#arr=list(map(int,input().split()))
#ls=list(map(int, input().split()))
a,b,c,d=map(int, input().split())
s=""
s+="01"*(a)
f=0
if a>b:
if a==b+1 and c==d==0:
s=s[:2*a-2]
s=s+"0"
print("YES")
s = list(s)
print(*s)
else:
print("NO")
exit()
else:
ss="23"*d
if c<d:
if c+1==d and a==0 and b==0:
ss=ss[:2*d-2]
ss="3"+ss
print("YES")
ss=list(ss)
print(*ss)
exit()
else:
print("NO")
exit()
else:
var=b-a
var2=c-d
if var!=var2:
v=min(var,var2)
ss=s+"21"*v+ss
var-=v
var2-=v
if var==1:
ss="1"+ss
elif var2==1:
ss+="2"
else:
print("NO")
exit()
print("YES")
ss = list(ss)
print(*ss)
exit()
else:
print("YES")
ss=s+"21"*var+ss
ss = list(ss)
print(*ss)
``` | output | 1 | 83,492 | 20 | 166,985 |
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 | 83,493 | 20 | 166,986 |
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 | 83,493 | 20 | 166,987 |
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 | 83,494 | 20 | 166,988 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
str1 = input()
def go(x):
s = [int(i) for i in str1.split()]
res = []
while sum(s) > 0:
res.append(x)
s[x] -= 1
if s[x] < 0:
return
if x == 0:
x = 1
elif x == 1:
if s[0] < s[1] or s[0] == 0:
x = 2
else:
x = 0
elif x == 2:
if s[3] < s[2] or s[3] == 0:
x = 1
else:
x = 3
elif x == 3:
x = 2
return res
for start in range(4):
r = go(start)
if r:
print("YES")
print(*r)
break
else:
print("NO")
``` | output | 1 | 83,494 | 20 | 166,989 |
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 | 83,495 | 20 | 166,990 |
Tags: brute force, constructive algorithms, greedy
Correct Solution:
```
a,b,c,d=[int(x) for x in input().split(' ')]
if abs(a+c-b-d) > 1:
print('NO')
else:
if d > c:
if d-c > 1:
print('NO')
else:
if a!=0 or b!=0:
print('NO')
else:
print('YES')
for i in range(c):
print(3,2,sep=' ',end=' ')
print(3)
else:
if a > b:
if a-b > 1:
print('NO')
else:
if c!=0 or d!=0:
print('NO')
else:
print('YES')
for i in range(b):
print(0,1,sep=' ',end=' ')
print(0)
else:
print('YES')
if a+c>=b+d:
for i in range(a):
print(0,1,sep=' ',end=' ')
for i in range(b-a):
print(2,1,sep=' ',end=' ')
for i in range(d):
print(2,3,sep=' ',end=' ')
for i in range(a+c-b-d):
print(2)
else:
print(1,end=' ')
for i in range(a):
print(0,1,sep=' ',end=' ')
for i in range(b-a-1):
print(2,1,sep=' ',end=' ')
for i in range(d):
print(2,3,sep=' ',end=' ')
``` | output | 1 | 83,495 | 20 | 166,991 |
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 | 83,496 | 20 | 166,992 |
Tags: brute force, constructive algorithms, greedy
Correct 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())
#we can create the 2 blocks and then consider the sequence in the middle
block1=[]
block2=[]
block3=[]
for s in range(min(a,b)):
block1.append("0")
block1.append("1")
a-=1
b-=1
for s in range(min(c,d)):
block3.append("2")
block3.append("3")
c-=1
d-=1
for s in range(min(b,c)):
block2.append("2")
block2.append("1")
b-=1
c-=1
for s in range(min(a,1)):
block1.append("0")
a-=1
for s in range(min(b,1)):
block1=["1"]+block1
b-=1
for s in range(min(c,1)):
block3.append("2")
c-=1
for s in range(min(d,1)):
block3=["3"]+block3
d-=1
if a>0 or b>0 or c>0 or d>0:
print("NO")
else:
#check if all good
outy=block1+block2+block3
broke=False
for s in range(1,len(outy)):
if abs(int(outy[s])-int(outy[s-1]))==1:
continue
else:
broke=True
break
if broke==False:
print("YES")
print(" ".join(outy))
else:
print("NO")
``` | output | 1 | 83,496 | 20 | 166,993 |
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 = 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)
``` | instruction | 0 | 83,497 | 20 | 166,994 |
Yes | output | 1 | 83,497 | 20 | 166,995 |
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
from sys import stdin, stdout
def ispossible(a , b , c , d):
if b >= a-1 and c >= d-1 and (b - a == c - d or b - a + 1 == c - d or b - a == c - d + 1):
return True
else:
return False
if __name__ == '__main__':
A = stdin.readline().strip().split()
a = int(A[0])
b = int(A[1])
c = int(A[2])
d = int(A[3])
if not ispossible(a,b,c,d):
print('NO')
sys.exit()
res = []
rng = a + b + c + d
pre = -1
for i in range(a + b + c + d):
if (pre == 1 or pre ==-1) and a > 0 and ispossible(a-1, b, c, d):
a -= 1
res.append(0)
pre = 0
elif (pre == 0 or pre == 2 or pre == -1) and b > 0 and ispossible(a,b-1,c,d):
b -= 1
res.append(1)
pre = 1
elif (pre == 1 or pre == 3 or pre == -1) and c > 0 and ispossible(a, b, c-1, d):
c -= 1
res.append(2)
pre = 2
elif (pre == 2 or pre == -1) and d > 0 and ispossible(a, b, c, d-1):
d -= 1
res.append(3)
pre = 3
else:
print('NO')
sys.exit()
print('YES')
print(" ".join(map(str, res)))
``` | instruction | 0 | 83,499 | 20 | 166,998 |
Yes | output | 1 | 83,499 | 20 | 166,999 |
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
a,b,c,d=map(int,sys.stdin.readline().split())
ans=[]
z=True
while a>0 and b>0 and z:
ans.append(0)
ans.append(1)
a-=1
b-=1
if b==0 and a!=0:
z=False
if b==0 and a!=0:
z=False
#print(z)
if not z:
if a==1 and c==0 and d==0:
ans.append(0)
print(*ans)
else:
#print('a')
print('NO')
else:
if c>0:
ans.append(2)
c-=1
if d>0:
ans.append(3)
d-=1
m=True
#print(c,d)
while d>0 and c>0 and m:
ans.append(2)
ans.append(3)
d-=1
c-=1
if c==0 and d!=0:
m=False
if d>0:
if d==1:
if ans[0]==2:
ans=[3]+ans
else:
m=False
if not m:
#print('c')
print('NO')
else:
#print(ans,b,c)
if ans[-1]==2:
if b>0:
b-=1
ans.append(1)
else:
print('NO')
m=False
if ans[-1]==3:
if c>0:
c-=1
ans.append(2)
else:
if b>1:
print('NO')
m=False
while b>0 and c>0:
if ans[-1]==2:
ans.append(1)
ans.append(2)
else:
ans.append(2)
ans.append(1)
b-=1
c-=1
#print(ans,b,c,'endgame')
if b==2:
ans.append(1)
ans=[1]+ans
elif b==1:
ans=[1]+ans
elif b!=0:
m=False
#print(ans,a,b,c,d)
#print('d')
print('NO')
if c>0:
if ans[-1]!=1:
m=False
#print('e')
print('NO')
elif c==1:
ans.append(2)
c-=1
else:
m=False
print('NO')
if m:
print('YES')
print(*ans)
``` | instruction | 0 | 83,501 | 20 | 167,002 |
No | output | 1 | 83,501 | 20 | 167,003 |
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:
```
def try_with_0_first(a, b, c, d):
res = []
if b >= a:
res += [0, 1] * a
b -= a
# Now we ended with a 1 and need as many 2 as the remaining ones
if c > b:
res += [2, 1] * b
res += [2]
c -= b + 1
# Now we ended with 2
if c == d:
res += [3, 2] * c
elif c == d - 1:
res += [3, 2] * (c - 1) + [3]
else:
return False
else:
return False
return res
def try_with_1_first(a, b, c, d):
res = []
if b <= a:
return False
else:
res += [1, 0] * a + [1]
b -= a + 1
# Now we ended with a 1 and need as many 2 as the remaining ones
if c > b:
res += [2, 1] * b
res += [2]
c -= b + 1
# Now we ended with 2
if c == d:
res += [3, 2] * c
elif c == d - 1:
res += [3, 2] * (c - 1) + [3]
else:
return False
return res
a, b, c, d = list(map(int, input().split()))
res = try_with_0_first(a, b, c, d)
if not (res):
res = try_with_1_first(a, b, c, d)
if res:
print("YES")
print(" ".join(map(str, res)))
else:
print("NO")
``` | instruction | 0 | 83,502 | 20 | 167,004 |
No | output | 1 | 83,502 | 20 | 167,005 |
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:
```
'''
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to 1.
More formally, a sequence s1,s2,β¦,sn is beautiful if |siβsi+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β€105).
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.
'''
class OrganizeNumbers:
def __init__(self,num_0, num_1, num_2, num_3):
self.__num_0 = int(num_0)
self.__num_1 = int(num_1)
self.__num_2 = int(num_2)
self.__num_3 = int(num_3)
def __rules(self):
'''
If 0 is present, 1 must be next to it.
If 1 is present, 2 or 0 must be next to it.
If 2 is present, 3 or 1 must be next to it.
If 3 is present, 2 must be next to it.
'''
pass
def __deducted(self):
'''
If there are 4 positive numbers:
The number of 3s must always be smaller than or equal to number of 2s
The number of 1s must always be larger than or equal to number of 0s
The sum of number of 3s and number of 1s must smaller than or equal to that of number of 2s and number of 0s,
at most more than 1.
If there are no 3s, the number of 2s must be smaller than that of 1s.\,and 0s <= 1s ala 0 exists
If there are no 2s, and there is at least one 3s, the sequence cannot be created
The number of the consecutive numbers, if there are only two consecutive numbers, must
at least be equal, or at most the difference is 1 number.
If there are no 0s, the number of 1s must be smaller than or equal to that of 2s, while 3s < 2s ala 1 exists.
If there are no 1s, and there is at least one 0, the seq cannot be created.
If there is only one type of number, the seq cannot be created
'''
pass
def __pre_req_1(self):
if self.__num_3 > self.__num_2:
return False
else: return True
def __pre_req_2(self):
if self.__num_0 > self.__num_1:
return False
else: return True
def __pre_req_3(self):
if abs(self.__num_3 + self.__num_1 - self.__num_2 - self.__num_0) > 1:
return False
else: return True
def __pre_req_4(self):
if self.__num_2 > self.__num_1 or self.__num_0 > self.__num_1 or self.__num_1 > self.__num_0 + self.__num_2:
return False
else:
return True
def __pre_req_6_sub_1(self):
if abs(self.__num_0 - self.__num_1) > 1:
return False
elif abs(self.__num_0 - self.__num_1) == 1 and self.__num_0 > 0 and self.__num_1 > 0: return True
elif abs(self.__num_0 - self.__num_1) == 0 and self.__num_0 > 0 and self.__num_1 > 0: return True
else: return False
def __pre_req_6_sub_2(self):
if abs(self.__num_2 - self.__num_3) > 1:
return False
elif abs(self.__num_2 - self.__num_3) == 1 and self.__num_2 > 0 and self.__num_3 > 0: return True
elif abs(self.__num_2 - self.__num_3) == 0 and self.__num_2 > 0 and self.__num_3 > 0: return True
else: return False
def __pre_req_6_sub_3(self):
if abs(self.__num_2 - self.__num_1) > 1:
return False
elif abs(self.__num_2 - self.__num_1) == 1 and self.__num_2 > 0 and self.__num_1 > 0: return True
elif abs(self.__num_2 - self.__num_1) == 0 and self.__num_2 > 0 and self.__num_1 > 0: return True
else: return False
def __pre_req_7(self):
if self.__num_1 > self.__num_2 or self.__num_3 > self.__num_2 or self.__num_2 > self.__num_1 + self.__num_3:
return False
else: return True
def __isPossible(self):
answer = False
if self.__num_0 > 0 and self.__num_1 > 0 and self.__num_2 > 0 and self.__num_3 > 0:
if self.__pre_req_1() and self.__pre_req_2() and self.__pre_req_3():
answer = True
elif self.__num_0 == 0:
if self.__num_1 > 0:
if self.__pre_req_7():
answer = True
elif self.__num_3 == 0 and self.__num_1 == 1 and self.__num_2 == 0:
answer = True
else:
if self.__pre_req_6_sub_2():
answer = True
elif (self.__num_3 == 0 and self.__num_2 == 1) or (self.__num_2 == 0 and self.__num_3 == 1):
answer = True
elif self.__num_1 == 0:
if self.__num_0 == 0:
if self.__pre_req_6_sub_2():
answer = True
elif (self.__num_3 == 0 and self.__num_2 == 1) or (self.__num_2 == 0 and self.__num_3 == 1):
answer = True
elif self.__num_0 == 1 and self.__num_2 == 0 and self.__num_3 == 0:
answer = True
elif self.__num_2 == 0:
if self.__num_3 == 0:
if self.__pre_req_6_sub_1():
answer = True
elif (self.__num_1 == 0 and self.__num_0 == 1) or (self.__num_0 == 0 and self.__num_1 == 1):
answer = True
elif self.__num_3 == 1 and self.__num_1 == 0 and self.__num_0 == 0:
answer = True
elif self.__num_3 == 0:
if self.__num_0 == 0:
if self.__pre_req_6_sub_3():
answer = True
elif (self.__num_2 == 0 and self.__num_1 == 1) or (self.__num_1 == 0 and self.__num_2 == 1):
answer = True
else:
if self.__pre_req_4():
answer = True
elif self.__num_0 == 1 and self.__num_2 == 0 and self.__num_3 == 0:
answer = True
return answer
def __cross_number_sort(self,num1, num2, amt1, amt2,prev_last_num=None):
# This is intentionally made for organizing 2 numbers with the same number of numbers
# or at most 1 number more/fewer
new_list = []
if num1 > num2 and amt1 - amt2 == 0:
if prev_last_num is not None:
if num2 == prev_last_num:
for time in range(amt1):
new_list.append(num1)
new_list.append(num2)
else:
for time in range(amt1):
new_list.append(num2)
new_list.append(num1)
elif num1 < num2 and amt1 - amt2 == 0:
if prev_last_num is not None:
if num1 == prev_last_num:
for time in range(amt1):
new_list.append(num2)
new_list.append(num1)
else:
for time in range(amt1):
new_list.append(num1)
new_list.append(num2)
elif num1 > num2 and amt1 - amt2 >= 1:
new_list.append(num1)
for time in range(amt2):
new_list.append(num2)
new_list.append(num1)
elif num2 > num1 and amt1 - amt2 >= 1:
new_list.append(num2)
for time in range(amt2):
new_list.append(num1)
new_list.append(num2)
elif num1 > num2 and amt2 - amt1 >= 1:
new_list.append(num2)
for time in range(amt1):
new_list.append(num1)
new_list.append(num2)
elif num2 > num1 and amt2 - amt1 >= 1:
new_list.append(num2)
for time in range(amt1):
new_list.append(num1)
new_list.append(num2)
return new_list
def __assert(self, ob_list):
satisfied = 0
for pos in range(len(ob_list) - 1):
if ob_list[pos+1] - ob_list[pos] == 1:
satisfied += 1
if satisfied == len(ob_list) - 1:
return True
else:
return False
def __organize(self):
final_list = []
if self.__num_0 > 0 and self.__num_1 > 0 and self.__num_2 > 0 and self.__num_3 > 0:
if self.__pre_req_1() and self.__pre_req_2() and self.__pre_req_3():
amt_1 = self.__num_1 - self.__num_0
amt_2 = self.__num_1 - self.__num_0 + 1
amt_3 = self.__num_2 - amt_2
if abs((self.__num_3 + self.__num_1) - (self.__num_2 + self.__num_0)) == 1:
if self.__num_1 - self.__num_0 == 1:
final_list.extend(self.__cross_number_sort(0,1,self.__num_0, self.__num_1))
final_list.extend(self.__cross_number_sort(2,3,self.__num_2,self.__num_3))
else:
if self.__num_0 > 1:
final_list.extend(self.__cross_number_sort(0, 1, self.__num_0, self.__num_0, 0))
final_list.extend(self.__cross_number_sort(1, 2, amt_1, amt_2 - 1,1))
final_list.extend(self.__cross_number_sort(3, 2, self.__num_3, amt_3 + 1, 2))
if not self.__assert(final_list):
final_list.clear()
final_list.extend(self.__cross_number_sort(0,1, self.__num_0, self.__num_0))
final_list.extend(self.__cross_number_sort(2,1, amt_2 - 1, amt_1,1))
final_list.extend(self.__cross_number_sort(3,2,self.__num_3, amt_3 + 1, 2))
else:
final_list.extend(self.__cross_number_sort(0, 1, self.__num_0, self.__num_0 + 1, 0))
final_list.extend(self.__cross_number_sort(1, 2, amt_1 - 1, amt_2 - 1, 1))
final_list.extend(self.__cross_number_sort(3, 2, self.__num_3, amt_3 + 1, 2))
else:
final_list.extend(self.__cross_number_sort(0, 1, self.__num_0, self.__num_0))
final_list.extend(self.__cross_number_sort(2, 1, amt_2, amt_1, 1))
final_list.extend(self.__cross_number_sort(3, 2, self.__num_3, amt_3, 2))
if not self.__assert(final_list):
final_list.clear()
final_list.extend(self.__cross_number_sort(0, 1, self.__num_0, self.__num_0,0))
final_list.extend(self.__cross_number_sort(2, 1, amt_2, amt_1))
final_list.extend(self.__cross_number_sort(3, 2, self.__num_3, amt_3, 2))
elif self.__num_0 == 0:
if self.__num_1 > 0:
if self.__pre_req_7():
amt_1 = self.__num_2 - self.__num_1
final_list.extend(self.__cross_number_sort(1, 2, self.__num_1, self.__num_1))
final_list.extend(self.__cross_number_sort(2, 3, amt_1, self.__num_3, 2))
elif self.__num_3 == 0 and self.__num_1 == 1 and self.__num_2 == 0:
final_list.append(1)
else:
if self.__pre_req_6_sub_2():
final_list.extend(self.__cross_number_sort(2, 3, self.__num_2, self.__num_3))
elif self.__num_3 == 0 and self.__num_2 == 1:
final_list.append(2)
elif self.__num_2 == 0 and self.__num_3 == 1:
final_list.append(3)
elif self.__num_1 == 0:
if self.__num_0 == 0:
if self.__pre_req_6_sub_2():
final_list.extend(self.__cross_number_sort(2, 3, self.__num_2, self.__num_3))
elif self.__num_3 == 0 and self.__num_2 == 1:
final_list.append(2)
elif self.__num_2 == 0 and self.__num_3 == 1:
final_list.append(3)
elif self.__num_0 == 1 and self.__num_2 == 0 and self.__num_3 == 0:
final_list.append(0)
elif self.__num_2 == 0:
if self.__num_3 == 0:
if self.__pre_req_6_sub_1():
final_list.extend(self.__cross_number_sort(0, 1, self.__num_0, self.__num_1))
elif self.__num_1 == 0 and self.__num_0 == 1:
final_list.append(0)
elif self.__num_0 == 0 and self.__num_1 == 1:
final_list.append(1)
elif self.__num_3 == 1 and self.__num_1 == 0 and self.__num_0 == 0:
final_list.append(3)
elif self.__num_3 == 0:
if self.__num_0 == 0:
if self.__pre_req_6_sub_3():
final_list.extend(self.__cross_number_sort(1, 2, self.__num_1, self.__num_2))
elif self.__num_2 == 0 and self.__num_1 == 1:
final_list.append(1)
elif self.__num_1 == 0 and self.__num_2 == 1:
final_list.append(2)
else:
if self.__pre_req_4():
amt_1 = self.__num_1 - self.__num_0
final_list.extend(self.__cross_number_sort(0, 1, self.__num_0, self.__num_0))
final_list.extend(self.__cross_number_sort(1, 2, amt_1, self.__num_2, 1))
elif self.__num_0 == 1 and self.__num_2 == 0 and self.__num_3 == 0:
final_list.append(0)
return final_list
def __print_list(self):
ob_list = self.__organize()
print(*ob_list)
def isPossible(self):
answer = self.__isPossible()
if answer:
print("YES")
self.__print_list()
else:
print("NO")
if __name__ == '__main__':
num_0, num_1, num_2, num_3 = input().split()
OrganizeNumbers(num_0, num_1, num_2, num_3).isPossible()
# def assert_(input_list, expected):
# num_0 = input_list[0]
# num_1 = input_list[1]
# num_2 = input_list[2]
# num_3 = input_list[3]
# print("input:", *input_list)
# answer = OrganizeNumbers(num_0, num_1, num_2, num_3).isPossible()
# print("Answer:", answer)
# print("Expected", expected)
#
# if answer == expected:
# print("True")
# else:
# print("False")
# print("-----------------------------------------------------------------------")
# print()
#
# def assert_examples():
# assert_([2,2,2,1], "YES") # First three the same, larger than remaining - YES
# assert_([1,1,1,2], "NO") # First three the same, smaller than remaining - NO
# assert_([1,2,3,4], "NO") # Consecutive - NO
# assert_([1,1,1,1], "YES") # All 4 the same - YES
# assert_([1,2,2,2], "YES") # Last three the same, larger than remaining - YES
# assert_([2,1,1,1], "NO") # Last three the same, smaller than remaining - NO
# assert_([1,2,5,5], "YES") # Last two the same, diff = 1 on 1s - YES
# assert_([2,1,5,5], "NO") # Last two the same, diff = 1 on 0s - NO
# assert_([2,2,4,5], "NO") # First two the same, diff = 1 on 3s - NO
# assert_([2,2,5,4], "YES") # First two the same, diff = 1 on 2s - YES
# assert_([2,2,1,2], "NO") # Same 0s, 1s and 3s, larger than remaining - NO
# assert_([1,1,2,1], "YES") # Same 0s, 1s and 3s, smaller than remaining - YES
# assert_([2,1,2,2], "NO") # Same 0s, 2s and 3s, larger than remaining - NO
# assert_([1,2,1,1], "YES") # Same 0s, 2s and 3s, smaller than remaining - YES
# assert_([2,1,2,1], "NO")
# assert_([1,2,1,2], "NO")
#
# assert_examples()
``` | instruction | 0 | 83,503 | 20 | 167,006 |
No | output | 1 | 83,503 | 20 | 167,007 |
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
import math
from collections import defaultdict,Counter,deque
# input=sys.stdin.readline
# def print(x):
# sys.stdout.write(str(x)+"\n")
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")
# sys.stdout=open("CP2/output.txt",'w')
# sys.stdin=open("CP2/input.txt",'r')
# mod=pow(10,9)+7
# t=int(input())
for i in range(1):
a,b,c,d=map(int,input().split())
if a>b:
if c>0 or d>0 or a-b>1:
print('NO')
else:
print("YES")
print([0]+[1,0]*b)
continue
if a==b:
ans=[0,1]*a
a=0
else:
ans=[1]+[0,1]*a
a=b-a-1
b=c
if a>=b:
if d>0 or a>b:
print('NO')
else:
print("YES")
ans+=[2,1]*a
print(*ans)
continue
ans+=[2,1]*a
a=b-a
b=d
if b>a or a-b>1:
print("NO")
continue
print("YES")
ans+=[2,3]*b
a-=b
if a:
ans+=[2]
print(*ans)
``` | instruction | 0 | 83,504 | 20 | 167,008 |
No | output | 1 | 83,504 | 20 | 167,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | instruction | 0 | 83,671 | 20 | 167,342 |
Tags: binary search, combinatorics, dp
Correct Solution:
```
def f(x):
if x < 10:
return x
if str(x)[0] > str(x)[-1]:
return x // 10 + 8
else:
return x // 10 + 9
l, r = map(int, input().split())
print(f(r) - f(l - 1))
``` | output | 1 | 83,671 | 20 | 167,343 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | instruction | 0 | 83,672 | 20 | 167,344 |
Tags: binary search, combinatorics, dp
Correct Solution:
```
l,r=input().split()
def ans(n):
a=0
if len(n)==1:
return int(n)
elif len(n)==2:
if n[1]<=n[0]:
return int(n[0])+9
else:
return int(n[0])+10
else:
for i in range(len(n)-1):
if i>0:
a+=int(n[i])*(10**(len(n)-i-2))
else:
a+=(int(n[i])-1)*(10**(len(n)-i-2))
if i==len(n)-2:
if n[-1]>n[0]:
a+=1
return a
x=ans(r)
y=ans(l)
if int(l)>99:
for i in range(len(l)-1,1,-1):
y+=ans('9'*i)+1
if int(r)>99:
for i in range(len(r)-1,1,-1):
x+=ans('9'*i)+1
if r[0]==r[-1]:
x+=1
print(x-y)
``` | output | 1 | 83,672 | 20 | 167,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | instruction | 0 | 83,673 | 20 | 167,346 |
Tags: binary search, combinatorics, dp
Correct Solution:
```
l, r = map(int, input().split())
result = 0
for digit in range(1, 10):
d_str = str(digit)
for length in range(3, 19):
if int(d_str + (length - 2) * '0' + d_str) <= r and \
int(d_str + (length - 2) * '9' + d_str) >= l:
a, b, c = 0, int((length - 2) * '9'), 0
while a < b:
c = (a + b) // 2
if int(d_str + '0' * (length - 2 - len(str(c))) + str(c) + d_str) < l:
a = c + 1
else:
b = c
l_end = a
a, b, c = 0, int((length - 2) * '9'), 0
while a < b:
c = (a + b + 1) // 2
if int(d_str + '0' * (length - 2 - len(str(c))) + str(c) + d_str) > r:
b = c - 1
else:
a = c
r_end = a
#print(str(l_end) + " " + str(r_end))
#print(" " + str(d_str + '0' * (length - 2 - len(str(l_end))) + str(l_end) + d_str))
#print(" " + str(d_str + '0' * (length - 2 - len(str(r_end))) + str(r_end) + d_str))
result += r_end - l_end + 1
for digit in range(1, 10):
length = 1
if l <= digit and digit <= r:
result += 1
length = 2
if int(str(digit) + str(digit)) >= l and int(str(digit) + str(digit)) <= r:
result += 1
print(result)
``` | output | 1 | 83,673 | 20 | 167,347 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | instruction | 0 | 83,674 | 20 | 167,348 |
Tags: binary search, combinatorics, dp
Correct Solution:
```
l, r = input().split()
lr = len(r)
retr = 1
if lr > 1:
for i in range(1,lr):
retr += 9 * 10**max(i-2,0)
r0 = int(r[0])
retr += (r0-1) * 10**(lr-2)
hr = r0*(10**(lr-1)+1)
retr += (int(r)-hr)//10 + 1
else:
retr += int(r)
ll = len(l)
retl = 1
if ll > 1:
for i in range(1,ll):
retl += 9 * 10**max(i-2,0)
l0 = int(l[0])
retl += (l0-1) * 10**(ll-2)
hl = l0*(10**(ll-1)+1)
retl += (int(l)-hl)//10 + 1
else:
retl += int(l)
if l[-1] == l[0]:
retl -= 1
print(retr-retl)
``` | output | 1 | 83,674 | 20 | 167,349 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | instruction | 0 | 83,675 | 20 | 167,350 |
Tags: binary search, combinatorics, dp
Correct Solution:
```
n=input().split()
l=int(n[0])
r=int(n[1])
s=0
if l==235 and r==236:
print(0)
exit()
if r==l and str(r)[0]==str(r)[len(str(r))-1]:
print(1)
exit()
if r==l:
print(0)
exit()
if r<=100:
for i in range(l,r+1):
i=str(i)
if i[0]==i[len(i)-1]:
s+=1
print(s)
exit()
if l>=100:
s1=(l-100)//10
s2=(r-100)//10
r2=str(r)
l2=str(l)
if r2[0]<=r2[len(r2)-1]:
print(s2-s1+1)
exit()
elif l2[0]<l2[len(l2)-1]:
print(s2-s1-1)
exit()
print(s2-s1)
'''if str(l)[0]==str(l)[len(str(l))-1]:
print((r-l)//10+1)
exit()
print(int((r-l)/10))
exit()'''
if r>100 and l<100:
for i in range(l,100):
i=str(i)
if i[0]==i[len(i)-1]:
s+=1
if str(r)[0]<str(r)[len(str(r))-1]:
print(s+((r-100)//10)+1)
exit()
print(s+((r-100)//10))
``` | output | 1 | 83,675 | 20 | 167,351 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | instruction | 0 | 83,676 | 20 | 167,352 |
Tags: binary search, combinatorics, dp
Correct Solution:
```
def func(b):
n2 = len(b)
ans = 0
for i in range(1, n2):
if i == 1: ans += 9
else:
ans += 9 * (10 ** (i - 2))
for i in range(0, n2 - 1):
if n2 > 2:
if i == 0: tmp = (int(b[i]) - 1) * (10 ** (n2 - 2 - i))
else: tmp = (int(b[i])) * (10 ** (n2 - 2 - i))
else:
tmp = int(b[i]) - 1
ans += tmp
if n2 == 1: ans = int(b)
elif int(b[n2 - 1]) >= int(b[0]): ans -= -1
return ans
a, b = map(int, input().split())
a += -1
a = str(a)
b = str(b)
ans1 = func(a)
ans2 = func(b)
# print(ans1, ans2)
print(func(b) - func(a))
``` | output | 1 | 83,676 | 20 | 167,353 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | instruction | 0 | 83,677 | 20 | 167,354 |
Tags: binary search, combinatorics, dp
Correct Solution:
```
# cook your dish here
def find(s):
n=len(s)
x=int(s)
if(x<10):
return x
ans=x//10-1
ans+=9
if(s[0]<=s[n-1]):
ans+=1
return ans
l,r=map(int,input().split())
l=l-1
l=str(l)
r=str(r)
count1=find(l)
count2=find(r)
print( count2 - count1)
``` | output | 1 | 83,677 | 20 | 167,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44. | instruction | 0 | 83,678 | 20 | 167,356 |
Tags: binary search, combinatorics, dp
Correct Solution:
```
left, right = map(int, input().split())
def f(x):
if x < 10:
return x
a = []
t = x
while t:
a.append(t % 10)
t //= 10
a = a[::-1]
ret = min(9, x)
size = len(a)
first = a[0]
last = a[-1]
for curSize in range(size - 1):
for dig in range(1, 10):
if curSize < size - 2 or dig < first:
ret += 10 ** curSize
elif dig == first:
s = 0
for i in range(1, size - 1):
s = s * 10 + a[i]
ret += s
if last >= dig:
ret += 1
return ret
print(f(right) - f(left - 1))
``` | output | 1 | 83,678 | 20 | 167,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+7
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
length_wise=[0,10,19]
for i in range(3,19):
length_wise.append(9*(10**(i-2))+length_wise[-1])
# print(length_wise)
def operate(x):
if(x==-1): return 0
x=str(x)
if(len(x)==1): return int(x)+1
ans=length_wise[len(x)-1]
key=min(int(x[0]),int(x[-1]))
key1=max(int(x[0]),int(x[-1]))
if(key==int(x[0])): type=1
else: type=2
# print(key,ans)
x=x[1:-1]
ans1=0
try:ans1=int(x)
except:pass
if(type==2):
ans+=(key1-1)*(10**len(x))
else:
ans+=(key-1)*(10**len(x))
ans1+=1
# print(ans,ans1,x)
return ans+ans1
l,r=value()
# print(operate(l-1))
# print(operate(r))
print(operate(r)-operate(l-1))
# BruteForce
# ans=0
#
# for i in range(l,r+1):
# x=str(i)
# if(x[0]==x[-1]):
# # print(x)
# ans+=1
# print(ans)
``` | instruction | 0 | 83,679 | 20 | 167,358 |
Yes | output | 1 | 83,679 | 20 | 167,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
Submitted Solution:
```
dp = [0] * 22
dp[1] = 9
dp[2] = 9
dp[3] = 90
for i in range(4,21):
dp[i] = dp[i-1] * 10
for i in range(1,21):
dp[i] = dp[i] + dp[i-1]
def good(s):
if(str(s)[0]==str(s)[-1]):
return 1
return 0
def till(x):
Ans = 0
N = len(str(x))
if(N == 1):
return int(x)
Ans += dp[N-1]
x = str(x)
Ans += (int(x[0])-1) * (10**(N-2))
for i in range(1,N-1):
Ans += int(x[i]) * (10 ** (N-i-2))
if(int(x[-1])>= int(x[0])):
Ans += 1
return Ans
l,r = map(int,input().split())
Ans =0
if(r<=100):
for i in range(l,r+1):
Ans += good(i)
print(Ans)
else:
print(int(till(r) - till(l)+good(l)))
``` | instruction | 0 | 83,680 | 20 | 167,360 |
Yes | output | 1 | 83,680 | 20 | 167,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
Submitted Solution:
```
from math import log, floor
rdi = lambda: list(map(int, input().split()))
def f(x):
if x < 10: return x
ans = 9
n = int(log(x, 10))+1
for i in range(2, n): ans += 9*(10**(i-2))
head = x//(10**(n-1))
tail = x%10
ans += (head-1)*(10**(n-2))
ans += (x-head*(10**(n-1))-tail)//10+(tail>=head)
return ans
l, r = rdi()
print(f(r)-f(l-1))
``` | instruction | 0 | 83,681 | 20 | 167,362 |
Yes | output | 1 | 83,681 | 20 | 167,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
Submitted Solution:
```
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
def solve(x):
a=[10,9]
x=str(x)
for i in range(3,len(x)):
a.append(pow(10,i-2)*9)
return sum(a[:len(x)-1])+(int(x[0])-(len(x)!=1))*pow(10,max(len(x)-2,0))+(int(x[1:len(x)-1]) if len(x)>2 else 0)+(x[-1]>=x[0])
def main():
l,r=map(int,input().split())
print(solve(r)-solve(l-1))
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | instruction | 0 | 83,682 | 20 | 167,364 |
Yes | output | 1 | 83,682 | 20 | 167,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
Submitted Solution:
```
import math
l, r = map(int, input().split())
ans = (l <= 9) * (9 - l + 1)
for d in range(1, 10):
for k in range(0, 17):
rb = int(math.floor(r - d - 10 ** (k + 1) * d) / 10)
lb = int(math.ceil(l - d - 10 ** (k + 1) * d) / 10)
#print("k = %d, d = %d" % (k, d))
#print(rb)
rb = min(10 ** k - 1, rb)
lb = max(0, lb)
ans += (rb >= lb) * (rb - lb + 1)
print(ans - 1)
``` | instruction | 0 | 83,683 | 20 | 167,366 |
No | output | 1 | 83,683 | 20 | 167,367 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
Submitted Solution:
```
from sys import stdin, stdout
mod=1000000007
# a,b = [s for s in stdin.readline()[:-1].split(" ")]
a,b = [s for s in input().split(" ")]
# print(stdin.readline()[:-1])
l=int(a)
r=int(b)
a=[int(q) for q in list(a)]
b=[int(q) for q in list(b)]
# print(a,b)
# [int(q) for q in list(s)]
# l=int(a)
# r=int(b)
ans=0
if(len(b)-len(a)>1):
for i in range(len(a)+1,len(b)):
ans+=9*pow(10,i-2)
ans%=mod
# if(len(a)==2):
# if(a[0]!=a[-1]):
# a[0]+=1
# a[-1]=a[0]
# if(len(a)>2):
# if(a[0]!=a[-1]):
# if(a[-1]<=a[0]):
# a[-1]=a[0]
# else:
# a[-1]=a[0]
# a[-2]+=1
# for i in range(len(a)-2,0,-1):
# if(a[i]>9):
# a[i]=9
# a[i-1]+=1
# l=pow(10,len(a))
while(l%10!=a[0]):
l+=1
ans+=pow(10,len(a)-1)-int(l/10)
ans%=mod
r=int(r/10)
r-=pow(10,len(str(r))-1)
# print("r = ",r)
ans+=r
ans%=mod
ans+=1
ans%=mod
print(ans)
# ans=str(ans)+'\n'
# stdout.write(ans)
# print("ans = ",ans)
#
# #
# # a="134"
# # a=list(a)
# # a[0]='4'
# # 1000-434
# #
# # ans=0
# # curr=0
# # ans=str(ans)+'\n'
# # stdout.write(ans)
# cunt=0
# for i in range(1334 ,2491173333349+1):
# a=str(i)
# if(a[0]==a[-1]):
# cunt+=1
# # print(i)
# cunt
# #
# # 24911-10000
# # 249117
# # 24911-100
# # 100-14
# # 14911+9900+86+1
# #
# #
# # +cunt
# # 99-43
# # 24911-10000
``` | instruction | 0 | 83,684 | 20 | 167,368 |
No | output | 1 | 83,684 | 20 | 167,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
Submitted Solution:
```
n=input().split()
l=int(n[0])
r=int(n[1])
s=0
if r==l and str(r)[0]==str(r)[len(str(r))-1]:
print(1)
exit()
if r==l:
print(0)
exit()
if r<=100:
for i in range(l,r+1):
i=str(i)
if i[0]==i[len(i)-1]:
s+=1
print(s)
exit()
if l>=100:
s1=(l-100)/10
s2=(r-100)/10
s3=s2-s1
r2=str(r)
l2=str(l)
if r2[0]<=r2[len(r2)-1]:
print(int(s3+1))
exit()
elif l2[0]<l2[len(l2)-1]:
print(int(s3-1))
exit()
print(int(s3))
'''if str(l)[0]==str(l)[len(str(l))-1]:
print((r-l)//10+1)
exit()
print(int((r-l)/10))
exit()'''
if r>100 and l<100:
for i in range(l,100):
i=str(i)
if i[0]==i[len(i)-1]:
s+=1
if str(r)[0]<str(r)[len(str(r))-1]:
print(s+((r-100)//10)+1)
exit()
print(s+((r-100)//10))
``` | instruction | 0 | 83,685 | 20 | 167,370 |
No | output | 1 | 83,685 | 20 | 167,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l β€ r). The Little Elephant has to find the number of such integers x (l β€ x β€ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him and count the number of described numbers x for a given pair l and r.
Input
The single line contains a pair of integers l and r (1 β€ l β€ r β€ 1018) β the boundaries of the interval.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
Output
On a single line print a single integer β the answer to the problem.
Examples
Input
2 47
Output
12
Input
47 1024
Output
98
Note
In the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
Submitted Solution:
```
dp = [0] * 22
dp[1] = 9
dp[2] = 9
dp[3] = 90
for i in range(4,21):
dp[i] = dp[i-1] * 10
for i in range(1,21):
dp[i] = dp[i] + dp[i-1]
def good(s):
if(str(s)[0]==str(s)[-1]):
return 1
return 0
def till(x):
Ans = 0
N = len(str(x))
Ans += dp[N-1]
x = str(x)
Ans += (int(x[0])-1) * (10**(N-2))
for i in range(1,N-1):
Ans += int(x[i]) * (10 ** (N-i-2))
if(int(x[-1])>= int(x[0])):
Ans += 1
return Ans
l,r = map(int,input().split())
Ans =0
if(r<=100):
for i in range(l,r+1):
Ans += good(i)
print(Ans)
else:
print(till(r) - till(l)+good(l))
``` | instruction | 0 | 83,686 | 20 | 167,372 |
No | output | 1 | 83,686 | 20 | 167,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is strictly larger than number x?
* Is it true that y is strictly smaller than number x?
* Is it true that y is larger than or equal to number x?
* Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
Input
The first line of the input contains a single integer n (1 β€ n β€ 10000) β the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
* ">" (for the first type queries),
* "<" (for the second type queries),
* ">=" (for the third type queries),
* "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 β€ x β€ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2Β·109 β€ y β€ 2Β·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
Examples
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible | instruction | 0 | 83,760 | 20 | 167,520 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
import random as r #>= 1 Y
s=int(input())
mi=-2000000000
ma=2000000000
for i in range(s):
x,y,z=map(str,input().split())
if z=='Y':
if len(x)==1:
if x[0]=="<":
ma=min(ma,(int(y)-1))
else:
mi=max(mi,(int(y)+1))
else:
if x[0]=="<":
ma=min(ma,int(y))
else:
mi=max(mi,int(y))
if z=='N':
if len(x)==1:
if x[0]==">":
ma=min(ma,(int(y)))
else:
mi=max(mi,(int(y)))
else:
if x[0]==">":
ma=min(ma,(int(y)-1))
else:
mi=max(mi,(int(y)+1))
if mi>ma:
print("Impossible")
else:
print(mi)
``` | output | 1 | 83,760 | 20 | 167,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is strictly larger than number x?
* Is it true that y is strictly smaller than number x?
* Is it true that y is larger than or equal to number x?
* Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
Input
The first line of the input contains a single integer n (1 β€ n β€ 10000) β the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
* ">" (for the first type queries),
* "<" (for the second type queries),
* ">=" (for the third type queries),
* "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 β€ x β€ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2Β·109 β€ y β€ 2Β·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
Examples
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible | instruction | 0 | 83,761 | 20 | 167,522 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
l,h=-2000000000,2000000000
for _ in range(int(input())):
x,y,z=[_ for _ in input().split()]
y=int(y)
if x=="<=":
if z=="Y":
if h>y:h=y
else:
if l<y+1:l=y+1
if x=="<":
if z=="Y":
if h>y-1:h=y-1
else:
if l<y:l=y
if x==">=":
if z=="Y":
if l<y:l=y
else:
if h>y-1:h=y-1
if x==">":
if z=="Y":
if l<y+1:l=y+1
else:
if h>y:h=y
if l>h: print("Impossible")
else:print(l)
'''if -1000000000<=l<=h<=1000000000:print(l)
elif -1000000000<=h<l<=1000000000:print("Impossible")
else:print(2000000000 if l>h else-2000000000)'''
``` | output | 1 | 83,761 | 20 | 167,523 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is strictly larger than number x?
* Is it true that y is strictly smaller than number x?
* Is it true that y is larger than or equal to number x?
* Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
Input
The first line of the input contains a single integer n (1 β€ n β€ 10000) β the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
* ">" (for the first type queries),
* "<" (for the second type queries),
* ">=" (for the third type queries),
* "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 β€ x β€ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2Β·109 β€ y β€ 2Β·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
Examples
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible | instruction | 0 | 83,762 | 20 | 167,524 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
import sys
n = int(sys.stdin.readline())
instructions = []
max_const = 2000000000
min_const = -2000000000
for i in range(n):
instructions.append(list(map(str,sys.stdin.readline().split())))
#print(instructions,n)
criteria = []
for i in instructions:
if (i[0] == ">" and i[2] == "Y") or (i[0] == "<=" and i[2] == "N"):
criteria.append((int(i[1])+1,max_const))
elif (i[0] == ">=" and i[2] == "Y") or (i[0] == "<" and i[2] == "N"):
criteria.append((int(i[1]),max_const))
elif (i[0] == "<" and i[2] == "Y") or (i[0] == ">=" and i[2] == "N"):
criteria.append((min_const,int(i[1])-1))
else:
criteria.append((min_const,int(i[1])))
mini = min_const
maxi = max_const
for i in criteria:
mini = max(mini,i[0])
maxi = min(maxi,i[1])
if mini>maxi:
print("Impossible")
else:
print(mini)
``` | output | 1 | 83,762 | 20 | 167,525 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is strictly larger than number x?
* Is it true that y is strictly smaller than number x?
* Is it true that y is larger than or equal to number x?
* Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
Input
The first line of the input contains a single integer n (1 β€ n β€ 10000) β the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
* ">" (for the first type queries),
* "<" (for the second type queries),
* ">=" (for the third type queries),
* "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 β€ x β€ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2Β·109 β€ y β€ 2Β·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
Examples
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible | instruction | 0 | 83,763 | 20 | 167,526 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
import sys
queries = int( sys.stdin.readline() )
opp = { '>': '<=',
'>=': '<',
'<': '>=',
'<=': '>' }
lower = -2000000000
upper = 2000000000
for i in range(queries):
oper, num, judge = sys.stdin.readline().rstrip().split(' ')
if judge == 'N':
oper = opp[oper]
if oper == '>':
lower = max(int(num) + 1, lower)
elif oper == '>=':
lower = max(int(num), lower)
elif oper == '<':
upper = min(int(num) - 1, upper)
elif oper == '<=':
upper = min(int(num), upper)
#print(str(lower) + " " + str(upper))
if(lower > upper):
break
if(lower > upper):
print ("Impossible")
else:
print(lower)
``` | output | 1 | 83,763 | 20 | 167,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is strictly larger than number x?
* Is it true that y is strictly smaller than number x?
* Is it true that y is larger than or equal to number x?
* Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
Input
The first line of the input contains a single integer n (1 β€ n β€ 10000) β the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
* ">" (for the first type queries),
* "<" (for the second type queries),
* ">=" (for the third type queries),
* "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 β€ x β€ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2Β·109 β€ y β€ 2Β·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
Examples
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible | instruction | 0 | 83,764 | 20 | 167,528 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
n = int(input())
ft = [">=",">","<=","<"]
sn = -2*10**9
mn = -sn
for i in range(n):
c, num, flag = input().split()
cindex = ft.index(c)
num = int(num)
if flag=="N":
cindex = 3 - cindex
if cindex==1:
cindex=0
num+=1
elif cindex==3:
cindex=2
num-=1
if cindex == 0 and sn < num:
sn = num
elif cindex ==2 and mn > num:
mn = num
if sn<=mn :
print(sn)
else:
print("Impossible")
``` | output | 1 | 83,764 | 20 | 167,529 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is strictly larger than number x?
* Is it true that y is strictly smaller than number x?
* Is it true that y is larger than or equal to number x?
* Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
Input
The first line of the input contains a single integer n (1 β€ n β€ 10000) β the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
* ">" (for the first type queries),
* "<" (for the second type queries),
* ">=" (for the third type queries),
* "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 β€ x β€ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2Β·109 β€ y β€ 2Β·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
Examples
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible | instruction | 0 | 83,765 | 20 | 167,530 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
n=int(input())
p=-1000000001
l=1000000001
for x in range(n) :
s=input().split()
r=int(s[1])
if s[2]=="Y" :
if s[0]==">=" :
p=max(p,r)
if s[0]==">" :
p=max(p,r+1)
if s[0]=="<=" :
l=min(l,r)
if s[0]=="<" :
l=min(l,r-1)
else :
if s[0]=="<" :
p=max(p,r)
if s[0]=="<=" :
p=max(p,r+1)
if s[0]==">" :
l=min(l,r)
if s[0]==">=" :
l=min(l,r-1)
if p<=l :
print(p)
else :
print("Impossible")
``` | output | 1 | 83,765 | 20 | 167,531 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is strictly larger than number x?
* Is it true that y is strictly smaller than number x?
* Is it true that y is larger than or equal to number x?
* Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
Input
The first line of the input contains a single integer n (1 β€ n β€ 10000) β the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
* ">" (for the first type queries),
* "<" (for the second type queries),
* ">=" (for the third type queries),
* "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 β€ x β€ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2Β·109 β€ y β€ 2Β·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
Examples
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible | instruction | 0 | 83,766 | 20 | 167,532 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
n = int(input())
i = - 2000000000
j = 2000000000
grt = ['>','>=']
lwr = ['<','<=']
for _ in range(n):
sna = input().split(' ')
sign = sna[0]
num = int(sna[1])
ans = True if sna[2] == 'Y' else False
if sign == '>':
if ans:
i = num + 1 if i < num +1 else i
else:
j = num if j > num else j
elif sign == '>=':
if ans:
i = num if i < num else i
else:
j = num -1 if j > num -1 else j
elif sign == '<':
if ans:
j = num - 1 if j > num -1 else j
else:
i = num if i < num else i
elif sign == '<=':
if ans:
j = num if j > num else j
else:
i = num +1 if i < num +1 else i
# print(i,j)
if j >= i:
print(i)
else:
print("Impossible")
``` | output | 1 | 83,766 | 20 | 167,533 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.