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.
Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0.
Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)
For example, when n=7, it becomes 0 after two operations, as follows:
* \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.
* \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.
You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
Constraints
* 1 \leq N \leq 2 \times 10^5
* X is an integer with N digits in binary, possibly with leading zeros.
Input
Input is given from Standard Input in the following format:
N
X
Output
Print N lines. The i-th line should contain the value f(X_i).
Examples
Input
3
011
Output
2
1
1
Input
23
00110111001011011001110
Output
2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3
Submitted Solution:
```
N = int(input())
X = int('0b' + input(), 0)
for i in range(N-1, -1, -1):
xx = X ^ (1 << i)
c = 0
while xx > 0:
x = xx - ((xx >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x += (x >> 8)
x += (x >> 16)
x += (x >> 32)
x &= 0x0000007f
xx %= x
c += 1
else:
print(c)
``` | instruction | 0 | 89,894 | 20 | 179,788 |
No | output | 1 | 89,894 | 20 | 179,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let \mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0.
Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)
For example, when n=7, it becomes 0 after two operations, as follows:
* \mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.
* \mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.
You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N).
Constraints
* 1 \leq N \leq 2 \times 10^5
* X is an integer with N digits in binary, possibly with leading zeros.
Input
Input is given from Standard Input in the following format:
N
X
Output
Print N lines. The i-th line should contain the value f(X_i).
Examples
Input
3
011
Output
2
1
1
Input
23
00110111001011011001110
Output
2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3
Submitted Solution:
```
n = int(input())
x = input()
c = x.count("1")
for i in range(n):
a = int(x[i])
if a == 1:
a = 0
cc = c - 1
else:
a = 1
cc = c + 1
ref = int(x[:i] + str(a) + x[i + 1:], 2)
cnt = 0
ref = ref%cc
cnt += 1
while ref > 0:
bitcnt = bin(ref).count("1")
ref = ref%bitcnt
cnt += 1
print(cnt)
``` | instruction | 0 | 89,895 | 20 | 179,790 |
No | output | 1 | 89,895 | 20 | 179,791 |
Provide a correct Python 3 solution for this coding contest problem.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31 | instruction | 0 | 90,026 | 20 | 180,052 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0162
"""
import sys
from sys import stdin
from bisect import bisect_right, bisect_left
from math import ceil, log
input = stdin.readline
def main(args):
hammings = []
temp = set()
for i in range(ceil(log(1e6, 2)) + 1):
for j in range(ceil(log(1e6, 3)) + 1):
for k in range(ceil(log(1e6, 5)) + 1):
ans = 2**i * 3**j * 5**k
temp.add(ans)
hammings = list(temp)
hammings.sort()
while True:
try:
m, n = map(int, input().split(' '))
except ValueError:
break
s = bisect_left(hammings, m)
t = bisect_right(hammings, n)
print(t - s)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 90,026 | 20 | 180,053 |
Provide a correct Python 3 solution for this coding contest problem.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31 | instruction | 0 | 90,027 | 20 | 180,054 |
"Correct Solution:
```
while 1:
n=list(map(int,input().split()))
if n[0]==0:break
a=0
for i in range(n[0],n[1]+1):
b=i
while b%5==0: b/=5
while b%3==0: b/=3
while b%2==0: b/=2
if b==1:a+=1
print(a)
``` | output | 1 | 90,027 | 20 | 180,055 |
Provide a correct Python 3 solution for this coding contest problem.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31 | instruction | 0 | 90,028 | 20 | 180,056 |
"Correct Solution:
```
while True:
A = list(map(int, input().split()))
if A[0] == 0:
break
n, m = A[0], A[1]
ans = 0
for i in range(n, m+1):
b = i
while b % 5 == 0:
b //= 5
while b % 3 == 0:
b //= 3
while b % 2 == 0:
b //= 2
if b == 1:
ans += 1
print(ans)
``` | output | 1 | 90,028 | 20 | 180,057 |
Provide a correct Python 3 solution for this coding contest problem.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31 | instruction | 0 | 90,029 | 20 | 180,058 |
"Correct Solution:
```
MAX = 1000000
hamming_list = [False] * (MAX + 1)
hamming_list[0] = False
hamming_list[1] = True
for index in range(2, MAX + 1):
if index % 2 == 0:
if hamming_list[index // 2]:
hamming_list[index] = True
elif index % 3 == 0:
if hamming_list[index // 3]:
hamming_list[index] = True
elif index % 5 == 0:
if hamming_list[index // 5]:
hamming_list[index] = True
while True:
input_data = input()
if input_data == "0":
break
start, end = [int(item) for item in input_data.split(" ")]
count = sum(hamming_list[start:end + 1])
print(count)
``` | output | 1 | 90,029 | 20 | 180,059 |
Provide a correct Python 3 solution for this coding contest problem.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31 | instruction | 0 | 90,030 | 20 | 180,060 |
"Correct Solution:
```
MAX = 1000000
hamming_list = [False] * (MAX + 1)
hamming_list[0] = False
hamming_list[1] = True
for index in range(2, MAX + 1):
if index / 2 % 1 == 0:
if hamming_list[index // 2]:
hamming_list[index] = True
elif index / 3 % 1 == 0:
if hamming_list[index // 3]:
hamming_list[index] = True
elif index / 5 % 1 == 0:
if hamming_list[index // 5]:
hamming_list[index] = True
while True:
input_data = input()
if input_data == "0":
break
start, end = [int(item) for item in input_data.split(" ")]
count = sum(hamming_list[start:end + 1])
print(count)
``` | output | 1 | 90,030 | 20 | 180,061 |
Provide a correct Python 3 solution for this coding contest problem.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31 | instruction | 0 | 90,031 | 20 | 180,062 |
"Correct Solution:
```
H = [False for i in range(1000001)]
H[1] = True
for i in range(20):
for j in range(13):
for k in range(9):
if (2 ** i) * (3 ** j) * (5 ** k) < 1000001:
H[(2 ** i) * (3 ** j) * (5 ** k)] = True
else:
break
while True:
L = input()
if L == "0":
break
a, b = [int(i) for i in L.split()]
ans = 0
for i in range(a, b+1):
if H[i]:
ans += 1
print(ans)
``` | output | 1 | 90,031 | 20 | 180,063 |
Provide a correct Python 3 solution for this coding contest problem.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31 | instruction | 0 | 90,032 | 20 | 180,064 |
"Correct Solution:
```
while 1:
n=list(map(int,input().split()))
if n[0]==0:break
a=0
for i in range(n[0],n[1]+1):
b=i
while b%2==0: b/=2
while b%3==0: b/=3
while b%5==0: b/=5
if b==1:a+=1
print(a)
``` | output | 1 | 90,032 | 20 | 180,065 |
Provide a correct Python 3 solution for this coding contest problem.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31 | instruction | 0 | 90,033 | 20 | 180,066 |
"Correct Solution:
```
while 1:
datas = list(map(int, input().split()))
if datas[0] == 0:
break
n, m = datas[0], datas[1]
cnt = 0
for i in range(n, m+1):
b = i
while b % 5 == 0:
b //= 5
while b % 3 == 0:
b //= 3
while b % 2 == 0:
b //= 2
if b == 1:
cnt += 1
print(cnt)
``` | output | 1 | 90,033 | 20 | 180,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31
Submitted Solution:
```
# AOJ 0162 Hamming Numbers
# Python3 2018.6.23 bal4u
MAX = 1000000
t = [0]*(MAX+5)
a5 = 1
for i in range(9):
a3 = 1
for j in range(13):
a35 = a5*a3
if a35 > MAX: break
a2 = 1
for k in range(20):
if a35*a2 > MAX: break
t[a35*a2] = 1
a2 <<= 1
a3 *= 3
a5 *= 5
while 1:
a = input()
if a == '0': break
m, n = map(int, a.split())
print(sum(t[m:n+1]))
``` | instruction | 0 | 90,034 | 20 | 180,068 |
Yes | output | 1 | 90,034 | 20 | 180,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31
Submitted Solution:
```
twos = [2 ** i for i in range(21) if 2 ** i <= 1000000]
threes = [3 ** i for i in range(21) if 2 ** i <= 1000000]
fives = [5 ** i for i in range(21) if 2 ** i <= 1000000]
muls = [x * y * z for x in twos for y in threes for z in fives]
muls.sort()
def under(n):
cnt = 0
for i in muls:
if i <= n:
cnt += 1
else:
break
return cnt
while True:
s = input()
if s == "0":
break
m, n = map(int, s.split())
print(under(n) - under(m - 1))
``` | instruction | 0 | 90,036 | 20 | 180,072 |
Yes | output | 1 | 90,036 | 20 | 180,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example
* 1
* 1 x 2 x 2 = 4
* 1 x 2 x 2 x 3 x 5 x 5 = 300
Etc. are humming numbers, but 11, 13, 14 etc. are not humming numbers.
All humming numbers are divisible by a power of 60 (for example, 54 is divisible by 603 = 21600), so they have long been known as convenient numbers for sexagesimal calculations such as time. In just intonation, which is one of the scales used for tuning musical instruments, the ratio of the frequencies of the sounds is a sequence of humming numbers of 24, 27, 30, 32, 36, 40, 45, 48.
Create a program that takes integers m and n as inputs and outputs the number of humming numbers that are m or more and n or less.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros.
For each dataset, two integers m and n (1 β€ m, n β€ 1000000, m β€ n) are given on one line, separated by blanks.
The number of datasets does not exceed 20.
Output
Outputs the number of humming numbers from m to n for each data set on one line.
Example
Input
3 8
1 27
1 86
0
Output
5
17
31
Submitted Solution:
```
import sys
def main():
for line in sys.stdin:
mn = list(line)
if mn[0] == "0":
break
else:
num = [str(i) for i in range(0, 10)]
d = ""
for x in range(len(mn)):
if mn[x] not in num:
dd = x
break
else:
d += mn[x]
m = int(d)
d = ""
for y in range(dd + 1, len(mn) - 1):
d += mn[y]
n = int(d)
a2 = []
for i in range(1, n):
hoge = 2 ** i
if hoge <= n:
a2.append(hoge)
else:
break
a3 = []
for i in range(1, n):
hoge = 3 ** i
if hoge <= n:
a3.append(hoge)
else:
break
a5 = []
for i in range(1, n):
hoge = 5 ** i
if hoge <= n:
a5.append(hoge)
else:
break
a23 = []
for i in range(len(a2)):
for j in range(len(a3)):
fuga = a2[i] * a3[j]
if fuga <= n:
a23.append(fuga)
else:
break
a35 = []
for i in range(len(a3)):
for j in range(len(a5)):
fuga = a3[i] * a5[j]
if fuga <= n:
a35.append(fuga)
else:
break
a52 = []
for i in range(len(a5)):
for j in range(len(a2)):
fuga = a5[i] * a2[j]
if fuga <= n:
a52.append(fuga)
else:
break
a2335 = []
for i in range(len(a23)):
for j in range(len(a35)):
fuga = a23[i] * a35[j]
if fuga <= n:
a2335.append(fuga)
else:
break
a3552 = []
for i in range(len(a35)):
for j in range(len(a52)):
fuga = a35[i] * a52[j]
if fuga <= n:
a3552.append(fuga)
else:
break
a23353552 = []
for i in range(len(a2335)):
for j in range(len(a3552)):
fuga = a2335[i] * a3552[j]
if fuga <= n:
a23353552.append(fuga)
else:
break
a30 = []
i = 1
while 1:
fuga = 30 * i
if fuga <= n:
a30.append(fuga)
i += 1
else:
break
a = a2 + a3 + a5 + a23 + a35 + a52 + a2335 + a3552 +\
a23353552 + a30
if m == 1:
a.append(1)
else:
pass
a = sorted(set(a))
for x in range(len(a)):
if a[x] >= m:
c = x
break
else:
pass
cnt = 0
for x in range(c, len(a)):
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
``` | instruction | 0 | 90,038 | 20 | 180,076 |
No | output | 1 | 90,038 | 20 | 180,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | instruction | 0 | 90,419 | 20 | 180,838 |
Tags: bitmasks, brute force, dfs and similar
Correct Solution:
```
from itertools import product
n = int(input().strip())
if n<102:
print(n)
else:
res = set()
combination = (str(i)+str(j) for i in range(10) for j in range(i+1,10))
for it in (product(comb,repeat=l) for comb in combination for l in range(1,len(str(n))+1)):
for line in it:
tmp = int("".join(line))
if tmp and tmp<=n:
res.add(tmp)
print(len(res))
``` | output | 1 | 90,419 | 20 | 180,839 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | instruction | 0 | 90,420 | 20 | 180,840 |
Tags: bitmasks, brute force, dfs and similar
Correct Solution:
```
def p(k):
if 0 < k <= n:
s.add(k)
k *= 10
p(k + x)
p(k + y)
n = int(input())
s = set()
for x in range(10):
for y in range(10):
p(x)
print(len(s))
``` | output | 1 | 90,420 | 20 | 180,841 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | instruction | 0 | 90,421 | 20 | 180,842 |
Tags: bitmasks, brute force, dfs and similar
Correct Solution:
```
# https://codeforces.com/contest/244/problem/B
def gen(digit, x, length, S):
S.append(x)
if length == 10:
return
if len(digit) == 1:
for i in range(0, 10):
next_x = x * 10 + i
if i == digit[0]:
gen(digit, next_x, length+1, S)
else:
gen(digit+[i], next_x, length+1, S)
else:
next_x1 = x * 10 + digit[0]
next_x2 = x * 10 + digit[1]
gen(digit, next_x1, length+1, S)
gen(digit, next_x2, length+1, S)
S = []
for i in range(1, 10):
gen([i], i, 1, S)
S = sorted(S)
x = int(input())
l = -1
u = len(S)
while u-l>1:
md = (u+l) // 2
if x >= S[md]:
l = md
else:
u = md
print(u)
``` | output | 1 | 90,421 | 20 | 180,843 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | instruction | 0 | 90,422 | 20 | 180,844 |
Tags: bitmasks, brute force, dfs and similar
Correct Solution:
```
#CF Round 150. Div II Prob. A - Dividing Orange
import sys
dp = [[[-1 for j in range(3)] for i in range (1 << 10)] for k in range(11)]
In = sys.stdin
n = In.readline().strip()
def go (idx, mask, equal):
if dp[idx][mask][equal] != -1:
return dp[idx][mask][equal]
if bin(mask).count("1") > 2:
return 0
if idx == len(n):
return 1
res = 0
if idx == 0 or equal == 2:
res += go(idx + 1, mask, 2)
elif equal == 1 and int(n[idx]) == 0:
res += go(idx + 1, mask | 1, 1)
else:
res += go(idx + 1, mask | 1, 0)
for i in range(1, 10):
if equal == 1 and i > int(n[idx]):
break
elif equal == 1 and i == int(n[idx]):
res += go(idx + 1, mask | (1 << i), 1)
else:
res += go(idx + 1, mask | (1 << i), 0)
dp[idx][mask][equal] = res
return res
print(go(0, 0, 1) - 1)
``` | output | 1 | 90,422 | 20 | 180,845 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | instruction | 0 | 90,423 | 20 | 180,846 |
Tags: bitmasks, brute force, dfs and similar
Correct Solution:
```
def dfs(k):
if 0 < k <= n:
s.add(k)
k *= 10
dfs(k + x)
dfs(k + y)
n = int(input())
s = set()
for x in range(10):
for y in range(10):
dfs(x)
print(len(s))
``` | output | 1 | 90,423 | 20 | 180,847 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | instruction | 0 | 90,424 | 20 | 180,848 |
Tags: bitmasks, brute force, dfs and similar
Correct Solution:
```
def findNum(num):
if 0 < num <= n:
s.add(num)
num*=10
findNum(num+x)
findNum(num+y)
n = int(input())
s = set()
for x in range(10):
for y in range(10):
findNum(x)
print(len(s))
``` | output | 1 | 90,424 | 20 | 180,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | instruction | 0 | 90,425 | 20 | 180,850 |
Tags: bitmasks, brute force, dfs and similar
Correct Solution:
```
n=int(input())
def bruteforce(number):
res=0
liste=[]
while number>0:
integer=number%10
if integer not in liste:
liste.append(integer)
number=number//10
return len(liste)<=2
answer=[0]
def dfs(num):
if (num>0 and num<=n):
answer[0]+=1
for a in range(10):
if bruteforce(num*10+a):
dfs(num*10+a)
for chiffre in range(1,10):
dfs(chiffre)
print(answer[0])
``` | output | 1 | 90,425 | 20 | 180,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | instruction | 0 | 90,426 | 20 | 180,852 |
Tags: bitmasks, brute force, dfs and similar
Correct Solution:
```
ii=lambda:int(input())
kk=lambda:map(int, input().split())
ll=lambda:list(kk())
q =[]
s=set()
n=ii()
for x in range(10):
for y in range(10):
q.append(x)
while q:
q2 = []
for item in q:
if item > 0 and item <= n:
s.add(item)
item*=10
q2.append(item+x)
q2.append(item+y)
q=q2
print(len(s))
``` | output | 1 | 90,426 | 20 | 180,853 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
Submitted Solution:
```
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
# @Time : 2020/12/4 1:44 PM
# @Author : Songtao Li
s = set()
def DFS(x, y, num, max_n):
s.add(num)
num_x = 10 * num + x
num_y = 10 * num + y
if num_x and num_x <= max_n:
DFS(x, y, num_x, max_n)
if num_y and num_y <= max_n:
DFS(x, y, num_y, max_n)
if __name__ == "__main__":
n = int(input())
for i in range(10):
for j in range(i, 10):
DFS(i, j, 0, n)
print(len(s)-1)
``` | instruction | 0 | 90,427 | 20 | 180,854 |
Yes | output | 1 | 90,427 | 20 | 180,855 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
Submitted Solution:
```
def cnt(s, p):
ans = 0
if p > s: ans = 0
elif len(p) == len(s):
ans = 1 if len(set(p.lstrip('0'))) <= 2 else 0
elif len(set(p.lstrip('0'))) > 2: ans = 0
elif s[:len(p)] > p:
if len(set(p.lstrip('0'))) == 2:
ans = 2**(len(s)-len(p))
elif len(set(p.lstrip('0'))) == 1:
ans = 1 + 9 * (2**(len(s)-len(p)) - 1)
else:
# ab for all a, b != 0
ans = 10 + 45 * (2**(len(s)-len(p)) - 2)
ans += 36 * sum([2**l-2 for l in range(2,len(s)-len(p))])
else: ans = sum(cnt(s, p+c) for c in '0123456789')
return ans
print(cnt(input().strip(), '')-1)
# Made By Mostafa_Khaled
``` | instruction | 0 | 90,428 | 20 | 180,856 |
Yes | output | 1 | 90,428 | 20 | 180,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
Submitted Solution:
```
#d=sorted(d,key=lambda x:(len(d[x]),-x)) d=dictionary d={x:set() for x in arr}
#n=int(input())
#n,m,k= map(int, input().split())
import heapq
#for _ in range(int(input())):
#n,k=map(int, input().split())
#input=sys.stdin.buffer.readline
#for _ in range(int(input())):
def dfs(x):
if 0< x <=n :
s.add(x)
x*=10
dfs(x+i)
dfs(x+j)
n=int(input())
#arr = list(map(int, input().split()))
s=set()
for i in range(1,10):
for j in range(10):
dfs(i)
print(len(s))
``` | instruction | 0 | 90,429 | 20 | 180,858 |
Yes | output | 1 | 90,429 | 20 | 180,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
Submitted Solution:
```
n=int(input())
a=[]
def foo(x,i,j):
if x>n:
return
if x:
a.append(x)
if 10*x+i!=x:
foo(10*x+i,i,j)
foo(10*x+j,i,j)
for i in range(10):
for j in range(i+1,10):
foo(0,i,j)
print(len(set(a)))
``` | instruction | 0 | 90,430 | 20 | 180,860 |
Yes | output | 1 | 90,430 | 20 | 180,861 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
Submitted Solution:
```
global ans
ans = 0;
global n
def dfs(num):
global ans
if num > n :
return
a = [0]*10
k = num
while k != 0 :
a[int(k%10)] += 1
k = k / 10
cnt = 0
for i in range(10):
if a[i] > 0 :
cnt += 1
if cnt > 2 :
return
if num > 0 :
ans += 1
for i in range(10):
if i == 0 and num == 0 :
continue
dfs(num*10 + i)
global n
n = int(input())
dfs(0)
print(ans)
``` | instruction | 0 | 90,431 | 20 | 180,862 |
No | output | 1 | 90,431 | 20 | 180,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
Submitted Solution:
```
from random import randint
n = int(input())
ses = set()
for c1 in range(10):
for c2 in range(c1 + 1, 10):
C = [c1, c2]
for _ in range(4000):
kek = C[randint(0, 1)]
while kek <= n:
ses.add(kek)
kek *= 10; kek += C[randint(0, 1)]
print(len(ses)-1)
``` | instruction | 0 | 90,432 | 20 | 180,864 |
No | output | 1 | 90,432 | 20 | 180,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
Submitted Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**9
n = int(input())
if n < 100:
print(n)
sys.exit()
a = [[_,set(map(int,list(str(_))))] for _ in range(100)]
c = 99
for k in range(2,11):
t = (10 ** (k-1))
for aa in a:
if aa[0] >= t:
break
aa[1] |= set([0])
for i in range(1,10):
t = i * (10 ** k)
for ai, ae in a[:]:
ac = ai + t
if ac > n:
print(c)
sys.exit()
if len(ae) < 2:
ae = ae | set([i])
if i in ae:
c += 1
a.append([ac,ae])
``` | instruction | 0 | 90,433 | 20 | 180,866 |
No | output | 1 | 90,433 | 20 | 180,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
Input
The first line contains a single integer n (1 β€ n β€ 109) β Polycarpus's number.
Output
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
Examples
Input
10
Output
10
Input
123
Output
113
Note
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky.
Submitted Solution:
```
from random import randint
n = int(input())
ses = set()
for c1 in range(10):
for c2 in range(c1 + 1, 10):
C = [c1, c2]
for _ in range(4100):
kek = C[randint(0, 1)]
while kek <= n:
ses.add(kek)
kek *= 10; kek += C[randint(0, 1)]
print(len(ses)-1)
``` | instruction | 0 | 90,434 | 20 | 180,868 |
No | output | 1 | 90,434 | 20 | 180,869 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. | instruction | 0 | 90,642 | 20 | 181,284 |
Tags: math, number theory
Correct Solution:
```
a, b, c = map(int, input().split())
pos = -1
for i in range(1, 309):
if int((a * pow(10, i) // b)) % 10 == c:
pos = i
break
print(pos)
#128 7 0
``` | output | 1 | 90,642 | 20 | 181,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. | instruction | 0 | 90,643 | 20 | 181,286 |
Tags: math, number theory
Correct Solution:
```
import decimal
a, b, c = map(int, input().split())
decimal.getcontext().prec = 3 * b + 100
s = str(decimal.Decimal(a) / decimal.Decimal(b)).ljust(3 * b + 100, '0')
r = s.find(str(c), 2, 2 * b + 8) - 1
if r == -2:
print(-1)
else:
print(r)
``` | output | 1 | 90,643 | 20 | 181,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. | instruction | 0 | 90,644 | 20 | 181,288 |
Tags: math, number theory
Correct Solution:
```
from decimal import *
getcontext().prec = 300
split_strings = input().split()
[a, b, c] = map(lambda x: int(x), split_strings)
a = Decimal(a)
b = Decimal(b)
decimal = (a / b) * 10
for i in range(1, 300):
ones = int(decimal)
fractional = decimal % 1
if ones == c:
print(i)
exit()
decimal = fractional * 10
print(-1)
``` | output | 1 | 90,644 | 20 | 181,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. | instruction | 0 | 90,645 | 20 | 181,290 |
Tags: math, number theory
Correct Solution:
```
a,b,c = map(int,input().split(" "))
a = a%b
i = 1
while i <= b :
if a==0:
if c==0 :
print(i)
exit()
else :
print(-1)
exit()
if a<b : a *= 10
while(a<b) :
if c==0 :
print(i)
exit()
a *= 10
i += 1
d = a//b
if d==c:
print(i)
exit()
a -= d*b
i += 1
print(-1)
``` | output | 1 | 90,645 | 20 | 181,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. | instruction | 0 | 90,646 | 20 | 181,292 |
Tags: math, number theory
Correct Solution:
```
a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
num = []
cnt = 0
while True:
cnt += 1
num.append( a )
n = a*10//b
if n == c:
break
a = a*10 - n*b
if a in num:
cnt = -1
break
print( cnt )
``` | output | 1 | 90,646 | 20 | 181,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. | instruction | 0 | 90,647 | 20 | 181,294 |
Tags: math, number theory
Correct Solution:
```
from decimal import *
getcontext().prec = 10000
a, b, c = map(int, input().split())
d = Decimal(a)/Decimal(b)
# print(d)
s = str(d)[2:]
if len(s) > 900:
s = s[:-1]
else:
s += '0'
# print(s)
try:
ans = s.index(str(c))
except ValueError:
print(-1)
else:
print(ans+1)
``` | output | 1 | 90,647 | 20 | 181,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. | instruction | 0 | 90,648 | 20 | 181,296 |
Tags: math, number theory
Correct Solution:
```
a,b,c=map(int,input().split())
r=a%b
t=b
cnt=1
f=0
while(t!=0):
r*=10
k=r//b
r=r%b
if(k==c):
f=1
break
cnt+=1
t-=1
if(f):
print(cnt)
else:
print(-1)
``` | output | 1 | 90,648 | 20 | 181,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction. | instruction | 0 | 90,649 | 20 | 181,298 |
Tags: math, number theory
Correct Solution:
```
from decimal import *
getcontext().prec = 2048
getcontext().rounding = ROUND_DOWN
num, denom, target = [int(x) for x in input().split()]
a = Decimal(num)/Decimal(denom)
a = str(a)
a = a[a.find('.') : ]
if len(a) < 2047:
a = a + '0'
print(a.find(str(target)))
``` | output | 1 | 90,649 | 20 | 181,299 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction.
Submitted Solution:
```
from fractions import Fraction
(a, b, c) = tuple(map(int, input().split()))
f = Fraction(a, b)
for i in range(900):
for j in range(10):
if f < Fraction(j+1, 10):
if j == c:
print(i+1)
exit(0)
f -= Fraction(j, 10)
f *= 10
break
print(-1)
``` | instruction | 0 | 90,650 | 20 | 181,300 |
Yes | output | 1 | 90,650 | 20 | 181,301 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction.
Submitted Solution:
```
from decimal import *
def main():
getcontext().prec = 500
a, b, c = map(int, input().split())
d = str(Decimal(a) / Decimal(b))
d += "0" * (502 - (len(d)))
cnt = [-2] * 10
for idx, item in enumerate(d[2:-1]):
if cnt[int(item)] == -2:
cnt[int(item)] = idx
print(cnt[c] + 1)
if __name__ == "__main__":
main()
``` | instruction | 0 | 90,651 | 20 | 181,302 |
Yes | output | 1 | 90,651 | 20 | 181,303 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction.
Submitted Solution:
```
arr = list(map(int, input().split()))
a=arr[0]
b=arr[1]
c=arr[2]
for i in range(1,b+1):
a*=10
if a//b==c:
print(i)
break
a%=b
else:
print(-1)
``` | instruction | 0 | 90,652 | 20 | 181,304 |
Yes | output | 1 | 90,652 | 20 | 181,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction.
Submitted Solution:
```
a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
d = (10**10000) * a // b
x = 10 ** (10000 - 1)
for i in range(1, 1001, 1):
if d // x == c:
print(i)
exit(0)
d %= x
x //= 10
print(-1)
``` | instruction | 0 | 90,653 | 20 | 181,306 |
Yes | output | 1 | 90,653 | 20 | 181,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction.
Submitted Solution:
```
a,b,c=map(int,input().split())
a=(a%b)
count=0
l=0
m=0
n=0
k=0
while True:
n=k
a*=10
k=a//b
a=(a%b)
count+=1
if k==c:
l+=1
print(count)
break
if a==0 and c!=0 :
m+=1
break
if n==k and c==k:
print(count-1)
break
if n==k:
m+=1
break
if m>l:
print('-1')
``` | instruction | 0 | 90,654 | 20 | 181,308 |
No | output | 1 | 90,654 | 20 | 181,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction.
Submitted Solution:
```
a, b,c = map(int, input().split())
ans = float(a/b)
ans = format(ans, '.20f')
ans = str(ans)
ans = ans[2:len(ans)]
if(ans.count(str(c)) > 0):
print(str(ans.index(str(c))+1))
else:
print("-1")
``` | instruction | 0 | 90,655 | 20 | 181,310 |
No | output | 1 | 90,655 | 20 | 181,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction.
Submitted Solution:
```
a, b, c = map(int, input().split())
for i in range (b):
z = a*10
if z // b == c :
print (i+1)
break
a %= b
else: print(-1)
``` | instruction | 0 | 90,656 | 20 | 181,312 |
No | output | 1 | 90,656 | 20 | 181,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 β€ a < b β€ 105, 0 β€ c β€ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
Examples
Input
1 2 0
Output
2
Input
2 3 7
Output
-1
Note
The fraction in the first example has the following decimal notation: <image>. The first zero stands on second position.
The fraction in the second example has the following decimal notation: <image>. There is no digit 7 in decimal notation of the fraction.
Submitted Solution:
```
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
l=[]
rem=a
j=0
while 1:
ans=rem*10//b
l.append(ans)
j+=1
rem=rem*10%b
if j==1:
continue
if ans==l[0] or rem==0:
if rem==0:
l.append(0)
break
j=1
find=False
for i in l:
if c==i:
print(j)
find=True
break
j+=1
if not find:
print(-1)
``` | instruction | 0 | 90,657 | 20 | 181,314 |
No | output | 1 | 90,657 | 20 | 181,315 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to 35 and the number IXI β to 12.
Pay attention to the difference to the traditional roman system β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L.
Input
The only line of the input file contains a single integer n (1 β€ n β€ 10^9) β the number of roman digits to use.
Output
Output a single integer β the number of distinct integers which can be represented using n roman digits exactly.
Examples
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
Note
In the first sample there are exactly 4 integers which can be represented β I, V, X and L.
In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). | instruction | 0 | 90,694 | 20 | 181,388 |
Tags: brute force, combinatorics, dp, greedy, math
Correct Solution:
```
from sys import setrecursionlimit
setrecursionlimit((10**9))
n = int(input())
s = set()
arr = [1,5,10,50]
def comb(num, digit):
global n
if digit == n:
s.add(num)
else:
for i in range(4):
comb(num+arr[i], digit+1)
if n <= 12:
comb(0, 0)
print(len(s))
else:
print(49*n-247)
``` | output | 1 | 90,694 | 20 | 181,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to 35 and the number IXI β to 12.
Pay attention to the difference to the traditional roman system β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L.
Input
The only line of the input file contains a single integer n (1 β€ n β€ 10^9) β the number of roman digits to use.
Output
Output a single integer β the number of distinct integers which can be represented using n roman digits exactly.
Examples
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
Note
In the first sample there are exactly 4 integers which can be represented β I, V, X and L.
In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). | instruction | 0 | 90,695 | 20 | 181,390 |
Tags: brute force, combinatorics, dp, greedy, math
Correct Solution:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = int(input())
if n < 12:
print([1, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292][n])
else:
print(n*50-n-247)
``` | output | 1 | 90,695 | 20 | 181,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to 35 and the number IXI β to 12.
Pay attention to the difference to the traditional roman system β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L.
Input
The only line of the input file contains a single integer n (1 β€ n β€ 10^9) β the number of roman digits to use.
Output
Output a single integer β the number of distinct integers which can be represented using n roman digits exactly.
Examples
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
Note
In the first sample there are exactly 4 integers which can be represented β I, V, X and L.
In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). | instruction | 0 | 90,696 | 20 | 181,392 |
Tags: brute force, combinatorics, dp, greedy, math
Correct Solution:
```
def check(n, b, c):
for tb in range(0, 9):
for tc in range(0, min(n - tb + 1, 9)):
s1 = 9 * b + 4 * c
s2 = 9 * tb + 4 * tc
if s1 > s2 and (s1 - s2) % 49 == 0:
return False
return True
def main():
n = int(input())
ans = 0
for b in range(0, min(n + 1, 9)):
for c in range(0, min(n - b + 1, 9)):
if check(n, b, c):
ans += (n - b - c + 1)
print(ans)
if __name__ == "__main__":
exit(main())
``` | output | 1 | 90,696 | 20 | 181,393 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to 35 and the number IXI β to 12.
Pay attention to the difference to the traditional roman system β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L.
Input
The only line of the input file contains a single integer n (1 β€ n β€ 10^9) β the number of roman digits to use.
Output
Output a single integer β the number of distinct integers which can be represented using n roman digits exactly.
Examples
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
Note
In the first sample there are exactly 4 integers which can be represented β I, V, X and L.
In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). | instruction | 0 | 90,697 | 20 | 181,394 |
Tags: brute force, combinatorics, dp, greedy, math
Correct Solution:
```
a = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292]
n = int(input())
if n < len(a):
print (a[n])
else:
print (a[11] + 49*(n-11))
``` | output | 1 | 90,697 | 20 | 181,395 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.
For example, the number XXXV evaluates to 35 and the number IXI β to 12.
Pay attention to the difference to the traditional roman system β in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 11, not 9.
One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly n roman digits I, V, X, L.
Input
The only line of the input file contains a single integer n (1 β€ n β€ 10^9) β the number of roman digits to use.
Output
Output a single integer β the number of distinct integers which can be represented using n roman digits exactly.
Examples
Input
1
Output
4
Input
2
Output
10
Input
10
Output
244
Note
In the first sample there are exactly 4 integers which can be represented β I, V, X and L.
In the second sample it is possible to represent integers 2 (II), 6 (VI), 10 (VV), 11 (XI), 15 (XV), 20 (XX), 51 (IL), 55 (VL), 60 (XL) and 100 (LL). | instruction | 0 | 90,698 | 20 | 181,396 |
Tags: brute force, combinatorics, dp, greedy, math
Correct Solution:
```
def ceildiv(a, b):
return -(-a // b)
def test_ceildiv():
assert ceildiv(6, 3) == 2
assert ceildiv(7, 3) == 3
assert ceildiv(5, 3) == 2
def brute_force(n, m):
"""Count numbers in range [0; m] equal to 4a + 9b + 49c
...for some non-negative a, b and c such that (a + b + c) <= n
"""
numbers = set()
max_c = min(n, m // 49)
for c in range(max_c + 1):
_49c = 49 * c
max_b = min(n - c, (m - _49c) // 9, 48)
for b in range(max_b + 1):
_9b_49c = 9 * b + _49c
max_a = min(n - b - c, (m - _9b_49c) // 4, 8)
for a in range(max_a + 1):
numbers.add(4 * a + _9b_49c)
assert 0 in numbers
for x in (4, 9, 49):
if m // x <= n:
assert m - (m % 49) in numbers
return len(numbers)
def brute_force_range(n, l, u):
"""Count numbers in range [l; u] equal to 4a + 9b + 49c
...for some non-negative a, b and c such that (a + b + c) <= n
"""
numbers = set()
min_c = max(0, ceildiv(l - 9 * n, 40))
max_c = min(n, u // 49)
for c in range(min_c, max_c + 1):
_49c = 49 * c
min_b = max(0, ceildiv(l - 4 * n - 45 * c, 5))
max_b = min(n - c, (u - _49c) // 9, 48)
for b in range(min_b, max_b + 1):
_9b_49c = 9 * b + _49c
min_a = max(0, ceildiv(l - _9b_49c, 4))
max_a = min(n - b - c, (u - _9b_49c) // 4, 8)
for a in range(min_a, max_a + 1):
numbers.add(4 * a + _9b_49c)
if numbers:
assert min(numbers) >= l
assert max(numbers) <= u
return len(numbers)
def test_brute_force_range():
for (u, l) in ((60, 80), (104, 599), (200, 777)):
for n in (10, 13, 15, 17, 20):
assert brute_force_range(n, u, l) == brute_force(n, l) - brute_force(n, u - 1)
def solid_interval(n):
assert n >= 18
return 27, (49 * n - 807) + 1
def test_solid_interval():
for n in 18, 19, 100, 200, 300, 1000, 5000:
begin, end = solid_interval(n)
assert brute_force_range(n, begin, end - 1) == end - begin
def main():
n = int(input())
if n < 18:
result = brute_force(n, 49 * n) # naΓ―ve solution
else:
begin, end = solid_interval(n)
assert begin < end < 49 * n
result = sum((
brute_force_range(n, 0, begin - 1),
end - begin, # == brute_force_range(n, begin, end - 1)
brute_force_range(n, end, 49 * n)
))
print(result)
if __name__ == '__main__':
main()
``` | output | 1 | 90,698 | 20 | 181,397 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.