#C12623. Index of First Occurrence of Largest Integer

    ID: 42071 Type: Default 1000ms 256MiB

Index of First Occurrence of Largest Integer

Index of First Occurrence of Largest Integer

You are given a list of integers. Your task is to find the index (0-indexed) of the first occurrence of the largest integer in the list. If the list is empty, output -1.

Note:

  • If the list is empty, simply return -1.
  • If there are multiple occurrences of the maximum element, return the index of the first one.

For example:

  • For the input list [4, 2, 7, 1, 7, 5], the largest integer is 7 and its first occurrence is at index 2.
  • For the input list [], the result is -1.

inputFormat

The input is read from stdin and consists of two lines:

  1. The first line contains a single integer N (0 ≤ N ≤ 105) denoting the number of elements in the list.
  2. The second line contains N space-separated integers. If N is 0, the list is empty and the second line may be absent.

outputFormat

Output to stdout a single integer representing the index (0-indexed) of the first occurrence of the largest integer in the list. If the list is empty, output -1.

## sample
6
4 2 7 1 7 5
2