PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000155. Đoạn ngày làm việc hiệu quả dài nhất (Longest Well-Performing Interval)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đoạn ngày làm việc hiệu quả dài nhất (Longest Well-Performing Interval)

Longest Well-Performing Interval

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given daily working hours a1,…,ana_1,\ldots,a_n, a day is tiring when its hours are strictly greater than 8. All other days, including exactly 8 hours, are non-tiring. Find the longest contiguous interval containing strictly more tiring days than non-tiring days. Print 0 if no such interval exists.

Input

  • Line 1: integer nn, the number of days.
  • Line 2: nn integers a1,…,ana_1,\ldots,a_n in order.

Output

Print one integer: the maximum qualifying interval length.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; 0≤aj≤160\le a_j\le 16 for every 1≤j≤n1\le j\le n.
  • Subtask 2 (30 points): 1≤n≤100001\le n\le 10000; 9≤aj≤169\le a_j\le 16 for every 1≤j≤n1\le j\le n.
  • Subtask 3 (50 points): 1≤n≤100001\le n\le 10000; 0≤aj≤160\le a_j\le 16 for every 1≤j≤n1\le j\le n.

Example 1

Input

7
9 9 6 0 6 6 9

Output

3

Explanation

Interval [1,3] has two tiring days and one other day. For lengths 4, 5, 6, 7, the maximum tiring-day counts are 2, 2, 2, 3 respectively, never more than half.

Example 2

Input

3
6 6 6

Output

0

Explanation

There are no tiring days, so no nonempty interval qualifies.