#B3877. Consecutive Wins Scoring

    ID: 11534 Type: Default 1000ms 256MiB

Consecutive Wins Scoring

Consecutive Wins Scoring

There are \(n\) teams numbered from \(1\) to \(n\). A total of \(n\) matches are played, and in each match there is exactly one winning team. The scoring rules for a win are as follows:

  • If the win is the first in a consecutive winning streak, the team earns \(1\) point.
  • If it is the second consecutive win, the team earns \(2\) points.
  • If it is the third consecutive win, the team earns \(3\) points.
  • For the fourth (and any subsequent) consecutive win, the team always earns \(3\) points.

For example, when \(n=12\) and the winning teams in order are:

1 2 1 1 3 2 1 1 1 1 4 2

The scores are computed as follows:

  • Team 1: \(1 + 1 + 2 + 1 + 2 + 3 + 3 = 13\) points.
  • Team 2: \(1 + 1 + 1 = 3\) points.
  • Teams 3 and 4: \(1\) point each.
  • Teams 5 to 12: \(0\) points.

The task is to determine the maximum score achieved by any team.

inputFormat

The input consists of two lines:

  1. The first line contains an integer \(n\) indicating the number of teams and matches.
  2. The second line contains \(n\) integers. Each integer represents the team number of the winner for that match.

outputFormat

Output a single integer which is the maximum score among all teams after all matches are played.

sample

12
1 2 1 1 3 2 1 1 1 1 4 2
13