message stringlengths 2 59.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.
Input
In the only line given a non-empty binary string s with length up to 100.
Output
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
Examples
Input
100010001
Output
yes
Input
100
Output
no
Note
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: <https://en.wikipedia.org/wiki/Binary_system>
Submitted Solution:
```
b=list(input())
b=list(map(int,b))
for i in range(len(b)):
if i==1:
if b[i:].count(0)>5:
print("yes")
exit()
else:
print("no")
exit()
print("no")
``` | instruction | 0 | 39,306 | 20 | 78,612 |
No | output | 1 | 39,306 | 20 | 78,613 |
Provide a correct Python 3 solution for this coding contest problem.
Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).
<image>
To translate this format into a decimal representation that is easy for humans to understand, interpret it as follows.
(-1) Sign part × (integer part + decimal part)
In the above expression, the value of the integer part is b8 + 21 x b9 + 22 x b10 + ... + 223 x b31. For example, the integer part is
<image>
If it looks like, the value of the integer part is calculated as follows.
1 + 21 + 23 = 1 + 2 + 8 = 11
On the other hand, the value of the decimal part is (0.5) 1 × b7 + (0.5) 2 × b6 + ... + (0.5) 7 × b1. For example, the decimal part
<image>
If it looks like, the decimal part is calculated as follows.
0.51 + 0.53 = 0.5 + 0.125 = 0.625
Furthermore, in the case of the following bit string that combines the sign part, the integer part, and the decimal part,
<image>
The decimal number represented by the entire bit string is as follows (where -1 to the 0th power is 1).
(-1) 0 × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625
If you enter Q 32-bit bit strings, create a program that outputs the real decimal notation represented by those bit strings without any error.
input
The input consists of one dataset. Input data is given in the following format.
Q
s1
s2
..
..
..
sQ
The number of bit strings Q (1 ≤ Q ≤ 10000) is given in the first row. The input bit string si is given in the following Q row. Suppose the input bit string is given in hexadecimal notation (for example, 0111 1111 1000 1000 0000 0000 0000 0000 is given as 7f880000). In other words, each of the Q lines contains eight hexadecimal numbers, which are 4-bit binary numbers, without any blanks. The table below shows the correspondence between decimal numbers, binary numbers, and hexadecimal numbers.
<image>
Hexadecimal letters a through f are given in lowercase.
output
Outputs the real decimal notation represented by each bit string line by line. However, in the decimal part, if all the digits after a certain digit are 0, the digits after that digit are omitted. As an exception, if the decimal part is 0, one 0 is output to the decimal part.
Example
Input
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
Output
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875 | instruction | 0 | 39,536 | 20 | 79,072 |
"Correct Solution:
```
q = int(input())
for _ in range (q):
bits = F'{int(input(), 16):32b}'
sign = '-' if bits[0] == '1' else ''
integer = sum([2**i for i, b in enumerate(bits[1:25][::-1]) if b == '1'])
fraction = sum([0.5**i for i, b in enumerate(bits[25:], start=1) if b == '1'])
print(sign + str(float(integer + fraction)))
``` | output | 1 | 39,536 | 20 | 79,073 |
Provide a correct Python 3 solution for this coding contest problem.
Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).
<image>
To translate this format into a decimal representation that is easy for humans to understand, interpret it as follows.
(-1) Sign part × (integer part + decimal part)
In the above expression, the value of the integer part is b8 + 21 x b9 + 22 x b10 + ... + 223 x b31. For example, the integer part is
<image>
If it looks like, the value of the integer part is calculated as follows.
1 + 21 + 23 = 1 + 2 + 8 = 11
On the other hand, the value of the decimal part is (0.5) 1 × b7 + (0.5) 2 × b6 + ... + (0.5) 7 × b1. For example, the decimal part
<image>
If it looks like, the decimal part is calculated as follows.
0.51 + 0.53 = 0.5 + 0.125 = 0.625
Furthermore, in the case of the following bit string that combines the sign part, the integer part, and the decimal part,
<image>
The decimal number represented by the entire bit string is as follows (where -1 to the 0th power is 1).
(-1) 0 × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625
If you enter Q 32-bit bit strings, create a program that outputs the real decimal notation represented by those bit strings without any error.
input
The input consists of one dataset. Input data is given in the following format.
Q
s1
s2
..
..
..
sQ
The number of bit strings Q (1 ≤ Q ≤ 10000) is given in the first row. The input bit string si is given in the following Q row. Suppose the input bit string is given in hexadecimal notation (for example, 0111 1111 1000 1000 0000 0000 0000 0000 is given as 7f880000). In other words, each of the Q lines contains eight hexadecimal numbers, which are 4-bit binary numbers, without any blanks. The table below shows the correspondence between decimal numbers, binary numbers, and hexadecimal numbers.
<image>
Hexadecimal letters a through f are given in lowercase.
output
Outputs the real decimal notation represented by each bit string line by line. However, in the decimal part, if all the digits after a certain digit are 0, the digits after that digit are omitted. As an exception, if the decimal part is 0, one 0 is output to the decimal part.
Example
Input
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
Output
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875 | instruction | 0 | 39,537 | 20 | 79,074 |
"Correct Solution:
```
BIN = [0] * 32
v = 1
for i in range(24, 0, -1):
BIN[i] = v
v *= 2
v = float(1) / 2
for i in range(25, 32):
BIN[i] = v
v /= 2
Q = int(input())
for i in range(Q):
inp = format(int(input(),16),'b').zfill(32)
res = float(0)
for j, v in enumerate(list(inp)[1:]):
#print(str(BIN[j]) + ' ' + v + ' ' + str(float(v) * BIN[j]))
res += BIN[j+1] * int(v)
print(('-' if inp[0] == '1' else '') + str(res))
``` | output | 1 | 39,537 | 20 | 79,075 |
Provide a correct Python 3 solution for this coding contest problem.
Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).
<image>
To translate this format into a decimal representation that is easy for humans to understand, interpret it as follows.
(-1) Sign part × (integer part + decimal part)
In the above expression, the value of the integer part is b8 + 21 x b9 + 22 x b10 + ... + 223 x b31. For example, the integer part is
<image>
If it looks like, the value of the integer part is calculated as follows.
1 + 21 + 23 = 1 + 2 + 8 = 11
On the other hand, the value of the decimal part is (0.5) 1 × b7 + (0.5) 2 × b6 + ... + (0.5) 7 × b1. For example, the decimal part
<image>
If it looks like, the decimal part is calculated as follows.
0.51 + 0.53 = 0.5 + 0.125 = 0.625
Furthermore, in the case of the following bit string that combines the sign part, the integer part, and the decimal part,
<image>
The decimal number represented by the entire bit string is as follows (where -1 to the 0th power is 1).
(-1) 0 × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625
If you enter Q 32-bit bit strings, create a program that outputs the real decimal notation represented by those bit strings without any error.
input
The input consists of one dataset. Input data is given in the following format.
Q
s1
s2
..
..
..
sQ
The number of bit strings Q (1 ≤ Q ≤ 10000) is given in the first row. The input bit string si is given in the following Q row. Suppose the input bit string is given in hexadecimal notation (for example, 0111 1111 1000 1000 0000 0000 0000 0000 is given as 7f880000). In other words, each of the Q lines contains eight hexadecimal numbers, which are 4-bit binary numbers, without any blanks. The table below shows the correspondence between decimal numbers, binary numbers, and hexadecimal numbers.
<image>
Hexadecimal letters a through f are given in lowercase.
output
Outputs the real decimal notation represented by each bit string line by line. However, in the decimal part, if all the digits after a certain digit are 0, the digits after that digit are omitted. As an exception, if the decimal part is 0, one 0 is output to the decimal part.
Example
Input
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
Output
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875 | instruction | 0 | 39,538 | 20 | 79,076 |
"Correct Solution:
```
hex_to_dig = {"0":"0000", "1":"0001", "2":"0010", "3":"0011",
"4":"0100", "5":"0101", "6":"0110", "7":"0111",
"8":"1000", "9":"1001", "a":"1010", "b":"1011",
"c":"1100", "d":"1101", "e":"1110", "f":"1111"}
def dig_to_dec(digit):
tf = digit[0]
x = digit[1:25][::-1]
y = digit[25:32]
sumx = 0
acc = 1
for i, c in enumerate(x):
if c == "1":
sumx += acc
acc *= 2
sumy = 0
acc = 0.5
for i, c in enumerate(y):
if c == "1":
sumy += acc
acc /= 2
tf = "-" if int(tf) == 1 else ""
if sumy == 0:
print(tf + str(sumx) + "." + "0")
else:
print(tf + str(sumx + sumy))
n = int(input())
for _ in range(n):
h = input()
d = ""
for c in h:
d += hex_to_dig[c]
dig_to_dec(d)
``` | output | 1 | 39,538 | 20 | 79,077 |
Provide a correct Python 3 solution for this coding contest problem.
Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).
<image>
To translate this format into a decimal representation that is easy for humans to understand, interpret it as follows.
(-1) Sign part × (integer part + decimal part)
In the above expression, the value of the integer part is b8 + 21 x b9 + 22 x b10 + ... + 223 x b31. For example, the integer part is
<image>
If it looks like, the value of the integer part is calculated as follows.
1 + 21 + 23 = 1 + 2 + 8 = 11
On the other hand, the value of the decimal part is (0.5) 1 × b7 + (0.5) 2 × b6 + ... + (0.5) 7 × b1. For example, the decimal part
<image>
If it looks like, the decimal part is calculated as follows.
0.51 + 0.53 = 0.5 + 0.125 = 0.625
Furthermore, in the case of the following bit string that combines the sign part, the integer part, and the decimal part,
<image>
The decimal number represented by the entire bit string is as follows (where -1 to the 0th power is 1).
(-1) 0 × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625
If you enter Q 32-bit bit strings, create a program that outputs the real decimal notation represented by those bit strings without any error.
input
The input consists of one dataset. Input data is given in the following format.
Q
s1
s2
..
..
..
sQ
The number of bit strings Q (1 ≤ Q ≤ 10000) is given in the first row. The input bit string si is given in the following Q row. Suppose the input bit string is given in hexadecimal notation (for example, 0111 1111 1000 1000 0000 0000 0000 0000 is given as 7f880000). In other words, each of the Q lines contains eight hexadecimal numbers, which are 4-bit binary numbers, without any blanks. The table below shows the correspondence between decimal numbers, binary numbers, and hexadecimal numbers.
<image>
Hexadecimal letters a through f are given in lowercase.
output
Outputs the real decimal notation represented by each bit string line by line. However, in the decimal part, if all the digits after a certain digit are 0, the digits after that digit are omitted. As an exception, if the decimal part is 0, one 0 is output to the decimal part.
Example
Input
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
Output
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875 | instruction | 0 | 39,539 | 20 | 79,078 |
"Correct Solution:
```
N = int(input())
for i in range(N):
s = int(input(), 16)
ans = (s & ~(1 << 31)) >> 7
v = 0.5
for i in range(6, -1, -1):
if (s >> i) & 1:
ans += v
v /= 2
if s & (1 << 31):
t = "-%.10f" % ans
else:
t = "%.10f" % ans
i = len(t)
while t[i-1] == '0':
i -= 1
if t[i-1] == '.':
i += 1
print(t[:i])
``` | output | 1 | 39,539 | 20 | 79,079 |
Provide a correct Python 3 solution for this coding contest problem.
Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).
<image>
To translate this format into a decimal representation that is easy for humans to understand, interpret it as follows.
(-1) Sign part × (integer part + decimal part)
In the above expression, the value of the integer part is b8 + 21 x b9 + 22 x b10 + ... + 223 x b31. For example, the integer part is
<image>
If it looks like, the value of the integer part is calculated as follows.
1 + 21 + 23 = 1 + 2 + 8 = 11
On the other hand, the value of the decimal part is (0.5) 1 × b7 + (0.5) 2 × b6 + ... + (0.5) 7 × b1. For example, the decimal part
<image>
If it looks like, the decimal part is calculated as follows.
0.51 + 0.53 = 0.5 + 0.125 = 0.625
Furthermore, in the case of the following bit string that combines the sign part, the integer part, and the decimal part,
<image>
The decimal number represented by the entire bit string is as follows (where -1 to the 0th power is 1).
(-1) 0 × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625
If you enter Q 32-bit bit strings, create a program that outputs the real decimal notation represented by those bit strings without any error.
input
The input consists of one dataset. Input data is given in the following format.
Q
s1
s2
..
..
..
sQ
The number of bit strings Q (1 ≤ Q ≤ 10000) is given in the first row. The input bit string si is given in the following Q row. Suppose the input bit string is given in hexadecimal notation (for example, 0111 1111 1000 1000 0000 0000 0000 0000 is given as 7f880000). In other words, each of the Q lines contains eight hexadecimal numbers, which are 4-bit binary numbers, without any blanks. The table below shows the correspondence between decimal numbers, binary numbers, and hexadecimal numbers.
<image>
Hexadecimal letters a through f are given in lowercase.
output
Outputs the real decimal notation represented by each bit string line by line. However, in the decimal part, if all the digits after a certain digit are 0, the digits after that digit are omitted. As an exception, if the decimal part is 0, one 0 is output to the decimal part.
Example
Input
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
Output
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875 | instruction | 0 | 39,540 | 20 | 79,080 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Kongo Type
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0268
"""
import sys
def solve():
bits = f'{int(input(), 16):032b}'
sign = '-' if bits[0] == '1' else ''
integer = sum([2**i for i, b in enumerate(bits[1:25][::-1]) if b == '1'])
fraction = sum([0.5**i for i, b in enumerate(bits[25:], start=1) if b == '1'])
return sign + str(float(integer + fraction))
def main(args):
Q = int(input())
for _ in range(Q):
ans = solve()
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 39,540 | 20 | 79,081 |
Provide a correct Python 3 solution for this coding contest problem.
Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).
<image>
To translate this format into a decimal representation that is easy for humans to understand, interpret it as follows.
(-1) Sign part × (integer part + decimal part)
In the above expression, the value of the integer part is b8 + 21 x b9 + 22 x b10 + ... + 223 x b31. For example, the integer part is
<image>
If it looks like, the value of the integer part is calculated as follows.
1 + 21 + 23 = 1 + 2 + 8 = 11
On the other hand, the value of the decimal part is (0.5) 1 × b7 + (0.5) 2 × b6 + ... + (0.5) 7 × b1. For example, the decimal part
<image>
If it looks like, the decimal part is calculated as follows.
0.51 + 0.53 = 0.5 + 0.125 = 0.625
Furthermore, in the case of the following bit string that combines the sign part, the integer part, and the decimal part,
<image>
The decimal number represented by the entire bit string is as follows (where -1 to the 0th power is 1).
(-1) 0 × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625
If you enter Q 32-bit bit strings, create a program that outputs the real decimal notation represented by those bit strings without any error.
input
The input consists of one dataset. Input data is given in the following format.
Q
s1
s2
..
..
..
sQ
The number of bit strings Q (1 ≤ Q ≤ 10000) is given in the first row. The input bit string si is given in the following Q row. Suppose the input bit string is given in hexadecimal notation (for example, 0111 1111 1000 1000 0000 0000 0000 0000 is given as 7f880000). In other words, each of the Q lines contains eight hexadecimal numbers, which are 4-bit binary numbers, without any blanks. The table below shows the correspondence between decimal numbers, binary numbers, and hexadecimal numbers.
<image>
Hexadecimal letters a through f are given in lowercase.
output
Outputs the real decimal notation represented by each bit string line by line. However, in the decimal part, if all the digits after a certain digit are 0, the digits after that digit are omitted. As an exception, if the decimal part is 0, one 0 is output to the decimal part.
Example
Input
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
Output
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875 | instruction | 0 | 39,541 | 20 | 79,082 |
"Correct Solution:
```
N = int(input())
for i in range(N):
S = str(input())
bit = bin(int(S, 16))[2:].zfill(32)
bit = bit[::-1]
# print(bit)
pos = (-1)**int(bit[31])
up = int(bit[7:31][::-1], 2)
# print(bit[7:31],len(bit[7:31]), int(bit[7:31], 2))
# print(bit[:7],len(bit[:7]))
# print(up)
low = 0
pow = 0.5
for b in bit[:7][::-1]:
# print(pow*int(b))
low = low + pow*int(b)
# print(int(b))
pow *= 0.5
# print(low)
print(pos*(up+low))
``` | output | 1 | 39,541 | 20 | 79,083 |
Provide a correct Python 3 solution for this coding contest problem.
Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).
<image>
To translate this format into a decimal representation that is easy for humans to understand, interpret it as follows.
(-1) Sign part × (integer part + decimal part)
In the above expression, the value of the integer part is b8 + 21 x b9 + 22 x b10 + ... + 223 x b31. For example, the integer part is
<image>
If it looks like, the value of the integer part is calculated as follows.
1 + 21 + 23 = 1 + 2 + 8 = 11
On the other hand, the value of the decimal part is (0.5) 1 × b7 + (0.5) 2 × b6 + ... + (0.5) 7 × b1. For example, the decimal part
<image>
If it looks like, the decimal part is calculated as follows.
0.51 + 0.53 = 0.5 + 0.125 = 0.625
Furthermore, in the case of the following bit string that combines the sign part, the integer part, and the decimal part,
<image>
The decimal number represented by the entire bit string is as follows (where -1 to the 0th power is 1).
(-1) 0 × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625
If you enter Q 32-bit bit strings, create a program that outputs the real decimal notation represented by those bit strings without any error.
input
The input consists of one dataset. Input data is given in the following format.
Q
s1
s2
..
..
..
sQ
The number of bit strings Q (1 ≤ Q ≤ 10000) is given in the first row. The input bit string si is given in the following Q row. Suppose the input bit string is given in hexadecimal notation (for example, 0111 1111 1000 1000 0000 0000 0000 0000 is given as 7f880000). In other words, each of the Q lines contains eight hexadecimal numbers, which are 4-bit binary numbers, without any blanks. The table below shows the correspondence between decimal numbers, binary numbers, and hexadecimal numbers.
<image>
Hexadecimal letters a through f are given in lowercase.
output
Outputs the real decimal notation represented by each bit string line by line. However, in the decimal part, if all the digits after a certain digit are 0, the digits after that digit are omitted. As an exception, if the decimal part is 0, one 0 is output to the decimal part.
Example
Input
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
Output
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875 | instruction | 0 | 39,542 | 20 | 79,084 |
"Correct Solution:
```
# Aizu Problem 0268: Konto Type
import sys, math, os, datetime
# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
sys.stdin = open("sample-input.txt", "rt")
n = int(input())
for _ in range(n):
k = int(input(), 16)
s = 1 << 31
p = ""
if k & s != 0:
k ^= s
p = "-"
a = int(k * 1.0 / (1 << 7))
print(p + str(a) + str(abs(k * 1.0 / (1 << 7) - a))[1:])
``` | output | 1 | 39,542 | 20 | 79,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1).
<image>
To translate this format into a decimal representation that is easy for humans to understand, interpret it as follows.
(-1) Sign part × (integer part + decimal part)
In the above expression, the value of the integer part is b8 + 21 x b9 + 22 x b10 + ... + 223 x b31. For example, the integer part is
<image>
If it looks like, the value of the integer part is calculated as follows.
1 + 21 + 23 = 1 + 2 + 8 = 11
On the other hand, the value of the decimal part is (0.5) 1 × b7 + (0.5) 2 × b6 + ... + (0.5) 7 × b1. For example, the decimal part
<image>
If it looks like, the decimal part is calculated as follows.
0.51 + 0.53 = 0.5 + 0.125 = 0.625
Furthermore, in the case of the following bit string that combines the sign part, the integer part, and the decimal part,
<image>
The decimal number represented by the entire bit string is as follows (where -1 to the 0th power is 1).
(-1) 0 × (1 + 2 + 8 + 0.5 + 0.125) = 1 × (11.625) = 11.625
If you enter Q 32-bit bit strings, create a program that outputs the real decimal notation represented by those bit strings without any error.
input
The input consists of one dataset. Input data is given in the following format.
Q
s1
s2
..
..
..
sQ
The number of bit strings Q (1 ≤ Q ≤ 10000) is given in the first row. The input bit string si is given in the following Q row. Suppose the input bit string is given in hexadecimal notation (for example, 0111 1111 1000 1000 0000 0000 0000 0000 is given as 7f880000). In other words, each of the Q lines contains eight hexadecimal numbers, which are 4-bit binary numbers, without any blanks. The table below shows the correspondence between decimal numbers, binary numbers, and hexadecimal numbers.
<image>
Hexadecimal letters a through f are given in lowercase.
output
Outputs the real decimal notation represented by each bit string line by line. However, in the decimal part, if all the digits after a certain digit are 0, the digits after that digit are omitted. As an exception, if the decimal part is 0, one 0 is output to the decimal part.
Example
Input
8
00000000
80000000
00000080
00000040
000000c0
00000100
80000780
80000f70
Output
0.0
-0.0
1.0
0.5
1.5
2.0
-15.0
-30.875
Submitted Solution:
```
BIN = [0] * 32
v = 1
for i in range(24, 0, -1):
BIN[i] = v
v *= 2
v = float(1) / 2
for i in range(25, 32):
BIN[i] = v
v /= 2
while 1:
Q = int(input())
if not Q:break
for i in range(Q):
inp = format(int(input(),16),'b').zfill(32)
res = float(0)
for j, v in enumerate(list(inp)[1:]):
#print(str(BIN[j]) + ' ' + v + ' ' + str(float(v) * BIN[j]))
res += BIN[j+1] * int(v)
print(('-' if inp[0] == '1' else '') + str(res))
``` | instruction | 0 | 39,543 | 20 | 79,086 |
No | output | 1 | 39,543 | 20 | 79,087 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 109 + 7 (so you should find the remainder after dividing by 109 + 7).
Input
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.
The second line contains positive integer a in decimal presentation (without leading zeroes).
The third line contains positive integer b in decimal presentation (without leading zeroes).
It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.
Output
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
Examples
Input
2 6
10
99
Output
8
Input
2 0
1
9
Output
4
Input
19 7
1000
9999
Output
6
Note
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747. | instruction | 0 | 40,057 | 20 | 80,114 |
Tags: dp
Correct Solution:
```
import sys
m, d = map(int, input().split())
mod = 10**9 + 7
def solve(a: list):
dp = [0]*m
border = a[0] % m if a[0] != d else -1
m10 = 10 % m
for i in range(a[0]):
if i != d:
dp[i % m] += 1
for i, digit in enumerate(a[1:], start=1):
next_dp = [0]*m
if i & 1:
t = d % m
for j in range(m):
next_dp[t] += dp[j]
t = t + m10 if t + m10 < m else t + m10 - m
if border != -1:
if d < digit:
next_dp[(border * 10 + d) % m] += 1
border = -1
elif d == digit:
border = (border * 10 + d) % m
else:
border = -1
else:
for j in range(m):
if dp[j] == 0:
continue
if dp[j] >= mod:
dp[j] -= mod
t = (j * 10 - 1) % m
for k in range(10):
t += 1
if t == m:
t = 0
if k == d:
continue
next_dp[t] += dp[j]
if next_dp[t] >= mod:
next_dp[t] -= mod
if border != -1:
for k in range(digit):
if k == d:
continue
next_dp[(border * 10 + k) % m] += 1
if digit != d:
border = (border * 10 + digit) % m
else:
border = -1
dp = next_dp
return dp[0] + (1 if border == 0 else 0)
a = list(map(int, input()))
b = list(map(int, input()))
a[-1] -= 1
for i in range(len(a)-1, 0, -1):
if a[i] < 0:
a[i] = 9
a[i-1] -= 1
else:
break
ans = solve(b) - solve(a)
print(ans % mod)
``` | output | 1 | 40,057 | 20 | 80,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 109 + 7 (so you should find the remainder after dividing by 109 + 7).
Input
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.
The second line contains positive integer a in decimal presentation (without leading zeroes).
The third line contains positive integer b in decimal presentation (without leading zeroes).
It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.
Output
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
Examples
Input
2 6
10
99
Output
8
Input
2 0
1
9
Output
4
Input
19 7
1000
9999
Output
6
Note
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747. | instruction | 0 | 40,058 | 20 | 80,116 |
Tags: dp
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
from array import array
def solve(x,m,d,mod,par):
dp = [[array('i',[0])*m for _ in range(2)] for _ in range(len(x))]
# remainder of number formed till now ; smaller/equal ; place value
zz = int(x[0])
for _ in range(1,zz):
if _ == d:
continue
dp[0][0][_%m] += 1
if zz != d:
dp[0][1][zz%m] = 1
for i in range(1,len(x)):
zz = int(x[i])
if i&1:
for j in range(m):
z = (j*10+d)%m
dp[i][0][z] = (dp[i][0][z]+dp[i-1][0][j]+
(0 if d >= zz else dp[i-1][1][j]))%mod
dp[i][1][z] = (dp[i][1][z]+(0 if d != zz else dp[i-1][1][j]))%mod
else:
for j in range(m):
for k in range(10):
if k==d:
continue
z = (j*10+k)%m
dp[i][0][z] = (dp[i][0][z]+dp[i-1][0][j]+
(0 if k>=zz else dp[i-1][1][j]))%mod
dp[i][1][z] = (dp[i][1][z]+(0 if k!=zz else dp[i-1][1][j]))%mod
if par:
return (dp[len(x)-1][0][0]+dp[len(x)-1][1][0])%mod
return dp[len(x)-1][0][0]
def main():
m,d = map(int,input().split())
a = input().strip()
b = input().strip()
print((solve(b,m,d,10**9+7,1)-solve(a,m,d,10**9+7,0))%(10**9+7))
# Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self,file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
self.newlines = b.count(b"\n")+(not b)
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd,self.buffer.getvalue())
self.buffer.truncate(0),self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self,file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s:self.buffer.write(s.encode("ascii"))
self.read = lambda:self.buffer.read().decode("ascii")
self.readline = lambda:self.buffer.readline().decode("ascii")
sys.stdin,sys.stdout = IOWrapper(sys.stdin),IOWrapper(sys.stdout)
input = lambda:sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
``` | output | 1 | 40,058 | 20 | 80,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 109 + 7 (so you should find the remainder after dividing by 109 + 7).
Input
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.
The second line contains positive integer a in decimal presentation (without leading zeroes).
The third line contains positive integer b in decimal presentation (without leading zeroes).
It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.
Output
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
Examples
Input
2 6
10
99
Output
8
Input
2 0
1
9
Output
4
Input
19 7
1000
9999
Output
6
Note
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
Submitted Solution:
```
from functools import lru_cache
m, d = map(int, input().split())
a = input()
b = input()
def solve(m, d, b):
@lru_cache(None)
def call(pos, remain, f):
# print (pos, remain, f)
nonlocal d
if pos == len(b):
if remain:
return 0
return 1
# even
if (pos + 1) % 2 == 0:
if d <= int(b[pos]):
next_remain = (remain * 10 + d) % m
# print (pos, next_remain, d)
if d == int(b[pos]):
if pos == len(b) or pos == len(b) - 1:
return 1
return call(pos + 1, next_remain, f)
return call(pos + 1, next_remain, 0)
return 0
# odd
if f:
# == b
res = 0
for i in range(10):
if (pos == 0 and i == 0) or (i == d):
continue
next_remain = (remain * 10 + i) % m
# print (pos, i, next_remain)
if i < int(b[pos]):
# next_f = 0
res += call(pos + 1, next_remain, 0)
elif i == int(b[pos]):
# next_f = 1
res += call(pos + 1, next_remain, f)
return res
else:
# < b
res = 0
for i in range(10):
next_remain = (remain * 10 + i) % m
res += call(pos + 1, next_remain, 0)
return res
ans = call(0, 0, 1)
return ans % (10**9 + 7)
if len( str( int(a) - 1) ) == len(a):
c1 = solve(m, d, str( int(a) - 1) )
else:
c1 = 0
c2 = solve(m, d, b)
# print (c1, c2)
print ( (c2 - c1) % (10**9 + 7) )
``` | instruction | 0 | 40,059 | 20 | 80,118 |
No | output | 1 | 40,059 | 20 | 80,119 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 109 + 7 (so you should find the remainder after dividing by 109 + 7).
Input
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.
The second line contains positive integer a in decimal presentation (without leading zeroes).
The third line contains positive integer b in decimal presentation (without leading zeroes).
It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.
Output
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
Examples
Input
2 6
10
99
Output
8
Input
2 0
1
9
Output
4
Input
19 7
1000
9999
Output
6
Note
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
Submitted Solution:
```
from functools import lru_cache
m, d = map(int, input().split())
a = input()
b = input()
def solve(m, d, b):
@lru_cache(None)
def call(pos, remain, f):
# print (pos, remain, f)
nonlocal d
if pos == len(b):
if remain:
return 0
return 1
# even
if (pos + 1) % 2 == 0:
next_remain = (remain * 10 + d) % m
if f:
if d <= int(b[pos]):
# print (pos, next_remain, d)
if d == int(b[pos]):
if pos == len(b) or pos == len(b) - 1:
return 1
return call(pos + 1, next_remain, f)
return call(pos + 1, next_remain, 0)
return 0
return call(pos + 1, next_remain, 0)
# odd
if f:
# == b
res = 0
for i in range(10):
if (pos == 0 and i == 0) or (i == d):
continue
next_remain = (remain * 10 + i) % m
if i < int(b[pos]):
# print (pos, i, b[pos], next_remain)
# next_f = 0
res += call(pos + 1, next_remain, 0)
elif i == int(b[pos]):
# print (pos, i, b[pos], next_remain)
# next_f = 1
res += call(pos + 1, next_remain, f)
return res
else:
# < b
res = 0
for i in range(10):
next_remain = (remain * 10 + i) % m
res += call(pos + 1, next_remain, 0)
return res
ans = call(0, 0, 1)
return ans % (10**9 + 7)
if len( str( int(a) - 1) ) == len(a):
c1 = solve(m, d, str( int(a) - 1) )
# c1 = 0
else:
c1 = 0
c2 = solve(m, d, b)
# print (c1, c2)
print ( (c2 - c1) % (10**9 + 7) )
``` | instruction | 0 | 40,060 | 20 | 80,120 |
No | output | 1 | 40,060 | 20 | 80,121 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 109 + 7 (so you should find the remainder after dividing by 109 + 7).
Input
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.
The second line contains positive integer a in decimal presentation (without leading zeroes).
The third line contains positive integer b in decimal presentation (without leading zeroes).
It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.
Output
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
Examples
Input
2 6
10
99
Output
8
Input
2 0
1
9
Output
4
Input
19 7
1000
9999
Output
6
Note
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
Submitted Solution:
```
import sys
m, d = map(int, input().split())
mod = 10**9 + 7
def solve(a: list):
dp = [0]*m
border = a[0] % m if a[0] != d else -1
m10 = 10 % m
for i in range(a[0]):
if i != d:
dp[i % m] += 1
for i, digit in enumerate(a[1:], start=1):
next_dp = [0]*m
if i & 1:
t = d % m
for j in range(m):
next_dp[t] += dp[j]
t = t + m10 if t + m10 < m else t + m10 - m
if border != -1:
if d < digit:
next_dp[(border * 10 + d) % m] += 1
border = -1
elif d == digit:
border = (border * 10 + d) % m
else:
border = -1
else:
for j in range(m):
if dp[j] == 0:
continue
t = (j * 10 - 1) % m
for k in range(10):
t += 1
if t == m:
t = 0
if k == d:
continue
next_dp[t] += dp[j]
if next_dp[t] >= mod:
next_dp[t] %= mod
if border != -1:
for k in range(digit):
if k == d:
continue
next_dp[(border * 10 + k) % m] += 1
if digit != d:
border = (border * 10 + digit) % m
else:
border = -1
dp = next_dp
print(max(dp))
return dp[0] + (1 if border == 0 else 0)
a = list(map(int, input()))
b = list(map(int, input()))
a[-1] -= 1
for i in range(len(a)-1, 0, -1):
if a[i] < 0:
a[i] = 9
a[i-1] -= 1
else:
break
ans = solve(b) - solve(a)
print(ans % mod)
``` | instruction | 0 | 40,061 | 20 | 80,122 |
No | output | 1 | 40,061 | 20 | 80,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else.
For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic, 34 is 4-magic and 71 is 1-magic.
Find the number of d-magic numbers in the segment [a, b] that are multiple of m. Because the answer can be very huge you should only find its value modulo 109 + 7 (so you should find the remainder after dividing by 109 + 7).
Input
The first line contains two integers m, d (1 ≤ m ≤ 2000, 0 ≤ d ≤ 9) — the parameters from the problem statement.
The second line contains positive integer a in decimal presentation (without leading zeroes).
The third line contains positive integer b in decimal presentation (without leading zeroes).
It is guaranteed that a ≤ b, the number of digits in a and b are the same and don't exceed 2000.
Output
Print the only integer a — the remainder after dividing by 109 + 7 of the number of d-magic numbers in segment [a, b] that are multiple of m.
Examples
Input
2 6
10
99
Output
8
Input
2 0
1
9
Output
4
Input
19 7
1000
9999
Output
6
Note
The numbers from the answer of the first example are 16, 26, 36, 46, 56, 76, 86 and 96.
The numbers from the answer of the second example are 2, 4, 6 and 8.
The numbers from the answer of the third example are 1767, 2717, 5757, 6707, 8797 and 9747.
Submitted Solution:
```
s=[]
count=0
m,i=map(int,input().split())
a=int(input())
b=int(input())
if b<=9:
for u in range(a,b+1,1):
if u%m==0:
s.append(u)
elif b<=99:
for u in range(a,b+1,1):
if int(str(u)[1])==i and int(str(u)[0])!=i and u%m==0:
s.append(u)
else:
for u in range(a,b+1,1):
if len(str(u))%2==0:
for j in range(1,len(str(u)),2):
if str(u)[j]!=i:
continue
else:
count+=1
else:
for j in range(1,len(str(u))-1,2):
if str(u)[j]!=i:
continue
else:
count+=1
if count==(len(str(u))//2) and u%m==0 and u%111!=0:
s.append(u)
print(len(s))
``` | instruction | 0 | 40,062 | 20 | 80,124 |
No | output | 1 | 40,062 | 20 | 80,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers a and b and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) + (b ⊕ x) for any given x, where ⊕ denotes the [bitwise XOR operation](http://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^{4}). Description of the test cases follows.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^{9}).
Output
For each testcase, output the smallest possible value of the given expression.
Example
Input
6
6 12
4 9
59 832
28 14
4925 2912
1 1
Output
10
13
891
18
6237
0
Note
For the first test case Sana can choose x=4 and the value will be (6 ⊕ 4) + (12 ⊕ 4) = 2 + 8 = 10. It can be shown that this is the smallest possible value. | instruction | 0 | 40,623 | 20 | 81,246 |
Tags: bitmasks, greedy, math
Correct Solution:
```
t=int(input())
for i in range(t):
n,k=map(int,input().split())
p=n&k
a=(n^p)+(k^p)
print(a)
``` | output | 1 | 40,623 | 20 | 81,247 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers a and b and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) + (b ⊕ x) for any given x, where ⊕ denotes the [bitwise XOR operation](http://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^{4}). Description of the test cases follows.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^{9}).
Output
For each testcase, output the smallest possible value of the given expression.
Example
Input
6
6 12
4 9
59 832
28 14
4925 2912
1 1
Output
10
13
891
18
6237
0
Note
For the first test case Sana can choose x=4 and the value will be (6 ⊕ 4) + (12 ⊕ 4) = 2 + 8 = 10. It can be shown that this is the smallest possible value. | instruction | 0 | 40,624 | 20 | 81,248 |
Tags: bitmasks, greedy, math
Correct Solution:
```
n=int(input())
for _ in range(n):
a, b = [int(i) for i in input().split()]
x = a & b
print((a^x)+(b^x))
``` | output | 1 | 40,624 | 20 | 81,249 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers a and b and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) + (b ⊕ x) for any given x, where ⊕ denotes the [bitwise XOR operation](http://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^{4}). Description of the test cases follows.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^{9}).
Output
For each testcase, output the smallest possible value of the given expression.
Example
Input
6
6 12
4 9
59 832
28 14
4925 2912
1 1
Output
10
13
891
18
6237
0
Note
For the first test case Sana can choose x=4 and the value will be (6 ⊕ 4) + (12 ⊕ 4) = 2 + 8 = 10. It can be shown that this is the smallest possible value. | instruction | 0 | 40,625 | 20 | 81,250 |
Tags: bitmasks, greedy, math
Correct Solution:
```
t = int(input())
for _ in range(t):
a,b = map(int,input().split())
if a > b:
a,b = b,a
print(a^b)
``` | output | 1 | 40,625 | 20 | 81,251 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers a and b and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) + (b ⊕ x) for any given x, where ⊕ denotes the [bitwise XOR operation](http://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^{4}). Description of the test cases follows.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^{9}).
Output
For each testcase, output the smallest possible value of the given expression.
Example
Input
6
6 12
4 9
59 832
28 14
4925 2912
1 1
Output
10
13
891
18
6237
0
Note
For the first test case Sana can choose x=4 and the value will be (6 ⊕ 4) + (12 ⊕ 4) = 2 + 8 = 10. It can be shown that this is the smallest possible value. | instruction | 0 | 40,626 | 20 | 81,252 |
Tags: bitmasks, greedy, math
Correct Solution:
```
t=int(input())
for _ in range(t):
a,b=map(int,input().split())
x=bin(a)
y=bin(b)
x=x[2:]
y=y[2:]
# print(x,y)
if len(x)<len(y):
d=len(y)-len(x)
x='0'*d+x
if len(y)<len(x):
d=len(x)-len(y)
y='0'*d+y
ans=''
for i in range(len(x)):
if x[i]==y[i]:
ans+=x[i]
else:
ans+='0'
new=int('0b'+ans,2)
print((a^new )+( b^new))
# for i in range(len(min()))
``` | output | 1 | 40,626 | 20 | 81,253 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers a and b and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) + (b ⊕ x) for any given x, where ⊕ denotes the [bitwise XOR operation](http://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^{4}). Description of the test cases follows.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^{9}).
Output
For each testcase, output the smallest possible value of the given expression.
Example
Input
6
6 12
4 9
59 832
28 14
4925 2912
1 1
Output
10
13
891
18
6237
0
Note
For the first test case Sana can choose x=4 and the value will be (6 ⊕ 4) + (12 ⊕ 4) = 2 + 8 = 10. It can be shown that this is the smallest possible value. | instruction | 0 | 40,627 | 20 | 81,254 |
Tags: bitmasks, greedy, math
Correct Solution:
```
def findX(A, B):
j = 0
x = 0
while (A or B):
if ((A & 1) and (B & 1)):
x += (1 << j)
A >>= 1
B >>= 1
j += 1
return x
if __name__ == '__main__':
for i in range(int(input())):
A,B=map(int,input().split())
X = findX(A, B)
print( (A ^ X) + (B ^ X))
``` | output | 1 | 40,627 | 20 | 81,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers a and b and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) + (b ⊕ x) for any given x, where ⊕ denotes the [bitwise XOR operation](http://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^{4}). Description of the test cases follows.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^{9}).
Output
For each testcase, output the smallest possible value of the given expression.
Example
Input
6
6 12
4 9
59 832
28 14
4925 2912
1 1
Output
10
13
891
18
6237
0
Note
For the first test case Sana can choose x=4 and the value will be (6 ⊕ 4) + (12 ⊕ 4) = 2 + 8 = 10. It can be shown that this is the smallest possible value. | instruction | 0 | 40,628 | 20 | 81,256 |
Tags: bitmasks, greedy, math
Correct Solution:
```
for ii in range(int(input())):
a,b=map(int,input().split())
print(a^b)
``` | output | 1 | 40,628 | 20 | 81,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers a and b and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) + (b ⊕ x) for any given x, where ⊕ denotes the [bitwise XOR operation](http://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^{4}). Description of the test cases follows.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^{9}).
Output
For each testcase, output the smallest possible value of the given expression.
Example
Input
6
6 12
4 9
59 832
28 14
4925 2912
1 1
Output
10
13
891
18
6237
0
Note
For the first test case Sana can choose x=4 and the value will be (6 ⊕ 4) + (12 ⊕ 4) = 2 + 8 = 10. It can be shown that this is the smallest possible value. | instruction | 0 | 40,629 | 20 | 81,258 |
Tags: bitmasks, greedy, math
Correct Solution:
```
tc=int(input())
for iii in range(tc):
a,b=[int(i) for i in input().split()]
temp = max(a,b)
print( (a^temp)+(b^temp) )
``` | output | 1 | 40,629 | 20 | 81,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers a and b and a really important quest.
In order to complete the quest, Sana has to output the smallest possible value of (a ⊕ x) + (b ⊕ x) for any given x, where ⊕ denotes the [bitwise XOR operation](http://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^{4}). Description of the test cases follows.
The only line of each test case contains two integers a and b (1 ≤ a, b ≤ 10^{9}).
Output
For each testcase, output the smallest possible value of the given expression.
Example
Input
6
6 12
4 9
59 832
28 14
4925 2912
1 1
Output
10
13
891
18
6237
0
Note
For the first test case Sana can choose x=4 and the value will be (6 ⊕ 4) + (12 ⊕ 4) = 2 + 8 = 10. It can be shown that this is the smallest possible value. | instruction | 0 | 40,630 | 20 | 81,260 |
Tags: bitmasks, greedy, math
Correct Solution:
```
for _ in range(int(input())):
a,b=map(int,input().split())
'''
6
12
0110
1100
1010
-------
'''
print(a^b)
``` | output | 1 | 40,630 | 20 | 81,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1 | instruction | 0 | 40,708 | 20 | 81,416 |
Tags: implementation, math
Correct Solution:
```
a,b,n=[int(x) for x in input().split(' ')]
bhul=True
for j in range(10):
if((a*10+j)%b==0):
a=a*10+j
bhul=False
break
if(bhul):
print(-1)
else:
for x in str(a):
print(x,end='')
for i in range(n-1):
print(0,end='')
``` | output | 1 | 40,708 | 20 | 81,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1 | instruction | 0 | 40,709 | 20 | 81,418 |
Tags: implementation, math
Correct Solution:
```
a,b,n=map(int,input().split())
R=-1
for i in range(10):
r=a*10+i
if r%b==0:
R=str(r)+'0'*(n-1)
break
print(R)
``` | output | 1 | 40,709 | 20 | 81,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1 | instruction | 0 | 40,710 | 20 | 81,420 |
Tags: implementation, math
Correct Solution:
```
from sys import stdin,stdout
import math
a,b,n=map(int,stdin.readline().split())
y=1
a=a*10
i=0
flag=0
for i in range(10):
k=a+i
if k%b==0:
a=k
flag=1
break
if flag==0:
stdout.write("-1")
else:
a=str(a)
a=a+('0'*(n-1))
stdout.write(a)
``` | output | 1 | 40,710 | 20 | 81,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1 | instruction | 0 | 40,711 | 20 | 81,422 |
Tags: implementation, math
Correct Solution:
```
a, b, n = map(int, input().split())
k = ((10 * a + 9) // b) * b;
print (-1 if 10 * a > k else str(k) + '0' * (n - 1))
``` | output | 1 | 40,711 | 20 | 81,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1 | instruction | 0 | 40,712 | 20 | 81,424 |
Tags: implementation, math
Correct Solution:
```
a,b,n = list(map(int,input().split()))
i = 0
f = 0
for j in range(10):
na = a*10+j
if na%b == 0:
a = na
f = 1
break
if f == 1:
print(a*(10**(n-1)))
else:
print(-1)
``` | output | 1 | 40,712 | 20 | 81,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1 | instruction | 0 | 40,713 | 20 | 81,426 |
Tags: implementation, math
Correct Solution:
```
a,b,n=map(int,input().split())
Done=False
for i in range(10):
if(int(str(a)+str(i))%b==0):
Done=True
a*=10
a+=i
break
if(not Done):
print(-1)
else:
print(a,end="")
print("0"*(n-1))
``` | output | 1 | 40,713 | 20 | 81,427 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1 | instruction | 0 | 40,714 | 20 | 81,428 |
Tags: implementation, math
Correct Solution:
```
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
from heapq import heappop , heappush
from bisect import *
from collections import deque , Counter , defaultdict
from math import *
from itertools import permutations , accumulate
dx = [-1 , 1 , 0 , 0 ]
dy = [0 , 0 , 1 , - 1]
#visited = [[False for i in range(m)] for j in range(n)]
#sys.stdin = open(r'input.txt' , 'r')
#sys.stdout = open(r'output.txt' , 'w')
#for tt in range(INT()):
#CODE
a , b , n = MAP()
ans = -1
for i in range(0 , 10):
x = str(a) + str(i)
y = int(x)
if y % b == 0 :
z = '0' * (n - 1)
k = str(y) + z
ans = int(k)
break
print(ans)
``` | output | 1 | 40,714 | 20 | 81,429 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1 | instruction | 0 | 40,715 | 20 | 81,430 |
Tags: implementation, math
Correct Solution:
```
abn=list(input().split())
a=int(abn[0])
b=int(abn[1])
n=int(abn[2])
a=a*10
c=a
for j in range(0,10):
a=a+j
if a%b!=0:
a=c
else:
print(a*(10**(n-1)))
break
if j==9:
print(-1)
``` | output | 1 | 40,715 | 20 | 81,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1
Submitted Solution:
```
a,b,n = map(int,input().split())
flag = 0
a = (a * 10) + 9
check = a % b
if check < 10:
a = a - check
else:
flag = 1
if flag == 1:
print(-1)
else:
for i in range(n-1):
a = a * 10
print(a)
``` | instruction | 0 | 40,716 | 20 | 81,432 |
Yes | output | 1 | 40,716 | 20 | 81,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1
Submitted Solution:
```
a,b,n=map(int,input().split())
ans=-1
for i in range(10):
r=a*10+i
if r%b==0:ans=str(r)+'0'*(n-1)
print(ans)
``` | instruction | 0 | 40,717 | 20 | 81,434 |
Yes | output | 1 | 40,717 | 20 | 81,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1
Submitted Solution:
```
a,b,n=map(int,input().split())
flg=0
for i in range(0,10):
a=str(a)
if(int(a+str(i))%b==0):
num=i
flg=1
break
if(flg==1):
a=str(a)
a+=str(num)
for i in range(n-1):
a+="0"
print(int(a))
else:
print(-1)
``` | instruction | 0 | 40,718 | 20 | 81,436 |
Yes | output | 1 | 40,718 | 20 | 81,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1
Submitted Solution:
```
a,b,n=map(int,input().split())
f=False
for i in range(10):
if int(str(a)+str(i))%b==0:
a=str(a)+str(i)
f=True
n-=1
break
if f:
if n>0:
a=a+"0"*n
print(a)
else:
print(-1)
``` | instruction | 0 | 40,719 | 20 | 81,438 |
Yes | output | 1 | 40,719 | 20 | 81,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1
Submitted Solution:
```
a,b,n=map(int,input().split())
x=[1,2,3,4,5,6,7,8,9]
for i in range(n):
j=0
while(j<len(x)):
m=a
m=m*10+x[j]
if(m%b==0):
a=m
j=9
j+=1
print(a)
if(len(str(a))==n+1):
print(a)
else:
print(-1)
``` | instruction | 0 | 40,720 | 20 | 81,440 |
No | output | 1 | 40,720 | 20 | 81,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1
Submitted Solution:
```
a,b,n = map(int,input().split())
res = a
lastRes = a
while n > 0:
for x in range(1,9):
tempRes = int(str(res)+str(x))
if tempRes % b == 0:
res = tempRes
lastRes = tempRes
break
if res == lastRes:
res = -1
n = 0
else:
n-=1
print(res)
``` | instruction | 0 | 40,721 | 20 | 81,442 |
No | output | 1 | 40,721 | 20 | 81,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1
Submitted Solution:
```
a,b,c=[int(x) for x in input().split()]
d=0
for i in range(c):
for j in range(1,10):
temp=str(a)+str(j)
if int(temp)%b==0:
d=int(temp)
break
if a!=d:
a=-1
break
else:
a=int(temp)
print(a)
``` | instruction | 0 | 40,722 | 20 | 81,444 |
No | output | 1 | 40,722 | 20 | 81,445 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.
Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.
Input
The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).
Output
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
Examples
Input
5 4 5
Output
524848
Input
12 11 1
Output
121
Input
260 150 10
Output
-1
Submitted Solution:
```
def main():
a,b,n = map(int, input().split())
x = "1" + "0"*(len(str(b))-1)
if(a%10 == 0 and b/int(x)==1 ):
print("exception case")
x = "0"*n
a = str(a) +x
print(a)
else:
print("normal case")
i = 0
while(i<n):
flag = 0
for j in range(10):
if( int(str(a)+str(j))%b==0 ):
a = int(str(a)+str(j))
flag = 1
break
if(flag==0):
break
i = i + 1
# print("i = ",i)
if(i==n):
print(a)
else:
print("-1")
if __name__ == '__main__':
main()
``` | instruction | 0 | 40,723 | 20 | 81,446 |
No | output | 1 | 40,723 | 20 | 81,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya wrote a programme on C++ that calculated a very interesting function f(n). Petya ran the program with a certain value of n and went to the kitchen to have some tea. The history has no records concerning how long the program had been working. By the time Petya returned, it had completed the calculations and had the result. However while Petya was drinking tea, a sly virus managed to destroy the input file so that Petya can't figure out for which value of n the program was run. Help Petya, carry out the inverse function!
Mostly, the program consists of a function in C++ with the following simplified syntax:
* function ::= int f(int n) {operatorSequence}
* operatorSequence ::= operator | operator operatorSequence
* operator ::= return arithmExpr; | if (logicalExpr) return arithmExpr;
* logicalExpr ::= arithmExpr > arithmExpr | arithmExpr < arithmExpr | arithmExpr == arithmExpr
* arithmExpr ::= sum
* sum ::= product | sum + product | sum - product
* product ::= multiplier | product * multiplier | product / multiplier
* multiplier ::= n | number | f(arithmExpr)
* number ::= 0|1|2|... |32767
The whitespaces in a operatorSequence are optional.
Thus, we have a function, in which body there are two kinds of operators. There is the operator "return arithmExpr;" that returns the value of the expression as the value of the function, and there is the conditional operator "if (logicalExpr) return arithmExpr;" that returns the value of the arithmetical expression when and only when the logical expression is true. Guaranteed that no other constructions of C++ language — cycles, assignment operators, nested conditional operators etc, and other variables except the n parameter are used in the function. All the constants are integers in the interval [0..32767].
The operators are performed sequentially. After the function has returned a value other operators in the sequence are not performed. Arithmetical expressions are performed taking into consideration the standard priority of the operations. It means that first all the products that are part of the sum are calculated. During the calculation of the products the operations of multiplying and division are performed from the left to the right. Then the summands are summed, and the addition and the subtraction are also performed from the left to the right. Operations ">" (more), "<" (less) and "==" (equals) also have standard meanings.
Now you've got to pay close attention! The program is compiled with the help of 15-bit Berland C++ compiler invented by a Berland company BerSoft, that's why arithmetical operations are performed in a non-standard way. Addition, subtraction and multiplication are performed modulo 32768 (if the result of subtraction is negative, then 32768 is added to it until the number belongs to the interval [0..32767]). Division "/" is a usual integer division where the remainder is omitted.
Examples of arithmetical operations:
<image>
Guaranteed that for all values of n from 0 to 32767 the given function is performed correctly. That means that:
1. Division by 0 never occures.
2. When performing a function for the value n = N recursive calls of the function f may occur only for the parameter value of 0, 1, ..., N - 1. Consequently, the program never has an infinite recursion.
3. As the result of the sequence of the operators, the function always returns a value.
We have to mention that due to all the limitations the value returned by the function f is independent from either global variables or the order of performing the calculations of arithmetical expressions as part of the logical one, or from anything else except the value of n parameter. That's why the f function can be regarded as a function in its mathematical sense, i.e. as a unique correspondence between any value of n from the interval [0..32767] and a value of f(n) from the same interval.
Given the value of f(n), and you should find n. If the suitable n value is not unique, you should find the maximal one (from the interval [0..32767]).
Input
The first line has an integer f(n) from the interval [0..32767]. The next lines have the description of the function f. In the description can be found extra spaces and line breaks (see the examples) which, of course, can’t break key words int, if, return and numbers. The size of input data can’t exceed 100 bytes.
Output
Output a single number — the answer to the problem. If there’s no answer, output "-1" (without quotes).
Examples
Input
17
int f(int n)
{
if (n < 100) return 17;
if (n > 99) return 27;
}
Output
99
Input
13
int f(int n)
{
if (n == 0) return 0;
return f(n - 1) + 1;
}
Output
13
Input
144
int f(int n)
{
if (n == 0) return 0;
if (n == 1) return n;
return f(n - 1) + f(n - 2);
}
Output
24588 | instruction | 0 | 40,744 | 20 | 81,488 |
Tags: implementation
Correct Solution:
```
import re, sys, functools
def cut_modulo(x):
y = x % 32768
if (y < 0):
y += 32768
return y
class berland_cpp_int:
def __init__(self, x):
self.value = cut_modulo(int(x))
def __add__(self, x):
return berland_cpp_int(cut_modulo(self.value + x.value))
def __sub__(self, x):
return berland_cpp_int(cut_modulo(self.value - x.value))
def __mul__(self, x):
return berland_cpp_int(cut_modulo(self.value * x.value))
def __div__(self, x):
return berland_cpp_int(cut_modulo(self.value // x.value))
def __truediv__(self, x):
return berland_cpp_int(cut_modulo(self.value // x.value))
def __and__(self, x):
return berland_cpp_int(cut_modulo(self.value & x.value))
def __eq__(self, x):
return self.value == x.value
def __lt__(self, x):
return self.value < x.value
def __gt__(self, x):
return self.value > x.value
def __str__(self):
return str(self.value)
def __int__(self):
return self.value
def __hash__(self):
return self.value
def translate_program(source_code):
s = source_code
s = s.replace('\n', '')
s = s.replace('{', '')
s = s.replace('}', '')
s = re.sub('([0-9]+)', 'berland_cpp_int(\\1)', s)
s = s.replace('int f(int n)', \
'\n@functools.lru_cache(maxsize=None)\ndef f(n):\n\t')
s = re.sub('return(.*?);', 'return berland_cpp_int(\\1);', s)
s = s.replace(';', '\n\t')
s = s.replace('return', ':return')
s = re.sub('\t[ :]+', '\t', s)
return s
#file_input = sys.stdin.read().split('\n')
file_input = sys.stdin.read().split('\n')
nnn = int(file_input[0])
source = '\n'.join(file_input[1:])
compiled = translate_program(source)
exec(compiled)
vals = list(map(lambda x: f(berland_cpp_int(x)), range(32768)))
vals = list(map(lambda x: x.value, vals))
ans = -1
for i in range(32768):
if (vals[i] == nnn):
ans = i
print(ans)
``` | output | 1 | 40,744 | 20 | 81,489 |
Provide a correct Python 3 solution for this coding contest problem.
For a positive integer n, let us define f(n) as the number of digits in base 10.
You are given an integer S. Count the number of the pairs of positive integers (l, r) (l \leq r) such that f(l) + f(l + 1) + ... + f(r) = S, and find the count modulo 10^9 + 7.
Constraints
* 1 \leq S \leq 10^8
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
Examples
Input
1
Output
9
Input
2
Output
98
Input
123
Output
460191684
Input
36018
Output
966522825
Input
1000
Output
184984484 | instruction | 0 | 41,063 | 20 | 82,126 |
"Correct Solution:
```
s = int(input())
dv = []
mod = 10**9+7
for i in range(1,int((s+0.5)**0.5)+1):
if s%i == 0:
if s//i != i:
dv.append(s//i)
dv.append(i)
dv.sort()
ans = 0
cnt = 0
for i in dv:
if s//i <= 8:
break
ans += pow(10,(s//i)-1,mod)*9-i
ans %= mod
cnt += 1
ans += (s-1)//8
t = s
for i in range(1,11):
minus = i*9*10**(i-1)
if minus > t:
mx = (t+i-1)//i+10**(i-1)
break
else:
t -= minus
bettable = [[[0,0] for i in range(9)] for j in range(9)]
for i in range(9):
for j in range(i+1,9):
for k in range(i+1,j):
bettable[i][j][0] += k*10**(k-1)*9
bettable[i][j][1] += 10**(k-1)*9
for i in range((s+7)//8,mx):
avgl = s//i
if avgl*i == s and 10**(avgl-1)*9 >= i:
ans += 10**(avgl-1)*9-i+1
continue
avgh = avgl+1
for l in range(1,avgl+1):
for h in range(avgh,9):
t = s-bettable[l][h][0]
j = i-bettable[l][h][1]
if t < 0 or j < 0:
continue
lnum = min(j,10**(l-1)*9)
hnum = min(j,10**(h-1)*9)
if (h*j-t)%(h-l) == 0:
x = (h*j-t)//(h-l)
if 0 < x <= lnum and 0 < j-x <= hnum:
ans += 1
break
print(ans%mod)
``` | output | 1 | 41,063 | 20 | 82,127 |
Provide a correct Python 3 solution for this coding contest problem.
Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is correct for C and 5 is correct for E. An operation that lacks some numbers in this way is called worm-eaten calculation.
<image>
The condition that the numbers 1 to 9 appear only once remains the same, and if more numbers are missing as shown below, is there only one way to fill in the correct numbers? In fact, it is not always decided in one way.
<image>
Create a program that outputs how many correct filling methods are available when the information of each cell from A to I is given in the form of worm-eaten calculation as shown in the above figure.
Input
The input is given in the following format.
A B C D E F G H I
One line is given the information of the numbers in the cells from A to I of the worm-eaten calculation. However, when the given value is -1, it means that the number in that square is missing. Values other than -1 are any of the integers from 1 to 9 and there is no duplication between them.
Output
Outputs how many correct filling methods are available on one line.
Examples
Input
7 6 -1 1 -1 9 2 3 4
Output
1
Input
7 6 5 1 8 9 2 3 4
Output
0
Input
-1 -1 -1 -1 -1 -1 8 4 6
Output
12
Input
-1 -1 -1 -1 -1 -1 -1 -1 -1
Output
168 | instruction | 0 | 41,127 | 20 | 82,254 |
"Correct Solution:
```
def make_list(X) :
if X != -1 :
x_list = [X]
else :
x_list = [i for i in range(1, 10)]
return x_list
A, B, C, D, E, F, G, H, I = map(int, input().split())
a_list = make_list(A)
b_list = make_list(B)
c_list = make_list(C)
d_list = make_list(D)
e_list = make_list(E)
f_list = make_list(F)
g_list = make_list(G)
h_list = make_list(H)
i_list = make_list(I)
cnt = 0
for a in a_list :
for b in b_list :
if b not in [a]:
for c in c_list :
if c not in [a, b] :
for d in d_list :
if d not in [a, b, c] :
for e in e_list :
if e not in [a, b, c, d] :
for f in f_list :
if f not in [a, b, c, d, e] :
for g in g_list :
if g not in [a, b, c, d, e, f] :
for h in h_list :
if h not in [a, b, c, d, e, f, g] :
for i in i_list :
if i not in [a, b, c, d, e, f, g, h] :
if a+10*b+c+100*d+10*e+f == 100*g+10*h+i :
cnt += 1
print(cnt)
``` | output | 1 | 41,127 | 20 | 82,255 |
Provide a correct Python 3 solution for this coding contest problem.
Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is correct for C and 5 is correct for E. An operation that lacks some numbers in this way is called worm-eaten calculation.
<image>
The condition that the numbers 1 to 9 appear only once remains the same, and if more numbers are missing as shown below, is there only one way to fill in the correct numbers? In fact, it is not always decided in one way.
<image>
Create a program that outputs how many correct filling methods are available when the information of each cell from A to I is given in the form of worm-eaten calculation as shown in the above figure.
Input
The input is given in the following format.
A B C D E F G H I
One line is given the information of the numbers in the cells from A to I of the worm-eaten calculation. However, when the given value is -1, it means that the number in that square is missing. Values other than -1 are any of the integers from 1 to 9 and there is no duplication between them.
Output
Outputs how many correct filling methods are available on one line.
Examples
Input
7 6 -1 1 -1 9 2 3 4
Output
1
Input
7 6 5 1 8 9 2 3 4
Output
0
Input
-1 -1 -1 -1 -1 -1 8 4 6
Output
12
Input
-1 -1 -1 -1 -1 -1 -1 -1 -1
Output
168 | instruction | 0 | 41,128 | 20 | 82,256 |
"Correct Solution:
```
from collections import deque
*N, = map(int, input().split())
used = set([i for i in N if i != -1])
deq = deque({i for i in range(1, 10)} - used)
C = [1, 10, 1, 100, 10, 1, -100, -10, -1]
def solve():
res = 0
for i in range(9):
res += C[i] * N[i]
return+(res == 0)
def dfs(c, rest):
if rest == 0:
return solve()
if N[c] != -1:
return dfs(c+1, rest)
res = 0
for i in range(rest):
v = deq.popleft()
N[c] = v
res += dfs(c+1, rest-1)
deq.append(v)
N[c] = -1
return res
print(dfs(0, len(deq)))
``` | output | 1 | 41,128 | 20 | 82,257 |
Provide a correct Python 3 solution for this coding contest problem.
Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is correct for C and 5 is correct for E. An operation that lacks some numbers in this way is called worm-eaten calculation.
<image>
The condition that the numbers 1 to 9 appear only once remains the same, and if more numbers are missing as shown below, is there only one way to fill in the correct numbers? In fact, it is not always decided in one way.
<image>
Create a program that outputs how many correct filling methods are available when the information of each cell from A to I is given in the form of worm-eaten calculation as shown in the above figure.
Input
The input is given in the following format.
A B C D E F G H I
One line is given the information of the numbers in the cells from A to I of the worm-eaten calculation. However, when the given value is -1, it means that the number in that square is missing. Values other than -1 are any of the integers from 1 to 9 and there is no duplication between them.
Output
Outputs how many correct filling methods are available on one line.
Examples
Input
7 6 -1 1 -1 9 2 3 4
Output
1
Input
7 6 5 1 8 9 2 3 4
Output
0
Input
-1 -1 -1 -1 -1 -1 8 4 6
Output
12
Input
-1 -1 -1 -1 -1 -1 -1 -1 -1
Output
168 | instruction | 0 | 41,129 | 20 | 82,258 |
"Correct Solution:
```
import itertools
a = input().split()
b = set(map(str,range(1,10)))
n, c = [], 0
for i in range(9):
if a[i] in b:b.remove(a[i])
else:n.append(i)
for i in itertools.permutations(tuple(b)):
for j in range(len(n)):a[n[j]] = i[j]
if int(a[0]) + int(a[1] + a[2]) + int(a[3] + a[4] + a[5]) == int(a[6] + a[7] + a[8]):c += 1
print(c)
``` | output | 1 | 41,129 | 20 | 82,259 |
Provide a correct Python 3 solution for this coding contest problem.
Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is correct for C and 5 is correct for E. An operation that lacks some numbers in this way is called worm-eaten calculation.
<image>
The condition that the numbers 1 to 9 appear only once remains the same, and if more numbers are missing as shown below, is there only one way to fill in the correct numbers? In fact, it is not always decided in one way.
<image>
Create a program that outputs how many correct filling methods are available when the information of each cell from A to I is given in the form of worm-eaten calculation as shown in the above figure.
Input
The input is given in the following format.
A B C D E F G H I
One line is given the information of the numbers in the cells from A to I of the worm-eaten calculation. However, when the given value is -1, it means that the number in that square is missing. Values other than -1 are any of the integers from 1 to 9 and there is no duplication between them.
Output
Outputs how many correct filling methods are available on one line.
Examples
Input
7 6 -1 1 -1 9 2 3 4
Output
1
Input
7 6 5 1 8 9 2 3 4
Output
0
Input
-1 -1 -1 -1 -1 -1 8 4 6
Output
12
Input
-1 -1 -1 -1 -1 -1 -1 -1 -1
Output
168 | instruction | 0 | 41,130 | 20 | 82,260 |
"Correct Solution:
```
from itertools import permutations as pm
def judge(lst):
a, b, c, d, e, f, g, h, i = lst
return a + (b * 10 + c) + (d * 100 + e * 10 + f) == (g * 100 + h * 10 + i)
def solve(lst, rest):
n = len(rest)
if n == 0:
return int(judge(lst))
ans = 0
for loc in pm(rest, n):
tmp = lst[:]
for i in loc:
tmp[tmp.index(-1)] = i
ans += judge(tmp)
return ans
lst = list(map(int, input().split()))
rest = {i for i in range(1, 10)} - set(lst)
print(solve(lst, rest))
``` | output | 1 | 41,130 | 20 | 82,261 |
Provide a correct Python 3 solution for this coding contest problem.
Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is correct for C and 5 is correct for E. An operation that lacks some numbers in this way is called worm-eaten calculation.
<image>
The condition that the numbers 1 to 9 appear only once remains the same, and if more numbers are missing as shown below, is there only one way to fill in the correct numbers? In fact, it is not always decided in one way.
<image>
Create a program that outputs how many correct filling methods are available when the information of each cell from A to I is given in the form of worm-eaten calculation as shown in the above figure.
Input
The input is given in the following format.
A B C D E F G H I
One line is given the information of the numbers in the cells from A to I of the worm-eaten calculation. However, when the given value is -1, it means that the number in that square is missing. Values other than -1 are any of the integers from 1 to 9 and there is no duplication between them.
Output
Outputs how many correct filling methods are available on one line.
Examples
Input
7 6 -1 1 -1 9 2 3 4
Output
1
Input
7 6 5 1 8 9 2 3 4
Output
0
Input
-1 -1 -1 -1 -1 -1 8 4 6
Output
12
Input
-1 -1 -1 -1 -1 -1 -1 -1 -1
Output
168 | instruction | 0 | 41,131 | 20 | 82,262 |
"Correct Solution:
```
def f(n,x):
for i in range(9):
if n[i] != -1 and n[i] != x[i]: return 1
import itertools
u=[1,2,3,4,5,6,7,8,9]
a=0
n=list(map(int,input().split()))
for x in itertools.permutations(u):
if f(n,x):continue
if x[0]+x[2]+x[5]-x[8]+(x[1]+x[4]-x[7])*10+(x[3]-x[6])*100==0:a+=1
print(a)
``` | output | 1 | 41,131 | 20 | 82,263 |
Provide a correct Python 3 solution for this coding contest problem.
Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is correct for C and 5 is correct for E. An operation that lacks some numbers in this way is called worm-eaten calculation.
<image>
The condition that the numbers 1 to 9 appear only once remains the same, and if more numbers are missing as shown below, is there only one way to fill in the correct numbers? In fact, it is not always decided in one way.
<image>
Create a program that outputs how many correct filling methods are available when the information of each cell from A to I is given in the form of worm-eaten calculation as shown in the above figure.
Input
The input is given in the following format.
A B C D E F G H I
One line is given the information of the numbers in the cells from A to I of the worm-eaten calculation. However, when the given value is -1, it means that the number in that square is missing. Values other than -1 are any of the integers from 1 to 9 and there is no duplication between them.
Output
Outputs how many correct filling methods are available on one line.
Examples
Input
7 6 -1 1 -1 9 2 3 4
Output
1
Input
7 6 5 1 8 9 2 3 4
Output
0
Input
-1 -1 -1 -1 -1 -1 8 4 6
Output
12
Input
-1 -1 -1 -1 -1 -1 -1 -1 -1
Output
168 | instruction | 0 | 41,132 | 20 | 82,264 |
"Correct Solution:
```
num=[0]*9
used=[0]*10
def check():
if num[0]+num[2]+num[5]-num[8]+(num[1]+num[4]-num[7])*10+(num[3]-num[6])*100: return 0
return 1
def dfs(id):
if id==9:return check()
if num[id]!=-1:return dfs(id+1)
ans=0
for i in range(1,10):
if used[i]:continue
num[id]=i;used[i]=1
ans+=dfs(id+1)
num[id]=-1;used[i]=0
return ans
num=list(map(int,input().split()))
for x in num:
if x!=-1:used[x]=True
print(dfs(0))
``` | output | 1 | 41,132 | 20 | 82,265 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is correct for C and 5 is correct for E. An operation that lacks some numbers in this way is called worm-eaten calculation.
<image>
The condition that the numbers 1 to 9 appear only once remains the same, and if more numbers are missing as shown below, is there only one way to fill in the correct numbers? In fact, it is not always decided in one way.
<image>
Create a program that outputs how many correct filling methods are available when the information of each cell from A to I is given in the form of worm-eaten calculation as shown in the above figure.
Input
The input is given in the following format.
A B C D E F G H I
One line is given the information of the numbers in the cells from A to I of the worm-eaten calculation. However, when the given value is -1, it means that the number in that square is missing. Values other than -1 are any of the integers from 1 to 9 and there is no duplication between them.
Output
Outputs how many correct filling methods are available on one line.
Examples
Input
7 6 -1 1 -1 9 2 3 4
Output
1
Input
7 6 5 1 8 9 2 3 4
Output
0
Input
-1 -1 -1 -1 -1 -1 8 4 6
Output
12
Input
-1 -1 -1 -1 -1 -1 -1 -1 -1
Output
168
Submitted Solution:
```
ls = list(map(int, input().split()))
print(len(ls)*ls.count(-1))
``` | instruction | 0 | 41,133 | 20 | 82,266 |
No | output | 1 | 41,133 | 20 | 82,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.
There is integer n and array a, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positive integers with the following properties:
* the number's length does not exceed n;
* the number doesn't have leading zeroes;
* digit i (0 ≤ i ≤ 9) occurs in the number at least a[i] times.
Input
The first line contains integer n (1 ≤ n ≤ 100). The next line contains 10 integers a[0], a[1], ..., a[9] (0 ≤ a[i] ≤ 100) — elements of array a. The numbers are separated by spaces.
Output
On a single line print the remainder of dividing the answer to the problem by 1000000007 (109 + 7).
Examples
Input
1
0 0 0 0 0 0 0 0 0 1
Output
1
Input
2
1 1 0 0 0 0 0 0 0 0
Output
1
Input
3
1 1 0 0 0 0 0 0 0 0
Output
36
Note
In the first sample number 9 meets the requirements.
In the second sample number 10 meets the requirements.
In the third sample numbers 10, 110, 210, 120, 103 meet the requirements. There are other suitable numbers, 36 in total. | instruction | 0 | 41,515 | 20 | 83,030 |
Tags: combinatorics, dp
Correct Solution:
```
from math import factorial
dp=[[-1 for i in range (101)] for j in range(101)] # array utilizado para el mamoization donde se guardan las soluciones previamente calculadas
def solve(length,digit,a):
if dp[length][digit] is not -1:
return dp[length][digit] # si la solución ya fue precalculada se devuelve de manera instantanea
elif digit is 9:
if length >= a[9]:
return 1 # si al llegar al análisis del dígito 9 el espacio para ubicarlos
# es menor que la cantidad mínima a ubicar tengo una combinación válida
else:
return 0 # en caso contrario no puedo construir una combinación
elif digit is 0:
ans=0
for i in range(a[0],length):
partial = solve(length-i,1,a) # ubicando i ceros en la combinación comenzando
# en el mínimo que debo ubicar de ceros para obtener una posible combinación válida
partial *= combinations(length-1, i) # se calculan cuantas combinaciones se pueden generar a partir de una distribución válida
# sin contar la primera posición (el cero no puede estar ubicado en la primera posición)
ans += partial
dp[length][digit] = ans #se guarda la respuesta calculada en su ubicación correspondiente en el array del memoization
return ans
else:
ans = 0
for i in range(a[digit],length+1):
partial = solve(length-i,digit+1,a) # se determina si ubicando i veces el dígito se puede llegar a una combinación válida
# comenzando i en la cantidad mínima a ubicar
partial *= combinations(length, i) # se calculan la cantidad de combinaciones posibles a partir de una distribución válida
ans += partial
dp[length][digit] = ans
return ans
def combinations(n, k):
return factorial(n)//(factorial(k)*factorial(n-k)) # fórmula de combinaciones
max_val = 1000000007
length = int(input())
a = input().rstrip().split(' ')
min_length = 0
for i in range(0, len(a)):
a[i] = int(a[i])
min_length += int(a[i])
ans=0
for i in range(min_length, length+1):
ans += solve(i,0,a)
ans %= max_val
print(ans)
``` | output | 1 | 41,515 | 20 | 83,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.
There is integer n and array a, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positive integers with the following properties:
* the number's length does not exceed n;
* the number doesn't have leading zeroes;
* digit i (0 ≤ i ≤ 9) occurs in the number at least a[i] times.
Input
The first line contains integer n (1 ≤ n ≤ 100). The next line contains 10 integers a[0], a[1], ..., a[9] (0 ≤ a[i] ≤ 100) — elements of array a. The numbers are separated by spaces.
Output
On a single line print the remainder of dividing the answer to the problem by 1000000007 (109 + 7).
Examples
Input
1
0 0 0 0 0 0 0 0 0 1
Output
1
Input
2
1 1 0 0 0 0 0 0 0 0
Output
1
Input
3
1 1 0 0 0 0 0 0 0 0
Output
36
Note
In the first sample number 9 meets the requirements.
In the second sample number 10 meets the requirements.
In the third sample numbers 10, 110, 210, 120, 103 meet the requirements. There are other suitable numbers, 36 in total. | instruction | 0 | 41,516 | 20 | 83,032 |
Tags: combinatorics, dp
Correct Solution:
```
from math import factorial
dp=[[-1 for i in range (101)] for j in range(101)] # array utilizado para el mamoization donde se guardan las soluciones previamente calculadas
def solve(length,digit,a):
if dp[length][digit] is not -1:
return dp[length][digit] # si la solución ya fue precalculada se devuelve de manera instantanea
elif digit is 9:
if length >= a[9]:
return 1 # si al llegar al análisis del dígito 9 el espacio para ubicarlos
# es menor que la cantidad mínima a ubicar tengo una combinación válida
else:
return 0 # en caso contrario no puedo construir una combinación
elif digit is 0:
ans=0
for i in range(a[0],length):
partial = solve(length-i,1,a) # ubicando i ceros en la combinación comenzando
# en el mínimo que debo ubicar de ceros para obtener una posible combinación válida
partial *= combinations(length-1, i) # se calculan cuantas combinaciones se pueden generar a partir de una distribución válida
# sin contar la primera posición (el cero no puede estar ubicado en la primera posición)
ans += partial
dp[length][digit] = ans #se guarda la respuesta calculada en su ubicación correspondiente en el array del memoization
return ans
else:
ans = 0
for i in range(a[digit],length+1):
partial = solve(length-i,digit+1,a) # se determina si ubicando i veces el dígito se puede llegar a una combinación válida
# comenzando i en la cantidad mínima a ubicar
partial *= combinations(length, i) # se calculan la cantidad de combinaciones posibles a partir de una distribución válida
ans += partial
dp[length][digit] = ans
return ans
def combinations(n, k):
return factorial(n)//(factorial(k)*factorial(n-k)) # fórmula de combinaciones
max_val = 1000000007
length = int(input())
a = input().rstrip().split(' ')
min_length = 0
for i in range(0, len(a)):
a[i] = int(a[i])
min_length += int(a[i])
ans=0
for i in range(1, length+1):
ans += solve(i,0,a)
ans %= max_val
print(ans)
``` | output | 1 | 41,516 | 20 | 83,033 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.