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
Provide tags and a correct Python 3 solution for this coding contest problem. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10
instruction
0
107,379
14
214,758
Tags: implementation Correct Solution: ``` a,b=map(int,input().split()) z=list(map(int,input().split()[1:])) ans,t=0,1 for i in range(1,a+1): if i in z:ans+=1;t=1 elif t==b:ans+=1;t=1 else:t+=1 print(ans) ```
output
1
107,379
14
214,759
Provide tags and a correct Python 3 solution for this coding contest problem. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10
instruction
0
107,380
14
214,760
Tags: implementation Correct Solution: ``` class CodeforcesTask54ASolution: def __init__(self): self.result = '' self.n_k = [] self.holidays = [] def read_input(self): self.n_k = [int(x) for x in input().split(" ")] self.holidays = [int(x) for x in input().split(" ")] def process_task(self): days = [0] * self.n_k[0] for h in self.holidays[1:]: days[h - 1] = 1 l = 1 p = 0 given = 0 while p < self.n_k[0]: #print(p, given) if days[p]: l = 0 given += 1 if l >= self.n_k[1]: l = 0 given += 1 l += 1 p += 1 self.result = str(given) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask54ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
output
1
107,380
14
214,761
Provide tags and a correct Python 3 solution for this coding contest problem. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10
instruction
0
107,381
14
214,762
Tags: implementation Correct Solution: ``` n, k = map(int, input().split()) h, d, hi, v = list(map(int, input().split())) + [n + 1], 0, 1, -1 while d <= n: v += 1 if h[hi] <= d + k: d = h[hi] hi += 1 else: d += k print(v) ```
output
1
107,381
14
214,763
Provide tags and a correct Python 3 solution for this coding contest problem. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10
instruction
0
107,382
14
214,764
Tags: implementation Correct Solution: ``` entrada1 = input().split() n, k = int(entrada1[0]), int(entrada1[1]) entrada2 = input().split() c = int(entrada2[0]) festivos = [] for i in range(c): festivos.append(int(entrada2[i+1])) regalos = 0 k_esimo = 0 f = 0 i = 1 while i<=n: if f<c and i == festivos[f]: regalos = regalos + 1 f = f+1 k_esimo = 0 else: k_esimo = k_esimo + 1 if k_esimo == k: regalos = regalos + 1 k_esimo = 0 i =i+1 print(regalos) ```
output
1
107,382
14
214,765
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10 Submitted Solution: ``` n,k=map(int,input().split()) a=list(map(int,input().split())) t=1 ans=0 for i in range(1,n+1): if i in a[1:]: ans+=1 t=1 elif t==k: ans+=1 t=1 else: t+=1 print(ans) ```
instruction
0
107,383
14
214,766
Yes
output
1
107,383
14
214,767
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10 Submitted Solution: ``` n,k=input().split() lis=input().split() lis1=lis[1:] count=dict() for i in lis1 : count[int(i)]=count.get(int(i),0)+1 ans=0 prev=0 for i in range(int(n)+1) : if count.get(i,0)>0 : ans+=1 prev=i elif (i-prev) >= int(k) : prev=i ans+=1 print(ans) ```
instruction
0
107,384
14
214,768
Yes
output
1
107,384
14
214,769
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10 Submitted Solution: ``` N,K = map(int, input().split()); dl, d, index, ans = list(map(int, input().split()))+[N+1], 0, 1, -1; while(d<=N): ans+=1; if dl[index]<=d+K: d=dl[index]; index+=1; else: d+=K; print(ans) ```
instruction
0
107,385
14
214,770
Yes
output
1
107,385
14
214,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10 Submitted Solution: ``` n,k=input().split() lis=input().split() lis1=lis[1:] count=dict() for i in lis1 : count[int(i)]=count.get(int(i),0)+1 ans=0 prev=0 for i in range(int(n)+1) : if count.get(i,0)>0 : ans+=1 prev=i elif (i-prev) >= int(k) : prev=i ans+=1 print(ans) #0 1 2 3 4 ```
instruction
0
107,386
14
214,772
Yes
output
1
107,386
14
214,773
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10 Submitted Solution: ``` import math n,k = [int(a) for a in input().split() ] c = [int(a) for a in input().split()] def NumPresent(n,k,c): if c == [0]: res = math.ceil(n/k) else: cn = c.pop(0) downVal = math.ceil((c[0]-1)/k) upVal = math.ceil((n-c[cn-1])/k) res = cn + downVal + upVal return res # test1 = [1,3] # print(NumPresent(5,2,test1) ) # test2 = [3,6,7,8] # print(NumPresent(10,1,test2) ) # test3 = [0] # print(NumPresent(5,2,test3)) print(NumPresent(n,k,c)) # print(math.ceil(2.5)) ```
instruction
0
107,387
14
214,774
No
output
1
107,387
14
214,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10 Submitted Solution: ``` n,k=[int(i) for i in input().split()] a=[int(i) for i in input().split()] l=[] e=0 for i in range(1,n+1,k): l.append(i) for i in range(0,len(a)): if(a[i] not in l): e=e+1 print(len(l)+e) ```
instruction
0
107,388
14
214,776
No
output
1
107,388
14
214,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10 Submitted Solution: ``` n, k = list(map(int, input().split())) a = list(map(int, input().split())) c, *a = a if c == 0: print(n // k) else: a.append(n) res = 1 for i in range(1, len(a)): if a[i] - a[i-1] >= k: res += (a[i] - a[i-1]) // k if a[0] - 1 >= k: res += (a[0] - 1) // k print(res) ```
instruction
0
107,389
14
214,778
No
output
1
107,389
14
214,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be? In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle: * on each holiday day the Hedgehog will necessarily receive a present, * he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day). For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer). Input The first line contains integers N and K (1 ≀ N ≀ 365, 1 ≀ K ≀ N). The second line contains a number C which represents the number of holidays (0 ≀ C ≀ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them. Output Print a single number β€” the minimal number of presents the Hedgehog will receive over the following N days. Examples Input 5 2 1 3 Output 3 Input 10 1 3 6 7 8 Output 10 Submitted Solution: ``` n,k = map(int,input().split(' ')) c, *h = input().split(' ') c = int(c) h = list(map(int, h)) if n == k: l = 1 else: temp = [] temp.append(1) i = 1 while(i < n): i += k temp.append(i) l = len(temp) for i in h: if i not in temp: l += 1 print(l) ```
instruction
0
107,390
14
214,780
No
output
1
107,390
14
214,781
Provide tags and a correct Python 3 solution for this coding contest problem. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
instruction
0
107,439
14
214,878
Tags: math Correct Solution: ``` n=int(input()) m=n%3 z=n//3 if m==0: print(z*2) else: print(z*2+1) ```
output
1
107,439
14
214,879
Provide tags and a correct Python 3 solution for this coding contest problem. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
instruction
0
107,440
14
214,880
Tags: math Correct Solution: ``` n=int(input()) c=n//3 c*=2 if n%3!=0: c+=1 print(c) ```
output
1
107,440
14
214,881
Provide tags and a correct Python 3 solution for this coding contest problem. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
instruction
0
107,441
14
214,882
Tags: math Correct Solution: ``` n=int(input()) if n%3==0: print(2*n//3) else: print(2*(n//3+1)-1) ```
output
1
107,441
14
214,883
Provide tags and a correct Python 3 solution for this coding contest problem. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
instruction
0
107,442
14
214,884
Tags: math Correct Solution: ``` n = int(input()) result = 2 * (n // 3) if n % 3 != 0: result += 1 print(result) ```
output
1
107,442
14
214,885
Provide tags and a correct Python 3 solution for this coding contest problem. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
instruction
0
107,443
14
214,886
Tags: math Correct Solution: ``` n=int(input()) print(n//3*2+(n%3>0)) ```
output
1
107,443
14
214,887
Provide tags and a correct Python 3 solution for this coding contest problem. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
instruction
0
107,444
14
214,888
Tags: math Correct Solution: ``` n = int(input()) print(2 * (n // 3) + int(n % 3 != 0)) ```
output
1
107,444
14
214,889
Provide tags and a correct Python 3 solution for this coding contest problem. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
instruction
0
107,445
14
214,890
Tags: math Correct Solution: ``` #rOkY #FuCk ################################## kOpAl ##################################### t=int(input()) g=0 g=t//3 g=g*2 if(t%3>0): g+=1 print(g) ```
output
1
107,445
14
214,891
Provide tags and a correct Python 3 solution for this coding contest problem. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
instruction
0
107,446
14
214,892
Tags: math Correct Solution: ``` n=int(input()) ans=(n//3)*2 if n%3 !=0: ans += 1 print(ans) ```
output
1
107,446
14
214,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. Submitted Solution: ``` n=int(input()) count=0 if n=="1" or n=='2': print("1") exit(0) else: while n>0: n=n-1 count+=1 if n>=2: n=n-2 count+=1 else: print(count) exit(0) print(count) ```
instruction
0
107,447
14
214,894
Yes
output
1
107,447
14
214,895
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. Submitted Solution: ``` n = int(input()) if n % 3 == 2: n -= 1 print(((n // 3) * 2) + (n % 3)) ```
instruction
0
107,448
14
214,896
Yes
output
1
107,448
14
214,897
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. Submitted Solution: ``` n=int(input()) if(n==1 or n==2): print(1) else: if(n%3==0): print(2*(n//3)) else: print(2*(n//3)+1) ```
instruction
0
107,449
14
214,898
Yes
output
1
107,449
14
214,899
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. Submitted Solution: ``` n = int(input()) r = n/1.5 if(r-int(r)>0.5): r=int(r)+1 else: r=int(r) print(r) ```
instruction
0
107,450
14
214,900
Yes
output
1
107,450
14
214,901
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. Submitted Solution: ``` import math stones = int(input()) if stones >= 3: print(math.floor(stones/3)*2 + stones%3) else: print("1") ```
instruction
0
107,451
14
214,902
No
output
1
107,451
14
214,903
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. Submitted Solution: ``` n = int(input()) if n == 1 or n == 2: print(1) elif n == 4 or n == 5: print(3) elif n % 3 == 0: print((n//3)*2) else: print((n//3)-1) ```
instruction
0
107,452
14
214,904
No
output
1
107,452
14
214,905
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. Submitted Solution: ``` def main(): n = int(input()) m = n/3 r = n%3 if r == 0: print(2*m) else: print(2*m + 1) main() ```
instruction
0
107,453
14
214,906
No
output
1
107,453
14
214,907
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input The only line of the input contains a single integer n (1 ≀ n ≀ 109) β€” number of stones Artem received on his birthday. Output Print the maximum possible number of times Artem can give presents to Masha. Examples Input 1 Output 1 Input 2 Output 1 Input 3 Output 2 Input 4 Output 3 Note In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again. Submitted Solution: ``` num = int(input()) if num%3 == 0: print(num/3) else: print(num//3 + 1) ```
instruction
0
107,454
14
214,908
No
output
1
107,454
14
214,909
Provide tags and a correct Python 3 solution for this coding contest problem. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
instruction
0
107,515
14
215,030
Tags: implementation Correct Solution: ``` if __name__ == "__main__": n, c1, c2 = list(map(int, input().split())) g = list(map(int, input().split())) count = 0 deny = 0 for i in range(n): if g[i] == 1: if c1 > 0: c1 -= 1 elif c1 <= 0 and c2 > 0: c2 -= 1 count += 1 elif c2 <= 0 and count > 0: count -= 1 else: deny += 1 else: if c2 > 0: c2 -= 1 else: deny += 2 print(deny) ```
output
1
107,515
14
215,031
Provide tags and a correct Python 3 solution for this coding contest problem. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
instruction
0
107,516
14
215,032
Tags: implementation Correct Solution: ``` n,a,b=map(int,input().split()) l=list(map(int,input().split())) ans=0 c=0 for i in range(n): if l[i]==2: if b==0: ans+=2 else: b-=1 else: if a!=0: a-=1 elif b!=0: b-=1 c+=1 elif c!=0: c-=1 else: ans+=1 print(ans) ```
output
1
107,516
14
215,033
Provide tags and a correct Python 3 solution for this coding contest problem. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
instruction
0
107,517
14
215,034
Tags: implementation Correct Solution: ``` n = input().split() a = int(n[1]) b = int(n[2]) n = int(n[0]) t = [int(i) for i in input().split()] lost = 0 bm = 2 * b b2 = b b1 = 0 for i in t: if i == 1: if a > 0: a -= 1 else: if bm > 0: if b2 > 0: b2 -= 1 b1 += 1 bm -= 1 else: b1 -= 1 bm -= 1 else: lost += 1 else: if b2 > 0: b2 -= 1 bm -= 2 else: lost += 2 print(lost) ```
output
1
107,517
14
215,035
Provide tags and a correct Python 3 solution for this coding contest problem. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
instruction
0
107,518
14
215,036
Tags: implementation Correct Solution: ``` n, a, b = map(int, input().split()) t = list(map(int, input().split())) ans = 0 cnta = 0 cntb1 = 0 cntb2 = 0 for ti in t: if ti == 1: if cnta < a: cnta += 1 elif cntb1 + cntb2 < b: cntb1 += 1 elif 0 < cntb1: cntb1 -= 1 cntb2 += 1 else: ans += 1 else: if cntb1 + cntb2 < b: cntb2 += 1 else: ans += 2 print(ans) ```
output
1
107,518
14
215,037
Provide tags and a correct Python 3 solution for this coding contest problem. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
instruction
0
107,519
14
215,038
Tags: implementation Correct Solution: ``` from sys import stdin, stdout n, a, b = map(int, stdin.readline().split()) values = list(map(int, stdin.readline().split())) cnt = 0 c = 0 for i in range(n): if values[i] == 2: if b: b -= 1 else: cnt += 2 else: if a: a -= 1 elif b: b -= 1 c += 1 elif c: c -= 1 else: cnt += 1 stdout.write(str(cnt)) ```
output
1
107,519
14
215,039
Provide tags and a correct Python 3 solution for this coding contest problem. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
instruction
0
107,520
14
215,040
Tags: implementation Correct Solution: ``` primLinea=input().split() iteraciones=int(primLinea[0]) indiv=int(primLinea[1]) par=int(primLinea[2]) parParaIndiv=0 personas=input().split() negados=0 for i in range(0,iteraciones): costumer=int(personas[i]) if costumer==1: if indiv>0: indiv-=1 elif par>0: par-=1 parParaIndiv+=1 elif parParaIndiv>0: parParaIndiv-=1 else: negados+=1 elif costumer==2: if par>0: par-=1 else: negados+=2 print (negados) ```
output
1
107,520
14
215,041
Provide tags and a correct Python 3 solution for this coding contest problem. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
instruction
0
107,521
14
215,042
Tags: implementation Correct Solution: ``` n, a, b = [int(nab) for nab in str(input()).split(' ')] t = [int(ti) for ti in str(input()).split(' ')] tables = {1: {0: a, 1: 0}, 2: {0: b, 1: 0, 2: 0}} noservice = 0 for ti in t: if (ti == 1): if (tables[1][0] > 0): tables[1][0] -= 1 tables[1][1] += 1 elif (tables[2][0] > 0): tables[2][0] -= 1 tables[2][1] += 1 elif (tables[2][1] > 0): tables[2][1] -= 1 tables[2][2] += 1 else: noservice += 1 elif (tables[2][0] > 0): tables[2][0] -= 1 tables[2][2] += 1 else: noservice += 2 print(noservice) ```
output
1
107,521
14
215,043
Provide tags and a correct Python 3 solution for this coding contest problem. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
instruction
0
107,522
14
215,044
Tags: implementation Correct Solution: ``` n, a, b = map(int, input().split()) str = input() ls = [int(u) for u in str.split()] #print(ls) t=0 count=0 sum = 0 for u in ls: sum += u if u==1 and a>0: a -=1 count += 1 elif u==1 and a==0 and t>0 and b==0: t-=1 count += 1 elif u==1 and a==0 and b>0: t+=1 b -= 1 count += 1 elif u==2 and b>0: b -= 1 count += 2 print(sum-count) ```
output
1
107,522
14
215,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. Submitted Solution: ``` par=[int(i) for i in str(input()).split()] n,a,b=par[0],par[1],par[2] group=[int(i) for i in str(input()).split()] fill_1=0 fill_2_1_left=0 fill_2_1_full=0 fill_2_2=0 denied=0 for i in range(len(group)): if group[i]==2: if b-fill_2_1_left-fill_2_2>0: fill_2_2+=1 else: denied+=2 else: if a-fill_1>0: fill_1+=1 continue if b-fill_2_1_left-fill_2_2>0: fill_2_1_left+=1 fill_2_1_full+=1 continue if fill_2_1_full>0: fill_2_1_full-=1 continue denied+=1 print(denied) ```
instruction
0
107,523
14
215,046
Yes
output
1
107,523
14
215,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. Submitted Solution: ``` n,a,b = [int(i) for i in input().split()] nums = [int(i) for i in input().split()] count = 0 c = 0 for item in nums: if item!=1: if b==0: count+=2 else: b-=1 else: if a>0: a-=1 elif b>0: b-=1 c+=1 elif c>0: c-=1 else: count+=1 print(count) ```
instruction
0
107,524
14
215,048
Yes
output
1
107,524
14
215,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. Submitted Solution: ``` n, ones, twos = list(map(int,input().split())) semi = 0 deny = 0 humans = list(map(int,input().split())) for k in humans: if k==1: if ones>0: ones-=1 elif ones==0: if twos>0: twos-=1 semi+=1 elif twos==0: if semi>0: semi-=1 else: deny+=1 elif k==2: if twos>0: twos-=1 else: deny+=2 print(deny) ```
instruction
0
107,525
14
215,050
Yes
output
1
107,525
14
215,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. Submitted Solution: ``` #code #code n,a,b=map(int,input().strip().split(' ')) hb=0 c=0 l1=list(map(int,input().strip().split(' '))) for k in l1: if k==2: if b==0: c+=2 else: b-=1 else: if a==0: if b==0: if hb==0: c+=1 else: hb-=1 else: b-=1 hb+=1 else: a-=1 print(c) ```
instruction
0
107,526
14
215,052
Yes
output
1
107,526
14
215,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. Submitted Solution: ``` n,a,b=[int(x) for x in input().split(' ')] SumOfTables= a + (b * 2) CountOfGroups = 0 GroupOfPeople = [int(x) for x in input().split(' ')] i = 0 while i < len(GroupOfPeople): CountOfGroups += GroupOfPeople[i] i+=1 print(abs(CountOfGroups - SumOfTables)) ```
instruction
0
107,527
14
215,054
No
output
1
107,527
14
215,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. Submitted Solution: ``` n,a,b = map(int,input().split()) c = list(map(int,input().split())) d = 0 for i in range(len(c)): if c[i]==1: if a>=1: a-=1 elif b>=0.5: b-=0.5 else: d+=1 elif c[i]==2: if b>=1: b-=1 else: d+=2 print(d) ```
instruction
0
107,528
14
215,056
No
output
1
107,528
14
215,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. Submitted Solution: ``` a = input().split() n = int(a[0]) b = int(a[2]) a = int(a[1]) data = input().split() rej = 0 for i in range(n): if int(data[i]) == 1: if a > 0: a -= 1 elif b > 0: b -= 1 a += 1 else: rej += 1 else: if b > 0: b -= 1 else: rej += 2 print(rej) ```
instruction
0
107,529
14
215,058
No
output
1
107,529
14
215,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input The first line contains three integers n, a and b (1 ≀ n ≀ 2Β·105, 1 ≀ a, b ≀ 2Β·105) β€” the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1, t2, ..., tn (1 ≀ ti ≀ 2) β€” the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. Output Print the total number of people the restaurant denies service to. Examples Input 4 1 2 1 2 1 1 Output 0 Input 4 1 1 1 1 2 1 Output 2 Note In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. Submitted Solution: ``` #!usr/bin/python 3 def main(): a=input().split(' ') a=[int(x) for x in a] lst=input().split(' ') lst=[int(x) for x in lst] rejected=0 for x in lst: if a[1]>0 or a[2]>0: if x==1: if a[1]==0: a[2]-=1 a[1]+=1 else: a[1]-=1 elif x==2: if a[2]==0: rejected+=2 else: a[2]-=1 else: print('fail') else: rejected+=x print(rejected) if __name__=='__main__': main() ```
instruction
0
107,530
14
215,060
No
output
1
107,530
14
215,061
Provide tags and a correct Python 3 solution for this coding contest problem. While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level. Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level. Input The first line of the input consists of two integers, the number of robots n (2 ≀ n ≀ 100 000) and the number of rap battles m (<image>). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all m relations. Output Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1. Examples Input 4 5 2 1 1 3 2 3 4 2 4 3 Output 4 Input 3 2 1 2 3 2 Output -1 Note In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles. In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.
instruction
0
108,260
14
216,520
Tags: binary search, dp, graphs Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase def topsort(n,path,indeg): ans = [] for i in range(n): if not indeg[i]: ans.append(i) i = 0 if len(ans) > 1: return 0 while i != len(ans): for x in path[ans[i]]: indeg[x] -= 1 if not indeg[x]: ans.append(x) i += 1 if len(ans)-i > 1: return 0 return ans def main(): n,m = map(int,input().split()) path = [[] for _ in range(n)] indeg = [0]*n edg = [] for _ in range(m): u1,v1 = map(lambda xx:int(xx)-1,input().split()) edg.append((u1,v1)) path[u1].append(v1) indeg[v1] += 1 top = topsort(n,path,indeg) if not top: return -1 inde = [0]*n for ind,i in enumerate(top): inde[i] = ind ls = -1 for i in range(m): x,y = edg[i] if abs(inde[x]-inde[y]) == 1: ls = i+1 return ls # Fast IO Region 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") if __name__ == "__main__": print(main()) ```
output
1
108,260
14
216,521
Provide tags and a correct Python 3 solution for this coding contest problem. While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level. Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level. Input The first line of the input consists of two integers, the number of robots n (2 ≀ n ≀ 100 000) and the number of rap battles m (<image>). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all m relations. Output Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1. Examples Input 4 5 2 1 1 3 2 3 4 2 4 3 Output 4 Input 3 2 1 2 3 2 Output -1 Note In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles. In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.
instruction
0
108,261
14
216,522
Tags: binary search, dp, graphs Correct Solution: ``` from collections import defaultdict,deque def bfs(q,n,mid): g=defaultdict(list) vis=[0]*(n) for i in range(mid): x,y=q[i] g[x].append(y) vis[y]+=1 q=deque() for i in range(n): if vis[i]==0: q.append(i) flag=True cnt=0 while q and flag: # print(q) if len(q)!=1 : # ek se zyada winner us pos ke liye flag=False t=q.popleft() cnt+=1 for i in g[t]: vis[i]-=1 if vis[i]==0: q.append(i) return cnt==n and flag==True def f(q,n): lo=0 hi=len(q) ans=-1 while lo<=hi: mid=(lo+hi)//2 if bfs(q,n,mid): ans=mid hi=mid-1 else: lo=mid+1 return ans q=[] n,m=map(int,input().strip().split()) for _ in range(m): x,y=map(int,input().strip().split()) q.append((x-1,y-1)) print(f(q,n)) ```
output
1
108,261
14
216,523
Provide tags and a correct Python 3 solution for this coding contest problem. While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level. Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level. Input The first line of the input consists of two integers, the number of robots n (2 ≀ n ≀ 100 000) and the number of rap battles m (<image>). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all m relations. Output Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1. Examples Input 4 5 2 1 1 3 2 3 4 2 4 3 Output 4 Input 3 2 1 2 3 2 Output -1 Note In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles. In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.
instruction
0
108,262
14
216,524
Tags: binary search, dp, graphs Correct Solution: ``` from heapq import heappop,heappush n,m = map(int,input().split()) C = [[] for _ in range(n)] indeg = [0]*n def toposort(): S = [i for i in range(n) if indeg[i] == 0] nparent = indeg[:] topo = [] while S: cur = S.pop() topo.append(cur) for neigh,_ in C[cur]: nparent[neigh] -= 1 if nparent[neigh] == 0: S.append(neigh) return topo def solve(): topo = toposort() D = [(0,0)]*n for cur in topo: for neigh,t in C[cur]: cd,ct = D[cur] nd,_ = D[neigh] if nd <= cd + 1: D[neigh] = cd + 1, max(ct,t) d,t = max(D) return t+1 if d == n-1 else -1 for _ in range(m): a,b = map(int,input().split()) C[a-1].append((b-1, _)) indeg[b-1] += 1 print(solve()) ```
output
1
108,262
14
216,525
Provide tags and a correct Python 3 solution for this coding contest problem. While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level. Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level. Input The first line of the input consists of two integers, the number of robots n (2 ≀ n ≀ 100 000) and the number of rap battles m (<image>). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all m relations. Output Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1. Examples Input 4 5 2 1 1 3 2 3 4 2 4 3 Output 4 Input 3 2 1 2 3 2 Output -1 Note In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles. In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.
instruction
0
108,263
14
216,526
Tags: binary search, dp, graphs Correct Solution: ``` from collections import defaultdict class RobotRapping(): def __init__(self, n, m, battles): self.n, self.m = n, m self.battles = battles def generate_graph(self, k): edge_map = defaultdict(list) rev_map = defaultdict(list) for i in range(k): edge_map[self.battles[i][0]-1].append((self.battles[i][1]-1, i)) rev_map[self.battles[i][1]-1].append((self.battles[i][0]-1, i)) return edge_map, rev_map def check_order(self, num_battles): edge_map, rev_map = self.generate_graph(num_battles) outgoing_cnt = defaultdict(int) for k in edge_map: outgoing_cnt[k] = len(edge_map[k]) s = [] cntr = 0 for i in range(self.n): if outgoing_cnt[i] == 0: s.append(i) while len(s) > cntr: if len(s) > cntr+1 : return False else: node = s[cntr] for v in rev_map[node]: outgoing_cnt[v] -= 1 if outgoing_cnt[v] == 0: s.append(v) cntr += 1 return True def min_battles(self): if not self.check_order(self.m): print(-1) else: mn, mx = 0, self.m while mn < mx-1: md = int((mn+mx)/2) if self.check_order(md): mx = md else: mn = md print(mx) def min_battles2(self): edge_map, rev_map = self.generate_graph(self.m) outgoing_cnt = defaultdict(int) for k in edge_map: outgoing_cnt[k] = len(edge_map[k]) s = [] cntr = 0 order = [] for i in range(self.n): if outgoing_cnt[i] == 0: s.append(i) while len(s) > cntr: if len(s) > cntr+1 : print(-1) return else: node = s[cntr] order.append(node) for v,_ in rev_map[node]: outgoing_cnt[v] -= 1 if outgoing_cnt[v] == 0: s.append(v) cntr += 1 mn_pos = -1 for i in range(1,self.n): for v,ind in edge_map[order[i]]: if v == order[i-1]: mn_pos = max(mn_pos, ind) break print(mn_pos+1) n,m = list(map(int,input().strip(' ').split(' '))) battles = [] for i in range(m): x,y = list(map(int,input().strip(' ').split(' '))) battles.append((x,y)) rr = RobotRapping(n,m,battles) rr.min_battles2() ```
output
1
108,263
14
216,527
Provide tags and a correct Python 3 solution for this coding contest problem. While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level. Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level. Input The first line of the input consists of two integers, the number of robots n (2 ≀ n ≀ 100 000) and the number of rap battles m (<image>). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all m relations. Output Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1. Examples Input 4 5 2 1 1 3 2 3 4 2 4 3 Output 4 Input 3 2 1 2 3 2 Output -1 Note In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles. In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.
instruction
0
108,264
14
216,528
Tags: binary search, dp, graphs Correct Solution: ``` from sys import stdin, stdout import sys import bisect import heapq input = sys.stdin.readline def solve(n, m, edges): lo = 0 hi = m curr_k = -1 while lo <= hi: mid = lo + (hi - lo) // 2 can_do = True # condition adj_list = {x: [] for x in range(0, n)} in_degree = [0] * n for ed in range(min(mid, len(edges))): edge = edges[ed] adj_list[edge[0]].append(edge[1]) in_degree[edge[1]] += 1 candidates = [] for i in range(len(in_degree)): if in_degree[i] == 0: candidates.append(i) res = [] while candidates: ele = candidates.pop(0) if len(candidates) > 0: can_do = False break res.append(ele) for i in adj_list[ele]: in_degree[i] -= 1 if in_degree[i] == 0: candidates.append(i) if len(res) < n: can_do = False if can_do: curr_k = mid hi = mid - 1 else: lo = mid + 1 return curr_k def main(): n, m = map(int, input().split()) edges = [] for i in range(m): a, b = map(int, input().split()) edges.append([a - 1, b - 1]) stdout.write(str(solve(n, m, edges))) stdout.write("\n") if __name__ == "__main__": main() ```
output
1
108,264
14
216,529
Provide tags and a correct Python 3 solution for this coding contest problem. While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level. Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level. Input The first line of the input consists of two integers, the number of robots n (2 ≀ n ≀ 100 000) and the number of rap battles m (<image>). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≀ ui, vi ≀ n, ui β‰  vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all m relations. Output Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1. Examples Input 4 5 2 1 1 3 2 3 4 2 4 3 Output 4 Input 3 2 1 2 3 2 Output -1 Note In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles. In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.
instruction
0
108,265
14
216,530
Tags: binary search, dp, graphs Correct Solution: ``` from sys import stdin def main(): def f(k): g, cnt = [[] for _ in range(n)], [0] * n for u, v in data[:k]: g[u].append(v) cnt[v] += 1 if cnt.count(0) > 1: return False w, u = cnt.index(0), -1 while u != w: u = w for v in g[u]: cnt[v] -= 1 if not cnt[v]: if u != w: return False w = v return True n, m = map(int, input().split()) data = stdin.read().splitlines() for i, s in enumerate(data): u, v = map(int, s.split()) data[i] = (u - 1, v - 1) lo, hi = n - 1, m + 1 while lo < hi: mid = (lo + hi) // 2 if f(mid): hi = mid else: lo = mid + 1 print(-1 if hi > m else lo) if __name__ == '__main__': main() ```
output
1
108,265
14
216,531