The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
-  *d*<sub class="lower-index">1</sub> is the distance between the 1-st and the 2-nd station;-  *d*<sub class="lower-index">2</sub> is the distance between the 2-nd and the 3-rd station;...-  *d*<sub class="lower-index">*n* - 1</sub> is the distance between the *n* - 1-th and the *n*-th station;-  *d*<sub class="lower-index">*n*</sub> is the distance between the *n*-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
The first line contains integer *n* (3 ≤ *n* ≤ 100) — the number of stations on the circle line. The second line contains *n* integers *d*<sub class="lower-index">1</sub>, *d*<sub class="lower-index">2</sub>, ..., *d*<sub class="lower-index">*n*</sub> (1 ≤ *d*<sub class="lower-index">*i*</sub> ≤ 100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1 ≤ *s*, *t* ≤ *n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.

The numbers in the lines are separated by single spaces.
#!/usr/bin/python3.4

ans = 0

class Edge:
    def __init__(self, vertex_to, weight):
        self.vertex_to = vertex_to
        self.weight = weight

class Graph:

    WHITE_NODE, GRAY_NODE, BLACK_NODE, NULL_PARENT = 0, 1, 2, None

    def __init__(self, size):
        self.adj = [[] for i in range(size)]

    def add_edge(self, vertex_from, vertex_to, weight = 0):
        edge = Edge(vertex_to, weight)
        self.adj[vertex_from].append(edge)

n = int(input())
arr = list(map(int, input().split()))
dist = sum(arr)
a, b = map(int, input().split())
if a > b:
    a, b = b, a

def dfs(g, vertex):

    used = [g.WHITE_NODE for i in range(len(g.adj))]

    def _dfs(vertex):
        global ans
        used[vertex] = g.GRAY_NODE
        for edge in g.adj[vertex]:
            next_vertex = edge.vertex_to
            if used[next_vertex] == g.WHITE_NODE:
                ans += edge.weight
                if next_vertex != b:
                    _dfs(next_vertex)
        used[vertex] = g.BLACK_NODE

    _dfs(vertex)


graph = Graph(n + 10)

for i, val in enumerate(arr):
    if i == len(arr) - 1:
        graph.add_edge(i + 1, 1, val)
    graph.add_edge(i + 1, i + 2, val)

dfs(graph, a)

print(min(ans, abs(dist - ans)))
