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.
Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such tickets and moved on to a more general question. Now he explores k-lucky tickets.
Pollard sais that a ticket is k-lucky if we can add arithmetic operation signs between its digits to the left or right of them (i.e., "+", "-", " × ") and brackets so as to obtain the correct arithmetic expression whose value would equal k. For example, ticket "224201016" is 1000-lucky as ( - 2 - (2 + 4)) × (2 + 0) + 1016 = 1000.
Pollard was so carried away by the lucky tickets that he signed up for a seminar on lucky tickets and, as far as Gerald knows, Pollard will attend it daily at 7 pm in some famous institute and will commute to it in the same tram for m days. In this tram tickets have eight digits. And Gerald wants to make a surprise for Pollard: each day Pollard will receive a tram k-lucky ticket. The conductor has already agreed to give Pollard certain tickets during all these m days and he only wants Gerald to tell him what kind of tickets to give out. In this regard, help Gerald pick exactly m distinct k-lucky tickets.
Input
The single line contains two integers k and m (0 ≤ k ≤ 104, 1 ≤ m ≤ 3·105).
Output
Print m lines. Each line must contain exactly 8 digits — the k-winning ticket. The tickets may begin with 0, all tickets must be distinct. If there are more than m distinct k-lucky tickets, print any m of them. It is guaranteed that at least m distinct k-lucky tickets exist. The tickets can be printed in any order.
Examples
Input
0 3
Output
00000000
00000001
00000002
Input
7 4
Output
00000007
00000016
00000017
00000018
Submitted Solution:
```
n, m = map(int, input().split())
op = ['+', '-', '*']
st = ['#' for i in range(0, 15)]
used = []
ret = []
def check(s):
global n
global used
news = []
for character in s:
if character in '+-*': news.append(character)
else:
if len(news) > 0 and news[-1] == '*':
news.pop()
a = int(news[-1])
b = int(character)
news.pop()
news.append(str(a*b))
else: news.append(character)
sol = int(news[0])
for i in range(1, len(news), 2):
if news[i] == '-': sol -= int(news[i+1])
else: sol += int(news[i+1])
if n == 0:
used.append(s[0:len(s):2])
return True
if sol != 0 and sol % n == 0:
used.append(s[0:len(s):2])
return True
return False
def back(k):
global m
global used
if m <= 0: return
if k % 2 == 0: #cifra
for i in range(0, 10):
st[k] = chr(i+48)
if k == 14 and m > 0:# and not st[0:len(st):2] in used:
if check(st):
m -= 1
ret.append(''.join(st[0:len(st):2]))
if k < 14: back(k+1)
else: #operator
for i in op:
st[k] = i
back(k+1)
def main():
back(0)
print('\n'.join(ret))
if __name__ == '__main__':
main()
``` | instruction | 0 | 41,539 | 20 | 83,078 |
No | output | 1 | 41,539 | 20 | 83,079 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such tickets and moved on to a more general question. Now he explores k-lucky tickets.
Pollard sais that a ticket is k-lucky if we can add arithmetic operation signs between its digits to the left or right of them (i.e., "+", "-", " × ") and brackets so as to obtain the correct arithmetic expression whose value would equal k. For example, ticket "224201016" is 1000-lucky as ( - 2 - (2 + 4)) × (2 + 0) + 1016 = 1000.
Pollard was so carried away by the lucky tickets that he signed up for a seminar on lucky tickets and, as far as Gerald knows, Pollard will attend it daily at 7 pm in some famous institute and will commute to it in the same tram for m days. In this tram tickets have eight digits. And Gerald wants to make a surprise for Pollard: each day Pollard will receive a tram k-lucky ticket. The conductor has already agreed to give Pollard certain tickets during all these m days and he only wants Gerald to tell him what kind of tickets to give out. In this regard, help Gerald pick exactly m distinct k-lucky tickets.
Input
The single line contains two integers k and m (0 ≤ k ≤ 104, 1 ≤ m ≤ 3·105).
Output
Print m lines. Each line must contain exactly 8 digits — the k-winning ticket. The tickets may begin with 0, all tickets must be distinct. If there are more than m distinct k-lucky tickets, print any m of them. It is guaranteed that at least m distinct k-lucky tickets exist. The tickets can be printed in any order.
Examples
Input
0 3
Output
00000000
00000001
00000002
Input
7 4
Output
00000007
00000016
00000017
00000018
Submitted Solution:
```
k, m = map(int, input().split())
obtainable = [ [] for i in range(-k-5, k+5) ]
sol = []
def interpret(a,b,c,d,e,f,g):
ret = a
if b == '+': ret += c
if b == '-': ret -= c
if b == '*': ret *= c
if d == '+': ret += e
if d == '-': ret -= e
if d == '*': ret *= e
if f == '+': ret += g
if f == '-': ret -= g
if f == '*': ret *= g
return ret
def tipar(x):
x = str(x)
ret = ''
for i in range(0, 4-len(x)): ret += '0'
ret += x
return ret
for a in range(0, 10):
for c in range(0, 10):
for e in range(0, 10):
for g in range(0, 10):
for b in '+-*':
for d in '+-*':
for f in '+-*':
conf = a*1000 + c*100 + e*10 + g
if abs(interpret(a,b,c,d,e,f,g)) <= k:
obtainable[interpret(a,b,c,d,e,f,g)].append(conf)
for x in range(-k-1, k+1):
obtainable[x] = set(obtainable[x])
for a in range(0, k+1):
if len(sol) >= m: break
b = k - a
for x in obtainable[a]:
if len(sol) >= m: break
for y in obtainable[b]:
if len(sol) >= m: break
sol.append('%s%s' % (tipar(x), tipar(y)))
print('\n'.join(sol))
``` | instruction | 0 | 41,540 | 20 | 83,080 |
No | output | 1 | 41,540 | 20 | 83,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by the arithmetic expression was number 100. But he quickly analyzed all such tickets and moved on to a more general question. Now he explores k-lucky tickets.
Pollard sais that a ticket is k-lucky if we can add arithmetic operation signs between its digits to the left or right of them (i.e., "+", "-", " × ") and brackets so as to obtain the correct arithmetic expression whose value would equal k. For example, ticket "224201016" is 1000-lucky as ( - 2 - (2 + 4)) × (2 + 0) + 1016 = 1000.
Pollard was so carried away by the lucky tickets that he signed up for a seminar on lucky tickets and, as far as Gerald knows, Pollard will attend it daily at 7 pm in some famous institute and will commute to it in the same tram for m days. In this tram tickets have eight digits. And Gerald wants to make a surprise for Pollard: each day Pollard will receive a tram k-lucky ticket. The conductor has already agreed to give Pollard certain tickets during all these m days and he only wants Gerald to tell him what kind of tickets to give out. In this regard, help Gerald pick exactly m distinct k-lucky tickets.
Input
The single line contains two integers k and m (0 ≤ k ≤ 104, 1 ≤ m ≤ 3·105).
Output
Print m lines. Each line must contain exactly 8 digits — the k-winning ticket. The tickets may begin with 0, all tickets must be distinct. If there are more than m distinct k-lucky tickets, print any m of them. It is guaranteed that at least m distinct k-lucky tickets exist. The tickets can be printed in any order.
Examples
Input
0 3
Output
00000000
00000001
00000002
Input
7 4
Output
00000007
00000016
00000017
00000018
Submitted Solution:
```
n, m = map(int, input().split())
op = ['+', '-', '*']
st = ['#' for i in range(0, 15)]
used = []
def check(s):
global n
global used
news = []
for character in s:
if character in '+-*': news.append(character)
else:
if len(news) > 0 and news[-1] == '*':
news.pop()
a = int(news[-1])
b = int(character)
news.pop()
news.append(str(a*b))
else: news.append(character)
sol = int(news[0])
for i in range(1, len(news), 2):
if news[i] == '-': sol -= int(news[i+1])
else: sol += int(news[i+1])
if n == 0 or sol % n == 0:
used.append(s[0:len(s):2])
return True
return False
def back(k):
global m
global used
if m <= 0: return
if k % 2 == 0: #cifra
for i in range(0, 10):
st[k] = chr(i+48)
if k == 14 and m > 0 and not st[0:len(st):2] in used:
if check(st):
m -= 1
print(''.join(st[0:len(st):2]))
if k < 14: back(k+1)
else: #operator
for i in op:
st[k] = i
back(k+1)
def main():
back(0)
if __name__ == '__main__':
main()
``` | instruction | 0 | 41,541 | 20 | 83,082 |
No | output | 1 | 41,541 | 20 | 83,083 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142 | instruction | 0 | 41,610 | 20 | 83,220 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n = int(input())
x = input()
a = [x]
temp = x
for j in range (0, 9):
for i in range (0, n):
if(temp[i] == '9'):
f = list(temp)
f[i] = '0'
temp = "".join(f)
else:
s = list(temp)
s[i] = str(int(s[i]) + 1)
temp = "".join(s)
a.append(temp)
##################
ans = []
for i in range(0, 10):
for j in range (0, n):
temp = a[i][n - 1]
a[i] = a[i][:n - 1]
a[i] = temp + a[i]
ans.append(a[i])
print(min(ans))
``` | output | 1 | 41,610 | 20 | 83,221 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142 | instruction | 0 | 41,611 | 20 | 83,222 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
#!/usr/bin/env python3
n = int(input())
state = [int(c) for c in input()]
min_s = state
for i in range(n):
tmp = state[i:] + state[:i]
tmp_min = [tmp[i] - tmp[0] for i in range(n)]
for i in range(n):
if tmp_min[i] < 0:
tmp_min[i] += 10
if tmp_min < min_s:
min_s = tmp_min
print("".join(map(str, min_s)))
``` | output | 1 | 41,611 | 20 | 83,223 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142 | instruction | 0 | 41,612 | 20 | 83,224 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n=int(input())
s=input()
mn=s
for shift in range(n):
copy=s[n-shift:]+s[:n-shift]
for add in range(10):
ans=''
for dig in range(n):
ans+=str((int(copy[dig])+add)%10)
if(int(ans)<int(mn)):
mn=ans
print(mn)
``` | output | 1 | 41,612 | 20 | 83,225 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142 | instruction | 0 | 41,613 | 20 | 83,226 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n = int(input())
d = input()
c = d
s = '1'
m = 10**1005
for k in range(0,11):
for i in range(0,n):
c = c[:i]+str((int(c[i])+1)%10)+c[i+1:]
for i in range(0,n):
c = c[1:]+c[0]
b = int(c)
if b < m:
m = b
s = c
print(s)
``` | output | 1 | 41,613 | 20 | 83,227 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142 | instruction | 0 | 41,614 | 20 | 83,228 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n = int(input())
a = list(input())
ans = a
for i in range(0,10):
for j in range(0,n):
if a < ans:
ans = a
a = a[1:] + [a[0]]
for j in range(0,n):
a[j] = str((int(a[j])+1)%10)
print("".join(ans))
``` | output | 1 | 41,614 | 20 | 83,229 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142 | instruction | 0 | 41,615 | 20 | 83,230 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
def main():
input()
digits = tuple(map(int, input()))
l = [digits]
for a in range(1, 10):
l.append(tuple((a + b) % 10 for b in digits))
for digits in l[:]:
a = digits[-1]
for i, b in enumerate(digits):
if a and not b:
l.append(digits[i:] + digits[:i])
a = b
print(''.join(map(str, min(l))))
if __name__ == '__main__':
main()
``` | output | 1 | 41,615 | 20 | 83,231 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142 | instruction | 0 | 41,616 | 20 | 83,232 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
def upshift(s):
for i in range(n):
if s[i] == '9':
s[i] = '0'
else:
s[i] = chr(ord(s[i])+1)
return s
def lshift(s):
k = [s[n-1]]
for i in range (0, n-1):
k.append(s[i])
s = k
return s
def copy(s):
k = []
for i in s:
k.append(i)
return k
n = int(input())
s = list(str(input()))
small = copy(s)
for i in range(n):
s = lshift(s)
for j in range(10):
s = upshift(s)
if small > s:
small = copy(s)
for i in small:
print(i, end='')
``` | output | 1 | 41,616 | 20 | 83,233 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142 | instruction | 0 | 41,617 | 20 | 83,234 |
Tags: brute force, constructive algorithms, implementation
Correct Solution:
```
n = int(input())
l = list(map(int, [x for x in input()]))
m = [9] * (n + 1)
for i in range(len(l)):
x = list(l[i + 1:]) + list(l[:i + 1])
s = x[0]
for j in range(len(x)):
x[j] = (x[j] - s) % 10
if x < m:
m = x
print("".join(list(map(str, m))))
``` | output | 1 | 41,617 | 20 | 83,235 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142
Submitted Solution:
```
n = int(input())
s = input()
i = 0
min_ = int(s)
s1 = s
i = 0
while (i <= n):
s = s[1::] + s[0]
if (int(s[0]) != 0):
g = (9 - int(s[0])) + 1
s2 = ''
for j in range(len(s)):
h = int(s[j]) + g
if (h >= 10):
h = abs(10 - h)
s2 = s2 + str(h)
s = s2
if (int(s) < min_):
min_ = int(s)
s1 = s
i = i + 1
print(s1)
``` | instruction | 0 | 41,618 | 20 | 83,236 |
Yes | output | 1 | 41,618 | 20 | 83,237 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142
Submitted Solution:
```
n = int(input()) # ���������� ����
t = int(input())
min = t
a = []
for i in range(n):
a.append(t%10)
t //= 10
# ������ ����� ��������� ��� ��������� �������� � ����� ����������� �����
for i in range(n):
k = (10-a[n-1]) % 10
l = 1
new = 0
for j in range(n):
new += ((a[j] + k) % 10) * l
l *= 10
# �������� ����� ����� � ���������� �����
if new < min:
min = new
a.append(a[0])
a.pop(0)
print('0'*(n-len(str(min))) + str(min))
``` | instruction | 0 | 41,619 | 20 | 83,238 |
Yes | output | 1 | 41,619 | 20 | 83,239 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142
Submitted Solution:
```
from itertools import chain
C = 0
def main():
input()
ls = list(map(int, input()))
n = len(ls)
a = ls[-1]
for stop, b in enumerate(ls):
if b != a:
break
else:
print('0' * n)
return
ls = ls[stop:] + ls[:stop]
a, l = ls[0], []
start = ma = tail = 0
for stop, b in enumerate(ls):
if b != a:
le = stop - start
if ma < le:
ma, tail = le, (b - a) % 10
l.clear()
l.append(start)
elif ma == le:
tl = (b - a) % 10
if tail > tl:
tail = tl
l.clear()
l.append(start)
elif tail == tl:
l.append(start)
a, start = b, stop
le = n - start
if ma < le:
l.clear()
l.append(start)
elif ma == le:
tl = (ls[0] - a) % 10
if tail > tl:
l.clear()
l.append(start)
elif tail == tl:
l.append(start)
for i, start in enumerate(l):
base = ls[start]
l[i] = tuple((a - base) % 10 + 48 for a in chain(ls[start:], ls[:start]))
print(''.join(map(chr, min(l))))
if __name__ == '__main__':
main()
``` | instruction | 0 | 41,620 | 20 | 83,240 |
Yes | output | 1 | 41,620 | 20 | 83,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142
Submitted Solution:
```
n = int(input())
s = [int(i) for i in input()]
k = [1 for i in range(n)]
for i in range(n):
if [(u+(10-s[i-1])%10)%10 for u in s[i-1:]]+[(u+(10-s[i-1])%10)%10 for u in s[:i-1]] < k:
k = [(u+(10-s[i-1])%10)%10 for u in s[i-1:]]+[(u+(10-s[i-1])%10)%10 for u in s[:i-1]]
ans = ''
for i in k:
ans+=str(i)
print(ans)
``` | instruction | 0 | 41,621 | 20 | 83,242 |
Yes | output | 1 | 41,621 | 20 | 83,243 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142
Submitted Solution:
```
######### ## ## ## #### ##### ## # ## # ##
# # # # # # # # # # # # # # # # # # #
# # # # ### # # # # # # # # # # # #
# ##### # # # # ### # # # # # # # # #####
# # # # # # # # # # # # # # # # # #
######### # # # # ##### # ##### # ## # ## # #
"""
PPPPPPP RRRRRRR OOOO VV VV EEEEEEEEEE
PPPPPPPP RRRRRRRR OOOOOO VV VV EE
PPPPPPPPP RRRRRRRRR OOOOOOOO VV VV EE
PPPPPPPP RRRRRRRR OOOOOOOO VV VV EEEEEE
PPPPPPP RRRRRRR OOOOOOOO VV VV EEEEEEE
PP RRRR OOOOOOOO VV VV EEEEEE
PP RR RR OOOOOOOO VV VV EE
PP RR RR OOOOOO VV VV EE
PP RR RR OOOO VVVV EEEEEEEEEE
"""
"""
Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;
def ceil(x):
if x != int(x):
x = int(x) + 1
return x
def factorial(x, m):
val = 1
while x>0:
val = (val * x) % m
x -= 1
return val
def fact(x):
val = 1
while x > 0:
val *= x
x -= 1
return val
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
## gcd function
def gcd(a,b):
if b == 0:
return a;
return gcd(b, a % b);
## nCr function efficient using Binomial Cofficient
def nCr(n, k):
if k > n:
return 0
if(k > n - k):
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
if hi == None:
hi = len(a);
while lo < hi:
mid = (lo+hi)//2;
if a[mid] < x:
lo = mid+1;
else:
hi = mid;
return lo;
## prime factorization
def primefs(n):
## if n == 1 ## calculating primes
primes = {}
while(n%2 == 0 and n > 0):
primes[2] = primes.get(2, 0) + 1
n = n//2
for i in range(3, int(n**0.5)+2, 2):
while(n%i == 0 and n > 0):
primes[i] = primes.get(i, 0) + 1
n = n//i
if n > 2:
primes[n] = primes.get(n, 0) + 1
## prime factoriazation of n is stored in dictionary
## primes and can be accesed. O(sqrt n)
return primes
## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
res = 1
x = x % p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) :
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
temp = a
a = b
b = temp
return a,b;
# find function with path compression included (recursive)
# def find(x, link):
# if link[x] == x:
# return x
# link[x] = find(link[x], link);
# return link[x];
# find function with path compression (ITERATIVE)
def find(x, link):
p = x;
while( p != link[p]):
p = link[p];
while( x != p):
nex = link[x];
link[x] = p;
x = nex;
return p;
# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x,y = swap(x,y)
if x != y:
size[x] += size[y]
link[y] = x
## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
prime = [True for i in range(n+1)]
prime[0], prime[1] = False, False
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
spf[1] = 1;
for i in range(2, MAXN):
spf[i] = i;
for i in range(4, MAXN, 2):
spf[i] = 2;
for i in range(3, ceil(MAXN ** 0.5), 2):
if spf[i] == i:
for j in range(i*i, MAXN, i):
if spf[j] == j:
spf[j] = i;
## function for storing smallest prime factors (spf) in the array
################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
res = []
for i in range(2, int(x ** 0.5) + 1):
while x % i == 0:
res.append(i)
x //= i
if x != 1:
res.append(x)
return res
## this function is useful for multiple queries only, o/w use
## primefs function above. complexity O(log n)
## taking integer array input
def int_array():
return list(map(int, input().strip().split()));
def float_array():
return list(map(float, input().strip().split()));
## taking string array input
def str_array():
return input().strip().split();
#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
################### ---------------- TEMPLATE ENDS HERE ---------------- ###################
from itertools import permutations
import math
from bisect import bisect_left
def solve():
n = int(input())
mystring = input().rstrip()
s = list(map(int, [x for x in mystring]))
for i in range(10):
a = [str((x + i) % 10) for x in s]
minimum = min(a)
ind = a.index(minimum)
zstring = "".join(a[ind:]) + "".join(a[:ind])
mystring = min(zstring,mystring)
mystring = mystring.rstrip('0')
if len(mystring) != n:
mystring = '0'*(n - len(mystring)) + mystring
print(mystring)
if __name__ == '__main__':
for _ in range(1):
solve()
# fin_time = datetime.now()
# print("Execution time (for loop): ", (fin_time-init_time))
``` | instruction | 0 | 41,622 | 20 | 83,244 |
No | output | 1 | 41,622 | 20 | 83,245 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142
Submitted Solution:
```
import copy
# x=int(input(''))
# a=str(input(''))
a="579"
a=list(a)
o=[]
for i in range(10):
p=[]
for s in a:
if(s=="9"):
p.append("0")
else:
p.append(str(int(s)+1))
z=("".join(p))
a=copy.deepcopy(z)
m=[]
for i in range(len(p)):
s=z[:i]+z[i:]
m.append(str(s))
l=str(min(m))
o.append(int(l))
k=min(o)
q=len(a)-len(str(k))
print("0"*q + str(k))
``` | instruction | 0 | 41,623 | 20 | 83,246 |
No | output | 1 | 41,623 | 20 | 83,247 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142
Submitted Solution:
```
length = int(input())
number = input()
def add(n):
num = str(n)
s = ""
for i in num:
ad = int(i) + 1
if(ad>9):
ad = 0
s = s + str(ad)
return s
def reverse(num):
return num[-1] + num[:-1]
dict_map ={}
def recursion(num,height):
if(height == 10):
return num
return min( min( int(add(num)),int(recursion(add(num) ,height+1)) ) , min(int(reverse(num)) ,int( recursion(reverse(num),height+1) ) ) )
ans = str(recursion(number,1))
for each in range(len(ans) , length):
ans = "0" + ans
print(ans)
``` | instruction | 0 | 41,624 | 20 | 83,248 |
No | output | 1 | 41,624 | 20 | 83,249 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.
You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.
The second line contains n digits — the initial state of the display.
Output
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
Examples
Input
3
579
Output
024
Input
4
2014
Output
0142
Submitted Solution:
```
class na(object):
n = 0
na.n, num = int(input()), input()
bum = []
loops = 0
for i in range(na.n):
bum.append(int(num[i]))
def a(x, rec):
global loops
loops += 1
rec -= 1
for i in range(na.n):
x[i] = x[i] - 1 if x[i] >0 else 9
return x if rec == 0 else a(x, rec)
def b(x, rec):
global loops
loops += 1
rec -= 1
l = x[0]
for i in range(na.n-1):
x[i] = x[i+1]
x[-1] = l
return x if rec == 0 else b(x, rec)
def li(x):
global loops
loops += 1
b = 0
for i in range(na.n):
b += (x[i] * 10 ** (na.n - i - 1))
return b
#print((bum))
#ar = [li(a(bum[:])), li(b(bum[:])), li(a(b(bum[:]))), li(b(a(bum[:])))]
#print((bum, ar))
#for i in range(4):
# m = ar[i] if ar[i] < m else m
'''j = 0
for i in range(1, na.n+1):
temp = abs(li(b(bum[:], i)))
if m > temp:
j = i
m = temp
j = b(bum[:], j)
k = 0
for i in range(1, 11):
temp = a(j[:], i)[0]
if temp == 0:
k = i
break
'''
#print(li(a(j[:], i)))
#print(repr(li(a(j[:], i))).rjust(na.n, '0'))
massigned = 0
m = 0
for j in range(1, 11):
temp = li(b(a(bum[:], j), na.n))
if m > temp or massigned == 0:
m = temp
massigned = 1
print(repr(m).rjust(na.n, '0'))
``` | instruction | 0 | 41,625 | 20 | 83,250 |
No | output | 1 | 41,625 | 20 | 83,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note
In the first example, the last digit of <image> is 2;
In the second example, the last digit of <image> is 0;
In the third example, the last digit of <image> is 2. | instruction | 0 | 41,768 | 20 | 83,536 |
Tags: math
Correct Solution:
```
a, b = map(int, input().split())
if b - a >= 5:
print(0)
else:
ans = 1
for x in range(a + 1, b + 1):
ans *= x
ans %= 10
print(ans % 10)
``` | output | 1 | 41,768 | 20 | 83,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note
In the first example, the last digit of <image> is 2;
In the second example, the last digit of <image> is 0;
In the third example, the last digit of <image> is 2. | instruction | 0 | 41,769 | 20 | 83,538 |
Tags: math
Correct Solution:
```
import sys
nums = [int(x) for x in sys.stdin.readline().split(' ')]
# keep multiplying mode 10
digit = 1
for i in range(nums[0] + 1, nums[1] + 1):
digit *= (i % 10)
digit = digit % 10
if digit is 0:
break
print(digit)
``` | output | 1 | 41,769 | 20 | 83,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note
In the first example, the last digit of <image> is 2;
In the second example, the last digit of <image> is 0;
In the third example, the last digit of <image> is 2. | instruction | 0 | 41,770 | 20 | 83,540 |
Tags: math
Correct Solution:
```
import functools
print((lambda a,b:0 if b-a>9 else functools.reduce(lambda x,y:x*y%10,range(a+1,b+1),1))(*map(int,input().split())))
``` | output | 1 | 41,770 | 20 | 83,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note
In the first example, the last digit of <image> is 2;
In the second example, the last digit of <image> is 0;
In the third example, the last digit of <image> is 2. | instruction | 0 | 41,771 | 20 | 83,542 |
Tags: math
Correct Solution:
```
a, b = map(int, input().split())
if (b - a > 10):
print(0);
else:
ans = 1
for i in range(a + 1, b + 1):
ans *= i;
print(ans % 10);
``` | output | 1 | 41,771 | 20 | 83,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note
In the first example, the last digit of <image> is 2;
In the second example, the last digit of <image> is 0;
In the third example, the last digit of <image> is 2. | instruction | 0 | 41,772 | 20 | 83,544 |
Tags: math
Correct Solution:
```
a ,b=map(int,input().split())
c = 1
d = 0
for i in range(a+1, b+1):
c *= i
d += 1
if(d == 5):
break
print(c % 10)
``` | output | 1 | 41,772 | 20 | 83,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note
In the first example, the last digit of <image> is 2;
In the second example, the last digit of <image> is 0;
In the third example, the last digit of <image> is 2. | instruction | 0 | 41,773 | 20 | 83,546 |
Tags: math
Correct Solution:
```
import math
n,m=map(int,input().split())
sum=1
if(m-n>=5):
print(0)
else:
for i in range(n+1,m+1):
sum*=i
print(sum%10)
``` | output | 1 | 41,773 | 20 | 83,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note
In the first example, the last digit of <image> is 2;
In the second example, the last digit of <image> is 0;
In the third example, the last digit of <image> is 2. | instruction | 0 | 41,774 | 20 | 83,548 |
Tags: math
Correct Solution:
```
from collections import Counter,defaultdict
from math import factorial as fact
#n = int(input())
a,b = [int(x) for x in input().split()]
d = b-a
if d>=10:
print(0)
else:
t = 1
while b>a:
t*=b
b-=1
print(t%10)
``` | output | 1 | 41,774 | 20 | 83,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, <image>. Note that when b ≥ a this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note
In the first example, the last digit of <image> is 2;
In the second example, the last digit of <image> is 0;
In the third example, the last digit of <image> is 2. | instruction | 0 | 41,775 | 20 | 83,550 |
Tags: math
Correct Solution:
```
a, b = map(int, input().split())
n = b - a
if n >= 10:
print(0)
else:
ans = 1
for i in range(a + 1, b + 1):
ans *= i
print(ans % 10)
``` | output | 1 | 41,775 | 20 | 83,551 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the number at the first glance. Could it be shortened? For example, instead of 1000000 you could write 10^{6}, instead of 1000000000 —10^{9}, instead of 1000000007 — 10^{9}+7.
Vasya decided that, to be concise, the notation should follow several rules:
* the notation should only consist of numbers, operations of addition ("+"), multiplication ("*") and exponentiation ("^"), in particular, the use of braces is forbidden;
* the use of several exponentiation operations in a row is forbidden, for example, writing "2^3^4" is unacceptable;
* the value of the resulting expression equals to the initial number;
* the notation should consist of the minimal amount of symbols.
Given n, find the equivalent concise notation for it.
Input
The only line contains a single integer n (1 ≤ n ≤ 10 000 000 000).
Output
Output a concise notation of the number n. If there are several concise notations, output any of them.
Examples
Input
2018
Output
2018
Input
1000000007
Output
10^9+7
Input
10000000000
Output
100^5
Input
2000000000
Output
2*10^9
Note
The third sample allows the answer 10^10 also of the length 5. | instruction | 0 | 41,832 | 20 | 83,664 |
Tags: brute force, greedy, implementation, math
Correct Solution:
```
import math
import itertools
pow10 = [1]
for i in range(10):
pow10.append(pow10[-1] * 10)
def getlen(x):
"""length of the decimal representation of integer x"""
return int(math.log10(x)) + 1
class ShortestRepresentation:
def __init__(self, n):
self.n = n
self._m = {}
self._s = [set() for i in range(10)]
self._generate_powers()
self._generate_power_and_power(7)
self._generate_simple_and_power(7)
def _generate_powers(self):
"""add to the collection all expressions of the form a^b"""
range_x = itertools.takewhile(
lambda x: x**2 <= self.n,
itertools.count(2))
for x in range_x:
c = x**2
p = 2
while c <= self.n:
self.update(c, '{}^{}'.format(x, p))
c *= x
p += 1
def _generate_power_and_power(self, maxlen):
"""add to the collection all expressions of the form a^b*c^d"""
for i in range(1, maxlen + 1):
range_j = itertools.takewhile(
lambda j: i + j + 1 <= maxlen,
itertools.count(i))
for j in range_j:
for x, y in itertools.product(self._s[i], self._s[j]):
x2 = self.get(x)
y2 = self.get(y)
self.update(x * y, '{}*{}'.format(x2, y2))
def _generate_simple_and_power(self, maxlen):
"""add to the collection all expressions of the form a^b*c"""
for i in range(1, maxlen - 1):
range_xy = itertools.product(
range(1, pow10[maxlen - 1 - i]),
self._s[i])
for x, y in range_xy:
y2 = self.get(y)
self.update(x * y, '{}*{}'.format(x, y2))
def update(self, x, s):
"""update with s x'th entry of the collection"""
if x > self.n:
return
ls = len(s)
if ls >= getlen(x): # length of s should be at least shorter
return
if x not in self._m:
self._m[x] = s
self._s[ls].add(x)
else:
lm = len(self._m[x])
if ls < lm:
self._s[lm].remove(x)
self._m[x] = s
self._s[ls].add(x)
def get(self, x):
"""retrieve shortest valid representation of number x"""
return self._m[x] if x in self._m else str(x)
n = int(input())
if n < 10**10:
sr = ShortestRepresentation(n)
ans = sr.get(n)
# check a*b and a+b
range_i = itertools.takewhile(
lambda i: i * 2 + 1 < len(ans),
itertools.count())
for i in range_i:
range_x = itertools.chain(
range(1, pow10[i] + 1),
sr._s[i])
for x in range_x:
ans = min(
ans, '{}+{}'.format(sr.get(x), sr.get(n - x)), key=len)
if n % x > 0:
continue
ans = min(
ans, '{}*{}'.format(sr.get(x), sr.get(n // x)), key=len)
print(ans)
else:
print('100^5')
``` | output | 1 | 41,832 | 20 | 83,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the number at the first glance. Could it be shortened? For example, instead of 1000000 you could write 10^{6}, instead of 1000000000 —10^{9}, instead of 1000000007 — 10^{9}+7.
Vasya decided that, to be concise, the notation should follow several rules:
* the notation should only consist of numbers, operations of addition ("+"), multiplication ("*") and exponentiation ("^"), in particular, the use of braces is forbidden;
* the use of several exponentiation operations in a row is forbidden, for example, writing "2^3^4" is unacceptable;
* the value of the resulting expression equals to the initial number;
* the notation should consist of the minimal amount of symbols.
Given n, find the equivalent concise notation for it.
Input
The only line contains a single integer n (1 ≤ n ≤ 10 000 000 000).
Output
Output a concise notation of the number n. If there are several concise notations, output any of them.
Examples
Input
2018
Output
2018
Input
1000000007
Output
10^9+7
Input
10000000000
Output
100^5
Input
2000000000
Output
2*10^9
Note
The third sample allows the answer 10^10 also of the length 5.
Submitted Solution:
```
import math
n = int(input())
aux = n
resp = ""
exp = 0
while n != 0:
num = 0
mult = 1
exp_aux = 0
while n%10 != 0:
num = n%10*mult + num
mult *= 10
n //= 10
exp_aux += 1
exp += 1
if num == 1:
if exp - exp_aux == 0:
resp = str(num) + resp
else:
resp = "10^" + str(exp - exp_aux) + resp
resp = "+" + resp
elif num != 0:
if exp - exp_aux == 0:
resp = str(num) + resp
else:
resp = str(num) + "*10^" + str(exp - exp_aux) + resp
resp = "+" + resp
exp += 1
n //= 10
resp = resp[1:] if len(resp) > 0 else resp
if len(str(aux)) > len(resp):
print(resp)
else:
print(aux)
``` | instruction | 0 | 41,833 | 20 | 83,666 |
No | output | 1 | 41,833 | 20 | 83,667 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the number at the first glance. Could it be shortened? For example, instead of 1000000 you could write 10^{6}, instead of 1000000000 —10^{9}, instead of 1000000007 — 10^{9}+7.
Vasya decided that, to be concise, the notation should follow several rules:
* the notation should only consist of numbers, operations of addition ("+"), multiplication ("*") and exponentiation ("^"), in particular, the use of braces is forbidden;
* the use of several exponentiation operations in a row is forbidden, for example, writing "2^3^4" is unacceptable;
* the value of the resulting expression equals to the initial number;
* the notation should consist of the minimal amount of symbols.
Given n, find the equivalent concise notation for it.
Input
The only line contains a single integer n (1 ≤ n ≤ 10 000 000 000).
Output
Output a concise notation of the number n. If there are several concise notations, output any of them.
Examples
Input
2018
Output
2018
Input
1000000007
Output
10^9+7
Input
10000000000
Output
100^5
Input
2000000000
Output
2*10^9
Note
The third sample allows the answer 10^10 also of the length 5.
Submitted Solution:
```
from math import sqrt
ans = N = input()
L = len(N)
N = int(N)
def check(x, y, z):
global ans
r = "%d^%d+%d" % (x, y, N-z) if z < N else "%d^%d" % (x, y)
if len(r) < len(ans):
ans = r
k = N // z
r = "%d*%d^%d+%d" % (k, x, y, N-k*z) if k*z < N else "%d*%d^%d" % (k, x, y)
if len(r) < len(ans):
ans = r
p = 9
while p <= k:
r = "%d*%d^%d+%d" % (p, x, y, N-p*z) if p*z < N else "%d*%d^%d" % (p, x, y)
if len(r) < len(ans):
ans = r
p = 10*p + 9
x = 2
while x*x <= N:
z = x; y = 1
while z*x <= N:
z *= x
y += 1
check(x, y, z)
if 9 < y:
check(x, 9, x**9)
x += 1
print(ans)
``` | instruction | 0 | 41,834 | 20 | 83,668 |
No | output | 1 | 41,834 | 20 | 83,669 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the number at the first glance. Could it be shortened? For example, instead of 1000000 you could write 10^{6}, instead of 1000000000 —10^{9}, instead of 1000000007 — 10^{9}+7.
Vasya decided that, to be concise, the notation should follow several rules:
* the notation should only consist of numbers, operations of addition ("+"), multiplication ("*") and exponentiation ("^"), in particular, the use of braces is forbidden;
* the use of several exponentiation operations in a row is forbidden, for example, writing "2^3^4" is unacceptable;
* the value of the resulting expression equals to the initial number;
* the notation should consist of the minimal amount of symbols.
Given n, find the equivalent concise notation for it.
Input
The only line contains a single integer n (1 ≤ n ≤ 10 000 000 000).
Output
Output a concise notation of the number n. If there are several concise notations, output any of them.
Examples
Input
2018
Output
2018
Input
1000000007
Output
10^9+7
Input
10000000000
Output
100^5
Input
2000000000
Output
2*10^9
Note
The third sample allows the answer 10^10 also of the length 5.
Submitted Solution:
```
def f(n):
c=0
while(n!=0):
n=n//10
c+=1
return c
g=input()
n=int(g)
j=[]
t=0
a=f(n)
if n%(10**(a-1))>9:
print(n)
else:
b=n//(10**(a-1))
c=n%(10**(a-1))
if b==1:
if a-1<=1:
print(n)
else:
if c==0:
t=4
if t<len(g):
print("10^%d"%((a-1)))
else:
print(n)
else:
t=6
if t<len(g):
print("10^%d+%d"%((a-1),c))
else:
print(n)
else:
if a-1<=1:
print(n)
else:
if c==0:
t=6
if t<len(g):
print("%d*10^%d"%(b,(a-1)))
else:
print(n)
else:
t=8
if t<len(g):
print("%d*10^%d+%d"%(b,(a-1),c))
else:
print(n)
``` | instruction | 0 | 41,835 | 20 | 83,670 |
No | output | 1 | 41,835 | 20 | 83,671 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a number less than 1000000000. However, sometimes it's hard to understand the number at the first glance. Could it be shortened? For example, instead of 1000000 you could write 10^{6}, instead of 1000000000 —10^{9}, instead of 1000000007 — 10^{9}+7.
Vasya decided that, to be concise, the notation should follow several rules:
* the notation should only consist of numbers, operations of addition ("+"), multiplication ("*") and exponentiation ("^"), in particular, the use of braces is forbidden;
* the use of several exponentiation operations in a row is forbidden, for example, writing "2^3^4" is unacceptable;
* the value of the resulting expression equals to the initial number;
* the notation should consist of the minimal amount of symbols.
Given n, find the equivalent concise notation for it.
Input
The only line contains a single integer n (1 ≤ n ≤ 10 000 000 000).
Output
Output a concise notation of the number n. If there are several concise notations, output any of them.
Examples
Input
2018
Output
2018
Input
1000000007
Output
10^9+7
Input
10000000000
Output
100^5
Input
2000000000
Output
2*10^9
Note
The third sample allows the answer 10^10 also of the length 5.
Submitted Solution:
```
import math
n = int(input())
div = 1 ; respF = str(n)
while div <=10:
aux = n ; resp = "" ; exp = 0 ; div += 1
while aux != 0:
num = 0
mult = 1
exp_aux = 0
while aux%div != 0:
num = aux%div*mult + num
mult *= div
aux //= div
exp_aux += 1
exp += 1
if num == 1:
if exp - exp_aux == 0:
resp = str(num) + resp
else:
resp = str(div) + "^" + str(exp - exp_aux) + resp
resp = "+" + resp
elif num != 0:
if exp - exp_aux == 0:
resp = str(num) + resp
else:
resp = str(num) + "*" + str(div) + "^" + str(exp - exp_aux) + resp
resp = "+" + resp
if len(str(n)) < len(resp):
break
exp += 1
aux //= div
if len(respF) > len(resp):
respF = resp
respF = respF[1:] if respF[0] == "+" else respF
if len(str(n)) > len(respF):
print(respF)
else:
print(n)
``` | instruction | 0 | 41,836 | 20 | 83,672 |
No | output | 1 | 41,836 | 20 | 83,673 |
Provide a correct Python 3 solution for this coding contest problem.
There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.
The conditions for completing the puzzle are
* You must have one combination of the same numbers.
* The remaining 12 numbers are 4 combinations of 3 numbers.
The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
* The same number can be used up to 4 times.
Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.
For example, if the given string is 3456666777999
If there is a "2", 234 567 666 77 999
If there is a "3", then 33 456 666 777 999
If there is a "5", then 345 567 666 77 999
If there is an "8", then 345 666 678 77 999
And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.
Input
The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.
Output
For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.
Example
Input
3649596966777
6358665788577
9118992346175
9643871425498
7755542764533
1133557799246
Output
2 3 5 8
3 4
1 2 3 4 5 6 7 8 9
7 8 9
1 2 3 4 6 7 8
0 | instruction | 0 | 41,966 | 20 | 83,932 |
"Correct Solution:
```
def check(nums):
#print(nums)
#5回以上出てこないか判別
for i in range(9):
if(nums[i]>4):
return False
for head in range(9):
#作業用の配列を作る
anums=nums[:]
#頭ができているか確認
if(anums[head]<2):
continue
anums[head]-=2
for i in range(9):
#三つ同じものがある場合はそれをひとまとめにする
if(anums[i]>=3):
anums[i]-=3
while(anums[i]>0):
#8以上が1になってても成立しないからFalse
if i>=7:
break
ok=True
for j in range(i,i+3):
if anums[j]<=0:
ok=False
#okがFalseなら順番になってない
if not ok:
break
#okがTrueなら順番になっているので一ずつ減らす。
for j in range(i,i+3):
anums[j]-=1
#全て0になっていればTrue
if not any(anums):
return True
return False
while True:
st=""
try:
st=input()
except:
break
#9個の配列を作り0を入れる
nums=[0 for i in range(9)]
#各数字の数を数える
for c in st:
nums[int(c)-1]+=1
#答えの配列を作る
anss=[]
#与えられたものに1~9を一つずつ加えてそれぞれで判定
for n in range(0,9):
nums[n]+=1
if(check(nums[:])):
anss.append(n+1)
nums[n]-=1
if(len(anss)==0):
anss.append(0)
print(" ".join(map(str,anss)))
``` | output | 1 | 41,966 | 20 | 83,933 |
Provide a correct Python 3 solution for this coding contest problem.
There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.
The conditions for completing the puzzle are
* You must have one combination of the same numbers.
* The remaining 12 numbers are 4 combinations of 3 numbers.
The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
* The same number can be used up to 4 times.
Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.
For example, if the given string is 3456666777999
If there is a "2", 234 567 666 77 999
If there is a "3", then 33 456 666 777 999
If there is a "5", then 345 567 666 77 999
If there is an "8", then 345 666 678 77 999
And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.
Input
The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.
Output
For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.
Example
Input
3649596966777
6358665788577
9118992346175
9643871425498
7755542764533
1133557799246
Output
2 3 5 8
3 4
1 2 3 4 5 6 7 8 9
7 8 9
1 2 3 4 6 7 8
0 | instruction | 0 | 41,967 | 20 | 83,934 |
"Correct Solution:
```
from collections import Counter
from copy import copy
def _check(pi):
pi=sorted(pi)
if len(pi)==0:
return True
retval=False
try:
_pi=copy(pi)
tmp=_pi[0]
for i in range(3):
_pi.remove(tmp)
retval = retval or _check(_pi)
except:
pass
try:
_pi=copy(pi)
tmp=_pi[0]
for i in range(3):
_pi.remove(tmp+i)
retval = retval or _check(_pi)
except:
pass
return retval
def check(pi,tsumo):
pi=pi+[tsumo]
c=Counter(pi)
for i in range(1,10):
if c[i]>4:
return False
for i in range(1,10):
if c[i]>=2:
_pi = copy(pi)
_pi.remove(i)
_pi.remove(i)
_pi=sorted(_pi)
if _check(_pi):
return True
return False
while True:
try:
s=input()
s=[int(i) for i in s]
retval=[]
for i in range(1,10):
if check(s,i):
retval.append(str(i))
if len(retval)==0:
print("0")
else:
print(" ".join(retval))
except EOFError:
break
``` | output | 1 | 41,967 | 20 | 83,935 |
Provide a correct Python 3 solution for this coding contest problem.
There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.
The conditions for completing the puzzle are
* You must have one combination of the same numbers.
* The remaining 12 numbers are 4 combinations of 3 numbers.
The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
* The same number can be used up to 4 times.
Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.
For example, if the given string is 3456666777999
If there is a "2", 234 567 666 77 999
If there is a "3", then 33 456 666 777 999
If there is a "5", then 345 567 666 77 999
If there is an "8", then 345 666 678 77 999
And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.
Input
The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.
Output
For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.
Example
Input
3649596966777
6358665788577
9118992346175
9643871425498
7755542764533
1133557799246
Output
2 3 5 8
3 4
1 2 3 4 5 6 7 8 9
7 8 9
1 2 3 4 6 7 8
0 | instruction | 0 | 41,969 | 20 | 83,938 |
"Correct Solution:
```
def check(nums):
for i in range(9):
if(nums[i]>4):return False
for head in range(9):
anums=nums[:]
if(anums[head]<2):continue
anums[head]-=2
for i in range(9):
if(anums[i]>=3):
anums[i]-=3
while(anums[i]>0):
if i>=7:break
ok=True
for j in range(i,i+3):
if anums[j]<=0:
ok=False
if not ok:
break
for j in range(i,i+3):
anums[j]-=1
if not any(anums):
return True
return False
while True:
st=''
try:
st=input()
except:
break
nums=[0 for i in range(9)]
for c in st:
nums[int(c)-1]+=1
anss=[]
for n in range(0,9):
nums[n]+=1
if(check(nums[:])):anss.append(n+1)
nums[n]-=1
if(len(anss)==0):anss.append(0)
print(' '.join(map(str,anss)))
``` | output | 1 | 41,969 | 20 | 83,939 |
Provide a correct Python 3 solution for this coding contest problem.
There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.
The conditions for completing the puzzle are
* You must have one combination of the same numbers.
* The remaining 12 numbers are 4 combinations of 3 numbers.
The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
* The same number can be used up to 4 times.
Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.
For example, if the given string is 3456666777999
If there is a "2", 234 567 666 77 999
If there is a "3", then 33 456 666 777 999
If there is a "5", then 345 567 666 77 999
If there is an "8", then 345 666 678 77 999
And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.
Input
The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.
Output
For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.
Example
Input
3649596966777
6358665788577
9118992346175
9643871425498
7755542764533
1133557799246
Output
2 3 5 8
3 4
1 2 3 4 5 6 7 8 9
7 8 9
1 2 3 4 6 7 8
0 | instruction | 0 | 41,970 | 20 | 83,940 |
"Correct Solution:
```
from itertools import combinations_with_replacement, combinations
def gen_dict(nums):
r = {}
for i in nums:
if i in r.keys():
r[i] += 1
else:
r[i] = 1
return r
def has_more_4(num_dict):
for i in num_dict.values():
if i > 4: return True
return False
def gen_conseq3(nums):
r = []
for i in range(1, 8):
for j in range(i, i+3):
if j not in nums: break
else:
r.append((i, i+1, i+2))
return r
def gen_same(n, num_dict):
r = []
for i, v in num_dict.items():
if v >= n: r.append(i)
return r
def gen_prec(c1s, c2s, c3):
r = []
for i in c1s:
for j in i:
r.append(j)
for i in c2s:
for j in range(3): r.append(i)
for j in range(2):
r.append(c3)
return sorted(r)
while True:
try: line = input()
except EOFError: break
founds = []
for i in range(1, 10):
ln = line + str(i)
nums = sorted(list(map(int, ln[:])))
num_dict = gen_dict(nums)
if has_more_4(num_dict):
continue
conseq_3s = gen_conseq3(nums)
same_3s = gen_same(3, num_dict)
same_2s = gen_same(2, num_dict)
was_found = False
for r in range(1, 5):
if was_found: break
for c1s in combinations_with_replacement(conseq_3s, r):
if was_found: break
for c2s in combinations(same_3s, 4-r):
if was_found: break
for c3 in same_2s:
pred = gen_prec(c1s, c2s, c3)
if pred == nums:
founds.append(str(i))
was_found = True
if founds:
print(' '.join(founds))
else:
print(0)
``` | output | 1 | 41,970 | 20 | 83,941 |
Provide a correct Python 3 solution for this coding contest problem.
There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.
The conditions for completing the puzzle are
* You must have one combination of the same numbers.
* The remaining 12 numbers are 4 combinations of 3 numbers.
The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
* The same number can be used up to 4 times.
Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.
For example, if the given string is 3456666777999
If there is a "2", 234 567 666 77 999
If there is a "3", then 33 456 666 777 999
If there is a "5", then 345 567 666 77 999
If there is an "8", then 345 666 678 77 999
And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.
Input
The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.
Output
For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.
Example
Input
3649596966777
6358665788577
9118992346175
9643871425498
7755542764533
1133557799246
Output
2 3 5 8
3 4
1 2 3 4 5 6 7 8 9
7 8 9
1 2 3 4 6 7 8
0 | instruction | 0 | 41,971 | 20 | 83,942 |
"Correct Solution:
```
def is_solved(nums):
keys = set(nums)
for key in keys:
if nums.count(key) >= 2:
tmp = nums[:]
tmp.remove(key)
tmp.remove(key)
for key in keys:
key_count = tmp.count(key)
if key_count == 4:
if key + 1 in tmp and key + 2 in tmp:
for _ in range(4): tmp.remove(key)
tmp.remove(key + 1)
tmp.remove(key + 2)
elif key_count == 3:
for _ in range(3): tmp.remove(key)
elif tmp.count(key + 1) >= key_count and tmp.count(key + 2) >= key_count:
for _ in range(key_count):
tmp.remove(key)
tmp.remove(key + 1)
tmp.remove(key + 2)
if tmp == []:
return True
return False
while True:
try:
puzzle = list(map(int, list(input())))
ans = []
for i in range(1, 10):
if puzzle.count(i) <= 3 and is_solved(puzzle + [i]):
ans.append(i)
if ans:
print(*ans)
else:
print(0)
except EOFError:
break
``` | output | 1 | 41,971 | 20 | 83,943 |
Provide a correct Python 3 solution for this coding contest problem.
There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.
The conditions for completing the puzzle are
* You must have one combination of the same numbers.
* The remaining 12 numbers are 4 combinations of 3 numbers.
The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
* The same number can be used up to 4 times.
Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.
For example, if the given string is 3456666777999
If there is a "2", 234 567 666 77 999
If there is a "3", then 33 456 666 777 999
If there is a "5", then 345 567 666 77 999
If there is an "8", then 345 666 678 77 999
And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.
Input
The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.
Output
For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.
Example
Input
3649596966777
6358665788577
9118992346175
9643871425498
7755542764533
1133557799246
Output
2 3 5 8
3 4
1 2 3 4 5 6 7 8 9
7 8 9
1 2 3 4 6 7 8
0 | instruction | 0 | 41,972 | 20 | 83,944 |
"Correct Solution:
```
import sys
def g(c,i):
a=[0]*9
for j in e+[i]:a[j-1]+=1
return a
def f(c):
if sum(c)in c:return 1
if 5 in c:return 0
if 4 in c:
k=c.index(4);c[k]-=3
if f(c):return 1
c[k]+=3
if 3 in c:
k=c.index(3);c[k]-=3
if f(c):return 1
c[k]+=3
for i in range(7):
if c[i]and c[i+1]and c[i+2]:
c[i]-=1;c[i+1]-=1;c[i+2]-=1
if f(c):return 1
c[i]+=1;c[i+1]+=1;c[i+2]+=1
for e in sys.stdin:
e=list(map(int,e.strip()))
a=[i for i in range(1,10)if f(g(e,i))]
if a:print(*a)
else:print(0)
``` | output | 1 | 41,972 | 20 | 83,945 |
Provide a correct Python 3 solution for this coding contest problem.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100 | instruction | 0 | 41,981 | 20 | 83,962 |
"Correct Solution:
```
while 1:
a=int(input())
if a<0:break
ans='' if a!=0 else '0'
while a:ans,a=str(a%4)+ans,a//4
print(ans)
``` | output | 1 | 41,981 | 20 | 83,963 |
Provide a correct Python 3 solution for this coding contest problem.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100 | instruction | 0 | 41,982 | 20 | 83,964 |
"Correct Solution:
```
def to_4(x):
if x // 4:
return to_4(x//4) + str(x%4)
return str(x%4)
while True:
n = int(input())
if n == -1: break
print(to_4(n))
``` | output | 1 | 41,982 | 20 | 83,965 |
Provide a correct Python 3 solution for this coding contest problem.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100 | instruction | 0 | 41,983 | 20 | 83,966 |
"Correct Solution:
```
import math
while 1:
n = int(input())
if n == -1:
break
elif n == 0:
print(0)
else:
p = int(math.log(n,4))
l =[None for i in range(p)]
x = n
for i in range(p):
l[i] = x // (4 ** (p - i))
x = x % (4 ** (p - i))
l.append(x)
print(*l,sep="")
``` | output | 1 | 41,983 | 20 | 83,967 |
Provide a correct Python 3 solution for this coding contest problem.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100 | instruction | 0 | 41,984 | 20 | 83,968 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0175
"""
import sys
from sys import stdin
input = stdin.readline
def main(args):
while True:
n = int(input())
if n == -1:
break
q = []
q.append(n % 4)
while n > 3:
n //= 4
q.append(n % 4)
q.reverse()
print(''.join(map(str, q)))
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 41,984 | 20 | 83,969 |
Provide a correct Python 3 solution for this coding contest problem.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100 | instruction | 0 | 41,985 | 20 | 83,970 |
"Correct Solution:
```
BASE = 4
while True:
input_num = int(input())
if input_num == -1:
break
result = ""
while True:
quotient, remainder = divmod(input_num, BASE)
result = str(remainder) + result
if input_num < BASE:
break
input_num = quotient
print(result)
``` | output | 1 | 41,985 | 20 | 83,971 |
Provide a correct Python 3 solution for this coding contest problem.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100 | instruction | 0 | 41,986 | 20 | 83,972 |
"Correct Solution:
```
while True:
v = int(input())
if v == -1:
break
if v < 4:
print(v)
else:
b = str(bin(v))[2:]
bb = [b[i:i+2] for i in range(len(b)-2, -1, -2)]
if len(b) % 2 != 0:
bb.append(b[0])
ans = []
for t in bb:
tmp = 0
for i, v in enumerate(t[::-1]):
tmp += pow(2, i) * int(v)
ans.append(tmp)
print(''.join(map(str, ans[::-1])))
``` | output | 1 | 41,986 | 20 | 83,973 |
Provide a correct Python 3 solution for this coding contest problem.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100 | instruction | 0 | 41,987 | 20 | 83,974 |
"Correct Solution:
```
# AOJ 0175 Quaternary Notation
# Python3 2018.6.19 bal4u
while True:
n = int(input())
if n < 0: break
if n == 0: print(0)
else:
ans = []
while n > 0:
ans.append(str(n & 3))
n >>= 2
print(*ans[::-1], sep='')
``` | output | 1 | 41,987 | 20 | 83,975 |
Provide a correct Python 3 solution for this coding contest problem.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100 | instruction | 0 | 41,988 | 20 | 83,976 |
"Correct Solution:
```
import sys
def main():
for line in sys.stdin:
n = int(line)
if n == -1:
break
else:
if n != 0:
hoge = []
while True:
foo = n // 4
bar = n % 4
if foo >= 4:
hoge.append(bar)
n = foo
elif foo < 4:
hoge.append(bar)
hoge.append(foo)
break
hoge.reverse()
hoge = [str(hoge[i]) for i in range(len(hoge))]
fuga = ""
for i in range(len(hoge)):
fuga += hoge[i]
print(int(fuga))
elif n == 0:
print(n)
if __name__ == "__main__":
main()
``` | output | 1 | 41,988 | 20 | 83,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100
Submitted Solution:
```
def f(n):
if int(n/4):
return(f(int(n/4))+str(n%4))
return str(n%4)
while 1:
n=int(input())
if n==-1:
break
print(f(n))
``` | instruction | 0 | 41,989 | 20 | 83,978 |
Yes | output | 1 | 41,989 | 20 | 83,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100
Submitted Solution:
```
def translate(x):
if int(x/4):
return translate(int(x/4)) + str(x % 4)
return str(x % 4)
while 1:
n = int(input())
if n == -1:
break
n4 = translate(n)
print(n4)
``` | instruction | 0 | 41,990 | 20 | 83,980 |
Yes | output | 1 | 41,990 | 20 | 83,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100
Submitted Solution:
```
while True:
n = int(input())
if n == -1:
break
if n == 0:
print(0)
else:
ans = []
while n > 0:
ans.append(n % 4)
n = n // 4
for i in range(len(ans)):
print(ans[len(ans) - 1 - i], end="")
print("")
``` | instruction | 0 | 41,991 | 20 | 83,982 |
Yes | output | 1 | 41,991 | 20 | 83,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.
Binary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.
Only the four numbers 0, 1, 2, and 3 are used in quaternary numbers. In quaternary numbers, when the number is incremented from 0, it will be carried to the next digit when it reaches 4. Therefore, the decimal number 4 is carried to the expression "10".
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |- ---
Binary | 0 | 1 | 10 | 11 | 100 | 101 | 110 | 111 | 1000 | 101 | 1010 | ...
Quadrant | 0 | 1 | 2 | 3 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | ...
In Hawaii, fish and taro were counted between fingers in the old days, so it seems that they used quaternary numbers instead of decimal numbers.
Create a program that converts the integer n input in decimal to decimal and outputs it.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of -1. One integer n (0 ≤ n ≤ 1000000) is given on one row for each dataset.
The number of datasets does not exceed 2000.
Output
The result of conversion to quaternary number for each input data set is output on one line.
Example
Input
7
4
0
12
10
10000
-1
Output
13
10
0
30
22
2130100
Submitted Solution:
```
def to_four(n):
if n == 0:
return "0"
acc = ""
while n:
acc = str(n % 4) + acc
n //= 4
return acc
while True:
n = int(input())
if n == -1:
break
print(to_four(n))
``` | instruction | 0 | 41,992 | 20 | 83,984 |
Yes | output | 1 | 41,992 | 20 | 83,985 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.