message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every k-th (2 β€ k β€ n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be b) and then close all tabs with numbers c = b + i β
k that satisfy the following condition: 1 β€ c β€ n and i is an integer (it may be positive, negative or zero).
For example, if k = 3, n = 14 and Roman chooses b = 8, then he will close tabs with numbers 2, 5, 8, 11 and 14.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it e) and the amount of remaining social network tabs (s). Help Roman to calculate the maximal absolute value of the difference of those values |e - s| so that it would be easy to decide what to do next.
Input
The first line contains two integers n and k (2 β€ k < n β€ 100) β the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of n integers, each of them equal either to 1 or to -1. The i-th integer denotes the type of the i-th tab: if it is equal to 1, this tab contains information for the test, and if it is equal to -1, it's a social network tab.
Output
Output a single integer β the maximum absolute difference between the amounts of remaining tabs of different types |e - s|.
Examples
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
Note
In the first example we can choose b = 1 or b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e = 2 and s = 0 and |e - s| = 2.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
Submitted Solution:
```
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
su=sum(l)
ll=[0 for i in range(k)]
j=0
for i in range(n):
ll[j]+=l[i]
j+=1
j%=k
res=0
for i in ll:
res=max(res,abs(su-i))
print(res)
``` | instruction | 0 | 65,662 | 14 | 131,324 |
Yes | output | 1 | 65,662 | 14 | 131,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every k-th (2 β€ k β€ n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be b) and then close all tabs with numbers c = b + i β
k that satisfy the following condition: 1 β€ c β€ n and i is an integer (it may be positive, negative or zero).
For example, if k = 3, n = 14 and Roman chooses b = 8, then he will close tabs with numbers 2, 5, 8, 11 and 14.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it e) and the amount of remaining social network tabs (s). Help Roman to calculate the maximal absolute value of the difference of those values |e - s| so that it would be easy to decide what to do next.
Input
The first line contains two integers n and k (2 β€ k < n β€ 100) β the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of n integers, each of them equal either to 1 or to -1. The i-th integer denotes the type of the i-th tab: if it is equal to 1, this tab contains information for the test, and if it is equal to -1, it's a social network tab.
Output
Output a single integer β the maximum absolute difference between the amounts of remaining tabs of different types |e - s|.
Examples
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
Note
In the first example we can choose b = 1 or b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e = 2 and s = 0 and |e - s| = 2.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
Submitted Solution:
```
# -*- coding: utf-8 -*-
# @Date : 2019-08-25 18:52:26
# @Author : raj lath (oorja.halt@gmail.com)
# @Link : link
# @Version : 1.0.0
import sys
sys.setrecursionlimit(10**5+1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
n, k = RMI()
tabs = RMI()
sums = sum(tabs)
close= 0
for i in range(k):
close = max(close, abs(sums - sum(tabs[i::k])))
print(close)
``` | instruction | 0 | 65,663 | 14 | 131,326 |
Yes | output | 1 | 65,663 | 14 | 131,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every k-th (2 β€ k β€ n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be b) and then close all tabs with numbers c = b + i β
k that satisfy the following condition: 1 β€ c β€ n and i is an integer (it may be positive, negative or zero).
For example, if k = 3, n = 14 and Roman chooses b = 8, then he will close tabs with numbers 2, 5, 8, 11 and 14.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it e) and the amount of remaining social network tabs (s). Help Roman to calculate the maximal absolute value of the difference of those values |e - s| so that it would be easy to decide what to do next.
Input
The first line contains two integers n and k (2 β€ k < n β€ 100) β the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of n integers, each of them equal either to 1 or to -1. The i-th integer denotes the type of the i-th tab: if it is equal to 1, this tab contains information for the test, and if it is equal to -1, it's a social network tab.
Output
Output a single integer β the maximum absolute difference between the amounts of remaining tabs of different types |e - s|.
Examples
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
Note
In the first example we can choose b = 1 or b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e = 2 and s = 0 and |e - s| = 2.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
Submitted Solution:
```
n,m=map(int,input().split())
l=list(map(int,input().split()))
ma=0
for i in range(n) :
k=0
k1=0
for j in range(n) :
if (j-i)%m!=0 :
if l[j]==1 :
k+=1
else :
k1+=1
ma=max(ma,abs(k-k1))
print(ma)
``` | instruction | 0 | 65,664 | 14 | 131,328 |
Yes | output | 1 | 65,664 | 14 | 131,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every k-th (2 β€ k β€ n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be b) and then close all tabs with numbers c = b + i β
k that satisfy the following condition: 1 β€ c β€ n and i is an integer (it may be positive, negative or zero).
For example, if k = 3, n = 14 and Roman chooses b = 8, then he will close tabs with numbers 2, 5, 8, 11 and 14.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it e) and the amount of remaining social network tabs (s). Help Roman to calculate the maximal absolute value of the difference of those values |e - s| so that it would be easy to decide what to do next.
Input
The first line contains two integers n and k (2 β€ k < n β€ 100) β the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of n integers, each of them equal either to 1 or to -1. The i-th integer denotes the type of the i-th tab: if it is equal to 1, this tab contains information for the test, and if it is equal to -1, it's a social network tab.
Output
Output a single integer β the maximum absolute difference between the amounts of remaining tabs of different types |e - s|.
Examples
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
Note
In the first example we can choose b = 1 or b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e = 2 and s = 0 and |e - s| = 2.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
Submitted Solution:
```
"""
____ _ _____
/ ___|___ __| | ___| ___|__ _ __ ___ ___ ___
| | / _ \ / _` |/ _ \ |_ / _ \| '__/ __/ _ \/ __|
| |__| (_) | (_| | __/ _| (_) | | | (_| __/\__ \
\____\___/ \__,_|\___|_| \___/|_| \___\___||___/
"""
"""
βββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
"""
import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt
from bisect import bisect_right, bisect_left
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2**20)
def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)
def ncr(n, r):
r = min(r, n - r)
numer = reduce(op.mul, range(n, n - r, -1), 1)
denom = reduce(op.mul, range(1, r + 1), 1)
return numer // denom # or / in Python 2
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return len(set(factors))
def isPowerOfTwo(x):
return (x and (not(x & (x - 1))))
def factors(n):
return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def printp(p):
for i in p:
print(i)
MOD = 10**9 + 7
T = 1
# T = int(stdin.readline())
for _ in range(T):
# n, k = list(map(int, stdin.readline().split()))
# s1 = list(stdin.readline().strip('\n'))
# s = str(stdin.readline().strip('\n'))
# n = int(stdin.readline())
n, k = list(map(int, stdin.readline().split()))
# s = list(stdin.readline().strip('\n'))
a = list(map(int, stdin.readline().split()))
if abs(sum(a)) == n:
print(n - k)
continue
val = inf
for b in range(n):
ac = a.copy()
i, j = 0, 0
while b + i * k < n:
ac[b + i * k] = 0
i += 1
while b - j * k >= 0:
ac[b - j * k] = 0
j += 1
e = ac.count(1)
s = ac.count(-1)
val = min(val, abs(e + s))
print(val)
``` | instruction | 0 | 65,665 | 14 | 131,330 |
No | output | 1 | 65,665 | 14 | 131,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every k-th (2 β€ k β€ n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be b) and then close all tabs with numbers c = b + i β
k that satisfy the following condition: 1 β€ c β€ n and i is an integer (it may be positive, negative or zero).
For example, if k = 3, n = 14 and Roman chooses b = 8, then he will close tabs with numbers 2, 5, 8, 11 and 14.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it e) and the amount of remaining social network tabs (s). Help Roman to calculate the maximal absolute value of the difference of those values |e - s| so that it would be easy to decide what to do next.
Input
The first line contains two integers n and k (2 β€ k < n β€ 100) β the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of n integers, each of them equal either to 1 or to -1. The i-th integer denotes the type of the i-th tab: if it is equal to 1, this tab contains information for the test, and if it is equal to -1, it's a social network tab.
Output
Output a single integer β the maximum absolute difference between the amounts of remaining tabs of different types |e - s|.
Examples
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
Note
In the first example we can choose b = 1 or b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e = 2 and s = 0 and |e - s| = 2.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
Submitted Solution:
```
put = lambda: tuple(map(int, input().split()))
n, k = put()
a = list(put())
f = a.count(1)
s = a.count(-1)
def check(start):
cnt_a = 0
cnt_b = 0
while start < n:
if a[start] == 1:
cnt_a += 1
else:
cnt_b += 1
start += k
return cnt_a, cnt_b
ans = []
for i in range((n + k) // 2 - 1):
x, y = check(i)
ans.append(abs((f - x) - (s - y)))
print(max(ans))
``` | instruction | 0 | 65,666 | 14 | 131,332 |
No | output | 1 | 65,666 | 14 | 131,333 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every k-th (2 β€ k β€ n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be b) and then close all tabs with numbers c = b + i β
k that satisfy the following condition: 1 β€ c β€ n and i is an integer (it may be positive, negative or zero).
For example, if k = 3, n = 14 and Roman chooses b = 8, then he will close tabs with numbers 2, 5, 8, 11 and 14.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it e) and the amount of remaining social network tabs (s). Help Roman to calculate the maximal absolute value of the difference of those values |e - s| so that it would be easy to decide what to do next.
Input
The first line contains two integers n and k (2 β€ k < n β€ 100) β the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of n integers, each of them equal either to 1 or to -1. The i-th integer denotes the type of the i-th tab: if it is equal to 1, this tab contains information for the test, and if it is equal to -1, it's a social network tab.
Output
Output a single integer β the maximum absolute difference between the amounts of remaining tabs of different types |e - s|.
Examples
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
Note
In the first example we can choose b = 1 or b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e = 2 and s = 0 and |e - s| = 2.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
Submitted Solution:
```
n,k=map(int,input().split(" "))
a=list(map(int,input().split(" ")))
i=0
ans=0
j=0
count=0
d=0
while i<k:
while j<n:
count=count+a[i]
j=j+k
s=a.count(-1)
e=a.count(1)
ans=abs(e-s)
i=i+1
ans = max(ans,abs(e-s)-count)
print(ans)
``` | instruction | 0 | 65,667 | 14 | 131,334 |
No | output | 1 | 65,667 | 14 | 131,335 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This morning, Roman woke up and opened the browser with n opened tabs numbered from 1 to n. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every k-th (2 β€ k β€ n - 1) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be b) and then close all tabs with numbers c = b + i β
k that satisfy the following condition: 1 β€ c β€ n and i is an integer (it may be positive, negative or zero).
For example, if k = 3, n = 14 and Roman chooses b = 8, then he will close tabs with numbers 2, 5, 8, 11 and 14.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it e) and the amount of remaining social network tabs (s). Help Roman to calculate the maximal absolute value of the difference of those values |e - s| so that it would be easy to decide what to do next.
Input
The first line contains two integers n and k (2 β€ k < n β€ 100) β the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of n integers, each of them equal either to 1 or to -1. The i-th integer denotes the type of the i-th tab: if it is equal to 1, this tab contains information for the test, and if it is equal to -1, it's a social network tab.
Output
Output a single integer β the maximum absolute difference between the amounts of remaining tabs of different types |e - s|.
Examples
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
Note
In the first example we can choose b = 1 or b = 3. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, e = 2 and s = 0 and |e - s| = 2.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
m = 0
for l in range(k-1):
use = [True] * n
for i in range(l, n, k):
use[i] = False
b = 0
for i in range(n):
if use[i]:
b += a[i]
if abs(b) > m:
m = abs(b)
print(m)
``` | instruction | 0 | 65,668 | 14 | 131,336 |
No | output | 1 | 65,668 | 14 | 131,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | instruction | 0 | 65,706 | 14 | 131,412 |
Tags: math
Correct Solution:
```
n, a, b = map(int, input().split())
s = a+1
e = n - b
ans = n-max(s, e) + 1
print(ans)
``` | output | 1 | 65,706 | 14 | 131,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | instruction | 0 | 65,707 | 14 | 131,414 |
Tags: math
Correct Solution:
```
n,a,b = [int(i) for i in input().split()[:3]]
x = n-a
y = b+1
print(min(x,y))
``` | output | 1 | 65,707 | 14 | 131,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | instruction | 0 | 65,708 | 14 | 131,416 |
Tags: math
Correct Solution:
```
n,a,b=map(int,input().split())
kol=0
for i in range(b+1):
x=n-i-1
if x>a-1:
kol+=1
print(kol)
``` | output | 1 | 65,708 | 14 | 131,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | instruction | 0 | 65,709 | 14 | 131,418 |
Tags: math
Correct Solution:
```
n,a,b=map(int,input().split())
if (a+b)<n:
print(b+1)
else:
print(n-a)
``` | output | 1 | 65,709 | 14 | 131,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | instruction | 0 | 65,710 | 14 | 131,420 |
Tags: math
Correct Solution:
```
n,A,B=map(int,input().split())
C=[int(x) for x in range(n+1)]
cnt=0
for i in range(n,0,-1):
b=abs(i-n)
a=i-1
if a<A or b>B:
break
cnt+=1
print(cnt)
``` | output | 1 | 65,710 | 14 | 131,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | instruction | 0 | 65,711 | 14 | 131,422 |
Tags: math
Correct Solution:
```
n, a, b = map(int, input().split())
min_pos = max(a+1, n - b)
print(n - min_pos + 1)
``` | output | 1 | 65,711 | 14 | 131,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | instruction | 0 | 65,712 | 14 | 131,424 |
Tags: math
Correct Solution:
```
n,a,b=map(int,input().split())
d=min(n-a,b+1)
print(d)
``` | output | 1 | 65,712 | 14 | 131,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | instruction | 0 | 65,713 | 14 | 131,426 |
Tags: math
Correct Solution:
```
n,a,b=map(int,input().split())
if n-b>a:
print(b+1)
elif n-b==a:
print(b)
elif n-b<a:
print(n-a)
``` | output | 1 | 65,713 | 14 | 131,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
Submitted Solution:
```
n , a,b = map(int, input().split())
l = n-a
k = b+1
print(min(l,k))
``` | instruction | 0 | 65,714 | 14 | 131,428 |
Yes | output | 1 | 65,714 | 14 | 131,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
Submitted Solution:
```
n,a,b=map(int,input().split());print(min(n-a,b+1))
``` | instruction | 0 | 65,715 | 14 | 131,430 |
Yes | output | 1 | 65,715 | 14 | 131,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
Submitted Solution:
```
a,b,c=map(int,input().split())
z=b+1
h=a-b-1
if c>=h:
print(h+1)
else:
print(c+1)
``` | instruction | 0 | 65,716 | 14 | 131,432 |
Yes | output | 1 | 65,716 | 14 | 131,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
Submitted Solution:
```
n, a, b = map(int,input().split())
p1 = n - a
p2 = n - b
print(n - max(p1, p2)+1)
``` | instruction | 0 | 65,718 | 14 | 131,436 |
No | output | 1 | 65,718 | 14 | 131,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
Submitted Solution:
```
#CF 124A
v = input().split()
print(int(v[0])-int(v[2]))
``` | instruction | 0 | 65,719 | 14 | 131,438 |
No | output | 1 | 65,719 | 14 | 131,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
Submitted Solution:
```
n,a,b = list(map(int,input().split()))
cnt = 0
for i in range(0,n):
if i>=a and n-i<=b:
cnt+=1
print(cnt)
``` | instruction | 0 | 65,720 | 14 | 131,440 |
No | output | 1 | 65,720 | 14 | 131,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
Input
The only line contains three integers n, a and b (0 β€ a, b < n β€ 100).
Output
Print the single number β the number of the sought positions.
Examples
Input
3 1 1
Output
2
Input
5 2 3
Output
3
Note
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
Submitted Solution:
```
n,a,b=map(int,input().split())
if(min(n,a,b)==n):
print(1)
else:
print(n-min(a,b))
``` | instruction | 0 | 65,721 | 14 | 131,442 |
No | output | 1 | 65,721 | 14 | 131,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n children, who study at the school β41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.
You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.
For instance, for the configuration shown below and k = 2 children can do the following steps:
<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration: <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job. <image>
It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".
Input
The first line of input contains two integers n and k (2 β€ n β€ 3000, 1 β€ k β€ 3000000) β the number of children and required number of moves.
The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.
Output
If there is no solution, print a single line with number -1.
Otherwise, output k lines. Each line has to start with a number n_i (1β€ n_i β€ n/2) β the number of pairs of children, who turn at this move. After that print n_i distinct integers β the numbers of the children who will turn left during this move.
After performing all "headturns", there can't be a pair of two neighboring children looking at each other.
If there are many solutions, print any of them.
Examples
Input
2 1
RL
Output
1 1
Input
2 1
LR
Output
-1
Input
4 2
RLRL
Output
2 1 3
1 2
Note
The first sample contains a pair of children who look at each other. After one move, they can finish the process.
In the second sample, children can't make any move. As a result, they can't end in k>0 moves.
The third configuration is described in the statement. | instruction | 0 | 65,722 | 14 | 131,444 |
Tags: brute force, constructive algorithms, games, graphs, greedy, implementation, sortings
Correct Solution:
```
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = list(input().rstrip())
ans = []
while True:
ok = True
epoch = []
for i, (s1, s2) in enumerate(zip(s, s[1:])):
if s1 == "R" and s2 == "L":
epoch.append(i + 1)
ok = False
if ok:
break
ans.append(epoch)
for item in epoch:
s[item-1], s[item] = s[item], s[item - 1]
minima = len(ans)
maxima = 0
for line in ans:
maxima += len(line)
if k < minima or k > maxima:
print(-1)
exit()
skip = k - minima
ans_str = []
for line in ans:
if skip == 0:
ans_str.append(str(len(line)) + " " + " ".join([str(item) for item in line]))
continue
val = min(skip, len(line) - 1)
for _ in range(val):
item = line.pop()
ans_str.append("1 " + str(item))
skip -= val
if line:
ans_str.append(str(len(line)) + " " + " ".join([str(item) for item in line]))
print("\n".join(ans_str))
``` | output | 1 | 65,722 | 14 | 131,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n children, who study at the school β41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.
You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.
For instance, for the configuration shown below and k = 2 children can do the following steps:
<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration: <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job. <image>
It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".
Input
The first line of input contains two integers n and k (2 β€ n β€ 3000, 1 β€ k β€ 3000000) β the number of children and required number of moves.
The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.
Output
If there is no solution, print a single line with number -1.
Otherwise, output k lines. Each line has to start with a number n_i (1β€ n_i β€ n/2) β the number of pairs of children, who turn at this move. After that print n_i distinct integers β the numbers of the children who will turn left during this move.
After performing all "headturns", there can't be a pair of two neighboring children looking at each other.
If there are many solutions, print any of them.
Examples
Input
2 1
RL
Output
1 1
Input
2 1
LR
Output
-1
Input
4 2
RLRL
Output
2 1 3
1 2
Note
The first sample contains a pair of children who look at each other. After one move, they can finish the process.
In the second sample, children can't make any move. As a result, they can't end in k>0 moves.
The third configuration is described in the statement. | instruction | 0 | 65,723 | 14 | 131,446 |
Tags: brute force, constructive algorithms, games, graphs, greedy, implementation, sortings
Correct Solution:
```
# print(out)
# pass
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
mod = 1000000007
def main():
# global out
n, k = [int(j) for j in input().split()]
# sys.stdout.write(str(n))
s = list(input().strip())
k_t = dict()
ls = []
# m = deepcopy(s)
for i in range(n-1):
if s[i]+s[i+1]=="RL":
ls.append(i)
# m[i] = "L"
# m[i+1] = "R"
# s = m
for j in ls:
s[j]="L"
s[j+1] = "R"
# k_t[1] = ls
# steps = 2
total_head_turns = len(ls)
main_ls = []
main_ls.append(ls)
while(ls):
# sys.stdout.write(ls)
new_ls = []
# m = deepcopy(s)
tr = set()
for i in ls:
tr.add(max(i-1, 0))
tr.add(min(i+1, n-1))
# tr = [max(i-1, 0), min(i+1, n-1)]
for j in tr:
if j!=n-1:
if s[j]+s[j+1]=="RL":
new_ls.append(j)
# m[j] = "L"
# m[j+1] = "R"
# s = m
for j in new_ls:
s[j]="L"
s[j+1] = "R"
# main_ls.append(j)
ls = new_ls
if new_ls:
main_ls.append(new_ls)
# k_t[steps] = new_ls
# steps+=1
total_head_turns += len(new_ls)
if total_head_turns<k:
print("-1")
# os.write(1, b'\n'.join(out))
else:
try:
ls = main_ls
d = dict()
for i in range(1,k+1):
d[i] = []
curr = 0
curr_ind = 0
i = 0
steps = 1
compensate = total_head_turns-k
while(i<total_head_turns):
# sys.stdout.write(ls, curr_ind, curr)
# sys.stdout.write(d)
ini_curr = curr
left = ls[curr][curr_ind]
k+=1
d[steps].append(left)
curr_ind+=1
i+=1
# sys.stdout.write(ls, curr_ind, curr)
while (compensate>0 and curr_ind<len(ls[curr])):
left = ls[curr][curr_ind]
k+=1
d[steps].append(left)
curr_ind+=1
i+=1
compensate-=1
# sys.stdout.write(ls, curr_ind, curr)
steps+=1
if curr_ind>len(ls[curr])-1:
curr+=1
curr_ind = 0
for i in d:
san = str(len(d[i]))+" "
# print(str(len(d[i]))+" ")
for j in d[i]:
san += str(j+1)+" "
# print(str(j+1)+" ")
print(san)
# os.write(1, b'\n'.join(out))
except:
print("-1")
# region fastio
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")
# endregion
if __name__ == "__main__":
main()
``` | output | 1 | 65,723 | 14 | 131,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n children, who study at the school β41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.
You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.
For instance, for the configuration shown below and k = 2 children can do the following steps:
<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration: <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job. <image>
It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".
Input
The first line of input contains two integers n and k (2 β€ n β€ 3000, 1 β€ k β€ 3000000) β the number of children and required number of moves.
The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.
Output
If there is no solution, print a single line with number -1.
Otherwise, output k lines. Each line has to start with a number n_i (1β€ n_i β€ n/2) β the number of pairs of children, who turn at this move. After that print n_i distinct integers β the numbers of the children who will turn left during this move.
After performing all "headturns", there can't be a pair of two neighboring children looking at each other.
If there are many solutions, print any of them.
Examples
Input
2 1
RL
Output
1 1
Input
2 1
LR
Output
-1
Input
4 2
RLRL
Output
2 1 3
1 2
Note
The first sample contains a pair of children who look at each other. After one move, they can finish the process.
In the second sample, children can't make any move. As a result, they can't end in k>0 moves.
The third configuration is described in the statement. | instruction | 0 | 65,724 | 14 | 131,448 |
Tags: brute force, constructive algorithms, games, graphs, greedy, implementation, sortings
Correct Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
n,k = [int(x) for x in input().split()]
word = list(input())
minimum = 0
aux=0
maximum = 0
complete =[]
mov = []
t = True
while t:
aux+=1
t=False
i=n-2
while i>=0:
if word[i]=='R' and word[i+1]=='L':
maximum+=1
mov.append(i+1)
minimum = max(minimum,aux)
word[i],word[i+1]=word[i+1],word[i]
t=True
i-=1
i-=1
complete.append(mov)
mov = []
if not minimum<=k<=maximum:
print(-1)
else:
base = 1
ans=[]
k2 = k
for i in range(0,minimum):
complete_aux = []
for j in range(len(complete[i])):
if maximum == k:
complete_aux.append(complete[i][j])
ans.append(complete_aux)
complete_aux=[]
k-=1
maximum-=1
else:
complete_aux.append(complete[i][j])
maximum-=1
if len(complete_aux):
ans.append(complete_aux)
k-=1
for i in range(k2):
print(len(ans[i]),end=' ')
for j in range(len(ans[i])):
print(ans[i][j],end=' ')
print()
# region fastio
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | output | 1 | 65,724 | 14 | 131,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n children, who study at the school β41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.
You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.
For instance, for the configuration shown below and k = 2 children can do the following steps:
<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration: <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job. <image>
It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".
Input
The first line of input contains two integers n and k (2 β€ n β€ 3000, 1 β€ k β€ 3000000) β the number of children and required number of moves.
The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.
Output
If there is no solution, print a single line with number -1.
Otherwise, output k lines. Each line has to start with a number n_i (1β€ n_i β€ n/2) β the number of pairs of children, who turn at this move. After that print n_i distinct integers β the numbers of the children who will turn left during this move.
After performing all "headturns", there can't be a pair of two neighboring children looking at each other.
If there are many solutions, print any of them.
Examples
Input
2 1
RL
Output
1 1
Input
2 1
LR
Output
-1
Input
4 2
RLRL
Output
2 1 3
1 2
Note
The first sample contains a pair of children who look at each other. After one move, they can finish the process.
In the second sample, children can't make any move. As a result, they can't end in k>0 moves.
The third configuration is described in the statement. | instruction | 0 | 65,725 | 14 | 131,450 |
Tags: brute force, constructive algorithms, games, graphs, greedy, implementation, sortings
Correct Solution:
```
# region fastio
import sys, io, os
BUFSIZE = 8192
class FastIO(io.IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = io.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(io.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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputi = lambda: map(int, input().split())
inputl = lambda: list(inputi())
from re import *
from math import *
from heapq import *
from bisect import *
from functools import reduce, lru_cache
from collections import Counter, defaultdict
from builtins import *
def main():
def C():
i = 0
t = False
L = []
for i in range(n):
if t:
if not S[i]:
L.append(i)
S[i - 1] = False
S[i] = True
t = False
elif S[i]:
t = True
return L
for _ in inputt(1):
n, k = inputi()
S = [c == "R" for c in input().strip()]
A = []
t = 0
l = C()
while l:
A.append(l)
t += len(l)
l = C()
if not len(A) <= k <= t:
print(-1)
break
k -= len(A)
i = j = 0
while k:
print(1, A[i][j])
j += 1
if j == len(A[i]):
j = 0
i += 1
else:
k -= 1
if j:
print(len(A[i][j:]), *A[i][j:])
i += 1
while i < len(A):
print(len(A[i]), *A[i])
i += 1
if __name__ == "__main__":
main()
``` | output | 1 | 65,725 | 14 | 131,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n children, who study at the school β41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.
You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.
For instance, for the configuration shown below and k = 2 children can do the following steps:
<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration: <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job. <image>
It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".
Input
The first line of input contains two integers n and k (2 β€ n β€ 3000, 1 β€ k β€ 3000000) β the number of children and required number of moves.
The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.
Output
If there is no solution, print a single line with number -1.
Otherwise, output k lines. Each line has to start with a number n_i (1β€ n_i β€ n/2) β the number of pairs of children, who turn at this move. After that print n_i distinct integers β the numbers of the children who will turn left during this move.
After performing all "headturns", there can't be a pair of two neighboring children looking at each other.
If there are many solutions, print any of them.
Examples
Input
2 1
RL
Output
1 1
Input
2 1
LR
Output
-1
Input
4 2
RLRL
Output
2 1 3
1 2
Note
The first sample contains a pair of children who look at each other. After one move, they can finish the process.
In the second sample, children can't make any move. As a result, they can't end in k>0 moves.
The third configuration is described in the statement. | instruction | 0 | 65,726 | 14 | 131,452 |
Tags: brute force, constructive algorithms, games, graphs, greedy, implementation, sortings
Correct Solution:
```
n, k = map(int, input().split())
in_ = input()
arr = []
S = 0
s = [1 if x == 'R' else 0 for x in in_]
while True:
next_ = [i for i in range(n-1) if s[i]==1 and s[i+1]==0]
if len(next_) == 0:
break
arr.append(next_)
S+=len(next_)
for pos in next_:
s[pos] = 0
s[pos+1] = 1
if S < k or k < len(arr):
print(-1)
else:
r = S - k
for a in arr:
n_ = len(a) - 1
if r >= n_:
print(str(n_+1)+' '+' '.join([str(x+1) for x in a]))
r -= n_
else:
print(str(r+1)+' '+' '.join([str(x+1) for x in a[:r+1]]))
for x in a[r+1:]:
print(str(1)+' '+str(x+1))
r=0
``` | output | 1 | 65,726 | 14 | 131,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n children, who study at the school β41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.
You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.
For instance, for the configuration shown below and k = 2 children can do the following steps:
<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration: <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job. <image>
It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".
Input
The first line of input contains two integers n and k (2 β€ n β€ 3000, 1 β€ k β€ 3000000) β the number of children and required number of moves.
The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.
Output
If there is no solution, print a single line with number -1.
Otherwise, output k lines. Each line has to start with a number n_i (1β€ n_i β€ n/2) β the number of pairs of children, who turn at this move. After that print n_i distinct integers β the numbers of the children who will turn left during this move.
After performing all "headturns", there can't be a pair of two neighboring children looking at each other.
If there are many solutions, print any of them.
Examples
Input
2 1
RL
Output
1 1
Input
2 1
LR
Output
-1
Input
4 2
RLRL
Output
2 1 3
1 2
Note
The first sample contains a pair of children who look at each other. After one move, they can finish the process.
In the second sample, children can't make any move. As a result, they can't end in k>0 moves.
The third configuration is described in the statement. | instruction | 0 | 65,727 | 14 | 131,454 |
Tags: brute force, constructive algorithms, games, graphs, greedy, implementation, sortings
Correct Solution:
```
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
N, K = map(int, input().split())
S = [1 if a == "R" else 0 for a in input()]
t = 0
a = 0
for s in S:
if s:
a += 1
else:
t += a
if K>t:
print(-1)
exit()
X=[]
while True:
Y=[i for i in range(N-1) if S[i] and not S[i+1]]
if not len(Y): break
X.append(Y)
nS = [0] * N
i = N - 1
while i >= 0:
if S[i-1] and not S[i] and i:
nS[i] = 1
i -= 2
elif S[i]:
nS[i] = 1
i -= 1
else:
i -= 1
S = nS
u = len(X)
if K < u:
print(-1)
exit()
p1 = lambda x: [y+1 for y in x]
st = lambda x: " ".join(map(str, x))
ANS = []
K -= u
i = 0
#print(X,K)
for x in X:
for j, xx in enumerate(x):
if K:
ANS.append(st([1, xx + 1]))
if j < len(x) - 1: K -= 1
else:
ANS.append(st([len(x) - j] + p1(x[j:])))
break
strANS = "\n".join(ANS)
print(strANS)
``` | output | 1 | 65,727 | 14 | 131,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n children, who study at the school β41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.
You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.
For instance, for the configuration shown below and k = 2 children can do the following steps:
<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration: <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job. <image>
It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".
Input
The first line of input contains two integers n and k (2 β€ n β€ 3000, 1 β€ k β€ 3000000) β the number of children and required number of moves.
The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.
Output
If there is no solution, print a single line with number -1.
Otherwise, output k lines. Each line has to start with a number n_i (1β€ n_i β€ n/2) β the number of pairs of children, who turn at this move. After that print n_i distinct integers β the numbers of the children who will turn left during this move.
After performing all "headturns", there can't be a pair of two neighboring children looking at each other.
If there are many solutions, print any of them.
Examples
Input
2 1
RL
Output
1 1
Input
2 1
LR
Output
-1
Input
4 2
RLRL
Output
2 1 3
1 2
Note
The first sample contains a pair of children who look at each other. After one move, they can finish the process.
In the second sample, children can't make any move. As a result, they can't end in k>0 moves.
The third configuration is described in the statement. | instruction | 0 | 65,728 | 14 | 131,456 |
Tags: brute force, constructive algorithms, games, graphs, greedy, implementation, sortings
Correct Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
n , k = [int(n) for n in input().split()]
arr = input()
max_moves = 0
min_moves = 0
movements = []
while 'RL' in arr:
min_moves+=1
max_moves+= arr.count('RL')
ref_arr = arr.replace('RL','LR')
movements.append([i for i,(old,new) in enumerate(zip(arr,ref_arr),1) if old == 'R' and new == 'L'])
arr = ref_arr
if k>max_moves or k<min_moves:
print(-1)
else:
movements=movements[::-1]
while k:
if k>len(movements):
print(1,movements[-1].pop())
if not movements[-1]:
movements.pop()
else:
print(len(movements[-1]), " ".join(str(x) for x in movements[-1]))
movements.pop()
k-=1
# region fastio
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | output | 1 | 65,728 | 14 | 131,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n children, who study at the school β41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other.
You are given the number n, the initial arrangement of children and the number k. You have to find a way for the children to act if they want to finish the process in exactly k seconds. More formally, for each of the k moves, you need to output the numbers of the children who turn left during this move.
For instance, for the configuration shown below and k = 2 children can do the following steps:
<image> At the beginning, two pairs make move: (1, 2) and (3, 4). After that, we receive the following configuration: <image> At the second move pair (2, 3) makes the move. The final configuration is reached. Good job. <image>
It is guaranteed that if the solution exists, it takes not more than n^2 "headturns".
Input
The first line of input contains two integers n and k (2 β€ n β€ 3000, 1 β€ k β€ 3000000) β the number of children and required number of moves.
The next line contains a string of length n and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.
Output
If there is no solution, print a single line with number -1.
Otherwise, output k lines. Each line has to start with a number n_i (1β€ n_i β€ n/2) β the number of pairs of children, who turn at this move. After that print n_i distinct integers β the numbers of the children who will turn left during this move.
After performing all "headturns", there can't be a pair of two neighboring children looking at each other.
If there are many solutions, print any of them.
Examples
Input
2 1
RL
Output
1 1
Input
2 1
LR
Output
-1
Input
4 2
RLRL
Output
2 1 3
1 2
Note
The first sample contains a pair of children who look at each other. After one move, they can finish the process.
In the second sample, children can't make any move. As a result, they can't end in k>0 moves.
The third configuration is described in the statement. | instruction | 0 | 65,729 | 14 | 131,458 |
Tags: brute force, constructive algorithms, games, graphs, greedy, implementation, sortings
Correct Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def main():
n , k = [int(n) for n in input().split()]
arr = input()
max_moves = 0
min_moves = 0
movements = []
while 'RL' in arr:
aux=[]
ref_arr = arr.replace('RL','LR')
min_moves+=1
for idx,val in enumerate(zip(arr,ref_arr),1):
if val[0]=='R' and val[1]=='L':
aux.append(idx)
max_moves+=1
movements.append(aux)
arr = ref_arr
if k>max_moves or k<min_moves:
print(-1)
else:
while k:
if k>len(movements):
print(1,movements[0].pop(0))
if not movements[0]:
movements.pop(0)
else:
print(len(movements[0]), " ".join(str(x) for x in movements[0]))
movements.pop(0)
k-=1
# region fastio
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | output | 1 | 65,729 | 14 | 131,459 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM. | instruction | 0 | 65,911 | 14 | 131,822 |
Tags: constructive algorithms, dp
Correct Solution:
```
s = input()
g,no,ans = 0,0,0
for i in range(len(s)):
if(s[i] == 'M'):
no = max(no-1,0)
else:
if(i != g):
ans = max(ans,i-g+no)
no += 1
g += 1
print(ans)
``` | output | 1 | 65,911 | 14 | 131,823 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM. | instruction | 0 | 65,912 | 14 | 131,824 |
Tags: constructive algorithms, dp
Correct Solution:
```
t = input()[:: -1]
i = t.find('F')
if i < 0:
print(0)
else:
j = t.find('M', i + 1)
if j < 0:
print(0)
else:
s, t = 0, t[j:t.rfind('M') + 1]
for k in t:
if k == 'M':
s += 1
else:
s = max(s - 1, 0)
print(s + t.count('F') + j - i - 1)
``` | output | 1 | 65,912 | 14 | 131,825 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM. | instruction | 0 | 65,913 | 14 | 131,826 |
Tags: constructive algorithms, dp
Correct Solution:
```
# https://codeforces.com/problemset/problem/353/D
s = [0 if x=='M' else 1 for x in input()]
ans = 0
pre = -1
num1 = 0
flg=False
for i in range(len(s)-1, -1, -1):
if s[i]==1:
flg=True
num1+=1
else:
if flg==True:
pre=pre+1
ans=max(num1, pre)
pre=ans
print(ans)
``` | output | 1 | 65,913 | 14 | 131,827 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM. | instruction | 0 | 65,914 | 14 | 131,828 |
Tags: constructive algorithms, dp
Correct Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq,bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=2**51, func=lambda a, b: a & b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: max(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <=key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
s=list(input())
st=0
for i in range(len(s)-1,-1,-1):
if s[i]=='F':
st=i
break
if st==0:
print(0)
sys.exit(0)
c=0
f=[]
m=[]
if s[st-1]=='M':
f.append(0)
for i in range(st-1,-1,-1):
if s[i]=='M':
if c!=0:
f.append(c)
c=0
else:
c+=1
if c!=0:
f.append(c)
c=0
for i in range(st-1,-1,-1):
if s[i]=='F':
if c!=0:
m.append(c)
c=0
else:
c+=1
if c!=0:
m.append(c)
if len(f)>len(m):
f=f[:len(f)-1]
ans=0
back=0
fcur=0
for i in range(len(f)):
fcur+=f[i]
cur=max(0,fcur-back)+m[i]
ans+=cur
back=back+cur
print(ans)
``` | output | 1 | 65,914 | 14 | 131,829 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM. | instruction | 0 | 65,915 | 14 | 131,830 |
Tags: constructive algorithms, dp
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M = 10**9 + 7
EPS = 1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
s = input().lstrip('F')
n = len(s)
prev = 0
need = 0
steps = 0
for i in range(n):
if(s[i] == 'F'):
steps = max(steps+1,prev)
else:
prev += 1
print(steps)
``` | output | 1 | 65,915 | 14 | 131,831 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM. | instruction | 0 | 65,916 | 14 | 131,832 |
Tags: constructive algorithms, dp
Correct Solution:
```
def main():
for _ in inputt(1):
P = [ch == "F" for ch in input()]
t = 0
d = 0
for i, e in enumerate(P):
if e:
if i != d:
t = max(t + 1, i - d)
d += 1
print(t)
# region M
# region import
# ζζimportι¨ε
from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
# endregion
# region fastio
# εΏ«ιioοΌθ½ζεε€§ιζΆι΄
BUFSIZE = 8192
class FastIO(io.IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = io.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(io.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")
def print(*args, **kwargs):
sys.stdout.write(kwargs.pop("split", " ").join(map(str, args)))
sys.stdout.write(kwargs.pop("end", "\n"))
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda: map(int, inputs())
inputl = lambda: list(inputi())
# endregion
# region bisect
# δΊεζη΄’οΌζ εεΊζ²‘ζε½ζ°εζ°
def len(a):
if isinstance(a, range):
return -((a.start - a.stop) // a.step)
return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
if lo < 0: lo = 0
if hi == None: hi = len(a)
if key == None: key = do_nothing
while lo < hi:
mid = (lo + hi) // 2
if key(a[mid]) < x: lo = mid + 1
else: hi = mid
return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
if lo < 0: lo = 0
if hi == None: hi = len(a)
if key == None: key = do_nothing
while lo < hi:
mid = (lo + hi) // 2
if x < key(a[mid]): hi = mid
else: lo = mid + 1
return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
lo = bisect_left(a, x, key, lo, hi)
a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
lo = bisect_right(a, x, key, lo, hi)
a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, key = None, default = None, lo = 0, hi = None):
if lo < 0: lo = 0
if hi == None: hi = len(a)
if key == None: key = do_nothing
i = bisect_left(a, x, key, lo, hi)
if lo <= i < hi and key(a[i]) == x: return a[i]
if default != None: return default
raise ValueError
def find_lt(a, x, key = None, default = None, lo = 0, hi = None):
if lo < 0: lo = 0
if hi == None: hi = len(a)
i = bisect_left(a, x, key, lo, hi)
if lo < i <= hi: return a[i - 1]
if default != None: return default
raise ValueError
def find_le(a, x, key = None, default = None, lo = 0, hi = None):
if lo < 0: lo = 0
if hi == None: hi = len(a)
i = bisect_right(a, x, key, lo, hi)
if lo < i <= hi: return a[i - 1]
if default != None: return default
raise ValueError
def find_gt(a, x, key = None, default = None, lo = 0, hi = None):
if lo < 0: lo = 0
if hi == None: hi = len(a)
i = bisect_right(a, x, key, lo, hi)
if lo <= i < hi: return a[i]
if default != None: return default
raise ValueError
def find_ge(a, x, key = None, default = None, lo = 0, hi = None):
if lo < 0: lo = 0
if hi == None: hi = len(a)
i = bisect_left(a, x, key, lo, hi)
if lo <= i < hi: return a[i]
if default != None: return default
raise ValueError
# endregion
# region main
# mainε½ζ°ι¨ε
if __name__ == "__main__":
main()
# endregion
# endregion
``` | output | 1 | 65,916 | 14 | 131,833 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM. | instruction | 0 | 65,917 | 14 | 131,834 |
Tags: constructive algorithms, dp
Correct Solution:
```
a=input();n=len(a);o,k=0,0
for i in range(n):
if(a[i]=='F'):
k=k+1
if(i+1!=k):o=max(o+1,i+1-k)
print(o)
``` | output | 1 | 65,917 | 14 | 131,835 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM. | instruction | 0 | 65,918 | 14 | 131,836 |
Tags: constructive algorithms, dp
Correct Solution:
```
s = input()
n = len(s)
try:
ai = s.index('M')
bi = n - s[::-1].index('F')
s = s[ai:bi]
n = len(s)
femcount = sum(map(lambda s: 1 if s == 'F' else 0, s))
cong = 0
for a in s:
if a == 'M':
cong = max(0, cong - 1)
else:
cong += 1
print(n - femcount + max(0, cong - 1))
except:
print(0)
# while True:
# l = list(s)
# for i in range(len(s) - 1):
# if s[i] == 'M' and s[i + 1] == 'F':
# l[i] = 'F'
# l[i + 1] = 'M'
# if ''.join(l) == s:
# break
# s = ''.join(l)
# print(s)
``` | output | 1 | 65,918 | 14 | 131,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM.
Submitted Solution:
```
s=input()
j=0
ans=0
f=1
for i in range(len(s)):
if s[i]=='F':
if f==1:
j=i+1
continue
if ans==0:
ans=i-j
else:
ans=max(ans+1,i-j)
j+=1
else:
f=0
print(ans)
``` | instruction | 0 | 65,919 | 14 | 131,838 |
Yes | output | 1 | 65,919 | 14 | 131,839 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM.
Submitted Solution:
```
s = input()
f = 0
cur_t = -1
for i in range(len(s)):
if s[i] == 'F':
t = i - f
f += 1
if t > cur_t or t == 0:
cur_t = t
else:
cur_t += 1
print(max(0, cur_t))
``` | instruction | 0 | 65,920 | 14 | 131,840 |
Yes | output | 1 | 65,920 | 14 | 131,841 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM.
Submitted Solution:
```
from sys import stdin
counter = 0
ans = 0
s = stdin.read(1)
while s == 'F':
s = stdin.read(1)
while s != '\n':
if s == 'F':
ans = counter
counter += 1
s = stdin.read(1)
print(ans)
``` | instruction | 0 | 65,921 | 14 | 131,842 |
No | output | 1 | 65,921 | 14 | 131,843 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM.
Submitted Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq,bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=2**51, func=lambda a, b: a & b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: max(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <=key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
s=list(input())
st=len(s)-1
for i in range(len(s)-1,-1,-1):
if s[i]=='F':
st=i
break
if st==0:
print(0)
sys.exit(0)
c=0
f=[]
m=[]
if s[st-1]=='M':
f.append(0)
for i in range(st-1,-1,-1):
if s[i]=='M':
if c!=0:
f.append(c)
c=0
else:
c+=1
if c!=0:
f.append(c)
c=0
for i in range(st-1,-1,-1):
if s[i]=='F':
if c!=0:
m.append(c)
c=0
else:
c+=1
if c!=0:
m.append(c)
if len(f)>len(m):
f=f[:len(f)-1]
ans=0
back=0
fcur=0
for i in range(len(f)):
fcur+=f[i]
cur=max(0,fcur-back)+m[i]
ans+=cur
back=back+cur
print(ans)
``` | instruction | 0 | 65,922 | 14 | 131,844 |
No | output | 1 | 65,922 | 14 | 131,845 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM.
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
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")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M = 10**9 + 7
EPS = 1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
s = input()
n = len(s)
prev = 0
need = 0
steps = 0
for i in range(n):
if(s[i] == 'F'):
steps = max(steps+1,prev)
else:
prev += 1
print(steps)
``` | instruction | 0 | 65,923 | 14 | 131,846 |
No | output | 1 | 65,923 | 14 | 131,847 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.
Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.
Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.
Input
The first line contains a sequence of letters without spaces s1s2... sn (1 β€ n β€ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter si equals F, then initially the line had a girl on the i-th position.
Output
Print a single integer β the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.
Examples
Input
MFM
Output
1
Input
MMFF
Output
3
Input
FFMMM
Output
0
Note
In the first test case the sequence of changes looks as follows: MFM β FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF β MFMF β FMFM β FFMM.
Submitted Solution:
```
s = input()
n = len(s)
mode = 0
st = -1
le = 0
femcount = 0
for i, a in enumerate(s[::-1]):
j = n - 1 - i
if mode == 0 and a == 'F':
mode = 1
st = j
le += 1
femcount += 1
elif mode == 1 and a == 'F':
le += 1
femcount += 1
elif mode == 1 and a == 'M':
mode = 2
elif mode == 2 and a == 'F':
femcount += 1
rr = st - femcount + le
mode = 0
st = -1
le = 0
femcount = 0
for i, a in enumerate(s):
j = n - 1 - i
if mode == 0 and a == 'M':
mode = 1
st = j
le += 1
femcount += 1
elif mode == 1 and a == 'M':
le += 1
femcount += 1
elif mode == 1 and a == 'F':
mode = 2
elif mode == 2 and a == 'M':
femcount += 1
b = st - femcount + le
print(max(rr, b))
``` | instruction | 0 | 65,924 | 14 | 131,848 |
No | output | 1 | 65,924 | 14 | 131,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 β to a2 billion, ..., and in the current (2000 + n)-th year β an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year β 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers ai can even occur negative ones that are a sign of the companyβs losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers ai from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years y1, y2, ..., yk,so that in the year y1 the company income amounted to 1 billion bourles, in the year y2 β 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers ai ( - 100 β€ ai β€ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output
Output k β the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
Examples
Input
10
-2 1 1 3 2 3 4 -10 -2 5
Output
5
2002 2005 2006 2007 2010
Input
3
-1 -2 -3
Output
0 | instruction | 0 | 65,925 | 14 | 131,850 |
Tags: greedy
Correct Solution:
```
n = int(input())
lis = list(map(int,input().split()))
li=[]
c=1
for i in range(n):
if(lis[i]==c):
li.append(2000+i+1)
c+=1
if(c==1):
print('0')
else:
print(len(li),*li)
``` | output | 1 | 65,925 | 14 | 131,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 β to a2 billion, ..., and in the current (2000 + n)-th year β an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year β 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers ai can even occur negative ones that are a sign of the companyβs losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers ai from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years y1, y2, ..., yk,so that in the year y1 the company income amounted to 1 billion bourles, in the year y2 β 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers ai ( - 100 β€ ai β€ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output
Output k β the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
Examples
Input
10
-2 1 1 3 2 3 4 -10 -2 5
Output
5
2002 2005 2006 2007 2010
Input
3
-1 -2 -3
Output
0 | instruction | 0 | 65,926 | 14 | 131,852 |
Tags: greedy
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
tf = False
k = 1
ans = []
for i in range(0,len(a)):
if (a[i]==k):
k+=1
tf = True
ans.append(i+2001)
print(k-1)
for i in ans:
print(i,end = ' ')
``` | output | 1 | 65,926 | 14 | 131,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 β to a2 billion, ..., and in the current (2000 + n)-th year β an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year β 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers ai can even occur negative ones that are a sign of the companyβs losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers ai from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years y1, y2, ..., yk,so that in the year y1 the company income amounted to 1 billion bourles, in the year y2 β 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers ai ( - 100 β€ ai β€ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output
Output k β the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
Examples
Input
10
-2 1 1 3 2 3 4 -10 -2 5
Output
5
2002 2005 2006 2007 2010
Input
3
-1 -2 -3
Output
0 | instruction | 0 | 65,927 | 14 | 131,854 |
Tags: greedy
Correct Solution:
```
i=input
n=i()
m=list(map(int,i().split()))
t=1
p=[]
for x in range(len(m)):
if(t==m[x]):
p.append(2001+x)
t+=1
print(t-1)
for _ in range(len(p)):
print(p[_],end=" ")
# Made By Mostafa_Khaled
``` | output | 1 | 65,927 | 14 | 131,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 β to a2 billion, ..., and in the current (2000 + n)-th year β an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year β 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers ai can even occur negative ones that are a sign of the companyβs losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers ai from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years y1, y2, ..., yk,so that in the year y1 the company income amounted to 1 billion bourles, in the year y2 β 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers ai ( - 100 β€ ai β€ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output
Output k β the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
Examples
Input
10
-2 1 1 3 2 3 4 -10 -2 5
Output
5
2002 2005 2006 2007 2010
Input
3
-1 -2 -3
Output
0 | instruction | 0 | 65,928 | 14 | 131,856 |
Tags: greedy
Correct Solution:
```
from sys import stdin, stdout
years = int(input())
incomes = list(map(int,list(stdin.readline().split(' '))))
respuestas = list()
cnt = 1
for x in range(years):
if incomes[x] == cnt:
respuestas.append(str(2000+x+1))
cnt+=1
print(len(respuestas))
if respuestas:
print(' '.join(respuestas))
``` | output | 1 | 65,928 | 14 | 131,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 β to a2 billion, ..., and in the current (2000 + n)-th year β an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year β 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers ai can even occur negative ones that are a sign of the companyβs losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers ai from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years y1, y2, ..., yk,so that in the year y1 the company income amounted to 1 billion bourles, in the year y2 β 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers ai ( - 100 β€ ai β€ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output
Output k β the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
Examples
Input
10
-2 1 1 3 2 3 4 -10 -2 5
Output
5
2002 2005 2006 2007 2010
Input
3
-1 -2 -3
Output
0 | instruction | 0 | 65,929 | 14 | 131,858 |
Tags: greedy
Correct Solution:
```
n = int(input())
container = list(map(int, input().split()))
years = list()
if 1 in container:
indexOfOne = container.index(1)
years.append(2001 + indexOfOne)
while indexOfOne < len(container) - 1:
for j in range(indexOfOne + 1, len(container)):
if (container[indexOfOne] + 1 == container[j]):
years.append(2001 + j)
indexOfOne = j
indexOfOne -= 1
break
if j == len(container)-1:
break
indexOfOne += 1
print(len(years))
for item in years:
print(item, end=" ")
``` | output | 1 | 65,929 | 14 | 131,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 β to a2 billion, ..., and in the current (2000 + n)-th year β an billion bourles. On the base of the information Petya decided to show in his presentation the linear progress history which is in his opinion perfect. According to a graph Petya has already made, in the first year BerSoft company income must amount to 1 billion bourles, in the second year β 2 billion bourles etc., each following year the income increases by 1 billion bourles. Unfortunately, the real numbers are different from the perfect ones. Among the numbers ai can even occur negative ones that are a sign of the companyβs losses in some years. That is why Petya wants to ignore some data, in other words, cross some numbers ai from the sequence and leave only some subsequence that has perfect growth.
Thus Petya has to choose a sequence of years y1, y2, ..., yk,so that in the year y1 the company income amounted to 1 billion bourles, in the year y2 β 2 billion bourles etc., in accordance with the perfect growth dynamics. Help him to choose the longest such sequence.
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers ai ( - 100 β€ ai β€ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output
Output k β the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
Examples
Input
10
-2 1 1 3 2 3 4 -10 -2 5
Output
5
2002 2005 2006 2007 2010
Input
3
-1 -2 -3
Output
0 | instruction | 0 | 65,930 | 14 | 131,860 |
Tags: greedy
Correct Solution:
```
input()
t = []
for y, d in enumerate(map(int, input().split()), 2001):
if d == len(t) + 1: t.append(y)
print(len(t), *t)
``` | output | 1 | 65,930 | 14 | 131,861 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.