message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input consists of four lines, each line containing a single digit 0 or 1.
Output
Output a single digit, 0 or 1.
Example
Input
0
1
1
0
Output
0 | instruction | 0 | 10,451 | 20 | 20,902 |
Tags: *special, brute force, implementation
Correct Solution:
```
"""
Codeforces April Fools Contest 2017 Problem E
Author : chaotic_iak
Language: Python 3.5.2
"""
################################################### SOLUTION
def main():
a, = read()
b, = read()
c, = read()
d, = read()
n = 8*a + 4*b + 2*c + d
dc = { 0: 0, # test 2 confirmed correct
1: 1, # test 9 confirmed correct
2: 0, # probably test 6
3: 1, # test 13 confirmed correct
4: 0, # probably test 4
5: 0, # probably test 11
6: 0, # test 1 confirmed correct
7: 0, # probably test 15
8: 1, # test 3 confirmed correct
9: 1, # test 10 confirmed correct
10: 0, # probably test 7
11: 1, # probably test 14
12: 1, # test 5 confirmed correct
13: 0, # probably test 12
14: 1, # test 8 confirmed correct
15: 1, # probably test 16
}
print(dc[n])
#################################################### HELPERS
def read(callback=int):
return list(map(callback, input().strip().split()))
def write(value, end="\n"):
if value is None: return
try:
if not isinstance(value, str):
value = " ".join(map(str, value))
except:
pass
print(value, end=end)
write(main())
``` | output | 1 | 10,451 | 20 | 20,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
<image>
Input
The input consists of four lines, each line containing a single digit 0 or 1.
Output
Output a single digit, 0 or 1.
Example
Input
0
1
1
0
Output
0 | instruction | 0 | 10,452 | 20 | 20,904 |
Tags: *special, brute force, implementation
Correct Solution:
```
a = int(input())
b = int(input())
c = int(input())
d = int(input())
p = a ^ b
q = c | d
r = b & c
s = a ^ d
x = p & q
y = r | s
z = x ^ y
print(z)
``` | output | 1 | 10,452 | 20 | 20,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output
Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Examples
Input
01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110
Output
12345678
Input
10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000
Output
30234919 | instruction | 0 | 10,511 | 20 | 21,022 |
Tags: implementation, strings
Correct Solution:
```
c=[input() for i in range(11)]
x=[ c[0][i:i+10] for i in range(0,80,10)]
for i in x:
print(c.index(i)-1,end='')
``` | output | 1 | 10,511 | 20 | 21,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output
Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Examples
Input
01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110
Output
12345678
Input
10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000
Output
30234919 | instruction | 0 | 10,512 | 20 | 21,024 |
Tags: implementation, strings
Correct Solution:
```
msg = input()
password = [msg[i:i+10] for i in range(0,80, 10)]
for i in range(10):
digit = input()
while digit in password:
password[password.index(digit)] = str(i)
print("".join(password))
``` | output | 1 | 10,512 | 20 | 21,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output
Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Examples
Input
01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110
Output
12345678
Input
10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000
Output
30234919 | instruction | 0 | 10,513 | 20 | 21,026 |
Tags: implementation, strings
Correct Solution:
```
string = str(input())
number0 = str(input())
number1 = str(input())
number2 = str(input())
number3 = str(input())
number4 = str(input())
number5 = str(input())
number6 = str(input())
number7 = str(input())
number8 = str(input())
number9 = str(input())
number = ""
i = 0
while i <= 80:
try:
if string[i:i + 10] == number0:
number += "0"
elif string[i:i + 10] == number1:
number += "1"
elif string[i:i + 10] == number2:
number += "2"
elif string[i:i + 10] == number3:
number += "3"
elif string[i:i + 10] == number4:
number += "4"
elif string[i:i + 10] == number5:
number += "5"
elif string[i:i + 10] == number6:
number += "6"
elif string[i:i + 10] == number7:
number += "7"
elif string[i:i + 10] == number8:
number += "8"
elif string[i:i + 10] == number9:
number += "9"
i += 10
except IndexError:
pass
print(number)
``` | output | 1 | 10,513 | 20 | 21,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output
Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Examples
Input
01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110
Output
12345678
Input
10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000
Output
30234919 | instruction | 0 | 10,514 | 20 | 21,028 |
Tags: implementation, strings
Correct Solution:
```
from __future__ import print_function
import sys
if __name__ == "__main__":
# '''input
# 01001100100101100000010110001001011001000101100110010110100001011010100101101100
# 0100110000
# 0100110010
# 0101100000
# 0101100010
# 0101100100
# 0101100110
# 0101101000
# 0101101010
# 0101101100
# 0101101110
# '''
encryted_password = input()
n = 10
split_password = [encryted_password[i:i+n]
for i in range(0, len(encryted_password), n)]
num_code_list = []
for i in range(10):
num_code_list.append(input())
decryted_password = ""
for i in range(len(split_password)):
for j in range(len(num_code_list)):
if split_password[i] == num_code_list[j]:
decryted_password += str(j)
print(decryted_password)
``` | output | 1 | 10,514 | 20 | 21,029 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output
Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Examples
Input
01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110
Output
12345678
Input
10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000
Output
30234919 | instruction | 0 | 10,515 | 20 | 21,030 |
Tags: implementation, strings
Correct Solution:
```
a=input()
c=[]
for i in range(0,10):
b=input()
c.append(b)
k=0
for i in range(0,8):
x=a[k:k+10]
j=0
while(x!=c[j]):
j=j+1
print(j,end="")
k=k+10
``` | output | 1 | 10,515 | 20 | 21,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output
Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Examples
Input
01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110
Output
12345678
Input
10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000
Output
30234919 | instruction | 0 | 10,516 | 20 | 21,032 |
Tags: implementation, strings
Correct Solution:
```
n = input()
numbers = {}
for i in range(10):
x = input()
numbers[x] = i
res = []
for i in range(8):
p = n[i*10 : (i*10)+10 ]
#print(p)
if p in numbers:
res.append(numbers[p])
for i in res:
print(i,end="")
``` | output | 1 | 10,516 | 20 | 21,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output
Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Examples
Input
01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110
Output
12345678
Input
10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000
Output
30234919 | instruction | 0 | 10,517 | 20 | 21,034 |
Tags: implementation, strings
Correct Solution:
```
def pars(_str):
pars_list = []
for i in range(0,80,10):
pars_list.append(_str[i:i+10])
return pars_list
def recover(_str,_list):
password = ''
for i in _str:
if i in _list:
password += str(_list.index(i))
return password
_str = input()
_list = []
for i in range(10):
_list.append(input())
_str = pars(_str)
print(recover(_str,_list))
``` | output | 1 | 10,517 | 20 | 21,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" β thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output
Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Examples
Input
01001100100101100000010110001001011001000101100110010110100001011010100101101100
0100110000
0100110010
0101100000
0101100010
0101100100
0101100110
0101101000
0101101010
0101101100
0101101110
Output
12345678
Input
10101101111001000010100100011010101101110010110111011000100011011110010110001000
1001000010
1101111001
1001000110
1010110111
0010110111
1101001101
1011000001
1110010101
1011011000
0110001000
Output
30234919 | instruction | 0 | 10,518 | 20 | 21,036 |
Tags: implementation, strings
Correct Solution:
```
s=input()
x={}
for i in range(10):
w=input()
x[w]=str(i)
ans=''
for i in range(0,80,10):
ans+=x[s[i:i+10]]
print(ans)
``` | output | 1 | 10,518 | 20 | 21,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010 | instruction | 0 | 10,909 | 20 | 21,818 |
Tags: greedy, implementation
Correct Solution:
```
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
def ter(n,x):
s=str(x)
a="1"
b="1"
maxi=False
for i in range(1,n):
if s[i]=="2":
if maxi:
a+="0"
b+="2"
else:
a+="1"
b+="1"
elif s[i]=="0":
a+="0"
b+="0"
else:
if maxi:
a+="0"
b+="1"
else:
maxi=True
a+="1"
b+="0"
print(int(a))
print(int(b))
t=int(input())
for i in range(t):
n=int(input())
x=int(input())
ter(n,x)
# In[ ]:
``` | output | 1 | 10,909 | 20 | 21,819 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010 | instruction | 0 | 10,910 | 20 | 21,820 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
x = input()
a = x.find("1")
b = x.find("0")
d=""; e=""
if(a==-1):
for i in range(n):
if x[i]=="2":
d+="1"; e+="1"
else:
d+="0"; e+="0"
else:
for i in range(a):
if x[i]=="2":
d+="1"; e+="1"
else:
d+="0"; e+="0"
d+="1";e+="0"
d+="0"*(n-a-1)
e+=x[a+1:]
print(d+"\n"+e)
``` | output | 1 | 10,910 | 20 | 21,821 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010 | instruction | 0 | 10,911 | 20 | 21,822 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for tt in range(t):
n = int(input())
x = input()
h1 = False
sol1 = ''
sol2 = ''
for xi in x:
if h1:
sol1 += '0'
sol2 += xi
else:
if xi == '0':
sol1 += '0'
sol2 += '0'
elif xi == '2':
sol1 += '1'
sol2 += '1'
else:
sol1 += '1'
sol2 += '0'
h1 = True
print(sol1)
print(sol2)
``` | output | 1 | 10,911 | 20 | 21,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010 | instruction | 0 | 10,912 | 20 | 21,824 |
Tags: greedy, implementation
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
x = input()
a = []
b = []
c = 0
flag = False
for i in range(n):
if x[i]=='2':
a.append('1')
b.append('1')
elif x[i]=='0':
a.append('0')
b.append('0')
else:
a.append('1')
b.append('0')
c = i
flag = True
break
if flag==False or c==n-1:
a = ''.join(a)
b = ''.join(b)
else:
a = ''.join(a) + '0'*(n-c-1)
b = ''.join(b) + x[c+1:n]
print(a)
print(b)
``` | output | 1 | 10,912 | 20 | 21,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010 | instruction | 0 | 10,913 | 20 | 21,826 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for k in range(t):
n = int(input())
x = input()
a, b = [], []
was_zero_one = False
for i, d in enumerate(x):
if d == '0':
a.append('0')
b.append('0')
elif d == '1':
if not was_zero_one:
a.append('1')
b.append('0')
was_zero_one = True
else:
a.append('0')
b.append('1')
elif d == '2':
if not was_zero_one:
a.append('1')
b.append('1')
else:
a.append('0')
b.append('2')
print("".join(a))
print("".join(b))
``` | output | 1 | 10,913 | 20 | 21,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010 | instruction | 0 | 10,914 | 20 | 21,828 |
Tags: greedy, implementation
Correct Solution:
```
"""
Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
"""
def ternary_xor(s, n):
a, b = '', ''
flag = False
for i in range(n):
if s[i] == '2':
if flag:
a += '2'
b += '0'
else:
a += '1'
b += '1'
elif s[i] == '1':
a += '1'
b += '0'
if not flag:
flag = True
a, b = b, a
else:
a += '0'
b += '0'
if b > a:
a, b = b, a
print(a)
print(b)
if __name__== "__main__":
t = int(input())
for _ in range(t):
n = int(input())
s = input()
ternary_xor(s, n)
``` | output | 1 | 10,914 | 20 | 21,829 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010 | instruction | 0 | 10,915 | 20 | 21,830 |
Tags: greedy, implementation
Correct Solution:
```
for h in range(int(input())):
n = int(input())
x = [int(i) for i in input()]
a = [0] * n
a[0] = 1
b = [0] * n
b[0] = 1
fl = 0
for i in range(1, n):
if fl:
b[i] = x[i]
elif x[i] == 1:
a[i] = 1
fl = 1
elif x[i] == 2:
a[i] = 1
b[i] = 1
[print(i, end="") for i in a]
print()
[print(i, end="") for i in b]
print()
``` | output | 1 | 10,915 | 20 | 21,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010 | instruction | 0 | 10,916 | 20 | 21,832 |
Tags: greedy, implementation
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
s = input()
a, b = '', ''
is_one_found = False
for x in s:
if is_one_found:
a += '0'
b += x
else:
num = int(x)
if num == 1:
is_one_found = True
a += x
b += '0'
else:
a += str(num // 2)
b += str(num // 2)
print(a, b, sep='\n')
``` | output | 1 | 10,916 | 20 | 21,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
lst = list(input())
a, b = ['0']*n, ['0']*n
for i in range(n):
if lst[i] == '1':
a[i] = '1'
b[i] = '0'
for j in range(i+1, n):
b[j] = lst[j]
break
elif lst[i] == '0':
a[i] = b[i] = '0'
elif lst[i] == '2':
a[i] = b[i] = '1'
print(''.join(a))
print(''.join(b))
``` | instruction | 0 | 10,917 | 20 | 21,834 |
Yes | output | 1 | 10,917 | 20 | 21,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
lis = input()
s1 = []
s2 = []
diff = 0
for i in lis:
if diff == 0:
if i == '2':
s1.append(1)
s2.append(1)
elif i == '0':
s1.append(0)
s2.append(0)
else:
s1.append(1)
s2.append(0)
diff = 1
else:
s1.append(0)
s2.append(i)
for i in range(len(s1)):
print(s1[i],end='')
print()
for i in range(len(s1)):
print(s2[i],end='')
print()
``` | instruction | 0 | 10,918 | 20 | 21,836 |
Yes | output | 1 | 10,918 | 20 | 21,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
Submitted Solution:
```
from collections import Counter
from collections import defaultdict
import math
t=int(input())
for _ in range(0,t):
lis,mis=list(),list()
n =input()
n=int(n)
x =input()
x=list(x)
x=list(map(int,x))
s1=x[0]
if(s1 > 1):
mis.append(1)
lis.append(1)
g=1
i = g
while(i < n):
if(x[i] == 0):
lis.append(0)
mis.append(0)
elif(x[i] == 2):
lis.append(1)
mis.append(1)
elif(x[i] == 1):
lis.append(1)
mis.append(0)
i += 1
break
i=i+1
while(i<n):
k=0
lis.append(k)
mis.append(x[i])
i=i+ 1
lis=map(str,lis)
mis=map(str,mis)
s1="".join(list(lis))
s2="".join(list(mis))
print(s1)
print(s2)
``` | instruction | 0 | 10,919 | 20 | 21,838 |
Yes | output | 1 | 10,919 | 20 | 21,839 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
Submitted Solution:
```
T = int(input())
while T > 0 :
n = int(input())
val = input()
a = "1"
b = "1"
count = 1
for x in range(1, n) :
if val[x] == "2" :
a = a + "1"
b = b + "1"
elif val[x] == "0" :
a = a + "0"
b = b + "0"
else :
break
count += 1
if count < n :
if val[count] == "1" :
a = a + "1"
b = b + "0"
count = count + 1
for x in range(count, n) :
if val[x] == "2" :
a = a + "0"
b = b + "2"
elif val[x] == "1" :
a = a + "0"
b = b + "1"
else :
a = a + "0"
b = b + "0"
print(a)
print(b)
T -= 1
``` | instruction | 0 | 10,920 | 20 | 21,840 |
Yes | output | 1 | 10,920 | 20 | 21,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
Submitted Solution:
```
try:
t=int(input())
for _ in range(t):
a=''
b=''
n=int(input())
k=input()
for i in range(n):
if(k[i]=='1'):
a+='1'
b+='0'
for j in range(i+1,n):
a+='0'
b+=k[i]
break
else:
if(k[i]=='2'):
a+='1'
b+='1'
else:
a+='0'
b+='0'
print(a)
print(b)
except Exception:
pass
``` | instruction | 0 | 10,921 | 20 | 21,842 |
No | output | 1 | 10,921 | 20 | 21,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
Submitted Solution:
```
q = int(input())
for _ in range(q):
input()
x = input()
ans1 = ['1']
ans2 = ['1']
is_one = False
for i in x[1:]:
if i == '0':
ans1.append('0')
ans2.append('0')
elif i == '1':
if is_one:
ans1.append('0')
ans2.append('1')
else:
ans1.append('1')
ans2.append('1')
is_one = True
else:
if is_one:
ans1.append('0')
ans2.append('2')
else:
ans1.append('1')
ans2.append('1')
for i in ans1:
print(i, end='')
print()
for i in ans2:
print(i, end='')
print()
``` | instruction | 0 | 10,922 | 20 | 21,844 |
No | output | 1 | 10,922 | 20 | 21,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
Submitted Solution:
```
cases = int(input())
def ternaryXOR( value):
value = [x for x in value]
a = []
b = []
for x in value:
if x == "2":
a.append("1")
b.append("1")
elif x == "1":
if int("".join(a)) < int("".join(b)):
a.append("0")
b.append("1")
else:
a.append("1")
b.append("0")
else:
a.append("0")
b.append("0")
return "".join(a), "".join(b)
for _ in range(cases):
input()
value = input()
a, b = ternaryXOR(value)
print(a)
print(b)
``` | instruction | 0 | 10,923 | 20 | 21,846 |
No | output | 1 | 10,923 | 20 | 21,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.
You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can be 0, 1 or 2.
Let's define the ternary XOR operation β of two ternary numbers a and b (both of length n) as a number c = a β b of length n, where c_i = (a_i + b_i) \% 3 (where \% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 3. For example, 10222 β 11021 = 21210.
Your task is to find such ternary numbers a and b both of length n and both without leading zeros that a β b = x and max(a, b) is the minimum possible.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow. The first line of the test case contains one integer n (1 β€ n β€ 5 β
10^4) β the length of x. The second line of the test case contains ternary number x consisting of n digits 0, 1 or 2. It is guaranteed that the first digit of x is 2. It is guaranteed that the sum of n over all test cases does not exceed 5 β
10^4 (β n β€ 5 β
10^4).
Output
For each test case, print the answer β two ternary integers a and b both of length n and both without leading zeros such that a β b = x and max(a, b) is the minimum possible. If there are several answers, you can print any.
Example
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
Submitted Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
x = list(map(int, list(input())))
a = [1]
b = [1]
for i in range(1, n):
if x[i] == 2:
a.append(1)
b.append(1)
elif x[i] == 1:
a.append(1)
b.append(0)
else:
a.append(0)
b.append(0)
print("".join(map(str, a)))
print("".join(map(str, b)))
``` | instruction | 0 | 10,924 | 20 | 21,848 |
No | output | 1 | 10,924 | 20 | 21,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to give Masha such collection of numbers for which the following conditions fulfill:
* Let's introduce x1 to denote the xor of all numbers Petya has got left; and let's introduce x2 to denote the xor of all numbers he gave to Masha. Value (x1 + x2) must be as large as possible.
* If there are multiple ways to divide the collection so that the previous condition fulfilled, then Petya minimizes the value x1.
The xor operation is a bitwise excluding "OR", that is denoted as "xor" in the Pascal language and "^" in C/C++/Java.
Help Petya divide the collection as described above. If there are multiple suitable ways to divide it, find any of them. Please note that after Petya gives a part of his numbers to Masha, he may have no numbers left. The reverse situation is also possible, when Petya gives nothing to Masha. In both cases we must assume that the xor of an empty set of numbers equals 0.
Input
The first line contains integer n (1 β€ n β€ 105), showing how many numbers Petya's mother gave him. The second line contains the actual space-separated numbers. They are all integer, non-negative and do not exceed 1018.
Output
Print n space-separated integers, the i-th of them should equal either 1, if Petya keeps the number that follows i-th in his collection, or it should equal 2, if Petya gives the corresponding number to Masha. The numbers are indexed in the order in which they are given in the input.
Examples
Input
6
1 2 3 4 5 6
Output
2 2 2 2 2 2
Input
3
1000000000000 1000000000000 1000000000000
Output
2 2 2
Input
8
1 1 2 2 3 3 4 4
Output
1 2 1 2 2 2 1 2 | instruction | 0 | 11,067 | 20 | 22,134 |
Tags: bitmasks, math
Correct Solution:
```
base = [-1] * 60
how = [-1] * 60
who = [-1] * 60
n = int(input())
arr = list(map(int, input().split()))
x = 0
for a in arr:
x ^= a
mapper = [-1] * 60
ind = 59
ind_start = bin(x).count('1') - 1
for bit in reversed(range(60)):
if (1 << bit) & x :
mapper[bit] = ind_start
ind_start -= 1
else:
mapper[bit] = ind
ind -= 1
for i in range(len(arr)):
temp = 0
for bit in range(60):
if (1 << bit) & arr[i]:
temp ^= (1 << mapper[bit])
arr[i] = temp
for i in range(n):
x = arr[i]
temp_how = 0
while x > 0:
b = x.bit_length() - 1
if who[b]!= -1:
temp_how ^= how[b]
x = x ^ base[b]
else:
who[b] = i
base[b] = x
how[b] = temp_how | (1 << b)
break
x = 0
temp = 0
for bit in reversed(range(60)):
if (x & (1 << bit) ) == 0 and who[bit] != -1:
x ^= base[bit]
temp ^= how[bit]
#print(base)
#print(how)
#print(who)
result = [1] * n
for j in range(60):
if temp & (1 << j):
result[who[j]] = 2
print(*result)
``` | output | 1 | 11,067 | 20 | 22,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to give Masha such collection of numbers for which the following conditions fulfill:
* Let's introduce x1 to denote the xor of all numbers Petya has got left; and let's introduce x2 to denote the xor of all numbers he gave to Masha. Value (x1 + x2) must be as large as possible.
* If there are multiple ways to divide the collection so that the previous condition fulfilled, then Petya minimizes the value x1.
The xor operation is a bitwise excluding "OR", that is denoted as "xor" in the Pascal language and "^" in C/C++/Java.
Help Petya divide the collection as described above. If there are multiple suitable ways to divide it, find any of them. Please note that after Petya gives a part of his numbers to Masha, he may have no numbers left. The reverse situation is also possible, when Petya gives nothing to Masha. In both cases we must assume that the xor of an empty set of numbers equals 0.
Input
The first line contains integer n (1 β€ n β€ 105), showing how many numbers Petya's mother gave him. The second line contains the actual space-separated numbers. They are all integer, non-negative and do not exceed 1018.
Output
Print n space-separated integers, the i-th of them should equal either 1, if Petya keeps the number that follows i-th in his collection, or it should equal 2, if Petya gives the corresponding number to Masha. The numbers are indexed in the order in which they are given in the input.
Examples
Input
6
1 2 3 4 5 6
Output
2 2 2 2 2 2
Input
3
1000000000000 1000000000000 1000000000000
Output
2 2 2
Input
8
1 1 2 2 3 3 4 4
Output
1 2 1 2 2 2 1 2
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
arr[i] = (arr[i], i)
basis = []
who_give = [0] * 60
done = 0
for bit in reversed(range(60)):
if len(arr) == 0:
break
m = max(arr)
if m[0].bit_length() - 1 != bit:
continue
for x in range(bit+1):
if 1 << x & m[0]:
who_give[x] = m[1]
arr.remove(m)
basis.append(m)
for i in range(len(arr)):
if m[0].bit_length() == arr[i][0].bit_length():
arr[i] = (arr[i][0] ^ m[0], arr[i][1])
result = [1] * n
selected = 0
chosen = {}
for bit in reversed(range(60)):
if (1 << bit) & selected:
continue
m = (0, -1)
for b in basis:
if b[1] in chosen:
continue
if b[0].bit_length() - 1 == bit:
m = max(m, b)
if m[1] == -1:
continue
selected = selected ^ m[0]
chosen[m[1]] = 1
for bit in reversed(range(60)):
if (1 << bit) & selected:
result[who_give[bit]] = 2
print(*result)
``` | instruction | 0 | 11,068 | 20 | 22,136 |
No | output | 1 | 11,068 | 20 | 22,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to give Masha such collection of numbers for which the following conditions fulfill:
* Let's introduce x1 to denote the xor of all numbers Petya has got left; and let's introduce x2 to denote the xor of all numbers he gave to Masha. Value (x1 + x2) must be as large as possible.
* If there are multiple ways to divide the collection so that the previous condition fulfilled, then Petya minimizes the value x1.
The xor operation is a bitwise excluding "OR", that is denoted as "xor" in the Pascal language and "^" in C/C++/Java.
Help Petya divide the collection as described above. If there are multiple suitable ways to divide it, find any of them. Please note that after Petya gives a part of his numbers to Masha, he may have no numbers left. The reverse situation is also possible, when Petya gives nothing to Masha. In both cases we must assume that the xor of an empty set of numbers equals 0.
Input
The first line contains integer n (1 β€ n β€ 105), showing how many numbers Petya's mother gave him. The second line contains the actual space-separated numbers. They are all integer, non-negative and do not exceed 1018.
Output
Print n space-separated integers, the i-th of them should equal either 1, if Petya keeps the number that follows i-th in his collection, or it should equal 2, if Petya gives the corresponding number to Masha. The numbers are indexed in the order in which they are given in the input.
Examples
Input
6
1 2 3 4 5 6
Output
2 2 2 2 2 2
Input
3
1000000000000 1000000000000 1000000000000
Output
2 2 2
Input
8
1 1 2 2 3 3 4 4
Output
1 2 1 2 2 2 1 2
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
arr[i] = (arr[i], i)
basis = []
who_give = [-1] * 60
done = 0
for bit in reversed(range(60)):
if who_give[bit] != -1:
continue
if len(arr) == 0:
break
m = max(arr)
if m[0].bit_length() - 1 != bit:
continue
for x in range(bit+1):
if 1 << x & m[0]:
who_give[x] = m[1]
arr.remove(m)
basis.append(m)
for i in range(len(arr)):
if m[0].bit_length() == arr[i][0].bit_length():
arr[i] = (arr[i][0] ^ m[0], arr[i][1])
result = [1] * n
selected = 0
chosen = {}
for bit in reversed(range(60)):
if (1 << bit) & selected:
continue
m = (0, -1)
for b in basis:
if b[1] in chosen:
continue
if b[0].bit_length() - 1 == bit:
m = max(m, b)
if m[1] == -1:
continue
selected = selected ^ m[0]
chosen[m[1]] = 1
for bit in reversed(range(60)):
if (1 << bit) & selected:
result[who_give[bit]] = 2
print(*result)
``` | instruction | 0 | 11,069 | 20 | 22,138 |
No | output | 1 | 11,069 | 20 | 22,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to give Masha such collection of numbers for which the following conditions fulfill:
* Let's introduce x1 to denote the xor of all numbers Petya has got left; and let's introduce x2 to denote the xor of all numbers he gave to Masha. Value (x1 + x2) must be as large as possible.
* If there are multiple ways to divide the collection so that the previous condition fulfilled, then Petya minimizes the value x1.
The xor operation is a bitwise excluding "OR", that is denoted as "xor" in the Pascal language and "^" in C/C++/Java.
Help Petya divide the collection as described above. If there are multiple suitable ways to divide it, find any of them. Please note that after Petya gives a part of his numbers to Masha, he may have no numbers left. The reverse situation is also possible, when Petya gives nothing to Masha. In both cases we must assume that the xor of an empty set of numbers equals 0.
Input
The first line contains integer n (1 β€ n β€ 105), showing how many numbers Petya's mother gave him. The second line contains the actual space-separated numbers. They are all integer, non-negative and do not exceed 1018.
Output
Print n space-separated integers, the i-th of them should equal either 1, if Petya keeps the number that follows i-th in his collection, or it should equal 2, if Petya gives the corresponding number to Masha. The numbers are indexed in the order in which they are given in the input.
Examples
Input
6
1 2 3 4 5 6
Output
2 2 2 2 2 2
Input
3
1000000000000 1000000000000 1000000000000
Output
2 2 2
Input
8
1 1 2 2 3 3 4 4
Output
1 2 1 2 2 2 1 2
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
for i in range(n):
arr[i] = (arr[i], i)
basis = []
for bit in reversed(range(60)):
m = max(arr)
if m[0].bit_length() - 1 != bit:
continue
arr.remove(m)
basis.append(m)
for i in range(len(arr)):
if m[0].bit_length() == arr[i][0].bit_length():
arr[i] = (arr[i][0] ^ m[0], arr[i][1])
result = [1] * n
selected = 0
chosen = {}
for bit in reversed(range(60)):
if (1 << bit) & selected:
continue
m = (0, -1)
for b in basis:
if b[1] in chosen:
continue
if (b[0] & (1 << bit)):
m = max(m, b)
if m[1] == -1:
continue
selected = selected ^ m[0]
chosen[m[1]] = 1
result[m[1]] = 2
print(*result)
``` | instruction | 0 | 11,070 | 20 | 22,140 |
No | output | 1 | 11,070 | 20 | 22,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to give Masha such collection of numbers for which the following conditions fulfill:
* Let's introduce x1 to denote the xor of all numbers Petya has got left; and let's introduce x2 to denote the xor of all numbers he gave to Masha. Value (x1 + x2) must be as large as possible.
* If there are multiple ways to divide the collection so that the previous condition fulfilled, then Petya minimizes the value x1.
The xor operation is a bitwise excluding "OR", that is denoted as "xor" in the Pascal language and "^" in C/C++/Java.
Help Petya divide the collection as described above. If there are multiple suitable ways to divide it, find any of them. Please note that after Petya gives a part of his numbers to Masha, he may have no numbers left. The reverse situation is also possible, when Petya gives nothing to Masha. In both cases we must assume that the xor of an empty set of numbers equals 0.
Input
The first line contains integer n (1 β€ n β€ 105), showing how many numbers Petya's mother gave him. The second line contains the actual space-separated numbers. They are all integer, non-negative and do not exceed 1018.
Output
Print n space-separated integers, the i-th of them should equal either 1, if Petya keeps the number that follows i-th in his collection, or it should equal 2, if Petya gives the corresponding number to Masha. The numbers are indexed in the order in which they are given in the input.
Examples
Input
6
1 2 3 4 5 6
Output
2 2 2 2 2 2
Input
3
1000000000000 1000000000000 1000000000000
Output
2 2 2
Input
8
1 1 2 2 3 3 4 4
Output
1 2 1 2 2 2 1 2
Submitted Solution:
```
n = int(input())
arr = list(map(int, input().split()))
basis = []
who_give = [-1] * 60
done = 0
for i in range(n):
b = 0
while arr[i]:
bit = arr[i].bit_length() - 1
if 1 << bit & done:
arr[i] ^= 1 << bit
else:
b ^= 1 << bit
who_give[bit] = i
done ^= 1 << bit
arr[i] ^= 1 << bit
if b:
basis.append(b)
result = [1] * n
selected = 0
chosen = {}
for x in basis:
selected ^= x
for bit in reversed(range(60)):
if (1 << bit) & selected:
result[who_give[bit]] = 2
print(*result)
``` | instruction | 0 | 11,071 | 20 | 22,142 |
No | output | 1 | 11,071 | 20 | 22,143 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input
The first line of input contains a single integer N (1 β€ N β€ 16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].
Output
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.
Examples
Input
1
2
0
Output
0.500000
Input
2
2 3
1 0
Output
0.666667 | instruction | 0 | 11,223 | 20 | 22,446 |
Tags: *special, implementation
Correct Solution:
```
n = int(input())
m = list(map(int, input().split()))
r = list(map(int, input().split()))
k = 0
for i in range(100000):
for j in range(n):
if i % m[j] == r[j]:
k += 1
break
print(k / 100000)
``` | output | 1 | 11,223 | 20 | 22,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input
The first line of input contains a single integer N (1 β€ N β€ 16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].
Output
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.
Examples
Input
1
2
0
Output
0.500000
Input
2
2 3
1 0
Output
0.666667 | instruction | 0 | 11,224 | 20 | 22,448 |
Tags: *special, implementation
Correct Solution:
```
n = int(input())
M = [int(s) for s in input().split()]
R = [int(s) for s in input().split()]
c = 0
for i in range(100000):
bool = False
for j in range(n):
if i % M[j] == R[j]:
bool = True
break
if bool:
c += 1
print(c/100000)
``` | output | 1 | 11,224 | 20 | 22,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input
The first line of input contains a single integer N (1 β€ N β€ 16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].
Output
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.
Examples
Input
1
2
0
Output
0.500000
Input
2
2 3
1 0
Output
0.666667 | instruction | 0 | 11,226 | 20 | 22,452 |
Tags: *special, implementation
Correct Solution:
```
import fractions
from functools import reduce
N = int(input())
M = list(map(int, input().split(' ')))
R = list(map(int, input().split(' ')))
def gcd(*numbers):
return reduce(fractions.gcd, numbers)
def lcm(*numbers):
def _lcm(a, b):
return (a * b) // gcd(a, b)
return reduce(_lcm, numbers, 1)
lcm_M = lcm(*M)
a = [
any(d % M[i] == R[i] for i in range(N))
for d in range(lcm_M)
]
print(a.count(True) / len(a))
``` | output | 1 | 11,226 | 20 | 22,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input
The first line of input contains a single integer N (1 β€ N β€ 16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].
Output
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.
Examples
Input
1
2
0
Output
0.500000
Input
2
2 3
1 0
Output
0.666667 | instruction | 0 | 11,227 | 20 | 22,454 |
Tags: *special, implementation
Correct Solution:
```
a = int(input())
d = 34209
p = 0
m = list(map(int,input().split()))
r = list(map(int,input().split()))
for i in range(34209):
for j in range(a):
if i%m[j] == r[j]:
##print(d,m[j],p,d%m[j])
p += 1
break
##print(p,d)
s = round(p/d, 4)
print(s)
``` | output | 1 | 11,227 | 20 | 22,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input
The first line of input contains a single integer N (1 β€ N β€ 16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].
Output
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.
Examples
Input
1
2
0
Output
0.500000
Input
2
2 3
1 0
Output
0.666667 | instruction | 0 | 11,228 | 20 | 22,456 |
Tags: *special, implementation
Correct Solution:
```
input()
f=lambda:list(map(int,input().split()))
T,l=720720,list(zip(f(),f()))
print(sum(any(d%m==r for m,r in l) for d in range(T))/T)
``` | output | 1 | 11,228 | 20 | 22,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input
The first line of input contains a single integer N (1 β€ N β€ 16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].
Output
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.
Examples
Input
1
2
0
Output
0.500000
Input
2
2 3
1 0
Output
0.666667 | instruction | 0 | 11,229 | 20 | 22,458 |
Tags: *special, implementation
Correct Solution:
```
#!/usr/bin/env python3
n = int(input())
m = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]
counter = 0
num = 50000
for d in range(num):
for i in range(n):
if d % m[i] == r[i]:
counter += 1
break
frac = counter/num
print(frac)
``` | output | 1 | 11,229 | 20 | 22,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input
The first line of input contains a single integer N (1 β€ N β€ 16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].
Output
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.
Examples
Input
1
2
0
Output
0.500000
Input
2
2 3
1 0
Output
0.666667 | instruction | 0 | 11,230 | 20 | 22,460 |
Tags: *special, implementation
Correct Solution:
```
n = int(input())
m = [int(i) for i in input().split(" ")]
r = [int(i) for i in input().split(" ")]
L = 720720
ans = 0
for i in range(L):
for j, k in zip(m, r):
if i % j == k:
ans += 1
break
print(ans/L)
``` | output | 1 | 11,230 | 20 | 22,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shakespeare is a widely known esoteric programming language in which programs look like plays by Shakespeare, and numbers are given by combinations of ornate epithets. In this problem we will have a closer look at the way the numbers are described in Shakespeare.
Each constant in Shakespeare is created from non-negative powers of 2 using arithmetic operations. For simplicity we'll allow only addition and subtraction and will look for a representation of the given number which requires a minimal number of operations.
You are given an integer n. You have to represent it as n = a1 + a2 + ... + am, where each of ai is a non-negative power of 2, possibly multiplied by -1. Find a representation which minimizes the value of m.
Input
The only line of input contains a positive integer n, written as its binary notation. The length of the notation is at most 106. The first digit of the notation is guaranteed to be 1.
Output
Output the required minimal m. After it output m lines. Each line has to be formatted as "+2^x" or "-2^x", where x is the power coefficient of the corresponding term. The order of the lines doesn't matter.
Examples
Input
1111
Output
2
+2^4
-2^0
Input
1010011
Output
4
+2^0
+2^1
+2^4
+2^6
Submitted Solution:
```
def evaluate(counter , current_pos , size , pow_p , pow_n):
if counter == 1:
pow_p += [size - current_pos - 1]
else:
pow_p += [ size - current_pos ]
pow_n += [ size - current_pos - counter ]
if __name__ == "__main__":
cadena_entrada = input()
pow_pos = []
pow_neg = []
contador = 0
n = len(cadena_entrada) - 1
for i in range(n , -1 , -1):
if cadena_entrada[i] == "1":
contador +=1
else:
if contador>0:
evaluate(contador , i , n, pow_pos , pow_neg)
contador = 0
if contador != 0:
evaluate(contador , 0 ,n+1 , pow_pos , pow_neg)
for i in pow_pos:
print("+2^%d" % (i))
for i in pow_neg:
print("-2^%d"%(i))
``` | instruction | 0 | 11,762 | 20 | 23,524 |
No | output | 1 | 11,762 | 20 | 23,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Shakespeare is a widely known esoteric programming language in which programs look like plays by Shakespeare, and numbers are given by combinations of ornate epithets. In this problem we will have a closer look at the way the numbers are described in Shakespeare.
Each constant in Shakespeare is created from non-negative powers of 2 using arithmetic operations. For simplicity we'll allow only addition and subtraction and will look for a representation of the given number which requires a minimal number of operations.
You are given an integer n. You have to represent it as n = a1 + a2 + ... + am, where each of ai is a non-negative power of 2, possibly multiplied by -1. Find a representation which minimizes the value of m.
Input
The only line of input contains a positive integer n, written as its binary notation. The length of the notation is at most 106. The first digit of the notation is guaranteed to be 1.
Output
Output the required minimal m. After it output m lines. Each line has to be formatted as "+2^x" or "-2^x", where x is the power coefficient of the corresponding term. The order of the lines doesn't matter.
Examples
Input
1111
Output
2
+2^4
-2^0
Input
1010011
Output
4
+2^0
+2^1
+2^4
+2^6
Submitted Solution:
```
def evaluate(counter , current_pos , size , pow_p , pow_n):
if counter == 1:
pow_p += [size - current_pos - 1]
else:
pow_p += [ size - current_pos ]
pow_n += [ size - current_pos - counter ]
if __name__ == "__main__":
cadena_entrada = input()
pow_pos = []
pow_neg = []
contador = 0
n = len(cadena_entrada) - 1
for i in range(n , -1 , -1):
if cadena_entrada[i] == "1":
contador +=1
else:
if contador>0:
evaluate(contador , i , n, pow_pos , pow_neg)
contador = 0
if contador != 0:
evaluate(contador , 0 ,n+1 , pow_pos , pow_neg)
print(len(pow_pos) + len(pow_neg))
for i in pow_pos:
print("+2^%d" % (i))
for i in pow_neg:
print("-2^%d"%(i))
``` | instruction | 0 | 11,763 | 20 | 23,526 |
No | output | 1 | 11,763 | 20 | 23,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step.
Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.
Input
The input contains the only integer n (1 β€ n β€ 106).
Output
Print the only integer k.
Examples
Input
5
Output
3
Input
1
Output
0
Note
The pair (1,1) can be transformed into a pair containing 5 in three moves: (1,1) β (1,2) β (3,2) β (5,2). | instruction | 0 | 11,766 | 20 | 23,532 |
Tags: brute force, dfs and similar, math, number theory
Correct Solution:
```
import sys
def solve():
n = int(input())
if n == 1: return 0
res = 1000000
for other in range(n - 1, 0, -1):
pair = [n, other]
temp = 0
while (pair[0] > 1 or pair[1] > 1) and (pair[0] > 0 and pair[1] > 0):
if pair[0] > pair[1]: pair[0], pair[1] = pair[1], pair[0]
pair[1] -= pair[0]
temp+=1
if temp > res: break
if pair[0] == 1 and pair[1] == 1: res = min(res, temp)
return res
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
print(solve())
``` | output | 1 | 11,766 | 20 | 23,533 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step.
Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.
Input
The input contains the only integer n (1 β€ n β€ 106).
Output
Print the only integer k.
Examples
Input
5
Output
3
Input
1
Output
0
Note
The pair (1,1) can be transformed into a pair containing 5 in three moves: (1,1) β (1,2) β (3,2) β (5,2). | instruction | 0 | 11,767 | 20 | 23,534 |
Tags: brute force, dfs and similar, math, number theory
Correct Solution:
```
import sys
def solve():
n = int(input())
if n == 1: return 0
res = 1000000
for other in range(1, n):
pair = [n, other]
temp = 0
while (pair[0] > 1 or pair[1] > 1) and (pair[0] > 0 and pair[1] > 0):
if pair[0] > pair[1]: pair[0], pair[1] = pair[1], pair[0]
pair[1] -= pair[0]
temp+=1
if temp > res: break
if pair[0] == 1 and pair[1] == 1: res = min(res, temp)
return res
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
print(solve())
``` | output | 1 | 11,767 | 20 | 23,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1 | instruction | 0 | 12,076 | 20 | 24,152 |
Tags: math, number theory
Correct Solution:
```
import sys
import math
# sys.stdin = open('input.txt')
# sys.stdout = open('output.txt', 'w')
def main():
n = int(input())
a = n // 2
b = n // 3
c = n // 5
d = n // 7
ab = n // 6
ac = n // 10
ad = n // 14
bc = n // 15
bd = n // 21
cd = n // 35
abc = n // 30
abd = n // 42
acd = n // 70
bcd = n // 105
abcd = n // 210
v = a + b + c + d - ab - ac - ad - bc - bd - cd + abc + abd + acd + bcd - abcd
print(n - v)
main()
``` | output | 1 | 12,076 | 20 | 24,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1 | instruction | 0 | 12,077 | 20 | 24,154 |
Tags: math, number theory
Correct Solution:
```
n = int(input())
s = 0
for i in range(16):
d = 1
for j, k in ((1, 2), (2, 3), (4, 5), (8, 7)):
if i & j: d *= -k
if d > 0: s += n // d
else: s -= n // -d
print(s)
``` | output | 1 | 12,077 | 20 | 24,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1 | instruction | 0 | 12,078 | 20 | 24,156 |
Tags: math, number theory
Correct Solution:
```
from sys import stdin,stdout
from math import gcd, ceil, sqrt,factorial as f
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n = ii1()
div = 8 * 5 * 9 * 7
print(n//div)
``` | output | 1 | 12,078 | 20 | 24,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1 | instruction | 0 | 12,079 | 20 | 24,158 |
Tags: math, number theory
Correct Solution:
```
n = int(input())
a=(n//2+n//3+n//5+n//7-n//6-n//10-n//14-n//15-n//21-n//35+n//30+n//42+n//70+n//105-n//210)
print(n-a)
``` | output | 1 | 12,079 | 20 | 24,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1 | instruction | 0 | 12,080 | 20 | 24,160 |
Tags: math, number theory
Correct Solution:
```
n = int(input())
f = lambda x: n // x
a1 = f(2) + f(3) + f(5) + f(7)
a2 = f(6) + f(10) + f(14) + f(15) + f(21) + f(35)
a3 = f(30) + f(42) + f(70) + f(105)
a4 = f(210)
ans = n - (a1 - a2 + a3 - a4)
print(ans)
``` | output | 1 | 12,080 | 20 | 24,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1 | instruction | 0 | 12,081 | 20 | 24,162 |
Tags: math, number theory
Correct Solution:
```
n=int(input())
a=1
for i in {8,9,5,7}:
a*=i
#print(a)
print(n//a)
``` | output | 1 | 12,081 | 20 | 24,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1 | instruction | 0 | 12,082 | 20 | 24,164 |
Tags: math, number theory
Correct Solution:
```
x = int(input())
#x, y = map(int, input().split())
y = x//210*48
for i in range(1, x%210 + 1):
if i%2 and i%3 and i%5 and i%7:
y+=1
print(y)
``` | output | 1 | 12,082 | 20 | 24,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that n people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it.
Input
The only line of the input contains one integer n (1 β€ n β€ 1018) β the prediction on the number of people who will buy the game.
Output
Output one integer showing how many numbers from 1 to n are divisible by all numbers from 2 to 10.
Examples
Input
3000
Output
1 | instruction | 0 | 12,083 | 20 | 24,166 |
Tags: math, number theory
Correct Solution:
```
n = int(input())
print(n//(2*3*5*2*7*2*3))
``` | output | 1 | 12,083 | 20 | 24,167 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.