#C2027. Longest Working Days

    ID: 45298 Type: Default 1000ms 256MiB

Longest Working Days

Longest Working Days

Given an integer array representing the days of the week (where 0 corresponds to Sunday, 1 to Monday, ..., and 6 to Saturday), you are required to find the longest contiguous subsequence of working days. Working days are defined as Monday to Friday (i.e. days 1 through 5). If there are no working days or no consecutive group exists, output an empty result.

The input is given in two lines. The first line is an integer n denoting the number of days, and the second line contains n integers separated by spaces representing the days of the week.

The output should consist of the longest contiguous subsequence of working days. Each number in the output should be separated by a single space. If there is no valid subsequence, output an empty line.

Note: If there are multiple subsequences with the same maximum length, the one that appears first in the input should be returned.

Mathematical Formulation: Let\( A = [a_1, a_2, \dots, a_n] \) be the input array. We define a working day as any\( a_i \) satisfying \( 1 \leq a_i \leq 5 \). Find a segment \( A[i \dots j] \) such that for all \( k \) with \( i \leq k \leq j,\ a_k \) is a working day and \( j-i+1 \) is maximized.

inputFormat

The first line contains an integer n indicating the number of days. The second line contains n space-separated integers representing days of the week (0 for Sunday, 1 for Monday, ..., 6 for Saturday).

outputFormat

Output the longest contiguous subsequence of working days (Monday to Friday) as space-separated integers in a single line. If no such sequence exists, output an empty line.

## sample
11
1 2 3 0 4 5 6 1 2 3 4
1 2 3 4