import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class ConvenientForEverybody {

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println(new ConvenientForEverybody().run(reader));
    }

    public String run(BufferedReader reader) throws IOException {
        int amountOfTimezones = Integer.parseInt(reader.readLine());
        int[] amountOfPeopleInTimezones = Arrays.stream(reader.readLine().split(" "))
                .mapToInt(Integer::parseInt)
                .toArray();
        String[] hours = reader.readLine().split(" ");
        int s = Integer.parseInt(hours[0]);
        int f = Integer.parseInt(hours[1]);
        int interval = f - s;
        int maxIntervalPosition = 0;
        long maxIntervalSum = 0;
        long dynamicSum = 0;
        for (int i = 0; i < interval; i++) {
            dynamicSum += amountOfPeopleInTimezones[i];
        }
        for (int i = 1; i < amountOfTimezones; i++) {
            dynamicSum = dynamicSum + amountOfPeopleInTimezones[(i + interval - 1) % amountOfTimezones]
                    - amountOfPeopleInTimezones[(i - 1) % amountOfTimezones];
            if (dynamicSum >= maxIntervalSum) {
                maxIntervalPosition = i;
                maxIntervalSum = dynamicSum;
            }
        }
        int localTime = s - maxIntervalPosition;
        return String.valueOf(localTime > 0 && localTime < amountOfTimezones ? localTime : amountOfTimezones + localTime);
    }
}

@@ -847,78 +847,8 @@
  s;%0A
-        int maxIntervalPosition = 0;%0A        long maxIntervalSum = 0;%0A
     
@@ -975,32 +975,152 @@
 s%5Bi%5D;%0A        %7D%0A
+        long maxIntervalSum = dynamicSum;%0A        int maxIntervalPosition = s;%0A        int currentIntervalPosition = s;%0A
         for (int
@@ -1339,16 +1339,141 @@
 zones%5D;%0A
+            if (--currentIntervalPosition == 0) %7B%0A                currentIntervalPosition = amountOfTimezones;%0A            %7D%0A
         
@@ -1492,17 +1492,16 @@
 micSum %3E
-=
  maxInte
@@ -1549,17 +1549,39 @@
 ition = 
-i
+currentIntervalPosition
 ;%0A      
@@ -1624,32 +1624,122 @@
 m;%0A            %7D
+ else if (dynamicSum == maxIntervalSum && maxIntervalPosition %3E currentIntervalPosition) %7B
 %0A        %7D%0A     
@@ -1731,26 +1731,24 @@
         
-%7D%0A
         
 int loca
@@ -1743,169 +1743,128 @@
     
-int localTime = s - maxIntervalPosition;%0A        return String.valueOf(localTime %3E 0 && localTime %3C amountOfTimezones ? localTime : amountOfTimezones + localTime
+maxIntervalPosition = currentIntervalPosition;%0A            %7D%0A        %7D%0A        return String.valueOf(maxIntervalPosition
 );%0A 

Fix ConvenientForEverybody