{"raw_statement":[{"iden":"statement","content":"Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into _n_ pieces. The _i_\\-th piece is a sector of angle equal to _a__i_. Vasya and Petya want to divide all pieces of pizza into two _continuous_ sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty."},{"iden":"input","content":"The first line contains one integer _n_ (1 ≤ _n_ ≤ 360) — the number of pieces into which the delivered pizza was cut.\n\nThe second line contains _n_ integers _a__i_ (1 ≤ _a__i_ ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all _a__i_ is 360."},{"iden":"output","content":"Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya."},{"iden":"examples","content":"Input\n\n4\n90 90 90 90\n\nOutput\n\n0\n\nInput\n\n3\n100 100 160\n\nOutput\n\n40\n\nInput\n\n1\n360\n\nOutput\n\n360\n\nInput\n\n4\n170 30 150 10\n\nOutput\n\n0"},{"iden":"note","content":"In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.\n\nIn third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.\n\nIn fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.\n\nPicture explaning fourth sample:\n\n![image](https://espresso.codeforces.com/7aeb1713868b7fb0ae534eafef943af97abd11ae.png)\n\nBoth red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector."}],"translated_statement":[{"iden":"statement","content":"学生 Vasya 和 Petya 在 BSU（Byteland 国立大学）学习。在一次休息时，他们决定点一份披萨。在本题中，披萨是一个半径为某值的圆。披萨被切成 #cf_span[n] 块，第 #cf_span[i] 块是一个角度为 #cf_span[ai] 的扇形。Vasya 和 Petya 希望将所有披萨块划分为两个 _连续_ 的扇形，使得这两个扇形的角度差最小。扇形的角度等于其中所有块的角度之和。请注意，其中一个扇形可以为空。\n\n第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 360]) —— 披萨被切成的块数。\n\n第二行包含 #cf_span[n] 个整数 #cf_span[ai] (#cf_span[1 ≤ ai ≤ 360]) —— 披萨被切成的各扇形的角度。所有 #cf_span[ai] 的和为 360。\n\n请输出一个整数 —— Vasya 和 Petya 所得扇形角度的最小差值。\n\n在第一个样例中，Vasya 可以取第 #cf_span[1] 和 #cf_span[2] 块，Petya 可以取第 #cf_span[3] 和 #cf_span[4] 块。此时答案为 #cf_span[|(90 + 90) - (90 + 90)| = 0]。\n\n在第三个样例中，只有一块披萨，只能由 Vasya 或 Petya 之一取走。因此答案为 #cf_span[|360 - 0| = 360]。\n\n在第四个样例中，Vasya 可以取第 #cf_span[1] 和 #cf_span[4] 块，Petya 则取第 #cf_span[2] 和 #cf_span[3] 块。因此答案为 #cf_span[|(170 + 10) - (30 + 150)| = 0]。\n\n第四个样例的图示：\n\n\n\n红色和绿色扇形均由两个相邻的披萨块组成。因此 Vasya 可以取绿色扇形，Petya 则取红色扇形。"},{"iden":"input","content":"第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 360]) —— 披萨被切成的块数。第二行包含 #cf_span[n] 个整数 #cf_span[ai] (#cf_span[1 ≤ ai ≤ 360]) —— 披萨被切成的各扇形的角度。所有 #cf_span[ai] 的和为 360。"},{"iden":"output","content":"请输出一个整数 —— Vasya 和 Petya 所得扇形角度的最小差值。"},{"iden":"examples","content":"输入490 90 90 90输出0输入3100 100 160输出40输入1360输出360输入4170 30 150 10输出0"},{"iden":"note","content":"在第一个样例中，Vasya 可以取第 #cf_span[1] 和 #cf_span[2] 块，Petya 可以取第 #cf_span[3] 和 #cf_span[4] 块。此时答案为 #cf_span[|(90 + 90) - (90 + 90)| = 0]。在第三个样例中，只有一块披萨，只能由 Vasya 或 Petya 之一取走。因此答案为 #cf_span[|360 - 0| = 360]。在第四个样例中，Vasya 可以取第 #cf_span[1] 和 #cf_span[4] 块，Petya 则取第 #cf_span[2] 和 #cf_span[3] 块。因此答案为 #cf_span[|(170 + 10) - (30 + 150)| = 0]。第四个样例的图示：红色和绿色扇形均由两个相邻的披萨块组成。因此 Vasya 可以取绿色扇形，Petya 则取红色扇形。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of pizza pieces.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of positive integers such that $ \\sum_{i=1}^n a_i = 360 $.  \n\n**Constraints**  \n1. $ 1 \\leq n \\leq 360 $  \n2. $ 1 \\leq a_i \\leq 360 $ for all $ i \\in \\{1, \\dots, n\\} $  \n3. The pizza pieces are arranged in a circular order; a continuous sector is a contiguous subsequence of pieces in this circular arrangement.  \n\n**Objective**  \nFind the minimum absolute difference between the sums of two complementary continuous sectors:  \n$$\n\\min_{\\substack{0 \\leq i < j \\leq n \\\\ \\text{sector from } i \\text{ to } j-1 \\text{ (circular)}}} \\left| \\sum_{k=i}^{j-1} a_k - \\left(360 - \\sum_{k=i}^{j-1} a_k\\right) \\right| = \\min \\left| 2 \\cdot S - 360 \\right|\n$$  \nwhere $ S $ is the sum of angles in some continuous sector (possibly empty, i.e., $ S = 0 $).","simple_statement":null,"has_page_source":false}