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 a correct Python 3 solution for this coding contest problem. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1
instruction
0
14,818
14
29,636
"Correct Solution: ``` N,K=map(int,input().split()) S=input() po=[0] X=[] i=0 for i in range(N-1): if not S[i] == S[i+1]: po.append(i+1) po.append(len(S)) for i in range(len(po)): if 2*K+1>=len(po): X.append(po[-1]) break elif 2*K+i+1>=len(po): X.append(po[2*K+i]-po[i]) break elif S[po[i]]=='0': X.append(po[2*K+i]-po[i]) else: X.append(po[2*K+1+i]-po[i]) print(max(X)) ```
output
1
14,818
14
29,637
Provide a correct Python 3 solution for this coding contest problem. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1
instruction
0
14,819
14
29,638
"Correct Solution: ``` n, k = map(int, input().split()) s = input() c = 1 l = [] l += [0,0] if (s[0] == '0') else [0] for i in range(1, n): if s[i-1] != s[i]: l += [c+l[-1]]; c = 1; else: c +=1 l += [c+l[-1]] if s[-1] == '0': l += [l[-1]] ll = len(l) pl = 2 * k + 1 if ll <= pl: print(n) else: m = 0 for i in range(0, ll-pl+1, 2): t = l[pl+i]-l[i]; m = t if (t > m) else m print(m) ```
output
1
14,819
14
29,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1 Submitted Solution: ``` n, k = map(int, input().split()) s = input().rstrip() #s = "0001111011110" #n, k = len(s), 1 s="1"+s k_pt = 0 cur_tail = 0 for cur in range(1, len(s)): if s[cur-1] == '1' and s[cur] == '0': k_pt+=1 if k_pt > k: cur_tail+=1 if s[cur_tail] == '0' and s[cur_tail+1] == '1': k_pt-=1 #print((cur_tail, cur,k_pt)) print(cur-cur_tail) ```
instruction
0
14,820
14
29,640
Yes
output
1
14,820
14
29,641
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1 Submitted Solution: ``` N, K = map(int, input().split()) S = input() S = '1' + S + '1' rev = [] for i in range(N+1): if S[i] != S[i+1]: rev.append(i) l = len(rev)//2 a = [(rev[2*i], rev[2*i+1]) for i in range(l)] a = [(0, 0)] + a + [(N, N)] K = min(K, l) m = -1 for i in range(l-K+1): x = a[i+K+1][0]-a[i][1] m = max(m, x) print(m) ```
instruction
0
14,821
14
29,642
Yes
output
1
14,821
14
29,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1 Submitted Solution: ``` n,k=map(int,input().split()) s=list(input()) judge=[0] max_=0 for i in range(n-1): if s[i]!=s[i+1]: judge.append(i+1) judge.append(n) if len(judge)//2<=k: print(len(s)) else: for i in range(len(judge)-1): if s[judge[i]]=='0': ans=judge[min(i+2*k,len(judge)-1)]-judge[i] else: ans=judge[min(i+2*k+1,len(judge)-1)]-judge[i] if ans>max_: max_=ans print(max_) ```
instruction
0
14,822
14
29,644
Yes
output
1
14,822
14
29,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1 Submitted Solution: ``` n,k = map(int,input().split()) s=input() s = list(map(int,s)) memo = [0] for i in range(1,n): if s[i-1] != s[i]: memo.append(i) ans = 0 for i in range(len(memo)): start = memo[i] if (s[start] == 1): end = i + 2*k +1 else: end = i + 2*k if end < len(memo): end = memo[end] else: end = len(s) ans = max(ans, end-start) print(ans) ```
instruction
0
14,823
14
29,646
Yes
output
1
14,823
14
29,647
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1 Submitted Solution: ``` from itertools import groupby, accumulate N, K = map(int, input().split()) S = groupby(list(input())) state = [] number = [] for i, j in S: state.append(i) number.append(len(list(j))) answer = 0 if len(state) == 1: print(number[0]) exit() number = list(accumulate([0] + number)) l = len(number) - 1 if state[0] == '0': answer = number[min(l, 2 * K)] - number[0] start = state.index('1') + 1 for i in range(start, l, 2): answer = max(answer, number[min(2 * K + i + 1, l)] - number[i - 1]) print(answer) ```
instruction
0
14,824
14
29,648
No
output
1
14,824
14
29,649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1 Submitted Solution: ``` n, k = map(int, input().split()) s = input() + "#" count = 1 group = 0 L = [] for i in range(n): if s[i] == s[i+1]: count += 1 else: L.append(count) group += 1 count = 1 ans = 0 if k >= group//2: ans = n else: temp = sum(L[:2*k+1]) ans = temp for i in range(2*k+1, group): temp -= L[i-(2*k+1)] temp += L[i] ans = max(temp, ans) print(ans) ```
instruction
0
14,825
14
29,650
No
output
1
14,825
14
29,651
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1 Submitted Solution: ``` from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 13 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n, k = LI() s = S() X = [] if s[0] == '0': X += [0] cnt = 1 for i in range(n - 1): if s[i] != s[i + 1]: X += [cnt] cnt = 1 else: cnt += 1 X += [cnt] if len(X) <= 2 * k + 1: print(n) else: ans = 0 acc = list(accumulate([0] + X)) for j in range(2 * k + 1, len(acc), 2): ans = max(acc[j] - acc[j - (2 * k + 1)], ans) print(ans) ```
instruction
0
14,826
14
29,652
No
output
1
14,826
14
29,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. N people are arranged in a row from left to right. You are given a string S of length N consisting of `0` and `1`, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is `0`, and standing on hands if that character is `1`. You will give the following direction at most K times (possibly zero): Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints * N is an integer satisfying 1 \leq N \leq 10^5. * K is an integer satisfying 1 \leq K \leq 10^5. * The length of the string S is N. * Each character of the string S is `0` or `1`. Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Examples Input 5 1 00010 Output 4 Input 14 2 11101010110011 Output 8 Input 1 1 1 Output 1 Submitted Solution: ``` n, k = map(int, input().split()) s = input() + "2" c = [] ci = 1 for i in range(n): if s[i] == s[i+1]: ci += 1 else: c.append(ci) ci = 1 c = c + [0] ans = 1 if s[0] == "1": for i in range(0, len(c), 2): if i+2*k+1 > len(c): ans = max(ans, sum(c[i:])) else: ans = max(ans, sum(c[i:i+2*k+1])) else: c = [0] + c for i in range(0, len(c), 2): if i+2*k+1 > len(c): ans = max(ans, sum(c[i:])) else: ans = max(ans, sum(c[i:i+2*k+1])) print(ans) ```
instruction
0
14,827
14
29,654
No
output
1
14,827
14
29,655
Provide a correct Python 3 solution for this coding contest problem. A: Taking a Seat-Taking a Seat- story Mr. A entered the classroom at the examination site to take an examination. However, Mr. A is a very nervous type. Therefore, depending on the situation, there may be seats that Mr. A does not want to sit in. Therefore, Mr. A decided to find out how many seats he could sit on based on certain conditions. problem Mr. A is a nervous type of person. First of all, Mr. A cannot sit in the first row from the front. Because when I sit near the proctor, I get nervous and can't solve the problem. Also, if there is a person on the right or left, Mr. A cannot sit down. This is because the sound of the pencil next to me makes it impossible to concentrate during the test. In addition, you can't sit near a noisy guy (near 8 diagonally up, down, left, and right). This is because my voice echoes in my head during the break and I can't rest. Also, it's natural, but I can't sit in the seat where the students are already sitting. Is there a place where Mr. A can sit under these conditions? Assuming that M x N seats are lined up in the classroom, let's find the number. Input format The first row gives M (number of rows: number of vertical seats) and N (number of columns: number of horizontal seats). From the second line, M lines and a character string of length N are given line by line. The j character of the i-th character string represents the state of the seat in the i-th row and the j-th column. Each letter is either'-',' x'or'o', vacant seats'-', noisy students sitting during breaks'x', other students sitting' Let it be o'. Constraint * 0 <M ≀ 100 * 0 <N ≀ 100 Output format Output the number of seats that Mr. A can sit in one line depending on the conditions. Don't forget the line break at the end. Input example 1 5 5 --o-- --xo- --x-- o --- x --xoo Output example 1 3 Input example 2 2 6 --oooo x--o-- Output example 2 1 Input example 3 3 5 ----- ----- ----- Output example 3 Ten Input example 4 4 6 o-oxoo oo-ooo oooxo- o-ooox Output example 4 0 Example Input 5 5 --o-- --xo- --x-- o---x --xoo Output 3
instruction
0
15,026
14
30,052
"Correct Solution: ``` m,n = map(int,input().split()) seat = [list(input()) for i in range(m)] dummy = ["0" for i in range(n+2)] for i in range(m): seat[i].insert(0,"0") seat[i].append("0") seat.insert(0,dummy) seat.append(dummy) for i in range(1,m + 1): for j in range(1,n + 1): if seat[i][j] == "o": if seat[i][j - 1] == "-": seat[i][j - 1] = "0" if seat[i][j + 1] == "-": seat[i][j + 1] = "0" elif seat[i][j] == "x": for k in range(3): for l in range(3): if seat[i - 1 + k][j - 1 + l] == "-": seat[i - 1 + k][j - 1 + l] = "0" for i in range(n + 1): if seat[1][i] == "-": seat[1][i] = "0" count = 0 for i in seat: for j in i: if j == "-": count += 1 print (count) ```
output
1
15,026
14
30,053
Provide a correct Python 3 solution for this coding contest problem. A: Taking a Seat-Taking a Seat- story Mr. A entered the classroom at the examination site to take an examination. However, Mr. A is a very nervous type. Therefore, depending on the situation, there may be seats that Mr. A does not want to sit in. Therefore, Mr. A decided to find out how many seats he could sit on based on certain conditions. problem Mr. A is a nervous type of person. First of all, Mr. A cannot sit in the first row from the front. Because when I sit near the proctor, I get nervous and can't solve the problem. Also, if there is a person on the right or left, Mr. A cannot sit down. This is because the sound of the pencil next to me makes it impossible to concentrate during the test. In addition, you can't sit near a noisy guy (near 8 diagonally up, down, left, and right). This is because my voice echoes in my head during the break and I can't rest. Also, it's natural, but I can't sit in the seat where the students are already sitting. Is there a place where Mr. A can sit under these conditions? Assuming that M x N seats are lined up in the classroom, let's find the number. Input format The first row gives M (number of rows: number of vertical seats) and N (number of columns: number of horizontal seats). From the second line, M lines and a character string of length N are given line by line. The j character of the i-th character string represents the state of the seat in the i-th row and the j-th column. Each letter is either'-',' x'or'o', vacant seats'-', noisy students sitting during breaks'x', other students sitting' Let it be o'. Constraint * 0 <M ≀ 100 * 0 <N ≀ 100 Output format Output the number of seats that Mr. A can sit in one line depending on the conditions. Don't forget the line break at the end. Input example 1 5 5 --o-- --xo- --x-- o --- x --xoo Output example 1 3 Input example 2 2 6 --oooo x--o-- Output example 2 1 Input example 3 3 5 ----- ----- ----- Output example 3 Ten Input example 4 4 6 o-oxoo oo-ooo oooxo- o-ooox Output example 4 0 Example Input 5 5 --o-- --xo- --x-- o---x --xoo Output 3
instruction
0
15,027
14
30,054
"Correct Solution: ``` m, n = map(int, input().split()) mp = [list("#" * (n + 2))] + [list("#" + input() + "#") for _ in range(m)] + [list("#" * (n + 2))] vec = ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1)) for y in range(1, m + 1): for x in range(1, n + 1): if mp[y][x] == "x": for dx, dy in vec: if mp[y + dy][x + dx] == "-": mp[y + dy][x + dx] = "#" if mp[y][x] == "o": if mp[y][x - 1] == "-":mp[y][x - 1] = "#" if mp[y][x + 1] == "-":mp[y][x + 1] = "#" for x in range(1, n + 1): if mp[1][x] == "-": mp[1][x] = "#" print(sum([line.count("-") for line in mp])) ```
output
1
15,027
14
30,055
Provide tags and a correct Python 3 solution for this coding contest problem. As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide. Output Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them. Examples Input 7 1 2 3 4 5 6 7 Output 2 3 2 1 6 5 4 Input 3 2 2 3 Output 0
instruction
0
15,252
14
30,504
Tags: binary search, data structures, greedy Correct Solution: ``` import sys import math n = int(sys.stdin.readline()) r = [int(x) for x in sys.stdin.readline().strip().split()] r = sorted(r) a = 0 b = n // 3 d = {key:0 for key in r} for i in range(n): d[r[i]] += 1 while a != b: k = math.ceil((a + b) / 2) rp = 0 for i in d: rp += min(k, d[i]) if rp < 3 * k:b = k - 1 else:a = k #print(rp, d, k) k = a sys.stdout.write(str(k) + "\n") rp = [] for i in d: rp += [i] * (min(k, d[i])) rp = sorted(rp) i = 0 for p in range(k): sys.stdout.write("{} {} {}\n".format(rp[i + 2 * k], rp[i + k], rp[i])) i += 1 ```
output
1
15,252
14
30,505
Provide tags and a correct Python 3 solution for this coding contest problem. As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide. Output Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them. Examples Input 7 1 2 3 4 5 6 7 Output 2 3 2 1 6 5 4 Input 3 2 2 3 Output 0
instruction
0
15,253
14
30,506
Tags: binary search, data structures, greedy Correct Solution: ``` from heapq import * from collections import defaultdict n = int(input()) r = map(int, input().split()) assoc = defaultdict(int) for ballsize in r: assoc[ballsize] += 1 available = [(-1 * val, key) for key, val in assoc.items()] heapify(available) ret = [] while len(available) > 2: a, b, c = heappop(available), heappop(available), heappop(available) ret.append(sorted([a[1], b[1], c[1]], reverse=True)) # decrease absolute quantities by adding to negative and put them back if not 0 for i, j in (a, b, c): x, xi = i + 1, j if x: heappush(available, (x, xi)) print(len(ret)) for a, b, c in ret: print(a, b, c) ```
output
1
15,253
14
30,507
Provide tags and a correct Python 3 solution for this coding contest problem. As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide. Output Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them. Examples Input 7 1 2 3 4 5 6 7 Output 2 3 2 1 6 5 4 Input 3 2 2 3 Output 0
instruction
0
15,254
14
30,508
Tags: binary search, data structures, greedy Correct Solution: ``` from io import BytesIO import os from collections import Counter import heapq input = BytesIO(os.read(0, os.fstat(0).st_size)).readline def main(): count = int(input()) balls = list(map(int, input().split())) counter = Counter(balls) pq = [] for value, count in counter.items(): heapq.heappush(pq, (-count, value)) ans = [] while len(pq) > 2: first = heapq.heappop(pq) second= heapq.heappop(pq) third = heapq.heappop(pq) ans.append(sorted([first[1], second[1], third[1]], reverse=True)) if first[0] < -1: heapq.heappush(pq, (first[0] + 1, first[1])) if second[0] < -1: heapq.heappush(pq, (second[0] + 1, second[1])) if third[0] < -1: heapq.heappush(pq, (third[0] + 1, third[1])) print(len(ans)) for snowman in ans: print(*snowman) if __name__ == "__main__": main() ```
output
1
15,254
14
30,509
Provide tags and a correct Python 3 solution for this coding contest problem. As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide. Output Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them. Examples Input 7 1 2 3 4 5 6 7 Output 2 3 2 1 6 5 4 Input 3 2 2 3 Output 0
instruction
0
15,255
14
30,510
Tags: binary search, data structures, greedy Correct Solution: ``` from collections import Counter as c from heapq import * input() a = dict(c([int(x) for x in input().split()])) d = [(-1 * v, k) for k, v in a.items()] heapify(d) ans = [] while len(d) > 2: a, b, c = heappop(d), heappop(d), heappop(d) ans.append(sorted([a[1], b[1], c[1]], reverse=True)) for x, y in (a, b, c): if x+1: heappush(d, (x+1, y)) print(len(ans)) for x in ans: print(*x) ```
output
1
15,255
14
30,511
Provide tags and a correct Python 3 solution for this coding contest problem. As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide. Output Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them. Examples Input 7 1 2 3 4 5 6 7 Output 2 3 2 1 6 5 4 Input 3 2 2 3 Output 0
instruction
0
15,256
14
30,512
Tags: binary search, data structures, greedy Correct Solution: ``` import heapq from collections import defaultdict n=int(input()) b=list(map(int,input().split())) cnt=defaultdict(lambda:0) for j in b: cnt[j]+=1 li=[] for j in list(set(b)): li.append([-cnt[j],j]) heapq.heapify(li) l=len(li) ans=[] while(l>=3): ball1=heapq.heappop(li) ball2 = heapq.heappop(li) ball3 = heapq.heappop(li) ans.append([ball1[1],ball2[1],ball3[1]]) cnt1=ball1[0]+1 if cnt1!=0: heapq.heappush(li,[cnt1,ball1[1]]) else: l+=-1 cnt2 = ball2[0] + 1 if cnt2 != 0: heapq.heappush(li, [cnt2, ball2[1]]) else: l+=-1 cnt3 = ball3[0] + 1 if cnt3 != 0: heapq.heappush(li, [cnt3, ball3[1]]) else: l+=-1 print(len(ans)) for j in ans: j.sort() print(*j[::-1]) ```
output
1
15,256
14
30,513
Provide tags and a correct Python 3 solution for this coding contest problem. As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide. Output Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them. Examples Input 7 1 2 3 4 5 6 7 Output 2 3 2 1 6 5 4 Input 3 2 2 3 Output 0
instruction
0
15,258
14
30,516
Tags: binary search, data structures, greedy Correct Solution: ``` from collections import defaultdict n, t = int(input()), input().split() p = defaultdict(int) for i in t: p[i] += 1 if len(p) < 3: print(0) else: q = list(p.items()) a, b = q[0][1], q[1][1] x, y = 0, 1 if a < b: x, y, a, b = y, x, b, a for i in range(2, len(q)): if q[i][1] > b: if q[i][1] > a: x, y, a, b = i, x, q[i][1], a else: y, b = i, q[i][1] k = n // 3 if a > k: c, s = n - a - b, n - a if c > b: q[x], q[y], k = (q[x][0], (s >> 1)), (q[y][0], b - (s & 1)), (s >> 1) else: q[x], q[y], k = (q[x][0], c), (q[y][0], c), c q = [(int(x), y) for x, y in q] q.sort(reverse = True) p, n = [], 2 * k for i in q: p += [str(i[0]) + ' '] * i[1] print(k) print('\n'.join(p[i] + p[k + i] + p[n + i] for i in range(k))) ```
output
1
15,258
14
30,517
Provide tags and a correct Python 3 solution for this coding contest problem. As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide. Output Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them. Examples Input 7 1 2 3 4 5 6 7 Output 2 3 2 1 6 5 4 Input 3 2 2 3 Output 0
instruction
0
15,259
14
30,518
Tags: binary search, data structures, greedy Correct Solution: ``` import os import sys from io import BytesIO, IOBase import math import itertools import bisect import heapq def main(): pass 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") def binary(n): return (bin(n).replace("0b", "")) def decimal(s): return (int(s, 2)) def pow2(n): p = 0 while (n > 1): n //= 2 p += 1 return (p) def primeFactors(n): l = [] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: l.append(i) n = n / i if n > 2: l.append(int(n)) return (l) def isPrime(n): if (n == 1): return (False) else: root = int(n ** 0.5) root += 1 for i in range(2, root): if (n % i == 0): return (False) return (True) def maxPrimeFactors(n): maxPrime = -1 while n % 2 == 0: maxPrime = 2 n >>= 1 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime) def countcon(s, i): c = 0 ch = s[i] for i in range(i, len(s)): if (s[i] == ch): c += 1 else: break return (c) def lis(arr): n = len(arr) lis = [1] * n for i in range(1, n): for j in range(0, i): if arr[i] > arr[j] and lis[i] < lis[j] + 1: lis[i] = lis[j] + 1 maximum = 0 for i in range(n): maximum = max(maximum, lis[i]) return maximum def isSubSequence(str1, str2): m = len(str1) n = len(str2) j = 0 i = 0 while j < m and i < n: if str1[j] == str2[i]: j = j + 1 i = i + 1 return j == m def maxfac(n): root = int(n ** 0.5) for i in range(2, root + 1): if (n % i == 0): return (n // i) return (n) def p2(n): c=0 while(n%2==0): n//=2 c+=1 return c def seive(n): primes=[True]*(n+1) primes[1]=primes[0]=False for i in range(2,n+1): if(primes[i]): for j in range(i+i,n+1,i): primes[j]=False p=[] for i in range(0,n+1): if(primes[i]): p.append(i) return(p) def ncr(n, r, p): num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p def denofactinverse(n,m): fac=1 for i in range(1,n+1): fac=(fac*i)%m return (pow(fac,m-2,m)) def numofact(n,m): fac = 1 for i in range(1, n + 1): fac = (fac * i) % m return(fac) def sumnum(n): s=0 for i in str(n): s+=int(i) return s n=int(input()) l=list(map(int,input().split())) d={} for i in l: if(i not in d): d.update({i:1}) else: d[i]+=1 l=[] for i in d: l.append([-d[i],i]) l.sort() #print(l) ans=[] while(len(l)>2): t1,t2,t3=heapq.heappop(l),heapq.heappop(l),heapq.heappop(l) ans.append([t1[1],t2[1],t3[1]]) #print(t1,t2,t3) if(t1[0]<-1): t1[0]+=1 heapq.heappush(l,t1) if (t2[0]<-1): t2[0]+=1 heapq.heappush(l,t2) if (t3[0]<-1): t3[0]+=1 heapq.heappush(l,t3) print(len(ans)) for i in ans: i.sort(reverse=True) print(*i) ```
output
1
15,259
14
30,519
Provide tags and a correct Python 3 solution for this coding contest problem. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
instruction
0
15,357
14
30,714
Tags: greedy Correct Solution: ``` import sys def solve(): n, k = map(int, input().split()) bada = list(map(int, input().split())) a = list() for i in range(len(bada)): if len(a) > 0 and bada[i] == a[-1]: continue a.append(bada[i]) bad = [0] * (k + 1) for i, val in enumerate(a): if i + 1 >= len(a) and i == 0: continue if i + 1 >= len(a): bad[val] += 1 elif i == 0: bad[val] += 1 else: before = a[i-1] after = a[i+1] bad[val] += 2 if before == after else 1 which = -1 howmany = -1 for i in range(len(bad)): if bad[i] > howmany: which = i howmany = bad[i] print(which) if sys.hexversion == 50594544 : sys.stdin = open("test.txt") solve() ```
output
1
15,357
14
30,715
Provide tags and a correct Python 3 solution for this coding contest problem. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
instruction
0
15,358
14
30,716
Tags: greedy Correct Solution: ``` import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) n, k = mints() a = list(mints()) i = 0 c = [0]*(k+1) while i < n: j = i while j < n and a[j] == a[i]: j += 1 if i - 1 >= 0: if j < n: if a[i-1] != a[j]: c[a[i]] += 1 else: c[a[i]] += 2 else: c[a[i]] += 1 elif j < n: c[a[i]] += 1 i = j z = 1 for i in range(k+1): if c[z] < c[i]: z = i print(z) ```
output
1
15,358
14
30,717
Provide tags and a correct Python 3 solution for this coding contest problem. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
instruction
0
15,359
14
30,718
Tags: greedy Correct Solution: ``` import math #n,m=map(int,input().split()) from collections import Counter #for i in range(n): import math #for _ in range(int(input())): #n = int(input()) #for _ in range(int(input())): #n = int(input()) import bisect '''for _ in range(int(input())): n=int(input()) n,k=map(int, input().split()) arr = list(map(int, input().split()))''' #n, m, k = [int(x) for x in input().split()] n,m=map(int,input().split()) arr=list(map(int,input().split())) ls=[0]*(10**5+1) pre=arr[0] for i in range(1,n-1): if arr[i]!=arr[i+1]: ls[arr[i]]+=2 if arr[i+1]==pre else 1 pre=arr[i] if arr[0]!=arr[-1]: ls[arr[-1]]+=1 if arr[0]!=arr[1]: ls[arr[0]]+=1 var=ls.index(max(ls)) mm=max(ls) #print(ls[:4]) if m==2: if 1 in arr and 2 in arr: print(1) else: print(0) else: for i in range(len(ls)): if ls[i] == mm: print(i) break ```
output
1
15,359
14
30,719
Provide tags and a correct Python 3 solution for this coding contest problem. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
instruction
0
15,360
14
30,720
Tags: greedy Correct Solution: ``` # 1 2 3 2 3 1 3 # 12 23 32 23 31 13 # 1 1 2 3 2 3 3 1 1 3 # 112 123 232 323 233 331 311 113 # 12/21 1 0 0 0 0 1 0 0 # 23/32 0 1 1 1 0 0 0 0 # 13/31 0 1 0 0 0 1 0 0 # 1 2 3 1 2 3 1 2 3| 1 # 123 231 312 123 231 312 123 231 # 12/21 1 1 1 0 1 1 0 1 # 23/32 1 1 0 1 0 1 1 0 # 13/31 1 1 0 1 1 0 1 1 # with open('h.in', 'r') as inputFile, open('h.out', 'w') as outputFile: # (n,k) = [int(x) for x in inputFile.readline().strip().split(' ')] # dataF = inputFile.readline().strip().split(' '); (n,k) = [int(x) for x in input().strip().split(' ')] dataF = input().strip().split(' '); dataF = [int(x) for x in dataF] data = [0] for i in range(len(dataF)): if (data[len(data)-1] != dataF[i]): data.append(dataF[i]) data = data[1:] res = {x:0 for x in set(data)} res[data[0]] += 1 res[data[len(data)-1]] += 1 for i in range(0,len(data)-2,1): prev = data[i] curr = data[i+1] next = data[i+2] if (prev == next): res[curr] += 2 if (prev != next): res[curr] += 1 print(max(res, key=res.get)) ```
output
1
15,360
14
30,721
Provide tags and a correct Python 3 solution for this coding contest problem. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
instruction
0
15,361
14
30,722
Tags: greedy Correct Solution: ``` __author__ = 'Michael Ilyin' def prepare(a): na = [] last = 0 for i in range(0, len(a)): if last != a[i]: na.append(a[i]) last = a[i] return na header = input() films = int(header[:header.find(' ')]) genres = int(header[header.find(' '):]) numbers = [int(x) for x in input().split()] res = [[genre, 0] for genre in range(1, genres + 1)] numbers = prepare(numbers) films = len(numbers) for i, obj in enumerate(numbers): if i == 0: res[obj - 1][1] += 1 continue if i == films - 1: res[obj - 1][1] += 1 continue if numbers[i - 1] == numbers[i + 1]: res[obj - 1][1] += 2 else: res[obj - 1][1] += 1 res = sorted(res, key=lambda x: x[0], reverse=False) res = sorted(res, key=lambda x: x[1], reverse=True) print(str(res[0][0])) ```
output
1
15,361
14
30,723
Provide tags and a correct Python 3 solution for this coding contest problem. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
instruction
0
15,362
14
30,724
Tags: greedy Correct Solution: ``` import sys import math import heapq import bisect from collections import Counter from collections import defaultdict from io import BytesIO, IOBase import string class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os 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 self.BUFSIZE = 8192 def read(self): while True: b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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 = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.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: self.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") def get_int(): return int(input()) def get_ints(): return list(map(int, input().split(' '))) def get_int_grid(n): return [get_ints() for _ in range(n)] def get_str(): return input().split(' ') def yes_no(b): if b: return "YES" else: return "NO" def binary_search(good, left, right, delta=1, right_true=False): """ Performs binary search ---------- Parameters ---------- :param good: Function used to perform the binary search :param left: Starting value of left limit :param right: Starting value of the right limit :param delta: Margin of error, defaults value of 1 for integer binary search :param right_true: Boolean, for whether the right limit is the true invariant :return: Returns the most extremal value interval [left, right] which is good function evaluates to True, alternatively returns False if no such value found """ limits = [left, right] while limits[1] - limits[0] > delta: if delta == 1: mid = sum(limits) // 2 else: mid = sum(limits) / 2 if good(mid): limits[int(right_true)] = mid else: limits[int(~right_true)] = mid if good(limits[int(right_true)]): return limits[int(right_true)] else: return False def prefix_sums(a): p = [0] for x in a: p.append(p[-1] + x) return p def solve_a(): n = get_int() a = get_ints() negs = 0 cnt = 0 ans = [] for i in range(n): cnt += 1 if a[i] < 0: negs += 1 if negs == 3: ans.append(cnt - 1) cnt = 1 negs = 1 ans.append(cnt) return ans def solve_b(): s = input() pass def solve_c(): n, k = get_ints() a = get_ints() #if k == 1: #return 1 a_uniq = [] for x in a: if len(a_uniq) == 0 or x != a_uniq[-1]: a_uniq.append(x) m = len(a_uniq) d = defaultdict(int) for i in range(m): if 0 < i < m - 1 and a_uniq[i + 1] == a_uniq[i - 1]: d[a_uniq[i]] += 2 else: d[a_uniq[i]] += 1 m = -1 j = -1 for i in range(1, k + 1): if i in d and d[i] > m: m, j = d[i], i return j print(solve_c()) ```
output
1
15,362
14
30,725
Provide tags and a correct Python 3 solution for this coding contest problem. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
instruction
0
15,363
14
30,726
Tags: greedy Correct Solution: ``` n, k = map(int, input().split()) a = [int(i) for i in input().split()] s = [0 for i in range(k)] b = [a[0]] for i in range(1, n): if a[i] == b[-1]: continue else: b.append(a[i]) y = len(b) for i in range(y): if i == 0 and b[i] != b[i + 1]: s[a[0] - 1] += 1 elif i == y - 1 and b[i] != b[i - 1]: s[b[y - 1] - 1] += 1 else: if b[i - 1] == b[i + 1]: s[b[i] - 1] += 2 else: s[b[i] - 1] += 1 x = max(s) print(s.index(x) + 1) ```
output
1
15,363
14
30,727
Provide tags and a correct Python 3 solution for this coding contest problem. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.
instruction
0
15,364
14
30,728
Tags: greedy Correct Solution: ``` n,k = map(int,input().split()) lis=list(map(int,input().split())) ans=[] freq=[0]*(k+1) for i in range(n-1): if lis[i]!=lis[i+1]: ans.append(lis[i]) if lis[-1]!=ans[-1]: ans.append(lis[-1]) #print(ans,freq) l=len(ans) for i in range(1,l-1): if ans[i-1]==ans[i+1]: freq[ans[i]]+=2 else: freq[ans[i]]+=1 freq[ans[-1]]+=1 freq[ans[0]]+=1 print(freq.index(max(freq))) ```
output
1
15,364
14
30,729
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses. Submitted Solution: ``` n, k = map(int, input().split()) t = list(map(int, input().split())) t = [t[0]] + [t[i] for i in range(1, len(t)) if t[i] != t[i - 1]] p = [0] * (k + 1) for i in range(1, len(t) - 1): if t[i - 1] == t[i + 1]: p[t[i]] += 2 else: p[t[i]] += 1 p[t[0]] += 1 p[t[-1]] += 1 print(p.index(max(p))) ```
instruction
0
15,365
14
30,730
Yes
output
1
15,365
14
30,731
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses. Submitted Solution: ``` # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------- fast io -------------------- from math import gcd, ceil def pre(s): n = len(s) pi = [0] * n for i in range(1, n): j = pi[i - 1] while j and s[i] != s[j]: j = pi[j - 1] if s[i] == s[j]: j += 1 pi[i] = j return pi def prod(a): ans = 1 for each in a: ans = (ans * each) return ans def lcm(a, b): return a * b // gcd(a, b) def binary(x, length=16): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y for _ in range(int(input()) if not True else 1): #n = int(input()) n, k = map(int, input().split()) #a, b = map(int, input().split()) #c, d = map(int, input().split()) a = list(map(int, input().split())) #b = list(map(int, input().split())) #s = input() b = [a[0]] for i in range(1, n): if a[i] == b[-1]: continue else: b += [a[i]] di = {} for i in range(len(b)): if b[i] not in di: di[b[i]] = [] di[b[i]] += [i] total = len(b) - 1 ans = [0]*(k+1) for i in range(1, k+1): ans[i] = total - len(di[i]) for i in range(1, k+1): for j in range(len(di[i])): if di[i][j] and di[i][j]+1 != len(b) and b[di[i][j]-1] == b[di[i][j]+1]: ans[i] -= 1 ans[0] = 9999999999999 print(ans.index(min(ans))) ```
instruction
0
15,366
14
30,732
Yes
output
1
15,366
14
30,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses. Submitted Solution: ``` num_days, num_genres = map(int, input().split()) schedule = list(map(int, input().split())) compressed = [] current = schedule[0] pos = 1 while True: compressed.append(current) while pos < num_days and schedule[pos] == current: pos += 1 if pos < num_days: current = schedule[pos] else: break score = (num_genres + 1) * [ 0 ] score[compressed[0]] += 1 for i in range(2, len(compressed)): score[compressed[i - 1]] += 1 if compressed[i - 2] == compressed[i]: score[compressed[i - 1]] += 1 score[compressed[len(compressed) - 1]] += 1 best_score, best_genre = -1, -1 for genre in range(1, num_genres + 1): if score[genre] > best_score: best_score = score[genre] best_genre = genre print(best_genre) # Made By Mostafa_Khaled ```
instruction
0
15,367
14
30,734
Yes
output
1
15,367
14
30,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses. Submitted Solution: ``` n,k=map(int,input().split()) a=[int(i) for i in input().split()] a=[0]+a+[0] i=1 tot=0 j=1 cnt=[0]*(k+1) while i<=n: while j<=n and a[j]==a[i]: j+=1 tot+=1 if a[i-1]==a[j]: cnt[a[i]]+=2 #gain a strain of 2 if we remove a[i] else: cnt[a[i]]+=1 i=j tot-=1 ans=tot #print(cnt) for i in range(1,k+1): if ans>tot-cnt[i]: ans=tot-cnt[i] res=i print(res) ```
instruction
0
15,368
14
30,736
Yes
output
1
15,368
14
30,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses. Submitted Solution: ``` n, k = map(int, input().split()) a = [int(i) for i in input().split()] s = [0 for i in range(k)] if n == 100000 and k == 3: print(1) elif n == 100000 and k == 5: print(2) else: for i in range(n): if i == 0 and a[i] == a[i + 1]: continue elif i == 0 and a[i] != a[i + 1]: s[a[0] - 1] += 1 elif i == n - 1 and a[i] == a[i - 1]: continue elif i == n - 1 and a[i] != a[i - 1]: s[a[n - 1] - 1] += 1 else: if a[i - 1] == a[i + 1]: s[a[i] - 1] += 2 else: s[a[i] - 1] += 1 x = max(s) print(s.index(x) + 1) ```
instruction
0
15,369
14
30,738
No
output
1
15,369
14
30,739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses. Submitted Solution: ``` import math #n,m=map(int,input().split()) from collections import Counter #for i in range(n): import math #for _ in range(int(input())): #n = int(input()) #for _ in range(int(input())): #n = int(input()) import bisect '''for _ in range(int(input())): n=int(input()) n,k=map(int, input().split()) arr = list(map(int, input().split()))''' #n, m, k = [int(x) for x in input().split()] n,m=map(int,input().split()) arr=list(map(int,input().split())) ls=[0]*(10**5+1) pre=arr[0] for i in range(1,n-1): if arr[i]!=arr[i+1]: ls[arr[i]]+=2 if arr[i+1]==pre else 1 if arr[0]!=arr[-1]: ls[arr[-1]]+=1 if arr[0]!=arr[1]: ls[arr[0]]+=1 var=ls.index(max(ls)) mm=max(ls) if m<=2: print(0) else: print(ls[:10]) for i in range(len(ls)): if ls[i]==mm: print(i) break ```
instruction
0
15,370
14
30,740
No
output
1
15,370
14
30,741
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses. Submitted Solution: ``` import math #n,m=map(int,input().split()) from collections import Counter #for i in range(n): import math #for _ in range(int(input())): #n = int(input()) #for _ in range(int(input())): #n = int(input()) import bisect '''for _ in range(int(input())): n=int(input()) n,k=map(int, input().split()) arr = list(map(int, input().split()))''' #n, m, k = [int(x) for x in input().split()] n,m=map(int,input().split()) arr=list(map(int,input().split())) ls=[0]*(10**5+1) pre=arr[0] for i in range(1,n-1): if arr[i]!=arr[i+1]: ls[arr[i]]+=2 if arr[i+1]==pre else 1 if arr[0]!=arr[-1]: ls[arr[-1]]+=1 if arr[0]!=arr[1]: ls[arr[0]]+=1 var=ls.index(max(ls)) mm=max(ls) for i in range(len(ls)): if ls[i]==mm: print(i) break ```
instruction
0
15,371
14
30,742
No
output
1
15,371
14
30,743
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre β€” an integer from 1 to k. On the i-th day the festival will show a movie of genre ai. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence a1, a2, ..., an at least once. Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site. As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress. Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies. Valentine wants to choose such genre x (1 ≀ x ≀ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum. Input The first line of the input contains two integers n and k (2 ≀ k ≀ n ≀ 105), where n is the number of movies and k is the number of genres. The second line of the input contains a sequence of n positive integers a1, a2, ..., an (1 ≀ ai ≀ k), where ai is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence. Output Print a single number β€” the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number. Examples Input 10 3 1 1 2 3 2 3 3 1 1 3 Output 3 Input 7 3 3 1 3 2 3 1 2 Output 1 Note In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses. In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses. Submitted Solution: ``` import math #n,m=map(int,input().split()) from collections import Counter #for i in range(n): import math #for _ in range(int(input())): #n = int(input()) #for _ in range(int(input())): #n = int(input()) import bisect '''for _ in range(int(input())): n=int(input()) n,k=map(int, input().split()) arr = list(map(int, input().split()))''' #n, m, k = [int(x) for x in input().split()] n,m=map(int,input().split()) arr=list(map(int,input().split())) ls=[0]*(10**5+1) pre=arr[0] for i in range(1,n-1): if arr[i]!=arr[i+1]: ls[arr[i]]+=2 if arr[i+1]==pre else 1 if arr[0]!=arr[-1]: ls[arr[-1]]+=1 if arr[0]!=arr[1]: ls[arr[0]]+=1 var=ls.index(max(ls)) mm=max(ls) if m<=2: print(0) else: for i in range(len(ls)): if ls[i]==mm: print(i) break ```
instruction
0
15,372
14
30,744
No
output
1
15,372
14
30,745
Provide tags and a correct Python 3 solution for this coding contest problem. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
instruction
0
15,493
14
30,986
Tags: brute force Correct Solution: ``` n = int(input()) m = [0] * 366 f = [0] * 366 res = 0 for i in range(n): x, l, r = [i for i in input().split()] l = int(l) r = int(r) if x == 'M': for j in range(l-1, r): m[j] += 1 else: for j in range(l-1, r): f[j] += 1 for i in range(366): res = max(res, min(m[i], f[i])) print(res * 2) ```
output
1
15,493
14
30,987
Provide tags and a correct Python 3 solution for this coding contest problem. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
instruction
0
15,494
14
30,988
Tags: brute force Correct Solution: ``` # Description of the problem can be found at http://codeforces.com/problemset/problem/629/B n = int(input()) a_g = list([0] * 367 for _ in range(2)) a_b = [0] * 367 for _ in range(n): g, s, e = input().split() for i in range(int(s), int(e) + 1): a_g[1 if g == "F" else 0][i] += 1 m = 0 for i in range(1, 367): m = max(m, 2 * min(a_g[0][i], a_g[1][i])) print(m) ```
output
1
15,494
14
30,989
Provide tags and a correct Python 3 solution for this coding contest problem. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
instruction
0
15,495
14
30,990
Tags: brute force Correct Solution: ``` readInts=lambda: list(map(int, input().split())) n = int(input()) num = [[0,0] for i in range(370)] for i in range(n): s,u,v = (input().split()) u=int(u) v=int(v) c=int(s=='F') num[u][c]+=1 num[v+1][c]-=1 x=0;y=0 ret=0 for i in range(367): x+=num[i][0] y+=num[i][1] ret=max(ret,min(x,y)) ret*=2 print(ret) ```
output
1
15,495
14
30,991
Provide tags and a correct Python 3 solution for this coding contest problem. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
instruction
0
15,496
14
30,992
Tags: brute force Correct Solution: ``` n = int(input()) m1 = {} m2 = {} for x in range(367): m1[x] = 0 for y in range(367): m2[y] = 0 for friend in range(n): g, a, b = input().split() for bruh in range(int(a), int(b)+1): if g == "M": m1[bruh] += 1 elif g == "F": m2[bruh] += 1 attendees = [] for day in range(367): attendees.append(min(m1[day], m2[day])) print(max(attendees)*2) ```
output
1
15,496
14
30,993
Provide tags and a correct Python 3 solution for this coding contest problem. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
instruction
0
15,497
14
30,994
Tags: brute force Correct Solution: ``` n=int(input()) ab=[list(input().split()) for i in range(n)] man,woman=0,0 day=[] for i in range(1,367): for x in range(len(ab)): if int(ab[x][1])<=i<=int(ab[x][2]): if ab[x][0]=='M': man+=1 else: woman+=1 day.append(2*min(man,woman)) man=0 woman=0 print(max(day)) ```
output
1
15,497
14
30,995
Provide tags and a correct Python 3 solution for this coding contest problem. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
instruction
0
15,498
14
30,996
Tags: brute force Correct Solution: ``` n = int(input()) f = [0]*366 m = [0]*366 for i in range(n): a,b,c = input().split() if a=='F': for j in range(int(b)-1,int(c)):f[j]+=1 if a=='M': for j in range(int(b)-1,int(c)):m[j]+=1 ans = 0 for i in range(366): t = min(m[i],f[i]) ans = max(ans,t) print(ans*2) ```
output
1
15,498
14
30,997
Provide tags and a correct Python 3 solution for this coding contest problem. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
instruction
0
15,499
14
30,998
Tags: brute force Correct Solution: ``` n = int(input()) male,female = [0]*370,[0]*370 for _ in range(n): g,l,r = input().split() if g =='M': for i in range(int(l),int(r)+1): male[i]+=1 else: for i in range(int(l),int(r)+1): female[i]+=1 ans = 0 for i in range(1,367): tans = 2*min(male[i],female[i]) if tans>ans: ans = tans print(ans) ```
output
1
15,499
14
30,999
Provide tags and a correct Python 3 solution for this coding contest problem. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
instruction
0
15,500
14
31,000
Tags: brute force Correct Solution: ``` __author__ = 'aste' DAYS = 366 def main(): n = int(input()) g_f = [0] * DAYS g_m = [0] * DAYS for i in range(0, n): g, a, b = input().split() a = int(a) b = int(b) for j in range(1, DAYS + 1): if a <= j <= b: if g == 'F': g_f[j - 1] += 1 else: g_m[j - 1] += 1 res = 0 for i in range(0, DAYS): res = max(res, 2*min(g_f[i], g_m[i])) print(res) main() ```
output
1
15,500
14
31,001
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. Submitted Solution: ``` n=int(input()) friends=[None]*n*3 from_to=[None]*n*2 for i in range(n): line=input().split() friends[i*3]=line[0] friends[i*3+1]=from_to[i*2]=int(line[1]) friends[i*3+2]=from_to[i*2+1]=int(line[2]) from_to_dist=list(set(from_to)) len_from_to_dist=len(from_to_dist) female_male=[0]*len_from_to_dist*2 pair_counts=[None]*len_from_to_dist for i in range(len_from_to_dist): cur=from_to_dist[i] for j in range(n): if cur>=friends[j*3+1] and cur<=friends[j*3+2]: if friends[j*3]=='F': female_male[i*2]+=1 else: female_male[i*2+1]+=1 pair_counts[i]=min(female_male[i*2],female_male[i*2+1]) print(max(pair_counts)*2) ```
instruction
0
15,501
14
31,002
Yes
output
1
15,501
14
31,003
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. Submitted Solution: ``` m=[0]*367 f=[0]*367 for i in range(int(input())): a=list(input().split()) if a[0]=='M': for i in range(int(a[1]),int(a[2])+1): m[i]+=1 else: for i in range(int(a[1]),int(a[2])+1): f[i]+=1 x=0 for i in range(367): x=max(x,min(m[i],f[i])) print(2*x) ```
instruction
0
15,502
14
31,004
Yes
output
1
15,502
14
31,005
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. Submitted Solution: ``` if __name__ == '__main__': n = int(input()) mi = [0] * 366 fi = [0] * 366 for _ in range(n): fm, s, e = map(str, input().split()) if fm == 'M': for i in range(int(s) - 1, int(e)): mi[i] += 1 elif fm == 'F': for i in range(int(s) - 1, int(e)): fi[i] += 1 print(2 * max([min(m, f) for m, f in zip(mi, fi)])) ```
instruction
0
15,503
14
31,006
Yes
output
1
15,503
14
31,007
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. Submitted Solution: ``` n=int(input()) a,b=[[0,0] for i in range(366)],0 for i in range(n): x,y,z=map(str,input().split()) y,z=int(y),int(z) if x=='M': for i in range(y-1,z):a[i][0]+=1 else: for i in range(y-1,z):a[i][1]+=1 for i in range(366): if min(a[i])>b:b=min(a[i]) print(b*2) ```
instruction
0
15,504
14
31,008
Yes
output
1
15,504
14
31,009
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. Submitted Solution: ``` class friends: def __init__(self,gender,start,end): self.gender=gender self.start=start self.end=end n=int(input()) obj=[] for _ in range(n): gender,start,end=input().split() obj.append(friends(gender,int(start),int(end))) obj.sort(key= lambda x:x.start) invit=[] count=0 for i in obj: mygen=1 othergen=0 count=1 for j in obj[obj.index(i)+1:n]: if j.start<=i.end: count+=1 if j.gender!=i.gender: othergen+=1 else: mygen+=1 if mygen==othergen: invit.append(2*mygen) if mygen!=othergen: invit.append(2*min(mygen,othergen)) print(max(invit)) ```
instruction
0
15,505
14
31,010
No
output
1
15,505
14
31,011
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. Submitted Solution: ``` a=int(input()) ma=[] md=[] fa=[] fd=[] for i in range(a): y=input().split() if y[0]=='M': ma.append(int(y[1])) md.append(int(y[2])+1) else: fa.append(int(y[1])) fd.append(int(y[2])+1) ma.sort() md.sort() fa.sort() fd.sort() m=0 f=0 mx=0 mpa=0 fpa=0 mda=0 fda=0 for i in range(1,366): while mpa<len(ma) and ma[mpa]==i: mpa+=1 m+=1 while mda<len(md) and md[mda]==i: mda+=1 m-=1 while fpa<len(fa) and fa[fpa]==i: fpa+=1 f+=1 while fda<len(fd) and fd[fda]==i: fda+=1 f-=1 mx=max(mx, min(f,m)*2) print(mx) ```
instruction
0
15,506
14
31,012
No
output
1
15,506
14
31,013
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party. Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party. Input The first line of the input contains a single integer n (1 ≀ n ≀ 5000) β€” then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≀ ai ≀ bi ≀ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive. Output Print the maximum number of people that may come to Famil Door's party. Examples Input 4 M 151 307 F 343 352 F 117 145 M 24 128 Output 2 Input 6 M 128 130 F 128 131 F 131 140 F 131 141 M 131 200 M 140 200 Output 4 Note In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. Submitted Solution: ``` # print("Input n") n = int(input()) # Array to store all the input information arr = [[0 for i in range(n)] for j in range(3)] # Set to hold all the endpoints we need to check endpts = set() # Input all the information for i in range(n): # print("Input the next information") s,a,b = [x for x in input().split()] a = int(a) b = int(b) endpts.add(a) endpts.add(b) arr[0][i] = s arr[1][i] = a arr[2][i] = b # Must add the first and last one to the check! endpts.add(1) endpts.add(366) # Loop over the set of endpoints and brute force the max answer = 0 # for check in endpts: for check in range(367): male = 0 female = 0 total = 0 for i in range(n): sex = arr[0][i] left = arr[1][i] right = arr[2][i] if left <= check and check <= right: # A person who can come on that day total += 1 if sex == "M": male += 1 else: female += 1 if male == female and total > answer: answer = total # print("A better day is day " + str(check)) print(answer) ```
instruction
0
15,507
14
31,014
No
output
1
15,507
14
31,015