Every year the professor selects the top two students from his class and takes them on a fun filled field trip, this year Ali and Zafar were selected.
The professor took them to a place where there was a never-ending queue of solid metal cubes. The professor could see $n$ cubes at a time. On the day before, he had painted the first $n$ cubes from the left with various colours.
Ali was allowed to choose any painted cube to initially stand on (say $X$). Zafar was asked to stand on the last painted cube (the $n^{th}$ cube) with the professor.
The two students were given an activity each:
- Ali had to shout out the colour of the cube he is standing on.
- Zafar had to paint the adjacent cube on the right of him with that colour.
Both Ali and Zafar had to take one step to the right each time they performed their activity.
The Professor jumped along with Zafar, and never left his side. Throughout the activity he was looking leftwards keeping an eye on Ali. They were given a gold star and were allowed to go home when all the cubes that the professor could see at the time were painted with the same color.
Ali wanted to choose a position furthest from the professor and also wanted the gold star.
Can you help Ali to choose this position $X$?
The cubes are numbered from 1 starting from the first painted cube.
The colours are represented as integers.

-----Input:-----
- The first line contains one integer n, the number of cubes initially painted.
- The second line contains n space-separated integers: $a_1$, $a_2$, $\dots$, $a_n$, the colours the professor chose for the first $n$ cubes.

-----Output:-----
Print a single line containing one integer $X$, the position Ali should initially stand on.

-----Constraints-----
- $1 \leq n \leq 10^{6}$
- $0 \leq a_i \leq 999$

-----Sample Input 1:-----
4

3 3 8 8   

-----Sample Output 1:-----
3

-----Sample Input 2:-----
4

2 8 7 3

-----Sample Output 2:-----
4

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
n = int(input())
arr = [int(x) for x in input().split()]
ans = n - 1
while ans > 0 and arr[ans] == arr[ans - 1]:
	ans -= 1
print(ans + 1)


def checklist(a):
	return len(set(a)) == 1
n = int(input())
a = list(map(int, input().split()))
x = 0
if checklist(a) == True:
	x = 1
	print(1)
elif x == 0:
	while a[n - 1] == a[n - 2]:
		n -= 1
	print(n)


try:
	n = int(input())
	c = 0
	l = list(map(int, input().split()))
	for i in range(n - 1, 0, -1):
		if l[i] != l[i - 1]:
			print(i + 1)
			c = 1
			break
	if c == 0:
		print(1)
except EOFError:
	pass


import sys
import math
from collections import defaultdict, Counter
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n - 2, -1, -1):
	if a[i] != a[i + 1]:
		ans = i + 2
		break
print(ans)


t = 1
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 1
	for i in range(n - 2, -1, -1):
		if a[i] != a[i + 1]:
			s = i + 2
			break
	print(s)


n = int(input())
lst = list(map(int, input().split()))
for i in range(len(lst) - 1, 0, -1):
	if lst[i] != lst[i - 1]:
		pos = i + 1
		break
	if i == 1:
		pos = 1
print(pos)


n = int(input())
arr = list(map(int, input().split()))
tar = arr[n - 1]
j = n - 2
flag = 0
while j > 0:
	if arr[j] == tar:
		tar = arr[j]
		j = j - 1
		continue
	else:
		flag = j + 1
		break
print(str(flag + 1))


n = int(input())
arr = list(map(int, input().split()))
lst = arr[-1]
count = 0
for i in range(len(arr) - 1, -1, -1):
	if arr[i] == lst:
		count = count + 1
	else:
		break
print(len(arr) - count + 1)


n = int(input())
a = list(map(int, input().split()))
if a[-1] == a[-2]:
	k = n - 1
	while a[k - 1] == a[k] and k >= 1:
		k -= 1
	print(k + 1)
else:
	print(n)


n = int(input())
lis = []
lis = input().split(' ')
pos = n
for i in range(n - 1):
	if lis[n - 1] == lis[n - i - 2]:
		pos = n - i - 1
	else:
		break
print(pos)


n = int(input())
arr = list(map(int, input().split()))
for i in range(n - 1, 0, -1):
	if arr[i] == arr[i - 1]:
		pass
	else:
		print(i + 1)
		break
else:
	print(1)


n = int(input())
a = [int(x) for x in input().split()]
ans = n - 1
x = a[-1]
while ans - 1 >= 0:
	if a[ans - 1] == x:
		x = a[ans - 1]
		ans -= 1
	else:
		break
print(ans + 1)


n = int(input())
a = list(map(int, input().split()))
i = n - 1
while i + 1:
	if a[i] != a[-1]:
		break
	i -= 1
print(i + 2)


n = int(input())
li = list(map(int, input().split()))
prev = None
for (ind, z) in enumerate(reversed(li)):
	if prev is not None:
		if z != prev[1]:
			break
		prev[0] = ind
	else:
		prev = [ind, z]
print(n - prev[0])


n = int(input())
cubes = list(map(int, input().split()))
col = cubes[n - 1]
pos = n - 1
i = n - 1
while i > -1:
	if col == cubes[i]:
		col = cubes[i]
	else:
		print(i + 2)
		break
	i -= 1
else:
	print(1)


n = int(input())
arr = list(map(int, input().split()))
const = arr[n - 1]
ans = n
for i in range(n - 2, 0, -1):
	if arr[i] != const:
		ans = i + 2
		break
	else:
		ans = i
print(ans)