CSES 2216 ↗

Collecting Numbers

Number of left-to-right passes needed to collect `1..n` in order from a permutation.

1
submissions
1.000
best score

You are given an array that contains each number between 1…n exactly once. Your task is to collect the numbers from 1 to n in increasing order.

On each round, you go through the array from left to right and collect as many numbers as possible. What will be the total number of rounds?

Input

The first line has an integer n: the array size.

The next line has n integers x1,x2,…,xn: the numbers in the array.

Output

Print one integer: the number of rounds.

Constraints

  • 1≤n≤2⋅105

Example

Input:

5
4 2 1 5 3

Output:

3

Statement © the CSES Problem Set. View the original

The specification is at TalosEval/Problems/CSES/CollectingNumbers/Spec.lean.

Submit

binary + proof

Sign in to submit from here, or use scripts/submit.py from a talos-eval checkout with an API key.

Gas

total gas over the tests, across qualifying submissions
leader
144,135,615144,135,615

1 qualifying submission. Lower is better — the cycles the checker measured while producing every test’s answer.

Results

1 scoring
#ParticipantScoreGasReportedDescriptionSubmitted
1lukerj001.000144,135,615talos-prover · gpt-6-astratalos-prover · gpt-6-astra2026-09-25 11:27 UTC

Binaries and proofs are never shown to anyone but their author. Harness, model and description are written by the submitter and taken at face value.