text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers yi, he should ask the questions about.
Input
A single line contains number n (1 β€ n β€ 103).
Output
Print the length of the sequence of questions k (0 β€ k β€ n), followed by k numbers β the questions yi (1 β€ yi β€ n).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
Examples
Input
4
Output
3
2 4 3
Input
6
Output
4
2 4 3 5
Note
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
Submitted Solution:
```
def sieve(a, b):
m = []
if (b != 1):
if (a == 1):
a += 1
primes = [1] * (b + 1)
primes[0] = 0
primes[1] = 0
for i in range(2, b + 1):
if (primes[i] == 1):
for j in range(2 * i, b + 1, i):
primes[j] = 0
for i in range(a, b + 1):
if (primes[i] == 1):
m.append(i)
return m
elif (a == 1) and (b == 1):
return
n = int(input())
k = 0
ans = []
if n == 1:
print(k)
else:
mas = sieve(2, n)
for i in mas:
j = i
ans.append(j)
k += 1
while (n >= j ** 2):
j *= j
ans.append(j)
k += 1
print(k)
print(*ans)
```
No
| 105,700 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers yi, he should ask the questions about.
Input
A single line contains number n (1 β€ n β€ 103).
Output
Print the length of the sequence of questions k (0 β€ k β€ n), followed by k numbers β the questions yi (1 β€ yi β€ n).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
Examples
Input
4
Output
3
2 4 3
Input
6
Output
4
2 4 3 5
Note
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
Submitted Solution:
```
__author__ = 'dwliv_000'
def isPrime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
n=int(input())
c={}
c[1]=[]
c[2]=[2]
c[3]=[2,3]
c[4]=[2,3,4]
c[5]=[2,4,3,5]
k=6
while k<=n:
t=[]
for j in range(2,k+1):
if(j%k==0)and(isPrime(j)):
t.append(j)
c[k]=c[k-1]+t
k=k+1
print(len(c[n]))
for j in range(len(c[n])):
print(c[n][j],end=' ')
```
No
| 105,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers yi, he should ask the questions about.
Input
A single line contains number n (1 β€ n β€ 103).
Output
Print the length of the sequence of questions k (0 β€ k β€ n), followed by k numbers β the questions yi (1 β€ yi β€ n).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
Examples
Input
4
Output
3
2 4 3
Input
6
Output
4
2 4 3 5
Note
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
Submitted Solution:
```
n = int(input())
if n == 1:
print(0)
arr = [i for i in range(n + 1)]
flags = [0 for i in range(n + 1)]
primes = []
for i in range(2, n + 1):
if flags[i]:
continue
primes.append(i)
for j in range(i * 2, n + 1, i):
flags[j] = 1
ans = set()
for number in primes:
k = 1
while number ** k <= n:
ans.add(number * k)
k += 1
print(len(ans))
print(*ans)
```
No
| 105,702 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers yi, he should ask the questions about.
Input
A single line contains number n (1 β€ n β€ 103).
Output
Print the length of the sequence of questions k (0 β€ k β€ n), followed by k numbers β the questions yi (1 β€ yi β€ n).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
Examples
Input
4
Output
3
2 4 3
Input
6
Output
4
2 4 3 5
Note
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
Submitted Solution:
```
def gen_prime():
num = [0 for i in range(10**3+1)]
num[2] = 1
num[3] = 1
for i in range(4, 10**3+1):
isprime = True
for j in range(2, int(i**0.5)+1):
if num[j]:
if not i%j:
isprime = False
break
if isprime:
num[i] = 1
prime = []
for i in range(2, 10**3+1):
if num[i]:
prime.append(i)
return prime
n = int(input())
prime = gen_prime()
div = []; high_div = 1
i = 0
while i < len(prime):
for j in range(1, 10):
if prime[i]**j > n:
break
div.append(prime[i]**j)
if n%(prime[i]**j):
break
elif high_div < prime[i]**j:
high_div = prime[i]**j
i += 1
# if high_div*prime[i] > n:
# if prime[i] < n:
# div.append(prime[i])
# break
print(len(div))
for i in range(len(div)):
print(div[i], end = " ")
print()
```
No
| 105,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Tags: implementation, strings
Correct Solution:
```
s = str(input())
ll = sum(map(str.islower, s))
ul = sum(map(str.isupper, s))
if ul > ll:
print(s.upper())
else:
print(s.lower())
```
| 105,704 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Tags: implementation, strings
Correct Solution:
```
a = input()
l = len(a)
count = 0
for i in a:
if i.isupper():
count += 1
if count <= int(l/2):
print(a.lower())
else:
print(a.upper())
```
| 105,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Tags: implementation, strings
Correct Solution:
```
s=list(input())
p=""
l=[]
x=[]
for i in range(len(s)):
if s[i]==s[i].upper():
l.append(s[i])
elif s[i]==s[i].lower():
x.append(s[i])
if len(l)>len(x):
print(p.join(s).upper())
else:
print(p.join(s).lower())
```
| 105,706 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Tags: implementation, strings
Correct Solution:
```
word = input()
uppercases = 0
lowercases = 0
for letter in word:
if letter.upper() == letter:
uppercases += 1
else:
lowercases += 1
if uppercases > lowercases:
print(word.upper())
else:
print(word.lower())
```
| 105,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Tags: implementation, strings
Correct Solution:
```
s=input();print(s.upper() if sum(1 for c in s if c.isupper())>sum(1 for c in s if c.islower())else s.lower())
```
| 105,708 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Tags: implementation, strings
Correct Solution:
```
w = input()
upp = 0
low = 0
for i in w:
if i.isupper() == True:
upp += 1
else:
low += 1
if upp <= low:
print(w.lower())
else:
print(w.upper())
```
| 105,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Tags: implementation, strings
Correct Solution:
```
n=input()
l=0
u=0
for i in range(len(n)):
if n[i].islower():
l+=1
elif n[i].isupper():
u+=1
if l>u:
print(n.lower())
elif l<u:
print(n.upper())
else:
print(n.lower())
```
| 105,710 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Tags: implementation, strings
Correct Solution:
```
word = str(input())
sumUppercaseLetters = 0
sumLowercaseLetters = 0
for i in word:
if i.isupper():
sumUppercaseLetters += 1
elif i.islower():
sumLowercaseLetters += 1
if sumUppercaseLetters > sumLowercaseLetters:
print(word.upper())
elif sumLowercaseLetters > sumUppercaseLetters:
print(word.lower())
else:
print(word.lower())
```
| 105,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Submitted Solution:
```
s = input()
length = len(s)
c = 0
a = 0
for i in range(length):
if s[i].isupper():
c += 1
else:
a += 1
if a >= c:
s = s.lower()
print(s)
else:
s = s.upper()
print(s)
```
Yes
| 105,712 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Submitted Solution:
```
string=input()
count1=0
count2=0
for i in string:
if(i.islower()):
count1=count1+1
elif(i.isupper()):
count2=count2+1
if count1>=count2:
print(string.lower())
elif count1<count2:
print(string.upper())
```
Yes
| 105,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Submitted Solution:
```
s = input()
n = len(s)
c = sum([1 for i in s if i.isupper() == True])
if(c > (n-c)):
print(s.upper())
else:
print(s.lower())
```
Yes
| 105,714 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Submitted Solution:
```
n=input()
c1=0
c2=0
for i in n:
if i.isupper():
c1=c1+1
if i.islower():
c2=c2+1
if c1>c2:
print(n.upper())
else:
print(n.lower())
```
Yes
| 105,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Submitted Solution:
```
print(input().lower())
```
No
| 105,716 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Submitted Solution:
```
word = input()
assert len(word) <= 100
print(word.lower())
```
No
| 105,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Submitted Solution:
```
alphabet = "abcdefghijklmnopqrstuvwxyz"
word = input()
if sum([c in alphabet for c in word]) < (len(word)+1) / 2:
print((word.upper()))
else:
print((word.lower()))
```
No
| 105,718 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP β with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input
The first line contains a word s β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output
Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Examples
Input
HoUse
Output
house
Input
ViP
Output
VIP
Input
maTRIx
Output
matrix
Submitted Solution:
```
a=str(input())
cnt=0
d=0
for i in a:
if i>='A' and i<='Z':
cnt+=1
elif i>='a' and i<='z':
d+=1
print(cnt)
print(d)
if d>cnt:
print(a.lower())
elif cnt>d:
print(a.upper())
elif d==cnt:
print(a.lower())
```
No
| 105,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.
The New Year tree is an undirected tree with n vertices and root in the vertex 1.
You should process the queries of the two types:
1. Change the colours of all vertices in the subtree of the vertex v to the colour c.
2. Find the number of different colours in the subtree of the vertex v.
Input
The first line contains two integers n, m (1 β€ n, m β€ 4Β·105) β the number of vertices in the tree and the number of the queries.
The second line contains n integers ci (1 β€ ci β€ 60) β the colour of the i-th vertex.
Each of the next n - 1 lines contains two integers xj, yj (1 β€ xj, yj β€ n) β the vertices of the j-th edge. It is guaranteed that you are given correct undirected tree.
The last m lines contains the description of the queries. Each description starts with the integer tk (1 β€ tk β€ 2) β the type of the k-th query. For the queries of the first type then follows two integers vk, ck (1 β€ vk β€ n, 1 β€ ck β€ 60) β the number of the vertex whose subtree will be recoloured with the colour ck. For the queries of the second type then follows integer vk (1 β€ vk β€ n) β the number of the vertex for which subtree you should find the number of different colours.
Output
For each query of the second type print the integer a β the number of different colours in the subtree of the vertex given in the query.
Each of the numbers should be printed on a separate line in order of query appearing in the input.
Examples
Input
7 10
1 1 1 1 1 1 1
1 2
1 3
1 4
3 5
3 6
3 7
1 3 2
2 1
1 4 3
2 1
1 2 5
2 1
1 6 4
2 1
2 2
2 3
Output
2
3
4
5
1
2
Input
23 30
1 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 6
1 2
1 3
1 4
2 5
2 6
3 7
3 8
4 9
4 10
4 11
6 12
6 13
7 14
7 15
7 16
8 17
8 18
10 19
10 20
10 21
11 22
11 23
2 1
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 4
1 12 1
1 13 1
1 14 1
1 15 1
1 16 1
1 17 1
1 18 1
1 19 1
1 20 1
1 21 1
1 22 1
1 23 1
2 1
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 4
Output
6
1
3
3
2
1
2
3
5
5
1
2
2
1
1
1
2
3
Submitted Solution:
```
def dfs_list(graph, start):
visited = []
stack = [start]
while stack:
vertex = stack.pop()
if vertex not in visited:
visited.append(vertex)
stack.extend(graph[vertex])
else:
visited.append(vertex)
return visited
def get_nodes(tree_list, node):
temp = tree_list[:]
tree_list.reverse()
i, j = temp.index(node), len(temp) - 1 - tree_list.index(node)
stack = set()
if i == j:
stack.add(node)
return stack
for k in range(i, j):
if temp[k] not in stack:
stack.add(temp[k])
return stack
def change_colors(colors, tree_list, node, color):
stack = get_nodes(tree_list, node)
for element in stack:
colors[element-1] = color
return colors
def get_number_of_colors(tree_list, node, colors):
stack = get_nodes(tree_list, node)
dif_colors = set()
for element in stack:
if colors[element-1] not in dif_colors:
dif_colors.add(colors[element-1])
return len(dif_colors)
n, m = map(int, input().split())
tree = {}
index = 1
colors = []
for color in input().split():
tree[index] = []
colors.append(int(color))
index += 1
for i in range(n-1):
key, value = map(int, input().split())
tree[key].append(value)
tree[value].append(key)
list_tree = dfs_list(tree, 1)
for i in range(m):
command = [int(item) for item in input().split()]
if len(command) == 3:
colors = change_colors(colors, list_tree, command[1], command[2])
else:
print(get_number_of_colors(list_tree, command[1], colors))
```
No
| 105,720 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Tags: dp, implementation, math, probabilities
Correct Solution:
```
import math
n = int(input())
Y = [0.0]
Z = [0.0]
Y = Y + [float(y) for y in input().split()]
Z = Z + [float(z) for z in input().split()]
S = [y + z for y, z in zip(Y, Z)]
CS = [0 for i in range(n+1)]
for i in range(1, n+1):
CS[i] = CS[i-1] + S[i]
A = [0 for i in range(0, n+1)]
B = [0 for i in range(0, n+1)]
CA = 0
for e in range(1, n+1):
dis = (CS[e] - 2 * CA) ** 2 + 4 * (S[e] * CA - Y[e])
if abs(dis) < 1e-12:
dis = 0
# print(dis)
A[e] = CS[e] - 2*CA + math.sqrt(dis)
A[e] /= 2
CA += A[e]
B[e] = S[e] - A[e]
# print(Y, Z, S)
# print(CS)
print(' '.join(['%.7f' % a for a in A[1:]]))
print(' '.join(['%.7f' % a for a in B[1:]]))
```
| 105,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Tags: dp, implementation, math, probabilities
Correct Solution:
```
def tle():
k=0
while (k>=0):
k+=1
def quad(a, b, c):
disc = (b**2-4*a*c)
if disc<0:
disc=0
disc = (disc)**0.5
return ((-b+disc)/2/a, (-b-disc)/2/a)
x = int(input())
y = list(map(float, input().strip().split(' ')))
z = list(map(float, input().strip().split(' ')))
py = [0, y[0]]
for i in range(1, x):
py.append(py[-1]+y[i])
z.reverse()
pz = [0, z[0]]
for i in range(1, x):
pz.append(pz[-1]+z[i])
pz.reverse()
k = []
for i in range(0, x+1):
k.append(py[i]+1-pz[i])
l = [0]
for i in range(x):
l.append(k[i+1]-k[i])
#a[i]+b[i]
s1 = 0
s2 = 0
avals = []
bvals = []
for i in range(1, x+1):
a, b = (quad(-1, s1+l[i]-s2, (s1+l[i])*s2-py[i]))
if b<0 or l[i]-b<0:
a, b = b, a
if a<0 and b<0:
a=0
b=0
bvals.append(b)
avals.append(l[i]-b)
s1+=avals[-1]
s2+=bvals[-1]
for i in range(len(avals)):
if abs(avals[i])<=10**(-10):
avals[i] = 0
if abs(bvals[i])<=10**(-10):
bvals[i] = 0
print(' '.join([str(i) for i in avals]))
print(' '.join([str(i) for i in bvals]))
```
| 105,722 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Tags: dp, implementation, math, probabilities
Correct Solution:
```
n = int(input())
mx = list(map(float, input().split()))
mn = list(map(float, input().split())) + [0]
for i in range(1, n):
mx[i] += mx[i - 1]
for i in range(n - 2, -1, -1):
mn[i] += mn[i + 1]
a, b = [0] * (n + 1), [0] * (n + 1)
for i in range(n):
p = mx[i]
s = 1 + mx[i] - mn[i + 1]
a[i] = (s - max(s * s - 4 * p, 0) ** 0.5) / 2
b[i] = (s + max(s * s - 4 * p, 0) ** 0.5) / 2
print(*(a[i] - a[i - 1] for i in range(n)))
print(*(b[i] - b[i - 1] for i in range(n)))
```
| 105,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Tags: dp, implementation, math, probabilities
Correct Solution:
```
n = int(input())
M = list(map(float, input().split()))
m = list(map(float, input().split()))
a = []
sa = [0]
b = []
sb = [0]
for i in range(0, n):
p = sa[i] - sb[i] - M[i] - m[i]
q = M[i] - sa[i]*(M[i] + m[i])
d = p*p - 4*q
if d < 0:
d = -d
a.append((-p + (d ** 0.5))/2)
b.append(M[i] + m[i] - a[i])
sa.append(sa[i] + a[i])
sb.append(sb[i] + b[i])
for i in range(0, n-1):
print(a[i], ' ', end='')
print(a[-1])
for i in range(0, n-1):
print(b[i], ' ', end='')
print(b[-1])
```
| 105,724 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Tags: dp, implementation, math, probabilities
Correct Solution:
```
n = int(input())
maxs = list(map(float, input().split()))
mins = list(map(float, input().split()))
d1s, d2s = [], []
cd1sum, cd2sum = 0, 0
for i in range(n):
z = mins[i]+maxs[i]
c = cd2sum
d = cd1sum
s = mins[i]
b = d-z-c
c = z-d*z-s
disc = max(0, (b**2-4*c))**0.5
ans = min( (-b + disc)/(2.0), (-b-disc)/(2.0))
d1s.append(ans)
d2s.append(z-ans)
cd1sum += d1s[-1]
cd2sum += d2s[-1]
print(' '.join(map(str, d1s)))
print(' '.join(map(str, d2s)))
```
| 105,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Submitted Solution:
```
def quad(a, b, c):
disc = (b**2-4*a*c)
if disc<0:
disc=0
disc = (disc)**0.5
return ((-b+disc)/2/a, (-b-disc)/2/a)
x = int(input())
y = list(map(float, input().strip().split(' ')))
z = list(map(float, input().strip().split(' ')))
py = [0, y[0]]
for i in range(1, x):
py.append(py[-1]+y[i])
z.reverse()
pz = [0, z[0]]
for i in range(1, x):
pz.append(pz[-1]+z[i])
pz.reverse()
k = []
for i in range(0, x+1):
k.append(py[i]+1-pz[i])
l = [0]
for i in range(x):
l.append(k[i+1]-k[i])
#a[i]+b[i]
s1 = 0
s2 = 0
avals = []
bvals = []
for i in range(1, x+1):
a, b = (quad(-1, s1+l[i]-s2, (s1+l[i])*s2-py[i]))
if b<0:
a, b = b, a
bvals.append(b)
avals.append(l[i]-b)
s1+=avals[-1]
s2+=bvals[-1]
for i in range(len(avals)):
if avals[i]<=10**(-10):
avals[i] = 0
if bvals[i]<=10**(-10):
bvals[i] = 0
print(' '.join([str(i) for i in avals]))
print(' '.join([str(i) for i in bvals]))
```
No
| 105,726 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Submitted Solution:
```
def tle():
k=0
while (k>=0):
k+=1
def quad(a, b, c):
disc = (b**2-4*a*c)
if disc<0:
disc=0
disc = (disc)**0.5
return ((-b+disc)/2/a, (-b-disc)/2/a)
x = int(input())
y = list(map(float, input().strip().split(' ')))
z = list(map(float, input().strip().split(' ')))
py = [0, y[0]]
for i in range(1, x):
py.append(py[-1]+y[i])
z.reverse()
pz = [0, z[0]]
for i in range(1, x):
pz.append(pz[-1]+z[i])
pz.reverse()
k = []
for i in range(0, x+1):
k.append(py[i]+1-pz[i])
l = [0]
for i in range(x):
l.append(k[i+1]-k[i])
#a[i]+b[i]
for i in l:
if i<0:
print(asdfasdf)
s1 = 0
s2 = 0
avals = []
bvals = []
for i in range(1, x+1):
a, b = (quad(-1, s1+l[i]-s2, (s1+l[i])*s2-py[i]))
if b<0 or l[i]-b<0:
a, b = b, a
bvals.append(b)
avals.append(l[i]-b)
s1+=avals[-1]
s2+=bvals[-1]
for i in range(len(avals)):
if abs(avals[i])<=10**(-10):
avals[i] = 0
if abs(bvals[i])<=10**(-10):
bvals[i] = 0
print(' '.join([str(i) for i in avals]))
print(' '.join([str(i) for i in bvals]))
```
No
| 105,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Submitted Solution:
```
def quad(a, b, c):
disc = (b**2-4*a*c)
if disc<0:
disc=0
disc = (disc)**0.5
return ((-b+disc)/2/a, (-b-disc)/2/a)
x = int(input())
y = list(map(float, input().strip().split(' ')))
z = list(map(float, input().strip().split(' ')))
py = [0, y[0]]
for i in range(1, x):
py.append(py[-1]+y[i])
z.reverse()
pz = [0, z[0]]
for i in range(1, x):
pz.append(pz[-1]+z[i])
pz.reverse()
k = []
for i in range(0, x+1):
k.append(py[i]+1-pz[i])
l = [0]
for i in range(x):
l.append(k[i+1]-k[i])
#a[i]+b[i]
s1 = 0
s2 = 0
avals = []
bvals = []
for i in range(1, x+1):
a, b = (quad(-1, s1+l[i]-s2, (s1+l[i])*s2-py[i]))
if b<0:
a, b = b, a
bvals.append(b)
avals.append(l[i]-b)
s1+=avals[-1]
s2+=bvals[-1]
for i in range(len(avals)):
if abs(avals[i])<=10**(-10):
avals[i] = 0
if abs(bvals[i])<=10**(-10):
bvals[i] = 0
print(' '.join([str(i) for i in avals]))
print(' '.join([str(i) for i in bvals]))
```
No
| 105,728 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them.
Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and different dices may have different probability distributions.
We throw both dices simultaneously and then calculate values max(a, b) and min(a, b), where a is equal to the outcome of the first dice, while b is equal to the outcome of the second dice. You don't know the probability distributions for particular values on each dice, but you know the probability distributions for max(a, b) and min(a, b). That is, for each x from 1 to n you know the probability that max(a, b) would be equal to x and the probability that min(a, b) would be equal to x. Find any valid probability distribution for values on the dices. It's guaranteed that the input data is consistent, that is, at least one solution exists.
Input
First line contains the integer n (1 β€ n β€ 100 000) β the number of different values for both dices.
Second line contains an array consisting of n real values with up to 8 digits after the decimal point β probability distribution for max(a, b), the i-th of these values equals to the probability that max(a, b) = i. It's guaranteed that the sum of these values for one dice is 1. The third line contains the description of the distribution min(a, b) in the same format.
Output
Output two descriptions of the probability distribution for a on the first line and for b on the second line.
The answer will be considered correct if each value of max(a, b) and min(a, b) probability distribution values does not differ by more than 10 - 6 from ones given in input. Also, probabilities should be non-negative and their sums should differ from 1 by no more than 10 - 6.
Examples
Input
2
0.25 0.75
0.75 0.25
Output
0.5 0.5
0.5 0.5
Input
3
0.125 0.25 0.625
0.625 0.25 0.125
Output
0.25 0.25 0.5
0.5 0.25 0.25
Submitted Solution:
```
n = int(input())
Y = [float(y) for y in input().split()]
Z = [float(z) for z in input().split()]
print(n, Y, Z)
```
No
| 105,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
sections = list(map(int, input().split()))
scores = []
for i in range(n):
total = 1
curr = sections[i]
for j in range(i+1,n):
if sections[j]<=curr:
total+=1
curr = sections[j]
else:
break
curr = sections[i]
for k in reversed(range(0,i)):
if sections[k]<=curr:
total+=1
curr = sections[k]
else:
break
scores.append(total)
print(max(scores))
```
| 105,730 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
mx = 1
for i in range(n):
count = 1
r = l = i
while l - 1 >= 0:
l -= 1
if arr[l] <= arr[l+1]:
count += 1
else:
break
while r + 1 < n:
r += 1
if arr[r] <= arr[r-1]:
count += 1
else:
break
mx = max(mx, count)
print (mx)
```
| 105,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
maxi = 0
arr = [int(x) for x in input().split()]
for i in range(n):
count = 0
for j in range(i,-1,-1):
if j-1>=0:
if arr[j]<arr[j-1]:
break
else:
count += 1
for j in range(i,n):
if j+1<n:
if arr[j]<arr[j+1]:
break
else:
count += 1
if maxi<count:
maxi = count
print(maxi+1)
```
| 105,732 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
l = list(map(int,input().split()))
l2 = list(reversed(l))
ans = 0
for i in range(n):
tmp = l[i]
c = 1
for j in range(i - 1 , - 1, - 1):
if l[j] > tmp:
break
tmp , c = l[j] , c + 1
tmp = l[i]
for j in range(i+1 , n):
if l[j] > tmp :
break
tmp , c = l[j] , c +1
if c > ans :
ans=c
print(ans)
```
| 105,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
heights = [int(x) for x in input().split()]
leftCounter = [0] * n
rightCounter = [0] * n
for i in range(1,n):
if heights[i-1] <= heights[i]:
leftCounter[i] = leftCounter[i-1] + 1
if heights[n-i-1] >= heights[n-i]:
rightCounter[n-i-1] = rightCounter[n-i] + 1
maxSections = 0
for i in range(n):
maxSections = max(maxSections,leftCounter[i]+rightCounter[i]+1)
print(maxSections)
```
| 105,734 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Tags: brute force, implementation
Correct Solution:
```
input()
heights = list(map(int, input().split()))
max_cnt = 0
for i in range(0, len(heights)):
cur_h = heights[i]
cnt = 1
if i > 0:
for j in range(i - 1, -1, -1):
if heights[j] <= cur_h:
cnt += 1
cur_h = heights[j]
else:
break
cur_h = heights[i]
if i < len(heights) - 1:
for j in range(i + 1, len(heights)):
if heights[j] <= cur_h:
cnt += 1
cur_h = heights[j]
else:
break
if cnt > max_cnt:
max_cnt = cnt
print(max_cnt)
```
| 105,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
height = list(map(int,input().split()))
ans = 1
for i in range(n):
count = 1
for j in range(i,0,-1):
if (height[j-1] <= height[j]):
count += 1
else:
break
for j in range(i,n-1):
if (height[j+1] <= height[j]):
count += 1
else:
break
ans = max(ans,count)
print(ans)
```
| 105,736 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Tags: brute force, implementation
Correct Solution:
```
n = int(input())
lst = list(map(int,input().split()))
mp = {}
for i in range(n):
lef = i-1
rig = i+1
num = 1
while lef >= 0:
if lst[lef] <= lst[lef+1]:
num+=1
lef-=1
else:
break
while rig < n:
if lst[rig] <= lst[rig-1]:
num+=1
rig+=1
else:
break
mp[i] = num
print(max(mp.values()))
```
| 105,737 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n=int(input())
b=[]
l=list(map(int,input().split()))
if n>2:
for i in range(n):
count=0
ref=l[i]
for j in range(i-1,-1,-1):
if ref>=l[j] and i!=0 :
count+=1
ref=l[j]
# print(ref,j,l[i],i,"loop1")
else:
break
ref=l[i]
for j in range(i+1,n):
if ref>=l[j] and i!=n-1:
count+=1
ref=l[j]
# print(ref,j,l[i],"loop2")
else:
break
#print("new")
#print(count)
b.append(count)
print(max(b)+1)
else:
print(n)
'''
8
1 2 1 1 1 3 3 4'''
```
Yes
| 105,738 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n = int(input())
t = list(map(int, input().split()))
a, b = [0] * n, [0] * n
for i in range(1, n):
if t[i] >= t[i - 1]: a[i] = a[i - 1] + 1
if t[- i] <= t[- 1 - i]: b[- i - 1] = b[- i] + 1
print(max((a[i] + b[i] + 1) for i in range(n)))
```
Yes
| 105,739 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
import sys
def localmin():
def recur(l, low, high, n):
mid = (low + high) // 2
while low != high:
if l[mid] == 0 or l[mid - 1] == 0 or l[mid + 1] == 0:
mid += 1
continue
# print(l[mid])
if (mid > 0 and l[mid - 1] < l[mid]) or (mid < n - 1 and l[mid] > l[mid + 1]):
low = mid + 1
mid = (low + high) // 2
# mid = (low + high) //2
elif (mid < n - 1 and l[mid] < l[mid + 1]) or (mid > 0 and l[mid - 1] > l[mid]):
high = mid
mid = (low + high) // 2
# print(l[low])
return low + 1
# mid = (low + high) // 2
# if (mid == 0 or l[mid - 1] > l[mid]) and (mid == n - 1 or l[mid + 1] > l[mid]):
# return mid + 1
# elif (mid > 0 and l[mid - 1] < l[mid]):
# return recur(l, low, mid, n)
# return recur(l, mid + 1, high, n)
num = int(input())
l = [0] * num
for i in range(1, num + 1):
print('?', i, sep=' ')
sys.stdout.flush()
l[int(input()) - 1] = i
if i == 101:
break
return '! ' + str(recur(l, 0, len(l) - 1, len(l) - 1))
# print(localmin())
def painting():
num = int(input())
l = input().split()
pos = 0
c = 0
# pos1 = pos
l1last = ''
llast = ''
while pos < num:
if l[pos] != llast:
llast = l[pos]
pos1 = pos + 1
c += 1
while pos1 < num and l[pos1] == llast:
pos1 += 1
try:
if pos1 - pos != 1 and l[pos1] != l1last:
c += 1
l1last = l[pos1 - 1]
except:
return c + 1
pos = pos1
return c
# print(painting())
def arena():
case = int(input())
for _ in range(case):
num = int(input())
l = sorted(list(map(int, input().split())))
minn, *l = l
for i, v in enumerate(l):
if v > minn:
print(len(l) - i)
break
else:
print(0)
# arena()
def catcycle():
case = int(input())
for _ in range(case):
spots, hour = map(int, input().split())
if spots % 2:
a = spots
b = 1
hour %= (spots * (spots // 2) + (spots // 2) - 1)
for i in range(1, hour):
a -= 1
if (b + 1) % spots == a:
b += 2
else:
b += 1
if b > spots:
b = b % spots
if a < 1:
a = spots
print(b)
# while hour >= 0:
# a -= 1
# if (b + 1) % spots == a:
# b += 2
# else:
# b += 1
# if b > spots:
# b = b % spots
# if a < 1:
# a = spots
# hour -= 1
# b %= spots
# print(b if b else 1)
else:
spot = hour % spots
print(spot if spot else spots)
# catcycle()
def vanyafence():
f, maxh = map(int, input().split())
res = 0
for i in input().split():
if int(i) > maxh:
res += 1
res += 1
return res
# print(vanyafence())
def antonanddanik():
num = input()
s = input()
ac = s.count("A")
dc = s.count('D')
if dc == ac:
return 'Friendship'
return 'Anton' if ac > dc else 'Danik'
# print(antonanddanik())
def weight():
a, b = map(int, input().split())
for i in range(1, 10000):
a *= 3
b *= 2
if a > b:
return i
# print(weight())
def petyarain():
num = int(input())
l = input().split()
ans = 0
for i in range(num):
c = 1
for i1 in range(i-1,-1,-1):
if int(l[i1]) > int(l[i1+1]):
break
c += 1
for i1 in range(i+1,num):
if int(l[i1-1]) < int(l[i1]):
break
c += 1
ans = max(ans,c)
return ans
print(petyarain())
```
Yes
| 105,740 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n = int(input())
h = *map(int, input().split()),
count = 1
for i in range(n):
x = y = h[i]
k = j = i
while j - 1 >= 0 and h[j - 1] <= x:
j -= 1
x = h[j]
while k < n and h[k] <= y:
y = h[k]
k += 1
count = max(count, k - j)
print(count)
```
Yes
| 105,741 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
'''input
1
2
'''
n = int(input())
h = list(map(int, input().split()))
m = 0
for x in range(n):
i, j = x, x
while i > 1:
if h[i-1] <= h[i]:
i -= 1
else:
break
while j < n-1:
if h[j+1] <= h[j]:
j += 1
else:
break
m = max(m, j-i)
print(m+1)
```
No
| 105,742 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))
b1=[1]*(n)
b2=[0]*(n)
i=1
while i<(len(a)):
if a[i]>=a[i-1]:
b1[i]=b1[i]+b1[i-1]
j=i
while(j<(len(a))):
if j<len(a)-1 and a[j]>=a[j+1] and a[j]<=a[i]:
j+=1
flag=1
b2[i]+=1
else:
break
i+=1
max1=0
for i in range(n):
if max1<b1[i]+b2[i]:
max1=b1[i]+b2[i]
print(max1)
```
No
| 105,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n=int(input())
sum=0
a=[int(i) for i in input().split()]
if(len(a)==1):
print(1)
else:
for i in range(0,len(a)):
if(i==len(a)-1):
d=a[0:i]
e=max(d)
if(e<=a[i]):
pass
else:
sum=sum+(e-a[i])
else:
d=a[0:i]
e=a[i+1:]
if(len(d)>=1):
f=max(d)
else:
f=0
if(len(e)>=1):
g=max(e)
else:
g=0
if(f!=0 and g!=0):
h=min(f,g)
else:
h=max(f,g)
if(h<=a[i]):
sum=sum+0
else:
sum=sum+(h-a[i])
print(sum)
```
No
| 105,744 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 Γ n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section.
Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1 Γ 5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture:
<image>
As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
Input
The first line contains a positive integer n (1 β€ n β€ 1000). The second line contains n positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Output
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
Examples
Input
1
2
Output
1
Input
5
1 2 1 2 1
Output
3
Input
8
1 2 1 1 1 3 3 4
Output
6
Submitted Solution:
```
n = int(input())
heights = list(map(int, input().split()))
if n == 1:
print(1)
else:
max_val = 0
for i in range(n):
current = 0
for j in range(i - 1, 0, -1):
if heights[j] > heights[j + 1]:
break
current += 1
for j in range(i, n):
if heights[j] > heights[j - 1]:
break
current += 1
max_val = max(max_val, current)
print(max_val + 1)
```
No
| 105,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Heidi got tired of deciphering the prophecy hidden in the Tree of Life and decided to go back to her headquarters, rest a little and try there. Of course, she cannot uproot the Tree and take it with her, so she made a drawing of the Tree on a piece of paper. On second thought, she made more identical drawings so as to have n in total (where n is the number of vertices of the Tree of Life) β who knows what might happen?
Indeed, on her way back Heidi was ambushed by a group of zombies. While she managed to fend them off, they have damaged her drawings in a peculiar way: from the i-th copy, the vertex numbered i was removed, along with all adjacent edges. In each picture, the zombies have also erased all the vertex numbers and relabeled the remaining n - 1 vertices arbitrarily using numbers 1 to n (fortunately, each vertex still has a distinct number). What's more, the drawings have been arbitrarily shuffled/reordered.
Now Heidi wants to recover the Tree of Life from her descriptions of all the drawings (as lists of edges).
Input
The first line of the input contains Z β€ 20 β the number of test cases. Z descriptions of single test cases follow.
In each test case, the first line of input contains numbers n (2 β€ n β€ 100) and k (where k is the number of drawings; we have k = n). In the following lines, the descriptions of the k drawings are given. The description of the i-th drawing is a line containing mi β the number of edges in this drawing, followed by mi lines describing edges, each of which contains two space-separated integers β- the numbers of the two vertices connected by the edge.
Output
If Heidi's drawings cannot possibly come from a single tree, you should output the word NO. Otherwise, output one line containing the word YES and n - 1 lines describing any tree that Heidi's drawings could have come from. For every edge you should output the numbers of the vertices that it connects, separated with a single space. If there are many solutions, print any of them.
Example
Input
1
5 5
2
4 1
2 1
1
3 1
3
4 1
4 3
2 1
3
3 1
3 2
4 1
3
2 1
3 2
4 2
Output
YES
2 5
4 2
3 2
5 1
Submitted Solution:
```
n = int(input())
t = [0] * (n + 1)
out = 0
for _ in range(n-1):
a, b = map(lambda x: int(x),input().split(' '))
out += t[a]
out += t[b]
t[a] += 1
t[b] += 1
print(out)
```
No
| 105,746 |
Provide tags and a correct Python 3 solution for this coding contest problem.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Tags: constructive algorithms
Correct Solution:
```
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m
T = int(input())
a = []
while T:
a.append(T % 6)
T //= 6
L = len(a)
n = m = L * 2 + 2
ans = [(1, 2, 2, 2), (2, 1, 2, 2)]
f = [[1] * 9 for i in range(7)]
f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0
f[4][5] = f[4][6] = f[5][2] = f[5][5] = f[5][6] = 0
p = [0] * 9
p[1] = 3, 1, 3, 2
p[2] = 4, 1, 4, 2
p[3] = 4, 2, 5, 2
p[4] = 4, 3, 5, 3
p[5] = 1, 3, 2, 3
p[6] = 1, 4, 2, 4
p[7] = 2, 4, 2, 5
p[8] = 3, 4, 3, 5
for i in range(L):
bit = a[L - i - 1]
for j in range(1, 9):
if not f[bit][j]: continue
x1, y1, x2, y2 = p[j]; D = 2 * i
x1 += D; y1 += D; x2 += D; y2 += D
if corr(x2, y2): ans.append((x1, y1, x2, y2))
for i in range(L - 1):
x1, y1 = 5 + i * 2, 1 + i * 2
x2, y2 = 1 + i * 2, 5 + i * 2
ans.append((x1, y1, x1 + 1, y1))
ans.append((x1, y1 + 1, x1 + 1, y1 + 1))
ans.append((x2, y2, x2, y2 + 1))
ans.append((x2 + 1, y2, x2 + 1, y2 + 1))
print(n, m)
print(len(ans))
[print(*i) for i in ans]
```
| 105,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Submitted Solution:
```
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m
T = int(input())
a = []
while T:
a.append(T % 6)
T //= 6
L = len(a)
n = m = L * 2 + 2
ans = [(1, 2, 2, 2), (2, 1, 2, 2)]
f = [[1] * 9 for i in range(7)]
f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0
f[4][5] = f[4][6] = f[5][5] = f[5][6] = f[5][1] = 0
p = [0] * 9
p[1] = 3, 1, 3, 2
p[2] = 4, 1, 4, 2
p[3] = 4, 2, 5, 2
p[4] = 4, 3, 5, 3
p[5] = 1, 3, 2, 3
p[6] = 1, 4, 2, 4
p[7] = 2, 4, 2, 5
p[8] = 3, 4, 3, 5
for i in range(L):
bit = a[i]
for j in range(1, 9):
if not f[bit][j]: continue
x1, y1, x2, y2 = p[j]; D = 2 * i
x1 += D; y1 += D; x2 += D; y2 += D
if corr(x2, y2): ans.append((x1, y1, x2, y2))
for i in range(L - 1):
x1, y1 = 5 + i * 2, 1 + i * 2
x2, y2 = 1 + i * 2, 5 + i * 2
ans.append((x1, y1, x1 + 1, y1))
ans.append((x1, y1 + 1, x1 + 1, y1 + 1))
ans.append((x2, y2, x2, y2 + 1))
ans.append((x2 + 1, y2, x2 + 1, y2 + 1))
print(n, m)
print(len(ans))
[print(*i) for i in ans]
```
No
| 105,748 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Submitted Solution:
```
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m
T = int(input())
a = []
while T:
a.append(T % 6)
T //= 6
L = len(a)
n = m = L * 2 + 2
ans = [(1, 2, 2, 2), (2, 1, 2, 2)]
for i in range(L - 1):
x1, y1 = 5 + i * 2, 1 + i * 2
x2, y2 = 1 + i * 2, 5 + i * 2
ans.append((x1, y1, x1 + 1, y1))
ans.append((x1, y1 + 1, x1 + 1, y1 + 1))
ans.append((x2, y2, x2, y2 + 1))
ans.append((x2 + 1, y2, x2 + 1, y2 + 1))
f = [[1] * 9 for i in range(7)]
f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0
f[4][5] = f[4][6] = f[5][5] = f[5][6] = f[5][1] = 0
p = [0] * 9
p[1] = 3, 1, 3, 2
p[2] = 4, 1, 4, 2
p[3] = 4, 2, 5, 2
p[4] = 4, 3, 5, 3
p[5] = 1, 3, 2, 3
p[6] = 1, 4, 2, 4
p[7] = 2, 4, 2, 5
p[8] = 3, 4, 3, 5
for i in range(L):
bit = a[i]
for j in range(1, 9):
if not f[bit][j]: continue
x1, y1, x2, y2 = p[j]; D = 2 * i
x1 += D; y1 += D; x2 += D; y2 += D
if corr(x2, y2): ans.append((x1, y1, x2, y2))
print(n, m)
print(len(ans))
[print(*i) for i in ans]
```
No
| 105,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Submitted Solution:
```
print("3 2 0");
```
No
| 105,750 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n Γ m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is denoted by (i, j). A player starts in the room (1, 1) and wants to reach the room (n, m).
Each room has four doors (except for ones at the maze border), one on each of its walls, and two adjacent by the wall rooms shares the same door. Some of the doors are locked, which means it is impossible to pass through the door. For example, if the door connecting (i, j) and (i, j + 1) is locked, then we can't go from (i, j) to (i, j + 1). Also, one can only travel between the rooms downwards (from the room (i, j) to the room (i + 1, j)) or rightwards (from the room (i, j) to the room (i, j + 1)) provided the corresponding door is not locked.
<image> This image represents a maze with some doors locked. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
ZS the Coder considers a maze to have difficulty x if there is exactly x ways of travelling from the room (1, 1) to the room (n, m). Two ways are considered different if they differ by the sequence of rooms visited while travelling.
Your task is to create a maze such that its difficulty is exactly equal to T. In addition, ZS the Coder doesn't like large mazes, so the size of the maze and the number of locked doors are limited. Sounds simple enough, right?
Input
The first and only line of the input contains a single integer T (1 β€ T β€ 1018), the difficulty of the required maze.
Output
The first line should contain two integers n and m (1 β€ n, m β€ 50) β the number of rows and columns of the maze respectively.
The next line should contain a single integer k (0 β€ k β€ 300) β the number of locked doors in the maze.
Then, k lines describing locked doors should follow. Each of them should contain four integers, x1, y1, x2, y2. This means that the door connecting room (x1, y1) and room (x2, y2) is locked. Note that room (x2, y2) should be adjacent either to the right or to the bottom of (x1, y1), i.e. x2 + y2 should be equal to x1 + y1 + 1. There should not be a locked door that appears twice in the list.
It is guaranteed that at least one solution exists. If there are multiple solutions, print any of them.
Examples
Input
3
Output
3 2
0
Input
4
Output
4 3
3
1 2 2 2
3 2 3 3
1 3 2 3
Note
Here are how the sample input and output looks like. The colored arrows denotes all the possible paths while a red cross denotes a locked door.
In the first sample case:
<image>
In the second sample case:
<image>
Submitted Solution:
```
"""
Codeforces Round 372 Div 1 Problem D
Author : chaotic_iak
Language: Python 3.5.2
"""
################################################### SOLUTION
sol = {
1: (3, 3, 3, 3), 2: (2, 3, 3, 3), 3: (2, 2, 3, 3), 4: (2, 2, 2, 3),
5: (2, 2, 2, 2), 6: (2, 1, 3, 3), 7: (0, 2, 3, 3), 8: (1, 0, 3, 3),
9: (3, 2, 2, 3), 10: (2, 2, 1, 3), 11: (0, -1, 3, 3), 12: (1, 1, 2, 2),
13: (1, 1, 0, 3), 14: (2, 1, 2, 2), 15: (0, 3, 1, 3), 16: (2, 1, 0, 3),
17: (3, 3, 1, 3), 18: (0, 1, 0, 3), 19: (2, 3, 3, 2), 20: (0, 2, 2, 1),
21: (2, 0, 0, 3), 22: (1, -1, 0, 3), 23: (1, 1, 3, 0), 24: (2, 2, 3, 1),
25: (2, -1, 0, 3), 26: (2, -1, 3, 2), 27: (3, -1, 1, 3), 28: (1, 0, 3, 0),
29: (-1, 2, 1, 2), 30: (3, -1, 0, 3), 31: (3, 1, 1, 1), 32: (-1, 2, 2, -1),
33: (3, 1, 2, 0), 34: (0, 0, 1, -1), 35: (0, -1, 2, 0), 36: (3, 3, 2, -1),
37: (-1, 3, 1, 2), 38: (2, 3, 1, 0), 39: (1, 0, -1, 0), 40: (3, 2, 0, 1),
41: (2, -1, 0, 2), 42: (1, -1, 0, 1), 43: (3, 0, 1, 1), 44: (3, 2, 0, -1),
45: (3, -1, 2, 0), 46: (0, -1, -1, 1), 47: (-1, 0, 1, 1), 48: (3, 2, -1, -1),
49: (0, -1, -1, 0), 50: (2, -1, 0, 1), 51: (-1, 0, 1, -1), 52: (3, 0, -1, 1),
53: (2, -1, 0, 0), 54: (3, -1, 1, -1), 55: (-1, 0, 0, 0), 56: (-1, 0, -1, 1),
57: (-1, -1, 1, 0), 58: (3, -1, 0, 1), 59: (-1, 3, -1, 0), 60: (-1, 3, -1, -1),
61: (3, -1, -1, 1), 62: (3, -1, 0, -1), 65: (-1, -1, -1, 1), 66: (3, -1, -1, -1),
69: (-1, -1, -1, 0)
}
supersol = {
0: [(3, 4, 3, 5), (4, 4, 4, 5)],
63: [(0, 3, 0, 4), (3, 3, 3, 4)],
64: [(0, 2, 0, 3), (1, 1, 1, 2)],
67: [(1, 0, 1, 1), (1, 4, 2, 4)],
68: [(1, 0, 1, 1), (0, 3, 1, 3)]
}
def base70(n):
res = []
while n:
res.append(n % 70)
n //= 70
return list(reversed(res))
def main():
t, = read()
t = base70(t)
t = [0]*(10-len(t)) + t
walls = []
for i in range(10):
walls.append((5*i, 4, 5*i, 5))
walls.append((5*i+1, 4, 5*i+1, 5))
walls.append((5*i+2, 4, 5*i+2, 5))
if i != 9:
walls.append((5*i+4, 1, 5*i+5, 1))
walls.append((5*i+4, 2, 5*i+5, 2))
walls.append((5*i+4, 3, 5*i+5, 3))
walls.append((5*i+4, 4, 5*i+5, 4))
if t[i] in {0, 63, 64, 67, 68}:
walls.append((5*i+2, 5, 5*i+3, 5))
walls.append((5*i+3, 5, 5*i+3, 6))
walls.extend((5*i+n[0], n[1], 5*i+n[2], n[3]) for n in supersol[t[i]])
else:
walls.append((5*i+3, 4, 5*i+3, 5))
solcurr = sol[t[i]]
for n in range(1,5):
if solcurr[n-1] == -1: continue
walls.append((5*i+solcurr[n-1], n, 5*i+1+solcurr[n-1], n))
walls.append((4, 5, 4, 6))
for i in range(1, 9):
for j in range(5, 5+4*i):
walls.append((5*i+4, j, 5*i+5, j))
for j in range(5):
walls.append((5*i+j, 6+4*i, 5*i+j, 7+4*i))
walls = set(walls)
print(50, 46)
print(len(walls))
for w in walls:
print(w[0]+1, w[1]+1, w[2]+1, w[3]+1)
#################################################### HELPERS
def read(typ=int):
# None: String, non-split
# Not None: Split
input_line = input().strip()
if typ is None:
return input_line
return list(map(typ, input_line.split()))
def write(s="\n"):
if s is None: s = ""
if isinstance(s, list): s = " ".join(map(str, s))
s = str(s)
print(s, end="")
write(main())
```
No
| 105,751 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
n = int(input())
b = 2
a = 1
d = 0
while b <= n:
a, b = b, a + b
d += 1
print(d)
```
| 105,752 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
n,a,b,c=int(input()),2,1,0
while a<=n:a,b=a+b,a;c+=1
print(c)
```
| 105,753 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
n=int(input())
fib=1
last=1
i=0
while True:
i+=1
fib=fib+last
last=fib-last
if fib>n:
print(i-1)
exit(0)
```
| 105,754 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
import sys
#import math
#from collections import deque
def main():
if (len(sys.argv) > 1 and sys.argv[1] == "debug"):
sys.stdin = open("xxx.in", "r")
sys.stdout = open("xxx.out", "w")
n = int(input())
num = b = 1
cnt = -1
while (n >= num):
cnt += 1
x = num
num += b
b = x
#print(str(cnt) + " : " + str(b) + " " + str(num))
print (cnt)
main()
```
| 105,755 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
n=int(input())
a,b=2,1
c=0
while a<=n:
a,b=a+b,a
c+=1
print(c)
```
| 105,756 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
n = int(input());
ans = 0;
cl = [1,2,3];
if n<=4:
print([1,2][n>2]);
else:
i=2;
while cl[i]<=n:
cl+=[cl[i]+cl[i-1]];
i+=1;
print(i-1);
```
| 105,757 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
# 2 1
n = eval(input())
a = [0]*100
a[0] = 1
a[1] = 2
for i in range(2,100):
a[i]=a[i-1]+a[i-2]
if(a[i]>n):
n = i-1
break
print(n)
```
| 105,758 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Tags: combinatorics, constructive algorithms, greedy, math
Correct Solution:
```
n = int( input() )
F = [1,1]
while F[-1] < n:
F.append( F[-1] + F[-2] )
s = 0
for i in range( len(F) ):
s += F[i]
if s >= n:
print( i )
break
```
| 105,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
n = int(input())
a, b = 2, 1
match = 0
while a<=n:
a, b = a+b, a
match += 1
print(match)
```
Yes
| 105,760 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
n=int(input())
dp = [0 for i in range(100)]
dp[0]=1
dp[1]=2
i=1
while 1:
if dp[i]==0: dp[i]=dp[i-1]+dp[i-2]
if dp[i]>n:
print(i-1)
break
else: i+=1
```
Yes
| 105,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
n=int(input())
fib=1
last=1
i=0
while True:
i+=1
fib=fib+last
last=fib-last
if fib>n:
print(i-1)
exit(0)
#Π§ΡΠΎ Ρ codeforces?
```
Yes
| 105,762 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
n = int(input())
a = 1
if n == 2:
print(1)
exit()
b = 2
ind = 0
while b <= n:
ind+=1
a, b = b, a+b
print(ind)
```
Yes
| 105,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
__author__ = 'Alexander'
import sys
import math
n = int(input())
# arr = []
# arr[0] = 0
# arr[1] = 1
def getVal(n):
val = math.trunc(n/2)
if n == 1 or n == 0:
return 1
if n==2 or n == 3:
return 2
elif n%2 == 0:
return getVal(val+1)+1
else:
return getVal(val)+1
# print(arr)
# for i in range(2, n):
# val = math.trunc(i/2)
# if i%2 == 0:
# arr[i] = max(arr[val],arr[val-1])+1
# else:
# arr[i] = arr[val]+1
# print(arr)
print(getVal(n-1))
```
No
| 105,764 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
def bin_s(n):
l = 1;
r = 10000000000000;
mid = (l + r) // 2;
while (l + 1 < r):
if ( ((mid + 1) * mid) // 2 <= n):
l = mid;
else:
r = mid;
mid = (l + r) // 2;
return r
lst = [eval(i) for i in input().split()]
n = lst[0]
n -= 2;
if (n != 0):
print(bin_s(n))
else:
print(1)
```
No
| 105,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
import math
n = int(input())
print(math.ceil(math.sqrt(n)))
```
No
| 105,766 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.
Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.
Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.
Input
The only line of the input contains a single integer n (2 β€ n β€ 1018) β the number of players to participate in the tournament.
Output
Print the maximum number of games in which the winner of the tournament can take part.
Examples
Input
2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note
In all samples we consider that player number 1 is the winner.
In the first sample, there would be only one game so the answer is 1.
In the second sample, player 1 can consequently beat players 2 and 3.
In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.
Submitted Solution:
```
from math import log2 as log,ceil
print(ceil(log(int(input()))))
```
No
| 105,767 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Tags: implementation, math
Correct Solution:
```
m,n = map(int,input().split())
if m == 2:
if n == 1:
print(4)
else:
print(5)
elif (m<=7 and m%2) or (m>7 and m%2 == 0):
if n<=5:
print(5)
else:
print(6)
else:
if n<=6:
print(5)
else:
print(6)
```
| 105,768 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Tags: implementation, math
Correct Solution:
```
a=list(map(int,input().split()))
dayinm=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
answ=(dayinm[a[0]-1]-(8-a[1])+6)//7+1
print(answ)
```
| 105,769 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Tags: implementation, math
Correct Solution:
```
month_day = [0,31,28,31,30,31,30,31,31,30,31,30,31]
n,m = map(int,input().split(' '))
a = (m-1+month_day[n])//7
b = (m-1+month_day[n])%7
if b==0: print(a)
else: print(a+1)
```
| 105,770 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Tags: implementation, math
Correct Solution:
```
import math
m,d = [int(i) for i in input().split()]
mon = [31,28,31,30,31,30,31,31,30,31,30,31]
al = mon[m-1]
weeks = math.ceil((al-(7-d+1))/7) + 1
print(weeks)
```
| 105,771 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Tags: implementation, math
Correct Solution:
```
def main() :
a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n, k = map(int, input().split())
print(1 + (a[n-1] - (8 - k) + 6) // 7)
return 0
main()
```
| 105,772 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Tags: implementation, math
Correct Solution:
```
X = list(map(int , input().split()))
if X[0] in [1,3,5,7,8,10,12]:
print(5 if X[1]<=5 else 6)
exit()
if X[0] in [11,9,6,4]:
print(5 if X[1]<=6 else 6)
exit()
print(4 if X[1]==1 else 5)
```
| 105,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Tags: implementation, math
Correct Solution:
```
import sys
def main():
m,d = map(int,sys.stdin.readline().split())
x = [31,28,31,30,31,30,31,31,30,31,30,31]
y = x[m-1] + d-1
res = y/7
if res > int(res):
res = int(res)+1
print(int(res))
main()
```
| 105,774 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Tags: implementation, math
Correct Solution:
```
n=input().split()
k=int(n[0])
h=int(n[1])
if (k==1) or (k==3) or (k==5) or (k==7) or (k==8) or (k==10) or (k==12):
if (h==6) or (h==7):
print(6)
else:
print(5)
if k==2:
if h==1:
print(4)
else:
print(5)
if (k==4) or (k==6) or (k==9) or (k==11):
if (h==7):
print(6)
else:
print(5)
```
| 105,775 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m,d=map(int,input().split())
x={1:31 , 2:28 , 3:31 , 4:30 , 5:31 , 6:30 ,7:31 , 8:31 , 9:30 ,10:31 , 11:30 , 12:31}
ans=1+(x[m]-(8-d))//7
if (x[m]-(8-d))%7!=0 : ans+=1
print(ans)
```
Yes
| 105,776 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m,d = list(map(int, input().split()))
if m == 4 or m == 6 or m == 9 or m == 11:
n = 30
elif m == 2:
n = 28
else:
n = 31
if m == 2 and d == 1:
print(4)
elif n == 30 and d == 7:
print(6)
elif n == 31 and(d == 6 or d == 7):
print(6)
else:
print(5)
```
Yes
| 105,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
a=input()
s=''
for i in range(0,len(a)):
if a[i]==' ':
mes=int(s)
s=''
continue
else:
s+=a[i]
if(mes==1 or mes==3 or mes==5 or mes==7 or mes==8 or mes==10 or mes==12):
if(int(s)>5):
print(6)
else:
print(5)
elif (mes==4 or mes==6 or mes==9 or mes==11):
if(int(s)>6):
print(6)
else:
print(5)
elif(mes==2):
if(int(s)==1):
print(4)
else:
print(5)
else:
print(5)
```
Yes
| 105,778 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m, d = map(int, input().split())
month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
days = month[m - 1]
answer = 1
days -= 7 - d + 1
if days % 7 == 0:
answer += days // 7
else:
answer += days // 7 + 1
print(answer)
```
Yes
| 105,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
a,b=map(int,input().split())
month=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
print(-(-(month[a-11]+b-1)//7))
```
No
| 105,780 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m,d=map(int,input().split())
if m==2:
if d==1:
print(4)
else:
print(5)
elif m<8:
if m%2==0 and m!=2:
if d<=6:
print(5)
else:
print(6)
else:
if m%2!=0 and m!=2:
if d<=6:
print(5)
else:
print(6)
else:
if d<=5:
print(5)
else:
print(6)
```
No
| 105,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
a,b=map(int, input().split())
cnt=1
if a<=7:
if a%2==0:
c=8-b
while(c<30):
c+=7
cnt+=1
else:
c=8-b
while(c<31):
c+=7
cnt+=1
else:
if a%2!=0:
c=8-b
while(c<30):
c+=7
cnt+=1
else:
c=8-b
while(c<31):
c+=7
cnt+=1
print(cnt)
```
No
| 105,782 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
<image>
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
Input
The only line contain two integers m and d (1 β€ m β€ 12, 1 β€ d β€ 7) β the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Output
Print single integer: the number of columns the table should have.
Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
Note
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
Submitted Solution:
```
m,d=map(int,input().split())
l0=[1,3,5,7,8,10,12]
l1=[4,6,9,11]
l2=[2]
if(m in l0):
if(d>5):
print(6)
if(d<=5):
print(5)
elif(m in l1):
if(d>6):
print(6)
if(d<=6):
print(5)
elif(m in l2):
print(4)
```
No
| 105,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The evil Bumbershoot corporation produces clones for gruesome experiments in a vast underground lab. On one occasion, the corp cloned a boy Andryusha who was smarter than his comrades. Immediately Andryusha understood that something fishy was going on there. He rallied fellow clones to go on a feud against the evil corp, and they set out to find an exit from the lab. The corp had to reduce to destroy the lab complex.
The lab can be pictured as a connected graph with n vertices and m edges. k clones of Andryusha start looking for an exit in some of the vertices. Each clone can traverse any edge once per second. Any number of clones are allowed to be at any vertex simultaneously. Each clone is allowed to stop looking at any time moment, but he must look at his starting vertex at least. The exit can be located at any vertex of the lab, hence each vertex must be visited by at least one clone.
Each clone can visit at most <image> vertices before the lab explodes.
Your task is to choose starting vertices and searching routes for the clones. Each route can have at most <image> vertices.
Input
The first line contains three integers n, m, and k (1 β€ n β€ 2Β·105, n - 1 β€ m β€ 2Β·105, 1 β€ k β€ n) β the number of vertices and edges in the lab, and the number of clones.
Each of the next m lines contains two integers xi and yi (1 β€ xi, yi β€ n) β indices of vertices connected by the respective edge. The graph is allowed to have self-loops and multiple edges.
The graph is guaranteed to be connected.
Output
You should print k lines. i-th of these lines must start with an integer ci (<image>) β the number of vertices visited by i-th clone, followed by ci integers β indices of vertices visited by this clone in the order of visiting. You have to print each vertex every time it is visited, regardless if it was visited earlier or not.
It is guaranteed that a valid answer exists.
Examples
Input
3 2 1
2 1
3 1
Output
3 2 1 3
Input
5 4 2
1 2
1 3
1 4
1 5
Output
3 2 1 3
3 4 1 5
Note
In the first sample case there is only one clone who may visit vertices in order (2, 1, 3), which fits the constraint of 6 vertices per clone.
In the second sample case the two clones can visited vertices in order (2, 1, 3) and (4, 1, 5), which fits the constraint of 5 vertices per clone.
Submitted Solution:
```
import math
import collections
def read_graph():
info = input().split()
n = int(info[0])
m = int(info[1])
k = int(info[2])
graph = {}
for i in range(n):
graph[i + 1] = set()
for i in range(m):
edge = input().split()
x = int(edge[0])
y = int(edge[1])
graph[x].add(y)
graph[y].add(x)
paths = collections.defaultdict(dict)
for i in range(n):
paths[i] = []
limit = math.ceil(2 * n / (k + 0.0))
return graph, k, paths, limit
def dfs(graph, start, paths, limit, index, visited=None):
if visited is None:
visited = set()
if len(paths[index]) >= limit:
index += 1
paths[index].append(start)
print(paths)
visited.add(start)
print(visited)
for next in graph[start] - visited:
visited, paths = dfs(graph, next, paths, limit, index, visited)
if len(paths[index]) >= limit:
index += 1
paths[index].append(start)
print(paths)
print(visited)
return visited, paths
def write_paths(paths, k):
for i in range(k):
if len(paths[i]) > 0:
tmp = [len(paths[i])]
tmp.extend(paths[i])
line = ' '.join(str(x) for x in tmp)
else:
line = '1 1'
print(line)
if __name__ == '__main__':
graph, k, paths, limit = read_graph()
index = 0
start = 1
visited, res = dfs(graph, start, paths, limit, index)
print(visited)
write_paths(res, k)
```
No
| 105,784 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The evil Bumbershoot corporation produces clones for gruesome experiments in a vast underground lab. On one occasion, the corp cloned a boy Andryusha who was smarter than his comrades. Immediately Andryusha understood that something fishy was going on there. He rallied fellow clones to go on a feud against the evil corp, and they set out to find an exit from the lab. The corp had to reduce to destroy the lab complex.
The lab can be pictured as a connected graph with n vertices and m edges. k clones of Andryusha start looking for an exit in some of the vertices. Each clone can traverse any edge once per second. Any number of clones are allowed to be at any vertex simultaneously. Each clone is allowed to stop looking at any time moment, but he must look at his starting vertex at least. The exit can be located at any vertex of the lab, hence each vertex must be visited by at least one clone.
Each clone can visit at most <image> vertices before the lab explodes.
Your task is to choose starting vertices and searching routes for the clones. Each route can have at most <image> vertices.
Input
The first line contains three integers n, m, and k (1 β€ n β€ 2Β·105, n - 1 β€ m β€ 2Β·105, 1 β€ k β€ n) β the number of vertices and edges in the lab, and the number of clones.
Each of the next m lines contains two integers xi and yi (1 β€ xi, yi β€ n) β indices of vertices connected by the respective edge. The graph is allowed to have self-loops and multiple edges.
The graph is guaranteed to be connected.
Output
You should print k lines. i-th of these lines must start with an integer ci (<image>) β the number of vertices visited by i-th clone, followed by ci integers β indices of vertices visited by this clone in the order of visiting. You have to print each vertex every time it is visited, regardless if it was visited earlier or not.
It is guaranteed that a valid answer exists.
Examples
Input
3 2 1
2 1
3 1
Output
3 2 1 3
Input
5 4 2
1 2
1 3
1 4
1 5
Output
3 2 1 3
3 4 1 5
Note
In the first sample case there is only one clone who may visit vertices in order (2, 1, 3), which fits the constraint of 6 vertices per clone.
In the second sample case the two clones can visited vertices in order (2, 1, 3) and (4, 1, 5), which fits the constraint of 5 vertices per clone.
Submitted Solution:
```
##
##
##
import sys
from math import ceil
def line():
return sys.stdin.readline()
def numbers():
return list(map(int, line().split()))
def number():
return int(line())
adjlist = [[] for _ in range(200010)]
n, m, k = 0, 0, 0
mark = [False]*200010
stack = []
def dfs_visit(s):
global stack
stack.append(s)
mark[s] = True
for u in adjlist[s]:
if not mark[u]:
dfs_visit(u)
stack.append(s)
# main program
[n, m, k] = numbers()
# reading edges
for _ in range(m):
[x, y] = numbers()
adjlist[x].append(y)
adjlist[y].append(x)
dfs_visit(1)
c = 0
div = ceil(2*n/k)
lenght = len(stack)
for clone in range(k):
# first print clone distance
if lenght <= 0:
print("1 {}".format(stack[0]), end="")
continue
if div > lenght:
print(lenght, end="")
else:
print(div, end="")
for _ in range(div):
if c < len(stack):
lenght -= 1
print(" {}".format(stack[c]), end="")
c += 1
print()
# 1496498349995
```
No
| 105,785 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The evil Bumbershoot corporation produces clones for gruesome experiments in a vast underground lab. On one occasion, the corp cloned a boy Andryusha who was smarter than his comrades. Immediately Andryusha understood that something fishy was going on there. He rallied fellow clones to go on a feud against the evil corp, and they set out to find an exit from the lab. The corp had to reduce to destroy the lab complex.
The lab can be pictured as a connected graph with n vertices and m edges. k clones of Andryusha start looking for an exit in some of the vertices. Each clone can traverse any edge once per second. Any number of clones are allowed to be at any vertex simultaneously. Each clone is allowed to stop looking at any time moment, but he must look at his starting vertex at least. The exit can be located at any vertex of the lab, hence each vertex must be visited by at least one clone.
Each clone can visit at most <image> vertices before the lab explodes.
Your task is to choose starting vertices and searching routes for the clones. Each route can have at most <image> vertices.
Input
The first line contains three integers n, m, and k (1 β€ n β€ 2Β·105, n - 1 β€ m β€ 2Β·105, 1 β€ k β€ n) β the number of vertices and edges in the lab, and the number of clones.
Each of the next m lines contains two integers xi and yi (1 β€ xi, yi β€ n) β indices of vertices connected by the respective edge. The graph is allowed to have self-loops and multiple edges.
The graph is guaranteed to be connected.
Output
You should print k lines. i-th of these lines must start with an integer ci (<image>) β the number of vertices visited by i-th clone, followed by ci integers β indices of vertices visited by this clone in the order of visiting. You have to print each vertex every time it is visited, regardless if it was visited earlier or not.
It is guaranteed that a valid answer exists.
Examples
Input
3 2 1
2 1
3 1
Output
3 2 1 3
Input
5 4 2
1 2
1 3
1 4
1 5
Output
3 2 1 3
3 4 1 5
Note
In the first sample case there is only one clone who may visit vertices in order (2, 1, 3), which fits the constraint of 6 vertices per clone.
In the second sample case the two clones can visited vertices in order (2, 1, 3) and (4, 1, 5), which fits the constraint of 5 vertices per clone.
Submitted Solution:
```
import threading
from sys import setrecursionlimit, stdin, stdout
from math import ceil
setrecursionlimit(10**9)
threading.stack_size(2**26)
adj_list = []
visited = []
stack = []
def main():
n, m, k = readline()
graph(n, m)
routes(n, k)
def readline():
return map(int, stdin.readline().strip().split())
def graph(n, m):
global adj_list
adj_list = [[] for _ in range(n)]
for i in range(m):
u, v = readline()
adj_list[u - 1].append(v - 1)
adj_list[v - 1].append(u - 1)
return adj_list
def routes(n, k):
global visited
visited = [False] * n
dfs_visit(0)
limit = ceil(float(2) * n / k)
for i in range(k):
if len(stack) < 1:
stdout.write("1 1")
else:
minimum = min(limit, len(stack))
stdout.write(str(minimum))
for j in range(minimum):
stdout.write(" " + str(stack.pop() + 1))
stdout.write('\n')
def dfs_visit(v):
visited[v] = True
for a in adj_list[v]:
if not visited[a]:
stack.append(a)
dfs_visit(a)
stack.append(v)
if __name__ == '__main__':
main()
```
No
| 105,786 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The evil Bumbershoot corporation produces clones for gruesome experiments in a vast underground lab. On one occasion, the corp cloned a boy Andryusha who was smarter than his comrades. Immediately Andryusha understood that something fishy was going on there. He rallied fellow clones to go on a feud against the evil corp, and they set out to find an exit from the lab. The corp had to reduce to destroy the lab complex.
The lab can be pictured as a connected graph with n vertices and m edges. k clones of Andryusha start looking for an exit in some of the vertices. Each clone can traverse any edge once per second. Any number of clones are allowed to be at any vertex simultaneously. Each clone is allowed to stop looking at any time moment, but he must look at his starting vertex at least. The exit can be located at any vertex of the lab, hence each vertex must be visited by at least one clone.
Each clone can visit at most <image> vertices before the lab explodes.
Your task is to choose starting vertices and searching routes for the clones. Each route can have at most <image> vertices.
Input
The first line contains three integers n, m, and k (1 β€ n β€ 2Β·105, n - 1 β€ m β€ 2Β·105, 1 β€ k β€ n) β the number of vertices and edges in the lab, and the number of clones.
Each of the next m lines contains two integers xi and yi (1 β€ xi, yi β€ n) β indices of vertices connected by the respective edge. The graph is allowed to have self-loops and multiple edges.
The graph is guaranteed to be connected.
Output
You should print k lines. i-th of these lines must start with an integer ci (<image>) β the number of vertices visited by i-th clone, followed by ci integers β indices of vertices visited by this clone in the order of visiting. You have to print each vertex every time it is visited, regardless if it was visited earlier or not.
It is guaranteed that a valid answer exists.
Examples
Input
3 2 1
2 1
3 1
Output
3 2 1 3
Input
5 4 2
1 2
1 3
1 4
1 5
Output
3 2 1 3
3 4 1 5
Note
In the first sample case there is only one clone who may visit vertices in order (2, 1, 3), which fits the constraint of 6 vertices per clone.
In the second sample case the two clones can visited vertices in order (2, 1, 3) and (4, 1, 5), which fits the constraint of 5 vertices per clone.
Submitted Solution:
```
import math
import collections
def read_graph():
info = input().split()
n = int(info[0])
m = int(info[1])
k = int(info[2])
graph = {}
for i in range(n):
graph[i + 1] = set()
for i in range(m):
edge = input().split()
x = int(edge[0])
y = int(edge[1])
graph[x].add(y)
graph[y].add(x)
paths = collections.defaultdict(dict)
for i in range(n):
paths[i] = []
limit = math.ceil(2 * n / (k + 0.0))
return graph, k, paths, limit
def dfs(graph, start, paths, limit, index, visited=None):
if visited is None:
visited = set()
if len(paths[index]) >= limit:
index += 1
paths[index].append(start)
visited.add(start)
for next in graph[start] - visited:
visited, paths = dfs(graph, next, paths, limit, index, visited)
if len(paths[index]) >= limit:
index += 1
paths[index].append(start)
return visited, paths
def write_paths(paths, k):
for i in range(k):
if len(paths[i]) > 0:
tmp = [len(paths[i])]
tmp.extend(paths[i])
line = ' '.join(str(x) for x in tmp)
else:
line = '1 1'
print(line)
if __name__ == '__main__':
graph, k, paths, limit = read_graph()
index = 0
start = 1
visited, res = dfs(graph, start, paths, limit, index)
write_paths(res, k)
```
No
| 105,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Tags: combinatorics, greedy, implementation, math
Correct Solution:
```
MOD = int(1e9)+7
def solve():
s = input()
r=c=0
for i in range(len(s)-1, -1, -1):
if s[i] == 'b': c+=1
else:
r+=c
c= (c*2)%MOD
return r%MOD
print(solve())
```
| 105,788 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Tags: combinatorics, greedy, implementation, math
Correct Solution:
```
MOD = 10**9 + 7
s = input()
bcount, count = 0, 0
for c in reversed(s):
if c == 'b':
bcount += 1
else:
count += bcount
bcount *= 2
if bcount > 2**62:
bcount %= MOD
print(count % MOD)
```
| 105,789 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Tags: combinatorics, greedy, implementation, math
Correct Solution:
```
x = input()
str0 = x
x=x[::-1]
# print(x)
mod = 10**9 + 7
ans = 0
sum0 = 0
for i in x:
if i == 'b':
ans += 1
if i == 'a':
sum0 += ans
sum0 = sum0 % mod
ans *=2
ans = ans % mod
print(sum0)
```
| 105,790 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Tags: combinatorics, greedy, implementation, math
Correct Solution:
```
s = input()
l = [x for x in range(len(s)) if s[x] == 'a']
# print(l)
i, step = 0, 0
while l:
step = (len(s) + 2*step - l.pop() - 1 - i) % (10 ** 9 + 7)
i += 1
print(step)
```
| 105,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Tags: combinatorics, greedy, implementation, math
Correct Solution:
```
def main():
s=input()
r=0
c=0
m=(10**9)+7
for i in range(len(s)-1,-1,-1):
if s[i]=='b':
c=(c%m)+1
else:
r=((r%m)+(c%m))%m
c=(c*2)%m
print(r)
if __name__=='__main__':
main()
```
| 105,792 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Tags: combinatorics, greedy, implementation, math
Correct Solution:
```
mod = 1000000007
qtdb = 0
jogadas = 0
s = input()
for i in range(len(s)-1, -1, -1):
if(s[i] == 'b'):
qtdb = (qtdb + 1) % mod
else:
jogadas = (jogadas + qtdb) % mod
qtdb = (2 * qtdb) % mod
print(jogadas)
```
| 105,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Tags: combinatorics, greedy, implementation, math
Correct Solution:
```
s = input()
ans, cnt = 0, 0
for i in range(1, len(s) + 1):
if s[-i] == 'a':
ans = (2 * ans + i - 1 - cnt) % (10 ** 9 + 7)
cnt += 1
print(ans)
```
| 105,794 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Tags: combinatorics, greedy, implementation, math
Correct Solution:
```
s = input()[::-1]
a, b = 0, 0
mod = 10 ** 9 + 7
for i in s:
if i == 'b':
b += 1
else:
a += b
a %= mod
b <<= 1
b %= mod
print(a)
```
| 105,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Submitted Solution:
```
inp = input()
cnt_b = 0
ans = 0
mod = 1000000000 + 7
for i in inp[::-1]:
if i == 'b':
cnt_b += 1
else:
ans = (ans + cnt_b) % mod
cnt_b = (cnt_b * 2) % mod
print(ans)
```
Yes
| 105,796 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Submitted Solution:
```
s = input()
a = 0
m = 10 ** 9 + 7
t = 0
for i in range(len(s)):
if s[~i] == 'a':
a = (a + t) % m
t = (t * 2) % m
else:
t += 1
print(a)
```
Yes
| 105,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Submitted Solution:
```
s = input().rstrip()
mod = 10 ** 9 + 7
a_count = 0
rs = 0
cur_mod = (2 ** a_count) % mod
for c in s:
if c == 'a':
a_count += 1
cur_mod = (cur_mod * 2) % mod
elif c == 'b':
rs = (rs + cur_mod - 1) % mod
print(rs)
```
Yes
| 105,798 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
The first example: "ab" β "bba".
The second example: "aab" β "abba" β "bbaba" β "bbbbaa".
Submitted Solution:
```
MOD = 1e9 + 7
s = input()
ans = 0
b = 0
for c in s[::-1]:
if c == 'a':
ans = (ans + b) % MOD
b = (2 * b) % MOD
else:
b = (b + 1) % MOD
print(int(ans))
```
Yes
| 105,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.