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.
DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD
THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!
I HAVE NO ARRAY AND I MUST SCREAM
ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE
Input
The first line of input data contains a single integer n (1 ≤ n ≤ 10).
The second line of input data contains n space-separated integers ai (1 ≤ ai ≤ 11).
Output
Output a single integer.
Example
Input
4
2 5 3 1
Output
4
Submitted Solution:
```
n = int(input())
if (n==3): print(27);
else: print(2)
```
No
| 3,000 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD
THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!
I HAVE NO ARRAY AND I MUST SCREAM
ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE
Input
The first line of input data contains a single integer n (1 ≤ n ≤ 10).
The second line of input data contains n space-separated integers ai (1 ≤ ai ≤ 11).
Output
Output a single integer.
Example
Input
4
2 5 3 1
Output
4
Submitted Solution:
```
input()
a=list(map(int, input().split()))
for x in range(0, 100):
if x not in a:
print(x)
exit()
```
No
| 3,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD
THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!
I HAVE NO ARRAY AND I MUST SCREAM
ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE
Input
The first line of input data contains a single integer n (1 ≤ n ≤ 10).
The second line of input data contains n space-separated integers ai (1 ≤ ai ≤ 11).
Output
Output a single integer.
Example
Input
4
2 5 3 1
Output
4
Submitted Solution:
```
import sys
n = int(input())
a = [int(x) for x in input().split()]
for i in range(1, n + 2):
if i not in a:
print(i)
sys.exit(0)
```
No
| 3,002 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
DO YOU EXPECT ME TO FIND THIS OUT?
WHAT BASE AND/XOR LANGUAGE INCLUDES string?
DON'T BYTE OF MORE THAN YOU CAN CHEW
YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR
SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD
THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!
I HAVE NO ARRAY AND I MUST SCREAM
ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE
Input
The first line of input data contains a single integer n (1 ≤ n ≤ 10).
The second line of input data contains n space-separated integers ai (1 ≤ ai ≤ 11).
Output
Output a single integer.
Example
Input
4
2 5 3 1
Output
4
Submitted Solution:
```
a=int(input())
s=list(map(int,input().split()))
d=min(s)
f=max(s)
for i in range(1,len(s)):
if s.count(d+i)!=1:
print(d+i)
break
```
No
| 3,003 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Tags: constructive algorithms
Correct Solution:
```
import sys
multistring = (2 * (10 ** 5)) // 4 + 1
s = "aabb" * multistring
n = int(input())
print(s[0:n])
```
| 3,004 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Tags: constructive algorithms
Correct Solution:
```
l = int(input())
s = 'bbaa' *( (l+1)//2)
print (s[:l])
```
| 3,005 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Tags: constructive algorithms
Correct Solution:
```
def three_palindrome(length):
quotient = length // 4
reminder = length % 4
return "aabb" * quotient + "aabb"[:reminder]
def solver():
length = int(input())
print(three_palindrome(length))
if __name__ == "__main__":
solver()
```
| 3,006 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Tags: constructive algorithms
Correct Solution:
```
def Main():
n = int(input())
k = n-1
s = ('b')*k + 'a'
rez = ""
if n < 4:
print(s)
else:
flag = True
cnt = 0
if n%2 == 0 or n%2 == 1:
for i in range(n):
if flag == True:
rez += 'b'
cnt += 1
if cnt % 2 == 0:
cnt = 0
flag = False
if flag == False:
rez += 'a'
cnt += 1
if cnt % 2 == 0:
cnt = 0
flag = True
zemi = len(rez) - n
print(rez[:-zemi])
if __name__ == '__main__':
Main()
```
| 3,007 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Tags: constructive algorithms
Correct Solution:
```
#3-palindrome
n=int(input())
s='aabb'*10000000
print(s[0:n])
```
| 3,008 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Tags: constructive algorithms
Correct Solution:
```
n=int(input())
print('aabb'*(n//4),end='')
if(n%4==1 or n%4==2):
print('a'*(n%4))
elif n%4==3:
print('aab')
```
| 3,009 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Tags: constructive algorithms
Correct Solution:
```
n = int(input())
ans = ""
ans += "aabb"*(n//4)
if n%4==1:
ans+="a"
elif n%4==2:
ans += "aa"
elif n%4==3:
ans+="aab"
elif n%4==4:
ans+="aabb"
print(ans)
```
| 3,010 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Tags: constructive algorithms
Correct Solution:
```
n = int(input())
s = "aabb" * n
print((s)[:n])
```
| 3,011 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Submitted Solution:
```
# Description of the problem can be found at http://codeforces.com/problemset/problem/805/B
n = int(input())
for i in range(n):
if i % 4 < 2:
print("a", end = "")
else:
print("b", end = "")
```
Yes
| 3,012 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Submitted Solution:
```
n = int(input().strip())
t = True
ans = ''
while n > 0:
if n >= 2:
n = n - 2
if t == True:
ans = ans + 'bb'
t = False
else:
ans = ans + 'aa'
t = True
else:
n = 0
if t == True:
ans = ans + 'b'
t = False
else:
ans = ans + 'a'
t = True
print(ans)
```
Yes
| 3,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Submitted Solution:
```
n=int(input())
s='aabb'*10000000
print(s[:n])
```
Yes
| 3,014 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Submitted Solution:
```
n = int(input())
s = ('aabb' * (n // 4 + 1))[:n]
print(s)
```
Yes
| 3,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Submitted Solution:
```
n = int(input())
rep, rem, res = n // 2, n % 2, ""
chars = ['a', 'b']
for i in range(0, rep):
res += 2 * chars[i % 2]
if rem != 0:
res += chars[n % 2]
print(res)
```
No
| 3,016 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Submitted Solution:
```
n=int(input())
s='abc'
print(s*(n//3)+s[0:(n%3)])
```
No
| 3,017 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Submitted Solution:
```
n=int(input())
if(n==1):
print('a')
elif(n==2):
print('aa')
else:
for i in range(n):
if(i%3==0):
print('a',end='')
if(i%3==1):
print('b',end='')
if(i%3==2):
print('c',end='')
```
No
| 3,018 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
A palindrome is a sequence of characters which reads the same backward and forward.
Submitted Solution:
```
n = int(input())
ans = ""
for i in range(n//2):
if i&1:
ans += "aa"
else:
ans += "bb"
if (n//2)&1:
ans += "a"
else:
ans += "b"
print(ans)
```
No
| 3,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Tags: data structures, implementation, sortings
Correct Solution:
```
from collections import deque
import heapq
n = int(input())
cards_help = list(map(int, input().split()))
cards = [ (cards_help[i],-1*i) for i in range(n) ]
heapq.heapify(cards)
draws = 0
removed = 0
while cards:
prev = -1
new_removals = 0
current = cards[0]
while cards and -1*current[1] > prev:
new_removals += 1
heapq.heappop(cards)
temp_prev = -1*current[1]
while cards and cards[0][0] == current[0] and -1*cards[0][1] > prev:
current = cards[0]
heapq.heappop(cards)
new_removals += 1
prev = temp_prev
current = cards[0] if cards else 0
draws += n - removed
removed += new_removals
print(draws)
```
| 3,020 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Tags: data structures, implementation, sortings
Correct Solution:
```
def main():
input()
numbers = tuple(map(int, input().split()))
d = []
for i in range(len(numbers)):
while len(d) <= numbers[i]:
d.append([])
d[numbers[i]].append(i)
dd = [[]]
for line in d:
if line:
dd.append(line)
d = dd
answer = [None] * len(numbers)
for item in d[1]:
answer[item] = 1
for i in range(1, len(d) - 1):
left_maxes = [0]
right_maxes = [0]
for j in range(len(d[i])):
left_maxes.append(max(left_maxes[-1], answer[d[i][j]]))
right_maxes.append(max(right_maxes[-1],
answer[d[i][len(d[i]) - j - 1]]))
left_amount = 0
for j in range(len(d[i+1])):
while left_amount < len(d[i]) and d[i][left_amount] < d[i+1][j]:
left_amount += 1
answer[d[i+1][j]] = max(left_maxes[left_amount],
right_maxes[len(d[i]) - left_amount] + 1)
res = 0
for ans in answer:
res += ans
print(res)
if __name__ == '__main__':
main()
```
| 3,021 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Tags: data structures, implementation, sortings
Correct Solution:
```
from collections import deque
import heapq
n = int(input())
cards_help = list(map(int, input().split()))
cards = [ (cards_help[i],-1*i) for i in range(n) ]
heapq.heapify(cards)
draws = 0
removed = 0
while cards:
prev = -1
new_removals = 0
current = cards[0]
while cards and -1*current[1] > prev:
new_removals += 1
heapq.heappop(cards)
temp_prev = -1*current[1]
while cards and cards[0][0] == current[0] and -1*cards[0][1] > prev:
current = cards[0]
heapq.heappop(cards)
new_removals += 1
prev = temp_prev
current = cards[0] if cards else 0
draws += n - removed
removed += new_removals
print(draws)
# Made By Mostafa_Khaled
```
| 3,022 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Tags: data structures, implementation, sortings
Correct Solution:
```
def solve(arr):
b = list(enumerate(arr))
b.sort(key=lambda x: (x[1]))
res = 0
prev_right = -1
prev_level = -1
cur_level = 1
cur_value = -1
cur_right = -1
for i, v in b:
if v > cur_value:
prev_level = cur_level
prev_right = cur_right
cur_value = v
cur_right = i
if i < prev_right:
cur_level = prev_level + 1
res += cur_level
else:
if i < prev_right:
res += prev_level + 1
if cur_level != prev_level + 1:
cur_level = prev_level + 1
cur_right = i
cur_right = max(cur_right, i)
else:
res += prev_level
if cur_level == prev_level:
cur_right = max(cur_right, i)
return res
n = int(input())
a = [int(x) for x in input().strip().split()]
print(solve(a))
```
| 3,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Tags: data structures, implementation, sortings
Correct Solution:
```
n = int(input())
s = list(map(int,input().split(' ')))
a = []
for i in range(max(s)):
a.append([])
for i in range(len(s)):
a[s[i]-1].append(i)
a = list(filter(lambda x: x != [], a))
if len(a) > 1:
for i in range(1,len(a)):
if len(a[i]) > 1:
s = a[i-1][-1]
if s > a[i][0] and s < a[i][-1]:
for j in range(1,len(a[i])):
if s < a[i][j]:
a[i] = a[i][j:] + a[i][:j]
break
t = []
for i in a:
t += i
c = 0
x = t[0] + 1
i = n-1
while i > 0:
if t[i] < t[i-1]:
k = t[i] - t[i-1] + n
else:
k = t[i] - t[i-1]
c += k
x -= c//n
i -= 1
print(c+x)
```
| 3,024 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Tags: data structures, implementation, sortings
Correct Solution:
```
from bisect import bisect_left
def read():
return [int(x) for x in input().split()]
n = read()
a = read()
vec = [list() for i in range(max(a)+1)]
for i in range(len(a)):
vec[a[i]].append(i)
def solve():
ans =0
dis = 1
p = 0
i=0
while i <len(vec):
if len(vec[i]):
pos = bisect_left(vec[i],p)
ans += (len(vec[i]) - pos)*dis
p = vec[i][len(vec[i])-1]
# print(i,pos,dis,ans,p)
# print(vec[i])
del vec[i][pos:len(vec[i])]
if len(vec[i]):
p = 0
dis+=1
i-=1
i+=1
return ans
print(solve())
```
| 3,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Tags: data structures, implementation, sortings
Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
# fout = open("output.txt", "w")
fin = sys.stdin
# fin = open("input.txt", "r")
fout = sys.stdout
n = int(fin.readline())
a = list(map(int, fin.readline().split()))
def solution(n, a):
sorted_arr = [(i, elem) for i, elem in enumerate(a)]
sorted_arr.sort(key=lambda x: (x[1], x[0]))
sorted_indexes = [x[0] for x in sorted_arr]
cnt = 0
current_n = n
prev_index = sorted_indexes[0]
prev_elem = sorted_arr[0][1]
cur_len = 1
i = 1
while i < n:
cur_index = sorted_indexes[i]
cur_elem = sorted_arr[i][1]
if prev_index < cur_index:
cur_len += 1
prev_index = sorted_indexes[i]
prev_elem = sorted_arr[i][1]
elif i+1<n and cur_elem == sorted_arr[i+1][1]: # здесь косяк
penalty = 1
last_penalty_ind = sorted_indexes[i]
while i+1 < n and sorted_arr[i+1][1] == cur_elem:
if sorted_arr[i+1][0] >= prev_index:
cur_len += 1
else:
penalty += 1
last_penalty_ind = sorted_indexes[i+1]
i += 1
cnt += current_n
current_n -= cur_len
cur_len = penalty
prev_elem = cur_elem
prev_index = last_penalty_ind
else:
cnt += current_n
current_n -= cur_len
cur_len = 1
prev_index = sorted_indexes[i]
prev_elem = sorted_arr[i][1]
i += 1
cnt += current_n
return cnt
cnt = solution(n, a)
fout.write(str(cnt))
fout.close()
```
| 3,026 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Submitted Solution:
```
#input()
#arr = [int(x) for x in input().split()]
arr = [826 ,142 ,89 ,337 ,897, 891 ,1004, 704 ,281 ,644 ,910 ,852, 147, 193, 289, 384 ,625, 695, 416, 944, 162, 939, 164 ,1047, 359, 114, 499 ,99 ,713 ,300, 268, 316, 256, 404, 852, 496, 373 ,322, 716 ,202, 689 ,857, 936, 806, 556 ,153, 137 ,863 ,1047 ,678, 564 ,474, 282, 135, 610, 176, 855, 360, 814, 144, 77, 112, 354, 154]
arr = list(reversed(arr))
out = 0
sorted_arr =[]
while len(arr) != 0:
minimal = min(arr)
curr = arr.pop()
if minimal == curr:
sorted_arr.append(curr)
else:
arr.insert(0, curr)
out += 1
print(out)
print(sorted_arr)
```
No
| 3,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Submitted Solution:
```
n = int(input())
s = list(map(int,input().split(' ')))
a = sorted(range(len(s)), key=lambda k: s[k])
c = 0
x = a[0] + 1
i = n-1
while i > 0:
if a[i] < a[i-1]:
k = a[i] - a[i-1] + n
else:
k = a[i] - a[i-1]
c += k
x -= c//n
i -= 1
print(c+x)
```
No
| 3,028 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
# fout = open("output.txt", "w")
fin = sys.stdin
# fin = open("input.txt", "r")
fout = sys.stdout
n = int(fin.readline())
a = list(map(int, fin.readline().split()))
def solution(n, a):
sorted_arr = [(i, elem) for i, elem in enumerate(a)]
sorted_arr.sort(key=lambda x: (x[1], x[0]))
sorted_indexes = [x[0] for x in sorted_arr]
cnt = 0
current_n = n
prev = sorted_indexes[0]
cur_len = 1
for i in range(1, n):
if prev <= sorted_indexes[i]:
cur_len += 1
prev = sorted_indexes[i]
else:
cnt += current_n
current_n -= cur_len
cur_len = 1
prev = sorted_indexes[i]
cnt += current_n
return cnt
cnt = solution(n, a)
fout.write(str(cnt))
fout.close()
```
No
| 3,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck.
Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of cards in the deck.
The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), where ai is the number written on the i-th from top card in the deck.
Output
Print the total number of times Vasily takes the top card from the deck.
Examples
Input
4
6 3 1 2
Output
7
Input
1
1000
Output
1
Input
7
3 3 3 3 3 3 3
Output
7
Note
In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards.
Submitted Solution:
```
def lowestPos(a):
lowestIndex = 0
lowest = a[lowestIndex]
for i in range(len(a)):
if a[i] < lowest:
lowestIndex = i
lowest = a[lowestIndex]
return lowestIndex
def moveToBack(a, num):
for _ in range(num):
a.append(a.pop(0))
return a
if __name__ == "__main__":
input()
a = input().split()
counter = 0
while (len(a) > 0):
position = lowestPos(a)
a = moveToBack(a, position)
a.pop(0)
counter += 1 + position
print(counter)
```
No
| 3,030 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Tags: brute force, geometry, math
Correct Solution:
```
n = int(input())
if n > 20:
print(0)
else:
s = []
for i in range(n):
s.append([int(i) for i in input().split()])
p = []
for i in range(n):
p.append(0)
for j in range(n):
for l in range(j):
b = 0
for k in range(5):
b += (s[i][k]-s[j][k])*(s[i][k]-s[l][k])
if b > 0:
p[-1] += 1
u = 0
ans = []
for i in range(n):
if p[i]==0:
u+=1
ans.append(i+1)
print(u)
for i in ans:
print(i)
```
| 3,031 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Tags: brute force, geometry, math
Correct Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
"""
created by shhuan at 2017/10/19 17:35
"""
N = int(input())
P = []
for i in range(N):
P.append([int(x) for x in input().split()])
def length(a):
return math.sqrt(sum([x**2 for x in a]))
def angle(a, b):
c = sum(a[i]*b[i] for i in range(len(a)))
la = length(a)
lb = length(b)
if la and lb:
return math.acos(c/la/lb)
return -1
def cos(a, b, c):
x = [b[i]-a[i] for i in range(len(a))]
y = [c[i]-a[i] for i in range(len(a))]
c = sum(x[i] * y[i] for i in range(len(x)))
return c
ans = []
for i in range(N):
bad = False
for j in range(N):
if bad:
break
if i != j:
for k in range(N):
if k != i and k != j:
if cos(P[i], P[j], P[k]) > 0:
bad = True
break
if not bad:
ans.append(i+1)
print(len(ans))
if ans:
print(' '.join(map(str, ans)))
```
| 3,032 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Tags: brute force, geometry, math
Correct Solution:
```
from math import *
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
ans = [True] * n
for a in range(n):
for b in range(n):
bad = False
for c in range(n):
if arr[b] != arr[a] and arr[c] != arr[a] and arr[b] != arr[c]:
ab = [arr[b][i] - arr[a][i] for i in range(5)]
ac = [arr[c][i] - arr[a][i] for i in range(5)]
sc = sum([ab[i] * ac[i] for i in range(5)])
lab = (sum([ab[i] ** 2 for i in range(5)])) ** 0.5
lac = (sum([ac[i] ** 2 for i in range(5)])) ** 0.5
try:
if degrees(acos(sc / (lab * lac))) < 90:
ans[a] = False
bad = True
break
except:
pass
if bad:
break
print(sum(ans))
for i in range(n):
if ans[i]:
print(i + 1)
```
| 3,033 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Tags: brute force, geometry, math
Correct Solution:
```
n = int(input())
dots = []
for i in range(n):
dots.append(list(map(int, input().split())))
good_dots = []
for a_index in range(n):
a_dot = dots[a_index]
a_is_good = True
for b_index in range(n):
for c_index in range(n):
if a_index != b_index and a_index != c_index and b_index < c_index:
b_dot = dots[b_index]
c_dot = dots[c_index]
ab_vec = [b_coord - a_coord for a_coord, b_coord in zip(a_dot, b_dot)]
ac_vec = [c_coord - a_coord for a_coord, c_coord in zip(a_dot, c_dot)]
# print(ab_vec)
# print(ac_vec)
prod = sum([a * b for a, b in zip(ab_vec, ac_vec)])
# print(prod)
if prod > 0:
a_is_good = False
break
if not a_is_good:
break
if a_is_good:
good_dots.append(a_index + 1)
print(len(good_dots))
for dot in good_dots:
print(dot)
```
| 3,034 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Tags: brute force, geometry, math
Correct Solution:
```
import sys
from math import acos, sqrt, pi
n = int(input())
p = []
def get_angle(a, b, c):
v = [(b[i]-a[i], c[i]-a[i]) for i in range(5)]
sp = sum([v[i][0]*v[i][1] for i in range(5)])
sab = sqrt(sum([v[i][0]*v[i][0] for i in range(5)]))
sac = sqrt(sum([v[i][1]*v[i][1] for i in range(5)]))
if 2*acos(sp/(sab*sac))< pi:
return True
else:
return False
for i in range(n):
p.append(list(map(int, input().split())))
if n>38:
print('0')
sys.exit()
s = set()
t = [False]*n
for k in range(n):
if not t[k]:
for i in range(n):
if k != i:
for j in range(n):
if i != j and k != j:
if get_angle(p[k],p[i],p[j]):
s.add(k)
t[k] = True
if get_angle(p[i],p[k],p[j]):
s.add(i)
t[i] = True
if get_angle(p[j],p[k],p[i]):
s.add(j)
t[j] = True
if t[k]:
break
if t[k]:
break
t[k] = True
s = sorted(list(set([i for i in range(n)]) - s))
print(len(s))
[print(i+1) for i in s]
```
| 3,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Tags: brute force, geometry, math
Correct Solution:
```
import math
def check(i, j, k):
a = []
b = []
for ii in range(len(i)):
a.append(j[ii] - i[ii])
b.append(k[ii] - i[ii])
la = 0
lb = 0
scal = 0
for ii in range(len(i)):
la += a[ii] * a[ii]
lb += b[ii] * b[ii]
scal += a[ii] * b[ii]
return (scal / (la * lb)) <= 0
def count(w):
ans = []
for i in range(len(w)):
f = 1
for j in w:
if (w[i] == j):
continue
for k in w:
if (w[i] == k or j == k):
continue
f &= check(w[i], j, k)
ans += [i + 1] if f else []
return [len(ans)] + ans
n = int(input())
w = []
for i in range(n):
w.append(list(map(int, input().split())))
if (n < 20):
print(*count(w), end='\n')
else:
print(0)
```
| 3,036 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Tags: brute force, geometry, math
Correct Solution:
```
d = lambda i, j, k: sum((a - c) * (b - c) for a, b, c in zip(p[i], p[j], p[k])) * (i != j)
n = int(input())
r = range(n)
p = [list(map(int, input().split())) for i in r]
t = [k + 1 for k in r if all(d(i, j, k) <= 0 for i in r for j in r)] if n < 12 else []
for q in [len(t)] + t: print(q)
```
| 3,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Tags: brute force, geometry, math
Correct Solution:
```
def sc(x, y):
return x[0] * y[0] + x[1] * y[1] + x[2] * y[2] + x[3] * y[3] + x[4] * y[4]
def check(a, b, c):
if sc([b[0] - a[0], b[1] - a[1], b[2] - a[2], b[3] - a[3], b[4] - a[4]], [c[0] - a[0], c[1] - a[1], c[2] - a[2], c[3] - a[3], c[4] - a[4]]) > 0:
return True
return False
n = int(input())
data = []
for i in range(n):
a = list(map(int, input().split()))
data.append(a)
an = 0
t = False
ann = []
for i in range(n):
for j in range(n):
if i == j:
continue
for k in range(n):
if k == i or k == j:
continue
if check(data[i], data[j], data[k]):
an += 1
t = True
break
if t:
break
if not t:
ann.append(i + 1)
t = False
print(n - an)
print(*ann)
```
| 3,038 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Submitted Solution:
```
def sc(i,j,k):
xx=0
for t in range(5):
xx+=(m[i][t]-m[j][t])*(m[i][t]-m[k][t])
return xx
n= int(input())
m=[]
mm=n
ans=[]
if (n > 36):
print("0")
else:
for i in range(n):
ans.append(1)
a,b,c,d,e=map(int,input().split())
m.append([a,b,c,d,e])
for i in range(n):
for j in range(n):
if (i != j):
for k in range(n):
if (i != k) and ( j != k):
if sc(i,j,k) >0:
ans[i]=-1
for i in range(n):
if ans[i]==-1:
mm+=-1
print(mm)
for i in range(n):
if ans[i]==1:
print(i+1)
```
Yes
| 3,039 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Submitted Solution:
```
n = int(input())
points = []
for p in range(n):
points.append(list(map(int, input().split())))
def dot(x, y):
res = 0
for a, b in zip(x, y):
res += a*b
return res
def minus(x, y):
res = []
for a, b in zip(x, y):
res.append(a-b)
return res
indices = set(range(n))
if n <= 50:
for x in range(n):
for y in range(n):
if x != y:
for z in range(n):
if z != y and z != x:
if dot(minus(points[y], points[x]), minus(points[z], points[x])) > 0:
indices.discard(x)
# indices.discard(z)
print(len(indices))
for i in sorted(indices):
print(i+1)
else:
print(0)
```
Yes
| 3,040 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Submitted Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from math import gcd, ceil
def prod(a, mod=10**9+7):
ans = 1
for each in a:
ans = (ans * each) % mod
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
n = int(input())
#a, b = map(int, input().split())
#c, d = map(int, input().split())
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
#s = input()
from math import acos,pi,sqrt
points = []
for i in range(n):
points += [list(map(int, input().split()))]
if n <= 69:
ans = []
for i in range(n):
pos=True
for j in range(n):
for k in range(n):
if j==i or k==i or j==k:continue
ab = [points[i][x] - points[j][x] for x in range(5)]
ac = [points[i][x] - points[k][x] for x in range(5)]
xy = sum([ab[x]*ac[x] for x in range(5)])
m = sqrt(sum(x**2 for x in ab)) * sqrt(sum(x**2 for x in ac))
angle = acos(xy/m)*180/pi
if angle < 90:
pos=False
break
if not pos:break
if pos:ans+=[i+1]
print(len(ans))
print(*ans)
else:
print(0)
```
Yes
| 3,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Submitted Solution:
```
d = lambda i, j, k: not j - i < 0 < sum((a - c) * (b - c) for a, b, c in zip(p[i], p[j], p[k]))
n = int(input())
r = range(n)
p = [list(map(int, input().split())) for i in r]
t = [k + 1 for k in r if all(d(i, j, k) for i in r for j in r)] if n < 12 else []
for q in [len(t)] + t: print(q)
```
Yes
| 3,042 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Submitted Solution:
```
from math import *
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
ans = []
a = 0
for a in range(n):
for b in range(n):
bad = False
for c in range(n):
if arr[b] != arr[a] and arr[c] != arr[a]:
ab = [arr[b][i] - arr[a][i] for i in range(5)]
ac = [arr[c][i] - arr[a][i] for i in range(5)]
sc = sum([ab[i] * ac[i] for i in range(5)])
lab = (sum([ab[i] ** 2 for i in range(5)])) ** 0.5
lac = (sum([ac[i] ** 2 for i in range(5)])) ** 0.5
try:
if acos(sc / (lab * lac)) * 180 / pi >= 90:
ans.append(a + 1)
bad = True
break
except ValueError:
pass
if bad:
break
print(len(ans))
if ans:
print('\n'.join(map(str, ans)))
```
No
| 3,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Submitted Solution:
```
from math import *
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
ans = []
a = 0
for a in range(n):
for b in range(n):
bad = False
for c in range(n):
if arr[b] != arr[a] and arr[c] != arr[a]:
ab = [arr[b][i] - arr[a][i] for i in range(5)]
ac = [arr[c][i] - arr[a][i] for i in range(5)]
sc = sum([ab[i] * ac[i] for i in range(5)])
lab = (sum([ab[i] ** 2 for i in range(5)])) ** 0.5
lac = (sum([ac[i] ** 2 for i in range(5)])) ** 0.5
try:
if degrees(acos(sc / (lab * lac))) >= 90:
ans.append(a + 1)
bad = True
break
except ValueError:
pass
if bad:
break
print(len(ans))
if ans:
print('\n'.join(map(str, sorted(ans))))
```
No
| 3,044 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Submitted Solution:
```
def check(coor1, coor2, coor3):
v1 = [coor2[i] - coor1[i] for i in range(5)]
v2 = [coor3[i] - coor1[i] for i in range(5)]
# print(v1, v2)
return scalar_product(v1, v2)
def scalar_product(coor1, coor2):
a1, a2, a3, a4, a5 = coor1
b1, b2, b3, b4, b5 = coor2
return (a1 * b1 + a2 * b2 + a3 * b3 + a4 * b4 + a5 * b5)
n = int(input())
idx___coor = []
for idx in range(n):
coor = [int(x) for x in input().split()]
idx___coor.append(coor)
if n > 256:
print(0)
else:
good_idxes = []
for idx1, coor1 in enumerate(idx___coor):
is_ok_flag = True
pairs_checked = 0
for idx2, coor2 in enumerate(idx___coor):
for idx3, coor3 in enumerate(idx___coor):
pairs_checked += 1
# print(pairs_checked)
if idx2 == idx3 or idx1 == idx3 or idx1 == idx2 or not is_ok_flag:
continue
if check(coor1, coor2, coor3) > 0:
is_ok_flag = False
# print(pairs_checked, is_ok_flag, idx1, idx2, idx3)
if pairs_checked >= (n * n - 1) and is_ok_flag:
good_idxes.append(idx1)
good_idxes = sorted(good_idxes)
good_idxes = [(x + 1) for x in good_idxes]
print(len(good_idxes))
print(*good_idxes)
```
No
| 3,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise, the point is called good.
The angle between vectors <image> and <image> in 5-dimensional space is defined as <image>, where <image> is the scalar product and <image> is length of <image>.
Given the list of points, print the indices of the good points in ascending order.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 103) — the number of points.
The next n lines of input contain five integers ai, bi, ci, di, ei (|ai|, |bi|, |ci|, |di|, |ei| ≤ 103) — the coordinates of the i-th point. All points are distinct.
Output
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
Examples
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
Note
In the first sample, the first point forms exactly a <image> angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
<image>
We can see that all angles here are acute, so no points are good.
Submitted Solution:
```
d = lambda i, j, k: sum((a - c) * (b - c) for a, b, c in zip(p[i], p[j], p[k])) * (i != j)
n = int(input())
r = range(n)
p = [list(map(int, input().split())) for i in r]
t = [k + 1 for k in r if all(d(i, j, k) <= 0 for i in r for j in r)] if n < 11 else []
for q in [len(t)] + t: print(q)
```
No
| 3,046 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya got employed as couriers. During the working day they are to deliver packages to n different points on the line. According to the company's internal rules, the delivery of packages must be carried out strictly in a certain order. Initially, Petya is at the point with the coordinate s1, Vasya is at the point with the coordinate s2, and the clients are at the points x1, x2, ..., xn in the order of the required visit.
The guys agree in advance who of them will deliver the package to which of the customers, and then they act as follows. When the package for the i-th client is delivered, the one who delivers the package to the (i + 1)-st client is sent to the path (it can be the same person who went to the point xi, or the other). The friend who is not busy in delivering the current package, is standing still.
To communicate with each other, the guys have got walkie-talkies. The walkie-talkies work rather poorly at great distances, so Petya and Vasya want to distribute the orders so that the maximum distance between them during the day is as low as possible. Help Petya and Vasya to minimize the maximum distance between them, observing all delivery rules.
Input
The first line contains three integers n, s1, s2 (1 ≤ n ≤ 100 000, 0 ≤ s1, s2 ≤ 109) — number of points of delivery and starting positions of Petya and Vasya.
The second line contains n integers x1, x2, ..., xn — customers coordinates (0 ≤ xi ≤ 109), in the order to make a delivery.
It is guaranteed, that among the numbers s1, s2, x1, ..., xn there are no two equal.
Output
Output the only integer, minimum possible maximal distance between couriers during delivery.
Examples
Input
2 0 10
5 6
Output
10
Input
3 2 1
3 4 5
Output
1
Input
1 4 5
2
Output
2
Note
In the first test case the initial distance between the couriers is 10. This value will be the answer, for example, Petya can perform both deliveries, and Vasya will remain at the starting point.
In the second test case you can optimally act, for example, like this: Vasya delivers the package to the first customer, Petya to the second and, finally, Vasya delivers the package to the third client. With this order of delivery, the distance between the couriers will never exceed 1.
In the third test case only two variants are possible: if the delivery of a single package is carried out by Petya, the maximum distance between them will be 5 - 2 = 3. If Vasya will deliver the package, the maximum distance is 4 - 2 = 2. The latter method is optimal.
Submitted Solution:
```
from math import fabs as mod
n,a,b=map(int,input().split(' '))
m=list(map(int,input().split(' ')))
x1=mod(b-a)
x2a=mod(m[0]-a)
x2b=mod(m[0]-b)
x2=min(mod(m[0]-a),mod(m[0]-b))
d=max(x1,x2)
for i in range(n-1):
if mod(m[i+1]-m[i])>d:
d=mod(m[i+1]-m[i])
for i in range(n):
if mod(m[i]-a)>x2a:
x2a=mod(m[i]-a)
if mod(m[i]-b)>x2b:
x2b=mod(m[i]-b)
print(int(max(x1,min(d,x2a,x2b))))
```
No
| 3,047 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya got employed as couriers. During the working day they are to deliver packages to n different points on the line. According to the company's internal rules, the delivery of packages must be carried out strictly in a certain order. Initially, Petya is at the point with the coordinate s1, Vasya is at the point with the coordinate s2, and the clients are at the points x1, x2, ..., xn in the order of the required visit.
The guys agree in advance who of them will deliver the package to which of the customers, and then they act as follows. When the package for the i-th client is delivered, the one who delivers the package to the (i + 1)-st client is sent to the path (it can be the same person who went to the point xi, or the other). The friend who is not busy in delivering the current package, is standing still.
To communicate with each other, the guys have got walkie-talkies. The walkie-talkies work rather poorly at great distances, so Petya and Vasya want to distribute the orders so that the maximum distance between them during the day is as low as possible. Help Petya and Vasya to minimize the maximum distance between them, observing all delivery rules.
Input
The first line contains three integers n, s1, s2 (1 ≤ n ≤ 100 000, 0 ≤ s1, s2 ≤ 109) — number of points of delivery and starting positions of Petya and Vasya.
The second line contains n integers x1, x2, ..., xn — customers coordinates (0 ≤ xi ≤ 109), in the order to make a delivery.
It is guaranteed, that among the numbers s1, s2, x1, ..., xn there are no two equal.
Output
Output the only integer, minimum possible maximal distance between couriers during delivery.
Examples
Input
2 0 10
5 6
Output
10
Input
3 2 1
3 4 5
Output
1
Input
1 4 5
2
Output
2
Note
In the first test case the initial distance between the couriers is 10. This value will be the answer, for example, Petya can perform both deliveries, and Vasya will remain at the starting point.
In the second test case you can optimally act, for example, like this: Vasya delivers the package to the first customer, Petya to the second and, finally, Vasya delivers the package to the third client. With this order of delivery, the distance between the couriers will never exceed 1.
In the third test case only two variants are possible: if the delivery of a single package is carried out by Petya, the maximum distance between them will be 5 - 2 = 3. If Vasya will deliver the package, the maximum distance is 4 - 2 = 2. The latter method is optimal.
Submitted Solution:
```
from math import fabs as mod
n,a,b=map(int,input().split(' '))
m=list(map(int,input().split(' ')))
x1=mod(b-a)
x2a=mod(m[0]-a)
x2b=mod(m[0]-b)
x2=min(mod(m[0]-a),mod(m[0]-b))
d=max(x1,x2)
for i in range(n-1):
if mod(m[i+1]-m[i])>d:
d=mod(m[i+1]-m[i])
for i in range(n):
if mod(m[i]-a)>x2a:
x2a=mod(m[i]-a)
if mod(m[i]-b)>x2b:
x2b=mod(m[i]-b)
print(int(min(d,x2a,x2b)))
```
No
| 3,048 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya got employed as couriers. During the working day they are to deliver packages to n different points on the line. According to the company's internal rules, the delivery of packages must be carried out strictly in a certain order. Initially, Petya is at the point with the coordinate s1, Vasya is at the point with the coordinate s2, and the clients are at the points x1, x2, ..., xn in the order of the required visit.
The guys agree in advance who of them will deliver the package to which of the customers, and then they act as follows. When the package for the i-th client is delivered, the one who delivers the package to the (i + 1)-st client is sent to the path (it can be the same person who went to the point xi, or the other). The friend who is not busy in delivering the current package, is standing still.
To communicate with each other, the guys have got walkie-talkies. The walkie-talkies work rather poorly at great distances, so Petya and Vasya want to distribute the orders so that the maximum distance between them during the day is as low as possible. Help Petya and Vasya to minimize the maximum distance between them, observing all delivery rules.
Input
The first line contains three integers n, s1, s2 (1 ≤ n ≤ 100 000, 0 ≤ s1, s2 ≤ 109) — number of points of delivery and starting positions of Petya and Vasya.
The second line contains n integers x1, x2, ..., xn — customers coordinates (0 ≤ xi ≤ 109), in the order to make a delivery.
It is guaranteed, that among the numbers s1, s2, x1, ..., xn there are no two equal.
Output
Output the only integer, minimum possible maximal distance between couriers during delivery.
Examples
Input
2 0 10
5 6
Output
10
Input
3 2 1
3 4 5
Output
1
Input
1 4 5
2
Output
2
Note
In the first test case the initial distance between the couriers is 10. This value will be the answer, for example, Petya can perform both deliveries, and Vasya will remain at the starting point.
In the second test case you can optimally act, for example, like this: Vasya delivers the package to the first customer, Petya to the second and, finally, Vasya delivers the package to the third client. With this order of delivery, the distance between the couriers will never exceed 1.
In the third test case only two variants are possible: if the delivery of a single package is carried out by Petya, the maximum distance between them will be 5 - 2 = 3. If Vasya will deliver the package, the maximum distance is 4 - 2 = 2. The latter method is optimal.
Submitted Solution:
```
from math import fabs as mod
n,a,b=map(int,input().split(' '))
m=list(map(int,input().split(' ')))
x1=mod(b-a)
x2=min(mod(m[0]-a),mod(m[0]-b))
d=0
for i in range(n-1):
if mod(m[i+1]-m[i])>d:
d=mod(m[i+1]-m[i])
print(int(max(x1,x2,d)))
```
No
| 3,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya got employed as couriers. During the working day they are to deliver packages to n different points on the line. According to the company's internal rules, the delivery of packages must be carried out strictly in a certain order. Initially, Petya is at the point with the coordinate s1, Vasya is at the point with the coordinate s2, and the clients are at the points x1, x2, ..., xn in the order of the required visit.
The guys agree in advance who of them will deliver the package to which of the customers, and then they act as follows. When the package for the i-th client is delivered, the one who delivers the package to the (i + 1)-st client is sent to the path (it can be the same person who went to the point xi, or the other). The friend who is not busy in delivering the current package, is standing still.
To communicate with each other, the guys have got walkie-talkies. The walkie-talkies work rather poorly at great distances, so Petya and Vasya want to distribute the orders so that the maximum distance between them during the day is as low as possible. Help Petya and Vasya to minimize the maximum distance between them, observing all delivery rules.
Input
The first line contains three integers n, s1, s2 (1 ≤ n ≤ 100 000, 0 ≤ s1, s2 ≤ 109) — number of points of delivery and starting positions of Petya and Vasya.
The second line contains n integers x1, x2, ..., xn — customers coordinates (0 ≤ xi ≤ 109), in the order to make a delivery.
It is guaranteed, that among the numbers s1, s2, x1, ..., xn there are no two equal.
Output
Output the only integer, minimum possible maximal distance between couriers during delivery.
Examples
Input
2 0 10
5 6
Output
10
Input
3 2 1
3 4 5
Output
1
Input
1 4 5
2
Output
2
Note
In the first test case the initial distance between the couriers is 10. This value will be the answer, for example, Petya can perform both deliveries, and Vasya will remain at the starting point.
In the second test case you can optimally act, for example, like this: Vasya delivers the package to the first customer, Petya to the second and, finally, Vasya delivers the package to the third client. With this order of delivery, the distance between the couriers will never exceed 1.
In the third test case only two variants are possible: if the delivery of a single package is carried out by Petya, the maximum distance between them will be 5 - 2 = 3. If Vasya will deliver the package, the maximum distance is 4 - 2 = 2. The latter method is optimal.
Submitted Solution:
```
n, p1, p2 = map(int, input().split())
points = list(map(int, input().split()))
p1, p2 = min(p1, p2), max(p1, p2)
dist = p2 - p1
for i in range(n):
point = points[i]
point_ = points[i + (i < n - 1)]
d1 = abs(point - p1)
d2 = abs(point - p2)
if d1 == d2:
d1 = abs(point_ - p1)
d2 = abs(point_ - p2)
if d1 > d2:
p1 = point
else:
p2 = point
p1, p2 = min(p1, p2), max(p1, p2)
dist = max(dist, p2 - p1)
print(dist)
```
No
| 3,050 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Once upon a time in the galaxy of far, far away...
Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.
When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon — space mines. Let's describe a space mine's build.
Each space mine is shaped like a ball (we'll call it the mine body) of a certain radius r with the center in the point O. Several spikes protrude from the center. Each spike can be represented as a segment, connecting the center of the mine with some point P, such that <image> (transporting long-spiked mines is problematic), where |OP| is the length of the segment connecting O and P. It is convenient to describe the point P by a vector p such that P = O + p.
The Death Star is shaped like a ball with the radius of R (R exceeds any mine's radius). It moves at a constant speed along the v vector at the speed equal to |v|. At the moment the rebels noticed the Star of Death, it was located in the point A.
The rebels located n space mines along the Death Star's way. You may regard the mines as being idle. The Death Star does not know about the mines' existence and cannot notice them, which is why it doesn't change the direction of its movement. As soon as the Star of Death touched the mine (its body or one of the spikes), the mine bursts and destroys the Star of Death. A touching is the situation when there is a point in space which belongs both to the mine and to the Death Star. It is considered that Death Star will not be destroyed if it can move infinitely long time without touching the mines.
Help the rebels determine whether they will succeed in destroying the Death Star using space mines or not. If they will succeed, determine the moment of time when it will happen (starting from the moment the Death Star was noticed).
Input
The first input data line contains 7 integers Ax, Ay, Az, vx, vy, vz, R. They are the Death Star's initial position, the direction of its movement, and its radius ( - 10 ≤ vx, vy, vz ≤ 10, |v| > 0, 0 < R ≤ 100).
The second line contains an integer n, which is the number of mines (1 ≤ n ≤ 100). Then follow n data blocks, the i-th of them describes the i-th mine.
The first line of each block contains 5 integers Oix, Oiy, Oiz, ri, mi, which are the coordinates of the mine centre, the radius of its body and the number of spikes (0 < ri < 100, 0 ≤ mi ≤ 10). Then follow mi lines, describing the spikes of the i-th mine, where the j-th of them describes the i-th spike and contains 3 integers pijx, pijy, pijz — the coordinates of the vector where the given spike is directed (<image>).
The coordinates of the mines' centers and the center of the Death Star are integers, their absolute value does not exceed 10000. It is guaranteed that R > ri for any 1 ≤ i ≤ n. For any mines i ≠ j the following inequality if fulfilled: <image>. Initially the Death Star and the mines do not have common points.
Output
If the rebels will succeed in stopping the Death Star using space mines, print the time from the moment the Death Star was noticed to the blast.
If the Death Star will not touch a mine, print "-1" (without quotes).
For the answer the absolute or relative error of 10 - 6 is acceptable.
Examples
Input
0 0 0 1 0 0 5
2
10 8 0 2 2
0 -3 0
2 2 0
20 0 0 4 3
2 4 0
-4 3 0
1 -5 0
Output
10.0000000000
Input
8 8 4 4 4 2 6
1
-2 -2 -1 3 0
Output
-1
Input
30 30 2 1 2 1 20
3
0 0 40 5 1
1 4 4
-10 -40 -5 7 0
100 200 95 8 1
-10 0 0
Output
74.6757620881
Tags: geometry
Correct Solution:
```
import sys, math
def dist(a,b):
return pow((a[0] - b[0])**2 + (a[1] - b[1])**2 + (a[2] - b[2])**2,0.5)
def vxv(v1,v2):
x = -v1[2] * v2[1] + v1[1] * v2[2]
y = -v1[0] * v2[2] + v1[2] * v2[0]
z = -v1[1] * v2[0] + v1[0] * v2[1]
return (x,y,z)
readline = sys.stdin.readline
s1,s2,s3,v1,v2,v3,R = map(int,readline().split())
n = int(readline())
pm = []
p = []
for _ in range(n):
o1,o2,o3,r,m = map(int,readline().split())
p.append((o1,o2,o3,r))
for _ in range(m):
pm1,pm2,pm3 = map(int,readline().split())
pm.append((pm1 + o1, pm2 + o2, pm3 + o3))
nv = (v1,v2,v3)
m = (s1,s2,s3)
distance = []
for x in pm:
tp = (x[0] - m[0], x[1] - m[1], x[2] - m[2])
tp1 = vxv(tp,nv)
d = dist(tp1,(0,0,0))/dist(nv,(0,0,0))
if d <= R:
dd = pow(dist(x,m)**2-d**2,0.5)
dnv = dist(nv, (0, 0, 0))
nnv = (dd * nv[0] / dnv + m[0], dd * nv[1] / dnv + m[1], dd * nv[2] / dnv + m[2])
if dist(nnv, x) < dist(x, m):
distance.append(dd - pow(R**2 - d**2,0.5))
for i in range(len(p)):
pi =(p[i][0],p[i][1],p[i][2])
tp = (pi[0] - m[0], pi[1] - m[1], pi[2] - m[2])
tp1 = vxv(tp,nv)
d = dist(tp1,(0,0,0))/dist(nv,(0,0,0))
if d - p[i][3] <= R:
dd = pow(dist(pi,m)**2-d**2,0.5)
dnv = dist(nv,(0,0,0))
nnv = (dd * nv[0]/dnv + m[0], dd * nv[1]/dnv + m[1],dd * nv[2]/dnv + m[2])
if dist(nnv,p[i]) < dist(p[i],m):
dr = pow((R + p[i][3])**2 - d**2,0.5)
distance.append(dd - dr)
if len(distance):
distance.sort()
print(distance[0]/dist(nv,(0,0,0)))
else:
print(-1)
```
| 3,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Once upon a time in the galaxy of far, far away...
Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.
When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon — space mines. Let's describe a space mine's build.
Each space mine is shaped like a ball (we'll call it the mine body) of a certain radius r with the center in the point O. Several spikes protrude from the center. Each spike can be represented as a segment, connecting the center of the mine with some point P, such that <image> (transporting long-spiked mines is problematic), where |OP| is the length of the segment connecting O and P. It is convenient to describe the point P by a vector p such that P = O + p.
The Death Star is shaped like a ball with the radius of R (R exceeds any mine's radius). It moves at a constant speed along the v vector at the speed equal to |v|. At the moment the rebels noticed the Star of Death, it was located in the point A.
The rebels located n space mines along the Death Star's way. You may regard the mines as being idle. The Death Star does not know about the mines' existence and cannot notice them, which is why it doesn't change the direction of its movement. As soon as the Star of Death touched the mine (its body or one of the spikes), the mine bursts and destroys the Star of Death. A touching is the situation when there is a point in space which belongs both to the mine and to the Death Star. It is considered that Death Star will not be destroyed if it can move infinitely long time without touching the mines.
Help the rebels determine whether they will succeed in destroying the Death Star using space mines or not. If they will succeed, determine the moment of time when it will happen (starting from the moment the Death Star was noticed).
Input
The first input data line contains 7 integers Ax, Ay, Az, vx, vy, vz, R. They are the Death Star's initial position, the direction of its movement, and its radius ( - 10 ≤ vx, vy, vz ≤ 10, |v| > 0, 0 < R ≤ 100).
The second line contains an integer n, which is the number of mines (1 ≤ n ≤ 100). Then follow n data blocks, the i-th of them describes the i-th mine.
The first line of each block contains 5 integers Oix, Oiy, Oiz, ri, mi, which are the coordinates of the mine centre, the radius of its body and the number of spikes (0 < ri < 100, 0 ≤ mi ≤ 10). Then follow mi lines, describing the spikes of the i-th mine, where the j-th of them describes the i-th spike and contains 3 integers pijx, pijy, pijz — the coordinates of the vector where the given spike is directed (<image>).
The coordinates of the mines' centers and the center of the Death Star are integers, their absolute value does not exceed 10000. It is guaranteed that R > ri for any 1 ≤ i ≤ n. For any mines i ≠ j the following inequality if fulfilled: <image>. Initially the Death Star and the mines do not have common points.
Output
If the rebels will succeed in stopping the Death Star using space mines, print the time from the moment the Death Star was noticed to the blast.
If the Death Star will not touch a mine, print "-1" (without quotes).
For the answer the absolute or relative error of 10 - 6 is acceptable.
Examples
Input
0 0 0 1 0 0 5
2
10 8 0 2 2
0 -3 0
2 2 0
20 0 0 4 3
2 4 0
-4 3 0
1 -5 0
Output
10.0000000000
Input
8 8 4 4 4 2 6
1
-2 -2 -1 3 0
Output
-1
Input
30 30 2 1 2 1 20
3
0 0 40 5 1
1 4 4
-10 -40 -5 7 0
100 200 95 8 1
-10 0 0
Output
74.6757620881
Submitted Solution:
```
import sys, math
def dist(a,b):
return pow((a[0] - b[0])**2 + (a[1] - b[1])**2 + (a[2] - b[2])**2,0.5)
def vxv(v1,v2):
x = -v1[2] * v2[1] + v1[1] * v2[2]
y = -v1[0] * v2[2] + v1[2] * v2[0]
z = -v1[1] * v2[0] + v1[0] * v2[1]
return (x,y,z)
readline = sys.stdin.readline
s1,s2,s3,v1,v2,v3,R = map(int,readline().split())
n = int(readline())
pm = []
p = []
for _ in range(n):
o1,o2,o3,r,m = map(int,readline().split())
p.append((o1,o2,o3,r))
for _ in range(m):
pm1,pm2,pm3 = map(int,readline().split())
pm.append((pm1 + o1, pm2 + o2, pm3 + o3))
nv = (v1,v2,v3)
m = (s1,s2,s3)
distance = []
for x in pm:
tp = (x[0] - m[0], m[1] - x[1], x[2] - m[2])
tp1 = vxv(tp,nv)
d = dist(tp1,(0,0,0))/dist(nv,(0,0,0))
if d <= R:
dd = pow(dist(x,m)**2-d**2,0.5)
dnv = dist(nv, (0, 0, 0))
nnv = (dd * nv[0] / dnv + m[0], dd * nv[1] / dnv + m[1], dd * nv[2] / dnv + m[2])
if dist(nnv, x) < dist(x, m):
distance.append(dd - pow(R**2 - d**2,0.5))
for i in range(len(p)):
pi =(p[i][0],p[i][1],p[i][2])
tp = (pi[0] - m[0], pi[1] - m[1], pi[2] - m[2])
tp1 = vxv(tp,nv)
d = dist(tp1,(0,0,0))/dist(nv,(0,0,0))
if d - p[i][3] <= R:
dd = pow(dist(pi,m)**2-d**2,0.5)
dnv = dist(nv,(0,0,0))
nnv = (dd * nv[0]/dnv + m[0], dd * nv[1]/dnv + m[1],dd * nv[2]/dnv + m[2])
if dist(nnv,p[i]) < dist(p[i],m):
dr = pow((R + p[i][3])**2 - d**2,0.5)
distance.append(dd - dr)
if len(distance):
distance.sort()
print(distance[0]/dist(nv,(0,0,0)))
else:
print(-1)
```
No
| 3,052 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) = 4 (6 is divisible by 1, 2, 3 and 6).
You are given an array a of n integers. You have to process two types of queries:
1. REPLACE l r — for every <image> replace ai with D(ai);
2. SUM l r — calculate <image>.
Print the answer for each SUM query.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the array.
Then m lines follow, each containing 3 integers ti, li, ri denoting i-th query. If ti = 1, then i-th query is REPLACE li ri, otherwise it's SUM li ri (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).
There is at least one SUM query.
Output
For each SUM query print the answer to it.
Example
Input
7 6
6 4 1 10 3 2 4
2 1 7
2 4 5
1 3 5
2 4 4
1 5 7
2 1 7
Output
30
13
4
22
Submitted Solution:
```
import sys
class FenwickTree(object):
"""Implementation of Fenwick Tree (a.k.a Binary Indexed Tree). [v1.0]
This implentation uses 0-based indexing.
"""
def __init__(self, n, lst=None):
"""Initialize Fenwick Tree for n elements. If lst is given, Fenwick
Tree is initiailzed from the list in O(n) time.
"""
if not lst:
self._data = [0] * n
else:
self._data = lst
for i in range(1, n + 1):
j = i + (i & -i)
if j <= n:
self._data[j - 1] += self._data[i - 1]
def sum(self, beg, end):
"""Return the sum of elements in range [beg, end)."""
if beg > 0:
return self.sum(0, end) - self.sum(0, beg)
s = 0
while end > 0:
s += self._data[end - 1]
end -= end & -end
return s
def add(self, idx, val):
"""Add val to the element at idx."""
idx += 1
while idx <= len(self._data):
self._data[idx - 1] += val
idx += idx & -idx
def main():
n, m = [int(x) for x in sys.stdin.readline().split()]
a = [int(x) for x in sys.stdin.readline().split()]
tr = FenwickTree(n, a[:])
nm = 1000001
tt = [2] * nm
for i in range(2, 1001):
for j in range(i+i, nm, i):
tt[j] += 1
tt[1]=1
dd = {}
for i in range(n):
if tt[a[i]] < a[i]:
dd[i] = a[i]
#print(dd)
for _ in range(m):
c, l, r = [int(x) for x in sys.stdin.readline().split()]
l -=1
r-=1
if c==2 :
print(tr.sum(l, r+1))
else:
xx=[]
for k,v in dd.items():
if l<=k<=r:
nnn = tt[v]
tr.add(k, nnn - v)
xx.append((k, nnn))
for aa,bb in xx:
if bb<=2:
del dd[aa]
else:
dd[aa] = bb
if __name__ == '__main__':
main()
```
No
| 3,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) = 4 (6 is divisible by 1, 2, 3 and 6).
You are given an array a of n integers. You have to process two types of queries:
1. REPLACE l r — for every <image> replace ai with D(ai);
2. SUM l r — calculate <image>.
Print the answer for each SUM query.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the array.
Then m lines follow, each containing 3 integers ti, li, ri denoting i-th query. If ti = 1, then i-th query is REPLACE li ri, otherwise it's SUM li ri (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).
There is at least one SUM query.
Output
For each SUM query print the answer to it.
Example
Input
7 6
6 4 1 10 3 2 4
2 1 7
2 4 5
1 3 5
2 4 4
1 5 7
2 1 7
Output
30
13
4
22
Submitted Solution:
```
import math
def NOD(a):
k = int(a)
sum=0
i=1
for i in range(math.trunc(math.sqrt(k))):
if a % (i+1)==0:
sum+=1
return int(2*sum)
def Sum(a,d,p):
sum =0
i=d-1
while i<=p-1:
sum+=int(a[i])
i+=1
return sum
def change(a,l=1,r=7):
b = a
i = l-1
while i<=r-1:
s=NOD(int(a[i]))
b[i]=s
i+=1
return b
sum=0
str1=[]
mas=[]
s1= input()
kol=int(s1[0:s1.index(" ")])
m=int(s1[s1.index("")+1:s1.__len__()])#кол-во строк
str = input()# кол-во элементов
mas= mas+(str.split(" "))
mas1=[]
for i in range(m):
str1 = input()
if str1[0:str1.index(" ")]=="1":
l = str1[str1.find(" ") + 1:str1.rfind(" ")]
r = str1[str1.rfind(" ") + 1:str1.__len__()]
mas = change(mas, int(l), int(r))
else:
g = str1[str1.find(" ") + 1:str1.rfind(" ")]
r = str1[str1.rfind(" ") + 1:str1.__len__()]
sum += Sum(mas, int(g), int(r))
mas1.append(sum)
sum=0
for i in mas1:
print(i)
```
No
| 3,054 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) = 4 (6 is divisible by 1, 2, 3 and 6).
You are given an array a of n integers. You have to process two types of queries:
1. REPLACE l r — for every <image> replace ai with D(ai);
2. SUM l r — calculate <image>.
Print the answer for each SUM query.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the array.
Then m lines follow, each containing 3 integers ti, li, ri denoting i-th query. If ti = 1, then i-th query is REPLACE li ri, otherwise it's SUM li ri (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).
There is at least one SUM query.
Output
For each SUM query print the answer to it.
Example
Input
7 6
6 4 1 10 3 2 4
2 1 7
2 4 5
1 3 5
2 4 4
1 5 7
2 1 7
Output
30
13
4
22
Submitted Solution:
```
def change(ar, l, r):
for i in range(int(l), int(r)+1):
count = 1
for k in range(1,ar[i]):
if ar[i] % k == 0:
count += 1
ar[i] = count
#return ar
print(ar)
def sum(ar, l, r):
su = 0
for i in range(int(l)-1, int(r)):
su = su + int(ar[i])
return su
n , m = input().split(' ')
ll = list(input().split(' '))
for i in range(int(m)):
x, l, r = input().split(' ')
if x == 1:
change(ll, l, r)
else:
y = sum(ll, l, r)
print(y)
```
No
| 3,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) = 4 (6 is divisible by 1, 2, 3 and 6).
You are given an array a of n integers. You have to process two types of queries:
1. REPLACE l r — for every <image> replace ai with D(ai);
2. SUM l r — calculate <image>.
Print the answer for each SUM query.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 3·105) — the number of elements in the array and the number of queries to process, respectively.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the array.
Then m lines follow, each containing 3 integers ti, li, ri denoting i-th query. If ti = 1, then i-th query is REPLACE li ri, otherwise it's SUM li ri (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).
There is at least one SUM query.
Output
For each SUM query print the answer to it.
Example
Input
7 6
6 4 1 10 3 2 4
2 1 7
2 4 5
1 3 5
2 4 4
1 5 7
2 1 7
Output
30
13
4
22
Submitted Solution:
```
n,q = tuple(map(int,input().split()))
arr = list(map(int,input().split()))
import math
def get_factors(n):
if n<=2:
return 2
count = 0
for i in range(1,int(math.sqrt(n)) + 1):
if ( n%i) == 0:
if (n/i == i):
count += 1;
else:
count += 2;
return count;
def update(bit,index,val):
index+=1;
while index <= n:
bit[index] += val;
index += index & (-index)
def sum(bit, index):
SUM = 0
index+=1;
while index > 0:
SUM += bit[index]
index -= index & (-index)
return SUM
bit = [0 for _ in range(n+1)]
for i in range(n):
update(bit,i,arr[i])
for _ in range(q):
t,l,r = tuple(map(int,input().split()))
if t == 1: #replace
for i in range(l-1,r):
cal = get_factors(arr[i])
delta = cal - arr[i]
arr[i] = cal;
update(bit,i,delta)
else:
l-=1;r-=1;
if l == r:
print(arr[l])
continue;
if l==0:
left = 0
else:
left = sum(bit,l-1)
right = sum(bit,r)
print(right - left);
```
No
| 3,056 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Instructors of Some Informatics School make students go to bed.
The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to n. Initially, in i-th room there are ai students. All students are currently somewhere in the house, therefore a1 + a2 + ... + an = nb. Also 2 instructors live in this house.
The process of curfew enforcement is the following. One instructor starts near room 1 and moves toward room n, while the second instructor starts near room n and moves toward room 1. After processing current room, each instructor moves on to the next one. Both instructors enter rooms and move simultaneously, if n is odd, then only the first instructor processes the middle room. When all rooms are processed, the process ends.
When an instructor processes a room, she counts the number of students in the room, then turns off the light, and locks the room. Also, if the number of students inside the processed room is not equal to b, the instructor writes down the number of this room into her notebook (and turns off the light, and locks the room). Instructors are in a hurry (to prepare the study plan for the next day), so they don't care about who is in the room, but only about the number of students.
While instructors are inside the rooms, students can run between rooms that are not locked and not being processed. A student can run by at most d rooms, that is she can move to a room with number that differs my at most d. Also, after (or instead of) running each student can hide under a bed in a room she is in. In this case the instructor will not count her during the processing. In each room any number of students can hide simultaneously.
Formally, here is what's happening:
* A curfew is announced, at this point in room i there are ai students.
* Each student can run to another room but not further than d rooms away from her initial room, or stay in place. After that each student can optionally hide under a bed.
* Instructors enter room 1 and room n, they count students there and lock the room (after it no one can enter or leave this room).
* Each student from rooms with numbers from 2 to n - 1 can run to another room but not further than d rooms away from her current room, or stay in place. Each student can optionally hide under a bed.
* Instructors move from room 1 to room 2 and from room n to room n - 1.
* This process continues until all rooms are processed.
Let x1 denote the number of rooms in which the first instructor counted the number of non-hidden students different from b, and x2 be the same number for the second instructor. Students know that the principal will only listen to one complaint, therefore they want to minimize the maximum of numbers xi. Help them find this value if they use the optimal strategy.
Input
The first line contains three integers n, d and b (2 ≤ n ≤ 100 000, 1 ≤ d ≤ n - 1, 1 ≤ b ≤ 10 000), number of rooms in the house, running distance of a student, official number of students in a room.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109), i-th of which stands for the number of students in the i-th room before curfew announcement.
It is guaranteed that a1 + a2 + ... + an = nb.
Output
Output one integer, the minimal possible value of the maximum of xi.
Examples
Input
5 1 1
1 0 0 0 4
Output
1
Input
6 1 2
3 8 0 1 0 0
Output
2
Note
In the first sample the first three rooms are processed by the first instructor, and the last two are processed by the second instructor. One of the optimal strategies is the following: firstly three students run from room 5 to room 4, on the next stage two of them run to room 3, and one of those two hides under a bed. This way, the first instructor writes down room 2, and the second writes down nothing.
In the second sample one of the optimal strategies is the following: firstly all students in room 1 hide, all students from room 2 run to room 3. On the next stage one student runs from room 3 to room 4, and 5 students hide. This way, the first instructor writes down rooms 1 and 2, the second instructor writes down rooms 5 and 6.
Tags: binary search, brute force, greedy, sortings
Correct Solution:
```
read = lambda: map(int, input().split())
n, d, b = read()
d += 1
t, a = 0, [0] * (n + 1)
for i, x in enumerate(read()):
t += x
a[i + 1] = t
print(max(i - min(a[min(n, i * d)], (a[n] - a[max(0, n - i * d)])) // b for i in range(n + 3 >> 1)))
```
| 3,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Instructors of Some Informatics School make students go to bed.
The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to n. Initially, in i-th room there are ai students. All students are currently somewhere in the house, therefore a1 + a2 + ... + an = nb. Also 2 instructors live in this house.
The process of curfew enforcement is the following. One instructor starts near room 1 and moves toward room n, while the second instructor starts near room n and moves toward room 1. After processing current room, each instructor moves on to the next one. Both instructors enter rooms and move simultaneously, if n is odd, then only the first instructor processes the middle room. When all rooms are processed, the process ends.
When an instructor processes a room, she counts the number of students in the room, then turns off the light, and locks the room. Also, if the number of students inside the processed room is not equal to b, the instructor writes down the number of this room into her notebook (and turns off the light, and locks the room). Instructors are in a hurry (to prepare the study plan for the next day), so they don't care about who is in the room, but only about the number of students.
While instructors are inside the rooms, students can run between rooms that are not locked and not being processed. A student can run by at most d rooms, that is she can move to a room with number that differs my at most d. Also, after (or instead of) running each student can hide under a bed in a room she is in. In this case the instructor will not count her during the processing. In each room any number of students can hide simultaneously.
Formally, here is what's happening:
* A curfew is announced, at this point in room i there are ai students.
* Each student can run to another room but not further than d rooms away from her initial room, or stay in place. After that each student can optionally hide under a bed.
* Instructors enter room 1 and room n, they count students there and lock the room (after it no one can enter or leave this room).
* Each student from rooms with numbers from 2 to n - 1 can run to another room but not further than d rooms away from her current room, or stay in place. Each student can optionally hide under a bed.
* Instructors move from room 1 to room 2 and from room n to room n - 1.
* This process continues until all rooms are processed.
Let x1 denote the number of rooms in which the first instructor counted the number of non-hidden students different from b, and x2 be the same number for the second instructor. Students know that the principal will only listen to one complaint, therefore they want to minimize the maximum of numbers xi. Help them find this value if they use the optimal strategy.
Input
The first line contains three integers n, d and b (2 ≤ n ≤ 100 000, 1 ≤ d ≤ n - 1, 1 ≤ b ≤ 10 000), number of rooms in the house, running distance of a student, official number of students in a room.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109), i-th of which stands for the number of students in the i-th room before curfew announcement.
It is guaranteed that a1 + a2 + ... + an = nb.
Output
Output one integer, the minimal possible value of the maximum of xi.
Examples
Input
5 1 1
1 0 0 0 4
Output
1
Input
6 1 2
3 8 0 1 0 0
Output
2
Note
In the first sample the first three rooms are processed by the first instructor, and the last two are processed by the second instructor. One of the optimal strategies is the following: firstly three students run from room 5 to room 4, on the next stage two of them run to room 3, and one of those two hides under a bed. This way, the first instructor writes down room 2, and the second writes down nothing.
In the second sample one of the optimal strategies is the following: firstly all students in room 1 hide, all students from room 2 run to room 3. On the next stage one student runs from room 3 to room 4, and 5 students hide. This way, the first instructor writes down rooms 1 and 2, the second instructor writes down rooms 5 and 6.
Tags: binary search, brute force, greedy, sortings
Correct Solution:
```
func = lambda: map(int, input().split())
n, d, b = func()
d += 1
t, a = 0, [0] * (n + 1)
for i, x in enumerate(func()):
t += x
a[i + 1] = t
print(max(i - min(a[min(n, i * d)], (a[n] - a[max(0, n - i * d)])) // b for i in range(n + 3 >> 1)))
```
| 3,058 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Instructors of Some Informatics School make students go to bed.
The house contains n rooms, in each room exactly b students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to n. Initially, in i-th room there are ai students. All students are currently somewhere in the house, therefore a1 + a2 + ... + an = nb. Also 2 instructors live in this house.
The process of curfew enforcement is the following. One instructor starts near room 1 and moves toward room n, while the second instructor starts near room n and moves toward room 1. After processing current room, each instructor moves on to the next one. Both instructors enter rooms and move simultaneously, if n is odd, then only the first instructor processes the middle room. When all rooms are processed, the process ends.
When an instructor processes a room, she counts the number of students in the room, then turns off the light, and locks the room. Also, if the number of students inside the processed room is not equal to b, the instructor writes down the number of this room into her notebook (and turns off the light, and locks the room). Instructors are in a hurry (to prepare the study plan for the next day), so they don't care about who is in the room, but only about the number of students.
While instructors are inside the rooms, students can run between rooms that are not locked and not being processed. A student can run by at most d rooms, that is she can move to a room with number that differs my at most d. Also, after (or instead of) running each student can hide under a bed in a room she is in. In this case the instructor will not count her during the processing. In each room any number of students can hide simultaneously.
Formally, here is what's happening:
* A curfew is announced, at this point in room i there are ai students.
* Each student can run to another room but not further than d rooms away from her initial room, or stay in place. After that each student can optionally hide under a bed.
* Instructors enter room 1 and room n, they count students there and lock the room (after it no one can enter or leave this room).
* Each student from rooms with numbers from 2 to n - 1 can run to another room but not further than d rooms away from her current room, or stay in place. Each student can optionally hide under a bed.
* Instructors move from room 1 to room 2 and from room n to room n - 1.
* This process continues until all rooms are processed.
Let x1 denote the number of rooms in which the first instructor counted the number of non-hidden students different from b, and x2 be the same number for the second instructor. Students know that the principal will only listen to one complaint, therefore they want to minimize the maximum of numbers xi. Help them find this value if they use the optimal strategy.
Input
The first line contains three integers n, d and b (2 ≤ n ≤ 100 000, 1 ≤ d ≤ n - 1, 1 ≤ b ≤ 10 000), number of rooms in the house, running distance of a student, official number of students in a room.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109), i-th of which stands for the number of students in the i-th room before curfew announcement.
It is guaranteed that a1 + a2 + ... + an = nb.
Output
Output one integer, the minimal possible value of the maximum of xi.
Examples
Input
5 1 1
1 0 0 0 4
Output
1
Input
6 1 2
3 8 0 1 0 0
Output
2
Note
In the first sample the first three rooms are processed by the first instructor, and the last two are processed by the second instructor. One of the optimal strategies is the following: firstly three students run from room 5 to room 4, on the next stage two of them run to room 3, and one of those two hides under a bed. This way, the first instructor writes down room 2, and the second writes down nothing.
In the second sample one of the optimal strategies is the following: firstly all students in room 1 hide, all students from room 2 run to room 3. On the next stage one student runs from room 3 to room 4, and 5 students hide. This way, the first instructor writes down rooms 1 and 2, the second instructor writes down rooms 5 and 6.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 22 13:35:06 2018
@author: Minoru Jayakody
"""
n,d,b=map(int,input().split())
rooms=[]
for x in map(int,input().split()):
rooms.append(x)
for i in range(int(n/2)):
s,x1,x2=0,0,0
if rooms[i]>b:
pre_v=rooms[i]-b
rooms[i]=b
while s<d:
s=s+1
if (i+s)>int(n/2):
break
rooms[i+s]=pre_v
if pre_v>b:
pre_v-=b
rooms[i+s]=b
else:
break
else:
x1+=1
if rooms[-i]>b:
pre_v=rooms[-i]-b
rooms[-i]=b
while s<d:
s=s+1
if -(-i-s)>int(n/2):
break
rooms[-i-s]=pre_v
if pre_v>b:
pre_v-=b
rooms[-i-s]=b
else:
break
else:
x2+=1
print(x1+x2)
```
No
| 3,059 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Tags: sortings
Correct Solution:
```
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
a = sorted(a)
count = 0
if n < k:
print(-1)
exit()
if k == 0:
ans = a[0]-1
else:
ans = a[k-1]
for i in range(n):
if a[i]<= ans:
count+=1
if count != k or ans<1:
print(-1)
else:
print(ans)
```
| 3,060 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Tags: sortings
Correct Solution:
```
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
if k == 0:
if min(a) == 1:
print(-1)
else:
print(1)
exit()
c = a[k - 1] + 1
counter = 0
for el in a:
if el <= c:
counter += 1
if counter == k and c <= 10 ** 9:
print(c)
exit()
c = a[k - 1]
counter = 0
for el in a:
if el <= c:
counter += 1
if counter == k and c <= 10 ** 9:
print(c)
exit()
print(-1)
```
| 3,061 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Tags: sortings
Correct Solution:
```
z,zz=input,lambda:list(map(int,z().split()))
zzz=lambda:[int(i) for i in stdin.readline().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
p=ceil(x**.5)+1
for i in range(2,p):
if (x%i==0 and x!=2) or x==0:return 0
return 1
def dfs(u,visit,graph):
visit[u]=True
for i in graph[u]:
if not visit[i]:
dfs(i,visit,graph)
###########################---Test-Case---#################################
"""
"""
###########################---START-CODING---##############################
num=1
for _ in range( num ):
n,k=zz()
lst=[1]+szzz()
p=lst[k]
if k==n:
print(p)
continue
print(p if lst[k+1]-lst[k] else -1)
```
| 3,062 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Tags: sortings
Correct Solution:
```
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.append(1)
a.sort()
if k==n:
print(a[k])
else:
if a[k+1]-a[k]==0:
print(-1)
else:
print(a[k])
```
| 3,063 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Tags: sortings
Correct Solution:
```
n,k = map(int,input().split())
l = map(int,input().split())
l = sorted(l)
if k == 0:
if l[0] == 1:
print(-1)
else:
print(1)
elif k == n:
print(1000000000)
else:
if l[k] == l[k-1]:
print(-1)
else:
print(l[k-1])
```
| 3,064 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Tags: sortings
Correct Solution:
```
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
a.sort()
if k==0:
print(-1+a[0]*(a[0]>1))
quit()
if a[k-1] not in a[k:]:
print(a[k-1])
quit()
print(-1)
```
| 3,065 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Tags: sortings
Correct Solution:
```
n,k=map(int,input().split())
t=list(map(int,input().split()))
t.sort()
t=t[::-1]
d={}
for i in t:
if d.get(i)==None:
d[i]=1
else:
d[i]+=1
s=0
a=0
while d!={} and s<k:
l=d.popitem()
s+=l[1]
a=l[0]
if k==0 and t[-1]!=1:
print(1)
elif s==k and k!=0:
print(a)
else:
print(-1)
```
| 3,066 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Tags: sortings
Correct Solution:
```
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if k==0:
if a[0]==1:
print(-1)
else:
print(1)
elif k<=n-1 and a[k-1]==a[k]:
print(-1)
else:
print(a[k-1])
```
| 3,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Submitted Solution:
```
def quickSort(alist):
quickSortHelper(alist,0,len(alist)-1)
def quickSortHelper(alist,first,last):
if first<last:
splitpoint = partition(alist,first,last)
quickSortHelper(alist,first,splitpoint-1)
quickSortHelper(alist,splitpoint+1,last)
def partition(alist,first,last):
pivotvalue = alist[int((first+last)/2)]
leftmark = first+1
rightmark = last
done = False
while not done:
while leftmark <= rightmark and alist[leftmark] <= pivotvalue:
leftmark = leftmark + 1
while alist[rightmark] >= pivotvalue and rightmark >= leftmark:
rightmark = rightmark -1
if rightmark < leftmark:
done = True
else:
temp = alist[leftmark]
alist[leftmark] = alist[rightmark]
alist[rightmark] = temp
temp = alist[first]
alist[first] = alist[rightmark]
alist[rightmark] = temp
return rightmark
n,k = map(int,input().split())
alist = [int(x) for x in input().split()]
alist.sort()
if k==0:
if alist[0]==1:
print(-1)
else:
print(alist[0]-1)
else:
if k==n:
print(alist[n-1])
else:
if alist[k-1]==alist[k]:
print(-1)
else:
print(alist[k-1])
```
Yes
| 3,068 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Submitted Solution:
```
a = input()
b = input()
a = list(map(int, a.split()))
b = list(map(int, b.split()))
n=a[0]
k=a[1]
b.sort()
if k==0:
if b[0]!=1:
res = 1
else:
res = -1
elif k==len(b):
res = b[-1]
elif b[k-1]==b[k]:
res = -1
else:
res = b[k-1]
print(res)
```
Yes
| 3,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Submitted Solution:
```
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
if(k==0):
if(a[0]>=2):
print(a[0]-1)
else:
print(-1)
elif(n==k):
print(a[-1])
else:
if(a[k-1]==a[k]):
print("-1")
else:
print(a[k-1])
```
Yes
| 3,070 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Submitted Solution:
```
n, k = (int(x) for x in input().split())
s = list(map(int, input().split()))
ss = sorted(s)
if k == 0:
print(-1 if ss[0] == 1 else 1)
exit()
if k == n:
print(ss[-1])
exit()
if ss[k-1] != ss[k]:
print(ss[k-1])
else:
print(-1)
```
Yes
| 3,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Submitted Solution:
```
a = input().split(" ")
n, k = int(a[0]), int(a[1])
l1 = input().split(" ")
l2 = []
for item in l1:
l2.append(int(item))
l2.sort()
# print(f"n == {n}, k == {k}")
# print(l2)
if k == n or k == 0:
print(-1)
exit()
if l2[k-1] != l2[k]:
print(l2[k-1]+1)
else:
print(-1)
```
No
| 3,072 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Submitted Solution:
```
def check(k,j):
list1=[]
for x in j:
list1.append(int(x))
list1.sort()
a=list1[k-1]
if a==list1[k]:
return -1
else:
return a
i=input().split()
n=int(i[0])
k=int(i[1])
j=input().split()
print(check(k,j))
```
No
| 3,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Submitted Solution:
```
n, k = map(int, input().split())
nbs = sorted(list(map(int, input().split())))
if k == n:
print(nbs[n])
else:
if nbs[k-1] < nbs[k]:
print(nbs[k-1])
else:
print(-1)
```
No
| 3,074 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a sequence of integers of length n and integer number k. You should print any integer number x in the range of [1; 10^9] (i.e. 1 ≤ x ≤ 10^9) such that exactly k elements of given sequence are less than or equal to x.
Note that the sequence can contain equal elements.
If there is no such x, print "-1" (without quotes).
Input
The first line of the input contains integer numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 0 ≤ k ≤ n). The second line of the input contains n integer numbers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the sequence itself.
Output
Print any integer number x from range [1; 10^9] such that exactly k elements of given sequence is less or equal to x.
If there is no such x, print "-1" (without quotes).
Examples
Input
7 4
3 7 5 1 10 3 20
Output
6
Input
7 2
3 7 5 1 10 3 20
Output
-1
Note
In the first example 5 is also a valid answer because the elements with indices [1, 3, 4, 6] is less than or equal to 5 and obviously less than or equal to 6.
In the second example you cannot choose any number that only 2 elements of the given sequence will be less than or equal to this number because 3 elements of the given sequence will be also less than or equal to this number.
Submitted Solution:
```
f = input().split(" ")
n = int(f[0])
k = int(f[1])
a = input().split(" ")
for i in range(0, n):
a[i] = int(a[i])
a_updated = sorted(a)
if n <= k:
print(a_updated[-1]+1)
else:
if k != 0 and len(a_updated) > 1:
if a_updated[k-1] == a_updated[k]:
print(-1)
else:
print(a_updated[k-1])
elif k != 0 and len(a_updated) == 1:
if a_updated[0] != 1:
print(a_updated[0])
else:
print(-1)
elif k == 0:
if a_updated[0] != 1:
print(a_updated[0]-1)
else:
print(-1)
else:
print(a_updated[k-1])
```
No
| 3,075 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Tags: brute force, greedy, implementation, math
Correct Solution:
```
def main():
n, x, y = map(int, input().split())
s = input()
p = ''
t = []
for c in s:
if c != p:
t.append(c)
p = c
k = 0
for c in t:
if c == '0':
k += 1
if k == 0:
print(0)
elif k == 1:
print (y)
else:
if x < y:
print(x * (k - 1) + y)
else:
print(k * y)
main()
```
| 3,076 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Tags: brute force, greedy, implementation, math
Correct Solution:
```
def main():
n, x, y = map(int, input().split())
s, zo, a = input(), [0, 0], ' '
for b in s:
if a != b:
zo[b == '1'] += 1
a = b
z, o = zo
if s[0] == '1':
o -= 1
if s[-1] == '1':
o -= 1
if o < 0:
o = 0
print(min(z * y, o * x + y))
if __name__ == '__main__':
main()
```
| 3,077 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Tags: brute force, greedy, implementation, math
Correct Solution:
```
n, x, y = list(map(int, input().split()))
s = ""
len_s = 0
a = input()
for i in range(n):
if len_s == 0:
s += a[i]
len_s += 1
elif a[i] != s[len_s - 1]:
s += a[i]
len_s += 1
sm = 0
if x < y:
if len(s) > 3:
sm += x * ((len(s) - 2)//2)
else:
if len(s) > 3:
sm += y * ((len(s) - 2)//2)
sm += y
if len(s) != 1 and s[0] == '0' and s[len(s) - 1] == '0':
if y < x:
sm += y
else:
sm += x
if s == '1':
sm = 0
print(sm)
```
| 3,078 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Tags: brute force, greedy, implementation, math
Correct Solution:
```
n, x, y = list(map(int,input().strip().split(' ')))
s = input()
groups = 0
if s[0] == '0':
groups += 1
for b in range(1,n):
if s[b] == '0' and s[b-1] == '1':
groups += 1
if groups == 0:
print(0)
else:
print((groups - 1) * min(x,y) + y)
```
| 3,079 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Tags: brute force, greedy, implementation, math
Correct Solution:
```
n,x,y = map(int,input().split())
s = input()
c=0
for i in range(0,len(s)-1):
if s[i]=='0' and s[i+1]=='1': c+=1
if(s[len(s)-1])=='0': c+=1
if c==0: print(0)
else: print((c-1)*min(x,y)+y)
```
| 3,080 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Tags: brute force, greedy, implementation, math
Correct Solution:
```
n, x, y = map(int, input().split())
u = list(map(int, input()))
d0 = 0
k0 = 0
for i in range(n):
if k0 == 1 and u[i] == 1:
d0 += 1
k0 = 0
elif u[i] == 0:
k0 = 1
if k0 == 1:
d0 += 1
if d0 == 0:
p = 0
else:
p = (d0 - 1) * min(x, y) + y
print(p)
```
| 3,081 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Tags: brute force, greedy, implementation, math
Correct Solution:
```
n , x , y = map(int , input().split())
s = input()
c = 0
for i in range(len(s)-1):
if s[i] == '0' and s[i+1] == '1' :
c += 1
if s[len(s)-1] == '0' :
c += 1
if c == 0 :
print(0)
else :
print((c-1)*min(x , y) + y )
```
| 3,082 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Tags: brute force, greedy, implementation, math
Correct Solution:
```
n, reverse, change = map(int, input().split())
a = input()
g = list(filter(lambda x: x, a.split('1')))
nGroups = len(g)
print(0 if not nGroups else min((nGroups - 1) * reverse + change, nGroups * change))
```
| 3,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Submitted Solution:
```
n, x, y = tuple(map(int, input().split()))
str = input()
num = 0
i = 0
while i < len(str):
if str[i] == '0':
j = i + 1
num += 1
while j < len(str) and str[j] == '0':
j += 1
i = j
i += 1
if n*'1' == str:
print(0)
else:
if x <= y:
print((num-1)*x+y)
else:
print(num*y)
```
Yes
| 3,084 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Submitted Solution:
```
n,x,y = map(int,input().split())
s = input()
count = 0
if(s[0] == '1'):
tp = -1
else:
tp = 0
count = 1
for i in range(1,n):
if s[i] == '0':
if tp == -1:
tp = 0
count += 1
else:
if tp == 0:
tp = -1
if x >= y:
print(count*y)
else:
if count >= 2:
print((count -1)*x + y)
elif count == 1 :
print(y)
else:
print(0)
```
Yes
| 3,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Submitted Solution:
```
n, x, y = (int (i) for i in input ().split())
s = input ()
on = False
c = 0
for e in s:
if (e == '0' and not on):
on = True
c += 1
elif (e == '1'):
on = False
print (max(0, min((c-1)*x + y, c*y)))
```
Yes
| 3,086 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Submitted Solution:
```
n, x, y = [int(i) for i in input().split()]
s = [int(i) for i in input()]
lis = []
ind = -1
flag0 = flag1 = 0
for i in range(n):
if s[i] == 0 and flag0 == 0:
ind = i
flag0 = 1
flag1 = 0
else:
if s[i] == 1 and flag1 == 0:
if ind != -1:
lis.append(ind)
flag1 = 1
flag0 = 0
if flag1 == 0 and flag0 == 1:
if ind != -1:
lis.append(ind)
x1 = len(lis)
if x1 == 0:
print(0)
else:
ans = (x1 - 1) * (min(x, y)) + y
print(ans)
```
Yes
| 3,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Submitted Solution:
```
print(50)
```
No
| 3,088 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Submitted Solution:
```
"""
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000
"""
# import sys
# input = sys.stdin.buffer.readline
def solution():
n,x,y=map(int,input().split())
s=input()
flag=0
cnt=0
for i in range(0,n-1):
if s[i]=='0' and s[i+1]=='1':
cnt+=1
if s[i]=='1' and s[i+1]=='0':
cnt+=1
if '0' in s and cnt==0:
cnt=1
# print(cnt)
if cnt==0:
print(0)
else:
if x<y:
print((cnt-1)*x+y)
else:
print((cnt)*y)
solution()
```
No
| 3,089 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Submitted Solution:
```
n,x,y=map(int,input().split())
A=list(input())
c=0
cur=A[0]
for i in A:
if i!=cur:
c+=1
cur=i
if x*(c-1)+y<=y*c:
print(x*(c-1)+y)
else:
print(y*c)
```
No
| 3,090 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You've got a string a_1, a_2, ..., a_n, consisting of zeros and ones.
Let's call a sequence of consecutive elements a_i, a_{i + 1}, …, a_j (1≤ i≤ j≤ n) a substring of string a.
You can apply the following operations any number of times:
* Choose some substring of string a (for example, you can choose entire string) and reverse it, paying x coins for it (for example, «0101101» → «0111001»);
* Choose some substring of string a (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying y coins for it (for example, «0101101» → «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input
The first line of input contains integers n, x and y (1 ≤ n ≤ 300 000, 0 ≤ x, y ≤ 10^9) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string a of length n, consisting of zeros and ones.
Output
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print 0, if you do not need to perform any operations.
Examples
Input
5 1 10
01000
Output
11
Input
5 10 1
01000
Output
2
Input
7 2 3
1111111
Output
0
Note
In the first sample, at first you need to reverse substring [1 ... 2], and then you need to invert substring [2 ... 5].
Then the string was changed as follows:
«01000» → «10000» → «11111».
The total cost of operations is 1 + 10 = 11.
In the second sample, at first you need to invert substring [1 ... 1], and then you need to invert substring [3 ... 5].
Then the string was changed as follows:
«01000» → «11000» → «11111».
The overall cost is 1 + 1 = 2.
In the third example, string already consists only of ones, so the answer is 0.
Submitted Solution:
```
a,b,c=map(int,input().split())
n=list(input())
n=n[::-1]
l=0
w=0
p=min(b,c)
i=0
while n[i]=="0":
i+=1
w=1
if i==a:
break
while i<a:
if n[i]=="0":
w+=1
l+=p
while n[i]=="0":
i+=1
if i==a:
break
else:
if n[i]=="1":
while n[i]=="1":
i+=1
if i==a:
break
#print(l,i)
l+=c
print(l)
```
No
| 3,091 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).
Constraints
* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).
Examples
Input
4 2 3
Output
11
Input
10 7 2
Output
533
Input
1000 100 10
Output
828178524
"Correct Solution:
```
MOD = 10 ** 9 + 7
n, a, b = map(int, input().split())
if a > b:
a, b = b, a
dp_1s = [0] * b
for l in range(a + 2, b):
dp = [[0, 0] for _ in range(l + 1)] # at i, 0/1 precedes
dp[1][1] = 1
for i in range(1, l):
dp[i + 1][0] = (dp[i + 1][0] + dp[i][0]) % MOD
dp[i + 1][1] = (dp[i + 1][1] + dp[i][0] + dp[i][1]) % MOD
if i + a < l:
dp[i + a][0] = (dp[i + a][0] + dp[i][1]) % MOD
dp_1s[l] = dp[l][1] - 1
dp_0s_edge = [0] * b
for l in range(a + 1, b):
dp = [[0, 0] for _ in range(l + 1)]
dp[a][0] = 1
for i in range(1, l):
dp[i + 1][0] = (dp[i + 1][0] + dp[i][0]) % MOD
dp[i + 1][1] = (dp[i + 1][1] + dp[i][0] + dp[i][1]) % MOD
if i + a < l:
dp[i + a][0] = (dp[i + a][0] + dp[i][1]) % MOD
dp_0s_edge[l] = dp[l][1]
# starting at i, 0s/1s precede, i.e., 1s/0s follow
# when 0s precede, len of preceding 0s is lt a
dp = [[0, 0] for _ in range(n + 1)]
dp[0] = [1, 1]
# starting with 0s whose len is gt or eq to a
for l in range(a + 1, b):
dp[l][1] = dp_0s_edge[l]
for i in range(n):
for j in range(i + 1, min(n + 1, i + b)):
dp[j][1] = (dp[j][1] + dp[i][0]) % MOD
for j in range(i + 1, min(n + 1, i + a)):
dp[j][0] = (dp[j][0] + dp[i][1]) % MOD
for l in range(a + 2, b):
if i + l <= n:
dp[i + l][1] = (dp[i + l][1] + dp[i][0] * dp_1s[l]) % MOD
# ending with 0s whose len is gt or eq to a
for l in range(a + 1, b):
dp[n][0] = (dp[n][0] + dp[n - l][0] * dp_0s_edge[l]) % MOD
print((pow(2, n, MOD) - sum(dp[n])) % MOD)
```
| 3,092 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).
Constraints
* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).
Examples
Input
4 2 3
Output
11
Input
10 7 2
Output
533
Input
1000 100 10
Output
828178524
"Correct Solution:
```
n,aa,bb = list(map(int, input().split()))
a = max(aa,bb)
b = min(aa,bb)
p = 1000000007
xs0 = [0]*(n+1)
os0 = [0]*(n+1)
os0[0] = 1
for i in range(b,a-1):
for j in range(b,i+1):
xs0[i] += os0[i-j]
xs0[i] %= p
for j in range(1,i+1):
os0[i] += xs0[i-j]
os0[i] %= p
#print(xs0[:50])
#print(os0[:50])
os = [0]*a
for i in range(b,a-2): #number-x
for j in range(2,a-i): # adding o
os[i+j] += xs0[i] * (j-1)
x = [0]*(n+1)
o = [0]*(n+1)
for i in range(b+1,a): # adding distination
for j in range(b,i): # length of xs
o[i] += xs0[j]
o[i] %= p
x[0] = 1
o[0] = 1
for i in range(1,n+1):
for j in range(1,min(b,i+1)):
x[i] += o[i-j]
for j in range(1,min(a,i+1)):
o[i] += x[i-j]
for j in range(b+2,min(a,i+1)):
o[i] += x[i-j]*os[j]
x[i] %= p
o[i] %= p
for i in range(b+1,a):
for j in range(b,i):
o[n] += xs0[j] * x[n-i]
o[i]%=p
ans = o[n] + x[n]
ans %= p
#print(ans)
beki2 = [1]*5001
for i in range(5000):
beki2[i+1] = beki2[i]*2
beki2[i+1] %= p
ans = beki2[n] - ans
ans += p
ans %= p
print(ans)
```
| 3,093 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).
Constraints
* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).
Examples
Input
4 2 3
Output
11
Input
10 7 2
Output
533
Input
1000 100 10
Output
828178524
"Correct Solution:
```
import math
#import sys
#input = sys.stdin.readline
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
def ValueToBits(x,digit):
res = [0 for i in range(digit)]
now = x
for i in range(digit):
res[i]=now%2
now = now >> 1
return res
def BitsToValue(arr):
n = len(arr)
ans = 0
for i in range(n):
ans+= arr[i] * 2**i
return ans
def ZipArray(a):
aa = [[a[i],i]for i in range(n)]
aa.sort(key = lambda x : x[0])
for i in range(n):
aa[i][0]=i+1
aa.sort(key = lambda x : x[1])
b=[aa[i][0] for i in range(len(a))]
return b
def ValueToArray10(x, digit):
ans = [0 for i in range(digit)]
now = x
for i in range(digit):
ans[digit-i-1] = now%10
now = now //10
return ans
def Zeros(a,b):
if(b<=-1):
return [0 for i in range(a)]
else:
return [[0 for i in range(b)] for i in range(a)]
def AddV2(v,w):
return [v[0]+w[0],v[1]+w[1]]
dir4 = [[1,0],[0,1],[-1,0],[0,-1]]
def clamp(x,y,z):
return max(y,min(z,x))
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
#
def Zaatsu(a):
a.sort()
now = a[0][0]
od = 0
for i in range(n):
if(now==a[i][0]):
a[i][0]=od
else:
now = a[i][0]
od+=1
a[i][0] = od
a.sort(key = lambda x : x[1])
return a
class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
# 検索
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
self.par[x] = y
else:
self.par[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same_check(self, x, y):
return self.find(x) == self.find(y)
'''
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 2
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
'''
def rl(x):
return range(len(x))
# a = list(map(int, input().split()))
#################################################
#################################################
#################################################
#################################################
#11-
n,aa,bb = list(map(int, input().split()))
a = max(aa,bb)
b = min(aa,bb)
p = 1000000007
xs0 = [0]*(n+1)
os0 = [0]*(n+1)
os0[0] = 1
for i in range(b,a-1):
for j in range(b,i+1):
xs0[i] += os0[i-j]
xs0[i] %= p
for j in range(1,i+1):
os0[i] += xs0[i-j]
os0[i] %= p
#print(xs0[:50])
#print(os0[:50])
os = [0]*a
for i in range(b,a-2): #number-x
for j in range(2,a-i): # adding o
os[i+j] += xs0[i] * (j-1)
x = [0]*(n+1)
o = [0]*(n+1)
for i in range(b+1,a): # adding distination
for j in range(b,i): # length of xs
o[i] += xs0[j]
o[i] %= p
x[0] = 1
o[0] = 1
for i in range(1,n+1):
for j in range(1,min(b,i+1)):
x[i] += o[i-j]
for j in range(1,min(a,i+1)):
o[i] += x[i-j]
for j in range(b+2,min(a,i+1)):
o[i] += x[i-j]*os[j]
x[i] %= p
o[i] %= p
for i in range(b+1,a):
for j in range(b,i):
o[n] += xs0[j] * x[n-i]
o[i]%=p
ans = o[n] + x[n]
ans %= p
#print(ans)
beki2 = [1]*5001
for i in range(5000):
beki2[i+1] = beki2[i]*2
beki2[i+1] %= p
ans = beki2[n] - ans
ans += p
ans %= p
print(ans)
```
| 3,094 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).
Constraints
* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).
Examples
Input
4 2 3
Output
11
Input
10 7 2
Output
533
Input
1000 100 10
Output
828178524
"Correct Solution:
```
N,A,B=map(int,input().split())
mod=10**9+7
A,B=min(A,B),max(A,B)
data=[0]*B
data[0]=1
for i in range(1,B):
data[i]=(data[i-1]+sum(data[i-1-k] for k in range(A,i)))%mod
#print(data)
dp=[0]*(N+1)
dp[0]=1
imos=[0]*(N+1)
imos[0]=1
for i in range(1,N+1):
if i!=N:
for j in range(1,min(i,B)):
#dp[i]+=sum(dp[i-j-k]*data[j-1] for k in range(1,min(A,i-j+1)))
R=i-j-1
L=i-j-min(A,i-j+1)
if R>L:
if L>-1:
dp[i]+=(imos[R]-imos[L])*data[j-1]
else:
dp[i]+=imos[R]*data[j-1]
dp[i]%=mod
if B>i:
dp[i]+=data[i]
dp[i]%=mod
else:
for j in range(B):
#dp[i]+=sum(dp[i-j-k]*data[j] for k in range(1,min(A,i-j+1)))
R=i-j-1
L=i-j-min(A,i-j+1)
if R>L:
if L>-1:
dp[i]+=(imos[R]-imos[L])*data[j]
else:
dp[i]+=imos[R]*data[j]
dp[i]%=mod
#print(dp[i])
#dp[i]+=sum(dp[i-k] for k in range(1,A))
imos[i]=dp[i]
imos[i]+=imos[i-1]
imos[i]%=mod
#print(dp)
print((pow(2,N,mod)-dp[N])%mod)
```
| 3,095 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).
Constraints
* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).
Examples
Input
4 2 3
Output
11
Input
10 7 2
Output
533
Input
1000 100 10
Output
828178524
"Correct Solution:
```
def solve(n, a, b):
MOD = 10 ** 9 + 7
if a > b:
a, b = b, a
if a == 1:
return pow(2, n, MOD)
# 長さ i の区間であり、右端が '1' であり、
# はじめ '1' で塗りつぶされていたのを、
# 長さ a 以上の '0' で0回以上上書きすることで実現できる並びの個数
dp1 = [0] * (b + 1)
dp1_acc = [0] * (b + 1)
dp1[0] = 1
dp1_acc[0] = 1
for i in range(1, b + 1):
tmp = dp1[i - 1] # 末尾に1を付ける
if i - a - 1 >= 0:
tmp = (tmp + dp1_acc[i - a - 1]) % MOD # 末尾に 00..01 を付ける
dp1[i] = tmp
dp1_acc[i] = (dp1_acc[i - 1] + tmp) % MOD
# 派生情報
# dp1[i-1]: 長さ i の区間であり、「両端」が'1'であるものの個数
# dp1[i] - dp1[i-1]: 長さ i の区間であり、左端が'0'、右端が'1'(またはその逆)のものの個数
# dp2x[i]
# 長さ i の区間であり、末尾が x であり、
# 長さa以上の'0'も、長さb以上の'1'も含まない01の並びの個数
# ただし'1'は、dp1で求めたように、その内部をa個以上の'0'で置きかえたものも含む
dp20 = [0] * (n + 1)
dp21 = [0] * (n + 1)
dp21_acc = [0] * (n + 1)
dp20[0] = dp21[0] = dp21_acc[0] = 1
for i in range(1, n + 1):
t0 = dp21_acc[i - 1]
if i >= a:
t0 -= dp21_acc[i - a]
dp20[i] = t0 % MOD
t1 = 0
for j in range(1, min(i + 1, b)):
t1 += dp20[i - j] * dp1[j - 1]
# 左端が '111...' でb個以上取れないもので、さらに'0'で置きかえられた結果、最左端が'0'のもの
if i < b:
t1 += dp1[i] - dp1[i - 1]
t1 %= MOD
dp21[i] = t1
dp21_acc[i] = (dp21_acc[i - 1] + t1) % MOD
disable = dp20[n] + dp21[n]
# 最後が'111..'でb個以上取れないもので、
# さらに'0'で置きかえられた結果、右端が'0'のものが数えられていない
for i in range(1, b):
disable += dp20[n - i] * (dp1[i] - dp1[i - 1])
return (pow(2, n, MOD) - disable) % MOD
n, a, b = map(int, input().split())
print(solve(n, a, b))
```
| 3,096 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).
Constraints
* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).
Examples
Input
4 2 3
Output
11
Input
10 7 2
Output
533
Input
1000 100 10
Output
828178524
"Correct Solution:
```
"""
Writer: SPD_9X2
すべて0にする、すべて1にするは自明に可能
なので A >= B としてよい(A<Bの時は01を入れ替えて考えればよい)
最後に置いた場所の周囲がどんな状況か考える
0*Aがある場合、その周囲はすべての場合構成可能
ない場合は…?
1*Bがある場合を考える。長さB以上の1列は後からおけるからおkだが…
長さB以上の1をすべて0に変えたときに、長さA以上の0があればおk
どう数え上げる?
ダメな場合を引くのがよさそう?
→dp[i][last][num] = i番目まで見て、lastを現在num個連続しておいている場合の通り数
ただし、dp[?][1][B-1]はdp[?][0][B]に伝播する
これまずいか
ブロックで考えるやり方はどうなんだろう
つまり、連鎖を断ち切れるのは長さB以下の1列だけ
0 or B以上連続する1の列のみで構成されたブロックX(Yに隣接する端は0である必要あり)
B未満の1列であるブロックYを交互に置いていく
dp[i][XorY] = i番目の文字を次に置けるとき、最後に置いたブロックがXorYの時の通り数
初期値は
dp[0][X] = 1
dp[0][Y] = 1 ←これ、かなり注意する必要がある左端が1でもいいから
同様に、Nに移行する時にXを置くときも右端を1にできるのに注意
B以上連続する1を0に変えるとすべて0になる文字列の数をまず求める
上と同様にブロックdp?
0のブロックは,1以上のどんな長さでも置ける
1のブロックは,B以上の長さ置ける
dp[0][Z] = 1
dp[0][O] = 1
"""
N,A,B = map(int,input().split())
fdp = [[0,0] for i in range(N+1)]
fdp[0] = [1,1]
mod = 10**9+7
if A < B:
tmp = B
B = A
A = tmp
for i in range(N):
for j in range(i+1,N+1):
fdp[j][0] += fdp[i][1]
fdp[j][0] %= mod
for j in range(i+B,N+1):
fdp[j][1] += fdp[i][0]
fdp[j][1] %= mod
#print (fdp)
dp = [[0,0] for i in range(N+1)]
dp[0] = [1,1]
for i in range(N):
for j in range(i+1,min(N+1,i+B)):
dp[j][1] += dp[i][0]
dp[j][1] %= mod
#ここかなり注意
for j in range(i+1,min(N+1,i+A)):
l = j-i
if i == 0 or j == N:
if l == 1:
dp[j][0] += dp[i][1]
dp[j][0] %= mod
else:
dp[j][0] += dp[i][1] * sum(fdp[l-1])
dp[j][0] %= mod
else:
if l <= 2:
dp[j][0] += dp[i][1]
dp[j][0] %= mod
else:
dp[j][0] += dp[i][1] * sum(fdp[l-2])
dp[j][0] %= mod
#print (dp)
print ((pow(2,N,mod)-sum(dp[N])) % mod)
```
| 3,097 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).
Constraints
* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).
Examples
Input
4 2 3
Output
11
Input
10 7 2
Output
533
Input
1000 100 10
Output
828178524
Submitted Solution:
```
def combination_mod(n, r, mod):
# フェルマーの小定理
# nCr=n!(r!)^p-2((n-r)!)^p-2
n_ = 1
for i in range(1, n + 1):
n_ = (n_ * i) % mod
r_ = 1
for i in range(1, r + 1):
r_ = (r_ * i) % mod
nr_ = 1
for i in range(1, n - r + 1):
nr_ = (nr_ * i) % mod
power_r = pow(r_, mod - 2, mod)
power_nr = pow(nr_, mod - 2, mod)
return (n_ * power_r * power_nr) % mod
def main():
N,A,B=map(int,input().split())
mod=pow(10,9)+7
PatternA=0
PatternB=0
#PatternA
for a in range(N-(A-1)):
PatternA+=combination_mod(N-(A-1),a,mod)
#PatternB
for b in range(N-(B-1)):
PatternB+=combination_mod(N-(B-1),b,mod)
res=PatternA+PatternB
print(res+1)
if __name__=="__main__":
main()
```
No
| 3,098 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke has a string x of length N. Initially, every character in x is `0`.
Snuke can do the following two operations any number of times in any order:
* Choose A consecutive characters in x and replace each of them with `0`.
* Choose B consecutive characters in x and replace each of them with `1`.
Find the number of different strings that x can be after Snuke finishes doing operations. This count can be enormous, so compute it modulo (10^9+7).
Constraints
* 1 \leq N \leq 5000
* 1 \leq A,B \leq N
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of different strings that x can be after Snuke finishes doing operations, modulo (10^9+7).
Examples
Input
4 2 3
Output
11
Input
10 7 2
Output
533
Input
1000 100 10
Output
828178524
Submitted Solution:
```
def combination_mod(n, r, mod):
# フェルマーの小定理
# nCr=n!(r!)^p-2((n-r)!)^p-2
n_ = 1
for i in range(1, n + 1):
n_ = (n_ * i) % mod
r_ = 1
for i in range(1, r + 1):
r_ = (r_ * i) % mod
nr_ = 1
for i in range(1, n - r + 1):
nr_ = (nr_ * i) % mod
power_r = pow(r_, mod - 2, mod)
power_nr = pow(nr_, mod - 2, mod)
return (n_ * power_r * power_nr) % mod
def main():
N,A,B=map(int,input().split())
mod=pow(10,9)+7
PatternA=0
PatternB=0
#PatternA
for a in range(1,N-A+2):
PatternA+=combination_mod(N-(A-1),a,mod)
#PatternB
for b in range(1,N-B+2):
PatternB+=combination_mod(N-(B-1),b,mod)
res=PatternA+PatternB
print(res+1)
if __name__=="__main__":
main()
```
No
| 3,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.