message stringlengths 2 59.7k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 37 108k | cluster float64 20 20 | __index_level_0__ int64 74 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.
The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:
* Is it true that y is strictly larger than number x?
* Is it true that y is strictly smaller than number x?
* Is it true that y is larger than or equal to number x?
* Is it true that y is smaller than or equal to number x?
On each question the host answers truthfully, "yes" or "no".
Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".
Input
The first line of the input contains a single integer n (1 β€ n β€ 10000) β the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:
* ">" (for the first type queries),
* "<" (for the second type queries),
* ">=" (for the third type queries),
* "<=" (for the fourth type queries).
All values of x are integer and meet the inequation - 109 β€ x β€ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no").
Consequtive elements in lines are separated by a single space.
Output
Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation - 2Β·109 β€ y β€ 2Β·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).
Examples
Input
4
>= 1 Y
< 3 N
<= -3 N
> 55 N
Output
17
Input
2
> 100 Y
< -100 Y
Output
Impossible | instruction | 0 | 83,767 | 20 | 167,534 |
Tags: greedy, implementation, two pointers
Correct Solution:
```
"""
βββ βββββββ βββ βββββββ βββββββ βββ ββββββ
βββββββββββββββ βββββββββββββββββββββββββββββ
ββββββ ββββββ ββββββββββββββββββββββββββββ
ββββββ ββββββ βββββββ βββββββββ βββ βββββββ
βββββββββββββββ βββββββββββββββββ βββ βββββββ
βββ βββββββ βββ ββββββββ βββββββ βββ ββββββ
βββββββ ββββββ βββββββββββ βββ βββββββ βββββββ
ββββββββββββββ βββββββββββ ββββββββββββββββββββ
βββ βββββββββ βββββββββββββββββββ ββββββ βββ
βββ βββββββββ βββββββββββββββββββ ββββββ βββ
ββββββββββββββββββββββββββββββ ββββββββββββββββββββ
βββββββ ββββββββββββββββββββββ βββ βββββββ βββββββ
"""
m, M = -2000000000, 2000000000
n = int(input())
for i in range(n):
a, b, c = map(str, input().split())
b = int(b)
if c == "Y":
if a == ">":
m = max(b + 1, m)
elif a == ">=":
m = max(b, m)
elif a == "<":
M = min(b - 1, M)
elif a == "<=":
M = min(M, b)
else:
if a == ">":
M = min(b, M)
elif a == ">=":
M = min(b - 1, M)
elif a == "<":
m = max(m, b)
else:
m = max(b + 1, m)
if m > M:print("Impossible")
else:print(m)
``` | output | 1 | 83,767 | 20 | 167,535 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output
Output a single integer.
Examples
Input
A221033
Output
21
Input
A223635
Output
22
Input
A232726
Output
23 | instruction | 0 | 83,843 | 20 | 167,686 |
Tags: *special
Correct Solution:
```
s = input()
pr = 0
ss = 0
for i in range(1, len(s)):
if (s[i] == '0'):
pr *= 10
ss += pr
pr = int(s[i])
ss += pr
print(ss + 1)
``` | output | 1 | 83,843 | 20 | 167,687 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output
Output a single integer.
Examples
Input
A221033
Output
21
Input
A223635
Output
22
Input
A232726
Output
23 | instruction | 0 | 83,844 | 20 | 167,688 |
Tags: *special
Correct Solution:
```
bj = str(input())
points = 1
for h in range(1,7):
if int(bj[h]) > 1:
points += int(bj[h])
elif int(bj[h]) == 1:
points += 10
print(points)
``` | output | 1 | 83,844 | 20 | 167,689 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output
Output a single integer.
Examples
Input
A221033
Output
21
Input
A223635
Output
22
Input
A232726
Output
23 | instruction | 0 | 83,846 | 20 | 167,692 |
Tags: *special
Correct Solution:
```
a=list(input())
b=int(0)
for i in range(len(a)):
if a[i]=="1":
b+=10
elif a[i]=="2":
b+=2
elif a[i]=="3":
b+=3
elif a[i]=="4":
b+=4
elif a[i]=="5":
b+=5
elif a[i]=="6":
b+=6
elif a[i]=="7":
b+=7
elif a[i]=="8":
b+=8
elif a[i]=="9":
b+=9
elif a[i]=="0":
b+=0
elif a[i]=="A":
b+=1
print(int(b))
``` | output | 1 | 83,846 | 20 | 167,693 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output
Output a single integer.
Examples
Input
A221033
Output
21
Input
A223635
Output
22
Input
A232726
Output
23 | instruction | 0 | 83,847 | 20 | 167,694 |
Tags: *special
Correct Solution:
```
nums = input()
counter = 0
for i in nums:
if i == 'A':
counter += 1
elif i == '1':
counter += 10
else:
counter += int(i)
print(counter)
``` | output | 1 | 83,847 | 20 | 167,695 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output
Output a single integer.
Examples
Input
A221033
Output
21
Input
A223635
Output
22
Input
A232726
Output
23 | instruction | 0 | 83,848 | 20 | 167,696 |
Tags: *special
Correct Solution:
```
s = input()
s = s[::-1]
f = 0
for i in range(len(s)):
if s[i] == 'A':
x = 1
else:
x = int(s[i])
if x == 0:
x = 9
f += x
print(f)
``` | output | 1 | 83,848 | 20 | 167,697 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Input
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output
Output a single integer.
Examples
Input
A221033
Output
21
Input
A223635
Output
22
Input
A232726
Output
23 | instruction | 0 | 83,849 | 20 | 167,698 |
Tags: *special
Correct Solution:
```
s=input();ans=0
for i in range(0,len(s)):
if s[i]=='1':
ans+=10
elif s[i]=='A':
ans+=1
else:
ans+=int(s[i])
print(ans)
``` | output | 1 | 83,849 | 20 | 167,699 |
Provide a correct Python 3 solution for this coding contest problem.
<image>
At the request of a friend who started learning abacus, you decided to create a program to display the abacus beads. Create a program that takes a certain number as input and outputs a row of abacus beads. However, the number of digits of the abacus to be displayed is 5 digits, and the arrangement of beads from 0 to 9 is as follows using'*' (half-width asterisk),''(half-width blank), and'=' (half-width equal). It shall be expressed as.
<image>
Input
Multiple test cases are given. Up to 5 digits (integer) are given on one line for each test case.
The number of test cases does not exceed 1024.
Output
Output the abacus bead arrangement for each test case. Insert a blank line between the test cases.
Example
Input
2006
1111
Output
****
*
=====
* *
****
* ***
*****
*****
*****
=====
****
*
*****
*****
***** | instruction | 0 | 84,112 | 20 | 168,224 |
"Correct Solution:
```
f=0
while 1:
try:n=int(input())
except:break
if f:print()
f=1
a=[['*' for _ in range(5)]for _ in range(8)]
for i in range(4,-1,-1):
b=n%10
a[not b//5][i]=' '
a[b%5+3][i]=' '
n//=10
a[2]='='*5
for i in a:
print(''.join(i))
``` | output | 1 | 84,112 | 20 | 168,225 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5 = 101_2 and 14 = 1110_2 equals to 3, since 0101 and 1110 differ in 3 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 0 to n. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
Input
The input consists of multiple test cases. The first line contains one integer t (1 β€ t β€ 10 000) β the number of test cases. The following t lines contain a description of test cases.
The first and only line in each test case contains a single integer n (1 β€ n β€ 10^{18}).
Output
Output t lines. For each test case, you should output a single line with one integer β the unfairness of the contest if the rating sequence equals to 0, 1, ..., n - 1, n.
Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n = 5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):
* 000
* 001
* 010
* 011
* 100
* 101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1 + 2 + 1 + 3 + 1 = 8. | instruction | 0 | 84,390 | 20 | 168,780 |
Tags: bitmasks, greedy, math
Correct Solution:
```
x = int(input())
while x > 0:
n = int(input())
temp = bin(n)
cnt = [i for i in temp[2:] if i == '1']
print(2*n-len(cnt), sep='\n')
x -= 1
``` | output | 1 | 84,390 | 20 | 168,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5 = 101_2 and 14 = 1110_2 equals to 3, since 0101 and 1110 differ in 3 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 0 to n. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
Input
The input consists of multiple test cases. The first line contains one integer t (1 β€ t β€ 10 000) β the number of test cases. The following t lines contain a description of test cases.
The first and only line in each test case contains a single integer n (1 β€ n β€ 10^{18}).
Output
Output t lines. For each test case, you should output a single line with one integer β the unfairness of the contest if the rating sequence equals to 0, 1, ..., n - 1, n.
Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n = 5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):
* 000
* 001
* 010
* 011
* 100
* 101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1 + 2 + 1 + 3 + 1 = 8. | instruction | 0 | 84,391 | 20 | 168,782 |
Tags: bitmasks, greedy, math
Correct Solution:
```
for i in range(int(input())):
n=int(input())
print(2*n-bin(n)[2:].count("1"))
``` | output | 1 | 84,391 | 20 | 168,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5 = 101_2 and 14 = 1110_2 equals to 3, since 0101 and 1110 differ in 3 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 0 to n. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
Input
The input consists of multiple test cases. The first line contains one integer t (1 β€ t β€ 10 000) β the number of test cases. The following t lines contain a description of test cases.
The first and only line in each test case contains a single integer n (1 β€ n β€ 10^{18}).
Output
Output t lines. For each test case, you should output a single line with one integer β the unfairness of the contest if the rating sequence equals to 0, 1, ..., n - 1, n.
Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n = 5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):
* 000
* 001
* 010
* 011
* 100
* 101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1 + 2 + 1 + 3 + 1 = 8. | instruction | 0 | 84,392 | 20 | 168,784 |
Tags: bitmasks, greedy, math
Correct Solution:
```
t=int(input())
while t > 0:
t-=1
n = int(input())
d = bin(n).count('1')
print(2*n-d)
``` | output | 1 | 84,392 | 20 | 168,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5 = 101_2 and 14 = 1110_2 equals to 3, since 0101 and 1110 differ in 3 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 0 to n. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
Input
The input consists of multiple test cases. The first line contains one integer t (1 β€ t β€ 10 000) β the number of test cases. The following t lines contain a description of test cases.
The first and only line in each test case contains a single integer n (1 β€ n β€ 10^{18}).
Output
Output t lines. For each test case, you should output a single line with one integer β the unfairness of the contest if the rating sequence equals to 0, 1, ..., n - 1, n.
Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n = 5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):
* 000
* 001
* 010
* 011
* 100
* 101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1 + 2 + 1 + 3 + 1 = 8. | instruction | 0 | 84,393 | 20 | 168,786 |
Tags: bitmasks, greedy, math
Correct Solution:
```
arr=[]
for j in range(69):
arr.append(2**(j+1)-1)
lis=[0]
for j in range(60):
lis.append(arr[j]+lis[-1])
t=int(input())
for i in range(t):
n=int(input())
a=bin(n)
a=a[2:]
s=len(a)
ans=lis[s-1]+s
k=0
for j in range(1,s):
if a[j]=="1" and k==0:
k+=1
ans+=lis[s-j]
if a[j]=="0" and k==1:
ans-=lis[s-j]
k-=1
print(ans)
``` | output | 1 | 84,393 | 20 | 168,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5 = 101_2 and 14 = 1110_2 equals to 3, since 0101 and 1110 differ in 3 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 0 to n. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
Input
The input consists of multiple test cases. The first line contains one integer t (1 β€ t β€ 10 000) β the number of test cases. The following t lines contain a description of test cases.
The first and only line in each test case contains a single integer n (1 β€ n β€ 10^{18}).
Output
Output t lines. For each test case, you should output a single line with one integer β the unfairness of the contest if the rating sequence equals to 0, 1, ..., n - 1, n.
Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n = 5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):
* 000
* 001
* 010
* 011
* 100
* 101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1 + 2 + 1 + 3 + 1 = 8. | instruction | 0 | 84,394 | 20 | 168,788 |
Tags: bitmasks, greedy, math
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
x=bin(n).count('1')
s=2*n-x
print(s)
``` | output | 1 | 84,394 | 20 | 168,789 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5 = 101_2 and 14 = 1110_2 equals to 3, since 0101 and 1110 differ in 3 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 0 to n. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
Input
The input consists of multiple test cases. The first line contains one integer t (1 β€ t β€ 10 000) β the number of test cases. The following t lines contain a description of test cases.
The first and only line in each test case contains a single integer n (1 β€ n β€ 10^{18}).
Output
Output t lines. For each test case, you should output a single line with one integer β the unfairness of the contest if the rating sequence equals to 0, 1, ..., n - 1, n.
Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n = 5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):
* 000
* 001
* 010
* 011
* 100
* 101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1 + 2 + 1 + 3 + 1 = 8. | instruction | 0 | 84,395 | 20 | 168,790 |
Tags: bitmasks, greedy, math
Correct Solution:
```
import sys
input = sys.stdin.buffer.readline
from math import log,ceil
def I(): return(list(map(int,input().split())))
def sieve(n):
a=[1]*n
for i in range(2,n):
if a[i]:
for j in range(i*i,n,i):
a[j]=0
return a
def precalc():
arr=[0]*61
curr=1
for i in range(61):
arr[i]=curr
curr*=2
return arr
powers=precalc()
for __ in range(int(input())):
m=int(input())
n=ceil(log(m,2))+1
s=0
for i in range(n):
pow2=powers[i]
# if m%pow2:
# currs=m//pow2
# else:
# currs=m//pow2+1
# print(pow2)
s+=(m//pow2)
print(s)
``` | output | 1 | 84,395 | 20 | 168,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5 = 101_2 and 14 = 1110_2 equals to 3, since 0101 and 1110 differ in 3 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 0 to n. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
Input
The input consists of multiple test cases. The first line contains one integer t (1 β€ t β€ 10 000) β the number of test cases. The following t lines contain a description of test cases.
The first and only line in each test case contains a single integer n (1 β€ n β€ 10^{18}).
Output
Output t lines. For each test case, you should output a single line with one integer β the unfairness of the contest if the rating sequence equals to 0, 1, ..., n - 1, n.
Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n = 5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):
* 000
* 001
* 010
* 011
* 100
* 101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1 + 2 + 1 + 3 + 1 = 8. | instruction | 0 | 84,396 | 20 | 168,792 |
Tags: bitmasks, greedy, math
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
b = bin(n)[2:]
b = list(b)
print(2*n-b.count("1"))
``` | output | 1 | 84,396 | 20 | 168,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of 5 = 101_2 and 14 = 1110_2 equals to 3, since 0101 and 1110 differ in 3 positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from 0 to n. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
Input
The input consists of multiple test cases. The first line contains one integer t (1 β€ t β€ 10 000) β the number of test cases. The following t lines contain a description of test cases.
The first and only line in each test case contains a single integer n (1 β€ n β€ 10^{18}).
Output
Output t lines. For each test case, you should output a single line with one integer β the unfairness of the contest if the rating sequence equals to 0, 1, ..., n - 1, n.
Example
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
Note
For n = 5 we calculate unfairness of the following sequence (numbers from 0 to 5 written in binary with extra leading zeroes, so they all have the same length):
* 000
* 001
* 010
* 011
* 100
* 101
The differences are equal to 1, 2, 1, 3, 1 respectively, so unfairness is equal to 1 + 2 + 1 + 3 + 1 = 8. | instruction | 0 | 84,397 | 20 | 168,794 |
Tags: bitmasks, greedy, math
Correct Solution:
```
tests=int(input())
for _ in range(tests):
n=int(input())
x=2
a=[0]*11
y=10
t=1
ans=0
while(n+x//2>=x):
z=(n+x//2)//x
ans+=t*z
t+=1
x=pow(2,t)
print(ans)
``` | output | 1 | 84,397 | 20 | 168,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18 | instruction | 0 | 84,476 | 20 | 168,952 |
Tags: brute force, math, number theory
Correct Solution:
```
from sys import stdin
input = stdin.readline
T = int(input())
for _ in range(T):
N = int(input())
cnt = 0
for i in range(1, 10):
val = ''
while True:
val += str(i)
if int(val) > N:
break
cnt += 1
print(cnt)
``` | output | 1 | 84,476 | 20 | 168,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18 | instruction | 0 | 84,477 | 20 | 168,954 |
Tags: brute force, math, number theory
Correct Solution:
```
for _ in range(int(input())):
n = int(input())
ans = 0
s = str(n)
k = len(s)
last = '1' + '0'*(k-1)
ans = ans + (k-1)*9
for i in range(1,10):
if int(str(i)*k)<=n:
ans = ans + 1
print(ans)
``` | output | 1 | 84,477 | 20 | 168,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18 | instruction | 0 | 84,478 | 20 | 168,956 |
Tags: brute force, math, number theory
Correct Solution:
```
t=int(input())
while(t!=0):
t=t-1
n=int(input())
s=str(n)
k=len(s)
s1=str(1)
c=9*(k-1)
for i in range(k-1):
s1+='1'
#print(s1)
n1=int(s1)
j=1
while(n1*j<=n):
j=j+1
c=c+1
print(c)
``` | output | 1 | 84,478 | 20 | 168,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18 | instruction | 0 | 84,479 | 20 | 168,958 |
Tags: brute force, math, number theory
Correct Solution:
```
# main.py
# D <--~~~ __ _
# U o'')}____//
# O `_/ )
# N (_(_/-(_/
# G ~~~~~~~~~~~~~~~~~-->
import math
MOD = 10**9 + 7
sv = math.sqrt(5)
fip = (1 + sv)/2
fin = (1 - sv)/2
F = lambda i: (fip**i - fin**i)//sv
L = lambda i: (fip**i + fin**i)//1
ln = len
# prime factors
def pfs(n):
fs = []
i = 2
while i*i <= n:
while n%i == 0:
n = n//i
factors.append(i)
i += 1
return (factors + [n,]*(n!=1))[::-1]
def in_var(to: type):
return to(input())
def in_arr(to: type):
return list(
map(to, input().split())
)
def in_ivar():
return in_var(int)
def in_iarr():
return in_arr(int)
# Code goes here
def solve():
n = in_ivar()
l = len(str(n))
count = 9*(len(str(n))-1)
for i in range(1, 10):
if str(i)*l <= str(n):
count += 1
print(count)
def main():
for _ in range(in_ivar()):
# print(f"Case #{_+1}:", solve())
solve()
return
if __name__ == "__main__":
main()
``` | output | 1 | 84,479 | 20 | 168,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18 | instruction | 0 | 84,480 | 20 | 168,960 |
Tags: brute force, math, number theory
Correct Solution:
```
from math import floor, log10
for _ in range(int(input())):
n = int(input())
nd = floor(log10(n)) + 1
c = (nd - 1) * 9
c += n // int("1" * nd)
print(c)
``` | output | 1 | 84,480 | 20 | 168,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18 | instruction | 0 | 84,481 | 20 | 168,962 |
Tags: brute force, math, number theory
Correct Solution:
```
t=int(input())
for i in range(t):
count=0
n=int(input())
l=len(str(n))
if(n<=9):
count=n
else:
div=['1']*l
s="".join(div)
count=count+(l-1)*9
count=count+(n//int(s))
print(count)
``` | output | 1 | 84,481 | 20 | 168,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18 | instruction | 0 | 84,482 | 20 | 168,964 |
Tags: brute force, math, number theory
Correct Solution:
```
n=int(input())
for i in range(n):
t=input()
s=(len(t)-1)*9
b=''
for j in t:
b+='1'
f=(int(t))//(int(b))
if(len(t)==1):
print(t)
else:
print(f+s)
``` | output | 1 | 84,482 | 20 | 168,965 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18 | instruction | 0 | 84,483 | 20 | 168,966 |
Tags: brute force, math, number theory
Correct Solution:
```
import math
for _ in range(int(input())):
n=int(input())
s=len(str(n))
a=str(n)
b=int(a[0])
c=0
j=10**(s-1)
while j>0:
c=c+b*j
j=j//10
k=9*(s-1)
k=k+b-1
if n>=int(c):
k=k+1
print(k)
``` | output | 1 | 84,483 | 20 | 168,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18
Submitted Solution:
```
for t in range(int(input())):
n = int(input())
n2 = n
s = 0
while n >= 10:
s += min(n, 9)
n //= 10
for i in range(1, 10):
if int(str(i) * len(str(n2))) <= n2:
s += 1
print(s)
``` | instruction | 0 | 84,484 | 20 | 168,968 |
Yes | output | 1 | 84,484 | 20 | 168,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
p=len(str(n))
count=(p-1)*9
for i in range(1,10):
if int(str(i)*p)>n:
break
else:
count+=1
print(count)
``` | instruction | 0 | 84,485 | 20 | 168,970 |
Yes | output | 1 | 84,485 | 20 | 168,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18
Submitted Solution:
```
import sys
# sys.stdin = open('input.txt','r')
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
ans = 0
for i in range(9):
cur = 1
for j in range(i):
cur = cur * 10 + 1
start = cur
for j in range(9):
if start <= n:
ans += 1
start += cur
print(ans)
``` | instruction | 0 | 84,486 | 20 | 168,972 |
Yes | output | 1 | 84,486 | 20 | 168,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18
Submitted Solution:
```
import math
t = int(input())
def count(L, R):
temp = 0
result = 0
n = int(math.log10(R) + 1)
for i in range(0, n):
temp = temp * 10 + 1
for j in range(1, 10):
if L <= (temp * j) and (temp * j) <= R:
result += 1
return result
def solve():
n = int(input())
print(count(1, n))
while t != 0:
solve()
t -= 1
``` | instruction | 0 | 84,487 | 20 | 168,974 |
Yes | output | 1 | 84,487 | 20 | 168,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18
Submitted Solution:
```
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n = int(input())
i = n
front = 0
same = True
cnt = 0
while i > 0:
if i // 10 == 0:
front = i
elif not ((i % 10) == (i // 10) % 10):
same = False
i = i // 10
cnt += 1
if n < 10:
print(n)
elif same:
print(9 * (cnt-1) + n % 10)
else:
print(9 * (cnt-1) + front - 1)
``` | instruction | 0 | 84,488 | 20 | 168,976 |
No | output | 1 | 84,488 | 20 | 168,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18
Submitted Solution:
```
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict,Counter
def ceil(a,b):
return (a+b-1)//b
for _ in range(ri()):
n=ri()
x=n//10
x-=1
if n>9:
cnt=9
else:
print(n)
continue
cnt=9+x
if len(set(str(n)))==1:
cnt+=1
print(cnt)
``` | instruction | 0 | 84,489 | 20 | 168,978 |
No | output | 1 | 84,489 | 20 | 168,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18
Submitted Solution:
```
#from _typeshed import SupportsKeysAndGetItem
import sys
#sys.stdin=open("input.txt","r");
#sys.stdout=open("output.txt","w")
def ans():
n=int(input())
if n<10:
print(n)
return
if n==10:
print(9)
return
if n==100:
print(18)
return
if n<100:
tempo=9
bola=n//10
tempo=tempo+bola-1
ele=n%10
if ele>=bola:
print(tempo+1)
else:
print(tempo)
return
digit=str(n)
first=digit[0]
k=len(digit)
take=n//100
tempo=18
tempo=tempo+take-1
first=first*k
if int(first)<=n:
print(tempo+1)
else:
print(tempo)
for _ in range(int(input())):
ans()
``` | instruction | 0 | 84,490 | 20 | 168,980 |
No | output | 1 | 84,490 | 20 | 168,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let's call a positive integer n ordinary if in the decimal notation all its digits are the same. For example, 1, 2 and 99 are ordinary numbers, but 719 and 2021 are not ordinary numbers.
For a given number n, find the number of ordinary numbers among the numbers from 1 to n.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer n (1 β€ n β€ 10^9).
Output
For each test case output the number of ordinary numbers among numbers from 1 to n.
Example
Input
6
1
2
3
4
5
100
Output
1
2
3
4
5
18
Submitted Solution:
```
t=int(input())
while(t):
n=int(input())
if(n>0 and n<=99):
print(n)
if(n>99):
print("18")
t=t-1
``` | instruction | 0 | 84,491 | 20 | 168,982 |
No | output | 1 | 84,491 | 20 | 168,983 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image> | instruction | 0 | 84,555 | 20 | 169,110 |
Tags: math, number theory
Correct Solution:
```
import sys
n = sys.stdin.readline().split("\n")[0]
n = int(n[-2:])
if n % 4 == 0:
print(4)
else:
print(0)
``` | output | 1 | 84,555 | 20 | 169,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image> | instruction | 0 | 84,556 | 20 | 169,112 |
Tags: math, number theory
Correct Solution:
```
def f(n,till):
i=1
#x=n**6
#hold=n**4%5
while i<till:
#x=n**i%5
#print(str(n**i)+" "+str(n**i%5))
i+=1
return
#print("Ans = " + str(f(2,10)))
two={1:2,2:4,3:3,0:1}
three={1:3,2:4,3:2,0:1}
four={1:4,0:1}
s=input()
s=int(s[-2:])
sumx=1+two[s%4]+three[s%4]+four[s%2]
print(sumx%5)
``` | output | 1 | 84,556 | 20 | 169,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image> | instruction | 0 | 84,557 | 20 | 169,114 |
Tags: math, number theory
Correct Solution:
```
n=int(input())
if(n==0):
print(4)
else:
r=n%4
if(r==0):
print(4)
else:
print(0)
``` | output | 1 | 84,557 | 20 | 169,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image> | instruction | 0 | 84,558 | 20 | 169,116 |
Tags: math, number theory
Correct Solution:
```
n = int(input())
a = n%4
b = n%4
c = n%2
print((1+2**a+3**b+4**c)%5)
``` | output | 1 | 84,558 | 20 | 169,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image> | instruction | 0 | 84,559 | 20 | 169,118 |
Tags: math, number theory
Correct Solution:
```
print('4' if int(input())%4==0 else '0')
``` | output | 1 | 84,559 | 20 | 169,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image> | instruction | 0 | 84,560 | 20 | 169,120 |
Tags: math, number theory
Correct Solution:
```
n=input()
n=int(n[-2:])
if n%4==0:
print(4)
else:
print(0)
``` | output | 1 | 84,560 | 20 | 169,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image> | instruction | 0 | 84,561 | 20 | 169,122 |
Tags: math, number theory
Correct Solution:
```
n=int(input())
if n == 0:
print ("4")
else:
if n%4 == 1:
print ("0")
elif n%4 == 2:
print ("0")
elif n%4 == 3:
print ("0")
elif n%4 == 0:
print ("4")
pass
``` | output | 1 | 84,561 | 20 | 169,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image> | instruction | 0 | 84,562 | 20 | 169,124 |
Tags: math, number theory
Correct Solution:
```
s = input()[-2:]
print(4 if int(s) % 4 == 0 else 0)
``` | output | 1 | 84,562 | 20 | 169,125 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image>
Submitted Solution:
```
m=(input())
n=int(m[(len(m)-2):])
n=n%4
sol=0
x=pow(2,n,5)
sol=(sol%5+x%5)%5
x=pow(3,n,5)
sol=(sol%5+x%5)%5
x=pow(4,n,5)
sol=(sol%5+x%5)%5
sol=(sol%5+1)%5
print(sol)
``` | instruction | 0 | 84,563 | 20 | 169,126 |
Yes | output | 1 | 84,563 | 20 | 169,127 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image>
Submitted Solution:
```
a = 1
b = [1, 2, 4, 3]
c = [1, 3, 4, 2]
d = [1, 4]
n = int(input())
print((1 + b[n % 4] + c[n % 4] + d[n % 2]) % 5)
``` | instruction | 0 | 84,564 | 20 | 169,128 |
Yes | output | 1 | 84,564 | 20 | 169,129 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image>
Submitted Solution:
```
n=int(input())
if n%4!=0:
print(0)
else:
print(4)
``` | instruction | 0 | 84,565 | 20 | 169,130 |
Yes | output | 1 | 84,565 | 20 | 169,131 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image>
Submitted Solution:
```
n = int(input().strip())
if n == 0:
print(4)
else:
k = 0
if n % 4 == 0:
k += 14
elif n % 4 == 1:
k += 10
elif n % 4 == 2:
k += 20
else:
k += 20
print(k % 5)
``` | instruction | 0 | 84,566 | 20 | 169,132 |
Yes | output | 1 | 84,566 | 20 | 169,133 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image>
Submitted Solution:
```
n=(input(''))
def check(a):
res=0
b=len(a)
for i in range(b):
res=(res*10+int(a[i]))%1000000007
return res%1000000007
def expo(x,n):
total=1
while n>0:
if n%2==1:
total=(total*x)%5
else:
x=(x*x)%5
n=n/2
return total
p=check(n)
#print(p)
z=0
z=z+expo(2,p)%5
z=z+expo(3,p)%5
z=z+expo(4,p)%5
#print(z)
z=z+1
#print(z)
z=z%5
print(z)# your code goes here
``` | instruction | 0 | 84,567 | 20 | 169,134 |
No | output | 1 | 84,567 | 20 | 169,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image>
Submitted Solution:
```
print(0 if int(input()[-2:]) % 2 else 4)
``` | instruction | 0 | 84,568 | 20 | 169,136 |
No | output | 1 | 84,568 | 20 | 169,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image>
Submitted Solution:
```
print(4 if int(input()[-1]) in [4, 8] else 0)
``` | instruction | 0 | 84,569 | 20 | 169,138 |
No | output | 1 | 84,569 | 20 | 169,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5
for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Input
The single line contains a single integer n (0 β€ n β€ 10105). The number doesn't contain any leading zeroes.
Output
Print the value of the expression without leading zeros.
Examples
Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note
Operation x mod y means taking remainder after division x by y.
Note to the first sample:
<image>
Submitted Solution:
```
import sys
input = sys.stdin.readline
n = input()
ans = [4,0,2,0]
if(len(n)<2):
n = int(n)
else:
n = int(n[-2:])
print(ans[n%4])
``` | instruction | 0 | 84,570 | 20 | 169,140 |
No | output | 1 | 84,570 | 20 | 169,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A wavy number is such positive integer that for any digit of its decimal representation except for the first one and the last one following condition holds: the digit is either strictly larger than both its adjacent digits or strictly less than both its adjacent digits. For example, numbers 35270, 102, 747, 20 and 3 are wavy and numbers 123, 1000 and 2212 are not.
The task is to find the k-th smallest wavy number r that is divisible by n for the given integer values n and k.
You are to write a program that will find the value of r if it doesn't exceed 1014.
Input
The only line of input contains two integers n and k, separated by a single space (1 β€ n, k β€ 1014).
Output
Your task is to output the only integer r β the answer to the given problem. If such number does not exist or it is larger than 1014, then print "-1" (minus one without the quotes) instead.
Examples
Input
123 4
Output
1845
Input
100 1
Output
-1
Input
97461 457
Output
1805270103
Note
The values of the first four wavy numbers that are divisible by n for the first sample are: 492, 615, 738 and 1845.
Submitted Solution:
```
def wn(arr):
for i in range(1,len(arr)-1):
if arr[i-1]<arr[i]>arr[i+1] or arr[i-1]>arr[i]<arr[i+1]:
continue
else:
return 0
return 1
l=list(map(int,input().split()))
arr=l[0]
k=l[1]
print(arr,k)
n=arr
c=0
i=1
if n%10==0:
print(-1)
else:
while c<k and int(n)<(10**14):
n=str(arr*i)
a=[int(x) for x in n]
if wn(a):
c+=1
i+=1
if c==k:
print(n)
else:
print(-1)
``` | instruction | 0 | 84,571 | 20 | 169,142 |
No | output | 1 | 84,571 | 20 | 169,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A wavy number is such positive integer that for any digit of its decimal representation except for the first one and the last one following condition holds: the digit is either strictly larger than both its adjacent digits or strictly less than both its adjacent digits. For example, numbers 35270, 102, 747, 20 and 3 are wavy and numbers 123, 1000 and 2212 are not.
The task is to find the k-th smallest wavy number r that is divisible by n for the given integer values n and k.
You are to write a program that will find the value of r if it doesn't exceed 1014.
Input
The only line of input contains two integers n and k, separated by a single space (1 β€ n, k β€ 1014).
Output
Your task is to output the only integer r β the answer to the given problem. If such number does not exist or it is larger than 1014, then print "-1" (minus one without the quotes) instead.
Examples
Input
123 4
Output
1845
Input
100 1
Output
-1
Input
97461 457
Output
1805270103
Note
The values of the first four wavy numbers that are divisible by n for the first sample are: 492, 615, 738 and 1845.
Submitted Solution:
```
l = input().split()
n,k = [int(s) for s in l]
i = 1
l = n*i
ctr = 0
while(True):
l = n*i
i+=1
flag = 0
m = str(l)
if m.count('0')==(len(m)-1):
print("-1")
break
for p in range(1,len(m)-1):
if int(m[p])>int(m[p+1]) and int(m[p])>int(m[p-1]):
continue
elif int(m[p])<int(m[p+1]) and int(m[p])<int(m[p-1]):
continue
else:
flag=1
if flag==0:
ctr+=1
if ctr==k:
print(m)
break
``` | instruction | 0 | 84,572 | 20 | 169,144 |
No | output | 1 | 84,572 | 20 | 169,145 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.