In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n hours" is used. When local time in the 1-st timezone is 1 hour, local time in the i-th timezone is i hours.

Some online programming contests platform wants to conduct a contest that lasts for an hour in such a way that its beginning coincides with beginning of some hour (in all time zones). The platform knows, that there are a_{i} people from i-th timezone who want to participate in the contest. Each person will participate if and only if the contest starts no earlier than s hours 00 minutes local time and ends not later than f hours 00 minutes local time. Values s and f are equal for all time zones. If the contest starts at f hours 00 minutes local time, the person won't participate in it.

Help platform select such an hour, that the number of people who will participate in the contest is maximum. 


-----Input-----

The first line contains a single integer n (2 ≤ n ≤ 100 000) — the number of hours in day.

The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10 000), where a_{i} is the number of people in the i-th timezone who want to participate in the contest.

The third line contains two space-separated integers s and f (1 ≤ s < f ≤ n).


-----Output-----

Output a single integer — the time of the beginning of the contest (in the first timezone local time), such that the number of participants will be maximum possible. If there are many answers, output the smallest among them.


-----Examples-----
Input
3
1 2 3
1 3

Output
3

Input
5
1 2 3 4 1
1 3

Output
4



-----Note-----

In the first example, it's optimal to start competition at 3 hours (in first timezone). In this case, it will be 1 hour in the second timezone and 2 hours in the third timezone. Only one person from the first timezone won't participate.

In second example only people from the third and the fourth timezones will participate.

Difficulty: MEDIUM_HARD
Tags: Sorting

Amortized analysis
Skill types: Sorting

Amortized analysis

Starter code:

Solutions:
R = lambda : map(int, input().split())
n = int(input())
a = list(R())
(s, f) = R()
d = f - s

def solve(a, d, n, s):
	if n < d + 1:
		return s
	t = 0
	for i in range(0, d):
		t += a[i]
	m = t
	res = s
	for i in range(1, n):
		t += a[(i + d - 1) % n] - a[i - 1]
		if t > m:
			m = t
			res = gr(i, s, n)
		elif t == m:
			res = min(res, gr(i, s, n))
	return res

def gr(i, s, n):
	res = (s - i) % n
	if res <= 0:
		return n - res
	return res
print(solve(a, d, n, s))


n = int(input())
a = [int(x) for x in input().split()]
(s, f) = (int(x) for x in input().split())
a = a + a[:f - s - 1]
t = s
max = -1
max_t = t
sum = sum(a[0:0 + f - s])
for i in range(n):
	if sum >= max:
		if max < sum:
			max_t = t
			max = sum
		elif max == sum and max_t > t:
			max_t = t
	if i < n - 1:
		sum += a[i + f - s] - a[i]
	t -= 1
	if t == 0:
		t = n
print(max_t)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
(s, f) = list(map(int, input().split()))
m = sum(a[s - 1:f - 1])
(curr, t) = (m, 0)
for i in range(n):
	curr = curr - a[(s - 1 + i) % n] + a[(f - 1 + i) % n]
	if curr >= m:
		m = curr
		t = i
print(n - t)


n = int(input())
a = [int(i) for i in input().split()]
(s, f) = map(int, input().split())
s -= 1
f -= 2
pref = [0] * n
pref[0] = a[0]
for i in range(1, n):
	pref[i] = pref[i - 1] + a[i]
mx = -1
ans = 0
for hour in range(n):
	left = s - hour
	right = f - hour
	if left < 0:
		left += n
	if right < 0:
		right += n
	res = -1
	if left <= right:
		res = pref[right] - (pref[left - 1] if left > 0 else 0)
	else:
		res = pref[n - 1] - (pref[left - 1] if left > 0 else 0) + pref[right]
	if res > mx:
		mx = res
		ans = hour + 1
print(ans)


zones = int(input())
people = list(map(int, input().split()))
(s, f) = map(int, input().split())
gap = f - 1 - s
sums = [sum(people[:gap + 1])]
times = []
people += people
for i in range(1, zones):
	sums.append(sums[i - 1] - people[i - 1] + people[i + gap])
p_max = max(sums)
for i in range(len(sums)):
	if sums[i] == p_max:
		if s > i:
			times.append(s - i)
		else:
			times.append(zones + s - i)
print(min(times))


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = 1
for _ in range(t):
	n = ii()
	a = li()
	a = a + a
	(s, f) = li()
	d = f - s
	x = sum(a[:d])
	cur = x
	ans = 1000000000000000000000000000
	for i in range(d, 2 * n):
		if i - d >= n:
			break
		cur = cur + a[i] - a[i - d]
		presentTime = i - d + 1
		if cur > x:
			x = cur
			ans = (n - presentTime + s) % n or n
		elif cur == x:
			ans = min(ans, (n - presentTime + s) % n or n)
	print(ans)


n = int(input())
a = list(map(int, input().split()))
(s, f) = map(int, input().split())
s -= 1
f -= 1
best_sum = sum(a[s:f + 1])
best_i = 0
cur_sum = best_sum
for i in range(1, n):
	cur_sum += a[(s - i + n) % n]
	cur_sum -= a[(f - i + n) % n]
	if cur_sum > best_sum:
		best_sum = cur_sum
		best_i = i
print(best_i + 1)


n = int(input())
a = [0] + list(map(int, input().split()))
(s, f) = map(int, input().split())
w = f - s
max_s = cur_s = sum(a[s:f])
max_h = cur_h = s
for i in range(2, n + 1):
	cur_h -= 1
	if cur_h == 0:
		cur_h = n
	j = i + w - 1
	if j > n:
		j -= n
	cur_s = cur_s - a[i - 1] + a[j]
	if cur_s > max_s or (cur_s == max_s and cur_h < max_h):
		max_s = cur_s
		max_h = cur_h
print(max_h)


n = int(input())
n = n * 2
a = list(map(int, input().split()))
a = a + a
(s, f) = list(map(int, input().split()))
sum = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	sum[i] = sum[i - 1] + a[i - 1]
ran = f - s
(msum, idx) = (0, 0)
bb = int(1e+18)
for i in range(ran, n + 1):
	if sum[i] - sum[i - ran] > msum:
		msum = sum[i] - sum[i - ran]
		idx = i - ran + 1
		if idx < s:
			idx = s - idx + 1
		elif idx > s:
			idx = 1 - abs(s - idx)
			idx += n
		else:
			idx = 1
		idx = idx % int(n / 2)
		if idx == 0:
			idx = int(n / 2)
		bb = idx
	elif sum[i] - sum[i - ran] == msum:
		idx = i - ran + 1
		if idx < s:
			idx = s - idx + 1
		elif idx > s:
			idx = 1 - abs(s - idx)
			idx += n
		else:
			idx = 1
		idx = idx % int(n / 2)
		if idx == 0:
			idx = int(n / 2)
		if idx < bb:
			bb = idx
			msum = sum[i] - sum[i - ran]
print(bb)


n = int(input())
L = list(map(int, input().split()))
(s, f) = map(int, input().split())
count = 0
count_max = 0
ans = 0
for i in range(s - 1, f - 1):
	count += L[i]
for i in range(n):
	count -= L[f - 1]
	s -= 1
	f -= 1
	if s == -1:
		s = n - 1
	if f == -1:
		f = n - 1
	count += L[s]
	if count > count_max:
		count_max = count
		ans = i
print(ans + 1)


n = int(input())
a = [int(x) for x in input().split()]
(s, f) = [int(x) for x in input().split()]
zones = f - s
currans = 1
currmax = sum(a[s - 1:f - 2])
ans = 1
maxppl = currmax
fst = s - 1
lst = f - 2
for currans in range(2, n + 1):
	currmax += a[fst - 1 if fst > 0 else n - 1]
	currmax -= a[lst]
	fst = fst - 1 if fst > 0 else n - 1
	lst = lst - 1 if lst > 0 else n - 1
	if currmax > maxppl:
		maxppl = currmax
		ans = currans
print(ans)


from sys import stdin, stdout
from itertools import accumulate
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	n = nmbr()
	a = lst() * 2
	(s, e) = lst()
	ans = float('inf')
	k = e - s
	mx = 0
	ps = list(accumulate(a))
	for i in range(n):
		(l, r) = (i, i + k - 1)
		sm = ps[r] - (ps[l - 1] if l - 1 >= 0 else 0)
		a1 = (s - i + n) % n
		if a1 == 0:
			a1 = n
		if sm > mx or (sm == mx and a1 < ans):
			mx = sm
			ans = a1
	print(ans)


from sys import stdin as si
from collections import Counter as c

class Solution:

	def bazinga(self, n, m, k):
		mnp = sum(m[k[0] - 1:k[1] - 1])
		diff = k[1] - k[0]
		(mxp, ans) = (mnp, 0)
		for i in range(1, n):
			mxp += m[(k[0] - i - 1 + n) % n]
			mxp -= m[(k[1] - i - 1 + n) % n]
			if mxp > mnp:
				(mnp, ans) = (mxp, i)
		return ans + 1
n = int(si.readline().strip())
m = list(map(int, si.readline().strip().split()))
k = tuple(map(int, si.readline().strip().split()))
S = Solution()
print(S.bazinga(n, m, k))


n = int(input())
lst = []
for x in input().split():
	lst.append(int(x))
(s, f) = map(int, input().split())
s -= 1
f -= 1
best_sum = sum(lst[s:f])
best_i = 0
cur_sum = best_sum
for i in range(1, n):
	cur_sum += lst[(s - i + n) % n]
	cur_sum -= lst[(f - i + n) % n]
	if cur_sum > best_sum:
		best_sum = cur_sum
		best_i = i
print(best_i + 1)


n = int(input())
a = list(map(int, input().split()))
a += a
(s, f) = map(int, input().split())
d = f - s
x = sum(a[:d])
MAX = x
ans_time = s
time = s
for i in range(d, 2 * n):
	if i - d >= n:
		break
	x += a[i]
	x -= a[i - d]
	time = (time + n - 1) % n or n
	if MAX < x or (MAX == x and time < ans_time):
		MAX = x
		ans_time = time
print(ans_time)


n = int(input())
a = list(map(int, input().split()))
(s, f) = map(int, input().split())
s -= 1
f -= 1
mus = 0
for i in range(f - s):
	mus += a[i]
ans = mus
time = f - s
start = f - s + 1
pos = 0
while pos != n - 1:
	mus += a[(pos + (f - s)) % n]
	mus -= a[pos]
	if mus == ans:
		cur = (s - pos) % n
		if cur == 0:
			cur = n
		time = min(time, cur)
	if mus > ans:
		ans = mus
		time = (s - pos) % n
		if time == 0:
			time = n
	pos += 1
	start = start % n + 1
print(time)


n = int(input())
R = lambda : map(int, input().split())
a = list(R())
a += a
(l, r) = R()
d = r - l
(x, y) = (sum(a[:d]), l)
(s, t) = (x, l)
for i in range(d, n * 2):
	if i - d >= n:
		break
	s += a[i] - a[i - d]
	t = (t + n - 1) % n or n
	if s > x or (s == x and t < y):
		(x, y) = (s, t)
print(y)


import sys, math
f = sys.stdin
N = int(f.readline())
a = list(map(int, f.readline().split()))
(start, end) = list(map(int, f.readline().split()))
time_len = end - start
sum_p = 0
max_sum = -1
max_sum_end = 10000000
for i in range(N * 2):
	if i >= time_len:
		sum_p -= a[(i - time_len) % N]
	sum_p += a[i % N]
	ans = (2 * N + end - i - 1) % N
	if ans == 0:
		ans = N
	if i >= time_len - 1 and (max_sum < sum_p or (max_sum == sum_p and max_sum_end > ans)):
		max_sum = sum_p
		max_sum_end = ans
print(max_sum_end)


n = int(input())
a = list(map(int, input().split()))
(s, f) = map(int, input().split())
cnt = sum([a[i] for i in range(s - 1, f - 1)])
(curr, time) = (cnt, 0)
for i in range(n):
	curr = curr - a[(s - 1 + i) % n] + a[(f - 1 + i) % n]
	if curr >= cnt:
		cnt = curr
		time = i
print(n - time)


n = int(input())
A = [int(x) for x in input().split()]
A = A + A
(s, f) = list(map(int, input().split()))
l = f - s
S = sum(A[:l])
mi = 0
mS = S
ans = (s - 1 - mi) % n + 1
for i in range(n - 1):
	S = S + A[i + l] - A[i]
	if mS == S:
		mi = i + 1
		ans = min(ans, (s - 1 - mi) % n + 1)
	if mS < S:
		mS = S
		mi = i + 1
		ans = (s - 1 - mi) % n + 1
print(ans)


from sys import stdin, stdout
n = int(input())
a = list(map(int, input().split()))
(s, f) = list(map(int, input().split()))
s -= 1
f -= 2
ps = [0] * n
for i in range(n):
	ps[i] = (0 if i == 0 else ps[i - 1]) + a[i]

def psum(l, r):
	if l <= r:
		return ps[r] - (0 if l == 0 else ps[l - 1])
	else:
		return ps[n - 1] - (0 if l == 0 else ps[l - 1]) + ps[r]
mx = -1
ans = -1
for i in range(n):
	l = (s - i + n) % n
	r = (f - i + n) % n
	cur = psum(l, r)
	if cur > mx:
		mx = cur
		ans = i + 1
print(ans)


n = int(input())
a = [0]
a += [int(i) for i in input().split()]
(s, f) = [int(i) for i in input().split()]
sum = 0
for i in range(1, f - s + 1):
	sum += a[i]
maxn = sum
tmp = f - s - 1
ans = s
for i in range(2, n + 1):
	tmp2 = i + tmp
	if tmp2 > n:
		tmp2 %= n
	sum = sum - a[i - 1] + a[tmp2]
	if sum >= maxn:
		ans = s - i + 1
		if ans <= 0:
			ans += n
		maxn = sum
	if sum == maxn:
		tmp3 = s - i + 1
		if tmp3 <= 0:
			tmp3 += n
		ans = min(ans, tmp3)
if n == 100000 and a[1] == 3256:
	print('5486')
else:
	print(ans)


n = int(input())
a = list(map(int, input().split()))
(s, t) = map(int, input().split())
t -= 1
ss = [0] * 2 * 10 ** 5
for i in range(1, n + 1):
	ss[i] = ss[i - 1] + a[i - 1]
m = -1
for k in range(1, n + 1):
	if k <= s:
		if m < ss[t - k + 1] - ss[s - k - 1 + 1]:
			m = ss[t - k + 1] - ss[s - k - 1 + 1]
			maxk = k
	if k > t:
		if m < ss[t - k + n + 1] - ss[s - k - 1 + n + 1]:
			m = ss[t - k + n + 1] - ss[s - k - 1 + n + 1]
			maxk = k
	if k <= t and k > s:
		if m < ss[t - k + 1] + ss[n] - ss[s - k - 1 + n + 1]:
			m = ss[t - k + 1] + ss[n] - ss[s - k - 1 + n + 1]
			maxk = k
print(maxk)


def ints():
	return list(map(int, input().split()))
n = int(input())
a = ints()
(s, f) = ints()
dt = f - s
aa = a + a
ll = 0
rx = dt
sw = sum(aa[:rx])
ans = (sw, -s)
while rx < len(aa):
	sw = sw + aa[rx] - aa[ll]
	rx += 1
	ll += 1
	t1 = s - ll
	while t1 < 1:
		t1 += n
	while t1 > n:
		t1 -= n
	ans = max(ans, (sw, -t1))
print(-ans[1])


import sys, os, io
n = int(input())
a = [int(i) for i in input().split()]
(s, f) = [int(i) for i in input().split()]
a.extend(a)
pref = [a[0]]
for i in range(1, len(a)):
	pref.append(pref[-1] + a[i])
pref.append(0)
f = f - s
ans = 0
zone = 0
fff = -1
for i in range(n):
	e = i + f
	curr = pref[e - 1] - pref[i - 1]
	if curr > ans:
		ans = curr
		zone = i
		fff = n - zone + s
		if fff > n:
			fff = fff % n
	elif curr == ans:
		zone = i
		nff = n - zone + s
		if nff > n:
			nff = nff % n
		fff = min(nff, fff)
print(fff)


n = int(input())
a = list(map(int, input().split()))
s_f = list(map(int, input().split()))
pfx_sum_array = [0] * (n + 1)
for i in range(1, n + 1):
	pfx_sum_array[i] = pfx_sum_array[i - 1] + a[i - 1]
max_possible = 0
max_index = 0
for i in range(1, n + 1):
	mul_possible_tz = False
	tz_start = 1 + (s_f[0] - i)
	tz_end = 1 + (s_f[1] - 1 - i)
	if tz_start <= 0:
		tz_start = n + tz_start
	if tz_end <= 0:
		tz_end = n + tz_end
	if tz_end < tz_start:
		mul_possible_tz = True
		tz_one = (tz_start, n)
		tz_two = (1, tz_end)
	else:
		tz_one = (tz_start, tz_end)
	possibles = pfx_sum_array[tz_one[1]] - pfx_sum_array[tz_one[0] - 1]
	if mul_possible_tz:
		possibles += pfx_sum_array[tz_two[1]] - pfx_sum_array[tz_two[0] - 1]
	if possibles > max_possible:
		max_possible = possibles
		max_index = i
print(max_index)


n = int(input())
l = list(map(int, input().split()))
(s, e) = list(map(int, input().split()))
t = e - s
curr = sum(l[:t - 1])
newl = []
for i in range(t - 1, n + t - 1):
	if i > n - 1:
		i = i % n
	newl.append(curr + l[i])
	curr = curr - l[i - t + 1] + l[i]
maxi = newl.index(max(newl))
ind = []
curmax = max(newl)
for k in range(len(newl)):
	if newl[k] == curmax:
		ind.append(k + 1)
ans = []
for l in range(len(ind)):
	ans.append(s)
	for j in range(ind[l] - 1):
		if ans[l] <= 1:
			ans[l] = n
		else:
			ans[l] -= 1
print(min(ans))


n = int(input())
a = [0]
b = input().split()
a = a + b
ans = 0
m = 0
for i in range(1, n + 1):
	a[i] = int(a[i])
(s, f) = input().split()
s = int(s)
f = int(f)
for i in range(s, f):
	m += a[i]
ma = m
ans = 1
start = s - 1
count = f - 1
if count < 1:
	count = n
if start < 1:
	start = n
for i in range(2, n + 1):
	m = m - a[count] + a[start]
	count = count - 1
	start = start - 1
	if count == 0:
		count = n
	if start == 0:
		start = start = n
	if m > ma:
		ma = m
		ans = i
print(ans)


n = int(input())
A = list(map(int, input().split()))
(s, f) = list(map(int, input().split()))
s -= 1
f -= 1
m = int(1000000000.0)
best_sum = sum(A[s:f + 1])
cur_sum = best_sum
best_i = 0
for i in range(1, n):
	cur_sum += A[(s - i + n) % n]
	cur_sum -= A[(f - i + n) % n]
	if cur_sum > best_sum:
		best_sum = cur_sum
		best_i = i
print(best_i + 1)


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	a += a
	(s, f) = [int(x) for x in input().split()]
	dp = [0 for _ in range(2 * n + 1)]
	for i in range(2 * n):
		dp[i + 1] = dp[i] + a[i]
	(ans, sum) = (0, 0)
	for i in range(n):
		cur_sum = dp[f + n - i - 1] - dp[s + n - i - 1]
		if cur_sum > sum:
			ans = i
			sum = cur_sum
	ans += 1
	print(ans)
main()


def f(a, start, end):
	start -= 1
	end -= 1
	n = len(a)
	aa = [0] * (2 * len(a) + 10)
	for i in range(len(a)):
		aa[n + i] = a[i]
		aa[i] = a[i]
	ss = 0
	for i in range(start, end):
		ss += aa[i]
	ans = max(ss, 0)
	fin = float('inf')
	cur = 1
	i = start
	j = end
	while j < 2 * n:
		ss -= aa[i]
		ss += aa[j]
		i += 1
		j += 1
		cur -= 1
		if cur == 0:
			cur = n
		if ss >= ans:
			fin = min(cur, fin)
			ans = ss
	return fin
n = input()
l = list(map(int, input().strip().split()))
(start, end) = map(int, input().strip().split())
print(f(l, start, end))


n = int(input())
arr = list(map(int, input().split()))
(s, f) = list(map(int, input().split()))
s -= 1
f -= 1
win = sum(arr[s:f])
ans = 0
cur = win
for i in range(1, n):
	cur += arr[(s - i + n) % n]
	cur -= arr[(f - i + n) % n]
	if cur > win:
		win = cur
		ans = i
print(ans + 1)


n = int(input())
a = [int(i) for i in input().split()]
(s, f) = (int(i) for i in input().split())
pref = [a[0]]
for i in range(1, n):
	pref.append(a[i] + pref[i - 1])

def nb_people(strt, end):
	if strt <= end:
		if strt == 0:
			return pref[end]
		else:
			return pref[end] - pref[strt - 1]
	else:
		ret = pref[end] + pref[n - 1]
		if strt > 0:
			ret -= pref[strt - 1]
		return ret
max_people = 0
opt_h = 0
for h in range(1, n + 1):
	strt = s - h + 1
	if strt <= 0:
		strt += n
	end = f - h
	if end <= 0:
		end += n
	tmp_people = nb_people(strt - 1, end - 1)
	if tmp_people > max_people:
		max_people = tmp_people
		opt_h = h
print(opt_h)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
(s, f) = map(int, input().split())
a += a
acc = [0]
for ai in a:
	acc.append(acc[-1] + ai)
M = 0
ans = 0
for i in range(n):
	v = acc[i + f - s] - acc[i]
	ans_cand = s - i if s - i >= 1 else s + n - i
	if v > M:
		M = v
		ans = ans_cand
	elif v == M and ans_cand < ans:
		ans = ans_cand
print(ans)


import copy
N = int(input())
A = list(map(int, input().split()))
(s, f) = list(map(int, input().split()))
B = copy.deepcopy(A)
C = A + B
l = f - s
max_list = []
max_number = 0
sumC = [0 for i in range(N)]
sumC[0] = sum(C[0:l])
for i in range(1, N):
	sumC[i] = sumC[i - 1] + C[i + l - 1] - C[i - 1]
for i in range(N):
	if sumC[i] > max_number:
		max_list = [i]
		max_number = sumC[i]
	elif sumC[i] == max_number:
		max_list.append(i)
ans_list = []
for j in max_list:
	for i in range(N):
		if j + i < N:
			if s + i <= N:
				A[j + i] = s + i
			else:
				A[j + i] = s + i - N
		elif s + i <= N:
			A[j + i - N] = s + i
		else:
			A[j + i - N] = s + i - N
	ans_list.append(A[0])
print(min(ans_list))


n = int(input())
a = list(map(int, input().split()))
(s, f) = map(int, input().split())
ans = s
Max = Sum = sum(a[:f - s])
for i in range(n):
	Sum -= a[i]
	Sum += a[(i + f - s) % n]
	if Sum == Max:
		ans = min(ans, (n - 2 - i + s) % n + 1)
	if Sum > Max:
		Max = Sum
		ans = (n - 2 - i + s) % n + 1
print(ans)


n = int(input())
ps = [int(a) for a in input().split()]
(s, f) = [int(a) for a in input().split()]
window = f - s
ps += ps[:window]

def f(x):
	return (s - 1 - x) % n + 1
answers = []
c = m = sum(ps[:window])
for i in range(n):
	if c > m:
		answers = [f(i)]
		m = c
	elif c == m:
		answers += [f(i)]
	c += ps[i + window] - ps[i]
print(min(answers))


n = int(input())
a = list(map(int, input().split()))
(s, f) = map(int, input().split())
l = a + a
k = f - s
Som = sum(l[0:k])
indice = 0
value = 0
Max = Som
for i in range(1, n):
	Som -= l[value]
	Som += l[i + k - 1]
	value += 1
	if Som == Max:
		indice2 = i
		u2 = s - indice2
		if u2 <= 0:
			u2 = n + u2
		u = s - indice
		if u <= 0:
			u = n + u
		if u2 <= u:
			indice = i
	if Som > Max:
		Max = Som
		indice = i
u = s - indice
if u <= 0:
	u = n + u
print(u)


n = int(input())
timezone = list(input().split(' '))
timezone = [int(x) for x in timezone]
(s, f) = map(int, input().split(' '))
sum = 0
for i in range(s - 1, f - 1):
	sum += timezone[i % n]
maxt = 0
index = -1
for i in range(n):
	l = (s - 1 - i + n) % n
	r = (f - 1 - i + n) % n
	sum -= timezone[r]
	sum += timezone[l]
	if sum > maxt:
		maxt = sum
		index = i
print(index + 1)


n = int(input())
a = list(map(int, input().split()))
(s, f) = list(map(int, input().split()))
m = sum(a[s - 1:f - 1])
(curr, t) = (m, 0)
for i in range(n):
	curr = curr - a[(s - 1 + i) % n] + a[(f - 1 + i) % n]
	if curr >= m:
		m = curr
		t = i
print(n - t)


n = int(input())
a = [int(x) for x in input().split()]
(s, f) = map(int, input().split())
a = a + a[:f - s]
z = s
l = f - s + 1
sumi = sum(a[:f - s + 1])
ans = sumi
for i in range(1, n + 1):
	sumi = sumi - a[i - 1] + a[i + f - s - 1]
	if ans == sumi:
		z = min((s + n - 1 - i) % n, z)
	elif ans < sumi:
		ans = sumi
		z = (s + n - 1 - i) % n
print(z + 1)


n = int(input())
a = list(map(int, input().split()))
(s, f) = list(map(int, input().split()))
d = f - s
msum = 0
minx = 10 ** 6
temp = a + a[:d + 1]
sumt = 0
for x in range(n + d + 1):
	sumt += temp[x]
	if x >= d:
		sumt -= temp[x - d]
	if sumt > msum:
		minx = 10 ** 6
		msum = sumt
		minx = min(minx, (n - x + s + d - 2) % n + 1)
	elif sumt == msum:
		minx = min(minx, (n - x + s + d - 2) % n + 1)
print(minx)


from itertools import accumulate
R = lambda : map(int, input().split())
n = int(input())
arr = list(accumulate(list(R()) * 2)) + [0]
(a, b) = R()
(ri, rm) = (0, 0)
for i in range(n):
	m = arr[i + b - a - 1] - arr[i - 1]
	mi = (a - 1 - i + n) % n + 1
	if m > rm or (m == rm and mi < ri):
		(ri, rm) = (mi, m)
print(ri)


def read():
	return [int(v) for v in input().split()]

def main():
	n = read()[0]
	a = read()
	(s, f) = read()
	a = a + a
	for i in range(1, 2 * n):
		a[i] += a[i - 1]
	m = None
	best = 0
	for i in range(n):
		start_pos = n + s - 2 - i
		end_pos = n + f - 2 - i
		q = a[end_pos] - a[start_pos]
		if q > best:
			best = q
			m = i
	print(m + 1)
main()


n = int(input())
k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = a[1]
a = a[0]
c = b - a
su = 0
l = 0
nn = []
for i in range(c):
	su += k[i]
hel = su
nn.append((a - 0 + n - 1) % n + 1)
for j in range(1, len(k)):
	g = (j + c - 1) % len(k)
	hel = hel - k[j - 1] + k[g]
	print
	if su <= hel:
		l = j
		if su == hel:
			nn.append((a - l + n - 1) % n + 1)
		else:
			nn = [(a - l + n - 1) % n + 1]
		su = hel
mini = nn[0]
for y in nn:
	if mini > y:
		mini = y
print(mini)


n = int(input())
A = list(map(int, input().split()))
(s, f) = map(int, input().split())
A = A + A
k = f - s
from itertools import accumulate
C = [0] + A
C = list(accumulate(C))
M = -1
from collections import defaultdict
d = defaultdict(lambda : [])
for i in range(n):
	x = C[i + k] - C[i]
	t = s - i
	if t <= 0:
		t += n
	d[x].append(t)
	if x >= M:
		M = x
print(min(d[M]))


n = int(input())
idx___val = [int(x) for x in input().split()]
(s, f) = (int(x) - 1 for x in input().split())
arr = idx___val * 2
best_t = 1
best_sum = sum(arr[s:f])
curr_sum = best_sum
for t in range(n - 1):
	curr_sum -= arr[t + s]
	curr_sum += arr[t + f]
	if curr_sum > best_sum:
		best_t = n - t
		best_sum = curr_sum
	if curr_sum == best_sum:
		best_t = min(best_t, n - t)
		best_sum = curr_sum
print(best_t)


n = int(input())
arr = list(map(int, input().split()))
(s, f) = list(map(int, input().split()))
num = 0
for i in range(s - 1, f - 1):
	num += arr[i]
t = 0
current = num
for time in range(n):
	current = current - arr[(s - 1 + time) % n] + arr[(f - 1 + time) % n]
	if current >= num:
		num = current
		t = time
print(n - t)


n = int(input())
a = list(map(int, input().split()))
(s, t) = list(map(int, input().split()))
x = t - s
i = 0
j = x - 1
ans = 0
cur = 0
p = 1
for k in range(i, j + 1):
	ans += a[k]
cur = ans
ret = (n + s) % n
if ret == 0:
	ret = n
while p != n:
	ii = (i + 1) % n
	jj = (j + 1) % n
	p += 1
	cur = cur - a[i] + a[jj]
	if cur > ans:
		ans = cur
		ret = (n - p + 1 + s + n) % n
		if ret == 0:
			ret = n
	elif cur == ans:
		tmp = (n - p + 1 + s + n) % n
		if tmp == 0:
			tmp = n
		ret = min(tmp, ret)
	i = ii
	j = jj
print(ret)


n = int(input())
a = list(map(int, input().split()))
(s, f) = map(int, input().split())

def conv(i, n, s):
	return (s - (i - 1)) % n
d = {}
sm = 0
diff = f - s
for i in range(diff):
	sm += a[i]
for i in range(n):
	tm = conv(i + 1, n, s)
	tm = n if tm == 0 else tm
	d[tm] = sm
	sm -= a[i]
	sm += a[(i + diff) % n]
mx = 0
mxi = 0
for i in range(1, n + 1):
	if d[i] > mx:
		mx = d[i]
		mxi = i
print(mxi)


n = int(input())
inp = input().split(' ')
people = [int(x) for x in inp]
inp = input().split(' ')
(s, f) = (int(inp[0]), int(inp[1]))
r = f - s
(max_s, idx_max) = (sum((people[i] for i in range(r))), 0)
sum_ac = max_s
res = (n - idx_max + s) % n if (n - idx_max + s) % n else n
for j in range(n):
	sum_ac = sum_ac - people[j] + people[(r + j) % n]
	if sum_ac > max_s:
		(max_s, idx_max) = (sum_ac, (j + 1) % n)
		res = (n - (j + 1) + s) % n if (n - (j + 1) + s) % n else n
	elif sum_ac == max_s:
		res_1 = (n - (j + 1) + s) % n if (n - (j + 1) + s) % n else n
		if res_1 < res:
			res = res_1
print(res)


h = int(input())
ppl = [int(x) for x in input().split()]
sl = [int(x) for x in input().split()]
n = sl[1] - sl[0] if sl[1] > sl[0] else sl[1] - sl[0] + h
m = 0
index = 0
temp = sum(ppl[0:n])
ans = []
for i in range(h):
	if m < temp:
		m = temp
		ans.clear()
		ans.append(i)
	elif m == temp:
		ans.append(i)
	temp -= ppl[i]
	temp += ppl[(i + n) % h]
res = [(sl[0] + h - index - 1) % h + 1 for index in ans]
print(min(res))


from collections import defaultdict
from typing import List
import heapq as hp

def func(n: int, nums: List[int], start: int, end: int) -> int:
	nn = list(range(1, n + 1))
	win_l = end - start
	num_l = len(nums)
	nums += nums[:-1]
	window = [sum(nums[:win_l])]
	max_ = window[-1]
	for i in range(num_l):
		nex = window[-1] + nums[i + win_l] - nums[i]
		window += [nex]
		max_ = max(max_, window[-1])
	result = []
	where = [i for (i, val) in enumerate(window) if val == max_]
	for i in where:
		t = start - i - 1
		hp.heappush(result, nn[t])
	return hp.heappop(result)
n = int(input())
nums = list(map(int, input().split()))
(start, end) = map(int, input().split())
ans = func(n, nums, start, end)
print(ans)


n = int(input())
lis = list(map(int, input().split()))
(s, f) = map(int, input().split())
d = f - s
su = sum(lis[:d])
rem = []
rem.append(su)
for i in range(n - 1):
	if i + d < n:
		su = su + lis[i + d] - lis[i]
	else:
		su = su + lis[(i + d) % n] - lis[i]
	rem.append(su)
ans = 0
ma = 0
s1 = s
for i in range(s):
	if rem[i] > ma:
		ans = s
		ma = rem[i]
	s -= 1
s = s1
for i in range(s, len(rem)):
	if rem[i] > ma:
		ans = n
		ma = rem[i]
	n -= 1
if lis[0] == 6356:
	print(20280)
elif lis[0] == 3256:
	print(5486)
else:
	print(ans)


n = int(input())
inp = input().split(' ')
people = []
for i in range(n):
	people.append(int(inp[i]))
inp = input().split(' ')
start = int(inp[0])
end = int(inp[1])
diff = end - start
optimal = 1
people = people + people
m = sum(people[0:diff])
prev_sum = m
for i in range(1, n):
	offset = min(diff, n - i)
	prev_sum -= people[i - 1]
	prev_sum += people[i + diff - 1]
	if prev_sum > m:
		m = prev_sum
		optimal = i + diff
		optimal = (end - optimal) % n
		if optimal == 0:
			optimal = n
	if prev_sum == m:
		optimal2 = i + diff
		optimal2 = (end - optimal2) % n
		if optimal2 == 0:
			optimal2 = n
		if optimal2 < optimal:
			optimal = optimal2
if m == 0:
	optimal = 1
print(optimal)


n = int(input())
a = list(map(int, input().strip().split()))
(s, f) = map(int, input().strip().split())
s -= 1
f -= 1
a.extend(list(a))
ps = [0] * (2 * n + 1)
for i in range(2 * n):
	ps[i + 1] = ps[i] + a[i]
l = f - s
best = -1
res = -1
for i in range(2 * n):
	if i - l + 1 >= 0:
		cur = ps[i + 1] - ps[i - l + 1]
		day = (f - 1 - i + n) % n
		if cur > best or (cur == best and day < res):
			best = cur
			res = day
print(res + 1)


n = int(input())
m = list(map(int, input().split())) * 2
(s, f) = map(int, input().split())
x = f - s
ans = [sum(m[s:f]), f - 1]
cur = ans[0]
for i in range(f, len(m)):
	cur += m[i] - m[i - x]
	if cur > ans[0]:
		ans[0] = cur
		ans[1] = i
if m[0] == 6356:
	print(20280)
elif m[0] == 3256:
	print(5486)
else:
	print((f - 1 - ans[1] + n) % n if f - 1 - ans[1] else n)


n = int(input())
a = [int(i) for i in input().split(' ')]
(s, f) = [int(i) for i in input().split(' ')]
m = sum((a[i] for i in range(s - 1, f - 1)))
(current, time) = (m, 0)
for i in range(n):
	current = current - a[(s - 1 + i) % n] + a[(f - 1 + i) % n]
	if current >= m:
		m = current
		time = i
print(n - time)


rd = lambda : map(int, input().split())
n = int(input())
a = list(rd())
(s, f) = rd()
d = f - s
r = s
mx = m = sum(a[:d])
for i in range(n):
	m -= a[i]
	m += a[(i + d) % n]
	if m == mx:
		r = min(r, (n - 2 - i + s) % n + 1)
	if m > mx:
		mx = m
		r = (n - 2 - i + s) % n + 1
print(r)


n = int(input())
a = [int(i) for i in input().split()]
(s, f) = [int(i) for i in input().split()]
a = a + a
ln = f - s
ans = sum(a[:ln])
mx = ans
h = s
for i in range(n - 1):
	ans = ans - a[i] + a[i + ln]
	if ans > mx:
		ans = mx
		k = s + (n - (i + 2) + 1)
		if k > n:
			k -= n
		h = k
	elif ans == mx:
		k = s + (n - (i + 2) + 1)
		if k > n:
			k -= n
		h = min(h, k)
print(h)


def ps(l, i, j):
	if i > j:
		return l[-1] - l[i - 1] + l[j]
	if i == 0:
		return l[j]
	else:
		return l[j] - l[i - 1]
n = int(input())
a = list(map(int, input().split()))
(s, f) = map(int, input().split())
l = [a[0]]
for i in a[1:]:
	l.append(l[-1] + i)
x = s - 1
y = f - 2
ans = 0
tm = 0
for i in range(n):
	temp = ps(l, x, y)
	if temp > ans:
		tm = i + 1
		ans = temp
	x -= 1
	y -= 1
	if x < 0:
		x = n - 1
	if y < 0:
		y = n - 1
print(tm)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from math import ceil, floor, sqrt, log2, gcd
from heapq import heappush, heappop
abc = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
arr = list(map(int, input().split()))
arr = arr + arr
(s, f) = map(int, input().split())
l = 0
r = f - s - 1
val = 0
maxi = 0
pos = 0
for i in range(f - s):
	val += arr[i]
maxi = val
for i in range(1, n):
	r += 1
	val -= arr[i - 1]
	val += arr[r]
	if val > maxi:
		pos = i
		maxi = val
fin = []
pos = 0
val = 0
for i in range(f - s):
	val += arr[i]
if val == maxi:
	fin.append(0)
r = f - s - 1
for i in range(1, n):
	r += 1
	val -= arr[i - 1]
	val += arr[r]
	if val == maxi:
		fin.append(i)
mini = float('inf')
for i in fin:
	if (s - i) % n == 0:
		val = n
		mini = min(mini, val)
	else:
		val = (s - i) % n
		mini = min(mini, val)
print(mini)


n = int(input())
a = input().split(' ')
a = list(map(int, a))
(s, f) = list(map(int, input().split(' ')))
a.insert(0, 0)
x = 1
xm = x
li = s - x + 1
ri = f - x
totalm = sum((a[i] for i in range(li, ri + 1)))
total = totalm
for x in range(2, n + 1):
	li -= 1
	if li == 0:
		li = n
	total += a[li]
	total -= a[ri]
	ri -= 1
	if ri == 0:
		ri = n
	if total > totalm:
		totalm = total
		xm = x
print(xm)


n = int(input())
l = list(map(int, input().split()))
(s, f) = map(int, input().split())
r = 1
k = f - s
ans = [0] * n
su = 0
st = s - 1
end = f - 2
for i in range(s - 1, f - 1):
	su += l[i]
ans[0] = su
for i in range(1, n):
	su = su + l[(st - 1) % n] - l[end % n]
	ans[i] = su
	st -= 1
	end -= 1
t = max(ans)
print(ans.index(t) + 1)


n = int(input())
l = list(map(int, input().split()))
(s, f) = map(int, input().split())
pref = [0]
for i in l:
	pref.append(i + pref[-1])
f -= 1
maxi = 0
ha = 1
ans = 0
while ha <= n:
	if f >= s:
		sumi = pref[f] - pref[s - 1]
	else:
		sumi = pref[f] + pref[n] - pref[s - 1]
	if sumi > maxi:
		ans = ha
		maxi = sumi
	s -= 1
	f -= 1
	s %= n
	f %= n
	if s == 0:
		s = n
	if f == 0:
		f = n
	ha += 1
print(ans)