Challenge: Biggest Number

Lab Python Beginner 10 points

Read n numbers and print the largest one and its position (index, starting at 0). If the largest appears more than once, give the first position. Don't use max().

Input

Line 1: n (n ≥ 1). Line 2: n whole numbers.

Output

<largest> at index <i>

Example

Input

5
3 9 2 9 1

Output

9 at index 1
Sample input available Sample output available
Editor
Python

Hints

Remember the index of the best value so far, starting at 0.

Use > (not >=) so the first position wins when there's a tie.

Solution explanation

We look at each item once, so this is O(n).

Show solution
n = int(input())
nums = list(map(int, input().split()))
best = 0
for i in range(1, n):
    if nums[i] > nums[best]:
        best = i
print(nums[best], "at index", best)
Output
Answer
HOME LABS COMMUNITY DASHBOARD