problem_id
stringlengths 32
32
| name
stringlengths 2
54
| problem
stringlengths 204
5.28k
| solutions
sequencelengths 1
5.17k
| test_cases
stringlengths 38
86.7k
| difficulty
stringclasses 1
value | language
stringclasses 1
value | source
stringclasses 1
value | num_solutions
int64 1
5.17k
| starter_code
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|
2983f24ee4b182c38ef2d076e55954d6 | Road Problem | The Berland capital (as you very well know) contains *n* junctions, some pairs of which are connected by two-way roads. Unfortunately, the number of traffic jams in the capital has increased dramatically, that's why it was decided to build several new roads. Every road should connect two junctions.
The city administration noticed that in the cities of all the developed countries between any two roads one can drive along at least two paths so that the paths don't share any roads (but they may share the same junction). The administration decided to add the minimal number of roads so that this rules was fulfilled in the Berland capital as well. In the city road network should exist no more than one road between every pair of junctions before or after the reform.
The first input line contains a pair of integers *n*, *m* (2<=≤<=*n*<=≤<=900,<=1<=≤<=*m*<=≤<=100000), where *n* is the number of junctions and *m* is the number of roads. Each of the following *m* lines contains a description of a road that is given by the numbers of the connected junctions *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). The junctions are numbered from 1 to *n*. It is possible to reach any junction of the city from any other one moving along roads.
On the first line print *t* — the number of added roads. Then on *t* lines print the descriptions of the added roads in the format of the input data. You can use any order of printing the roads themselves as well as the junctions linked by every road. If there are several solutions to that problem, print any of them.
If the capital doesn't need the reform, print the single number 0.
If there's no solution, print the single number -1.
Sample Input
4 3
1 2
2 3
3 4
4 4
1 2
2 3
2 4
3 4
Sample Output
1
1 4
1
1 3
| [
"def dfs1(v):\r\n mark[v]=1\r\n st.append(v)\r\n dp[v]=d[v]\r\n for u in adj[v]:\r\n if not mark[u]:\r\n d[u]=d[v]+1\r\n dfs1(u)\r\n dp[v]=min(dp[u],dp[v])\r\n elif d[u]<d[v]-1:\r\n dp[v]=min(dp[v],d[u])\r\n if dp[v]==d[v]:\r\n ver[cnt[0]]=v\r\n prv =-1\r\n while prv != v:\r\n prv = st.pop()\r\n if d[ver[cnt[0]]]<d[prv]:\r\n ver[cnt[0]]=prv\r\n col[prv]=cnt[0]\r\n for u in adj[prv]:\r\n if col[u]!=-1 and col[u]!= cnt[0]:\r\n child[cnt[0]].append(col[u])\r\n cnt[0]+=1\r\n\r\ncnt=[0]\r\nN = 100000\r\nadj=[[]for i in range(N)]\r\nchild=[[]for i in range(N)]\r\nord=[]\r\nmark=[False]*N\r\ndp=[-1]*N\r\nd=[-1]*N\r\nst = []\r\ncol=[-1]*N\r\nver =[-1]*N\r\nn,m = map(int,input().split())\r\nif n == 2 and m == 1:\r\n\tprint(\"-1\")\r\n\texit(0)\r\nfor i in range(m):\r\n\tu,v = map(int,input().split())\r\n\tadj[v-1].append(u-1)\r\n\tadj[u-1].append(v-1)\r\ndfs1(0)\r\nver[cnt[0]-1] = 0\r\nif cnt[0] == 1:\r\n\tprint(\"0\")\r\n\texit(0)\r\nfor i in range(cnt[0]):\r\n\tif len(child[i]) == 0:\r\n\t\tord.append(i)\r\nif len(child[cnt[0]-1]) == 1:\r\n\t\tord.append(cnt[0]-1);\r\nans = int((len(ord)+1) /2)\r\nprint(ans)\r\nans1=0\r\nans2=0\r\nfor i in range(ans):\r\n ans1 = ver[ord[i]]+1\r\n ans2 = ver[ord[min(len(ord),int(i+len(ord)/2))]]+1\r\n print(ans1,ans2)\r\n"
] | {"inputs": ["4 3\n1 2\n2 3\n3 4", "4 4\n1 2\n2 3\n2 4\n3 4", "10 18\n6 4\n3 7\n4 9\n8 4\n3 4\n3 6\n7 5\n3 9\n10 9\n10 5\n1 2\n1 8\n8 2\n5 6\n6 9\n5 9\n3 10\n7 10", "10 13\n2 9\n9 5\n5 10\n4 8\n5 7\n6 1\n5 8\n9 7\n10 3\n7 1\n7 10\n2 1\n3 1", "10 16\n1 3\n4 3\n6 4\n5 3\n5 4\n1 2\n9 8\n10 5\n2 6\n7 9\n7 8\n1 4\n2 3\n10 7\n1 6\n6 10", "10 19\n3 7\n3 6\n8 1\n9 10\n1 4\n1 3\n4 3\n5 4\n7 10\n9 1\n4 2\n8 2\n9 4\n9 8\n7 6\n9 3\n8 6\n2 10\n6 2", "10 9\n7 9\n8 9\n8 2\n10 6\n8 3\n9 4\n2 6\n8 5\n9 1", "10 9\n5 4\n3 10\n8 2\n10 1\n8 3\n7 9\n5 7\n8 5\n4 6", "20 21\n12 6\n14 12\n5 7\n17 6\n10 11\n8 5\n13 1\n11 2\n4 16\n2 16\n3 4\n10 19\n20 15\n11 9\n13 6\n11 13\n5 15\n11 8\n9 18\n17 14\n2 3", "20 45\n3 9\n5 20\n2 16\n20 12\n18 11\n12 8\n15 8\n5 18\n8 7\n11 1\n5 10\n4 18\n10 17\n13 16\n10 11\n14 18\n9 4\n3 18\n12 1\n12 18\n5 1\n8 16\n8 19\n12 3\n8 6\n5 17\n19 7\n20 1\n6 19\n15 13\n10 20\n15 7\n4 1\n4 11\n2 7\n19 13\n14 20\n15 2\n17 14\n3 4\n6 13\n15 19\n13 2\n5 11\n16 7", "20 20\n1 7\n9 4\n11 16\n19 1\n8 3\n13 14\n10 1\n15 6\n10 18\n12 16\n15 11\n20 5\n17 11\n6 8\n20 16\n2 4\n5 12\n10 15\n17 14\n9 18", "20 20\n19 1\n11 9\n17 11\n15 12\n19 8\n11 5\n10 3\n10 16\n10 9\n7 20\n15 6\n14 2\n8 13\n15 19\n2 4\n9 18\n4 20\n10 15\n8 14\n17 18", "20 21\n19 7\n6 15\n17 3\n6 20\n10 11\n18 8\n1 9\n13 19\n4 16\n3 4\n3 16\n10 13\n2 3\n13 18\n1 17\n10 1\n18 6\n13 5\n9 12\n14 12\n2 16", "20 20\n19 1\n11 9\n17 11\n15 12\n19 8\n11 5\n10 3\n10 16\n10 9\n7 20\n15 6\n14 2\n8 13\n15 19\n2 4\n9 18\n4 20\n10 15\n8 14\n17 18", "20 20\n6 5\n3 17\n8 9\n6 1\n19 8\n11 18\n15 6\n15 11\n15 19\n12 16\n15 13\n7 20\n19 3\n15 14\n5 12\n14 4\n5 16\n10 15\n1 2\n8 7", "20 20\n1 9\n11 9\n3 5\n15 13\n1 20\n11 18\n10 6\n10 8\n10 19\n12 16\n10 3\n9 18\n8 4\n15 1\n13 16\n11 2\n7 20\n10 15\n3 17\n17 14", "20 20\n2 17\n5 17\n14 4\n4 11\n5 1\n4 9\n18 16\n1 18\n13 6\n9 19\n2 7\n20 6\n11 12\n18 8\n13 3\n14 17\n18 13\n2 15\n10 8\n5 2", "20 21\n6 20\n12 19\n17 14\n12 6\n10 11\n9 16\n1 9\n13 15\n3 4\n15 19\n7 2\n10 13\n20 15\n13 5\n1 18\n10 1\n18 8\n13 17\n9 2\n17 4\n20 19", "3 2\n2 1\n3 1", "2 1\n1 2", "4 3\n2 1\n3 4\n2 4", "5 5\n4 2\n1 4\n3 2\n5 1\n3 5", "6 6\n4 6\n2 1\n3 2\n4 3\n5 6\n3 5", "10 16\n2 6\n3 7\n6 5\n5 9\n5 4\n1 2\n9 8\n6 4\n2 10\n3 8\n7 9\n1 4\n2 4\n10 5\n1 6\n6 10", "8 14\n8 4\n3 5\n3 4\n6 3\n5 1\n1 4\n8 7\n2 4\n2 3\n2 1\n3 1\n2 6\n6 1\n2 5", "9 8\n4 3\n6 4\n7 5\n3 8\n7 6\n4 1\n6 2\n9 1", "6 6\n4 2\n6 2\n5 6\n4 3\n5 1\n3 5", "7 7\n4 6\n2 3\n2 4\n3 1\n5 2\n6 7\n4 7", "30 29\n12 20\n18 8\n1 18\n1 27\n17 6\n28 23\n26 16\n2 9\n15 5\n24 19\n2 21\n13 11\n16 13\n27 17\n24 26\n26 7\n18 28\n24 25\n2 15\n4 29\n24 3\n8 10\n20 30\n26 4\n15 24\n2 22\n16 14\n5 1\n21 12", "20 20\n19 11\n17 9\n1 12\n19 3\n19 2\n13 7\n10 6\n10 1\n10 19\n20 5\n10 18\n14 2\n1 17\n19 8\n14 4\n13 20\n2 4\n10 15\n1 13\n8 16", "40 40\n4 7\n37 10\n26 14\n26 24\n39 28\n29 40\n37 39\n19 5\n3 16\n33 1\n15 20\n38 8\n7 19\n29 38\n29 37\n8 13\n33 4\n29 33\n9 18\n39 26\n8 22\n23 27\n34 15\n37 2\n27 12\n28 36\n21 32\n36 21\n30 31\n23 6\n40 11\n31 23\n30 40\n26 35\n4 17\n4 34\n11 31\n17 9\n24 3\n18 25", "50 50\n37 15\n19 9\n42 43\n5 23\n17 2\n14 37\n27 20\n37 46\n48 6\n41 10\n26 40\n45 12\n47 29\n14 5\n24 25\n50 44\n3 49\n47 38\n18 48\n50 24\n13 45\n39 50\n18 26\n11 39\n26 27\n50 4\n12 31\n40 1\n32 19\n23 2\n26 42\n39 47\n48 35\n28 21\n50 16\n40 3\n11 32\n32 34\n14 36\n8 11\n43 7\n46 21\n22 29\n16 30\n39 13\n17 5\n41 33\n26 8\n3 14\n4 41", "60 61\n19 31\n1 56\n35 37\n1 47\n56 60\n15 31\n38 33\n26 57\n43 29\n28 22\n6 5\n56 38\n3 30\n49 17\n12 13\n20 49\n13 35\n31 16\n49 3\n15 14\n35 21\n54 4\n37 52\n12 32\n32 8\n23 2\n38 20\n50 5\n53 41\n12 45\n41 19\n40 39\n50 9\n58 27\n22 44\n10 46\n56 58\n20 12\n37 36\n15 28\n25 40\n58 11\n49 2\n22 55\n49 42\n11 43\n33 34\n34 48\n49 26\n53 4\n52 59\n49 51\n25 18\n58 24\n1 25\n16 54\n5 9\n21 7\n8 10\n56 6\n49 15", "70 69\n32 67\n1 57\n40 34\n44 38\n50 24\n69 5\n68 7\n19 61\n36 29\n60 6\n8 12\n32 10\n63 69\n62 39\n14 16\n40 63\n6 70\n39 58\n57 27\n9 55\n43 21\n25 15\n69 22\n30 3\n60 37\n22 50\n29 41\n37 56\n41 28\n11 19\n60 25\n50 46\n11 49\n14 2\n11 9\n40 60\n63 11\n62 1\n60 32\n15 64\n61 4\n10 66\n46 68\n32 18\n32 65\n50 62\n19 35\n40 36\n62 33\n56 31\n13 51\n17 44\n55 14\n14 47\n67 53\n46 17\n10 23\n69 45\n27 54\n60 8\n14 26\n43 52\n66 48\n26 59\n69 30\n36 43\n53 20\n56 51\n19 42", "60 66\n27 43\n37 11\n30 31\n50 53\n30 51\n13 8\n1 38\n22 57\n51 48\n10 5\n3 33\n5 60\n6 29\n58 39\n28 2\n33 36\n33 46\n41 33\n53 9\n47 40\n5 59\n20 3\n4 25\n17 57\n1 12\n55 6\n21 57\n41 28\n52 38\n23 42\n3 30\n22 21\n59 32\n49 35\n14 55\n4 32\n33 15\n59 40\n24 40\n36 16\n32 25\n37 52\n55 29\n58 45\n31 17\n20 15\n51 18\n24 47\n59 23\n34 49\n5 27\n33 39\n46 19\n1 56\n51 35\n30 50\n51 54\n5 41\n34 35\n13 26\n36 37\n10 14\n7 11\n45 39\n12 44\n59 13", "70 71\n56 50\n52 51\n6 5\n56 67\n29 17\n13 41\n39 10\n61 13\n3 22\n49 11\n2 20\n44 59\n30 4\n8 39\n37 26\n8 58\n21 57\n29 63\n69 24\n66 21\n44 55\n29 40\n44 37\n62 8\n53 64\n44 2\n15 28\n11 42\n67 53\n6 1\n52 14\n23 33\n59 16\n22 48\n2 34\n36 61\n61 32\n26 65\n56 49\n52 68\n6 25\n29 31\n15 12\n36 28\n37 9\n56 29\n47 43\n51 24\n68 35\n27 21\n22 52\n29 70\n43 23\n65 19\n7 36\n44 3\n17 45\n59 7\n36 6\n6 38\n14 62\n54 55\n69 51\n37 56\n52 30\n12 28\n25 60\n4 18\n37 47\n16 66\n46 57"], "outputs": ["1\n1 4", "1\n1 4", "1\n1 3", "1\n6 4", "1\n1 7", "1\n1 5", "3\n1 10\n5 7\n3 4", "2\n1 6\n9 2", "4\n1 18\n6 20\n19 7\n1 2", "1\n1 2", "3\n19 5\n2 3\n13 7", "4\n1 16\n7 5\n13 3\n12 6", "4\n2 8\n14 20\n11 15\n7 5", "4\n1 16\n7 5\n13 3\n12 6", "5\n2 17\n5 4\n9 13\n20 18\n2 10", "4\n7 4\n2 6\n12 14\n19 5", "4\n12 16\n19 20\n15 3\n7 10", "4\n8 14\n16 3\n7 6\n11 5", "1\n3 2", "-1", "1\n1 3", "0", "1\n1 3", "1\n1 3", "1\n1 7", "2\n9 2\n5 8", "1\n1 2", "2\n1 5\n1 4", "7\n6 14\n23 11\n10 7\n22 29\n30 25\n9 19\n6 3", "6\n9 16\n5 3\n7 2\n12 18\n11 15\n9 6", "7\n1 13\n20 32\n25 35\n5 16\n12 14\n6 10\n22 2", "10\n1 44\n49 25\n28 30\n15 33\n36 10\n2 38\n7 22\n20 31\n35 34\n6 9", "12\n47 36\n39 7\n18 51\n60 42\n27 57\n24 17\n29 4\n5 55\n48 44\n45 14\n46 30\n59 23", "16\n54 16\n58 2\n33 52\n7 21\n38 28\n24 34\n45 13\n3 31\n5 20\n49 65\n4 18\n42 48\n35 23\n47 64\n59 12\n54 70", "11\n56 26\n44 8\n7 43\n16 6\n19 39\n2 54\n60 48\n24 34\n4 18\n42 9\n56 21", "15\n1 10\n38 48\n60 34\n5 20\n32 33\n41 19\n12 9\n46 64\n27 50\n54 42\n35 70\n24 63\n18 40\n58 31\n1 45"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2985deca1c5256464afb41fab7fce20a | Numbers | One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if she had arranged the numbers correctly, but at this point her younger sister Maria came and shuffled all numbers. Anna got sick with anger but what's done is done and the results of her work had been destroyed. But please tell Anna: could she have hypothetically completed the task using all those given numbers?
The first line contains an integer *n* — how many numbers Anna had (3<=≤<=*n*<=≤<=105). The next line contains those numbers, separated by a space. All numbers are integers and belong to the range from 1 to 109.
Print the single line "YES" (without the quotes), if Anna could have completed the task correctly using all those numbers (using all of them is necessary). If Anna couldn't have fulfilled the task, no matter how hard she would try, print "NO" (without the quotes).
Sample Input
4
1 2 3 2
6
1 1 2 2 2 3
6
2 4 1 1 2 2
Sample Output
YES
YES
NO
| [
"n= int(input())\r\na = list(map(int,input().split()))\r\na.sort()\r\nmm=a[0]\r\nb=list(map(lambda x: x-mm, a))\r\nif b[-1]>n or n%2==1:\r\n print('NO')\r\nelse:\r\n c=[0]*(b[-1]+1)\r\n for el in b:\r\n c[el]+=1\r\n for i in range(1,len(c)):\r\n c[i] = c[i]-c[i-1] \r\n c[i-1]=0\r\n #print(c)\r\n if i!=len(c)-1:\r\n if (c[i]==0 or c[i]<0):\r\n print('NO')\r\n break\r\n else:\r\n if c[i]!=0:\r\n print('NO')\r\n break\r\n else:\r\n print('YES')\r\n\n# Sat Oct 17 2020 10:31:31 GMT+0300 (Москва, стандартное время)\n",
"from collections import defaultdict\r\nimport heapq\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nif n % 2:\r\n ans = \"NO\"\r\nelse:\r\n cnt = defaultdict(lambda : 0)\r\n for i in a:\r\n cnt[i] += 1\r\n mi, ma = min(a), max(a)\r\n cnt[mi] -= 1\r\n cnt[ma] -= 1\r\n ok = 1\r\n for i in range(mi + 1, ma):\r\n if cnt[i] < 2:\r\n ok = 0\r\n break\r\n cnt[i] -= 2\r\n h = []\r\n for i in cnt.keys():\r\n for _ in range(cnt[i]):\r\n heapq.heappush(h, i)\r\n while h and ok:\r\n i = heapq.heappop(h)\r\n if not cnt[i]:\r\n continue\r\n elif not cnt[i + 1]:\r\n ok = 0\r\n break\r\n cnt[i] -= 1\r\n cnt[i + 1] -= 1\r\n ans = \"YES\" if ok else \"NO\"\r\nprint(ans)",
"#https://codeforces.com/problemset/problem/128/D\r\ndef main():\r\n n, a = int(input()), list(map(int, input().split()))\r\n\r\n x, y = min(a), max(a)\r\n d = y - x\r\n if 2 * d > n:\r\n print(\"NO\")\r\n exit(0)\r\n\r\n c = [0] * (d + 1)\r\n for i in range(n):\r\n c[a[i] - x] += 1\r\n\r\n for i in range(1, d):\r\n c[i] -= c[i - 1]\r\n if c[i] <= 0:\r\n print(\"NO\")\r\n exit(0)\r\n\r\n if c[d] == c[d - 1]:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nif __name__ == '__main__':\r\n main()",
"def no():\n print(\"NO\")\n exit(0)\n \nn, a = int(input()), list(map(int, input().split()))\n \nx, y = min(a), max(a)\nd = y-x\nif 2*d > n:\n print(\"NO\")\n exit(0)\n \nc = [0] * (d+1)\nfor i in range(n):\n c[a[i]-x] += 1\n \nfor i in range(1, d):\n c[i] -= c[i-1]\n if c[i] <= 0:\n no()\n \nif c[d] == c[d-1]:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n\t\t \t\t \t \t\t \t\t \t\t \t \t \t\t \t\t",
"from collections import Counter\r\nimport string\r\nimport bisect\r\n#import random\r\nimport math\r\nimport sys\r\n# sys.setrecursionlimit(10**6) \r\nfrom fractions import Fraction\r\ndef array_int():\r\n return [int(i) for i in sys.stdin.readline().split()]\r\ndef vary(arrber_of_variables):\r\n if arrber_of_variables==1:\r\n return int(sys.stdin.readline())\r\n if arrber_of_variables>=2:\r\n return map(int,sys.stdin.readline().split()) \r\ndef makedict(var):\r\n return dict(Counter(var))\r\ntestcases=1\r\nfor _ in range(testcases):\r\n n=vary(1)\r\n num=array_int()\r\n ct=makedict(num)\r\n mini=min(num)\r\n ct[mini]-=1\r\n ans=1\r\n while 1:\r\n if ans==n:\r\n break\r\n if ct.get(mini+1,0)>0:\r\n ct[mini+1]-=1\r\n ans+=1\r\n # print('hello',mini)\r\n mini+=1\r\n elif ct.get(mini-1,0)>0:\r\n ct[mini-1]-=1\r\n ans+=1\r\n # print(mini)\r\n mini-=1\r\n else:\r\n break\r\n # print(mini)\r\n # print(ans,mini)\r\n if ans==n and mini==min(num)+1:\r\n print('YES')\r\n else:\r\n print('NO')\r\n \r\n",
"import sys\nn = int(input())\nc = {}\na = [int(i) for i in input().split()]\nmaxi = max(a)\nfor i in a:\n c[i] = c.get(i, 0) + 1\nl = sorted(c)\nt = l[:-1]\nfor u in t:\n if u + 1 not in c:\n print(\"NO\")\n sys.exit()\n c[u + 1] -= c[u]\n if 0 > c[u + 1]:\n print(\"NO\")\n sys.exit()\narr = list(c.values())\nif arr.count(0) == 1 and c[maxi] == 0:\n print(\"YES\")\nelse:\n print(\"NO\")\n\n# Fri Oct 16 2020 22:20:09 GMT+0300 (Москва, стандартное время)\n\n \t\t\t\t\t \t \t\t \t \t\t\t \t \t"
] | {"inputs": ["4\n1 2 3 2", "6\n1 1 2 2 2 3", "6\n2 4 1 1 2 2", "4\n999999998 1000000000 999999999 999999999", "5\n6 7 6 7 6", "8\n3 5 8 4 7 6 4 7", "10\n10 11 10 11 10 11 10 11 10 11", "6\n1 2 3 4 5 6", "4\n294368194 294368194 294368194 294368195", "5\n637256245 637256246 637256248 637256247 637256247", "5\n473416369 473416371 473416370 473416371 473416370", "5\n650111756 650111755 650111754 650111755 650111756", "10\n913596052 913596055 913596054 913596053 913596055 913596054 913596053 913596054 913596052 913596053", "16\n20101451 20101452 20101452 20101452 20101453 20101452 20101451 20101451 20101452 20101451 20101452 20101451 20101454 20101454 20101451 20101451", "13\n981311157 104863150 76378528 37347249 494793049 33951775 3632297 791848390 926461729 94158141 54601123 332909757 722201692", "50\n363510947 363510954 363510943 363510964 363510969 363510950 363510951 363510960 363510967 363510952 363510956 363510948 363510944 363510946 363510965 363510946 363510963 363510962 363510947 363510955 363510954 363510948 363510961 363510964 363510963 363510945 363510965 363510953 363510952 363510968 363510955 363510966 363510968 363510950 363510967 363510949 363510958 363510957 363510956 363510959 363510953 363510951 363510966 363510949 363510944 363510962 363510945 363510958 363510961 363510957", "3\n1 2 1000000000", "8\n1 1 2 2 5 5 6 6", "16\n1 2 2 2 3 3 3 4 4 5 5 5 6 6 6 7", "8\n1 2 2 2 2 3 3 3", "8\n1 2 2 2 3 3 3 4", "8\n5 4 3 2 1 2 3 4", "20\n2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 5 6 5 6", "8\n1 2 3 2 3 2 3 2"], "outputs": ["YES", "YES", "NO", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES"]} | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
298842cf255460074457de672e78bc2b | Restoring Increasing Sequence | Peter wrote on the board a strictly increasing sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.
Restore the the original sequence knowing digits remaining on the board.
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of the sequence. Next *n* lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.
If the answer exists, print in the first line "YES" (without the quotes). Next *n* lines must contain the sequence of positive integers — a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them.
If there is no answer, print a single line "NO" (without the quotes).
Sample Input
3
?
18
1?
2
??
?
5
12224
12??5
12226
?0000
?00000
Sample Output
YES
1
18
19
NO
YES
12224
12225
12226
20000
100000
| [
"def check(a,b,n):\r\n for i in range(n):\r\n if not ((b[i] == '?') or (a[i] == b[i])): \r\n return False\r\n return True\r\n\r\ndef process(a,b):\r\n for i in range(len(a)-1,-1,-1):\r\n if ((b[i] == '?' and a[i] != '9') or (b[i] != '?' and a[i] < b[i])) and check(a,b,i):\r\n for j in range(i):\r\n if b[j] == '?':\r\n b[j] = a[j]\r\n if b[i] == '?':\r\n b[i] = str(int(a[i])+1)\r\n for j in range(i+1, len(a)):\r\n if b[j] == '?':\r\n b[j] = '0'\r\n return b, 0\r\n return b, 1\r\n \r\ndef solve(a,n):\r\n if a[0][0] == '?':\r\n a[0] = '1' + a[0][1:]\r\n for i in range(1, len(a[0])):\r\n if a[0][i] == '?':\r\n a[0] = a[0][:i] + '0' + a[0][i+1:]\r\n for i in range(1, n):\r\n if len(a[i-1]) > len(a[i]):\r\n return []\r\n b = list(a[i])\r\n if len(a[i-1]) < len(a[i]):\r\n if a[i][0] == '?':\r\n a[i] = '1' + a[i][1:]\r\n for index in range(len(a[i])):\r\n if a[i][index] == '?':\r\n a[i] = a[i][:index] + '0' + a[i][index+1:]\r\n else:\r\n b, flag = process(list(a[i-1]),b)\r\n if flag:\r\n return []\r\n else:\r\n a[i] = \"\".join(b)\r\n return a\r\nn = int(input())\r\na = []\r\nfor _ in range(n):\r\n a.append(input())\r\na = solve(a,n)\r\nif len(a) == 0:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n for b in a:\r\n print(b)"
] | {"inputs": ["3\n?\n18\n1?", "2\n??\n?", "5\n12224\n12??5\n12226\n?0000\n?00000", "10\n473883\n3499005\n4?74792\n58146??\n8?90593\n9203?71\n?39055?\n1?692641\n11451902\n?22126?2", "8\n?\n2\n3\n4\n?\n?\n?\n9", "98\n?\n?0\n2?\n6?\n6?\n69\n??\n??\n96\n1?2\n??3\n104\n??4\n1?9\n??2\n18?\n?01\n205\n?19\n244\n??8\n?5?\n?5?\n276\n??3\n???\n???\n?28\n?3?\n3??\n??8\n355\n4?0\n4??\n?10\n??1\n417\n4?9\n?3?\n4?4\n?61\n?8?\n???\n507\n?2?\n???\n??6\n5?7\n540\n5?9\n???\n?7?\n5??\n591\n?9?\n6?0\n620\n??4\n??1\n?35\n65?\n65?\n6?8\n6??\n68?\n7?4\n7??\n718\n?2?\n??9\n???\n7??\n?7?\n776\n7??\n788\n???\n?0?\n803\n83?\n846\n84?\n853\n85?\n87?\n?8?\n89?\n9?1\n91?\n929\n??0\n??6\n??3\n9??\n98?\n9?5\n9??\n995", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "3\n18\n19\n1?", "3\n20\n19\n21", "3\n19\n2?\n20", "2\n99999999\n99999999", "2\n140\n?40", "11\n?\n?\n?\n?\n?\n?\n?\n?\n?\n?\n?", "4\n100\n???\n999\n???", "1\n????????", "2\n100\n???", "2\n100\n?00", "2\n?00\n100", "3\n100\n?00\n200", "2\n50\n5", "3\n99999998\n????????\n99999999", "3\n99999998\n99999999\n????????", "3\n99999997\n99999998\n???????", "4\n????????\n10000001\n99999998\n????????", "2\n13300\n12?34"], "outputs": ["YES\n1\n18\n19", "NO", "YES\n12224\n12225\n12226\n20000\n100000", "YES\n473883\n3499005\n4074792\n5814600\n8090593\n9203071\n9390550\n10692641\n11451902\n12212602", "YES\n1\n2\n3\n4\n5\n6\n7\n9", "YES\n1\n10\n20\n60\n61\n69\n70\n71\n96\n102\n103\n104\n114\n119\n122\n180\n201\n205\n219\n244\n248\n250\n251\n276\n283\n284\n285\n328\n330\n331\n338\n355\n400\n401\n410\n411\n417\n419\n430\n434\n461\n480\n481\n507\n520\n521\n526\n527\n540\n549\n550\n570\n571\n591\n592\n600\n620\n624\n631\n635\n650\n651\n658\n659\n680\n704\n705\n718\n720\n729\n730\n731\n770\n776\n777\n788\n789\n800\n803\n830\n846\n847\n853\n854\n870\n880\n890\n901\n910\n929\n930\n936\n943\n944\n980\n985\n986\n995", "YES\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "NO", "NO", "NO", "NO", "YES\n140\n240", "NO", "NO", "YES\n10000000", "YES\n100\n101", "YES\n100\n200", "NO", "NO", "NO", "NO", "NO", "NO", "YES\n10000000\n10000001\n99999998\n99999999", "NO"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
29bd0490fe176e76bac1e031211a7544 | Amity Assessment | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2<=×<=2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below:
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
The first two lines of the input consist of a 2<=×<=2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2<=×<=2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
Sample Input
AB
XC
XB
AC
AB
XC
AC
BX
Sample Output
YES
NO
| [
"def main():\n res = []\n for _ in 0, 1:\n a, b = input()\n d, c = input()\n res.append([x for x in (a, b, c, d) if x != 'X'])\n a, b = res\n print((\"NO\", \"YES\")[b[b.index(a[0]) - 1] == a[2]])\n\n\nif __name__ == '__main__':\n main()\n",
"l1=str()\r\ns=str(input())\r\nl1=s.replace(\"X\",\"\")\r\ns=str(input())\r\ns=s.replace(\"X\",\"\")\r\nl1+=s[::-1]\r\nl2=str()\r\ns=str(input())\r\nl2=s.replace(\"X\",\"\")\r\ns=str(input())\r\ns=s.replace(\"X\",\"\")\r\nl2+=s[::-1]\r\nl1=3*l1\r\nif l2 in l1:\r\n print(\"YES\")\r\nelse: print(\"NO\")",
"a, b = input() + input()[::-1], input() + input()[::-1]\r\nprint('YES' if b.replace('X', '') in a.replace('X', '') * 2 else 'NO')\r\n",
"puzzle1 = ''\r\npuzzle2 = ''\r\n\r\nrow = input()\r\nif row[0] != 'X':\r\n puzzle1 += row[0]\r\nif row[1] != 'X':\r\n puzzle1 += row[1]\r\nrow = input()\r\nif row[1] != 'X':\r\n puzzle1 += row[1]\r\nif row[0] != 'X':\r\n puzzle1 += row[0]\r\nrow = input()\r\nif row[0] != 'X':\r\n puzzle2 += row[0]\r\nif row[1] != 'X':\r\n puzzle2 += row[1]\r\nrow = input()\r\nif row[1] != 'X':\r\n puzzle2 += row[1]\r\nif row[0] != 'X':\r\n puzzle2 += row[0]\r\n\r\nvar = [puzzle2,\r\n puzzle2[2]+puzzle2[0]+puzzle2[1],\r\n puzzle2[1]+puzzle2[2]+puzzle2[0]]\r\n\r\nif puzzle1 in var:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n",
"f = lambda: 'ABC' in 2*(input()+input()[::-1]).replace('X', '')\r\nprint('NO' if f()^f() else 'YES')",
"a,b,c=list(input()+input()),list(input()+input()),0\nwhile c<20 and (a[0]!=b[0] or a[1]!=b[1] or a[2]!=b[2] or a[3]!=b[3]):\n\ta0,b0=a.index(\"X\"),b.index(\"X\")\n\tif a0==0:a[0],a[1]=a[1],a[0]\n\tif a0==1:a[1],a[3]=a[3],a[1]\n\tif a0==2:a[0],a[2]=a[2],a[0]\n\tif a0==3:a[2],a[3]=a[3],a[2]\n\tc+=1\nprint(\"YES\" if c<20 else \"No\")",
"# TEST\r\nB_0 = str(input().strip('\\n\\r'))\r\nB_1 = str(input().strip('\\n\\r'))\r\nB = list(B_0) + list(B_1[::-1])\r\nE_0 = str(input().strip('\\n\\r'))\r\nE_1 = str(input().strip('\\n\\r'))\r\nE = list(E_0) + list(E_1[::-1])\r\nB.remove(\"X\")\r\nE.remove(\"X\")\r\n\r\n\r\ndef main():\r\n for i in range(3):\r\n if B == E:\r\n return \"YES\"\r\n else:\r\n tmp = B.pop(0)\r\n B.append(tmp)\r\n return \"NO\"\r\n\r\n\r\nprint(main())",
"import sys\n\npa = input() + input()\npb = input() + input()\n\nmark = set()\nqt = [pb]\nwhile qt:\n\ts = qt.pop()\n\tif s == pa:\n\t\tprint('YES')\n\t\tsys.exit(0)\n\n\tif s in mark: continue\n\tmark.add(s)\n\t\n\ttb = [list(s[:2]), list(s[2:])]\n\tx = y = None \n\tfor i in range(0, 2):\n\t\tfor j in range(0, 2):\n\t\t\tif tb[i][j] == 'X':\n\t\t\t\tx, y = i, j\n\t\t\t\tbreak\n\n\tif x - 1 >= 0:\n\t\tntb = [tb[0][:], tb[1][:]]\n\t\tntb[x - 1][y], ntb[x][y] = ntb[x][y], ntb[x - 1][y]\n\t\tqt.append(''.join(ntb[0] + ntb[1]))\n\n\tif x + 1 < 2:\n\t\tntb = [tb[0][:], tb[1][:]]\n\t\tntb[x + 1][y], ntb[x][y] = ntb[x][y], ntb[x + 1][y]\n\t\tqt.append(''.join(ntb[0] + ntb[1]))\n\n\tif y - 1 >= 0:\n\t\tntb = [tb[0][:], tb[1][:]]\n\t\tntb[x][y - 1], ntb[x][y] = ntb[x][y], ntb[x][y - 1]\n\t\tqt.append(''.join(ntb[0] + ntb[1]))\n\n\tif y + 1 < 2:\n\t\tntb = [tb[0][:], tb[1][:]]\n\t\tntb[x][y + 1], ntb[x][y] = ntb[x][y], ntb[x][y + 1]\n\t\tqt.append(''.join(ntb[0] + ntb[1]))\n\t\t\t\nprint('NO')\n",
"def read(s, t):\n if (s[0] == 'X'):\n return s[1] + t[::-1]\n if (s[1] == 'X'):\n return t[::-1] + s[0]\n if (t[0] == 'X'):\n return t[1] + s\n if (t[1] == 'X'):\n return s + t[0]\n\ns1 = ''.join(input().split())\ns2 = ''.join(input().split())\nt1 = ''.join(input().split())\nt2 = ''.join(input().split())\ns = read(s1, s2)\nt = read(t1, t2)\nfor i in range(3):\n for j in range(3):\n #print(s[i:] + s[:i], t[j:] + t[:j])\n if s[i:] + s[:i] == t[j:] + t[:j]:\n print(\"YES\")\n exit(0)\nprint(\"NO\")\n",
"t = ''\r\nans = ''\r\ns = input()\r\nt = t + s\r\ns = input()\r\nt = t + s[::-1]\r\nt = list(t)\r\ns = input()\r\nans = ans + s\r\ns = input()\r\nans = ans + s[::-1]\r\nans = list(ans)\r\nidx = t.index('X')\r\nfor i in range(12):\r\n t[(idx + i) % 4], t[(idx + i + 1) % 4] = t[(idx + i + 1) % 4], t[(idx + i) % 4]\r\n if t == ans:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")",
"a = input()\r\nb = input()[::-1]\r\ns1=''\r\nif a[0] != 'X':\r\n s1 += a[0]\r\nif a[1] != 'X':\r\n s1 += a[1]\r\nif b[0] != 'X':\r\n s1 += b[0]\r\nif b[1] != 'X':\r\n s1 += b[1]\r\na = input()\r\nb = input()[::-1]\r\ns2=''\r\nif a[0] != 'X':\r\n s2 += a[0]\r\nif a[1] != 'X':\r\n s2 += a[1]\r\nif b[0] != 'X':\r\n s2 += b[0]\r\nif b[1] != 'X':\r\n s2 += b[1]\r\nc = s2.index(s1[0])\r\nif s2[(c + 1) % 3] == s1[1]:\r\n print(\"YES\")\r\nelse:\r\n print('NO')",
"import sys\nsys.setrecursionlimit(10000000)\nfrom math import pi\na = list(input())\nb = list(input())\nab = a+list(reversed(b))\nab.remove('X')\na = list(input())\nb = list(input())\ncd = a+list(reversed(b))\ncd.remove('X')\ncd = cd + cd\nfriends = False\nfor i in range(3):\n good = True\n for j in range(3):\n if ab[j] != cd[i+j]:\n good = False\n friends = friends or good\nif friends:\n print('YES')\nelse:\n print('NO')\n",
"class CodeforcesTask655ASolution:\n def __init__(self):\n self.result = ''\n self.a = []\n self.b = []\n\n def read_input(self):\n self.a = input() + input()[::-1]\n self.b = input() + input()[::-1]\n\n def process_task(self):\n self.a = self.a.replace(\"X\", \"\")\n self.b = self.b.replace(\"X\", \"\")\n a1 = self.a\n a2 = self.a[2] + self.a[0] + self.a[1]\n a3 = self.a[1] + self.a[2] + self.a[0]\n #print(a1, a2, a3, self.b)\n if a1 == self.b or a2 == self.b or a3 == self.b:\n self.result = \"YES\"\n else:\n self.result = \"NO\"\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask655ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n",
"\r\nimport sys\r\ns = [x.strip().strip('X') for x in sys.stdin.readlines()]\r\ns1 = s[0][::-1] + s[1] + s[0][-1]\r\ns2 = s[2][::-1] + s[3] + s[2][-1]\r\nch = 1\r\nfor i in range(3):\r\n if s1[i + 1] != s2[s2.find(s1[i]) + 1]:\r\n ch = 0\r\nprint(\"YES\" if ch else \"NO\")\r\n\r\n",
"def read_ints():\r\n return [int(x) for x in input(' ').split()]\r\n\r\n\r\ndef evaluate(top, bot):\r\n res = 1 if 'X' in top else 2\r\n perm = top + bot\r\n perm = [x for x in perm if x != 'X']\r\n for i in range(len(perm)):\r\n for j in range(i+1, len(perm)):\r\n if perm[i] > perm[j]:\r\n res += 1\r\n return res % 2\r\n\r\n\r\ndef main():\r\n top = input()\r\n bot = input()\r\n x = evaluate(top, bot)\r\n top = input()\r\n bot = input()\r\n y = evaluate(top, bot)\r\n print(\"YES\" if x == y else \"NO\")\r\n\r\nif __name__ == '__main__':\r\n main()",
"l1=str()\ns=str(input())\nl1=s.replace(\"X\",\"\")\ns=str(input())\ns=s.replace(\"X\",\"\")\nl1+=s[::-1]\nl2=str()\ns=str(input())\nl2=s.replace(\"X\",\"\")\ns=str(input())\ns=s.replace(\"X\",\"\")\nl2+=s[::-1]\nl1=2*l1\nif l2 in l1:\n print(\"YES\")\nelse: print(\"NO\")\n \t\t \t \t\t\t \t \t \t \t\t",
"l=[]\r\nfor i in range(2):\r\n a,b=input(),input()\r\n # print(a,b)\r\n temp=list(b[0]+a+b[1])\r\n # print(temp)\r\n temp.remove(\"X\")\r\n # print(temp)\r\n while temp[0]!=\"A\":\r\n temp[0],temp[1],temp[2]=temp[2],temp[0],temp[1]\r\n l.append(\"\".join(temp))\r\nif l[0]==l[1]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"l1 = list(input())\r\ntemp = list(input())\r\nl1.append(temp[1])\r\nl1.append(temp[0])\r\nl1.remove('X')\r\n\r\nl2 = list(input())\r\ntemp = list(input())\r\nl2.append(temp[1])\r\nl2.append(temp[0])\r\nl2.remove('X')\r\n\r\nflag = False\r\nfor i in range(3):\r\n if l1 == l2:\r\n print(\"YES\")\r\n flag = True\r\n break\r\n l1.append(l1[0])\r\n del l1[0]\r\nif not flag:\r\n print(\"NO\")\r\n",
"a = [''] * 2\r\nb = [''] * 2\r\nfor i in range(2):\r\n a[i] = input()\r\nfor i in range(2):\r\n b[i] = input()\r\nway1 = ''\r\nway2 = ''\r\nfor i in range(2):\r\n if i == 0:\r\n for q in range(2):\r\n if a[i][q] != 'X':\r\n way1 += a[i][q]\r\n if b[i][q] != 'X':\r\n way2 += b[i][q]\r\n else:\r\n for q in range(1, -1, -1):\r\n if a[i][q] != 'X':\r\n way1 += a[i][q]\r\n if b[i][q] != 'X':\r\n way2 += b[i][q]\r\nfor i in range(3):\r\n if way1 == way2:\r\n print(\"YES\")\r\n exit()\r\n way2 = way2[1:] + way2[0]\r\nprint(\"NO\")\r\nexit()",
"a1 = input()\na2 = input()\nb1 = input()\nb2 = input()\nbel = [a1,a2]\nel = [b1,b2]\nchecker = False\nfor i in range(100):\n if not( a1 == b1 and a2 == b2):\n if 'X' in a1:\n if a1.find('X') == 0:\n a1 = a2[0]+a1[1]\n a2 = 'X'+a2[1]\n else:\n a1 = 'X'+a1[0]\n \n \n \n else:\n if a2.find('X') == 0:\n a2 = a2[1] + 'X'\n else:\n \n a2 = a2[0] + a1[1]\n a1 = a1[0] +'X'\n \n else:\n \n \n checker = True\n break\nif checker == True:\n print('YES')\nelse:\n print('NO')",
"a=input()+input()[::-1]\r\nb=input()+input()[::-1]\r\na=a.replace(\"X\",\"\")\r\nb=b.replace(\"X\",\"\")\r\nif (a+a).find(b)+1:print(\"YES\")\r\nelse:print('NO')",
"def check(A):\r\n flag1 = 0\r\n if A[0][0] == 'A' and A[0][1] == 'B' and A[1][1] == 'C':\r\n flag1 = 1 \r\n elif A[0][0] == 'A' and A[0][1] == 'B' and A[1][0] == 'C':\r\n flag1 = 1 \r\n elif A[0][0] == 'A' and A[1][1] == 'B' and A[1][0] == 'C':\r\n flag1 = 1 \r\n elif A[0][1] == 'A' and A[1][1] == 'B' and A[1][0] == 'C':\r\n flag1 = 1 \r\n elif A[0][1] == 'A' and A[1][1] == 'B' and A[0][0] == 'C':\r\n flag1 = 1 \r\n elif A[0][1] == 'A' and A[1][0] == 'B' and A[0][0] == 'C':\r\n flag1 = 1 \r\n elif A[1][1] == 'A' and A[1][0] == 'B' and A[0][0] == 'C':\r\n flag1 = 1 \r\n elif A[1][1] == 'A' and A[1][0] == 'B' and A[0][1] == 'C':\r\n flag1 = 1 \r\n elif A[1][1] == 'A' and A[0][0] == 'B' and A[0][1] == 'C':\r\n flag1 = 1 \r\n elif A[1][0] == 'A' and A[0][0] == 'B' and A[0][1] == 'C':\r\n flag1 = 1 \r\n elif A[1][0] == 'A' and A[0][0] == 'B' and A[1][1] == 'C':\r\n flag1 = 1 \r\n elif A[1][0] == 'A' and A[0][1] == 'B' and A[1][1] == 'C':\r\n flag1 = 1 \r\n return flag1\r\nA = []\r\nB = []\r\n\r\na1 = list(input())\r\na2 = list(input())\r\nb1 = list(input())\r\nb2 = list(input())\r\nA.append(a1)\r\nA.append(a2)\r\nB.append(b1)\r\nB.append(b2)\r\n\r\nif check(A) == check(B):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ",
"I = input\r\nbs = ''.join([I(), I()[::-1]]).replace('X','')*2\r\nel = ''.join([I(), I()[::-1]]).replace('X','')\r\nif el in bs: print(\"YES\")\r\nelse: print(\"NO\")",
"import re\n\ns1, s2, s3, s4 = [input().rstrip() for _ in range(4)]\n\nt1, t2 = s1 + s2[::-1], s3 + s4[::-1]\nt1 = re.sub('X', '', t1)\nt2 = re.sub('X', '', t2)\n\nif len(t1) == len(t2) and (t1 + t1).find(t2) != -1:\n print(\"YES\")\nelse:\n print(\"NO\")\n",
"d1 = list(input() + input()[::-1])\r\nd2 = list(input() + input()[::-1])\r\n\r\nj = d1.index('X')\r\nk = d2.index('X')\r\nL = []\r\nfor i in range(12):\r\n d1[j%4], d1[(j+1)%4] = d1[(j+1)%4], d1[j%4]\r\n d2[k%4], d2[(k+1)%4] = d2[(k+1)%4], d2[k%4]\r\n L.append(''.join(d1))\r\n L.append(''.join(d2))\r\n j += 1\r\n k += 1\r\n\r\nif len(L) > len(set(L)): print('YES')\r\nelse: print('NO')",
"def find_order(A, B):\r\n d = dict()\r\n i = 0\r\n if A[0] != 'X':\r\n d[i] = A[0]\r\n i += 1\r\n if A[1] != 'X':\r\n d[i] = A[1]\r\n i += 1\r\n if B[1] != 'X':\r\n d[i] = B[1]\r\n i += 1\r\n if B[0] != 'X':\r\n d[i] = B[0]\r\n i += 1\r\n return d\r\n\r\n\r\na = input()\r\nb = input()\r\nc = input()\r\nd = input()\r\nm = find_order(a, b)\r\nn = find_order(c, d)\r\n\r\nm[3] = m[0]\r\nm[4] = m[1]\r\nif m[0] == n[0]:\r\n if m[1] == n[1] and m[2] == n[2]:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelif m[1] == n[0]:\r\n if m[2] == n[1] and m[3] == n[2]:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelif m[2] == n[0]:\r\n if m[3] == n[1] and m[4] == n[2]:\r\n print('YES')\r\n else:\r\n print('NO')\r\n",
"#!/usr/bin/python3\n\ndef readln(): return map(int, input().split())\n\ndef main():\n inp = [input() for _ in range(4)]\n a = inp[0] + inp[1][1] + inp[1][0]\n a = a.replace('X', '')\n b = inp[2] + inp[3][1] + inp[3][0]\n b = b.replace('X', '')\n print('YES' if a == b or a == b[1:] + b[0] or a == b[2] + b[:2] else 'NO')\n\nif __name__ == '__main__':\n main()\n",
"\r\n\r\n\r\na1=input()\r\na2=input()\r\nb1=input()\r\nb2=input()\r\n\r\nfirst=list(a1+a2[::-1])\r\nsecond=list(b1+b2[::-1])\r\n\r\nfirst.remove('X')\r\nsecond.remove('X')\r\n#print(first,second)\r\n\r\nans=\"NO\"\r\n\r\nfor i in range(3):\r\n if(first==second):\r\n ans=\"YES\"\r\n break\r\n second=second[1:]+[second[0]]\r\n\r\nprint(ans)\r\n",
"def rotate(arr):\r\n return arr[1:]+arr[0]\r\n \r\na1 = input().replace(\"X\",\"\")\r\na2 = input().replace(\"X\",\"\")\r\nb1 = input().replace(\"X\",\"\")\r\nb2 = input().replace(\"X\",\"\")\r\n\r\narr1 = a1+a2[::-1]\r\narr2 = b1+b2[::-1]\r\nflag=False\r\nfor i in range(4):\r\n if arr1==arr2:\r\n flag=True\r\n break\r\n arr2 = rotate(arr2)\r\n \r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"def main():\r\n a1, a2, b1, b2 = input(), input(), input(), input()\r\n\r\n combs1 = set(['AB', 'BC', 'CA'])\r\n combs2 = set(['BA', 'CB', 'AC'])\r\n\r\n type1 = a1 in combs1 or a2 in combs2\r\n type2 = b1 in combs1 or b2 in combs2\r\n\r\n print('YES' if type1 == type2 else 'NO')\r\n \r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"def main():\r\n b1 = input()\r\n b2 = input()\r\n e1 = input()\r\n e2 = input()\r\n b1 = b1.replace('X', '')\r\n b2 = b2.replace('X', '')\r\n e1 = e1.replace('X', '')\r\n e2 = e2.replace('X', '')\r\n b2 = b2[::-1]\r\n e2 = e2[::-1]\r\n b = b1 + b2 + b1 + b2\r\n e = e1 + e2 + e1 + e2\r\n if ('ABC' in b and 'ABC' in e) or ('ACB' in b and 'ACB' in e):\r\n return 'YES'\r\n return 'NO'\r\n\r\n\r\nprint(main())\r\n",
"# 0 = 4\r\n# 1 = 5\r\n# 2 = 6\r\n# 3 = 7\r\nflag = False\r\nm_list = []\r\n\r\nfor i in range(0,4):\r\n\r\n m_list += input()\r\n\r\nnewl = [m_list[0] + m_list[2],m_list[1] + m_list[0], m_list[3] + m_list[1], m_list[2] + m_list[3]]\r\n\r\n\r\nlastl = [m_list[4] + m_list[5],m_list[5] + m_list[7], m_list[7] + m_list[6], m_list[6] + m_list[4]]\r\n\r\n\r\nfor i in range(len(newl)):\r\n if (newl[i] in lastl) and (\"X\" not in newl[i]):\r\n flag = True\r\n\r\n\r\nif flag == True:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")",
"a=''.join(input())\r\na=a.join(input())\r\na=list(a)\r\na.remove('X')\r\na=''.join(map(str,a))\r\nb=''.join(input())\r\nb=b.join(input())\r\nb=list(b)\r\nb.remove('X')\r\nb=''.join(map(str,b))\r\nc=b+b+b+b+b+b\r\nif a in c:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ",
"import poplib\r\nimport string\r\nimport math\r\n\r\ndef rotate(l):\r\n x = l[-1]\r\n l.pop()\r\n l.insert(0, x)\r\n\r\n\r\n\r\n\r\n\r\ndef main_function():\r\n s_1 = list(input())\r\n s_2 = list(input())\r\n s_3 = list(input())\r\n s_4 = list(input())\r\n s_2.reverse()\r\n s_4.reverse()\r\n s_1 += s_2\r\n s_3 += s_4\r\n s_1.pop(s_1.index(\"X\"))\r\n s_3.pop(s_3.index(\"X\"))\r\n found = False\r\n for i in range(4):\r\n rotate(s_1)\r\n if s_1 == s_3:\r\n found = True\r\n break\r\n if found:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nif __name__ == '__main__':\r\n main_function()",
"A = list(input() + input()[::-1])\nB = list(input() + input()[::-1])\nA.remove('X')\nB.remove('X')\nk = B.index(A[0])\nprint('YES' if all((A[i] == B[(i+k)%3] for i in range(3))) else 'NO')\n",
"a = input()\na = a + input()[::-1]\na = a.replace('X','')\nb = input()\nb = b + input()[::-1]\nb = b.replace('X','')\nb = b * 2\n\nif b.find(a) == -1:\n\tprint('NO')\nelse:\n\tprint('YES')",
"def solve(s, mem):\r\n tem = ''\r\n for j in range(4):\r\n ix = (i + j) % 4\r\n if s[ix] != 'X':\r\n tem += s[ix]\r\n\r\n mem[tem] = True\r\n\r\n\r\na, b, mema, memb = input() + input()[::-1], input() + input()[::-1], dict(), dict()\r\nfor i in range(4):\r\n solve(a, mema)\r\n solve(b, memb)\r\n\r\nprint('YES' if any([x in memb for x in mema]) else 'NO')\r\n",
"L1 = list(input()[::-1] + input())\r\nL2 = list(input()[::-1] + input())\r\n\r\nL1.remove('X')\r\ninA1 = L1.index('A')\r\nL2.remove('X')\r\ninA2 = L2.index('A')\r\nL1 = L1[inA1:] + L1[:inA1]\r\nL2 = L2[inA2:] + L2[:inA2]\r\n\r\n\r\nif L1 == L2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"bes1 = input()\nbes2 = input()\nels1 = input()\nels2 = input()\nbes = bes1[0] + bes2[0] + bes2[1] + bes1[1]\nels = els1[0] + els2[0] + els2[1] + els1[1]\nbes = bes.replace(\"X\",\"\")\nels = els.replace(\"X\",\"\")\n\nif els[els.find(bes[0])-1] == bes[-1]:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t \t\t\t\t\t\t\t \t \t\t\t \t\t \t \t",
"#!/usr/bin/env python3\nimport random\n\ndef main():\n (a, b, c, d) = (input(),input(),input(),input())\n a = a.replace('X', '')\n b = b.replace('X', '')\n c = c.replace('X', '')\n d = d.replace('X', '')\n a+=b[::-1]\n c+=d[::-1]\n for i in range(9):\n a = a[2] + a[:2]\n if a == c:\n print(\"YES\")\n quit()\n\n print(\"NO\")\nif __name__==\"__main__\":\n main()\n",
"# You lost the game.\nch = [str(input()) for _ in range(4)]\nL = [ch[0][0],ch[0][1],ch[1][1],ch[1][0]]\nR = [ch[2][0],ch[2][1],ch[3][1],ch[3][0]]\ndel(L[L.index('X')])\ndel(R[R.index('X')])\ni = 0\nwhile i < 4 and L != R:\n i += 1\n L = L[1:]+[L[0]]\nif L == R:\n print(\"YES\")\nelse:\n print(\"NO\")\n ",
"Bessie = input() + input()\r\nElsie = input() + input()\r\ndef get_permutations(line):\r\n permutations = [line]\r\n x_index = line.index('X')\r\n for i in range(11):\r\n if x_index == 0:\r\n line = ''.join((line[2], line[1], line[0], line[3]))\r\n x_index = 2\r\n elif x_index == 1:\r\n line = ''.join((line[1], line[0], line[2], line[3]))\r\n x_index = 0 \r\n elif x_index == 2:\r\n line = ''.join((line[0], line[1], line[3], line[2]))\r\n x_index = 3 \r\n else:\r\n line = ''.join((line[0], line[3], line[2], line[1]))\r\n x_index = 1 \r\n permutations.append(line)\r\n return permutations\r\nis_best_friends_for_life = not set(get_permutations(Bessie)).isdisjoint(get_permutations(Elsie))\r\nprint(\"YES\" if is_best_friends_for_life else \"NO\")",
"c = input()\r\nd = input()\r\nA = c + d[::-1]\r\nc = input()\r\nd = input()\r\nB = c + d[::-1]\r\n\r\nA = A.replace('X', '')\r\nB = B.replace('X', '')\r\n\r\nA = A + A\r\n\r\nif (A.find(B) == -1):\r\n print('NO')\r\nelse:\r\n print('YES')",
"#THIS PROBLEM EATEN MY BRAIN\r\nb=''.join([input() for j in range(2)])\r\ne=''.join([input() for j in range(2)])\r\nB=[];E=[]\r\nfor i in b: B.append(i)\r\nfor i in e: E.append(i)\r\nB[2], B[3] = B[3], B[2]\r\nE[2], E[3] = E[3], E[2]\r\nb=''.join(B)\r\ne=''.join(E)\r\ne=e*3\r\nb=b.replace(\"X\",'')\r\ne=e.replace(\"X\",'')\r\nif b in e:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"def mp(): return map(int,input().split())\r\ndef lt(): return list(map(int,input().split()))\r\ndef pt(x): print(x)\r\ndef ip(): return input()\r\ndef it(): return int(input())\r\ndef sl(x): return [t for t in x]\r\ndef spl(x): return x.split()\r\ndef aj(liste, item): liste.append(item)\r\ndef bin(x): return \"{0:b}\".format(x)\r\ndef printlist(l): print(''.join([str(x) for x in l]))\r\ndef listring(l): return ''.join([str(x) for x in l])\r\n\r\ns1 = ip()\r\ns2 = ip()\r\nt1 = ip()\r\nt2 = ip()\r\nr1 = []\r\nr2 = []\r\nfor i in s1:\r\n if i != \"X\":\r\n r1.append(i)\r\nfor i in s2[::-1]:\r\n if i != \"X\":\r\n r1.append(i)\r\nfor i in t1:\r\n if i != \"X\":\r\n r2.append(i)\r\nfor i in t2[::-1]:\r\n if i != \"X\":\r\n r2.append(i)\r\ni1 = r1.index(\"A\")\r\ni2 = r2.index(\"A\")\r\nfor i in range(1,3):\r\n if r1[(i1+i)%3] != r2[(i2+i)%3]:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")\r\n \r\n \r\n ",
"s1 = ''\r\ns2 = ''\r\nfor i in range(2):\r\n r = list(input())\r\n if i == 1:\r\n r = r[1] + r[0]\r\n for c in r:\r\n if c != 'X':\r\n s1+=c\r\nfor i in range(2):\r\n r = input()\r\n if i == 1:\r\n r = r[1] + r[0] \r\n for c in r:\r\n if c != 'X':\r\n s2+=c\r\n \r\ns2 *= 2\r\nk = 0\r\nfor i in range(3):\r\n if s1 == s2[i:i + 3]:\r\n k = 1\r\nif k == 0:\r\n print('NO')\r\nelse:\r\n print('YES')",
"a = list(input()) + list(input())\r\nb = list(input()) + list(input())\r\n\r\na = [a[0], a[1], a[3], a[2]]\r\nb = [b[0], b[1], b[3], b[2]]\r\n\r\nfor i in range(4):\r\n if a[i] == 'X':\r\n del(a[i])\r\n break\r\nfor i in range(4):\r\n if b[i] == 'X':\r\n del(b[i])\r\n break\r\n\r\nb = b + b[:]\r\n#print(a)\r\nfor i in range(3):\r\n #print(b[i:i+3])\r\n if b[i:i+3] == a:\r\n print('YES')\r\n break\r\nelse:\r\n for i in range(6,3,-1):\r\n #print(b[i-3:i])\r\n if b[i-3:i] == a:\r\n print('YES')\r\n break\r\n else:\r\n print('NO')\r\n\r\n",
"a = input().strip() + input().strip()[::-1]\nb = input().strip() + input().strip()[::-1]\na = a.replace(\"X\", \"\")\nb = b.replace(\"X\", \"\")\nif (a == b or a[1:] + a[:1] == b or a[2:] + a[:2] == b):\n print(\"YES\")\nelse:\n print(\"NO\")\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ns1 = input()[:-1]\r\ns2 = input()[:-1]\r\ns3 = input()[:-1]\r\ns4 = input()[:-1]\r\n\r\ns = (s1 + s2[::-1]).replace('X', '')\r\nw = (s3 + s4[::-1]).replace('X', '')\r\n\r\nfor i in range(3):\r\n if s[0] != 'A':\r\n s = s[1:] + s[0]\r\n else:\r\n break\r\nfor i in range(3):\r\n if w[0] != 'A':\r\n w = w[1:] + w[0]\r\n else:\r\n break\r\nprint('YES' if s == w else 'NO')",
"from collections import deque\r\nf = []\r\ns = []\r\nh = input()\r\nh1 = input()\r\nh = h + h1[::-1]\r\nfor i in h:\r\n if i != 'X':\r\n f.append(i)\r\nh = input()\r\nh1 = input()\r\nh = h + h1[::-1]\r\nfor i in h:\r\n if i != 'X':\r\n s.append(i)\r\nf1 = []\r\nf1.append(f[1])\r\nf1.append(f[2])\r\nf1.append(f[0])\r\nf2 = []\r\nf2.append(f[2])\r\nf2.append(f[0])\r\nf2.append(f[1])\r\nif f1 == s or f2 == s or f == s:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n",
"a = [list(input()) for _ in range(2)]\r\nb = [list(input()) for _ in range(2)]\r\na = [a[0][0], a[0][1], a[1][1], a[1][0]]\r\nb = [b[0][0], b[0][1], b[1][1], b[1][0]]\r\na.remove(\"X\")\r\nb.remove(\"X\")\r\nx = a.index(\"A\")\r\ny = b.index(\"A\")\r\nret = True\r\nfor i in range(3):\r\n if a[(x + i) % 3] != b[(y + i) % 3]:\r\n ret = False\r\nif ret:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"l1 = input()\r\nl2 = input()\r\nl3 = input()\r\nl4 = input()\r\ns = l1 + l2[::-1]\r\nl = s.split('X')\r\ns = ''\r\nfor i in l:\r\n s += i\r\ns1 = s*2\r\ns = l3 + l4[::-1]\r\nl = s.split('X')\r\ns = ''\r\nfor i in l:\r\n s += i\r\nif s in s1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n",
"A = \"\"\r\nB = \"\"\r\n\r\nA += input()\r\nA += input()[::-1]\r\nB += input()\r\nB += input()[::-1]\r\n\r\nA_new = \"\"\r\nB_new = \"\"\r\n\r\nfor i in range(4):\r\n if A[i] != 'X':\r\n A_new += A[i]\r\n if B[i] != 'X':\r\n B_new += B[i]\r\n\r\nif B_new == A_new or B_new[1:] + B_new[0] == A_new or B_new[2:] + B_new[:2] == A_new:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"a1 = input()\na2 = input()\nb1 = input()\nb2 = input()\n\nbes = a1[0] + a1[1] + a2[1] + a2[0]\nels = b1[0] + b1[1] +b2[1] +b2[0]\n\nbes2 = bes.replace(\"X\", \"\")\nels2 = els.replace(\"X\", \"\")\n\nbes2 += bes2\n\nans = bes2.find(els2)\nif ans == -1:\n print(\"NO\")\nelse:\n print(\"YES\")\n\n\n\n\t\t\t\t \t \t\t \t\t\t\t\t \t \t \t\t",
"s1, s2 = input(), input()\r\nt1, t2 = input(), input()\r\na = [s1[0], s1[1], s2[1], s2[0]]\r\nb = [t1[0], t1[1], t2[1], t2[0]]\r\na.pop(a.index('X'))\r\nb.pop(b.index('X'))\r\nai = a.index('A')\r\nbi = b.index('A')\r\nfor i in 'ABC':\r\n if a[ai] != b[bi]:\r\n print('NO')\r\n exit()\r\n ai = (ai + 1) % 3\r\n bi = (bi + 1) % 3\r\nprint('YES')\r\n",
"def det(a, b):\n if a[0] == 'X':\n return a[1] + b[::-1]\n elif a[1] == 'X':\n return b[::-1] + a[0]\n elif b[0] =='X':\n return a + b[1]\n else:\n return a + b[0]\n\n\ndef solve():\n s1 = input()\n s2 = input()\n s3 = input()\n s4 = input()\n\n p1 = det(s1, s2)\n p2 = det(s3, s4)\n\n for i in range(3):\n if p1 == (p2 + p2)[i:i+3]:\n print('YES')\n return\n print('NO')\n\n\nif __name__ == '__main__':\n solve()\n",
"a1=str(input())\r\na2=str(input())\r\nb1=str(input())\r\nb2=str(input())\r\na1=list(a1)\r\na2=list(a2)\r\na2.reverse()\r\na=a1+a2\r\nb1=list(b1)\r\nb2=list(b2)\r\nb2.reverse()\r\nb=b1+b2\r\na=\"\".join(a)\r\nb=\"\".join(b)\r\na=a.replace(\"X\",\"\")\r\nb=b.replace(\"X\",\"\")\r\nb=b*2\r\nc=b.count(a)\r\nif c>0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"a = (input()+input()[::-1]).replace('X','')\nb = (input()+input()[::-1]).replace('X','')\n#print(a,b)\nc = b.index(a[0])\nd = b[c:]+b[:c]\nprint('YES' if a==d else 'NO')",
"#!/usr/bin/env python3\n\nletters = {\n 0 : 1,\n 1 : 3,\n 3 : 2,\n 2 : 0,\n }\n\ndef enum_letters(s):\n start = s.find('A')\n yield(s[start])\n for i in range(0, 2):\n start = letters[start]\n if s[start] == 'X':\n start = letters[start]\n yield(s[start])\n\ndef read_string():\n s = ''\n for c in enum_letters(input() + input()):\n s += c\n return s\n\na = read_string()\nb = read_string()\nif a == b:\n print('YES')\nelse:\n print('NO')\n",
"a = input()\r\nb = input()\r\nc = input()\r\nd = input()\r\n \r\na = (a + b[::-1]).replace(\"X\", \"\") * 2\r\nc = (c + d[::-1]).replace(\"X\", \"\")\r\nif a.find(c) != -1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"s1 = \"\"\r\ns2 = \"\"\r\na = input()\r\nb = input()\r\nc = input()\r\nd = input()\r\ns1 = list(a + b[1] + b[0])\r\ns2 = list(c + d[1] + d[0])\r\nt = s1.index('X')\r\nif t != 3:\r\n s1 = s1[:t] + s1[t+1:]\r\nelse:\r\n s1 = s1[:3]\r\nt = s2.index('X')\r\nif t != 3:\r\n s2 = s2[:t] + s2[t+1:]\r\nelse:\r\n s2 = s2[:3]\r\nif s1[0] + s1[1] + s1[2] == s2[0] + s2[1] + s2[2] or s1[1] + s1[2] + s1[0] == s2[0] + s2[1] + s2[2] or s1[2] + s1[0] + s1[1] == s2[0] + s2[1] + s2[2]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"c = input()\nd = input()\nA = c + d[::-1]\nc = input()\nd = input()\nB = c + d[::-1]\n\nA = A.replace('X', '')\nB = B.replace('X', '')\n\nA = A + A\n\nif (A.find(B) == -1):\n print('NO')\nelse:\n print('YES')",
"import functools\r\nimport math\r\nimport sys\r\n\r\ns = [input() for i in range(4)]\r\nA, B = '', ''\r\nif s[0][0] == 'X':\r\n A = s[0][1] + s[1][1] + s[1][0]\r\nelif s[0][1] == 'X':\r\n A = s[1][1] + s[1][0] + s[0][0]\r\nelif s[1][0] == 'X':\r\n A = s[0][0] + s[0][1] + s[1][1]\r\nelse:\r\n A = s[1][0] + s[0][0] + s[0][1]\r\n\r\nif s[2][0] == 'X':\r\n B = s[2][1] + s[3][1] + s[3][0]\r\nelif s[2][1] == 'X':\r\n B = s[3][1] + s[3][0] + s[2][0]\r\nelif s[3][0] == 'X':\r\n B = s[2][0] + s[2][1] + s[3][1]\r\nelse:\r\n B = s[3][0] + s[2][0] + s[2][1]\r\n\r\nif A == B or A == B[2] + B[:2] or A == B[1:] + B[0]:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n \r\n \r\n",
"f=lambda:(input()+input()[::-1]).replace('X','')\r\na=f();b=f()\r\nprint('YES' if a in [b[i:]+b[:i] for i in range(3)] else 'NO')",
"a = input()\r\nb = input()\r\nc = input()\r\nd = input()\r\n\r\ns = list(a + b[1] + b[0])\r\nt = list(c + d[1] + d[0])\r\ns.remove('X')\r\nt.remove('X')\r\n\r\nfor i in range(5):\r\n t = t[1:] + [t[0]]\r\n if s == t:\r\n print(\"YES\")\r\n break\r\nelse:\r\n print(\"NO\")",
"import os,sys,io,math\r\nfrom tokenize import Triple\r\nfrom array import array\r\nfrom math import *\r\nI=lambda:[*map(int,sys.stdin.readline().split())]\r\nIS=lambda:input()\r\nIN=lambda:int(input())\r\nIF=lambda:float(input())\r\n\r\na,b,c,d=IS(),IS(),IS(),IS()\r\na+=b[::-1]\r\nx=\"X\"\r\nfor i in range(4):\r\n if a[i]==x:\r\n a=a[:i]+a[i+1:]\r\n break\r\nc+=d[::-1]\r\nfor i in range(4):\r\n if c[i]==x:\r\n c=c[:i]+c[i+1:]\r\n break\r\nf=False\r\nfor i in range(4):\r\n if a==c:f=True\r\n c=c[1:]+c[0]\r\nprint(\"YES\" if f else \"NO\")",
"import copy\ndef g(s):\n ans = set()\n q = [s]\n while q:\n t = q.pop(0)\n for i in range(2):\n for j in range(2):\n if t[i][j] == 'X':\n xx = copy.deepcopy(t)\n xx[i][j], xx[i][1 - j] = xx[i][1 - j], xx[i][j]\n k = ''.join(map(lambda r: ''.join(r), xx))\n if k not in ans:\n ans.add(k)\n q.append(xx)\n\n xx = copy.deepcopy(t)\n xx[i][j], xx[1 - i][j] = xx[1 - i][j], xx[i][j]\n k = ''.join(map(lambda r: ''.join(r), xx))\n if k not in ans:\n ans.add(k)\n q.append(xx)\n\n return ans\n\nt = []\nt.append(list(input()))\nt.append(list(input()))\n\nr = []\nr.append(list(input()))\nr.append(list(input()))\n\nprint('YES' if (g(r) & g(t)) else 'NO')\n",
"a1 = input()\r\nb1 = input()\r\na2 = input()\r\nb2 = input()\r\na1 = a1 + b1[::-1]\r\na2 = a2 + b2[::-1]\r\nr1 = \"\"\r\nr2 = \"\"\r\nfor x in a1:\r\n if x != 'X':\r\n r1 = r1 + x\r\nfor x in a2:\r\n if x != 'X':\r\n r2 = r2 + x\r\nr2 = r2 + r2\r\nif r1 in r2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"puzzle = [input() for i in range(2)]\r\npuzzle2 = [input() for i in range(2)]\r\nstroke = \"\"\r\nstroke2 = \"\"\r\ni = 0\r\nfor j in range(2):\r\n if puzzle[i][j] != \"X\":\r\n stroke += puzzle[i][j]\r\n if puzzle2[i][j] != \"X\":\r\n stroke2 += puzzle2[i][j]\r\ni = 1\r\nfor j in range(1,-1,-1):\r\n if puzzle[i][j] != \"X\":\r\n stroke += puzzle[i][j]\r\n if puzzle2[i][j] != \"X\":\r\n stroke2 += puzzle2[i][j]\r\nstroke += stroke\r\nif stroke.find(stroke2) != -1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"b1 = input()\nb2 = input()\ne1 = input()\ne2 = input()\nb = (b1 + b2[::-1]).split(\"X\")\ne = (e1 + e2[::-1]).split(\"X\")\nb = b[1] + b[0]\ne = e[0] + e[1]\nif e == b:\n print(\"YES\")\nelif (e[2] + e[0] + e[1]) == b:\n print(\"YES\")\nelif (e[1] + e[2] + e[0]) == b:\n print(\"YES\")\nelse:\n print(\"NO\")\n",
"a=(input()+input()[::-1]).replace('X','')\r\nb=(input()+input()[::-1]).replace('X','')\r\nif a==b or a==b[1:]+b[0] or a==b[2]+b[:2]:\r\n print('YES')\r\nelse:\r\n print('NO')",
"s1=input()\r\ns2=input()\r\ns3=input()\r\ns4=input()\r\ns11=s1+s2[::-1]\r\ns22=s3+s4[::-1]\r\nk1=\"\"\r\nk2=\"\"\r\nfor i in range(4):\r\n if s11[i]!='X':\r\n k1+=s11[i]\r\nfor i in range(4):\r\n if s22[i]!='X':\r\n k2+=s22[i]\r\nk1=k1*3\r\n#print(k1)\r\n#print(k2)\r\nif k2 in k1:\r\n print('YES')\r\nelse:\r\n print('NO')",
"#!/usr/bin/python3\n\nA = (input() + input()[::-1]).replace('X', '')\nB = (input() + input()[::-1]).replace('X', '')\n\nwhile A[0] != 'A':\n\tA = A[1:] + A[0]\nwhile B[0] != 'A':\n\tB = B[1:] + B[0]\n\nprint('YES' if A == B else 'NO')\n",
"#[int(i) for i in input().split()]\r\na = input()\r\nb = input()\r\na = a + b[::-1]\r\na = a.replace('X', '')\r\ni = a.find('A')\r\na = a[i:] + a[:i]\r\n\r\nc = input()\r\nd = input()\r\nc = c + d[::-1]\r\nc = c.replace('X', '')\r\ni = c.find('A')\r\nc = c[i:] + c[:i]\r\nif a == c:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n",
"p11 = input()\r\np12 = input()\r\np21 = input()\r\np22 = input()\r\n\r\ns1 = (p11 + p12[1] + p12[0]).replace('X', '')\r\ns2 = (p21 + p22[1] + p22[0]).replace('X', '')\r\n\r\nif(s1 == 'ABC' or s1 == 'BCA' or s1 == 'CAB'):\r\n first = True\r\nelse:\r\n first = False\r\n \r\nif(s2 == 'ABC' or s2 == 'BCA' or s2 == 'CAB'):\r\n second = True\r\nelse:\r\n second = False\r\n \r\n \r\nif(first == second):\r\n print('YES')\r\nelse:\r\n print('NO')",
"per1 = input()\r\nper2 = input()\r\nper3 = input()\r\nper4 = input()\r\ns= []\r\ns.append(per1[0])\r\ns.append (per1[1])\r\ns.append (per2[1])\r\ns.append (per2[0])\r\nfor i in range(len(s)):\r\n if s[i] == 'X':\r\n s.pop(i)\r\n break\r\nd= []\r\nd.append(per3[0])\r\nd.append (per3[1])\r\nd.append (per4[1])\r\nd.append (per4[0])\r\nfor i in range(len(d)):\r\n if d[i] == 'X':\r\n d.pop(i)\r\n break\r\nper2 = False\r\nfor i in range(3):\r\n if s != d:\r\n t = d.pop(0)\r\n d.append(t)\r\n else:\r\n per2 = True\r\n break\r\nif per2:\r\n print('YES')\r\nelse:\r\n print('NO')",
"a = input().strip()\r\na = a + ''.join(list(reversed(input().strip())))\r\n\r\nb = input().strip()\r\nb = b + ''.join(list(reversed(input().strip())))\r\n\r\na = a.replace('X', '')\r\nb = b.replace('X', '')\r\nf = False\r\nfor i in range(4):\r\n if a == b:\r\n f = True\r\n b = b[1:] + b[:1]\r\nif f:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"import sys\ns1=input()\ns2=input()\nl1=list(s1+s2[::-1])\ns1=input()\ns2=input()\nl2=list(s1+s2[::-1])\nf=0\nl3=l1.copy()\nix=l1.index('X')\nix1=l3.index('X')\nfor i in range(8):\n if l1==l2 or l3==l2:\n print (\"YES\")\n f=1\n break\n l1[ix],l1[(ix+1)%4]=l1[(ix+1)%4],l1[ix]\n ix=(ix+1)%4\n l3[ix1],l3[(ix1-1)%4]=l3[(ix1-1)%4],l3[ix1]\n ix1=(ix1-1)%4\n\nif f==0:\n print(\"NO\")\n\t \t\t \t \t \t \t \t\t\t \t\t \t\t\t \t\t",
"list1 = [(i)for i in input()]\r\nlist2 = [(i)for i in input()]\r\nlist3 = [(i)for i in input()]\r\nlist4 = [(i)for i in input()]\r\nchars1 = \"\"\r\nchars2 = \"\"\r\n\r\nif list1[0]!=\"X\":\r\n chars1+=list1[0]\r\nif list1[1]!=\"X\":\r\n chars1+=list1[1]\r\nif list2[1]!=\"X\":\r\n chars1+=list2[1]\r\nif list2[0]!=\"X\":\r\n chars1+=list2[0]\r\n\r\nchars1*=2\r\n\r\nif list3[0]!=\"X\":\r\n chars2+=list3[0]\r\nif list3[1]!=\"X\":\r\n chars2+=list3[1]\r\nif list4[1]!=\"X\":\r\n chars2+=list4[1]\r\nif list4[0]!=\"X\":\r\n chars2+=list4[0]\r\n\r\n\r\nif chars2 in chars1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n",
"# import math\nfrom collections import Counter, deque, defaultdict\n# from math import *\n\nfrom bisect import bisect_right\n\nMOD = 1000000007\n\n\n# from functools import reduce\n# from itertools import permutations\n# import queue\ndef rotate(s1,i,j):\n x1=\"\"\n if i == 0:\n if j == 0:\n if s1[0][1] != \"X\":\n x1 += s1[0][1]\n if s1[1][1] != \"X\":\n x1 += s1[1][1]\n if s1[1][0] != \"X\":\n x1 += s1[1][0]\n else:\n if s1[1][1] != \"X\":\n x1 += s1[1][1]\n if s1[1][0] != \"X\":\n x1 += s1[1][0]\n if s1[0][0] != \"X\":\n x1 += s1[0][0]\n else:\n if j == 0:\n if s1[0][0] != \"X\":\n x1 += s1[0][0]\n if s1[0][1] != \"X\":\n x1 += s1[0][1]\n if s1[1][1] != \"X\":\n x1 += s1[1][1]\n else:\n if s1[1][0] != \"X\":\n x1 += s1[1][0]\n if s1[0][0] != \"X\":\n x1 += s1[0][0]\n if s1[0][1] != \"X\":\n x1 += s1[0][1]\n return x1\n\ndef solve():\n s1=[]\n s2=[]\n x1=\"\"\n x2=\"\"\n for i in range(2):\n s1.append(list(input()))\n for i in range(2):\n s2.append(list(input()))\n for i in range(2):\n for j in range(2):\n if s1[i][j]==\"A\":\n x1+=\"A\"\n x1+=rotate(s1,i,j)\n break\n for i in range(2):\n for j in range(2):\n if s2[i][j]==\"A\":\n x2+=\"A\"\n x2+=rotate(s2,i,j)\n break\n if x1==x2:\n print(\"YES\")\n return\n print(\"NO\")\n\n\n\n\n\n\n# t = int(input())\nt = 1\nfor num in range(t):\n # print(\"Case #{}: \".format(num + 1), end=\"\")\n solve()\n\n \t\t \t \t\t \t\t\t\t \t \t\t \t\t\t \t\t",
"import math, re, sys, string, operator, functools, fractions, collections\nsys.setrecursionlimit(10**7)\nRI=lambda x=' ': list(map(int,input().split(x)))\nRS=lambda x=' ': input().rstrip().split(x)\ndX= [-1, 1, 0, 0,-1, 1,-1, 1]\ndY= [ 0, 0,-1, 1, 1,-1,-1, 1]\nmod=int(1e9+7)\neps=1e-6\npi=math.acos(-1.0)\nMAX=20\n#################################################\ns1=(input()+(input()[::-1])).replace('X','')\ns2=(input()+(input()[::-1])).replace('X','')\nf=0\nfor i in range(3):\n if s1==s2[i:3]+s2[:i]:\n f=1\nprint([\"NO\",\"YES\"][f])\n",
"def roll(x):\n\n x=x.replace('X','')\n\n while x[0]!='A':x=x[-1]+x[:2]\n\n return(x)\n\na,b=input()+input()[::-1],input()+input()[::-1];print(['NO','YES'][roll(a)==roll(b)])\n\n\n\n# Made By Mostafa_Khaled",
"def find(state):\r\n global results\r\n global board2\r\n if state==board2:\r\n return True;\r\n t = state.index('X')\r\n if t==0:\r\n state1 = state[1]+\"X\"+state[2]+state[3]\r\n state2 = state[2]+state[1]+\"X\"+state[3]\r\n if state1 in results and state2 in results:\r\n return False\r\n if state1 not in results:\r\n results+=[state1]\r\n if find(state1): return True;\r\n if state2 not in results:\r\n results+=[state2]\r\n if find(state2): return True;\r\n elif t==1:\r\n state1 = state[0]+state[3]+state[2]+\"X\"\r\n state2 = \"X\"+state[0]+state[2]+state[3]\r\n if state1 in results and state2 in results:\r\n return False\r\n if state1 not in results:\r\n results+=[state1]\r\n if find(state1): return True;\r\n if state2 not in results:\r\n results+=[state2]\r\n if find(state2): return True;\r\n elif t==2:\r\n state1 = \"X\"+state[1]+state[0]+state[3]\r\n state2 = state[0]+state[1]+state[3]+\"X\"\r\n if state1 in results and state2 in results:\r\n return False\r\n if state1 not in results:\r\n results+=[state1]\r\n if find(state1): return True;\r\n if state2 not in results:\r\n results+=[state2]\r\n if find(state2): return True; \r\n elif t==3:\r\n state1 = state[0]+\"X\"+state[2]+state[1]\r\n state2 = state[0]+state[1]+\"X\"+state[2]\r\n if state1 in results and state2 in results:\r\n return False\r\n if state1 not in results:\r\n results+=[state1]\r\n if find(state1): return True;\r\n if state2 not in results:\r\n results+=[state2]\r\n if find(state2): return True;\r\n return False\r\n\r\n\r\nboard1 = input()\r\nboard1+=input()\r\n\r\nboard2 = input()\r\nboard2+=input()\r\n\r\nresults=[]\r\nresults+=[board1]\r\n\r\nprint([\"NO\",\"YES\"][find(board1)])\r\n",
"def find(let, data):\r\n for i in range(2):\r\n for j in range(2):\r\n if data[i][j] == let:\r\n return i, j\r\n\r\n\r\ndata1 = [input(), input()]\r\ndata2 = [input(), input()]\r\na1 = data1[0][0] + data1[0][1] + data1[1][0] + data1[1][1]\r\nb1 = data2[0][0] + data2[0][1] + data2[1][0] + data2[1][1]\r\nind = a1.find('A')\r\nif ind == 0:\r\n sos = a1[1]\r\nelif ind == 1:\r\n sos = a1[3]\r\nelif ind == 2:\r\n sos = a1[0]\r\nelse:\r\n sos = a1[2]\r\nind = b1.find('A')\r\nif ind == 0:\r\n sos1 = b1[1]\r\nelif ind == 1:\r\n sos1 = b1[3]\r\nelif ind == 2:\r\n sos1 = b1[0]\r\nelse:\r\n sos1 = b1[2]\r\nif sos == 'X':\r\n ind = a1.find('X')\r\n if ind == 0:\r\n sos = a1[1]\r\n elif ind == 1:\r\n sos = a1[3]\r\n elif ind == 2:\r\n sos = a1[0]\r\n else:\r\n sos = a1[2]\r\nif sos1 == 'X':\r\n ind = b1.find('X')\r\n if ind == 0:\r\n sos1 = b1[1]\r\n elif ind == 1:\r\n sos1 = b1[3]\r\n elif ind == 2:\r\n sos1 = b1[0]\r\n else:\r\n sos1 = b1[2] \r\nif sos == sos1:\r\n print('YES')\r\nelse:\r\n print('NO')",
"def f(s):\r\n s = s.replace('X', '')\r\n while s[0] != 'A':\r\n s = s[1:] + s[0]\r\n return s\r\nprint('YES' if len({f(input() + input()[::-1]) for i in range(2)}) == 1 else 'NO')",
"one = input() + input()[::-1]\r\ntwo = input() + input()[::-1]\r\none = one.replace(\"X\", \"\")\r\ntwo = two.replace(\"X\", \"\") \r\nprint([\"NO\",\"YES\"][one in two*2])",
"A = input()\r\nA += input()[::-1] # reverse the input and add\r\nA = A.replace('X', '')\r\nB = input()\r\nB += input()[::-1] # reverse the input and add\r\nB = B.replace('X', '')\r\nif B == A or B[1:] + B[0] == A or B[2:] + B[:2] == A:\r\n\tprint (\"YES\")\r\nelse:\r\n\tprint(\"NO\")\r\n",
"a, b, c, d = input(), input(), input(), input()\r\na = a + b[::-1]\r\nx = \"X\"\r\nfor i in range(4):\r\n if a[i] == x:\r\n a = a[:i] + a[i + 1:]\r\n break\r\nc = c + d[::-1]\r\n\r\nfor i in range(4):\r\n if c[i] == x:\r\n c = c[:i] + c[i + 1:]\r\n break\r\nflag = False\r\nfor i in range(4):\r\n if a == c:\r\n flag = True\r\n c = c[1:] + c[0]\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"print('YES' if (input() + ''.join(reversed(input()))).replace('X', '') \\\n in (input() + ''.join(reversed(input()))).replace('X', '') * 2 else 'NO')\n",
"s1 = str(input()) + str(input())\r\ns2 = str(input()) + str(input())\r\ndef f(s):\r\n return 1 if s in [\"ABXC\", \"ABCX\", \"AXCB\", \"XACB\", \"CAXB\", \"XBAC\", \"BXAC\", \"BCAX\", \"BCXA\", \"XCBA\", \"CXBA\", \"CABX\"] else 2\r\nc1 = f(s1)\r\nc2 = f(s2)\r\nprint(\"YES\" if c1 == c2 else \"NO\")",
"from itertools import permutations\r\n\r\n\r\ndef solve():\r\n\r\n b1, b2 = list(input()), list(input())\r\n e1, e2 = list(input()), list(input())\r\n\r\n b2[0], b2[1] = b2[1], b2[0]\r\n e2[0], e2[1] = e2[1], e2[0]\r\n\r\n b = b1 + b2\r\n e = e1 + e2\r\n\r\n b.remove('X')\r\n e.remove('X')\r\n\r\n if str(e).replace('[', '').replace(']', '') in str(b + b):\r\n print('YES')\r\n else:\r\n print('NO')\r\n return\r\n\r\n\r\nsolve()\r\n\r\n",
"import sys\r\nimport string\r\n\r\nfrom collections import Counter, defaultdict\r\nfrom math import fsum, sqrt, gcd, ceil, factorial\r\nfrom operator import *\r\nfrom itertools import accumulate\r\n\r\ninf = float(\"inf\")\r\n# input = sys.stdin.readline\r\nflush = lambda: sys.stdout.flush\r\ncomb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y)\r\n\r\n\r\n# inputs\r\n# ip = lambda : input().rstrip()\r\nip = lambda: input()\r\nii = lambda: int(input())\r\nr = lambda: map(int, input().split())\r\nrr = lambda: list(r())\r\n\r\n\r\na = ip() + ip()[::-1]\r\nb = ip() + ip()[::-1]\r\nx = a.index(\"A\")\r\narr = \"\"\r\nbrr = \"\"\r\nwhile len(arr) != 3:\r\n if a[x] != \"X\":\r\n arr += a[x]\r\n x = (x + 1) % 4\r\n\r\nx = b.index(\"A\")\r\nwhile len(brr) != 3:\r\n if b[x] != \"X\":\r\n brr += b[x]\r\n x = (x + 1) % 4\r\n\r\nprint(\"YES\" if arr == brr else \"NO\")",
"def go(lst):\r\n global cnt, ans, lst2\r\n cnt += 1\r\n if lst == lst2:\r\n ans = 'YES' \r\n if cnt < 800 :\r\n \r\n if lst[0][0] == 23:\r\n lst[0][1], lst[0][0] = lst[0][0], lst[0][1]\r\n go(lst)\r\n lst[0][1], lst[0][0] = lst[0][0], lst[0][1]\r\n \r\n if lst[0][1] == 23:\r\n lst[0][1], lst[1][1] = lst[1][1], lst[0][1]\r\n go(lst)\r\n lst[0][1], lst[1][1] = lst[1][1], lst[0][1]\r\n \r\n if lst[1][1] == 23:\r\n lst[1][1], lst[1][0] = lst[1][0], lst[1][1]\r\n go(lst)\r\n lst[1][1], lst[1][0] = lst[1][0], lst[1][1]\r\n \r\n if lst[1][0] == 23:\r\n lst[0][0], lst[1][0] = lst[1][0], lst[0][0]\r\n go(lst)\r\n lst[0][0], lst[1][0] = lst[1][0], lst[0][0]\r\n\r\n \r\n if lst[0][0] == 23:\r\n lst[0][0], lst[1][0] = lst[1][0], lst[0][0]\r\n go(lst)\r\n lst[0][0], lst[1][0] = lst[1][0], lst[0][0]\r\n \r\n if lst[0][1] == 23:\r\n lst[0][1], lst[0][0] = lst[0][0], lst[0][1]\r\n go(lst)\r\n lst[0][1], lst[0][0] = lst[0][0], lst[0][1]\r\n \r\n if lst[1][1] == 23:\r\n lst[1][1], lst[0][1] = lst[0][1], lst[1][1]\r\n go(lst)\r\n lst[1][1], lst[0][1] = lst[0][1], lst[1][1]\r\n \r\n if lst[1][0] == 23:\r\n lst[1][1], lst[1][0] = lst[1][0], lst[1][1]\r\n go(lst)\r\n lst[1][1], lst[1][0] = lst[1][0], lst[1][1]\r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\ns1 = input()\r\nans = 'NO'\r\ncnt = 0\r\nlst1 = [[], []]\r\nlst1[0] = [ord(i) - ord('A') for i in s1]\r\ns1 = input()\r\nlst1[1] = [ord(i) - ord('A') for i in s1]\r\n\r\ns1 = input()\r\nlst2 = [[], []]\r\nlst2[0] = [ord(i) - ord('A') for i in s1]\r\ns1 = input()\r\nlst2[1] = [ord(i) - ord('A') for i in s1]\r\ngo(lst1)\r\nprint(ans)\r\n",
"ll,kk=[],\"\"\r\nfor _ in range(2):\r\n ll.append(list(input()))\r\nfor _ in range(2):\r\n kk+=input()\r\ni=0\r\nwhile i<1000:\r\n if ll[0][0]==\"X\":\r\n ll[0].reverse()\r\n elif ll[1][1]==\"X\":\r\n ll[1].reverse()\r\n elif ll[1][0]==\"X\":\r\n ll[0][0],ll[1][0]=ll[1][0],ll[0][0]\r\n else:\r\n ll[0][1],ll[1][1]=ll[1][1],ll[0][1]\r\n i+=1\r\n g=\"\".join(ll[0])+\"\".join(ll[1])\r\n if g==kk:\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")",
"def main():\r\n a = list(input()) + list(reversed(list(input())))\r\n b = list(input()) + list(reversed(list(input())))\r\n\r\n a.remove('X')\r\n b.remove('X')\r\n\r\n a *= 2\r\n\r\n a = ''.join(a)\r\n b = ''.join(b)\r\n\r\n print(\"YES\" if b in a else \"NO\")\r\n\r\n\r\nmain()\r\n"
] | {"inputs": ["AB\nXC\nXB\nAC", "AB\nXC\nAC\nBX", "XC\nBA\nCB\nAX", "AB\nXC\nAX\nCB", "CB\nAX\nXA\nBC", "BC\nXA\nBA\nXC", "CA\nXB\nBA\nCX", "CA\nXB\nAC\nBX", "CB\nAX\nCX\nAB", "AX\nCB\nBC\nXA", "CA\nXB\nBA\nXC", "CX\nAB\nAX\nCB", "AB\nXC\nAB\nCX", "XC\nBA\nXC\nAB", "BA\nXC\nAC\nXB", "AX\nBC\nAC\nBX", "XC\nBA\nCB\nXA", "CB\nAX\nXC\nBA", "AX\nCB\nBC\nAX", "AB\nXC\nBX\nAC", "XA\nCB\nBA\nCX", "CX\nBA\nBX\nAC", "AB\nXC\nXC\nAB", "BA\nCX\nAC\nBX", "XA\nCB\nAB\nXC", "XC\nBA\nAC\nBX", "CA\nBX\nBA\nXC", "AX\nBC\nCA\nXB", "BC\nAX\nXC\nBA", "XB\nAC\nBX\nAC", "CX\nBA\nAX\nBC", "XB\nCA\nXC\nBA", "BX\nCA\nXB\nCA", "XB\nAC\nXC\nAB", "CX\nBA\nCX\nBA", "XB\nAC\nCA\nBX", "BA\nXC\nBC\nAX", "AC\nXB\nCX\nBA", "XB\nCA\nCX\nBA", "AB\nCX\nXA\nBC", "CX\nAB\nXB\nAC", "BC\nAX\nAC\nBX", "XA\nBC\nCB\nAX", "XC\nAB\nCB\nAX", "CX\nBA\nCX\nAB", "CA\nBX\nXC\nBA", "CX\nBA\nBA\nXC", "CA\nBX\nCB\nXA", "CB\nAX\nBC\nAX", "CB\nAX\nBC\nXA", "AC\nXB\nCB\nXA", "AB\nCX\nXB\nAC", "CX\nBA\nXB\nAC", "BX\nAC\nAB\nXC", "CX\nAB\nXC\nBA", "XB\nAC\nCX\nAB", "CB\nAX\nXB\nAC", "CB\nAX\nCA\nXB", "XC\nBA\nBA\nXC", "AC\nBX\nCB\nAX", "CA\nBX\nAC\nXB", "BX\nAC\nCX\nBA", "XB\nCA\nAX\nCB", "CB\nXA\nBC\nXA", "AX\nCB\nCX\nAB", "BC\nAX\nXC\nAB", "XB\nCA\nBC\nXA", "XB\nAC\nCX\nBA", "BC\nXA\nCB\nXA", "AX\nCB\nAX\nBC", "CA\nBX\nBX\nCA", "BA\nXC\nXB\nAC", "XA\nBC\nBX\nAC", "BX\nCA\nAC\nBX", "XB\nAC\nXC\nBA", "XB\nAC\nAB\nXC", "BA\nCX\nCX\nBA", "CA\nXB\nXB\nCA", "BA\nCX\nBA\nXC", "BA\nCX\nAB\nCX", "BX\nCA\nXA\nBC", "XC\nBA\nBX\nCA", "XC\nAB\nBC\nXA", "BC\nXA\nXC\nAB", "BX\nCA\nXB\nAC", "BA\nXC\nCA\nXB", "CX\nBA\nAC\nXB", "AB\nCX\nAC\nBX", "BC\nXA\nBX\nCA", "XA\nBC\nCX\nAB", "AX\nBC\nAX\nCB", "CB\nAX\nCA\nBX", "CB\nAX\nBA\nXC", "AB\nCX\nXC\nBA", "AC\nXB\nBA\nCX", "AX\nCB\nCB\nAX", "CX\nBA\nCA\nXB", "AC\nBX\nAB\nXC", "XA\nCB\nXA\nBC", "XC\nBA\nCA\nBX", "XA\nBC\nXB\nCA", "CA\nBX\nCB\nAX"], "outputs": ["YES", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "YES", "YES", "NO", "YES", "NO", "NO", "YES", "YES", "NO"]} | UNKNOWN | PYTHON3 | CODEFORCES | 95 | |
29ecd093ea72b0b060198f59c4a18db5 | Three Sons | Three sons inherited from their father a rectangular corn fiend divided into *n*<=×<=*m* squares. For each square we know how many tons of corn grows on it. The father, an old farmer did not love all three sons equally, which is why he bequeathed to divide his field into three parts containing *A*, *B* and *C* tons of corn.
The field should be divided by two parallel lines. The lines should be parallel to one side of the field and to each other. The lines should go strictly between the squares of the field. Each resulting part of the field should consist of at least one square.
Your task is to find the number of ways to divide the field as is described above, that is, to mark two lines, dividing the field in three parts so that on one of the resulting parts grew *A* tons of corn, *B* on another one and *C* on the remaining one.
The first line contains space-separated integers *n* and *m* — the sizes of the original (1<=≤<=*n*,<=*m*<=≤<=50,<=*max*(*n*,<=*m*)<=≥<=3). Then the field's description follows: *n* lines, each containing *m* space-separated integers *c**ij*, (0<=≤<=*c**ij*<=≤<=100) — the number of tons of corn each square contains. The last line contains space-separated integers *A*,<=*B*,<=*C* (0<=≤<=*A*,<=*B*,<=*C*<=≤<=106).
Print the answer to the problem: the number of ways to divide the father's field so that one of the resulting parts contained *A* tons of corn, another one contained *B* tons, and the remaining one contained *C* tons. If no such way exists, print 0.
Sample Input
3 3
1 1 1
1 1 1
1 1 1
3 3 3
2 5
1 1 1 1 1
2 2 2 2 2
3 6 6
3 3
1 2 3
3 1 2
2 3 1
5 6 7
Sample Output
2
3
0
| [
"import sys\r\ninput = sys.stdin.readline\r\nfrom itertools import permutations\r\n\r\nf = open('input.txt', 'r')\r\nn, m = map(int, f.readline().split())\r\ng = [list(map(int, f.readline().split())) for _ in range(n)]\r\nw = list(zip(*g))\r\ng = [sum(i) for i in g]\r\nw = [sum(i) for i in w]\r\ns = set(permutations(map(int, f.readline().split()), 3))\r\n\r\nx = 0\r\nfor i in range(1, n-1):\r\n for j in range(i+1, n):\r\n a = sum(g[:i])\r\n b = sum(g[i:j])\r\n c = sum(g[j:])\r\n if (a, b, c) in s:\r\n x += 1\r\n\r\nfor i in range(1, m-1):\r\n for j in range(i+1, m):\r\n a = sum(w[:i])\r\n b = sum(w[i:j])\r\n c = sum(w[j:])\r\n if (a, b, c) in s:\r\n x += 1\r\n \r\nf = open('output.txt', 'w')\r\nprint(x, file=f)",
"# /**\r\n# * author: brownfox2k6\r\n# * created: 16/05/2023 23:24:55 Hanoi, Vietnam\r\n# **/\r\nimport sys\r\nsys.stdin = open(\"input.txt\")\r\nsys.stdout = open(\"output.txt\", \"w\")\r\n\r\nn, m = map(int, input().split())\r\na = [list(map(int, input().split())) for _ in range(n)]\r\nr = sorted(map(int, input().split()))\r\nans = 0\r\n\r\nfor i in range(2):\r\n # Loop xong một vòng thì xoay chiều matrix\r\n if i == 1:\r\n a = zip(*a)\r\n\r\n # Tính tổng từng row\r\n s = list(map(sum, a))\r\n\r\n for i in range(1, len(s)-1):\r\n for j in range(i+1, len(s)):\r\n c = map(sum, [s[:i], s[i:j], s[j:]])\r\n ans += (sorted(c) == r)\r\n\r\nprint(ans)",
"import sys\r\nimport itertools\r\nfrom typing import List\r\n\r\n\r\ndef get_ans(sums: List[int], a, b, c):\r\n try:\r\n if sums[-1] != a + b + c:\r\n return 0\r\n ind = sums.index(a)\r\n ans = 0\r\n while ind + 1 < len(sums) and sums[ind] == a:\r\n try:\r\n ind2 = sums.index(a + b, ind + 1)\r\n while ind2 < len(sums) and sums[ind2] == a + b:\r\n if ind2 < len(sums) - 1:\r\n ans += 1\r\n ind2 += 1\r\n ind += 1\r\n except:\r\n break\r\n return ans\r\n except:\r\n return 0\r\n\r\n\r\nsys.stdin = open('input.txt', 'r')\r\nsys.stdout = open('output.txt', 'w')\r\n\r\nn, m = [int(x) for x in input().split()]\r\nls = []\r\nfor i in range(n):\r\n ls.append([int(x) for x in input().split()])\r\n\r\nparts = [int(x) for x in input().split()]\r\n\r\nhorizontal_sums = [sum(ls[i]) for i in range(n)]\r\nfor i in range(1, n):\r\n horizontal_sums[i] = horizontal_sums[i] + horizontal_sums[i - 1]\r\n\r\nvertical_sums = [0] * m\r\ns = 0\r\nfor i in range(m):\r\n for j in range(n):\r\n s += ls[j][i]\r\n vertical_sums[i] = s\r\n\r\nans = 0\r\nfor l in set(itertools.permutations(parts, 3)):\r\n ans += get_ans(horizontal_sums, *l)\r\n ans += get_ans(vertical_sums, *l)\r\nprint(ans)\r\n"
] | {"inputs": ["3 3\n1 1 1\n1 1 1\n1 1 1\n3 3 3", "2 5\n1 1 1 1 1\n2 2 2 2 2\n3 6 6", "3 3\n1 2 3\n3 1 2\n2 3 1\n5 6 7", "3 3\n0 0 0\n0 0 1\n1 1 0\n2 1 0", "3 3\n0 0 0\n0 1 0\n0 0 0\n1 0 0", "3 2\n0 0\n0 2\n0 0\n2 0 0", "3 2\n0 1\n2 1\n0 1\n3 1 1", "5 10\n0 1 4 4 4 1 4 0 0 4\n1 1 2 0 4 4 2 2 0 3\n3 2 4 0 3 0 1 3 1 0\n4 1 2 3 0 2 0 2 0 1\n4 4 4 0 2 4 3 1 3 2\n10 78 12", "5 10\n0 0 0 0 0 0 0 0 0 0\n0 2 0 1 0 5 0 3 0 4\n0 0 0 0 0 0 0 0 0 0\n0 2 0 4 0 3 0 3 0 2\n0 0 0 0 0 0 0 0 0 0\n0 15 14", "10 10\n2 0 1 5 5 0 4 1 2 0\n3 5 2 5 4 0 2 3 4 0\n4 0 3 0 5 1 2 3 4 4\n1 3 2 0 5 2 4 3 5 0\n5 0 1 5 1 4 4 2 1 2\n3 2 0 4 0 0 0 1 2 4\n3 3 2 2 5 5 2 0 4 3\n3 0 2 5 4 2 5 3 1 4\n2 3 0 3 1 1 0 0 1 4\n3 2 3 5 3 1 0 3 5 5\n45 124 74", "10 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0", "10 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0", "10 10\n0 0 0 0 0 0 0 0 0 0\n0 6 0 6 0 1 0 4 0 1\n0 0 0 0 0 0 0 0 0 0\n0 4 0 1 0 3 0 4 0 1\n0 0 0 0 0 0 0 0 0 0\n0 3 0 5 0 1 0 2 0 5\n0 0 0 0 0 0 0 0 0 0\n0 1 0 6 0 3 0 4 0 5\n0 0 0 0 0 0 0 0 0 0\n0 3 0 6 0 2 0 4 0 6\n0 69 18", "10 15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n5 20 10", "10 15\n2 91 9 36 34 23 88 86 19 91 29 41 39 47 9\n66 63 69 60 73 19 93 78 15 38 70 39 36 4 49\n93 4 25 32 31 49 33 76 22 83 60 49 47 27 20\n34 9 29 85 84 59 8 87 92 5 44 4 60 63 74\n92 50 27 78 62 88 2 50 95 29 37 3 42 72 80\n41 72 35 1 35 85 42 64 41 79 58 2 41 4 11\n2 3 19 77 97 52 74 37 16 58 57 44 14 94 41\n5 47 75 72 49 52 41 48 59 56 38 54 81 9 50\n54 6 46 52 39 79 30 52 79 68 76 40 44 38 68\n7 12 11 87 78 23 47 14 27 83 83 14 84 54 69\n289 5446 1371", "30 2\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0 0", "30 2\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n12 2 1", "30 2\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n34 34\n1836 68 136", "40 4\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n0 0 0 0\n0 1 0 1\n34 4 2", "40 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0"], "outputs": ["2", "3", "0", "1", "2", "1", "1", "2", "5", "3", "127", "127", "6", "24", "0", "406", "24", "6", "24", "744"]} | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
29f9d8a3d36ed0108307535ffacebc46 | Find Maximum | Valera has array *a*, consisting of *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1, and function *f*(*x*), taking an integer from 0 to 2*n*<=-<=1 as its single argument. Value *f*(*x*) is calculated by formula , where value *bit*(*i*) equals one if the binary representation of number *x* contains a 1 on the *i*-th position, and zero otherwise.
For example, if *n*<==<=4 and *x*<==<=11 (11<==<=20<=+<=21<=+<=23), then *f*(*x*)<==<=*a*0<=+<=*a*1<=+<=*a*3.
Help Valera find the maximum of function *f*(*x*) among all *x*, for which an inequality holds: 0<=≤<=*x*<=≤<=*m*.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of array elements. The next line contains *n* space-separated integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (0<=≤<=*a**i*<=≤<=104) — elements of array *a*.
The third line contains a sequence of digits zero and one without spaces *s*0*s*1... *s**n*<=-<=1 — the binary representation of number *m*. Number *m* equals .
Print a single integer — the maximum value of function *f*(*x*) for all .
Sample Input
2
3 8
10
5
17 0 10 2 1
11010
Sample Output
3
27
| [
"n = int(input())\na = list(map(int, input().split()))\nk = input()\npref = [a[0]]\nfor i in range(1, n):\n pref.append(pref[-1] + a[i])\ncur = 0\nans = 0\nfor i in range(n - 1, -1, -1):\n if k[i] == '0':\n continue\n if cur + (pref[i - 1] if i > 0 else 0) > ans:\n ans = cur + (pref[i - 1] if i > 0 else 0)\n cur += a[i]\ncur = 0\nfor i in range(n):\n if k[i] == '1':\n cur += a[i]\nans = max(ans, cur)\nprint(ans)\n",
"from sys import stdin\r\nfrom itertools import accumulate\r\n\r\n\r\ndef arr_enu():\r\n return [[i, int(x)] for i, x in enumerate(stdin.readline().split())]\r\n\r\n\r\ndef get_col(arr, i):\r\n return [row[i] for row in arr]\r\n\r\n\r\ndef arr_sum(arr):\r\n arr.insert(0, 0)\r\n return list(accumulate(arr, lambda x, y: x + y))\r\n\r\n\r\ndef fun(x, y):\r\n return int(x) * y[1]\r\n\r\n\r\nn, a, s = int(stdin.readline()), arr_enu(), stdin.readline()\r\ncum, cum2 = arr_sum(get_col(a, 1)), arr_sum(list(map(fun, s, a)))\r\nans = cum2[-1]\r\n\r\nfor i in range(n - 1, -1, -1):\r\n if s[i] == '1':\r\n ans = max(ans, cum[i] + (cum2[-1] - cum2[i + 1]))\r\n\r\nprint(ans)\r\n",
"import sys\r\n\r\n\r\n\r\ndef prefix_sum(values):\r\n res = [0] * (len(values) + 1)\r\n for i in range(len(values)):\r\n res[i + 1] = values[i] + res[i]\r\n return res\r\n\r\ndef main():\r\n read = sys.stdin.readline\r\n n = int(read())\r\n\r\n values = [int(i) for i in read().split()]\r\n # The binary string is given to us in reversed order -> i.e the msb is the last digit instead of the first\r\n binary_string = read().strip()\r\n total = 0\r\n for i in range(len(values)):\r\n total += values[i] * int(binary_string[i])\r\n\r\n prefix_sum_arr = prefix_sum(values)\r\n sum_from_the_right = 0\r\n for i in range(len(values) - 1, -1, -1):\r\n if binary_string[i] == '0':\r\n # Nothing to do\r\n continue\r\n else:\r\n # Make the current digit 0. Say the number (in correct binary order) is 100110, then we know that\r\n # 001111 is less than it and a valid option\r\n # Compute the sum assuming that all numbers after it are now 1 (not ehtat bc the binary is reversed,\r\n # this means that the numbers before it will all be 1\r\n curr_total = prefix_sum_arr[i] + sum_from_the_right\r\n total = max(curr_total, total)\r\n # Update sum from the right to include this value\r\n sum_from_the_right += values[i]\r\n\r\n\r\n\r\n\r\n print(total)\r\n\r\nif __name__ == '__main__':\r\n main()\r\n\r\n\r\n",
"# link: https://codeforces.com/contest/353/problem/C\r\n\r\nfor _ in range(1):\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n s = input()\r\n b = a[:]\r\n one_location = []\r\n for i in range(n):\r\n if s[i] == \"1\": one_location.append(i)\r\n for i in range(1,n):\r\n a[i] += a[i-1]\r\n a.append(0)\r\n right = 0\r\n ans = 0\r\n for j in reversed(range(len(one_location))):\r\n ans = max(ans, a[one_location[j] - 1] + right)\r\n right += b[one_location[j]]\r\n print(max(ans, right)) ",
"def main():\r\n input()\r\n a = [int(c) for c in input().split()]\r\n s = list(input())\r\n\r\n sum_ = ans = 0\r\n for a_i, s_i in zip(a, s):\r\n if s_i == '1':\r\n ans = max(ans + a_i, sum_)\r\n sum_ += a_i\r\n\r\n\r\n print(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"m = int(input())\nlistValue = input().split()\nx = input().rstrip('\\n')\n\nvalues = [int(v) for v in listValue]\nreverse_x = list(x)\nreverse_int = [int(s) for s in reverse_x]\nreverse_list = [0] * m\nsum_list = 0\nfor i in range(m):\n if reverse_x[i] == '1':\n reverse_list[i] = max(reverse_list[i - 1] + values[i], sum_list)\n else:\n reverse_list[i] = reverse_list[i - 1]\n sum_list += values[i]\n\nprint(reverse_list[-1])\n",
"n = int(input())\r\na = [0] + list(map(int, input().split()))\r\ns = '0' + input()\r\n\r\nsum1 = [0]*(n+1)\r\nsum2 = [0]*(n+1)\r\n\r\nfor i in range(n+1):\r\n sum1[i] = sum1[i-1] + a[i]\r\n\r\nfor i in range(n+1):\r\n sum2[i] = sum2[i-1]\r\n if s[i] == '1':\r\n sum2[i] += a[i]\r\n\r\nans = sum2[n]\r\n\r\nfor i in range(0, n+1):\r\n if s[i] == '1':\r\n ans = max(ans, sum1[i-1] + sum2[n] - sum2[i])\r\n\r\nprint(ans)",
"n = int(input())\r\na = list(map(int, input().split()))\r\ncum_sum = [0] * (n+1)\r\nact_sum = [0] * (n+1)\r\nm = list(input())\r\nfor i in range(n):\r\n cum_sum[i+1] = cum_sum[i] + a[i]\r\n act_sum[i+1] = act_sum[i]\r\n if m[i] == '1':\r\n act_sum[i+1] += a[i]\r\nres = 0\r\nfor i in range(n-1, -1, -1):\r\n if m[i] == '1':\r\n res = max(res, cum_sum[i] - act_sum[i+1])\r\nprint(res + act_sum[n])\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nm = input()\r\ns1,s=0,0\r\nfor i,j in zip(arr,m):\r\n if j=='1':\r\n s = max(s+i, s1)\r\n s1 += i\r\nprint(s)",
"from sys import stdin\r\n\r\n\r\ndef main():\r\n n = int(stdin.readline())\r\n ar = list(map(int, stdin.readline().split()))\r\n ar.reverse()\r\n s = list(input())\r\n s.reverse()\r\n pre = [0] * n\r\n if s[0] == '1':\r\n pre[0] = ar[0]\r\n for i in range(1, n):\r\n if s[i] == '1':\r\n pre[i] = pre[i - 1] + ar[i]\r\n else:\r\n pre[i] = pre[i - 1]\r\n post = [0] * n\r\n post[n - 1] = ar[n - 1]\r\n for i in range(n - 2, -1, -1):\r\n post[i] = post[i + 1] + ar[i]\r\n ans = pre[n - 1]\r\n for i in range(n - 2, -1, -1):\r\n if s[i] == '1':\r\n ans = max(ans, pre[i] - ar[i] + post[i + 1])\r\n print(ans)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"n = int(input())\r\na = list(map(int, input().split(\" \")))[::-1]\r\nm = input()[::-1]\r\n\r\nsumall = [0]*(n+1)\r\nfor x, ai in enumerate(reversed(a)):\r\n i = n-1 - x\r\n sumall[i] = sumall[i+1]+ai\r\n\r\nsumm = [0]*(n+1)\r\nfor i, ai in enumerate(a):\r\n summ[i] = summ[i-1]\r\n if(m[i] == '1'):\r\n summ[i] += ai\r\n\r\nmaxval = summ[n-1]\r\n\r\nfor i in range(n):\r\n \r\n if m[i]== '1' and maxval < summ[i-1] + sumall[i+1]:\r\n maxval = summ[i-1] + sumall[i+1] \r\n\r\nprint(maxval)\r\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = list(map(int, input().split()))\r\ns = input()[:-1]\r\n\r\nif '1' in s:\r\n a = s.rindex('1')\r\n b, c = 0, 0\r\n for i in range(a+1):\r\n if s[i] == '0':\r\n b += w[i]\r\n else:\r\n c += w[i]\r\n q = c\r\n x = 0\r\n for i in range(a, -1, -1):\r\n if s[i] == '0':\r\n b -= w[i]\r\n else:\r\n x = max(x, b-w[i])\r\n print(q+x)\r\nelse:\r\n print(0)",
"# import math\nfrom collections import Counter, deque, defaultdict\n# from math import *\n\nfrom bisect import bisect_right\n\nMOD = 1000000007\n\n\n# from functools import reduce\n# from itertools import permutations\n# import queue\n\ndef solve():\n n=int(input())\n s=list(map(int,input().split()))\n bits=input()\n res,m=0,0\n for i in range(len(bits)):\n if bits[i]=='1':\n res = max(res+s[i],m)\n m+=s[i]\n print(res)\n\n\n\n\n\n# t = int(input())\nt = 1\nfor num in range(t):\n # print(\"Case #{}: \".format(num + 1), end=\"\")\n solve()\n\n\t \t\t \t\t\t\t\t\t\t \t \t \t \t\t",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = input()\r\n \r\nans = 0\r\nsm = 0\r\n \r\nfor i in range(n):\r\n if s[i] == '1':\r\n ans = max(ans + a[i], sm)\r\n sm += a[i]\r\n \r\nprint(ans)",
"n = int(input())\r\ns = list(map(int, input().split()))\r\nbit = input()\r\nres, m = 0, 0\r\nfor i in range(len(bit)):\r\n if bit[i] == '1':\r\n res = max(s[i] + res, m)\r\n m += s[i]\r\nprint(res)",
"\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\ns = input()\r\npref = [0] + l[:]\r\nfor i in range(1, n+1):\r\n pref[i] += pref[i-1]\r\n# print(pref)\r\nans = 0\r\nsum = 0\r\nfor i in range(n-1, -1, -1):\r\n if s[i] == '1':\r\n # print(sum, pref[i])\r\n ans = max(ans, sum+pref[i])\r\n sum += l[i]\r\nprint(max(ans, sum))\r\n",
"n = int(input())\r\nelems = [int(i) for i in input().split()]\r\n\r\nacum = []\r\nacum.append(elems[0])\r\nfor i in range(1,n):\r\n acum.append(elems[i] + acum[i-1])\r\n\r\nm = input()\r\ndp = [0 for i in range(n)]\r\ndp[0] = elems[0] * int(m[0])\r\n\r\nfor i in range(1,n):\r\n dp[i] = dp[i-1] + elems[i] * int(m[i])\r\n if m[i] == '1':\r\n dp[i] = max(dp[i], acum[i-1])\r\n\r\nprint(dp[n-1])",
"n = int(input()) \r\narr = list(map(int, input().split())) \r\ns = list(input())\r\ncs = [i for i in arr]\r\nfor i in range(1, n): cs[i] += cs[i-1] \r\nans = 0\r\nfor i in range(n) : \r\n ans += arr[i] * int(s[i])\r\nc = cur = 0 \r\nfor i in range(n-1, 0, -1) : \r\n if int(s[i]) : \r\n c = max(arr[i], cs[i-1])\r\n ans = max(cur* int(s[i]) + c, ans)\r\n cur += arr[i] * int(s[i])\r\nprint(ans)\r\n\r\n\r\n",
"import sys\r\nimport string\r\nimport math\r\nimport heapq\r\nfrom collections import defaultdict\r\nfrom collections import deque\r\nfrom collections import Counter\r\nfrom functools import lru_cache\r\nfrom fractions import Fraction\r\n\r\ndef mi(s):\r\n return map(int, s.strip().split())\r\n\r\ndef lmi(s):\r\n return list(mi(s))\r\n\r\ndef tmi(s):\r\n return tuple(mi(s))\r\n\r\ndef mf(f, s):\r\n return map(f, s)\r\n\r\ndef lmf(f, s):\r\n return list(mf(f, s))\r\n\r\ndef js(lst):\r\n return \" \".join(str(d) for d in lst)\r\n\r\ndef jsns(lst):\r\n return \"\".join(str(d) for d in lst)\r\n\r\ndef line():\r\n return sys.stdin.readline().strip()\r\n\r\ndef linesp():\r\n return line().split()\r\n\r\ndef iline():\r\n return int(line())\r\n\r\ndef mat(n):\r\n matr = []\r\n for _ in range(n):\r\n matr.append(linesp())\r\n return matr\r\n\r\ndef matns(n):\r\n mat = []\r\n for _ in range(n):\r\n mat.append([c for c in line()])\r\n return mat\r\n\r\ndef mati(n):\r\n mat = []\r\n for _ in range(n):\r\n mat.append(lmi(line())) \r\n return mat\r\n\r\ndef pmat(mat):\r\n for row in mat:\r\n print(js(row))\r\n\r\ndef main():\r\n line()\r\n arr = lmi(line())\r\n bits = line()\r\n\r\n curr_best = 0\r\n bit_sum = {-1: 0}\r\n for e, temp in enumerate(zip(arr, bits)):\r\n val, bit = temp\r\n if bit == '1':\r\n curr_best += val\r\n bit_sum[e] = curr_best\r\n\r\n cum_sum = {-1: 0}\r\n for e, n in enumerate(arr):\r\n cum_sum[e] = cum_sum[e - 1] + n\r\n\r\n for e, bit in enumerate(bits):\r\n if bit == '1':\r\n # print(e, cum_sum[e - 1], bit_sum[len(bits) - 1], bit_sum[e])\r\n # Let this be the right most bit\r\n # we flip in the optimal solution.\r\n # We can add everything to the left of it.\r\n new_best = cum_sum[e - 1] + bit_sum[len(bits) - 1] - bit_sum[e]\r\n curr_best = max(curr_best, new_best)\r\n print(curr_best)\r\nmain()\r\n",
"n = int(input())\n\na = list(map(int, input().split()))\n\nm = input()\n\n\n\nres, summ = 0, 0\n\n\n\nfor i, bit in enumerate(m):\n\n if bit == '1':\n\n res = max(res + a[i], summ) # try to add\n\n summ += a[i]\n\n\n\nprint(res)\n\n\n\n# Made By Mostafa_Khaled",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nm = input()\r\ns1 = 0\r\norgpre = [0]\r\nactpre = [0]\r\nfor i in range(n):\r\n if m[i] == '1':\r\n s1 += arr[i]\r\n actpre.append(actpre[-1]+arr[i])\r\n else:\r\n actpre.append(actpre[-1])\r\n orgpre.append(orgpre[-1]+arr[i])\r\nfor i in range(n-1,-1,-1):\r\n if m[i] == '1':\r\n s = (actpre[n]-actpre[i+1])+(orgpre[i])\r\n s1 = max(s, s1)\r\nprint(s1)",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom itertools import accumulate\r\n\r\nN = int(input())\r\nA = list(map(int, input().split()))\r\nsums = [0]+list(accumulate(A))\r\n\r\nS = input()\r\nans = 0\r\nfor i in range(N):\r\n if S[i]=='1':\r\n ans+=A[i]\r\n \r\ncur = 0\r\nfor i in range(N-1,-1,-1):\r\n if S[i]=='1':\r\n ans = max(ans, sums[i]+cur)\r\n cur+=A[i]\r\n \r\nprint(ans)\r\n\r\n\r\n\r\n",
"def main():\r\n n = int(input())\r\n a = list(map(int, input().split())) + [0]\r\n s = input() + \"0\"\r\n\r\n t = 0\r\n full_sum = [t := t + x for x in a]\r\n t = 0\r\n raw_sum = [t := t + (x if s[i] == '1' else 0) for i, x in enumerate(a)]\r\n\r\n result = raw_sum[n]\r\n for i in range(n - 1, -1, -1):\r\n if s[i] == '1':\r\n result = max(result, (raw_sum[n] - raw_sum[i]) +\r\n max(raw_sum[i], (full_sum[i - 1] if i > 0 else 0)))\r\n\r\n print(result)\r\n\r\n\r\nmain()\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = [0] + a\r\nfor i in range(1, n + 1):\r\n b[i] += b[i - 1]\r\nt = input()\r\ns, m, i = 0, 0, t.rfind('1')\r\nwhile i >= 0: \r\n d = b[i] + s\r\n if d > m: m = d\r\n if d + a[i] < m: break\r\n s += a[i]\r\n i = t[: i].rfind('1')\r\nprint(max(m, s))",
"from sys import stdin, stdout\nrd = lambda: list(map(int, stdin.readline().split()))\nrds = lambda: stdin.readline().rstrip()\nii = lambda: int(stdin.readline())\n\nn = ii()\na = rd()\nm = rds()\n\nval1 = 0\n\nps = [0]\nps2 = [0]\nind = []\nfor i in range(n):\n if m[i] == '1':\n val1 += a[i]\n ind.append(i)\n ps2.append(ps2[-1] + a[i])\n\n ps.append(ps[-1] + a[i])\n\n# we can zero a higher bit and set to 1 all lower bits\nmax_res = 0\nfor ii in range(1, len(ind)):\n i = ind[ii]\n # delete ii th 1\n # ps[i] = sum of a[j], j < i\n # ps[-1] = f(m)\n # ps[ii+1] - val of f if we took first bits up to the ii'th one\n res = ps[i] + ps2[-1] - ps2[ii+1]\n max_res = max(res, max_res)\n\nprint(max(val1, max_res))\n",
"N = int(input())\ndata = [int(i) for i in input().split()]\nM = input()\nSgood = [0] * N\nSgood[0] = max(data[0], 0)\nfor i in range(1, N):\n Sgood[i] = Sgood[i - 1] + max(data[i], 0)\n\nSorig = [0] * N\nSorig[0] = max(data[0] if M[0] == '1' else 0, 0)\nfor i in range(1, N):\n Sorig[i] = Sorig[i - 1] + max(data[i] if M[i] == '1' else 0, 0)\n\nanswer = Sorig[-1]\nfor i in range(1, N):\n if M[i] == '1':\n answer = max((answer, Sgood[i - 1] + Sorig[-1] - Sorig[i]))\n\nprint(answer)\n",
"n = int(input())\nnums = list(map(int, input().split()))\ns = input()\nans = 0\nfor i in range(n):\n if s[i] == '1':\n ans += nums[i]\ncur = 0\npa = ans\nfor i in range(n):\n if s[i] == '1':\n ans = max(ans, pa+cur-nums[i])\n else:\n cur += nums[i]\nprint(ans)\n\n\n \t \t\t \t \t \t \t \t \t\t\t\t \t",
"#!/usr/bin/python3\n\ndef readln(): return tuple(map(int, input().split()))\n\nn, = readln()\na = readln()\ns = [0] * (n + 1)\nsm = [0] * (n + 1)\nm = list(input())\nfor i in range(n):\n s[i + 1] = s[i] + a[i]\n sm[i + 1] = sm[i] + (a[i] if m[i] == '1' else 0)\nans = sm[n]\nfor i in range(n - 1, -1, -1):\n if m[i] == '1':\n ans = max(ans, s[i] + sm[n] - sm[i + 1])\nprint(ans)\n",
"from itertools import accumulate\r\nfrom os import path\r\nfrom sys import stdin, stdout\r\n\r\n\r\nfilename = \"../templates/input.txt\"\r\nif path.exists(filename):\r\n stdin = open(filename, 'r')\r\n\r\n\r\ndef input():\r\n return stdin.readline().rstrip()\r\n\r\n\r\ndef print(*args, sep=' ', end='\\n'):\r\n stdout.write(sep.join(map(str, args)))\r\n stdout.write(end)\r\n\r\n\r\ndef solution():\r\n n = int(input())\r\n nums = [int(num) for num in input().split()]\r\n s = input()\r\n pref = list(accumulate(nums, initial=0))\r\n best = sum(nums[i] if s[i] == '1' else 0 for i in range(n))\r\n total = 0\r\n for i in range(n - 1, -1, -1):\r\n if s[i] == '1':\r\n best = max(best, total + pref[i])\r\n total += nums[i]\r\n print(best)\r\n\r\n\r\n\r\ndef main():\r\n t = 1\r\n while t:\r\n solution()\r\n t -= 1\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"\r\ndef main():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n k = input()\r\n ans, s = 0, 0\r\n for i in range(n):\r\n if k[i] == \"1\":\r\n ans = max(ans + a[i], s)\r\n s += a[i]\r\n print(ans)\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"from sys import exit\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ns = input()\r\n\r\nprefix = [0] * n\r\nprefix[0] = a[0]\r\nfor i in range(1, n):\r\n prefix[i] = prefix[i - 1] + a[i]\r\n\r\nlast = 0\r\nansw = 0\r\n\r\nif len(s) > n:\r\n print(sum(a))\r\n exit(0)\r\n\r\nfor i, x in enumerate(s):\r\n if x == '1':\r\n last = i\r\n answ += a[i] * int(x)\r\n\r\ntotal = 0\r\nfor i in range(last, 0, -1):\r\n if s[i] == '0': continue\r\n answ = max(answ, total + prefix[i - 1])\r\n total += a[i]\r\n\r\nprint(answ)\r\n"
] | {"inputs": ["2\n3 8\n10", "5\n17 0 10 2 1\n11010", "18\n4382 3975 9055 7554 8395 204 5313 5739 1555 2306 5423 828 8108 9736 2683 7940 1249 5495\n110001100101110111", "43\n475 2165 8771 7146 8980 7209 9170 9006 6278 6661 4740 6321 7532 6869 3788 7918 1707 5070 3809 5189 2494 8255 1123 3197 190 5712 9873 3286 9997 133 9030 3067 8043 5297 5398 4240 8315 2141 1436 3297 247 8438 2300\n0111011100100011110010011110011011010001101", "1\n0\n1", "1\n1\n0", "1\n1\n1", "1\n0\n0", "2\n10000 10000\n11", "2\n10000 9999\n10", "2\n9999 10000\n10", "2\n10000 10000\n00"], "outputs": ["3", "27", "88691", "222013", "0", "0", "1", "0", "20000", "10000", "9999", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 31 | |
2a130954f3cc1e321e7e8e7593c5ef5a | Milking cows | Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).
Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right.
Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Sample Input
4
0 0 1 0
5
1 0 1 0 1
Sample Output
13 | [
"from math import inf\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nsm = [0]\r\nfor x in a: sm.append(sm[-1]+x)\r\n\r\nans1 = ans2 = 0\r\nfor i in range(1, n+1):\r\n if a[i-1] == 0:\r\n ans1 += sm[i-1]\r\n\r\nfor i in range(1, n+1):\r\n if a[i-1] == 1:\r\n ans2 += n-i-(sm[n]-sm[i])\r\n\r\nprint(min(ans1, ans2))",
"def solve():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n count_arr = [0] * n\r\n zero_count = 0\r\n for _ in range(n):\r\n if arr[n - _ - 1] == 0:\r\n zero_count += 1\r\n count_arr[n - _ - 1] = zero_count\r\n\r\n ans = 0\r\n for _ in range(n):\r\n if arr[_] == 1:\r\n ans += count_arr[_]\r\n print(ans)\r\n\r\n\r\nsolve()\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=0\r\nc=0\r\nd=0\r\ne=0\r\nfor i in range(n):\r\n b+=a[i]\r\n c+=b*(1-a[i])\r\nfor i in range(n-1,-1,-1):\r\n d+=1-a[i]\r\n e+=d*a[i]\r\nprint(min(c,e))",
"n = int(input())\r\nlst = list(map(int,input().split()))\r\n\r\ndp_0 = [0 for i in range(n)]\r\ndp_1 = [0 for i in range(n)]\r\n\r\n\r\ncount_1 = 0 \r\nfor i in range(n):\r\n dp_1[i] = count_1\r\n count_1+=lst[i]\r\n \r\n\r\ncount_0 = 0\r\nfor i in range(n-1,-1,-1):\r\n dp_0[i] = count_0\r\n if(lst[i]==0):\r\n count_0+=1\r\n\r\nnum_0 = 0\r\nnum_1 = 0\r\n\r\ntotal_0 = 0\r\ntotal_1 = 0 \r\n\r\nfor i in range(n):\r\n if(lst[i]==1):\r\n total_1 = total_1+dp_0[i]+dp_1[i]\r\n total_1 =total_1 - (n-i-1-dp_0[i])\r\n \r\n else:\r\n total_0 = total_0 +dp_0[i]+dp_1[i]\r\n total_0 = total_0 - (i-dp_1[i])\r\n \r\n \r\n \r\n# print(total_1,total_0)\r\n\r\nprint(min(total_1,total_0))\r\n \r\n \r\n \r\n",
"n = int(input())\na = [int(x) for x in input().split()]\nans = 0\nr = 0\nfor x in a:\n\tif x == 1:\n\t\tr += 1\n\telse:\n\t\tans += r\nprint(ans)\n",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nN = int(input())\r\nA = list(map(int, input().split()))\r\n\r\na1,b1=[0]*N,[0]*N\r\nfor i in range(1,N):\r\n if A[i-1]==1:\r\n a1[i]=a1[i-1]+1\r\n else:\r\n a1[i]=a1[i-1]\r\nfor i in range(N-2,-1,-1):\r\n if A[i+1]==0:\r\n b1[i]=b1[i+1]+1\r\n else:\r\n b1[i]=b1[i+1]\r\n\r\nans = float('inf')\r\ntmp = 0\r\nfor i in range(N):\r\n if A[i]==0:\r\n tmp+=a1[i]\r\nans = min(ans, tmp) \r\ntmp = 0\r\nfor i in range(N):\r\n if A[i]==1:\r\n tmp+=b1[i]\r\nans = min(ans, tmp) \r\nprint(ans)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=[0,0]\r\nans=0\r\nfor i in range(n):\r\n b[a[i]]+=1\r\n if a[i]==0: ans+=b[1]\r\nprint(ans)\r\n",
"\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn = int(input())\r\nw = input()[:-1].split()\r\na = w.count('1')\r\nb = n-a\r\nc1, c2 = 0, 0\r\nfor i in w[::-1]:\r\n if i == '1':\r\n a -= 1\r\n else:\r\n c1 += a\r\nfor i in w:\r\n if i == '0':\r\n b -= 1\r\n else:\r\n c2 += b\r\nprint(min(c1, c2))\r\n",
"n = int(input())\nls = list(map(int,input().split()))\ncnt = 0;ans = 0\nfor i in ls:\n if i == 0:\n ans += cnt\n elif i==1:\n cnt += 1\nprint(ans)\n \t \t \t\t \t\t\t \t \t\t\t \t \t",
"def main():\n input()\n i = res = 0\n for c in input()[::2]:\n if c == \"1\":\n i += 1\n else:\n res += i\n print(res)\n\n\nif __name__ == '__main__':\n main()\n",
" \r\ndef P0122_cow_milk(n,a):\r\n ans = 0\r\n r = 0\r\n for x in a:\r\n if x == 1:\r\n r += 1\r\n else:\r\n ans += r\r\n return(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n a = [int(x) for x in input().split()]\r\n result = P0122_cow_milk(n,a)\r\n print(result)\r\n",
"__author__ = 'Pavel Mavrin'\n\nn = int(input())\na = [int(x) for x in input().split()]\n\ns = 0\nres = 0\nfor i in a:\n if i == 0:\n res += s\n else:\n s += 1\n\nprint(res)\n",
"n=int(input())\r\ncnt=0\r\ns=0\r\nl=[int(i) for i in input().split()]\r\nfor i in range(n):\r\n\tif l[i]==1:\r\n\t\tcnt+=1\r\n\telse:\r\n\t\ts+=cnt\r\nprint(s)",
"from collections import *\r\nfrom math import *\r\n\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nct0,res0 = 0,0\r\nfor i in range(n):\r\n\tif(a[i] == 1): ct0 += 1\r\n\telse: res0 += ct0\r\nct1,res1 = 0,0\r\nfor i in range(n-1,-1,-1):\r\n\tif(a[i] == 0): ct1 += 1\r\n\telse: res1 += ct1\r\nprint(min(res0,res1))",
"a=int(input())\r\nz=list(map(int,input().split()))\r\nans=[z[0]]\r\nfor i in range(1,len(z)):\r\n ans.append(ans[-1]+z[i])\r\n\r\nscore=0\r\nfor i in range(len(z)):\r\n if(z[i]==0):\r\n score+=ans[i]\r\nprint(score)\r\n",
"n=int(input())\r\nl=[int(i) for i in input().split()]\r\nzeroes=[0]*n \r\nif l[-1]==0:\r\n zeroes[n-1]=1 \r\nelse:\r\n zeroes[n-1]=0 \r\nfor i in range(n-2,-1,-1):\r\n zeroes[i]=zeroes[i+1]\r\n if l[i]==0:\r\n zeroes[i]+=1 \r\ncnt=0 \r\nfor i in range(n):\r\n if l[i]==1:\r\n cnt+=zeroes[i]\r\nprint(cnt)",
"def cows(n, lst):\r\n zeros, result = 0, 0\r\n for i in range(n - 1, -1, -1):\r\n if lst[i] == 0:\r\n zeros += 1\r\n else:\r\n result += zeros\r\n return result\r\n\r\n\r\nm = int(input())\r\na = [int(j) for j in input().split()]\r\nprint(cows(m, a))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ndp=[]\r\nif a[0]==0:\r\n dp.append([1,0])\r\nelse:\r\n dp.append([0,1])\r\nfor i in range(1,n):\r\n dp.append([dp[-1][0],dp[-1][1]])\r\n if a[i]==0:\r\n dp[i][0]+=1\r\n else:\r\n dp[i][1]+=1\r\ncurr=0\r\nfor i in range(n-1):\r\n if a[i]==1:\r\n zero=dp[-1][0]-dp[i][0]\r\n curr+=zero\r\nans=curr\r\nprint(ans)",
"#! usr/bin/env python3\n# coding:UTF-8\n\n# wdnmd UKE\n\nans = 0\ncnt = 0\nN = input()\nt = input().split()\n\nfor i in t:\n if(int(i) == 1):\n cnt += 1\n else:\n ans += cnt\n\nprint(ans)\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans, delta = 0, 0\r\nfor x in a:\r\n if x == 1:\r\n delta += 1\r\n else:\r\n ans += delta\r\nprint(ans)# 1691016186.2820828",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nx=l.count(0)\r\ny=l.count(1)\r\nif x>=y:\r\n a=[]\r\n k=0\r\n for i in range(n-1,-1,-1):\r\n if l[i]==1:\r\n a.append(k)\r\n else:\r\n k+=1\r\nelse:\r\n a=[]\r\n k=0\r\n for i in range(n):\r\n if l[i]==0:\r\n a.append(k)\r\n else:\r\n k+=1\r\nprint(sum(a))",
" ###### ### ####### ####### ## # ##### ### ##### \r\n # # # # # # # # # # # # # ### \r\n # # # # # # # # # # # # # ### \r\n ###### ######### # # # # # # ######### # \r\n ###### ######### # # # # # # ######### # \r\n # # # # # # # # # # #### # # # \r\n # # # # # # # ## # # # # # \r\n ###### # # ####### ####### # # ##### # # # # \r\n \r\nfrom __future__ import print_function # for PyPy2\r\n# from itertools import permutations\r\n# from functools import cmp_to_key # for adding custom comparator\r\n# from fractions import Fraction\r\nfrom collections import *\r\nfrom sys import stdin\r\nfrom bisect import *\r\nfrom heapq import *\r\nfrom math import log2\r\nfrom math import *\r\n \r\ng = lambda : stdin.readline().strip()\r\ngl = lambda : g().split()\r\ngil = lambda : [int(var) for var in gl()]\r\ngfl = lambda : [float(var) for var in gl()]\r\ngcl = lambda : list(g())\r\ngbs = lambda : [int(var) for var in g()]\r\nrr = lambda x : reversed(range(x)) \r\nmod = int(1e9)+7\r\ninf = float(\"inf\")\r\n\r\nn, = gil()\r\na = gil()\r\nans = inf\r\n\r\nz = 0\r\ntmp = 0\r\n\r\nfor i in reversed(range(n)):\r\n if a[i]:\r\n tmp += z\r\n else:\r\n z += 1\r\n\r\no = 0\r\nans = min(ans, tmp)\r\ntmp = 0\r\n\r\nfor i in range(n):\r\n if a[i]:\r\n o += 1\r\n else:\r\n tmp += o\r\n\r\nprint(min(ans, tmp))",
"n = int(input())\narr = list(map(int, input().split()))\n\nzero_count = [0] * n\nzero_count[n - 1] = int(arr[n - 1] == 0)\nfor i in reversed(range(n - 1)):\n zero_count[i] = zero_count[i + 1] + int(arr[i] == 0)\n\nres = 0\nfor i in range(n - 1):\n if arr[i] == 1:\n res += zero_count[i + 1]\n\nprint(res)\n",
"import sys\nimport heapq\nimport random\nfrom math import ceil,floor,fmod,gcd,sqrt,inf\nfrom bisect import bisect_left\nfrom collections import defaultdict,Counter,deque,OrderedDict\nfrom functools import lru_cache,cmp_to_key\n\n# 输入1\ndef ii():\n return int(sys.stdin.readline().strip())\n\n# 输入2\ndef iin():\n return map(int,sys.stdin.readline().split())\n\n# 快速幂\ndef binpow(a, b):\n res = 1\n while b:\n if (b & 1):\n res = res * a\n a = a * a\n b >>= 1\n return res\n\n# 最小公倍数\ndef lcm(a,b):\n return a*b//gcd(a,b)\n\n# 欧拉筛\ndef euler(n,vis,pri):\n cnt=0\n for i in range(2, n + 1):\n if vis[i] == False:\n pri[cnt] = i\n cnt = cnt + 1\n for j in range(0, cnt):\n if i * pri[j] > n:\n break\n vis[i * pri[j]] = 1\n if i % pri[j] == 0:\n break\n return pri[:cnt]\nn=ii()\na=list(iin())\nres=0\ncnt=0\nfor i in range(len(a)):\n if a[i]==0:\n res+=cnt\n else:\n cnt+=1\nans=0\ncnt=0\nfor i in range(len(a)-1,-1,-1):\n if a[i]:\n ans+=cnt\n else:\n cnt+=1\nprint(min(ans,res))\n\n\n \t \t\t \t \t\t\t \t \t \t\t \t\t\t\t\t\t\t\t",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nans = 0\r\nr = 0\r\nfor x in a:\r\n\tif x == 1:\r\n\t\tr += 1\r\n\telse:\r\n\t\tans += r\r\nprint(ans)",
"import sys\r\n\r\ntry:\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\nexcept:\r\n pass\r\n\r\ninput = sys.stdin.readline\r\n\r\nt = 1\r\n# t = int(input())\r\n\r\nwhile t:\r\n t -= 1\r\n\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n # b = list(map(int, input().split()))\r\n # s = input()\r\n zero, one = 0, 0\r\n z, o = 0, 0\r\n for i in range(n):\r\n if a[i] == 0:\r\n zero += z\r\n else:\r\n z += 1\r\n for i in range(n-1, -1, -1):\r\n if a[i] == 1:\r\n one += o\r\n else:\r\n o += 1\r\n print(min(zero, one))\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans, cnt = 0, 0\r\nfor i, x in enumerate(a):\r\n if x == 1:\r\n cnt += 1\r\n else:\r\n ans += cnt\r\nprint(ans)\r\n",
"n = int(input())\r\n\r\nlst = list(map(int, input().strip().split()))\r\ncur_zero = 0\r\ndirs_zero = []\r\nfor i in range(len(lst)):\r\n if lst[i] == 0:\r\n cur_zero += 1\r\n dirs_zero.append(cur_zero)\r\nans = 0\r\nfor i in range(len(lst)):\r\n if lst[i] == 1:\r\n ans += (dirs_zero[-1] - dirs_zero[i])\r\n\r\nprint(ans)\r\n",
"n = int(input())\r\ncows = list(map(int, input().split()))\r\nrcows = 0\r\nans = 0\r\nfor cow in cows:\r\n if cow == 0:\r\n ans += rcows\r\n else:\r\n rcows += 1\r\nprint(ans)",
"import sys\r\ninput=sys.stdin.readline\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ncnt0=[0]*n\r\nfor i in range(n):\r\n if a[i]==0:\r\n cnt0[i]+=1\r\nfor i in range(n-1)[::-1]:\r\n cnt0[i]+=cnt0[i+1]\r\nans=0\r\nfor i in range(n):\r\n if a[i]==1:\r\n ans+=cnt0[i]\r\nprint(ans)",
"n = int(input().strip())\r\nface = list(map(int, input().strip().split()))\r\nt = 0\r\nans = 0\r\n\r\nfor i in face:\r\n if i == 1:\r\n t += 1\r\n else:\r\n ans += t\r\n\r\nprint(ans)\r\n",
"# Matheus de Souza Oliveira - RA: 203407\n\nnumberOfCows = int(input())\ncows = list(map(int, input().split()))\nmilkLost = 0\nrightCowConter = 0\n\nfor cow in cows:\n rightCowConter += cow\n if cow == 0:\n milkLost += rightCowConter\n\nprint(milkLost)\n\t\t\t \t\t\t \t \t\t \t\t\t \t\t \t\t",
"#!python\r\n\r\nimport fileinput\r\n\r\ndef countCow(input):\r\n # number of cow\r\n n = int(input.readline())\r\n # cow's list\r\n cows = input.readline().split()\r\n # cows 0\r\n c0 = len([x for x in cows if x == '0'])\r\n l = []\r\n c0i = 0\r\n for x in cows:\r\n if x == '0':\r\n c0i += 1\r\n else:\r\n l.append(c0 - c0i)\r\n return sum(l)\r\n\r\nif __name__ == \"__main__\":\r\n print(countCow(fileinput.input()))\r\n",
"n = int(input())\r\ns = k = 0\r\nfor i in input()[::2]:\r\n if i == '1': \r\n k += 1\r\n else: \r\n s += k\r\nprint(s)",
"n = int(input())\r\nm = list(input().split())\r\nca = cb = int(0)\r\nfor i in range(n):\r\n if int(m[i]) == 0: \r\n ca += 1\r\n else:\r\n cb += 1\r\n\r\na = b = int(0)\r\nif ca > cb:\r\n for i in range(n):\r\n if int(m[n-i-1]) == 0:\r\n a = a + cb\r\n else:\r\n cb -= 1\r\n print(a)\r\nelse:\r\n for i in range(n):\r\n if int(m[i]) == 1:\r\n b += ca\r\n else:\r\n ca -= 1\r\n print(b)",
"n=int(input())\r\narr=list(map(int,input().split()))\r\ndif=[0]*n\r\nl=0\r\nfor i in range(n-1,-1,-1):\r\n if arr[i]==0:\r\n l+=1\r\n dif[i]=l\r\nnuksan=0\r\nfor i in range(n-1):\r\n if arr[i]==1:\r\n nuksan+=dif[i+1]\r\nprint(nuksan)\r\n \r\n",
"#If you win, you live. You cannot win unless you fight.\n# remember hash hack use tuple\nimport string\nfrom sys import stdin,setrecursionlimit\ninput=stdin.readline\nrd=lambda: map(lambda s: int(s), input().strip().split())\nri=lambda: int(input())\nrs=lambda :input().strip()\nsetrecursionlimit(10**5)\nfrom collections import defaultdict,deque,Counter\nfrom bisect import bisect_left as bl, bisect_right as br\nfrom math import gcd, ceil, floor,log2,factorial\n\n'''\n0=left\n1 =right\ncontri to cost\ncow ke piche vale right 1\naage vale left 0\n\n'''\n\n\nn=ri()\na=list(rd())\npre=[[0,0]]\nfor i in a:\n if i==0:\n pre.append([pre[-1][0]+1,pre[-1][1]])\n else:\n pre.append([pre[-1][0] , pre[-1][1]+1])\nans1=0\nfor id,i in enumerate(a):\n if i==1:\n ans1+=pre[-1][0]-pre[id][0]\nans2=0\nfor i in reversed(range(n)):\n if a[i]==0:\n ans2+=pre[i][1]\nprint(min(ans1,ans2))\n\n\t\t \t\t\t\t \t \t \t\t \t\t \t\t \t \t \t",
"n = input()\r\na = list(map(int, input().split(' ')))\r\n\r\nn0 = a.count(0)\r\nn1 = a.count(1)\r\n\r\nres = list()\r\nif n0 < n1:\r\n n1_cnt = 0\r\n for i in a:\r\n if i == 1:\r\n n1_cnt += 1\r\n else:\r\n res.append(n1_cnt)\r\nelse:\r\n n0_cnt = 0\r\n for i in reversed(a):\r\n if i == 0:\r\n n0_cnt += 1\r\n else:\r\n res.append(n0_cnt)\r\n\r\nprint(sum(res))\r\n",
"#in the name of god\r\n#Mr_Rubick\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ncnt,s=0,[0]*n\r\ns[n-1]=1*(a[n-1]==0)\r\nfor i in range(n-2,-1,-1): s[i]=s[i+1]+1*(a[i]==0)\r\nfor i in range(n): cnt+=s[i]*(a[i]==1)\r\nprint(cnt)",
"n = int(input())\r\na = [int(x) for x in str(input()).split()]\r\ncnt = 0\r\ncnt_1 = 0\r\n\r\n\r\nfor i in range(n):\r\n if a[i] == 1:\r\n cnt_1 += 1\r\n\r\n\r\nfor i in range(n - 1, -1, -1):\r\n if a[i] == 0:\r\n cnt += cnt_1\r\n else:\r\n cnt_1 -= 1\r\n\r\n\r\nprint(cnt)\r\n",
"n=int(input())\r\nlis=list(map(int,input().split()))\r\noc,tc=0,0\r\nfor i in lis:\r\n if i==1:\r\n oc+=1\r\n elif i==0:\r\n tc+=oc\r\nval1=tc\r\ntc,oc=0,0\r\nfor i in reversed(lis):\r\n if i==0:\r\n oc+=1\r\n elif i==1:\r\n tc+=oc\r\nval2=tc\r\nprint(min([val1,val2]))\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nres = 0\r\nb = 0\r\nfor i in reversed(range(n)):\r\n\tif a[i]==1: res += b\r\n\telse: b += 1\r\nprint(res)",
"n = int(input())\r\narray = list(map(int, input().split()))\r\ncnt = 0\r\ns = [0 for i in range(n)]\r\ns[n - 1] = 1 * (array[n - 1] == 0)\r\nfor i in range(n - 2, -1, -1):\r\n s[i] = s[i + 1] + 1 * (array[i] == 0)\r\nfor i in range(n):\r\n cnt += s[i] * (array[i] == 1)\r\nprint(cnt)",
" #n,k=map(int, input().split())\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\ncnt=[0]*n\r\ncnt[0]=arr[0]\r\nfor i in range(1,n):\r\n cnt[i]=cnt[i-1]+arr[i]\r\nans=0\r\nfor i in range(n):\r\n if arr[i]==0:\r\n ans+=cnt[i]\r\nprint(ans)\r\n",
"input()\r\ncnt = 0\r\nsum = 0\r\nfor i in input().split():\r\n if i==\"1\":\r\n cnt+=1\r\n else:\r\n sum+=cnt\r\nprint(sum)",
"n = int(input())\r\nlis = list(map(int,input().split()))\r\nans=b=0\r\nfor i in range(n-1,-1,-1):\r\n if lis[i]==1:\r\n ans+=b\r\n else:\r\n b+=1\r\nprint(ans) ",
"n = int(input())\na = input()\na = [int(x) for x in a.split()]\nsum = 0\nans = 0\nfor i in range(n):\n if a[i] == 1:\n sum += 1\n else:\n ans += sum\nprint(ans)\n\t\t\t\t \t\t \t \t \t\t\t \t \t\t \t \t\t\t\t",
"n = int(input())\r\nls = list(map(int,input().split()))\r\ncnt = 0;ans = 0\r\nfor i in ls:\r\n if i == 0:\r\n ans += cnt\r\n elif i==1:\r\n cnt += 1\r\nprint(ans)",
"def cows(lst):\r\n k1, k2 = 0, 0\r\n for i in range(len(lst)):\r\n if lst[i] == 1:\r\n k1 += 1\r\n else:\r\n k2 += k1\r\n return k2\r\n\r\n\r\nn = int(input())\r\na = [int(j) for j in input().split()]\r\nprint(cows(a))\r\n",
"x = 0\r\ny = 0\r\nn = int(input())\r\na1 = input().split()\r\na = [int(a1[i]) for i in range(len(a1))]\r\nfor i in range(n):\r\n if a[i]:\r\n x += 1\r\n else:\r\n y += x\r\nprint(y)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ncnt_zero, res = 0, 0\r\nfor i in range(n-1, -1, -1):\r\n if arr[i] == 0:\r\n cnt_zero += 1\r\n else:\r\n res += cnt_zero\r\nprint(res)\r\n",
"ans = 0\r\ncnt = 0\r\nN = input()\r\nt = input().split()\r\n \r\nfor i in t:\r\n if i == \"1\" :\r\n cnt += 1\r\n else:\r\n ans += cnt\r\n \r\nprint(ans)",
"n=int(input())\nnm=[0]+list(map(int,input().split()))+[-1]\nsm=[0]*len(nm)\nfor i in range(n+1,0,-1):\n if not nm[i]:\n sm[i-1]=sm[i]+1\n else:\n sm[i-1]=sm[i]\nans=0\nfor i in range(1,n+1):\n if nm[i]:ans+=sm[i]\nprint(str(ans))",
"import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\n\r\n \r\ndef process(A):\r\n S = [0]\r\n answer = 0\r\n for x in A:\r\n S.append(S[-1]+x)\r\n if x==0:\r\n answer+=S[-1]\r\n print(answer)\r\n \r\nn = int(input())\r\nA = [int(x) for x in input().split()]\r\nprocess(A)",
"#! usr/bin/env python3\r\n# coding:UTF-8\r\n\r\nans = 0\r\ncnt = 0\r\nN = input()\r\nt = input().split()\r\n\r\nfor i in t:\r\n if(int(i) == 1):\r\n cnt += 1\r\n else:\r\n ans += cnt\r\n\r\nprint(ans)\r\n",
"n = int(input())\r\nlst = list(map(int,input().split()))\r\nres,s = 0,0\r\nfor i in lst:\r\n if i == 0:\r\n res+=s\r\n else:\r\n s+=1\r\nprint(res)",
"n = int(input())\r\ncows = [int(i) for i in input().strip().split()\r\n]\r\nscare = 0\r\nrightCows = 0\r\nfor i in cows:\r\n if i==1: rightCows += 1\r\n else: scare += rightCows\r\nprint(scare)",
"#If you win, you live. You cannot win unless you fight.\r\n# remember hash hack use tuple\r\nimport string\r\nfrom sys import stdin,setrecursionlimit\r\ninput=stdin.readline\r\nrd=lambda: map(lambda s: int(s), input().strip().split())\r\nri=lambda: int(input())\r\nrs=lambda :input().strip()\r\nsetrecursionlimit(10**5)\r\nfrom collections import defaultdict,deque,Counter\r\nfrom bisect import bisect_left as bl, bisect_right as br\r\nfrom math import gcd, ceil, floor,log2,factorial\r\n\r\n'''\r\n0=left\r\n1 =right\r\ncontri to cost\r\ncow ke piche vale right 1\r\naage vale left 0\r\n\r\n'''\r\n\r\n\r\nn=ri()\r\na=list(rd())\r\npre=[[0,0]]\r\nfor i in a:\r\n if i==0:\r\n pre.append([pre[-1][0]+1,pre[-1][1]])\r\n else:\r\n pre.append([pre[-1][0] , pre[-1][1]+1])\r\nans1=0\r\nfor id,i in enumerate(a):\r\n if i==1:\r\n ans1+=pre[-1][0]-pre[id][0]\r\nans2=0\r\nfor i in reversed(range(n)):\r\n if a[i]==0:\r\n ans2+=pre[i][1]\r\nprint(min(ans1,ans2))\r\n",
"import sys\r\nn=int(input())\r\nL=list(map(int,sys.stdin.readline().split()))\r\n\r\nz=L.count(0)\r\n\r\nif(z==n or z==0):\r\n print(0)\r\n Zeros=[0]*n\r\n Zeros[n-1]+=1-L[n-1]\r\n for i in range(n-2,-1,-1):\r\n Zeros[i]=Zeros[i+1]\r\n if(L[i]==0):\r\n Zeros[i]+=1\r\nelse:\r\n Zeros=[0]*n\r\n Zeros[n-1]+=1-L[n-1]\r\n for i in range(n-2,-1,-1):\r\n Zeros[i]=Zeros[i+1]\r\n if(L[i]==0):\r\n Zeros[i]+=1\r\n\r\n Ans=0\r\n o=0\r\n z=0\r\n p=L[0]\r\n if(L[0]==1):\r\n o+=1\r\n for i in range(1,n):\r\n if(L[i]==p):\r\n \r\n if(p==1):\r\n o+=1\r\n else:\r\n if(L[i]==0):\r\n Ans+=Zeros[i]*o\r\n p=0\r\n else:\r\n o=1\r\n p=1\r\n print(Ans)\r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nz = l.count(0)\r\no = l.count(1)\r\nif z>=o:\r\n ans = []\r\n temp = 0\r\n l=l[::-1]\r\n for i in range(n):\r\n if l[i]==0:\r\n temp+=1\r\n else:\r\n ans.append(temp)\r\n # print(ans)\r\nelse:\r\n ans = []\r\n temp = 0\r\n for i in range(n):\r\n if l[i]==1:\r\n temp+=1\r\n else:\r\n ans.append(temp)\r\n # print(ans)\r\nprint(sum(ans))",
"n = int(input())\ncows = list(map(int, input().split()))\n\ncnt = 0\nans = 0\n\nfor i in range(len(cows)):\n if cows[i]: # milk the cow who is facing right, all of cows who is facing left after this cow will get scared\n cnt += 1\n else: # cows i who is facing left gets scared cnt times\n ans += cnt\nprint(ans)",
"n=int(input())\r\nz=[int(x ) for x in input().split()]\r\n\r\n\r\n\r\nx=z.count(0)\r\nan=0\r\nfor i in range(n):\r\n if z[i]==0:\r\n x-=1\r\n else:\r\n an+=x\r\n\r\nx=z.count(1)\r\n\r\nz=z[::-1]\r\nan12=0\r\nfor i in range(n):\r\n if z[i]==1:\r\n x-=1\r\n else:\r\n an12+=x\r\nprint(min(an,an12))",
"import fileinput\r\nfor line in fileinput.input(): \r\n x = [ int(i) for i in line.split()]\r\n\r\nrightCows = 0\r\ntotal = 0\r\n\r\nfor i in range(0,len(x)):\r\n if x[i]:\r\n rightCows+=1\r\n else:\r\n total +=rightCows\r\n\r\nprint(total)",
"n = input()\r\na = [int(x) for x in input().split()]\r\nans=sum=0\r\nfor i in a:\r\n\tif i==1:\r\n\t\tsum+=1\r\n\telse:\r\n\t\tans+=sum\r\nprint(ans)",
"n=int(input())\r\narr=list(map(int, input().split()))\r\ncost, d=0, 0\r\nfor i in range(n-1, -1, -1):\r\n if arr[i]==0:\r\n d+=1\r\n if arr[i]==1:\r\n cost+=d\r\nprint(cost)",
"from sys import stdin,stdout\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nfor _ in range(1):#nmbr():\r\n n=nmbr()\r\n a=lst();sm=0\r\n looking_l=[0]*(1+n)\r\n for i in range(n-1,-1,-1):\r\n if a[i]==0:looking_l[i]=1+looking_l[i+1]\r\n else:looking_l[i]=looking_l[i+1]\r\n for i in range(n):\r\n if a[i]==1:\r\n sm+=looking_l[i]\r\n print(sm)"
] | {"inputs": ["4\n0 0 1 0", "5\n1 0 1 0 1", "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0", "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 0", "1\n1", "1\n0", "2\n0 1", "2\n1 0", "2\n0 0", "2\n1 1", "4\n1 1 1 1"], "outputs": ["1", "3", "416", "1446", "0", "0", "0", "1", "0", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 66 | |
2a30f64e79901e0b36893401ae12ce7a | Chessboard | Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size *n* by *n*, *n* is always odd. And what's even worse, some squares were of wrong color. *j*-th square of the *i*-th row of *k*-th piece of the board has color *a**k*,<=*i*,<=*j*; 1 being black and 0 being white.
Now Magnus wants to change color of some squares in such a way that he recolors minimum number of squares and obtained pieces form a valid chessboard. Every square has its color different to each of the neightbouring by side squares in a valid board. Its size should be 2*n* by 2*n*. You are allowed to move pieces but not allowed to rotate or flip them.
The first line contains odd integer *n* (1<=≤<=*n*<=≤<=100) — the size of all pieces of the board.
Then 4 segments follow, each describes one piece of the board. Each consists of *n* lines of *n* characters; *j*-th one of *i*-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separated by an empty line.
Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard.
Sample Input
1
0
0
1
0
3
101
010
101
101
000
101
010
101
011
010
101
010
Sample Output
1
2
| [
"n = int(input())\n\npieces = []\nrecolors = []\nfor i in range(4):\n piece = []\n for j in range(n):\n line = input().strip()\n piece.append(line)\n if i != 3:\n input()\n pieces.append(piece)\n cur1 = 0\n for x in range(n):\n for y in range(n):\n cur1 += (x + y + int(piece[x][y])) % 2\n cur2 = 0\n for x in range(n):\n for y in range(n):\n cur2 += (x + y + 1 + int(piece[x][y])) % 2\n recolors.append([cur1, cur2])\n\n#print(recolors)\n\nmmin = (2 * n) * (2 * n)\nenums = [[[0, 1], [2, 3]],\n [[0, 2], [1, 3]],\n [[0, 3], [1, 2]],\n [[1, 2], [0, 3]],\n [[1, 3], [0, 2]],\n [[2, 3], [0, 1]]]\nfor i in range(len(enums)):\n a, b = enums[i]\n #print(a, b, recolors)\n summ = recolors[a[0]][0] + recolors[a[1]][0] + recolors[b[0]][1] + recolors[b[1]][1]\n mmin = min((mmin, summ))\nprint(mmin)\n \t \t\t\t\t\t\t \t \t \t \t\t \t \t \t",
"n = int(input())\r\na = []\r\nb = []\r\nans = 1000000\r\nfor i in range(4):\r\n a.append([]*n)\r\n for j in range(n):\r\n a[i].append([0]*n)\r\nfor i in range(4):\r\n for j in range(n):\r\n s = input()\r\n for k in range(len(s)):\r\n a[i][j][k] = int(s[k])\r\n if i < 3:\r\n input()\r\nfor i in range(16):\r\n c = [0]*4\r\n y = 3\r\n ans1 = 0\r\n while i > 0:\r\n c[y] = i % 2\r\n y-=1\r\n i //= 2\r\n c.reverse()\r\n if sum(c) == 2:\r\n for k in range(4):\r\n if c[k] == 1:\r\n for i in range(n):\r\n for j in range(n):\r\n if i % 2 == j % 2:\r\n ans1+=min(1,1 - a[k][i][j])\r\n else:\r\n ans1+=max(0,a[k][i][j])\r\n else:\r\n for i in range(n):\r\n for j in range(n):\r\n if i % 2 != j % 2:\r\n ans1+=min(1,1 - a[k][i][j])\r\n else:\r\n ans1+=max(0,a[k][i][j])\r\n ans = min(ans,ans1)\r\nprint(ans)\r\n \r\n \r\n",
"n=int(input())\r\naa=[0]*4\r\nfor i in range(4):\r\n aa[i]=''.join(input() for j in range(n))\r\n if(i!=3):\r\n input()\r\n\r\nx=''.join('10' for i in range((n**2)//2)) +'1'\r\ny=''.join('01' for i in range((n**2)//2)) +'0'\r\n#print(aa,x,y)\r\nx=int(x,2)\r\ny=int(y,2)\r\n\r\n#print(a,b,c,d,x,y)\r\na=[0]*4\r\nb=[0]*4\r\nfor i in range(4):\r\n a[i]=bin(x^int(aa[i],2))[2:].count('1')\r\n b[i]=bin(y^int(aa[i],2))[2:].count('1')\r\n#print(ch1,ch2)\r\n\r\nans=[a[0]+a[1]+ b[2]+b[3], a[0]+a[2]+ b[1]+b[3], a[0]+a[3]+ b[2]+b[1], a[1]+a[2]+ b[0]+b[3], a[1]+a[3]+ b[0]+b[2], a[2]+a[3]+ b[0]+b[1], ]\r\n \r\nprint(min(ans))\r\n",
"import bisect\r\nimport collections\r\nimport copy\r\nimport enum\r\nimport functools\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport re\r\nimport sys\r\nimport time\r\nimport string\r\nfrom typing import List\r\nsys.setrecursionlimit(3001)\r\n\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ndp = [[0,0] for _ in range(4)]\r\n\r\nfor c in range(4):\r\n for i in range(n):\r\n s = input().strip()\r\n for j in range(n):\r\n if (i+j)%2==0:\r\n dp[c][0]+= (s[j]=='1')\r\n dp[c][1] += (s[j]=='0')\r\n else:\r\n dp[c][0]+= (s[j]=='0')\r\n dp[c][1] += (s[j]=='1')\r\n if c!=3:\r\n input()\r\n\r\nans = 4*n*n\r\nfor state in range(1<<4):\r\n if bin(state).count('1')==2:\r\n ta = 0\r\n for i in range(4):\r\n ta += dp[i][(state>>i)&1]\r\n ans = min(ans,ta)\r\n\r\nprint(ans)",
"from itertools import combinations\n\n\ndef fn(mtrx):\n w = 0\n b = 0\n n = len(mtrx)\n\n for i in range(n):\n for j in range(n):\n if (i + j) % 2:\n if mtrx[i][j] == '0':\n w += 1\n else:\n b += 1\n else:\n if mtrx[i][j] == '1':\n w += 1\n else:\n b += 1\n\n return (w, b)\n\n\nif __name__ == '__main__':\n n = int(input())\n\n ms = []\n\n for i in range(4):\n mtrx = []\n for _ in range(n):\n mtrx.append(list(input()))\n ms.append(mtrx)\n if i < 3:\n input()\n\n costs = list(map(lambda o: fn(o), ms))\n combs = list(map(lambda o: list(o), combinations(range(4), 2)))\n\n mc = 40 ** 4\n\n for ws in combs:\n bs = [0, 1, 2, 3]\n for w in ws:\n bs.remove(w)\n mc = min(mc, costs[ws[0]][0] + costs[ws[1]][0] + costs[bs[0]][1] + costs[bs[1]][1])\n\n print(mc)\n",
"n=int(input())\r\npieces=[]\r\nblacks=[0]*4\r\nwhites=[0]*4\r\nfor i in range(4):\r\n grid=[]\r\n for j in range(n):\r\n grid.append(input())\r\n if i<3:\r\n input()\r\n count=0\r\n for j in range(n):\r\n for k in range(n):\r\n if (int(grid[j][k])+j+k)%2:\r\n count+=1\r\n blacks[i]=count\r\n whites[i]=n*n-count\r\nans=4*n*n\r\nfor white1 in range(3):\r\n for white2 in range(white1+1,4):\r\n for black1 in range(4):\r\n if black1==white1 or black1==white2:\r\n continue\r\n for black2 in range(black1+1,4):\r\n if black2==white1 or black2==white2:\r\n continue\r\n ans=min(ans,whites[white1]+whites[white2]+blacks[black1]+blacks[black2])\r\nprint(ans)",
"from itertools import permutations\n\n\ndef count(board, first_square):\n cnt = 0\n n = len(board)\n same = str(first_square)\n inverted = str(1 - first_square)\n\n for i in range(n):\n for j in range(n):\n if (i + j) % 2 == 0:\n c = same\n else:\n c = inverted\n cnt += board[i][j] != c\n return cnt\n\n\ndef main():\n n = int(input())\n\n m = n * n * 4\n\n pieces = []\n for _ in range(4):\n piece = []\n for i in range(n):\n piece.append(input())\n pieces.append(piece)\n try:\n input()\n except:\n pass\n\n for color in range(2):\n for p in permutations(range(4)):\n changed = (count(pieces[p[0]], color) + count(pieces[p[1]], 1 - color) +\n count(pieces[p[2]], 1 - color) + count(pieces[p[3]], color))\n if changed < m:\n m = changed\n\n print(m)\n\n\nif __name__ == '__main__':\n main()\n",
"def countSetBits( n):\r\n\tans = bin( n )\r\n\treturn ans.count( \"1\" )\r\nn=int(input())\r\ns=[]\r\nfor j in range(4*n+3):\r\n a=input()\r\n if len(a)==0:continue\r\n val=0\r\n for i in range(n):\r\n val += int(a[i])*(1<<(n-i-1))\r\n s.append(val)\r\n\r\nx=((1<<((n+1)))-1)//3\r\ny = ((1<<(n))-1)^x\r\none = []\r\nzero= []\r\nfor i in range(4*n):\r\n val=s[i]\r\n if ((i%n)%2==0):x1=x;y1=y\r\n else : x1=y;y1=x\r\n one.append(countSetBits(val^x1))\r\n zero.append(countSetBits(val^y1))\r\nfouro = []\r\nfourz = []\r\ni=0\r\nwhile i<4*n:\r\n a1=0\r\n a2=0\r\n for j in range(i,i+n):\r\n a1+=one[j]\r\n a2+=zero[j]\r\n fouro.append(a1)\r\n fourz.append(a2)\r\n i+=n\r\n# print(fouro,fourz)\r\nx=list(zip(fouro,fourz))\r\ny=list(zip(fourz,fouro))\r\nx=sorted(x)\r\ny=sorted(y)\r\nans1=x[0][0]+x[1][0] + x[2][1]+x[3][1]\r\nans2=y[2][0]+y[3][0] + y[0][1]+y[1][1]\r\n# print(x,y)\r\nresul=min(ans1,ans2)\r\nprint(resul)\r\n\r\n\r\n",
"import bisect\r\nimport math\r\nimport itertools\r\nimport sys\r\n\r\n# import sys.stdout.flush() use for interactive problems\r\nalpha = 'abcdefghijklmnopqrstuvwxyz'\r\ninf = 1e17\r\n\r\n\r\n# Max = 10**6\r\n# primes = []\r\n# prime = [True for i in range(10**6+1)]\r\n# p = 2\r\n# while (p * p <= Max+1):\r\n#\r\n# # If prime[p] is not\r\n# # changed, then it is a prime\r\n# if (prime[p] == True):\r\n#\r\n# # Update all multiples of p\r\n# for i in range(p * p, Max+1, p):\r\n# prime[i] = False\r\n# p += 1\r\n#\r\n# for p in range(2, Max+1):\r\n# if prime[p]:\r\n# primes.append(p)\r\ndef calc1(grid):\r\n l = len(grid)\r\n cnt = 0\r\n for i in range(l):\r\n for j in range(l):\r\n if (i+j) % 2 and grid[i][j]:\r\n cnt += 1\r\n if (i+j) % 2 == 0 and grid[i][j] == 0:\r\n cnt += 1\r\n return cnt\r\n\r\ndef calc2(grid):\r\n l = len(grid)\r\n cnt = 0\r\n for i in range(l):\r\n for j in range(l):\r\n if (i+j) % 2 and grid[i][j] == 0:\r\n cnt += 1\r\n if (i+j) % 2 == 0 and grid[i][j]:\r\n cnt += 1\r\n return cnt\r\ndef solve(n,grids):\r\n one = []\r\n zero = []\r\n for grid in grids:\r\n one.append(calc1(grid))\r\n zero.append(calc2(grid))\r\n take = [3,5,6,9,10,12]\r\n answer = inf\r\n for mask in range(16):\r\n cnt = 0\r\n if mask not in take:\r\n continue\r\n if mask in take:\r\n if mask & 1:\r\n cnt += one[3]\r\n pass\r\n else:\r\n cnt += zero[3]\r\n pass\r\n if mask & 2:\r\n cnt += one[2]\r\n pass\r\n else:\r\n cnt += zero[2]\r\n pass\r\n if mask & 4:\r\n cnt += one[1]\r\n pass\r\n else:\r\n cnt += zero[1]\r\n pass\r\n if mask & 8:\r\n cnt += one[0]\r\n pass\r\n else:\r\n cnt += zero[0]\r\n pass\r\n answer = min(answer,cnt)\r\n return answer\r\n\r\nt = 1#int(input())\r\nans = []\r\nfor _ in range(t):\r\n n = int(input())\r\n #n, u, r, d, l = map(int, input().split())\r\n #a,b = map(int, input().split())\r\n # s = input()\r\n # arr = list(input())\r\n # arr = [int(x) for x in input().split()]\r\n # c = [int(x) for x in input().split()]\r\n\r\n # b = [int(x) for x in input().split()]\r\n # s = input()\r\n # t = input()\r\n grids = []\r\n for i in range(4):\r\n grid = []\r\n for j in range(n):\r\n arr = list(map(int,list(input())))\r\n grid.append(arr)\r\n if i != 3:\r\n s = input()\r\n grids.append(grid)\r\n # options = [int(x) for x in input().split()]\r\n \"\"\"ladders = []\r\n for j in range(l):\r\n ladders.append([int(x) for x in input().split()])\"\"\"\r\n \"\"\"queries = []\r\n for j in range(q):\r\n queries.append(list(map(int, input().split())))\"\"\"\r\n # s = list(input())\r\n # start,end = map(int,input().split())\r\n\r\n ans.append(solve(n,grids))\r\n\r\nfor test in ans:\r\n print(test)",
"n = int(input())\r\ns = [[\"\" for _ in range(n)] for __ in range(4)]\r\nfor i in range(3):\r\n for j in range(n):\r\n s[i][j] = input()\r\n input()\r\nfor j in range(n):\r\n s[3][j] = input()\r\nres = int(1e13)\r\nfor i in range(24):\r\n perm = [0, 1, 2, 3]\r\n L = [0]*4\r\n tmp = i\r\n for j in range(4):\r\n L[j] = tmp % (4-j)\r\n tmp //= (4-j)\r\n LL = [0]*4\r\n for j in range(4):\r\n LL[j] = perm[L[j]]\r\n for k in range(L[j], 3-j):\r\n perm[k] = perm[k+1]\r\n lu, ru, ld, rd = LL[0], LL[1], LL[2], LL[3]\r\n Map = [s[lu][_][:]+s[ru][_][:] for _ in range(n)] + [s[ld][_][:]+s[rd][_][:] for _ in range(n)]\r\n cnt0, cnt1 = 0, 0\r\n for j in range(2*n):\r\n for k in range(2*n):\r\n if (j+k) % 2:\r\n if Map[j][k] == '0':\r\n cnt0 += 1\r\n else:\r\n cnt1 += 1\r\n else:\r\n if Map[j][k] == '1':\r\n cnt0 += 1\r\n else:\r\n cnt1 += 1\r\n res = min(res, cnt0, cnt1)\r\nprint(res)",
"n = int(input())\r\ndef func(a,li):\r\n global n\r\n ans = 0\r\n for i in range(n):\r\n for j in range(n):\r\n if(a[i][j] != li[i][j]):\r\n ans = ans + 1\r\n return ans\r\n\r\na = []\r\nfor i in range(n//2):\r\n a.append(\"10\" * (n//2) +\"1\")\r\n a.append(\"01\"* (n//2) +\"0\")\r\na.append(\"10\" * (n//2)+\"1\")\r\n\r\nnums = []\r\n\r\nfor j in range(4):\r\n li = []\r\n for k in range(n):\r\n li.append(input())\r\n nums.append(func(a,li))\r\n if(j != 3):\r\n input()\r\n \r\nnums = sorted(nums)\r\nx = n*n\r\nprint(nums[0] + nums[1] + (x - nums[2]) + (x - nums[3]))",
"# _\r\n#####################################################################################################################\r\n\r\ndef main():\r\n pieces_Dimension = int(input())\r\n piece1 = ''.join(input() for _ in range(pieces_Dimension))\r\n input()\r\n piece2 = ''.join(input() for _ in range(pieces_Dimension))\r\n input()\r\n piece3 = ''.join(input() for _ in range(pieces_Dimension))\r\n input()\r\n piece4 = ''.join(input() for _ in range(pieces_Dimension))\r\n\r\n brokenPieces = (piece1, piece2, piece3, piece4)\r\n nSquares = pieces_Dimension*pieces_Dimension\r\n squares = '01'*-(-nSquares//2)\r\n\r\n return nSquaresToRecolorIn(brokenPieces, nSquares, squares)\r\n\r\n\r\ndef nSquaresToRecolorIn(brokenPieces, nSquares, squares):\r\n possible_nSquares = [(sum(1 for i in range(nSquares) if piece[i] != squares[:-1][i]),\r\n sum(1 for i in range(nSquares) if piece[i] != squares[1:][i]))\r\n for piece in brokenPieces]\r\n possible_nSquares.sort(key=lambda x: x[0])\r\n\r\n return possible_nSquares[0][0] + possible_nSquares[1][0] + possible_nSquares[2][1] + possible_nSquares[3][1]\r\n\r\n\r\nif __name__ == '__main__':\r\n print(main())\r\n # main()\r\n",
"d = []\ndef rec(x,i):\n global d\n if i >= 4:\n d += [x]\n return\n if '1' not in x:\n rec(x + '1',i + 1)\n if '2' not in x:\n rec(x + '2',i + 1)\n if '3' not in x:\n rec(x + '3',i + 1)\n if '4' not in x:\n rec(x + '4',i + 1)\nrec('1',1)\nrec('2',1)\nrec('3',1)\nrec('4',1)\nd1 = []\np = ['']\nn = int(input())\nt = 4 * n\ni = 0\nwhile t > 0:\n i += 1\n s = input()\n d1 += [s]\n if i == n:\n i = 0\n if t > 1:\n s1 = input()\n p += [d1]\n d1 = []\n t -= 1\nmn = 10000000\nfor v in d:\n kol = 0\n a,b,c,d1 = int(v[0]),int(v[1]),int(v[2]),int(v[3])\n for i in range(1, n + 1):\n for j in range(1, n + 1):\n if (i + j) % 2 == 0:\n if p[a][i - 1][j - 1] == '0':\n kol += 1\n if p[b][i -1][j - 1] == '0':\n kol += 1\n else:\n if p[a][i- 1][j - 1] == '1':\n kol += 1\n if p[b][i - 1][j - 1] == '1':\n kol += 1\n if (i + j) % 2 == 1:\n if p[c][i - 1][j - 1] == '0':\n kol += 1\n if p[d1][i - 1][j - 1] == '0':\n kol += 1\n else: \n if p[c][i - 1][j - 1] == '1':\n kol += 1\n if p[d1][i - 1][j - 1] == '1':\n kol += 1\n # print(kol)\n mn = min(mn,kol)\nprint(mn)\n",
"new_n = int(input())\nc = [0] * 4\nfor k in range(4):\n for i in range(new_n):\n s = input()\n for j in range(new_n):\n if (i + j) % 2 != int(s[j]):\n c[k] += 1\n if k < 3:\n input()\nc.sort()\nresult = c[0] + c[1] + 2 * new_n * new_n - c[2] - c[3]\nprint(result)\n\n \t\t\t \t \t\t \t \t \t \t\t\t \t\t\t\t \t",
"import collections, math\r\n\r\nlocal = False\r\nif local:\r\n file = open(\"inputt.txt\", \"r\")\r\n\r\ndef inp():\r\n if local:\r\n return file.readline().rstrip()\r\n else:\r\n return input().rstrip()\r\n\r\ndef ints():\r\n return [int(_) for _ in inp().split()]\r\n\r\n\r\nn = int(inp())\r\n\r\nk = [[] for _ in range(4)]\r\n\r\nfor i in range(4):\r\n grid = [\"\" for _ in range(n)]\r\n\r\n for _ in range(n):\r\n grid[_] = inp()\r\n\r\n if i<3:\r\n inp()\r\n\r\n k[i] = grid\r\n\r\ngoBlackCrossCount = [0]*4\r\n\r\nfor i in range(4):\r\n grid = k[i]\r\n\r\n for r in range(n):\r\n for c in range(n):\r\n if r%2==0:\r\n if c%2==0:\r\n if grid[r][c]==\"1\":\r\n goBlackCrossCount[i] += 1\r\n else:\r\n if grid[r][c]==\"0\":\r\n goBlackCrossCount[i] += 1\r\n else:\r\n if c%2==0:\r\n if grid[r][c]==\"0\":\r\n goBlackCrossCount[i] += 1\r\n else:\r\n if grid[r][c]==\"1\":\r\n goBlackCrossCount[i] += 1\r\n\r\ngoBlackCrossCount.sort()\r\nans = goBlackCrossCount[0]+goBlackCrossCount[1]+(n**2)-goBlackCrossCount[2]+(n**2)-goBlackCrossCount[3]\r\n\r\nprint(ans)\r\n \r\n\r\n\r\n\r\n",
"from sys import stdin, stdout\r\nfrom itertools import permutations\r\n\r\n\r\ndef count_cells(mas, n):\r\n c_b = 0\r\n for i in range(n):\r\n c_b += sum(mas[i])\r\n return c_b\r\n\r\n\r\ndef solve():\r\n\r\n n = int(stdin.readline())\r\n m_1 = [[int(s) for s in stdin.readline().rstrip('\\r\\n')] for _ in range(n)]\r\n stdin.readline()\r\n m_2 = [[int(s) for s in stdin.readline().rstrip('\\r\\n')] for _ in range(n)]\r\n stdin.readline()\r\n m_3 = [[int(s) for s in stdin.readline().rstrip('\\r\\n')] for _ in range(n)]\r\n stdin.readline()\r\n m_4 = [[int(s) for s in stdin.readline().rstrip('\\r\\n')] for _ in range(n)]\r\n\r\n ans = float('inf')\r\n for board in permutations([m_1, m_2, m_3, m_4]):\r\n m = []\r\n for i in range(0, 3, 2):\r\n for j in range(n):\r\n m.append(board[i][j]+board[i+1][j])\r\n\r\n # case 1: from white\r\n c1 = 0\r\n for i in range(2*n):\r\n cur = i % 2\r\n for j in range(2*n):\r\n if m[i][j] != cur:\r\n c1 += 1\r\n cur ^= 1\r\n\r\n # case 1: from white\r\n c2 = 0\r\n for i in range(2 * n):\r\n cur = (i+1) % 2\r\n for j in range(2 * n):\r\n if m[i][j] != cur:\r\n c2 += 1\r\n cur ^= 1\r\n\r\n ans = min(ans, c1, c2)\r\n print(ans)\r\n\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n",
"n = int(input())\r\nw = [0, 0, 0, 0]\r\nb = [0, 0, 0, 0]\r\nfor i in range(4):\r\n for count in range(n):\r\n line = list(map(int, input()))\r\n #print(line)\r\n for pos in range(n):\r\n w[i] += abs((count + pos) % 2 - line[pos])\r\n b[i] += abs(abs((count + pos) % 2 - line[pos]) - 1)\r\n if i < 3:\r\n input()\r\nw.sort()\r\nb.sort()\r\nprint(w[0] + w[1] + b[0] + b[1])\r\n",
"import sys\r\n\r\n# For getting input from input.txt file \r\n# sys.stdin = open('input.txt', 'r') \r\n \r\n# Printing the Output to output.txt file \r\n# sys.stdout = open('output.txt', 'w') \r\n# from math import log2\r\ntry: \r\n # t=int(input())\r\n\r\n # for _ in range(t):\r\n def check(n):\r\n count1=0\r\n s=\"\"\r\n while(n!=0):\r\n if n%2:\r\n count1+=1\r\n s=\"1\"+s\r\n else:\r\n s=\"0\"+s\r\n n//=2\r\n return s\r\n \r\n def solve(flag,n,l):\r\n temp_ans=0\r\n for i in range(n):\r\n y=(z[flag]^int(l[i],2) )\r\n b=bin(y)\r\n temp_ans+=b.count(\"1\")\r\n flag=not(flag)\r\n # print(temp_ans)\r\n return temp_ans\r\n \r\n \r\n \r\n n=int(input())\r\n l1 = [input() for y in range(n)]\r\n temp=input()\r\n l2 = [input() for y in range(n)]\r\n temp=input()\r\n l3 = [input() for y in range(n)]\r\n temp=input()\r\n l4 = [input() for y in range(n)]\r\n \r\n z=[]\r\n s=0\r\n for i in range(n):\r\n if i%2==1:\r\n s+=(2**i)\r\n z.append(s)\r\n z.append( z[0] ^ (2**n-1) ) \r\n ans=m=sys.maxsize\r\n for i in range(2,17):\r\n s=check(i)\r\n if s.count(\"1\")==2:\r\n s=(4-len(s))*\"0\"+s\r\n res=sys.maxsize\r\n for i in range(4):\r\n if i==0:\r\n x=l1\r\n elif i==1:\r\n x=l2\r\n elif i==2:\r\n x=l3\r\n else:\r\n x=l4\r\n \r\n if s[i]==\"1\":\r\n res+=min(res,solve(1,n,x))\r\n else:\r\n res+=min(res,solve(0,n,x))\r\n ans=min(ans,res-m)\r\n print(ans) \r\n\r\n \r\nexcept EOFError:\r\n pass",
"import itertools\r\n\r\nn = int(input())\r\nboards = []\r\nfor i in range(4):\r\n boards.append([])\r\n for j in range(n):\r\n boards[-1].append(list(map(int, list(input()))))\r\n if i < 3: input()\r\n\r\nans = n * n * 4\r\n\r\n\r\ndef check_board(corner, board):\r\n ans = 0\r\n for i in range(n):\r\n for j in range(n):\r\n if board[i][j] != corner:\r\n ans += 1\r\n corner = 1 - corner\r\n return ans\r\n\r\n\r\ndef solve(corner, p):\r\n ans = check_board(corner, boards[p[0]])\r\n ans += check_board(1- corner, boards[p[1]])\r\n ans += check_board(1 - corner, boards[p[2]])\r\n ans += check_board(corner, boards[p[3]])\r\n\r\n return ans\r\n\r\n\r\nfor p in itertools.permutations(range(4), 4):\r\n ans = min(ans, solve(1, p))\r\n ans = min(ans, solve(0, p))\r\n\r\nprint(ans)",
"# link: https://codeforces.com/problemset/problem/961/C\r\n\r\nimport os, sys\r\nfrom io import BytesIO, IOBase\r\n \r\nBUFSIZE = 8192\r\n \r\n \r\nclass FastIO(IOBase):\r\n newlines = 0\r\n \r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n \r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n \r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n \r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n \r\n \r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n \r\n \r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\nfrom math import ceil\r\nmod = 10 ** 9 + 7 \r\n\r\ndef get_original_pieces(x):\r\n common = (pow(x, 2) - 1) // 2\r\n first_piece = \"10\"*common + '1'\r\n second_piece = '0' + \"10\"*common\r\n return [first_piece, second_piece]\r\n\r\n# number of test cases\r\nfor _ in range(1):\r\n n = int(input())\r\n pieces = [\"\" for _ in range(4)]\r\n original_pieces = get_original_pieces(n)\r\n i = 0\r\n for _ in range(3 + (n*4)):\r\n s = input()\r\n if s:\r\n pieces[i] += s\r\n else:\r\n i += 1 \r\n #print(pieces) \r\n till = pow(n, 2)\r\n fp = [[0,i] for i in range(4)]\r\n sp = [[0,i] for i in range(4)]\r\n for i in range(4):\r\n fpc, spc = 0, 0\r\n for j in range(till):\r\n if pieces[i][j] != original_pieces[0][j]:\r\n fpc += 1\r\n if pieces[i][j] != original_pieces[1][j]:\r\n spc += 1\r\n fp[i][0] = fpc\r\n sp[i][0] = spc\r\n fp.sort()\r\n sp.sort()\r\n ans1 = fp[0][0] + fp[1][0]\r\n ans2 = sp[0][0] + sp[1][0]\r\n for i in range(4):\r\n if sp[i][1] not in [fp[0][1], fp[1][1]]: ans1 += sp[i][0]\r\n if fp[i][1] not in [sp[0][1], sp[1][1]]: ans2 += fp[i][0]\r\n ans = min(ans1, ans2)\r\n print(ans) ",
"import sys\r\ninput = sys.stdin.readline\r\nfrom itertools import permutations\r\n\r\ndef f(x1, x2, x3, x4, n):\r\n w = []\r\n for i in range(n):\r\n w.append(x1[i] + x2[i])\r\n for i in range(n):\r\n w.append(x3[i] + x4[i])\r\n return w\r\n\r\nn = int(input())\r\na1 = [input()[:-1] for _ in range(n)]\r\ninput()\r\na2 = [input()[:-1] for _ in range(n)]\r\ninput()\r\na3 = [input()[:-1] for _ in range(n)]\r\ninput()\r\na4 = [input()[:-1] for _ in range(n)]\r\n\r\nq = []\r\nfor b1,b2,b3,b4 in list(permutations([a1,a2,a3,a4], 4)):\r\n q.append(f(b1,b2,b3,b4,n))\r\n\r\ns = []\r\nd = []\r\nfor i in range(2*n):\r\n s.append(('10')*n if i%2 == 0 else ('01')*n)\r\n d.append(('10')*n if i%2 else ('01')*n)\r\n\r\nc = 1000000\r\nfor i in q:\r\n c1 = c2 = 0\r\n for j in range(2*n):\r\n for k in range(2*n):\r\n if i[j][k] != s[j][k]:\r\n c1 += 1\r\n if i[j][k] != d[j][k]:\r\n c2 += 1\r\n c = min(c, c1, c2)\r\n\r\nprint(c)\r\n",
"from functools import reduce\r\nimport math\r\nfrom decimal import *\r\ndef factors(n):\r\n return set(reduce(list.__add__,\r\n ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))\r\ndef sol():\r\n am = int(input())\r\n pieces = []\r\n\r\n need1 = [0]*4\r\n need2 = [0]*4\r\n\r\n for i in range(4):\r\n piece = []\r\n for g in range(am):\r\n piece.append(list(map(int,list(input()))))\r\n for g in range(am):\r\n for j in range(am):\r\n need1[i]+= ((piece[g][j] == (j&1==g&1)) + 1)&1\r\n # for g in range(am):\r\n # for j in range(am):\r\n # need2[i]+= ((piece[g][j] == (j&1==g&1)))\r\n if i != 3:\r\n input()\r\n pieces.append(piece)\r\n need1.sort()\r\n s = 0\r\n for i in range(2):\r\n s+=need1[i]\r\n for i in range(2,4):\r\n s+= am**2 -need1[i]\r\n print(s)\r\n # for i in range(3):\r\n # for g in range(3):\r\n # print(i&1 == g&1, end=\" \")\r\n # print('\\n')\r\nsol()",
"n = int(input())\r\nS = []\r\nfor i in range(4):\r\n s = [str(input()) for i in range(n)]\r\n S.append(s)\r\n if i != 3:\r\n _ = input()\r\n#print(S)\r\nimport itertools\r\nans = 10**18\r\nfor P in itertools.permutations(range(4), 4):\r\n T = [[-1]*(2*n) for i in range(2*n)]\r\n for i, p in enumerate(P):\r\n if i == 0:\r\n for y in range(n):\r\n for x in range(n):\r\n T[y][x] = S[p][y][x]\r\n elif i == 1:\r\n for y in range(n):\r\n for x in range(n):\r\n T[y][x+n] = S[p][y][x]\r\n elif i == 2:\r\n for y in range(n):\r\n for x in range(n):\r\n T[y+n][x] = S[p][y][x]\r\n else:\r\n for y in range(n):\r\n for x in range(n):\r\n T[y+n][x+n] = S[p][y][x]\r\n E = [0]*2\r\n O = [0]*2\r\n for y in range(2*n):\r\n for x in range(2*n):\r\n if (y+x)%2 == 0:\r\n E[int(T[y][x])] += 1\r\n else:\r\n O[int(T[y][x])] += 1\r\n ans = min(ans, min(E[0]+O[1], E[1]+O[0]))\r\nprint(ans)\r\n",
"n = int(input())\r\n\r\nans = [0] * 4\r\n\r\nfor i in range(4):\r\n \r\n for j in range (n):\r\n\r\n row = []\r\n vals = input()\r\n\r\n \r\n for k in range (n):\r\n\r\n if (j+k) % 2 == int(vals[k]):\r\n ans[i] += 1\r\n \r\n \r\n \r\n \r\n if i < 3 : \r\n input()\r\nans.sort()\r\nprint((ans[0] + ans[1]) + ((n*n)-ans[2]) + ((n*n)-ans[3]))\r\n",
"n=int(input())\r\np=[]\r\nfor i in range(4):\r\n p1=[]\r\n if(i==3):\r\n for j in range(n):\r\n p1.append(input())\r\n p.append(p1)\r\n else:\r\n for j in range(n):\r\n p1.append(input())\r\n w=input()\r\n p.append(p1)\r\n#print(p)\r\nmin_1=[]\r\nmin_2=[]\r\nfor k in range(4):\r\n cnt=0\r\n for i in range(n):\r\n for j in range(n):\r\n if((i+j)%2 and p[k][i][j]=='1' or (i+j)%2==0 and p[k][i][j]=='0'):\r\n cnt+=1\r\n min_1.append(cnt)\r\n min_2.append(n*n-cnt)\r\nmin_1.sort()\r\nmin_2.sort()\r\n#print(min_1,min_2)\r\nprint(min_1[0]+min_2[1]+min_1[1]+min_2[0])\r\n \r\n \r\n\r\n\r\n",
"n = int(input())\r\nvs = [0]*4\r\nfor i in range(4):\r\n\tw=v=0\r\n\tfor _ in range(n):\r\n\t\tfor k in input():\r\n\t\t\tw^=1\r\n\t\t\tif w==int(k): v+=1\r\n\tvs[i]=v\r\n\tif i < 3: input()\r\nbase = 2*n**2+sum(vs)\r\nminv = 4*n**2\r\nfor i in range(4):\r\n\tfor j in range(i+1,4):\r\n\t\tminv = min(minv, base-2*(vs[i]+vs[j]))\r\nprint(minv)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nx = []\r\nfor k in range(4):\r\n s = [list(input().rstrip()) for _ in range(n)]\r\n c = 0\r\n for i in range(n):\r\n for j in range(n):\r\n c += int(s[i][j]) ^ ((i + j) % 2)\r\n x.append(c)\r\n if k < 3:\r\n input() \r\npow2 = [1]\r\nfor _ in range(4):\r\n pow2.append(2 * pow2[-1])\r\nans = 4 * n * n\r\nfor i in range(pow2[4]):\r\n c = 0\r\n m = 0\r\n for j in range(4):\r\n if i & pow2[j]:\r\n c += 1\r\n m += x[j]\r\n else:\r\n m += n * n - x[j]\r\n if c == 2:\r\n ans = min(ans, m)\r\nprint(ans)",
"import sys,math,itertools\r\nfrom collections import Counter,deque,defaultdict\r\nfrom bisect import bisect_left,bisect_right \r\nfrom heapq import heappop,heappush,heapify, nlargest\r\nfrom copy import deepcopy\r\nmod = 10**9+7\r\nINF = float('inf')\r\ndef inp(): return int(sys.stdin.readline())\r\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\r\ndef inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split()))\r\ndef inps(): return sys.stdin.readline()\r\ndef inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x])\r\ndef err(x): print(x); exit()\r\n\r\nn = inp()\r\ns = []\r\nfor _ in range(4):\r\n tmp = [input() for i in range(n)]\r\n if _<3: input()\r\n s.append(tmp)\r\nres = INF\r\nfor pt in itertools.combinations(range(4),2):\r\n cnt = 0\r\n for k in range(4):\r\n f = 1 if k in pt else 0\r\n for i in range(n):\r\n for j in range(n):\r\n if (i+j+f)%2 != int(s[k][i][j]): cnt += 1\r\n res = min(res, cnt)\r\nprint(res)",
"#Bhargey Mehta (Junior)\r\n#DA-IICT, Gandhinagar\r\nimport sys, math, queue, bisect\r\nfrom itertools import permutations\r\n#sys.stdin = open('input.txt', 'r')\r\nMOD = 998244353\r\nsys.setrecursionlimit(1000000)\r\n\r\ndef cost(p, r, s, n):\r\n c = 0\r\n for i in range(n):\r\n for j in range(n):\r\n if p[i][j] != r[s][j]:\r\n c += 1\r\n s = s^1\r\n return c\r\n\r\nn = int(input())\r\np = [[], [], [], []]\r\nfor i in range(4):\r\n for j in range(n):\r\n p[i].append(input())\r\n if i < 3: input()\r\nc = [[], []]\r\nfor i in range(n):\r\n c[(i&1)].append('0')\r\n c[(i&1)^1].append('1')\r\nc[0] = ''.join(c[0])\r\nc[1] = ''.join(c[1])\r\n\r\nans = 5*n*n\r\nfor perm in permutations(range(4)):\r\n u, v, w, x = perm\r\n pc = 0\r\n pc += cost(p[u], c, 0, n)\r\n pc += cost(p[v], c, 1, n)\r\n pc += cost(p[w], c, 1, n)\r\n pc += cost(p[x], c, 0, n)\r\n ans = min(ans, pc)\r\nprint(ans)",
"n=int(input())\r\nc=[0]*4\r\nfor k in range(4):\r\n for i in range(n):\r\n s=input()\r\n for j in range(n):\r\n if(i+j)%2!=int(s[j]):c[k]+=1\r\n if k<3:input()\r\nc.sort()\r\nprint(c[0]+c[1]+2*n*n-c[2]-c[3])\r\n",
"# https://codeforces.com/problemset/problem/961/C\r\nclass BitArray:\r\n \"\"\"implements bitarray using bytearray\"\"\"\r\n def __init__(self, size):\r\n self.bytes = bytearray((size >> 3) + 1)\r\n\r\n def __getitem__(self, index):\r\n return (self.bytes[index >> 3] >> (index & 7)) & 1\r\n\r\n def __setitem__(self, index, value):\r\n if value:\r\n self.bytes[index >> 3] |= 1 << (index & 7)\r\n else:\r\n self.bytes[index >> 3] &= ~(1 << (index & 7))\r\n\r\n\r\nclass BitMatrix(BitArray):\r\n \"\"\"implements bitmatrix using bitarray\"\"\"\r\n def __init__(self, rows, cols):\r\n self.rows = rows\r\n self.cols = cols\r\n super().__init__(rows * cols)\r\n\r\n def __getitem__(self, index):\r\n row, col = index\r\n return super().__getitem__(row * self.cols + col)\r\n \r\n def __setitem__(self, index, value):\r\n row, col = index\r\n super().__setitem__(row * self.cols + col, value)\r\n\r\n def __str__(self):\r\n return '\\n'.join(\r\n ''.join('01'[self[i, j]] for j in range(self.cols))\r\n for i in range(self.rows)\r\n )\r\n def __repr__(self):\r\n return f'{self.__class__.__name__}({self.rows}, {self.cols})'\r\n\r\n def __eq__(self, other):\r\n return self.rows == other.rows and self.cols == other.cols and self.bytes == other.bytes\r\n\r\n# n is the size of each of the 4 segments of the chess board\r\nn = int(input())\r\n\r\nbitmasks = [BitMatrix(n, n) for _ in range(4)]\r\nfor k in range(4):\r\n for i in range(n):\r\n row = input()\r\n for j in range(n):\r\n bitmasks[k][i, j] = row[j] == '1'\r\n if (k != 3):\r\n input()\r\n\r\n\r\ndef check_for_recolor(bitmat):\r\n i_color = False\r\n j_color = False\r\n count = 0\r\n for i in range(bitmat.rows):\r\n j_color = i_color\r\n for j in range(bitmat.cols):\r\n if (bitmat[i, j] != j_color):\r\n count += 1\r\n bitmat[i, j] = j_color\r\n j_color = not j_color\r\n i_color = not i_color\r\n return count, bitmat\r\n\r\nfrom itertools import permutations\r\n\r\nanswers = []\r\nfor k in permutations([0,1,2,3], 4):\r\n bitmask_2n = BitMatrix(2*n, 2*n)\r\n # if (bitmasks[k[0]][0, 0] == bitmasks[k[1]][0,0]):\r\n # continue # since the order is not valid chessboard\r\n for i in range(n):\r\n for j in range(n):\r\n bitmask_2n[i, j] = bitmasks[k[0]][i, j]\r\n bitmask_2n[i, j+n] = bitmasks[k[1]][i, j]\r\n bitmask_2n[i+n, j] = bitmasks[k[2]][i, j]\r\n bitmask_2n[i+n, j+n] = bitmasks[k[3]][i, j]\r\n answers.append(check_for_recolor(bitmask_2n))\r\n\r\nprint(min(answers, key=lambda x: x[0])[0])\r\n# print(min(answers, key=lambda x: x[0])[1])\r\n\r\n\r\n# bitmask_2n = BitMatrix(2*n, 2*n)\r\n# # if (bitmasks[k[0]][0, 0] == bitmasks[k[1]][0,0]):\r\n# # continue # since the order is not valid chessboard\r\n# for i in range(n):\r\n# for j in range(n):\r\n# bitmask_2n[i, j] = bitmasks[0][i, j]\r\n# bitmask_2n[i, j+n] = bitmasks[1][i, j]\r\n# bitmask_2n[i+n, j] = bitmasks[2][i, j]\r\n# bitmask_2n[i+n, j+n] = bitmasks[3][i, j]\r\n# num_changes = check_for_recolor(bitmask_2n)",
"m=1000000007\r\n#------------------------------------#\r\ndef zodom(x):#x is list of nxn\r\n zerodom=0\r\n onedom=0\r\n for i in range(len(x)):\r\n for j in range(len(x[0])):\r\n if (i+j)%2==0:\r\n if x[i][j]=='0':\r\n onedom+=1\r\n else:\r\n zerodom+=1\r\n else:\r\n if x[i][j]=='1':\r\n onedom+=1\r\n else:\r\n zerodom+=1\r\n return(zerodom,onedom)\r\nn=int(input())\r\nL2=[]\r\nfor i in range(4):\r\n L=[]\r\n for _ in range(n):\r\n L.append(input())\r\n L2.append(zodom(L))\r\n if (i!=3):\r\n input()\r\n\r\nmin=float(\"inf\")\r\nfor i in range(2):\r\n for j in range(2):\r\n for k in range(2):\r\n for l in range(2):\r\n if (i+j+k+l)==2 and L2[0][i]+L2[1][j]+L2[2][k]+L2[3][l]<min:\r\n min=L2[0][i]+L2[1][j]+L2[2][k]+L2[3][l]\r\nprint(min)\r\n",
"import sys\r\nfrom itertools import permutations\r\n\r\nn = int(input())\r\nboard = []\r\nfor i in range(4):\r\n board.append([list(map(int, input())) for _ in range(n)])\r\n if i < 3:\r\n input()\r\n\r\n\r\ndef solve(a, b, c, d):\r\n mat = []\r\n for i in range(n):\r\n mat.append(board[a][i] + board[b][i])\r\n for i in range(n):\r\n mat.append(board[c][i] + board[d][i])\r\n\r\n res, color = 0, 0\r\n for i in range(2*n):\r\n for j in range(2*n):\r\n if mat[i][j] == color:\r\n res += 1\r\n color ^= 1\r\n color ^= 1\r\n\r\n return min(res, (2*n)**2 - res)\r\n\r\n\r\nans = 10**9\r\nfor a in permutations(range(4)):\r\n ans = min(ans, solve(*a))\r\n\r\nprint(ans)\r\n",
"import math\r\nfrom decimal import Decimal\r\ndef na():\r\n\tn = int(input())\r\n\tb = [int(x) for x in input().split()]\r\n\treturn n,b\r\n \r\n \r\ndef nab():\r\n\tn = int(input())\r\n\tb = [int(x) for x in input().split()]\r\n\tc = [int(x) for x in input().split()]\r\n\treturn n,b,c\r\n \r\n \r\ndef dv():\r\n\tn, m = map(int, input().split())\r\n\treturn n,m\r\n \r\n \r\ndef dva():\r\n\tn, m = map(int, input().split())\r\n\ta = [int(x) for x in input().split()]\r\n\tb = [int(x) for x in input().split()]\r\n\treturn n,m,b\r\n \r\n \r\ndef eratosthenes(n): \r\n\tsieve = list(range(n + 1))\r\n\tfor i in sieve:\r\n\t\tif i > 1:\r\n\t\t\tfor j in range(i + i, len(sieve), i):\r\n\t\t\t\tsieve[j] = 0\r\n\treturn sorted(set(sieve))\r\n \r\n \r\n \r\ndef nm():\r\n\tn = int(input())\r\n\tb = [int(x) for x in input().split()]\r\n\tm = int(input())\r\n\tc = [int(x) for x in input().split()]\r\n\treturn n,b,m,c\r\n \r\n \r\ndef dvs():\r\n\tn = int(input())\r\n\tm = int(input())\r\n\treturn n, m\r\n \r\n\r\nn = int(input())\r\nd = [0] * 4\r\nfor i in range(4):\r\n\tfor j in range(n):\r\n\t\ts = input()\r\n\t\tfor k in range(n):\r\n\t\t\tif (k + j) % 2 == 0:\r\n\t\t\t\tif s[k] == '1':\r\n\t\t\t\t\td[i] += 1\r\n\t\t\telse:\r\n\t\t\t\tif s[k] == '0':\r\n\t\t\t\t\td[i] += 1\r\n\tif i < 3:\r\n\t\tinput()\r\ndop = n * n\r\nd = sorted(d)\r\nans = dop * 2 + d[0] + d[1] - d[2] - d[3]\r\nprint(ans)\r\n\r\n"
] | {"inputs": ["1\n0\n\n0\n\n1\n\n0", "3\n101\n010\n101\n\n101\n000\n101\n\n010\n101\n011\n\n010\n101\n010", "3\n000\n000\n000\n\n111\n111\n111\n\n111\n111\n111\n\n000\n000\n000", "3\n101\n010\n101\n\n101\n010\n101\n\n101\n010\n101\n\n101\n010\n101", "1\n1\n\n0\n\n1\n\n0", "1\n0\n\n0\n\n1\n\n1", "1\n1\n\n1\n\n0\n\n1", "1\n0\n\n0\n\n0\n\n0", "1\n1\n\n1\n\n0\n\n0"], "outputs": ["1", "2", "16", "18", "0", "0", "1", "2", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 34 | |
2a338b07cfffe109bf58c7f0c5113a13 | Misha and Changing Handles | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone.
In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
Sample Input
5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov
Sample Output
3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123
| [
"n=int(input())\r\na=[]\r\n\r\nfor i in range(n):\r\n b=input().split()\r\n if b[0] in a:\r\n ind=a.index(b[0])\r\n a.insert(ind,b[1])\r\n a.pop(ind+1)\r\n else:\r\n a.append(b[0])\r\n a.append(b[1])\r\nprint(len(a)//2)\r\nfor i in range(len(a)//2):\r\n print(*a[:2])\r\n a=a[2:]\r\n\r\n",
"def find(x):\r\n if a[x] not in a.keys():\r\n return a[x]\r\n else:\r\n return find(a[x])\r\n\r\nn=int(input())\r\na={}\r\nd={}\r\nfor i in range(n):\r\n b,c=input().split()\r\n a[b]=c\r\n d[c]=b\r\ne=[]\r\nfor i in a:\r\n if i not in d.keys():\r\n e.append([i,find(i)])\r\nprint(len(e))\r\nfor i in range(len(e)):\r\n print(*e[i])",
"\r\ncases = int(input())\r\nchanged = 0\r\nseen = set()\r\nfinal = {}\r\nfor _ in range(cases):\r\n old, new = input().split()\r\n # print(seen)\r\n # print(final)\r\n if new in seen:\r\n continue\r\n if old not in seen:\r\n changed += 1\r\n if old in seen and new not in seen:\r\n for key, val in final.items():\r\n if val == old:\r\n final[key] = new\r\n break\r\n else:\r\n final[old] = new\r\n seen.add(old)\r\n seen.add(new)\r\n\r\nprint(changed)\r\n\r\nfor key, val in final.items():\r\n print(key, val)",
"n=int(input())\r\nd={}\r\nfor j in range(n):\r\n\tl=list(map(str,input().split()))\r\n\tif l[0] in d:\r\n\t\td[l[1]]=d[l[0]]\r\n\t\td.pop(l[0])\r\n\telse:\r\n\t\td[l[1]]=l[0]\r\nprint(len(d))\r\nfor i in d:\r\n\tprint(d[i],i)",
"linhas = int(input())\r\n\r\ndic = {}\r\nstack = []\r\n\r\nfor i in range(linhas):\r\n old, new = input().split()\r\n if(old in set(list(dic.values()))):\r\n index = list(dic.values()).index(old)\r\n dic[list(dic.keys())[index]] = new\r\n stack.append(list(dic.keys())[index])\r\n else:\r\n dic[old] = new\r\n stack.append(old)\r\n \r\nprint(len(dic))\r\nconj = set([])\r\n \r\nfor i in range(len(dic)):\r\n tmp = stack.pop()\r\n while tmp in conj:\r\n tmp = stack.pop()\r\n print(tmp + \" \" + dic[tmp])\r\n conj.add(tmp)",
"\n\nhandles = {}\nnum_req = int(input())\nfor _ in range(num_req):\n old, new = input().strip().split(' ')\n # verificamos si el nuevo nombre ya existe\n if new in handles.items():\n continue\n # si el nombre antiguo esta entre los values\n if old in handles.values():\n # buscamos la llave original\n name = next(filter(lambda x: x[1] == old, handles.items()))[0]\n handles[name] = new\n continue\n # si el nombre antiguo no está entre los valores\n # creamos el nuevo\n handles[old] = new\n\nprint(len(handles))\nfor k, v in handles.items():\n print(f'{k} {v}')\n",
"import fileinput\r\n\r\ndata = []\r\nwith fileinput.input() as f:\r\n for line in f:\r\n data.append(line.strip())\r\n\r\ngraph = {}\r\nnames = []\r\nnames2 = []\r\nfor i in range(1, len(data)):\r\n names.append(data[i].split(' ')[0])\r\n names2.append(data[i].split(' ')[1])\r\n graph[data[i].split(' ')[0]] = (data[i].split(' ')[1], None)\r\n graph[data[i].split(' ')[1]] = (None, data[i].split(' ')[0])\r\n\r\ncounter = 0\r\noutput = []\r\nfor name in names:\r\n if name not in names2:\r\n name_aux = graph[name][0]\r\n while(graph[name_aux][0]):\r\n name_aux = graph[name_aux][0]\r\n output.append(name+\" \"+name_aux)\r\n counter += 1\r\n\r\nprint(counter)\r\nfor line in output:\r\n print(line)",
"n = int(input())\r\n\r\ndic = {}\r\n\r\nfor i in range(n):\r\n nomes = input().split()\r\n old, new = nomes[0], nomes[1]\r\n if new not in dic.values():\r\n if old in dic.values():\r\n for i in dic.items():\r\n if i[1] == old:\r\n dic[i[0]] = new\r\n else:\r\n dic[old] = new\r\n\r\nprint(len(dic.keys()))\r\nfor i in dic.keys():\r\n print(i, dic[i])",
"n = int(input())\ndt = {}\n\nfor i in range(n):\n a = input().split(' ')\n if a[0] in dt.keys():\n dt[a[1]] = dt[a[0]]\n del dt[a[0]]\n else:\n dt[a[1]] = a[0]\n\nprint(len(dt))\n\nfor k, v in dt.items():\n print (v + ' ' + k)",
"# Imports\nfrom typing import Dict, List\n\nq: int = int(input())\nnew: str = ''\nold: str = '' \n\ndatabase: Dict[str, List[str]] = dict()\n\nfor i in range(q):\n\n\t# old new\n\told, new = input().split()\n\t\n\ttry:\n\t\tif database[old]: # checking if previous records exists\n\t\t\tdatabase[new] = database[old] + [old]\n\t\t\tdel database[old]\n\texcept KeyError: # such entry has never been made before and is a new one\n\t\tdatabase[new] = [old]\n\nprint(len(database))\t\nfor key, value in database.items():\n\tprint(value[0], key, sep=' ')\n",
"import sys, threading\ninput = sys.stdin.readline\nfrom collections import defaultdict\ninput = sys.stdin.readline\n\n# returns the first number where key becomes true for a given delegate type key\ndef bs(low=1, high=1, key = lambda x: True):\n\n while low <= high:\n mid = (low + high)//2\n if key(mid):\n high = mid-1\n else:\n low = mid+1\n return low\n\n\ndef main():\n t = int(input())\n queries = defaultdict(str)\n for _ in range(t):\n o, n = input().strip().split()\n for key in queries:\n if queries[key] == o:\n queries[key] = n\n break\n else:\n queries[o] = n\n\n print(len(queries))\n for key in queries:\n print(key, queries[key])\n\nmain()\n",
"n = int(input())\r\nl = {}\r\nfor i in range(n):\r\n o, n = input().split()\r\n l[n] = l.get(o, o)\r\n l.pop(o, None)\r\nprint(len(l))\r\nfor n, o in l.items():\r\n print(o, n)\r\n",
"from collections import defaultdict as dd\nfrom sys import setrecursionlimit\nsetrecursionlimit(11000)\n\nq = int(input())\nvis = dd(int)\nnames = dict()\nans = []\n\n\ndef findNew(name):\n if names.get(name, -1) == -1:\n return name\n\n vis[name] = 1\n\n return findNew(names.get(name))\n\n\nfor _ in range(q):\n s, t = input().split()\n names[s] = t\n\nfor name in names:\n if vis[name] != 1:\n ans.append((name, findNew(name)))\n\nprint(len(ans))\nfor i in ans:\n print(i[0], i[1])\n",
"import sys\r\n\r\ndata = sys.stdin.readlines()\r\narchivo = [line.split() for line in data]\r\n\r\n\r\ncambios = int(archivo[0][0])\r\ndic = {}\r\ncontador=0\r\nlista=[]\r\n\r\nfor i in range(cambios):\r\n\tdic[archivo[i+1][0]] = archivo[i+1][1]\r\n\r\nfor key, value in dic.items():\r\n\tviejo = key\r\n\tnuevo = value\r\n\teliminar = nuevo\r\n\twhile True:\r\n\t\tif nuevo in dic.keys():\r\n\t\t\teliminar = nuevo\r\n\t\t\tnuevo = dic.get(nuevo)\r\n\t\t\tdic[eliminar] = 0\r\n\t\telse:\r\n\t\t\tif eliminar != 0 and nuevo != 0:\r\n\t\t\t\tcambio = viejo + \" \" + nuevo\r\n\t\t\t\tlista.append(cambio)\r\n\t\t\tbreak\r\n\r\n\r\nprint(len(lista))\r\nfor i in lista:\r\n\tprint(i)\r\n\r\n\r\n",
"t = int(input())\r\ncurr = {}\r\norg = {}\r\n\r\nfor _ in range(t):\r\n old, new = input().split()\r\n\r\n if old not in org:\r\n curr[old] = new\r\n org[new] = old\r\n else:\r\n original = org[old]\r\n curr[original] = new\r\n org[new] = original\r\n\r\nprint(len(curr))\r\nfor name in curr:\r\n print(name, curr[name])",
"# inputList = [\r\n# ['Misha', 'ILoveCodeforces'],['Vasya','Petrov'],['Petrov','VasyaPetrov123'],['ILoveCodeforces','MikeMirzayanov'],['Petya','Ivanov']\r\n# ]\r\n\r\ninputList = []\r\nn = int(input())\r\nfor i in range(n):\r\n tempList = list(input().split())\r\n inputList.append(tempList)\r\noldNames = []\r\nnewNames = []\r\n\r\nfor tempList in inputList:\r\n oldName, newName = tempList[0],tempList[1]\r\n if oldName not in newNames:\r\n oldNames.append(oldName)\r\n newNames.append(newName)\r\n # print('adike')\r\n # print(oldName,newName)\r\n # print('oldNames:',oldNames)\r\n # print('newNames:',newNames)\r\n # print('\\n')\r\n else:\r\n idx = newNames.index(oldName)\r\n newNames[idx] = newName\r\n # print('ei khane')\r\n # print(oldName,newName)\r\n # print('oldNames:',oldNames)\r\n # print('newNames:',newNames)\r\n # print('\\n')\r\n\r\n\r\nprint(len(oldNames))\r\nfor oldName,newName in zip(oldNames,newNames):\r\n print(oldName,newName)",
"\nmapping = {}\n\n\ndef buildHash(old, new):\n mapping[old] = new\n\n\ntestcase = int(input())\nfor i in range(testcase):\n old, new = input().split(' ')\n buildHash(old, new)\n\n\nres = {}\nsett = set()\nfor o, n in mapping.items():\n if o not in sett:\n curr = n\n # sett.add(curr)\n while curr in mapping:\n sett.add(curr)\n curr = mapping[curr]\n res[o] = curr\n# print(res)\nprint(len(res))\nfor k, v in res.items():\n print(k, \" \", v)\n",
"\"\"\"\r\n-----------------------------Pseudo---------------------------------\r\n501B misha and changing handles----dsu\r\n\r\n\"\"\"\r\nimport copy\r\nimport sys\r\nfrom collections import defaultdict, Counter\r\n#sys.setrecursionlimit(20000)\r\n\r\ndef input(): return sys.stdin.readline()\r\ndef mapi(): return map(int,input().split())\r\ndef maps(): return map(str,input().split())\r\n#\r\ndef print(arg, *argv, end=None):\r\n sys.stdout.write(str(arg))\r\n for i in argv: sys.stdout.write(\" \"+str(i))\r\n sys.stdout.write(end) if end else sys.stdout.write(\"\\n\")\r\n#\r\ndef GCD(x, y): return GCD(y,x%y) if y else x\r\n#\r\ndef modPow(x, y, p):\r\n res,x = 1,x%p\r\n while(y>0):\r\n if(y&1)==1: res=(res*x)%p\r\n y,x = y>>1,(x*x)%p\r\n return res\r\ndef modInv(s, mod): return modPow(s,mod-2,mod)\r\n#---------------------------------------------------------------#\r\n\r\n\r\n\r\ndef solve():\r\n \"\"\"\r\n naive approach bruteforce\r\n \"\"\"\r\n t = 1\r\n #t = int(input())\r\n while(t):\r\n t-=1\r\n n = int(input())\r\n tmp = {}\r\n for i in range(n):\r\n a,b = maps()\r\n tmp[a]=b\r\n res = []\r\n dn = {}\r\n for key,val in tmp.items():\r\n if key not in dn:\r\n x = val\r\n while x in tmp:\r\n dn[x]=1\r\n x = tmp[x]\r\n dn[key] = 1\r\n res.append([key,x])\r\n print(len(res))\r\n for i in res:\r\n print(\" \".join(i))\r\n\r\n\r\n#---------------------------------------------------------------#\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n\r\n",
"# MC521 - Desafios de Programacao I - 1s2021\n# Contest: 02/04/2021\n# Problema J: Misha and Changing Handles\n\n# le o numero de alteracoes a serem realizadas\nn = int(input())\n\n# inicializa o mapa dos idenficadores\nalt = {}\n\n# realiza a leitura das alteracoes e mapeia os identificadores dos usuarios\nfor _ in range(n):\n # le o identificador antigo e o novo\n antigo, novo = input().split()\n\n # checa se o identficador a ser atualizado existe\n if(antigo not in alt):\n # caso nao exista\n alt[novo] = antigo\n else:\n # caso exista, atualiza e remove o antigo\n alt[novo] = alt[antigo]\n alt.pop(antigo, None)\n\n# imprime a quantidade de usuarios diferentes\nprint(len(alt))\n# imprime os idenficadores iniciais e finais de cada usuario\nfor chave in alt:\n print('{name1} {name2}'.format(name1=alt[chave], name2=chave))\n\t\t \t \t \t \t \t\t \t \t \t",
"import collections\n\ndef dfs(graph, start, curNode):\n if not graph[curNode]:\n global res; res[start] = curNode\n return\n for nxtNode in graph[curNode]:\n dfs(graph, start, nxtNode)\nif __name__ == '__main__':\n n = int(input())\n strs = []\n graph = collections.defaultdict(list)\n inDeg = collections.defaultdict(int)\n for i in range(n):\n s, t = list(map(str, input().strip().split()))\n strs.append(s); strs.append(t)\n graph[s].append(t)\n inDeg[t] += 1\n que = collections.deque([])\n global res; res = collections.defaultdict(str)\n for start in strs:\n if start not in inDeg:\n dfs(graph, start, start)\n print(len(res))\n for start in res:\n print(start, res[start])",
"n = int(input())\r\n\r\nd = dict()\r\nfor i in range(n):\r\n a, b = input().split()\r\n if a not in d.values():\r\n d[a] = b\r\n else:\r\n for i in d:\r\n if a == d[i]:\r\n d[i] = b\r\nprint(len(d))\r\nfor i in d:\r\n print(i, end = \" \")\r\n print(d[i])",
"n=int(input())\r\na=dict()\r\nfor i in range(n):\r\n a.update({map(str,input().split())})\r\nk=0\r\nb=dict()\r\nfor i in a:\r\n if i not in a.values():\r\n j=a[i]\r\n while j in a.keys():\r\n j=a[j]\r\n k+=1\r\n b.update({i:j})\r\nprint(k)\r\nfor i in b:\r\n print(i,b[i])",
"# q = int(input())\n# my_list = []\n# for i in range(q):\n# line = input()\n# my_list.append(line.split(' '))\n# result = []\n\n# for j in range(len(my_list)):\n# old_name, new_name = my_list[j][0], my_list[j][1]\n\n# still_changing_names = False\n\n# for k in range(j+1, len(my_list)):\n# if new_name == my_list[k][0]:\n# still_changing_names = True\n# my_list[k][0] = old_name\n# break\n\n# if not still_changing_names:\n# result.append([old_name, new_name])\n\n# print(len(result))\n# for item in result:\n# print(*item)\n\n\nq = int(input())\nresult = {} # new_names are keys and old_names are values.\nfor i in range(q):\n line = input()\n old_name, new_name = line.split(' ')\n if old_name in result.keys():\n original_name = result[old_name]\n del result[old_name]\n result[new_name] = original_name\n else:\n result[new_name] = old_name\n\nprint(len(result))\nfor new_name, original_name in result.items():\n print(original_name, new_name)",
"def ff(x,a,s):\r\n if x[a]==a:\r\n s.add(a)\r\n return a \r\n s.add(x[a])\r\n return ff(x,x[a],s)\r\ndef find(x,a):\r\n if x[a]==a:\r\n return x[a]\r\n x[a]=find(x,x[a])\r\n return x[a]\r\n \r\ndef union(x,a,b):\r\n xx=find(x,a)\r\n yy=find(x,b)\r\n if xx!=yy:\r\n x[xx]=yy \r\nd={}\r\nfor _ in range(int(input())):\r\n x,y=map(str,input().split())\r\n d[x]=y\r\nx={}\r\ny={}\r\ns=set()\r\nfor a,b in d.items():\r\n s.add(a)\r\n s.add(b)\r\nfor i in s:\r\n x[i]=i\r\n y[i]=True\r\n\r\nfor a,b in d.items():\r\n union(x,a,b)\r\n\r\nans={}\r\nss=set()\r\nfor a,b in d.items():\r\n if a not in ss:\r\n ss.add(a)\r\n ans[a]=ff(x,a,ss)\r\nprint(len(ans))\r\nfor a,b in ans.items():\r\n print(\"{} {}\".format(a,b))\r\n",
"from collections import Counter\r\nfrom collections import defaultdict\r\nimport math\r\nimport random\r\nimport heapq as hq\r\nfrom math import sqrt\r\nimport sys\r\n\r\n\r\ndef input():\r\n return sys.stdin.readline().strip()\r\n\r\n\r\ndef iinput():\r\n return int(input())\r\n\r\n\r\ndef tinput():\r\n return input().split()\r\n\r\n\r\ndef rinput():\r\n return map(int, tinput())\r\n\r\n\r\ndef rlinput():\r\n return list(rinput())\r\n\r\n\r\nmod = int(1e9)+7\r\n\r\n\r\ndef root(parent,a):\r\n while parent[a]!=a:\r\n parent[a]=parent[parent[a]]\r\n a=parent[a]\r\n return a\r\n\r\n\r\ndef union(parent, size, a, b):\r\n\r\n root_a, root_b = root(parent,a), root(parent,b)\r\n\r\n if root_a==root_b:\r\n return \r\n if size[root_a]>=size[root_b]:\r\n parent[root_b]=root_a\r\n size[root_a]+=size[root_b]\r\n size[root_b]=0\r\n else:\r\n parent[root_a]=root_b\r\n size[root_b]+=size[root_a]\r\n size[root_a]=0\r\n \r\n \r\n\r\n\r\n\r\ndef solve(d,n):\r\n dcpy=d.copy()\r\n for i in dcpy:\r\n if i in d:\r\n temp=i\r\n while temp in d:\r\n temp1=temp\r\n temp=d[temp]\r\n del d[temp1] \r\n d[i]=temp\r\n print(len(d))\r\n for i in d:\r\n print(i,d[i])\r\n \r\n\r\n\r\nif __name__ == \"__main__\":\r\n\r\n n=iinput()\r\n d=dict()\r\n for i in range(n):\r\n a,b=input().split()\r\n d[a]=b\r\n solve(d,n)\r\n",
"par = []\ncount = 0\n\ndef makeSet(n):\n global par\n for i in range(n + 1):\n par.append(i)\n\ndef find(a):\n global par\n if a == par[a]:\n return a\n par[a] = find(par[a])\n return par[a]\n\ndef union(a, b):\n global par\n par[find(a)] = find(b)\n\ndef main():\n global par, count\n n = int(input())\n makeSet(10000)\n m = {}\n og = set()\n for i in range(n):\n (old, new) = input().split(' ')\n if old not in m:\n m[old] = count\n count += 1\n og.add(old)\n if new not in m:\n m[new] = count\n count += 1\n union(m[old], m[new])\n rev = {}\n for i in m:\n rev[m[i]] = i\n print(len(og))\n for o in og:\n print(o, rev[find(m[o])])\n\nmain()\n",
"n=int(input())\r\ndir={}\r\nfor z in range(n):\r\n old,new=input().split()\r\n flag=True\r\n for ii in dir:\r\n if(dir[ii]==old):\r\n dir[ii]=new\r\n flag=False\r\n break\r\n if(flag):\r\n dir[old]=new\r\nprint(len(dir))\r\nfor ii in dir:\r\n print(ii,dir[ii])",
"starting_names = []\r\nending_names = []\r\n\r\nfor _ in range(int(input())):\r\n \r\n h1, h2 = input().split()\r\n\r\n if h1 not in ending_names:\r\n starting_names.append(h1)\r\n ending_names.append(h2)\r\n else:\r\n ending_names[ending_names.index(h1)] = h2\r\n \r\n\r\nprint(len(starting_names))\r\nfor x in range(len(ending_names)):\r\n print(starting_names[x] + ' ' + ending_names[x])",
"n = int(input())\r\nd = dict()\r\nold = \"\"\r\nnew = \"\"\r\nfor i in range(n):\r\n old, new = input().split()\r\n if d.get(old) == None:\r\n d[new] = old\r\n else:\r\n d[new] = d[old]\r\n d.pop(old)\r\nlent = len(d)\r\nprint(lent)\r\nfor a in d:\r\n print(d[a], a)",
"import collections\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\ninf = 1_000_000_000 + 7\r\nmod = inf\r\n\r\n\r\ndef find(a: list[int], q: int) -> bool:\r\n i = find_lower(a, q)\r\n return i >= 0 and a[i] == q\r\n\r\n\r\ndef binary_search(a: list[int], x: int) -> int:\r\n \"\"\"find i: a[i] = x. Else -1\"\"\"\r\n i = find_lower(a, x)\r\n return i if (i >= 0 and a[i] == x) else -1\r\n\r\n\r\ndef find_lower(a: list[int], x: int) -> int:\r\n \"\"\"max i: a[i] <= x\"\"\"\r\n l = -1 # a[l] <= x\r\n r = len(a) # a[r] > x\r\n while r > l + 1:\r\n m = (l + r) // 2\r\n if a[m] <= x:\r\n l = m\r\n else:\r\n r = m\r\n\r\n return l\r\n\r\n\r\ndef find_upper(a: list[int], x: int) -> int:\r\n \"\"\"min i: a[i] >= x\"\"\"\r\n l = -1\r\n r = len(a)\r\n while l + 1 < r:\r\n m = (l + r) // 2\r\n if a[m] >= x:\r\n r = m\r\n else:\r\n l = m\r\n\r\n return r\r\n\r\n\r\ndef linear_search(a: list[int], x: int) -> int:\r\n for i, num in enumerate(a):\r\n if num == x:\r\n return i\r\n\r\n return -1\r\n\r\n\r\ndef rec_dfs(graph: list[list[int]]) -> None:\r\n n = len(graph)\r\n visited = [False] * n\r\n\r\n def dfs(u: int) -> None:\r\n visited[u] = True\r\n for v in graph[u]:\r\n if not visited[v]:\r\n dfs(v)\r\n\r\n for i in range(1, n + 1):\r\n if not visited[i]:\r\n dfs(i)\r\n\r\n\r\ndef iter_dfs(graph: list[list[int]]) -> None:\r\n n = len(graph)\r\n visited = [False] * n\r\n\r\n def dfs(v: int) -> None:\r\n q = collections.deque()\r\n q.append(v)\r\n while q:\r\n u = q.popleft()\r\n if not visited[u]:\r\n for x in graph[u]:\r\n q.append(x)\r\n\r\n for i in range(1, n + 1):\r\n if not visited[i]:\r\n dfs(i)\r\n\r\n\r\ndef bfs(graph: list[list[int]], source: int, dest: int) -> int:\r\n global inf\r\n d = [inf] * len(graph)\r\n d[source] = 0\r\n q = collections.deque()\r\n q.append(source)\r\n while q:\r\n u = q.popleft()\r\n for v in graph[u]:\r\n if d[v] == inf:\r\n d[v] = 1 + d[u]\r\n q.append(v)\r\n\r\n return d[dest]\r\n\r\n\r\ndef quick_pow(x: int, n: int) -> float:\r\n if n < 0:\r\n return 1 / quick_pow(x, -n)\r\n if n == 0:\r\n return 1\r\n if n % 2 == 0:\r\n return quick_pow(x, n // 2) * quick_pow(x, n // 2)\r\n return x * quick_pow(x, n - 1)\r\n\r\n\r\ndef gcd(a: int, b: int) -> int:\r\n if a > 0:\r\n return gcd(b % a, a)\r\n return b\r\n\r\n\r\ndef sieve(n: int) -> list[bool]:\r\n prime = [True for _ in range(n + 1)]\r\n p = 2\r\n while p * p <= n:\r\n if prime[p]:\r\n for i in range(p * p, n + 1, p):\r\n prime[i] = False\r\n p += 1\r\n\r\n return prime\r\n\r\n\r\nclass SegmentTree:\r\n # TODO: complete tree ^^\r\n size: int\r\n tree: list[int]\r\n\r\n def __init__(self, n: int, a: list[int]) -> None:\r\n self.size = 1\r\n while self.size < n:\r\n self.size *= 2\r\n\r\n self.tree = [0] * (2 * self.size - 1)\r\n # self.build(a, )\r\n\r\n\r\ndef print_matrix(matrix: dict[list[int]]) -> None:\r\n for row in matrix.values():\r\n sys.stdout.write(\" \".join(str(x) for x in row))\r\n sys.stdout.write(\"\\n\")\r\n\r\n\r\ndef print_answer(flag: bool) -> None:\r\n sys.stdout.write(\"YES\\n\") if flag else sys.stdout.write(\"NO\\n\")\r\n\r\n\r\ndef print_list(array: list[int]) -> None:\r\n sys.stdout.write(\" \".join(str(x) for x in array))\r\n sys.stdout.write(\"\\n\")\r\n\r\n\r\ndef print_int(x: int) -> None:\r\n sys.stdout.write(f\"{x}\\n\")\r\n\r\n\r\ndef read_int() -> int:\r\n return int(input().strip())\r\n\r\n\r\ndef read_tuple() -> (int, int):\r\n return map(int, input().split())\r\n\r\n\r\ndef read_tuple_strings() -> (str, str):\r\n return input().split()\r\n\r\n\r\ndef read_list() -> list[int]:\r\n return list(map(int, input().split()))\r\n\r\n\r\nclass DSU:\r\n def __init__(self, n: int) -> None:\r\n self.cc = n\r\n self.rank = [1] * (n + 1)\r\n self.parent = [i for i in range(n + 1)]\r\n\r\n # def make_set(self, x: int):\r\n # self.parent[x] = x\r\n # self.rank[x] = 1\r\n\r\n def find(self, x: int) -> int:\r\n if x != self.parent[x]:\r\n self.parent[x] = self.find(self.parent[x])\r\n return self.parent[x]\r\n\r\n def union(self, x: int, y: int) -> None:\r\n x = self.find(x)\r\n y = self.find(y)\r\n if x != y:\r\n self.cc -= 1\r\n if self.rank[x] < self.rank[y]:\r\n x, y = y, x\r\n self.parent[y] = x\r\n diff = self.rank[y]\r\n self.rank[x] += diff\r\n\r\n\r\ndef solve():\r\n t = read_int()\r\n hash_map = dict()\r\n while t > 0:\r\n t -= 1\r\n old, new = input().split()\r\n if old not in hash_map.keys():\r\n hash_map[new] = old\r\n else:\r\n hash_map[new] = hash_map[old]\r\n hash_map.pop(old)\r\n\r\n return hash_map\r\n\r\n\r\ndef main():\r\n hash_map = solve()\r\n print_int(len(hash_map.keys()))\r\n for key in hash_map.keys():\r\n sys.stdout.write(f\"{hash_map[key]} {key}\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n = int(input())\r\nd1 = {}\r\nfor i in range(n):\r\n old, new = input().split()\r\n if old in d1.values():\r\n for key in d1:\r\n if d1[key] == old:\r\n d1[key] = new\r\n else:\r\n d1[old] = new\r\nprint(len(d1))\r\nfor k,v in d1.items():\r\n print(k, v)",
"n_changes = int(input())\n\ndict_original_handles = {}\ndict_newhandles = {}\n\nfor _ in range(n_changes):\n old, new = input().split()\n if old in dict_newhandles:\n prev_name = dict_original_handles[dict_newhandles[old]]\n dict_original_handles[dict_newhandles[old]] = new\n\n dict_newhandles[new] = dict_newhandles[old]\n \n else:\n\n dict_original_handles[old] = new\n dict_newhandles[new] = old\n\nprint(len(dict_original_handles))\nfor key, value in dict_original_handles.items():\n print(key, value)\n\t\t \t \t\t \t \t \t \t \t\t \t \t\t\t\t \t\t\t",
"from collections import defaultdict\r\n\r\np=defaultdict()\r\nl=defaultdict()\r\n\r\ndef find(x):\r\n if p[x]!=x:\r\n p[x]=find(p[x])\r\n return p[x]\r\n\r\nfor _ in range(int(input())):\r\n a,b=input().split()\r\n if a not in p:\r\n p[a]=a \r\n p[b]=find(a)\r\n l[p[b]]=b\r\n\r\nprint(len(l))\r\n\r\nfor x in l:\r\n print(x,l[x])\r\n",
"#Exercício J\n\nn = int(input())\noldNames = []\nnewNames = []\nfor i in range(n):\n old, new = input().split()\n if old in newNames:\n pos = newNames.index(old)\n newNames[pos] = new\n else:\n oldNames.append(old)\n newNames.append(new)\n\n\nsize = len(oldNames)\nprint(size)\nfor j in range(size):\n print(\"%s %s\" %(oldNames[j], newNames[j]))\n\n\t\t \t \t \t \t\t\t \t\t\t \t \t\t\t",
"#Coding is about expressing your feeling and there is always a better way to express your feeling_feelme\r\nimport sys\r\ntry:sys.stdin,sys.stdout=open('in.txt','r'),open('out.txt','w')\r\nexcept:pass\r\nii1=lambda:int(sys.stdin.readline().strip()) # for interger\r\nis1=lambda:sys.stdin.readline().strip() # for str\r\niia=lambda:list(map(int,sys.stdin.readline().strip().split())) # for List[int]\r\nisa=lambda:sys.stdin.readline().strip().split() # for List[str]\r\nmod=int(1e9 + 7);from collections import *;from math import *\r\n\r\n###################### Start Here ######################\r\ndef fun():\r\n n = ii1()\r\n parent = [-1]*n\r\n dic = {}\r\n arr = []\r\n for i in range(n):\r\n old,new = isa()\r\n arr.append([old,new])\r\n dic[old]=new\r\n res = []\r\n for old,new in arr:\r\n flag=False\r\n if old in dic:\r\n flag=True\r\n while new in dic:\r\n t=new\r\n new = dic[t]\r\n del dic[t]\r\n if flag:\r\n res.append([old,new])\r\n print(len(res))\r\n for a,b in res:\r\n print(a,b)\r\nif __name__=='__main__':\r\n fun()\r\n\r\n",
"\nimport sys\ninput=sys.stdin.readline\nn = int(input())\nd = dict()\nd1 = dict()\nfor i in range(n):\n old, new = input().split()\n if d1.get(old,-1) == -1:\n d[old] = new\n d1[new] = old\n else:\n d[d1[old]] = new\n d1[new] = d1[old]\nprint(len(d))\nfor i in d.keys():\n print(i,d[i])\n\n",
"#from sys import stdin,stdout\r\n#input = stdin.readline\r\n \r\ndef main():\r\n #t = int(input())\r\n t = 1\r\n for z in range(t):\r\n n = int(input())\r\n #n,t = map(int,input().split())\r\n #ai = list(map(int,input().split()))\r\n d = {}\r\n for i in range(n):\r\n o,ne = input().split()\r\n if o in d:\r\n d[ne] = d[o]\r\n d[o] = \"\"\r\n else:\r\n d[ne] = o\r\n ar = []\r\n for i in d:\r\n if d[i] != \"\":\r\n ar += [[d[i],i]]\r\n print(len(ar))\r\n for i in ar:\r\n print(i[0],i[1])\r\nmain()\r\n",
"n = int(input())\r\n\r\nk = 0\r\n\r\n#current = dict()\r\ninitial = dict()\r\n\r\ninp = [input().split() for i in range(n)]\r\n\r\nfor old, new in inp:\r\n if old not in initial:\r\n initial[new] = old\r\n initial[old] = old\r\n else: \r\n initial[new] = initial[old]\r\n\r\ncurr = dict()\r\n\r\nfor _, new in inp:\r\n curr[initial[new]] = new\r\n\r\nprint(len(curr.keys()))\r\nfor it in curr.items():\r\n print(*it)\r\n",
"q = int(input())\r\na = []\r\nb = []\r\nfor i in range(q):\r\n m, n = input().split()\r\n if not m in b:\r\n a.append(m)\r\n b.append(n)\r\n else:\r\n b[b.index(m)] = n\r\nprint(len(a))\r\nfor i in range(len(a)):\r\n print(a[i], ' ', b[i]) \r\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nx = []\r\ny = []\r\nfor _ in range(int(input())):\r\n a, b = input()[:-1].split()\r\n\r\n if a in y:\r\n y[y.index(a)] = b\r\n else:\r\n x.append(a)\r\n y.append(b)\r\n\r\nc = len(x)\r\nprint(c)\r\nfor i in range(c):\r\n print(x[i], y[i])\r\n",
"import sys\ninput = sys.stdin.readline\n\n\ndef inp():\n return (int(input()))\n\n\ndef inlt():\n return (list(map(int, input().split())))\n\n\ndef insr():\n s = input()\n return (list(s[:len(s) - 1]))\n\n\ndef invr():\n return list(map(int, input().split()))\n\n\ndef solve(arr):\n r = []\n for i, a in enumerate(arr):\n if a is None:\n continue\n first = arr[i]\n arr[i] = None\n last = first\n for j in range(i+1, n):\n if arr[j] is not None and arr[j][0] == last[1]:\n last = arr[j]\n arr[j] = None\n r.append([first[0], last[1]])\n\n return r\n\n\nif __name__ == '__main__':\n n = inp()\n arr = []\n for i in range(n):\n s = input()[:-1].split(\" \")\n arr.append(s)\n res = solve(arr)\n print(len(res))\n for i in range(len(res)):\n print(\" \".join(res[i]))\n",
"\r\n#k=int(input())\r\n#n,m=map(int,input().split())\r\n\r\n#a=list(map(int,input().split()))\r\n\r\n#b=list(map(int,input().split()))\r\n\r\nd=dict()\r\n\r\nn=int(input())\r\n\r\nfor i in range(n):\r\n x,y=input().split()\r\n\r\n if x in d:\r\n d[y]=d[x]\r\n d.pop(x)\r\n else:\r\n d[y]=x\r\n\r\nprint(len(d))\r\n\r\nfor i in d:\r\n print(d[i],i)\r\n\r\n",
"n = int(input())\n\nkeys = []\nvalues = []\n\nfor _ in range(n):\n old, new = input().split()\n\n if old in values:\n values[values.index(old)] = new\n else:\n keys.append(old)\n values.append(new)\n\nprint(len(keys))\nfor i in range(len(keys)):\n print(keys[i], values[i])\n\n \t\t\t \t\t\t \t \t\t \t\t\t\t \t\t\t\t\t",
"n = int(input())\r\nd = {}\r\nfor i in range(n):\r\n a = input().split()\r\n d[a[0]] = a[1]\r\na = []\r\nfor i in d.keys():\r\n l = i;\r\n while(l in d):\r\n t = d[l]\r\n d[l] = None\r\n l = t\r\n if(l != None):\r\n a.append(str(i) + \" \" + str(l))\r\nprint(len(a))\r\nfor i in a:\r\n print(i)\r\n ",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Sep 9 19:08:07 2019\r\n\r\n@author: avina\r\n\"\"\"\r\n\r\ndef dfs(d,u, visted):\r\n visted[u] = True\r\n \r\n while True:\r\n if u not in d:\r\n break\r\n u = d[u]\r\n visted[u] = True\r\n return u\r\nn = int(input())\r\n\r\nl = {}\r\nvisted = {}\r\nfor i in range(n):\r\n a,b = input().split()\r\n l[a] = b\r\n visted[a] = False\r\nk = 0\r\ne = []\r\nfor i in l:\r\n if visted[i] == False:\r\n k+=1\r\n a = dfs(l,i,visted)\r\n e.append((i,a))\r\n\r\nprint(k)\r\nfor i in range(k):\r\n print(*e[i])",
"entrada = int(input())\nnomes = {}\nsaida = {}\n\nfor i in range(entrada):\n anterior, novo = input().split()\n nomes[anterior] = novo\n\nfor key in nomes.keys():\n atual = key\n while atual in nomes.keys():\n atual = nomes[atual]\n if atual in saida.values():\n continue\n saida[key] = atual\n\nprint(len(saida))\nfor i in saida.keys():\n print(i + ' ' + saida[i])\n \t\t\t\t\t\t\t \t \t \t \t\t\t \t \t",
"n=int(input())\r\nm={}\r\nfor i in range(n):\r\n x,y=input().split()\r\n m[x]=y \r\n for s in m.keys():\r\n if m.get(s)==x:\r\n m.pop(x)\r\n m[s]=y \r\n break \r\nprint(len(m))\r\nfor s in m.keys():\r\n print(s,m[s])",
"def root(a):\r\n while parent[a]!=a:\r\n parent[a]=parent[parent[a]]\r\n a=parent[a]\r\n return a\r\n \r\ndef union(a,b):\r\n a=root(a)\r\n b=root(b)\r\n parent[a]=b\r\n\r\nfrom collections import defaultdict\r\nn=int(input())\r\nparent={}\r\nuser=[]\r\nfor _ in range(n): \r\n old,new=input().split()\r\n user.append(old)\r\n parent[old]=old\r\n parent[new]=new\r\n union(old,new)\r\n\r\ntaken=defaultdict(bool)\r\n\r\nans={}\r\nc=0\r\nfor u in user:\r\n if not taken[root(u)]:\r\n ans[u]=root(u)\r\n taken[root(u)]=True\r\n c+=1\r\nprint(c)\r\nfor m in ans:\r\n print(m,ans[m])\r\n\r\n\r\n",
"n=int(input())\r\nV=[]\r\nL=[]\r\nL1=[]\r\nfor i in range(n) :\r\n M=input().split()\r\n if M[0] not in L1 :\r\n L.append(M[0])\r\n V.append(M[0])\r\n if M[1] in V :\r\n L1.append(M[0])\r\n else :\r\n L1.append(M[1])\r\n V.append(M[1])\r\n else :\r\n if M[1] not in V :\r\n V.append(M[1])\r\n L1[L1.index(M[0])]=M[1]\r\nk=0\r\nfor i in range(len(L)) :\r\n if L[i]!=L1[i] :\r\n k=k+1\r\nprint(k)\r\nfor i in range(len(L)) :\r\n if L[i]!=L1[i] :\r\n print(L[i],L1[i])\r\n \r\n \r\n \r\n \r\n \r\n \r\n",
"q = int(input())\noldnames = []\nnewnames = []\n\nfor i in range(q):\n old, new = input().split()\n #add new instances of old and new names\n if old not in newnames:\n oldnames.append(old)\n newnames.append(new)\n #update old name a second time when an new becomes an old\n else:\n change = newnames.index(old)\n newnames[change] = new\n \nchanges = len(oldnames)\n#print number of changes\nprint(changes)\n#print list of changes\nfor j in range(changes):\n print(oldnames[j], newnames[j])\n \t \t \t \t \t \t\t \t \t",
"import math\r\n\r\nq=int(input())\r\nm={}\r\n\r\nfor _ in range(q):\r\n old,new=map(str,input().split())\r\n if old not in m:\r\n m[new]=old\r\n else:\r\n m[new]=m[old]\r\n del(m[old])\r\n \r\nprint(len(m))\r\nfor key in m:\r\n print(m[key],key)\r\n ",
"n = int(input())\n\nusers = []\ncounter = 0\n\n\nclass User():\n def __init__(self, old_name, new_name):\n self.old_name = old_name\n self.actual_name = new_name\n\n\nfor i in range(n):\n r = input().split()\n for u in users:\n if u.actual_name == r[0]:\n u.actual_name = r[1]\n break\n else:\n users.append(User(r[0], r[1]))\n counter += 1\n\nprint(counter)\nfor u in users:\n print('{} {}'.format(u.old_name, u.actual_name))\n",
"handles_num = int(input())\nusers = {}\n\nfor i in range(handles_num):\n change = input()\n old = change.split(\" \")[0]\n new = change.split(\" \")[1]\n\n if(old in users):\n users[new] = users[old]\n users.pop(old)\n \n else:\n users[new] = old\n\n\nprint(len(users))\n\nfor n, o in users.items():\n print(o + ' ' + n)\n\n\t\t\t \t \t \t \t \t\t\t \t\t\t",
"def changing_handles(n):\r\n handles = {}\r\n for _ in range(n):\r\n old, new = input().split(\" \")\r\n\r\n if old not in handles:\r\n handles[new] = old\r\n else:\r\n handles[new] = handles[old]\r\n del handles[old]\r\n return handles\r\n\r\ndef main():\r\n m = int(input())\r\n h = changing_handles(m)\r\n\r\n print(len(h))\r\n for k, v in h.items():\r\n print(v, \" \", k)\r\n\r\nmain()",
"n=int(input())\r\nhashmap={}\r\nfor _ in range(n):\r\n a,b=list(map(lambda x:x,input().split()))\r\n if a in hashmap:\r\n temp=hashmap[a]\r\n del hashmap[a]\r\n hashmap[b]=temp\r\n else:\r\n hashmap[b]=a\r\nprint(len(hashmap))\r\nfor a in hashmap:\r\n print(hashmap[a],a)\r\n",
"# -*- coding: utf-8 -*-\n\n# Baqir Khan\n# Software Engineer (Backend)\n\nn = int(input())\n\nnames = {}\n\nwhile n:\n n -= 1\n\n old, new = input().split()\n if old in names:\n names[new] = names[old]\n del names[old]\n else:\n names[new] = old\n\nprint(len(names))\nfor key, value in names.items():\n print(value, key)\n",
"n = int(input())\r\n\r\nd={}\r\n\r\nfor i in range(n):\r\n old,new = input().split()\r\n if old in d:\r\n d[new]=d[old]\r\n del d[old]\r\n#we are relating new to old rather its opposite \r\n#it is so because its easy to check in d,rather than d.values()\r\n\r\n else:\r\n d[new]=old\r\nprint(len(d))\r\nfor x in d:\r\n print(d[x],x)\r\n",
"from sys import stdin, stdout\r\n##que hago con el input\r\n\r\nnombres_originales = {}\r\nlista_queries = []\r\nq = int(stdin.readline().rstrip())\r\nfor i in range(q):\r\n linea = stdin.readline()\r\n linea = linea.split('\\n')[0]\r\n lista = linea.split(' ')\r\n lista_queries.append((lista[0], lista[1]))\r\n\r\n\r\nfor tupla in lista_queries:\r\n if tupla[0] in nombres_originales.values():\r\n for nombre_original, nombre_viejo in nombres_originales.items():\r\n if tupla[0] == nombre_viejo:\r\n nombres_originales[nombre_original] = tupla[1]\r\n break\r\n else:\r\n nombres_originales[tupla[0]] = tupla[1]\r\n\r\n\r\nstdout.write(str(len(nombres_originales)) + '\\n')\r\nfor nombre_original, nombre_viejo in nombres_originales.items():\r\n stdout.write(nombre_original + ' ' + nombre_viejo + '\\n')\r\n\r\n",
"def avaliaRequest(request, requests, trocados):\n\tif not(request[1] in requests) or not(request[1] in trocados):\n\t\t\n\t\tif request[0] in trocados:\n\t\t\trequests[trocados[request[0]]] = request[1]\n\t\t\ttrocados[request[1]] = trocados[request[0]]\n\t\t\t\n\t\telse:\n\t\t\trequests[request[0]] = request[1]\n\t\t\ttrocados[request[1]] = request[0]\n\t\t\n\t\t\n\t\t\n\n\nnumResquests = int(input())\nrequests = {}\ntrocados = {}\n\nfor i in range(numResquests):\n\trequest = input().split()\n\tavaliaRequest(request, requests, trocados)\n\nprint(len(requests))\nfor i in requests.keys():\n\tprint(\"%s %s\" %(i, requests[i]))\n\t\n",
"#Problem Set F: Collaborated with Rudransh Singh, Fatima Gowher\n\n#no. of users to change requests\n\nq = int(input())\n\n#dict... to keep track of old and new user handles\ndict1 = {}\n\nfor i in range(q):\n str_input = input().split()\n old_str = str_input[0]\n new_str = str_input[1]\n \n if old_str not in dict1:\n dict1[new_str] = old_str\n else:\n dict1[new_str] = dict1[old_str]\n del dict1[old_str]\n \n\n\nprint(len(dict1)) \nfor i in dict1:\n print(dict1[i], i)\n\t \t\t\t\t \t\t\t \t \t \t \t\t",
"o = []\r\nn = []\r\nfor el in range(int(input())):\r\n old , new = input().split()\r\n if(old in n):\r\n n[n.index(old)] = new \r\n else:\r\n o.append(old) \r\n n.append(new)\r\nprint(len(o))\r\nfor el in range(len(o)):\r\n print(str(o[el]) + ' ' + str(n[el]))",
"db = {}\nN = int(input())\n\nfor _ in range(N):\n old, new = input().split(\" \")\n db.setdefault(old, [old])\n\n names = db.pop(old)\n names.append(new)\n db[new] = names\n\nprint(len(db))\n\nfor _, vals in db.items():\n print(vals[0], vals[-1])\n \t \t \t\t\t\t \t \t \t",
"def solve():\r\n q = int(input())\r\n l = []\r\n for i in range(q):\r\n old, new = input().split()\r\n for namelist in l:\r\n if namelist[-1] == old:\r\n namelist.append(new)\r\n break\r\n else:\r\n l.append([old, new])\r\n\r\n print(len(l))\r\n for namelist in l:\r\n print(namelist[0], namelist[-1])\r\nsolve()",
"\nfrom collections import OrderedDict\n\nq = int(input())\nres = []\n\nnicks = OrderedDict()\nfor _ in range(q):\n old, new = input().split()\n nicks[old] = new\n\nwhile nicks:\n old, new = nicks.popitem(last=False)\n while new in nicks:\n new = nicks.pop(new)\n res.append((old, new))\n\nprint(len(res))\nfor _ in res: print(*_)\n",
"q = int(input())\r\ninit_names = []\r\nres_names = []\r\ndef exists(name):\r\n for i in range(len(init_names)):\r\n if(name==res_names[i]):\r\n return i\r\n return -1\r\ndef add(name, label):\r\n r = exists(name)\r\n if(r>=0):\r\n res_names[r] = label\r\n else:\r\n init_names.append(name)\r\n res_names.append(label)\r\nfor zzz in range(q):\r\n name, label = input().split()\r\n add(name, label)\r\nprint(len(init_names))\r\nfor i in range(len(init_names)):\r\n print(init_names[i], res_names[i])\r\n ",
"n = int(input())\n\ncurrent_users = set()\nold_to_new = {}\nnew_to_old = {}\ncount = 0\nfor i in range(n):\n old, new = input().split()\n\n if old not in current_users:\n count += 1\n old_to_new[old] = new\n new_to_old[new] = old\n else:\n current_users.remove(old)\n old_key = new_to_old[old]\n old_to_new[old_key] = new\n new_to_old[new] = old_key\n \n current_users.add(new)\n\nprint(count)\nfor k, v in old_to_new.items():\n print(f'{k} {v}')\n\n \t \t \t\t\t\t \t \t \t \t\t \t\t\t \t\t\t",
"tc = int(input())\n\nold_new_dict = dict()\nnew_old_dict = dict()\n\nfor _ in range(tc):\n old, new = input().strip().split()\n if old in new_old_dict:\n starting_handle = new_old_dict[old]\n old_new_dict[starting_handle] = new\n new_old_dict[new] = starting_handle\n else:\n old_new_dict[old] = new\n new_old_dict[new] = old\nprint(len(old_new_dict))\nfor key, value in old_new_dict.items():\n print(key, value)\n\n\t\t\t \t\t \t\t \t \t\t \t\t \t \t \t",
"import re\n\ntheNumber = int(input())\noldSet = []\nnewSet = []\nfor x in range(theNumber):\n arr = re.split(\"\\\\s\", input())\n if arr[0] in newSet:\n y = newSet.index(arr[0])\n newSet[y] = arr[1]\n else:\n oldSet.append(arr[0])\n newSet.append(arr[1])\n \nprint(len(oldSet))\nfor x in range(len(oldSet)):\n print(oldSet[x] + \" \" + newSet[x])\n\t \t \t \t\t\t\t\t\t\t\t\t\t \t \t\t \t\t \t",
"from heapq import *\n\n\ndef do_modifications(original, tracker, old_handle, new_handle):\n original[tracker[old_handle]] = new_handle\n tracker[new_handle] = tracker[old_handle]\n del tracker[old_handle]\n\n\ndef lets_do_it():\n q = int(input())\n original, tracker = {}, {}\n for _ in range(q):\n old_handle, new_handle = [a for a in input().split(' ')]\n if old_handle in tracker:\n do_modifications(original, tracker, old_handle, new_handle)\n if new_handle in original:\n temp_handle = original[new_handle]\n old_handle = new_handle\n new_handle = temp_handle\n do_modifications(original, tracker, old_handle, new_handle)\n del original[old_handle]\n elif new_handle in original:\n tracker[original[new_handle]] = old_handle\n original[old_handle] = original[new_handle]\n del original[new_handle]\n else:\n original[old_handle] = new_handle\n tracker[new_handle] = old_handle\n\n print(len(original))\n for key, value in original.items():\n print(key + ' ' + value)\n\n\ndef main():\n # test_cases = int(input())\n test_cases = 1\n while test_cases:\n lets_do_it()\n test_cases -= 1\n\n\nmain()\n",
"d = {}\r\no = {}\r\nfor i in range(int(input())):\r\n a, b = input().split()\r\n if a not in d.keys():\r\n o[a] = b\r\n d[a] = b\r\n d[b] = 'aboba'\r\nprint(len(o))\r\nfor el in o.keys():\r\n print(el, end=' ')\r\n t = el\r\n while d[t] in d.keys():\r\n t = d[t]\r\n print(t)",
"\r\nt=int(input())\r\nold=[]\r\nnew=[]\r\nfor i in range(t):\r\n\to,n=map(str,input().split())\r\n\told.append(o)\r\n\tnew.append(n)\r\nans=[]\r\nwhile 0<len(old):\r\n#\tprint(\"a\")\r\n\ts=new[0]\r\n\tans.append(old[0])\r\n\told.pop(0)\r\n\tnew.pop(0)\r\n\tj=0\r\n\twhile j<len(old):\r\n\t\tif old[j]==s:\r\n\t\t\ts=new[j]\r\n\t\t\told.pop(j)\r\n\t\t\tnew.pop(j)\r\n\t\telse:\r\n\t\t\tj+=1\r\n\tans.append(s)\r\nprint(len(ans)//2)\r\ni=0\r\nwhile i<len(ans)-1:\r\n\tprint(ans[i]+\" \"+ans[i+1])\r\n\ti+=2\r\n",
"# F - 2 Solution CSUEB 497 Assignment 2\n# Collaborated with no one (Daniel Perez, netID bd2255)\n\ndef rainy(S, D):\n FLAG = True\n while FLAG:\n FLAG = False\n for key,val in D.items():\n if val in D:\n D[key] = D[val]\n del D[val]\n FLAG = True\n break\n print(len(D))\n for key in D:\n print(key + \" \" + D[key])\n\n\n\n\nS = int(input())\n\nT = dict()\n\nfor i in range(S):\n X = input()\n\n X = X.split(' ')\n \n T[str(X[0])] = str(X[1])\n\n\nrainy(S, T)\n\n\n\n\n\n \t\t\t \t\t\t \t \t\t \t \t \t \t\t\t \t \t\t",
"from collections import defaultdict, deque\r\n\r\n\r\nn = input()\r\ninputs = [input() for _ in range(int(n)) ]\r\nnum = 0\r\ngraph = defaultdict(list)\r\ndic_names_first = dict()\r\ndic_names_second = dict()\r\nrealdict = list()\r\n\r\n\r\ndef breadth_first_search(graph, root):\r\n visited, queue = list(), deque([root])\r\n while queue:\r\n vertex = queue.popleft()\r\n for neighbour in graph[vertex]:\r\n if neighbour not in visited:\r\n visited.append(neighbour)\r\n queue.append(neighbour)\r\n return visited[-1]\r\n\r\nvisited, queue = list(), deque()\r\nfor handles in inputs:\r\n nicknames = handles.split(\" \")\r\n graph[nicknames[0]].append(nicknames[1])\r\n dic_names_first[nicknames[0]] = True\r\n dic_names_second[nicknames[1]] = True\r\n if dic_names_second.get(nicknames[0], False) == False:\r\n realdict.append(nicknames[0])\r\n num += 1\r\nprint(num)\r\nfor name in realdict:\r\n print(name, breadth_first_search(graph, name))",
"times = int(input())\r\nresult = {}\r\nfor _ in range(times):\r\n s = input().split()\r\n if s[0] in result:\r\n result[s[1]] = result[s[0]]\r\n del result[s[0]]\r\n else:\r\n result[s[1]] = s[0]\r\nprint(len(result))\r\nfor key in result:\r\n print(result[key], key)\r\n",
"class QuickFindUF:\r\n def __init__(self):\r\n self.parent = {}\r\n\r\n def connected(self, node1, node2):\r\n return self.root(node1) == self.root(node2)\r\n\r\n def root(self, node):\r\n if not node in self.parent.keys():\r\n self.parent[node] = node\r\n return node\r\n\r\n while self.parent[node] != node:\r\n self.parent[node] = self.parent[self.parent[node]]\r\n node = self.parent[node]\r\n return node\r\n\r\n def union(self, childNode, parentNode):\r\n rootChildNode = self.root(childNode)\r\n rootParentNode = self.root(parentNode)\r\n self.parent[rootChildNode] = rootParentNode\r\n\r\n\r\nunionFind = QuickFindUF()\r\nhandles = {} #stores whether a handle is the initial handle or not\r\n\r\nrequestCount = int(input())\r\n\r\nfor i in range(requestCount):\r\n oldHandle, newHandle = input().split(\" \")\r\n\r\n if oldHandle not in handles.keys():\r\n handles[oldHandle] = True\r\n handles[newHandle] = False\r\n\r\n unionFind.union(oldHandle, newHandle)\r\n\r\ninitialHandlesWithChange = list(filter(lambda x : handles[x], handles))\r\nprint(len(initialHandlesWithChange))\r\nfor handle in initialHandlesWithChange:\r\n print(handle, unionFind.root(handle))\r\n",
"def a():\r\n return [int(i) for i in input().split()]\r\ndef b():\r\n return a()[0]\r\ndef s():\r\n n = b()\r\n \r\n se = dict()\r\n es = dict()\r\n \r\n for i in range(n):\r\n c, nn = input().split()\r\n \r\n sn = es.get(c, c)\r\n se[sn] = nn\r\n es[nn] = sn\r\n \r\n print(len(se))\r\n \r\n se_pairs = [' '.join(item) for item in se.items()]\r\n print('\\n'.join(se_pairs))\r\n \r\n \r\nfor t in range(1):\r\n s()\r\n",
"n = int(input())\r\n\r\ndicionario = {}\r\nfor i in range(n):\r\n entrada = input().split()\r\n if(entrada[0] in dicionario.values()):\r\n for key in dicionario.keys():\r\n if(dicionario[key] == entrada[0]):\r\n dicionario[key] = entrada[1]\r\n else:\r\n dicionario[entrada[0]] = entrada[1]\r\n\r\nprint(len(dicionario))\r\nfor key in dicionario.keys():\r\n print(f'{key} {dicionario[key]}')\r\n",
"n = int(input())\n\nnomes = {}\n\nfor i in range(n):\n antigo, novo = input().split()\n if antigo in nomes.keys():\n nomes[novo] = nomes[antigo]\n nomes.pop(antigo)\n else:\n nomes[novo] = antigo\n\nkeys = nomes.keys()\nn = len(keys)\nprint(n)\nfor key in keys:\n print(f\"{nomes[key]} {key}\")",
"\r\nclass Set:\r\n def __init__(self, i, element1, element2):\r\n self.id = i\r\n self.elementos = {element1, element2}\r\n self.cabeza = element1\r\n self.fin = element2\r\n def unir(self, other):\r\n if self.cabeza == other.fin:\r\n self.cabeza = other.cabeza\r\n self.elementos = self.elementos.union(other.elementos)\r\n elif self.fin == other.cabeza:\r\n self.fin = other.fin\r\n self.elementos = self.elementos.union(other.elementos)\r\n def elementos_comunes(self, other):\r\n if not self.elementos.isdisjoint(other.elementos):\r\n return True\r\n return False\r\n def __eq__(self, other):\r\n if self.id == other.id:\r\n return True\r\n else:\r\n return False\r\n\r\n\r\n\r\n\r\nnumero_cambios = int(input())\r\n\r\n\r\nlista_sets = []\r\n\r\nfor i in range(numero_cambios):\r\n lista_cambio = input().split(\" \")\r\n lista_sets.append(Set(i, lista_cambio[0], lista_cambio[1]))\r\n\r\n\r\nentre = 0\r\nwhile True:\r\n for i in lista_sets:\r\n for j in lista_sets:\r\n if i.id != j.id:\r\n if i.elementos_comunes(j):\r\n i.unir(j)\r\n lista_sets.remove(j)\r\n entre += 1\r\n if entre == 0:\r\n break\r\n else:\r\n entre = 0\r\n\r\nprint(len(lista_sets))\r\nfor i in lista_sets:\r\n print(\"{} {}\".format(i.cabeza, i.fin))\r\n\r\n\r\n\r\n",
"class User:\n def __init__(self, old, new):\n self.used_names = {old, new}\n self.first_name = old\n self.current_name = new\n\n def change_name(self, new):\n self.used_names.add(new)\n self.current_name = new\n\nusers = []\n\nfor i in range(int(input())):\n old, new = input().split()\n\n exists = False\n for user in users:\n if old == user.current_name:\n user.change_name(new)\n exists = True\n\n if not exists:\n new_user = User(old, new)\n users.append(new_user)\n\nprint(len(users))\nfor user in users:\n print(user.first_name, user.current_name)\n\t \t \t\t\t \t\t \t \t\t\t \t \t\t\t",
"n = int(input())\n\nmap = [[], []]\n\nfor _ in range(n):\n old_handle, new_handle = input().split()\n\n if old_handle in map[1]: map[1][map[1].index(old_handle)] = new_handle\n else:\n map[0].append(old_handle)\n map[1].append(new_handle)\n\nprint(len(map[0]))\nfor i in range(len(map[0])):\n print(map[0][i], map[1][i])\n \t \t\t\t\t \t \t\t \t\t \t\t\t\t\t\t\t\t\t",
"n = int(input())\r\n\r\nc = {}\r\nd = []\r\nl = []\r\n\r\nfor i in range(n):\r\n a, b = input().split()\r\n l.append(b)\r\n if a not in l:\r\n d.append(a)\r\n c[a] = b\r\n\r\nprint(len(d))\r\n\r\nfor i in d:\r\n x = c[i]\r\n while (x in c):\r\n x = c[x]\r\n print(i, x)\r\n",
"def chance():\n q = int(input())\n dicio = {}\n for i in range(q):\n antigo, novo = map(str, input().split())\n # old.append(antigo)\n if antigo in dicio.values():\n dicio[list(dicio.keys())[list(dicio.values()).index(antigo)]] = novo\n elif antigo not in dicio:\n dicio[antigo] = novo\n print(len(dicio))\n for key in dicio:\n print(f\"{key} {dicio[key]}\")\n\n\nchance()\n\n\t \t\t\t\t\t\t \t \t \t\t \t\t\t\t\t\t \t\t\t",
"n = int(input())\nparent = {}\nchild = {}\nfor i in range(n):\n x, y = input().split()\n if child.get(x, \"\") != \"\":\n parent[child[x]] = y\n child[y] = child[x]\n else:\n parent[x] = y\n child[y] = x\nprint(len(parent))\nfor x in parent:\n print(x, parent[x])",
"\r\n\r\nq=int(input())\r\n\r\nd={}\r\nl=[]\r\nfor _ in range(q):\r\n a,b=input().split()\r\n if a in d.values():\r\n for i in d:\r\n if d[i]==a:\r\n d[i]=b\r\n break\r\n else:\r\n d[a]=b\r\nprint(len(d))\r\nfor i,j in d.items():\r\n print(i,j)",
"q = int(input())\ns = set()\np = {}\n\nfor _ in range(q):\n o, n = input().split()\n if o in s:\n s.remove(o)\n p[n] = p[o]\n else:\n p[o] = o\n p[n] = o\n s.add(n)\n\nprint(len(s))\nfor i in s:\n print(p[i], i)\n\n\t \t\t \t \t \t \t\t \t \t\t \t\t\t",
"cambios = int(input())\r\nclaves = {}\r\nchanges = {}\r\nwhile cambios != 0:\r\n actual = input().split(' ')\r\n if actual[0] not in claves.values() and actual[0] not in claves.keys():\r\n claves[actual[0]] = actual[1]\r\n changes[actual[0]] = 1\r\n else:\r\n if actual[0] in claves.keys() and changes[actual[0]] == 1:\r\n claves[actual[0]] = actual[1]\r\n changes[actual[0]] += 1\r\n else:\r\n llave = ''\r\n for k, v in claves.items():\r\n if v == actual[0]:\r\n valor = v\r\n llave = k\r\n claves[llave] = actual[1]\r\n changes[llave] += 1\r\n\r\n cambios -= 1\r\n\r\ntotal = 0\r\nfor val in changes.values():\r\n total += 1\r\nprint(total)\r\n\r\nfor k, v in claves.items():\r\n print(k, v)",
"def funcao(lista):\n mapa1 = {}\n mapa2 = {}\n\n for e in lista:\n if mapa1.get(e[0]) == None:\n if mapa2.get(e[0]) == None:\n mapa1[e[0]] = e[1]\n mapa2[e[1]] = e[0]\n else:\n valor = mapa2[e[0]]\n mapa1[valor] = e[1]\n mapa2.pop(e[0])\n mapa2[e[1]] = valor\n return mapa1\n\nn = int(input())\nlista = []\n\ni = 0\nwhile i < n:\n lista.append(input().split())\n i += 1\n\nres = funcao(lista)\nprint(len(res))\n\nfor k, v in res.items():\n print(k + \" \" + v)\n \t \t \t \t\t \t\t\t \t \t\t \t\t\t\t \t",
"import fileinput\r\ncounter = -1\r\ndictionary = {}\r\n\r\nfor linea in fileinput.input():\r\n counter += 1\r\n if counter > 0:\r\n linea = linea.replace(\"\\n\", \"\")\r\n linea = linea.split(\" \")\r\n if linea[0] in dictionary:\r\n dictionary[linea[1]] = dictionary.pop(linea[0])\r\n else:\r\n dictionary.update({linea[1]:linea[0]})\r\n\r\nprint(len(dictionary))\r\n\r\nfor i in dictionary:\r\n print(dictionary[i], i)\r\n",
"n = int(input())\r\n\r\ndic = {}\r\n\r\nfor i in range(n):\r\n x , y = input().split()\r\n\r\n if x in dic:\r\n dic[y] = dic[x]\r\n del dic[x]\r\n\r\n else:\r\n dic[y] = x\r\n\r\n#print(dic)\r\n\r\nprint(len(dic))\r\n\r\nfor i in dic:\r\n print(dic[i] , i )",
"q = int(input())\n\ndict_handles = {}\nfor i in range(q):\n handles = input().split()\n old = handles[0]\n new = handles[1]\n if (i == 0):\n dict_handles[old] = new\n else:\n flag = False\n for k,v in dict_handles.items():\n if(v == old):\n dict_handles[k] = new\n flag = True\n if (flag == False):\n dict_handles[old] = new\n \n \nprint(len(dict_handles.keys()))\nfor k,v in dict_handles.items():\n print(k, v)\n\t \t \t\t \t\t \t \t\t\t\t\t\t \t \t\t \t",
"q = int(input())\r\nold = dict()\r\nnew = dict()\r\nfor i in range(q):\r\n name = input().split()\r\n if new.get(name[0]) == None:\r\n old[name[0]] = name[1]\r\n new[name[1]] = name[0]\r\n else:\r\n old[new[name[0]]] = name[1]\r\n new[name[1]] = new[name[0]]\r\nprint(len(old))\r\nfor i in old:\r\n print(i, old[i])",
"l1,l2=[],[]\nfor _ in range(int(input())):\n\ta,b = input().split()\n\tif a in l2:\n\t\ti = l2.index(a)\n\t\tl2[i]=b\n\telse:\n\t\tl1.append(a)\n\t\tl2.append(b)\nprint(len(l1))\nfor i in range(len(l1)):\n\tprint(l1[i],l2[i])\n\t \t \t \t \t \t\t\t\t\t\t\t\t\t \t \t\t\t\t\t",
"d={}\r\nfor i in range(int(input())):\r\n x,y=input().split()\r\n if x not in d:\r\n d[y]= x\r\n else:\r\n d[y] = d.pop(x)\r\nprint(len(d))\r\nfor i ,j in d.items():\r\n print(j,i)\r\n",
"n = int(input())\n\nold_handles = list()\nnew_handles = list()\nfor _ in range(n):\n old, new = input().split(\" \")\n \n if old in new_handles:\n i = new_handles.index(old)\n new_handles[i] = new\n else:\n old_handles.append(old)\n new_handles.append(new)\n\nprint(len(new_handles))\nfor i in range(len(new_handles)):\n print(f'{old_handles[i]} {new_handles[i]}')\n\t \t\t\t\t\t \t\t \t\t\t\t \t\t \t\t\t \t\t",
"# ANDRE CHEKER BURIHAN RA194071 APR 2ND 2021\nnumchanges = int(input())\n\nqueues = [[\"empty\"] for i in range(numchanges+1)]\n\nlastPopulated = 0\ninserted = False\n\nfor i in range(numchanges):\n\n old, new = map(str, input().split())\n\n for j in range(lastPopulated+1):\n if old == queues[j][0]:\n queues[j].insert(0, new)\n inserted = True\n\n if not inserted:\n queues[lastPopulated].insert(0, old)\n queues[lastPopulated].insert(0, new)\n lastPopulated += 1\n else:\n inserted = False\n\n# print(queues)\nprint(lastPopulated)\nfor i in range(lastPopulated):\n print(\"%s %s\" %(queues[i][-2], queues[i][0]))\n \t\t\t\t\t\t \t \t \t \t\t \t\t",
"n = int(input())\n\nlistas = []\n\nfor _ in range(n):\n old, new = input().split(' ')\n have = False\n for i in range(len(listas)):\n if listas[i][-1] == old:\n listas[i].append(new)\n have = True\n \n if not have:\n listas.append([old, new])\n\nprint(len(listas))\nfor l in listas:\n print(l[0], l[-1])\n\n\n\n\t\t \t \t\t\t\t\t \t\t \t\t\t\t \t\t\t \t",
"q = int(input())\nusers = []\n\nfor k in range(q):\n old, new = input().split()\n if len(users) == 0:\n users.append([old, new])\n else:\n encontrou = False\n for i in users:\n if i[-1] == old:\n i.append(new)\n encontrou = True\n if not encontrou:\n users.append([old, new])\n\nprint(len(users))\nfor i in users:\n print(i[0], i[-1])\n\n\t\t\t\t \t\t \t \t \t \t \t",
"n = int(input())\nmapa = {}\n\nfor i in range(n):\n a, n = input().split()\n if a in mapa:\n mapa.update({n: mapa.pop(a)})\n else:\n mapa.update({n: a})\nkeys = list(mapa.keys())\nprint(len(keys))\n\nresultado = []\nfor i in keys:\n resultado.append(mapa.get(i) + \" \" + i)\nprint(\"\\n\".join(resultado))\n \t\t\t \t \t\t\t \t\t\t \t \t\t \t\t",
"used = set()\r\nn = int(input())\r\n\r\np_names = {}\r\n\r\nfor i in range(n):\r\n cur_name, new_name = input().split()\r\n if new_name not in used:\r\n used.add(new_name)\r\n if cur_name in used:\r\n used.remove(cur_name)\r\n\r\n if cur_name in p_names:\r\n p_names[new_name] = p_names[cur_name]\r\n else:\r\n p_names[new_name] = cur_name\r\n\r\nprint(len(used))\r\nfor name in used:\r\n print(p_names[name], name)",
"q = int(input())\r\nnames = []\r\nfor i in range(q):\r\n old, new = input().split()\r\n if old in list(map(lambda x:x[1], names)):\r\n names[list(map(lambda x:x[1], names)).index(old)][1] = new\r\n else:\r\n names += [[old, new]]\r\nprint(len(names))\r\nprint(\"\\n\".join(list(map(lambda x:\" \".join(x), names))))",
"n=int(input())\r\nm={}\r\nfor i in range(n):\r\n a,b=map(str,input().split())\r\n try:\r\n kk=m[a]\r\n m.__delitem__(a)\r\n m[b]=kk\r\n except KeyError:\r\n m[b]=a \r\nprint(len(m))\r\nfor k in m:\r\n print(m[k],k)\r\n \r\n",
"n = int(input().strip())\nnames = {}\nc = 0\nfor i in range(n):\n\told, new = input().strip().split()\n\tfound = False\n\tfor name in names:\n\t\tif names[name] == old:\n\t\t\tnames[name] = new\n\t\t\tfound = True\n\t\t\tbreak\n\tif not found:\n\t\tnames[old] = new\n\t\tc += 1\nprint(c)\nfor name in names:\n\tprint(name, names[name])",
"# maa chudaaye duniya\r\ndic = {}\r\nfor i in range(int(input())):\r\n old, new = input().split()\r\n found = False\r\n for el in dic:\r\n if old in dic[el]:\r\n found = True\r\n dic[el].append(new)\r\n if not found:\r\n dic[old] = [new]\r\n\r\nprint(len(dic))\r\nfor i in dic:\r\n print(i, dic[i][-1]) ",
"q = int(input())\r\nd = {}\r\nfor i in range(q):\r\n\told, new = input().split()\r\n\td[old] = new\r\n\td[new] = None\r\narr = []\r\ns = set()\r\nfor i in d:\r\n\tif d[i] is not None:\r\n\t\tsubs = d[i]\r\n\t\twhile d[subs] is not None:\r\n\t\t\tsubs = d[subs]\r\n\t\tif i not in s and subs not in s:\r\n\t\t\tarr.append([i, subs])\r\n\t\t\ts.add(i)\r\n\t\t\ts.add(subs)\r\nprint(len(arr))\r\nfor i in arr:\r\n\tprint(*i)",
"dp = {}\nfor _ in range(int(input())):\n o , n = input().split(' ')\n if o in dp:\n val = dp.pop(o)\n dp[n] = val\n else:\n dp[n] = o\n \nprint(len(dp))\nfor i,a in dp.items():\n print(a,i)\n \t\t \t \t \t\t \t\t \t\t\t\t \t\t \t",
"import sys\n\nn_inputs = int(sys.stdin.readline())\ninput_ = [line.strip().split() for line in sys.stdin.readlines()]\n\nflatten_input = [item for collection in input_ for item in collection]\n\nunique_handles = list(dict.fromkeys(flatten_input))\n\nchanges = []\n\nfor old, new in input_:\n trigger = False\n for index in range(len(changes)):\n original, last = changes[index]\n if last == old:\n changes[index] = [original, new]\n trigger = True\n break\n\n if not trigger:\n changes.append([old, new])\n\nprint(len(changes))\nfor original, last in changes:\n print(original, last)\n",
"changes = int(input())\r\n\r\nlogins = {}\r\nfor i in range(changes):\r\n antigo, novo = input().split()\r\n if(antigo not in logins):\r\n logins[novo] = antigo\r\n else:\r\n aux = logins[antigo]\r\n logins[novo] = aux\r\n logins.pop(antigo)\r\n\r\nprint(len(logins))\r\nfor l in logins:\r\n relacao = str(logins[l]) + \" \" + str(l)\r\n print(relacao)",
"n = int(input())\n\nold_h = {}\n\nfor i in range(n):\n old, new = input().split()\n\n if new not in old_h:\n if old in old_h:\n aux = old_h[old]\n\n del old_h[old]\n old_h[new] = aux\n \n else:\n old_h[new] = old\n\nprint(len(old_h.items()))\n\nfor k, v in old_h.items():\n print(v + ' ' + k)",
"\ndef misha_handles(l):\n d = {}\n for i in l:\n if i[0] in d.values():\n key = [k for k, v in d.items() if v == i[0]]\n d[key[0]] = i[1]\n else:\n d[i[0]] = i[1]\n \n print(len(d))\n \n for i in d:\n print(i + \" \" + d[i])\n\n \n\n\nl = []\nfor _ in range(int(input())):\n s = list(map(str, input().split()))\n l.append(s)\n\nmisha_handles(l)\n\t \t \t \t \t \t\t\t\t \t \t \t",
"q = int(input())\r\n\r\nous = []\r\nus = []\r\nfor i in range(q):\r\n\told, new = input().split()\r\n\tif old in us:\r\n\t\tus[us.index(old)] = new\r\n\telse:\r\n\t\tous.append(old)\r\n\t\tus.append(new)\r\n\r\nprint(len(ous))\r\nfor i in range(len(ous)):\r\n\tprint(ous[i], us[i])",
"n = int(input())\ndic = dict()\n\nnum = 0\nfor _ in range(n):\n old, new = input().split(' ')\n\n if old not in dic:\n dic[new] = [old, new]\n num += 1\n\n else:\n dic[new] = dic.pop(old)\n dic[new].append(new)\n\n\nprint(num)\nfor value in dic.values():\n print(value[0], end=\" \")\n print(value[-1])\n \t \t \t \t \t\t \t \t\t",
"parent = dict()\r\n\r\ndef find(name):\r\n while parent[name] != name:\r\n parent[name] = parent[parent[name]]\r\n name = parent[name]\r\n return parent[name]\r\n\r\nqueries = []\r\nfor _ in range(int(input())):\r\n old, new = input().split()\r\n queries.append((old, new))\r\n parent[new] = new\r\n parent[old] = new\r\nnewest = set()\r\nans = dict()\r\nfor old, new in queries:\r\n z = find(old)\r\n if z in newest:\r\n continue\r\n newest.add(z)\r\n ans[old] = z\r\nprint(len(ans))\r\nfor k, v in ans.items():\r\n print(k, v)\r\n\r\n\r\n ",
"n = int(input())\nmatrix = []\n\nfor i in range(n):\n old, new = [item for item in input().split()]\n if i == 0:\n matrix.append([old, new])\n else:\n for c in range(len(matrix)):\n ver = 0\n if matrix[c][1] == old:\n matrix[c][1] = new\n ver = 1\n break\n\n if ver == 0:\n matrix.append([old, new])\n\ntam = len(matrix)\nprint(tam)\nfor i in range(tam):\n print(matrix[i][0] + \" \" + matrix[i][1])\n\n \t\t\t\t\t \t\t \t \t\t \t \t \t\t\t \t \t \t",
"from sys import stdin\r\ninput=lambda : stdin.readline().strip()\r\nfrom math import ceil,sqrt,factorial\r\nINT_MIN=float(\"-infinity\")\r\nINT_MAX=float(\"infinity\")\r\nq=int(input())\r\nd={}\r\ncurrent=set()\r\nfor i in range(q):\r\n\ta,b=map(str,input().split())\r\n\t# for j in d:\r\n\tif b in current:\r\n\t\tpass\r\n\telse:\r\n\t\tflag=0\r\n\t\tx=''\r\n\t\tfor j in d:\r\n\t\t\tif d[j]==a:\r\n\t\t\t\tflag=1\r\n\t\t\t\tx=j\r\n\t\tif flag==1:\r\n\t\t\tcurrent.remove(a)\r\n\t\t\tcurrent.add(b)\r\n\t\t\td[x]=b\r\n\t\telse:\r\n\t\t\td[a]=b\r\n\t\t\tcurrent.add(b)\r\nprint(len(d))\r\nfor i in d:\r\n\tprint(i,d[i])",
"from collections import defaultdict\r\nclass DisjSet: \r\n def __init__(self, n): \r\n self.rank = defaultdict(lambda:1)\r\n self.parent = defaultdict(lambda:None)\r\n \r\n def sol(self,a):\r\n if self.parent[a]==None:\r\n self.parent[a]=a\r\n \r\n def find(self, x): \r\n #ans=1\r\n if (self.parent[x] != x): \r\n self.parent[x] = self.find(self.parent[x]) \r\n #ans+=1\r\n\r\n return self.parent[x]\r\n\r\n def Union(self, x, y): \r\n xset = self.find(x) \r\n yset = self.find(y) \r\n \r\n if xset == yset: \r\n return\r\n if self.rank[xset] < self.rank[yset]: \r\n self.parent[xset] = yset \r\n \r\n elif self.rank[xset] > self.rank[yset]: \r\n self.parent[yset] = xset \r\n else: \r\n self.parent[yset] = xset \r\n self.rank[xset] = self.rank[xset] + 1\r\nn=int(input())\r\nobj=DisjSet(n+1)\r\ntemp=[]\r\nvisited=defaultdict(lambda:None)\r\nfor p in range(n):\r\n a,b=input().split()\r\n temp.append([a,b])\r\n obj.sol(a)\r\n obj.sol(b)\r\n obj.Union(a,b)\r\n#print(obj.find('MikeMirzayanov'))\r\ncont=0\r\nans=[]\r\nwhile temp:\r\n a,b=temp.pop()\r\n if visited[obj.find(b)]==None:\r\n ans.append([obj.find(b),b])\r\n cont+=1\r\n visited[obj.find(b)]=True\r\nprint(cont)\r\nfor val in ans:\r\n print(*val)\r\n\r\n \r\n \r\n \r\n\r\n ",
"\"\"\"\nOh, Grantors of Dark Disgrace, \nDo Not Wake Me Again.\n\"\"\"\n\nii = lambda: int(input())\nmi = lambda: map(int, input().split())\nli = lambda: list(mi())\nsi = lambda: input()\n\nd = {}\n\nfor _ in range(ii()):\n q = input().split()\n try:\n d[q[1]] = d[q[0]]\n del d[q[0]]\n except KeyError:\n d[q[1]] = q[0]\n\nprint(len(d))\nfor x, y in d.items():\n print(y, x)\n",
"def val(d,e):\r\n\tfor i in d:\r\n\t\tif d[i]==e:return i\r\n\telse:return '12'\r\n\r\nm=int(input());d={}\r\nfor i in range(m):\r\n\tx,y=input().split();a=val(d,x)\r\n\tif a=='12':d[x]=y\r\n\telse:d[a]=y\r\nprint(len(d))\r\nfor i in d:print(i,d[i]) \r\n",
"p = {}\r\nfor i in range(int(input())):\r\n old,new = input().split()\r\n p[old] = new\r\n#{'Misha': 'ILoveCodeforces', 'Vasya': 'Petrov', 'Petrov': 'VasyaPetrov123', 'ILoveCodeforces': 'MikeMirzayanov', 'Petya': 'Ivanov'}\r\nans = []\r\nfor i in p:\r\n temp = p[i]\r\n if temp == 'hibru':\r\n continue\r\n else:\r\n while temp in p:\r\n p[i] = p[temp]\r\n temp2 = p[temp]\r\n p[temp] = 'hibru'\r\n temp = temp2\r\n ans.append([i,p[i]])\r\n\r\nprint(len(ans))\r\nfor i in ans:\r\n print(\"{} {}\".format(i[0],i[1]))",
"sl = dict()\r\nfor _ in range(int(input())):\r\n a, b = input().split()\r\n for i, j in sl.items():\r\n if j == a:\r\n sl[i] = b\r\n break\r\n else:\r\n sl[a] = b\r\nprint(len(sl))\r\nfor i in sl.items():\r\n print(*i)",
"cambios = int(input())\nlista_de_cambios = []#[(\"Misha\", \"ILoveCodeforces\"),(\"Vasya\", \"Petrov\"),(\"Petrov\", \"VasyaPetrov123\"),(\"ILoveCodeforces\", \"MikeMirzayanov\"),(\"Petya\", \"Ivanov\")]\nfor xxx in range(cambios):\n\taux = tuple(input().strip().split(\" \"))\n\tlista_de_cambios.append(aux)\n\nfinales = {}\n\nfor cambio in lista_de_cambios:\n\tfor llave in finales.keys():\n\t\tif finales[llave] == cambio[0]:\n\t\t\tfinales[llave] = cambio[1]\n\t\t\tbreak\n\telse:\n\t\tfinales[cambio[0]] = cambio[1]\n\n\nprint(len(finales))\nfor llave in finales.keys():\n\tprint(llave, finales[llave])\n",
"#collaborated with Bhumi and Fatima\nq=int(input())\nf={}\nfor i in range(q):\n temp_str=input().split()\n old=temp_str[0]\n new=temp_str[1]\n if old not in f:\n f[new]=old\n else:\n f[new]=f[old]\n del f[old]\nprint(len(f))\nfor i in f:\n print(f[i],i)\n\t\t \t \t\t \t \t \t\t\t \t \t \t \t\t",
"n = int(input())\r\n\r\nd = {}\r\n\r\nfor _ in range(n):\r\n \r\n a,b = input().split()\r\n flag = False # еще не обновляли значение по данному ключу\r\n for key in d:\r\n if d[key] == a:\r\n d[key] = b\r\n flag = True\r\n break\r\n \r\n if not flag:\r\n d[a] = b\r\n \r\nprint(len(d))\r\nfor key in d:\r\n print(key, d[key])\r\n \r\n ",
"from sys import stdin\ndef solve(names):\n answer = []\n for name in names:\n bool = True\n for answer_name in answer:\n if answer_name[0] == name[1]:\n answer_name[0] = name[0]\n bool = False\n elif answer_name[1] == name[0]:\n answer_name[1] = name[1]\n bool = False\n if bool:\n answer.append([name[0], name[1]])\n return answer\n\n\nif __name__ == \"__main__\":\n question = stdin.readlines()\n while (len(question) > 1):\n n_boys = int(question.pop(0))\n names = []\n for i in range(n_boys):\n name = question.pop(0).strip('\\n')\n name_1, name_2 = name.split(\" \")\n names.append((name_1, name_2))\n\n real_names = solve(names)\n print(len(real_names))\n for name in real_names:\n print(name[0], name[1])",
"no_of_requests = int(input())\r\nhandle_map = {}\r\n\r\nfor _ in range(no_of_requests):\r\n old, new = input().split()\r\n\r\n if old in handle_map:\r\n handle_map[new] = handle_map.pop(old)\r\n else:\r\n handle_map[new] = old\r\n\r\nprint(len(handle_map))\r\nfor new, old in handle_map.items():\r\n print(old, new)\r\n",
"n = int(input())\r\n\r\nnames = {}\r\n\r\nfor i in range(n):\r\n handle = input().split(' ')\r\n old = handle[0]\r\n new = handle[1]\r\n if old in names: \r\n names[new] = names.pop(old)\r\n else: names[new] = old\r\n\r\nprint(len(names))\r\nfor key, value in reversed(names.items()):\r\n print(value, key)\r\n",
"n = int(input())\r\nnombres = {}\r\nfor i in range(n):\r\n a = input()\r\n if a.split(' ')[0] not in nombres.keys():\r\n nombres[a.split(' ')[0]] = [a.split(' ')[1], 0]\r\nnombres_visitados = []\r\nimprimir = []\r\nfor i in nombres.keys():\r\n nombre_actual = i\r\n if nombres[i][1] == 0:\r\n while True:\r\n nombres_visitados.append(nombre_actual)\r\n nombres_pasados = [i]\r\n nombres[nombre_actual][1] = 1\r\n if nombres[nombre_actual][0] not in nombres.keys() and nombres[nombre_actual][0] not in nombres_pasados:\r\n imprimir.append(i +\" \" + nombres[nombre_actual][0])\r\n break\r\n nombre_actual = nombres[nombre_actual][0]\r\nprint(len(imprimir))\r\nfor i in imprimir:\r\n print(i)\r\n",
"dinh_goc = {}\r\no = ''; n = '' #old, new handles\r\nfor _ in range(int(input())):\r\n o, n = input().split()\r\n dinh_goc[n] = dinh_goc.get(o, o)\r\n dinh_goc.pop(o, None)\r\nprint(len(dinh_goc))\r\ntemp = dinh_goc.items()\r\nfor a, b in temp:\r\n print(b, a, sep = ' ')",
"a = dict()\r\nb = dict()\r\nn = int(input())\r\nans = 0\r\nfor i in range(n):\r\n word = input().split()\r\n x = word[0]\r\n y = word[1]\r\n if a.get(x) == None and b.get(x) == None:\r\n a[x] = y\r\n b[y] = x\r\n else:\r\n if b.get(x) != None:\r\n b[y] = b[x]\r\n a[b[y]] = y\r\nm = len(a)\r\nprint(m)\r\nfor i in range(m):\r\n ans = a.popitem()\r\n print(ans[0], end=\" \")\r\n print(ans[1])\r\n \r\n \r\n \r\n",
"import pdb\nn = int(input())\n\np = {}\n\nfor i in range(n):\n a, b = input().split()\n if a not in p:\n p[b] = a\n else:\n temp = p[a]\n p[b] = temp\n del p[a]\n\nprint(len(p))\nfor e in p:\n print(p[e], e)\n",
"n = int(input())\nold_names = []\nnew_names = []\nrecords = {}\ncount = 0\nfor i in range(n):\n name1, name2 = input().split()\n old_names.append(name1)\n new_names.append(name2)\n\nfor i in range(n):\n if old_names[i] not in records:\n records[new_names[i]] = old_names[i]\n elif old_names[i] in records:\n records[new_names[i]] = records[old_names[i]]\n del records[old_names[i]]\nprint(len(records))\nfor key in records:\n root_names = records[key]\n print(root_names + \" \" + key)\n\n\n",
"if __name__ == '__main__':\n n = int(input())\n d = {}\n for i in range(n):\n [old, new] = list(input().split(' '))\n if old not in d:\n d[new] = old\n else:\n d[new] = d[old]\n del d[old]\n keys = d.keys()\n print(len(keys))\n for key in keys:\n print('{0} {1}'.format(d[key], key))\n\n \t \t\t \t\t \t \t\t \t \t \t\t\t\t \t",
"q=int(input())\r\nd={}\r\nfor i in range(q):\r\n old,new=input().split()\r\n t=d.get(old,old)\r\n d[new]=t\r\n if t!=old: del d[old]\r\nprint(len(d))\r\nfor x in d:\r\n print(d[x],x)",
"n = int(input())\nhandles = []\nfor i in range(n):\n handle = input().split()\n if(len(handles)) == 0:\n handles.append(handle)\n else:\n for i in range(len(handles)):\n if(handle[0] == handles[i][1]):\n handles[i][1] = handle[1]\n break\n elif(i == (len(handles) - 1)):\n handles.append(handle)\n \nprint(len(handles))\nfor i in handles:\n print(i[0], i[1])\n\t \t\t \t\t\t\t\t\t\t \t\t \t\t \t\t",
"def solve(n,seq) :\r\n used = []\r\n ans = {}\r\n temp = {}\r\n for old, new in seq :\r\n if old not in used :\r\n if new not in used : \r\n ans[old] = new\r\n used.append(new)\r\n temp[new] = old\r\n else :\r\n #ans[old] = None\r\n pass\r\n used.append(old)\r\n \r\n else :\r\n og = temp[old] \r\n if new not in used :\r\n ans[og] = new\r\n temp[new] = og\r\n temp.pop(old)\r\n used.append(new)\r\n \r\n \r\n q = ans.items()\r\n print (len(q))\r\n for i,j in q :\r\n print (i,j)\r\n\r\ntest = int(input())\r\nseq = []\r\nfor x in range(test) :\r\n n = input().split()\r\n seq.append(n)\r\n \r\nsolve(test,seq)\r\n \r\n ",
"n = int(input())\n\nd = {}\ncount = 0\n\nfor i in range(n):\n old, new = input().split()\n if old in d:\n val = d.pop(old)\n d[new] = val\n else:\n d[new] = old\n count += 1\n\nprint(count)\nfor i in d:\n print(d[i], i)\n\t \t \t\t\t\t\t \t \t\t\t\t \t \t \t\t\t",
"query = int(input())\nmapa = {}\nfor i in range(query):\n tupla = list(input().split())\n if not(tupla[0] in mapa):\n mapa[tupla[1]] = tupla[0]\n else:\n mapa[tupla[1]] = mapa[tupla[0]]\n del mapa[tupla[0]]\n\nprint(len(mapa))\n\nfor elemento in mapa:\n print(mapa[elemento],elemento)\n\t\t \t \t\t\t \t \t \t \t \t \t",
"n = int(input())\nname_changes = {}\nfinal_names = {}\n\nfor i in range(n):\n old_name, new_name = input().split()\n name_changes[old_name] = new_name\n\nfor key in name_changes.keys():\n current_key = key\n while current_key in name_changes.keys():\n current_key = name_changes[current_key]\n if current_key in final_names.values():\n continue\n final_names[key] = current_key\n\nprint(len(final_names))\nfor key, value in final_names.items():\n print(key + ' ' + value)\n \t\t \t \t \t\t \t \t\t \t \t \t \t \t",
"q = int(input())\n\nusers = {}\n\nfor c in range(q):\n query = input().split()\n marc = 0\n for v in users.keys():\n if(users[v] == query[0]):\n marc = 1\n users[v] = query[1]\n break\n if(marc == 0):\n users[query[0]] = query[1]\n \nprint(len(users))\nfor c in users.keys():\n print(f\"{c} {users[c]}\")\n\n \n \t\t\t \t \t\t \t\t\t \t \t \t \t \t\t",
"q = int(input())\r\ndic = {}\r\ncan_not = set()\r\nfor i in range(q):\r\n a, b = input().split()\r\n dic[a] = b\r\n can_not.add(b)\r\nans = []\r\nfor i in dic:\r\n if i not in can_not:\r\n curr = i\r\n while curr in dic:\r\n curr = dic[curr]\r\n ans.append([i, curr])\r\nprint(len(ans))\r\nfor a, b in ans:\r\n print(a, b)\r\n",
"\r\n# Problem: B. Misha and Changing Handles\r\n# Contest: Codeforces - Codeforces Round #285 (Div. 2)\r\n# URL: https://codeforces.com/contest/501/problem/B\r\n# Memory Limit: 256 MB\r\n# Time Limit: 1000 ms\r\n# Powered by CP Editor (https://github.com/cpeditor/cpeditor)\r\n\r\nfrom sys import stdin\r\ndef get_ints(): return list(map(int, stdin.readline().strip().split()))\r\n\r\nn = int(input())\r\nids = {} # translate original username into id\r\ncurnames = {} # translate latest username into id\r\nx = 0\r\nseen = set()\r\nfor i in range(n):\r\n\ta,b = input().split()\r\n\r\n\tif a not in curnames and a not in ids: # it is completely new\r\n\t\tids[a] = x\r\n\t\tcurnames[b] = a\r\n\t\tx+=1\r\n\telif a in curnames:\r\n\t\tt = curnames[a]\r\n\t\tdel curnames[a]\r\n\t\tcurnames[b] = t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\r\nprint(len(curnames))\r\nfor key in curnames:\r\n\tprint(curnames[key],key)\r\n",
"n=int(input())\r\nd={}\r\ns=set()\r\nfor _ in range(n):\r\n x,y=map(str,input().split())\r\n d[x]=y\r\n s.add(x)\r\nans=[]\r\nfor i in d:\r\n if i not in s:\r\n continue\r\n s.remove(i)\r\n y=d[i]\r\n while y in d and y in s:\r\n s.remove(y)\r\n y=d[y]\r\n ans.append([i,y])\r\nprint(len(ans))\r\nfor j in ans:\r\n print(*j)",
"q = int(input())\nlastusername ={}\nfor i in range(q):\n old, new = [item for item in input().split()]\n if old in lastusername:\n lastusername[new] = lastusername[old] \n del lastusername[old]\n else:\n lastusername[new] = old\ntamanho = len(lastusername.items())\ni = 0\nprint(tamanho)\nfor key in lastusername.items():\n if(i!=tamanho-1):\n print(key[1],key[0], end=\"\\n\")\n else:\n print(key[1],key[0], end=\"\")\n i+=1\n \t \t\t\t \t \t \t \t\t\t",
"if __name__ == '__main__':\n q = int(input())\n\n data = []\n for _ in range(q):\n req = input().split(' ')\n found = False\n for row in data:\n if req[0] in row:\n row.append(req[1])\n found = not found\n break\n\n if not found:\n data.append(req)\n\n print(len(data))\n for row in data:\n print(row[0], row[-1])\n\n\n\t \t \t \t \t \t\t \t\t \t \t\t \t",
"numero_lineas = int(input().strip())\r\n\r\nquerys = []\r\nhistorial = {}\r\n\r\nfor linea in range(numero_lineas):\r\n\r\n querys.append(input().strip().split())\r\n\r\nfor query in querys:\r\n\r\n if query[0] not in historial:\r\n\r\n if query[0] in historial.values():\r\n\r\n for k, v in historial.items():\r\n\r\n if query[0] == v:\r\n\r\n historial[k] = query[1]\r\n\r\n break\r\n\r\n else:\r\n\r\n historial[query[0]] = query[1]\r\n\r\nprint(len(historial))\r\n\r\nfor k, v in historial.items():\r\n\r\n print(k, v)",
"q = int(input())\n\ndi = {}\ncount = 0\n\nfor i in range(q):\n x = input().split()\n nome2 , nome1 = x\n if nome2 not in di.keys():\n \tcount += 1\n \tdi[nome1] = nome2\n else:\n di[nome1] = di[nome2]\n di[nome2] = \" \"\n \n#key =nome2\n#value =nome1\n\nprint(count)\t\n\t\nfor k,v in di.items():\n\tif v != \" \":\n\t\tprint(v,k)\n\t \t\t\t \t \t \t\t \t \t \t\t\t",
"n, h = int(input()), {}\r\nfor i in range(n):\r\n\to, n = input().split()\r\n\th[n] = h.get(o,o)\r\n\th.pop(o, None)\r\nprint(len(h))\r\nfor n, o in h.items():\r\n\tprint(o, n)# 1698231923.3237162",
"#!/usr/bin/python3\nn = int(input())\nusuarios = {}\n\nfor i in range(n):\n dato = input().strip().split(\" \")\n #print(dato)\n paso = False\n try:\n # Revisar values\n\n for key, value in usuarios.items():\n if dato[0] == value:\n usuarios[key] = dato[1]\n paso = True\n\n if not paso:\n raise KeyError\n\n except KeyError:\n #print(\"ERROR key\")\n usuarios[dato[0]] = dato[1]\n\n #print(usuarios[dato[0]])\nprint(len(usuarios))\nfor k,v in usuarios.items():\n print(k, v)\n",
"q = int(input());\n\nolds = [];\nnews = [];\n\nfor x in range(q):\n old, new = input().split(\" \");\n if(old in news):\n index = news.index(old);\n news[index] = new;\n else:\n olds.append(old);\n news.append(new);\n\nquant = len(olds);\nprint(quant);\nfor x in range(quant):\n print(olds[x]+\" \"+news[x]);\n \t \t\t\t \t\t\t\t\t \t\t \t\t",
"n = int(input())\nhandle = {}\nfor i in range(n):\n old, new = input().split()\n if old in handle.values():\n key_list = list(handle.keys())\n val_list = list(handle.values())\n k = val_list.index(old)\n ch = key_list[k]\n handle[ch] = new\n else:\n handle[old] = new\n\nkeys = list(handle.keys())\nprint(len(keys))\nfor i in keys:\n print(i, handle[i])\n \t\t\t\t \t\t\t \t\t\t\t\t\t \t \t\t",
"if __name__ == '__main__':\n n = int(input())\n changes = {}\n for i in range(0, n):\n old, new = input().split()\n first = changes.get(old)\n if first:\n changes.pop(old)\n changes[new] = first\n else:\n changes[new] = old\n print(len(changes))\n for new, old in changes.items():\n print(old, new)\n\n \t \t\t\t \t\t \t\t \t\t\t \t\t \t\t\t \t \t",
"# cook your dish here\r\nn = int(input())\r\nstr1, str2, count = [], [], 0\r\nfor _ in range(n):\r\n x, y = input().split()\r\n str1.append(x)\r\n str2.append(y)\r\nfor i in range(n):\r\n if(str1[i] != 0):\r\n count += 1\r\n rstr = str2[i]\r\n for j in range(i+1, n):\r\n if(str1[j] == rstr):\r\n rstr = str2[j]\r\n str1[j], str2[j] = 0, 0\r\n str2[i] = rstr\r\nprint(count)\r\nfor i in range(len(str1)):\r\n if(str1[i] != 0):\r\n print(str1[i], str2[i])\r\n ",
"n = int(input())\n\ndic = {}\nfor e in range(n):\n old, new = input().split()\n \n achou = False\n for x, y in dic.items():\n if x == old or y == old:\n dic[x] = new\n achou = True\n break\n if not achou:\n dic[old] = new\n\nprint(len(dic))\nfor i, e in dic.items():\n resp = i + \" \" + e\n print(resp)\n\n\t\t\t \t \t \t\t \t\t \t \t \t \t \t\t",
"m = int(input())\r\nold = []\r\nnew = []\r\nfor i in range(0, m):\r\n i1,i2 = input().split(' ')\r\n if new.count(i1) == 0:\r\n old.append(i1)\r\n new.append(i2)\r\n else:\r\n new[new.index(i1)] = i2\r\nprint(len(old))\r\nfor i in range(len(old)):\r\n print(old[i] + ' ' + new[i])\r\n\r\n",
"d = {}\nsources = set()\ncount = int(input())\nfor i in range(count):\n old, new_ = input().split()\n if old not in d:\n sources.add(old)\n d[old] = new_\n d[new_] = None\n\nbuf = []\ntotal = 0\nfor el in sources:\n cur = d[el]\n while True:\n if d[cur] == None:\n total +=1\n buf.append('{} {}'.format(el, cur))\n break\n else:\n cur = d[cur]\n\nprint(total)\nprint('\\n'.join(buf))",
"\r\nq = int(input())\r\nmapping = dict()\r\n\r\nfor _ in range(q):\r\n old, new = input().split()\r\n if old in mapping:\r\n mapping[new] = mapping[old]\r\n del mapping[old]\r\n else:\r\n mapping[new] = old\r\n\r\nprint(len(mapping))\r\nfor key, value in mapping.items():\r\n print(value, key)\r\n",
"n=int(input())\r\nx=[]\r\nd={}\r\nf={}\r\nfor i in range(n):\r\n a,b=map(str,input().split())\r\n x.append([a,b])\r\n if a in f:\r\n d[f[a]]=b\r\n f[b]=f[a]\r\n else:\r\n d[a]=b\r\n f[b]=a\r\nprint(len(d))\r\nfor i in d:\r\n print(i,d[i])",
"handles = {}\r\nq = int(input())\r\nfor i in range(q):\r\n old, new = map(str, input().split())\r\n if old not in handles.values():\r\n handles[old] = new\r\n else:\r\n for j in handles:\r\n if handles[j] == old:\r\n handles[j] = new\r\nprint(len(handles))\r\nfor i in handles:\r\n print(i, handles[i])",
"old=[]\r\nnew=[]\r\nresult=[]\r\nss=[]\r\nn=int(input())\r\nfor _ in range(n):\r\n kk=input().split()\r\n old.append(kk[0])\r\n new.append(kk[1])\r\nfor i in range(n):\r\n t=i\r\n if new[i] not in ss:\r\n while new[t] in old :\r\n t=old.index(new[t])\r\n ss.append(new[t])\r\n result.append([old[i], new[t]])\r\nprint(len(result))\r\nfor i in result:\r\n print(i[0],i[1])",
"def get_key(my_dict , val):\r\n for key, value in my_dict.items():\r\n if val == value:\r\n return key\r\n \r\n return -1\r\n\r\nn = int(input())\r\narr = {}\r\nfor _ in range(n):\r\n a , b = input().split()\r\n x = get_key(arr , a)\r\n if x == -1:\r\n arr[a] = b\r\n\r\n else:\r\n arr[x] = b\r\n\r\nprint(len(arr))\r\nfor i , j in arr.items():\r\n print(i , j)\r\n",
"import math\r\nclass usernames:\r\n def __init__(self,name):\r\n self.name=name\r\n self.change=None\r\n \r\ndef solve():\r\n n=int(input())\r\n \r\n d={}\r\n for _ in range(n):\r\n old,new=input().split()\r\n if old in d.keys():\r\n oldnode=d[old]\r\n newnode=usernames(new)\r\n oldnode.change=newnode\r\n d[new]=newnode\r\n \r\n else:\r\n oldnode=usernames(old)\r\n newnode=usernames(new)\r\n oldnode.change=newnode\r\n d[old]=oldnode\r\n d[new]=newnode\r\n \r\n visited=set()\r\n ans=[]\r\n for k in d.keys():\r\n if k not in visited:\r\n node=d[k]\r\n visited.add(node.name)\r\n orginal=(node.name)\r\n while(node!=None):\r\n lastname=node.name\r\n visited.add(node.name)\r\n node=node.change\r\n modified=(lastname)\r\n ans.append([orginal,modified])\r\n print(len(ans))\r\n for i in range(len(ans)):\r\n old=ans[i][0]\r\n new=ans[i][1]\r\n print(old,new)\r\n \r\n \r\n \r\nif __name__==\"__main__\":\r\n solve()\r\n ",
"class Node:\r\n def __init__(self, old):\r\n self.old = old\r\n self.last = old\r\n\r\nn = int(input())\r\n\r\ndict = {}\r\noriginals = []\r\nfor i in range(n):\r\n words = input().strip().split(\" \")\r\n old = words[0]\r\n new = words[1]\r\n if not old in dict:\r\n n = Node(old)\r\n originals.append(n)\r\n dict[old] = n\r\n dict[old].last = new\r\n dict[new] = dict[old]\r\n\r\nprint(len(originals))\r\nfor i in originals:\r\n print(i.old, i.last)\r\n",
"n = int(input())\nd1 = dict()\nd2 = dict()\n\nfor i in range(n):\n a, b = input().split()\n if d2.get(a) is None:\n d1[a] = b\n d2[b] = a\n else:\n d1[d2[a]] = b\n d2[b] = d2[a]\nprint(len(d1))\nfor i in d1:\n print(i, d1.get(i))\n \n",
"def changes(ul):\r\n ol = [u[0] for u in ul]\r\n nl = [u[1] for u in ul]\r\n rl = []\r\n for i in range(len(ul)):\r\n if ol[i] is None:\r\n continue\r\n j = i\r\n while nl[j] in ol:\r\n j = ol.index(nl[j])\r\n ol[j] = None\r\n rl.append('%s %s'%(ol[i],nl[j]))\r\n return [len(rl)] + rl\r\n\r\nul = [input().split() for _ in range(int(input()))] #1000;20\r\n[print(r) for r in changes(ul)]\r\n\r\n",
"'''input\n5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n'''\nfrom sys import stdin\ninput = stdin.readline\nimport math\nimport sys\nfrom collections import defaultdict\nsys.setrecursionlimit(10 ** 4)\n\n\n\ndef lowbit(n):\n\treturn n - (n &(n - 1))\n\t\n# main starts\nn = int(input().strip())\nname = dict()\nchange = dict()\nfor _ in range(n):\n\tfirst, second = list(input().split())\n\tif first not in change and first not in name:\n\t\tname[first] = second\n\t\tchange[second] = first\n\telif first in change:\n\t\ttemp = change[first]\n\t\tname[change[first]] = second\n\t\tchange[second] = temp\n\nprint(len(name))\nfor i in name:\n\tprint(i, name[i])\n\t\t\t\t\t \t \t \t\t\t\t\t \t \t \t\t",
"cantidad = int(input())\r\n\r\ncombis = []\r\n\r\nfor i in range(cantidad):\r\n linea = input().split(' ')\r\n listo = False\r\n for j in combis:\r\n if linea[0] == j[0]:\r\n j.insert(0, linea[1])\r\n listo = True\r\n if not listo:\r\n combis.append([linea[1], linea[0]])\r\n\r\nlargo_final = len(combis)\r\n\r\nprint(largo_final)\r\nfor i in range(largo_final):\r\n print(\"{} {}\".format(combis[i][-1], combis[i][0]))",
"n = int(input())\r\nd = {}\r\nfor i in range(n):\r\n old,new = input().split()\r\n if old in d:\r\n d[new] = d[old]\r\n d.pop(old)\r\n else:\r\n d[new] = old\r\nprint(len(d))\r\nfor i in d:\r\n print(d[i],i)",
"n = int(input())\nhandl = dict()\nfor _ in range(n):\n req = input().strip().split()\n old, new = req[0], req[1]\n handl[old] = new\n\nans = []\nfor key in handl.keys():\n if handl[key] not in handl.keys():\n if handl[key] == '-':\n continue\n ans.append((key, handl[key]))\n else:\n old = key\n while handl[key] in handl.keys():\n pred = key\n key = handl[key]\n handl[pred] = '-'\n ans.append((old, handl[key]))\n handl[key] = '-'\n\nprint(len(ans))\nfor par in ans:\n print(par[0], par[1])\n\t \t\t \t\t \t\t \t\t \t\t \t",
"n = int(input())\n\nusers = {}\n\nfor i in range(n):\n old, new = input().split()\n \n if(old not in users):\n users[new] = old\n else:\n aux = users[old]\n users.pop(old)\n users[new] = aux\n\nprint(len(users))\nfor user in users:\n print(users[user], user)\n\t \t \t\t\t\t\t \t \t \t\t \t \t\t\t\t\t",
"x = []\ny = []\nn = int(input())\nfor i in range(n):\n a, b = input().split(\" \")\n if a in y:\n y[y.index(a)] = b\n else:\n x.append(a)\n y.append(b)\nprint(len(x))\nfor i in range(len(x)):\n print(x[i], y[i])\n\t\t\t \t \t\t \t \t \t \t \t \t \t\t\t",
"def get_ints():\r\n return map(int, input().strip().split())\r\n\r\ndef get_list():\r\n return list(map(int, input().strip().split()))\r\n\r\ndef get_string():\r\n return input().strip()\r\n \r\nfirst_mapping = {}\r\ncurent_mapping = {}\r\n\r\nfor t in range(int(input().strip())):\r\n arr = input().strip().split()\r\n s1, s2 = arr[0], arr[1]\r\n \r\n if s1 not in curent_mapping:\r\n first_mapping[s1] = [s2]\r\n curent_mapping[s2] = s1\r\n else:\r\n first_mapping[curent_mapping[s1]].append(s2)\r\n curent_mapping[s2] = curent_mapping[s1]\r\n\r\nprint(len(first_mapping)) \r\nfor i in first_mapping:\r\n print(i, first_mapping[i][-1])\r\n\r\n \r\n ",
"n = int(input())\r\nnombres = {}\r\nfor _ in range(n):\r\n a = input().split()\r\n nombres[a[0]] = a[1]\r\nresultado = []\r\nvistos=[]\r\nfor ini in nombres:\r\n if ini in vistos:\r\n continue\r\n vistos.append(ini)\r\n handle = []\r\n handle.append(ini)\r\n final = nombres[ini]\r\n while final in nombres.keys():\r\n vistos.append(final)\r\n final = nombres[final]\r\n handle.append(final)\r\n resultado.append(handle)\r\nprint(len(resultado))\r\nfor i in resultado:\r\n print(\" \".join(i))",
"n=int(input())\nusers = []\nwhile n>0:\n request = input()\n old = request.split(' ')[0]\n new = request.split(' ')[1]\n \n i=-1\n p=None\n for u in users:\n i+=1\n if (u[1]==old):\n p=i\n break\n\n if (p==None):\n new_user={}\n new_user[0]=old\n new_user[1]=new\n users.append(new_user)\n else:\n users[p][1]=new\n\n n-=1\n\nprint(len(users))\nfor u in users:\n print(u[0]+\" \"+u[1])\n \t\t\t \t \t \t\t \t \t\t \t \t \t\t",
"n = int(input())\n\nd = dict()\n\nfor i in range(n):\n\tfr, to = map(str, input().split())\n\n\tif fr in d:\n\t\td[to] = d[fr]\n\t\tdel d[fr]\n\telse:\n\t\td[to] = fr\n\nprint(len(d))\nfor p in d:\n\tprint(d[p], p)",
"n=int(input())\r\narr=[]\r\nfor i in range(n):\r\n s=input()\r\n a=s.split(' ')\r\n arr.append(a)\r\narray=[['' for col in range(n)]for row in range(2)]\r\n\r\na1=[[]for k in range(n)]\r\na1[0].append(arr[0][0])\r\na1[0].append(arr[0][1])\r\na2=[]\r\na2.append(arr[0][1])\r\np=1\r\nwhile(p<n):\r\n a2.append(arr[p][1])\r\n if arr[p][0] in a2:\r\n c=0\r\n while(c<p):\r\n if arr[p][0] in a1[c]:\r\n break\r\n else:\r\n c=c+1\r\n a1[c].append(arr[p][1])\r\n p=p+1\r\n else:\r\n a1[p].append(arr[p][0])\r\n a1[p].append(arr[p][1])\r\n p=p+1\r\ncount=0\r\nfor z in range(len(a1)):\r\n if(a1[z]!=[]):\r\n count+=1\r\nprint(count)\r\nfor z in range(len(a1)):\r\n if(a1[z]!=[]):\r\n print(a1[z][0]+' '+a1[z][-1])\r\n \r\n \r\n \r\n\r\n \r\n \r\n",
"length = int(input())\nchanged = 0\nfinal = []\n\nfor i in range(length):\n a = 0\n old, new = input().split()\n for j in range(len(final)):\n if final[j][1] == old:\n final[j][1] = new\n a = 1\n break\n\n if a == 0:\n final.append([old, new])\n changed += 1\nprint(changed)\nfor a in range(len(final)):\n print(f\"{final[a][0]} {final[a][1]}\")\n \t \t\t \t\t\t\t \t\t \t\t \t \t \t\t",
"n, d = int(input()), dict()\nfor i in range(n):\n a, b = input().split()\n tag = False\n for i in d:\n if d[i] == a:\n d[i] = b\n tag = True\n break\n if not tag: d[a] = b\nprint(len(d))\nfor i in d:\n print(i, d[i])\n",
"n = int(input())\ndic = []\nvalues = []\ndic_inverse = []\n\nfor i in range(n):\n string = input().split()\n old = string[0]\n new = string[1]\n values.append(new)\n dic.append((old, new))\n dic_inverse.append((new, old))\n\ndic = dict(dic)\ndic_inverse = dict(dic_inverse)\n\ndef getKey(value):\n return dic_inverse[value]\n\nfor i in range(n-1, -1, -1):\n value = values[i]\n if value in dic:\n key = getKey(value)\n dic[key] = dic[value]\n dic.pop(value)\n \nprint(len(dic))\nfor key in dic:\n print(key, \" \", dic[key])\n \n\n\n \t\t\t \t\t \t\t\t\t \t\t \t \t \t \t\t",
"n = int(input())\n\nmapa = {}\n\nfor i in range(n):\n x = list(map(str,input().strip().split()))[:2]\n\n achou = False\n\n for key in mapa:\n if mapa[key] == x[0]:\n mapa[key] = x[1]\n achou = True\n break\n \n if (not achou):\n mapa[x[0]] = x[1]\n\nprint(len(mapa))\n\nfor key in mapa:\n print(key + \" \" + mapa[key]) \n \t\t\t\t \t\t \t\t \t\t\t\t\t \t \t",
"q = int(input())\r\n\r\ndi = dict()\r\nd = dict()\r\nfor i in range(q):\r\n old, new = input().split()\r\n if old not in d:\r\n if old in d.values():\r\n for k, v in d.items():\r\n if v == old:\r\n d[k] = new\r\n break\r\n else:\r\n d[old] = new\r\n\r\nprint(len(d))\r\nfor k, v in d.items():\r\n print(k, v)\r\n",
"l=[]\r\nfor _ in range(int(input())):\r\n l.append(list(input().split()))\r\nc=0\r\nfor i in range(len(l)):\r\n for j in range(len(l)):\r\n if(i!=j):\r\n if(l[i][0]==l[j][1] and l[i][0]!=\"@\"):\r\n l[i][0]=l[j][0]\r\n l[j][0],l[j][1]=\"@\",\"@\"\r\n c+=1\r\nprint(len(l)-c)\r\nfor i in l:\r\n if(i[0]==\"@\"):\r\n pass\r\n else:\r\n print(*i)",
"n = int(input())\na = []\nfor i in range(n):\n\ta.append(input().split())\nd = {}\nfor i in a:\n\tif i[0] in d:\n\t\td[i[1]] = d[i[0]]\n\t\tdel d[i[0]]\n\telse:\n\t\td[i[1]] = i[0]\nprint (len(d))\nfor i in d:\n\tprint (d[i],i)\n \t\t \t \t \t \t\t\t \t\t \t",
"q = int(input())\n\nusers = dict()\nfor i in range(q):\n old, new = input().split(\" \")\n if old not in users:\n users[new] = old\n else:\n users[new] = users[old]\n del users[old]\n\n\nprint(len(users))\nfor key, val in users.items():\n print(\"%s %s\" % (val, key))\n\n\t\t\t\t \t\t\t\t\t \t \t\t \t\t \t \t\t",
"n=int(input())\nhandle=[]\nlines=[]\nfor i in range(0,n):\n lines.append(input())\nfor line in lines:\n old,new=line.split(\" \")\n\n for h in handle:\n if h[-1]==old:\n h.append(new)\n old=None\n if old:\n handle.append([old,new])\nprint(len(handle))\nfor h in handle:\n print(h[0]+\" \"+h[-1])\n",
"q = int(input())\r\nold_new = {}\r\n\r\nfor i in range(q):\r\n old,new = list(map(str,input().split()))\r\n if old not in old_new:\r\n old_new[new] = old\r\n else :\r\n old_new[new] = old_new[old]\r\n old_new.pop(old)\r\n \r\nprint(len(old_new.items()))\r\nfor x,y in old_new.items():\r\n print(y,x)",
"n = int(input())\nlist1 = []\nlist2 = []\nfor _ in range(n):\n linha1,linha2 =input().split()\n if linha1 not in list2:\n list1.append(linha1)\n list2.append(linha2)\n else:\n list2[list2.index(linha1)] = linha2\nprint(len(list1))\nfor x in range(len(list1)):\n print(list1[x], list2[x])\n \t\t\t\t \t \t\t \t\t\t\t\t\t \t\t \t\t\t \t",
"n = int(input())\n# oldest:newest\nhandles = {}\n\nfor i in range(n):\n achado = False\n old, new = input().split()\n\n # Itera pelo dicionario. key, value\n for k, v in handles.items():\n if old == v:\n handles[k] = new\n achado = True\n break\n\n # Se não foi achado significa que é um \"old\" que nunca foi inserido antes.\n if not achado:\n handles[old] = new\n\nprint(len(handles))\nfor k, v in handles.items():\n print(k, v)\n",
"def main():\r\n n = int(input())\r\n mp = {}\r\n for _ in range(n):\r\n old, new = input().split()\r\n if old in mp:\r\n mp[new] = mp.pop(old)\r\n else:\r\n mp[new] = old\r\n print(len(mp))\r\n for new, old in mp.items():\r\n print(old, new)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"dicionario = {}\nnum_de_requests = int(input())\n\nfor novo in range(num_de_requests):\n antigo, novo = input().split(\" \")\n \n if antigo not in dicionario:\n dicionario[novo] = antigo\n else:\n aux = dicionario.pop(antigo)\n dicionario[novo] = aux\n \nprint(len(dicionario))\n\nfor novo, antigo in dicionario.items():\n print(antigo,novo)\n\t\t \t \t\t\t \t \t\t\t \t \t\t \t\t",
"if __name__ == '__main__':\n n=int(input())\n cnt=0\n name=[]\n for i in range(n):\n name.append(input().split())\n newdic={}\n\n\n def get_keys(d, value):\n return [k for k, v in d.items() if v == value]\n\n for old,new in name:\n if old not in newdic:\n if old in newdic.values():\n keys=get_keys(newdic,old)\n for k in keys:\n newdic[k]=new\n else:\n newdic[old]=new\n else:\n if old in newdic.values():\n keys = get_keys(newdic,old)\n for k in keys:\n newdic[k] = new\n print(len(newdic))\n for x,y in newdic.items():\n print(x,y)\n\t \t\t\t\t\t \t\t \t \t\t \t \t \t \t\t\t",
"n = int(input())\nnames = {}\nnum = 0\nnames_before = []\n\nfor i in range(n):\n [old, new] = input().split()\n if old not in names:\n names[old] = new\n names[new] = old\n num += 1\n names_before.append(old)\n else:\n veryold = names[old]\n names[veryold] = new\n names[new] = veryold\n del names[old]\n\nprint(num)\nfor i in names_before:\n print(i, names[i])\n \t\t\t \t\t\t\t \t \t\t\t \t \t\t\t \t\t \t",
"inp = int(input())\r\nout = 0\r\nold = []\r\nnew = []\r\n\r\nfor x in range(inp):\r\n y = input().split()\r\n if y[0] in new:\r\n new[new.index(y[0])] = y[1]\r\n else:\r\n out+=1\r\n old.append(y[0])\r\n new.append(y[1])\r\n\r\nprint(out)\r\nfor x in range(out):\r\n print(old[x], end=\" \")\r\n print(new[x])",
"n = int(input())\nhandles = {}\n\nfor e in range(n):\n old, new = map(str, input().split())\n if(old in handles):\n handles[new] = handles[old]\n handles.pop(old)\n else:\n handles[new] = old\n\nprint(len(handles))\nfor e in handles:\n print(handles[e], end=' ')\n print(e)\n\t\t \t\t\t\t\t\t\t \t \t \t\t\t\t \t \t",
"n = int(input())\r\n\r\nusernames = {}\r\n\r\nfor i in range(n):\r\n\told, new = input().split()\r\n\t\r\n\tif old in usernames.values():\r\n\t\t\r\n\t\tfor k, v in usernames.items():\r\n\t\t\tif old == v:\r\n\t\t\t\tusernames[k] = new\t\t\r\n\r\n\telse:\r\n\t\tusernames[old] = new\r\n\r\nprint(len(usernames))\r\n\r\nfor k, v in usernames.items():\r\n\tprint(k,v)\r\n",
"n = int(input())\r\nd = {}\r\nfor i in range(n):\r\n x, y = input().split()\r\n d[x] = y \r\n for i in d.keys():\r\n if d[i] == x:\r\n d.pop(x)\r\n d[i] = y \r\n break\r\nprint(len(d))\r\nfor i in d.keys():\r\n print(i, d[i])\r\n",
"n=int(input())\r\nres=[]\r\nupdate=False\r\nfor i in range(n):\r\n old,new=input().split()\r\n update=False\r\n for i in res:\r\n if i[1]==old:\r\n i[1]=new\r\n update=True\r\n break\r\n if update==False:\r\n res.append([old,new])\r\nprint(len(res))\r\nfor i in res:\r\n print(*i)\r\n",
"'''input\n5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n'''\nn = []\nfor _ in range(int(input())):\n\ta, b = input().split()\n\tfor x in range(len(n)):\n\t\tif n[x][1] == a:\n\t\t\tn[x][1] = b\n\t\t\tbreak\n\telse:\n\t\tn.append([a, b])\nprint(len(n))\nfor i in n:\n\tprint(\" \".join(i))\n\n",
"n = int(input())\r\nnombres = {}\r\nfor i in range(n):\r\n a = input()\r\n if a.split(' ')[0] not in nombres.keys():\r\n nombres[a.split(' ')[0]] = [a.split(' ')[1], 0]\r\nnombres_visitados = []\r\nimprimir = []\r\ni = 0\r\nwhile len(list(nombres.keys())) > 0:\r\n nombre_base = list(nombres.keys())[i]\r\n nombre_actual = list(nombres.keys())[i]\r\n if nombres[nombre_actual][1] == 0:\r\n while True:\r\n nombres_visitados.append(nombre_actual)\r\n nombres[nombre_actual][1] = 1\r\n nombres_futuro = nombres[nombre_actual][0]\r\n if nombres[nombre_actual][0] not in nombres.keys():\r\n imprimir.append(nombre_base +\" \" + nombres[nombre_actual][0])\r\n nombres.pop(nombre_actual)\r\n break\r\n else:\r\n nombres.pop(nombre_actual)\r\n nombre_actual = nombres_futuro\r\nprint(len(imprimir))\r\nfor i in imprimir:\r\n print(i)",
"n=int(input())\nnum=1\nlst=input().split()\nold=[]\nnew=[]\nold.append(lst[0])\nnew.append(lst[1])\nfor i in range(n-1):\n lst=input().split()\n str1=lst[0]\n str2=lst[1]\n for j in range(num):\n if(str1==new[j]):\n new[j]=str2\n break\n if(j==num-1):\n old.append(str1)\n new.append(str2)\n num+=1\nprint(num)\nfor i in range(num):\n print(old[i],new[i])\n\n \t\t\t\t\t \t\t\t\t\t\t\t\t\t \t \t \t \t \t",
"size = int(input())\n\nchanges = []\nfor i in range(size):\n changes.append(input())\n\nchangesDicionario = {}\ncont = 0\nfor i in range(size-1, -1, -1):\n mudanca = changes[i].split()\n if mudanca[1] in changesDicionario.keys():\n changesDicionario[mudanca[0]] = changesDicionario.pop(mudanca[1])\n else:\n changesDicionario[mudanca[0]] = [mudanca[1], cont]\n cont += 1 \n \nresult = [None] * len(changesDicionario)\nfor a in changesDicionario.keys():\n result[changesDicionario[a][1]] = a + \" \" + changesDicionario[a][0]\n\nprint(len(result))\n\nfor a in result:\n print(a)\n\n\n\t \t\t \t\t\t \t\t\t\t \t\t\t \t\t \t \t",
"dic = {}\nfor i in range(int(input())):\n old_key, new_key = input().split()\n if(dic.get(old_key) == None):\n dic[new_key] = old_key\n else:\n data = dic.get(old_key)\n dic.pop(old_key)\n dic[new_key] = data\n\nprint (len(dic))\n\nfor elem in reversed(dic):\n \n print(dic.get(elem), elem) \n \t\t \t\t\t \t\t \t\t \t\t\t \t \t\t",
"n = int(input())\r\nconjuntos = {}\r\nfor i in range(n):\r\n old, new = input().split(\" \")\r\n existe = False\r\n for representante, conjunto in conjuntos.items():\r\n if old in conjunto:\r\n existe = True\r\n conjuntos[representante].append(new)\r\n break\r\n if not existe:\r\n conjuntos[old] = [old, new]\r\n\r\nprint(len(conjuntos))\r\nfor elem in conjuntos.values():\r\n print(elem[0], elem[-1])",
"d={}\r\ng={}\r\nfor _ in range(int(input())):\r\n a,b=map(str,input().split())\r\n g[a]=b\r\n for i in g.keys():\r\n if g.get(i)==a:\r\n g.pop(a)\r\n g[i]=b\r\n break\r\nprint(len(g.keys()))\r\nfor i,j in g.items():\r\n print(i,j)\r\n \r\n \r\n",
"d = {}\r\nfor i in range(int(input())):\r\n\tn,m = map(str,input().split())\r\n\tif(n in d.values()):\r\n\t\tfor i in d.items():\r\n\t\t\tif(i[1] == n):\r\n\t\t\t\td[i[0]] = m\r\n\telse:\r\n\t\td[n] = m\r\nprint(len(d))\r\nfor i in d:\r\n\tprint(i + \" \" + d[i])",
"s={}\r\nk={}\r\nfor i in range(int(input())):\r\n old,new=map(str,input().split())\r\n if old in k:\r\n k[new]=k[old]\r\n s[k[old]]=new\r\n else:\r\n s[old]=new\r\n k[new]=old\r\nprint(len(s))\r\nfor i in s:\r\n print(i,s[i])",
"n=int(input())\r\nls=[]\r\nll=[]\r\noo=[]\r\ncounter=0\r\nfor i in range(n):\r\n ls.append(input().split())\r\nfor i in range(n):\r\n index=i\r\n if(ls[i][0] not in ll):\r\n while(True):\r\n start=i+1\r\n check=True\r\n for j in range(start,n):\r\n if(ls[j][0]==ls[index][1]):\r\n index=j\r\n start=j+1\r\n #print(\"find : \",j,ls[j][1])\r\n ll.append(ls[j][0])\r\n check=False\r\n #print(\"start : \",start,\" while\")\r\n #input()\r\n if(start>=n or check):\r\n #print(ls[i][0],ls[index][1])\r\n oo.append([ls[i][0],ls[index][1]])\r\n counter+=1\r\n break\r\nprint(counter)\r\nfor i in range(counter):\r\n print(*oo[i])",
"q=int(input())\np=[]\n\nfor i in range(q):\n a,b=map(str,input().split())\n da=True\n for j in range(len(p)):\n ind=j\n if p[j][1]==a:\n p[j][1]=b\n da=False\n break\n\n if da:\n p.append([a,b])\n## print(p)\n\nprint(len(p))\n##print(p)\nfor i in p:\n print(*i)\n\n \n\n\n \t \t\t\t \t \t \t\t \t \t \t\t\t\t",
"q = int(input())\r\nd={}\r\nfor i in range(q):\r\n s,t=list(map(str, input().split()))\r\n if s not in d:\r\n d[t] = s\r\n else:\r\n d[t] = d[s]\r\n d.pop(s)\r\nprint(len(d.items()))\r\nfor x, y in d.items():\r\n print(y, x)",
"n = int(input())\nnames = {}\norig = {}\nfor _ in range(n):\n a, b = input().split()\n if a not in orig:\n orig[a] = a\n orig[b] = orig[a]\n names[orig[b]] = b\n\nprint(len(names))\nfor x, y in names.items():\n print(x, y)\n",
"A = {}\r\nn=int(input())\r\nfor _ in range(n):\r\n a,b = input().split(\" \")\r\n if a in A:\r\n A[b] = A[a]\r\n A[a] = -1\r\n else:\r\n A[b] = a\r\nprint(sum(A[i]!= -1 for i in A))\r\nfor i in A:\r\n if A[i] != -1:\r\n print(A[i], i)",
"n = int(input())\n\nx = {}\ny = {}\nfor i in range(n):\n old, new = input().split()\n if not(old in y):\n y[old] = old\n x[y[old]] = new\n y[new] = y[old]\n \nprint(len(x))\nfor old in x:\n print(old, x[old])\n \t\t\t \t\t \t\t\t \t\t \t \t \t",
"n=int(input())\r\no=[]\r\nl=[]\r\nfor i in range(n):\r\n s1,s2=input().split()\r\n if s1 in l:\r\n ind=l.index(s1)\r\n l[ind]=s2\r\n else:\r\n o.append(s1)\r\n l.append(s2)\r\nprint(len(o))\r\nfor i in range(len(o)):\r\n print(o[i],end=\" \")\r\n print(l[i])",
"d={}\r\nfor _ in range(int(input())):\r\n b=1\r\n l=input().split()\r\n for i,j in d.items():\r\n if l[0]==j:\r\n d[i]=l[1]\r\n b=0\r\n break\r\n if b:\r\n d[l[0]]=l[1]\r\nprint(len(d))\r\nfor i,j in d.items():\r\n print(i,j)",
"nb_user = int(input())\r\nchanges = {}\r\nfor _ in range(nb_user):\r\n old, new = [x for x in input().split()]\r\n if old in changes:\r\n changes[new] = changes[old]\r\n del changes[old]\r\n else:\r\n changes[new] = old\r\nprint(len(changes))\r\nfor k in changes:\r\n print(changes[k], k)\r\n",
"abacaba = []\nabc = []\nq = int(input())\nd = {}\nused = set()\nfor i in range(q):\n a, b = input().split()\n abacaba.append(a)\n abacaba.append(b)\n abc.append(a)\n used.add(b)\n d[a] = b\ns = list(set(abacaba))\nprint(q - len(abacaba) + len(s))\nfor j in range(len(abc)):\n ans = d[abc[j]]\n while True:\n try:\n ans = d[ans]\n except KeyError:\n break\n if abc[j] not in used:\n print(abc[j], ans)\n else:\n used.add(abc[j])\n",
"IL = lambda: list(map(int, input().split()))\r\nIS = lambda: input().split()\r\nI = lambda: int(input())\r\nS = lambda: input()\r\n\r\nq = I()\r\nmapp = {}\r\nfor i in range(q):\r\n nbefore, nafter = IS()\r\n if nbefore not in mapp:\r\n mapp[nafter] = nbefore\r\n else:\r\n mapp[nafter] = mapp[nbefore]\r\n mapp.pop(nbefore)\r\n\r\nprint(len(mapp))\r\nfor item in mapp.items():\r\n print(item[1], item[0])\r\n",
"q = int(input())\n\ncontrole = []\nn = 0\nfor i in range(q):\n\tsituacao = 0\n\tantigo, novo = input().split()\n\tfor e in range(len(controle)):\n\t\tif controle[e][1] == antigo:\n\t\t\tcontrole[e][1] = novo\n\t\t\tsituacao = 1\n\t\t\tbreak\n\t\t\t\n\tif situacao == 0:\n\t\tcontrole.append([antigo, novo])\n\t\tn += 1\t\t\n\nprint(n)\nfor s in range(len(controle)):\n\tprint(f\"{controle[s][0]} {controle[s][1]}\")\n\n \t \t\t \t\t \t \t \t\t \t\t",
"q = int(input())\nrelacoes = dict()\nfor i in range(q):\n antigo, novo = input().split()\n if antigo in relacoes:\n relacoes[novo] = relacoes.pop(antigo)\n else:\n relacoes[novo] = antigo\nprint(len(relacoes))\nfor e in relacoes:\n print(relacoes[e], e)\n\t \t\t\t \t \t \t \t \t\t\t \t\t \t \t",
"\"\"\"\r\nMisha and Changing Handles Problem Resolution.\r\nSol: Union de Conjuntos Disjuntos.\r\n\"\"\"\r\n# Packages and Libraries.\r\nimport sys\r\n\r\n\r\n# Function definitions.\r\ndef main(in_file):\r\n n = in_file.readline()\r\n persons = []\r\n for line in in_file:\r\n old, new = line.split()\r\n flag = True\r\n for names in persons:\r\n if old in names:\r\n flag = False\r\n names.append(new)\r\n if flag:\r\n new_person = [old, new]\r\n persons.append(new_person)\r\n print(len(persons))\r\n for person in persons:\r\n print(\"{} {}\".format(person[0], person[-1]))\r\n\r\n\r\n# Execution.\r\nmain(sys.stdin)\r\n",
"n,h=int(input()),{}\r\nfor i in range(n):\r\n\to,n=input().split()\r\n \r\n\th[n]=h.get(o,o)\r\n\th.pop(o,None)\r\nprint(len(h))\r\nfor n,o in h.items():\r\n\tprint(o,n)\r\n ",
"from sys import stdin, stdout\nimport string, re\n############# input ####################\n\ndef inp():\n return(int(input()))\ndef inlt():\n return(list(map(int,input().split())))\ndef inl():\n return(list(map(str,input().split())))\n\nclass User:\n def __init__(self, user):\n self._original = user\n self._latest = None\n \n def original(self):\n return self._original\n \n def latest(self):\n return self._latest\n \n def change(self, l):\n self._latest = l\n \n def __repr__(self):\n return f'{self._original} {self._latest}'\n\n\ndef findUser(users, user):\n for u in users:\n if u.latest() == user:\n return u\n return None\n\nn = inp()\nusers = set()\nfor i in range(n):\n q = inl()\n u = findUser(users, q[0])\n if u is not None:\n u.change(q[1])\n else:\n user = User(q[0])\n user.change(q[1])\n users.add(user)\n\nprint(len(users))\nfor user in users:\n print(user)",
"n = int(input())\r\nd = {}\r\ncnt = 0\r\nfor i in range(n):\r\n s = input().split()\r\n if s[0] in d:\r\n d[s[1]] = d[s[0]]\r\n d[s[0]] = 0\r\n else:\r\n d[s[1]] = s[0]\r\n cnt += 1\r\nprint(cnt)\r\nd = [list(d.values()), list(d.keys())]\r\n#for i, j in d:\r\n\r\nfor i in range(len(d[0])):\r\n if d[0][i] != 0:\r\n print(d[0][i], d[1][i])\r\n#print(d)",
"n = int(input())\n\nresult = dict()\nfor i in range(n):\n tmp = input().split()\n k = tmp[0]\n v = tmp[1]\n if k in result.values():\n tmp = list(result.values()).index(k)\n result[list(result.keys())[tmp]] = v\n else:\n result[k] = v\nprint(len(result))\nfor i in result:\n print(i + ' ' + result[i])\n",
"import sys\r\n\r\ndata = sys.stdin.readlines()\r\nnombres = []\r\nrelaciones = []\r\nfor i in range(int(data[0])):\r\n cambio = data[i+1].strip('\\n').split(' ')\r\n if cambio[0] in nombres:\r\n for relacion in relaciones:\r\n if cambio[0] == relacion[-1]:\r\n relacion.append(cambio[1])\r\n nombres.remove(cambio[0])\r\n nombres.append(cambio[1])\r\n \r\n else:\r\n relaciones.append(cambio)\r\n nombres.append(cambio[1])\r\n\r\nprint(len(relaciones))\r\nfor relacion in relaciones:\r\n print(relacion[0] + ' ' + relacion[-1])",
"n = int(input())\r\nd = {}\r\nfor _ in range(n):\r\n old, new = input().split()\r\n if(old not in d):\r\n d[new] = old\r\n else:\r\n d[new] = d[old]\r\n d.pop(old)\r\nprint(len(d))\r\nfor k, v in d.items():\r\n print(v, k, sep = ' ')",
"n = int(input())\nnomes = {}\nfor i in range(n):\n a = input()\n if a.split(' ')[0] not in nomes.keys():\n nomes[a.split(' ')[0]] = [a.split(' ')[1], 0]\nnomes_visitados = []\nimprimir = []\ni = 0\nwhile len(list(nomes.keys())) > 0:\n nomes_base = list(nomes.keys())[i]\n nomes_atuais = list(nomes.keys())[i]\n if nomes[nomes_atuais][1] == 0:\n while True:\n nomes_visitados.append(nomes_atuais)\n nomes[nomes_atuais][1] = 1\n nomes_futuro = nomes[nomes_atuais][0]\n if nomes[nomes_atuais][0] not in nomes.keys():\n imprimir.append(nomes_base +\" \" + nomes[nomes_atuais][0])\n nomes.pop(nomes_atuais)\n break\n else:\n nomes.pop(nomes_atuais)\n nomes_atuais = nomes_futuro\nprint(len(imprimir))\nfor i in imprimir:\n print(i)\n \t \t \t \t \t \t \t\t \t\t \t \t\t\t",
"#!/usr/bin/env python3\nnum_lines = input()\n\nname_mapping = []\n\nfor i in range(int(num_lines)):\n line = input()\n former, latter = line.split(\" \")\n check = 0\n\n for j in name_mapping:\n if(j[-1] == former):\n j.append(latter)\n check = 1\n\n if check == 0:\n name_mapping.append([former,latter])\n\n# Let's print the output\nprint(len(name_mapping))\nfor k in name_mapping:\n print(k[0], \" \", k[-1])\n\n",
"handles = {}\r\n\r\nfor _ in range(int(input())):\r\n old, new = input().split()\r\n if new in handles.items():\r\n continue\r\n if old in handles.values():\r\n name = next(filter(lambda x: x[1] == old, handles.items()))[0]\r\n handles[name] = new\r\n continue\r\n handles[old] = new\r\n \r\nprint(len(handles))\r\nfor k in handles:\r\n print(k + ' ' + handles[k])\r\n",
"n = int(input())\r\nnew = {}\r\noldold = {}\r\nfor i in range(n):\r\n \r\n u, v = input().split()\r\n \r\n if not(u in oldold):\r\n oldold[u] = u\r\n \r\n oldold[v] = oldold[u]\r\n new[oldold[u]] = v\r\n\r\nprint(len(new))\r\nfor u in new:\r\n print(u, new[u])",
"q=int(input())\r\nnew=[]\r\nold=[]\r\nfor i in range(q):\r\n n1,n2=input().split()\r\n if n1 not in new:\r\n old+=[n1]\r\n new+=[n2]\r\n else:\r\n x=new.index(n1)\r\n new.pop(x)\r\n new.insert(x,n2)\r\nprint(len(old))\r\nfor i,j in zip(old,new):\r\n print(i,j)\r\n",
"n = int(input())\n\na = []\nb = []\nresp = []\nfor i in range (0, n):\n ent = list(map(str,input().split()))[:2]\n if ent[0] in b:\n b[b.index(ent[0])] = ent[1]\n else:\n a.append(ent[0])\n b.append(ent[1])\n\nprint(len(a))\nfor j in range (0, len(a)):\n print(a[j], end = ' ')\n print(b[j])\n \n \t\t \t\t\t \t\t\t \t\t\t \t\t\t\t \t\t\t \t\t\t",
"import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\ninput=sys.stdin.readline\r\nn=int(input())\r\nd={}\r\nl=[]\r\nfor i in range(n):\r\n s1,s2=(i for i in input().split())\r\n d[s1]=s2\r\nfor i in d:\r\n if(d[i]!=-1):\r\n k=d[i]\r\n k1=i\r\n while(k in d):\r\n d[k1]=-1\r\n k1=k\r\n k=d[k]\r\n l.append([i,k])\r\n d[k1]=-1\r\nc=len(l)\r\nprint(c)\r\nfor i in range(c):\r\n print(*l[i])",
"\"\"\"\ncontest template, Mikhail Dektyarev <[email protected]>\nreal code is below\n\"\"\"\nfrom sys import stderr\n\n\ndef readint():\n return int(input())\n\n\ndef readfloat():\n return float(input())\n\n\ndef readarray(n, f=input):\n return [f() for i in range(n)]\n\n\ndef readlinearray(f=int):\n return list(map(f, input().split()))\n\n\n#gcd, x, y; a * x + b * y = gcd\ndef euclide(a, b):\n if a < 0:\n g, x, y = euclide(-a, b)\n return g, -x, y\n if b < 0:\n g, x, y = euclide(a, -b)\n return g, x, -y\n\n\ndef gen_primes(max):\n primes = [1] * (max + 1)\n for i in range(2, max + 1):\n if primes[i]:\n for j in range(i + i, max + 1, i):\n primes[j] = 0\n primes[0] = 0\n return [x for x in range(max + 1) if primes[x]]\n\n\ndef is_prime(N):\n if N % 2 == 0:\n return N == 2\n i = 3\n while i * i <= N:\n if N % i == 0:\n return False\n i += 2\n return True\n\n\ndef answer():\n return \"\"\n\n\ndef gcj():\n case_number = readint()\n for case in range(case_number):\n print(\"Case #%s: %s\" % (case + 1, str(answer), ))\n\n\nif __name__ == \"__main__\":\n n = readint()\n start_name = {}\n for i in range(n):\n a, b = input().split()\n if a not in start_name:\n start_name[b] = a\n else:\n start_name[b] = start_name[a]\n del start_name[a]\n print(len(start_name))\n for k, v in start_name.items():\n print(v, k)\n",
"n = int(input())\nd = {}\nfor i in range(n):\n old, new = map(str, input().split())\n f = 0\n for key, item in d.items():\n if item == old:\n d[key] = new\n f = 1\n break\n if f == 1:\n continue\n d[old] = new\nprint(len(d))\nfor i, j in d.items():\n print(i, j)\n",
"# Description of the problem can be found at http://codeforces.com/problemset/problem/501/B\r\n\r\nd_n = {}\r\n\r\nn = int(input())\r\n\r\nfor _ in range(n):\r\n x, y = input().split()\r\n \r\n if x in d_n:\r\n d_n[y] = d_n[x]\r\n del d_n[x]\r\n else:\r\n d_n[y] = x\r\n\r\nprint(len(d_n))\r\nfor key in d_n:\r\n print(\"%s %s\" % (d_n[key], key))",
"l1=[]\r\nl2=[]\r\nfor i in range(int(input())):\r\n s1,s2=input().split()\r\n if s1 not in l1 and s1 not in l2:\r\n l1.append(s1)\r\n l2.append(s2)\r\n else :\r\n l2[l2.index(s1)]=s2\r\nprint(len(l1))\r\nfor i in range(0,len(l1)):\r\n print(l1[i],l2[i])",
"n = int(input())\ndic = {}\n\nfor i in range(n):\n achado = False\n old, new = input().split()\n\n for k, v in dic.items():\n if old == v:\n dic[k] = new\n achado = True\n break\n\n if not achado:\n dic[old] = new\n\nprint(len(dic))\nfor k, v in dic.items():\n print(k, v)\n\n",
"q = int(input())\r\nd = {}\r\nfor i in range(q):\r\n l = input().split()\r\n for j in d.keys():\r\n if(d[j] == l[0]):\r\n d[j] = l[1]\r\n break \r\n else:\r\n d[l[0]] = l[1]\r\n \r\nprint(len(d.keys()))\r\nfor i in d.keys():\r\n print(i, d[i])\r\n ",
"q = int(input())\ndict1 = {}\ndict2 = {}\nans = []\nanswer = ''\n\nfor i in range(q):\n old, new = map(str, input().split())\n if old not in dict2:\n ans.append(old)\n dict1[old] = new\n dict2[new] = old\n\nprint(len(ans))\nfor i in range(len(ans)):\n f = ans[i]\n answer = ''\n answer += f\n while True:\n if f in dict1:\n f = dict1[f]\n else:\n break\n answer += ' ' + f\n print(answer)",
"def main():\n n = int(input())\n col = set()\n dic = {}\n chav = []\n values = []\n for i in range(n):\n aux = input().split(' ')\n if aux[0] not in values:\n chav.append(aux[0])\n values.append(aux[1])\n else:\n ind = values.index(aux[0])\n values[ind] = aux[1]\n \n \n print(len(chav))\n for i in range(len(chav)):\n print(chav[i] + ' ' + values[i])\n\n\n\n\n\nif __name__ == '__main__':\n main()\n\t \t \t \t \t\t\t \t\t\t \t\t \t\t \t",
"n=int(input())\r\nd={}\r\nfor i in range(n):\r\n a,b=input().split()\r\n if a in d:\r\n c=d.pop(a);\r\n d[b]=c\r\n else:\r\n d[b]=a\r\nprint(len(d))\r\nfor i in d:\r\n print(d[i],i)",
"try:\r\n \r\n t=int(input())\r\n l=[]\r\n l1=[]\r\n for i in range(t):\r\n \r\n x,y=map(str,input().split())\r\n if l.count(x)==0 and l1.count(x)==0:\r\n l.append(x)\r\n if l1.count(x)==1:\r\n z=l1.index(x)\r\n l1[z]=y\r\n \r\n else:\r\n l1.append(y)\r\n \r\n print(len(l))\r\n for i in range(len(l)):\r\n print(l[i],l1[i])\r\n \r\n \r\n \r\n \r\n \r\n \r\nexcept EOFError:\r\n pass",
"t = int(input())\ndomain = set()\ndsu = dict()\nfor _ in range(t):\n\told, new = input().split()\n\tif new not in domain:\n\t\tif old not in domain:\n\t\t\tdsu[new] = old\n\t\telse:\n\t\t\tdsu[new] = dsu[old]\n\t\t\tdel(dsu[old])\n\t\tdomain.add(old)\n\t\tdomain.add(new)\nprint(len(dsu))\nfor i in dsu:\n\tprint(dsu[i], i)",
"class Person:\r\n\r\n def __init__(self, first_name, actual_name):\r\n self.actual_name = actual_name\r\n self.first_name = first_name\r\n\r\n def change_name(self, name):\r\n self.actual_name = name\r\n\r\nperson_list = []\r\nn_handles = int(input())\r\nfor x in range(n_handles):\r\n handle = input().split(' ')\r\n add = True\r\n for person in person_list:\r\n if handle[0] == person.actual_name:\r\n add = False\r\n person.change_name(handle[1])\r\n if add:\r\n person_list.append(Person(handle[0], handle[1]))\r\nprint(len(person_list))\r\nfor person in person_list:\r\n print(person.first_name+' '+person.actual_name)\r\n\r\n",
"n=int(input());\nh={};\nfor i in range(n):\n\to,n=input().split(\" \")\n\th[n]=h.get(o,o)\n\th.pop(o,None)\nprint(len(h))\nfor n,o in h.items():\n\tprint(o,n)",
"n = int(input())\r\n\r\nhandles = {}\r\nfor i in range(n):\r\n old, new = input().split()\r\n handles[new] = handles.get(old, old)\r\n handles.pop(old, None)\r\n\r\nprint(len(handles))\r\nfor new, old in handles.items():\r\n print(old, new)\r\n",
"q = int(input())\r\n\r\nclass Node:\r\n def __init__(self, v):\r\n self.val = v\r\n self.next = None\r\n\r\nclass LinkedList:\r\n def __init__(self):\r\n self.start = None\r\n self.end = None\r\n\r\n def is_empty(self):\r\n return (self.start == None)\r\n\r\n def append(self, v):\r\n if self.is_empty():\r\n self.start = Node(v)\r\n self.end = self.start\r\n else:\r\n self.end.next = Node(v)\r\n self.end = self.end.next\r\n\r\nmy_dict = []\r\n\r\nfor i in range(q):\r\n old, new = list(input().split())\r\n if my_dict == []:\r\n first_list = LinkedList()\r\n first_list.append(old)\r\n first_list.append(new)\r\n my_dict.append(first_list)\r\n else:\r\n flg = 0\r\n for i in range(len(my_dict)):\r\n if my_dict[i].end.val == old:\r\n my_dict[i].append(new)\r\n flg = 1\r\n if flg == 0:\r\n new_list = LinkedList()\r\n new_list.append(old)\r\n new_list.append(new)\r\n my_dict.append(new_list)\r\n\r\nprint(len(my_dict))\r\nfor i in range(len(my_dict)):\r\n print(my_dict[i].start.val, my_dict[i].end.val)",
"n = int(input())\ninicial = []\natual = []\ncount = 0\nfor i in range(n):\n at, nw = map(str, input().split())\n if at in atual:\n for j in range(len(atual)):\n if at == atual[j]:\n atual[j] = nw\n count +=1\n break\n else:\n inicial.append(at)\n atual.append(nw)\n\nprint(len(inicial))\nfor i in range(len(atual)):\n print(inicial[i] + \" \" + atual[i])\n\n\t\t\t \t\t \t \t \t \t \t \t \t \t\t\t\t\t",
"n = int(input())\nnewest, dict = {}, {}\nfor i in range(n):\n str1 = input().split()\n if not str1[0] in newest:\n newest[str1[1]] = str1[0]\n dict[str1[0]] = str1[1]\n continue\n\n pos = newest[str1[0]]\n dict[pos] = str1[1]\n newest[str1[1]] = pos\n\nprint(len(dict))\nfor item in dict:\n print(item, dict[item])\n \t\t\t \t \t \t\t\t\t\t \t \t \t \t",
"from collections import defaultdict\r\nn = int(input())\r\ndic = {}\r\nfor i in range(n):\r\n curr = str(input())\r\n post = curr.split(\" \")\r\n p1 = post[0]\r\n p2 = post[1]\r\n\r\n if p1 not in dic:\r\n dic[p2] = p1\r\n else:\r\n val = dic[p1]\r\n dic.pop(p1)\r\n dic[p2] = val\r\nprint(len(dic))\r\nfor i in dic:\r\n print(dic[i], i)\r\n",
"n = {}\r\nfor _ in range(int(input())):\r\n a,b = map(str,input().split())\r\n if a in n:\r\n n[b] = n[a]\r\n del n[a]\r\n else:\r\n n[b] = a\r\nprint(len(list(n)))\r\nfor x in list(n):\r\n print(n[x], x)",
"#sold = set()\r\ns = set()\r\nd = {}\r\nq = int(input())\r\nfor _ in range(q):\r\n old, new = map(str, input().split())\r\n if new not in s:\r\n flag = True\r\n for key, val in d.items():\r\n if val == old:\r\n s.discard(old)\r\n d[key] = new\r\n flag = False\r\n break\r\n if flag:\r\n d[old] = new\r\n s.add(old)\r\n s.add(new)\r\n \r\nprint(len(d)) \r\nfor key, val in d.items():\r\n print(key, val) \r\n ",
"apelidos_usados = set()\napelidos_usuarios = {}\n\nfor i in range(int(input())):\n nick_antigo, nick_novo = input().split()\n\n if not(nick_antigo in apelidos_usados):\n apelidos_usados.add(nick_antigo)\n\n if not(nick_novo in apelidos_usados):\n apelidos_usados.add(nick_novo)\n if nick_antigo in apelidos_usuarios:\n apelidos_usuarios[nick_novo] = apelidos_usuarios.pop(nick_antigo)\n else:\n apelidos_usuarios[nick_novo] = nick_antigo\n\nprint(len(apelidos_usuarios))\nfor nick_novo in apelidos_usuarios:\n print(apelidos_usuarios[nick_novo] + \" \" + nick_novo)\n\n \t \t\t \t \t\t \t\t\t \t\t \t\t\t",
"n = int(input())\r\ns = []\r\nnickname = input().split()\r\ns.append([nickname[0], nickname[1]])\r\nfor i in range(n - 1):\r\n f = False\r\n nickname = input().split()\r\n for j in s:\r\n if nickname[0] == j[-1]:\r\n j.append(nickname[1])\r\n f = True\r\n break\r\n if f is False:\r\n s.append([nickname[0], nickname[1]])\r\n\r\nprint(len(s))\r\nfor i in s:\r\n print(i[0], i[-1])\r\n",
"# collaborated with no one\n\nusers = dict()\n\nnumOfUsers = int(input())\n\n# 0 for old\n# 1 for new\n\n# [old, new]\nfor x in range(numOfUsers):\n newUser = input().split()\n if newUser[0] in users.keys():\n users[newUser[1]] = users[newUser[0]]\n del users[newUser[0]]\n else:\n users[newUser[1]] = newUser[0]\n\n\nprint(len(users))\n\nfor key in users:\n print(users[key], key)\n\n\n\n \t \t \t \t \t\t\t\t \t\t \t \t\t\t",
"n = int(input())\r\nl = [[] for i in range(n)]\r\nst = set()\r\nfor i in range(n):\r\n ini, cur = [x for x in input().split()]\r\n\r\n## print(ini, cur)\r\n if ini in st:\r\n for i in range(n):\r\n if l[i][-1] == ini:\r\n l[i].append(cur)\r\n st.add(cur)\r\n break\r\n else:\r\n for i in range(n):\r\n if len(l[i]) > 0:\r\n continue\r\n l[i].append(ini)\r\n l[i].append(cur)\r\n st.add(ini)\r\n st.add(cur)\r\n break\r\n\r\nans = []\r\nfor i in range(len(l)):\r\n if len(l[i]) > 0:\r\n## print(l[i][0], l[i][-1])\r\n ans.append([l[i][0], l[i][-1]])\r\n else:\r\n break\r\n\r\nprint(len(ans))\r\nfor i in ans:\r\n print(*i)\r\n",
"q = int(input())\r\nD = {}\r\nfor i in range(q):\r\n\tx,y = input().split()\r\n\tif x in D:\r\n\t\tD[y]=D[x]\r\n\t\tD.pop(x)\r\n\telse:\r\n\t\tD[y]=x\r\n \r\nprint(len(D))\r\nfor i in D:\r\n\tprint(D[i],i)",
"def main():\n n = int(input())\n\n old2new = dict()\n\n while n:\n old, new = input().split()\n \n if old not in old2new.values():\n # user is changing handle for\n # the first time\n old2new[old] = new\n else:\n # not the first time that\n #the user changes handle\n \n for k in old2new:\n if old2new[k] == old:\n old2new[k] = new \n\n n -= 1\n\n print(len(old2new))\n \n for old, new in old2new.items():\n print(old, new)\n\n\nif __name__ == \"__main__\":\n main()\n\n",
"import sys\r\n\r\n\r\n# sys.stdin = open('input.txt', 'r')\r\n# sys.stdout = open('output.txt', 'w')\r\n\r\ninput = sys.stdin.readline\r\n\r\nnames = {}\r\ncnt = {}\r\nfor _ in range(int(input())):\r\n old, new = input().strip().split()\r\n names[old] = new\r\n cnt[old] = cnt.get(old, 0) + 1\r\n cnt[new] = cnt.get(new, 0) + 1\r\n\r\n\r\nans = []\r\nfor old in names:\r\n if cnt[old] == 1:\r\n new = names[old]\r\n while new in names:\r\n new = names[new]\r\n ans.append((old, new))\r\n\r\nprint(len(ans))\r\nfor i in ans:\r\n print(*i)",
"n = eval(input())\ns = {}\ncnt = 0\ndef update():\n a,b = input().split(\" \")\n for g in s.keys():\n if s[g]==a:\n s[g]=b\n return 1\n s[a] = b\n global cnt\n cnt += 1\nfor i in range(n):\n update()\nprint(cnt)\nfor a,b in s.items():\n print(a+\" \"+b)\n \n\t\t \t\t \t \t\t \t \t \t \t \t\t \t \t",
"import sys\n\nsys.stdin.readline().strip()\n\ncurrents = {}\nlength = 0\n\nfor line in sys.stdin:\n handles = line.strip().split(' ')\n for key in currents:\n \tif handles[0] == currents[key]:\n \t\tcurrents[key] = handles[1]\n \t\tbreak\n else:\n \tcurrents[handles[0]] = handles[1]\n \tlength += 1\n\nprint(length)\nfor key in currents:\n\tprint(key, currents[key])\n",
"n = input()\n\nlista_nuevos = []\nlista_viejos = []\nfor i in range(int(n)):\n elem = input().split(' ')\n if (elem[0] not in lista_viejos) and (elem[0] not in lista_nuevos):\n lista_viejos.append(elem[0])\n lista_nuevos.append(elem[1])\n elif elem[0] in lista_nuevos:\n indice = lista_nuevos.index(elem[0])\n lista_nuevos.pop(indice)\n viejo = lista_viejos[indice]\n lista_viejos.remove(viejo)\n lista_viejos.append(viejo)\n lista_nuevos.append(elem[1])\nprint(len(lista_nuevos))\n\nj = len(lista_viejos) - 1\n\nwhile j >= 0:\n s = \"\"\n s += lista_viejos[j] + \" \"\n s += lista_nuevos[j]\n print(s)\n j -= 1\n\n\n\n\n\n",
"def get_key(d, value):\r\n for k, v in d.items():\r\n if v == value:\r\n return k\r\n\r\nm = [int(x) for x in input().split()][0]\r\nd = dict()\r\nfor _ in range(m):\r\n x = input().split()\r\n if x[0] in d.values():\r\n d[get_key(d, x[0])] = x[1]\r\n else:\r\n d[x[0]] = x[1]\r\nprint(len(d))\r\nfor x in d.keys():\r\n print(x, d[x], sep=' ')",
"size = int(input())\nlista_completa = []\nlista_completa.append([1])\nadd = 0\nfor i in range (0,size):\n old, new = input().split(\" \")\n for e in lista_completa:\n if old == e[-1]:\n e.append(new)\n add = 1\n else:\n continue\n if add == 0:\n lista_completa.append([old,new])\n add = 0\n\nprint(len(lista_completa)-1)\nlista_completa = lista_completa[1:]\n\nfor e in lista_completa:\n print(e[0] + \" \" + e[-1])\n",
"def search_key(handles, old, new):\n for key, value in handles.items():\n if value == old:\n handles[key] = new\n return True\n \n return False\n \n\ndef toString(handles):\n first = True\n total = 0\n res = \"\"\n for key, value in handles.items():\n total += 1\n if first:\n res += key + \" \" + value\n first = False\n else:\n res += \"\\n\" + key + \" \" + value\n\n return \"{}\\n{}\".format(total, res)\n \n\nqueries = int(input())\n\nhandles = {}\n\nfor __ in range(queries):\n query = input().split()\n \n old = query[0]\n new = query[1]\n \n if not search_key(handles, old, new):\n handles[old] = new\n \nprint(toString(handles))\n\n\t \t \t\t \t \t \t \t\t\t\t \t \t\t",
"n = int(input())\n\n# Dictionary to store mappings\nmappings = {}\n\nfor i in range(n):\n old, new = input().split()\n \n # Update mapping if old handle exists\n if old in mappings:\n mappings[new] = mappings[old]\n del mappings[old]\n else:\n mappings[new] = old\n\n# Output number of users and mappings\nprint(len(mappings))\nfor new, old in mappings.items():\n print(old, new)\n\n\t \t \t\t \t\t \t \t \t \t\t \t",
"q = int(input())\n\nnomes = {}\nfor i in range(q):\n old, new = map(str, input().split())\n if old in nomes.values():\n for k,j in nomes.items():\n if j == old:\n nomes[k] = new \n break\n else:\n nomes[old] = new\n\nprint(len(nomes))\nfor i,j in nomes.items():\n print(i, j)\n \t \t \t \t\t \t \t \t\t \t \t\t\t \t\t \t",
"n = int(input())\nmapa = {}\nfor i in range(n):\n nomes = input().split()\n old = nomes[0]\n new = nomes[1]\n if(mapa.get(old) != None):\n aux = mapa[old]\n mapa.pop(old)\n mapa[new] = aux\n else:\n mapa[new] = old\n\nprint(len(mapa.values()))\nfor i in mapa.keys():\n print(mapa[i], i)\n \t\t \t \t\t \t \t\t\t \t\t \t\t \t\t",
"import fileinput\r\n\r\nlines = [line.split() for line in fileinput.input()][1:]\r\nnameSets = []\r\n\r\nfor line in lines:\r\n newUser = True\r\n for set in nameSets:\r\n if line[0] in set:\r\n newUser = False\r\n set.append(line[1])\r\n if newUser:\r\n nameSets.append(line)\r\n \r\nprint(len(nameSets))\r\nfor set in nameSets:\r\n print(set[0]+' '+set[len(set)-1])",
"#coding:utf-8\r\n\r\nn = int( input())\r\n\r\nnames = {}\r\nchanges = 0\r\nfor i in range(n):\r\n\tcurrent, changed = map(str, input().split())\r\n\tif current not in names:\r\n\t\tnames[changed] = current\r\n\t\tchanges += 1\r\n\telse:\r\n\t\taux = names[current]\r\n\t\tnames.pop(current)\r\n\t\tnames[changed] = aux\r\nprint(changes)\t\t\r\nfor i in names:\r\n\tprint(names[i],i)\r\n",
"q = int(input())\r\na = []\r\nfor i in range(q):\r\n a.append(input().split())\r\n \r\n\r\nd = {}\r\nfor i in a:\r\n if i[0] in d:\r\n d[i[1]] = d[i[0]]\r\n del d[i[0]]\r\n else:\r\n d[i[1]] = i[0]\r\nprint(len(d))\r\nfor i in d:\r\n print(d[i], i)\r\n",
"q = int(input(), 10)\r\nd = dict()\r\n\r\nfor i in range(q):\r\n old, new = input().split(' ')\r\n if old not in d:\r\n d[new] = old\r\n else:\r\n f = d[old]\r\n d.pop(old)\r\n d[new] = f\r\n\r\nprint(len(d))\r\nfor i in d:\r\n print(d[i], ' ', i)",
"n = int(input())\n\nrequests = {}\n\nwhile n > 0:\n old, new = input().split(' ')\n\n if old in requests:\n original = requests[old]\n requests.pop(old)\n requests[new] = original\n \n else:\n requests[new] = old\n \n n -= 1\n\nprint(len(requests))\n\nfor k in requests:\n print(f'{requests[k]} {k}')\n\t\t \t \t\t \t \t \t \t\t \t \t\t\t \t\t\t\t",
"requests = int(input())\nnamesMap = {}\nfinalMap = {}\n\nfor i in range(requests):\n old, new = input().split()\n namesMap[old] = new\n\nfor key in namesMap.keys():\n currentKey = key\n while currentKey in namesMap.keys():\n currentKey = namesMap[currentKey]\n if currentKey in finalMap.values():\n continue\n finalMap[key] = currentKey\n\nprint(len(finalMap))\nfor i in finalMap.keys():\n print(i + ' ' + finalMap[i])\n\n\t\t \t \t\t \t \t \t \t\t \t\t\t\t\t",
"positions_old = {}\npositions_new = {}\nolds = []\nnews = []\n\nq = int(input())\nfor vez in range(q):\n old, new = input().split()\n if old in positions_new:\n position = positions_new[old]\n news[position] = new\n del positions_new[old]\n positions_new[new] = position\n else:\n position = len(olds)\n olds.append(old)\n news.append(new)\n positions_old[old] = position\n positions_new[new] = position\n \nnum_users = len(olds)\nprint(num_users)\nfor position in range(num_users):\n print(f'{olds[position]} {news[position]}')\n \t \t\t \t \t\t\t\t\t\t\t\t \t\t\t\t \t \t",
"def Get_new(Dic, name):\r\n while(Dic[name] != name):\r\n name = Dic[name]\r\n return name\r\n\r\ndic = {}\r\norig = []\r\n\r\nfor _ in range(int(input())):\r\n old, new = input().split()\r\n if old not in dic:\r\n dic[old] = new\r\n dic[new] = new\r\n orig.append(old)\r\n else:\r\n dic[old] = new\r\n dic[new] = new\r\nprint(len(orig))\r\nfor name in orig:\r\n if dic[name] != name:\r\n print(name, Get_new(dic, name))",
"s = int(input())\nc = []\nfor i in range(s):\n c.append(input())\ndc = {}\ncont = 0\nfor i in range(s-1, -1, -1):\n m = c[i].split()\n if m[1] in dc.keys():\n dc[m[0]] = dc.pop(m[1])\n else:\n dc[m[0]] = [m[1], cont]\n cont += 1 \nr = [0] * len(dc)\nfor a in dc.keys():\n r[dc[a][1]] = a + \" \" + dc[a][0]\nprint(len(r))\nfor a in r:\n print(a)\n\t\t \t \t \t \t \t \t\t \t \t \t\t\t",
"\r\nq=int(input())\r\nkey=[]\r\nval=[]\r\nfor _ in range(q):\r\n temp=input().split(\" \")\r\n key.append(temp[0])\r\n val.append(temp[1])\r\n\r\ni=0\r\nwhile i<len(key):\r\n\r\n if val[i] in key:\r\n j=-1\r\n while val[i] in key:\r\n j=key.index(val[i])\r\n val[i]=val[j]\r\n del key[j]\r\n del val[j]\r\n i+=1\r\nprint(len(key))\r\nk=0\r\nwhile k<len(key):\r\n print(key[k],val[k])\r\n k+=1",
"n = int(input())\r\n\r\nmap = {}\r\n\r\nfor i in range(0,n):\r\n input_string = input()\r\n input_string = input_string.split(\" \")\r\n \r\n if input_string[0] in map:\r\n temp = map[input_string[0]]\r\n map.pop(input_string[0])\r\n map[input_string[1]] = temp\r\n else:\r\n map[input_string[1]] = input_string[0]\r\n\r\n\r\nprint(len(map))\r\nfor key in map.keys():\r\n value = map[key]\r\n print(f'{value} {key}')",
"\r\nmaps = {}\r\nfor i in range(int(input())):\r\n old, new = input().split()\r\n \r\n if old in maps: \r\n maps[new] = maps[old]\r\n del maps[old]\r\n else:\r\n maps[new] = old\r\n \r\nprint(len(maps))\r\n\r\nfor k, v in maps.items():\r\n print(v + \" \" + k)",
"n = int(input())\r\nusers = {}\r\nfor x in range(n):\r\n new = users.values()\r\n string = input()\r\n usernames = string.split()\r\n a, b = usernames[0], usernames[1]\r\n if not a in new:\r\n users[a] = b\r\n else:\r\n for x in users:\r\n if users[x] == a:\r\n users[x] = b\r\n break\r\nprint(len(users))\r\nfor x, y in users.items():\r\n print(\"%s %s\" % (x, y))",
"q = int(input())\nmy_list = []\nfor i in range(q):\n line = input()\n my_list.append(line.split(' '))\nresult = []\n\nfor j in range(len(my_list)):\n old_name, new_name = my_list[j][0], my_list[j][1]\n\n still_changing_names = False\n\n for k in range(j+1, len(my_list)):\n if new_name == my_list[k][0]:\n still_changing_names = True\n my_list[k][0] = old_name\n break\n\n if not still_changing_names:\n result.append([old_name, new_name])\n\nprint(len(result))\nfor item in result:\n print(*item)\n# for l in range(len(result)):\n# print(*result[l])\n # print(f\"{result[l][0]} {result[l][1]}\")\n \n\n\n",
"n=int(input())\r\ntot=0\r\nmp={}\r\napp={}\r\ns=[]\r\nfor i in range(n):\r\n s1,s2=input().split(' ')\r\n if not app.__contains__(s1):\r\n s.append(s1)\r\n app[s1]=1\r\n tot=tot+1\r\n mp[s1]=s2\r\n app[s2]=1\r\nprint(tot)\r\nfor i in range(tot):\r\n print(s[i],end=' ')\r\n x=s[i]\r\n while mp.__contains__(x):\r\n x=mp[x]\r\n print(x)\r\n",
"ii=lambda:int(input())\r\nkk=lambda:map(int,input().split())\r\nll=lambda:list(kk())\r\n\r\nd = {}\r\nfor _ in range(ii()):\r\n\ta,b=input().split()\r\n\tif a in d: \r\n\t\td[b]=d[a]\r\n\t\tdel d[a]\r\n\telse:\r\n\t\td[b]=a\r\nprint(len(d))\r\nfor k in d:\r\n\tprint(d[k],k)\r\n",
"def get_key(d, value):\r\n for k, v in d.items():\r\n if v == value:\r\n return k\r\nn=int(input())\r\nd={}\r\nfor i in range(n):\r\n s1, s2 = input().split()\r\n if s1 in d.values():\r\n d[get_key(d,s1)] = s2\r\n else:\r\n d[s1] = s2\r\nprint(len(d))\r\nfor k, v in d.items():\r\n print(k,v)",
"n=int(input())\nqueries=[]\nnames=[]\nf=[]\nl=[]\nfor i in range(n):\n queries.append(input().split(' '))\nfor i in range(n):\n for j in range(2):\n if queries[i][j] in names:\n if j==0:\n names.remove(queries[i][j])\n l[l.index(queries[i][j])]=queries[i][j-1]\n else:\n names.append(queries[i][j])\n if j==0:\n f.append(queries[i][j])\n else:\n if queries[i][j] not in l:\n l.append(queries[i][j])\nprint(len(f))\nfor k in range(len(f)):\n print(f[k],l[k])\n \t \t \t\t \t \t \t\t \t \t \t \t",
"# n=5\r\nn=int(input())\r\ni=0\r\ngraph={}\r\nwhile i<n:\r\n pair=input().strip()\r\n head,tail=pair.split(\" \")\r\n graph[head]=tail\r\n i+=1\r\n\r\ndef merge(dicc,key1,key2):\r\n new_dict=dict(dicc)\r\n new_set=dicc[key2]\r\n del new_dict[key2]\r\n new_dict[key1]=new_set\r\n return new_dict\r\n\r\n\r\n\r\nwhile True:\r\n merged=False\r\n for head in graph:\r\n el=graph[head] ## revisar la cola\r\n if el in graph: ## si hay otra arista del tipo (Tail,Algo)\r\n graph=merge(graph,head,el)\r\n merged=True\r\n break\r\n if not(merged):\r\n break\r\nprint(len(graph))\r\nfor key in graph:\r\n el=graph[key]\r\n print(\"{} {}\".format(key,el))\r\n",
"n = int(input())\nusers = {}\n\nfor i in range(n):\n a,b = list(map(str, input().split()))\n flag = 0\n if(len(users) > 0):\n for name, newName in users.items():\n if newName == a:\n flag = 1\n break\n if flag==1:\n users[name] = b\n else:\n users[a] = b\n else:\n users[a] = b\n \nprint(len(users))\nfor name, newName in users.items():\n arr = []\n arr.append(name)\n arr.append(newName)\n print(*arr)\n",
"q = int(input())\nmy_list = []\nfor i in range(q):\n line = input()\n my_list.append(line.split(' '))\nresult = []\n\nj = 0\nwhile j < len(my_list):\n old_name, new_name = my_list[j][0], my_list[j][1]\n\n k = 0\n while k < len(my_list) - 1:\n if new_name == my_list[k+1][0] and k+1 >= j:\n new_name = my_list[k+1][1] \n del my_list[k+1]\n else:\n k=k+1\n\n # for k in range(len(my_list) - 1):\n # if new_name == my_list[k+1][0] and k+1 >= j:\n # new_name = my_list[k+1][1] \n # del my_list[k+1]\n\n result.append([old_name, new_name])\n j = j + 1\n\nprint(len(result))\nfor item in result:\n print(*item)\n# for l in range(len(result)):\n# print(*result[l])\n # print(f\"{result[l][0]} {result[l][1]}\")\n \n\n\n",
"viejos = []\nnuevos = []\ncantidad = int(input())\nprimer_input = input().rsplit(\" \")\nviejos.append(primer_input[0])\nnuevos.append(primer_input[1])\nfor i in range(cantidad - 1):\n Esta = False\n entrada = input()\n entrada = entrada.rsplit(\" \")\n old = entrada[0]\n new = entrada[1]\n for item in nuevos:\n if item == old:\n reemplazar = nuevos.index(item)\n nuevos[reemplazar] = new\n Esta = True\n if not Esta:\n viejos.append(old)\n nuevos.append(new)\n\nprint(len(viejos))\nfor i in range(len(viejos)):\n print(viejos[i] + \" \" + nuevos[i])\n",
"n = int(input())\nd = {}\nfor i in range(n):\n handle, newHandle = input().split()\n if(handle not in d and handle not in d.values()):\n d[handle] = newHandle\n elif(handle in d):\n d[handle] = newHandle\n else:\n for j in d:\n if(d[j] == handle):\n d[j] = newHandle\n break\nprint(len(d))\nfor i in d:\n print(i, d[i])\n\n \t \t\t\t\t \t \t\t\t\t\t \t\t \t\t \t",
"number_of_names = int(input())\n\nname_dict = {}\n\n\nfor i in range(number_of_names):\n name_pair = input().split(' ')\n old_name = name_pair[0]\n new_name = name_pair[1]\n\n if old_name in name_dict:\n name_dict[new_name] = name_dict.pop(old_name)\n else:\n name_dict[new_name] = old_name\n\n\nprint(len(name_dict))\n\nfor key, value in reversed(name_dict.items()):\n print(value, key)\n \t\t \t \t \t \t\t\t \t\t\t\t \t\t\t \t",
"d = {}\r\nfor s in [*open(0)][1:]:\r\n cn = False\r\n a,b = s.split()\r\n for i in d:\r\n if d[i] == a:\r\n cn = True\r\n d[i] = b\r\n if not cn:d[a] = b\r\nprint(len(d))\r\nfor i in d:\r\n print(f'{i} {d[i]}')",
"import sys\r\nimport math\r\n\r\nn = int(input())\r\n\r\nlst = dict()\r\nfor _ in range(n):\r\n s = input().split(' ')\r\n if s[0] in lst.values():\r\n k = list(lst.keys())[list(lst.values()).index(s[0])]\r\n lst[k] = s[1]\r\n else:\r\n lst.update({s[0]: s[1]})\r\n\r\nprint(len(lst))\r\n\r\nfor x, y in lst.items():\r\n print(x,y)",
"class User:\r\n def __init__(self, name, id):\r\n self.first_name = name\r\n self.last_name = None\r\n self.id = id\r\n\r\n def __repr__(self):\r\n return \"{} - {}\\n\".format(self.first_name, self.last_name)\r\n\r\nused = set()\r\nusernames = dict()\r\nusers = dict()\r\n\r\nN = int(input())\r\ni = 0\r\nn_users = 0\r\nwhile i < N:\r\n inp = input().strip(\"\\n\").split(\" \")\r\n old = inp[0]\r\n new = inp[1]\r\n if new in used:\r\n continue\r\n else:\r\n if old not in usernames:\r\n new_user = User(old, n_users)\r\n users[n_users] = new_user\r\n usernames[old] = n_users\r\n usernames[new] = n_users\r\n new_user.last_name = new\r\n used.add(new)\r\n used.add(old)\r\n n_users += 1\r\n else:\r\n user_id = usernames[old]\r\n users[user_id].last_name = new\r\n usernames[new] = user_id\r\n used.add(new)\r\n i += 1\r\n\r\nprint(len(users))\r\nfor u in users:\r\n text = \"{} {}\".format(users[u].first_name, users[u].last_name)\r\n print(text)",
"q = int(input())\r\nmemo = []\r\nfor _ in range(q):\r\n old_new = input().split()\r\n x = len(memo)\r\n done = False\r\n for i in range(x):\r\n if memo[i][-1] == old_new[0]:\r\n memo[i].append(old_new[1])\r\n done = True\r\n if not done:\r\n memo.append([old_new[0], old_new[1]])\r\n\r\nprint(len(memo))\r\nfor handles in memo:\r\n print(handles[0], handles[-1])\r\n \r\n",
"numR = int(input())\n \ndic ={}\n \nfor i in range(numR):\n old, new = input().split()\n if old not in dic:\n dic[new] = old\n else:\n aux = dic.pop(old)\n dic[new] = aux\n \nprint(len(dic))\nfor key in dic:\n print(dic[key], key)\n\n \t \t \t\t \t\t \t \t \t \t",
"from sys import stdin,stdout\r\ninput=stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n stdout.write(sep.join(map(str, args)) + end)\r\n \r\ndef dfs(st):\r\n dic2[st[-1]]=1\r\n if len(dic1[st[-1]])>0 and dic2[dic1[st[-1]]]==0:\r\n st.append(dic1[st[-1]])\r\n dfs(st)\r\n else:\r\n arr.append(st)\r\n\r\ndic1={} ; dic2={} ; n=int(input()) ; ans=0 ; arr=[] ; c=0\r\n\r\nfor i in range(n):\r\n a,b=input().split()\r\n dic1[a]=b ; dic2[a]=0\r\n dic1[b]=\"\" ; dic2[b]=0\r\nfor i in dic1.keys():\r\n if not dic2[i]:\r\n c+=1\r\n dfs([i])\r\nprint(c)\r\nfor i in arr:\r\n print(i[0],i[-1])\r\n",
"q = int(input())\r\nd = {}\r\nfor i in range(q):\r\n w = input().split()\r\n a, b = w[0], w[1]\r\n if a in d.values():\r\n for j in d.keys():\r\n if d[j]==a:\r\n d[j]=b\r\n break\r\n else:\r\n d[a]=b\r\nprint(len(d))\r\nfor i in d:\r\n print(i, d[i])\r\n",
"import sys\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport itertools\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict, Counter, deque\r\nfrom bisect import bisect_left,bisect_right, insort_left, insort_right\r\n\r\nmod=1000000007\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\ndef get_int(): return int(sys.stdin.readline().strip())\r\ndef get_list_strings(): return list(map(str, sys.stdin.readline().strip().split()))\r\n\r\n\r\n\r\n\r\n\r\ndef solve():\r\n n = get_int()\r\n \r\n # parent, size, distance\r\n parent = {}\r\n\r\n def find(member):\r\n if member not in parent:\r\n parent[member] = member\r\n return member\r\n \r\n if member == parent[member]:\r\n return member\r\n \r\n parent[member] = find(parent[member])\r\n return parent[member]\r\n \r\n def union(x,y):\r\n xpar = find(x)\r\n ypar = find(y)\r\n\r\n parent[ypar] = xpar\r\n \r\n def isConnected(x,y):\r\n return find(x) == find(y)\r\n \r\n for i in range(n):\r\n inp = get_list_strings()\r\n # print(inp, parent)\r\n union(inp[0], inp[1])\r\n \r\n parentset = defaultdict(list)\r\n for key in parent.keys():\r\n parentset[find(key)].append(key)\r\n \r\n print(len(parentset))\r\n for p in parentset.values():\r\n print(p[0], p[-1])\r\n \r\n\r\n \r\n \r\n\r\n\r\nif __name__ == \"__main__\":\r\n solve()",
"times = int(input())\r\n\r\nold_to_new = {}\r\nnew_to_old = {}\r\n\r\nfor _ in range(times):\r\n (old, new) = input().split(\" \")\r\n\r\n if old in new_to_old:\r\n old_to_new[new_to_old[old]] = new\r\n new_to_old[new] = new_to_old[old]\r\n else:\r\n old_to_new[old] = new\r\n new_to_old[new] = old\r\n\r\nprint(len(old_to_new))\r\nfor k in old_to_new:\r\n print(f\"{k} {old_to_new[k]}\")",
"t = int(input())\r\nd = {}\r\nfor i in range(t):\r\n old,new = input().split()\r\n d[new] = d.get(old,old)\r\n if old in d:\r\n \td.pop(old)\r\nprint(len(d))\r\nfor a,b in d.items():\r\n print(b,a)",
"quant_trocas = int(input())\ndic_1 = dict()\ndic_2 = dict()\nfor c in range(quant_trocas):\n user_antigo, user_novo = input().split()\n\n if user_antigo not in dic_2:\n dic_1[user_antigo] = user_novo\n dic_2[user_novo] = user_antigo\n else:\n dic_2[user_novo] = dic_2[user_antigo]\n dic_1[dic_2[user_novo]] = user_novo\n\nprint(len(dic_1))\nfor k, v in dic_1.items():\n print(k, v)\n\n \t \t\t\t\t \t \t \t\t \t\t\t",
"q = int(input())\nd = {}\nfor i in range(q):\n\to,n = map(str, input().split())\n \n\tif o in d:\n\t\td[n] = d[o]\n\t\tdel d[o]\n\telse:\n\t\td[n] = o\n \nprint(len(d))\nfor j in d:\n\tprint(d[j],j)\n\n \t\t \t\t \t\t\t\t \t \t \t \t \t \t",
"q = int(input())\r\nn = [input() for x in range(q)]\r\na = [n[0].split(), ]\r\nfor x in range(1, q):\r\n f = False\r\n s = n[x].split()\r\n for y in a:\r\n if s[0] == y[-1]:\r\n y.append(s[1])\r\n f = True\r\n break\r\n if not f:\r\n a.append(s)\r\nprint(len(a))\r\nfor x in a:\r\n print(x[0], x[-1])\r\n",
"import sys\r\nd={}\r\nfor i in range(int(sys.stdin.readline())):\r\n old, new = sys.stdin.readline().strip().split()\r\n if old in d.values():\r\n index = [j for j in d.keys() if d[j] == old]\r\n d[index[0]] = new\r\n elif old not in d.keys():\r\n d[old] = new\r\nprint(len(d))\r\nfor i, j in d.items():\r\n print(i, j)",
"z,zz=input,lambda:list(map(int,z().split()))\r\nfast=lambda:stdin.readline().strip()\r\nzzz=lambda:[int(i) for i in fast().split()]\r\nszz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())\r\nfrom string import *\r\nfrom re import *\r\nfrom collections import *\r\nfrom queue import *\r\nfrom sys import *\r\nfrom collections import *\r\nfrom math import *\r\nfrom heapq import *\r\nfrom itertools import *\r\nfrom bisect import *\r\nfrom collections import Counter as cc\r\nfrom math import factorial as f\r\nfrom bisect import bisect as bs\r\nfrom bisect import bisect_left as bsl\r\nfrom itertools import accumulate as ac\r\ndef lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))\r\ndef prime(x):\r\n p=ceil(x**.5)+1\r\n for i in range(2,p):\r\n if (x%i==0 and x!=2) or x==0:return 0\r\n return 1\r\ndef dfs(u,visit,graph):\r\n visit[u]=1\r\n for i in graph[u]:\r\n if not visit[i]:\r\n dfs(i,visit,graph)\r\n\r\n###########################---Test-Case---#################################\r\n\"\"\"\r\n\r\n If you Know me , Then you probably don't know me !\r\n\r\n\r\n\"\"\"\r\n###########################---START-CODING---##############################\r\n\r\n\r\nn=int(z())\r\n\r\nlst={}\r\n\r\nfor _ in range( n ):\r\n name1,name2=z().split()\r\n\r\n lst[name1]=name2\r\n\r\nans=[]\r\nansx=[]\r\n\r\n\r\nvis=[]\r\n\r\ndef searchx(i):\r\n \r\n vis.append(i)\r\n\r\n try:\r\n new_name=lst[i]\r\n searchx(new_name)\r\n \r\n \r\n except:\r\n ansx.append(i)\r\n \r\n \r\n\r\n\r\nres=0\r\n\r\nfor i in lst:\r\n if i not in vis:\r\n vis.append(i)\r\n x=searchx(i)\r\n ans.append(i)\r\n res+=1\r\nprint(res)\r\nfor i,j in zip(ans,ansx):\r\n print(i,j)\r\n \r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n",
"import collections\r\nfrom collections import Counter\r\nn=int(input())\r\na1=collections.defaultdict(set)\r\nx=[]\r\ni=0\r\nwhile(n):\r\n n-=1 \r\n a,b=map(str,input().split())\r\n x.append([a,b])\r\n if(a not in a1):\r\n a1[a].add(i) \r\n i+=1\r\n if(b not in a1):\r\n a1[b].add(i)\r\n i+=1\r\nx1=[]\r\nfor i in range(len(x)):\r\n z=[]\r\n for j in a1[x[i][0]]:\r\n z.append(j)\r\n for j in a1[x[i][1]]:\r\n z.append(j)\r\n x1.append(z)\r\nparent=[0]*len(a1)\r\nrank=[0]*len(a1)\r\nfor i in range(len(a1)):\r\n parent[i]=i \r\n rank[i]=0\r\ndef findPar(node):\r\n if(node==parent[node]):\r\n return node \r\n parent[node]=findPar(parent[node])\r\n return findPar(parent[node])\r\ndef union(u,v):\r\n u=findPar(u) \r\n v=findPar(v) \r\n if(rank[u]<rank[v]):\r\n parent[u]=v\r\n elif(rank[v]<rank[u]):\r\n parent[v]=u \r\n else:\r\n parent[v]=u \r\n rank[u]+=1 \r\nfor i in x1:\r\n union(i[0],i[1]) \r\na11=[]\r\nfor i in a1:\r\n a11.append(i)\r\nx2=Counter(parent).keys()\r\nprint(len(x2))\r\nans=[-1]*len(a11) \r\nfor i in range(len(parent)-1,-1,-1):\r\n if(ans[parent[i]]==-1):\r\n ans[parent[i]]+=1\r\n print(a11[parent[i]],a11[i])\r\n",
"def MCH(n):\r\n d = dict()\r\n cont = 0\r\n for i in range(n):\r\n q = input().strip().split(\" \")\r\n if not q[0] in d.values():\r\n d[q[0]] = q[1]\r\n cont += 1\r\n else:\r\n for k in d.keys():\r\n if d[k] == q[0]:\r\n d[k] = q[1]\r\n print(cont)\r\n for k in d.keys():\r\n print(k + \" \" + d[k])\r\n\r\nn = int(input())\r\nMCH(n)",
"d, P = {}, []\r\n\r\nfor _ in range(int(input())):\r\n old, new = input().split()\r\n if old in d:\r\n P[d[old]][1], d[new] = new, d[old]\r\n else:\r\n d[new] = len(P)\r\n P.append([old, new])\r\n\r\nprint(len(P))\r\nfor p in P:\r\n print(*p)",
"n = int(input())\n\naux = {}\n\nfor i in range(n):\n entrada = input().split()\n if len(aux) == 0:\n aux[entrada[1]] = entrada[0]\n\n elif entrada[0] in aux:\n aux[entrada[1]] = aux.pop(entrada[0])\n \n else:\n aux[entrada[1]] = entrada[0]\n\nprint (len(aux))\nfor s in aux:\n print (aux[s], s)\n \t \t \t\t\t \t\t\t \t\t\t\t \t\t \t \t\t \t \t\t",
"new=[]\r\nold=[]\r\nt=int(input())\r\nfor num in range(0,t):\r\n o,n=input().split()\r\n if len(new)==0:\r\n old.append(o)\r\n new.append(n)\r\n else:\r\n l=0\r\n for num in new:\r\n if num==o:\r\n i=new.index(num)\r\n new[i]=n\r\n l=1\r\n if l==0:\r\n new.append(n)\r\n old.append(o)\r\nprint(len(new))\r\ni=0\r\nii=len(new)\r\nwhile i<ii:\r\n print(old[i],new[i])\r\n i=i+1\r\n",
"import sys\r\nfrom collections import deque\r\n# from collections import Counter\r\n# from math import sqrt\r\n# from math import log\r\n# from math import ceil\r\n# from bisect import bisect_left, bisect_right\r\n\r\n# alpha=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\n# mod=10**9+7\r\n# mod=998244353\r\n\r\n# def BinarySearch(a,x): \r\n# \ti=bisect_left(a,x) \r\n# \tif(i!=len(a) and a[i]==x): \r\n# \t\treturn i \r\n# \telse: \r\n# \t\treturn -1\r\n\r\n# def sieve(n): \r\n# \tprime=[True for i in range(n+1)]\r\n# \tp=2\r\n# \twhile(p*p<=n): \r\n# \t\tif (prime[p]==True): \r\n# \t\t\tfor i in range(p*p,n+1,p): \r\n# \t\t\t\tprime[i]=False\r\n# \t\tp+=1\r\n# \tprime[0]=False\r\n# \tprime[1]=False\r\n# \ts=set()\r\n# \tfor i in range(len(prime)):\r\n# \t\tif(prime[i]):\r\n# \t\ts.add(i)\r\n# \treturn s\r\n\r\n# def gcd(a, b):\r\n# \tif(a==0):\r\n# \t\treturn b \r\n# \treturn gcd(b%a,a)\r\n\r\nfast_reader=sys.stdin.readline\r\nfast_writer=sys.stdout.write\r\n\r\ndef input():\r\n\treturn fast_reader().strip()\r\n\r\ndef print(*argv):\r\n\tfast_writer(' '.join((str(i)) for i in argv))\r\n\tfast_writer('\\n')\r\n\r\n#____________________________________________________________________________________________________________________________________\r\n\r\nfor _ in range(1):\r\n\tn=int(input())\r\n\td={}\r\n\tp=[]\r\n\tfor i in range(n):\r\n\t\told,new=input().split()\r\n\t\td[old]=new\r\n\t\tp.append(old)\r\n\tvisited=set()\r\n\tans=0\r\n\tlans=[]\r\n\tfor i in range(len(p)):\r\n\t\tif(p[i] in visited):\r\n\t\t\tcontinue\r\n\t\tans+=1\r\n\t\told=p[i]\r\n\t\tq=deque()\r\n\t\tq.append(p[i])\r\n\t\tnew=\"\"\r\n\t\twhile(len(q)!=0):\r\n\t\t\tt=q.popleft()\r\n\t\t\tif(t in visited):\r\n\t\t\t\tcontinue\r\n\t\t\telif(t not in d):\r\n\t\t\t\tvisited.add(t)\r\n\t\t\t\tbreak\r\n\t\t\telse:\r\n\t\t\t\tvisited.add(t)\r\n\t\t\t\tnew=d[t]\r\n\t\t\t\tq.append(d[t])\r\n\t\tlans.append([old,new])\r\n\tprint(ans)\r\n\tfor i in range(len(lans)):\r\n\t\tprint(*lans[i])",
"t=int(input())\r\na=[]\r\nfor i in range(t):\r\n b=[x for x in input().split()]\r\n a.append(b)\r\n\r\nb=[]\r\nc=[]\r\nfor i in range(t):\r\n b.append(a[i][0])\r\n c.append(a[i][1])\r\n\r\ncnt=0\r\nd=[]\r\nfor x in b:\r\n if x not in c:\r\n cnt+=1\r\n d.append(x)\r\n\r\nprint(cnt)\r\nh=[]\r\nfor y in d:\r\n e=b.index(y)\r\n g=[]\r\n p=c[e]\r\n while c[e] in b:\r\n f=b.index(c[e])\r\n e=f\r\n p=c[e]\r\n g.append(y)\r\n g.append(p)\r\n\r\n h.append(g)\r\n\r\nfor i in range(cnt):\r\n print(h[i][0] + ' ' + h[i][1])",
"t = int(input())\na =[]\nb = []\nfor i in range(t):\n x, y = input().split()\n if x not in b:\n a.append(x)\n b.append(y)\n else:\n b[b.index(x)] = y\nprint(len(a))\nfor i in range(len(a)):\n print(a[i], b[i])\n\t \t \t \t \t \t \t\t\t \t\t\t\t\t\t\t \t",
"q = int(input())\r\nd = {}\r\nused = set()\r\n\r\nfor _ in range(q):\r\n old, new = input().split()\r\n parent = d.get(old)\r\n \r\n if parent:\r\n del d[old]\r\n d[new] = parent\r\n else:\r\n d[new] = old\r\n\r\nprint(len(d))\r\n\r\nfor i in d:\r\n print(d[i], i)\r\n",
"n = int(input())\r\ndic = {}\r\nfor i in range(n):\r\n a,b = input().split()\r\n if a in dic :\r\n dic[b] = dic.pop(a) \r\n else : \r\n dic[b] = a\r\nprint(len(dic))\r\nfor i in dic:\r\n print(dic[i] , i)",
"x = int(input())\r\n\r\ndicio = {}\r\nchanges = 0\r\nfor i in range(x):\r\n\thandle, new_hadle = input().split()\r\n\t\r\n\tif handle not in dicio:\r\n\t\tchanges += 1\r\n\t\tdicio[new_hadle] = handle\r\n\telse:\r\n\t\tdicio[new_hadle] = dicio[handle]\r\n\t\tdicio[handle] = \"\"\r\n\t\t\r\n\t\r\nprint(changes)\r\n\r\nfor key,value in dicio.items():\r\n\tif value != \"\":\r\n\t\tprint(value,key)\r\n\r\n\r\n",
"n = int(input())\nusers = {}\n\nfor i in range(n):\n old, new = input().split()\n users[new] = users.get(old, old)\n users.pop(old, None)\nprint(len(users))\nfor new, old in users.items():\n print(old, new)\n\t \t \t \t \t \t\t \t \t \t\t\t\t\t \t",
"n = int(input())\r\n\r\nnomes = {}\r\n\r\nfor i in range(n):\r\n entrada = input().split(' ')\r\n antigo_nome = entrada[0]\r\n novo_nome = entrada[1]\r\n\r\n if antigo_nome in nomes: \r\n nomes[novo_nome] = nomes.pop(antigo_nome)\r\n else:\r\n nomes[novo_nome] = antigo_nome\r\n\r\nprint(len(nomes))\r\n\r\nfor chave, valor in reversed(nomes.items()):\r\n print(valor, chave)",
"from sys import stdin, stdout\n\ndef solve(renames):\n handles = {}\n for names in renames:\n oldname = names[0]\n newname = names[1]\n if oldname not in handles:\n handles[newname] = oldname\n else:\n oldername = handles.pop(oldname)\n handles[newname] = oldername\n return handles\n\ndef print_handles(handles):\n names = handles.items()\n stdout.write(str(len(names)));\n stdout.write('\\n');\n for newname,oldname in names:\n stdout.write('{} {}'.format(oldname, newname))\n stdout.write('\\n');\n \n\nrenames = []\nn = int(stdin.readline())\nfor i in range(n):\n lines = stdin.readline().rstrip(\"\\r\\n\").split()\n renames.append((lines[0],lines[1]))\nsolution = solve(renames)\nprint_handles(solution)\n",
"\ndic = {}\nn = int(input())\nwhile(n > 0):\n alreadyInputted = False\n change = input().split()\n for firstName, changedName in dic.items():\n if(change[0] == changedName):\n dic[firstName] = change[1]\n alreadyInputted = True\n if(not alreadyInputted):\n dic[change[0]] = change[1]\n \n n -= 1\n\nprint(len(dic))\nfor n1, n2 in dic.items():\n print(n1 + ' ' + n2)\n \t\t \t \t\t\t\t \t \t \t\t\t \t \t",
"n = int(input())\ngraph = {}\nfor i in range(n):\n\to, n = input().split()\n\tgraph[n] = graph.get(o, o)\n\tgraph.pop(o, None)\nprint(len(graph))\nfor n, o in graph.items():\n\tprint(o, n)\n \t \t \t \t\t\t \t \t\t\t \t \t\t \t",
"# -*- coding: utf-8 -*-\r\n# Link al problema: https://codeforces.com/problemset/problem/501/B\r\n# Usamos una tabla de hash en la que se mantienen los nombres originales con\r\n# una referencia al más reciente y los más recientes con referencia la original\r\nimport sys\r\n\r\n\r\nif __name__ == \"__main__\":\r\n handles = sys.stdin.readlines()\r\n handles = [handle.rstrip('\\n').split(\" \") for handle in handles[1:]]\r\n users = {}\r\n originals = []\r\n\r\n for old, new in handles:\r\n if old not in users.keys():\r\n # Agregamos un nombre original\r\n users[old] = new\r\n originals.append(old)\r\n # Agregamos su primer cambio\r\n users[new] = old\r\n else:\r\n previous = old\r\n old = users[old]\r\n # Como tendremos referencia directa no necesitamos a este\r\n del users[previous]\r\n\r\n # El nuevo nombre tiene referencia directa al original\r\n users[new] = old\r\n # Aumentamos contador de cambios de nombre original\r\n users[old] = new\r\n\r\n sys.stdout.write(\"{}\\n\".format(len(originals)))\r\n for handle in originals:\r\n sys.stdout.write(\"{} {}\\n\".format(handle, users[handle]))\r\n",
"d={}\r\nfor _ in range(int(input())):\r\n\ts=input().split()\r\n\told,new=s[0],s[1]\r\n\tif old in d:\r\n\t\tk=d[old]\r\n\t\td[new]=k\r\n\t\tdel d[old]\r\n\t\td[new].append(old)\r\n\telse:\r\n\t\td[new]=[old]\r\nprint(len(d))\r\nfor x in d:\r\n\tprint(d[x][0],x)",
"n = int(input())\r\ndic = {}\r\nc= 0\r\nfor i in range(n):\r\n o, n = str(input()).split(\" \")\r\n x = dic.get(o)\r\n if(x is not None and x!= o):\r\n oo = dic.pop(o)\r\n dic[n] = oo\r\n else:\r\n dic[n]=o\r\n c+=1\r\nprint(c)\r\nl = list(dic)\r\nfor i in range(len(l),0,-1):\r\n print(dic[l[i-1]] + \" \" + l[i-1])\r\n",
"q = int(input())\nanswers = []\nfor i in range(0,q):\n inp = input().split(' ')\n old = inp[0]\n new = inp[1]\n found = False\n for a in answers:\n if old==a[1]:\n a[1] = new\n found = True\n break\n if not found:\n answers.append([old,new])\n\nprint(len(answers))\nfor a in answers:\n print(a[0],' ',a[1])\n \t \t\t \t \t\t \t \t \t",
"n = int(input())\nd={}\nfor i in range(n):\n flag = 0\n aux = input().split()\n for j in d:\n if d[j] == aux[0]:\n d[j] = aux[1]\n flag = 1\n if flag == 0:\n d[aux[0]] = aux[1]\n\nprint(len(d))\nfor i in d:\n print(i, end=' ')\n print(d[i])\n \t\t\t\t\t \t \t \t \t\t \t \t",
"\r\nt=int(input())\r\ndic=dict()\r\nfor i in range(t):\r\n\ta,b=map(str,(input().split()))\r\n\tif a in dic:\r\n\t\tdic[b]=dic[a]\r\n\t\tdic.pop(a)\r\n\telse:\r\n\t\tdic[b]=a\r\nprint(len(dic))\r\nfor i in dic:\r\n\tprint(dic[i],i)",
"t = int(input())\r\nd = {}\r\nfor i in range(t):\r\n o,n = map(str,input().split())\r\n d[o] = n\r\n d[n] = 0\r\nc = []\r\nfor key in d:\r\n if(d[key]!=0):\r\n k = key\r\n while(d[k]!=0):\r\n l = d[k]\r\n d[k] = 0\r\n k = l\r\n c.append([key,k])\r\nprint(len(c))\r\nfor i in c:\r\n print(*i)\r\n",
"a = int(input())\nb = {}\nfor c in range(a):\n d,e = input().split()\n if d not in b:b[e] = d\n else:b[e] = b.pop(d)\nprint(len(b))\nfor i in b:print(b[i], i)\n\n \t \t\t\t\t \t \t \t\t\t \t\t \t \t\t \t\t",
"q=int(input())\nd={}\nc=0\nfor i in range(q):\n t=False\n old, new = input().split(' ')\n if(old not in d):\n for j in d.keys():\n if(d[j][-1]==old):\n d[j].append(new)\n t=True\n if(t == False):\n d[old] = [new]\n else:\n d[old] = [new]\n\nprint(len(d))\nfor k in d.keys():\n print(k, d[k][-1])\n \t\t\t\t \t\t\t \t\t\t\t\t \t\t\t\t \t \t",
"q = int(input())\r\ndic = {}\r\nfor i in range(q):\r\n\ta,b = input().split()\r\n\tused = False\r\n\tfor i in dic.keys():\r\n\t\tif a == dic[i]:\r\n\t\t\tused = True\r\n\t\t\tdic[i] = b\r\n\tif not used:\r\n\t\tdic[a] = b\r\n \r\nprint(len(dic))\r\nfor i in dic.keys():\r\n\tprint(i,dic[i])",
"\r\nname = {}\r\nname_l = []\r\n\r\nfor _ in range(int(input())):\r\n old, new = input().split()\r\n\r\n if old in name_l:\r\n name[list(name.keys())[list(name.values()).index(old)]] = new\r\n else:\r\n name[old] = new\r\n name_l = name.values()\r\n\r\nprint(len(name))\r\n\r\nfor key, v in name.items():\r\n print(key, v)"
] | {"inputs": ["5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov", "1\nMisha Vasya", "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k", "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha", "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e", "17\nn5WhQ VCczxtxKwFio5U\nVCczxtxKwFio5U 1WMVGA17cd1LRcp4r\n1WMVGA17cd1LRcp4r SJl\nSJl D8bPUoIft5v1\nNAvvUgunbPZNCL9ZY2 jnLkarKYsotz\nD8bPUoIft5v1 DnDkHi7\njnLkarKYsotz GfjX109HSQ81gFEBJc\nGfjX109HSQ81gFEBJc kBJ0zrH78mveJ\nkBJ0zrH78mveJ 9DrAypYW\nDnDkHi7 3Wkho2PglMDaFQw\n3Wkho2PglMDaFQw pOqW\n9DrAypYW G3y0cXXGsWAh\npOqW yr1Ec\nG3y0cXXGsWAh HrmWWg5u4Hsy\nyr1Ec GkFeivXjQ01\nGkFeivXjQ01 mSsWgbCCZcotV4goiA\nHrmWWg5u4Hsy zkCmEV", "10\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9\nSEj 2knOMLyzr\n0v69ijnAc S7d7zGTjmlku01Gv\n2knOMLyzr otGmEd\nacwr3TfMV7oCIp RUSVFa9TIWlLsd7SB\nS7d7zGTjmlku01Gv Gd6ZufVmQnBpi\nS1 WOJLpk\nWOJLpk Gu\nRUSVFa9TIWlLsd7SB RFawatGnbVB\notGmEd OTB1zKiOI", "14\nTPdoztSZROpjZe z6F8bYFvnER4V5SP0n\n8Aa3PQY3hzHZTPEUz fhrZZPJ3iUS\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nAO s1VGWTCbHzM\ni 4F\nfhrZZPJ3iUS j0OVZQF6MvNcKN9xDZFJ\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\nj0OVZQF6MvNcKN9xDZFJ DzjmeNqN0H4Teq0Awr\n4F wJcdxt1kwqfDeJ\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nJ0Usg DKdKMFJ6tK8XA\nz6F8bYFvnER4V5SP0n 0alJ\nMijh2O6 qic8kXWuR6", "14\nHAXRxayyf1Dj1F0mT hjR4A8IQMb0nyBtqG\nWNuMJa5Jg05qkqZOrL noNkWXrSidHGwxgbQ\nmOitVy6W52s0FENMz6 oLUkLNfojssvLvb1t\nhjR4A8IQMb0nyBtqG oA7uBFu4Oo\noA7uBFu4Oo M450\nM450 LXEzO4\noLUkLNfojssvLvb1t YG5\nnoNkWXrSidHGwxgbQ L\nL YBWzu4W\nYBWzu4W ML\nML scVZE9m8JnH\nLXEzO4 Ne0oBPY0Iy\nscVZE9m8JnH GXhznv\nYG5 UY08abilYF1LaXj49hQ"], "outputs": ["3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123", "1\nMisha Vasya", "1\na k", "2\n123abc 1A2B3C\n1 Misha", "3\nM G\n1 R\nS e", "2\nn5WhQ mSsWgbCCZcotV4goiA\nNAvvUgunbPZNCL9ZY2 zkCmEV", "5\n0v69ijnAc Gd6ZufVmQnBpi\nS1 Gu\nSEj OTB1zKiOI\nacwr3TfMV7oCIp RFawatGnbVB\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9", "10\nTPdoztSZROpjZe 0alJ\nJ0Usg DKdKMFJ6tK8XA\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\n8Aa3PQY3hzHZTPEUz DzjmeNqN0H4Teq0Awr\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nMijh2O6 qic8kXWuR6\nAO s1VGWTCbHzM\ni wJcdxt1kwqfDeJ", "3\nWNuMJa5Jg05qkqZOrL GXhznv\nHAXRxayyf1Dj1F0mT Ne0oBPY0Iy\nmOitVy6W52s0FENMz6 UY08abilYF1LaXj49hQ"]} | UNKNOWN | PYTHON3 | CODEFORCES | 334 | |
2a36302b6d7ee6e2e5069592a4d07e84 | The Art of Dealing with ATM | ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most *k* bills from it, and the bills may be of at most two distinct denominations.
For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at *k*<==<=20 such ATM can give sums 100<=000 burles and 96<=000 burles, but it cannot give sums 99<=000 and 101<=000 burles.
Let's suppose that the country uses bills of *n* distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash *q* times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the *q* of requests for cash withdrawal.
The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=5000, 1<=≤<=*k*<=≤<=20).
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=107) — the denominations of the bills that are used in the country. Numbers *a**i* follow in the strictly increasing order.
The next line contains integer *q* (1<=≤<=*q*<=≤<=20) — the number of requests for cash withdrawal that you will make.
The next *q* lines contain numbers *x**i* (1<=≤<=*x**i*<=≤<=2·108) — the sums of money in burles that you are going to withdraw from the ATM.
For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print <=-<=1, if it is impossible to get the corresponding sum.
Sample Input
6 20
10 50 100 500 1000 5000
8
4200
100000
95000
96000
99000
10100
2015
9950
5 2
1 2 3 5 8
8
1
3
5
7
9
11
13
15
Sample Output
6
20
19
20
-1
3
-1
-1
1
1
1
2
2
2
2
-1
| [
"n,k = [int(s) for s in input().split()]\r\n\r\nbills = [int(s) for s in input().split()]\r\npairs = {}\r\nfor bill in bills:\r\n for i in range(k):\r\n possible = (i+1)*bill\r\n if possible not in pairs or i+1 < pairs[possible]:\r\n pairs[possible] = i+1\r\nq = int(input())\r\n\r\nmymax = 100000000000000000\r\nfor i in range(q):\r\n query = int(input())\r\n minumum = mymax\r\n for money, nbills in pairs.items():\r\n if money == query and nbills <=k and nbills < minumum:\r\n minumum = nbills\r\n else:\r\n rest = query-money\r\n if rest in pairs and nbills+pairs[rest] < minumum and nbills+pairs[rest] <= k:\r\n minumum = nbills+pairs[rest]\r\n if minumum == mymax:\r\n print(-1)\r\n else:\r\n print(minumum)\r\n",
"from collections import defaultdict\nn, m = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\nd = defaultdict(int)\n\nd[0] = 0\nfor v in a:\n for i in range(1, m + 1):\n d[v * i] = i\n\nq = int(input())\nfor _ in range(q):\n x = int(input())\n r = m + 1\n for k, v in d.items():\n y = x - k\n if y in d:\n r = min(r, v + d[y])\n print(r if r <= m else -1)\n",
"def find(x):\r\n ret = 100\r\n for k in mp:\r\n if x - k in mp:\r\n ret = min(ret, mp[k] + mp[x - k])\r\n return ret if ret <= m else -1\r\n\r\n\r\nn, m = (int(x) for x in input().split())\r\na = [int(x) for x in input().split()]\r\nmp = {}\r\nfor i in a:\r\n for j in range(m + 1):\r\n x = i * j\r\n if x in mp:\r\n mp[x] = min(j, mp[x])\r\n else:\r\n mp[x] = j\r\nq = int(input())\r\n\r\nfor Q in range(q):\r\n x = int(input())\r\n print(find(x))\r\n",
"f = lambda: map(int, input().split())\r\nn, k = f()\r\nt = list(f())\r\nu = [{i * q for q in t} for i in range(1, k + 1)]\r\n\r\ndef g(d):\r\n v = [{d - q for q in p} for p in u]\r\n for j in range(1, k + 1):\r\n if d in u[j - 1]: return j\r\n for i in range(j // 2):\r\n if u[i].intersection(v[j - i - 2]): return j\r\n return -1\r\n\r\nfor i in range(int(input())): print(g(int(input())))\r\n",
"f = lambda: map(int, input().split())\r\nn, k = f()\r\nt = list(f())\r\n\r\nd = {0: 0}\r\nfor q in t:\r\n for i in range(1, k + 1): d[q * i] = i\r\n\r\nfor j in range(int(input())):\r\n a = int(input())\r\n p = [i + d[a - b] for b, i in d.items() if a - b in d]\r\n print(min(p) if p and min(p) <= k else -1)"
] | {"inputs": ["6 20\n10 50 100 500 1000 5000\n8\n4200\n100000\n95000\n96000\n99000\n10100\n2015\n9950", "5 2\n1 2 3 5 8\n8\n1\n3\n5\n7\n9\n11\n13\n15", "5 5\n1 2 3 6 102\n10\n1\n4\n30\n1\n76\n114\n10\n13\n13\n4", "3 5\n1 36 95\n10\n3\n1\n4212\n144\n4\n109\n6\n5\n2\n24", "4 5\n1 11 50 203\n10\n5\n5\n150\n53\n56\n5\n12304\n852\n1\n5", "4 5\n2 12 71 424\n10\n355\n342\n8\n1835\n6625\n355\n16\n1490\n148\n213", "4 5\n1 27 49 135\n10\n17\n4\n81\n13390\n1\n525\n701\n5\n30\n31", "3 1\n1 36 43\n10\n1\n627\n36\n36\n4\n1\n36\n1\n16\n64", "3 1\n1 4 21\n10\n42\n1\n1\n4\n1\n1\n1\n117\n6\n829", "5 1\n1 13 23 211 709\n10\n27\n77\n13\n10\n148\n10\n1\n88\n23\n31", "4 5\n1 4 30 891\n10\n717\n410\n1\n5015\n16\n3\n1\n5\n5\n1", "4 5\n1 36 468 791\n10\n5\n5075\n1404\n5\n198\n53\n5\n4121\n1404\n4244", "4 5\n1 2 322 758\n10\n648\n547\n647\n322\n13\n10\n1\n1742\n7\n1173", "4 20\n1 2 45 229\n10\n15\n13\n41406\n900\n18\n27\n20\n15\n589\n14", "14 1\n1 6 30 49 189 478 1514 1776 49588 655130 673561 1101207 2953118 4634078\n20\n1514\n5\n189\n23\n45\n77500\n49588\n84799\n2052853\n8815\n26\n1\n68\n478\n61\n189\n6\n1\n478\n500", "51 5\n1 2 4 5 6 7 8 10 12 13 20 23 31 58 63 66 71 83 230 305 322 550 559 596 952 1353 1494 1610 2156 2160 3053 4312 4698 8240 13445 16060 34590 52653 68265 134554 203093 203689 302605 403350 687107 1006006 1551678 2840590 3326364 7266429 7447528\n20\n284\n4\n8\n21997625\n5\n273060\n550\n74\n10742012\n330\n40\n24722\n8306\n1220\n20\n6511\n8\n2\n33054009\n16", "55 5\n1 2 3 4 5 6 7 9 11 13 19 25 42 65 126 138 164 275 315 364 411 1297 1532 2562 3280 10675 11275 22596 28563 33704 38710 74921 88560 94671 155311 166320 166913 228504 271152 284013 333826 697037 941357 1012652 1132991 1230723 1501332 1722000 1826550 2128486 2286428 4050608 5396247 7607666 7751599\n20\n196\n2395370\n831600\n5\n325\n12\n21\n296\n532926\n4018\n22\n7\n565\n28\n193550\n7\n46\n144\n67838\n78019", "35 20\n1 2 3 4 5 7 29 41 111 176 248 291 704 1557 2112 2624 7322 7960 10989 15277 18740 20135 32948 56220 65554 112440 131792 153762 219812 508510 1591650 1634639 2691141 4546819 5985721\n20\n158964830\n20\n1240\n899531\n284\n522\n95\n13455733\n41913730\n60423\n3077372\n26\n189248\n9330\n16\n25634561\n5201868\n73197\n9017\n899540", "5 1\n2 9 13 442 2772\n20\n9353\n2\n9\n1658772\n2\n2\n442\n616\n4399\n9\n96\n442\n442\n9\n9\n18395\n13\n2\n2\n2", "53 20\n1 2 5 12 13 22 110 137 192 201 256 274 285 618 646 1008 1259 2373 2828 3117 7351 7918 10686 13363 17755 26103 30849 32058 36202 38094 56252 61698 67760 91829 104412 139304 158237 222774 244133 278608 281260 370188 468245 936490 975198 1582370 1914289 3001845 3657737 3828578 4394394 4827053 4875990\n20\n21396\n1772314\n14693\n162\n14140\n304226\n3\n20\n154078\n63\n3673488\n1537\n836\n88\n1012\n73644\n67771090\n2\n370258\n55752756", "44 20\n1 2 3 4 15 19 20 27 29 31 44 58 103 106 156 203 206 222 499 515 1339 3557 4017 5017 7105 14416 24926 27799 35904 42393 127972 166738 186649 304616 927340 1854680 2189529 3436045 3497568 4379058 4893003 5331302 6998715 7895196\n20\n918\n18758\n32328\n1387737\n871\n31\n1521\n312902\n17489324\n65685880\n11603\n27386575\n29013091\n775866\n7725\n102059\n1718\n2014\n104199396\n19", "20 1\n1 99 115 460 805 2415 3220 8280 13800 16560 42780 50600 141680 425040 1127000 1416800 1710280 2254000 2781275 5667200\n20\n13800\n1556849\n1\n460\n33\n99\n102\n805\n99\n8280\n1\n1\n2541\n12\n1\n354\n115\n235598\n4863\n136", "58 5\n1 6 9 18 34 41 82 99 164 179 183 204 240 396 636 1224 2023 2856 4488 4705 5712 9180 9266 18360 18850 20270 23086 60810 190701 197064 211140 214200 222970 243240 263510 314442 425670 486480 708288 789888 1009800 1025349 1054040 1094580 1325184 1579776 1748076 2050698 2635100 2895984 2918880 3975552 4284000 4739328 4938778 5386284 6992304 7898880\n20\n825982\n428758\n7062\n183\n4101396\n2\n11583907\n1228\n612\n1318\n170\n1980\n24574\n2770806\n1019\n123\n58\n145\n4292\n21545136", "62 20\n1 5 7 22 28 30 37 44 49 80 135 240 285 329 409 410 570 658 672 830 855 955 1132 1274 2309 2940 3477 3681 3948 6381 6792 7567 7896 10902 11460 18424 19740 29448 59820 117502 125154 141506 149424 211521 353376 387680 525084 706752 908040 1379115 1575252 1816080 3150504 3962147 4246074 5535096 6103922 7153540 7260701 8442370 8567160 8913115\n20\n880\n56\n119\n47\n21042\n21\n787\n1480658\n2597864\n281\n308\n31597\n8100\n29470\n19\n83\n11494\n32\n3232\n1203", "45 1\n1 2 4 23 43 70 71 430 638 908 1042 1290 1846 2150 5160 10320 11180 16340 30960 55900 176085 239510 257140 278640 443167 514280 526750 771420 1028560 1285700 1424160 1542840 1799980 2057120 3085680 3342820 4114240 4628520 4790200 4885660 6171360 6428500 6685640 7632210 7714200\n20\n2\n2\n23\n5119\n1\n245644\n75545\n1516554\n4179\n1\n16340\n1\n1\n612762\n1\n1\n1\n1424160\n43\n4", "16 5\n1 145 524 820 1048 13120 36680 102500 141860 283720 512500 1332500 2558400 3944200 4100000 5116800\n20\n4716\n56979\n14333600\n16\n3\n2653\n25489787\n479469\n1050\n669\n5240\n2665002\n1730\n1643\n20500000\n43808729\n557\n40689909\n2097\n5240", "6 20\n1 4 38 76 304 74214\n20\n12\n90\n39\n440\n319\n9\n66\n50\n647\n2460\n196\n18\n77\n11\n18\n58\n5888496\n211\n500\n281512", "41 20\n1 3 4 154 1405 2810 4215 7025 19670 33720 49175 54795 64630 82895 129260 130665 151557 165790 168600 255710 300024 461710 663160 792420 927300 1500120 1584840 1854600 1906585 2377260 2781900 3150010 3709200 3962100 4500360 5056595 5305280 5546940 5563800 5968440 7131780\n20\n121163\n22255200\n8472\n8\n21\n292085\n137697\n705\n435970\n775562\n131108\n5502\n71655\n39341\n57721\n46365\n90703013\n77983120\n164400\n547953", "27 5\n31900 63800 127600 191400 255200 319000 478500 510400 574200 638000 765600 1020800 2296800 2552000 2679600 3062400 3445200 3572800 3828000 3891800 4083200 4466000 5359200 6124800 7273200 9187200 9378600\n20\n159500\n3828000\n4\n1165857\n159500\n765600\n269036\n1\n478500\n2296800\n127600\n159500\n3190000\n5327300\n1276000\n9187200\n9\n382800\n11675400\n15312000", "35 20\n2616 7848 13080 18312 23544 36624 47088 70632 75864 94176 109872 125568 143880 146496 151728 164808 227592 337464 455184 635688 659232 682776 824040 910368 1012392 1318464 1357704 1365552 1648080 1669008 2024784 2508744 4049568 5007024 5017488\n20\n238056\n1\n22280472\n117720\n334848\n8\n1365552\n26160\n94176\n1121157\n15478872\n97125922\n219744\n658642\n1383864\n3296160\n151728\n235440\n787416\n47088", "27 20\n2 12 34 48 68 70 102 136 140 210 230 756 2268 4464 7378 8928 49630 71424 142848 144096 376278 688296 752556 1069810 1343724 3209430 5744760\n20\n18189038\n572752\n5\n51291\n584\n6108\n3209440\n100315\n368\n1122\n46\n26\n280\n256\n567936\n2800\n1454352\n1196050\n73582149\n149765054", "39 1\n139873 279746 419619 559492 699365 839238 979111 1118984 1258857 1398730 1538603 1678476 1958222 2098095 2237968 2517714 2657587 2797460 3077206 3356952 3496825 3916444 4196190 4475936 5035428 5594920 6154412 6294285 6434158 6713904 6853777 6993650 7133523 7273396 7832888 7972761 8112634 8392380 8951872\n20\n11575\n9\n419619\n139873\n15\n419619\n308818\n1\n296\n6713904\n139873\n1118984\n139873\n5594920\n839238\n279746\n1040050\n7809292\n839238\n2797460", "1 20\n4247942\n20\n63719130\n80710898\n188731\n4876\n67967072\n8\n63719130\n728\n76462956\n84958840\n72215014\n9667\n8495884\n4247942\n29735594\n28521424\n94864\n76462956\n84958840\n84958840", "1 1\n42\n5\n1\n41\n42\n43\n84", "1 2\n42\n8\n1\n41\n42\n43\n83\n84\n85\n126", "2 1\n23 42\n11\n1\n22\n23\n24\n41\n42\n43\n66\n67\n68\n987", "2 2\n23 42\n17\n1\n22\n23\n24\n41\n42\n43\n45\n46\n47\n66\n67\n68\n83\n84\n85\n987", "2 5\n1 2\n1\n200000000", "1 20\n1\n20\n200000000\n199999999\n199999998\n199999997\n199999996\n199999995\n199999994\n199999993\n199999992\n199999991\n199999990\n199999989\n199999988\n199999987\n199999986\n199999985\n199999984\n199999983\n199999982\n199999981", "2 20\n1 10000000\n1\n190000001", "1 1\n1\n1\n1", "1 1\n1000000\n1\n200000000", "5 20\n1 2 3 4 5\n5\n100000000\n100000001\n190000099\n199999999\n200000000", "2 2\n1 2\n1\n200000000", "1 20\n1\n1\n200000000", "1 20\n10000000\n1\n200000000", "20 20\n9970642 9971855 9973038 9973500 9975536 9976719 9980831 9981533 9983173 9984276 9988058 9988522 9990039 9993666 9994295 9994564 9995173 9997005 9999509 9999959\n20\n199640580\n199667040\n199630770\n199670280\n199940730\n199623640\n199880310\n199743150\n199814920\n199888590\n199620220\n199667040\n199692020\n199603770\n199768390\n199570690\n199700430\n199969640\n199453550\n199837850"], "outputs": ["6\n20\n19\n20\n-1\n3\n-1\n-1", "1\n1\n1\n2\n2\n2\n2\n-1", "1\n2\n5\n1\n-1\n3\n3\n3\n3\n2", "3\n1\n-1\n4\n4\n4\n-1\n5\n2\n-1", "5\n5\n3\n4\n-1\n5\n-1\n-1\n1\n5", "5\n-1\n4\n-1\n-1\n5\n3\n-1\n5\n3", "-1\n4\n3\n-1\n1\n-1\n-1\n5\n4\n5", "1\n-1\n1\n1\n-1\n1\n1\n1\n-1\n-1", "-1\n1\n1\n1\n1\n1\n1\n-1\n-1\n-1", "-1\n-1\n1\n-1\n-1\n-1\n1\n-1\n1\n-1", "-1\n-1\n1\n-1\n4\n3\n1\n2\n2\n1", "5\n-1\n3\n5\n-1\n-1\n5\n-1\n3\n-1", "4\n-1\n5\n1\n-1\n5\n1\n-1\n4\n-1", "8\n7\n-1\n20\n9\n14\n10\n8\n9\n7", "1\n-1\n1\n-1\n-1\n-1\n1\n-1\n-1\n-1\n-1\n1\n-1\n1\n-1\n1\n1\n1\n1\n-1", "4\n1\n1\n-1\n1\n4\n1\n2\n-1\n2\n2\n4\n2\n4\n1\n4\n1\n1\n-1\n2", "4\n-1\n5\n1\n3\n2\n2\n4\n-1\n5\n2\n1\n5\n2\n5\n1\n2\n2\n5\n-1", "-1\n4\n5\n19\n10\n15\n5\n9\n-1\n9\n15\n4\n-1\n-1\n3\n-1\n-1\n10\n12\n12", "-1\n1\n1\n-1\n1\n1\n1\n-1\n-1\n1\n-1\n1\n1\n1\n1\n-1\n1\n1\n1\n1", "4\n4\n6\n5\n5\n-1\n2\n4\n19\n5\n-1\n7\n10\n4\n3\n-1\n20\n1\n15\n-1", "5\n17\n-1\n-1\n13\n1\n9\n-1\n19\n20\n-1\n-1\n-1\n8\n7\n-1\n12\n10\n-1\n1", "1\n-1\n1\n1\n-1\n1\n-1\n1\n1\n1\n1\n1\n-1\n-1\n1\n-1\n1\n-1\n-1\n-1", "-1\n4\n-1\n1\n2\n2\n-1\n5\n3\n-1\n2\n5\n-1\n-1\n-1\n2\n5\n5\n5\n4", "4\n2\n5\n3\n12\n3\n9\n18\n-1\n8\n6\n17\n10\n2\n3\n4\n10\n3\n17\n8", "1\n1\n1\n-1\n1\n-1\n-1\n-1\n-1\n1\n1\n1\n1\n-1\n1\n1\n1\n1\n1\n1", "5\n-1\n3\n-1\n3\n-1\n-1\n-1\n3\n2\n5\n4\n-1\n5\n5\n-1\n-1\n-1\n3\n5", "3\n14\n2\n20\n16\n3\n8\n4\n18\n15\n11\n6\n2\n5\n6\n6\n-1\n-1\n17\n-1", "-1\n4\n16\n2\n6\n-1\n14\n-1\n-1\n8\n13\n-1\n2\n3\n20\n3\n-1\n15\n8\n11", "2\n1\n-1\n-1\n2\n1\n-1\n-1\n1\n1\n1\n2\n2\n4\n2\n1\n-1\n2\n2\n2", "2\n-1\n12\n2\n3\n-1\n1\n2\n1\n-1\n17\n-1\n2\n-1\n2\n2\n1\n2\n2\n1", "18\n14\n-1\n-1\n6\n13\n6\n-1\n4\n9\n2\n3\n2\n11\n-1\n14\n13\n-1\n-1\n-1", "-1\n-1\n1\n1\n-1\n1\n-1\n-1\n-1\n1\n1\n1\n1\n1\n1\n1\n-1\n-1\n1\n1", "15\n19\n-1\n-1\n16\n-1\n15\n-1\n18\n20\n17\n-1\n2\n1\n7\n-1\n-1\n18\n20\n20", "-1\n-1\n1\n-1\n-1", "-1\n-1\n1\n-1\n-1\n2\n-1\n-1", "-1\n-1\n1\n-1\n-1\n1\n-1\n-1\n-1\n-1\n-1", "-1\n-1\n1\n-1\n-1\n1\n-1\n-1\n2\n-1\n-1\n-1\n-1\n-1\n2\n-1\n-1", "-1", "-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1", "20", "1", "-1", "-1\n-1\n-1\n-1\n-1", "-1", "-1", "20", "20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20"]} | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
2a66bad0fc0565adc9835909ce2b06c6 | Vanya and Computer Game | Vanya and his friend Vova play a computer game where they need to destroy *n* monsters to pass a level. Vanya's character performs attack with frequency *x* hits per second and Vova's character performs attack with frequency *y* hits per second. Each character spends fixed time to raise a weapon and then he hits (the time to raise the weapon is 1<=/<=*x* seconds for the first character and 1<=/<=*y* seconds for the second one). The *i*-th monster dies after he receives *a**i* hits.
Vanya and Vova wonder who makes the last hit on each monster. If Vanya and Vova make the last hit at the same time, we assume that both of them have made the last hit.
The first line contains three integers *n*,*x*,*y* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*,<=*y*<=≤<=106) — the number of monsters, the frequency of Vanya's and Vova's attack, correspondingly.
Next *n* lines contain integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the number of hits needed do destroy the *i*-th monster.
Print *n* lines. In the *i*-th line print word "Vanya", if the last hit on the *i*-th monster was performed by Vanya, "Vova", if Vova performed the last hit, or "Both", if both boys performed it at the same time.
Sample Input
4 3 2
1
2
3
4
2 1 1
1
2
Sample Output
Vanya
Vova
Vanya
Both
Both
Both
| [
"n,x,y=map(int,input().split())\r\ndef f(a,x,y):return(a*x+x+y-1)//(x+y)\r\nfor _ in[0]*n:n=int(input());r=f(n,x,y)*y-f(n,y,x)*x;print(['Both','Vova','Vanya'][(r>0)+(r<0)*2])"
] | {"inputs": ["4 3 2\n1\n2\n3\n4", "2 1 1\n1\n2", "7 5 20\n26\n27\n28\n29\n30\n31\n32", "10 10 1\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "10 1 10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "1 999999 1000000\n1000000000", "5 5 6\n999999999\n999999998\n999999997\n999999996\n999999995", "10 13 27\n3\n21\n23\n17\n15\n23\n16\n7\n24\n20", "1 1 1\n1", "5 999999 1000000\n1999997\n1999998\n1999999\n2000000\n2000001", "5 999998 1000000\n999997\n999998\n999999\n1000000\n1000001", "20 5 15\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39", "11 22 33\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65"], "outputs": ["Vanya\nVova\nVanya\nBoth", "Both\nBoth", "Vova\nVova\nVova\nBoth\nBoth\nVova\nVova", "Vanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nVanya\nBoth", "Vova\nVova\nVova\nVova\nVova\nVova\nVova\nVova\nVova\nBoth", "Vanya", "Vova\nVanya\nVova\nVanya\nVova", "Vanya\nVanya\nVova\nVova\nVanya\nVova\nVova\nVova\nVanya\nVova", "Both", "Vova\nBoth\nBoth\nVova\nVanya", "Vova\nBoth\nBoth\nVova\nVanya", "Both\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth\nBoth\nVova\nVova\nBoth", "Both\nVova\nVanya\nVova\nBoth\nBoth\nVova\nVanya\nVova\nBoth\nBoth"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2aabae6e92b6532ec48754a161b83180 | White, Black and White Again | Polycarpus is sure that his life fits the description: "first there is a white stripe, then a black one, then a white one again". So, Polycarpus is sure that this rule is going to fulfill during the next *n* days. Polycarpus knows that he is in for *w* good events and *b* not-so-good events. At least one event is going to take place during each day. As each day is unequivocally characterizes as a part of a white or a black stripe, then each day is going to have events of the same type only (ether good or not-so-good).
What is the number of distinct ways this scenario can develop over the next *n* days if Polycarpus is in for a white stripe (a stripe that has good events only, the stripe's length is at least 1 day), the a black stripe (a stripe that has not-so-good events only, the stripe's length is at least 1 day) and a white stripe again (a stripe that has good events only, the stripe's length is at least 1 day). Each of *n* days will belong to one of the three stripes only.
Note that even the events of the same type are distinct from each other. Even if some events occur on the same day, they go in some order (there are no simultaneous events).
Write a code that prints the number of possible configurations to sort the events into days. See the samples for clarifications on which scenarios should be considered distinct. Print the answer modulo 1000000009 (109<=+<=9).
The single line of the input contains integers *n*, *w* and *b* (3<=≤<=*n*<=≤<=4000, 2<=≤<=*w*<=≤<=4000, 1<=≤<=*b*<=≤<=4000) — the number of days, the number of good events and the number of not-so-good events. It is guaranteed that *w*<=+<=*b*<=≥<=*n*.
Print the required number of ways modulo 1000000009 (109<=+<=9).
Sample Input
3 2 1
4 2 2
3 2 2
Sample Output
2
4
4
| [
"import sys\r\n\r\nMOD = int(1e9) + 9\r\n\r\ndef inv(n):\r\n return pow(n, MOD - 2, MOD)\r\n\r\ndef combo(n):\r\n rv = [0 for __ in range(n + 1)]\r\n rv[0] = 1\r\n for k in range(n):\r\n rv[k + 1] = rv[k] * (n - k) % MOD * inv(k + 1) % MOD\r\n return rv\r\n\r\nwith sys.stdin as fin, sys.stdout as fout:\r\n n, w, b = map(int, next(fin).split())\r\n\r\n combw = combo(w - 1)\r\n combb = combo(b - 1)\r\n\r\n ans = 0\r\n for black in range(max(1, n - w), min(n - 2, b) + 1):\r\n ans = (ans + (n - 1 - black) * combw[n - black - 1] % MOD * combb[black - 1]) % MOD\r\n\r\n for f in w, b:\r\n for k in range(1, f + 1):\r\n ans = k * ans % MOD\r\n\r\n print(ans, file=fout)\r\n",
"M=10**9+9\r\nR=10**4\r\nFact=[1]*(R+1)\r\nfor i in range(2,R+1):\r\n Fact[i]=(i*Fact[i-1])%M\r\nFacthyp=[1]*(R+1)\r\nFacthyp[R]=pow(Fact[R],M-2,M)\r\nfor i in range(R-1,-1,-1):\r\n Facthyp[i]=((i+1)*Facthyp[i+1])%M\r\ndef C(n,k):\r\n if n<k or n<0 or k<0:\r\n return 0\r\n return (Fact[n]*Facthyp[n-k]*Facthyp[k])%M\r\nn,w,b=[int(e) for e in input().split()]\r\nprint(( Fact[w]*Fact[b]*sum((n-m-1)*C(b-1,m-1)*C(w-1,n-m-1) for m in range(1,n-1)) )%M)"
] | {"inputs": ["3 2 1", "4 2 2", "3 2 2", "3 3 1", "3 2 2", "3 3 3", "4 2 3", "4 3 2", "10 10 10", "10 7 5", "10 4 9", "100 200 300", "200 100 300", "239 300 231", "300 300 300", "300 2 300", "300 300 1", "3 300 300", "3 2 300", "3 300 1", "4000 1000 3000", "4000 2000 2000", "4000 100 3900", "4000 2 3998", "3 2 4000", "3 4000 4000", "4000 4000 1", "4000 3998 2", "4000 4000 4000", "4000 4000 100", "4000 100 4000"], "outputs": ["2", "4", "4", "12", "4", "72", "24", "48", "318389383", "130636800", "135283173", "316471646", "949581532", "774612666", "375912430", "775907030", "775907030", "496527918", "196174631", "828107078", "876839920", "310481606", "221262673", "686088712", "938379934", "680114446", "63263244", "296557186", "997463324", "994443885", "908339579"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2b14359cdb47916fbca3f80ffe7e2333 | Treasure Hunt | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $7$ because its subribbon a appears $7$ times, and the ribbon abcdabc has the beauty of $2$ because its subribbon abc appears twice.
The rules are simple. The game will have $n$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $n$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
Sample Input
3
Kuroo
Shiro
Katie
7
treasurehunt
threefriends
hiCodeforces
1
abcabc
cbabac
ababca
15
foPaErcvJ
mZaxowpbt
mkuOlaHRE
Sample Output
Kuro
Shiro
Katie
Draw
| [
"n = int(input())\r\ns1, s2, s3 = input(), input(), input()\r\nl = len(s1)\r\n\r\nflag = 0\r\n\r\nif n>=l:\r\n\tprint(\"Draw\")\r\n\tflag = 1\r\n\r\n\r\nif flag == 0:\r\n\r\n\tans = []\r\n\tm1 = m2 = m3 = 0\r\n\ts01 = s02 = s03 = ''\r\n\tli = [chr(x) for x in range(ord('a'), ord('z') + 1)] \r\n\tli += [chr(x) for x in range(ord('A'), ord('Z') + 1)]\r\n\r\n\ts_temp = set([char for char in s1])\r\n\tfor item in li:\r\n\t\tt1 = s1.count(item)\r\n\t\tt2 = s2.count(item)\r\n\t\tt3 = s3.count(item)\r\n\t\tif t1>m1:\r\n\t\t\tm1 = t1\r\n\t\t\ts01 = item\r\n\t\tif t2>m2:\r\n\t\t\tm2 = t2\r\n\t\t\ts02 = item\r\n\t\tif t3>m3:\r\n\t\t\tm3 = t3\r\n\t\t\ts03 = item\t\t\r\n\r\n\tif (n==1):\r\n\t\tif (m1==l):\r\n\t\t\tm1-=1\r\n\t\telse:\r\n\t\t\tm1+=1\r\n\t\tif (m2==l):\r\n\t\t\tm2-=1\r\n\t\telse:\r\n\t\t\tm2+=1\r\n\t\tif (m3==l):\r\n\t\t\tm3-=1\r\n\t\telse:\r\n\t\t\tm3+=1\t\t\t\t\r\n\r\n\telse:\t\t\r\n\t\tif m1+n>l:\r\n\t\t\tm1 = l\r\n\t\telse:\r\n\t\t\tm1 += n\t\r\n\t\tif m2+n>l:\r\n\t\t\tm2 = l\r\n\t\telse:\r\n\t\t\tm2 += n\t\r\n\t\tif m3+n>l:\r\n\t\t\tm3 = l\r\n\t\telse:\r\n\t\t\tm3 += n\r\n\r\n\r\n\tif (m1>m2 and m1>m3):\r\n\t\tprint(\"Kuro\")\r\n\telif (m2>m1 and m2>m3):\r\n\t\tprint(\"Shiro\")\r\n\telif (m3>m1 and m3>m2):\r\n\t\tprint(\"Katie\")\t\t\r\n\telse:\r\n\t\tprint(\"Draw\")\t",
"from collections import Counter\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n _kuro = input().strip()\r\n _shiro = input().strip()\r\n _katie = input().strip()\r\n length = len(_kuro)\r\n\r\n if n != 1:\r\n kuro = max(0, length - Counter(_kuro).most_common(1)[0][1] - n)\r\n shiro = max(0, length - Counter(_shiro).most_common(1)[0][1] - n)\r\n katie = max(0, length - Counter(_katie).most_common(1)[0][1] - n)\r\n else:\r\n kuro = length - Counter(_kuro).most_common(1)[0][1] - n\r\n if kuro == -1:\r\n kuro = 1\r\n\r\n shiro = length - Counter(_shiro).most_common(1)[0][1] - n\r\n if shiro == -1:\r\n shiro = 1\r\n\r\n katie = length - Counter(_katie).most_common(1)[0][1] - n\r\n if katie == -1:\r\n katie = 1\r\n\r\n srt = sorted([kuro, shiro, katie])\r\n if srt[0] == srt[1]:\r\n print('Draw')\r\n else:\r\n if kuro == srt[0]:\r\n print('Kuro')\r\n elif shiro == srt[0]:\r\n print('Shiro')\r\n else:\r\n print('Katie')\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"from collections import Counter\r\nn = int(input())\r\ntotal = [0] * 3\r\nfor i in range(3):\r\n s = input()\r\n a = Counter(s)\r\n MAX = max(a.values())\r\n if MAX == len(s) and n == 1:\r\n MAX = len(s) - 1\r\n else:\r\n MAX += n\r\n MAX = min(MAX, len(s)) \r\n total[i] = MAX\r\nmax = max(total)\r\nif total.count(max) > 1:\r\n print(\"Draw\")\r\nelse:\r\n if total[0] == max:\r\n print(\"Kuro\")\r\n elif total[1] == max:\r\n print(\"Shiro\")\r\n else:\r\n print(\"Katie\")# 1691074927.9507425",
"\r\ndef hard(a,n):\r\n di={}\r\n if len(a)<=n:\r\n return n\r\n mak=-1\r\n for i in a:\r\n if i in di:\r\n di[i]+=1\r\n else:\r\n di[i]=1\r\n mak= max(mak,di[i])\r\n \r\n if n==1 and mak==len(a):\r\n l=len(a)\r\n return (l-1)\r\n \r\n return min(mak+n,len(a)) \r\n \r\n\r\n\r\n\r\n\r\n\r\nn= int(input())\r\na= hard(input(),n)\r\nb= hard(input(),n)\r\nc= hard(input(),n)\r\nif a>b and a>c:\r\n print('Kuro')\r\nelif b>a and b>c:\r\n print('Shiro')\r\nelif c>a and c>b:\r\n print('Katie')\r\nelse:\r\n print('Draw')\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"def max_beauty(ribbon, n):\n b_cnt = {}\n for c in ribbon:\n if c in b_cnt:\n b_cnt[c] += 1\n else:\n b_cnt[c] = 1\n mx = 0\n for key, val in b_cnt.items():\n mx = max(mx, val)\n l = len(ribbon)\n if mx == l and n == 1:\n return l - 1\n elif mx == l:\n return l\n else:\n return min(l, mx + n)\n\n\nclass CodeforcesTask979BSolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.ribbons = []\n\n def read_input(self):\n self.n = int(input())\n self.ribbons = [input() for x in range(3)]\n\n def process_task(self):\n names = [\"Kuro\", \"Shiro\", \"Katie\"]\n bes = [max_beauty(x, self.n) for x in self.ribbons]\n winning = max(bes)\n if bes.count(winning) > 1:\n self.result = \"Draw\"\n else:\n self.result = names[bes.index(winning)]\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask979BSolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n",
"x = int(input())\r\nu = input()\r\nv = input()\r\nw = input()\r\n\r\ndef wtf(s):\r\n\tans = 0\r\n\tfor i in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ':\r\n\t\tans = max(ans, s.count(i))\r\n\tneed = len(s)-ans\r\n\tif need == 0 and x == 1:\r\n\t\treturn len(s)-1\r\n\tif need > x:\r\n\t\treturn ans + x\r\n\telse:\r\n\t\treturn len(s)\r\n\t\r\n\treturn ans\r\na = [wtf(u), wtf(v), wtf(w)]\r\nmaxi = max(a)\r\na, b, c = a[0], a[1], a[2]\r\n\r\nif a==maxi and b!=maxi and c!=maxi:\r\n\tprint(\"Kuro\")\r\nelif b==maxi and a!=maxi and c!=maxi:\r\n\tprint(\"Shiro\")\r\nelif c==maxi and a!=maxi and b!=maxi:\r\n\tprint(\"Katie\")\r\nelse:\r\n\tprint(\"Draw\")",
"from collections import Counter\r\nn = int(input())\r\n\r\nkuro=input()\r\nshir=input()\r\nkatie=input()\r\nl=len(kuro)\r\nm1 = list(Counter(kuro).most_common()[0])\r\nif n > l-m1[1]:\r\n if n==1:\r\n m1[1] -=1\r\n else:\r\n m1[1]=l\r\nelse:\r\n m1[1] = m1[1]+n\r\nm2 = list(Counter(shir).most_common()[0])\r\nif n > l-m2[1]:\r\n if n==1:\r\n m2[1] -=1\r\n else:\r\n m2[1]=l\r\nelse:\r\n m2[1] = m2[1]+n\r\nm3 = list(Counter(katie).most_common()[0])\r\nif n > l-m3[1]:\r\n if n==1:\r\n m3[1] -=1\r\n else:\r\n m3[1]=l\r\nelse:\r\n m3[1] = m3[1]+n\r\n \r\nM = max(m1[1],m2[1],m3[1])\r\nif (m1[1],m2[1],m3[1]).count(M) > 1:\r\n print(\"Draw\")\r\nelif M==m1[1]:\r\n print(\"Kuro\")\r\nelif M==m2[1]:\r\n print(\"Shiro\")\r\nelse:\r\n print(\"Katie\")\r\n",
"from collections import Counter\r\n\r\nn_turns = int(input())\r\nNAMES = [\"Kuro\", \"Shiro\", \"Katie\"]\r\nRibbons = []\r\nfor _ in range(3):\r\n Ribbons.append(list(input()))\r\n\r\nn_finals = []\r\nfor R in Ribbons:\r\n freq = max(list(Counter(R).values()))\r\n if freq == len(R) and n_turns == 1:\r\n n_final = 1\r\n else:\r\n n_final = max(0, len(R)-freq-n_turns)\r\n n_finals.append(n_final)\r\n\r\nsorted_players = sorted(range(3), key= lambda k: n_finals[k])\r\nfirst, second, *_ = sorted_players\r\n\r\nif n_finals[first] == n_finals[second]:\r\n ret = \"Draw\"\r\nelse:\r\n ret = NAMES[first]\r\n\r\nprint(ret)\r\n",
"n = int(input())\r\nS = [input() for i in range(3)]\r\nbu = []\r\nfor s in S:\r\n cnt = {}\r\n mx = 0\r\n for c in s:\r\n if c not in cnt:\r\n cnt[c] = 0\r\n cnt[c] += 1\r\n mx = max(mx, cnt[c])\r\n if mx == len(s) and n == 1:\r\n bu.append(mx - 1)\r\n else:\r\n bu.append(min(len(s), mx + n))\r\n\r\nans = -1\r\nansmx = -1\r\nfor i in range(3):\r\n if bu[i] > ansmx:\r\n ans = i\r\n ansmx = bu[i]\r\n elif bu[i] == ansmx:\r\n ans = -1\r\n\r\nif ans == -1:\r\n print('Draw')\r\nelif ans == 0:\r\n print('Kuro')\r\nelif ans == 1:\r\n print('Shiro')\r\nelse:\r\n print('Katie')\r\n",
"num_inp=lambda: int(input())\r\narr_inp=lambda: list(map(int,input().split()))\r\nsp_inp=lambda: map(int,input().split())\r\nstr_inp=lambda:input()\r\nN = int(input())\r\nn = [0,0,0]\r\n \r\nfor i in range(3):\r\n\tz = [0 for i in range(128)]\r\n\tx = input()\r\n\tfor j in x:\r\n\t\tz[ord(j)]+=1\r\n\tn[i]=min(N+max(z),len(x)-1 if (N==1 and len(x)==max(z)) else len(x))\r\nr=max(n)\r\nif n.count(r)==1:\r\n\tif(n[0]==r):\r\n\t\tprint(\"Kuro\")\r\n\telif(n[1]==r):\r\n\t\tprint(\"Shiro\")\r\n\telse:\r\n\t\tprint(\"Katie\")\r\nelse:\r\n\tprint(\"Draw\")",
"n = int(input())\r\np = input()\r\nq = input()\r\nr = input()\r\n\r\nma, mb, mc = 0, 0, 0\r\na, b, c = {}, {}, {}\r\n\r\nfor x in p: a[x] = 0\r\nfor x in q: b[x] = 0\r\nfor x in r: c[x] = 0\r\n\r\nfor x in p:\r\n a[x] += 1\r\n ma = max(ma, a[x])\r\n\r\nfor x in q:\r\n b[x] += 1\r\n mb = max(mb, b[x])\r\n\r\nfor x in r:\r\n c[x] += 1\r\n mc = max(mc, c[x])\r\n\r\nif n == 1 and ma == len(p): p = p[:-1]\r\nif n == 1 and mb == len(q): q = q[:-1]\r\nif n == 1 and mc == len(r): r = r[:-1]\r\n\r\nma = min(ma + n, len(p))\r\nmb = min(mb + n, len(q))\r\nmc = min(mc + n, len(r))\r\n\r\nif ma > mb and ma > mc: print(\"Kuro\")\r\nelif mb > ma and mb > mc: print(\"Shiro\")\r\nelif mc > ma and mc > mb: print(\"Katie\")\r\nelse: print(\"Draw\")",
"# Why do we fall ? So we can learn to pick ourselves up.\r\n\r\n\r\nfrom collections import Counter\r\nn = int(input())\r\nss = []\r\nfor _ in range(0,3):\r\n ss.append(input())\r\nans = [\"Kuro\",\"Shiro\",\"Katie\"]\r\nmaxi = [0,0,0]\r\nfor i in range(0,3):\r\n c = Counter(ss[i])\r\n mx = max(c.values())\r\n to = min(len(ss[i])-mx,n)\r\n maxi[i] = mx+to\r\n if n == 1 and mx == len(ss[i]):\r\n maxi[i] -= 1\r\n# print(maxi)\r\nif maxi.count(max(maxi)) > 1:\r\n print(\"Draw\")\r\nelse:\r\n print(ans[maxi.index(max(maxi))])\r\n\r\n\r\n\r\n\r\n\"\"\"\r\n\r\n1\r\nooooo\r\nabcde\r\nabcde\r\n\r\n3\r\nKuroo\r\nShiro\r\nKatie\r\n\r\n\r\n\r\n\"\"\"",
"import sys\r\nline=lambda:sys.stdin.buffer.readline().strip()\r\nn=int(line())\r\ns=[line() for _ in range(3)]\r\nr=[0]*3\r\nfor i in range(3):\r\n c={}\r\n r[i]=min(len(s[i]),n)\r\n for k in s[i]: c[k]=c[k]+1 if k in c else 1\r\n for k in c: r[i]=max(r[i],min(len(s[i]),c[k]+n)-(c[k]==len(s[i]) and n==1))\r\nm=max(r)\r\nt=r.count(m)\r\nif t>1: print(\"Draw\")\r\nelif r[0]==m: print(\"Kuro\")\r\nelif r[1]==m: print(\"Shiro\")\r\nelse: print(\"Katie\")",
"import collections\r\n\r\nn = int(input())\r\n\r\ns = []\r\nfor i in range(3):\r\n s.append(input())\r\n\r\n\r\nmax_val = [0, 0, 0]\r\nans = ['Kuro', 'Shiro', 'Katie']\r\n\r\nfor i in range(3):\r\n cnt = collections.Counter(s[i])\r\n rr = max(cnt.values())\r\n\r\n changed = min(len(s[i]) - rr, n)\r\n moves = n - changed\r\n\r\n max_val[i] = rr + changed - (moves == 1 and rr == len(s[i]))\r\n\r\n\r\nif max_val.count(max(max_val)) > 1:\r\n print('Draw')\r\nelse:\r\n print(ans[max_val.index(max(max_val))])\r\n",
"from collections import Counter\r\n\r\ndef f(x):\r\n return max(list(Counter(x).values()))\r\n\r\nn=int(input())\r\nz=input()\r\nl=len(z)\r\na=f(z)\r\nb=f(input())\r\nc=f(input())\r\n\r\ndef v(x):\r\n if x==l:\r\n return x-1\r\n else:\r\n return x+1\r\n\r\nif n==1:\r\n a, b, c=v(a), v(b), v(c)\r\n if a>b and a>c:\r\n print(\"Kuro\")\r\n elif b>a and b>c:\r\n print(\"Shiro\")\r\n elif c>a and c>b:\r\n print(\"Katie\")\r\n else:\r\n print(\"Draw\")\r\nelif (l-a<=n)+(l-b<=n)+(l-c<=n)>=2:\r\n print(\"Draw\")\r\nelif a>b and a>c:\r\n print(\"Kuro\")\r\nelif b>a and b>c:\r\n print(\"Shiro\")\r\nelif c>a and c>b:\r\n print(\"Katie\")\r\nelse:\r\n print(\"Draw\")\r\n#print((l-a<=n)+(l-b<=n)+(l-c<=n))\r\n#print(a, b, c)",
"#!/usr/bin/env python3\n# -*- coding: UTF-8 -*-\n\nfrom collections import Counter\nN = int(input())\n\n\ndef calc(string: str) -> int:\n cnts: dict = Counter(ch for ch in string)\n t = max(cnts[x] for x in cnts)\n length = len(string)\n if(N <= length - t):\n return t + N\n else:\n if t == length and N == 1:\n return length - 1\n else:\n return length\n\n\na, b, c = (calc(input()) for i in range(3))\n\nif a > b and a > c:\n print(\"Kuro\")\nelif b > a and b > c:\n print(\"Shiro\")\nelif c > a and c > b:\n print(\"Katie\")\nelse:\n print(\"Draw\")\n\n\t\t \t \t\t \t \t\t\t\t \t \t\t \t",
"#!/usr/bin/python3\nimport sys\nfrom collections import Counter\ninput = lambda: sys.stdin.readline().strip()\n\ndef score(s, n):\n if n >= len(s):\n return len(s)\n elif n == 1 and all(c == s[0] for c in s):\n return len(s) - 1\n else:\n c = Counter(s)\n return min(len(s), n + max(c.values()))\n\nn = int(input())\ns = [score(input(), n), score(input(), n), score(input(), n)]\nif s.count(max(s)) == 1:\n print(['Kuro', 'Shiro', 'Katie'][s.index(max(s))])\nelse:\n print('Draw')",
"n=int(input())\r\ns1=input()\r\ns2=input()\r\ns3=input()\r\nk1=len(s1)\r\nk2=len(s2)\r\nk3=len(s3)\r\na=0\r\nval1=[0 for i in range(1000)]\r\nval2=[0 for i in range(1000)]\r\nval3=[0 for i in range(1000)]\r\nfor i in range(k1):\r\n val1[ord(s1[i])-ord('a')]+=1\r\nfor i in range(k2): \r\n val2[ord(s2[i])-ord('a')]+=1\r\nfor i in range(k3):\r\n val3[ord(s3[i])-ord('a')]+=1\r\n \r\nif n==1 :\r\n if max(val1)==k1:\r\n l1=k1-1\r\n else:\r\n l1=min(max(val1)+n,k1)\r\n if max(val2)==k2:\r\n l2=k2-1\r\n else:\r\n l2=min(max(val2)+n,k2)\r\n if max(val3)==k3:\r\n l3=k3-1\r\n else:\r\n l3=min(max(val3)+n,k3)\r\nelse:\r\n l1=min(max(val1)+n,k1)\r\n l2=min(max(val2)+n,k2)\r\n l3=min(max(val3)+n,k3)\r\nif l1>max(l2,l3):\r\n print(\"Kuro\")\r\nelif l2>max(l1,l3):\r\n print(\"Shiro\")\r\nelif l3>max(l1,l2):\r\n print(\"Katie\")\r\nelse:\r\n print(\"Draw\")",
"n = int(input())\np = input()\nq = input()\nr = input()\nma, mb, mc = 0, 0, 0\na, b, c = {}, {}, {}\nfor x in p:\n\ta[x] = 0\nfor x in q:\n\tb[x] = 0\nfor x in r:\n\tc[x] = 0\nfor x in p:\n\ta[x] += 1\n\tma = max(ma, a[x])\nfor x in q:\n\tb[x] += 1\n\tmb = max(mb, b[x])\nfor x in r:\n\tc[x] += 1\n\tmc = max(mc, c[x])\nif n == 1 and ma == len(p):\n\tp = p[:-1]\nif n == 1 and mb == len(q):\n\tq = q[:-1]\nif n == 1 and mc == len(r):\n\tr = r[:-1]\nma = min(ma + n, len(p))\nmb = min(mb + n, len(q))\nmc = min(mc + n, len(r))\n\nif ma > mb and ma > mc:\n\tprint(\"Kuro\")\nelif mb > ma and mb > mc:\n\tprint(\"Shiro\")\nelif mc > ma and mc > mb:\n\tprint(\"Katie\")\nelse:\n\tprint(\"Draw\")\n",
"n = int(input())\r\na = input()\r\nb = input()\r\nc = input()\r\naa = 26*[0]\r\nab = 26*[0]\r\nac = 26*[0]\r\nba = 26*[0]\r\nbb = 26*[0]\r\nbc = 26*[0]\r\nr = len(a)\r\nfor i in range(r):\r\n\tif 'a'<=a[i]<='z':\r\n\t\taa[ord(a[i])%97]+=1\r\n\telse:\r\n\t\tba[ord(a[i])%65]+=1\r\n\tif 'a'<=b[i]<='z':\r\n\t\tab[ord(b[i])%97]+=1\r\n\telse:\r\n\t\tbb[ord(b[i])%65]+=1\r\n\t\t\r\n\tif 'a'<=c[i]<='z':\r\n\t\tac[ord(c[i])%97]+=1\r\n\telse:\r\n\t\tbc[ord(c[i])%65]+=1\r\nmq = max(max(aa),max(ba))\r\nmw = max(max(ab),max(bb))\r\nme = max(max(ac),max(bc))\r\nq = min(n+mq,len(a)-1 if (n==1 and len(a)==mq) else len(a))\r\nw = min(n+mw,len(b)-1 if (n==1 and len(b)==mw) else len(b))\r\ne = min(n+me,len(c)-1 if (n==1 and len(c)==me) else len(c))\r\nt = 0\r\nk = max(q,w,e)\r\n#print(q,w,e)\r\nif q == k:\r\n\tt+=1\r\nif w == k:\r\n\tt+=1\r\nif e == k:\r\n\tt+=1\r\nif t > 1:\r\n\tprint('Draw')\r\nelse:\r\n\tif q == k:\r\n\t\tprint('Kuro')\r\n\telif w == k:\r\n\t\tprint('Shiro')\r\n\telse:\r\n\t\tprint('Katie')\r\n",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nx = [0] * 3\r\nfor i in range(3):\r\n s = list(input().rstrip())\r\n cnt = [0] * 130\r\n for j in s:\r\n cnt[j] += 1\r\n m = max(cnt)\r\n c = min(m + n, len(s))\r\n if m == len(s) and n == 1:\r\n c = m - 1\r\n x[i] = c\r\nma = max(x)\r\nans = []\r\nd = [\"Kuro\", \"Shiro\", \"Katie\"]\r\nfor i in range(3):\r\n if ma == x[i]:\r\n ans.append(d[i])\r\nif len(ans) ^ 1:\r\n ans = [\"Draw\"]\r\nans = ans[0]\r\nprint(ans)",
"from collections import Counter\r\n\r\ndef bt(x, n):\r\n v = max(Counter(x).values())\r\n if v == len(x) and n == 1:\r\n return v - 1\r\n else:\r\n return min( v + n, len(x) )\r\n \r\nn = int(input())\r\nd = [bt(input(), n) for _ in range(3)]\r\ndm = max(d)\r\nif Counter(d)[dm] > 1:\r\n print(\"Draw\")\r\nelse:\r\n print([\"Kuro\", \"Shiro\", \"Katie\"][d.index(dm)])",
"s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'\nn = int(input())\n \na = input()\nb = input()\nc = input()\n \nm = len(a)\n \nx = max(map(lambda r: a.count(r), s))\ny = max(map(lambda r: b.count(r), s))\nz = max(map(lambda r: c.count(r), s))\n \nif n == 1:\n if x == m: x -= 1\n else: x += 1\n if y == m: y -= 1\n else: y += 1\n if z == m: z -= 1\n else: z += 1\nelse:\n x = min(m, x+n)\n y = min(m, y+n)\n z = min(m, z+n)\n \nmx = max(x, y, z)\n \nif x == mx and y < mx and z < mx:\n print ('Kuro')\nelif x < mx and y == mx and z < mx:\n print ('Shiro')\nelif x < mx and y < mx and z == mx:\n print ('Katie')\nelse:\n print ('Draw')"
] | {"inputs": ["3\nKuroo\nShiro\nKatie", "7\ntreasurehunt\nthreefriends\nhiCodeforces", "1\nabcabc\ncbabac\nababca", "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "1\naaaaaaaaaa\nAAAAAAcAAA\nbbbbbbzzbb", "60\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ", "9174\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd", "727\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef", "61\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub", "30\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr", "3\nabcabcabcabcdddabc\nzxytzytxxtytxyzxyt\nfgffghfghffgghghhh", "3\naaaaa\naaaaa\naaaab", "3\naaaaaaa\naaaabcd\nabcdefg", "3\naaaaaaa\naaabcde\nabcdefg", "3\naaaaaaa\naaaabbb\nabcdefg", "3\naaa\nbbb\nabc", "3\naaaaa\nabcde\nabcde", "3\naaaaa\nqwert\nlkjhg", "3\naaaaa\nbbbbb\naabcd", "3\nabcde\nfghij\nkkkkk", "4\naaaabcd\naaaabcd\naaaaaaa", "3\naaaabb\naabcde\nabcdef", "2\naaab\nabcd\naaaa", "3\naaaaaa\naaaaaa\nabcdef", "1\nAAAAA\nBBBBB\nABCDE", "1\nabcde\naaaaa\naaaaa", "4\naaabbb\nabfcde\nabfcde", "0\naaa\naab\nccd", "3\naaaaa\naaaaa\naabbb", "3\nxxxxxx\nxxxooo\nabcdef", "2\noooo\naaac\nabcd", "1\naaaaaaa\naaabcde\nabcdefg", "3\nooooo\naaabb\nabcde", "3\naaaaa\nqwert\nqwery", "2\naaaaaa\nbbbbbb\naaaaab", "3\naabb\naabb\naabc", "2\naaa\naab\naab", "3\nbbbbcc\nbbbbbb\nsadfgh", "3\naaaaaacc\nxxxxkkkk\nxxxxkkkk", "2\naaaac\nbbbbc\nccccc", "3\naaaaaaaaa\naaabbbbbb\nabcdewert", "3\naaabc\naaaab\nabcde", "3\naaaaaaaa\naaaaaaab\naaaabbbb", "2\nabcdefg\nabccccc\nacccccc", "3\naaaaa\naabcd\nabcde", "4\naaabbb\nabcdef\nabcdef", "4\naaabbb\naabdef\nabcdef", "3\nabba\nbbbb\naaaa", "3\naaaaa\nbbaaa\nabcde", "2\naaa\naaa\nabc", "3\naaaaa\nabcda\nabcde", "3\naaaaa\nabcde\nbcdef", "3\naaabb\naabbc\nqwert", "3\naaaaaa\naabbcc\naabbcc", "3\nAAAAAA\nAAAAAB\nABCDEF", "3\nabc\naac\nbbb", "2\naaaab\naabbc\naabbc", "2\naaaaaab\naaaaabb\nabcdefg", "3\naaaaaaaaaaa\nbbbbbbbbaaa\nqwertyuiasd", "3\naaaa\nbbbb\naabb", "3\naaaabb\naaabcd\nabcdef", "3\naaa\nabc\nbbb", "1\naa\nab\nbb", "1\naacb\nabcd\naaaa", "3\naaaabb\naaabbb\nabcdef", "3\naaaa\naaaa\nabcd", "2\nabcd\nabcd\naaad", "3\naaa\nbbb\naab", "3\naaaaaa\naaaaab\naaaaaa", "2\naaab\nabcd\nabcd", "3\nooooo\nShiro\nKatie", "3\naaabb\naabcd\nabcde", "4\nabcd\nabcd\naaaa", "4\naaa\nbbb\naab", "2\nxxxx\nyyyx\nabcd", "3\nAAAAA\nAAAAB\nABCDE", "3\naaaacdc\naaaaabc\naaaaabc", "3\naaaaaa\naabcde\naabcde", "3\naaabb\naaabb\naaaaa", "5\nabbbbb\ncbbbbb\nabcdef", "3\naaaaaaaaa\naaaaabbbb\naaaaabbbb", "4\naaaaaab\naaabbbb\naaabbbb", "3\naaaabb\naaaabb\naaabbb", "2\naaaabb\naaaaab\nabcdef", "2\naaaaa\naaaae\nabcde", "3\naaaaaa\nbbbcde\nabcdef", "4\naaaabbb\naabcdef\naabcdef", "2\naaaaa\naaaab\nabcde", "3\naabbbbb\naaabbbb\nabcdefg", "3\nabcde\naabcd\naaaaa", "5\naaabbcc\nabcdefg\nabcdefg", "3\naabbb\nabcde\nabcde", "0\nbbb\nabb\nqer", "5\naabbbbb\naaaaaaa\nabcdefg", "2\naaaab\naaaab\naaabb", "2\naaaaaab\naaaabbb\naaaaccc", "3\naaaaaaaaaaaa\naaaaaaaaaaab\naaaaaabbbbbb", "3\naaabb\nabcde\naaaaa", "3\naaaaaac\naaaaebc\naaaaaac", "3\naaaaaa\naaabbb\nqwerty", "3\ncccca\nabcde\nabcde", "100005\nAA\nBC\nCC", "3\naaaa\nbbbb\nccca", "3\naaaaa\nbcdef\nbcdef", "2\naaab\naabb\nqwer", "3\nabcddd\nabcdef\nbbaaaa", "2\naaaa\naaaa\naabc", "3\naaaa\naaaa\naaab", "3\nabcddd\nabcdef\naaaaaa", "1\naaaa\nabcd\naaab"], "outputs": ["Kuro", "Shiro", "Katie", "Draw", "Shiro", "Draw", "Draw", "Draw", "Katie", "Draw", "Katie", "Draw", "Draw", "Kuro", "Draw", "Draw", "Kuro", "Kuro", "Draw", "Katie", "Draw", "Kuro", "Draw", "Draw", "Draw", "Draw", "Kuro", "Kuro", "Draw", "Draw", "Draw", "Kuro", "Draw", "Kuro", "Draw", "Draw", "Draw", "Draw", "Kuro", "Draw", "Draw", "Draw", "Draw", "Draw", "Draw", "Kuro", "Draw", "Draw", "Draw", "Draw", "Draw", "Kuro", "Draw", "Kuro", "Draw", "Draw", "Kuro", "Draw", "Draw", "Draw", "Draw", "Draw", "Shiro", "Draw", "Draw", "Draw", "Katie", "Draw", "Draw", "Kuro", "Kuro", "Draw", "Draw", "Draw", "Draw", "Draw", "Draw", "Kuro", "Draw", "Draw", "Kuro", "Draw", "Draw", "Draw", "Draw", "Draw", "Kuro", "Draw", "Draw", "Draw", "Kuro", "Kuro", "Kuro", "Draw", "Draw", "Kuro", "Draw", "Draw", "Draw", "Draw", "Kuro", "Draw", "Draw", "Kuro", "Draw", "Draw", "Draw", "Draw", "Draw", "Katie"]} | UNKNOWN | PYTHON3 | CODEFORCES | 23 | |
2b1d53828b5f8636bf0f7bf04797d798 | Queries on a String | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string *s* is abacaba and the query is *l*1<==<=3,<=*r*1<==<=6,<=*k*1<==<=1 then the answer is abbacaa. If after that we would process the query *l*2<==<=1,<=*r*2<==<=4,<=*k*2<==<=2 then we would get the string baabcaa.
The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|,<=1<=≤<=*k**i*<=≤<=1<=000<=000) — the description of the *i*-th query.
Print the resulting string *s* after processing all *m* queries.
Sample Input
abacaba
2
3 6 1
1 4 2
Sample Output
baabcaa
| [
"import sys\r\nimport math\r\ninput=sys.stdin.readline\r\nINF=int(1e9)+7\r\n\r\ndef solve(): # 123456\r\n s=input().rstrip()\r\n for _ in range(int(input())):\r\n l,r,k=map(int,input().split())\r\n l-=1\r\n r-=1\r\n length=r-l+1\r\n k%=length\r\n s=s[:l]+s[r-k+1:r+1]+s[l:r-k+1]+s[r+1:]\r\n print(s)\r\n \r\n \r\n\r\nt=1\r\nwhile t:\r\n t-=1\r\n solve()\r\n",
"import sys\r\nreadline=sys.stdin.readline\r\n\r\nS=list(readline().rstrip())\r\nM=int(readline())\r\nfor _ in range(M):\r\n l,r,k=map(int,readline().split())\r\n l-=1\r\n SS=S[l:r]\r\n k%=len(SS)\r\n SS=SS[len(SS)-k:]+SS[:len(SS)-k]\r\n S[l:r]=SS\r\nprint(*S,sep=\"\")",
"import sys\r\nimport bisect\r\nfrom bisect import bisect_left as lb\r\ninput_=lambda: sys.stdin.readline().strip(\"\\r\\n\")\r\nfrom math import log\r\nfrom math import gcd\r\nfrom random import randint\r\nsa=lambda :input_()\r\nsb=lambda:int(input_())\r\nsc=lambda:input_().split()\r\nsd=lambda:list(map(int,input_().split()))\r\nse=lambda:float(input_())\r\nsf=lambda:list(input_())\r\nflsh=lambda: sys.stdout.flush()\r\n#sys.setrecursionlimit(10**6)\r\nmod=10**9+7\r\ngp=[]\r\ncost=[]\r\ndp=[]\r\nmx=[]\r\nans1=[]\r\nans2=[]\r\nspecial=[]\r\nspecnode=[]\r\na=0\r\nkthpar=[]\r\ndef dfs(root,par):\r\n if par!=-1:\r\n dp[root]=dp[par]+1\r\n for i in range(1,20):\r\n if kthpar[root][i-1]!=-1:\r\n kthpar[root][i]=kthpar[kthpar[root][i-1]][i-1]\r\n for child in gp[root]:\r\n if child==par:continue\r\n kthpar[child][0]=root\r\n dfs(child,root)\r\ndef hnbhai():\r\n s=list(sa())\r\n for i in range(sb()):\r\n l,r,k=sd()\r\n l-=1\r\n r-=1\r\n k=(k%(r-l+1))\r\n s=s[:l]+s[r-k+1:r+1]+s[l:r-k+1]+s[r+1:]\r\n print(\"\".join(s))\r\nfor _ in range(1):\r\n hnbhai()\r\n",
"s = input()\r\nm = int(input())\r\nq = [list(map(int,input().split())) for i in range(m)]\r\n\r\na = [i for i in range(len(s))]\r\nfor i in range(m):\r\n l,r,k = q[i]\r\n l -= 1\r\n r -= 1\r\n k %= (r-l+1)\r\n ku = a[l:r+1]\r\n ku = ku[-k:] + ku[:-k]\r\n a = a[:l] + ku + a[r+1:]\r\n\r\nans = []\r\nfor i in a:\r\n ans.append(s[i])\r\n\r\nprint(\"\".join(ans))",
"def f(s,k):\r\n k = k%len(s)\r\n return s[len(s)-k:len(s)] + s[0:len(s)-k]\r\n\r\ns = str(input())\r\nm=int(input())\r\n\r\nfor i in range(m):\r\n l,r,k=map(int,input().split())\r\n length = r-l\r\n\r\n s = s[0:l-1] + f(s[l-1:r],k) + s[r:len(s)]\r\n\r\nprint(s)",
"s = input()\r\n\r\nm = int(input())\r\n\r\nfor _ in range(m):\r\n l, r, k = list(map(int, input().split()))\r\n \r\n sub = s[l-1:r]\r\n k = k % len(sub)\r\n new_pos = [(i + k) % len(sub) for i in range(len(sub))]\r\n #print('substring to change', sub)\r\n #print('new positions', new_pos)\r\n new_sub = ['' for i in range(len(sub))]\r\n \r\n for i in range(len(sub)):\r\n new_sub[new_pos[i]] = sub[i]\r\n\r\n s = s[:l-1] + ''.join(new_sub) + s[r:]\r\n #print('new string', s)\r\n\r\nprint(s)",
"if __name__ == '__main__':\r\n a = list(input())\r\n m = int(input())\r\n s = \"\"\r\n\r\n while m > 0:\r\n l, r, k = map(int, input().split())\r\n k %= (r - l + 1)\r\n a = a[:l - 1] + a[r - k:r] + a[l - 1:r - k] + a[r:]\r\n m -= 1\r\n print(\"\".join(a))",
"s = list(input())\r\nm = int(input())\r\nqry = [ list(map(int, input().split())) for i in range(m)]\r\n\r\nfor l,r,k in qry:\r\n l-=1\r\n k = (k)%((r-l))\r\n ms = s[l:r]\r\n p = len(ms)-k\r\n for i in range(l,r):\r\n s[i] = ms[(i-l+p)%len(ms)]\r\n \r\nprint(''.join(s))",
"def shift(s, l, r, k):\r\n buf = s[l:r]\r\n for i, buf_i in enumerate(buf):\r\n s[l+(i + k)%(r - l)] = buf_i\r\n\r\n\r\nif __name__ == \"__main__\":\r\n s = list(input())\r\n m = int(input())\r\n for _ in range(m):\r\n l, r, k = map(int, input().split())\r\n l -= 1 # make 0-based\r\n shift(s, l, r, k)\r\n print(\"\".join(s))\r\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ns = input()[:-1]\r\nfor _ in range(int(input())):\r\n a, b, c = map(int, input().split())\r\n x = b-a+1\r\n c %= x\r\n s = s[:a-1] + s[b-c:b] + s[a-1:b-c] + s[b:]\r\nprint(s)\r\n",
"\"\"\"\nYou are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[li... ri] ki times. The queries should be processed one after another in the order they are given.\n\nOne operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.\n\nFor example, if the string s is abacaba and the query is l1 = 3, r1 = 6, k1 = 1 then the answer is abbacaa. If after that we would process the query l2 = 1, r2 = 4, k2 = 2 then we would get the string baabcaa.\n\"\"\"\nfrom itertools import chain\nss = input()\nn = int(input())\nfor x in range(n):\n l, r, k = [int(y) for y in input().split()]\n k %= (r-l+1)\n l -= 1\n ss = ss[:l] + ss[r-k:r] + ss[l:r-k] + ss[r:]\nprint(ss)\n",
"s = input()\n\nqueries = [[int(x) for x in input().strip().split()] for _ in range(int(input()))]\n\nfor q in queries:\n l,r,k = q\n sub = s[l-1:r]\n k %= len(sub)\n sub = sub[-k:]+sub[0:-k]\n s = s[:l-1]+sub+s[r:]\n\nprint(s)\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ns = input().strip()\r\nm = int(input())\r\n\r\nfor _ in range(m):\r\n l, r, k = map(int, input().split())\r\n\r\n tmp = s[l-1:r]\r\n length = r-l + 1\r\n shift = k % length\r\n s = s[:l-1] + (tmp if shift == 0 else (tmp[-shift:] + tmp[:-shift])) + s[r:]\r\nprint(s)",
"s = list(input())\r\nt = int(input())\r\ndef shift(l, r, k):\r\n length = r-l\r\n k %= length\r\n s[l:r] = s[r-k:r]+s[l:r-k]\r\nfor _ in range(t):\r\n l, r, k = map(int, input().split())\r\n shift(l-1, r, k)\r\nprint(''.join(s))",
"s = input()\nm = int(input())\nfor _ in range(m):\n l,r,k = map(int,input().split())\n k = k%(r-l+1)\n s = s[:l-1]+s[r-k:r]+s[l-1:r-k]+s[r:]\nprint(s)\n \t\t\t\t\t \t \t \t\t \t\t \t \t \t",
"s = list(input())\r\nm = int(input())\r\n\r\nfor i in range(m):\r\n l, r, k = map(int, input().split())\r\n haba = r - l + 1\r\n k %= haba\r\n t = s[l - 1:r]\r\n for j in range(haba):\r\n s[j + l - 1] = t[(j - k) % haba]\r\n\r\nprint(\"\".join(s))",
"import sys\r\nimport collections\r\n\r\ninput = sys.stdin.readline\r\ns = input().strip()\r\nqueries = int(input().strip())\r\nfor query in range(queries):\r\n l, r, k = map(int, input().strip().split())\r\n l -= 1\r\n new_s = []\r\n old_s = []\r\n for i in range(l, r):\r\n new_s += [s[(i + k) % r]]\r\n old_s += [s[i]]\r\n for i in range(len(new_s)):\r\n new_s[(i + k) % len(new_s)] = old_s[i]\r\n # print(old_s, new_s)\r\n s = s[:l] + ''.join(new_s) + s[r:]\r\n\r\nprint(s)\r\n\r\n",
"#!/usr/bin/env python3\r\n\r\nimport math\r\nimport sys\r\nfrom collections import defaultdict, deque, Counter\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\ndef test_case():\r\n s = list(input())\r\n m = int(input())\r\n for _ in range(m):\r\n l, r, k = map(int, input().split())\r\n l -= 1\r\n r -= 1\r\n k %= (r-l+1)\r\n t = []\r\n for i in range(r-k+1, r+1): t.append(s[i])\r\n for i in range(l, r-k+1): t.append(s[i])\r\n for i in range(l, r+1): s[i] = t[i-l]\r\n print(''.join(s))\r\n\r\ndef main():\r\n t = 1\r\n# t = int(input())\r\n for _ in range(t):\r\n test_case()\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"temp = [0] * 10000\r\n\r\n\r\ndef shift_cycle(a, left, right, k):\r\n start = left + (k % (right - left + 1))\r\n for i in range(left, right + 1):\r\n temp[start] = a[i]\r\n start = left + ((start - left + 1) % (right - left + 1))\r\n for i in range(left, right + 1):\r\n a[i] = temp[i]\r\n\r\n\r\ns = list(input())\r\nm = int(input())\r\nfor i in range(m):\r\n l, r, k = map(int, input().split())\r\n shift_cycle(s, l-1, r-1, k)\r\nprint(\"\".join(s))\r\n",
"s = list(input())\r\nm = int(input())\r\nfor _ in range(m):\r\n l, r, k = [int(x) for x in input().split()]\r\n l -= 1\r\n n = r - l\r\n k = k % n\r\n new_sub = [0] * n\r\n for j in range(0, n):\r\n old = s[j + l]\r\n new_sub[(j + k) % n] = old\r\n s[l:r] = new_sub\r\nprint(\"\".join(s))",
"s=input()\r\nn=int(input())\r\n\r\ndef shift_string(string, k):\r\n if not string:\r\n return string\r\n k %= len(string)\r\n shifted_string = string[-k:] + string[:-k]\r\n return shifted_string\r\n\r\nfor i in range(n):\r\n l,r,k=map(int,input().split())\r\n s=s[:l-1:]+shift_string(s[l-1:r:],k)+s[r::]\r\nprint(s)",
"from collections import *\r\nfrom itertools import *\r\nfrom functools import *\r\nfrom heapq import *\r\nimport sys,math\r\ninput = sys.stdin.readline\r\n\r\nS = list(input())[:-1]\r\nM = int(input())\r\n\r\nfor _ in range(M):\r\n l,r,k = map(int,input().split())\r\n l -= 1\r\n S[l:r] = [S[(i-k)%(r-l)+l] for i in range(r-l)]\r\nprint(''.join(S))",
"s = input()\r\nm = int(input())\r\n\r\nfor _ in range(m):\r\n l,r,k = map(int, input().split())\r\n l -= 1\r\n r -= 1\r\n k %= (r-l+1)\r\n left = s[:l]\r\n right = s[r+1:]\r\n middle = s[l:r+1]\r\n middle = middle[-k:] + middle[:-k]\r\n s = left + middle + right\r\nprint(s)",
"a=input()\r\ns=''\r\n\r\nt=int(input())\r\nfor tests in range(t):\r\n l,r,k=map(int,input().split())\r\n s=a[l-1:r]\r\n n=len(s)\r\n k=k%n\r\n s=s[n-k:]+s[:n-k]\r\n a=a[:l-1]+s+a[r:]\r\nprint(a)",
"from collections import deque\r\na=list(input())\r\na=[0]+a\r\nfor _ in range(int(input())):\r\n l,r,k=map(int,input().split())\r\n k=k%(r-l+1)\r\n if(k==0):\r\n continue\r\n b=deque(a[l:r+1])\r\n b.rotate(k)\r\n a=a[:l]+list(b)+a[r+1:]\r\nprint(''.join(a[1:]))",
"s = input()\r\nfor i in range(int(input())):\r\n l, r, k = map(int, input().split())\r\n a = s[l-1:r]\r\n ln = len(a)\r\n k = k % ln\r\n\r\n s = s[:l-1] + a[-k:] + a[:-k] + s[r:]\r\n\r\nprint(s)\r\n \r\n",
"import sys\r\n#read = lambda: sys.stdin.buffer.read().rstrip()\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n#readlines = lambda: sys.stdin.buffer.readlines().rstrip()\r\nsys.setrecursionlimit(10**5)\r\n\r\ndef rolling(str , n):\r\n t = [\"\"]*len(str)\r\n for i in range(len(str)):\r\n t[i] = str[i-n%len(str)]\r\n\r\n return t\r\n \r\ndef solve():\r\n S = list(input())\r\n N = int(input())\r\n \r\n for _ in range(N):\r\n l,r,k = map(int, input().split())\r\n \r\n t = rolling(S[l-1:r],k)\r\n S[l-1:r] = t\r\n print(\"\".join(S))\r\n \r\nsolve()",
"S=list(input())\r\nN=int(input())\r\nfor i in range(N):\r\n a,b,s=map(int, input().split())\r\n a-=1\r\n #print(S[:a],S[a:b],S[b:])\r\n T=S[a:b]\r\n t=len(T)\r\n s%=t \r\n #print(T[-s:],T[:-s])\r\n S=S[:a]+T[-s:]+T[:-s]+S[b:]\r\nprint(''.join(S))",
"s = input()\r\nt = int(input())\r\nn = len(s)\r\npos = list(range(n))\r\n\r\nfor _ in range(t):\r\n l,r,k = map(int,input().split())\r\n l = l-1\r\n r = r-1\r\n k = k%(r-l+1)\r\n if k>0:\r\n# print(s[:l])\r\n# print(s[r-k+1:r+1])\r\n# print(s[l:r-k+1] )\r\n# print(s[r+1:])\r\n s = s[:l] + s[r-k+1:r+1]+ s[l:r-k+1] + s[r+1:]\r\n \r\nprint(s) \r\n",
"# Bismillahir Rahmanir Rahim\r\n# Abu Hurayra - Handle: HurayraIIT\r\nimport sys\r\nimport math\r\ndef mp(): return map(int, sys.stdin.readline().split())\r\ndef rs(): return sys.stdin.readline().rstrip()\r\ndef ri(): return int(sys.stdin.readline())\r\ndef ria(): return list(map(int, sys.stdin.readline().split()))\r\ndef ws(s): sys.stdout.write(s + '\\n')\r\ndef wi(n): sys.stdout.write(str(n) + '\\n')\r\ndef wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\\n')\r\n#a = list(map(int, input().split()))\r\n \r\ndef Process(s, k):\r\n a = \"\"\r\n p = k % len(s)\r\n return s[len(s)-p:] + s[:len(s)-p]\r\n \r\ndef main():\r\n s = input()\r\n m = ri()\r\n for _ in range(m):\r\n l, r, k = mp()\r\n # print(l, r, k, s[l-1:r:1])\r\n a = s[l-1:r]\r\n b = Process(a, k)\r\n c = s[0:l-1] + b + s[r:]\r\n # print(s[0:l-1] , b , s[r:])\r\n s = c\r\n # print(s)\r\n ws(s)\r\n\r\n\r\n \r\n \r\nif __name__ == '__main__':\r\n t = 1\r\n while t:\r\n t -= 1\r\n main()\r\n",
"from sys import *\n\ndef applyPerm(sequence, permutation):\n\tnewSequence = sequence[::1]\n\tfor i in range(len(sequence)):\n\t\tnewSequence[i] = sequence[permutation[i]]\n\treturn newSequence\n\ndef solve(s: str, l: int, r: int, k: int):\n\n\tsequence = list(s)\n\tN = len(s)\n\tpermutation = [i for i in range(N)]\n\trevPart = [i for i in range(l - 1, r)]\n\trevPart = [revPart[-1]] + revPart[:-1]\n\tfor ctr, index in enumerate(range(l - 1, r)):\n\t\tpermutation[index] = revPart[ctr]\n\n\twhile k:\n\t\tif k & 1:\n\t\t\tsequence = applyPerm(sequence, permutation)\n\t\tpermutation = applyPerm(permutation, permutation)\n\t\tk >>= 1\n\n\treturn ''.join(sequence)\n\ndef main():\n\ts = stdin.readline().strip()\n\tm = int(stdin.readline().strip())\n\n\tfor _ in range(m):\n\t\tl, r, k = map(int, stdin.readline().strip().split())\n\t\ts = solve(s, l, r, k)\n\n\tstdout.write(f\"{s}\\n\")\n\nif __name__ == \"__main__\":\n\tmain()",
"R = lambda f=str: map(f, input().split())\n\ndef cyclically_shift(string: str, __k: int) -> str:\n rest = -(__k % len(string))\n return string[rest:] + string[:rest]\n\ns, = R()\nm, = R(int)\n\nfor _ in range(m):\n l, r, k, = R(int)\n s = s[:l - 1] + cyclically_shift(s[l - 1:r], k) + s[r:]\n\nprint(s)\n",
"s = input()\nfor _ in range(int(input())):\n l, r, k = map(int, input().split())\n sub = s[l-1:r]\n m = k % len(sub)\n c = sub[len(sub)-m:] + sub[:len(sub)-m]\n s = s[:l-1] + c + s[r:]\n #print(sub, m, c, s)\nprint(s)",
"s=input()\r\nfor _ in range(int(input())):\r\n l,r,k=map(int,input().split())\r\n k%=r-l+1\r\n l-=1\r\n a = s[:l]\r\n b = s[l:r - k]\r\n c = s[r - k:r]\r\n d = s[r:]\r\n s=a+c+b+d\r\nprint(s)",
"# Online Python compiler to run Python online.\n# Write Python code in this online editor and run it.\n\nR=input\ns=R()\nfor _ in '1'*int(R()):l,r,k=map(int,R().split());l-=1;a=s[l:r];k%=len(a);s=s[:l]+a[-k:]+a[:-k]+s[r:]\nprint(s)\n\t \t\t \t\t\t\t\t \t \t\t \t\t\t\t\t \t\t\t\t",
"import sys\r\nfrom os import path\r\nif path.exists('input.txt'):\r\n sys.stdin=open('input.txt','r')\r\n sys.stdout=open('output.txt','w')\r\n\r\n\r\ns = input()\r\nfor _ in range( int(input()) ):\r\n l, r, k = map( int, input().split() )\r\n l -= 1; r -= 1\r\n k %= r - l + 1\r\n s = s[ : l] + s[r - k + 1 : r + 1] + s[l : r - k + 1] + s[r + 1 : ]\r\nprint(s)\r\n",
"s = input()\nm = int(input())\nfor it in range(m):\n\tl, r, k = [int(i) for i in input().split()]\n\tl -= 1\n\tk = k % (r - l)\n\ts = s[:l] + s[r - k: r] + s[l: r - k] + s[r:]\nprint(s)\n\t\t \t \t\t\t \t\t\t\t\t \t\t \t",
"# aaaa abcd bbbb, l = 5, r = 8, k = 2\n# return \n\ns = input()\nt = int(input())\n\nfor i in range(t):\n vals = list(map(int, input().split(\" \")))\n\n l = vals[0]\n r = vals[1]\n k = vals[2]\n\n k %= (r - l + 1)\n prefix = s[0 : l-1]\n rotated_front = s[r-k : r]\n rotated_back = s[l-1 : r-k]\n suffix = s[r:]\n s = prefix + rotated_front + rotated_back + suffix\nprint(s)\n ",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\n# ----------------------- #\r\n\r\ns = list(input())\r\nq = int(input())\r\nfor _ in range(q):\r\n l, r, k = map(int, input().split())\r\n l -= 1\r\n length = r - l\r\n k %= length\r\n s[l:r] = s[r-k:r] + s[l:r-k]\r\nprint(''.join(s))\r\n",
"def modify(s, l, r, k):\r\n s_old = s[l-1: r]\r\n s_list = [char for char in s[l-1 : r]]\r\n length = len(s_list)\r\n\r\n for i in range(length):\r\n s_list[i] = s_old[(i + length - k) % length]\r\n\r\n \r\n s_new = s[ : l-1] + ''.join([char for char in s_list]) + s[r : ]\r\n \r\n return s_new\r\n\r\nif __name__ == '__main__':\r\n s = input()\r\n m = int(input())\r\n\r\n while m :\r\n l, r, k = list(map(int, input().split()))\r\n s = modify(s, l, r, k)\r\n m -= 1\r\n\r\n print(s)\r\n",
"s = input()\r\nt = int(input())\r\nfor _ in range(t):\r\n L = [int(x) for x in input().split()]\r\n l = L[0]\r\n r = L[1]\r\n k = L[2]\r\n s1 = s[l-1:r]\r\n s2 = s1[::-1]\r\n s2 = s2[:(k%(r-l+1))][::-1]\r\n s1 = s1[:r-l-(k%(r-l+1))+1]\r\n s1 = s2+s1\r\n s = s[:l-1]+s1+s[r:]\r\nprint(s)\r\n",
"def main():\r\n arr = [character for character in input()]\r\n\r\n for _ in range(int(input())):\r\n l, r, k = map(int, input().split())\r\n\r\n temp_arr1 = [arr[i] for i in range(l - 1, r)]\r\n temp_arr2 = [0 for _ in range(r - l + 1)]\r\n\r\n for i in range(r - l + 1):\r\n temp_arr2[(i + k) % (r - l + 1)] = temp_arr1[i]\r\n\r\n for i in range(l - 1, r):\r\n arr[i] = temp_arr2[i - l + 1]\r\n\r\n print(\"\".join(arr))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"R=input\r\ns=R()\r\nfor _ in '1'*int(R()):l,r,k=map(int,R().split());l-=1;a=s[l:r];k%=len(a);s=s[:l]+a[-k:]+a[:-k]+s[r:]\r\nprint(s)\r\n",
"s=input()\nfor _ in range(int(input())):\n l,r,k=map(int,input().split())\n n=r-l+1\n k=k%n\n s=s[:l-1]+s[r-k:r]+s[l-1:r-k]+s[r:]\nprint(s)\n\t\t \t \t\t \t \t \t \t\t\t \t",
"\ndef shift(l,r,k,s):\n len = r-l+1\n shift = k%len\n end = r-shift+1\n out = s[:l]+s[end:r+1]+s[l:end]+s[r+1:]\n return out\ns = input()\nm = int(input())\nfor _ in range(m):\n l,r,k = tuple(map(int,input().split()))\n s = shift(l-1,r-1,k,s)\n\nprint(s)\n",
"if __name__ == '__main__':\n s = list(input())\n t = int(input())\n for i in range(t):\n l, r, k = map(int, input().split())\n k = k % (r - l + 1)\n temp = s[l-1: r][-k:] + s[l-1: r][:-k]\n for j in range(r - l + 1):\n s[l - 1 + j] = temp[j]\n print(''.join(s))\n\n \t \t\t \t \t \t \t \t\t\t\t \t \t\t",
"def readints():\n return list(map(int, input().split()))\n\ndef unlimit(s=550000):\n import sys\n sys.setrecursionlimit(s)\n\ndef main():\n s = list(input())\n m = int(input())\n for _ in range(m):\n l, r, k = readints()\n l -= 1\n t = s[l:r]\n for j in range(l, r):\n s[j] = t[(j - l - k) % (r - l)]\n print(''.join(s))\n\n\nif __name__ == '__main__':\n # unlimit()\n main()\n",
"s = list(input())\r\nm = int(input())\r\n\r\nfor i in range(m):\r\n l,r,k = map(int, input().split())\r\n l -= 1\r\n r -= 1\r\n tmp = s[:l]\r\n k %= (r-l+1)\r\n\r\n x = s[l:r+1]\r\n for j in range(-k,(r-l+1)-k):\r\n tmp.append(x[j])\r\n\r\n tmp += s[r+1:]\r\n s = tmp\r\n\r\nprint(\"\".join(s))\r\n\r\n",
"s = input()\r\nm = int(input())\r\nfor i in range(m):\r\n l, r, k = map(int, input().split())\r\n k %= (r-l+1)\r\n s = s[:l-1] + s[r-k:r] + s[l-1:r-k] + s[r:]\r\nprint(s)\r\n\n# Sun Jan 15 2023 21:41:03 GMT+0300 (Moscow Standard Time)\n",
"def main():\r\n from sys import stdin, setrecursionlimit\r\n # setrecursionlimit(1000000)\r\n input = stdin.readline\r\n def iinput(): return int(input())\r\n def sinput(): return input().rstrip()\r\n def i0input(): return int(input()) - 1\r\n def linput(): return list(input().split())\r\n def liinput(): return list(map(int, input().split()))\r\n def miinput(): return map(int, input().split())\r\n def li0input(): return list(map(lambda x: int(x) - 1, input().split()))\r\n def mi0input(): return map(lambda x: int(x) - 1, input().split())\r\n INF = 1000000000000000000\r\n MOD = 1000000007\r\n\r\n S = sinput()\r\n M = iinput()\r\n idx = [i for i in range(len(S))]\r\n for _ in [0] * M:\r\n L, R, M = miinput()\r\n L -= 1\r\n R -= 1\r\n length = R - L + 1\r\n M %= length\r\n for i, j in enumerate(idx):\r\n if L <= j <= R:\r\n idx[i] = L + (j - L + M) % length \r\n\r\n ans = [None] * len(S)\r\n for i, j in enumerate(idx):\r\n ans[j] = S[i]\r\n print(''.join(ans))\r\n\r\nmain()",
"s=input()\r\nfor _ in range(int(input())):\r\n l,r,k=map(int,input().split())\r\n n=r-l+1\r\n k=k%n\r\n # out of range + in range from end + in range from start + out of range\r\n s=s[:l-1]+s[r-k:r]+s[l-1:r-k]+s[r:]\r\nprint(s)",
"s = list(input())\r\nm = int(input())\r\nfor _ in range(m):\r\n l,r,k = map(int,input().split())\r\n l -= 1\r\n buf = s[l:r]\r\n k = k % len(buf)\r\n for i in range(len(buf) - k):\r\n s[l + k + i] = buf[i]\r\n e = i + 1\r\n for i in range(e,e + k):\r\n s[l + i - e] = buf[i]\r\nfor e in s:\r\n print(f\"{e}\",end = '')",
"s = input()\r\nm = int(input())\r\nfor _ in range(m):\r\n l, r, k = tuple(map(int, input().split()))\r\n l = l-1\r\n r = r-1\r\n\r\n k0 = k % (r-l+1)\r\n# slow\r\n# for _ in range(k0):\r\n# ss = s[l:r]\r\n# s[l] = s[r]\r\n# s[l+1:r+1] = ss\r\n# print(''.join(s))\r\n# print([(i,k) for i,k in enumerate(list(s))])\r\n# print(k0, s[:l], s[r+1-k0:r+1], s[l:r+1-k0], s[r+1:])\r\n s = s[:l] + s[r+1-k0:r+1] + s[l:r+1-k0] + s[r+1:]\r\nprint(s)",
"def reverse(s, l, r):\r\n while l < r:\r\n s[l], s[r] = s[r], s[l]\r\n l += 1\r\n r -= 1\r\n\r\ndef shift(s, l, r, k):\r\n k %= (r - l + 1)\r\n\r\n reverse(s, l, r)\r\n reverse(s, l, l + k - 1)\r\n reverse(s, l+k, r)\r\n\r\ns = list(input().strip())\r\nfor _ in range(int(input())):\r\n l, r, k = map(int, input().split())\r\n\r\n shift(s, l-1, r-1, k)\r\n\r\nprint(\"\".join(s))\r\n",
"s = input()\r\nfor q in range(int(input())):\r\n l, r, k = map(int, input().split())\r\n l -= 1\r\n k %= r - l\r\n s = s[: l] + s[r - k: r] + s[l: r - k] + s[r:]\r\nprint(s)",
"if __name__ == '__main__':\n s = input()\n t = int(input())\n for i in range(t):\n l, r, k = map(int, input().split())\n k = k % (r - l + 1)\n s = s[: l - 1] + s[l - 1: r][-k:] + s[l - 1: r][:-k] + s[r:]\n print(s)\n\n\t \t\t\t\t\t\t\t\t \t\t\t \t \t \t\t\t\t \t\t",
"from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\ns=list(input())\r\nm=int(input())\r\nfor _ in range(m):\r\n l,r,k=map(int,input().split())\r\n l,r=l-1,r-1\r\n d=(r-l+1)\r\n t=s[::]\r\n for i in range(d):\r\n t[l+(k+i)%d]=s[l+i]\r\n s=t[::]\r\n\r\nprint(''.join(s))",
"a = list(input())\r\nn = int(input())\r\nfor _ in range(n):\r\n l,r,k = list(map(int,input().split()))\r\n f = k%(r-l+1)\r\n a[l-1:r] = a[l-1:r][-f:] + a[l-1:r][:-f]\r\n\r\nprint(\"\".join(a))",
"s = [a for a in input()]\r\n\r\nfor _ in range(int(input())):\r\n i, j, k = [int(x) for x in input().split()]\r\n\r\n sub = s[i-1: j]\r\n\r\n for a in range(j-i+1):\r\n sub[(a + k) % (j-i+1)] = s[i-1+a]\r\n\r\n s = s[:i-1] + sub + s[j:]\r\n\r\nprint(\"\".join(s))",
"import os,sys,math\r\nfrom io import BytesIO,IOBase\r\nBUFSIZ=8192\r\nclass FastIO(IOBase):\r\n newlines=0\r\n def __init__(self,file):\r\n self._fd=file.fileno()\r\n self.buffer=BytesIO()\r\n self.writable=\"n\"in file.mode or \"r\" not in file.mode\r\n self.write=self.buffer.write if self.writable else None\r\n def read(self):\r\n while True: \r\n b=os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZ))\r\n if not b:\r\n break\r\n ptr=self.buffer.tell()\r\n self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)\r\n self.newlines=0\r\n return self.buffer.read()\r\n def readline(self):\r\n while self.newlines==0:\r\n b=os.read(self._fd,max(os.fstat(self._fd).st_size, BUFSIZ))\r\n self.newlines=b.count(b\"\\n\")+(not b)\r\n ptr=self.buffer.tell()\r\n self.buffer.seek(0, 2),self.buffer.write(b),self.buffer.seek(ptr)\r\n self.newlines-=1\r\n return self.buffer.readline()\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd,self.buffer.getvalue())\r\n self.buffer.truncate(0),self.buffer.seek(0)\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer=FastIO(file)\r\n self.flush=self.buffer.flush\r\n self.writable=self.buffer.writable\r\n self.write=lambda s:self.buffer.write(s.encode(\"ascii\"))\r\n self.rexad=lambda:self.buffer.read().decode(\"ascii\")\r\n self.readline=lambda:self.buffer.readline().decode(\"ascii\")\r\nif sys.version_info[0]<3:\r\n sys.stdin,sys.stdout=FastIO(sys.stdin),FastIO(sys.stdout)\r\nelse:\r\n sys.stdin,sys.stdout=IOWrapper(sys.stdin),IOWrapper(sys.stdout)\r\ninput=lambda:sys.stdin.readline().rstrip(\"\\r\\n\")\r\ndef divisors(n):\r\n d=dict()\r\n num=n\r\n c=0\r\n while num%2==0:\r\n c+=1\r\n num=num//2\r\n d[2]=c\r\n for i in range(3,int(math.sqrt(n))+1,2):\r\n c=0\r\n while num%i==0:\r\n c+=1\r\n num=num//i \r\n d[i]=c\r\n if num>2:\r\n d[num]=1\r\n return d\r\ndef I():\r\n return map(int,input().split())\r\ns=list(input())\r\nn=int(input())\r\nl=len(s)\r\narr=[]\r\nfor i in range(n):\r\n arr.append(list(I()))\r\nfor i in range(n):\r\n arr[i][1]-=1\r\n arr[i][0]-=1\r\n \r\n \r\n x=arr[i][1]-arr[i][0]+1\r\n y=arr[i][2]%x\r\n a1=s[arr[i][0]+x-y:arr[i][1]+1]+s[arr[i][0]:arr[i][0]+x-y]\r\n s[arr[i][0]:arr[i][1]+1]=a1\r\nprint(\"\".join(s))\r\n \r\n \r\n \r\n \r\n ",
"s = list(input())\r\nfor i in range(int(input())):\r\n l, r, k = map(int, input().split())\r\n l -= 1\r\n r -= 1\r\n temp = k % (r - l + 1)\r\n # print(\"\".join(s))\r\n if temp != 0:\r\n s[l:l + temp], s[l + temp:r + 1] = s[r - temp + 1:r + 1], s[l:r - temp+1]\r\nprint(\"\".join(s))\r\n"
] | {"inputs": ["abacaba\n2\n3 6 1\n1 4 2", "u\n1\n1 1 1", "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4", "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6", "tcpyzttcpo\n10\n2 3 6\n2 4 1\n2 6 9\n7 10 5\n2 3 5\n4 5 6\n3 4 5\n7 9 4\n9 10 7\n1 10 8", "yywlblbblw\n10\n4 7 2\n3 8 2\n4 10 6\n4 7 1\n3 9 6\n1 7 3\n3 7 3\n3 7 1\n1 8 7\n2 7 5", "thisisahacktest\n1\n1 2 1", "ozozumuhackleyan\n1\n1 4 1", "lacongaithattuyet\n1\n1 1 1"], "outputs": ["baabcaa", "u", "p", "ssssssssss", "zctycopttp", "bylwlwylbb", "htisisahacktest", "zozoumuhackleyan", "lacongaithattuyet"]} | UNKNOWN | PYTHON3 | CODEFORCES | 61 | |
2b29fa76601c100b41a167c1605ef5fb | SMSC | Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC.
For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In the end, Polycarpus got a list of *n* tasks that went to the SMSC of the corporation. Each task was described by the time it was received by the SMSC and the number of text messages to send. More formally, the *i*-th task was described by two integers *t**i* and *c**i* — the receiving time (the second) and the number of the text messages, correspondingly.
Polycarpus knows that the SMSC cannot send more than one text message per second. The SMSC uses a queue to organize its work. Consider a time moment *x*, the SMSC work at that moment as follows:
1. If at the time moment *x* the queue is not empty, then SMSC sends one message from the queue (SMSC gets the message from the head of the queue). Otherwise it doesn't send messages at the time moment *x*. 1. If at the time moment *x* SMSC receives a task, then it adds to the queue all the messages from this task (SMSC adds messages to the tail of the queue). Note, that the messages from the task cannot be send at time moment *x*. That's because the decision about sending message or not is made at point 1 before adding these messages to the queue.
Given the information about all *n* tasks, Polycarpus wants to count two values: the time when the last text message was sent and the maximum size of the queue at some time. Help him count these two characteristics he needs to evaluate the efficiency of the SMSC.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103) — the number of tasks of the SMSC. Next *n* lines contain the tasks' descriptions: the *i*-th line contains two space-separated integers *t**i* and *c**i* (1<=≤<=*t**i*,<=*c**i*<=≤<=106) — the time (the second) when the *i*-th task was received and the number of messages to send, correspondingly.
It is guaranteed that all tasks were received at different moments of time. It is guaranteed that the tasks are sorted in the chronological order, that is, *t**i*<=<<=*t**i*<=+<=1 for all integer *i* (1<=≤<=*i*<=<<=*n*).
In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
Sample Input
2
1 1
2 1
1
1000000 10
3
3 3
4 3
5 3
Sample Output
3 1
1000010 10
12 7
| [
"import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\nn=int(input())\r\nl=[]\r\nfor i in range(n):\r\n t,c=(int(i) for i in input().split())\r\n l.append([t,c])\r\nt1=-1\r\nk=0\r\nm=0\r\ns=0\r\nfor i in range(1000002):\r\n m=max(m,s)\r\n if(k==n):\r\n t1=i-1\r\n break\r\n s=max(s-1,0)\r\n if(i==l[k][0]):\r\n s+=l[k][1]\r\n k+=1\r\nm=max(m,s)\r\nprint(t1+s,m)",
"n = eval(input())\r\ncnt = 0\r\nlt = 0\r\nmn = 0\r\nfor i in range(n):\r\n t, c = input().split()\r\n t, c = int(t), int(c)\r\n cnt -= t - lt\r\n lt = t\r\n if cnt < 0:\r\n cnt = 0\r\n cnt += c\r\n if cnt > mn:\r\n mn = cnt\r\nprint(cnt + t, mn)\r\n",
"if __name__ == '__main__':\r\n n = int(input())\r\n a = [[int(i) for i in input().split()] for _ in range(n)]\r\n mx, cnt = a[0][1], a[0][1]\r\n\r\n for i in range(1, n):\r\n t = a[i][0] - a[i - 1][0]\r\n cnt -= t\r\n if cnt <= 0:cnt = 0\r\n cnt += a[i][1]\r\n mx = max(mx, cnt)\r\n print(cnt + a[n - 1][0], mx)",
"max_q = q = 0\r\nt0 = 0\r\n\r\nfor _ in range(int(input())):\r\n t, c = map(int, input().split())\r\n q = max(0, t0-t+q) + c\r\n max_q = max(q, max_q)\r\n t0 = t\r\n\r\nprint(t+q, max_q)",
"pt, s, vs = 0, 0, 0\r\nfor i in range(int(input())):\r\n t, c = map(int, input().split())\r\n s = max(s - (t - pt), 0) + c\r\n vs = max(vs, s)\r\n pt = t\r\nprint(pt + s, vs)",
"Messages, Max, Last = 0, 0, 0\r\nfor i in range(int(input())):\r\n X = list(map(int, input().split()))\r\n Messages = max(0, Messages - (X[0] - Last))\r\n Messages += X[1]\r\n Max = max(Messages, Max)\r\n Last = X[0]\r\nprint(Last + Messages, Max)\r\n\r\n# UB_CodeForces\r\n# Advice: Falling down is an accident, staying down is a choice\r\n# Location: Mashhad for few days\r\n# Caption: Finally happened what should be happened\r\n# CodeNumber: 692\r\n",
"n = int(input())\r\n\r\nque = []\r\n\r\nfor i in range(n):\r\n t, c = map(int, input().split())\r\n que += [[t, c]]\r\n\r\n\r\nnumMessages = None\r\nlasReceive = None\r\n\r\nmaxQ, end = None, None\r\nfor i, q in enumerate(que):\r\n if numMessages == None:\r\n numMessages = q[1]\r\n lasReceive = q[0]\r\n maxQ = numMessages\r\n \r\n else:\r\n numMessages = max(numMessages - (q[0] - lasReceive), 0) + q[1]\r\n\r\n lasReceive = q[0]\r\n maxQ = max(maxQ, numMessages)\r\n if i == n - 1:\r\n print(lasReceive + numMessages, end=' ')\r\n print(maxQ, end=' ')\r\n \r\n \r\n ",
"n = int(input())\r\narr = []\r\nfor _ in range(n):\r\n arr.append([int(i) for i in input().split()])\r\narr.sort(key=lambda x: x[0])\r\nqueue_size = 0\r\ntime = 0\r\nmax_queue_size = 0\r\nlast_time = 0\r\nfor t, c in arr:\r\n # print(\"Queue:\", queue_size, \"Time:\", time)\r\n sent = t - last_time\r\n queue_size = max(0, queue_size - sent)\r\n queue_size += c\r\n time = t\r\n max_queue_size = max(max_queue_size, queue_size)\r\n last_time = time\r\nprint(time + queue_size, max_queue_size)",
"n = int(input())\r\n\r\nmt = 0\r\nmq = 0\r\n\r\nt = 0\r\nq = 0\r\n\r\nfor i in range(n):\r\n (ti, ci) = map(int, input().split())\r\n q = max(0, q-ti+t)\r\n t = ti\r\n q += ci\r\n mq = max(mq, q)\r\n mt = t+q\r\n\r\nprint(mt, mq)\r\n",
"\"\"\"\nhttps://codeforces.com/problemset/problem/292/A\n\"\"\"\nnumberoftasks = int(input())\ntaches = []\nmaxqueue = 0\nfor _ in range(numberoftasks):\n time, number = [int(x) for x in input().split()]\n taches.append([time, number])\ntemps_total = taches[0][0]\nqueue = taches[0][1]\nmaxqueue = queue\nfor (t, a) in taches[1:]:\n while temps_total < t:\n if queue:\n queue -= 1\n temps_total += 1\n queue += a\n if queue > maxqueue:\n maxqueue = queue\nif queue:\n temps_total += queue\n queue = 0\nprint(temps_total, maxqueue)\n",
"import math\r\n\r\nn = int(input())\r\n\r\nq = 0\r\ntime = 0\r\n\r\nhigh = 0\r\nfor _ in range(n):\r\n\trecv, count = map(int, input().split())\r\n\r\n\tif q > 0:\r\n\t\tq = max( q - (recv-time), 0)\r\n\r\n\r\n\tq += count\r\n\thigh = max(high, q)\r\n\ttime = recv\r\n\r\nprint(time+q,high)\r\n",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\n\\r\")\r\n\r\ndef solve():\r\n n = int(input()) \r\n a = [list(map(int, input().split())) for i in range(n)]\r\n curr = top = a[0][1]\r\n \r\n for i in range(1, n):\r\n dist = a[i][0] - a[i - 1][0]\r\n curr = max(0, curr - dist)\r\n curr += a[i][1]\r\n top = max(curr, top)\r\n \r\n time = a[-1][0] + curr\r\n \r\n print(time, top)\r\n\r\nfor _ in range(1):\r\n solve()\r\n\r\n ",
"n = int(input())\r\n\r\nt, c = [], []\r\n\r\nfor i in range(n):\r\n\tx, y = map(int, input().split())\r\n\t\r\n\tt.append(x)\r\n\tc.append(y)\r\n\t\r\ni, s, m = 0, 0, 0\r\n\t\r\nwhile len(t) > 0:\r\n\ti += 1\r\n\t\r\n\tif s != 0:\r\n\t\ts -= 1\r\n\t\t\r\n\tif i == t[0]:\r\n\t\ts += c[0]\r\n\t\t\r\n\t\tt.pop(0)\r\n\t\tc.pop(0)\r\n\t\t\r\n\tif s > m:\r\n\t\tm = s\r\n\t\t\r\nprint(i + s, m)",
"n = int(input())\na1,a2 = 0,0\nr = 0\nfor _ in range(n):\n b1,b2 = map(int,input().split())\n a2 = max(0,a2-(b1-a1))+b2\n r = max(r,a2)\n a1 = b1\nprint(a1+a2,r)\n\n",
"n = int(input())\r\n \r\nlast_sent_time = 0\r\nmax_queue_size = 0\r\ncurrent_time = 0\r\n\r\nfor _ in range(n):\r\n arrival_time, num_messages = map(int, input().split())\r\n last_sent_time = max(0, last_sent_time - (arrival_time - current_time))\r\n last_sent_time += num_messages\r\n max_queue_size = max(max_queue_size, last_sent_time)\r\n current_time = arrival_time\r\n \r\nprint(current_time + last_sent_time, max_queue_size)# 1698158448.9481006",
"n=int(input())\r\na,b=map(int,input().split())\r\nl=b\r\nx=a\r\nq=0\r\nm=0\r\nm=max(m,l)\r\nfor i in range(n-1):\r\n\ta,b=map(int,input().split())\r\n\tl-=(a-x)\r\n\tl=max(l,0)\r\n\tl+=b\r\n\tm=max(m,l)\r\n\tx=a\r\nprint(\"{} {}\".format(x+l,m))",
"import sys\r\nimport math\r\n\r\nn = int(input())\r\n\r\na, b = list(map(int, input().split()))\r\nvmax = b\r\nfor i in range(1, n):\r\n c, d = list(map(int, input().split()))\r\n b = max(0, b - (c - a))\r\n a = c\r\n b += d\r\n vmax = max(b, vmax)\r\n\r\nprint(a + b, vmax)\r\n",
"n = int(input())\n\nq = max_q = t0 = 0\n\nfor i in range(n):\n\n t, c = map(int, input().split())\n\n q = max(0, q - t + t0) + c\n\n if q > max_q:\n\n max_q = q\n\n t0 = t\n\nprint(t0 + q, max_q)",
"# LUOGU_RID: 101473903\n(n,), *a = [[*(map(int, s.split()))] for s in open(0)]\r\np = q = r = 0\r\nfor x, y in a:\r\n q = max(0, p + q - x) + y\r\n r = max(r, q)\r\n p = x\r\nprint(p+q, r)\r\n",
"n = int(input())\r\n\r\nmessage = 0\r\nm = 0\r\nl = 0\r\n\r\nfor _ in range(n):\r\n t, c = map(int, input().split())\r\n message = max(0, message-(t-l))\r\n message += c\r\n m = max(message, m)\r\n l = t\r\n\r\nprint(l+message, m)\r\n \r\n",
"i = int(input())\r\nt = q= m=0\r\nfor x in range(i):\r\n a,b = map(int,input().split())\r\n q -= a-t\r\n if q < 0: q = 0\r\n q += b\r\n if q > m: m = q\r\n t = a\r\nt += q\r\nprint(t,m)\r\n",
"n = int(input())\r\nct = 0\r\ncq = 0\r\nmcq = 0\r\n\r\nfor i in range(n):\r\n\tt, c = map(int, input().split())\r\n\tmcq = max(cq, mcq)\t\r\n\tcq = max(cq - (t - ct), 0)\r\n\tcq += c\r\n\tct = t\r\n\t#print(cq)\r\n\t\r\n\r\nmcq = max(cq, mcq)\r\nct += cq\r\nprint(ct, mcq)\t\r\n"
] | {"inputs": ["2\n1 1\n2 1", "1\n1000000 10", "3\n3 3\n4 3\n5 3", "1\n1 1", "2\n1 11\n100 10", "4\n1 10\n2 9\n3 8\n40 3", "5\n2 1\n5 2\n6 1\n7 1\n8 1", "4\n10 1000\n99998 20\n99999 10\n1000000 100", "6\n10 10\n100 500\n200 500\n500 1\n999995 4\n999996 15", "10\n1 5\n2 5\n3 10\n4 8\n5 5\n6 4\n7 8\n8 9\n9 2\n10 10", "10\n26 4\n85 97\n86 62\n87 74\n92 8\n93 81\n97 12\n98 25\n99 31\n100 3", "10\n964416 3980\n987048 334\n999576 6922\n999684 2385\n999896 6558\n999948 3515\n999966 1517\n999984 2233\n999988 7242\n999994 91", "50\n3 16\n25 5\n35 6\n39 9\n48 9\n50 12\n57 9\n58 2\n59 9\n60 16\n61 8\n62 7\n63 15\n64 3\n65 16\n66 12\n67 12\n68 8\n69 5\n70 11\n71 4\n72 6\n73 12\n74 20\n75 12\n76 11\n77 5\n78 15\n79 12\n80 5\n81 4\n82 17\n83 14\n84 11\n85 6\n86 10\n87 12\n88 8\n89 9\n90 2\n91 17\n92 14\n93 7\n94 15\n95 8\n96 3\n97 14\n98 13\n99 18\n100 7", "40\n313 97063\n372 23668\n377 56079\n428 88458\n435 57330\n454 88869\n456 75553\n466 87607\n468 4542\n469 30243\n471 8958\n472 59745\n473 90985\n474 32247\n475 71576\n476 14016\n477 91574\n478 38345\n479 93280\n480 89902\n481 41828\n482 3233\n483 66725\n484 23523\n485 46772\n486 95688\n487 19864\n488 10295\n489 83431\n490 51687\n491 4362\n492 85411\n493 30044\n494 97895\n495 6379\n496 79232\n497 341\n498 82766\n499 77612\n500 76069", "5\n987640 52\n994481 69\n995526 50\n996631 75\n999763 22", "30\n1227 3920\n2007 7796\n3074 5424\n5172 6174\n5314 8761\n5329 5644\n5352 5880\n5395 2721\n5403 4406\n5420 3835\n5421 2692\n5423 8241\n5425 6433\n5426 2900\n5427 2209\n5428 8672\n5429 3317\n5430 4857\n5431 5735\n5432 2784\n5433 1564\n5434 2094\n5435 6258\n5436 101\n5437 3745\n5438 7124\n5439 1484\n5440 8593\n5441 7198\n5442 8318", "23\n5 1045\n12 703\n16 26\n23 3384\n28 4563\n30 4501\n34 1033\n35 1393\n36 4095\n37 1279\n38 1787\n39 770\n40 5362\n41 4569\n42 3148\n43 2619\n44 5409\n45 3919\n46 732\n47 1297\n48 4512\n49 3231\n50 5169"], "outputs": ["3 1", "1000010 10", "12 7", "2 1", "110 11", "43 25", "10 2", "1000100 1000", "1000014 900", "67 57", "478 378", "1030039 30045", "515 415", "2183510 2183010", "999785 75", "150107 144665", "64551 64501"]} | UNKNOWN | PYTHON3 | CODEFORCES | 22 | |
2b6a04c9aeb28e5e0278b8ff88b2a9b6 | Big Maximum Sum | Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't.
This problem is similar to a standard problem but it has a different format and constraints.
In the standard problem you are given an array of integers, and you have to find one or more consecutive elements in this array where their sum is the maximum possible sum.
But in this problem you are given *n* small arrays, and you will create one big array from the concatenation of one or more instances of the small arrays (each small array could occur more than once). The big array will be given as an array of indexes (1-based) of the small arrays, and the concatenation should be done in the same order as in this array. Then you should apply the standard problem mentioned above on the resulting big array.
For example let's suppose that the small arrays are {1, 6, -2}, {3, 3} and {-5, 1}. And the indexes in the big array are {2, 3, 1, 3}. So the actual values in the big array after formatting it as concatenation of the small arrays will be {3, 3, -5, 1, 1, 6, -2, -5, 1}. In this example the maximum sum is 9.
Can you help Mostafa solve this problem?
The first line contains two integers *n* and *m*, *n* is the number of the small arrays (1<=≤<=*n*<=≤<=50), and *m* is the number of indexes in the big array (1<=≤<=*m*<=≤<=250000). Then follow *n* lines, the *i*-th line starts with one integer *l* which is the size of the *i*-th array (1<=≤<=*l*<=≤<=5000), followed by *l* integers each one will be greater than or equal -1000 and less than or equal 1000. The last line contains *m* integers which are the indexes in the big array, and you should concatenate the small arrays in the same order, and each index will be greater than or equal to 1 and less than or equal to *n*.
The small arrays are numbered from 1 to *n* in the same order as given in the input. Some of the given small arrays may not be used in big array.
Note, that the array is very big. So if you try to build it straightforwardly, you will probably get time or/and memory limit exceeded.
Print one line containing the maximum sum in the big array after formatting it as described above. You must choose at least one element for the sum, i. e. it cannot be empty.
Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).
Sample Input
3 4
3 1 6 -2
2 3 3
2 -5 1
2 3 1 3
6 1
4 0 8 -3 -10
8 3 -2 -5 10 8 -9 -5 -4
1 0
1 -3
3 -8 5 6
2 9 6
1
Sample Output
9
8
| [
"def get_best(arr):\r\n ans, now = -(1 << 64), 0\r\n for i in arr:\r\n now += i\r\n ans = max(ans, now)\r\n if (now < 0): now = 0\r\n return ans\r\n\r\n\r\ndef compute(arr):\r\n ans, now = -(1 << 64), 0\r\n for i in arr:\r\n now += i\r\n ans = max(ans, now)\r\n return ans\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\nvals = []\r\nsuffix, prefix, summation, best = [0] * n, [0] * n, [0] * n, [0] * n\r\nfor i in range(n):\r\n arr = list(map(int, input().split()))[1:]\r\n summation[i] = sum(arr)\r\n suffix[i] = compute(list(reversed(arr)))\r\n prefix[i] = compute(arr)\r\n best[i] = get_best(arr)\r\n vals.append(arr)\r\n\r\nidx = list(map(lambda x: int(x) - 1, input().split()))\r\n\r\n\r\nf = [[0 for x in range(m + 1)] for p in range(2)]\r\nf[0][m] = -(1 << 64)\r\n\r\ni = m - 1\r\nwhile i >= 0:\r\n cur = idx[i]\r\n f[0][i] = max(max(f[0][i + 1], best[cur]), suffix[cur] + f[1][i + 1])\r\n f[1][i] = max(prefix[cur], summation[cur] + f[1][i + 1])\r\n i -= 1\r\n\r\nprint(f[0][0])\r\n",
"def get_max_array_sums(a):\r\n current_prefix_sum = a[0]\r\n max_prefix_sum = a[0]\r\n \r\n current_suffix_sum = a[-1]\r\n max_suffix_sum = a[-1]\r\n\r\n array_sum = a[0]\r\n\r\n max_ending_here = a[0]\r\n max_so_far = max_ending_here\r\n if max_ending_here < 0:\r\n max_ending_here = 0\r\n \r\n for i in range(1,len(a)):\r\n\r\n current_prefix_sum += a[i]\r\n if max_prefix_sum < current_prefix_sum:\r\n max_prefix_sum = current_prefix_sum\r\n\r\n current_suffix_sum += a[-i-1]\r\n if max_suffix_sum < current_suffix_sum:\r\n max_suffix_sum = current_suffix_sum\r\n\r\n array_sum += a[i]\r\n\r\n max_ending_here += a[i]\r\n if max_so_far < max_ending_here:\r\n max_so_far = max_ending_here\r\n\r\n if max_ending_here < 0:\r\n max_ending_here = 0\r\n \r\n return [max_prefix_sum, max_so_far, max_suffix_sum, array_sum]\r\n\r\nsmall_array_sums = []\r\n\r\nn, m = map(int, input().split())\r\nfor i in range(n):\r\n _, *a = map(int, input().split())\r\n small_array_sums.append(get_max_array_sums(a))\r\n\r\nindexes = list(map(int, input().split()))\r\n\r\nidx = indexes[0] - 1\r\nmax_so_far = small_array_sums[idx][1]\r\nmax_ending_here = small_array_sums[idx][2]\r\nif max_ending_here < 0:\r\n max_ending_here = 0\r\n\r\n# print(0, max_so_far)\r\n\r\nfor i in range(1,m):\r\n idx = indexes[i] - 1\r\n\r\n max_so_far = max(max_so_far, max_ending_here + small_array_sums[idx][0], small_array_sums[idx][1])\r\n max_ending_here = max(max_ending_here + small_array_sums[idx][3], small_array_sums[idx][2])\r\n\r\n if max_ending_here < 0:\r\n max_ending_here = 0\r\n \r\n # print(i, max_so_far)\r\n\r\nprint(max_so_far)",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\nl, r, s = [0], [0], [0]\r\nu = [[0]]\r\ninf = pow(10, 9) + 1\r\nc = [0]\r\nfor _ in range(n):\r\n ans0 = -inf\r\n a = list(map(int, input().split()))[1:]\r\n l0, r0, s0 = -inf, -inf, 0\r\n mi = 0\r\n for i in a:\r\n s0 += i\r\n ans0 = max(ans0, s0 - mi)\r\n l0 = max(l0, s0)\r\n mi = min(mi, s0)\r\n s0 = 0\r\n for i in reversed(a):\r\n s0 += i\r\n r0 = max(r0, s0)\r\n l.append(l0)\r\n r.append(r0)\r\n s.append(s0)\r\n c.append(ans0)\r\na = list(map(int, input().split()))\r\nb = [0]\r\nans = -inf\r\nfor i in a:\r\n ans = max(ans, c[i])\r\n b.append(r[i])\r\nma = b[1]\r\nfor i in range(1, m):\r\n ai = a[i]\r\n ans = max(ans, l[ai] + ma)\r\n ma += s[ai]\r\n ma = max(ma, b[i + 1])\r\nprint(ans)",
"def maxContiguousSum(arr):\r\n max_so_far = arr[0]\r\n curr_max = arr[0]\r\n for i in range(1, len(arr)):\r\n curr_max = max(arr[i], curr_max + arr[i])\r\n max_so_far = max(max_so_far, curr_max)\r\n return max_so_far\r\n\r\nn,m=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n a.append(list(map(int,input().split()))[1:])\r\n\r\nsm=[sum(a[i]) for i in range(n)]\r\nmx=[]\r\nmxRev=[]\r\nfor i in range(n):\r\n m1=0\r\n s=0\r\n for j in a[i]:\r\n s+=j\r\n m1=max(m1,s)\r\n mx.append(m1)\r\n\r\nfor i in range(n):\r\n m1=0\r\n s=0\r\n for j in a[i][::-1]:\r\n s+=j\r\n m1=max(m1,s)\r\n mxRev.append(m1)\r\n\r\nb=list(map(int,input().split()))\r\nans=-9999999999999999\r\nfor i in set(b):\r\n ans=max(ans,maxContiguousSum(a[i-1]))\r\n \r\nif ans<0:\r\n print(ans)\r\n exit()\r\n\r\n# print(sm)\r\n# print(mx)\r\n\r\ndp=[0 for i in range(m+1)]\r\n\r\ndp[m-1]=mx[b[m-1]-1]\r\nfor i in range(m-2,-1,-1):\r\n dp[i]=max(sm[b[i]-1]+dp[i+1],mx[b[i]-1])\r\n ans=max(ans,mxRev[b[i]-1]+dp[i+1])\r\nans=max(ans,max(dp))\r\nprint(ans)",
"n,m=map(int,input().split())\r\nl,r,s=[0],[0],[0]\r\nc=[0]\r\nans=-float(\"inf\")\r\nfor i in range(n):\r\n ans0=-float(\"inf\")\r\n a=list(map(int,input().split()))[1:]\r\n l0,r0,s0=-float(\"inf\"),-float(\"inf\"),0\r\n mi=0\r\n \r\n for i in a:\r\n s0+=i\r\n ans0=max(ans0,s0-mi)\r\n l0=max(l0,s0)\r\n mi=min(mi,s0)\r\n s0=0\r\n for i in a[::-1]:\r\n \r\n s0+=i\r\n r0=max(r0,s0)\r\n\r\n l.append(l0)\r\n r.append(r0)\r\n s.append(s0)\r\n c.append(ans0)\r\na=list(map(int,input().split()))\r\nb=[0]\r\nans=-float(\"inf\")\r\nfor i in a:\r\n ans=max(ans,c[i])\r\n b.append(r[i])\r\nma=b[1]\r\nfor i in range(1,m):\r\n ai=a[i]\r\n ans=max(ans,l[ai]+ma)\r\n ma+=s[ai]\r\n ma=max(ma,b[i+1])\r\nprint(ans) \r\n ",
"if __name__ == \"__main__\":\n i = input().split()\n N = int(i[0])\n M = int(i[1])\n\n arrList = []\n leftMax = []\n rightMax = []\n listTotal = []\n rightSum = []\n for i in range(N):\n inputList = [int(x) for x in input().split()]\n list = inputList[1:inputList[0] + 1]\n\n listTotal.append(0)\n leftMax.append(-999999)\n rightMax.append(-999999)\n rightSum.append(-999999)\n rightIter = 0\n for j in list:\n listTotal[i] += j\n rightIter += j\n leftMax[i] = max(leftMax[i], listTotal[i])\n rightSum[i] = max(rightSum[i], rightIter)\n rightIter = 0 if rightIter < 0 else rightIter\n rightMax[i] = rightIter\n arrList.append(list)\n\n idxOrder = [int(x) for x in input().split()][0:M]\n maxSum = -99999999\n currMax = 0\n for i in idxOrder:\n bestTot = max(maxSum, rightSum[i - 1])\n bestSum = max(currMax + leftMax[i - 1], currMax + listTotal[i - 1])\n\n maxSum = max(bestSum, bestTot)\n currMax = max(currMax + listTotal[i - 1], rightMax[i - 1])\n\n print(maxSum)\n \t\t \t\t\t \t \t \t \t \t\t\t\t \t \t\t",
"import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nfrom math import gcd\r\n\r\nMOD0 = 10 ** 9 + 7\r\nMOD1 = 998244353\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\nimport math\r\n\r\nm, n = map(int, input().split())\r\nnums = []\r\nlength = []\r\nfor _ in range(m):\r\n tmp = list(map(int, input().split()))\r\n length.append(tmp[0])\r\n nums.append(tmp[1:])\r\nidxes = list(map(int, input().split()))\r\n\r\nfor i in range(n):\r\n idxes[i] -= 1\r\npre, post, s, inner = [], [], [], []\r\nfor ls in nums:\r\n # 最大前缀和\r\n max_val, p = -math.inf, 0\r\n for val in ls:\r\n p += val\r\n if p > max_val:\r\n max_val = p\r\n pre.append(max_val)\r\n s.append(p)\r\n # 最大后缀和\r\n max_val, p = -math.inf, 0\r\n for i in range(len(ls) - 1, -1, -1):\r\n p += ls[i]\r\n if p > max_val:\r\n max_val = p\r\n post.append(max_val)\r\n # 最大内部和\r\n max_val, cur = -math.inf, 0\r\n for v in ls:\r\n cur = v if cur <= 0 else v + cur\r\n if cur > max_val:\r\n max_val = cur\r\n inner.append(max_val)\r\n\r\nans, cur = max(inner[i] for i in idxes), 0\r\n\r\nfor idx in idxes:\r\n if cur < 0:\r\n cur = 0\r\n tmp_max = cur + pre[idx]\r\n cur += s[idx]\r\n if tmp_max > ans:\r\n ans = tmp_max\r\n if post[idx] > cur:\r\n cur = post[idx]\r\n\r\nprint(ans)"
] | {"inputs": ["3 4\n3 1 6 -2\n2 3 3\n2 -5 1\n2 3 1 3", "6 1\n4 0 8 -3 -10\n8 3 -2 -5 10 8 -9 -5 -4\n1 0\n1 -3\n3 -8 5 6\n2 9 6\n1", "4 3\n6 6 8 -5 4 10 -2\n1 -2\n1 -10\n5 -10 10 8 -7 -10\n2 4 1", "7 7\n2 -8 -7\n5 2 -10 10 -2 4\n7 10 -8 9 8 9 -10 -3\n6 0 6 -9 9 -6 -9\n4 -6 -9 10 -6\n3 -8 4 10\n7 -1 -3 10 -8 -6 -3 6\n4 5 4 6 6 1 7", "4 8\n8 0 3 -9 -10 0 -1 6 -4\n3 -10 -7 2\n10 6 -2 -9 0 -7 -4 -7 7 -1 2\n3 -5 1 -4\n1 1 1 1 4 4 3 3", "2 1\n2 -4 -6\n5 6 8 3 5 -2\n1", "9 4\n4 8 -2 -10 6\n10 -4 9 6 -2 -8 6 7 2 -6 2\n8 -10 1 9 9 -10 2 -10 -9\n7 3 -10 -10 -6 3 -7 0\n5 -4 -8 2 -5 2\n1 -3\n4 -9 0 7 -4\n7 4 -5 4 -8 -4 0 -1\n9 2 5 -10 4 -10 -2 6 5 10\n3 6 4 6", "3 1\n7 4 8 1 -7 -9 -8 -9\n10 5 -5 -5 -9 -1 7 4 -1 -4 4\n8 -7 7 4 10 -6 3 -6 9\n2", "7 3\n7 -9 -6 0 -6 -5 1 -9\n9 4 4 3 -6 -4 8 4 5 -6\n1 -4\n7 -3 -9 -9 1 -4 8 7\n2 6 3\n7 0 -5 -5 -2 -8 2 -1\n8 4 1 6 -7 -2 10 -8 -2\n3 1 5", "6 9\n8 -10 10 3 4 -9 0 3 9\n4 9 2 -1 6\n3 -10 -10 -5\n7 10 -6 7 1 -8 3 4\n8 -8 9 3 -1 0 1 -7 -7\n1 -4\n3 2 3 2 4 4 1 1 1", "3 6\n3 -1 -1 -1\n4 -2 -2 -2 -2\n5 -3 -3 -3 -3 -3\n1 2 3 1 2 3", "2 2\n11 -1 -1 -1 -1 10 -1 -1 -1 -1 -1 -1\n10 -1 -1 -1 10 -1 -1 -1 -1 -1 -1\n1 2", "1 1\n1 1\n1", "1 1\n1 -1\n1", "1 1\n1 0\n1", "2 2\n6 -1 -1 -1 1 1 1\n6 1 1 1 -1 -1 -1\n1 2", "2 2\n6 -1 -1 -1 1 1 1\n6 -1 -1 -1 -1 -1 -1\n1 2", "2 2\n6 -1 -1 -1 -1 -1 -1\n6 1 1 1 -1 -1 -1\n1 2", "2 2\n6 -1 -1 -1 -1 -1 -1\n6 -1 -1 -1 -1 -1 -1\n1 2", "2 2\n6 -1 -1 0 -1 -1 -1\n6 -1 -1 -1 -1 -1 -1\n1 2", "2 2\n6 -1 -1 0 1 0 -1\n6 -1 -1 -1 -1 -1 -1\n1 2", "2 2\n6 0 0 0 0 0 0\n6 0 0 0 0 0 0\n1 2", "14 14\n6 -1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 1\n6 1 1 1 1 1 -1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14"], "outputs": ["9", "8", "24", "20", "14", "-4", "19", "11", "9", "68", "-1", "11", "1", "-1", "0", "6", "3", "3", "-1", "0", "1", "0", "82"]} | UNKNOWN | PYTHON3 | CODEFORCES | 7 | |
2b6f2bf3f26bc64383b9036248b68a90 | A Student's Dream | Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych.
The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams.
So the professor began: "Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has *a**l* fingers on her left hand and *a**r* fingers on the right one. The boy correspondingly has *b**l* and *b**r* fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable."
The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa.
The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly.
Print YES or NO, that is, the answer to Petr Palych's question.
Sample Input
5 1
10 5
4 5
3 3
1 2
11 6
Sample Output
YESYESNO | [
"al, ar = list(map(int, input().split()))\r\nbl, br = list(map(int, input().split()))\r\n\r\nif (br >= al-1 and br <= (al+1)*2) or (bl <= (ar+1)*2 and bl >= ar-1):\r\n print('YES')\r\nelse:\r\n print('NO')",
"A1,A2=map(int,input().split())\r\nB1,B2=map(int,input().split())\r\nprint(\"YES\" if A2-1<=B1<=(A2-1)*2+4 or A1-1<=B2<=(A1-1)*2+4 else \"NO\")",
"al, ar = map(int, input().split())\r\nbl, br = map(int, input().split())\r\nif al-1<=br<=2*al+2 or ar-1<=bl<=2*ar+2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"girlL, girlR = map(int, input().split())\r\nboyL, boyR = map(int, input().split())\r\n\r\nif (girlL - 1 <= boyR <= 2 * (girlL + 1)) or (girlR - 1 <= boyL <= 2 * (girlR + 1)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"gl,gr=map(int,input().split())\r\nbl,br=map(int,input().split())\r\nif gl-1<=br<=2*gl+2 or gr-1<=bl<=2*gr+2:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")",
"a, b = map(int, input().split(' '))\r\nc, d = map(int, input().split(' '))\r\n\r\nif (c >= b-1 and c < (b+1)*2+1) or (d >= a-1 and d < (a+1)*2+1):\r\n print('YES')\r\nelse:\r\n print('NO')",
"import math\r\n\r\ngirlLeft, girlRight = [int(item) for item in input().split()]\r\nboyLeft, boyRight = [int(item) for item in input().split()]\r\n\r\nboyRf = boyRight // 3 if boyRight % 3 < 2 else boyRight // 3 + 1\r\nboyLf = boyLeft // 3 if boyLeft % 3 < 2 else boyLeft // 3 + 1\r\n\r\nif boyRf <= girlLeft <= boyRight + 1 or \\\r\n boyLf <= girlRight <= boyLeft + 1:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n'''\r\n\r\nBoy 1\r\nmin - 1\r\nI I I\r\nI I\r\nBoy 2\r\n\r\n I I I I\r\n I I I I\r\n\r\n Boy 3\r\n\r\n I I I I I\r\n I I I I I I\r\n\r\nBoy 4\r\n\r\n I I I I I I \r\n I I I I I I I I \r\n \r\n Boy 5\r\n \r\n I I I I I I I I\r\n I I I I I I I I I I\r\n \r\n \r\n ************************\r\n GL 2 6 GR\r\n BL 12 12 BR\r\n *************************\r\n \r\n | | | | | | \r\n Boy - | | | | | | | | | | | |\r\n | \r\n | | | |\r\n'''\r\n",
"ar, al = map(int, input().split())\r\nbr, bl = map(int, input().split())\r\nprint('YES' if 2 * (ar + 1) >= bl >= ar - 1 or 2 * (al + 1) >= br >= al - 1 else 'NO')",
"# @Chukamin ICPC_TRAIN\n\ndef main():\n al, ar = map(int, input().split())\n bl, br = map(int, input().split())\n if bl >= ar - 1 and bl <= (ar + 1) * 2:\n print('YES')\n elif br >= al - 1 and br <= (al + 1) * 2:\n print('YES')\n else:\n print('NO')\n\nif __name__ == '__main__':\n main()\n\n \t \t \t \t\t\t\t\t \t \t\t \t \t\t\t\t \t\t\t",
"import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\na,b=(int(i) for i in input().split())\r\nc,d=(int(i) for i in input().split())\r\ndef check(i,j):\r\n if((j>=i-1 and j<=(i+1)*2) or (i>=(j-1)//2 and i<=j+1)):\r\n return True\r\n else:\r\n return False\r\nif(check(a,d) or check(b,c)):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"\ngf = input().split()\nbf = input().split()\n\nal, ar = int(gf[0]), int(gf[1])\nbl, br = int(bf[0]), int(bf[1])\n\nif ar - 1 <= bl <= 2*ar + 2 or al - 1 <= br <= 2*al + 2:\n print(\"YES\")\nelse:\n print(\"NO\")\n",
"al, ar = map(int, input().split())\r\nbl, br = map(int, input().split())\r\nif (((al * 2 + 3 > br) and (br >= al - 1)) or ((ar * 2 + 3 > bl) and (bl >= ar - 1))) :\r\n print('YES')\r\nelse : print('NO')",
"def can(girl, boy):\n places = girl - 1\n return places <= boy <= places * 2 + 4\n\nal, ar = map(int, input().split())\nbl, br = map(int, input().split())\n\nif can(al, br) or can(ar, bl):\n print('YES')\nelse:\n print('NO')\n\n",
"r=lambda g,b: g-1<=b<=2*(g+1)\r\na,b=map(int,input().split())\r\nc,d=map(int,input().split())\r\nif r(a,d) or r(b,c):print(\"YES\")\r\nelse:print(\"NO\")",
"import math\r\n\r\ngirlLefT, girlRight = [int(item) for item in input().split(' ')]\r\nboyLeft, boyRight = [int(item) for item in input().split(' ')]\r\n\r\nif math.ceil(boyRight / 2) - 1 <= girlLefT and boyRight + 1 >= girlLefT or \\\r\n math.ceil(boyLeft / 2) - 1 <= girlRight and boyLeft + 1 >= girlRight:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"al,ar = map(int,input().split())\r\nbl,br = map(int,input().split())\r\nans = \"NO\"\r\nif (al-1) <= br <= 2*(al+1) or (ar-1) <= bl <= 2*(ar+1):\r\n ans = \"YES\"\r\nprint(ans)\r\n",
"g_l,g_r=input().split()\r\nb_l,b_r=input().split()\r\ng_l=int(g_l)\r\ng_r=int(g_r)\r\nb_l=int(b_l)\r\nb_r=int(b_r)\r\nflag=0\r\nif g_l==b_r:\r\n flag=1\r\nelif g_l>b_r and g_l-1==b_r:\r\n flag=1\r\nelif b_r>g_l and 2*g_l+2>=b_r:\r\n flag=1\r\n\r\nif flag==0:\r\n if g_r == b_l:\r\n flag = 1\r\n elif g_r > b_l and g_r - 1 == b_l:\r\n flag = 1\r\n elif b_l > g_r and 2 * g_r + 2 >= b_l:\r\n flag = 1\r\nif flag==0:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")",
"import math\r\na=input()\r\na=a.split()\r\na=[int(i) for i in a]\r\nb=input()\r\nb=b.split()\r\nb=[int(i) for i in b]\r\nif (a[0] <= b[1]+1) and (math.floor((b[1]+1)/2)-1 <= a[0]) :\r\n print('YES')\r\nelif (a[1] <= b[0]+1) and (math.floor((b[0]+1)/2)-1 <= a[1]) :\r\n print('YES')\r\nelse :\r\n print('NO')\r\n\r\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\na, b = map(int, input().split())\r\nc, d = map(int, input().split())\r\n\r\nif a - 1 <= d <= (a+1)*2 or b - 1 <= c <= (b+1)*2:\r\n print('YES')\r\nelse:\r\n print('NO')",
"\ndef constraints(g, b):\n\tif(g - b <= 1 and 2*g - b >= -2):\n\t\treturn True\n\telse:\n\t\treturn False\n\ng1, g2 = tuple(map(int, input().split()))\nb1, b2 = tuple(map(int, input().split()))\nif(constraints(g1, b2) or constraints(g2, b1)):\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")",
"def fun(x,y):\r\n if y>=x-1:\r\n s=1\r\n else:\r\n s=0\r\n if y%2==0:\r\n t=(y/2)-1\r\n else:\r\n t=int(y/2)\r\n if x>=t:\r\n w=1\r\n else:\r\n w=0\r\n if w*s==1:\r\n return 1\r\n else:\r\n return 0\r\na,b=map(int,input().split())\r\nc,d=map(int,input().split())\r\nif fun(a,d) or fun(b,c):\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"al,ar=map(int,input().split())\r\nbl,br=map(int,input().split())\r\nif al-br == 1 or ar-bl == 1 :\r\n print(\"YES\")\r\nelif al<=br<=al*2+2 or ar<=bl<=ar*2+2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"def fingers(a,b):\r\n if b+1>=a and 2*a+2>=b:\r\n return True\r\n\r\na, a1 = map(int,input().split())\r\nb, b1 = map(int,input().split())\r\nif fingers(a,b1)or fingers(a1,b) == True:\r\n print('YES')\r\nelse:\r\n print('NO')",
"l_g, r_g = [int(x) for x in input().split()]\nl_b, r_b = [int(x) for x in input().split()]\n\ndef is_okay(g, b):\n if g >= (b + 2):\n return False\n if b >= (((g + 1) * 2) + 1):\n return False\n return True\n\nif any([is_okay(l_g, r_b), is_okay(r_g, l_b)]):\n print('YES')\nelse: print('NO')\n\n",
"gl, gr = map(int, input().split())\r\nbl, br = map(int, input().split())\r\n\r\nprint ('YES' if (br >= gl - 1 and br <= 2 * gl + 2) or (bl >= gr - 1 and bl <= 2 * gr + 2) else 'NO')\r\n",
"# LUOGU_RID: 101453429\na, b, c, d = map(int, open(0).read().split())\r\nprint((a - 1 <= d < a * 2 + 3 or b - 1 <= c < b * 2 + 3) and 'YES' or 'NO')\r\n",
"'''\r\n\r\n|*|*|\r\n\r\n**|**|**|**\r\n\r\n|\r\n\r\n**|**\r\n\r\n|*|\r\n\r\n**|**|**\r\n\r\n\r\ngirl = 1 0 <= boy <= 4\r\n\r\ngirl = 2 1 <= boy <= 6\r\n\r\ngirl = 3 2 <= boy <= 8\r\n\r\ngirl = 4 3 <= boy <= 10\r\n\r\ngirl = 10 9 <= boy <= 22\r\n\r\n'''\r\n\r\ngLeft, gRight = [int(item) for item in input().split()]\r\nbLeft, bRight = [int(item) for item in input().split()]\r\n\r\nif gLeft - 1 <= bRight <= gLeft * 2 + 2 or \\\r\n gRight - 1 <= bLeft <= gRight * 2 + 2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"def readln(): return tuple(map(int, input().split()))\n\nal, ar = readln()\nbl, br = readln()\nprint('YES' if al - 1 <= br <= (al + 1) * 2 or ar - 1 <= bl <= (ar + 1) * 2 else 'NO')\n",
"gl, gr = map(int, input().split())\r\nbl, br = map(int, input().split())\r\nif br in range(gl-1, ((gl+1)*2)+1) or bl in range(gr-1,((gr+1)*2)+1):\r\n print('YES')\r\nelse:\r\n print('NO')",
"def check(d, m):\r\n return m >= d - 1 and m <= (d + 1) * 2\r\n \r\n \r\ndl, dr = map(int, input().split())\r\nml, mr = map(int, input().split())\r\nif check(dl, mr) or check(dr, ml):\r\n print('YES')\r\nelse:\r\n print('NO')",
"al, ar = map(int, input().split())\r\nbl, br = map(int, input().split())\r\nif 2 * (al + 1) >= br >= al - 1 or 2 * (ar + 1) >= bl >= ar - 1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"import bisect\r\nimport collections\r\nimport copy\r\nimport enum\r\nimport functools\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport re\r\nimport sys\r\nimport time\r\nimport string\r\nfrom typing import List\r\nsys.setrecursionlimit(3001)\r\n\r\ninput = sys.stdin.readline\r\n\r\na, b = map(int, map(int, input().split()))\r\nc, d = map(int, input().split())\r\nif a-1 <= d <= 2*(a+1):\r\n print(\"YES\")\r\n exit()\r\nif b-1 <= c <= 2*(b+1):\r\n print(\"YES\")\r\n exit()\r\nprint(\"NO\")\r\n",
"gl, gr = map(int, input().split())\r\nbl, br = map(int, input().split())\r\nif (br >= gl-1 and br <= (gl+1)*2) or (bl >= gr-1 and bl <= (gr+1)*2):\r\n print('YES')\r\nelse:\r\n print('NO')",
"from math import ceil\r\n\r\nai, ar = map(int, input().split())\r\nbi, br = map(int, input().split())\r\n\r\nif (ceil(bi / 2) - 1 <= ar and not bi + 1 < ar) or (ceil(br / 2) - 1 <= ai and not br +1 < ai):\r\n print('YES')\r\nelse:\r\n print('NO')",
"def student_dream(x1, y1, x2, y2):\r\n if x1 - 1 <= y2 <= 2 * (x1 + 1) or y1 - 1 <= x2 <= 2 * (y1 + 1):\r\n return \"YES\"\r\n return \"NO\"\r\n\r\n\r\nX1, Y1 = [int(i) for i in input().split()]\r\nX2, Y2 = [int(j) for j in input().split()]\r\nprint(student_dream(X1, Y1, X2, Y2))\r\n",
"bl,br=map(int,input().split())\r\nal,ar=map(int,input().split())\r\nif bl-1<=ar<=2*bl+2 or br-1<=al<=2*br+2:\r\n print(\"YES\")\r\nelse:\r\n print('NO')\r\n",
"al, ar = map(int, input().split())\r\nbl, br = map(int, input().split())\r\nprint('YES' if al - 1 <= br <= (al + 1) * 2 or ar - 1 <= bl <= (ar + 1) * 2 else 'NO')",
"a,b=[int(i) for i in input().split()]\r\np,q=[int(i) for i in input().split()]\r\nr=0\r\nif q>=a-1 and q<=2*(a+1):\r\n r=1\r\nif p>=b-1 and p<=2*(b+1):\r\n r=1\r\nif r==1:\r\n print('YES')\r\nelse:\r\n print('NO')",
"vl,vr=[int(x) for x in input().split()]\r\nbl,br=[int(x) for x in input().split()]\r\n\r\nif vl-1<=br<=2*vl+2 or vr-1<=bl<=2*vr+2:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"def check(girl,boy):\r\n if girl>boy+1:\r\n return 0 \r\n if boy>((girl+1)*2):\r\n return 0 \r\n return 1 \r\n\r\ngl,gr=map(int,input().split())\r\nbl,br=map(int,input().split())\r\nif check(gl,br) or check(gr,bl):\r\n print('YES')\r\nelse:\r\n print('NO')"
] | {"inputs": ["5 1\n10 5", "4 5\n3 3", "1 2\n11 6", "1 1\n1 1", "2 2\n1 1", "3 3\n1 1", "4 4\n1 1", "100 100\n50 50", "100 3\n4 1", "100 5\n1 1", "100 4\n1 1", "100 1\n4 1", "1 100\n1 4", "1 100\n5 4", "1 100\n1 5", "43 100\n65 24", "4 2\n12 1", "6 11\n13 11", "2 6\n12 12", "14 7\n2 9", "1 14\n7 14", "6 11\n2 10", "5 12\n13 11", "15 1\n11 9", "7 12\n10 6", "15 7\n15 15", "1 5\n14 1", "2 4\n6 6", "12 8\n4 12", "6 14\n5 5", "19 17\n5 8", "9 21\n13 16", "11 2\n11 22", "15 3\n12 16", "13 2\n13 5", "21 1\n5 19", "9 15\n16 2", "7 18\n23 19", "13 17\n19 1", "5 15\n13 9", "11 17\n6 4", "18 3\n16 15", "5 23\n12 17", "25 8\n14 24", "18 22\n22 19", "2 25\n8 24", "7 25\n18 15", "8 22\n2 3", "25 9\n16 12", "19 4\n25 17", "24 43\n96 39", "13 23\n19 63", "93 12\n87 54", "94 35\n53 79", "65 8\n73 25", "25 14\n19 91", "58 86\n40 46", "82 60\n100 38", "36 62\n81 12", "30 38\n12 100"], "outputs": ["YES", "YES", "NO", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "NO", "YES", "NO", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "NO"]} | UNKNOWN | PYTHON3 | CODEFORCES | 40 | |
2b7a88a8b2f2498416289bb61345d762 | Problem About Equation | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.
Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:
- there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal.
The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug.
Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique.
Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.
Sample Input
5 50
1 2 3 4 5
2 2
1 100
Sample Output
12.000000
11.000000
10.000000
9.000000
8.000000
-1
| [
"# import sys\r\n# sys.stdin = open(\"test.txt\", 'r')\r\n\r\nn, b = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\n\r\nans = []\r\nt = sum(a) + b\r\np = t/n\r\nfor v in a:\r\n s = p-v\r\n if s < 0:\r\n print(-1)\r\n break\r\n else:\r\n ans.append(s)\r\nelse:\r\n for s in ans:\r\n print(f'{s:.6f}')\r\n\r\n\r\n\r\n\r\n",
"class CodeforcesTask174ASolution:\n def __init__(self):\n self.result = ''\n self.n_b = []\n self.capacity = []\n\n def read_input(self):\n self.n_b = [int(x) for x in input().split(\" \")]\n self.capacity = [int(x) for x in input().split(\" \")]\n\n def process_task(self):\n mx = max(self.capacity)\n to_fill = sum([mx - x for x in self.capacity])\n if to_fill > self.n_b[1]:\n self.result = \"-1\"\n else:\n result = []\n for x in self.capacity:\n result.append(mx - x + (self.n_b[1] - to_fill) / self.n_b[0])\n self.result = \"\\n\".join([str(y) for y in result])\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask174ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n",
"n,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nm=max(l)\r\ncnt=0\r\nfor i in range(n):\r\n cnt+=m-l[i]\r\n\r\n\r\nif cnt > b :\r\n print(-1)\r\n exit()\r\n\r\na=b/n\r\nc=sum(l)/n\r\nfor i in range(n):\r\n print('{:.6f}'.format(a+c-l[i]))",
"num_friends, remaining = map(int, input().split())\nvolumes = list(map(int, input().split()))\nmax_volume = max(volumes)\npour = [ max_volume - volume for volume in volumes ]\nif sum(pour) > remaining:\n print(-1)\nelse:\n part = (remaining - sum(pour)) / len(pour)\n for i, volume in enumerate(pour):\n volume += part\n print('%.8f' % volume)\n",
"n,b=map(int,input().split())\r\na=list(map(int,input().split()))\r\nm,z=max(a),0\r\nfor i in range(n):\r\n z+=(m-a[i])\r\n a[i]=m-a[i]\r\nif z>b:\r\n print(-1)\r\n exit()\r\nb-=z\r\nb=b/n\r\nfor i in range(n):\r\n print(a[i]+b)\r\n\r\n",
"x , y = map(int,input().split())\r\nl = list(map(int,input().split()))\r\na = (sum(l)+y)/x\r\nif max(l) > a:\r\n print(-1)\r\nelse:\r\n for i in l:\r\n print(\"{:.6f}\".format(a-i))\r\nprint()",
"import sys\r\n\r\nn,b= map(int, input().split())\r\n\r\nb=float(b)\r\narr = list(map(float, (input().split())))\r\nmaxele=max(arr)\r\nneed=0.000000\r\nneedarr=[]\r\n\r\nfor i in range(n):\r\n if(b<maxele-arr[i]):\r\n print(-1)\r\n sys.exit()\r\n else:\r\n needarr+=[maxele-arr[i]]\r\n b-=maxele-arr[i]\r\n \r\n\r\nfor i in range(n):\r\n print(f\"{(b/n+needarr[i]):.6f}\")",
"n, k = [int(i) for i in input().split()] \r\na = [int(i) for i in input().split()] \r\nq = (sum(a) + k)/n\r\nres = []\r\nfor i in range(n): \r\n if q - a[i] < 0 : res = -1 ; break \r\n res.append(q-a[i]) \r\nif res == -1 : print(-1) \r\nelse : \r\n for i in res : print(i)\r\n",
"# ========= /\\ /| |====/|\r\n# | / \\ | | / |\r\n# | /____\\ | | / |\r\n# | / \\ | | / |\r\n# ========= / \\ ===== |/====| \r\n# code\r\n\r\ndef main():\r\n n,b = map(int, input().split())\r\n a = list(map(int,input().split()))\r\n X = (b + sum(a))/n\r\n c = [X - i for i in a]\r\n for i in c:\r\n if i < 0:\r\n print(-1)\r\n return\r\n for i in c:\r\n print(i)\r\n return\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"# LUOGU_RID: 101470714\nn, m, *a = map(int, open(0).read().split())\r\nt = (m + sum(a)) / n\r\nif t < max(a):\r\n exit(print(-1))\r\nfor x in a:\r\n print(t - x)\r\n",
"n,b=map(int,input().split())\r\na=list(map(int,input().split()))\r\ns=sum(a)+b\r\nm=s/n\r\nif m<max(a):\r\n print(-1)\r\nelse:\r\n for i in range(n):\r\n print(m-a[i])",
"n, b = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\nd = [(b + sum(a)) / len(a) - i for i in a]\r\nprint(-1) if any(i for i in d if i < 0) else [print(i) for i in d]",
"a, b = map(int,input().split())\nc = list(map(float, input().split()))\nd = b\nfor x in c:d += x\nd = d / a\nif any(x > d for x in c):print(-1)\nelse:\n\tfor x in c:print(\"%.6f\" %(d - x))\n",
"n,b=map(int,input().split())\r\na=list(map(int,input().split()))\r\nm=max(a)\r\nx=-1\r\nif b>=m*n-sum(a):\r\n b=b-m*n+sum(a)\r\n x=m\r\n x+=b/n\r\nif x==-1:print(x)\r\nelse:\r\n for k in a:\r\n print(\"{0:.6f}\".format(x-k))",
"#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-29 23:53:37\nLastEditTime: 2021-11-30 00:01:41\nDescription: Problem About Equation\nFilePath: CF174A.py\n'''\n\n\ndef func():\n n, b = map(int, input().strip().split())\n cpu = list(map(int, input().strip().split()))\n avenge = (sum(cpu) + b) / n\n if avenge < max(cpu):\n print(-1)\n else:\n for item in [(avenge - i) for i in cpu]:\n print(\"%.6f\" % item)\n\n\nif __name__ == '__main__':\n func()\n",
"b=(input())\na=b.split()\nnum=int(a[0])\ntot=float(a[1])\nk=input()\nk1=(k.split())\nk2=range(num)\nc=[]\nfor x in k2:\n\tc.append(float(k1[x]))\nd=0.0\nfor x in k2:\n\td=d+c[x]\ne=d/num\nf=[]\nfor x in k2:\n\tf.append(float(tot/num+e-c[x]))\ng=0\nfor x in k2:\n\tif f[x]<0: g=g-1\n\nif g<0:\n\tprint('-1')\nelse:\n\tfor x in k2:\n\t\tprint('%.6f'%f[x])",
"\r\n\r\n\r\nn,k = map(int,input().split())\r\n\r\nt = list(map(int,input().split()))\r\n\r\n\r\n\r\nf = (sum(t)+k)/n\r\n\r\nh=0\r\ny=[]\r\nfor i in t:\r\n a = round( f-i/1,6 )\r\n if a>=-0:\r\n y.append(a)\r\n else:\r\n h+=1\r\n print(-1)\r\n break\r\n\r\nif h==0:\r\n for j in y:\r\n print(j)\r\n",
"n,b=map(int,input().split())\r\nll=list(map(int,input().split()))\r\ns=sum(ll)\r\nif (s+b)/n>=max(ll):\r\n for i in ll:\r\n a=str((((s+b)/n)-i))\r\n a+=\"0\"*(6-(len(a)-a.index(\".\")-1))\r\n print(a)\r\nelse:\r\n print(-1)",
"n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\ns=0\r\nfor j in range(n):\r\n s=s+a[j]\r\ns=s+m\r\ne=s/n\r\nt=0\r\nfor i in range(n):\r\n if e-a[i]>=0:\r\n a[i]=e-a[i]\r\n else:\r\n print(-1)\r\n t=1\r\n break\r\nif t==0:\r\n print(*a,sep=\"\\n\")",
"x=[int(i) for i in input().split()]\r\nn=x[0]\r\ny=[int(i) for i in input().split()]\r\nif x[1]<max(y)*n-sum(y):\r\n print(-1)\r\n raise SystemExit\r\n\r\nfor i in range(n):\r\n s=x[1]/n-y[i]++sum(y)/n\r\n print('%.6f'% s)\r\n",
"\r\nn,b=map(int,input().split())\r\na=list(map(int,input().split()))\r\n\r\ne = max(a)\r\nfor i in range(n):\r\n b = b - (e - a[i])\r\n\r\nif b<0:\r\n print(-1)\r\nelse:\r\n to_add = b/n\r\n for i in range(n):\r\n print(\"%.9f\"%(e-a[i]+to_add))",
"n , b = map(int, input().split())\na = list(map(int, input().split()))\n# print(n, b, a)\nb += sum(a)\n# print(n, b, a)\nb /= n;\n# print(n, b, a)\npossible = True\nfor i in range(len(a)):\n a[i] = b - a[i]\n if a[i] < 0:\n possible = False\n# print(n, b, a)\nif possible:\n print(*a, sep='\\n')\nelse:\n print(-1)\n",
"n,b=map(int,input().split())\r\na=list(map(int,input().strip().split()))\r\navg1=b/n\r\navg2=sum(a)/n\r\nans=[0]*n\r\nf=0\r\nfor i in range(n):\r\n ans[i]=format(avg2-a[i]+avg1,\".6f\")\r\n if float(ans[i])<0:\r\n f=1\r\n break\r\nif f==1:print(-1)\r\nelse:\r\n for x in ans:\r\n print(x)",
"n,b=map(int,input().split())\r\na=list(map(int,input().split()))\r\nsumm=sum(a)+b\r\nhehe=max(a)*n-sum(a)\r\nif b<hehe:\r\n print('-1')\r\nelse:\r\n for i in a:\r\n he=(summ/n)-i\r\n form=\"{0:.6f}\".format(he)\r\n print(form)\r\n\r\n",
"strLine = input()\r\nstrLineSplit = strLine.split()\r\nnNum = int(strLineSplit[0])\r\nfBig = float(strLineSplit[1])\r\n\r\nstrLine = input()\r\nstrLineSplit = strLine.split()\r\nlList = []\r\nfor str in strLineSplit:\r\n lList.append(float(str))\r\n\r\nfMax = max(lList)\r\n\r\nfSum = 0.0\r\nfor i in lList :\r\n fSum += fMax - i\r\n\r\nif fSum > fBig :\r\n print('-1')\r\nelse :\r\n fLa = (fBig - fSum) / nNum\r\n for i in lList :\r\n print('%.6f' % (fLa + fMax - i))\r\n",
"I = lambda: map(int, input().split())\r\n\r\nn, b = I()\r\nA = list(I())\r\nx = (b+sum(A)) / n\r\n\r\nif x < max(A):\r\n print(-1)\r\nelse:\r\n print(*(x-a for a in A), sep='\\n')",
"I=lambda:map(int,input().split())\r\nP=print\r\nn,b=I()\r\na=list(I())\r\nx=(b+sum(a))/n\r\nif any(i>x for i in a):P(-1)\r\nelse:[P(x-i)for i in a]",
"import math\r\n\r\n\r\ndef main_function():\r\n n, b = [int(i) for i in input().split(\" \")]\r\n a = [int(i) for i in input().split(\" \")]\r\n adder = 0\r\n max_a = max(a)\r\n for i in a:\r\n adder += max_a - i\r\n if adder > b:\r\n print(-1)\r\n else:\r\n b -= adder\r\n z = b / n\r\n for i in a:\r\n print(max_a + z - i)\r\n\r\n\r\nmain_function()",
"def readString():\n return input().split(\" \")\n\ndef readInts():\n return list(map(lambda s: int(s), readString()))\n\ndef readInt():\n return int(input())\n\ndef intsToString(ints):\n return \" \".join(intsToStrings(ints))\n\ndef intsToStrings(ints):\n return list(map(lambda i: str(i), ints))\n\n\n#Задача на равенство\n\nn, rest = tuple(readInts())\na = readInts()\n\none = (sum(a) + rest)/n\n\nif max(a) > one:\n print(-1)\nelse:\n for i in a:\n print(format(one - i, '.6f'))\n",
"n, b = map(int, input().split())\r\nb = float(b)\r\na = list(map(float, input().split()))\r\nmx = max(a)\r\na = [mx - i for i in a]\r\ns = sum(a)\r\n\r\nif s > b:\r\n print(-1)\r\nelse:\r\n k = (b-s)/n\r\n for i in a:\r\n print(i+k)\r\n",
"n, b = map(int,input().split(' '))\r\narr = list(map(int,input().split(' ')))\r\n\r\narr_max = max(arr)\r\narr_up = []\r\nfor i in range(n):\r\n up = arr_max - arr[i]\r\n if b - up >= 0:\r\n arr_up.append(up) \r\n b -= up\r\n else:\r\n print(-1)\r\n break\r\nelse:\r\n up = b / n\r\n for a in arr_up:\r\n print(a + up)",
"n,b=map(int,input().split())\r\nlst=list(map(int,input().split()))\r\nmx=max(lst)\r\nfor i,x in enumerate(lst):b-=(mx-x)\r\nif b<0:print(-1)\r\nelse:\r\n b=b/n\r\n for i,x in enumerate(lst):print(\"%6.6f\"%(mx+b-x))",
"from math import inf,sqrt,floor,ceil\r\nfrom collections import Counter,defaultdict,deque\r\nfrom heapq import heappush as hpush,heappop as hpop,heapify as h\r\nfrom operator import itemgetter\r\nfrom itertools import product\r\nfrom bisect import bisect_left,bisect_right\r\n\r\n\r\n#for _ in range(int(input())):\r\n#n=int(input())\r\nn,b=map(int,input().split( ))\r\na=list(map(int,input().split( )))\r\nequal=(sum(a)+b)/n\r\nif equal<max(a):\r\n print(-1)\r\nelse:\r\n for i in range(n):\r\n ans=str(equal-a[i])\r\n i=ans.index('.')\r\n if len(ans[i:])<6:\r\n ans+='0'*(6-len(ans[i:])+1)\r\n print(ans)\r\n \r\n",
"n,k = map(int, input().strip().split(' '))\r\nlst = list(map(int, input().strip().split(' ')))\r\nm=max(lst)\r\nlst2=[]\r\ns=0\r\nfor i in range(n):\r\n lst2.append(m-lst[i])\r\n s+=m-lst[i]\r\nif s>k:\r\n print(-1)\r\nelse:\r\n k-=s\r\n k=k/n\r\n for i in range(n):\r\n print(\"{0:.6f}\".format(k+lst2[i]))\r\n",
"n, b = map(int, input().split())\r\na = list(map(int, input().split()))\r\nd = sum(a)\r\nf = (b + d) / n\r\nif any(a[i] > f for i in range(n)):\r\n print(-1)\r\nelse:\r\n for i in range(n):\r\n print(round(f - a[i], 6))",
"n,t=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nX=float((sum(l)+t)/n )\r\n#print(X)\r\nfor i in l:\r\n if(i>X):\r\n print(-1)\r\n break\r\nelse:\r\n for i in l:\r\n print(\"{0:.6f}\".format(X-i))\r\n",
"a,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nif (max(l)*a)-sum(l)>b:\r\n print(-1)\r\nelse:\r\n for i in l:\r\n print((sum(l)+b)/a-i)",
"n, b = map(int, input().split())\r\na = list(map(int, input().split()))\r\nmax_volume = max(a)\r\ntotal = sum(max_volume - x for x in a)\r\nif total > b:\r\n print(-1)\r\nelse:\r\n for x in a:\r\n print(f\"{max_volume - x + (b - total) / n:.6f}\")\r\n",
"n, b = map(int, input().split())\na = list(map(int, input().split()))\nm = max(a)\nd = 0\nfor x in a:\n d += (m - x)\nif d > b:\n print(-1)\nelse:\n b -= d\n m = m + (b / n)\n for x in a:\n print(m-x)",
"n,t=map(int,input().split())\r\na=list(map(int,input().split()))\r\nX=float((sum(a)+t)/n)\r\nfor i in a:\r\n if(i>X):\r\n print(-1)\r\n break\r\nelse:\r\n for i in a:\r\n print(\"{0:.6f}\".format(X-i))\r\n",
"n,b = map(int,input().split())\r\na = list(map(int,input().split()))\r\ntot = sum(a) + b\r\nok = 1\r\nans = []\r\nfor i in range(n):\r\n ans.append(tot/n - a[i])\r\n if ans[-1] < 0: \r\n print(-1)\r\n break\r\nelse:\r\n print(*ans, sep = \"\\n\")",
"def f(l1,al):\r\n n,b = l1\r\n c = (sum(al) + b)/n\r\n if max(al)>c:\r\n return [-1]\r\n return [c-a for a in al]\r\n\r\nl1 = list(map(int,input().split()))\r\nl2 = list(map(int,input().split()))\r\n[print(r) for r in f(l1,l2)]\r\n",
"n, b = map(int, input().split())\r\nl = list(map(int, input().split()))\r\n\r\ns = sum(l)\r\n\r\nx = []\r\n\r\nfor i in l:\r\n\tv = (((s + b) / n) - i)\r\n\t\r\n\tif v >= 0:\r\n\t\tx.append(f\"{v:.6f}\")\r\n\telse:\r\n\t\tx = [\"-1\"]\r\n\t\tbreak\r\n\t\t\r\nprint(\"\\n\".join(x))",
"def get_ints():\r\n return map(int, input().strip().split())\r\n\r\ndef get_list():\r\n return list(map(int, input().strip().split()))\r\n\r\ndef get_string():\r\n return input().strip()\r\n\r\nfor t in range(1):\r\n n, b = get_ints()\r\n arr = get_list()\r\n \r\n k = (sum(arr) + b)/n\r\n ans = []\r\n sol = True\r\n \r\n for i in arr:\r\n ans.append(k - i)\r\n if ans[-1] < 0:\r\n sol = False\r\n break\r\n \r\n if sol:\r\n for i in ans:\r\n print(i)\r\n else:\r\n print(\"-1\")\r\n \r\n \r\n \r\n\r\n ",
"n, b = map(int, input().split())\r\ns = list(map(int, input().split()))\r\n\r\nx = (sum(s) + b)/ n\r\nif x < max(s):\r\n print(-1)\r\nelse:\r\n for e in s:\r\n print('%.8f' % (x - e))\r\n\r\n\r\n\r\n\r\n",
"#\r\n# 24.06.2021\r\n\n#\n\r\n\r\nss = (input ()).split ()\r\n\nn = int (ss [0])\n\r\nb = int (ss [1])\r\n\n\n\r\nss = (input ()).split ()\r\n\na = [0]*n\n\r\nsum = 0\n\r\nmax = a [0]\r\n\nfor i in range (0, n) :\r\n\n a [i] = int (ss [i])\r\n\n sum += a [i]\n\r\n if ( a [i] > max ) :\r\n\n max = a [i]\n\n\r\n\r\nc = (sum + b) / n\r\n\r\n\n\nif ( max > c ) :\r\n\n print(\"-1\")\n\r\nelse :\r\n\n for i in range (0, n) :\n\r\n print (c - a [i])\n",
"m=input()\r\nl1=list(map(int,m.split()))\r\nn=input()\r\nl2=list(map(int,n.split()))\r\ns1=sum(l2)\r\nd=(s1+l1[1])/l1[0]\r\nl=[]\r\nfor i in range(len(l2)):\r\n l.append(d-l2[i])\r\nsum=0\r\nfor i in l:\r\n if(i<0):\r\n sum=sum+1\r\nif(sum!=0):\r\n print(\"-1\")\r\nelse:\r\n for item in l:\r\n print(\"{:.6f}\".format(item))\r\n\r\n\r\n\r\n\r\n\r\n",
"n, b = tuple([int(x) for x in input().split()])\narr = [int(x) for x in input().split()]\nmax_arr = max(arr)\nneeded = sum([max_arr - x for x in arr])\nif(needed > b):\n\tprint(\"-1\")\nelse:\n\ttarget = (b + sum(arr)) / n\n\tto_pour = [target - x for x in arr]\n\tfor element in to_pour:\n\t\tprint(\"%f\"%(element))\n",
"def main():\r\n n, b = map(int, input().split())\r\n a = [int(c) for c in input().split()]\r\n\r\n mx = max(a)\r\n\r\n res = [0] * n\r\n for i in range(len(a)):\r\n res[i] = mx - a[i]\r\n b -= res[i]\r\n\r\n if b < 0:\r\n print(-1)\r\n return\r\n\r\n d = b / n\r\n for i in range(len(res)):\r\n print(res[i] + d)\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn, b = input().split()\r\nn, b = int(n), int(b)\r\narr = list(map(int, input().split()))\r\ntotal = b + sum(arr)\r\nif total / n < max(arr):\r\n print(-1)\r\nelse:\r\n for elem in arr:\r\n print(float(total/n - elem))",
"n, b = map(int, input().split())\r\nmas = list(map(int, input().split()))\r\ntot = sum(mas)\r\navg = round((tot + b) / n, 6)\r\nans = []\r\n\r\nfor i in range(n):\r\n tmp = round(avg - mas[i], 6)\r\n if tmp < 0:\r\n print(-1)\r\n exit(0)\r\n b -= tmp\r\n ans.append(tmp)\r\neps = 10 ** -3\r\nif b < eps:\r\n for i in ans:\r\n print(i)\r\nelse:\r\n print(-1)\r\n\r\n",
"import sys\r\n\r\ndef get_int():\r\n\treturn int(sys.stdin.readline())\r\n\r\ndef get_string():\r\n\treturn sys.stdin.readline().strip()\r\n\r\nFILE=False\r\nif FILE:\r\n sys.stdin=open('input.txt','r')\r\n sys.stdout=open('output.txt','w')\r\ndata=get_string().split()\r\nn_friends=int(data[0])\r\nb_bottle=int(data[1])\r\ndata2=get_string().split()\r\nmugs=[]\r\ntotal_volume=b_bottle\r\nfor i in range(0,n_friends):\r\n mugs.append(int(data2[i]))\r\n total_volume=total_volume+int(mugs[i])\r\nfinal_configuration=total_volume/n_friends\r\nanswer=[]\r\nfor i in range(0,n_friends):\r\n vol=final_configuration-int(mugs[i])\r\n if vol<0:\r\n sys.stdout.write('-1')\r\n sys.exit()\r\n vol='{0:.6f}'.format(vol)\r\n answer.append(vol)\r\nfor item in answer:\r\n\tsys.stdout.write(item)\r\n\tsys.stdout.write('\\n')",
"N, S = map(int, input().split())\r\nA = list(map(int, input().split()))\r\n\r\nave = (S + sum(A)) / N\r\n\r\nans = []\r\n\r\nfor a in A:\r\n if a > ave: \r\n ans.append(-1)\r\n break\r\n else:\r\n ans.append(ave - a)\r\n \r\n\r\nif ans[-1] == -1:\r\n print(-1)\r\n \r\nelse:\r\n for a in ans:\r\n print(\"%.6f\" % a)",
"import math\r\nn,b=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nm=max(a)\r\nx=s=0\r\nfor i in range(n):\r\n x+=(m-a[i])\r\nif x>b:\r\n print(-1)\r\nelse:\r\n av=(b+sum(a))/n\r\n for item in a:\r\n print(\"{0:.6f}\".format(av-item))\r\n",
"n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nv=max(a)\r\nans=0\r\nfor i in a:\r\n ans+=v-i \r\nif(ans>k):\r\n print(-1)\r\nelse:\r\n k=k-ans \r\n k=k/n\r\n for i in a:\r\n print(v-i+k)",
"n, b = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nb += sum(a)\r\n\r\nif max(a) > b / n: print(-1)\r\nelse:\r\n for i in range(n): print(\"{:f}\".format(b / n - a[i]))\r\n",
"n, b = map(int, input().split())\r\na = list(map(int, input().split()))\r\nt = (sum(a) + b) / n\r\nans = [t - i for i in a]\r\nif any(i < 0 for i in ans):\r\n print(-1)\r\nelse:\r\n for i in ans:\r\n print(i)\r\n",
"from math import modf\r\n \r\n(n, b) = map(int,input().split())\r\nmugs = list(map(int,input().split()))\r\n\r\ndef isOk(array):\r\n for i in array:\r\n if i<0:\r\n return 0\r\n else:\r\n return 1\r\n \r\ndef print_the_given_array(array):\r\n if isOk(array):\r\n for i in array:\r\n print(\"%.6f\" %i)\r\n else:\r\n print(-1)\r\n \r\nx = sum(mugs) + b \r\n \r\navg = x/n \r\nmugs = [avg-x for x in mugs ]\r\nprint_the_given_array(mugs)",
"a,b=map(int,input().split())\r\nx=[int(q) for q in input().split()]\r\n\r\nl=sum(x)\r\ntotal = l+b\r\neach = total/a\r\n\r\nreqd=0\r\nz=max(x)\r\nfor i in range(a):\r\n reqd+=abs(x[i]-z)\r\nif b<reqd:\r\n print(-1)\r\nelse:\r\n for i in range(a):\r\n print(each-x[i])",
"n, bottle = map(int, input().split())\r\nglasses = list(map(int, input().split()))\r\n\r\ntotal = bottle + sum(glasses)\r\naggregate = total / n\r\nis_real = True\r\nglasses_add = []\r\nfor i in range(n):\r\n if glasses[i] > aggregate:\r\n is_real = False\r\n break\r\n else:\r\n glasses_add.append(aggregate - glasses[i])\r\n\r\nif is_real == False:\r\n print(-1)\r\nelse:\r\n for i in range(n):\r\n print(format(glasses_add[i], '.6f'))\r\n"
] | {"inputs": ["5 50\n1 2 3 4 5", "2 2\n1 100", "2 2\n1 1", "3 2\n1 2 1", "3 5\n1 2 1", "10 95\n0 0 0 0 0 1 1 1 1 1", "3 5\n1 2 3", "3 5\n1 3 2", "3 5\n2 1 3", "3 5\n2 3 1", "3 5\n3 1 2", "3 5\n3 2 1", "2 1\n1 1", "2 1\n2 2", "3 2\n2 1 2", "3 3\n2 2 1", "3 3\n3 1 2", "100 100\n37 97 75 52 33 29 51 22 33 37 45 96 96 60 82 58 86 71 28 73 38 50 6 6 90 17 26 76 13 41 100 47 17 93 4 1 56 16 41 74 25 17 69 61 39 37 96 73 49 93 52 14 62 24 91 30 9 97 52 100 6 16 85 8 12 26 10 3 94 63 80 27 29 78 9 48 79 64 60 18 98 75 81 35 24 81 2 100 23 70 21 60 98 38 29 29 58 37 49 72", "100 100\n1 3 7 7 9 5 9 3 7 8 10 1 3 10 10 6 1 3 10 4 3 9 4 9 5 4 9 2 8 7 4 3 3 3 5 10 8 9 10 1 9 2 4 8 3 10 9 2 3 9 8 2 4 4 4 7 1 1 7 3 7 8 9 5 1 2 6 7 1 10 9 10 5 10 1 10 5 2 4 3 10 1 6 5 6 7 8 9 3 8 6 10 8 7 2 3 8 6 3 6", "100 61\n81 80 83 72 87 76 91 92 77 93 77 94 76 73 71 88 88 76 87 73 89 73 85 81 79 90 76 73 82 93 79 93 71 75 72 71 78 85 92 89 88 93 74 87 71 94 74 87 85 89 90 93 86 94 92 87 90 91 75 73 90 84 92 94 92 79 74 85 74 74 89 76 84 84 84 83 86 84 82 71 76 74 83 81 89 73 73 74 71 77 90 94 73 94 73 75 93 89 84 92", "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "100 100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100 100\n99 100 99 100 100 100 99 99 99 100 100 100 99 100 99 100 100 100 100 100 99 99 99 99 100 99 100 99 100 99 99 100 100 100 100 100 99 99 99 100 99 99 100 99 100 99 100 99 99 99 99 100 100 99 99 99 100 100 99 100 100 100 99 99 100 100 100 100 100 100 99 99 99 99 99 100 99 99 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 100 99 100 100 100 100 99", "100 100\n100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100", "100 100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99", "10 100\n52 52 51 52 52 52 51 51 52 52", "10 100\n13 13 13 13 12 13 12 13 12 12", "10 100\n50 51 47 51 48 46 49 51 46 51", "10 100\n13 13 9 12 12 11 13 8 10 13", "93 91\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "93 97\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "91 99\n99 100 100 100 99 100 100 100 99 100 99 99 100 99 100 100 100 99 99 100 99 100 100 100 100 100 99 99 100 99 100 99 99 100 100 100 100 99 99 100 100 100 99 100 100 99 100 100 99 100 99 99 99 100 99 99 99 100 99 100 99 100 99 100 99 99 100 100 100 100 99 100 99 100 99 99 100 100 99 100 100 100 100 99 99 100 100 99 99 100 99", "99 98\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "98 99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 100 99 99 99 99 99", "13 97\n52 52 51 51 52 52 51 52 51 51 52 52 52", "17 99\n13 13 12 13 11 12 12 12 13 13 11 13 13 13 13 12 13", "9 91\n52 51 50 52 52 51 50 48 51", "17 91\n13 13 13 13 12 12 13 13 12 13 12 13 10 12 13 13 12", "2 3\n1 1", "2 90\n0 89", "4 17\n3 4 8 1", "2 9\n5 5", "7 28\n1 3 9 10 9 6 10", "5 11\n1 2 3 4 5", "2 1\n1 1", "5 3\n1 1 1 1 1", "3 1\n100 100 100", "5 50\n2 2 3 2 2", "3 3\n2 2 3", "2 52\n2 100", "3 2\n2 2 3", "5 1\n1 1 1 1 1", "2 4\n1 2", "5 49\n1 2 3 4 5"], "outputs": ["12.000000\n11.000000\n10.000000\n9.000000\n8.000000", "-1", "1.000000\n1.000000", "1.000000\n0.000000\n1.000000", "2.000000\n1.000000\n2.000000", "10.000000\n10.000000\n10.000000\n10.000000\n10.000000\n9.000000\n9.000000\n9.000000\n9.000000\n9.000000", "2.666667\n1.666667\n0.666667", "2.666667\n0.666667\n1.666667", "1.666667\n2.666667\n0.666667", "1.666667\n0.666667\n2.666667", "0.666667\n2.666667\n1.666667", "0.666667\n1.666667\n2.666667", "0.500000\n0.500000", "0.500000\n0.500000", "0.333333\n1.333333\n0.333333", "0.666667\n0.666667\n1.666667", "0.000000\n2.000000\n1.000000", "-1", "-1", "-1", "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1...", "1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1.000000\n1...", "1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n0.530000\n0.530000\n0.530000\n0.530000\n1.530000\n1.530000\n1.530000\n0.530000\n1.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n0.530000\n1.530000\n1.530000\n1.530000\n1.530000\n0...", "0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n1.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0.940000\n0...", "1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n1.020000\n0.020000\n1.020000\n1...", "9.700000\n9.700000\n10.700000\n9.700000\n9.700000\n9.700000\n10.700000\n10.700000\n9.700000\n9.700000", "9.600000\n9.600000\n9.600000\n9.600000\n10.600000\n9.600000\n10.600000\n9.600000\n10.600000\n10.600000", "9.000000\n8.000000\n12.000000\n8.000000\n11.000000\n13.000000\n10.000000\n8.000000\n13.000000\n8.000000", "8.400000\n8.400000\n12.400000\n9.400000\n9.400000\n10.400000\n8.400000\n13.400000\n11.400000\n8.400000", "0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0.978495\n0...", "1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1.043011\n1...", "1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n0.648352\n1.648352\n1.648352\n0.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n0.648352\n1.648352\n0.648352\n1.648352\n1...", "0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n1.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0.979798\n0...", "1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n1.051020\n0.051020\n1.051020\n1...", "7.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n8.076923\n7.076923\n8.076923\n8.076923\n7.076923\n7.076923\n7.076923", "5.294118\n5.294118\n6.294118\n5.294118\n7.294118\n6.294118\n6.294118\n6.294118\n5.294118\n5.294118\n7.294118\n5.294118\n5.294118\n5.294118\n5.294118\n6.294118\n5.294118", "8.888889\n9.888889\n10.888889\n8.888889\n8.888889\n9.888889\n10.888889\n12.888889\n9.888889", "4.823529\n4.823529\n4.823529\n4.823529\n5.823529\n5.823529\n4.823529\n4.823529\n5.823529\n4.823529\n5.823529\n4.823529\n7.823529\n5.823529\n4.823529\n4.823529\n5.823529", "1.500000\n1.500000", "89.500000\n0.500000", "5.250000\n4.250000\n0.250000\n7.250000", "4.500000\n4.500000", "9.857143\n7.857143\n1.857143\n0.857143\n1.857143\n4.857143\n0.857143", "4.200000\n3.200000\n2.200000\n1.200000\n0.200000", "0.500000\n0.500000", "0.600000\n0.600000\n0.600000\n0.600000\n0.600000", "0.333333\n0.333333\n0.333333", "10.200000\n10.200000\n9.200000\n10.200000\n10.200000", "1.333333\n1.333333\n0.333333", "-1", "1.000000\n1.000000\n0.000000", "0.200000\n0.200000\n0.200000\n0.200000\n0.200000", "2.500000\n1.500000", "11.800000\n10.800000\n9.800000\n8.800000\n7.800000"]} | UNKNOWN | PYTHON3 | CODEFORCES | 60 | |
2b7abc2a0c81c17cc233bb6a548d4284 | Petya and Spiders | Little Petya loves training spiders. Petya has a board *n*<=×<=*m* in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform its commands. There are 5 possible commands: to stay idle or to move from current cell to some of the four side-neighboring cells (that is, one command for each of the four possible directions). Petya gives the commands so that no spider leaves the field. It is allowed for spiders to pass through each other when they crawl towards each other in opposite directions. All spiders crawl simultaneously and several spiders may end up in one cell. Petya wants to know the maximum possible number of spider-free cells after one second.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=40,<=*n*·*m*<=≤<=40) — the board sizes.
In the first line print the maximum number of cells without spiders.
Sample Input
1 1
2 3
Sample Output
0
4
| [
"maxn = 7\r\nd = [[-1 for _ in range(1 << (2 * maxn))] for _ in range(57)]\r\nnbits = [0] * 100500\r\ndef ok(x, x3):\r\n x2 = (x & ((1 << m) - 1))\r\n x >>= m\r\n x1 = x\r\n x = 0\r\n x |= x1\r\n x |= x2\r\n x |= (x2 << 1)\r\n x |= (x2 >> 1)\r\n x |= x3\r\n return (x & ((1 << m) - 1)) == ((1 << m) - 1)\r\nfor i in range(1 << (2 * maxn)):\r\n x, y = i, 0\r\n while x:\r\n y += x % 2\r\n x //= 2\r\n nbits[i] = y\r\nn, m = map(int, input().split())\r\nif n < m:\r\n n, m = m, n\r\nfor mask in range(1 << m):\r\n d[0][mask] = m - nbits[mask]\r\nfor i in range(n - 1):\r\n for mask in range(1 << (2 * m)):\r\n if d[i][mask] == -1:\r\n continue\r\n for nm in range(1 << m):\r\n if ok(mask, nm):\r\n x = d[i][mask] + m - nbits[nm]\r\n msk = ((mask & ((1 << m) - 1)) << m) + nm\r\n d[i + 1][msk] = max(d[i + 1][msk], x)\r\nres = 0\r\nfor i in range(1 << (2 * m)):\r\n if d[n - 1][i] != -1 and ok(i, 0):\r\n res = max(res, d[n - 1][i])\r\nprint(res)# 1691433031.1881988"
] | {"inputs": ["1 1", "2 3", "4 1", "4 2", "4 3", "4 4", "1 40", "1 1", "1 2", "1 3", "1 4", "1 5", "1 6", "1 7", "1 8", "1 9", "1 10", "1 11", "1 12", "1 13", "1 14", "1 15", "1 16", "1 17", "1 18", "1 19", "1 20", "1 21", "1 22", "1 23", "1 24", "1 25", "1 26", "1 27", "1 28", "1 29", "1 30", "1 31", "1 32", "1 33", "1 34", "1 35", "1 36", "1 37", "1 38", "1 39", "1 40", "2 1", "2 2", "2 3", "2 4", "2 5", "2 6", "2 7", "2 8", "2 9", "2 10", "2 11", "2 12", "2 13", "2 14", "2 15", "2 16", "2 17", "2 18", "2 19", "2 20", "3 1", "3 2", "3 3", "3 4", "3 5", "3 6", "3 7", "3 8", "3 9", "3 10", "3 11", "3 12", "3 13", "4 1", "4 2", "4 3", "4 4", "4 5", "4 6", "4 7", "4 8", "4 9", "4 10", "5 1", "5 2", "5 3", "5 4", "5 5", "5 6", "5 7", "5 8", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6", "7 1", "7 2", "7 3", "7 4", "7 5", "8 1", "8 2", "8 3", "8 4", "8 5", "9 1", "9 2", "9 3", "9 4", "10 1", "10 2", "10 3", "10 4", "11 1", "11 2", "11 3", "12 1", "12 2", "12 3", "13 1", "13 2", "13 3", "14 1", "14 2", "15 1", "15 2", "16 1", "16 2", "17 1", "17 2", "18 1", "18 2", "19 1", "19 2", "20 1", "20 2", "21 1", "22 1", "23 1", "24 1", "25 1", "26 1", "27 1", "28 1", "29 1", "30 1", "31 1", "32 1", "33 1", "34 1", "35 1", "36 1", "37 1", "38 1", "39 1", "40 1"], "outputs": ["0", "4", "2", "5", "8", "12", "26", "0", "1", "2", "2", "3", "4", "4", "5", "6", "6", "7", "8", "8", "9", "10", "10", "11", "12", "12", "13", "14", "14", "15", "16", "16", "17", "18", "18", "19", "20", "20", "21", "22", "22", "23", "24", "24", "25", "26", "26", "1", "2", "4", "5", "7", "8", "10", "11", "13", "14", "16", "17", "19", "20", "22", "23", "25", "26", "28", "29", "2", "4", "6", "8", "11", "13", "15", "17", "20", "22", "24", "26", "29", "2", "5", "8", "12", "14", "17", "21", "24", "26", "30", "3", "7", "11", "14", "18", "22", "26", "29", "4", "8", "13", "17", "22", "26", "4", "10", "15", "21", "26", "5", "11", "17", "24", "29", "6", "13", "20", "26", "6", "14", "22", "30", "7", "16", "24", "8", "17", "26", "8", "19", "29", "9", "20", "10", "22", "10", "23", "11", "25", "12", "26", "12", "28", "13", "29", "14", "14", "15", "16", "16", "17", "18", "18", "19", "20", "20", "21", "22", "22", "23", "24", "24", "25", "26", "26"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2b86cf8aaf86f541b96b91d680b154cb | Help Shrek and Donkey | Shrek and the Donkey (as you can guess, they also live in the far away kingdom) decided to play a card game called YAGame. The rules are very simple: initially Shrek holds *m* cards and the Donkey holds *n* cards (the players do not see each other's cards), and one more card lies on the table face down so that both players cannot see it as well. Thus, at the beginning of the game there are overall *m*<=+<=*n*<=+<=1 cards. Besides, the players know which cards the pack of cards consists of and their own cards (but they do not know which card lies on the table and which ones the other player has). The players move in turn and Shrek starts. During a move a player can:
- Try to guess which card is lying on the table. If he guesses correctly, the game ends and he wins. If his guess is wrong, the game also ends but this time the other player wins.- Name any card from the pack. If the other player has such card, he must show it and put it aside (so that this card is no longer used in the game). If the other player doesn't have such card, he says about that.
Help Shrek assuming the pills are good in quality and that both players using them start playing in the optimal manner.
The first line contains space-separated integers *m* and *n* (0<=≤<=*m*,<=*n*<=≤<=1000).
Print space-separated probabilities that Shrek wins and Donkey wins correspondingly; the absolute error should not exceed 10<=-<=9.
Sample Input
0 3
1 0
1 1
Sample Output
0.25 0.75
1 0
0.5 0.5
| [
"N, M = map(int, input().split())\r\nK = max(N, M)\r\ndp = [[-1e8 for j in range(K + 1)] for i in range(K + 1)]\r\n\r\nfor i in range(K + 1):\r\n\tdp[0][i] = 1 / (1 + i)\r\n\tdp[i][0] = 1\r\nfor s in range(2, 2 * K + 1):\r\n\tn, m = 1, s - 1\r\n\twhile n < s:\r\n\t\tif not (K < n or K < m):\r\n\t\t\tassert dp[m - 1][n] != -1e8\r\n\t\t\tassert dp[m][n - 1] != -1e8\r\n\t\t\ta = m / (m + 1) * (1 - dp[m - 1][n])\r\n\t\t\tc = 1 / (m + 1)\r\n\t\t\tb = c + a\r\n\t\t\td = 1 - dp[m][n - 1]\r\n\t\t\tp = (d - 1) / (a - 1 + d - b)\r\n\t\t\tdp[n][m] = a * p + 1 - p\r\n\t\tn += 1\r\n\t\tm -= 1\r\nprint(dp[N][M], 1 - dp[N][M])"
] | {"inputs": ["0 3", "1 0", "1 1", "0 0", "2 0", "0 1", "0 2", "1 2", "2 1", "2 2", "863 814", "593 676", "124 830", "582 865", "458 81", "969 527", "886 340", "869 326", "292 760", "999 929", "528 716", "290 221", "863 620", "797 754", "915 183", "8 145", "176 38", "945 457", "997 971", "44 932", "230 840", "995 646", "466 342", "145 335", "517 420", "439 413", "316 728", "278 404", "971 394", "417 892", "986 24", "476 782", "239 959", "494 199", "526 180", "910 118", "400 529", "828 272", "115 466", "904 473", "933 930", "356 979", "775 436", "351 552", "383 81", "767 536", "927 443", "877 752", "813 407", "908 693", "811 84", "745 382", "835 167", "682 764", "61 116", "379 170", "893 849", "140 573", "112 499", "496 549", "187 438", "381 84", "504 693", "599 431", "989 945", "971 413", "461 331", "936 101", "143 959", "817 90", "864 0", "984 0", "561 0", "288 0", "416 0", "0 51", "0 45", "0 851", "0 351", "0 832", "257 1000", "327 1000", "785 1000", "314 1000", "521 1000", "1000 110", "1000 493", "1000 897", "1000 32", "1000 1000"], "outputs": ["0.2500000000000000 0.7500000000000000", "1.0000000000000000 0.0000000000000000", "0.5000000000000000 0.5000000000000000", "1.0000000000000000 0.0000000000000000", "1.0000000000000000 0.0000000000000000", "0.5000000000000000 0.5000000000000000", "0.3333333333333333 0.6666666666666667", "0.5000000000000000 0.5000000000000000", "0.6666666666666667 0.3333333333333333", "0.5555555555555556 0.4444444444444445", "0.5276200278934561 0.4723799721065439", "0.4424015525217101 0.5575984474782899", "0.0953414587193146 0.9046585412806855", "0.3425732635446256 0.6574267364553744", "0.8845491519873723 0.1154508480126277", "0.7215811345992123 0.2784188654007878", "0.7979217892875509 0.2020782107124492", "0.8018568566832087 0.1981431433167913", "0.2048964940792572 0.7951035059207428", "0.5341268008319124 0.4658731991680876", "0.3748204717131547 0.6251795282868453", "0.6101220421882655 0.3898779578117345", "0.6364521382599542 0.3635478617400458", "0.5262188409949206 0.4737811590050795", "0.8842865801642701 0.1157134198357299", "0.1024062982090509 0.8975937017909491", "0.8460331298315647 0.1539668701684353", "0.7505320048782014 0.2494679951217987", "0.5129154747745227 0.4870845252254772", "0.0504572758127267 0.9495427241872734", "0.1518922661058743 0.8481077338941256", "0.6705883638280096 0.3294116361719904", "0.6262428633441572 0.3737571366558427", "0.2385967565862941 0.7614032434137059", "0.5893460835202820 0.4106539164797181", "0.5282979431644124 0.4717020568355876", "0.2289941744785965 0.7710058255214035", "0.3553552485610654 0.6446447514389346", "0.7881032502577910 0.2118967497422090", "0.2431983869698381 0.7568016130301619", "0.9602291344083390 0.0397708655916610", "0.3121578144498619 0.6878421855501382", "0.1389465829388951 0.8610534170611048", "0.7832163791968516 0.2167836208031484", "0.8121571361695676 0.1878428638304324", "0.9157417404948328 0.0842582595051672", "0.3855660591427622 0.6144339408572379", "0.8235052119879621 0.1764947880120379", "0.1481169020875285 0.8518830979124715", "0.7311570334143406 0.2688429665856594", "0.5020349245008455 0.4979650754991545", "0.1927153080820126 0.8072846919179874", "0.7112726905771168 0.2887273094228831", "0.3277875683152701 0.6722124316847299", "0.8661760153892093 0.1338239846107907", "0.6454773325210086 0.3545226674789914", "0.7531609922031890 0.2468390077968110", "0.5690585809577738 0.4309414190422261", "0.7413726394428866 0.2586273605571135", "0.6148786953306118 0.3851213046693882", "0.9253912917590257 0.0746087082409743", "0.7349508761172829 0.2650491238827171", "0.8832155725457145 0.1167844274542855", "0.4494589507746312 0.5505410492253688", "0.3044180326794833 0.6955819673205167", "0.7587191030678759 0.2412808969321241", "0.5240293332658378 0.4759706667341623", "0.1435260487631065 0.8564739512368935", "0.1369030739746874 0.8630969260253126", "0.4556254692028442 0.5443745307971558", "0.2316723204029031 0.7683276795970969", "0.8621493892197305 0.1378506107802695", "0.3700982261347415 0.6299017738652585", "0.6343903812186339 0.3656096187813661", "0.5217673947588907 0.4782326052411093", "0.7787240715751295 0.2212759284248705", "0.6337385838340505 0.3662614161659495", "0.9255659559790833 0.0744340440209166", "0.0932096071577605 0.9067903928422395", "0.9226954449092134 0.0773045550907866", "1.0000000000000000 0.0000000000000000", "1.0000000000000000 0.0000000000000000", "1.0000000000000000 0.0000000000000000", "1.0000000000000000 0.0000000000000000", "1.0000000000000000 0.0000000000000000", "0.0192307692307692 0.9807692307692307", "0.0217391304347826 0.9782608695652174", "0.0011737089201878 0.9988262910798123", "0.0028409090909091 0.9971590909090909", "0.0012004801920768 0.9987995198079231", "0.1421267475833342 0.8578732524166658", "0.1751041603600256 0.8248958396399744", "0.3964373963757117 0.6035626036242883", "0.1689449752379237 0.8310550247620764", "0.2681780053273835 0.7318219946726166", "0.9255370262407143 0.0744629737592857", "0.7463393524285148 0.2536606475714852", "0.5500860654670416 0.4499139345329584", "0.9575365847396112 0.0424634152603888", "0.5004843592014406 0.4995156407985593"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2bc3804437ac327173e6ef757e083bb1 | Mike and strings | Mike has *n* strings *s*1,<=*s*2,<=...,<=*s**n* each consisting of lowercase English letters. In one move he can choose a string *s**i*, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".
Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal?
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of strings.
This is followed by *n* lines which contain a string each. The *i*-th line corresponding to string *s**i*. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50.
Print the minimal number of moves Mike needs in order to make all the strings equal or print <=-<=1 if there is no solution.
Sample Input
4
xzzwo
zwoxz
zzwox
xzzwo
2
molzv
lzvmo
3
kc
kc
kc
3
aa
aa
ab
Sample Output
5
2
0
-1
| [
"l = []\r\nfor _ in range(int(input())):\r\n s = input()\r\n l.append({s[i:] + s[:i]: i for i in range(len(s))[::-1]})\r\nr = min(sum(d.get(s, 9999) for d in l) for s in l[0])\r\nprint(r if r < 9999 else -1)\r\n",
"s = []\r\nfor _ in range(int(input())) :\r\n s.append(str(input()))\r\n\r\nans = 10**9\r\navail = True\r\nfor i in s :\r\n c = 0\r\n for j in s :\r\n pat = j + j\r\n x = pat.find(i)\r\n if x < 0 :\r\n avail = False\r\n else :\r\n c += x\r\n ans = min(c, ans)\r\nif avail :\r\n print(ans)\r\nelse :\r\n print(-1)",
"from collections import Counter\r\ndc = {}\r\nindx = {}\r\nlastcheck = []\r\nans = float('inf')\r\nflag = False\r\nrng = int(input())\r\nmyset = set()\r\nlost = []\r\nfor i in range(rng):\r\n s = input()\r\n ln = len(s)\r\n if i>0:\r\n for l in lost:\r\n if s in l:\r\n break\r\n else:\r\n flag = True\r\n lost.append(s+s)\r\n s+=s\r\n for u in range(ln*2):\r\n lst = []\r\n for j in range(u,ln*2):\r\n lst.append(s[j])\r\n put = ''.join(lst)\r\n if put in dc:\r\n dc[put]+=1\r\n indx[put].append(u)\r\n else:\r\n indx[put]=[u]\r\n dc[put]=1\r\ndc = Counter(dc)\r\nfor i in dc:\r\n if dc[i]==rng:\r\n lastcheck.append(indx[i])\r\n if dc[i]==1 and len(i)==1 and rng>1:\r\n flag = True\r\nfor i in lastcheck:\r\n mn = min(i)\r\n mnmn = 0\r\n for b in i:\r\n mnmn+=b-mn\r\n ans = min(ans,mnmn)\r\nprint(ans if not flag else -1)",
"#!/usr/bin/python3\n\"\"\" mike and strings 1300 \"\"\"\n\nfrom unittest import TestCase\nfrom typing import NamedTuple\nfrom typing import List\n\n\nclass Args(NamedTuple):\n \"\"\" arguments \"\"\"\n\n strngs: List[str]\n\n\ndef get_args() -> Args:\n \"\"\" get the input arguments \"\"\"\n\n strngs = []\n for _ in range(int(input())):\n strngs.append(input())\n\n return Args(strngs)\n\n\nclass Test(TestCase):\n \"\"\" test cases \"\"\"\n\n def test_answer(self):\n \"\"\" test the number of changes required given\n a list of strings \"\"\"\n\n temp = [\n 'xzzwo',\n 'zwoxz',\n 'zzwox',\n 'xzzwo'\n ]\n self.assertEqual(answer(temp), 5)\n temp = [\n 'molzv',\n 'lzvmo'\n ]\n self.assertEqual(answer(temp), 2)\n temp = [\n 'kc',\n 'kc',\n 'kc'\n ]\n self.assertEqual(answer(temp), 0)\n temp = [\n 'aa',\n 'aa',\n 'ab'\n ]\n self.assertEqual(answer(temp), -1)\n\n def test_diff(self):\n \"\"\" test the number of changes required given\n two strings \"\"\"\n\n self.assertEqual(diff('xzzwo', 'xzzwo'), 0)\n self.assertEqual(diff('xzzwo', 'zwoxz'), 3)\n self.assertEqual(diff('zwoxz', 'xzzwo'), 2)\n self.assertEqual(diff('xzzwo', 'zzwox'), 4)\n\n\ndef diff(str_1: str, str_2: str) -> int:\n \"\"\" return the number of differences given two strings \"\"\"\n\n for ind in range(len(str_1)):\n if str_1 == str_2[ind:] + str_2[:ind]:\n return ind\n return -1\n\n\ndef answer(strngs: List[str]) -> int:\n \"\"\" return the number of changes required given\n a list of strings \"\"\"\n\n mini = 50**50 + 1\n for str_j in strngs:\n curr = 0\n for str_i in strngs:\n change = diff(str_j, str_i)\n if change >= 0:\n curr += change\n else:\n return -1\n if curr < mini:\n mini = curr\n return mini\n\n\ndef main() -> None:\n \"\"\" do stuff \"\"\"\n\n args = get_args()\n print(answer(args.strngs))\n\n\nif __name__ == '__main__':\n main()\n",
"n=int(input())\r\nar=[]\r\nfor _ in range(n):\r\n s=input()\r\n ar.append(s)\r\nans=float(\"inf\")\r\nf=True\r\nfor i in range(n):\r\n temp=0\r\n p=ar[i]+ar[i]\r\n for j in range(n):\r\n if i!=j:\r\n if ar[j] not in p:\r\n f=False\r\n break\r\n else :\r\n for k,ch in enumerate(p):\r\n if ch==ar[j][0]:\r\n if p[k:len(ar[j])+k]==ar[j]:\r\n ind=k\r\n diff=(len(ar[i])-ind)%(len(ar[j]))\r\n temp+=diff\r\n ans=min(ans,temp)\r\nif not f:\r\n print(-1)\r\nelse:\r\n print(ans)",
"def solve(v):\r\n v2=[]\r\n for s in v:\r\n v2.append( {s[i:] + s[:i]: i for i in range(len(s))[::-1]} )\r\n tmp = min(sum(d.get(s, 9999) for d in v2) for s in v2[0])\r\n \r\n if tmp<9999:\r\n ans=tmp\r\n else:\r\n ans=-1\r\n return ans\r\n\r\nn=int(input())\r\nv=[]\r\nfor i in range(n):\r\n s=input()\r\n v.append(s)\r\nprint(solve(v))\r\n",
"import sys\r\ninput = lambda : sys.stdin.readline().rstrip(\"\\r\\n\")\r\nn = int(input())\r\ns = ['' for _ in range(n)]\r\nt = ['' for _ in range(n)]\r\n\r\nfor i in range(n):\r\n s[i] = input()\r\n t[i] = s[i] + s[i]\r\n\r\nm = len(s[0])\r\nans = 2*n*m\r\n\r\nfor i in range(m):\r\n sums = i\r\n for j in range(1,n):\r\n if t[j].find(t[0][i:i+m]) != -1:\r\n sums += t[j].find(t[0][i:i+m])\r\n else:\r\n ans = -1\r\n \r\n ans = min(ans,sums)\r\n\r\nprint(-1 if ans == -1 or ans == 2*n*m else ans)",
"def solve(v):\r\n v2=[]\r\n for s in v:\r\n v2.append({s[i:] + s[:i]: i for i in range(len(s))[::-1]})\r\n r = min(sum(d.get(s, 9999) for d in v2) for s in v2[0])\r\n ans = r if r < 9999 else -1\r\n return ans\r\n\r\nn=int(input())\r\nv=[]\r\nfor i in range(n):\r\n s=input()\r\n v.append(s)\r\nprint(solve(v))\r\n",
"# cook your dish here\r\nn = int(input())\r\nl = []\r\nfor i in range(n):\r\n s = str(input())\r\n l.append(s)\r\nans = []\r\nfor k in range(n):\r\n res = 0\r\n for i in l:\r\n t = 2*i\r\n if l[k] not in t:\r\n print(-1)\r\n exit(0)\r\n else:\r\n res+=t.index(l[k])\r\n ans.append(res)\r\nprint(min(ans))",
"# import sys\n\n# sys.stdin = open('input.txt', 'r')\n# sys.stdout = open('output.txt', 'w')\n\nt = 1\n# t = int(input())\nfor i in range(t):\n\tn = int(input())\n\tv = []\n\tfor i in range(n):\n\t\ts = input()\n\t\tv.append(s)\n\tm = len(v[0])\n\ta = \"hello\"\n\t# print(a[1:]+a[:1])\n\tmn = 10000001\n\tflag = 1\n\tfor i in v:\n\t\tcnt = 0\n\t\tfor j in v:\n\t\t\tfor k in range(m):\n\t\t\t\tif(j[k:]+j[:k] == i):\t\n\t\t\t\t\tcnt += k\n\t\t\t\t\tbreak;\n\t\t\t\tif(k==m-1 and j[k:]+j[:k] != i):\n\t\t\t\t\tflag = 0;\n\t\t#print(cnt)\n\t\tmn = min(cnt,mn)\n\tif(flag==0):\n\t\tprint(-1)\n\telse:\n\t\tprint(mn)",
"import sys,random,bisect\r\nfrom collections import deque,defaultdict,Counter\r\nfrom heapq import heapify,heappop,heappush\r\nfrom math import gcd\r\nmod = int(1e9 + 7)\r\ninf = int(1e20)\r\ninput = lambda :sys.stdin.readline().rstrip()\r\nmi = lambda :map(int,input().split())\r\nli = lambda :list(mi())\r\nii = lambda :int(input())\r\npy = lambda :print(\"YES\")\r\npn = lambda :print(\"NO\")\r\n\r\n\r\n\r\n\r\n\r\nt=ii()\r\n\r\narr=[]\r\n\r\nfor _ in range(t):\r\n arr.append(input())\r\n\r\nn=len(arr[0])\r\n\r\nss=arr[0]*2\r\n\r\nif any(s not in ss for s in arr):\r\n print(-1)\r\nelse:\r\n def check(s):\r\n res=0\r\n for a in arr:\r\n while a!=s:\r\n a=a[1:]+a[0]\r\n res+=1\r\n return res\r\n i=0\r\n j=n\r\n res=inf\r\n while j<=2*n:\r\n res=min(res,check(ss[i:j]))\r\n i+=1\r\n j+=1\r\n print(res)\r\n\r\n \r\n\r\n ",
"n=int(input())\r\ns=list()\r\nfor _ in range(n):\r\n x=input()\r\n s.append(x) \r\nl=len(s[0])\r\nflag=True\r\nc=1e9+10\r\nfor i in range(0,n):\r\n if(len(s[i])!=l):\r\n flag=False\r\n break\r\n t=s[i]*2\r\n if(s[0] not in t):\r\n flag=False\r\n break\r\n f=0\r\n for j in range(n):\r\n x=l+1\r\n for k in range(l):\r\n if(s[i]==s[j][k:l]+s[j][0:k]):\r\n x=min(x,k)\r\n f+=x\r\n c=min(c,f)\r\nif(flag):\r\n print(c)\r\nelse:\r\n print(-1)\r\n ",
"def min_operations(strs):\r\n n = len(strs)\r\n m = len(strs[0])\r\n res = -1\r\n \r\n for i in range(1, n):\r\n if len(strs[i]) != len(strs[i - 1]):\r\n return -1\r\n \r\n def make_same(s, t):\r\n if s == t:\r\n return 0\r\n res = 0\r\n for j in range(len(s)):\r\n res += 1\r\n t = t[1::] + t[0]\r\n if t == s:\r\n return res\r\n return -1\r\n \r\n first = strs[0]\r\n for i in range(m):\r\n count = i\r\n for j in range(1, len(strs)):\r\n operations = make_same(first, strs[j])\r\n if operations == -1:\r\n return -1\r\n count += operations\r\n \r\n if res == -1:\r\n res = count\r\n else:\r\n res = min(res, count)\r\n \r\n first = first[1:] + first[0]\r\n \r\n return res\r\n \r\n \r\n#t = int(input())\r\nt = 1\r\nfor _ in range(t):\r\n #a = list(map(int,input().split()))\r\n \r\n #nums = list(map(int,input().split()))\r\n n = int(input())\r\n strs = []\r\n for i in range(n):\r\n s = input()\r\n strs.append(s)\r\n \r\n print(min_operations(strs))\r\n \r\n",
"n = int(input())\r\nwords = [input() for _ in range(n)]\r\n\r\ndef solve(x ,y, dep):\r\n if x == y:\r\n return 0\r\n \r\n if dep > 50:\r\n return -float('inf')\r\n return 1+solve(x, y[1:]+y[0], dep+1)\r\n\r\nbest = float('inf')\r\nfor x in words:\r\n total = 0\r\n for y in words:\r\n res = solve(x, y, 0)\r\n if res < 0:\r\n total = -1\r\n break\r\n total += res\r\n \r\n best = min(best, total)\r\n\r\nprint(best)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ng = [input()[:-1] for _ in range(n)]\r\nx = g[0]\r\nm = len(x)\r\nd = 2500\r\nans = 0\r\nfor i in range(m):\r\n x = x[1:] + x[0]\r\n c = (i + 1)%m\r\n for j in range(1, n):\r\n t = m\r\n s = g[j]\r\n while t > 0 and s != x:\r\n s = s[1:] + s[0]\r\n t -= 1\r\n c += m-t\r\n if s != x:\r\n ans = 1\r\n break\r\n d = min(d, c)\r\n if ans == 1:\r\n break\r\n\r\nif ans == 1:\r\n print(-1)\r\nelse:\r\n print(d)",
"import sys\ninput = sys.stdin.readline\n\nn = int(input())\na = [input().strip() for _ in range(n)]\nm = float(\"inf\")\nfor i in a:\n c = 0\n for j in range(len(a)):\n t = a[j]\n swap = 0\n while t != i:\n t = t[1:] + t[0]\n swap += 1\n if swap >= len(a[j]):\n print(-1)\n exit()\n c += swap\n m = min(m, c)\n\nprint(m)\n",
"from asyncio import shield\n\n\nn = int(input())\ns_list = []\nfor i in range(n):\n s_list.append(input())\n\nresult = 1e9\nfor i in range(len(s_list[0])):\n goal = s_list[0] if (i == 0) else s_list[0][i:] + s_list[0][0:i]\n shift = i\n\n invalid = False\n for j in range(1, n):\n success = False\n for k in range(len(s_list[0])):\n curr_shift = s_list[j] if (k == 0) else s_list[j][k:] + s_list[j][0:k]\n if (curr_shift == goal):\n success = True\n shift += k\n break \n if (not(success)):\n invalid = True\n break\n if (not(invalid)):\n result = min(result, shift)\nif (result == 1e9):\n print(-1)\nelse:\n print(result)"
] | {"inputs": ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab", "3\nkwkb\nkbkw\nbkwk", "1\na", "2\nnjtazaab\nabnjtaza", "38\nkmlzdcnm\nmlzdcnmk\nlzdcnmkm\nkmlzdcnm\nlzdcnmkm\nzdcnmkml\nzdcnmkml\nmlzdcnmk\nzdcnmkml\nmlzdcnmk\nlzdcnmkm\nzdcnmkml\nkmlzdcnm\nlzdcnmkm\nzdcnmkml\nmlzdcnmk\nkmlzdcnm\nmkmlzdcn\nlzdcnmkm\nnmkmlzdc\nzdcnmkml\nnmkmlzdc\nkmlzdcnm\nmlzdcnmk\nmkmlzdcn\ndcnmkmlz\ncnmkmlzd\ncnmkmlzd\nmkmlzdcn\ncnmkmlzd\ndcnmkmlz\nkmlzdcnm\nnmkmlzdc\nnmkmlzdc\nkmlzdcnm\nkmlzdcnm\nlzdcnmkm\nzdcnmkml", "4\nxwppaubrphxjwmwfwypvwwjzotyobpiynyka\nubrphxjwmwfwypvwwjzotyobpiynykaxwppa\nwjzotyobpiynykaxwppaubrphxjwmwfwypvw\ntyobpiynykaxwppaubrphxjwmwfwypvwwjzo", "15\ngnizfqwqmimtgmtf\nmtgmtfgnizfqwqmi\ngmtfgnizfqwqmimt\nzfqwqmimtgmtfgni\nzfqwqmimtgmtfgni\nfqwqmimtgmtfgniz\nimtgmtfgnizfqwqm\nfgnizfqwqmimtgmt\ngmtfgnizfqwqmimt\nmtgmtfgnizfqwqmi\nqwqmimtgmtfgnizf\nizfqwqmimtgmtfgn\nmtfgnizfqwqmimtg\ntgmtfgnizfqwqmim\nmtfgnizfqwqmimtg", "33\nnkgcmrfvxe\nvxenkgcmrf\nrfvxenkgcm\nvxenkgcmrf\nxenkgcmrfv\nenkgcmrfvx\nenkgcmrfvx\nnkgcmrfvxe\nkgcmrfvxen\ncmrfvxenkg\ncmrfvxenkg\nxenkgcmrfv\nrfvxenkgcm\nrfvxenkgcm\nnkgcmrfvxe\nxenkgcmrfv\nrfvxenkgcm\nxenkgcmrfv\nxenkgcmrfv\ngcmrfvxenk\nmrfvxenkgc\nfvxenkgcmr\nvxenkgcmrf\nenkgcmrfvx\ncmrfvxenkg\ncmrfvxenkg\nmrfvxenkgc\nkgcmrfvxen\nvxenkgcmrf\nenkgcmrfvx\ncmrfvxenkg\ncmrfvxenkg\ngcmrfvxenk", "11\nxdngtxuqjalamqvotuhx\notuhxxdngtxuqjalamqv\ngtxuqjalamqvotuhxxdn\ndngtxuqjalamqvotuhxx\nvotuhxxdngtxuqjalamq\nxxdngtxuqjalamqvotuh\nalamqvotuhxxdngtxuqj\nuqjalamqvotuhxxdngtx\nqjalamqvotuhxxdngtxu\nhxxdngtxuqjalamqvotu\njalamqvotuhxxdngtxuq", "2\noiadfnwpdcxxhbwwqbrcdujcusgtkqdjmintwjlb\nbrcdujcusgtkqdjmintwjlboiadfnwpdcxxhbwwq", "20\ncynedh\nnedhcy\nhcyned\ncynedh\nynedhc\nynedhc\nnedhcy\nnedhcy\nnedhcy\nhcyned\nnedhcy\nhcyned\nnedhcy\ndhcyne\nynedhc\nedhcyn\ndhcyne\nynedhc\ncynedh\ncynedh", "9\nrgycrkgcjktfdjkffcnlnhiawq\nawqrgycrkgcjktfdjkffcnlnhi\nrkgcjktfdjkffcnlnhiawqrgyc\njktfdjkffcnlnhiawqrgycrkgc\ncjktfdjkffcnlnhiawqrgycrkg\nfdjkffcnlnhiawqrgycrkgcjkt\nffcnlnhiawqrgycrkgcjktfdjk\nktfdjkffcnlnhiawqrgycrkgcj\nwqrgycrkgcjktfdjkffcnlnhia", "2\ndzlisvouhbqogzusikmkuvkql\nqogzusikmkuvkqldzlisvouhb", "2\nsfotivvfgbdfcnvaybxhstavaoktatflelpyi\nsfotivvfgbdfcnvaybxhstavaoktatflelpyi", "1\numwnrjtcytnquvdmqfiqt", "4\nzumixjfqhbkeg\nkegzumixjfqhb\nhbkegzumixjfq\ngzumixjfqhbke", "12\nktwwduoopsnkhfklrskdxakbmqhl\nlktwwduoopsnkhfklrskdxakbmqh\nduoopsnkhfklrskdxakbmqhlktww\nklrskdxakbmqhlktwwduoopsnkhf\noopsnkhfklrskdxakbmqhlktwwdu\nopsnkhfklrskdxakbmqhlktwwduo\nkbmqhlktwwduoopsnkhfklrskdxa\nlrskdxakbmqhlktwwduoopsnkhfk\nwduoopsnkhfklrskdxakbmqhlktw\nklrskdxakbmqhlktwwduoopsnkhf\nhfklrskdxakbmqhlktwwduoopsnk\ndxakbmqhlktwwduoopsnkhfklrsk", "12\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "15\nkknrrejishjz\nhilbaftsfcaq\nlncsgtjqgwjz\nathvctulbhmb\nnfvsjyiulmmr\nhxjnvumwnwtr\nrncsxqvkvqeg\nqoabapuhodxk\nylinhbhyqjsn\ncnzxgdgytgav\nxufmacyangpv\nhwvzionkdmjl\nspklymjxiolk\nqjkfrccaayak\nonwrbgfvxrjx", "2\nadam\nmdaa", "2\naabc\nacab", "2\nabc\ncba", "5\naaaa\naaaa\naaaa\naaaa\naaaa", "2\na\nb", "2\nabab\naabb", "2\nbac\nabc", "2\naabb\nabab", "3\naa\naa\naa", "2\nabc\nacb", "3\naaaa\naaaa\naaaa", "2\naa\naa", "2\nab\naa", "2\nxyxy\nxxyy", "2\nabc\nbac", "2\naaabb\nbaaba", "2\nabcde\ndcabe", "2\nabcd\nbdca", "5\naaaaa\naabaa\naaaaa\naaaaa\naaaaa", "3\naab\nabb\nbab", "2\nnzxv\nzvnx", "10\nab\nbc\ncd\nde\nef\ngh\nhi\nij\nik\nmn", "3\naaa\naaa\naaa", "2\nac\nbb", "2\nabcd\nbdac", "2\nabcabc\ncabcab", "7\naaa\naab\naba\nabb\nbaa\nbab\nbba", "4\naa\naa\nbb\nbb", "2\nabcd\ncabd", "4\nabcabcabc\nbcabcabca\ncabcabcab\ncabcabcab", "3\nabcabc\nbcabca\nbcabca", "2\nabbc\nabcc", "2\naaabb\nababa", "3\naabbbaba\nabaabbab\nbbbaaaba", "2\naabaab\nbaabaa"], "outputs": ["5", "2", "0", "-1", "3", "0", "2", "104", "41", "89", "135", "79", "17", "34", "76", "10", "0", "0", "9", "121", "0", "-1", "-1", "-1", "-1", "0", "-1", "-1", "-1", "-1", "0", "-1", "0", "0", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "0", "-1", "-1", "1", "-1", "-1", "-1", "3", "1", "-1", "-1", "-1", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
2bdc40552d3c516afc25977c351a847a | Messenger | Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.
All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of *n* blocks, each block containing only equal characters. One block may be described as a pair (*l**i*,<=*c**i*), where *l**i* is the length of the *i*-th block and *c**i* is the corresponding letter. Thus, the string *s* may be written as the sequence of pairs .
Your task is to write the program, that given two compressed string *t* and *s* finds all occurrences of *s* in *t*. Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that *p* is the starting position of some occurrence of *s* in *t* if and only if *t**p**t**p*<=+<=1...*t**p*<=+<=|*s*|<=-<=1<==<=*s*, where *t**i* is the *i*-th character of string *t*.
Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as , , ...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the number of blocks in the strings *t* and *s*, respectively.
The second line contains the descriptions of *n* parts of string *t* in the format "*l**i*-*c**i*" (1<=≤<=*l**i*<=≤<=1<=000<=000) — the length of the *i*-th part and the corresponding lowercase English letter.
The second line contains the descriptions of *m* parts of string *s* in the format "*l**i*-*c**i*" (1<=≤<=*l**i*<=≤<=1<=000<=000) — the length of the *i*-th part and the corresponding lowercase English letter.
Print a single integer — the number of occurrences of *s* in *t*.
Sample Input
5 3
3-a 2-b 4-c 3-a 2-c
2-a 2-b 1-c
6 1
3-a 6-b 7-a 4-c 8-e 2-a
3-a
5 5
1-h 1-e 1-l 1-l 1-o
1-w 1-o 1-r 1-l 1-d
Sample Output
160 | [
"#!/usr/bin/env python3\r\n\r\ndef cal_last(s):\r\n n = len(s)\r\n last = [-1]*(n+1)\r\n i,j = 0,-1\r\n while i<n:\r\n while j!=-1 and s[i]!=s[j]:\r\n j=last[j]\r\n i,j = i+1,j+1\r\n last[i] = j\r\n return last\r\n\r\ndef kmp(p,t,last):\r\n m = len(p)\r\n n = len(t)\r\n i = j = 0\r\n rl = []\r\n while i<n:\r\n while j!=-1 and t[i]!=p[j]:\r\n j=last[j]\r\n i,j = i+1,j+1\r\n if j>=m:\r\n rl.append(i)\r\n j=last[j]\r\n return rl\r\n\r\ndef solve1(p,t):\r\n pn,pc = p[0]\r\n return sum([tn-pn+1 for tn,tc in t if tn>=pn and tc==pc])\r\n\r\ndef solve2(p,t):\r\n return sum([t[i][0]>=p[0][0] and t[i][1]==p[0][1] and t[i+1][0]>=p[1][0] and t[i+1][1]==p[1][1] for i in range(len(t)-1)])\r\n\r\ndef compact(s):\r\n t = [[int(s[0][:-2]),s[0][-1]]]\r\n for i in range(1,len(s)):\r\n n = int(s[i][:-2])\r\n c = s[i][-1]\r\n if c == t[-1][-1]:\r\n t[-1][0] += n\r\n else:\r\n t.append([n,c])\r\n return t\r\n\r\ndef f(p,t):\r\n tt,pp = compact(t),compact(p)\r\n if len(pp)==1:\r\n return solve1(pp,tt)\r\n if len(pp)==2:\r\n return solve2(pp,tt)\r\n last = cal_last(pp[1:-1])\r\n ml = kmp(pp[1:-1],tt,last)\r\n x = len(pp)-2\r\n n = len(tt)\r\n return sum([i-x>0 and tt[i-x-1][0]>=pp[0][0] and tt[i-x-1][1]==pp[0][1] and i<n and tt[i][0]>=pp[-1][0] and tt[i][1]==pp[-1][1] for i in ml])\r\n\r\n_ = input()\r\nt = input().split()\r\np = input().split()\r\nprint(f(p,t))\r\n\r\n",
"def ziped(a):\r\n p = []\r\n for i in a:\r\n x = int(i.split('-')[0])\r\n y = i.split('-')[1]\r\n if len(p) > 0 and p[-1][1] == y:\r\n p[-1][0] += x\r\n else:\r\n p.append([x, y])\r\n return p\r\n\r\ndef solve(a, b , c):\r\n \r\n ans = 0\r\n if len(b) == 1:\r\n for token in a:\r\n #print(\"token\",token)\r\n if c(token, b[0]):\r\n ans += token[0] - b[0][0] + 1\r\n return ans\r\n\t\t\r\n if len(b) == 2:\r\n for i in range(len(a) - 1):\r\n if c(a[i], b[0]) and c(a[i + 1], b[-1]):\r\n ans += 1\r\n return ans\r\n\t\t\r\n v = b[1 : -1] + [[100500, '#']] + a\r\n p = [0] * len(v)\r\n for i in range(1, len(v)):\r\n j = p[i - 1]\r\n while j > 0 and v[i] != v[j]:\r\n j = p[j - 1]\r\n if v[i] == v[j]:\r\n j += 1\r\n p[i] = j\r\n\t\t\r\n for i in range(len(v) - 1):\r\n if p[i] == len(b) - 2 and c(v[i - p[i]], b[0]) and c(v[i + 1], b[-1]):\r\n ans += 1\r\n return ans\r\n\r\nn, m = map(int, input().split())\r\na = ziped(input().split())\r\nb = ziped(input().split())\r\nprint(solve(a, b, lambda x, y: x[1] == y[1] and x[0] >= y[0]))\r\n"
] | {"inputs": ["5 3\n3-a 2-b 4-c 3-a 2-c\n2-a 2-b 1-c", "6 1\n3-a 6-b 7-a 4-c 8-e 2-a\n3-a", "5 5\n1-h 1-e 1-l 1-l 1-o\n1-w 1-o 1-r 1-l 1-d", "9 3\n1-h 1-e 2-l 1-o 1-w 1-o 1-r 1-l 1-d\n2-l 1-o 1-w", "5 3\n1-m 1-i 2-r 1-o 1-r\n1-m 1-i 1-r", "9 2\n1-a 2-b 1-o 1-k 1-l 1-m 1-a 3-b 3-z\n1-a 2-b", "10 3\n1-b 1-a 2-b 1-a 1-b 1-a 4-b 1-a 1-a 2-b\n1-b 1-a 1-b", "4 2\n7-a 3-b 2-c 11-a\n3-a 4-a", "4 3\n8-b 2-a 7-b 3-a\n3-b 2-b 1-a", "1 1\n12344-a\n12345-a", "1 1\n5352-k\n5234-j", "1 1\n6543-o\n34-o", "1 1\n1-z\n1-z", "5 2\n7-a 6-b 6-a 5-b 2-b\n6-a 7-b", "10 3\n7-a 1-c 6-b 1-c 8-a 1-c 8-b 6-a 2-c 5-b\n5-a 1-c 4-b", "4 2\n10-c 3-c 2-d 8-a\n6-a 1-b", "4 1\n10-a 2-b 8-d 11-e\n1-c", "28 7\n1-a 1-b 1-c 1-d 1-e 1-f 1-t 1-a 1-b 1-c 1-d 1-e 1-f 1-j 1-a 1-b 1-c 1-d 1-e 1-f 1-g 1-a 1-b 1-c 1-d 1-e 1-f 2-g\n1-a 1-b 1-c 1-d 1-e 1-f 1-g", "10 3\n2-w 4-l 2-w 4-l 2-w 5-l 2-w 6-l 3-w 3-l\n2-l 2-w 2-l", "15 7\n1-b 1-a 1-b 1-c 1-b 1-a 1-b 1-c 1-b 1-a 1-b 1-c 1-b 1-a 1-b\n1-b 1-a 1-b 1-c 1-b 1-a 1-b", "15 7\n1-b 2-a 1-b 1-c 1-b 1-a 1-b 1-c 1-b 2-a 1-b 1-c 1-b 1-a 1-b\n1-b 2-a 1-b 1-c 1-b 1-a 1-b", "2 2\n1-a 1-b\n2-a 1-b", "8 5\n1-a 1-b 1-c 1-a 2-b 1-c 1-a 1-b\n1-a 1-b 1-c 1-a 1-b", "9 5\n7-a 6-b 7-a 6-b 7-a 6-b 8-a 6-b 7-a\n7-a 6-b 7-a 6-b 7-a"], "outputs": ["1", "6", "0", "1", "1", "2", "3", "6", "2", "0", "0", "6510", "1", "1", "2", "0", "0", "2", "3", "3", "2", "0", "1", "2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2bec4379a795a2f285822a1a74be9293 | none | Once Vasya and Petya assembled a figure of *m* cubes, each of them is associated with a number between 0 and *m*<=-<=1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the *OX* is the ground, and the *OY* is directed upwards. Each cube is associated with the coordinates of its lower left corner, these coordinates are integers for each cube.
The figure turned out to be stable. This means that for any cube that is not on the ground, there is at least one cube under it such that those two cubes touch by a side or a corner. More formally, this means that for the cube with coordinates (*x*,<=*y*) either *y*<==<=0, or there is a cube with coordinates (*x*<=-<=1,<=*y*<=-<=1), (*x*,<=*y*<=-<=1) or (*x*<=+<=1,<=*y*<=-<=1).
Now the boys want to disassemble the figure and put all the cubes in a row. In one step the cube is removed from the figure and being put to the right of the blocks that have already been laid. The guys remove the cubes in such order that the figure remains stable. To make the process more interesting, the guys decided to play the following game. The guys take out the cubes from the figure in turns. It is easy to see that after the figure is disassembled, the integers written on the cubes form a number, written in the *m*-ary positional numerical system (possibly, with a leading zero). Vasya wants the resulting number to be maximum possible, and Petya, on the contrary, tries to make it as small as possible. Vasya starts the game.
Your task is to determine what number is formed after the figure is disassembled, if the boys play optimally. Determine the remainder of the answer modulo 109<=+<=9.
The first line contains number *m* (2<=≤<=*m*<=≤<=105).
The following *m* lines contain the coordinates of the cubes *x**i*,<=*y**i* (<=-<=109<=≤<=*x**i*<=≤<=109, 0<=≤<=*y**i*<=≤<=109) in ascending order of numbers written on them. It is guaranteed that the original figure is stable.
No two cubes occupy the same place.
In the only line print the answer to the problem.
Sample Input
3
2 1
1 0
0 1
5
0 0
0 1
0 2
0 3
0 4
Sample Output
19
2930
| [
"import heapq\n\ndef coor_neighbor(coor, dxs, dys):\n x, y = coor\n for dx in dxs:\n for dy in dys:\n yield x + dx, y + dy\n\n\ndef coor_bottoms(coor):\n return coor_neighbor(coor, (-1, 0, 1), (-1, ))\n\n\ndef coor_tops(coor):\n return coor_neighbor(coor, (-1, 0, 1), (1, ))\n\n\ndef coor_sibs(coor):\n return coor_neighbor(coor, (-2, -1, 1, 2), (0, ))\n\n\nclass Figure:\n\n def __init__(self, coors):\n self._coors = dict()\n self._stables_min = []\n self._stables_max = []\n self._pushed = set()\n self._dropped = set()\n\n cubes = dict()\n self._bots = dict()\n self._tops = dict()\n for idx, coor in enumerate(coors):\n cubes[coor] = idx\n self._coors[idx] = coor\n self._bots[idx] = set()\n self._tops[idx] = set()\n\n coor_set = set(coors)\n for idx, coor in enumerate(coors):\n for bottom in coor_bottoms(coor):\n if bottom in coor_set:\n self._bots[idx].add(cubes[bottom])\n for top in coor_tops(coor):\n if top in coor_set:\n self._tops[idx].add(cubes[top])\n\n for idx in self._coors:\n if self.isdroppable(idx):\n self.push(idx)\n\n def sibs(self, idx):\n for top_idx in self._tops[idx]:\n for sib_idx in self._bots[top_idx]:\n if sib_idx not in self._dropped:\n yield sib_idx\n\n def bottom_count(self, idx):\n return len(self._bots[idx])\n\n def isdroppable(self, idx):\n return all(len(self._bots[top_idx]) > 1 for top_idx in self._tops[idx])\n\n def push(self, idx):\n if idx not in self._pushed:\n heapq.heappush(self._stables_min, idx)\n heapq.heappush(self._stables_max, -idx)\n self._pushed.add(idx)\n\n def unpush(self, idx):\n if idx in self._pushed:\n self._pushed.remove(idx)\n\n def drop(self, idx):\n if idx not in self._pushed:\n return False\n self._pushed.remove(idx)\n self._dropped.add(idx)\n\n for bot_idx in self._bots[idx]:\n self._tops[bot_idx].remove(idx)\n for top_idx in self._tops[idx]:\n self._bots[top_idx].remove(idx)\n\n coor = self._coors[idx]\n for bot_idx in self._bots[idx]:\n if self.isdroppable(bot_idx):\n self.push(bot_idx)\n for sib_idx in self.sibs(idx):\n if not self.isdroppable(sib_idx):\n self.unpush(sib_idx)\n return True\n\n def drop_min(self):\n while True:\n if not self._stables_min:\n return None\n min_idx = heapq.heappop(self._stables_min)\n if self.drop(min_idx):\n return min_idx\n\n def drop_max(self):\n while True:\n if not self._stables_max:\n return None\n max_idx = - heapq.heappop(self._stables_max)\n if self.drop(max_idx):\n return max_idx\n\n def __bool__(self):\n return len(self._coors) != len(self._dropped)\n\n\ndef input_tuple():\n return tuple(map(int, input().split()))\n\n\ndef result_add(result, base, num):\n return (result * base + num) % (10 ** 9 + 9)\n\n\nN = int(input())\ncoors = [input_tuple() for _ in range(N)]\n\nfigure = Figure(coors)\nresult = 0\nwhile True:\n if not figure:\n break\n result = result_add(result, N, figure.drop_max())\n if not figure:\n break\n result = result_add(result, N, figure.drop_min())\nprint(result)\n"
] | {"inputs": ["3\n2 1\n1 0\n0 1", "5\n0 0\n0 1\n0 2\n0 3\n0 4", "10\n-1 2\n-3 0\n5 5\n4 4\n-2 1\n1 1\n3 3\n2 2\n0 0\n-1000000000 0", "10\n-678318184 2\n-678318182 3\n580731357 2\n-678318182 1\n-678318184 1\n-678318183 0\n-678318181 2\n580731357 1\n580731358 0\n-678318183 2", "15\n-491189818 2\n-491189821 6\n-491189823 4\n-491189821 4\n-491189822 5\n-491189819 1\n-491189822 4\n-491189822 7\n-491189821 1\n-491189820 2\n-491189823 3\n-491189817 3\n-491189821 3\n-491189820 0\n-491189822 2", "20\n900035308 3\n900035314 0\n900035309 2\n900035307 0\n900035311 0\n900035313 2\n900035312 0\n900035313 0\n900035311 3\n900035310 0\n900035311 2\n900035311 1\n900035308 2\n900035308 1\n900035308 0\n900035309 3\n900035310 2\n900035313 1\n900035312 3\n900035309 0", "25\n-611859852 0\n-611859842 0\n-611859837 0\n-611859843 0\n-611859863 0\n-611859851 0\n-611859857 0\n-611859858 0\n-611859845 0\n-611859865 0\n-611859836 0\n-611859839 0\n-611859850 0\n-611859854 0\n-611859838 0\n-611859840 0\n-611859860 0\n-611859853 0\n-611859848 0\n-611859844 0\n-611859861 0\n-611859856 0\n-611859862 0\n-611859859 0\n-611859849 0", "20\n1000000000 3\n-1000000000 3\n-1000000000 6\n1000000000 7\n-1000000000 5\n-1000000000 8\n-1000000000 0\n1000000000 0\n-1000000000 9\n1000000000 5\n-1000000000 4\n1000000000 4\n1000000000 2\n-1000000000 7\n-1000000000 2\n1000000000 1\n1000000000 9\n1000000000 6\n-1000000000 1\n1000000000 8", "2\n72098079 0\n72098078 1", "2\n-67471165 1\n-67471166 0", "2\n-939306957 0\n361808970 0", "2\n-32566075 1\n-32566075 0", "2\n73639551 1\n73639551 0"], "outputs": ["19", "2930", "41236677", "41627304", "936629642", "362446399", "93673276", "205917730", "2", "1", "2", "1", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2becae75cadf2898f188dd0410a44eb1 | Safe | Vasya tries to break in a safe. He knows that a code consists of *n* numbers, and every number is a 0 or a 1. Vasya has made *m* attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said in which positions the wrong numbers stand. Vasya has been so unlucky that he hasn’t entered the code where would be more than 5 correct numbers. Now Vasya is completely bewildered: he thinks there’s a mistake in the system and it is self-contradictory. Help Vasya — calculate how many possible code variants are left that do not contradict the previous system responses.
The first input line contains two integers *n* and *m* (6<=≤<=*n*<=≤<=35,<=1<=≤<=*m*<=≤<=10) which represent the number of numbers in the code and the number of attempts made by Vasya. Then follow *m* lines, each containing space-separated *s**i* and *c**i* which correspondingly indicate Vasya’s attempt (a line containing *n* numbers which are 0 or 1) and the system’s response (an integer from 0 to 5 inclusively).
Print the single number which indicates how many possible code variants that do not contradict the *m* system responses are left.
Sample Input
6 2
000000 2
010100 4
6 3
000000 2
010100 4
111100 0
6 3
000000 2
010100 4
111100 2
Sample Output
6
0
1
| [
"import sys\r\nreadline=sys.stdin.readline\r\n\r\ndef Pop_Count(N):\r\n r=(N&0x5555555555555555)+((N>>1)&0x5555555555555555)\r\n r=(r&0x3333333333333333)+((r>>2)&0x3333333333333333)\r\n r=(r&0x0f0f0f0f0f0f0f0f)+((r>>4)&0x0f0f0f0f0f0f0f0f)\r\n r=(r&0x00ff00ff00ff00ff)+((r>>8)&0x00ff00ff00ff00ff)\r\n r=(r&0x0000ffff0000ffff)+((r>>16)&0x0000ffff0000ffff)\r\n r=(r&0x00000000ffffffff)+((r>>32)&0x00000000ffffffff)\r\n return r\r\n\r\nN,M=map(int,readline().split())\r\nS,c=readline().split()\r\nS=sum(1<<i for i in range(N) if S[i]==\"1\")\r\nc=int(c)\r\nbit=(1<<c)-1\r\nans_lst=[]\r\nwhile bit<1<<N:\r\n ans_lst.append(bit^S)\r\n t=bit|bit-1\r\n bit=(t+1)|(~t&-~t)-1>>(bit&-bit).bit_length()\r\nfor _ in range(M-1):\r\n S,c=readline().split()\r\n S=sum(1<<i for i in range(N) if S[i]==\"1\")\r\n c=int(c)\r\n ans_lst=[bit for bit in ans_lst if Pop_Count(bit^S)==c]\r\nans=len(ans_lst)\r\nprint(ans)",
"from collections import defaultdict\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\npow2 = [1]\r\nfor _ in range(20):\r\n pow2.append(2 * pow2[-1])\r\nn1, n2 = n // 2, (n + 1) // 2\r\nx, y, z = [], [], []\r\nfor _ in range(m):\r\n s, c = list(input().rstrip().decode().split())\r\n x0, y0 = [], []\r\n for i in range(n1):\r\n x0.append(ord(s[i]) - 48)\r\n for i in range(n1, n):\r\n y0.append(ord(s[i]) - 48)\r\n x.append(x0)\r\n y.append(y0)\r\n z.append(int(c))\r\ncnt = defaultdict(lambda : 0)\r\nu = [0] * n1\r\nfor i in range(pow2[n1]):\r\n c = []\r\n for j in range(n1):\r\n u[j] = 1 if i & pow2[j] else 0\r\n for j in range(m):\r\n v = n1\r\n for k, l in zip(u, x[j]):\r\n v -= k ^ l\r\n if v > z[j]:\r\n break\r\n c.append(z[j] - v)\r\n if len(c) == m:\r\n cnt[tuple(c)] += 1\r\nans = 0\r\nu = [0] * n2\r\nfor i in range(pow2[n2]):\r\n c = []\r\n for j in range(n2):\r\n u[j] = 1 if i & pow2[j] else 0\r\n for j in range(m):\r\n v = n2\r\n for k, l in zip(u, y[j]):\r\n v -= k ^ l\r\n if v > z[j]:\r\n break\r\n c.append(v)\r\n if len(c) == m:\r\n c = tuple(c)\r\n if c in cnt:\r\n ans += cnt[c]\r\nprint(ans)"
] | {"inputs": ["6 2\n000000 2\n010100 4", "6 3\n000000 2\n010100 4\n111100 0", "6 3\n000000 2\n010100 4\n111100 2", "6 1\n101011 2", "7 2\n1011111 2\n1001111 1", "6 4\n000110 2\n010001 2\n001111 2\n001100 2", "8 3\n00111100 5\n10100111 2\n10110101 2", "35 10\n10010111001010111001011111000111111 1\n10100111001010100001111111010111111 5\n10010111001011110001001111010111110 4\n10010111001010011011011111010110111 3\n10010111001010111011011111010111111 1\n10110011001010111011011111010111111 3\n10010110001011111001011111010111111 2\n10000111000010111001111101000111111 5\n10010111000010011001011111010111111 2\n10010111001010111001011111000111111 1", "35 10\n11110011011000001101011101111100000 5\n01000011011001101101011101011101010 5\n11110011011000001101011101000101011 5\n11000011011101101101011111010001000 5\n10100011011001101101001101010101001 4\n11110011111000100101011101110001000 5\n01100111011000101101001101010101100 4\n11110001011000101111011101010101000 3\n11110010011010101100011101010101000 4\n10100011011000111101011101111101010 5", "35 10\n11101100001010011101100010101111111 5\n11101100010011101100001010101011011 5\n11101100001101111110000011101111010 5\n11101100101001111100000110111111001 5\n11101100001011000100001011101111011 5\n10101000001011111010000010001111011 5\n11101100001011111100010000111110001 5\n11101000001111111100000010101001010 5\n11101001001010101100100010101111011 5\n11100100001011111100010010001101010 5", "35 10\n10011011100001001101101001100011001 5\n10011011111001001101001010100011101 3\n11001011101101001101101010000000101 5\n10011011101001001101111010100001111 4\n10011011101001001101111010110011001 4\n10111001100001001101101010000011101 3\n10011011101001001101001010000101101 3\n10110011101001001100101010000011100 4\n00011110101001001101101011000011101 4\n10011111101001011101101010000001101 3", "35 10\n10000111101101011000011000011001110 5\n11010110010101011000111000111001110 5\n10011111111111011000110000011001110 5\n10000110110011011000111001001001110 5\n11100111110111001000111000001001011 5\n11101111110111001000011010011001110 5\n11000011110111001001111000110001110 5\n11010111111111011010111000111000110 5\n11100110010111011000111000110001110 5\n11000110110111111000101010011001111 5", "35 10\n01001110011001000001000010001101110 5\n01001101111011000001001000001000110 5\n01000101011000000011010000001100110 5\n00011101001001000011000001011100110 5\n11011111010001001011000000001100110 5\n01011100001011000001100000011100110 5\n00011101011011000100000100001100110 5\n01011101011000010001100000001100011 5\n01011001011011010001000000001110100 5\n01010101010001011001000000001110110 5", "35 10\n00101110001000011000011100001110011 5\n00111100011110011000011111111110010 5\n01101010011110111000011110100110010 5\n01101111010100011010011110101100010 5\n00101110011100011000010111011110011 5\n10001110111100011000111111101110010 5\n01101111011100010000010111101110010 5\n11101100011100011000010110101100010 5\n00101100011100011000011100001101010 5\n00100110011100011000011000111110000 5", "35 1\n00001111001110101000001101100010010 5", "30 10\n010000010000001001000000010000 5\n010000010000001001000000010000 5\n010000010000001001000000010000 5\n010000010000001001000000010000 5\n010000010000001001000000010000 5\n010000010000001001000000010000 5\n010000010000001001000000010000 5\n010000010000001001000000010000 5\n010000010000001001000000010000 5\n010000010000001001000000010000 5", "35 2\n00101101100111101110111010001101101 3\n00111111100101010110111010001101101 3", "35 1\n11000110100110101001100101001010110 2", "35 2\n00111111100000111101000110100111101 1\n00111111000000111101000010100111101 1", "35 6\n01100100110000001001100110001100011 5\n10000100110000011001110010001100011 5\n00101110100000010000100010001110011 4\n00110010101000011001100000001110011 5\n00100101110000011001101110001110011 4\n00110110110000011001101000000100011 5", "34 10\n0010101000011110000100111111010110 5\n0110011001011110001101110111000110 5\n0111001000011100000100111111110110 4\n0011011000001110100000110111010110 4\n0101011000011110000100010111010111 3\n0111011000011111010100111111010110 3\n0110010000011110000100110111010010 3\n0111011001111110000100110111010111 3\n1111111000011010000100110111010100 4\n1111001000011110000100110111001111 5", "6 10\n110000 5\n010011 4\n110011 5\n110010 4\n000001 4\n010001 5\n110101 5\n110011 5\n110010 4\n011001 4", "35 10\n11001101010000101110001101101110111 4\n11010101010000101011001001110100110 5\n11000100010000101011001100100100110 4\n11000001000100101011001101101100110 4\n01000101000000101010011101101110010 5\n00000101010010001011001101101100110 5\n01000101010100101010001101100010110 5\n11000100010000010010001101101100110 4\n10000101010000100010000101101100111 4\n11001100010000100010011101101100110 4", "35 10\n01110001000111100010110001110110100 5\n01110001000000000010100001110100010 3\n01110000100100000010100001111110010 4\n11110001011110000010100001110111010 4\n01110101000111000010100001110110110 3\n10110001000100010010000001110110010 5\n01110011000111000011100001110110010 3\n00110001000110000011100001111110010 3\n01110011000010000110000001110111010 5\n11110001000110100010101001110110010 3", "35 10\n10011010100110011101110001101011011 2\n10111010100111011011110000101011011 3\n10011010101111001001110000111111011 5\n10011010100111011100110000100011011 2\n10011010100111001101010000101010011 3\n10010010101001011101110000101011111 5\n10011010100111010101110000100011011 2\n00011010100111011100110001101011111 4\n10011010100111011101110000111001011 2\n10010000000110011101110000101011011 4", "35 10\n10101100110000010101111100110001110 4\n10100110000110000101011100110001110 4\n10100110111110000101010100010001110 5\n11100100010000000101010100110000110 5\n10100010110000100101011100110001110 2\n10000110100000000100011100110001100 4\n10000110110000000001011100110101110 3\n10100010111000000101011101110000110 4\n10100100110000000111001100110001110 3\n10100110100000000101011101110001110 2"], "outputs": ["6", "0", "1", "15", "6", "1", "6", "1", "1", "1", "1", "1", "1", "1", "324632", "142506", "20", "595", "2", "1", "1", "1", "1", "1", "1", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2bfb5015a753c9976a410730dcd8bc2e | Square Root of Permutation | A permutation of length *n* is an array containing each integer from 1 to *n* exactly once. For example, *q*<==<=[4,<=5,<=1,<=2,<=3] is a permutation. For the permutation *q* the square of permutation is the permutation *p* that *p*[*i*]<==<=*q*[*q*[*i*]] for each *i*<==<=1... *n*. For example, the square of *q*<==<=[4,<=5,<=1,<=2,<=3] is *p*<==<=*q*2<==<=[2,<=3,<=4,<=5,<=1].
This problem is about the inverse operation: given the permutation *p* you task is to find such permutation *q* that *q*2<==<=*p*. If there are several such *q* find any of them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=106) — the number of elements in permutation *p*.
The second line contains *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the elements of permutation *p*.
If there is no permutation *q* such that *q*2<==<=*p* print the number "-1".
If the answer exists print it. The only line should contain *n* different integers *q**i* (1<=≤<=*q**i*<=≤<=*n*) — the elements of the permutation *q*. If there are several solutions print any of them.
Sample Input
4
2 1 4 3
4
2 1 3 4
5
2 3 4 5 1
Sample Output
3 4 2 1
-1
4 5 1 2 3
| [
"import sys\r\nfrom collections import defaultdict\r\nreadline=sys.stdin.readline\r\n\r\nN=int(readline())\r\nP=list(map(int,readline().split()))\r\nfor x in range(N):\r\n P[x]-=1\r\nperm=[]\r\nseen=[False]*N\r\nfor x in range(N):\r\n if seen[x]:\r\n continue\r\n perm.append([])\r\n perm[-1].append(x)\r\n seen[x]=True\r\n while not seen[P[x]]:\r\n x=P[x]\r\n perm[-1].append(x)\r\n seen[x]=True\r\ndct=defaultdict(list)\r\nfor lst in perm:\r\n dct[len(lst)].append(lst)\r\nans_lst=[None]*N\r\nfor le,lst in dct.items():\r\n if le%2==0 and len(lst)%2:\r\n print(-1)\r\n exit()\r\n if le%2:\r\n for i in range(len(lst)):\r\n for j in range(le):\r\n ans_lst[lst[i][j]]=lst[i][(j+(le+1)//2)%le]+1\r\n else:\r\n for i in range(len(lst)//2):\r\n lst0=lst[i*2]\r\n lst1=lst[i*2+1]\r\n for j in range(le):\r\n ans_lst[lst0[j]]=lst1[j]+1\r\n ans_lst[lst1[j]]=lst0[(j+1)%le]+1\r\nprint(*ans_lst)",
"import os\r\nfrom re import M\r\nimport sys \r\nfrom io import BytesIO, IOBase\r\n \r\nBUFSIZE = 8192\r\n \r\nclass FastIO(IOBase):\r\n newlines = 0\r\n \r\n def __init__(self, file):\r\n self._fd = file.fileno() \r\n self.buffer = BytesIO() \r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n \r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break \r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0 \r\n return self.buffer.read()\r\n \r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) \r\n self.newlines = b.count(b\"\\n\") + (not b) \r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1 \r\n return self.buffer.readline()\r\n \r\n def flush(self): \r\n if self.writable: \r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0) \r\n \r\n \r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n \r\n \r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\ndef solve():\r\n n = int(input())\r\n P = list(map(int, input().split()))\r\n P = [p - 1 for p in P]\r\n Q = [-1] * n\r\n size = {}\r\n used = [False] * n\r\n for i in range(n):\r\n if used[i]:\r\n continue\r\n lst = []\r\n while not used[i]:\r\n used[i] = True\r\n lst.append(i)\r\n i = P[i]\r\n le = len(lst)\r\n if le & 1:\r\n c = (le + 1) // 2\r\n for i in range(le):\r\n Q[lst[i]] = lst[(i + c) % le]\r\n elif le not in size:\r\n size[le] = lst\r\n else:\r\n lst2 = size[le]\r\n del size[le]\r\n lst.append(lst[0])\r\n for i in range(le):\r\n Q[lst[i]] = lst2[i]\r\n Q[lst2[i]] = lst[i + 1]\r\n if -1 in Q:\r\n print(-1)\r\n else:\r\n Q = [q + 1 for q in Q]\r\n print(*Q)\r\n\r\n \r\n\r\n\r\n\r\n\r\n \r\nfor _ in range(1):\r\n solve() \r\n ",
"n=int(input())\r\na=list(map(lambda x:int(x)-1,input().split()))\r\n\r\nans=[-1]*n\r\n\r\ndef calc1(a):\r\n m=len(a)\r\n b=[0]*m\r\n for i in range(m):\r\n b[(2*i)%m]=a[i]\r\n for i in range(m):\r\n ans[b[i]]=b[(i+1)%m]\r\n\r\ndef calc2(a,b):\r\n m=len(a)\r\n c=[0]*2*m\r\n for i in range(m):\r\n c[2*i]=a[i]\r\n c[2*i+1]=b[i]\r\n for i in range(2*m):\r\n ans[c[i]]=c[(i+1)%(2*m)]\r\n\r\nmemo=[[] for i in range(n+1)]\r\nseen=[0]*n\r\nfor i in range(n):\r\n if seen[i]:\r\n continue\r\n loop=[i]\r\n seen[i]=1\r\n now=a[i]\r\n while now!=i:\r\n loop.append(now)\r\n seen[now]=1\r\n now=a[now]\r\n if len(loop)%2==1:\r\n calc1(loop)\r\n else:\r\n m=len(loop)\r\n if memo[m]:\r\n calc2(memo[m],loop)\r\n memo[m]=[]\r\n else:\r\n memo[m]=loop\r\n\r\nif min(ans)!=-1:\r\n print(*[i+1 for i in ans])\r\nelse:\r\n print(-1)",
"from collections import defaultdict\r\n\r\n# permutation start with 0, e.g [3 4 0 1 2]\r\ndef perm_loops(x, n): # from permutation create loops\r\n V, ans = set(), []\r\n for i in range(n):\r\n if i in V: continue\r\n q = i\r\n ans += [[q]]\r\n V.add(i)\r\n while x[q] != i:\r\n ans[-1] += [x[q]]\r\n q = x[q]\r\n V.add(q)\r\n return ans\r\n\r\ndef loops_perm(loops, n): # from loops create permutation\r\n ans = [0] * n\r\n for loop in loops:\r\n for x, y in zip(loop, loop[1:] + loop[:1]):\r\n ans[x] = y\r\n return ans\r\n\r\nn = int(input())\r\narr = [int(i) - 1 for i in input().split()]\r\nd_loops = defaultdict(list)\r\n\r\nloops = perm_loops(arr, n)\r\nfor loop in loops:\r\n d_loops[len(loop)] += [tuple(loop)]\r\n\r\ndef solve(d_loops):\r\n ans = []\r\n for d in d_loops:\r\n if d % 2 == 1:\r\n for loop in d_loops[d]:\r\n tmp = [0]*d\r\n tmp[::2] = loop[:d//2+1]\r\n tmp[1::2] = loop[d//2+1:]\r\n ans += [tmp]\r\n else:\r\n if len(d_loops[d]) % 2 == 1:\r\n return []\r\n else:\r\n for i in range(len(d_loops[d])//2):\r\n loop1 = d_loops[d][2*i]\r\n loop2 = d_loops[d][2*i+1]\r\n tmp = [0]*(2*d)\r\n tmp[::2] = loop1\r\n tmp[1::2] = loop2\r\n ans += [tmp]\r\n return ans\r\n\r\nans = solve(d_loops)\r\nif ans == []:\r\n print(-1)\r\nelse:\r\n out = loops_perm(ans, n)\r\n print(\" \".join(str(i+1) for i in out))",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\np = [0] + list(map(int, input().split()))\r\nvisit = [0] * (n + 1)\r\nx = [[] for _ in range(n + 1)]\r\nq = [0] * n\r\nfor i in range(1, n + 1):\r\n if visit[i]:\r\n continue\r\n y = [i]\r\n visit[i] = 1\r\n while not visit[p[y[-1]]]:\r\n y.append(p[y[-1]])\r\n visit[y[-1]] = 1\r\n l = len(y)\r\n if l % 2 == 0:\r\n x[l].append(y)\r\n continue\r\n z = [0] * l\r\n for j in range(l):\r\n z[2 * j % l] = y[j]\r\n for j in range(l):\r\n q[z[j] - 1] = z[(j + 1) % l]\r\nfor i in range(2, n + 1, 2):\r\n xi, l = x[i], 2 * i\r\n if len(xi) % 2:\r\n q = [-1]\r\n break\r\n for j in range(len(xi) // 2):\r\n u, v = xi[2 * j], xi[2 * j + 1]\r\n z = [0] * l\r\n for k in range(i):\r\n z[2 * k] = u[k]\r\n z[2 * k + 1] = v[k]\r\n for j in range(l):\r\n q[z[j] - 1] = z[(j + 1) % l]\r\nsys.stdout.write(\" \".join(map(str, q)))",
"import sys\r\nimport bisect\r\nfrom bisect import bisect_left as lb\r\ninput_=lambda: sys.stdin.readline().strip(\"\\r\\n\")\r\nfrom math import log\r\nfrom math import gcd\r\nfrom math import atan2,acos\r\nfrom random import randint\r\nsa=lambda :input_()\r\nsb=lambda:int(input_())\r\nsc=lambda:input_().split()\r\nsd=lambda:list(map(int,input_().split()))\r\nse=lambda:float(input_())\r\nsf=lambda:list(input_())\r\nflsh=lambda: sys.stdout.flush()\r\n#sys.setrecursionlimit(10**6)\r\nmod=10**9+7\r\ngp=[]\r\ncost=[]\r\ndp=[]\r\nmx=[]\r\nans1=[]\r\nans2=[]\r\nspecial=[]\r\nspecnode=[]\r\na=0\r\nkthpar=[]\r\ndef dfs(root,par):\r\n if par!=-1:\r\n dp[root]=dp[par]+1\r\n for i in range(1,20):\r\n if kthpar[root][i-1]!=-1:\r\n kthpar[root][i]=kthpar[kthpar[root][i-1]][i-1]\r\n for child in gp[root]:\r\n if child==par:continue\r\n kthpar[child][0]=root\r\n dfs(child,root)\r\ndef hnbhai():\r\n n=sb()\r\n a=[0]+sd()\r\n ans=[-1]*(n+1)\r\n d={}\r\n visited=[0]*(n+1)\r\n for i in range(1,n+1):\r\n if visited[i]==0:\r\n g=[]\r\n abe=i\r\n while not visited[abe]:\r\n visited[abe]=1\r\n g.append(abe)\r\n abe=a[abe]\r\n if len(g)%2:\r\n mid=(len(g)+1)//2\r\n for i in range(len(g)):\r\n ans[g[i]]=g[(i+mid)%len(g)]\r\n else:\r\n if d.get(len(g)):\r\n temp=d[len(g)]\r\n for i in range(len(g)):\r\n ans[g[i]]=temp[(i+1)%len(g)]\r\n ans[temp[i]]=g[i]\r\n del d[len(g)]\r\n else:\r\n d[len(g)]=g\r\n if len(d):\r\n print(-1)\r\n return\r\n print(*ans[1:])\r\nfor _ in range(1):\r\n hnbhai()\r\n"
] | {"inputs": ["4\n2 1 4 3", "4\n2 1 3 4", "5\n2 3 4 5 1", "1\n1", "1\n1", "10\n8 2 10 3 4 6 1 7 9 5", "10\n3 5 1 2 10 8 7 6 4 9", "100\n11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98", "100\n94 22 24 99 58 97 20 29 67 30 38 64 77 50 15 44 92 88 39 42 25 70 2 76 84 6 37 49 17 71 31 19 26 79 10 35 65 63 32 95 5 8 52 27 83 18 53 93 13 81 48 68 54 82 34 60 87 23 16 86 55 40 61 45 28 7 74 41 14 91 3 72 33 11 98 89 90 69 78 36 80 59 56 21 43 1 75 46 47 12 96 73 57 51 4 85 9 100 66 62"], "outputs": ["3 4 2 1", "-1", "4 5 1 2 3", "1", "1", "-1", "6 9 8 10 4 3 7 1 5 2", "-1", "78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 32 54 84 68 43 4 21 28 73 6 16 62 31 39 65 86 98 75 33 45 19 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 72 37 12 35 99 67 94 1 87 57 8 61 25 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30"]} | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
2c194e8d15f692a3b9c94af7a2f3a338 | Stripe | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, and each piece contains positive integer amount of squares. Would you help Bob solve this problem?
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value.
Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only.
Sample Input
9
1 5 -6 7 9 -16 0 -2 2
3
1 1 1
2
0 0
Sample Output
3
0
1
| [
"n = int(input())\n\nsq = [int(i) for i in input().split(\" \")]\n\nways = 0\n\nsoma1anterior = 0\nsoma2anterior = sum(sq[1:n]) + sq[0]\ncount = 0\n\nfor i in range(0, n - 1):\n\n s1 = soma1anterior + sq[i]\n s2 = soma2anterior - sq[i]\n\n if s1 == s2:\n ways += 1\n\n soma1anterior = s1\n soma2anterior = s2\n\nprint(ways)\n",
"n = int(input())\r\nstripes = list(map(int, input().split(\" \")))\r\n\r\ntotal = sum(stripes)\r\nleftSum = 0\r\nways = 0\r\n\r\nfor i in range(n-1):\r\n leftSum = leftSum + stripes[i]\r\n if(2*leftSum == total):\r\n ways = ways + 1\r\n \r\nprint(ways)\r\n ",
"n = int(input())\nsquares = list(map(eval, input().split()))\n\nsum1 = squares[0]\nsum2 = sum(squares) - sum1\ncount = 0\n\nfor i in range(1, n):\n if sum1 == sum2:\n count += 1\n sum1 += squares[i]\n sum2 -= squares[i]\n else:\n sum1 += squares[i]\n sum2 -= squares[i]\n \nprint(count)\n \t\t \t \t\t\t \t \t\t \t \t \t \t \t",
"n = int(input())\nnums = [int(x) for x in input().split()]\n\nleftsum = 0\nleft = [0 for _ in range(n)]\nfor x in range(n):\n\tleftsum += nums[x]\n\tleft[x] = leftsum\n\nrightsum = 0\nright = [0 for _ in range(n)]\nfor x in range(n - 1, -1, -1):\n\trightsum += nums[x]\n\tright[x] = rightsum\n# print(left)\n# print(right)\ncount = 0\nfor i in range(n - 1):\n\tif left[i] == right[i + 1]:\n\t\tcount += 1\nprint(count)\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nl,r,c=0,sum(a),0\r\nfor i in range(n-1):\r\n\tl+=a[i]\r\n\tr-=a[i]\r\n\tif l==r:\r\n\t\tc+=1\r\nprint(c)\r\n",
"n = int(input())\n\nstripe = list(map(int, input().split()))\n\ncount = 0\n\nleft = 0\nright = sum(stripe)\n\nfor s in stripe[:-1]:\n left += s\n right -= s\n\n if left == right:\n count += 1\n\nprint(count)\n",
"\r\ndef main_function():\r\n n = int(input())\r\n a = [int(i) for i in input().split(\" \")]\r\n sums_a = []\r\n current_sum = 0\r\n for i in a:\r\n current_sum += i\r\n sums_a.append(current_sum)\r\n total_sum = sum(a)\r\n counter = 0\r\n for i in sums_a[:-1]:\r\n if i == total_sum - i:\r\n counter += 1\r\n print(counter)\r\n\r\n\r\n\r\nmain_function()",
"n = int(input())\r\na = [0] + [int(i) for i in input().split()]\r\ns = [0]*(n+1)\r\nfor i in range(1,n+1):\r\n s[i] = s[i-1]+a[i]\r\n\r\nc = 0\r\nfor i in range(1,n):\r\n if s[i] == s[n]-s[i]:\r\n c += 1\r\nprint(c) \r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = [*a]\r\nfor i in range(1, n):\r\n s[i] = s[i-1] + s[i]\r\n\r\nans = 0\r\nfor i in range(n- 1):\r\n l = s[i]\r\n r = s[n-1] - s[i]\r\n if l == r:\r\n ans += 1\r\nprint(ans)",
"n=int(input())\ns=list(map(int,input().split()))\nsum0=sum(s)\nsum1=0\ndig=0\nfor i in range(n-1):\n sum1+=s[i]\n if sum1==sum0-sum1:\n dig+=1\nprint(dig)\n\t\t\t \t \t \t\t\t \t\t \t\t",
"import itertools\r\n\r\n\r\nn, a = int(input()), [*itertools.accumulate(map(int, input().split()))]\r\nif a[-1] % 2 != 0:\r\n print(0)\r\nelse:\r\n # print(*a)\r\n print(a[:-1].count(a[-1] // 2))\r\n",
"n=int(input())\r\n\r\nl=list(map(int,input().split()))\r\n\r\n\r\n\r\nl1=[]\r\n\r\n\r\nl2=[]\r\n\r\ns=0\r\nfor i in range(n):\r\n s+=l[i]\r\n\r\n l1.append(s)\r\n\r\ns=0\r\nfor i in range(n-1,-1,-1):\r\n s+=l[i]\r\n\r\n l2.append(s)\r\n\r\nc=0\r\nfor i in range(0,n-1):\r\n\r\n \r\n if l1[i]==l2[n-i-2]:\r\n\r\n \r\n c+=1\r\n\r\n\r\nprint(c)\r\n \r\n\r\n",
"n = int(input())\ns = list(map(int,input().split()))\nq = 0\na = 0\nb = sum(s)\nfor c in range(0,n-1):\n a += s[c]\n b -= s[c]\n if a == b:\n q += 1\nprint(q)",
"n = int(input())\ni = 0\ns = 0\na = [0] * n\nfor item in input().split():\n s += int(item)\n a[i] = s\n i += 1\nif s % 2 == 1:\n print(0)\nelse:\n s = s // 2\n counter = 0\n for i in range(n - 1):\n if a[i] == s:\n counter += 1\n print(counter)\n",
"import io,os,sys\r\nimport math\r\nimport random\r\nfrom queue import PriorityQueue as PQ\r\nfrom bisect import bisect_left as BSL\r\nfrom bisect import bisect_right as BSR\r\nfrom collections import OrderedDict as OD\r\nfrom collections import Counter\r\nfrom itertools import permutations\r\nfrom decimal import Decimal as BIGFLOAT\r\n\r\n# mod = 998244353\r\nmod = 1000000007\r\n# mod = 998244353 \r\nsys.setrecursionlimit(1000000)\r\n\r\n\r\ntry:\r\n f = os.open(\"actext.txt\",os.O_RDONLY)\r\n input = io.BytesIO(os.read(f,os.fstat(f).st_size)).readline\r\n \r\nexcept:\r\n input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n \r\n \r\n\r\n \r\ndef get_ints():\r\n return map(int,input().decode().split())\r\n \r\ndef palindrome(s):\r\n mid = len(s)//2\r\n for i in range(mid):\r\n if(s[i]!=s[len(s)-i-1]):\r\n return False\r\n return True\r\ndef check(i,n):\r\n if(0<=i<n):\r\n return True\r\n else:\r\n return False\r\n \r\n# --------------------------------------------------------------------------\r\nn = int(input().decode())\r\narr = list(get_ints())\r\npre1 =[0]\r\npre2 = [0]\r\nfor i in arr:\r\n pre1.append(pre1[-1]+i)\r\n\r\nfor i in arr[::-1]:\r\n pre2.append(pre2[-1]+i)\r\npre2.reverse()\r\npre2.pop()\r\npre1.pop(0)\r\ncounter = 0\r\nfor i in range(n-1):\r\n if(pre1[i]==pre2[i+1]):\r\n counter+=1\r\nprint(counter)",
"squares = int(input())\r\n\r\nstripe = [int(x) for x in input().split(' ')]\r\n\r\nfirst = 0\r\nsecond = sum(stripe)\r\npossibilities = 0\r\n\r\nfor i in range(squares - 1):\r\n first += stripe[i]\r\n second -= stripe[i]\r\n if first == second:\r\n possibilities += 1\r\n\r\nprint(possibilities)\r\n",
"n = int(input())\r\nl = list(map(int, input().split(' ')))\r\nans = 0\r\ns1 = 0\r\ns2 = sum(l)\r\nfor i in range(n - 1):\r\n s1 += l[i]\r\n s2 -= l[i]\r\n if s1 == s2:\r\n ans += 1 \r\nprint(ans)",
"i = int(input())\r\nl = list(map(int,input().split()))\r\nans =a= 0; b = sum(l)\r\nfor x in range(i):\r\n a += l[x]; b -= l[x]\r\n if a == b and x!=i-1: ans +=1\r\nprint(ans)",
"#Calc prefix sum list, and reverse prefix sum list, then count how many times the two have the same index in their list\n#should be ~O(3n)\nimport sys\ntoks = (token for token in sys.stdin.read().split())\nn = int(next(toks))\n\nsquares = []\nfor _ in range(n):\n squares.append(int(next(toks)))\n\n#print(squares)\n\ntotal = sum(squares)\npsums = []\nrpsums = []\naccf = 0\naccr = total\nfor i in range(len(squares) - 1):\n num = squares[i]\n accf += num\n accr -= num\n psums.append(accf)\n rpsums.append(accr)\n\n#print(psums)\n#print(rpsums)\n\nans = 0\nfor i in range(len(psums)):\n if psums[i] == rpsums[i]:\n ans += 1\nprint(ans)\n\n\t \t\t \t\t \t\t \t \t \t \t\t \t",
"##\r\nn = int(input())\r\nsquares = [int(x) for x in input().split(\" \")]\r\n\r\nladoA = 0\r\nladoB = sum(squares)\r\nc = 0\r\n\r\nfor i in range(n-1):\r\n ladoA += squares[i]\r\n ladoB -= squares[i]\r\n if ladoA == ladoB:\r\n c +=1\r\nprint(c)",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ns = 0\r\nse = sum(a)\r\ncum = 0\r\n\r\n\r\nfor i in range(n-1):\r\n cum += a[i]\r\n if cum == se - cum :\r\n s+=1\r\nprint(s)\r\n\r\n \r\n \r\n",
"\r\n#k=int(input())\r\n#n,m=map(int,input().split())\r\nimport sys\r\n\r\n\r\n#a=list(map(int,input().split()))\r\n\r\n#b=list(map(int,input().split()))\r\nimport math\r\n\r\nn=int(input())\r\n\r\na=list(map(int,input().split()))\r\n\r\nsuml=0\r\n\r\nsumr=sum(a)\r\ncnt=0\r\n\r\nfor i in range(n-1):\r\n suml+=a[i]\r\n sumr-=a[i]\r\n\r\n if suml==sumr:\r\n cnt+=1\r\n\r\nprint(cnt)",
"from itertools import accumulate, permutations\r\n\r\nR = lambda: map(int, input().split())\r\nn = int(input())\r\nacc = list(accumulate(R()))\r\nprint(sum(acc[i] == acc[-1] / 2 for i in range(n - 1)))",
"N = int(input())\r\nnums = list(map(int, input().split()))\r\ntotal = sum(nums)\r\n\r\ns, cnt = 0, 0\r\nfor i in range(N-1):\r\n s += nums[i]\r\n if(s == (total - s)): cnt += 1\r\n \r\nprint(cnt)",
"def main():\r\n n = int(input())\r\n s = tuple(map(int, input().split()))\r\n\r\n h = sum(s)\r\n if h % 2:\r\n print(0)\r\n return\r\n h //= 2\r\n l_sum = 0\r\n count = 0\r\n for a in s[:-1]:\r\n l_sum += a\r\n if l_sum == h:\r\n count += 1\r\n\r\n print(count)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n = int(input())\nS = [int(x) for x in input().split()]\n \ns2 = sum(S)\ns1 = 0\ncount = 0\n \nfor i in range(len(S) - 1):\n s1 += S[i]\n s2 -= S[i]\n if s1 == s2:\n count += 1\n\nprint(count)\n \t \t \t\t\t \t\t\t \t\t",
"n = int(input())\nl = list(map(int,input().split()))\n\nsoma=sum(l)\nadd=0\ncount=0\nlista=[]\n\nwhile count != n-1:\n soma -= l[count]\n add += l[count]\n if soma == add:\n lista.append(1)\n count+=1\n\nprint(sum(lista))\n \n\t \t\t \t\t \t\t \t \t\t \t",
"n=int(input())\r\narr=list(map(int,input().split()))\r\ncums=sum(arr)\r\nc=0\r\nx=0\r\nfor i in range(n-1):\r\n x+=arr[i]\r\n if x==cums-x:\r\n c+=1\r\nprint(c)",
"\r\ndef main():\r\n\t\r\n\tn = int(input())\r\n\tstripe = list(map(int, input().split()))\r\n\tacum = []\r\n\t\r\n\tsoma = 0\r\n\tfor i in range(n):\r\n\t\tsoma += stripe[i]\r\n\t\tacum.append(soma)\r\n\t\r\n\tcount = 0\r\n\tfor j in range(n-1):\r\n\t\tif acum[j] == acum[n-1]/2:\r\n\t\t\tcount += 1\r\n\tprint(count)\r\n\treturn 0\r\n\r\nif __name__ == '__main__':\r\n\tmain()\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\npre=[0]*n\r\nsuf=[0]*n\r\npre[0]=a[0]\r\nsuf[-1]=a[-1]\r\nfor i in range(1,n):\r\n temp=n-i-1\r\n pre[i]=pre[i-1]+a[i]\r\n suf[temp]=suf[temp+1]+a[temp]\r\nans=0\r\nfor i in range(n-1):\r\n if pre[i]==suf[i+1]:\r\n ans+=1\r\nprint(ans)",
"n = int(input())\nline = list(map(int, input().split()))\n\ncount = 0\nsum1 = 0\nsum2 = sum(line)\n\nfor i in range(n-1):\n sum1 += line[i]\n sum2 -= line[i]\n if sum1 == sum2:\n count += 1\n\nprint(count)\n",
"# Reading number n and array arr\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n# Intialize ans\r\nans = 0\r\n# Sum of array\r\nsum_arr = sum(arr)\r\n# Initialize s1, s2 and move border variables\r\ns1 = 0\r\ns2 = sum_arr\r\n# Loop through each number with index i and...\r\n# ...recalculating the values of S1 and S2 each iteration and increasing the ans when S1 = S2\r\nfor i in range(n - 1):\r\n s1 += arr[i]\r\n s2 -= arr[i]\r\n ans = ans + (s1 == s2)\r\n# Show the ans\r\nprint(ans)",
"d=0\r\nx=int(input())\r\na=list(map(int,input().split()))\r\nv=[]\r\nv1=[]\r\n\r\nfor i in range(len(a)-1):\r\n d+=a[i]\r\n v.append(d)\r\nd=0\r\nfor i in range(len(a)-1,0,-1):\r\n d+=a[i]\r\n v1.append(d)\r\nv1.reverse()\r\nzz=0\r\nfor i in range(len(v)):\r\n if v[i]==v1[i]:\r\n zz+=1\r\nprint(zz)",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nsa = sum(arr)\r\nif sa%2==1:\r\n print(0)\r\n exit()\r\nsa//=2\r\npre = [0]\r\nfor c in arr:\r\n pre.append(pre[-1]+c)\r\nprint(pre[1:-1].count(sa))",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ntotal = sum(a)\r\ncurrent_sum = 0\r\ncount = 0\r\n\r\nfor i in range(n - 1):\r\n current_sum += a[i]\r\n if current_sum * 2 == total:\r\n count += 1\r\n\r\nprint(count)\r\n",
"n=int(input())\r\n\na=list(map(int,input().split()))\r\n\nprefix=[a[0]]\n\r\nsuffix=[a[-1]]\n\r\nc=0\r\n\nfor i in range(1,n):\r\n\n prefix.append(prefix[-1]+a[i])\r\n\nfor i in range(n-2,-1,-1):\r\n\n suffix.append(suffix[-1]+a[i])\n\r\nsuffix=suffix[::-1]\r\n\nfor i in range(n-1):\r\n\n if prefix[i]==suffix[i+1]:\r\n\n c+=1\n\r\nprint(c)",
"n=int(input())\r\nli=list(map(int,input().split(\" \")))\r\nlefts=0\r\nrights=sum(li)\r\ncount=0\r\nfor x in range(n-1):\r\n lefts+=li[x]\r\n rights-=li[x]\r\n if lefts==rights:\r\n count+=1\r\n\r\nprint(count)\r\n",
"# Stripe\n\nn = input()\nsquares = list(map(int, input().split()))\n\nfor i in range(1, len(squares)):\n squares[i] += squares[i - 1]\n\nc = 0\nfor i in range(len(squares) - 1):\n if squares[-1] - squares[i] == squares[i]:\n c += 1\n\nprint(c)\n",
"n = int(input())\r\na = [int(c) for c in input().split()]\r\nx = sum(a)\r\nif x%2!=0:\r\n print(0)\r\nelse:\r\n x//=2\r\n s = 0\r\n o = 0\r\n for i in range(n-1):\r\n o+=a[i]\r\n if o==x:\r\n s+=1\r\n print(s)",
"x = int(input())\r\nl = list(map(int,input().split()))\r\n\r\n\r\np1 = [0]*(x-1)\r\nc1 = 0\r\n\r\nfor j in range(len(l)-1):\r\n c1+=l[j]\r\n p1[j]+=c1\r\n\r\np2 = [0]*(x-1)\r\nc2 = 0\r\nd = 0\r\n\r\nfor i in range(len(l)-1,0,-1):\r\n c2+=l[i]\r\n p2[d]+=c2\r\n d+=1\r\np2 = p2[::-1]\r\nc = 0\r\nfor o in range(len(p2)):\r\n if p2[o] == p1[o]:\r\n c+=1\r\nprint(c)",
"IN = lambda : map(int,input().split())\r\nn , = IN()\r\na = list(IN());\r\nl , r ,ans = 0,sum(a),0\r\nfor i in range (n-1):\r\n l += a[i]\r\n r -= a[i]\r\n if(l == r) :\r\n ans += 1;\r\nprint (ans)\r\n",
"'''\n 88\n 88\n 88\n,adPPYba, 88 88 8b d8 ,adPPYYba, ,adPPYba, 88,dPPYba,\nI8[ \"\" 88 88 `8b d8' \"\" `Y8 I8[ \"\" 88P' \"8a\n `\"Y8ba, 88 88 `8b d8' ,adPPPPP88 `\"Y8ba, 88 88\naa ]8I \"8a, ,a88 `8b,d8' 88, ,88 aa ]8I 88 88\n`\"YbbdP\"' `\"YbbdP'Y8 Y88' `\"8bbdP\"Y8 `\"YbbdP\"' 88 88\n d8'\n d8'\n'''\n \n \nfrom collections import Counter, defaultdict\nimport math\nfrom collections import deque\n \n \ndef T(): return int(input())\ndef S(): return str(input())\ndef A(): return list(map(int, input().split(\" \")))\ndef M(type): return map(type, input().split(\" \"))\n \ndef sumOfDigits(n):\n n = str(n)\n su = 0\n for i in n:\n su += int(i)\n return su\n \n \ndef lofint(n): return math.floor(math.log10(n))+1\n \n \ndef isPal(s): return s[::-1] == s\n \n \ndef sumNat(n): return (n*(n+1))//2\n \n \ndef lcm(a, b): return int((a * b)/math.gcd(a, b))\n\n\nn = T()\na = A()\nans = 0\na= [-math.inf] + a\ndp = [0] * (n+1)\nfor i in range(1, n+1):\n dp[i] = dp[i-1]+a[i]\nfor i in range(1, n):\n if dp[i] == dp[n]-dp[i]:\n ans+=1\n# print(dp[n])\nprint(ans)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nv=[]\r\nv1=0\r\nfor i in range(1,n+1):\r\n v1+=l[i-1]\r\n v.append(v1)\r\nfor i in range(n-1):\r\n if v[i]==v[-1]-v[i]:\r\n c+=1\r\nprint(c) ",
"import itertools as itt\r\n\r\n\r\nn, a = int(input()), [*itt.accumulate(map(int, input().split()))]\r\nprint(0 if a[-1] % 2 != 0 else a[:-1].count(a[-1] // 2))\r\n",
"import sys\r\nimport math\r\n\r\nn = int(sys.stdin.readline())\r\nan = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nvsum = sum(an)\r\nts = 0\r\nres = 0\r\nfor i in range(n - 1):\r\n ts += an[i]\r\n if(vsum - ts == ts):\r\n res += 1\r\n \r\nprint(res)\r\n \r\n \r\n ",
"n = int(input())\r\nL = [int(x) for x in input().split()]\r\ns = sum(L)\r\ntemp = 0\r\nif n == 1:\r\n print(0)\r\nelse:\r\n if s % 2 == 1:\r\n print(0)\r\n else:\r\n ss = s//2\r\n count = 0\r\n for i in range(0,n-1):\r\n temp += L[i]\r\n if temp == ss:\r\n count += 1\r\n print(count)",
"class Solve:\r\n\r\n def __init__(self) -> None:\r\n self.n = 0;\r\n self.stripePaper = [];\r\n\r\n def vao(self) -> None:\r\n self.n = int(input());\r\n self.stripePaper = [int(item) for item in input().split(\" \")];\r\n\r\n def tong(self) -> int:\r\n tong = 0;\r\n for i in self.stripePaper:\r\n tong += i;\r\n return tong;\r\n\r\n def lam(self) -> None:\r\n dem = 0;\r\n tongTrai = 0;\r\n tongPhai = self.tong();\r\n for i in range(self.n - 1):\r\n tongTrai += self.stripePaper[i];\r\n tongPhai -= self.stripePaper[i];\r\n if(tongTrai == tongPhai): dem += 1;\r\n print(dem);\r\n\r\n def ra(self) -> None:\r\n pass;\r\n\r\n\r\ndef main():\r\n p = Solve();\r\n p.vao();\r\n p.lam();\r\n p.ra();\r\n\r\n\r\nmain();\r\n",
"x = int(input())\ny = input().split(\" \")\nz = []\nfor i in y:\n z.append(int(i))\ncount = 0\ns=sum(z)\nx=0\nfor i in range(1,len(z)):\n x+=z[i-1]\n if x==(s/2):\n count+=1\nprint(count)\n\n \t\t \t \t \t \t\t \t \t \t\t\t",
"n = int(input())\r\na = list(map(int,input().split()))\r\nc = [a[0]]\r\nfor i in range(1,len(a)):\r\n c.append(c[-1]+a[i])\r\nl = 0\r\nfor i in range(len(c)-1):\r\n if(c[i]==c[-1]-c[i]):\r\n l+=1\r\nprint(l)\r\n",
"n = int(input()) #количество клеток в полоску\r\ns = list(map(int, input().split()))\r\nq = 0\r\na = 0\r\nb = sum(s)\r\nfor c in range(0, n - 1):\r\n a += s[c]\r\n b -= s[c]\r\n if a == b:\r\n q += 1\r\nprint(q)\r\n",
"nf=int(input())\na=input().split()\nfor x in range(nf):\n a[x]=int(a[x])\nesquerdo=0\ndireito=0\ncont=0\nfor x in range(nf):\n esquerdo=esquerdo+a[x]\nfor x in range(nf-1):\n direito=direito+a[x]\n esquerdo=esquerdo-a[x]\n if(direito==esquerdo):\n cont=cont+1\nprint(cont)\n \n\n\t \t \t \t \t\t\t\t \t\t \t",
"import sys\nfrom collections import defaultdict\n# import logging\n# logging.root.setLevel(level=logging.INFO)\n\n_ = sys.stdin.readline()\nnums = map(int,sys.stdin.readline().strip().split())\ntotal = 0\nsums = defaultdict(int)\nfor i in nums:\n total += i\n sums[total] += 1\nsums[total] -= 1\n# logging.info(sums)\nprint(sums[total/2])\n",
"import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nleft, right = 0, sum(a)\r\nans = 0\r\n\r\nfor i in range(n - 1):\r\n left += a[i]\r\n right -= a[i]\r\n if left == right:\r\n ans += 1\r\n\r\nprint(ans)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nls=sum(l)\r\n\r\ncount=0\r\nx=0\r\nfor i in range(n-1):\r\n x+=l[i]\r\n y=ls-x\r\n if x==y:\r\n count+=1\r\n\r\nprint(count) \r\n\r\n ",
"n = int(input())\r\ns = list(map(int, input().split()))\r\nr = sum(s)\r\nres = 0\r\ntmp = s[0]\r\nfor i in range(1,n):\r\n if tmp*2 == r: res += 1\r\n tmp += s[i]\r\nprint(res)",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ns = sum(a)\r\ncount = 0\r\ns_cur = 0\r\nfor i in range(n-1):\r\n s_cur += a[i]\r\n if s - s_cur == s_cur:\r\n count += 1\r\nprint(count)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\npref=[0]*n\r\n\r\nfor i in range(n):\r\n pref[i]=pref[i-1]+l[i]\r\n\r\n\r\nans=0\r\nfor u in range(n-1):\r\n pre=pref[u]\r\n aft=pref[n-1]-pref[u]\r\n if pre==aft:\r\n ans+=1\r\n \r\nprint(ans)\r\n",
"import math\r\n\r\npre = []\r\nsuff = []\r\n\r\nn = int(input())\r\narr = [int(x) for x in input().split()]\r\n\r\ns = 0\r\nfor i in range(0,n):\r\n\ts = s + arr[i]\r\n\r\nd = 0\r\nans = 0\r\nfor i in range(0,n):\r\n\td = d + arr[i]\r\n\tif d==(s-d) and i!=n-1:\r\n\t\tans = ans + 1\r\n\r\nprint (ans)",
"#######################PREFIC SUM ARRAY#################\r\n\r\n\r\n\r\n\r\nn = int(input())\r\n\r\nv = list(map(int, input().split()))\r\n\r\npref = [0] * n\r\n\r\nfor i in range(n):\r\n pref[i] = pref[i - 1] + v[i]\r\n\r\nans = 0\r\n\r\nfor i in range(n - 1):\r\n prevsum = pref[i]\r\n aftersum = pref[n - 1] - pref[i]\r\n if (prevsum == aftersum):\r\n ans += 1\r\n\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\"\"\"\r\nn,q = map(int,input().split())\r\n\r\na = list(map(int,input().split()))\r\n\r\nmlist = [0] * len(a)\r\nfor i in range(len(a)):\r\n if(i==0):\r\n mlist[i] = a[i];\r\n mlist[i] = mlist[i-1] + a[i]\r\n\r\nwhile (q!=0):\r\n c,b = map(int,input().split())\r\n c = c-1\r\n b = b-1\r\n if c == 0 and b == n-1:\r\n print(mlist[b])\r\n else:\r\n print(mlist[b] - mlist[c-1])\r\n\r\n q-=1\r\n\"\"\"\r\n\r\n",
"\r\ndef main():\r\n n = int(fin())\r\n *a, = map(int, fin().split())\r\n\r\n ps, pd = [0]*(n+2), [0]*(n+2)\r\n for i in range(1, 1+n):\r\n ps[i] = ps[i-1] + a[i-1]\r\n \r\n for i in range(n, 0, -1):\r\n pd[i] = pd[i+1] + a[i-1]\r\n\r\n res = 0\r\n for i in range(1, n):\r\n if ps[i] == pd[i+1]:\r\n res+=1\r\n \r\n fout(res)\r\n\r\n# FastIO\r\nfrom sys import stdin, stdout\r\ndef fin(): return stdin.readline().strip(\"\\r\\n\")\r\ndef fout(s=\"\", end=\"\\n\"): return stdout.write(str(s)+end)\r\nif __name__ == \"__main__\":\r\n t = 1 or int(fin())\r\n for i in range(t): main()\r\n",
"n=int(input())\r\nw=[int(k) for k in input().split()]\r\nc=[]\r\nres, x=0, 0\r\nfor j in w:\r\n x+=j\r\n c.append(x)\r\nfor j in range(n-1):\r\n if c[j]==c[-1]-c[j]:\r\n res+=1\r\nprint(res)",
"_ = input()\ntmp = list(map(int, input().split()))\nresult = 0\npref = [0] * len(tmp)\nsuff = [0] * len(tmp)\npref[0] = tmp[0]\nfor i in range(1, len(pref)):\n pref[i] = pref[i - 1] + tmp[i]\nsuff[-1] = tmp[-1]\nfor i in range(len(suff) - 2, -1, -1):\n suff[i] = suff[i + 1] + tmp[i]\n#print(pref)\n#print(suff)\nfor i in range(0, len(tmp) - 1):\n if pref[i] == suff[i + 1]:\n result += 1\nprint(result)\n",
"n = int(input())\n\nvalues = list(map(int, input().split(' ')))\n\nprefix_sum = []\nsum = 0\nfor i in range(n):\n sum += values[i]\n prefix_sum.append(sum)\n\n\nresp = 0\nfor e in range(n-1):\n dif = prefix_sum[-1] - prefix_sum[e]\n if (dif == prefix_sum[e]):\n resp += 1\nprint(resp)\n",
"n = int(input())\r\nnumeros = list(map(int, input().split()))\r\nsoma = 0\r\n\r\nfor i in range(len(numeros)):\r\n soma += numeros[i]\r\n\r\nesquerda = 0\r\ncont = 0\r\n\r\nfor i in range(n - 1):\r\n esquerda += numeros[i]\r\n if(2 * esquerda == soma):\r\n cont += 1\r\n\r\nprint(cont)",
"from sys import stdin\r\n\r\n\r\nlines = stdin.readlines()\r\narr = [int(n) for n in lines[1].split()]\r\n\r\ns = 0\r\nnarr =[]\r\nfor i in arr:\r\n s += i\r\n narr.append(s)\r\n\r\ncount = 0\r\nfor i in range(len(arr)-1):\r\n if narr[i] == s/2:\r\n count += 1\r\nprint(count)",
"n = int(input())\narr = list(map(int, input().split()))\n\ninc = [0] * n\ninc[0] = arr[0]\nfor i in range(1, n):\n inc[i] = arr[i] + inc[i - 1]\n\ndec = [0] * n\ndec[n - 1] = arr[n - 1]\nfor i in range(n - 2, -1, -1):\n dec[i] = arr[i] + dec[i + 1]\n\nans = 0\nfor i in range(n - 1):\n if inc[i] == dec[i + 1]:\n ans += 1\n\nprint(ans)\n",
"n = int(input())\na = list(map(int,input().split()))\n\nl = [0 for i in range(n)]\nr = [0 for i in range(n)]\nfor i in range(n): \n if i == 0: \n l[i] = a[i]\n r[n-(i+1)] = a[n-(i+1)]\n else: \n l[i] = l[i-1]+a[i]\n r[n-(i+1)] = r[n-i]+a[n-(i+1)]\n\nans = 0\n\nfor i in range(n-1): \n if l[i] == r[i+1]: \n ans += 1\n\nprint(ans)\n\n ",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\nsum_equal = 0\r\n\r\nleft_sum = 0\r\nright_sum = sum(nums)\r\n\r\nfor i in range(0, len(nums) - 1):\r\n\tleft_sum += nums[i]\r\n\tright_sum -= nums[i]\r\n\tif left_sum == right_sum:\r\n\t\tsum_equal += 1\r\n\r\nprint(sum_equal)",
"n, a = int(input()), list(map(int, input().split()))\r\nfor i in range(1, n):\r\n a[i] += a[i - 1]\r\nprint(sum(2 * a[i] == a[n - 1] for i in range(n - 1)))",
"n = int(input())\r\nline = input()\r\nline = list(map(int, line.split()))\r\nm = 0\r\nsuml = 0\r\nsumr = sum(line)\r\nfor i in range(n - 1):\r\n el = line[i]\r\n suml += el\r\n sumr -= el\r\n if suml == sumr:\r\n m += 1\r\nprint(m)",
"import sys\r\n\r\ndef stripe(n, cum):\r\n \r\n res = 0\r\n for i in range(n):\r\n \r\n if cum[i] == cum[n] - cum[i]:\r\n res += 1\r\n \r\n return res\r\n\r\n\r\n\r\n\r\nn = int(input()) - 1\r\nl = list(map(int, sys.stdin.readline().split()))\r\n\r\ncum = []\r\ncum.append(l[0])\r\nfor i in range(1,len(l),1):\r\n cum.append(cum[i-1] + l[i])\r\n\r\n# print(cum)\r\nans = stripe(n, cum)\r\nprint(ans)",
"num = int(input())\nnums = [int(x) for x in input().split()]\n\nleft = [0] * num\ncount = 0\ncount2= 0\n\nfor i in range(num):\n if i == 0:\n left[i] = nums[i]\n else:\n left[i] = left[i - 1] + nums[i]\n count2 += nums[i]\n\n\nfor i in range(num - 1):\n if 2 * left[i] == count2:\n count += 1\n\nprint(count)\n \t\t\t\t \t\t\t\t\t \t\t \t\t\t \t\t \t\t \t\t\t\t",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nps = [0]\r\nfor i in range(n):\r\n x = ps[i] + l[i]\r\n ps.append(x)\r\nct = 0\r\nfor i in range(n-1) :\r\n if ps[i+1] == ps[n]-ps[i+1] :\r\n ct += 1\r\nprint(ct)",
"# Wadea #\r\n\r\ns = int(input())\r\nm = list(map(int, input().split()))\r\nr = 0\r\nk = sum(m)\r\nc = 0\r\nif k % 2 == 0:\r\n k //= 2\r\n for j in m[:s-1]: \r\n r += j\r\n if r == k:\r\n c += 1\r\nprint(c)\r\n ",
"from sys import stdin\ndef sin():\n return stdin.readline()\n\nn=int(sin())\nl=list(map(int,sin().split(\" \")))\na=[]+l\nb=[]+l\n\nfor i in range(1,n):\n a[i]+=a[i-1]\n b[n-i-1]+=b[n-i]\n\n#print(a)\n#print(b)\n\nc=0\nfor i in range(n-1):\n if a[i]==b[i+1]:\n c+=1\nprint(c)",
"n = int(input())\r\narr = list(map(int,input().split(' ')))\r\n\r\nc = 0\r\nS = sum(arr)\r\ns = 0\r\nfor i in range(0,n-1):\r\n s = s+arr[i]\r\n if (S-s == s):\r\n c = c+1\r\n\r\nprint(c)\r\n\r\n",
"import sys\r\ninput = sys.stdin.readline\r\nfor _ in range(1):\r\n n=int(input())\r\n arr=[int(x) for x in input().split()]\r\n s=sum(arr)\r\n ans=0\r\n curr=0\r\n for i in range(n-1):\r\n curr+=arr[i]\r\n s-=arr[i]\r\n if curr==s:\r\n ans+=1\r\n print(ans)\r\n ",
"n = input()\r\nargs = input().split()\r\nlst = []\r\nfor x in args:\r\n lst.append(int(x))\r\n\r\n\r\n\r\ndef func(lst):\r\n count = 0\r\n sum = 0\r\n for x in lst:\r\n sum = sum + x\r\n sumlist = 0\r\n for i in range(len(lst)-1):\r\n sumlist = sumlist + lst[i]\r\n if sumlist == sum / 2:\r\n count = count + 1\r\n return count\r\n\r\nprint(func(lst))",
"n = int(input())\r\nstripe = list(map(int, input().rstrip().split()))\r\nlsum = 0\r\nrsum = 0\r\ncount = 0\r\nfor i in stripe:\r\n rsum += i\r\nfor i in range(n-1):\r\n lsum += stripe[i]\r\n rsum -= stripe[i]\r\n if lsum == rsum:\r\n count += 1\r\nprint(count)",
"n = int(input())\nstripes = list(map(int, input().split()))\nsums = []\ns=0\nfor i in stripes:\n\ts+=i\n\tsums.append(s)\n\namount = 0\nfor i in range(1, n):\n\tif sums[i-1] == sums[-1] - sums[i-1]:\n\t\tamount+=1\nprint(amount)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ndef Solve(n, arr):\r\n if n == 1:\r\n return 0\r\n \r\n num_ways = 0\r\n Pre_sum = [0 for i in range(n)]\r\n Pre_sum[0] = arr[0]\r\n \r\n for i in range(1, n):\r\n Pre_sum[i] = Pre_sum[i-1] + arr[i]\r\n \r\n for i in range(n-1):\r\n left = Pre_sum[i]\r\n right = Pre_sum[n-1] - Pre_sum[i]\r\n if left == right:\r\n num_ways += 1\r\n # print(i)\r\n \r\n return num_ways\r\n\r\nprint(Solve(n, arr))\r\n ",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ns = sum(arr)\r\nx, ct = 0,0\r\nif s%2 != 0:\r\n print(0)\r\n exit(0)\r\ns = s//2\r\nfor i in range(n-1):\r\n x += arr[i]\r\n if x == s:\r\n ct += 1\r\nprint(ct)",
"x = int(input())\r\nl = list(map(int,input().split()))\r\nf1 = [0]*x\r\nfor i in range(x):\r\n f1[i] = f1[i-1] + l[i]\r\n\r\nc = 0\r\nfor j in range(1,x):\r\n if f1[j-1]*2 == f1[x-1]:\r\n c+=1\r\n\r\nprint(c)\r\n",
"n = int(input())\r\nx = list(map(int,input().split()))\r\nc = 0\r\nc1 = x[0]\r\nc2 = sum(x[1:])\r\nfor i in range(1,n):\r\n if c1 == c2:\r\n c+=1\r\n c1 += x[i]\r\n c2 -= x[i]\r\nprint(c)",
"squares = int(input())\n\nstripe = [int(x) for x in input().split(' ')]\n\nfirst = 0\nsecond = sum(stripe)\npossibilities = 0\n\nfor i in range(squares - 1):\n first += stripe[i]\n second -= stripe[i]\n if first == second:\n possibilities += 1\n\nprint(possibilities)",
"from itertools import accumulate, islice\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nS = sum(a)\r\nprint(sum(S == 2*x for x in islice(accumulate(a), n-1)))",
"import sys\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nif n == 1:\r\n print(0)\r\n sys.exit()\r\ns1 = a[0]; s2 = sum(a[1:]); ans = 0\r\nfor i in range(1, n):\r\n if s1 == s2:\r\n ans+=1\r\n s1 += a[i]\r\n s2 -= a[i]\r\nprint(ans)\r\n",
"n = int(input())\narr = list(map(int,input().split()))\npre = [arr[0]]\nfor i in range(1,n):\n pre.append(pre[-1]+arr[i])\npost = [0]*(n+1)\nfor i in range(n-1,-1,-1):\n post[i] = arr[i]+post[i+1]\nans=0\nfor i in range(n-1):\n if pre[i]-post[i+1]==0:\n ans+=1\nprint(ans) \n \n",
"if __name__=='__main__':\r\n \r\n n=int(input())\r\n strip=list(map(int,input().split()))\r\n \r\n summ=[0 for _ in range(n)]\r\n for i in range(n):\r\n summ[i]=strip[i]+summ[i-1]\r\n \r\n ways=0\r\n for i in range(n-1):\r\n if summ[i]==summ[n-1]-summ[i]:\r\n ways+=1\r\n \r\n print(ways)",
"n = int(input())\ns = list(map(int, input().split()))\n \nsoma = sum(s)\n \nls = 0\nr = 0\n \nfor i in range(n-1):\n ls += s[i]\n soma -= s[i]\n if ls == soma:\n r += 1\n \nprint(r)\n\n \t \t \t \t\t\t \t\t\t\t \t\t",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\ns=sum(lst)\r\nc=m=0\r\nfor i in range(n-1):\r\n c+=lst[i]\r\n if c*2==s:\r\n m+=1\r\nprint(m)",
"\nn = int(input())\nprefix = [] # 前缀和\ns = 0 # 数组总和\nres = 0\n\n\nfor i in input().split():\n s += int(i)\n prefix.append(s)\n\nfor i in range(n - 1):\n if s == 2*prefix[i]:\n res += 1\n\nprint(res)\n\n\n\n\n\n\n",
"n = int(input())\narray = [int(x) for x in input().split()]\n\nsoma = 0\naux = 0\ncont = 0\n\nfor e in array:\n\tsoma += e\n\nfor i in range(n-1):\t\n\taux += array[i]\n\tsoma -= array[i]\n\t\n\tif aux == soma:\n\t\tcont += 1\t\n\t\nprint(cont)\n\n\t \t \t \t\t \t\t\t \t\t\t\t\t \t\t\t\t\t \t",
"n=int(input())\r\na=list(map(int, input().split()))\r\nx=sum(a)\r\ny=0\r\nc=0\r\nfor i in range(n-1):\r\n y+=a[i]\r\n x-=a[i]\r\n # print(y,x)\r\n if x==y:\r\n c+=1\r\nprint(c) ",
"qtd = input()\r\nnumeros = [int(x) for x in input().split()]\r\n\r\nsoma = 0\r\nfor e in numeros:\r\n\tsoma += e\r\n\r\naux = 0\r\nresposta = 0\r\nfor i in range(0, len(numeros)-1):\r\n\taux += numeros[i]\r\n\tsoma -= numeros[i]\r\n\tif aux == soma:\r\n\t\tresposta += 1\r\n\t\t\r\nprint(resposta)\r\n",
"n=int(input())\r\nc=0 \r\nl=[int(i) for i in input().split()]\r\npre=[0]*(n+1)\r\nfor i in range(1,n+1):\r\n pre[i]=pre[i-1]+l[i-1]\r\nfor i in range(1,n):\r\n if pre[i]==(pre[n]-pre[i]):\r\n c+=1 \r\nprint(c)",
"n = int(input())\r\nl = list(map(int, input().split()))\r\ncount=0\r\nprefix=[0]*(n)\r\nfor i in range(n):\r\n prefix[i]=prefix[i-1]+l[i]\r\nfor i in range(n-1):\r\n if(prefix[n-1]-prefix[i]==prefix[i]):\r\n count+=1\r\nprint(count)\r\n",
"n = int(input())\nentrada = input().split()\nlista = []\ntotal = 0\n\nfor i in entrada:\n num = int(i)\n lista.append(num)\n total += num\n\npossibilidades = 0\ntemp = 0\n\nfor i in range(n-1):\n temp += lista[i]\n total -= lista[i]\n\n if temp == total:\n possibilidades += 1\n\nprint(possibilidades)",
"n = int(input()) - 1\r\nl = list(map(int, input().split()))\r\nprt1 = sum(l)\r\nprt2 = 0\r\ncnt = 0\r\nfor i in range(n):\r\n prt1 -= l[i]\r\n prt2 += l[i]\r\n if prt1 == prt2: cnt += 1\r\nprint(cnt)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\n\r\nl = list(map(int,input().split()))\r\n\r\ns = sum(l)\r\nd = 0\r\nc = 0\r\n\r\nfor i in range(n-1):\r\n d += l[i]\r\n if d == s-d:\r\n c += 1\r\n\r\n \r\nprint(c)",
"class Stripe:\r\n @staticmethod\r\n def read_input():\r\n num_squares = input('')\r\n numbers = list(map(int, input('').split()))\r\n return numbers\r\n\r\n @staticmethod\r\n def run():\r\n left, right = set(), set()\r\n numbers = Stripe.read_input()\r\n sum_left = 0 \r\n sum_right = sum(numbers) \r\n num_equals = 0\r\n\r\n for i in range(0, len(numbers)-1):\r\n sum_left += numbers[i]\r\n sum_right -= numbers[i]\r\n if sum_left == sum_right: num_equals += 1\r\n print(num_equals)\r\n \r\n\r\nif __name__ == \"__main__\":\r\n Stripe.run()",
"n=int(input())\r\narr=[int(e) for e in input().split()]\r\nsum1=[0 for _ in range(n)]\r\nsum2=[0 for _ in range(n)]\r\nfor i in range(n):\r\n if i>0:sum1[i]=sum1[i-1]+arr[i]\r\n else:sum1[i]+=arr[i]\r\nfor i in range(n-1,-1,-1):\r\n if i<n-1:sum2[i]=sum2[i+1]+arr[i]\r\n else:sum2[i]+=arr[i]\r\ncount=0\r\nfor i in range(n-1):\r\n if sum1[i]==sum2[i+1]:count+=1\r\nprint(count)",
"n = int(input())\r\nnum = list(map(int, input().split()))\r\no = 0\r\n\r\na = 0\r\nb = sum(num)\r\n\r\nfor i in range(n - 1):\r\n a += num[i]\r\n b -= num[i]\r\n\r\n if a == b:\r\n o += 1\r\n\r\nprint(o)",
"n = int(input())\r\ntira = list(map(int,input().split()))\r\ncont = 0\r\nfor i in range(1,n):\r\n tira[i] += tira[i-1]\r\n\r\nfor i in range (n-1):\r\n if tira[i] == tira[n-1]-tira[i]:\r\n cont+=1\r\nprint(cont)",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\nsb=0\r\nsa=sum(a)\r\ncnt=0\r\nfor i in range(n-1):\r\n sb+=a[i]\r\n sa-=a[i]\r\n if sa==sb:\r\n cnt+=1\r\nprint(cnt)\r\n ",
"#ROUNIAAUDI\r\nint1=int(input())\r\nd=list(map(int,input().split()))\r\n#print(d)\r\nsum1=sum(d)\r\n#print(sum1)\r\ng=0\r\nc=0\r\nfor i in range(0,int1-1):\r\n #print(g,sum1,end=\"%\")\r\n g+=d[i]\r\n sum1-=d[i]\r\n if sum1==g:\r\n c+=1\r\nprint(c)",
"n = int(input())\nnumeros = list(map(int, input().split()))\nsoma = 0\n\nfor i in range(len(numeros)):\n soma += numeros[i]\n\nesquerda = 0\nmetade = soma/2\ncont = 0\n\nfor i in range(n - 1):\n esquerda += numeros[i]\n if(esquerda == metade):\n cont += 1\n\nprint(cont)\n\n \t\t\t \t \t\t \t\t\t\t \t \t\t\t\t \t\t",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\ncur = 0\r\nret = 0\r\nfor i in range(n - 1):\r\n cur += a[i]\r\n ret += cur == (s - cur)\r\nprint(ret)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=[0]*n\r\nfor i in range(n):\r\n if i==0:\r\n s[i]=l[i]\r\n else:\r\n s[i]=l[i]+s[i-1]\r\nans=0\r\nfor i in range(1,n):\r\n if s[i-1]==s[-1]-s[i-1]:\r\n ans=ans+1\r\nprint(ans)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ncums = sum(arr)\r\nc = 0\r\nx = 0\r\nfor i in range(n - 1):\r\n x += arr[i]\r\n if x == cums - x:\r\n c += 1\r\nprint(c)\r\n",
"num_nums = int(input())\nstripe = list(map(int, input().split()))\n\ncontrol = 0\n\nfor i in stripe:\n if i != 0:\n control += 1\n\nif control == 0:\n print(num_nums - 1)\n\nelif len(stripe) == 2:\n if stripe[1]==stripe[0]:\n print(1)\n else:\n print(0)\n\nelse:\n stripe_crescente = []\n stripe_decrescente = []\n stripe_crescente.append(stripe[0])\n\n for i in range(1, len(stripe)):\n stripe_crescente.append(stripe[i] + stripe_crescente[i-1])\n\n stripe.reverse()\n\n stripe_decrescente.append(stripe[0])\n\n for i in range(1, len(stripe)):\n stripe_decrescente.append(stripe[i] + stripe_decrescente[i-1])\n\n stripe_decrescente.reverse()\n\n result = 0\n \n for i in range(0, len(stripe)-1):\n\n if(stripe_crescente[i]==stripe_decrescente[i+1]):\n result+=1\n\n print(result)\n \t \t\t\t\t\t\t\t\t\t\t\t \t\t\t\t \t",
"n=int(input())\r\nn_lst=list(map(int,input().split()))\r\n\r\nways=0\r\n\r\nstripe1=0\r\nstripe2=sum(n_lst)\r\nfor i in range(n-1):\r\n num=n_lst[i]\r\n stripe1+=num\r\n stripe2-=num\r\n if stripe1==stripe2:\r\n ways+=1\r\n\r\nprint(ways)\r\n\r\n\r\n",
"n = int(input())\r\nlista = list(map(int, input().split()))\r\nx = sum(lista) / 2\r\nsoma = cont = i = 0\r\nwhile i < n-1:\r\n\tsoma += lista[i]\r\n\tif soma == x:\r\n\t\tcont += 1\r\n\ti += 1\r\nprint (cont)\r\n",
"n = int(input())\nballs = list(map(eval, input().split(' ')))\n\nsum1 = balls[0]\nsum2 = sum(balls) - sum1\ncount = 0\nfor j in range(1,n):\n if sum1 == sum2:\n count += 1\n sum1 += balls[j]\n sum2 -= balls[j]\n else: \n sum1 += balls[j]\n sum2 -= balls[j]\n\nprint(count)\n \t \t\t\t\t \t\t\t\t\t \t\t\t\t\t \t \t",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nacc_sum = sum(arr)\r\ncnt = 0\r\ncurr = 0\r\nfor i in range(n-1):\r\n curr += arr[i]\r\n if 2*curr == acc_sum:\r\n cnt += 1\r\nprint(cnt)\r\n",
"n=int(input())\r\nl=[int(i) for i in input().split()]\r\ns=sum(l)\r\nans=l[0]\r\nc=0\r\nfor i in range(1,n):\r\n if s-ans==ans:\r\n c=c+1\r\n ans=ans+l[i]\r\nprint(c)\r\n ",
"n = int(input())\n\ndata = list(map(int, input().split()))\n\nif sum(data)%2 == 1:\n print(0)\n quit()\n\nsum_data = sum(data)//2\ncount = 0\npartial_sum = 0\n\nfor el in data[:-1]:\n partial_sum += el\n if partial_sum == sum_data: count += 1\n\nprint(count)\n \t \t \t\t \t\t \t\t\t \t\t\t\t\t \t \t",
"aux = int(input())\nlista = list(map(int, input().split()))\nsoma = sum(lista)\nmetade = soma/2\naux = 0\ncont = 0\nfor j in range(len(lista)-1):\n i = lista[j]\n aux += i\n soma -= i\n if(soma == aux):\n cont += 1\nprint(cont)\n\n \t \t\t\t\t \t\t \t \t\t \t \t \t",
"n = int(input())\ndata = list(map(int, input().split()))\nprefixes = [0]\nfor i in data:\n prefixes.append(prefixes[-1] + i)\nk = 0\nfor i, j in enumerate(prefixes[1:-1]):\n if prefixes[-1] - j == j:\n k += 1\nprint(k)\n\t\t\t\t\t \t\t\t \t\t \t\t\t\t\t\t \t\t\t",
"n = int(input().strip())\npaper = list(map(int, input().strip().split()))\nanswer = 0\ntotal = sum(paper)\npartial = 0\n\nfor i in paper[:-1]:\n partial += i\n if partial == total / 2:\n answer += 1\n\nprint(answer)\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nleftsum = 0\r\nrightsum = sum(arr)\r\nways = 0\r\nfor i in range(len(arr)-1):\r\n leftsum+=arr[i]\r\n rightsum-=arr[i]\r\n if(leftsum==rightsum):\r\n ways+=1\r\nprint(ways)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns,q,z=sum(a),0,0\r\nfor i in range(n-1):\r\n s-=a[i]\r\n q+=a[i]\r\n if s==q:z+=1\r\nprint(z)",
"n = int(input())\r\na = [0] + [int(i) for i in input().split()]\r\ncum = [0]*(n+1)\r\nfor i in range(1,n+1):\r\n cum[i] = cum[i-1]+a[i]\r\n \r\ncpt = 0\r\nfor i in range(1,n):\r\n if cum[i] == cum[-1]-cum[i]:\r\n cpt += 1\r\nprint(cpt)",
"int_inp = lambda: int(input()) #integer input\nstrng = lambda: input().strip() #string input\nstrl = lambda: list(input().strip())#list of strings as input\nmul = lambda: map(int,input().split())#multiple integers as inpnut\nmulf = lambda: map(float,input().split())#multiple floats as ipnut\nseq = lambda: list(map(int,input().split()))#list of integers\nimport math\nfrom collections import Counter,defaultdict\n\nk = int_inp()\nm =seq()\nw =sum(m)\nans =0\nsumm =0\nfor i in range(k-1):\n summ +=m[i]\n w-=m[i]\n if summ==w:\n ans+=1\nprint(ans)\n",
"n = int(input())\na = [int(i) for i in input().split()]\nsum = []\ns = 0\nfor i in a:\n s += i\n sum.append(s)\na.reverse()\nsum_reverse = []\ns = 0\nfor i in a:\n s += i\n sum_reverse.append(s)\nsum_reverse.reverse()\nl = len(sum)\ncount = 0\nfor i in range(0,l-1):\n if sum[i] == sum_reverse[i+1]:\n count+=1\nprint(count)\n",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\ns = sum(lst)\r\nr = 0\r\nif s % 2 == 0:\r\n tgt = s // 2\r\n rt = 0\r\n for x in lst[:-1]:\r\n rt += x\r\n if rt == tgt: r += 1\r\nprint(r)\r\n",
"n=int(input())\r\nnumbers=list(map(int,input().split()))\r\nways=0\r\nsumArray = []\r\nsumArray.append(numbers[0])\r\nfor i in range(1,n):\r\n sumArray.append(sumArray[i-1]+numbers[i])\r\n \r\nfor i in range(n-1):\r\n if sumArray[i]==sumArray[n-1]-sumArray[i]:\r\n ways+=1\r\nprint(ways)\r\n\r\n\r\n## O(N)",
"nf=int(input())\r\na=input().split()\r\nfor x in range(nf):\r\n a[x]=int(a[x])\r\nesquerdo=0\r\ndireito=0\r\ncont=0\r\nfor x in range(nf):\r\n esquerdo=esquerdo+a[x]\r\nfor x in range(nf-1):\r\n direito=direito+a[x]\r\n esquerdo=esquerdo-a[x]\r\n if(direito==esquerdo):\r\n cont=cont+1\r\nprint(cont)\r\n \r\n",
"n = int(input())\r\nstrip = list(map(int, input().split()))\r\n\r\ngrandSum = sum(strip)\r\n\r\nleftSum = 0\r\nres = 0\r\n\r\nfor i in range(n-1):\r\n leftSum += strip[i]\r\n grandSum -= strip[i]\r\n if leftSum == grandSum:\r\n res += 1\r\n\r\nprint(res)",
"n = int(input())\nnums = input().split()\nsoma = 0\nsubtotais = []\nfor i in range(n):\n nums[i] = int(nums[i])\n soma += nums[i]\n if i == 0:\n subtotais.append(nums[i])\n else:\n subtotais.append(nums[i] + subtotais[i-1])\n\nsubtotais_rev = []\nfor j in range(n):\n if j == 0:\n subtotais_rev.append(soma)\n else:\n subtotais_rev.append(subtotais_rev[j-1] - nums[j-1])\n\n\ncont = 0\nif soma%2 == 0:\n for k in range(n-1):\n if subtotais[k] == subtotais_rev[k+1]:\n cont += 1\n\nprint(cont)\n \t\t \t \t\t\t\t \t \t \t \t\t \t",
"n = int(input())\r\nli = list(map(int, input().split()))\r\n\r\ns = sum(li)\r\nway = 0\r\nx = li[way]\r\nfor i in range(1, n):\r\n if s-x == x:\r\n way += 1\r\n x += li[i]\r\nprint(way)\r\n",
"def solve(n,seq) :\r\n pointer1 = 0\r\n ways = 0\r\n \r\n leftValue = 0\r\n rightValue = sum(seq)\r\n \r\n while pointer1 < n-1 :\r\n leftValue += seq[pointer1]\r\n rightValue -= seq[pointer1]\r\n \r\n if leftValue == rightValue :\r\n ways += 1\r\n \r\n pointer1 += 1\r\n return ways\r\n \r\nn = int(input())\r\nseq = list(map(int,input().split()))\r\n\r\nprint(solve(n,seq))\r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n ",
"# LUOGU_RID: 132831506\nn = int(input())\r\nline = list(map(int, input().split()))\r\n\r\nsum_front = [0]\r\nindex = 0\r\nfor i in line: # 初始化前缀和\r\n sum_front.append(sum_front[index] + i)\r\n index += 1\r\noutput = 0\r\nfor i in range(1,n):\r\n if sum_front[i] == sum_front[n] - sum_front[i]:\r\n output += 1\r\nprint(output)",
"nums = int(input())\r\nparam = list(map(int, input().split()))\r\ns = sum(param)\r\n\r\naccur = 0\r\nresult = 0\r\n\r\nfor i in range(nums - 1):\r\n accur += param[i]\r\n if accur == (s - accur):\r\n result += 1\r\n\r\nprint(result)\r\n",
"n = int(input())\r\n\r\na = [0] * n\r\narr = list(map(int, input().split()))\r\na[0] = arr[0]\r\nfor i in range(1,len(arr)):\r\n a[i] = arr[i] + a[i-1]\r\ncnt = 0\r\nlast = a[-1]\r\nfor i in range(0, len(a) - 1):\r\n sum_f = a[i]\r\n\r\n if last - a[i] == sum_f:\r\n cnt += 1\r\n\r\n\r\nprint(cnt)",
"n=int(input())\r\na = list(map(int, input().strip().split(' ')))\r\ns=sum(a)\r\nk=0\r\nc=0\r\nfor i in range(n-1):\r\n k+=a[i]\r\n s-=a[i]\r\n if k==s:\r\n \r\n c+=1\r\nprint(c)\r\n",
"if __name__ == '__main__':\r\n\tn = int(input())\r\n\tsequence = [int(x) for x in input().split()]\r\n\r\n\tcum_sum = list()\r\n\tcurr_sum = 0\r\n\r\n\tfor i in sequence:\r\n\t\tcurr_sum += i\r\n\t\tcum_sum.append(curr_sum)\r\n\r\n\ttotal_sum = cum_sum[-1]\r\n\r\n\tans = 0 \r\n\tfor i in cum_sum[:-1]:\r\n\t\tif 2*i == total_sum:\r\n\t\t\tans += 1\r\n\r\n\tprint(ans)\r\n\t",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns,f,x=0,sum(a),0\r\nfor i in range(n-1):\r\n s+=a[i]\r\n f-=a[i]\r\n if s==f:x+=1\r\nprint(x)",
"##c\r\ndef main():\r\n n=int(input())\r\n ans=0\r\n A=list(map(int,input().split()))\r\n l=0\r\n r=sum(A)\r\n for s in range(n-1):\r\n l+=A[s]\r\n r-=A[s]\r\n if ( r==l ):\r\n ans+=1\r\n print(ans)\r\nmain() \r\n",
"n = int(input())\na = list(map(int, input().split()))\nt = 0\ndp = [0] * (n + 1)\nfor i in range(n):\n dp[i + 1] = dp[i] + a[i]\nfor i in range(1, n):\n if dp[i] == dp[n] - dp[i]:\n t += 1\nprint(t)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=0\r\nb=[0]\r\nfor i in range(n):\r\n b.append(b[i]+a[i])\r\nfor i in range(n-1):\r\n if b[i+1]==b[n]-b[i+1]:\r\n s+=1\r\nprint(s)",
"n = int(input())\r\nv = list(map(int, input().split()))\r\n\r\ns1 = 0\r\ns2 = sum(v)\r\nc = 0\r\n\r\nfor i in range(n-1):\r\n s1 += v[i]\r\n s2 -= v[i]\r\n if(s1 == s2):\r\n c += 1\r\nprint(c)",
"n = int(input())\r\nmass = list(map(int, input().split()))\r\ns1 = sum(mass)\r\ns2 = 0\r\nk = 0\r\nfor i in range(n - 1):\r\n s2 += mass[i]\r\n s1 -= mass[i]\r\n if s2 == s1:\r\n k += 1\r\nprint(k)",
"n = int(input())\n\nl = list(map(int, input().split()))\n\nsumL = 0\nsumR = sum(l)\n\nt = 0\n\nfor i in range(n-1):\n sumL += l[i]\n sumR -= l[i]\n if sumL == sumR:\n t += 1\nprint(t)\n\t \t\t\t\t \t\t \t \t \t\t\t \t \t\t \t \t",
"n=int(input())\r\na=list(map(int,input().split()))\r\ntsum=0\r\nfor i in a:\r\n tsum+=i\r\n\r\nif tsum%2!=0:\r\n print(0)\r\nelse:\r\n tsum//=2\r\n count=0\r\n helper=0\r\n for j in a:\r\n helper+=j\r\n if tsum==helper:\r\n count+=1\r\n if tsum==0:\r\n print(count-1)\r\n else:\r\n print(count)\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nts=sum(a)\r\ns=0\r\nans=0\r\nfor i in range(n-1):\r\n s+=a[i]\r\n if s == ts/2:\r\n ans+=1 \r\nprint(ans)",
"\r\nn = int(input())\r\na = list(map(int,input().split()))\r\ns = sum(a)\r\nways = 0\r\nx = a[0]\r\n\r\nfor i in range(1 , n):\r\n if s - x == x :\r\n ways +=1\r\n\r\n x +=a[i]\r\n\r\nprint(ways)\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=0\r\nc=a[0]\r\nd=sum(a)\r\nfor i in range(1,n):\r\n if c==d-c:\r\n b+=1\r\n c+=a[i]\r\nprint(b)",
"n = int(input())\narr = list(map(int, input().split()))\n\nprefix = [arr[0]]\nfor i in range(1, n):\n prefix.append(prefix[i - 1] + arr[i])\n\nans = 0\nfor i in range(n - 1):\n if prefix[i] == prefix[n - 1] - prefix[i]:\n ans += 1\n\nprint(ans)\n",
"n = int(input())\r\nli = [int(x) for x in input().split()]\r\nres = 0\r\ns1 = 0\r\ns2 = sum(li)\r\n\r\nfor i in range(0, n-1):\r\n s1 += li[i]\r\n s2 -= li[i]\r\n if s1 == s2:\r\n res += 1\r\nprint(res)",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ncount = 0\r\nsum1 = 0\r\nsum2 = 0\r\n\r\nfor x in a:\r\n sum2 += x \r\n\r\nfor x in a[0:-1]:\r\n sum1 += x\r\n sum2 -= x\r\n if sum1 == sum2:\r\n count += 1\r\n\r\nprint(count)\r\n",
"n = int(input())\r\nA = list(map(int, input().split()))\r\nC = [0]+A\r\nfrom itertools import accumulate\r\nC = list(accumulate(C))\r\nans = 0\r\nfor i in range(1, n):\r\n if C[i]-C[0] == C[-1]-C[i]:\r\n ans += 1\r\nprint(ans)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\ncu=0\r\nm=sum(l)\r\nfor i in range(n-1):\r\n cu+=l[i]\r\n if cu==m-cu:\r\n c+=1\r\nprint(c)\r\n ",
"# LUOGU_RID: 133039189\nn = int(input())\r\nline = list(map(int, input().split()))\r\n\r\n求和 = sum(line)\r\n\r\n目前总和 = 0\r\n计数 = 0\r\nfor i in range(0,n-1):\r\n 目前总和 += line[i]\r\n if 目前总和 + 目前总和 == 求和:\r\n 计数 += 1\r\nprint(计数)",
"n = int(input())\r\nteste = list(map(eval, input().split()))\r\n\r\nsoma1 = teste[0]\r\nsoma2 = sum(teste) - soma1\r\n\r\ncont = 0\r\n\r\nfor i in range(n-1):\r\n if soma1 == soma2:\r\n cont += 1\r\n soma1 += teste[i+1]\r\n soma2 -= teste[i+1]\r\n else:\r\n soma1 += teste[i+1]\r\n soma2 -= teste[i+1]\r\n\r\n\r\nprint(cont)",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\np=a[:]\r\ns=a[:]\r\n\r\nfor i in range(1,n):\r\n p[i]+=p[i-1]\r\nfor i in range(n-2,-1,-1):\r\n s[i]+=s[i+1]\r\nan=0\r\nfor i in range(n-1):\r\n if p[i] == s[i+1]:\r\n an+=1\r\nprint(an)",
"\r\n# Time complexity is : O(n) Where n is : num_of_squares.\r\n\r\ndef get_all_ways_to_cut_stripe(num_of_squares, squares):\r\n num_of_ways = 0\r\n left_summation_squares = [0] * num_of_squares\r\n right_summation_squares = [0] * num_of_squares\r\n\r\n for left_index in range(num_of_squares):\r\n right_index = -(left_index+1)\r\n if left_index == 0:\r\n left_summation_squares[left_index] = squares[left_index]\r\n right_summation_squares[right_index] = squares[right_index]\r\n continue\r\n \r\n left_summation = squares[left_index] + left_summation_squares[left_index - 1]\r\n right_summation = squares[right_index] + right_summation_squares[right_index + 1]\r\n\r\n left_summation_squares[left_index] = left_summation\r\n right_summation_squares[right_index] = right_summation\r\n\r\n\r\n for i in range(num_of_squares - 1):\r\n current_left_summation = left_summation_squares[i]\r\n current_right_summation = right_summation_squares[i + 1]\r\n\r\n if current_left_summation == current_right_summation:\r\n num_of_ways += 1\r\n\r\n return num_of_ways\r\n \r\n\r\n\r\nif __name__ == \"__main__\":\r\n \r\n num_of_squares = int(input())\r\n squares = input().strip().split()\r\n\r\n for i in range(num_of_squares):\r\n squares[i] = int(squares[i])\r\n\r\n res = get_all_ways_to_cut_stripe(num_of_squares, squares)\r\n\r\n print(res)",
"n = int(input())\r\nl = [int(i) for i in input().split()]\r\nx = sum(l) ; temp = 0 ; ans = 0\r\nfor i in range(n-1):\r\n temp+= l[i]\r\n if(temp == (x - temp)):\r\n ans+=1\r\nprint(ans)",
"n = int(input())\r\nA = list(map(int,input().split()))\r\ns = sum(A)\r\ns1 = 0\r\nk = 0\r\nfor i in range(n - 1):\r\n s1 += A[i]\r\n s -= A[i]\r\n if s == s1:\r\n k += 1\r\nprint(k)\r\n",
"from collections import *\r\n# from math import ceil, gcd,inf\r\nfrom functools import *\r\nimport sys\r\ninput = lambda: sys.stdin.readline().rstrip() # faster!\r\n\r\n\r\nn=int(input())\r\n*arr,=map(int,input().split())\r\nsuml=0;sumr=sum(arr);ans=0\r\nfor i in arr[:-1]:\r\n suml+=i;sumr-=i\r\n if suml==sumr:ans+=1\r\nprint(ans) \r\n \r\n ",
"# -*- coding: utf-8 -*-\r\n\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nsuma,cont,tot = sum(a),0,0\r\n\r\nfor i in range(n-1):\r\n suma -= a[i]\r\n cont += a[i]\r\n if suma == cont: tot += 1\r\n \r\nprint(tot)\r\n",
"n = int(input())\r\nnth=list(map(int,input().split(\" \")))\r\nc=0\r\ns1=sum(nth)\r\ns2=0\r\nfor x in range(n-1):\r\n s1-=nth[x]\r\n s2+=nth[x]\r\n #print(s1,s2)\r\n if s1==s2:\r\n c+=1\r\nprint(c)\r\n\"\"\"\"\"\r\nif c>0:\r\n print(c-1)\r\nelse:\r\n print(c)\r\n\"\"\"",
"n = int(input())\nl = list(map(int,input().split()))\nok = sum(l); add = 0;hisab =0\nfor i in range(n-1):\n add+=l[i]\n ok-=l[i]\n if(ok==add):\n hisab+=1\nprint(hisab)\n\n\t \t\t\t \t\t\t\t \t \t\t\t \t \t\t",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = [a[0]]\r\ns = a[0]\r\nfor i in range(1, n):\r\n s += a[i]\r\n b.append(s)\r\nk = 0\r\nfor i in range(n - 1):\r\n if s == 2 * b[i]:\r\n k += 1\r\nprint(k)\r\n",
"num_squares=int(input())\r\nsquares=input()\r\nsquares=squares.split()\r\nsquares=map(int,squares)\r\nsquares=list(squares)\r\ncount=0\r\nleft_sum=0\r\nright_sum=sum(squares)\r\n\r\nfor i in range(num_squares-1):\r\n left_sum+=squares[i]\r\n #if squares[i]>=0:\r\n right_sum-=squares[i]\r\n #else:\r\n #right_sum+=squares[i]\r\n if left_sum==right_sum:\r\n count+=1\r\nprint(count)",
"n=int(input())\r\narr=list(map(int,input().split()))\r\npre=[arr[0]]\r\nsuff=[arr[-1]]\r\nfor i in range(1,n):\r\n pre.append(pre[i-1]+arr[i])\r\nfor i in range(-2,-n-1,-1):\r\n suff.append(suff[-i-2]+arr[i])\r\nsuff=list(reversed(suff))\r\nans=0\r\nfor i in range(n-1):\r\n if suff[i+1]==pre[i]:\r\n ans+=1\r\nprint(ans)\r\n",
"MOD = 10**9 + 7\r\nI = lambda:list(map(int,input().split()))\r\n\r\nn, = I()\r\nl = [0] + I()\r\na = [0]*(n + 1)\r\nfor i in range(1, n + 1):\r\n\ta[i] = a[i - 1] + l[i]\r\nsm = a[-1]\r\ncount = 0\r\nfor i in range(1,n):\r\n\tif a[i] == a[-1] - a[i]:\r\n\t\tcount += 1\r\nprint(count)",
"from collections import deque,Counter\nfrom math import *\nimport sys\nimport random\nfrom bisect import *\nfrom functools import reduce\nfrom sys import stdin\nimport copy\ninput = lambda: sys.stdin.readline().rstrip()\n\nn = int(input())\narr = list(map(int,input().split()))\nprefix = [0 for i in range(n)]\nfor i in range(0,n):\n prefix[i] = prefix[i-1]+arr[i]\nwhole = sum(arr)\nans=0\nfor i in range(n-1):\n if prefix[i] == whole-prefix[i]:\n ans+=1\nprint(ans)\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=[a[0]]\r\nfor i in range(1,n):\r\n b.append(b[i-1]+a[i])\r\nk=0\r\nfor i in range(n-1):\r\n if b[n-1]-b[i]==b[i]:\r\n k+=1\r\nprint(k)",
"x=int(input())\r\na=list(map(int,input().split()))\r\ns=0\r\no=[]\r\np=[]\r\nfor i in range(len(a)-1):\r\n s+=a[i]\r\n o.append(s)\r\ns=0\r\nfor i in range(len(a)-1,0,-1):\r\n s+=a[i]\r\n p.append(s)\r\np.reverse()\r\nn=0\r\nfor i in range(len(p)):\r\n if p[i]==o[i]:\r\n n+=1\r\nprint(n)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Sep 26 07:39:29 2019\r\n\r\n@author: avina\r\n\"\"\"\r\n\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\n\r\npre_fix = [l[0]]\r\nfor i in range(1,n):\r\n pre_fix.append(pre_fix[i-1] + l[i])\r\n\r\nans = 0\r\nfor i in range(n-1):\r\n if pre_fix[i] == pre_fix[n-1] - pre_fix[i]:\r\n ans+=1\r\nprint(ans)",
"from collections import Counter as cc,defaultdict as df\r\nimport sys\r\nfrom math import *\r\ndef counter(l): return dict(cc(l))\r\nbin = lambda x: format(x, 'b')\r\ndef input(): return sys.stdin.readline().strip()\r\ndef prefixSum(arr):\r\n for i in range(1, len(arr)):arr[i] = arr[i] + arr[i-1]\r\n return arr\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\ns=sum(l)\r\nc=0\r\ncount=0\r\nfor i in range(n-1):\r\n c+=l[i]\r\n s-=l[i]\r\n if c==s:\r\n count+=1\r\nprint(count)\r\n\r\n",
"n = int(input())\r\nm = list(map(int,input().split()))\r\nz = sum(m)\r\na = 0; c =0\r\nfor i in range(n-1):\r\n a+=m[i]\r\n z-=m[i]\r\n if(a==z):\r\n c+=1\r\n \r\nprint(c)",
"n = int(input())\r\ni = 0\r\ns = 0\r\na = [0] * n\r\nfor item in input().split():\r\n s += int(item)\r\n a[i] = s\r\n i += 1\r\nif s % 2 == 1:\r\n print(0)\r\nelse:\r\n s = s // 2\r\n counter = 0\r\n for i in range(n - 1):\r\n if a[i] == s:\r\n counter += 1\r\n print(counter)",
"import sys,math as mt\r\nI=lambda:list(map(int,input().split()))\r\nn,=I()\r\nl=[0]+I()\r\nans=0\r\nfor i in range(1,n+1):\r\n\tl[i]+=l[i-1]\r\ntot=l[-1]\r\nfor i in range(1,n):\r\n\tif l[i]==tot-l[i]:\r\n\t\tans+=1\r\nprint(ans)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nsumm_right=sum(l)\r\nsumm_left=0\r\ncounter=0\r\nfor i in range(n-1):\r\n summ_left+=l[i]\r\n summ_right-=l[i]\r\n if summ_left==summ_right:\r\n counter+=1\r\nprint(counter)\r\n ",
"n=int(input())\r\na=list(map(int , input().split()))\r\ns=sum(a)\r\nans=0\r\nfor i in range(1,n):\r\n a[i]=a[i]+a[i-1]\r\nfor i in range(n-1):\r\n if a[i]==a[n-1]-a[i]:\r\n ans+=1\r\nprint(ans)\r\n\r\n",
"n = int(input())\nteste = list(map(eval, input().split()))\n\nsoma1 = teste[0]\nsoma2 = sum(teste) - soma1\n\ncont = 0\n\nfor i in range(n-1):\n if soma1 == soma2:\n cont += 1\n soma1 += teste[i+1]\n soma2 -= teste[i+1]\n else:\n soma1 += teste[i+1]\n soma2 -= teste[i+1]\n\n\nprint(cont)\n\t\t \t \t\t \t \t \t \t\t\t \t \t\t",
"\r\n\r\nn = int(input())\r\nx = [int(x) for x in input().split()] \r\n\r\nSum = [0] *n\r\nSum[0] = x[0]\r\nfor i in range(1,n):\r\n Sum[i] = Sum[i-1] + x[i]\r\n \r\n\r\nc=0\r\nfor i in range(n-1):\r\n if Sum[i] == Sum[n-1]/2:\r\n c+=1\r\nprint(c)",
"qtd = input()\nnumeros = [int(x) for x in input().split()]\n\nsoma = 0\nfor e in numeros:\n\tsoma += e\n\naux = 0\nresposta = 0\nfor i in range(0, len(numeros)-1):\n\taux += numeros[i]\n\tsoma -= numeros[i]\n\tif aux == soma:\n\t\tresposta += 1\n\t\t\nprint(resposta)\n\n\n \t \t \t\t \t\t\t \t\t \t\t \t \t\t \t\t",
"n=int(input())\r\na=list(map(int,input().split()))\r\nps=[]\r\nsum=0\r\nfor i in range(0,n):\r\n sum+=a[i]\r\n ps.append(sum)\r\nif(ps[n-1]%2==0):\r\n k=int(ps[n-1]/2)\r\n c=0\r\n for i in range(0,n-1):\r\n if(ps[i]==k):\r\n c+=1\r\n print(c)\r\nelse:\r\n print(0)",
"n=int(input())\n\nA=list(map(int,input().split()))\n\nSums=[]\ns=0\n\nfor i in range(n):\n s+=A[i]\n Sums.append(s)\nans=0\nfor i in range(0,n-1):\n if(Sums[i]==s-Sums[i]):\n ans+=1\nprint(ans)\n",
"n=int(input())\r\nll=list(map(int,input().split()))\r\ns=sum(ll)\r\nc=0\r\nresult=0\r\nfor i in ll[:n-1]:\r\n c+=i\r\n if c==s-c:\r\n result+=1\r\nprint(result)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nfor i in range(1, n):\r\n a[i] += a[i - 1]\r\nans = 0 if a[-1] % 2 else a[:-1].count(a[-1] // 2)\r\nprint(ans)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nt = 0\r\nfor i in arr:\r\n t += i\r\ni = 0\r\nc = 0\r\nsl = 0\r\nsr = t\r\nwhile i < n-1:\r\n sl += arr[i]\r\n sr -= arr[i]\r\n if sl == sr:\r\n c += 1\r\n i += 1\r\nprint(c)\r\n",
"amount_of_squares = int(input())\nnumbers_written = [ int(x) for x in input().split() ]\n\nleft_numbers_sum = 0\nways_to_cut_the_stripe = 0\ntotal_sum = sum(numbers_written)\n\nfor n in range(amount_of_squares-1):\n\n\tleft_numbers_sum += numbers_written[n]\n\n\n\tif left_numbers_sum==total_sum-left_numbers_sum:\n\t\tways_to_cut_the_stripe+=1\n\nprint (ways_to_cut_the_stripe)\n\n\t \t \t \t\t\t \t \t\t\t \t\t \t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n l[i]=l[i]+l[i-1]\r\ncount=0\r\nfor i in range(n-1):\r\n if(l[i]==l[n-1]-l[i]):\r\n count+=1\r\nprint(count)",
"tamanho = int(input())\r\nlista = list(map(int, input().split()))\r\n\r\nsumLista = [0] * tamanho\r\nsumListaInv = [0] * tamanho\r\n\r\nfor i in range(tamanho):\r\n if(i == 0):\r\n sumLista[i] += lista[i]\r\n else:\r\n sumLista[i] = lista[i] + sumLista[i - 1]\r\n\r\nfor i in range(tamanho -1, -1, -1):\r\n if(i == (tamanho -1)):\r\n sumListaInv[i] += lista[i]\r\n else:\r\n sumListaInv[i] = lista[i] + sumListaInv[i + 1]\r\n\r\nsumListaInv = sumListaInv[::-1]\r\ncont = 0\r\n\r\nfor i in range(tamanho - 1):\r\n if(sumLista[i] == sumListaInv[tamanho -2 - i]):\r\n cont += 1\r\n\r\nprint(cont)",
"n=int(input())\r\nx=list(map(int,input().split()))\r\nans,su,s=0,sum(x),0\r\nfor i in range(n-1):\r\n s+=x[i]\r\n ans+=s==su-s\r\nprint(ans)",
"n = int(input())\nsquares = list(map(int, input().split()))\n\ncortes = 0\n\nia, ib = 0, 0\n\n\t\nsoma_esq = squares[0]\nsoma_dir = 0\nfor i in range(1, len(squares)):\n\tsoma_dir += squares[i]\n\nfor j in range(1, len(squares)):\n if soma_dir == soma_esq:\n cortes += 1\n soma_dir -= squares[j]\n soma_esq += squares[j]\n \n\t\t\nprint(cortes)\n",
"input()\r\nx = list(map(int, input().split()))\r\ny = [[0, 0] for _ in range(len(x))]\r\n#y[0][0] = x[0]\r\nfor i in range(len(x)):\r\n y[i][0] = y[i-1][0] + x[i]\r\nfor i in reversed(range(len(x)-1)):\r\n y[i][1] = x[i+1]+y[i+1][1]\r\nc = 0\r\nfor i in y[:-1]:\r\n if i[0] == i[1]: c+=1\r\nprint(c)\r\n\r\n",
"N = int(input())\r\nli = input().split()\r\nres = 0\r\nacu = []\r\nfor i in range(N):\r\n n = int(li[i])\r\n acu += [0]\r\n if i == 0:\r\n acu[i] = n\r\n else:\r\n acu[i] = acu[i - 1] + n\r\nfor i in range(N-1):\r\n if acu[i] == (acu[N-1]-acu[i]):\r\n res += 1\r\n\r\nprint(res)",
"n=int(input())\r\ns=input()\r\na=[int(i) for i in s.split()]\r\nt=0\r\nsa=0\r\nfor j in range(len(a)):\r\n sa=sa+a[j]\r\nsx=sa\r\nsy=0\r\nfor i in range(n-1):\r\n sx=sx-a[i]\r\n sy=sy+a[i]\r\n if sx==sy:\r\n t=t+1\r\nprint(t)\r\n",
"def task1_fun(arr):\n\tif len(arr) == 1:\n\t\treturn 0\n\tpref_arr = [0]*(len(arr)+1)\n\tans = 0\n\tfor i in range(len(arr)):\n\t\tpref_arr[i+1] = pref_arr[i] + arr[i]\n\tif (pref_arr[-1])%2 == 1:\n\t\treturn 0\n\tfind_elem = pref_arr[-1]/2\n\tfor num in pref_arr[1:-1]:\n\t\tif num == find_elem:\n\t\t\tans += 1\n\treturn ans\n\nk = int(input())\narr = [0]*k\narr = [int(x) for x in input().split()]\nprint(task1_fun(arr))\n \t \t\t \t \t\t \t\t \t \t \t\t",
"import sys\r\nimport math\r\nfrom collections import defaultdict,Counter\r\nfrom itertools import permutations\r\nfrom collections import deque\r\nfrom decimal import Decimal\r\nfrom fractions import Fraction\r\n \r\n \r\ndef sin():\r\n\treturn int(sys.stdin.readline())\r\n \r\ndef array():\t\r\n\treturn list(map(int, sys.stdin.readline().strip().split()))\r\n \r\ndef two():\r\n\treturn map(int, sys.stdin.readline().strip().split())\r\n \r\ndef multiple():\r\n\treturn [int(x) for x in sys.stdin.readline().split()]\r\n \r\ndef string():\r\n\treturn sys.stdin.readline().strip()\r\n \r\ndef sqrt(x):\r\n\tlow , high = 0 , x\r\n\twhile low <= high:\r\n\t\tmid = (low + high) // 2\r\n\t\tif mid * mid <= x < (mid+1) * (mid+1):\r\n\t\t\treturn mid\r\n\t\telif x < mid * mid:\r\n\t\t\thigh = mid - 1\r\n\t\telse:\r\n\t\t\tlow = mid + 1\r\n \r\n \r\nn = sin()\r\narr = array()\r\n\r\nres = sum(arr)\r\n\r\ncount = 0\r\npre = 0\r\n\r\nfor i in range(n-1):\r\n\tpre += arr[i]\r\n\tif pre == res - pre:\r\n\t\tcount += 1\r\n\r\n\r\nprint(count)",
"n = int(input())\r\narr = list(map(int, input().split(\" \")))\r\n\r\ndef getCount(arr):\r\n total = sum(arr) # O(n)\r\n temp = 0 # O(1)\r\n count = 0 # O(1)\r\n \r\n for v in arr[:len(arr)-1]: #O(n-1)\r\n temp += v\r\n if temp == total - temp:\r\n count += 1\r\n \r\n return count\r\n\r\nprint(getCount(arr))",
"'''input\n9\n1 5 -6 7 9 -16 0 -2 2\n'''\nfrom sys import stdin, setrecursionlimit\nfrom collections import defaultdict\nimport math\n\nsetrecursionlimit(15000)\n\n\ndef get_sum(arr):\n\tpre = [arr[0]]\n\tfor i in range(1, len(arr)):\n\t\tpre.append(pre[-1] + arr[i])\n\n\tpost = [0] * len(arr)\n\tpost[-1] = arr[-1]\n\tfor i in range(len(arr) - 2, -1, -1):\n\t\tpost[i] = arr[i] + post[i + 1]\n\n\treturn pre, post\n\n# main starts\nn = int(stdin.readline().strip())\narr = list(map(int, stdin.readline().split()))\npre, post = get_sum(arr)\n\ncount = 0\nfor i in range(1, len(arr)):\n\tif pre[i - 1] == post[i]:\n\t\tcount += 1\nprint(count)\n",
"sum = 0\n\nentrada = int(input())\nentradas = input()\nentradas = entradas.split(\" \")\nfor i in range(len(entradas)):\n entradas[i] = int(entradas[i])\n\nesquerda = [0] * len(entradas)\n\nfor i in range(entrada):\n if i == 0:\n esquerda[i] = entradas[i]\n else:\n esquerda[i] = esquerda[i - 1] + entradas[i]\n sum += entradas[i]\n\ncontador = 0\nfor i in range(entrada - 1):\n if 2 * esquerda[i] == sum:\n contador += 1\n\nprint(contador)\n\t \t \t\t \t \t \t \t \t \t \t \t",
"n = int(input())\r\nS = list(map(int,input().split()))\r\ntotal = sum(S)\r\n\r\nsSum = [0] * n\r\nsSum[0] = S[0]\r\nfor i in range(1, n):\r\n sSum[i] += sSum[i-1] + S[i]\r\n\r\ncount = 0\r\nfor i in range(n-1):\r\n value = sSum[i]\r\n if value == (total-value) :\r\n count += 1\r\nprint(count)",
"t = int(input())\r\nentrada = [int(x) for x in input().split()]\r\n\r\nsoma = 0\r\ntotal = 0\r\narr = []\r\nfor i in entrada:\r\n soma += i\r\n arr.append(soma)\r\n\r\nfor i in range(t-1):\r\n if(arr[i] == arr[-1] - arr[i]):\r\n total+= 1\r\n \r\nprint(total)",
"n = int(input())\narr = [int(p) for p in input().split()]\nsm = sum(arr)\nsuffixSum = [arr[-1]]\nprefixSum = [arr[0]]\nfor i in range(len(arr)-2, -1, -1):\n suffixSum.append(suffixSum[-1] + arr[i])\n prefixSum.append(prefixSum[-1] + arr[n-1-i])\nsuffixSum = list(reversed(suffixSum))\ncount = 0\nfor i in range(1, len(prefixSum)):\n if prefixSum[i-1] == suffixSum[i]:\n count += 1\nprint(count)",
"n = int(input())\r\nA = [0]*n\r\nstrA = input().split(' ')\r\nfor i in range (0, n):\r\n A[i] = int(strA[i])\r\nfor i in range (1, n):\r\n A[i] += A[i-1]\r\nans = 0\r\nfor i in range (0, n-1):\r\n if A[n-1] - A[i] == A[i]:\r\n ans += 1\r\nprint(ans)",
"n=int(input());\r\nar=list(map(int,input().split()));\r\n\r\narpartsum=0;\r\narsum=sum(ar);\r\nans=0;\r\nfor i in range(n-1):\r\n arpartsum+=ar[i];\r\n if arpartsum==arsum-arpartsum:\r\n ans+=1;\r\n\r\nprint(ans);\r\n",
"n=int(input())\na=list(map(int,input().split()))\nl,r,c=0,sum(a),0\nfor i in range(n-1):\n\tl+=a[i]\n\tr-=a[i]\n\tif l==r:\n\t\tc+=1\nprint(c)\n\n \t\t\t\t \t \t\t\t\t\t \t\t \t\t\t\t \t \t",
"n = int(input())\r\nnumbers = list(map(int, input().split()))\r\n\r\ntotal_sum = sum(numbers)\r\nleft_sum = 0\r\ncount = 0\r\n\r\nfor i in range(n - 1):\r\n left_sum += numbers[i]\r\n if left_sum * 2 == total_sum:\r\n count += 1\r\n\r\nprint(count)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ns = [0] * n\r\ns[0] = a[0]\r\nfor i in range(1, n):\r\n s[i] = s[i - 1] + a[i]\r\n\r\ncnt = 0\r\nfor i in range(n - 1):\r\n if s[i] * 2 == s[n - 1]:\r\n cnt += 1\r\nprint(cnt)\r\n\r\n",
"n=int(input())\r\nar=list(map(int,input().split(' ')))\r\nc,s0=0,ar[0]\r\ns=sum(ar)\r\nfor i in range(1,n):\r\n if(2*s0==s):\r\n c+=1\r\n s0+=ar[i]\r\nprint(c)\r\n",
"n=int(input())\nss=list(map(int, input().split()))\nl=0\nr=sum(ss)-ss[0]\nans=0\nfor i in range(n-1):\n l+=ss[i]\n if r==l:\n ans+=1\n r-=ss[i+1]\nprint (ans)\n \t \t\t\t \t \t \t\t\t\t\t\t \t \t",
"n = int(input())\nnums = [*map(int, input().split())]\n\nf = 0\nsoma = sum(nums)\ns1 = 0\ns2 = soma\nfor i in range(n-1):\n e = nums[i]\n s1 += e\n s2 -= e\n if s1 == s2:\n f += 1\n \nprint(f) \n \n",
"n = int(input())\nl = list(map(int, input().split()))\ncnt = 0\ne = 0\nsomar = sum(l)\nfor i in range(n-1):\n e += l[i]\n if somar - e == e:\n cnt +=1\n\nprint(cnt)\n\n\t\t\t \t\t \t\t \t\t\t \t\t\t \t\t\t \t\t\t",
"n = int(input())\ntira = list(map(int,input().split()))\ncont = 0\nfor i in range(1,n):\n tira[i] += tira[i-1]\n\nfor i in range (n-1):\n if tira[i] == tira[n-1]-tira[i]:\n cont+=1\nprint(cont)",
"n = int(input())\r\nballs = list(map(eval, input().split(' ')))\r\n\r\nsum1 = balls[0]\r\nsum2 = sum(balls) - sum1\r\ncount = 0\r\nfor j in range(1,n):\r\n if sum1 == sum2:\r\n count += 1\r\n sum1 += balls[j]\r\n sum2 -= balls[j]\r\n else: \r\n sum1 += balls[j]\r\n sum2 -= balls[j]\r\n\r\nprint(count)",
"n= int(input())\r\n\r\na= [0] + list(map(int, input().split()))\r\nb= [0] * len(a)\r\nc= [0] * (len(a) + 1)\r\n\r\nfor i in range(1, n + 1):\r\n b[i]= b[i - 1] + a[i]\r\n\r\nfor i in range(n, 0, -1):\r\n c[i]= c[i + 1] + a[i]\r\n\r\ncnt= 0\r\nfor i in range(2, n + 1):\r\n if (b[i - 1] == c[i]):\r\n cnt+= 1\r\n\r\nprint(cnt)\r\n \r\n",
"n=int(input())\r\nl1=list(map(int,input().split()))\r\ns=sum(l1)\r\nif s%2!=0:\r\n print(0)\r\nelse:\r\n ans=0\r\n s1=s//2\r\n s2=0\r\n for i in range(n-1):\r\n s2+=l1[i]\r\n if s1==s2:\r\n ans+=1\r\n print(ans)\r\n",
"n = int(input())\r\nli = list(map(int, input().split()))\r\npref_li = list()\r\nsum_li = 0\r\ncnt = 0\r\nfor i in range(n):\r\n sum_li += li[i]\r\n pref_li.append(sum_li)\r\nfor i in range(n-1):\r\n if pref_li[n-1]%2 == 0 and pref_li[n-1]/2 == pref_li[i]:\r\n cnt += 1\r\n# print(li)\r\n# print(pref_li)\r\nprint(cnt)\r\n",
"def main():\r\n mystical_n = int(input())\r\n numbers = list(map(int, input().split()))\r\n total = 0\r\n left_sum = 0\r\n ways = 0\r\n\r\n for number in numbers:\r\n total += number\r\n\r\n for k in range(mystical_n - 1):\r\n left_sum += numbers[k]\r\n if 2 * left_sum == total:\r\n ways += 1\r\n\r\n print(ways)\r\n\r\n# Invoke the main function\r\nmain()\r\n",
"n = int(input())\nline = list(map(int, input().split()))\n\nsum_front = [0]\nindex = 0\nfor i in line: # 初始化前缀和\n sum_front.append(sum_front[index] + i)\n index += 1\noutput = 0\nfor i in range(1,n):\n if sum_front[i] == sum_front[n] - sum_front[i]:\n output += 1\nprint(output)\n\t \t\t \t \t \t\t\t\t \t\t \t \t\t \t\t",
"def main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n right = sum(arr)\r\n left = 0\r\n\r\n result = 0\r\n\r\n for i in range(0, n - 1):\r\n left += arr[i]\r\n right -= arr[i]\r\n if left == right:\r\n result += 1\r\n\r\n print(result)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"if __name__ == \"__main__\":\r\n stripe_length = int(input())\r\n square_Values = list(map(int, input().split()))\r\n \r\n # create a prefix sum array\r\n for i in range(1, stripe_length):\r\n square_Values[i] += square_Values[i-1]\r\n\r\n\r\n flag = 0\r\n for i in range(stripe_length):\r\n if i != stripe_length - 1 and square_Values[i] == square_Values[stripe_length-1] - square_Values[i]:\r\n flag += 1\r\n\r\n print(flag)\r\n\r\n # basic logic >> time exceed when it comes to large array\r\n # flag = 0\r\n # i = 1\r\n # while i < len(square_Values):\r\n # if sum(square_Values[:i]) == sum(square_Values[i:]):\r\n # flag+=1\r\n # i += 1\r\n ",
"def main():\n n = int(input())\n a = list(map(int,input().split()))\n b = [a[0]]\n for i in range(1,n):\n b.append(b[i-1]+a[i])\n poss_count = 0\n for i in range(n-1):\n if b[i] == (b[n-1] - b[i]):\n poss_count += 1\n #print(i)\n print(poss_count)\nif __name__ == '__main__':\n main()\n",
"n = int(input())\narr = list(map(int, input().split()))\n\nprefix_arr = [arr[0]]\nfor i in range(1, n):\n prefix_arr.append(arr[i] + prefix_arr[i - 1])\n\nout = 0\nfor i in range(n - 1):\n if prefix_arr[i] == (prefix_arr[n - 1] - prefix_arr[i]):\n out += 1\n\nprint(out)\n\n",
"tam = int(input())\r\nvalues = list(map(int, input().split()))\r\n\r\nside1, possibilities = 0, 0\r\nside2 = sum(values[1:])\r\nfor i in range(tam - 1):\r\n side1 += values[i]\r\n if(i > 0):\r\n side2 -= values[i]\r\n if(side1 == side2):\r\n possibilities += 1\r\n\r\nprint(possibilities)",
"def solve():\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n s1=0\r\n s2=sum(l)\r\n ans=0\r\n for i in range(n-1):\r\n s1 += l[i]\r\n s2 -= l[i]\r\n if s1 == s2:\r\n ans += 1\r\n print(ans)\r\nsolve()",
"import sys\r\n\r\nsum = 0\r\ncur = 0\r\nres = 0\r\nn = int(sys.stdin.readline().strip())\r\nstripe = list(map(int, sys.stdin.readline().split()))\r\n\r\nif n == 1:\r\n print(0)\r\n exit()\r\n\r\nfor i in range(len(stripe)):\r\n sum += stripe[i]\r\n\r\nsum = sum / 2\r\n\r\nfor i in range(len(stripe) - 1):\r\n cur += stripe[i] \r\n if cur == sum:\r\n res += 1\r\n\r\nprint(res)",
"# 18C\r\n# θ(n) time\r\n# θ(n) space\r\n\r\n__author__ = 'artyom'\r\n\r\n\r\n# SOLUTION\r\n\r\ndef main():\r\n n = read()\r\n a = read(3)\r\n s = 0\r\n t = sum(a)\r\n count = 0\r\n for i in range(n - 1):\r\n s += a[i]\r\n t -= a[i]\r\n if s == t:\r\n count += 1\r\n return count\r\n\r\n\r\n# HELPERS\r\n\r\ndef read(mode=1, size=None):\r\n # 0: String\r\n # 1: Integer\r\n # 2: List of strings\r\n # 3: List of integers\r\n # 4: Matrix of integers\r\n if mode == 0: return input().strip()\r\n if mode == 1: return int(input().strip())\r\n if mode == 2: return input().strip().split()\r\n if mode == 3: return list(map(int, input().strip().split()))\r\n a = []\r\n for _ in range(size):\r\n a.append(read(3))\r\n return a\r\n\r\n\r\ndef write(s=\"\\n\"):\r\n if s is None: s = ''\r\n if isinstance(s, tuple) or isinstance(s, list): s = ' '.join(map(str, s))\r\n s = str(s)\r\n print(s, end=\"\\n\")\r\n\r\n\r\nwrite(main())",
"n = int(input())\nentrada = input().split(\" \")\n\nlista = []\n\nfor i in entrada:\n lista.append(int(i))\n\nfor j in range(1,len(lista)):\n lista[j] = lista[j] + lista[j - 1]\n\n\n\ncount = 0\nfor k in range(len(lista) - 1):\n esquerda = lista[k]\n direita = lista[len(lista) - 1] - esquerda\n if(esquerda == direita):\n count+=1\n\nprint(count)\n \t \t\t\t\t \t \t \t\t\t\t \t \t\t\t",
"n = int(input())\nnums = list(map(int, input().split()))\n\nsums_from_left = []\nsums_from_right = []\nsum_from_left = sum_from_right = 0\n\nfor i in range(n):\n j = n-i-1\n sum_from_left += nums[i]\n sum_from_right += nums[j]\n sums_from_left.append(sum_from_left)\n sums_from_right.append(sum_from_right)\n\nsums_from_right.reverse()\n\nans = 0\n\nfor i in range(n-1):\n if sums_from_left[i] == sums_from_right[i+1]:\n ans += 1\n\nprint(ans)",
"n = int (input())\r\nele = list(map(int,input().split()))\r\n\r\npref_arr=[0]*(n+1)\r\nfor i in range(1,n+1):\r\n pref_arr[i] = ele[i-1]+pref_arr[i-1]\r\n\r\nc=0\r\nfor i in range(1,n):\r\n if pref_arr[-1]-pref_arr[i]==pref_arr[i]:\r\n c+=1\r\nprint(c)\r\n ",
"# @author Matheus Alves dos Santos\n\nn = int(input())\nsquares = list(map(int, input().split()))\n\nways = 0\nsum_left = 0\nsum_right = sum(squares)\n\nfor i in range(len(squares) - 1):\n sum_left += squares[i]\n sum_right -= squares[i]\n \n if (sum_left == sum_right):\n ways += 1\n\nprint(ways)\n",
"from sys import stdin\n\t\nn = int(stdin.readline())-1\narr = list(map(int, stdin.readline().strip().split()))\nls = 0\nrs = sum(arr)\nc = 0\nfor ind, i in enumerate(arr):\n\tif ind == n:\n\t\tbreak\n\tls += i\n\trs -= i\n\tif ls == rs:\n\t\tc += 1\nprint(c)\n\t\t \t\t \t\t \t\t \t\t \t \t\t\t \t",
"n=int(input())\r\nk=0\r\na=[]\r\nfor i in input().split():\r\n a.append(int(i))\r\nsum1=sum(a)\r\nsum2=0\r\nfor i in range(n-1):\r\n sum1-=a[i]\r\n sum2+=a[i]\r\n if sum1==sum2:\r\n k+=1\r\nprint(k)",
"n = int(input())\r\na = list(map(int, input().split()))\r\npre = [0]*n\r\nsuff = [0]*(n-1) + [a[n-1]]\r\n\r\nfor i in range(1, n):\r\n pre[i] = pre[i-1] + a[i-1]\r\n \r\nfor i in range(n-2, -1, -1):\r\n suff[i] = a[i] + suff[i+1]\r\nc = 0\r\nfor i in range(1, n):\r\n if pre[i] == suff[i]: c+=1\r\nprint(c)",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nls = c = 0\r\nrs = sum(a)\r\n\r\nfor i in range(n - 1):\r\n ls += a[i]\r\n rs -= a[i]\r\n if ls == rs: c += 1\r\n\r\nprint(c)\r\n",
"n = int(input())\r\n\r\na = [int(i) for i in input().split()]\r\n\r\nstanga = [0 for i in range(n)]\r\ndreapta = [0 for i in range(n)]\r\n\r\ndef st():\r\n global stanga, n , a\r\n stanga[0] = a[0]\r\n for i in range(1,n):\r\n stanga[i] = a[i] + stanga[i - 1]\r\n\r\nst()\r\n\r\ndef dr():\r\n global n, dreapta, a\r\n dreapta[n-1] = a[n - 1]\r\n for i in range(n-2,-1,-1):\r\n dreapta[i] = a[i] + dreapta[i + 1]\r\n\r\ndr()\r\n\r\nnr = 0\r\n\r\nfor i in range(0,n-1):\r\n if stanga[i] == dreapta[i+1]:\r\n nr += 1\r\n\r\nprint(nr)",
"n = int(input())\r\nns = [int(i) for i in input().split()]\r\nperfix = [ns[0]] * n\r\nfor i in range(1, len(ns)):\r\n perfix[i] = perfix[i - 1] + ns[i]\r\nans = 0\r\nfor i in range(len(ns)-1):\r\n if perfix[i] == perfix[-1] - perfix[i]:\r\n ans += 1\r\nprint(ans)",
"n = int(input())\nnumbers = list(map(int, input().split()))\np1 = sum(numbers)\np2 = 0\nc = 0\nfor i in range(n - 1):\n p1 -= numbers[i]\n p2 += numbers[i]\n\n if p1 == p2:\n c += 1\n\nprint(c)\n \t\t\t\t\t\t \t\t \t \t \t\t",
"n = int(input())\nl =list(map(int,input().split(None,n)[:n]))\ns_i = [0]\ntam = len(l)\nj = -1\ncont = 0\n\nfor i in range(tam-1):\n\n s_i.append(s_i[i]+l[i])\n\ns_f = [0]\nwhile(tam>=1):\n s_f.append(s_f[j+1]+l[tam-1])\n j+=1\n tam-=1\naux = len(l)-1\nfor i in range(1,len(l)):\n if(s_i[i]==s_f[aux]):\n cont+=1\n aux-=1\n\nprint(cont)\n\n# 1534357840984\n",
"from sys import stdin, stdout\r\ninput = stdin.readline\r\n\r\nn = int(input()); l = list(); right = 0\r\nfor i in input().split():\r\n i = int(i); l += [i]; right += i\r\nleft = l.pop(); right -= left; count = 0\r\nfor i in range(n-1):\r\n if right == left:\r\n count += 1\r\n e = l.pop(); right -= e; left += e\r\nprint(count)",
"n=int(input())\r\na=list(map(int,input().strip().split()))\r\np=[]\r\nq=[]\r\ns=t=c=0\r\nfor i in range(n):\r\n s+=a[i]\r\n p.append(s)\r\nfor i in range(n-1,-1,-1):\r\n t+=a[i]\r\n q.append(t)\r\nq=q[::-1]\r\nfor i in range(0,n-1):\r\n if p[i]==q[i+1]:c+=1\r\nprint(c)",
"input()\ntmp=[int(i) for i in input().split()]\ns=sum(tmp)\nj=0\nc=0\nif not s%2:\n k=s//2\n for i in tmp[:-1]:\n j+=i\n if j==k:\n #print(i)\n c+=1\nprint(c)\n\n \t\t\t\t\t\t \t\t \t \t \t\t\t\t \t\t \t\t\t\t",
"n = int(input())\na = list(map(int, input().split()))\nans = 0\ns = sum(a)\npref = [0] * (n + 1)\nfor i in range(n):\n pref[i + 1] = pref[i] + a[i]\n if i < n - 1 and pref[i + 1] * 2 == s:\n ans += 1\nprint(ans)",
"n=int(input())\r\nA=list(map(int,input().split()))\r\n\r\nif sum(A)%2==1:\r\n print(0)\r\n exit()\r\n\r\nM=sum(A)//2\r\n\r\nS=0\r\nANS=0\r\nfor i in range(n-1):\r\n S+=A[i]\r\n if S==M:\r\n ANS+=1\r\n\r\nprint(ANS)\r\n \r\n",
"n = int(input())\r\naa = list(map(int, input().split()))\r\nans = 0\r\ntotal = sum(aa)\r\nss = 0\r\nfor i in range(n - 1):\r\n ss += aa[i]\r\n total -= aa[i]\r\n if ss == total:\r\n ans += 1\r\nprint(ans)\r\n",
"\r\nx = int(input())\r\nl = list(map(int,input().split()))\r\n\r\n\r\np1 = []\r\nc1 = 0\r\n\r\nfor j in range(len(l)-1):\r\n c1+=l[j]\r\n p1.append(c1)\r\n\r\n#print(p1)\r\np2 = []\r\nc2 = 0\r\nd = 0\r\n\r\nfor i in range(len(l)-1,0,-1):\r\n c2+=l[i]\r\n p2.append(c2)\r\n d+=1\r\np2 = p2[::-1]\r\n#print(p2)\r\nc = 0\r\nfor o in range(len(p2)):\r\n if p2[o] == p1[o]:\r\n c+=1\r\nprint(c) ",
"n=int(input())\r\na=list(map(int,input().split()))\r\nl=0\r\nr=sum(a)\r\nans=0\r\nfor i in range(n-1):\r\n\tl+=a[i]\r\n\tr-=a[i]\r\n\tif l==r:\r\n\t\tans+=1\r\nprint(ans)\r\n",
"input()\r\ndata = list(map(int, input().split(\" \")))\r\ntotal = sum(data)\r\nsize = 0\r\nbuffer = 0\r\noutput = 0\r\n\r\nfor num in data:\r\n buffer += num\r\n size += 1\r\n if buffer == total - buffer and size != len(data):\r\n output += 1\r\n\r\nprint(output)\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=0\r\nl=0\r\nans=0\r\nfor i in a:\r\n s=s+i\r\nfor i in range(n-1):\r\n l=l+a[i]\r\n if(l==s-l):\r\n ans+=1\r\nprint(ans) \r\n",
"n=int(input())\narr=list(map(int, input().split()))\n\nsum=0\nfor ele in arr:\n sum+=ele\n\nfirst=0\ncount=0\nfor i in range(n-1):\n first+=arr[i]\n\n second=sum-first\n\n if first==second:\n count+=1\n\nprint(count)",
"x=int(input())\r\nl=list(map(int,input().split()))\r\nper=[]\r\nrper=[]\r\nc=0\r\nr=0\r\nk=0\r\nfor i in l:\r\n c+=i\r\n per.append(c)\r\nfor i in reversed(l):\r\n r+=i\r\n rper.append(r)\r\n\r\nrper.reverse()\r\nfor i in range(x-1):\r\n if per[i]==rper[i+1]:\r\n k+=1\r\nprint(k)",
"import sys\r\nsys.setrecursionlimit(2000000)\r\n\r\nfrom collections import defaultdict\r\ndef clc(): \r\n n = int(input())\r\n arr = list(map(int,input().split()))\r\n summ = sum(arr)\r\n for i in range(1,len(arr)):\r\n arr[i]+=arr[i-1]\r\n count= 0\r\n for i in range(1,len(arr)):\r\n if summ-arr[i-1] ==arr[i-1]:\r\n count+=1\r\n print(count)\r\n \r\n return True\r\ncc = clc()\r\n\r\nif not cc :\r\n print(-1)\r\n ",
"# full logic before coding\r\n\r\n# test_cases = int(input())\r\n\r\n# for test_case in range(test_cases):\r\n# mylist = list(map(int, input().split()))\r\n\r\nno_of_sq = int(input())\r\n\r\nstripe = list(map(int, input().split()))\r\nrhs = sum(stripe)\r\nlhs = 0\r\ncuts = 0\r\n\r\nfor sq in stripe[:-1]:\r\n lhs += sq\r\n rhs -= sq\r\n\r\n if lhs == rhs:\r\n cuts += 1\r\n\r\nprint(cuts)",
"n = int(input())\r\ntemparr = input()\r\ntemparr = temparr.split()\r\narr = []\r\n\r\nfor i in temparr:\r\n arr.append(int(i))\r\n\r\nrightsum = sum(arr)\r\nleftsum = 0 \r\n\r\nans = 0 \r\n\r\nfor i in range(n - 1):\r\n leftsum += arr[i]\r\n rightsum -= arr[i]\r\n if leftsum == rightsum:\r\n ans += 1 \r\nprint(ans)",
"def numberStrips(lista):\n contador = 0\n sumEsquerda = 0\n sumDireita = sum(lista)\n\n for i in range(len(lista)-1):\n\n sumEsquerda += lista[i]\n sumDireita -= lista[i]\n\n if(sumEsquerda - sumDireita == 0):\n contador += 1\n\n return contador\n\nentrada = int(input())\n\nlista = input().split()\nlista = [int(valor) for valor in lista]\n\nprint(numberStrips(lista))\n\t \t\t\t \t \t \t\t\t\t\t \t \t \t"
] | {"inputs": ["9\n1 5 -6 7 9 -16 0 -2 2", "3\n1 1 1", "2\n0 0", "4\n100 1 10 111", "10\n0 4 -3 0 -2 2 -3 -3 2 5", "10\n0 -1 2 2 -1 1 0 0 0 2", "10\n-1 -1 1 -1 0 1 0 1 1 1", "10\n0 0 0 0 0 0 0 0 0 0", "50\n-4 -3 3 4 -1 0 2 -4 -3 -4 1 4 3 0 4 1 0 -3 4 -3 -2 2 2 1 0 -4 -4 -5 3 2 -1 4 5 -3 -3 4 4 -5 2 -3 4 -5 2 5 -4 4 1 -2 -4 3", "15\n0 4 0 3 -1 4 -2 -2 -4 -4 3 2 4 -1 -3", "10\n3 -1 -3 -1 3 -2 0 3 1 -2", "100\n-4 2 4 4 1 3 -3 -3 2 1 -4 0 0 2 3 -1 -4 -3 4 -2 -3 -3 -3 -1 -2 -3 -1 -4 0 4 0 -1 4 0 -4 -4 4 -4 -2 1 -4 1 -3 -2 3 -4 4 0 -1 3 -1 4 -1 4 -1 3 -3 -3 -2 -2 4 -3 -3 4 -3 -2 -1 0 -2 4 0 -3 -1 -2 -3 1 -4 1 -3 -3 -3 -2 -3 0 1 -2 -2 -4 -3 -1 2 3 -1 1 1 0 3 -3 -1 -2", "100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -1 -2 2 -2 2 -2 -2 2 1 1 1 -2 2 0 0 2 -1 2 2 2 0 -1 -1 -1 1 -2 2 2 2 -2 0 0 -2 0 -2 -2 0 -1 -1 -2 -1 1 2 -2 -1 1 -2 -1 0 -2 2 2 -1 -2 2 0 0 0 1 0 1 2 1 -2 -2 -1 -1 -2 -2 -2 -1 2 2 2 -2", "100\n2 7 6 0 8 -2 0 1 8 -1 7 -4 -1 1 0 3 4 -4 3 7 8 -4 -6 6 4 -2 -5 7 4 6 1 6 3 8 -2 6 -6 -3 0 -1 -7 -8 -2 5 8 6 -2 -2 -5 -4 -7 -3 -5 -3 -3 -1 5 8 4 0 -7 -6 8 -4 -1 7 2 6 6 4 -5 -4 -5 -2 2 -2 -7 -1 5 -8 -6 -2 -5 4 2 8 -6 7 -8 -1 -5 8 6 -3 -1 7 -1 2 -8 -8", "1\n0", "1\n10000", "1\n-10000"], "outputs": ["3", "0", "1", "1", "3", "0", "1", "9", "3", "0", "0", "1", "6", "0", "0", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 253 | |
2c3e5f11a0cecba2139f42a28820c14f | Replacement | Little Petya very much likes arrays consisting of *n* integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all.
After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), which represents how many numbers the array has. The next line contains *n* space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.
Print *n* space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.
Sample Input
5
1 2 3 4 5
5
2 3 4 5 6
3
2 2 2
Sample Output
1 1 2 3 4
1 2 3 4 5
1 2 2
| [
"input()\r\np = list(map(int, input().split()))\r\nx = max(p)\r\nif p[p.index(x)] == 1:\r\n p[p.index(x)] = 2\r\nelse:\r\n p[p.index(x)] = 1\r\np.sort()\r\nprint(' '.join(str(i) for i in p))",
"n=int(input())\r\nar=list(map(int,input().split()))\r\nar=sorted(ar)\r\nif(ar[-1]==1):\r\n ar[-1]=2\r\nelse:\r\n ar=[1]+ar[:n-1]\r\nprint(*ar)\r\n",
"n = int(input())\r\nnum = list(map(int, input().split()))\r\nmx = max(num)\r\nfor i in range(n):\r\n if num[i] == mx:\r\n if mx != 1: num[i] = 1\r\n else: num[i] = 2\r\n break\r\nnum.sort()\r\nfor i in range(n):\r\n print(num[i], end=\" \")\r\n ",
"n = int(input())\r\narr = list(map(int, input().split()))\r\narr.sort()\r\nif arr[-1] == 1:\r\n arr[-1] = 2\r\nelse:\r\n arr[-1] = 1\r\narr.sort()\r\nprint(*arr)\r\n",
"n = int(input())\r\na = [1]+list(map(int,input().split()))\r\na = sorted(a)\r\nif a[0]==a[-1]:\r\n a[-2] = a[0]+1\r\nprint(*a[:-1])",
"if __name__ == '__main__':\r\n\tn = int(input())\r\n\tseq = [int(x) for x in input().split()]\r\n\r\n\tseq_max = max(seq)\r\n\r\n\tif seq_max == 1:\r\n\t\tseq[0] = 2\r\n\telse:\r\n\t\tidx = seq.index(seq_max)\r\n\t\tseq[idx] = 1\r\n\t\t\r\n\tseq = sorted(seq)\r\n\r\n\tfor i in seq:\r\n\t\tprint(i, end =\" \")\r\n",
"input()\r\ns = list(map(int,input().split()))\r\nn = s.index(max(s))\r\ns[n] = 2 if s[n] == 1 else 1\r\nprint(*sorted(s))",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = sorted(map(int, input().split()))\r\nif w[-1] == 1:\r\n w[-1] = 2\r\nelse:\r\n w[-1] = 1\r\nw.sort()\r\nprint(' '.join(map(str, w)))",
"# your code goes here\r\ninput()\r\np = list(map(int,input().split()))\r\nx = max(p)\r\nif p[p.index(x)]==1:\r\n p[p.index(x)]=2\r\nelse:\r\n p[p.index(x)]=1\r\np.sort()\r\nprint(' '.join(str(i) for i in p))",
"x=int(input())\r\narr=list(map(int,input().split()))\r\ncrr=[]\r\narr.sort()\r\ni=0\r\nwhile i<len(arr) and arr[i]==1:\r\n i=i+1\r\nif i==len(arr):\r\n arr[i-1]=2\r\nelse:\r\n arr=arr[0:i]+[1]+arr[i:len(arr)-1]\r\nprint(*arr)\r\n \r\n\r\n",
"n = int(input())\r\nl = [int(x) for x in input().split()]\r\nl.sort()\r\nif l[n-1] == 1:\r\n l[n-1] = 2\r\nelse:\r\n l[n-1] = 1\r\nl.sort()\r\nfor i in range(n):\r\n print(l[i],end = \" \")\r\n",
"import sys\r\nimport math\r\n\r\nn=int(input())\r\nlista=[int(x) for x in input().strip().split()]\r\npap=lista[:]\r\npap.sort()\r\nif(pap[-1]==1):\r\n pap[-1]=2\r\nelse:\r\n pap=[1]+pap[:-1]\r\nfor i in range(n):\r\n print(pap[i], end=\" \")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ntemp=max(a)\r\nif len(set(a))==1 and a[0]==1:\r\n print(*a[:-1],2)\r\nelse:\r\n a[a.index(temp)]=1\r\n a.sort()\r\n print(*a)",
"\r\n\r\nfrom collections import defaultdict\r\nimport math\r\nimport sys \r\nfrom bisect import bisect_right\r\n\r\ndef clc():\r\n n = int(input())\r\n arr= list(map(int,input().split()))\r\n arr = sorted(arr)\r\n \r\n if arr[n-1] == 1:\r\n arr[n-1] = 2\r\n else:arr[n-1] = 1\r\n arr = sorted(arr)\r\n for i in range(n):\r\n print(arr[i],end= \" \")\r\n return True\r\ncc = clc()\r\n\r\nif not cc :\r\n print(-1)\r\n ",
"input()\r\na=sorted(map(int,input().split()))\r\na[-1]=1+(a[-1]<2)\r\nprint(*sorted(a))",
"\r\n\r\nn = int(input())\r\n\r\n\r\nt = list(map(int,input().split()))\r\n\r\n\r\nt.sort()\r\n\r\nif t[-1]==1:\r\n t[-1]=2\r\nelse:\r\n t[-1]=1\r\nt.sort()\r\nprint(*t)\r\n",
"import math\r\nn=int(input())\r\nlst = list(map(int, input().strip().split(' ')))\r\n#n,r = map(int, input().strip().split(' '))\r\np=max(lst)\r\nind=lst.index(p)\r\nif p==1:\r\n lst[ind]=2\r\nelse:\r\n lst[ind]=1\r\nlst.sort()\r\nfor j in range(n):\r\n print(lst[j],end=\" \")",
"input()\r\na=list(map(int,input().split()))\r\nt=max(a)\r\na[a.index(t)]=[1,2][not t-1]\r\nprint(' '.join(map(str,sorted(a))))",
"n=int(input())\r\nl=sorted([int(i) for i in input().split()])\r\nif(l[-1]==1):\r\n l[-1]=2\r\n print(*l)\r\nelse:\r\n l[-1]=1\r\n l.sort()\r\n print(*l)",
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nif a[-1] == 1:\r\n a[-1] = 2\r\nelse:\r\n a[-1] = 1\r\na.sort()\r\nprint(' '.join(map(str, a)))",
"input()\r\na = sorted(list(map(int, input().split())))\r\nprint(*(*a[:-1], 2) if a[-1] == 1 else (1, *a[:-1]))",
"input()\r\nt = sorted(list(map(int, input().split())))\r\nif t[-1] == 1: t[-1] = 2\r\nelse: t = [1] + t[: -1]\r\nprint(' '.join(map(str, t)))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nm=max(a)\r\na.remove(m)\r\nif(m==1):\r\n q=2\r\nelse:\r\n q=1\r\na.append(q)\r\na.sort()\r\nfor i in range(n):\r\n print(a[i],end=\" \")",
"n = int(input())\na = sorted(int(x) for x in input().split())\nif n == 1:\n\tif a[0] == 1:\n\t\tprint(2)\n\telse:\n\t\tprint(1)\n\texit()\nif a.count(1) == n:\n\ta[-2] = 2\nprint('1', ' '.join(str(x) for x in a[:-1]))\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nif l[n-1]==1:\r\n l[n-1]=2\r\nelse:\r\n l[n-1]=1\r\nl.sort()\r\nprint(*l)",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nl=sorted(l)\r\nif l[-1]==1:\r\n l[-1]=2\r\nelse:\r\n l[-1]=1\r\nl=sorted(l)\r\nprint(*l)",
"input()\r\na=list(map(int,input().split()))\r\ne=a.index(max(a))\r\na[e]=1+(a[e]==1)\r\na.sort()\r\nprint(' '.join(map(str,a)))",
"a=int(input())\r\nz=list(map(int,input().split()))\r\nz.sort()\r\nif(z.count(1)==len(z)):\r\n z[-1]=2\r\n print(*z)\r\n exit()\r\n\r\n \r\nans=[0 for i in range(len(z))]\r\nans[0]=1\r\nfor i in range(1,len(z)):\r\n \r\n ans[i]=z[i-1]\r\n \r\nprint(*ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n#1 1 1 1 1 \r\n",
"#from dust i have come dust i will be\r\n\r\nimport sys\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\n\r\na.sort()\r\n\r\nif a[n-1]!=1:\r\n a[n-1]=1\r\nelse:\r\n a[n-1]=2\r\n\r\na.sort()\r\n\r\ns=set(a)\r\n\r\nfor i in range(n):\r\n sys.stdout.write(str(a[i])+\" \")",
"n = int(input())\r\na = (list(map(int, input().split())))\r\na.sort()\r\nif a[-1] == 1:\r\n print(*(a[:-1] + [2]))\r\nelse:\r\n print(1, *a[:-1])",
"n=int(input().strip())\r\n\r\nl=list(map(int,input().strip().split()))\r\nl.sort() \r\nif(l[-1]!=1):\r\n l[-1]=1\r\nelse:\r\n l[-1]=2\r\n\r\nl.sort()\r\nfor i in l:\r\n print(i,end=\" \")\r\n\r\nprint()",
"'''input\n10\n5 6 1 2 3 1 3 45 7 1000000000\n'''\nn = int(input())\na = sorted(map(int, input().split()))\nif max(a) == 1:\n\ta[n-1] = 2\nelse:\n\ta[n-1] = 1\nprint(\" \".join(map(str, sorted(a)))) ",
"n = int(input())\r\narr = list(map(int,input().split()))\r\n\r\none = 0\r\n\r\nfor i in arr:\r\n\tif i == 1:\r\n\t\tone += 1\r\n\r\nif one == n:\r\n\tarr.remove(1)\r\n\tarr.append(2)\r\n\tprint(*arr)\r\nelse:\r\n\tarr.remove(max(arr))\r\n\tarr.append(1)\r\n\tarr.sort()\r\n\tprint(*arr)",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nz=max(b)\r\nif z==1:b[b.index(z)]=2\r\nelse:b[b.index(z)]=1\r\nprint(*sorted(b))",
"n = int(input())\r\na = list(map(int,input().split()))\r\nmax_a = max(a)\r\na[a.index(max_a)] = 2 if max_a == 1 else 1\r\nprint(*sorted(a))",
"n=int(input())\r\nl=[int(i) for i in input().split()]\r\nind=l.index(max(l))\r\nif l[ind]==1:\r\n l[ind]=2\r\nelse:\r\n l[ind]=1 \r\nl.sort()\r\nprint(*l)",
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nif a[n - 1] == 1:\r\n a[n - 1] = 2\r\nelse:\r\n a = [1] + a\r\nfor i in a[:n]:\r\n print(i, end = ' ')",
"n=int(input())\r\narr=list(map(int,input().split()))\r\narr=sorted(arr)\r\nif arr[-1]==1:arr[-1]=2\r\nelse:arr=[1]+arr[:n-1]\r\nprint(*arr)\r\n",
"n = int(input())\r\nA = list(map(int, input().split()))\r\nif n == 1:\r\n if A[0] == 1:\r\n print(2)\r\n else:\r\n print(1)\r\n exit(0)\r\nA.sort()\r\nif A[-1] == 1:\r\n print('1 ' * (n - 1), 2)\r\n exit(0)\r\nA[-1] = 1\r\nA.sort()\r\nprint(*A)\r\n",
"while True:\r\n try:\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n a.sort()\r\n\r\n if a[-1] != 1:\r\n a[-1] = 1\r\n else:\r\n a[-1] = 2\r\n\r\n a.sort()\r\n\r\n for num in a:\r\n print(num, end=\" \")\r\n \r\n print()\r\n except EOFError:\r\n break# 1698226817.615389",
"def miis():\r\n return map(int, input().split())\r\n\r\nn = int(input())\r\na = list(miis())\r\nif max(a) != 1:\r\n a[a.index(max(a))] = 1\r\nelse:\r\n a[0] = 2\r\na.sort()\r\nprint(*a)\r\n",
"def f(n):\r\n s=list(map(int,input().split()))\r\n L=list(range(1,n+1))\r\n i=0\r\n if s.count(1)!=n:\r\n s[s.index(max(s))]=1\r\n s.sort()\r\n else:\r\n s[-1]=2\r\n \r\n return \" \".join(str(i) for i in s)\r\n\r\nprint(f(int(input())))",
"import sys\r\nimport os\r\nfrom math import*\r\ninput=sys.stdin.buffer.readline\r\n\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\narr.sort()\r\nif arr[0]!=1:\r\n\tarr=[1]+arr[0:n-1]\r\nelif arr[0]==1 and arr[-1]==1:\r\n\tarr[-1]=2\r\nelse:\r\n\tfor i in range(n):\r\n\t\tif arr[i]!=1:\r\n\t\t\tarr=arr[0:i]+[1]+arr[i:n-1]\r\n\t\t\tbreak\r\nfor x in arr:\r\n\tprint(x,end=' ')\r\n",
"import sys\r\n\r\nn_values = int(sys.stdin.readline())\r\nvals = sorted([int(x) for x in sys.stdin.readline().split()])\r\n\r\nminimum, maximum = vals[0], vals[-1]\r\nif minimum == maximum == 1:\r\n vals[-1] = 2\r\nelif minimum == maximum != 1:\r\n vals[-1] = 1\r\nelse:\r\n vals[-1] = 1\r\n\r\nvals.sort()\r\n\r\nresult = \"\"\r\nfor val in vals:\r\n result += str(val) + \" \"\r\nprint(result)\r\n\r\n",
"def replace(arr):\r\n if arr==[1]*len(arr):\r\n arr[-1]=2\r\n print(*sorted(arr))\r\n return \"\"\r\n arr[arr.index(max(arr))]=1\r\n print(*sorted(arr))\r\n return \"\"\r\na=input()\r\nlst=list(map(int,input().strip().split()))\r\nprint(replace(lst))",
"import sys\nimport math as mt\nimport bisect\ninput=sys.stdin.buffer.readline \n#t=int(input())\nt=1\nfor __ in range(t):\n #s=input()\n n=int(input())\n #a,b,c,d=map(int,input().split())\n l=list(map(int,input().split()))\n l.sort()\n if l[-1]==1:\n l[-1]=2\n else: \n l[-1]=1\n l.sort() \n print(*l)\n \t \t \t \t \t\t\t\t \t \t \t\t",
"n = int(input())\nA = list(map(int, input().split()))\n\ndef solve(n,A):\n x = max(A)\n if x == 1:\n ans = [1]*n\n ans[n-1] = 2\n else:\n for i in range(n):\n if A[i] == x:\n A[i] = 1\n break\n ans = sorted(A)\n print(*ans)\n\nsolve(n,A)\n",
"input()\r\na=sorted(list(map(int,input().split())))\r\na[-1]=[1,2][a[-1]==1]\r\nprint(*(sorted(a)))"
] | {"inputs": ["5\n1 2 3 4 5", "5\n2 3 4 5 6", "3\n2 2 2", "4\n1 1 2 3", "3\n1 1 1", "10\n5 6 1 2 3 1 3 45 7 1000000000", "4\n1000000000 234765 3485636 385634876", "1\n1", "25\n1 1 1 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 2 1 2", "2\n2 1", "3\n1 2 1", "1\n2", "1\n4", "3\n1 1 2", "2\n1 2", "2\n1 3", "2\n1 1", "2\n5 5", "1\n5"], "outputs": ["1 1 2 3 4", "1 2 3 4 5", "1 2 2", "1 1 1 2", "1 1 2", "1 1 1 2 3 3 5 6 7 45", "1 234765 3485636 385634876", "2", "1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "1 1", "1 1 1", "1", "1", "1 1 1", "1 1", "1 1", "1 2", "1 5", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 48 | |
2c4ee4399f143ea9b2870f8e4b4d7336 | Vanya and Exams | Vanya wants to pass *n* exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least *avg*. The exam grade cannot exceed *r*. Vanya has passed the exams and got grade *a**i* for the *i*-th exam. To increase the grade for the *i*-th exam by 1 point, Vanya must write *b**i* essays. He can raise the exam grade multiple times.
What is the minimum number of essays that Vanya needs to write to get scholarship?
The first line contains three integers *n*, *r*, *avg* (1<=≤<=*n*<=≤<=105, 1<=≤<=*r*<=≤<=109, 1<=≤<=*avg*<=≤<=*min*(*r*,<=106)) — the number of exams, the maximum grade and the required grade point average, respectively.
Each of the following *n* lines contains space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*r*, 1<=≤<=*b**i*<=≤<=106).
In the first line print the minimum number of essays.
Sample Input
5 5 4
5 2
4 7
3 1
3 2
2 5
2 5 4
5 2
5 2
Sample Output
4
0
| [
"def solve(a, b, r, avg):\r\n diff = max(0, len(a) * avg - sum(a))\r\n \r\n sorted_indices = sorted(range(len(a)), key=lambda i: b[i])\r\n \r\n result = 0\r\n index = 0\r\n while diff != 0:\r\n raise_num = min(diff, r - a[sorted_indices[index]])\r\n result += raise_num * b[sorted_indices[index]]\r\n \r\n diff -= raise_num\r\n index += 1\r\n \r\n return result\r\n\r\ndef main():\r\n n, r, avg = map(int, input().split())\r\n a = []\r\n b = []\r\n for i in range(n):\r\n ai, bi = map(int, input().split())\r\n a.append(ai)\r\n b.append(bi)\r\n \r\n print(solve(a, b, r, avg))\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"from sys import stdin\r\ndef input(): return stdin.readline()[:-1]\r\n\r\nN, MAX, AVG = map(int, input().split())\r\nans = 0\r\ntot = AVG * N\r\nexams = []\r\nfor _ in range(N):\r\n a, b = map(int, input().split())\r\n tot -= a\r\n exams.append((b, a))\r\n\r\nif tot <= 0:\r\n print(0)\r\n exit()\r\n\r\nexams.sort()\r\nfor b, a in exams:\r\n can_be_done = MAX - a\r\n freq = min(can_be_done, tot)\r\n ans += freq * b\r\n tot -= freq\r\nprint(ans)",
"n,r,a=list(map(int,input().split()))\r\nz,add=[],0\r\nfor i in range(n):\r\n x,y=list(map(int,input().split()))\r\n add+=x\r\n z.append([y,x])\r\nz.sort()\r\nj,ans=0,0\r\nwhile add<a*n:\r\n if a*n-add>=r-z[j][1]:\r\n add+=r-z[j][1]\r\n ans+=(r-z[j][1])*z[j][0]\r\n else:\r\n ans+=(a*n-add)*z[j][0]\r\n add=a*n\r\n j+=1\r\nprint(ans)",
"def ni(): return int(input())\r\ndef ia(): return list(map(int, input().split()))\r\n\r\n\r\nn, r, avg = ia()\r\nm = []\r\nfor i in range(n):\r\n m.append(ia())\r\n\r\ntgt = avg * n\r\ncur = sum([s[0] for s in m])\r\nreq = tgt - cur\r\nm.sort(key=lambda x: x[1])\r\nans = 0\r\nfor i in range(len(m)):\r\n if req <= 0:\r\n break\r\n add = min(req, r - m[i][0])\r\n ans += add * m[i][1]\r\n req -= add\r\nprint(ans)\r\n",
"# http://codeforces.com/problemset/problem/492/C\n\nn, r, avg = map(int, input().split())\n\nt = 0\ns = 0\nl_s = list()\nfor _ in range(n):\n a, b = map(int, input().split())\n s += a\n l_s.append([a, b])\n\nl_s.sort(key = lambda x: x[1])\ni = 0\nwhile s / n < avg:\n t += min(r - l_s[i][0], n * avg - s) * l_s[i][1]\n s += min(r - l_s[i][0], n * avg - s)\n i += 1\n\nprint(t)\n ",
"n,r,avg=map(int,input().split())\r\nnums=[]\r\ntg=0\r\nfor _ in range(n):\r\n a,b=map(int,input().split())\r\n nums.append([b,a])\r\n tg+=a\r\nnums.sort()\r\nreq=n*avg-tg\r\nif req<=0:\r\n print(0)\r\nelse:\r\n ans=0\r\n index=0\r\n while req>0 and index<n:\r\n take=min(req,r-nums[index][-1])\r\n if take<=0:\r\n index+=1\r\n continue\r\n ans+=take*nums[index][0]\r\n req-=take\r\n index+=1\r\n # print(ans,req,index,'testcase')\r\n print(ans)\r\n# print('-----')\r\n\r\n",
"n,g,avg = map(int,input().split())\r\nexams = []\r\nsm = 0\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n sm+=l\r\n exams.append([r,l])\r\nexams.sort()\r\nz = 0\r\nans = 0\r\nwhile sm/n<avg:\r\n if exams[z][-1]<g:\r\n l,r = 1,g-exams[z][-1]\r\n cost = exams[z][0]\r\n poss = 0\r\n while l<=r:\r\n mid = (l+r)//2\r\n if (mid+sm)/n>=avg:\r\n poss = mid*cost\r\n r = mid-1\r\n else:\r\n l = mid+1\r\n if not poss:\r\n sm+=(g-exams[z][-1])\r\n ans+=(g-exams[z][-1])*(cost)\r\n else:\r\n ans+=poss\r\n sm+=l\r\n z+=1\r\nprint(ans)",
"import sys\r\n#sys.setrecursionlimit(10**7)\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n############ ---- Input Functions ---- ############\r\n\r\ndef Vanya_and_Exams():\r\n n,r,avg = invr()\r\n\r\n current_grade = []\r\n essay_cost = []\r\n\r\n for _ in range(n):\r\n ai,bi = invr()\r\n current_grade.append(ai)\r\n essay_cost.append(bi)\r\n \r\n extra_grade_needed = (n*avg) - sum(current_grade)\r\n \r\n if extra_grade_needed <= 0:\r\n print(0)\r\n else:\r\n sorted_data = sorted(zip(essay_cost,current_grade))\r\n essay_cost_sorted, current_grade_acc = zip(*sorted_data)\r\n\r\n number_of_essays = 0\r\n #print(\"extra grade needed:\", extra_grade_needed)\r\n for bi,ai in zip(essay_cost_sorted,current_grade_acc):\r\n\r\n grade_extracted = min(extra_grade_needed, r-ai)\r\n extra_grade_needed = extra_grade_needed - grade_extracted\r\n \r\n #print(grade_extracted,bi)\r\n number_of_essays += (grade_extracted*bi)\r\n #print(\"extra grade needed:\", extra_grade_needed)\r\n #print(\"number_of_essays:\", number_of_essays)\r\n\r\n if extra_grade_needed == 0:\r\n break \r\n \r\n print(number_of_essays)\r\n\r\n return \r\n\r\n\r\nVanya_and_Exams()",
"n, r, avg = map(int, input().split())\r\navg *= n\r\nexams = []\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n exams.append((a, b))\r\nexams.sort(key=lambda x: x[1])\r\n\r\ntotal_grade = sum(a for a, _ in exams)\r\nremaining_grade = avg - total_grade\r\nessays_needed = 0\r\nfor a, b in exams:\r\n if remaining_grade <= 0:\r\n break\r\n grade_increase = min(r - a, remaining_grade)\r\n essays_needed += grade_increase * b\r\n remaining_grade -= grade_increase\r\nprint(essays_needed)",
"from collections import deque\r\n\r\n\r\ndef main():\r\n n, r, avg = list(map(int, input().split()))\r\n a = []\r\n s = 0\r\n d = []\r\n for i in range(n):\r\n x, y = list(map(int, input().split()))\r\n a.append([x, y])\r\n s += x\r\n d.append([y, x])\r\n to_add = n * avg - s\r\n if to_add <= 0:\r\n print(0)\r\n else:\r\n ans = 0\r\n d.sort()\r\n d = deque(d)\r\n tmp = 0\r\n while tmp < to_add:\r\n pair = d.popleft()\r\n b = pair[0]\r\n if tmp + r - pair[1] < to_add:\r\n tmp += (r - pair[1])\r\n ans += b * (r - pair[1])\r\n else:\r\n ans += (to_add - tmp) * b\r\n tmp = to_add\r\n print(ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"import sys\r\nfrom collections import defaultdict\r\n\r\n\r\ndef main() -> None:\r\n read = sys.stdin.readline\r\n n, r, avrg = (int(i) for i in read().split())\r\n values: list[tuple[int, int]] = []\r\n total_score = 0\r\n\r\n for _ in range(n):\r\n score, cost = (int(i) for i in read().split())\r\n values.append((cost, score))\r\n total_score += score\r\n\r\n if total_score / n >= avrg:\r\n print(0)\r\n else:\r\n values.sort()\r\n missing = avrg * n - total_score\r\n total_essays = 0\r\n for val in values:\r\n cost, score = val\r\n max_possible_score = r - score\r\n essays = min(max_possible_score, missing)\r\n if essays <= 0:\r\n continue\r\n total_essays += essays * cost\r\n missing -= essays\r\n if missing == 0:\r\n break\r\n\r\n print(total_essays)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()",
"n,r,avg = map(int,input().split())\r\narr = []\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n arr.append([a, b])\r\narr.sort(key = lambda x: x[1])\r\ncurr = sum([i[0] for i in arr])\r\nneeded = n * avg\r\ni = 0\r\nans = 0\r\nwhile(curr < needed):\r\n a, b = arr[i]\r\n # Take all\r\n if(curr + (r - a) <= needed):\r\n curr += (r - a)\r\n ans += (r - a) * b\r\n # Take selective\r\n else:\r\n rem = needed - curr\r\n ans += rem * b\r\n curr = needed\r\n i += 1\r\nprint(ans)"
] | {"inputs": ["5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5", "2 5 4\n5 2\n5 2", "6 5 5\n1 7\n2 4\n3 5\n4 6\n5 6\n4 7", "1 1000000000 1000000\n1 1000000", "10 10 7\n1 10\n2 9\n3 8\n4 7\n5 6\n6 5\n7 4\n8 3\n9 2\n10 1", "3 5 2\n1 10\n1 7\n1 4", "10 10 10\n9 8\n3 9\n3 6\n10 5\n5 5\n6 10\n10 3\n6 7\n2 3\n9 8", "1 1 1\n1 1", "1 100 10\n8 27", "2 1000000000 1000000\n1000000 5\n999998 7", "10 10 6\n1 10\n2 9\n3 8\n4 7\n5 6\n6 5\n7 4\n8 3\n9 2\n10 1", "1 2 1\n2 2", "9 846678 205000\n102282 593538\n246630 24854\n545346 409737\n334264 443193\n37717 191227\n154582 913095\n97105 345066\n65504 578960\n163348 394257", "2 100000 100000\n1 1000000\n1 1000000", "2 1000000 1000000\n1 1000000\n1 1000000"], "outputs": ["4", "0", "63", "999999000000", "70", "12", "238", "0", "54", "10", "16", "0", "2441209588", "199998000000", "1999998000000"]} | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
2cb60d83414775ebf40f496074fdbc75 | Statues | In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8<=×<=8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria.
Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.
At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.
Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.
You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S".
It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".
If Maria wins, print string "WIN". If the statues win, print string "LOSE".
Sample Input
.......A
........
........
........
........
........
........
M.......
.......A
........
........
........
........
........
SS......
M.......
.......A
........
........
........
........
.S......
S.......
MS......
Sample Output
WIN
LOSE
LOSE
| [
"r, s = [63], ''.join(input() + 'T' for i in range(8)) + 'T' * 9\nfor i in range(0, 72, 9):\n t = set()\n for x in r:\n for y in (x, x - 1, x + 1, x - 9, x + 9, x - 10, x - 8, x + 10, x + 8):\n if s[y] == 'T': continue\n if (y < i or s[y - i] != 'S') and (y < i + 9 or s[y - i - 9] != 'S'): t.add(y)\n r = t\nprint('WIN' if r else 'LOSE')",
"a=list(input() for i in range(8))\r\nok1=list()\r\nok2=set()\r\nok1.append((7,0))\r\nw=[(1,0),(-1,0),(0,1),(0,-1),(1,-1),(1,1),(-1,-1),(-1,1),(0,0)]\r\nfor i in range(8) :\r\n\tfor pos in ok1 :\r\n\t\tif pos[0]>=i and a[pos[0]-i][pos[1]] == 'S' :\r\n\t\t\tcontinue \r\n\t\tfor j in w:\r\n\t\t\tto=(pos[0]+j[0],pos[1]+j[1])\r\n\t\t\tif to[0]<8 and to[1]<8 and to[0]>-1 and to[1]>-1:\r\n\t\t\t\tif to[0]<i or a[to[0]-i][to[1]] != 'S' :\r\n\t\t\t\t\tok2.add(to)\r\n\tok1.clear()\r\n\tok1=list(ok2.copy())\r\n\tok2.clear()\r\nprint(\"WIN\" if len(ok1)>0 else \"LOSE\")",
"from collections import deque\r\nfrom os import path\r\nfrom sys import stdin, stdout\r\n\r\n\r\nfilename = \"../templates/input.txt\"\r\nif path.exists(filename):\r\n stdin = open(filename, 'r')\r\n\r\n\r\ndef input():\r\n return stdin.readline().rstrip()\r\n\r\n\r\ndef print(*args, sep=' ', end='\\n'):\r\n stdout.write(sep.join(map(str, args)))\r\n stdout.write(end)\r\n\r\n\r\nd8 = ((0, 0), (0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1))\r\n\r\n\r\ndef solution():\r\n n = 8\r\n a = [[] for k in range(n)]\r\n for i in range(n):\r\n a[0].append(list(input()))\r\n for k in range(1, n):\r\n a[k] = a[k - 1].copy()\r\n a[k].pop()\r\n a[k] = [['.'] * 8] + a[k]\r\n q = deque([(0, 7, 0)])\r\n seen = {(0, 7, 0)}\r\n while q:\r\n k, i, j = q.popleft()\r\n if k == 7:\r\n print('WIN')\r\n return\r\n for di, dj in d8:\r\n ni = i + di\r\n nj = j + dj\r\n if 0 <= ni < n and 0 <= nj < n:\r\n if a[k][ni][nj] != 'S' and a[k + 1][ni][nj] != 'S':\r\n if (k + 1, ni, nj) not in seen:\r\n if (ni, nj) == (0, 7):\r\n print('WIN')\r\n return\r\n seen.add((k + 1, ni, nj))\r\n q.append((k + 1, ni, nj))\r\n print('LOSE')\r\n\r\n\r\ndef main():\r\n t = 1\r\n while t:\r\n solution()\r\n t -= 1\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"grid=None\ngridsovertime=None\nvisited=None\n\ndef readInput():\n\tglobal grid\n\tgrid = []\n\tfor _ in range(8):\n\t\tgrid.append(input())\n\tgrid = [[(False if char=='S' else True) for char in row] for row in grid]\n\treturn grid\n\ndef getNeighbours(pos):\n\tx,y,t = pos\n\tnewposes = []\n\tfor i in range(-1,2):\n\t\tfor j in range(-1,2):\n\t\t\tnewposes.append((x+i,y+j,t+1))\n\t# print(newposes, len(gridsovertime), len(gridsovertime[0]), len(gridsovertime[0][0]))\n\tnewposes = [(x,y,t) for x,y,t in newposes if (x>=0 and y>=0 and x<8 and y<8 and gridsovertime[t][x][y] and gridsovertime[t-1][x][y])]\n\treturn newposes\n\ndef dfs(pos):\n\tx,y,t = pos\n\tvisited[t][x][y]=True\n\tif t==10:\n\t\treturn True\n\tout = []\n\tfor x,y,t in getNeighbours(pos):\n\t\t# print(x,y,t)\n\t\tif visited[t][x][y]:\n\t\t\tcontinue\n\t\tout.append(dfs((x,y,t)))\n\treturn any(out)\n\ndef solve():\n\tglobal gridsovertime,visited\n\tgridsovertime = [grid]\n\tfor _ in range(12):\n\t\tcurrgrid = gridsovertime[-1]\n\t\tnewgrid = [[True]*8] + currgrid[:-1]\n\t\tgridsovertime.append(newgrid)\n\n\tvisited = [[[False for _ in range(8)] for _ in range(8)] for _ in range(13)]\n\n\tstart = (7,0,0)\n\t# visited[7][0][0] = True\n\treturn dfs(start)\n\n\ndef main():\n\treadInput()\n\tout = solve()\n\tif out:\n\t\tprint(\"WIN\")\n\telse:\n\t\tprint(\"LOSE\")\n\tpass\n\nif __name__ == '__main__':\n\tmain()",
"r,s = [63], ''.join(input()+'T' for i in range(8))+'T'*9\r\nfor i in range(0, 72, 9):\r\n t = set()\r\n for x in r:\r\n for y in (x,x-1,x+1,x-9,x+9,x-10,x-8,x+10,x+8):\r\n if s[y]=='T':continue\r\n if (y<i or s[y-i]!='S')and(y<i+9 or s[y-i-9]!='S'): t.add(y)\r\n r = t\r\nprint('WIN' if r else 'LOSE')",
"def play(b, x, y, c):\r\n if c == 9:\r\n return True\r\n if b[c][y][x] == 'S':\r\n return False\r\n dx = [-1, 1, 0, 0, 0, 1, 1, -1, -1]\r\n dy = [0, 0, -1, 1, 0, -1, 1, -1, 1]\r\n for i in range(len(dx)):\r\n nx = x + dx[i]\r\n ny = y + dy[i]\r\n if min(nx, ny) < 0 or max(nx, ny) >= 8: continue\r\n if b[c][ny][nx] != 'S' and play(b, nx, ny, c+1):\r\n return True\r\n return False\r\n\r\nboard = []\r\nfor x in range(8):\r\n board.append(input().strip())\r\nB = [board]\r\nfor x in range(10):\r\n b = B[-1]\r\n b_ = b[:]\r\n b_[0] = b_[0][:-1] + '.'\r\n b_.insert(0, \".......A\")\r\n B.append(b_[:-1])\r\nif play(B, 0, 7, 0):\r\n print(\"WIN\")\r\nelse:\r\n print(\"LOSE\")",
"grid = [ list(input().strip()) for r in range(8) ]\ngrid[0][7] = '.'\ngrid[7][0] = '.'\nmark = [ [ False for c in range(8) ] for r in range(8) ]\nmark[7][0] = True\n\ndef display_grid():\n print('\\n'.join(map(lambda row: ''.join(row), grid)))\n print()\n\ndef display_mark():\n for row in mark:\n row = map(lambda a: 'X' if a else '_', row)\n print(''.join(row))\n print()\n\nfor i in range(8):\n moved = False\n new_mark = [ [ False for c in range(8) ] for r in range(8) ]\n for r in range(8):\n for c in range(8):\n if not mark[r][c]:\n continue\n for R in range(max(0, r - 1), min(r + 2, 8)):\n for C in range(max(0, c - 1), min(c + 2, 8)):\n if grid[R][C] == 'S':\n continue\n if R - 1 >= 0 and grid[R - 1][C] == 'S':\n continue\n new_mark[R][C] = True\n moved = True\n mark = new_mark\n grid.insert(0, 8 * [ '.' ])\n grid.pop()\n if not moved:\n break\n\nif moved:\n print('WIN')\nelse:\n print('LOSE')\n",
"start=[]\r\nfor i in range(8): start.append(input())\r\na=[start]\r\n\r\n#start=[\".......A\",\"........\",\"........\",\"........\",\"........\",\".SSSSSSS\",\"S.......\",\"M.......\"]\r\n#a=[start]\r\n\r\nfor i in range(10):\r\n tmp=a[-1]\r\n tmp=[\".......A\"]+tmp\r\n tmp[1]=tmp[1][:-1]+\".\"\r\n a.append(tmp[:-1])\r\n\r\ndx=[-1,1,0,0,0,1,1,-1,-1]\r\ndy=[0,0,-1,1,0,-1,1,-1,1]\r\n\r\ndef chk(x,y,step):\r\n if a[step][y][x]==\"S\": return False\r\n if step==9:return True\r\n for i in range(8):\r\n x_,y_=x+dx[i],y+dy[i]\r\n if min(x_,y_)<0 or max(x_,y_)>7:continue\r\n if a[step][y_][x_]!='S' and chk(x_,y_,step+1): return True\r\n return False\r\nif chk(0,7,0):\r\n print(\"WIN\")\r\nelse:\r\n print(\"LOSE\")\r\n",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nA = []\r\nfor _ in range(8):\r\n A.append([c for c in input()])\r\n \r\nfor _ in range(9):\r\n pos = []\r\n for i in range(8):\r\n for j in range(8):\r\n if A[i][j]=='M':\r\n pos.append((i,j))\r\n if not pos:\r\n exit(print('LOSE'))\r\n \r\n for i,j in pos:\r\n for i1 in range(-1,2):\r\n for j1 in range(-1,2):\r\n ni = i1+i\r\n nj = j1+j\r\n if ni<0 or ni>=8 or nj<0 or nj>=8:continue\r\n if A[ni][nj]=='A':\r\n exit(print('WIN'))\r\n if A[ni][nj]=='S':continue\r\n A[ni][nj] = 'M'\r\n \r\n for i in range(7,-1,-1):\r\n for j in range(8):\r\n if A[i][j]=='S':\r\n A[i][j] = '.'\r\n if i+1<8:\r\n A[i+1][j] = 'S'\r\n \r\nprint('WIN')\r\n\r\n\r\n"
] | {"inputs": [".SSSSSSA\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\nMSSSSSSS", "SSSSSSSA\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSSSSS", "SSSSSSSA\n......SS\n.......S\n.......S\n.......S\n.......S\n.......S\nM......S", ".......A\nS.S.S.S.\n........\n.S.S.S.S\n........\nS.S.S.S.\n........\nMS.S.S.S", "S..SSSSA\n...S.S.S\n.SS.SS.S\nSS....SS\n.S.SSSS.\n...S.S.S\n..S..S..\nMSSSSS.S", "SSSSSSSA\nSS.SSSSS\nSSSSSSSS\nSSSSSSSS\nS..SS.SS\nSSSS.SSS\nSSSS.SSS\nM.SSS.SS", ".......A\n....S...\n...S....\n........\nS..S..SS\n.S....S.\nS....S..\nM....S.S", "...S.SSA\n.....S..\nSSS....S\n...S...S\n....SSSS\n.S.S...S\n..S....S\nM..SSSSS", "S..SS.SA\n.SSS.S.S\nSS.SSS.S\nSSS.S.S.\nSS.SSSSS\nSSSSSSSS\nSSSS.SS.\nM.SSS.S.", "...SSS.A\n.....S..\n..S.S.SS\n.S.S...S\nS.S...S.\n....S...\n........\nM..S.SSS", ".S.S..SA\n.S...S.S\nS....S..\n...S....\n.S.SSSSS\nS.....SS\n.S.S.SSS\nM....S.S", "SSSS.SSA\nSSS.SSSS\nSSSSSS.S\nSS.SSS.S\nSS.S.SS.\nSSSS.SS.\nSSSS.SSS\nMSS.SSS.", "SSSS.SSA\nSSSSS.SS\nSSSS.SSS\nSSSSSSSS\nSS.SSSSS\nSSS.SSSS\nSSSSSSSS\nMSSS..SS", "S.S.S..A\n...SSS.S\n.SSSSSS.\nSS.S..SS\nSSSS.SSS\n.S.SSS..\nSS.SSSSS\nMSSSS.S.", "SSSSSSSA\nSS.SSS.S\nSSSSSS.S\nSSSSSSSS\nSSSSSSSS\nSSSSSSS.\nSSSSSSSS\nM.SSSSSS", "...S...A\n........\n..S..S.S\n.S....S.\nS.......\n..S.S..S\n......S.\nM..SS..S", "SSSSSSSA\nSSSSSSSS\n.SSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSS.SS\nSSSSSSSS\nMSSSSSSS", "SSSSSSSA\nSSS.SSSS\nSSSSSSSS\nSSS.SSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSS.SS", "S.S..SSA\n...S.S..\n.SS.SSS.\n......S.\n.S...S..\n..S.S..S\n..SS..S.\nM.SS..SS", "SSSSSSSA\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSSSSS", ".....S.A\n...S.S..\n.....S..\n........\n........\n........\n......S.\nM....S..", "SSSSS..A\nS.SS.SS.\n.S.SSS.S\n..SSSSS.\n.S..S.S.\n.SS.S..S\nSSS.S...\nM..S..S.", ".SSSS.SA\n.SS.SSS.\n..S.SS..\nSSSS.SS.\nS.S.....\nS.S.SSSS\nS..SS..S\nMS.SS.SS", "SSS..SSA\nSSSSSSSS\n..SS..SS\n.S.S.SSS\n.SSS.SSS\nSSSS.S.S\n...SS..S\nMS..S.SS", "S..SSS.A\nS.S.SSSS\nSSSSSSSS\n...SS...\nS.SSSSSS\nSS..SS.S\nSS..S.S.\nMSS..SSS", "S.SS.SSA\n.S..SSS.\nSSS.SSS.\nSSSS.SSS\nS.SSSSSS\nSSSSSSSS\nSSSSS.SS\nMS.SSSSS", "SSS.SSSA\nSSS....S\nSS...SSS\n..SSS..S\nS..SS...\nSS.SS...\n.S..SSSS\nM.SSSSSS", "SSS.SSSA\nSSSSSSSS\nSSSSSSSS\nSS.SSS.S\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSSSSS"], "outputs": ["WIN", "LOSE", "LOSE", "WIN", "WIN", "LOSE", "WIN", "WIN", "LOSE", "WIN", "LOSE", "LOSE", "LOSE", "LOSE", "LOSE", "WIN", "LOSE", "LOSE", "WIN", "LOSE", "WIN", "LOSE", "LOSE", "LOSE", "LOSE", "LOSE", "LOSE", "LOSE"]} | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
2cebca1bd851b6b5e931ae824f9d6d35 | Almost Increasing Array | We call an array almost increasing if we can erase not more than one element from it so that the array becomes strictly increasing (that is, every element is striclty greater than every element before it).
You are given an array *a* consisting of *n* elements. You are allowed to replace any element with any integer number (and you may do so any number of times you need). What is the minimum number of replacements you have to perform in order to make the array almost increasing?
The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — the array *a*.
Print the minimum number of replaces you have to perform so that *a* is almost increasing.
Sample Input
5
5 4 3 2 1
5
1 2 8 9 5
Sample Output
3
0
| [
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef segment_tree(n):\r\n tree = [0] * pow(2, n.bit_length() + 1)\r\n return tree\r\n\r\ndef update(i, x, tree):\r\n i += len(tree) // 2\r\n tree[i] = x\r\n i //= 2\r\n while True:\r\n if i == 0:\r\n break\r\n tree[i] = max(tree[2 * i], tree[2 * i + 1])\r\n i //= 2\r\n return\r\n\r\ndef get_max(s, t, tree):\r\n s += len(tree) // 2\r\n t += len(tree) // 2\r\n ans = 0\r\n while s <= t:\r\n if s % 2 == 0:\r\n s //= 2\r\n else:\r\n ans = max(ans, tree[s])\r\n s = (s + 1) // 2\r\n if t % 2 == 1:\r\n t //= 2\r\n else:\r\n ans = max(ans, tree[t])\r\n t = (t - 1) // 2\r\n return ans\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nb = [a[i] - i for i in range(n)]\r\nc = [a[i] - i + 1 for i in range(n)]\r\ns = list(set(b + c))\r\ns.sort()\r\nd = dict()\r\nl = len(s)\r\nfor i in range(l):\r\n d[s[i]] = i + 1\r\ntree1 = segment_tree(l + 5)\r\ntree2 = segment_tree(l + 5)\r\nfor i in range(n - 1):\r\n u = d[c[i + 1]]\r\n ma = max(get_max(1, u, tree1), get_max(1, u, tree2))\r\n update(u, ma + 1, tree2)\r\n v = d[b[i]]\r\n ma = get_max(1, v, tree1)\r\n update(v, ma + 1, tree1)\r\nans = n - max(tree1[1], tree2[1]) - 1\r\nprint(ans)"
] | {"inputs": ["5\n5 4 3 2 1", "5\n1 2 8 9 5", "15\n1013 8003 4947 359 17360 21594 25180 25764 22357 22357 16649 12544 23382 10579 25937", "8\n1 1 1 1 1 1 1 1", "7\n100 105 108 108 107 108 109", "7\n1 5 6 2 3 4 5", "5\n3 4 1 2 5", "8\n53 8 4 6 4 3 8 5", "6\n13 7 4 3 1 4", "6\n6 1 6 2 1 5", "4\n1 2 1 2", "8\n1 5 2 3 4 7 5 6", "4\n2 1 2 21", "4\n1 2 3 4", "5\n1 2 3 2 1", "14\n6 7 8 9 10 11 12 13 14 15 16 17 18 19", "2\n1 2"], "outputs": ["3", "0", "7", "6", "1", "2", "1", "4", "3", "2", "1", "2", "0", "0", "1", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2cfe1a7284c39fbf0b07946174ad81ad | Biathlon | Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section.
Of course, biathlon as any sport, proved very difficult in practice. It takes much time and effort. Workouts, workouts, and workouts, — that's what awaited Valera on his way to great achievements in biathlon.
As for the workouts, you all probably know that every professional biathlete should ski fast and shoot precisely at the shooting range. Only in this case you can hope to be successful, because running and shooting are the two main components of biathlon. Valera has been diligent in his ski trainings, which is why he runs really fast, however, his shooting accuracy is nothing to write home about.
On a biathlon base where Valera is preparing for the competition, there is a huge rifle range with *n* targets. Each target have shape of a circle, and the center of each circle is located on the *Ox* axis. At the last training session Valera made the total of *m* shots. To make monitoring of his own results easier for him, one rather well-known programmer (of course it is you) was commissioned to write a program that would reveal how many and which targets Valera hit. More specifically, for each target the program must print the number of the first successful shot (in the target), or "-1" if this was not hit. The target is considered hit if the shot is inside the circle or on its boundary. Valera is counting on you and perhaps, thanks to you he will one day win international competitions.
The first line of the input file contains the integer *n* (1<=≤<=*n*<=≤<=104), which is the number of targets. The next *n* lines contain descriptions of the targets. Each target is a circle whose center is located on the *Ox* axis. Each circle is given by its coordinate of the center *x* (<=-<=2·104<=≤<=*x*<=≤<=2·104) and its radius *r* (1<=≤<=*r*<=≤<=1000). It is guaranteed that no two targets coincide, intersect or are nested into each other, but they can touch each other.
The next line contains integer *m* (1<=≤<=*m*<=≤<=2·105), which is the number of shots. Next *m* lines contain descriptions of the shots, which are points on the plane, given by their coordinates *x* and *y* (<=-<=2·104<=≤<=*x*,<=*y*<=≤<=2·104).
All the numbers in the input are integers.
Targets and shots are numbered starting from one in the order of the input.
Print on the first line a single number, the number of targets hit by Valera. Print on the second line for each of the targets the number of its first hit or "-1" (without quotes) if this number does not exist. Separate numbers with spaces.
Sample Input
3
2 1
5 2
10 1
5
0 1
1 3
3 0
4 0
4 0
3
3 2
7 1
11 2
4
2 1
6 0
6 4
11 2
Sample Output
2
3 3 -1
3
1 2 4
| [
"'''input\n3\n3 2\n7 1\n11 2\n4\n2 1\n6 0\n6 4\n11 2\n'''\nfrom sys import stdin\nfrom bisect import bisect_left\nfrom collections import OrderedDict\n\n\ndef check(c, r, x, y):\n\tif x**2 + y**2 - 2*x*c + c**2 <= r**2:\n\t\treturn True\n\telse:\n\t\treturn False\n\n\n# main starts\nn = int(stdin.readline().strip())\nrdict = OrderedDict()\ncenter = []\nfor _ in range(n):\n\tc, r = list(map(int, stdin.readline().split()))\n\trdict[c] = r\n\tcenter.append(c)\n\ncenter.sort()\n\nans = dict()\nm = int(stdin.readline().strip())\nfor i in range(m):\n\tx, y = list(map(int, stdin.readline().split()))\n\n\tindex = bisect_left(center, x)\n\n\tif index > 0 and index < len(center):\n\t\tif check(center[index], rdict[center[index]], x, y):\n\t\t\tif center[index] not in ans:\n\t\t\t\tans[center[index]] = i + 1\n\t\tif check(center[index - 1], rdict[center[index - 1]], x, y):\n\t\t\tif center[index - 1] not in ans:\n\t\t\t\tans[center[index - 1]] = i + 1\n\t\t\n\n\telif index == 0:\n\t\tif check(center[index], rdict[center[index]], x, y):\n\t\t\tif center[index] not in ans:\n\t\t\t\tans[center[index]] = i + 1\n\t\n\n\telif index == len(center):\n\t\tif check(center[index - 1], rdict[center[index - 1]], x, y):\n\t\t\tif center[index - 1] not in ans:\n\t\t\t\tans[center[index - 1]] = i + 1\n\nprint(len(ans))\nfor i in rdict:\n\tif i in ans:\n\t\tprint(ans[i], end = ' ')\n\telse:\n\t\tprint(-1, end = ' ')\n\n\n",
"from sys import stdin, stdout\r\n\r\nn = int(stdin.readline())\r\nchallengers = []\r\n\r\nfor i in range(n):\r\n a, b = map(int, stdin.readline().split())\r\n challengers.append((a, b, i))\r\n\r\nchallengers.sort()\r\n\r\nans = [float('inf') for i in range(n)]\r\nm = int(stdin.readline())\r\nquestions = []\r\n\r\n\r\nfor i in range(m):\r\n x, y = map(int, stdin.readline().split())\r\n \r\n l, r = -1, n\r\n while (r - l > 1):\r\n m = (r + l) // 2\r\n \r\n if challengers[m][0] <= x:\r\n l = m\r\n else:\r\n r = m\r\n \r\n \r\n if l >= 0 and (challengers[l][0] - x) ** 2 + y ** 2 <= challengers[l][1] ** 2:\r\n ans[challengers[l][2]] = min(ans[challengers[l][2]], i + 1)\r\n if r < n and (challengers[r][0] - x) ** 2 + y ** 2 <= challengers[r][1] ** 2:\r\n ans[challengers[r][2]] = min(ans[challengers[r][2]], i + 1)\r\n\r\nstdout.write(str(n - ans.count(float('inf'))) + '\\n')\r\nfor i in range(n):\r\n if ans[i] == float('inf'):\r\n stdout.write('-1' + ' \\n'[i == n - 1])\r\n else:\r\n stdout.write(str(ans[i]) + ' \\n'[i == n - 1])",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nl = 2 * pow(10, 4) + 1005\r\ns = [[] for _ in range(2 * l + 1)]\r\nxr = []\r\nfor i in range(n):\r\n x, r = map(int, input().split())\r\n x += l\r\n for j in range(x - r, x + r + 1):\r\n s[j].append(i)\r\n xr.append((x, r * r))\r\nm = int(input())\r\nans = [-1] * n\r\nfor i in range(1, m + 1):\r\n x, y = map(int, input().split())\r\n x += l\r\n for j in s[x]:\r\n if ans[j] ^ -1:\r\n continue\r\n x0, r = xr[j]\r\n if pow(abs(x - x0), 2) + pow(abs(y), 2) <= r:\r\n ans[j] = i\r\nc = n - ans.count(-1)\r\nprint(c)\r\nsys.stdout.write(\" \".join(map(str, ans)))",
"import sys\nimport math\n\nMAXNUM = math.inf\nMINNUM = -1 * math.inf\nASCIILOWER = 97\nASCIIUPPER = 65\n\n\ndef getInt():\n return int(sys.stdin.readline().rstrip())\n\n\ndef getInts():\n return map(int, sys.stdin.readline().rstrip().split(\" \"))\n\n\ndef getString():\n return sys.stdin.readline().rstrip()\n\n\ndef printOutput(th, d, ordering):\n sys.stdout.write(str(th) + \"\\n\")\n for target in ordering:\n if target in d:\n sys.stdout.write(str(d[target]) + \" \")\n else:\n sys.stdout.write(str(-1) + \" \")\n sys.stdout.write(\"\\n\")\n\n\ndef binSearch(t, x):\n l = 0\n r = len(t) - 1\n while l <= r:\n m = (l + r) // 2\n if t[m][0] >= x:\n r = m - 1\n else:\n l = m + 1\n\n return r\n\n\ndef distFrom(point, xPos):\n x1, y1 = xPos, 0\n x2, y2 = point\n\n return abs(x2 - x1) ** 2 + abs(y2 - y1) ** 2\n\n\ndef solve(t, s):\n d = dict()\n targetsHit = 0\n for x, y, shotNum in s:\n m = binSearch(\n t, x\n ) # find target to left if exists, and target to right if exists\n l = None\n r = None\n if 0 <= m <= len(t) - 1:\n l = m\n\n if 0 <= m + 1 <= len(t) - 1:\n r = m + 1\n if l != None:\n pos, rad = t[l]\n df = distFrom((x, y), pos)\n if df <= rad ** 2:\n if pos not in d:\n d[pos] = shotNum\n targetsHit += 1\n\n if r != None:\n pos, rad = t[r]\n df = distFrom((x, y), pos)\n if df <= rad ** 2:\n if pos not in d:\n d[pos] = shotNum\n targetsHit += 1\n return targetsHit, d\n\n\ndef readinput():\n n = getInt()\n originalOrdering = []\n targets = []\n for _ in range(n):\n pos, rad = getInts()\n originalOrdering.append(pos)\n targets.append((pos, rad))\n targets.sort()\n s = getInt()\n shots = []\n for i in range(s):\n x, y = getInts()\n shots.append((x, y, i + 1)) # x coord, y coord, shot number\n\n targetsHit, d = solve(targets, shots)\n printOutput(targetsHit, d, originalOrdering)\n\n\nreadinput()\n"
] | {"inputs": ["3\n2 1\n5 2\n10 1\n5\n0 1\n1 3\n3 0\n4 0\n4 0", "3\n3 2\n7 1\n11 2\n4\n2 1\n6 0\n6 4\n11 2", "2\n0 5\n10 5\n2\n7 2\n6 1", "3\n-3 3\n-10 2\n10 2\n4\n10 2\n2 -2\n-11 -1\n10 0", "5\n3 2\n-1 2\n6 1\n-6 1\n20 5\n6\n1 -2\n5 0\n5 1\n1 0\n-4 0\n3 2", "4\n2 1\n5 1\n-6 1\n10 2\n3\n-6 0\n-6 1\n-5 0", "2\n10 10\n-20 20\n4\n-1 6\n-1 -2\n21 0\n0 0", "3\n6 2\n-2 2\n2 1\n5\n2 0\n5 1\n2 0\n2 1\n2 -3", "3\n1 1\n3 1\n-4 2\n1\n-4 -3", "10\n67 5\n-69 5\n-58 3\n-5 6\n27 2\n95 3\n36 2\n-82 2\n-18 6\n-33 4\n20\n-41 3\n-47 -2\n37 3\n29 -6\n90 -8\n-40 -4\n-46 0\n70 -6\n93 -9\n84 -6\n-66 -1\n-44 6\n37 -8\n-29 3\n39 -4\n-77 -3\n-21 4\n-70 7\n97 -6\n-61 -5", "10\n57 5\n-59 5\n-28 3\n27 2\n46 2\n-48 6\n-3 2\n-21 2\n8 8\n-9 1\n30\n-26 3\n-29 9\n-66 -1\n-1 -9\n56 2\n-18 -9\n3 4\n-24 -12\n-33 -11\n44 0\n37 12\n-46 -11\n-25 0\n-41 -5\n-1 -1\n-27 7\n57 3\n35 4\n-1 -2\n-66 -3\n-60 12\n50 9\n58 10\n32 -1\n-64 -6\n48 3\n-21 -8\n28 0\n-67 8\n8 2", "15\n17 5\n-19 5\n-8 3\n27 2\n45 3\n36 2\n-32 2\n49 1\n-3 2\n-41 2\n-35 1\n-46 1\n-29 1\n33 1\n0 1\n50\n24 -4\n41 3\n37 3\n9 2\n38 -4\n-30 2\n-41 -5\n-9 -5\n-33 3\n0 2\n-20 -3\n-49 -4\n34 1\n-38 -2\n17 -1\n-33 3\n-17 4\n16 3\n-49 2\n-3 -4\n-9 2\n35 3\n37 -5\n0 0\n-46 -5\n48 1\n-22 -4\n-29 -5\n-41 4\n-11 0\n-5 -2\n-36 5\n42 0\n48 -3\n49 0\n-39 2\n-10 1\n38 3\n23 -1\n-35 -4\n7 -2\n4 5\n-29 0\n5 -1\n12 0\n-3 3\n46 1\n37 -1\n45 4\n-5 -4", "10\n2467 35\n-3169 25\n-5358 63\n-5705 46\n827 62\n2995 43\n5436 92\n-3902 54\n-4382 22\n-3718 96\n1\n5726 38", "1\n467 335\n10\n-169 -478\n-962 -705\n281 961\n995 -827\n-391 -902\n292 -421\n-718 447\n-771 -869\n-667 35\n-703 322", "2\n15000 1000\n-5000 1000\n2\n15000 0\n-5000 0"], "outputs": ["2\n3 3 -1 ", "3\n1 2 4 ", "1\n-1 1 ", "2\n-1 3 1 ", "3\n2 4 2 -1 -1 ", "1\n-1 -1 1 -1 ", "2\n4 1 ", "2\n2 -1 1 ", "0\n-1 -1 -1 ", "2\n-1 11 -1 -1 -1 -1 -1 -1 17 -1 ", "5\n5 -1 13 28 10 -1 -1 -1 7 -1 ", "8\n15 11 21 -1 33 48 -1 35 -1 -1 -1 -1 43 -1 24 ", "0\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ", "0\n-1 ", "2\n1 2 "]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
2d0d04fdf064776c1cdb48fe19f15fc2 | Text Document Analysis | Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.
In this problem you should implement the similar functionality.
You are given a string which only consists of:
- uppercase and lowercase English letters, - underscore symbols (they are used as separators), - parentheses (both opening and closing).
It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching "opening-closing" pair, and such pairs can't be nested.
For example, the following string is valid: "_Hello_Vasya(and_Petya)__bye_(and_OK)".
Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: "Hello", "Vasya", "and", "Petya", "bye", "and" and "OK". Write a program that finds:
- the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), - the number of words inside the parentheses (print 0, if there is no word inside the parentheses).
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols.
Print two space-separated integers:
- the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), - the number of words inside the parentheses (print 0, if there is no word inside the parentheses).
Sample Input
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
37
_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__
27
(LoooonG)__shOrt__(LoooonG)
5
(___)
Sample Output
5 42 65 20 0
| [
"def check(a):\r\n if a!='(' and a!=')' and a!='_':\r\n return True\r\n return False\r\n\r\nn=int(input())\r\ns=input()\r\ncnt,wcnt=0,0\r\ni=0\r\nwhile(i<n):\r\n if s[i]=='_':\r\n i+=1;continue\r\n if s[i]=='(':\r\n i+=1\r\n while(i<n and s[i]!=')'):\r\n if s[i]=='_':\r\n i+=1;continue\r\n while(i<n and check(s[i])):i+=1\r\n wcnt+=1\r\n i+=1;continue\r\n c=0\r\n while(i<n and check(s[i])):\r\n i+=1;c+=1\r\n cnt=max(cnt,c)\r\nprint(cnt,wcnt)\r\n \r\n \r\n \r\n \r\n",
"n = int(input())\r\nstring = input()\r\ninside_bracket = []\r\noutside_bracket = []\r\nb_start = False,\r\nw_start = False,\r\ntemp = ''\r\nfor char in string:\r\n if char == \"_\" and not w_start:\r\n w_start = True\r\n elif char == \"_\" and w_start:\r\n w_start = False\r\n if b_start == True:\r\n if len(temp) > 0:\r\n inside_bracket.append(temp)\r\n temp = \"\"\r\n else:\r\n if len(temp) > 0:\r\n outside_bracket.append(temp)\r\n temp = \"\"\r\n elif char == \"(\":\r\n b_start = True\r\n if w_start:\r\n if len(temp) > 0:\r\n outside_bracket.append(temp)\r\n temp = ''\r\n w_start = False\r\n elif char == \")\":\r\n b_start = False\r\n if w_start:\r\n if len(temp) > 0:\r\n inside_bracket.append(temp)\r\n temp = ''\r\n elif char.isalpha():\r\n temp += char\r\n w_start = True\r\nif len(temp) > 0:\r\n outside_bracket.append(temp)\r\n\r\nif len(outside_bracket) != 0:\r\n longest = max([len(x) for x in outside_bracket])\r\nelse:\r\n longest = 0\r\nparent = len(inside_bracket)\r\nprint(longest, parent)\r\n",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\ns = list(input().rstrip().decode())\r\nu = set(list(\"()_\"))\r\nc = 0\r\nf = 0\r\nans = [0, 0]\r\nfor i in s:\r\n if f and i in u and c:\r\n ans[1] += 1\r\n if i == \"(\":\r\n f, c = 1, 0\r\n elif i == \")\":\r\n f, c = 0, 0\r\n elif i == \"_\":\r\n c = 0\r\n else:\r\n c += 1\r\n if not f:\r\n ans[0] = max(ans[0], c)\r\nsys.stdout.write(\" \".join(map(str, ans)))",
"# LUOGU_RID: 123906943\ninput()\r\na = b = 0\r\nfor i, s in enumerate(input().replace(')', '(').split('(')):\r\n for x in s.split('_'):\r\n if x:\r\n if i % 2 == 0:\r\n a = max(a, len(x))\r\n else:\r\n b += 1\r\nprint(a, b)\r\n",
"n = int(input())\r\na = input()\r\ns = \"\"\r\nfor i in range(n):\r\n if a[i] == \")\":\r\n s = s + \" ) \"\r\n elif a[i] == \"(\":\r\n s = s + \" ( \"\r\n elif a[i] == \"_\":\r\n s = s + \" \"\r\n else:\r\n s = s + a[i]\r\n#print(s)\r\ns = list(s.split())\r\n#print(s) \r\n \r\nmxs = 0\r\nsc = 0\r\nc = 0\r\nfor i in range(len(s)):\r\n if s[i] == \"(\":\r\n sc = 1\r\n continue\r\n elif s[i] == \")\":\r\n sc = 0\r\n continue\r\n if len(s[i]) > mxs and sc == 0:\r\n mxs = len(s[i])\r\n elif sc == 1:\r\n c = c + 1\r\nprint(mxs, c)\r\n \r\n \r\n \r\n ",
"\"\"\" вне скобок внутри скобок внутри слова внутри слова вне скобок\r\n 0 1 2 3 \r\nбуква 3* 2* 2 3 \r\n( 1 1 1 1 \r\n) 0 0 0 0\r\n_ 0 1 1 0\r\n\"\"\"\r\nm = int(input())\r\na = input()\r\nstatus = tmp = res1 = res2 = 0\r\nfor i in a:\r\n if i == '(':\r\n status = 1\r\n elif i == ')':\r\n status = 0\r\n elif i == '_':\r\n if status in [0, 3]:\r\n status = 0\r\n elif status in [1, 2]:\r\n status = 1\r\n else:\r\n if status == 0:\r\n tmp = 1\r\n status = 3\r\n elif status == 1:\r\n res2 += 1\r\n status = 2\r\n elif status == 3:\r\n tmp += 1\r\n res1 = max(res1, tmp)\r\n\r\nprint(res1, res2)",
"n = int(input())\r\ns = input().replace(' ','')\r\nf = False\r\na = b = 0\r\nfor chr in s.replace('(',')').split(')'):\r\n for i in chr.split('_'):\r\n if f:\r\n b += len(i) != 0\r\n else:\r\n a = max(a,len(i))\r\n f = not f\r\nprint(a, b)\r\n\r\n",
"n = int(input())\r\ns = input()\r\nlongest = 0\r\nwords_inside = 0\r\nwithin = False\r\n\r\ni = 0\r\nwhile i < n:\r\n if s[i] == '(':\r\n within = True\r\n i += 1\r\n elif s[i] == ')':\r\n within = False\r\n i += 1\r\n else:\r\n if s[i] == '_':\r\n i += 1\r\n else:\r\n word_length = 0\r\n while i < n and s[i] != '(' and s[i] != ')' and s[i] != '_':\r\n word_length += 1\r\n i += 1\r\n if not within:\r\n longest = max(longest, word_length)\r\n else:\r\n words_inside += 1\r\n\r\nprint(longest, words_inside)# 1698407814.800496",
"\r\na = int(input())\r\n\r\nc = input()\r\n# _Hello_Vasya(and_Petya)__bye_(and_OK)\r\n\r\ninside = []\r\noutside = []\r\npos = c.find('(')\r\nwhile ~pos:\r\n e = c.find(')')\r\n newArr = c[pos+1:e].split('_')\r\n inside += newArr\r\n # Before (\r\n before = c[:pos].split('_')\r\n outside += [x for x in before if x != '']\r\n c = c[e+1:]\r\n pos = c.find('(')\r\n\r\noutside+= c.split('_')\r\noutside += [x for x in outside if x != '']\r\ninside = [x for x in inside if x != '']\r\nmx = 0\r\nfor ele in outside:\r\n mx = max(mx, len(ele))\r\n\r\nprint(mx, len(inside))",
"n = int(input())\r\nstr = input().replace(\"_\", \" \").replace(\"(\", \" ( \").replace(\")\", \" ) \").split()\r\ncounter1 = []\r\ncounter2 = 0\r\nflag = False\r\nfor i in str:\r\n if i == \"(\":\r\n flag = True\r\n if i == \")\":\r\n flag = False\r\n if flag == False:\r\n if i == \")\":\r\n continue\r\n counter1.append(len(i))\r\n if flag == True:\r\n counter2 += 1\r\nif len(counter1) == 0:\r\n counter1 = 0\r\n print(counter1, counter2 - str.count(\"(\"))\r\nelse:\r\n print(max(counter1), counter2 - str.count(\"(\"))\r\n\r\n\r\n\r\n"
] | {"inputs": ["37\n_Hello_Vasya(and_Petya)__bye_(and_OK)", "37\n_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__", "27\n(LoooonG)__shOrt__(LoooonG)", "5\n(___)", "254\n()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()", "14\nQ(___)_u(_U)HG", "50\n_F_()___(____q)H_(__)__(_____p________o_)__Bz()___", "10\ndJ_R_____K", "20\nm(_)jzay()s()d()T(M)", "50\n()()W()g_(EEX)UADba(R)()TD(L)X(Aub)DN(a)(YYJXNgyK)", "80\n_____(_____k_____q____N)(e___sM__pf___)_(___g_____)__V_n___________z(__)__(___)U", "100\nFE_i_UhQF_oIh(v__qf)WVa_gND___caHkdU(_WP_Kxm__WEIn_KZLBS)_XDwNnR_c(_Pv_A)LXO__GEd_R_bTP_hAnZ_____sDL", "150\njUcWddnQOXvZcdiQm_ngFnpbXyQCIzHHwU(KHNQPMDPFkoihdhZAthjelfgAHS_tco_JwgEFu)q_WLbNsZgQLJFFX_vAOClrvJQm_XWhHDOP_aMT_RuCFsegLgwQbI_FTJPfIHwmpr_jrtbiTsiIaX", "200\n()()()()()(_)()()()()()()()_()()()()()()()()(_)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()y()()()()()()()()()()()(_)()_()()()()()()()(_)()()()()()()()()()()()()(B)()()N_()()()()()()()()", "250\nST()jw()()()(c)()()s_(bB)()q()()()()()()()(_)()()()()()()()(u)()()(e)()()()()()()()()()(_)()()()()()_(B_)()()()()n(_)(A)()()()()(M)I()P()(VT)o(_)q()()()()(f)()()()()()()a(Du)()()()k(Q)()(_)()()()()(U)Z()(d)()_(D)()y()()i(i)(O)_b()()()(__M)()()()()()w", "255\nMSGxEfof_UkcbUrRTEUgYLoWoVjuQJbqbBBmvUPLU_BXTXNjysGvgZqtwh_snLtUPhFGJMnyRvF_lG_eEu_J__qI_wrADYbAKZjhJuYVC_etLQgvmVaeqJ_a(Xh_Z_zkWmHxSQYvBOP__nLINkxiWlGzQiFv_GgGGqShWhBS_lEqCidMabWaYwIx_fVTluiPJuBryPtBkkCGxb)lOj_iJXBGOqj_aerFn_cKkEWbAK_YrgX__mcroeiRmuaMqYh", "255\n___t_Cjo_____J___c__F_(_c______JY__Ub__x___________K_zf___T_U___Kc_______P_____W__S__o____Yx__ge___v____S___N_p_v____n_b___E__e_V___a___S____yvZk_Lr___U_e__x____i_____m___Z______E__A_________k____T__)l_B_________________q(__O___oi___B_b______Gf____jz____)", "255\nT___J(M_XZJlr_lH___mqJA_p__kW)ko__F_M_Aro__ZA_G_M_P_____j_V(J_Jk_dkR_ta_lbIUhKFfo_y_DluW)IVFj_gouRfMhabn()_e___q_vo__QPEGBI_TpVVI_clPwwb_m_yL_cMVKgi___RJb_J_f____tPCyntLOr_s_x_N_SyqQw_zP_mycsW_o_c_o_Yzb_UVa_ATd(BYH_gl___Y__Uzok_Y_IA_XL_D__bkJ____e__K_quk)", "255\ngB(ZKoVzD_WVZaYCzXGJYiTHB_XpOcKuLmclmw)UmpgxadtSQ(jGo)KQfXT(Yr_fP_CPbdIv)(AAmaGwrvN)(_Zg)dw(q_O_yLXQzdf)cVN_hd__EaTKwvYNte(_NmFs_)d_KOCp(UWUuGkuMJ)IXwulpMrJwBqdprtLcOE_JSnifGNBBQnuB_(_rhlesFvqglyJ_OYr_WpRM)_fjIfYdXpEbSOZCvk()x_YLygRDpOOZrjycBG_NEa_KjII_Db", "255\n__X__()__x___X_(_)(_Ax)__H()_(_)_(_________)___(Y_p__t)_(_F)_(bY__S__)_____v_()__()J____q_(__)_c___G_SI__(__ynv)_M_______(_x_____V___ib__i)(__r_)__A(_)d(H)____H_K_Q_(___KW)(p_n)__(______g)____L(_)_T_hL___(__)___(_)(_)_h()(f_____)_l_____(_)(l)____(_)_h(_)F", "255\njNufi_Tql(Q)()_Rm(_RS)w()(Q)_(_)(c)Eme()()()J(vKJ_)(X_si)()g(u)(_)n()F()a()(_)(U)fx(c__qivDE)J(__pS_k)r()(N_Z_cW__)__z_LgHJE_()s_()BCKMgJ(eW)_t(oGp)()kl()(_)_(__tn_W_Y)dD()(_)_()()x_(u)(W)(T)E(_LF_DkdIx)sx__(Q_)(bL)V(_)(oKrE)__(_)(fW_)_z_()()O(O)_()cacQg_", "255\na()J()f()vAL()(pV)(Ve)()()c()()(Wtg)(_)DW(D)()()sEXF()(_B)V(_W)Z_a_(_)U(tb)(u)I()Z()_()()()cw()ZW()Z()V()A(T)_a()()_jL(V)()(z)()Tn()y()(B)uEf()(B)()()p()()(B_)nz(Xs)(o)T()()IkH()()(pJ)()()()()()E()z()Ja_()Z()(Q)(_)(N)()c()p()g(_)l()()Q()()U()()()()(aZ)m()", "255\nAf________T_C____t_p(_Ug___Fr_Wg_)j_____x__j_a___Q_____(__p_____M)__J__jj____E__J(_W____eT)__wtm____T____Z_c_____C____P_____k___(___ql_X_B_________l____L_______F___m___p_S__DI______w)_f__r_lGG_m__SJ(__q__G_____s___s___o_______bg____f____vZ___rg_k___C____)", "255\n(s)()(y)()()l()()()()()()()()_c()()()()X()()()()(l)()()()()()ND()(F)()()_()()()()a()()F(O)(e)()(_)(t)(_)()_()()_()()()()()(So)()()(Lm)(e)()()(F)()Yt(_)()()__()()()(w)T()(s)()_()()()()O(j)()U()()()()()_(_H)()()_()()()c()(_)()()y(j)()C_()()HRx()()(EE)()p()W", "255\n()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()_()()()()()()()()K()()()()()()()()()()()()(_)()()_()()()z()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()", "255\n(I_____)_________Q__W(P_V___G__m_U_)___________a_X__X_n__Br______N___(__)(_q)(___G____x_)__r_ru__D_(____E_u)_cV_joiL_(______)C__W(___BtgJ__ga_FFwpcu_K)_Tm(____h__)_(____v_)_(_F___E_n_lm_kctg_____u__)Q___vh(u_)__(____CAM__F_Y___O__G_P___)_P_ZLo__K__nGAgq_S", "255\nacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJasdza", "255\n(cvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJacvfrAGKFJasdz)", "255\n(a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a)", "1\n_", "1\na", "2\n()", "2\nad", "2\n_a", "2\nq_", "3\n(_)", "3\n(a)", "3\nq_z", "6\na(al)a", "10\na(a)aa(a)a", "5\n()abc"], "outputs": ["5 4", "2 6", "5 2", "0 0", "0 0", "2 1", "2 3", "2 0", "4 1", "5 6", "1 7", "6 8", "17 3", "1 1", "2 17", "32 7", "3 45", "10 25", "20 17", "2 20", "6 31", "4 20", "3 29", "3 17", "1 0", "5 30", "255 0", "0 1", "0 127", "0 0", "1 0", "0 0", "2 0", "1 0", "1 0", "0 0", "0 1", "1 0", "1 1", "2 2", "3 0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 10 | |
2d12baac1920921d796b1d8793614adc | Rock-paper-scissors | Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.
The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture.
Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?".
Sample Input
rock
rock
rock
paper
rock
rock
scissors
rock
rock
scissors
paper
rock
Sample Output
?
F
?
?
| [
"F=input()\nM=input()\nS=input()\n \nBeater={\"paper\":\"scissors\",\"scissors\":\"rock\",\"rock\":\"paper\"}\n \nif S==Beater[F] and F==M:\n print(\"S\")\n \nelif F==Beater[S] and S==M:\n print(\"F\")\n \nelif M==Beater[F] and F==S:\n print(\"M\")\n \nelse:\n print(\"?\")\n \t \t\t\t \t \t\t \t\t\t \t",
"f=input()\r\nm=input()\r\ns=input()\r\nif f==m!=s:\r\n if f=='paper' and s=='scissors' or f=='scissors' and s=='rock' or f=='rock' and s=='paper':\r\n print('S')\r\n else:\r\n print('?')\r\nelif f!=m==s:\r\n if m=='paper' and f=='scissors' or m=='scissors' and f=='rock' or m=='rock' and f=='paper':\r\n print('F')\r\n else:\r\n print('?')\r\nelif f==s!=m:\r\n if s=='paper' and m=='scissors' or s=='scissors' and m=='rock' or s=='rock' and m=='paper':\r\n print('M')\r\n else:\r\n print('?')\r\nelse:\r\n print('?')\r\n",
"def main():\r\n a = [input(), input(), input()]\r\n winner = -1\r\n\r\n if a.count('rock') == 1 and a.count('scissors') == 2:\r\n winner = a.index('rock')\r\n elif a.count('scissors') == 1 and a.count('paper') == 2:\r\n winner = a.index('scissors')\r\n elif a.count('paper') == 1 and a.count('rock') == 2:\r\n winner = a.index('paper')\r\n\r\n print('?' if winner == -1 else\r\n 'F' if winner == 0 else\r\n 'M' if winner == 1 else\r\n 'S')\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"import sys\r\n\r\nfyodor_string = input()\r\nmatroskin_string = input()\r\nsharic_string = input()\r\n\r\n# Conditions under which Fyodor will win\r\nif (fyodor_string == \"rock\"): \r\n if (matroskin_string == \"scissors\"):\r\n if (sharic_string == \"scissors\"):\r\n print(\"F\")\r\n sys.exit(0)\r\nelif (fyodor_string == \"scissors\"): \r\n if (matroskin_string == \"paper\"):\r\n if (sharic_string == \"paper\"):\r\n print(\"F\")\r\n sys.exit(0)\r\nelse: # (fyodor_string == \"paper\"): \r\n if (matroskin_string == \"rock\"):\r\n if (sharic_string == \"rock\"):\r\n print(\"F\")\r\n sys.exit(0)\r\n\r\n# Conditions under which Matroskin will win\r\nif (matroskin_string == \"rock\"): \r\n if (sharic_string == \"scissors\"):\r\n if (fyodor_string == \"scissors\"):\r\n print(\"M\")\r\n sys.exit(0)\r\nelif (matroskin_string == \"scissors\"): \r\n if (sharic_string == \"paper\"):\r\n if (fyodor_string == \"paper\"):\r\n print(\"M\")\r\n sys.exit(0)\r\nelse: # (matroskin_string == \"paper\"): \r\n if (sharic_string == \"rock\"):\r\n if (fyodor_string == \"rock\"):\r\n print(\"M\")\r\n sys.exit(0)\r\n\r\n# Conditions under which Sharic will win\r\nif (sharic_string == \"rock\"): \r\n if (fyodor_string == \"scissors\"):\r\n if (matroskin_string == \"scissors\"):\r\n print(\"S\")\r\n sys.exit(0)\r\nelif (sharic_string == \"scissors\"): \r\n if (fyodor_string == \"paper\"):\r\n if (matroskin_string == \"paper\"):\r\n print(\"S\")\r\n sys.exit(0)\r\nelse: # (sharic_string == \"paper\"): \r\n if (fyodor_string == \"rock\"):\r\n if (matroskin_string == \"rock\"):\r\n print(\"S\")\r\n sys.exit(0)\r\n\r\nprint(\"?\")",
"# https://codeforces.com/problemset/problem/48/A\r\n\r\ndef func_sol(lines):\r\n a = lines\r\n\r\n R = 'rock'\r\n P = 'paper'\r\n S = 'scissors'\r\n\r\n r = a.count(R)\r\n p = a.count(P)\r\n s = a.count(S)\r\n\r\n winner = None\r\n if r == 1 and s == 2:\r\n winner = R\r\n if s == 1 and p == 2:\r\n winner = S\r\n if p == 1 and r == 2:\r\n winner = P\r\n\r\n return '?' if winner is None else 'FMS'[a.index(winner)]\r\n\r\n\r\ndef main():\r\n try:\r\n from codeforces.utilities import run_tests\r\n run_tests(func_sol)\r\n except ImportError:\r\n from sys import stdin\r\n print(func_sol(stdin.read().split('\\n')[:-1]))\r\n\r\n\r\nmain()\r\n",
"data = []\ndata.append(input())\ndata.append(input())\ndata.append(input())\n\nplayers = [\"F\", \"M\", \"S\"]\nr = p = s = 0\n\nfor i in data:\n if i == \"rock\": r += 1\n elif i == \"paper\": p += 1\n else: s += 1\n\nif p == 1 and r == 2:\n print(players[data.index(\"paper\")])\nelif s == 1 and p == 2:\n print(players[data.index(\"scissors\")])\nelif r == 1 and s == 2:\n print(players[data.index(\"rock\")])\nelse:\n print(\"?\")\n\n\n\n\n\t\t \t \t\t \t\t\t\t\t \t \t\t\t\t \t\t \t\t\t",
"F=str(input())\r\nM=str(input())\r\nS=str(input())\r\nif ((F=='scissors' and M==S=='paper') or (F=='paper' and M==S=='rock') or (F=='rock' and M==S=='scissors')):\r\n print('F')\r\nelif ((S=='scissors' and M==F=='paper') or (S=='paper' and M==F=='rock') or (S=='rock' and M==F=='scissors')):\r\n print('S')\r\nelif ((M == 'scissors' and S == F == 'paper') or (M == 'paper' and S == F == 'rock') or (M == 'rock' and S == F == 'scissors')):\r\n print('M')\r\nelse:\r\n print('?')",
"# bsdk idhar kya dekhne ko aaya hai, khud kr!!!\r\n# import math\r\n# from itertools import *\r\n# import random\r\n# import calendar\r\n# import datetime\r\n# import webbrowser\r\n\r\nfirst = input()\r\nsecond = input()\r\nthird = input()\r\nfinal = str(first[0] + second[0] + third[0])\r\nif final == \"prr\" or final == \"rss\" or final == \"spp\":\r\n print(\"F\")\r\nelif final == \"rpr\" or final == \"srs\" or final == \"psp\":\r\n print(\"M\")\r\nelif final == \"rrp\" or final == \"ssr\" or final == \"pps\":\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n",
"beat_dic={'rock':'scissors','paper':'rock','scissors':'paper'}\r\n\r\nhands=[input() for i in range(3)]\r\n\r\nfor i in range(3):\r\n if hands[i-1]==hands[i-2]==beat_dic[hands[i]]:\r\n print('FMS'[i])\r\n exit()\r\nprint('?')\r\n",
"import sys\r\nimport math\r\n\r\n#to read string\r\nget_string = lambda: sys.stdin.readline().strip()\r\n#to read list of integers\r\nget_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )\r\n#to read non spaced string and elements are integers to list of int\r\nget_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))\r\n#to read non spaced string and elements are character to list of character\r\nget_charList_from_str = lambda: list(sys.stdin.readline().strip())\r\n#get word sepetared list of character\r\nget_char_list = lambda: sys.stdin.readline().strip().split() \r\n#to read integers\r\nget_int = lambda: int(sys.stdin.readline())\r\n#to print faster\r\npt = lambda x: sys.stdout.write(str(x))\r\n\r\n#--------------------------------WhiteHat010--------------------------------#\r\nf = get_string()\r\nm = get_string()\r\ns = get_string()\r\n\r\nlst = [f,m,s]\r\ns = set(lst)\r\nif len(s) == 3:\r\n print('?')\r\nelif len(s) == 1:\r\n print('?')\r\nelse:\r\n a = max(s, key = lst.count)\r\n b = min(s, key = lst.count)\r\n if a == 'rock':\r\n if b == 'paper':\r\n print( ['F','M','S'][ lst.index(b) ] )\r\n else: #scissors\r\n print('?')\r\n elif a == 'scissors':\r\n if b == 'rock':\r\n print( ['F','M','S'][ lst.index(b) ] )\r\n else: #paper\r\n print('?')\r\n else: #paper\r\n if b == 'scissors':\r\n print( ['F','M','S'][ lst.index(b) ] )\r\n else: #rock\r\n print('?')\r\n\r\n",
"def solve(F: str, M: str, S: str) -> str:\r\n # scissors and paper\r\n if(F=='scissors' and M=='paper' and S=='paper'):\r\n return('F')\r\n elif(F=='paper' and M=='scissors' and S=='paper'):\r\n return('M')\r\n elif(F=='paper' and M=='paper' and S=='scissors'):\r\n return('S')\r\n \r\n \r\n #rock and paper\r\n elif(F=='paper' and M=='rock' and S=='rock'):\r\n return('F')\r\n elif(F=='rock' and M=='paper' and S=='rock'):\r\n return('M')\r\n elif(F=='rock' and M=='rock' and S=='paper'):\r\n return('S')\r\n \r\n #rock and scissors\r\n elif(F=='rock' and M=='scissors' and S=='scissors'):\r\n return('F')\r\n elif(F=='scissors' and M=='rock' and S=='scissors'):\r\n return('M')\r\n elif(F=='scissors' and M=='scissors' and S=='rock'):\r\n return('S')\r\n else:\r\n return('?')\r\n \r\n \r\nF=input().strip()\r\nM=input().strip()\r\nS=input().strip()\r\nprint(solve(F, M, S))\r\n ",
"r='rock'\r\ns='scissors'\r\np='paper'\r\nF=input()\r\nM=input()\r\nS=input()\r\ndef ganador(F,S1,S2):\r\n if S1 != S2:\r\n return False\r\n \r\n if F == r:\r\n if S1 == s:\r\n return True\r\n elif F == s:\r\n if S1 == p:\r\n return True\r\n else:\r\n if S1 == r:\r\n return True\r\n return False \r\n\r\nif ganador(F,M,S):\r\n print(\"F\")\r\nelif ganador(M,F,S):\r\n print(\"M\")\r\nelif ganador(S,F,M):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n\r\n",
"l=[]\r\nfor i in range(3):\r\n l.append(input())\r\nif l.count('rock')==2 and l.count('paper')==1:\r\n p=l.index('paper')\r\nelif l.count('scissors')==2 and l.count('rock')==1:\r\n p=l.index('rock')\r\nelif l.count('paper')==2 and l.count('scissors')==1:\r\n p=l.index('scissors')\r\nelse:\r\n p='?'\r\nif p==0:\r\n print('F')\r\nelif p==1:\r\n print('M')\r\nelif p==2:\r\n print('S')\r\nelse:\r\n print(p)\r\n",
"s=str(input())\r\ns1=str(input())\r\ns2=str(input())\r\nflag=0\r\nl=[]\r\nif(s =='rock' and len(l)==0):\r\n if(s1 =='scissors' and s2=='scissors'):\r\n l.append('F')\r\n\r\nif(s =='paper' and len(l)==0):\r\n if(s1 =='rock' and s2=='rock'):\r\n l.append('F')\r\n\r\nif(s =='scissors' and len(l)==0):\r\n if(s1 =='paper' and s2=='paper'):\r\n l.append('F')\r\nif(s1 =='rock' and len(l)==0):\r\n if(s =='scissors' and s2=='scissors'):\r\n l.append('M')\r\n\r\nif(s1 =='paper' and len(l)==0):\r\n if(s =='rock' and s2=='rock'):\r\n l.append('M')\r\n\r\nif(s1 =='scissors' and len(l)==0):\r\n if(s =='paper' and s2=='paper'):\r\n l.append('M') \r\nif(s2 =='rock' and len(l)==0):\r\n if(s =='scissors' and s1=='scissors'):\r\n l.append('S')\r\n\r\nif(s2 =='paper' and len(l)==0):\r\n if(s =='rock' and s1=='rock'):\r\n l.append('S')\r\n\r\nif(s2 =='scissors' and len(l)==0):\r\n if(s =='paper' and s1=='paper'):\r\n l.append('S') \r\nif(len(l)==0):\r\n print('?')\r\nelse:\r\n print(*l)\r\n\r\n \r\n\r\n \r\n ",
"f = input()\r\nm = input()\r\ns = input()\r\ndiction = dict()\r\ndiction2 = dict()\r\n\r\ndiction[\"F\"] = f\r\ndiction[\"M\"] = m\r\ndiction[\"S\"] = s\r\n\r\nfor value in diction.values():\r\n diction2[value] = diction2.get(value, 0) + 1\r\n\r\n\r\nif f == m and f == s:\r\n print(\"?\")\r\nelif f != m and f != s and m != s:\r\n print(\"?\")\r\nelse:\r\n if \"scissors\" not in diction.values():\r\n if diction2[\"paper\"] > 1:\r\n print(\"?\")\r\n else:\r\n for val in diction:\r\n if diction[val] == \"paper\":\r\n print(val)\r\n elif \"paper\" not in diction.values():\r\n if diction2[\"rock\"] > 1:\r\n print(\"?\")\r\n else:\r\n for val in diction:\r\n if diction[val] == \"rock\":\r\n print(val)\r\n elif \"rock\" not in diction.values():\r\n if diction2[\"scissors\"] > 1:\r\n print(\"?\")\r\n else:\r\n for val in diction:\r\n if diction[val] == \"scissors\":\r\n print(val)",
"s1=input()\r\ns2=input()\r\ns3=input()\r\ns=[s1,s2,s3]\r\nif len(set(s))==3:\r\n print('?')\r\nelif len(set(s))==1:\r\n print('?')\r\nelse:\r\n if s1==s2:\r\n if s1=='rock':\r\n if s3=='paper':\r\n print('S')\r\n else:\r\n print('?')\r\n elif s1=='paper':\r\n if s3=='scissors':\r\n print('S')\r\n else:\r\n print('?')\r\n else:\r\n if s3=='rock':\r\n print('S')\r\n else:\r\n print('?')\r\n elif s1==s3:\r\n if s1=='rock':\r\n if s2=='paper':\r\n print('M')\r\n else:\r\n print('?')\r\n elif s1=='paper':\r\n if s2=='scissors':\r\n print('M')\r\n else:\r\n print('?')\r\n else:\r\n if s2=='rock':\r\n print('M')\r\n else:\r\n print('?')\r\n else:\r\n if s2=='rock':\r\n if s1=='paper':\r\n print('F')\r\n else:\r\n print('?')\r\n elif s2=='paper':\r\n if s1=='scissors':\r\n print('F')\r\n else:\r\n print('?')\r\n else:\r\n if s1=='rock':\r\n print('F')\r\n else:\r\n print('?')",
"f=input()\r\nm=input()\r\ns=input()\r\nif f[0]=='r' and m[0]=='s' and s[0]=='s' or f[0]=='s' and m[0]=='p' and s[0]=='p' or f[0]=='p' and m[0]=='r' and s[0]=='r':\r\n print('F')\r\nelif m[0]=='r' and f[0]=='s' and s[0]=='s' or m[0]=='s' and f[0]=='p' and s[0]=='p' or m[0]=='p' and f[0]=='r' and s[0]=='r':\r\n print('M')\r\nelif s[0]=='r' and m[0]=='s' and f[0]=='s' or s[0]=='s' and m[0]=='p' and f[0]=='p' or s[0]=='p' and m[0]=='r' and f[0]=='r':\r\n print('S')\r\nelse:\r\n print('?')\r\n",
"F = input()\r\nM = input()\r\nS = input()\r\nif F == M and F == S:\r\n print(\"?\")\r\nelse:\r\n if F == M:\r\n if (S == \"rock\" and F == \"scissors\") or (S == \"scissors\" and F == \"paper\") or (S == \"paper\" and F == \"rock\"):\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\n elif M == S:\r\n if (F == \"rock\" and M == \"scissors\") or (F == \"scissors\" and M == \"paper\") or (F == \"paper\" and M == \"rock\"):\r\n print(\"F\")\r\n else:\r\n print(\"?\")\r\n elif F == S:\r\n if (M == \"rock\" and F == \"scissors\") or (M == \"scissors\" and F == \"paper\") or (M == \"paper\" and F == \"rock\"):\r\n print(\"M\")\r\n else:\r\n print(\"?\")\r\n else:\r\n print(\"?\")",
"def prostokvashino(lst):\r\n if all(x == lst[0] for x in lst):\r\n return \"?\"\r\n if (lst[0] == \"rock\" and lst[1] == \"scissors\" and lst[2] == \"scissors\") or (\r\n lst[0] == \"paper\" and lst[1] == \"rock\" and lst[2] == \"rock\") or (\r\n lst[0] == \"scissors\" and lst[1] == \"paper\" and lst[2] == \"paper\"):\r\n return \"F\"\r\n if (lst[1] == \"rock\" and lst[0] == \"scissors\" and lst[2] == \"scissors\") or (\r\n lst[1] == \"paper\" and lst[0] == \"rock\" and lst[2] == \"rock\") or (\r\n lst[1] == \"scissors\" and lst[0] == \"paper\" and lst[2] == \"paper\"):\r\n return \"M\"\r\n if (lst[2] == \"rock\" and lst[0] == \"scissors\" and lst[1] == \"scissors\") or (\r\n lst[2] == \"paper\" and lst[0] == \"rock\" and lst[1] == \"rock\") or (\r\n lst[2] == \"scissors\" and lst[0] == \"paper\" and lst[1] == \"paper\"):\r\n return \"S\"\r\n return \"?\"\r\n\r\n\r\na = list()\r\nfor i in range(3):\r\n t = input()\r\n a.append(t)\r\nprint(prostokvashino(a))\r\n",
"fedor = input()\r\nmatroskin = input()\r\nsharik = input()\r\nif (fedor == 'scissors' and matroskin =='paper' and sharik =='paper') or (fedor == 'paper' and matroskin =='rock' and sharik =='rock') or (fedor == 'rock' and matroskin =='scissors' and sharik =='scissors'):\r\n print('F')\r\nelif (matroskin == 'scissors' and fedor=='paper' and sharik =='paper') or ( matroskin == 'paper' and fedor =='rock' and sharik =='rock') or (matroskin == 'rock' and fedor =='scissors' and sharik =='scissors'):\r\n print('M')\r\nelif (sharik == 'scissors' and fedor=='paper' and matroskin =='paper') or ( sharik == 'paper' and fedor =='rock' and matroskin =='rock') or (sharik == 'rock' and fedor =='scissors' and matroskin =='scissors'):\r\n print('S')\r\nelse:\r\n print('?')",
"F=input ()\r\nM=input ()\r\nS=input ()\r\n \r\ndef check(s1,s2):\r\n if s1=='rock' and s2=='scissors':\r\n return 1\r\n elif s2=='paper' and s1=='scissors':\r\n return 1\r\n elif s1=='paper' and s2=='rock':\r\n return 1\r\n else:\r\n return 0\r\n\r\nif check(F,M) and check(F,S):\r\n print(\"F\")\r\nelif check(S,M) and check(S,F):\r\n print(\"S\")\r\nelif check(M,S) and check(M,F):\r\n print(\"M\")\r\nelse:\r\n print(\"?\")\r\n",
"Fwins = ['rss','prr','spp']\r\nMwins = ['srs','rpr','psp']\r\nSwins = ['ssr','rrp','pps']\r\nsum = ''\r\nfor i in range(3):\r\n sum += input()[0]\r\n\r\nif sum in Fwins:\r\n print(\"F\")\r\nelif sum in Mwins:\r\n print(\"M\")\r\nelif sum in Swins:\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n\r\n",
"f = \"\"\nm = \"\"\ns = \"\"\n\npaper = \"paper\"\nrock = \"rock\"\nscissors = \"scissors\"\n\ndef compare(f, s, m):\n if f == s and s == m:\n return \"?\"\n \n # F wins\n if f == paper:\n if s == rock and m == rock:\n return \"F\"\n if f == rock:\n if s == scissors and m == scissors:\n return \"F\"\n if f == scissors:\n if s == paper and m == paper:\n return \"F\"\n\n # M wins\n if m == paper:\n if s == rock and f == rock:\n return \"M\"\n if m == rock:\n if s == scissors and f == scissors:\n return \"M\"\n if m == scissors:\n if s == paper and f == paper:\n return \"M\"\n\n # S wins\n if s == paper:\n if m == rock and f == rock:\n return \"S\"\n if s == rock:\n if m == scissors and f == scissors:\n return \"S\"\n if s == scissors:\n if m == paper and f == paper:\n return \"S\"\n\n # Nobody wins\n return \"?\"\n\ndef main(inputs):\n f = inputs[0]\n m = inputs[1]\n s = inputs[2]\n\n print(compare(f, s, m))\n\n\nimport sys\ninputs = sys.stdin.read().split()\n\nmain(inputs)\n\t \t\t\t\t\t \t\t\t \t \t\t\t\t \t\t\t \t\t\t",
"\r\nf=input()\r\nl=[\"rock\",\"paper\",\"scissors\"]\r\nm=input()\r\n\r\ns=input()\r\nif (l[0]==f and m==l[2] and s==l[2] ) or (l[1]==f and m==l[0] and s==l[0] ) or (l[2]==f and m==l[1] and s==l[1] ):\r\n\tprint(\"F\")\r\nelif (l[0]==m and f==l[2] and s==l[2] ) or (l[1]==m and f==l[0] and s==l[0] ) or (l[2]==m and f==l[1] and s==l[1] ):\r\n\tprint(\"M\")\r\nelif (l[0]==s and f==l[2] and m==l[2] ) or (l[1]==s and f==l[0] and m==l[0] ) or (l[2]==s and f==l[1] and m==l[1] ):\r\n\tprint(\"S\")\r\nelse:\r\n\tprint(\"?\")",
"from collections import Counter\r\n\r\ndef solve(f,m,s):\r\n c = Counter()\r\n d = dict()\r\n comp = {'rock':'scissors', 'scissors':'paper', 'paper':'rock'}\r\n d[f] = 'F'\r\n d[m] = 'M'\r\n d[s] = 'S'\r\n c[f] += 1\r\n c[m] += 1\r\n c[s] += 1\r\n if len(c) == 1 or len(c) == 3:\r\n print(\"?\")\r\n return\r\n for k,v in c.items():\r\n if v == 1:\r\n one = k\r\n if v == 2:\r\n two = k\r\n if comp[one] == two:\r\n print(d[one])\r\n else:\r\n print('?')\r\n\r\nf = input()\r\nm = input()\r\ns = input()\r\nsolve(f,m,s)\r\n",
"gestures = [input() for i in range(3)]\r\nfor i, x in enumerate(['F', 'M', 'S']):\r\n opponents = [gestures[j] for j in range(3) if i != j]\r\n if gestures[i] == 'rock' and opponents[0] == 'scissors' and opponents[1] == 'scissors' or (\r\n gestures[i] == 'paper' and opponents[0] == 'rock' and opponents[1] == 'rock') or (\r\n gestures[i] == 'scissors' and opponents[0] == 'paper' and opponents[1] == 'paper'):\r\n print(x)\r\n break\r\nelse:\r\n print('?')\r\n",
"a=input()\r\nb=input()\r\nc=input()\r\nif a=='rock' and b=='scissors'and c==\"scissors\" :\r\n\tprint(\"F\")\r\nelif b=='rock' and a=='scissors'and c==\"scissors\":\r\n\tprint(\"M\")\r\nelif c=='rock' and b=='scissors'and a==\"scissors\": \r\n\tprint(\"S\")\r\nelif a=='paper' and b=='rock'and c==\"rock\":\r\n\tprint(\"F\")\r\nelif b=='paper' and c=='rock'and a==\"rock\":\r\n\tprint(\"M\")\r\nelif c=='paper' and b=='rock'and a==\"rock\":\r\n\tprint(\"S\")\r\nelif a=='scissors' and b=='paper'and c==\"paper\":\r\n\tprint(\"F\")\r\nelif b=='scissors' and c=='paper'and a==\"paper\":\r\n\tprint(\"M\")\r\nelif c=='scissors' and b=='paper'and a==\"paper\":\r\n\tprint(\"S\")\t\r\nelse:\r\n\tprint('?')",
"game = ['rock', 'paper', 'scissors']\nplayer = ['F', 'M', 'S']\nround = []\n\nfor c in range(0, 3):\n round.append(input().lower())\n\nnRock = round.count(game[0])\nnPaper = round.count(game[1])\nnScissors = round.count(game[2])\n\n#if (nRock == 3 or nScissors == 3 or nPaper == 3):\n# print('?')\n#elif nRock == 1 and nScissors == 1 and nPaper == 1:\n# print('?')\nif nRock == 2:\n if nPaper == 1:\n aux = round.index(game[1])\n print(player[aux])\n else:\n print('?')\nelif nPaper == 2:\n if nScissors == 1:\n aux = round.index(game[2])\n print(player[aux])\n else:\n print('?')\nelif nScissors == 2:\n if nRock == 1:\n aux = round.index(game[0])\n print(player[aux])\n else:\n print('?')\nelse:\n print('?')\n\n",
"a = input()\r\nb = input()\r\nc = input()\r\nif(a == \"paper\" and b == \"rock\" and c == \"rock\") or (a == \"rock\" and b == \"scissors\" and c == \"scissors\") or (a == \"scissors\" and b == \"paper\" and c == \"paper\"):\r\n print(\"F\")\r\nelif (b == \"paper\" and a == \"rock\" and c == \"rock\") or (b == \"rock\" and a == \"scissors\" and c == \"scissors\") or (b == \"scissors\" and a == \"paper\" and c == \"paper\"):\r\n print(\"M\")\r\nelif (c == \"paper\" and b == \"rock\" and a == \"rock\") or (c == \"rock\" and b == \"scissors\" and a == \"scissors\") or (c == \"scissors\" and b == \"paper\" and a == \"paper\"):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"b = {'rock': 'scissors', 'paper': 'rock', 'scissors': 'paper'}\r\nf = input()\r\nm = input()\r\ns = input()\r\nif m == s and b[f] == m:\r\n print('F')\r\nelif f == s and b[m] == f:\r\n print('M')\r\nelif f == m and b[s] == f:\r\n print('S')\r\nelse:\r\n print('?')",
"a=str(input())\r\nb=str(input())\r\nc=str(input())\r\n\r\nd='M'\r\ne='S'\r\nf='F'\r\nif a=='rock':\r\n if b == 'rock':\r\n if c=='rock':\r\n print('?')\r\n elif c == 'paper':\r\n print('S')\r\n elif c == 'scissors':\r\n print('?')\r\n \r\n if b == 'paper':\r\n if c == 'rock':\r\n print('M')\r\n elif c == 'paper':\r\n print('?')\r\n elif c == 'scissors':\r\n print('?')\r\n\r\n if b=='scissors':\r\n if c == 'rock':\r\n print('?')\r\n elif c == 'paper':\r\n print('?')\r\n elif c == 'scissors':\r\n print('F')\r\n \r\n\r\nif a=='paper':\r\n if b == 'rock':\r\n if c=='rock':\r\n print('F')\r\n elif c == 'paper':\r\n print('?')\r\n elif c == 'scissors':\r\n print('?')\r\n \r\n if b == 'paper':\r\n if c == 'rock':\r\n print('?')\r\n elif c == 'paper':\r\n print('?')\r\n elif c == 'scissors':\r\n print('S')\r\n\r\n if b=='scissors':\r\n if c == 'rock':\r\n print('?')\r\n elif c == 'paper':\r\n print('M')\r\n elif c == 'scissors':\r\n print('?')\r\n \r\nif a=='scissors':\r\n if b == 'rock':\r\n if c=='rock':\r\n print('?')\r\n elif c == 'paper':\r\n print('?')\r\n elif c == 'scissors':\r\n print('M')\r\n\r\n if b == 'paper':\r\n if c == 'rock':\r\n print('?')\r\n elif c == 'paper':\r\n print('F')\r\n elif c == 'scissors':\r\n print('?')\r\n\r\n if b=='scissors':\r\n if c == 'rock':\r\n print('S')\r\n elif c == 'paper':\r\n print('?')\r\n elif c == 'scissors':\r\n print('?')\r\n\r\n \r\n",
"# import sys\r\n# sys.stdin = open(\"test.in\",\"r\")\r\n# sys.stdout = open(\"test.out\",\"w\")\r\nf=input()\r\nm=input()\r\ns=input()\r\nif f[0]=='r' and m[0]=='s' and s[0]=='s':\r\n\tprint('F')\r\nelif f[0]=='p' and m[0]=='r' and s[0]=='r':\r\n\tprint('F')\r\nelif f[0]=='s' and m[0]=='p' and s[0]=='p':\r\n\tprint('F')\r\nelif m[0]=='r' and f[0]=='s' and s[0]=='s':\r\n\tprint('M')\t\r\nelif m[0]=='p' and f[0]=='r' and s[0]=='r':\r\n\tprint('M')\r\nelif m[0]=='s' and f[0]=='p' and s[0]=='p':\t\r\n\tprint('M')\r\nelif s[0]=='r' and f[0]=='s' and m[0]=='s':\r\n\tprint('S')\t\r\nelif s[0]=='p' and f[0]=='r' and m[0]=='r':\t\r\n\tprint('S')\r\nelif s[0]=='s' and f[0]=='p' and m[0]=='p':\t\r\n\tprint('S')\r\nelse:\r\n\tprint('?')\t\r\n",
"d=input()\r\nm=input()\r\nw=input()\r\nr={}\r\nr['rock']='scissors'\r\nr['paper']='rock'\r\nr['scissors']='paper'\r\nif d==m and m==w or d!=m and m!=w and d!=w:\r\n print('?')\r\nelif m==r[d] and w==r[d]:\r\n print('F')\r\nelif d==r[m] and w==r[m]:\r\n print('M')\r\nelif d==r[w] and m==r[w]:\r\n print('S')\r\nelse:\r\n print('?')\r\n\r\n",
"def solve():\r\n names = ['F', 'M', 'S']\r\n gestures = [input(), input(), input()]\r\n if sorted(gestures) in [['paper', 'paper', 'scissors'], ['rock', 'scissors', 'scissors'], ['paper', 'rock', 'rock']]:\r\n for i in range(3):\r\n if gestures.count(gestures[i]) == 1:\r\n return names[i]\r\n return '?'\r\n\r\nprint(solve())",
"from sys import stdin,stdout\r\nfrom collections import defaultdict\r\ninput=stdin.readline\r\n#print=stdout.write\r\nfrom random import randint\r\nimport math\r\nimport sys \r\n#sys.setrecursionlimit(10**6)\r\n###-----------Code Begins----------##\r\n \r\nF = input().strip()\r\nM = input().strip()\r\nS = input().strip()\r\n\r\ndef checkwin(Curr, Other):\r\n if(Curr==\"rock\" and Other==\"scissors\"):\r\n return True\r\n if(Curr==\"scissors\" and Other==\"paper\"):\r\n return True\r\n if(Curr==\"paper\" and Other==\"rock\"):\r\n return True\r\n return False\r\n\r\nif(checkwin(F,M) and checkwin(F,S)):\r\n print(\"F\")\r\nelif(checkwin(S,M) and checkwin(S,F)):\r\n print(\"S\")\r\nelif(checkwin(M,F) and checkwin(M, S)):\r\n print(\"M\")\r\nelse:\r\n print(\"?\")",
"def winner(s1,s2):\r\n r, p, s = 'rock', 'paper', 'scissors'\r\n # if s1 == r and s2 == p or s1 == p and s2 == s or s1 == s and s2 == r:\r\n # return s2\r\n if s1 == r and s2 == s or s1 == p and s2 == r or s1 == s and s2 == p:\r\n return True\r\n\r\n\r\n\r\nf, m, s = input(), input(), input()\r\nif f != m and f != s and m == s and winner(f,m):\r\n print('F')\r\nelif m != f and m != s and f == s and winner(m,s):\r\n print('M')\r\nelif s != f and s != m and f == m and winner(s,f):\r\n print('S')\r\nelse:\r\n print('?')\r\n",
"f=input()\r\nm=input()\r\ns=input()\r\nif (f=='rock' and m==s=='scissors') or (f=='paper' and m==s=='rock') or (f=='scissors' and m==s=='paper'):\r\n print('F')\r\nelif (m=='rock' and f==s=='scissors') or (m=='paper' and f==s=='rock') or (m=='scissors' and f==s=='paper'):\r\n print('M')\r\nelif (s=='rock' and f==m=='scissors') or (s=='paper' and f==m=='rock') or (s=='scissors' and f==m=='paper'):\r\n print('S')\r\nelse:\r\n print('?')",
"t = \"\"\r\nfor i in range(3):\r\n s = input()\r\n t += s[0]\r\n# p = paper s = scissor r = rock\r\nif t == \"prr\" or t == \"spp\" or t == \"rss\":\r\n print('F')\r\n exit()\r\nif t == \"rpr\" or t == \"psp\" or t == \"srs\":\r\n print('M')\r\n exit()\r\nif t == \"rrp\" or t == \"pps\" or t == \"ssr\":\r\n print('S')\r\n exit()\r\nprint('?')",
"# a,b,c=map(int,input().split())\r\n# print (\"%d %d %d\" %(a,b,c))\r\n# print('{} {} {}'.format(a,b,c))\r\ndef win(a,b):\r\n if a==\"rock\" and b==\"scissors\": return 1\r\n elif a==\"scissors\" and b==\"paper\": return 1\r\n elif a==\"paper\" and b==\"rock\": return 1\r\n else: return 0\r\na=input()\r\nb=input()\r\nc=input()\r\nif win(a,b)==1 and win(a,c)==1: print(\"F\")\r\nelif win(b,a)==1 and win(b,c)==1: print(\"M\")\r\nelif win(c,a)==1 and win(c,b)==1: print(\"S\")\r\nelse: print(\"?\")",
"f, m, s = (input() for _ in range(3))\ndef beats(first, second, third):\n if second != third:\n return False\n if first == \"rock\" and second == \"scissors\":\n return True\n if first == \"scissors\" and second == \"paper\":\n return True\n if first == \"paper\" and second == \"rock\":\n return True\n return False\nres = \"F\" if beats(f, m, s) else \"M\" if beats(m, f, s) else \"S\" if beats(s, f, m) else \"?\"\nprint(res)\n",
"f=input()\r\nm=input()\r\ns=input()\r\nt=[f,m,s]\r\na=set()\r\nfor i in range(3):\r\n a.add(t[i])\r\nif len(a)==3 or len(a)==1:\r\n print('?')\r\nelse:\r\n if 'paper' in a and 'rock' in a :\r\n if t.count('paper')==1:\r\n for k in range(len(t)):\r\n if t[k]=='paper':\r\n if k==0:\r\n print('F')\r\n elif k==1:\r\n print('M')\r\n else:\r\n print('S')\r\n else:\r\n print('?')\r\n elif 'paper' in a and 'scissors' in a:\r\n if t.count('scissors')==1:\r\n for k in range(len(t)):\r\n if t[k]=='scissors':\r\n if k==0:\r\n print('F')\r\n elif k==1:\r\n print('M')\r\n else:\r\n print('S')\r\n else:\r\n print('?')\r\n elif 'scissors' in a and 'rock' in a:\r\n if t.count('rock')==1:\r\n for k in range(len(t)):\r\n if t[k]=='rock':\r\n if k==0:\r\n print('F') \r\n elif k==1:\r\n print('M')\r\n else:\r\n print('S')\r\n else:\r\n print('?')",
"import math\n\ndef is_first_beats_second(first,second):\n if first == 'rock' and second == 'paper':\n return False\n if first == 'paper' and second == 'scissors':\n return False\n if first == 'scissors' and second == 'rock':\n return False\n return True\n\n\ndef solve(f,m,s):\n if f == m and f == s and m == s :\n return '?'\n if f != m and f !=s and m!=s :\n return '?'\n if f == m:\n if is_first_beats_second(s,f):\n return 'S'\n if f == s:\n if is_first_beats_second(m,f):\n return 'M'\n if m == s:\n if is_first_beats_second(f,m):\n return 'F'\n return '?'\n\n \n\n \n \n \n\ndef main() :\n # n = int(input())\n # arr = list(map(int, input().split(' ')))\n arr = []\n for _ in range(3):\n arr.append(input())\n print(solve(*arr))\nmain()\n",
"# import sys \r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"out.out\",'w')\r\na=input()\r\nb=input()\r\nc=input()\r\nif a==b and b==c:\r\n\tprint(\"?\")\r\nelif a==b and b!=c:\r\n\tif (a==\"rock\" and c==\"paper\") or (a==\"scissors\" and c==\"rock\") or (a==\"paper\" and c==\"scissors\"):\r\n\t\tprint(\"S\")\r\n\telse:\r\n\t\tprint(\"?\")\t\r\nelif b==c and a!=b:\r\n\tif (b==\"rock\" and a==\"paper\") or (b==\"scissors\" and a==\"rock\") or (b==\"paper\" and a==\"scissors\"):\r\n\t\tprint(\"F\")\r\n\telse:\r\n\t\tprint(\"?\")\t\r\nelif c==a and b!=a:\r\n\tif (c==\"rock\" and b==\"paper\") or (c==\"scissors\" and b==\"rock\") or (c==\"paper\" and b==\"scissors\"):\r\n\t\tprint(\"M\")\r\n\telse:\r\n\t\tprint(\"?\")\t\r\nelif a!=b and b!=c and c!=a:\r\n\tprint(\"?\")\r\n\r\n",
"wins = {'s': 'p', 'p': 'r', 'r': 's'}\r\na = [input() for i in range(3)]\r\nfor i in range(3):\r\n if a.count(a[i]) == 1 and a.count(a[(i + 1) % 3]) == 2 and wins[a[i][0]] == a[(i + 1) % 3][0]:\r\n exit(print('FMS'[i]))\r\nprint('?')\r\n",
"import sys\n\na, b, c = input().strip(), input().strip(), input().strip()\n\ndef beats(x, y):\n if x == 'rock' and y == 'scissors':\n return True\n if x == 'scissors' and y == 'paper':\n return True\n if x == 'paper' and y == 'rock':\n return True\n return False\n\nif beats(a, b) and beats(a, c):\n print('F')\nelif beats(b, a) and beats(b, c):\n print('M')\nelif beats(c, a) and beats(c, b):\n print('S')\nelse:\n print('?')\n",
"F = input() \nM = input()\nS = input()\n\nif F == \"scissors\" and M == \"paper\" and S == \"paper\":\n\tprint (\"F\")\nelif F == \"paper\" and M == \"rock\" and S == \"rock\":\n\tprint (\"F\")\nelif F == \"rock\" and M == \"scissors\" and S == \"scissors\":\n\tprint (\"F\")\nelif M == \"scissors\" and F == \"paper\" and S == \"paper\":\n\tprint (\"M\")\nelif M == \"paper\" and F == \"rock\" and S == \"rock\":\n\tprint (\"M\")\nelif M == \"rock\" and F == \"scissors\" and S == \"scissors\":\n\tprint (\"M\")\nelif S == \"scissors\" and M == \"paper\" and F == \"paper\":\n\tprint (\"S\")\nelif S == \"paper\" and M == \"rock\" and F == \"rock\":\n\tprint (\"S\")\nelif S == \"rock\" and M == \"scissors\" and F == \"scissors\":\n\tprint (\"S\")\nelse:\n\tprint (\"?\")\n",
"F = input()\r\nM = input()\r\nS = input()\r\n\r\ngesture = {\r\n 'F': F,\r\n 'M': M,\r\n 'S': S\r\n}\r\n\r\ndef battle(p1, p2):\r\n if gesture[p1] == 'rock' and gesture[p2] == 'scissors':\r\n return p1\r\n elif gesture[p1] == 'scissors' and gesture[p2] == 'rock':\r\n return p2\r\n elif gesture[p1] == 'rock' and gesture[p2] == 'paper':\r\n return p2\r\n elif gesture[p1] == 'paper' and gesture[p2] == 'rock':\r\n return p1\r\n elif gesture[p1] == 'paper' and gesture[p2] == 'scissors':\r\n return p2\r\n elif gesture[p1] == 'scissors' and gesture[p2] == 'paper':\r\n return p1\r\n else:\r\n return '?'\r\n\r\nres = [battle('F', 'M'), battle('F', 'S'), battle('S', 'M')]\r\nif res.count('F') == 2:\r\n print('F')\r\nelif res.count('M') == 2:\r\n print('M')\r\nelif res.count('S') == 2:\r\n print('S')\r\nelse:\r\n print('?')",
"a = [\"rock\",\"paper\",\"scissors\"]\nb = [\"paper\",\"scissors\",\"rock\"]\nc = []\nd = [\"F\",\"M\",\"S\"]\ne =[]\nfor x in range(3):\n\tc.append(input())\nfor x in range(len(c)):\n\tk = a.index(c[x])\n\tif b[k] in c:\n\t\te.append(0)\n\telse:\n\t\te.append(1)\nif e.count(1) != 1:\n\tprint(\"?\")\nelse:\n\tprint(d[e.index(1)])",
"games = {}\r\ngames['F'] = input()\r\ngames['M'] = input()\r\ngames['S'] = input()\r\nscores = {'F': 0, 'M': 0, 'S': 0}\r\n\r\n\r\ndef judging(x, y):\r\n if games[x] == games[y]:\r\n pass\r\n elif (games[x] == 'rock' and games[y] == 'scissors') or (games[x] == 'scissors' and games[y] == 'paper') or (\r\n games[x] == 'paper' and games[y] == 'rock'):\r\n scores[x] += 1\r\n elif (games[y] == 'rock' and games[x] == 'scissors') or (games[y] == 'scissors' and games[x] == 'paper') or (\r\n games[y] == 'paper' and games[x] == 'rock'):\r\n scores[y] += 1\r\n\r\n\r\njudging('F', 'M')\r\njudging('F', 'S')\r\njudging('M', 'S')\r\nl = list(scores.values())\r\n\r\n# 本质是一个迭代器\r\na = max(l)\r\nif l.count(a) >= 2:\r\n print('?')\r\nelse:\r\n for i in scores.keys():\r\n if scores[i] == max(scores.values()):\r\n print(i)\r\n else:\r\n pass",
"first = input()\r\nsecond = input()\r\nthird = input()\r\ngame = [first, second, third]\r\n\r\n# bumaga > kameni\r\n# nojnitz > bumaga\r\n# kameni > nojnitz\r\n\r\nnojnitz = game.count('scissors')\r\nbumaga = game.count('paper')\r\nkameni = game.count('rock')\r\n\r\nif nojnitz == 1 and bumaga == 2:\r\n winner = 'scissors'\r\nelif kameni == 1 and nojnitz == 2:\r\n winner = 'rock'\r\nelif bumaga == 1 and kameni == 2:\r\n winner = 'paper'\r\nelse:\r\n print('?')\r\n exit()\r\n\r\nletter = game.index(winner)\r\nif letter == 0:\r\n print('F')\r\nelif letter == 1:\r\n print('M')\r\nelif letter == 2:\r\n print('S')",
"p = [input() for i in range(3)]\r\n\r\nif p[0]=='paper' and p[1]=='rock' and p[2]=='rock':\r\n print(\"F\")\r\nelif p[1]=='paper' and p[0]=='rock' and p[2]=='rock':\r\n print(\"M\")\r\nelif p[2]=='paper' and p[1]=='rock' and p[0]=='rock':\r\n print(\"S\")\r\n\r\nelif p[0]=='scissors' and p[1]=='paper' and p[2]=='paper':\r\n print(\"F\")\r\nelif p[1]=='scissors' and p[0]=='paper' and p[2]=='paper':\r\n print(\"M\")\r\nelif p[2]=='scissors' and p[1]=='paper' and p[0]=='paper':\r\n print(\"S\")\r\n\r\nelif p[0]=='rock' and p[1]=='scissors' and p[2]=='scissors':\r\n print(\"F\")\r\nelif p[1]=='rock' and p[0]=='scissors' and p[2]=='scissors':\r\n print(\"M\")\r\nelif p[2]=='rock' and p[1]=='scissors' and p[0]=='scissors':\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n",
"result = [\"scissors\", \"rock\", \"paper\"]\r\nF = input()\r\nM = input()\r\nS = input()\r\nif M == result[(result.index(F) + 1) % 3]:\r\n if S == result[result.index(F)]:\r\n print(\"M\")\r\n else:\r\n print(\"?\")\r\nelif M == result[result.index(F)]:\r\n if S == result[(result.index(F) + 1) % 3]:\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\nelse:\r\n if S == result[(result.index(F) - 1) % 3]:\r\n print(\"F\")\r\n else:\r\n print(\"?\")\r\n",
"def fn(a,b):\r\n\tif a==\"rock\" and b==\"scissors\":\r\n\t\treturn True\r\n\telif a==\"scissors\" and b==\"paper\":\r\n\t\treturn True\r\n\telif a==\"paper\"and b==\"rock\":\r\n\t\treturn True\r\n\treturn False\r\n\r\nf=input()\r\nm=input()\r\ns=input()\r\nif fn(f,m) and fn(f,s):\r\n\tprint(\"F\")\r\nelif fn(m,f) and fn(m,s):\r\n\tprint(\"M\")\r\nelif fn(s,m) and fn(s,f):\r\n\tprint(\"S\")\r\nelse:\r\n\tprint(\"?\")",
"def output(i):\n if (i == 0):\n print('F')\n elif (i == 1):\n print('M')\n elif (i == 2):\n print('S')\n else:\n print(\"Winner is not in first 3 people\")\n\ndef beats(a, b):\n if a[0] == 'p' and b[0] == 'r':\n return True\n elif a[0] == 'r' and b[0] == 's':\n return True\n elif a[0] == 's' and b[0] == 'p':\n return True\n return False\n\n# Read in data\nN = 3\ngestures = []\nfor i in range(N):\n gestures.append(input())\n\n# Find the only potential winner\nbest_so_far = gestures[0]\nfor i in range(1, N):\n if beats(best_so_far, gestures[i]):\n continue\n elif beats(gestures[i], best_so_far):\n best_so_far = gestures[i]\n else:\n assert(best_so_far == gestures[i])\n\n# Check if he IS a winner\nhow_many_it_beats = 0\nfor i in range(0, N):\n if beats(best_so_far, gestures[i]):\n how_many_it_beats += 1\n\n# If he's a winner, find his index\nif how_many_it_beats == N - 1:\n for i in range(N):\n if best_so_far == gestures[i]:\n output(i)\nelse:\n print(\"?\")",
"# Rock-paper-scissors\ndef wins(a, b ,c):\n if a == 'paper' and b == 'rock' and c == 'rock':\n return True\n elif a == 'rock' and b == 'scissors' and c == 'scissors':\n return True\n elif a == 'scissors' and b == 'paper' and c == 'paper':\n return True\n else:\n return False\nfydor = input()\nmatroskin = input()\nsharic = input()\nif wins(fydor,matroskin,sharic):\n print('F')\nelif wins(matroskin,fydor,sharic):\n print('M')\nelif wins(sharic,fydor,matroskin):\n print('S')\nelse:\n print('?')\n",
"R=lambda:map(int,input().split())\r\nf=input()\r\nm=input()\r\ns=input()\r\nl=[[f,'F'],[m,'M'],[s,'S']]\r\nl.sort()\r\nif (l[0][0],l[1][0],l[2][0])==('paper','rock','rock'):\r\n print(l[0][1])\r\nelif (l[0][0],l[1][0],l[2][0])==('paper','paper','scissors'):\r\n print(l[2][1])\r\nelif (l[0][0],l[1][0],l[2][0])==('rock','scissors','scissors'):\r\n print(l[0][1])\r\nelse:\r\n print('?')",
"f=input()\r\nm=input()\r\nsh=input()\r\nkam=\"rock\"\r\nnoj=\"scissors\"\r\nbum=\"paper\"\r\nans=\"?\"\r\nif f==kam and m==noj and sh==noj:\r\n ans=\"F\"\r\nelif f==noj and m==bum and sh==bum:\r\n ans=\"F\"\r\nelif f==bum and m==kam and sh==kam:\r\n ans=\"F\"\r\nif m==kam and f==noj and sh==noj:\r\n ans=\"M\"\r\nelif m==noj and f==bum and sh==bum:\r\n ans=\"M\"\r\nelif m==bum and f==kam and sh==kam:\r\n ans=\"M\"\r\nif sh==kam and m==noj and f==noj:\r\n ans=\"S\"\r\nelif sh==noj and m==bum and f==bum:\r\n ans=\"S\"\r\nelif sh==bum and m==kam and f==kam:\r\n ans=\"S\"\r\nprint(ans)\r\n",
"a = input(\"\")\nb = input(\"\")\nc = input(\"\")\nif a == 'rock' and b == c == 'scissors':\n print(\"F\")\nelif a == 'scissors' and b == c == 'paper':\n print(\"F\")\nelif a == 'paper' and b == c == 'rock':\n print(\"F\")\nelif b == 'rock' and a == c == 'scissors':\n print(\"M\")\nelif b == 'scissors' and a == c == 'paper':\n print(\"M\")\nelif b == 'paper' and a == c == 'rock':\n print(\"M\")\nelif c == 'rock' and b == a == 'scissors':\n print(\"S\")\nelif c == 'scissors' and b == a == 'paper':\n print(\"S\")\nelif c == 'paper' and b == a == 'rock':\n print(\"S\")\nelse:\n print(\"?\")",
"f = input()\nm = input()\ns = input()\n\nl = [f, m, s]\ns = set(l)\n\nif len(s) == 1 or len(s) == 3: answer = '?'\nelse:\n m1, m2 = list(s)\n if (m1 == 'paper' and m2 == 'rock') or (m1 == 'rock' and m2 == 'paper') : winner = 'paper'\n elif (m1 == 'rock' and m2 == 'scissors') or (m1 == 'scissors' and m2 == 'rock'): winner = 'rock'\n elif (m1 == 'scissors' and m2 == 'paper') or (m1 == 'paper' and m2 == 'scissors'): winner = 'scissors'\n\n if l.count(winner) > 1: answer = '?'\n else:\n winner_index = l.index(winner)\n answer = 'F' if winner_index == 0 else 'M' if winner_index == 1 else 'S'\nprint(answer)",
"def find_winner(gestures):\n possible_wins = [\n [\"rock\", \"scissors\", \"scissors\"],\n [\"scissors\", \"paper\", \"paper\"],\n [\"paper\", \"rock\", \"rock\"]\n ]\n\n winner = '?'\n\n for i in range(3):\n initial_gesture = gestures\n person = initial_gesture[i]\n initial_gesture.pop(i)\n initial_gesture.insert(0, person)\n if initial_gesture in possible_wins:\n if i == 0:\n winner = 'F'\n elif i == 1:\n winner = 'M'\n elif i == 2:\n winner = 'S'\n\n print(winner)\n\ngestures = [input() for _ in range(3)]\nfind_winner(gestures)",
"import sys\r\nimport math\r\nimport bisect\r\nimport itertools\r\nimport random\r\n\r\ndef query(a, b):\r\n if a == 'scissors' and b == 'paper':\r\n return True\r\n if a == 'paper' and b == 'rock':\r\n return True\r\n if a == 'rock' and b == 'scissors':\r\n return True\r\n return False\r\n\r\ndef main():\r\n A = []\r\n for i in range(3):\r\n A.append(input())\r\n if query(A[0], A[1]) and query(A[0], A[2]):\r\n print('F')\r\n elif query(A[1], A[0]) and query(A[1], A[2]):\r\n print('M')\r\n elif query(A[2], A[0]) and query(A[2], A[1]):\r\n print('S')\r\n else:\r\n print('?')\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"a1=input()\r\na2=input()\r\na3=input()\r\na=['rock','paper','scissors']\r\nif (a1==a[0] and a2==a3==a[2]) or (a1==a[1] and a2==a3==a[0]) or (a1==a[2] and a2==a3==a[1]):\r\n print('F')\r\nelif (a2==a[0] and a1==a3==a[2]) or (a2==a[1] and a1==a3==a[0]) or (a2==a[2] and a1==a3==a[1]):\r\n print('M')\r\nelif (a3==a[0] and a2==a1==a[2]) or (a3==a[1] and a2==a1==a[0]) or (a3==a[2] and a2==a1==a[1]):\r\n print('S')\r\nelse:\r\n print('?')\r\n",
"from collections import Counter\r\nf = input()\r\nm = input()\r\ns = input()\r\ndam = {\r\n \"rock\": \"paper\",\r\n \"paper\": \"scissors\",\r\n \"scissors\": \"rock\"\r\n }\r\n\r\nif f != m and m != s and f != s:\r\n print(\"?\")\r\nelse:\r\n choices = [f, m, s]\r\n count = Counter(choices)\r\n if 3 in count.values():\r\n print(\"?\")\r\n else:\r\n for i in range(len(choices)):\r\n if count[choices[i]] == 1:\r\n one = choices[i]\r\n win = i\r\n else:\r\n two = choices[i]\r\n \r\n if dam[two] == one:\r\n ans = [\"F\", \"M\", \"S\"]\r\n print(ans[win])\r\n else:\r\n print(\"?\")\r\n \r\n \r\n ",
"s1 = str(input())\r\ns2 = str(input())\r\ns3 = str(input())\r\n\r\nif (s1 == \"rock\" and s2 == \"scissors\" and s3 == \"scissors\") or (s1 == \"scissors\" and s2 == \"paper\" and s3 == \"paper\") or (s1 == \"paper\" and s2 == \"rock\" and s3 == \"rock\"):\r\n print(\"F\")\r\nelif (s2 == \"rock\" and s1 == \"scissors\" and s3 == \"scissors\") or (s2 == \"scissors\" and s1 == \"paper\" and s3 == \"paper\") or (s2 == \"paper\" and s1 == \"rock\" and s3 == \"rock\"):\r\n print(\"M\")\r\nelif (s3 == \"rock\" and s2 == \"scissors\" and s1 == \"scissors\") or (s3 == \"scissors\" and s2 == \"paper\" and s1 == \"paper\") or (s3 == \"paper\" and s2 == \"rock\" and s1 == \"rock\"):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n",
"def func():\r\n f = input()\r\n m = input()\r\n s = input()\r\n test = {'F':f, 'M':m, 'S':s}\r\n r = 'rock'\r\n p = 'paper'\r\n sc = 'scissors'\r\n rn = 0\r\n pn = 0\r\n sn = 0\r\n\r\n if (f == m and f == s and m == s) or (f != m and f != s and m != s):\r\n return print('?')\r\n\r\n for i in test.values():\r\n if i == r:\r\n rn += 1\r\n elif i == p:\r\n pn += 1\r\n else:\r\n sn += 1\r\n\r\n if rn == 2 and sn == 1 or sn == 2 and pn == 1 or pn == 2 and rn == 1:\r\n return print('?')\r\n else:\r\n if test['M'] == test['F']:\r\n print('S')\r\n elif test['F'] == test['S']:\r\n print('M')\r\n else:\r\n print('F')\r\n\r\nfunc()\r\n",
"f = input()\r\nm = input()\r\ns = input()\r\nli = [f,m,s]\r\nli1 = [\"F\",\"M\",\"S\"]\r\nif li.count(\"rock\") == 1 and li.count(\"scissors\") == 2:\r\n print(li1[li.index(\"rock\")])\r\nelif li.count(\"scissors\") == 1 and li.count(\"paper\") == 2:\r\n print(li1[li.index(\"scissors\")])\r\nelif li.count(\"paper\") == 1 and li.count(\"rock\") == 2:\r\n print(li1[li.index(\"paper\")])\r\nelse:\r\n print(\"?\")\r\n",
"f = input()\r\nm = input()\r\ns = input()\r\n\r\ndef win(x, y):\r\n return (x == 'rock' and y == 'scissors') or (x == 'scissors' and y == 'paper') or (x == 'paper' and y == 'rock')\r\n\r\nif win(f, m) and win(f, s):\r\n print(\"F\")\r\nelif win(m, f) and win(m, s):\r\n print(\"M\")\r\nelif win(s, f) and win(s, m):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"f=input()\r\nm=input()\r\ns=input()\r\nif(f!=m and m!=s and f!=s):\r\n print('?')\r\nelif(f==m and m==s and s==f):\r\n print('?')\r\nelif((f=='rock' and m=='scissors' and s=='scissors') or (m=='rock' and f=='scissors' and s=='scissors') or (s=='rock' and m=='scissors' and f=='scissors')):\r\n if(f=='rock' and m=='scissors' and s=='scissors'):\r\n print('F')\r\n elif(m=='rock' and f=='scissors' and s=='scissors'):\r\n print('M')\r\n else:\r\n print('S')\r\nelif((f=='paper' and m=='rock' and s=='rock') or (m=='paper' and f=='rock' and s=='rock') or (s=='paper' and m=='rock' and f=='rock')):\r\n if(f=='paper' and m=='rock' and s=='rock'):\r\n print('F')\r\n elif(m=='paper' and f=='rock' and s=='rock'):\r\n print('M')\r\n else:\r\n print('S')\r\nelif((f=='scissors' and m=='paper' and s=='paper') or (m=='scissors' and f=='paper' and s=='paper') or (s=='scissors' and m=='paper' and f=='paper')):\r\n if(f=='scissors' and m=='paper' and s=='paper'):\r\n print('F')\r\n elif(m=='scissors' and f=='paper' and s=='paper'):\r\n print('M')\r\n else:\r\n print('S')\r\nelse:\r\n print('?')",
"import sys\r\nF = sys.stdin.readline().strip()\r\nM = sys.stdin.readline().strip()\r\nS = sys.stdin.readline().strip()\r\n\r\nfor i in range (0, 3):\r\n x = [\"rock\", \"paper\", \"scissors\"]\r\n if F == x[i]:\r\n F = i \r\n if M == x[i]:\r\n M = i \r\n if S == x[i]:\r\n S = i \r\nif (F+M+S) % 3 != 1:\r\n print(\"?\")\r\nelse:\r\n if (F - M + 3) % 3 == 1:\r\n print(\"F\")\r\n if (M - S + 3) % 3 == 1:\r\n print(\"M\")\r\n if (S - F + 3) % 3 == 1:\r\n print(\"S\")",
"F, M, S = input(), input(), input()\r\nif len({F, M, S}) != 2:\r\n print(\"?\")\r\nelse:\r\n lst = [F, M, S]\r\n for x in [(\"rock\",\"scissors\"), (\"scissors\", \"paper\"), (\"paper\", \"rock\")]:\r\n if lst.count(x[0]) == 1 and lst.count(x[1]) == 2:\r\n print(\"FMS\"[lst.index(x[0])])\r\n break\r\n else:\r\n print(\"?\")",
"def winner(s1, s2):\r\n r, p, s = 'rock', 'paper', 'scissors'\r\n if s1 == r and s2 == s or s1 == p and s2 == r or s1 == s and s2 == p:\r\n return True\r\n\r\n\r\ndef win(s1, s2, s3):\r\n if s1 != s2 and s1 != s3 and s2 == s3:\r\n return True\r\n\r\n\r\nf, m, s = input(), input(), input()\r\n\r\n\r\nif win(f, m, s) and winner(f, m):\r\n print('F')\r\nelif win(m, f, s) and winner(m, f):\r\n print('M')\r\nelif win(s, m, f) and winner(s, m):\r\n print('S')\r\nelse:\r\n print('?')\r\n",
"l = []\nfor i in range(3):\n l.append(input())\nd = {\"rock\":\"paper\", \"paper\":\"scissors\", \"scissors\":\"rock\"}\n\nif l[1] == l[2] and l[0] == d[l[1]]:\n print(\"F\")\nelif l[0] == l[2] and l[1] == d[l[0]]:\n print(\"M\")\nelif l[0] == l[1] and l[2] == d[l[1]]:\n print(\"S\")\nelse:\n print(\"?\")\n \t\t \t\t \t \t\t \t \t\t \t \t\t \t",
"def game(a,b):\r\n if (a=='rock' and b=='scissors') or (a=='scissors' and b=='paper') or (a=='paper' and b=='rock'):\r\n return 1\r\n else:\r\n return 0\r\n\r\nm=[] \r\nfor i in range(3):\r\n nn=input()\r\n m.append(nn)\r\nnam=list(['F','M','S'])\r\np=[]\r\nif m[0]==m[1]:\r\n p.append(1)\r\n b=m[0]\r\n a=m[2]\r\n win=2\r\nelse:\r\n p.append(0)\r\nif m[1]==m[2]:\r\n p.append(1)\r\n b=m[1]\r\n a=m[0]\r\n win=0\r\nelse:\r\n p.append(0) \r\nif m[2]==m[0]:\r\n p.append(1)\r\n b=m[2]\r\n a=m[1]\r\n win=1\r\nelse:\r\n p.append(0)\r\nif p[0]+p[1]+p[2]==1 and game(a,b)==1:\r\n print(nam[win])\r\nelse:\r\n print(\"?\")",
"\r\nl = []\r\nfor _ in range(3):\r\n\tl.append(input())\r\n\r\nlp = ['F', 'M', 'S']\r\nif l.count('rock') == 1 and l.count('scissors') == 2:\r\n\tprint(lp[l.index('rock')])\r\nelif l.count('paper') == 1 and l.count('rock') == 2:\r\n\tprint(lp[l.index('paper')])\r\nelif l.count('scissors') == 1 and l.count('paper') == 2:\r\n\tprint(lp[l.index('scissors')])\r\nelse:\r\n\tprint('?')",
"w = {\r\n ('rock', 'scissors'): True,\r\n ('scissors', 'rock'): False,\r\n ('paper', 'rock'): True,\r\n ('rock', 'paper'): False,\r\n ('scissors', 'paper'): True,\r\n ('paper', 'scissors'): False \r\n}\r\nf = input()\r\nm = input()\r\ns = input()\r\nif (f, m) in w and w[(f, m)] and (f, s) in w and w[(f, s)]:\r\n print('F')\r\nelif (m, f) in w and w[(m, f)] and (m, s) in w and w[(m, s)]:\r\n print('M')\r\nelif (s, m) in w and w[(s, m)] and (s, f) in w and w[(s, f)]:\r\n print('S')\r\nelse:\r\n print('?')\r\n",
"I = lambda: int(input())\r\nIL = lambda: list(map(int, input().split()))\r\n\r\nL = [input()[0] for i in '123']\r\ngt = {'r': 'rp', 'p': 'ps', 's': 'sr'}\r\n\r\nprint('F' if L[1] not in gt[L[0]] and L[2] not in gt[L[0]] else\r\n 'M' if L[0] not in gt[L[1]] and L[2] not in gt[L[1]] else\r\n 'S' if L[0] not in gt[L[2]] and L[1] not in gt[L[2]] else\r\n '?')",
"\r\na = [''] * 3\r\na[0] = input()\r\na[1] = input()\r\na[2] = input()\r\nres = '?'\r\nb = set(a)\r\nb = list(b)\r\n\r\nname = ['F','M','S']\r\nre = []\r\nif len(b) == 2:\r\n if b[0] == 'rock' and b[1] == 'scissors':\r\n win = b[0]\r\n if b[0] == 'paper' and b[1] == 'rock':\r\n win = b[0]\r\n if b[0] == 'scissors' and b[1] == 'paper':\r\n win = b[0]\r\n t = b[0]\r\n b[0] = b[1]\r\n b[1] = t\r\n if b[0] == 'rock' and b[1] == 'scissors':\r\n win = b[0]\r\n if b[0] == 'paper' and b[1] == 'rock':\r\n win = b[0]\r\n if b[0] == 'scissors' and b[1] == 'paper':\r\n win = b[0]\r\n for i in range(3):\r\n if a[i] == win:\r\n re.append(name[i])\r\nif len(re) ==1:\r\n res = re[0]\r\nprint(res)\r\n",
"import sys\r\nimport math\r\n\r\n#to read string\r\nget_string = lambda: sys.stdin.readline().strip()\r\n#to read list of integers\r\nget_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )\r\n#to read non spaced string and elements are integers to list of int\r\nget_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))\r\n#to read non spaced string and elements are character to list of character\r\nget_charList_from_str = lambda: list(sys.stdin.readline().strip())\r\n#get word sepetared list of character\r\nget_char_list = lambda: sys.stdin.readline().strip().split() \r\n#to read integers\r\nget_int = lambda: int(sys.stdin.readline())\r\n#to print faster\r\npt = lambda x: sys.stdout.write(str(x))\r\n\r\n#--------------------------------WhiteHat010--------------------------------#\r\nf = get_string()\r\nm = get_string()\r\ns = get_string()\r\n\r\nwins = { 'scissors':'paper', 'rock':'scissors', 'paper':'rock' }\r\n\r\n#winner only possible if two of one kind and third of another kind\r\nif f == m and f == wins[s]:\r\n print('S')\r\nelif s == m and s == wins[f]:\r\n print('F')\r\nelif f == s and f == wins[m]:\r\n print('M')\r\nelse:\r\n print('?')",
"fydor = input()\r\nmatroskin = input()\r\nsharic = input()\r\n\r\nif fydor == 'rock' and matroskin == \"scissors\" and sharic == 'scissors' or fydor == 'scissors' and matroskin == \"paper\" and sharic == 'paper' or fydor == 'paper' and matroskin == \"rock\" and sharic == 'rock':\r\n print('F')\r\nelif matroskin == 'rock' and fydor == \"scissors\" and sharic == 'scissors' or matroskin == 'scissors' and fydor == \"paper\" and sharic == 'paper' or matroskin == 'paper' and fydor == \"rock\" and sharic == 'rock':\r\n print('M')\r\nelif sharic == 'rock' and fydor == \"scissors\" and matroskin == 'scissors' or sharic == 'scissors' and fydor == \"paper\" and matroskin == 'paper' or sharic == 'paper' and fydor == \"rock\" and matroskin == 'rock':\r\n print('S')\r\nelse:\r\n print('?')",
"a = input()\r\nb = input()\r\nc = input()\r\n\r\nwho = [\r\n\t(\"paper\", \"rock\"), # who win, who lose\r\n\t(\"scissors\", \"paper\"),\r\n\t(\"rock\", \"scissors\")\r\n]\r\n\r\nif (a == b and a == c and b == c) or (a != b and a != c and b != c):\r\n\tprint(\"?\")\r\nelse:\r\n\tif a == b:\r\n\t\tif (a, c) in who:\r\n\t\t\tprint(\"?\")\r\n\t\telse:\r\n\t\t\tprint(\"S\")\r\n\telif a == c:\r\n\t\tif (a, b) in who:\r\n\t\t\tprint(\"?\")\r\n\t\telse:\r\n\t\t\tprint(\"M\")\r\n\telif b == c:\r\n\t\tif (b, a) in who:\r\n\t\t\tprint(\"?\")\r\n\t\telse:\r\n\t\t\tprint(\"F\")",
"i = [input()[0] for _ in '___']\r\ntry:\r\n print('FMS'[i.index('prs'[['prr','rss','pps'].index(''.join(sorted(i)))])])\r\nexcept ValueError:\r\n print('?')",
"F,M,S=input(),input(),input()\r\nB={\"rock\":\"paper\",\"paper\":\"scissors\",\"scissors\":\"rock\"}\r\nif(F==M and S==B[F]):\r\n print(\"S\")\r\nelif(F==S and M==B[F]):\r\n print(\"M\")\r\nelif(S==M and F==B[S]):\r\n print(\"F\")\r\nelse:\r\n print(\"?\")\r\n",
"game = 'rsp'\r\n\r\np1 = game.index(input().strip()[0])\r\np2 = game.index(input().strip()[0])\r\np3 = game.index(input().strip()[0])\r\n\r\ndef cmp(p1, p2):\r\n if (p1 == 0 and p2 == 1) or (p1 == 1 and p2 == 2) or (p1 == 2 and p2 == 0):\r\n return 1\r\n elif p1 == p2:\r\n return 0\r\n return -1\r\n\r\ndef p(i):\r\n return 'FMS'[i-1]\r\n\r\np1p2 = cmp(p1, p2)\r\np2p3 = cmp(p2, p3)\r\np1p3 = cmp(p1, p3)\r\n\r\nif p1p2 == 0 and p1p3 < 0:\r\n print(p(3))\r\nelif p1p3 == 0 and p1p2 < 0:\r\n print(p(2))\r\nelif p2p3 == 0 and p1p2 > 0:\r\n print(p(1))\r\nelse:\r\n print('?')\r\nexit()\r\n\r\n\r\n# print(p1, p2, p3)\r\n# print(p1p2, p2p3, p1p3)\r\nif p1p2 < 0:\r\n if p2p3 < 0:\r\n print(p(3))\r\n elif p2p3 > 0:\r\n print(p(2))\r\n else: # 1 < 2 == 3\r\n print('?')\r\nelif p1p2 > 0:\r\n if p1p3 > 0:\r\n print(p(1))\r\n elif p1p3 < 0:\r\n print(p(3))\r\n else: # 2 < 1 == 3\r\n print('?')\r\nelse: # 1 == 2\r\n if p1p3 < 0:\r\n print(p(3))\r\n else: # 2 == 1 == 3 or 3 < 2 == 1\r\n print('?')\r\n\r\n\r\n",
"s1=input();s2=input();s3=input()\r\nif (s1[0]=='r'and s2[0]=='s'and s3[0]=='s')or(s1[0]=='s'and s2[0]=='p'and s3[0]=='p')or(s1[0]=='p'and s2[0]=='r'and s3[0]=='r'):\r\n print('F')\r\nelif (s2[0]=='r'and s1[0]=='s'and s3[0]=='s')or(s2[0]=='s'and s1[0]=='p'and s3[0]=='p')or(s2[0]=='p'and s1[0]=='r'and s3[0]=='r'):\r\n print('M')\r\nelif (s3[0]=='r'and s1[0]=='s'and s2[0]=='s')or(s3[0]=='s'and s1[0]=='p'and s2[0]=='p')or(s3[0]=='p'and s1[0]=='r'and s2[0]=='r'):\r\n print('S')\r\nelse:\r\n print('?')\r\n",
"F=input().strip()\r\nM=input().strip()\r\nS=input().strip()\r\n\r\n# scissors and paper\r\nif(F=='scissors' and M=='paper' and S=='paper'):\r\n print('F')\r\nelif(F=='paper' and M=='scissors' and S=='paper'):\r\n print('M')\r\nelif(F=='paper' and M=='paper' and S=='scissors'):\r\n print('S')\r\n\r\n\r\n#rock and paper\r\nelif(F=='paper' and M=='rock' and S=='rock'):\r\n print('F')\r\nelif(F=='rock' and M=='paper' and S=='rock'):\r\n print('M')\r\nelif(F=='rock' and M=='rock' and S=='paper'):\r\n print('S')\r\n\r\n#rock and scissors\r\nelif(F=='rock' and M=='scissors' and S=='scissors'):\r\n print('F')\r\nelif(F=='scissors' and M=='rock' and S=='scissors'):\r\n print('M')\r\nelif(F=='scissors' and M=='scissors' and S=='rock'):\r\n print('S')\r\n\r\n#else\r\nelse:\r\n print('?')",
"names=['F','M','S']\r\nf = input()\r\nm = input()\r\ns = input()\r\nx = [f,m,s]\r\n\r\nx_sort = sorted(x)\r\nans = '?'\r\nif x_sort == ['paper','rock','rock']:\r\n ans = names[x.index('paper')]\r\nelif x_sort == ['paper', 'paper', 'scissors']:\r\n ans = names[x.index('scissors')]\r\nelif x_sort == ['rock', 'scissors', 'scissors']:\r\n ans = names[x.index('rock')]\r\nprint(ans)\r\n",
"uncle_fyodor = input()\nmatroskin = input()\nsharic = input()\n\ngames = [uncle_fyodor, matroskin, sharic]\nstands_for = ['F', 'M', 'S']\n\nif games.count('scissors') == 1 and games.count('paper') == 2:\n print(stands_for[games.index('scissors')])\nelif games.count('paper') == 1 and games.count('rock') == 2:\n print(stands_for[games.index('paper')])\nelif games.count('rock') == 1 and games.count('scissors') == 2:\n print(stands_for[games.index('rock')])\nelse:\n print('?')",
"x=input()\r\ny=input()\r\nz=input()\r\n\r\nif(x==y and y==z):\r\n print('?')\r\nelif(x!=y and y!=z and x!=z):\r\n print('?')\r\nelse:\r\n if((x==y and x=='rock' and z=='paper')or(x==y and x=='paper' and z=='scissors')or(x==y and x=='scissors' and z=='rock')):\r\n print('S')\r\n elif((z==y and z=='rock' and x=='paper')or(z==y and z=='paper' and x=='scissors')or(z==y and z=='scissors' and x=='rock')):\r\n print('F')\r\n elif((x==z and x=='rock' and y=='paper')or(x==z and x=='paper' and y=='scissors')or(x==z and x=='scissors' and y=='rock')):\r\n print('M')\r\n else:\r\n print('?')\r\n",
"f = input()\r\nm = input()\r\ns = input()\r\nd = {'scissors': 'paper', 'rock': 'scissors', 'paper': 'rock'}\r\n\r\nif d[f] == m and d[f] == s:\r\n print(\"F\")\r\nelif d[m] == f and d[m] == s:\r\n print(\"M\")\r\nelif d[s] == f and d[s] == m:\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n",
"F = input()\nM = input()\nS = input()\n\nplayers = ('F', 'M', 'S')\ngame = (F, M, S)\n\ndef search_tuple(items, tpl):\n for item in tpl:\n if not item in items:\n return tpl.index(item)\n return 3\n\n\ndef how_many(item, tpl):\n answer = 0\n for i in tpl:\n if i == item:\n answer += 1\n return answer\n\ndef main(game):\n answers = ('paper', 'scissors', 'rock')\n absent = search_tuple(game, answers)\n if absent == 3:\n return '?'\n number = how_many(answers[absent - 1], game)\n if number == 1:\n return game.index(answers[absent - 1])\n else:\n return '?'\n\nanswer_0 = main(game)\n\nif answer_0 == '?':\n print('?')\nelse:\n print(players[answer_0])\n\n\n\n",
"def findx(x):\r\n if tf == x:print(\"F\")\r\n elif tm == x:print(\"M\")\r\n else:print(\"S\")\r\ndef gt(s):\r\n if s == \"rock\": return 1\r\n if s == \"scissors\": return 3\r\n if s == \"paper\": return 9\r\nf = input()\r\nm = input()\r\ns = input()\r\ntf = gt(f)\r\ntm = gt(m)\r\nts = gt(s)\r\nsum = tf + tm + ts\r\nif sum == 7:findx(1)\r\nelif sum == 21:findx(3)\r\nelif sum == 11:findx(9)\r\nelse:print(\"?\")\r\n",
"F_gesture = input()\r\nM_gesture = input()\r\nS_gesture = input()\r\n\r\nif F_gesture == M_gesture:\r\n if F_gesture == \"scissors\" and S_gesture == \"rock\":\r\n print(\"S\")\r\n elif F_gesture == \"rock\" and S_gesture == \"paper\":\r\n print(\"S\")\r\n elif F_gesture == \"paper\" and S_gesture == \"scissors\":\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\nelif M_gesture == S_gesture:\r\n if M_gesture == \"scissors\" and F_gesture == \"rock\":\r\n print(\"F\")\r\n elif M_gesture == \"rock\" and F_gesture == \"paper\":\r\n print(\"F\")\r\n elif M_gesture == \"paper\" and F_gesture == \"scissors\":\r\n print(\"F\")\r\n else:\r\n print(\"?\")\r\nelif F_gesture == S_gesture:\r\n if F_gesture == \"scissors\" and M_gesture == \"rock\":\r\n print(\"M\")\r\n elif F_gesture == \"rock\" and M_gesture == \"paper\":\r\n print(\"M\")\r\n elif F_gesture == \"paper\" and M_gesture == \"scissors\":\r\n print(\"M\")\r\n else:\r\n print(\"?\")\r\nelse:\r\n print(\"?\")\r\n",
"fists = [input() for _ in range(3)]\r\n\r\nif (fists.count('rock') == 2 and fists.count('paper') == 1):\r\n print(('F', 'M', 'S')[fists.index('paper')])\r\nelif (fists.count('paper') == 2 and fists.count('scissors') == 1):\r\n print(('F', 'M', 'S')[fists.index('scissors')])\r\nelif(fists.count('scissors') == 2 and fists.count('rock') == 1):\r\n print(('F', 'M', 'S')[fists.index('rock')])\r\nelse:\r\n print('?')",
"def q48a():\n\tindex_arr = ['rock', 'paper', 'scissors']\n\tf = index_arr.index(input())\n\tm = index_arr.index(input())\n\ts = index_arr.index(input())\n\tif(q48a_check_beats(f, m) and q48a_check_beats(f, s)):\n\t\tprint(\"F\")\n\telif(q48a_check_beats(m, s) and q48a_check_beats(m, f)):\n\t\tprint(\"M\")\n\telif(q48a_check_beats(s, f) and q48a_check_beats(s, m)):\n\t\tprint(\"S\")\n\telse:\n\t\tprint(\"?\")\n\n\t\n# True if x1 beats x2\ndef q48a_check_beats(x1, x2):\n\tif(x1 == 1 and x2 == 0 or x1 == 2 and x2 == 1 or x1 == 0 and x2 == 2):\n\t\treturn True\n\telse:\n\t\treturn False\n\nq48a()",
"from collections import deque\r\nfrom collections import OrderedDict\r\nimport math\r\n \r\nimport sys\r\nimport os\r\nfrom io import BytesIO\r\nimport threading\r\nimport bisect\r\n \r\n \r\nimport heapq\r\n\r\n#sys.stdin = open(\"F:\\PY\\\\test.txt\", \"r\")\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\") \r\n\r\n\r\ndef winPos(cur, two):\r\n if cur==\"paper\" and two == \"rock\":\r\n return True\r\n elif cur==\"rock\" and two==\"scissors\":\r\n return True\r\n elif cur==\"scissors\" and two==\"paper\":\r\n return True\r\n else:\r\n return False\r\n\r\n\r\nar = []\r\nfor i in range(3):\r\n ar.append(input())\r\nif ar[0]==ar[1] and ar[1]==ar[2]:\r\n print(\"?\")\r\nelif ar[0]!=ar[1] and ar[0]!=ar[2] and ar[1]!=ar[2]:\r\n print(\"?\")\r\nelse:\r\n if ar[0]==ar[1]:\r\n if winPos(ar[2], ar[0])==True:\r\n print(\"S\")\r\n sys.exit(0)\r\n elif ar[0]==ar[2]:\r\n if winPos(ar[1], ar[0])==True:\r\n print(\"M\")\r\n sys.exit(0)\r\n else:\r\n if winPos(ar[0], ar[1])==True:\r\n print(\"F\")\r\n sys.exit(0)\r\n print(\"?\")",
"tc = 1\r\nwhile tc:\r\n tc-=1\r\n a = input(); b = input(); c = input()\r\n if a==b and b==c:\r\n print('?')\r\n elif a!=b and a!=c and b!=c:\r\n print('?')\r\n elif a=='paper' and b=='rock' and c=='rock':\r\n print('F')\r\n elif a=='scissors' and b=='paper' and c=='paper':\r\n print('F')\r\n elif a=='rock' and b=='scissors' and c=='scissors':\r\n print('F')\r\n elif b=='paper' and a=='rock' and c=='rock':\r\n print('M')\r\n elif b=='scissors' and a=='paper' and c=='paper':\r\n print('M')\r\n elif b=='rock' and a=='scissors' and c=='scissors':\r\n print('M')\r\n elif c=='paper' and a=='rock' and b=='rock':\r\n print('S')\r\n elif c=='scissors' and a=='paper' and b=='paper':\r\n print('S')\r\n elif c=='rock' and a=='scissors' and b=='scissors':\r\n print('S')\r\n else:\r\n print('?')\r\n \r\n ",
"def game(x,y,z):\r\n return ((x == \"rock\" and y == \"scissors\" and z == \"scissors\") or (x == \"scissors\" and y == \"paper\" and z == \"paper\") or (x == \"paper\" and y == \"rock\" and z == \"rock\")) \r\nf = input()\r\nm = input()\r\ns = input()\r\nif game(f,m,s) == True:\r\n print(\"F\")\r\nelif game(m,f,s) == True:\r\n print(\"M\")\r\nelif game(s,m,f):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndata = [input().rstrip() for _ in range(3)]\r\n\r\nmemo = {0: 'F', 1: 'M', 2: 'S'}\r\n\r\ntmp = list(set(data))\r\nif len(tmp) in (1, 3):\r\n print('?')\r\nelse:\r\n if data.count(tmp[0]) == 1:\r\n one = tmp[0]\r\n twos = tmp[1]\r\n elif data.count(tmp[1]) == 1:\r\n one = tmp[1]\r\n twos = tmp[0]\r\n else:\r\n one = tmp[2]\r\n twos = tmp[0]\r\n\r\n if (one == \"rock\" and twos == \"scissors\") or (one == \"paper\" and twos == \"rock\") or (one == \"scissors\" and twos == \"paper\"):\r\n print(memo[data.index(one)])\r\n else:\r\n print('?')",
"a=[input()[0] for x in range(3)]\r\nb=[\"F\",\"M\",\"S\"]\r\nif (a.count('r')==1 and a.count('s')==2) or (a.count('s')==1 and a.count('p')==2) or (a.count('p')==1 and a.count('r')==2):\r\n\tfor x in range(3):\r\n\t\tif a.count(a[x])==1:print(b[x])\r\nelse:print(\"?\")\r\n",
"a = []\r\nfor i in range(3): a.append(input())\r\nif a[0] == \"paper\" and a[1] == a[2] == \"rock\": print(\"F\")\r\nelif a[0] == \"rock\" and a[1] == a[2] == \"scissors\": print(\"F\")\r\nelif a[0] == \"scissors\" and a[1] == a[2] == \"paper\": print(\"F\")\r\nelif a[1] == \"paper\" and a[0] == a[2] == \"rock\": print(\"M\")\r\nelif a[1] == \"rock\" and a[0] == a[2] == \"scissors\": print(\"M\")\r\nelif a[1] == \"scissors\" and a[0] == a[2] == \"paper\": print(\"M\")\r\nelif a[2] == \"paper\" and a[1] == a[0] == \"rock\": print(\"S\")\r\nelif a[2] == \"rock\" and a[1] == a[0] == \"scissors\": print(\"S\")\r\nelif a[2] == \"scissors\" and a[1] == a[0] == \"paper\": print(\"S\")\r\nelse: print(\"?\")",
"L=[]\r\nfor i in range(3):\r\n L.append(input())\r\nrock=0 \r\nscissors=0\r\npaper=0\r\nfor i in range(3):\r\n if(L[i]=='rock'):\r\n rock=rock+1\r\n elif(L[i]=='scissors'):\r\n scissors=scissors+1\r\n else:\r\n paper=paper+1\r\n\r\n\r\nif((rock==2) and (paper==1)):\r\n for i in range(3):\r\n if(L[i]=='paper'):\r\n if(i==0):\r\n print('F')\r\n elif(i==1):\r\n print('M')\r\n else:\r\n print('S') \r\nelif((paper==2) and (scissors==1)):\r\n for i in range(3):\r\n if(L[i]=='scissors'):\r\n if(i==0):\r\n print('F')\r\n elif(i==1):\r\n print('M')\r\n else:\r\n print('S') \r\nelif((scissors==2) and (rock==1)):\r\n for i in range(3):\r\n if(L[i]=='rock'):\r\n if(i==0):\r\n print('F')\r\n elif(i==1):\r\n print('M')\r\n else:\r\n print('S') \r\nelif(rock==scissors==paper):\r\n print('?')\r\nelif((rock==3)or (scissors==3) or(paper==3)):\r\n print('?')\r\nelse:\r\n print('?') \r\n\r\n\r\n\r\n\r\n",
"a, b, c = input()[0], input()[0], input()[0]\r\np = {'s': 'r', 'r' : 'p', 'p': 's'}\r\nif b == c: print('F' if a == p[b] else '?')\r\nelif a == c: print('M' if b == p[c] else '?')\r\nelif a == b: print('S' if c == p[a] else '?')\r\nelse: print('?')",
"a=input()\r\nb=input()\r\nc=input()\r\nif a=='rock'and b=='scissors' and c=='scissors' or a=='paper'and b=='rock' and c=='rock' or a=='scissors' and b=='paper' and c=='paper':\r\n print('F')\r\nelif b=='rock'and a=='scissors' and c=='scissors' or b=='paper'and a=='rock' and c=='rock' or b=='scissors' and a=='paper' and c=='paper':\r\n print('M')\r\nelif c=='rock'and b=='scissors' and a=='scissors' or c=='paper'and b=='rock' and a=='rock' or c=='scissors' and b=='paper' and a=='paper':\r\n print('S')\r\nelse:\r\n print('?')\r\n",
"\r\nF = str(input())\r\nM = str(input())\r\nS = str(input())\r\n\r\ncomb = [F, M, S]\r\n\r\nr = [x == 'rock' for x in comb]\r\np = [x == 'paper' for x in comb]\r\ns = [x == 'scissors' for x in comb]\r\n\r\nnames = ['F', 'M', 'S']\r\n\r\n\r\nif (sum(r) == 2) & (sum(p) == 1):\r\n \r\n ind = [i for i, val in enumerate(p) if val][0]\r\n \r\n print(names[ind])\r\n\r\nelif (sum(p) == 2) & (sum(s) == 1):\r\n\r\n ind = [i for i, val in enumerate(s) if val][0]\r\n \r\n print(names[ind])\r\n\r\nelif (sum(s) == 2) & (sum(r) == 1):\r\n\r\n ind = [i for i, val in enumerate(r) if val][0]\r\n \r\n print(names[ind])\r\n \r\n \r\nelse:\r\n \r\n print('?')\r\n\r\n\r\n",
"def check(first,second,third):\r\n if first == 'rock' and second == third and second == 'scissors':\r\n return True\r\n if first == 'paper' and second == third and second == 'rock':\r\n return True\r\n if first == 'scissors' and second == third and second == 'paper':\r\n return True\r\n\r\nfyodor = input()\r\nmatroskin = input()\r\nsharic = input()\r\n\r\nif check(fyodor,matroskin,sharic) is True:\r\n print('F')\r\nelif check(matroskin,fyodor,sharic) is True:\r\n print('M')\r\nelif check(sharic,matroskin,fyodor) is True:\r\n print('S')\r\nelse:\r\n print('?')\r\n\r\n",
"#RockPaperScissors\r\nF=input()\r\nM=input()\r\nS=input()\r\ndef rps(f,m,s):\r\n if f==m and m==s:\r\n return \"?\"\r\n elif f!=m and m!=s and f!=s:\r\n return \"?\"\r\n \r\n winners={}\r\n winners[\"rock\"]=\"scissors\"\r\n winners[\"scissors\"]=\"paper\"\r\n winners[\"paper\"]=\"rock\"\r\n \r\n if f==m:\r\n if winners[s]==f:\r\n return \"S\"\r\n elif m==s:\r\n if winners[f]==s:\r\n return \"F\"\r\n else:\r\n if winners[m]==f:\r\n return \"M\"\r\n return \"?\"\r\n\r\nprint(rps(F,M,S))",
"def win(a, b):\n o = ['rock', 'scissors', 'paper']\n return True if (o.index(a) + 1) % 3 == o.index(b) else False\n\n\ndef solve(f, m, s):\n if win(f, m) and win(f, s): return \"F\"\n elif win(m, s) and win(m, f): return \"M\"\n elif win(s, m) and win(s, f): return \"S\"\n else: return '?'\n\n\ndef main():\n f = input() \n m = input()\n s = input()\n print(solve(f, m, s))\n\n\nmain()\n",
"a = input()\r\nb = input()\r\nc = input()\r\nr = \"rock\"\r\np = \"paper\"\r\ns = \"scissors\"\r\nif((a == r and b == s and c == s) or (a == p and b == r and c == r) or (a == s and b == p and c == p)):\r\n print(\"F\")\r\nelif((b == r and a == s and c == s) or (b == p and a == r and c == r) or (b == s and a == p and c == p)):\r\n print(\"M\")\r\nelif((c == r and a == s and b == s) or (c == p and a == r and b == r) or (c == s and a == p and b == p)):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"fms = []\r\ns = 0\r\nfor i in range(3):\r\n fms.append(input())\r\n if fms[i] == 'rock':\r\n fms[i] = 0\r\n elif fms[i] == 'scissors':\r\n fms[i] = 1\r\n else:\r\n fms[i] = 2\r\n s += fms[i]\r\nif s % 3 == 0 or s % 3 == 1:\r\n print('?')\r\nelse:\r\n if fms[0] == fms[1]:\r\n print('S')\r\n elif fms[0] == fms[2]:\r\n print('M')\r\n else:\r\n print('F')\r\n\r\n",
"def wins(x, y, z):\r\n # return True if x beats y and x beats z\r\n return (x==\"rock\" and y==z==\"scissors\") or \\\r\n (x==\"scissors\" and y==z==\"paper\") or \\\r\n (x==\"paper\" and y==z==\"rock\")\r\n\r\nf = input()\r\nm = input()\r\ns = input()\r\nif wins(f, m, s):\r\n print(\"F\")\r\nelif wins(m, f, s):\r\n print(\"M\")\r\nelif wins(s, m, f):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n",
"#rock\r\n#scissors\r\n#paper\r\ndef main():\r\n\ts1=str(input())\r\n\ts2=str(input())\r\n\ts3=str(input())\r\n\tif((s1==\"rock\" and s2==\"scissors\" and s3==\"scissors\") or (s1==\"scissors\" and s2==\"paper\" and s3==\"paper\") or(s1==\"paper\" and s2==\"rock\" and s3==\"rock\")):\r\n\t\tprint(\"F\")\r\n\telif((s2==\"rock\" and s1==\"scissors\"and s3==\"scissors\") or (s2==\"scissors\" and s1==\"paper\" and s3==\"paper\") or(s2==\"paper\" and s1==\"rock\" and s3==\"rock\")):\r\n\t\tprint(\"M\")\r\n\telif((s3==\"rock\" and s2==\"scissors\"and s1==\"scissors\") or (s3==\"scissors\" and s2==\"paper\" and s1==\"paper\") or(s3==\"paper\" and s2==\"rock\" and s1==\"rock\")):\r\n\t\tprint(\"S\")\r\n\telse:\r\n\t\tprint(\"?\")\r\nmain()",
"f=input()\nm=input()\ns=input()\n\nppt={'rock': 'scissors', 'paper': 'rock', 'scissors': 'paper'}\n\nif ppt[f] == m and ppt[f] == s: print(\"F\")\nelif ppt[m] == f and ppt[m] == s: print(\"M\")\nelif ppt[s] == f and ppt[s] == m: print(\"S\")\nelse: print(\"?\")\n\n \t\t \t \t\t \t\t\t \t \t \t \t\t",
"a = input()\nb = input()\nc = input()\n\ns = 'scissors'\np = 'paper'\nr = 'rock'\n\nlist = [[s, p, p], [p, s, p], [p, p, s], [p, r, r], [r, p, r], [r, r, p], [r, s, s], [s, r, s], [s, s, r]]\n\nif [a, b, c] in list:\n if a == c:\n print('M')\n if b == c:\n print('F')\n if a == b:\n print('S')\nelse:\n print('?')",
"def gets_winner(p1, p2):\r\n if p1 == p2:\r\n return -1\r\n\r\n if p1[0] == \"r\":\r\n if p2[0] == \"s\":\r\n return 0\r\n else:\r\n return 1\r\n elif p1[0] == \"p\":\r\n if p2[0] == \"r\":\r\n return 0\r\n else:\r\n return 1\r\n elif p1[0] == \"s\":\r\n if p2[0] == \"p\":\r\n return 0\r\n else:\r\n return 1\r\n\r\nuncle = input()\r\ncat = input() \r\ndog = input()\r\n\r\nuncle_cat = gets_winner(uncle, cat)\r\n\r\nif uncle_cat == 0:\r\n uncle_dog = gets_winner(uncle, dog)\r\n if uncle_dog == 0:\r\n print(\"F\")\r\n else:\r\n print(\"?\")\r\nelif uncle_cat == 1:\r\n dog_cat = gets_winner(dog, cat)\r\n if dog_cat == 1:\r\n print(\"M\")\r\n else:\r\n print(\"?\")\r\nelse:\r\n if gets_winner(uncle, dog) == 1:\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\n \r\n ",
"a = [input() for _ in range(3)]\r\nfor i in range(3):\r\n\tif a[i] == 'scissors':\r\n\t\ta[i] = 's'\r\n\tif a[i] == 'rock':\r\n\t\ta[i] = 'r'\r\n\tif a[i] == 'paper':\r\n\t\ta[i] = 'p'\r\nflag = False\r\nif a[0] == 's':\r\n\tif a[1] == 'p' and a[2] == 'p':\r\n\t\tflag = True\r\n\t\tprint('F')\r\nelif a[0] == 'p':\r\n\tif a[1] == 'r' and a[2] == 'r':\r\n\t\tflag = True\r\n\t\tprint('F')\r\nelif a[0] == 'r':\r\n\tif a[1] == 's' and a[2] == 's':\r\n\t\tflag = True\r\n\t\tprint('F')\r\nif not flag:\r\n\tif a[1] == 's':\r\n\t\tif a[0] == 'p' and a[2] == 'p':\r\n\t\t\tflag = True\r\n\t\t\tprint('M')\r\n\telif a[1] == 'p':\r\n\t\tif a[0] == 'r' and a[2] == 'r':\r\n\t\t\tflag = True\r\n\t\t\tprint('M')\r\n\telif a[1] == 'r':\r\n\t\tif a[0] == 's' and a[2] == 's':\r\n\t\t\tflag = True\r\n\t\t\tprint('M')\r\nif not flag:\r\n\tif a[2] == 's':\r\n\t\tif a[0] == 'p' and a[1] == 'p':\r\n\t\t\tflag = True\r\n\t\t\tprint('S')\r\n\telif a[2] == 'p':\r\n\t\tif a[0] == 'r' and a[1] == 'r':\r\n\t\t\tflag = True\r\n\t\t\tprint('S')\r\n\telif a[2] == 'r':\r\n\t\tif a[0] == 's' and a[1] == 's':\r\n\t\t\tflag = True\r\n\t\t\tprint('S')\r\nif not flag:\r\n\tprint('?')",
"rules={\"rock\":1,\"paper\":2,\"scissors\":3}\r\n\r\n\r\ndef main(rules):\r\n f=input()\r\n m=input()\r\n sh=input()\r\n f=rules[f]\r\n m=rules[m]\r\n sh=rules[sh]\r\n if f==m or m==sh or f==sh:\r\n if f==m:\r\n lose=f\r\n if (sh>lose and (sh!=3 or lose!=1)) or (sh==1 and lose==3):\r\n return \"S\"\r\n return \"?\"\r\n elif f==sh:\r\n lose=f\r\n if (m>lose and (m!=3 or lose!=1)) or (m==1 and lose==3):\r\n return \"M\"\r\n return \"?\"\r\n else:\r\n lose=sh\r\n if (f>lose and (f!=3 or lose!=1)) or (f==1 and lose==3):\r\n return \"F\"\r\n return \"?\"\r\n return \"?\"\r\n\r\n\r\n\r\nprint(main(rules))",
"choices = [input(), input(), input()]\r\nif len(set(choices)) == 2:\r\n for i in list(set(choices)):\r\n if choices.count(i) == 1:\r\n c1 = i\r\n if choices.count(i) == 2:\r\n c2 = i\r\n if (c1 == \"rock\" and c2 == \"scissors\") or (c1 == \"paper\" and c2 == \"rock\") or (c1 == \"scissors\" and c2 == \"paper\"):\r\n print(\"FMS\"[choices.index(c1)])\r\n else:\r\n print(\"?\")\r\nelse:\r\n print(\"?\")",
"def win(a,b):\r\n\tif((a=='r' and b=='s') or (a=='p' and b=='r') or (a=='s' and b=='p')):\r\n\t\treturn 1\r\n\telse:\r\n\t\treturn -1;\r\n\r\ndef con(a):\r\n\treturn a[0]\r\n\r\n\r\na=input()\r\nb=input()\r\nc=input()\r\n\r\na=con(a)\r\nb=con(b)\r\nc=con(c)\r\n\r\nif(win(a,b)+win(a,c)==2):\r\n\tprint('F')\r\n\texit()\r\n\r\n\r\nif(win(b,a)+win(b,c)==2):\r\n\tprint('M')\r\n\texit()\r\n\r\nif(win(c,b)+win(c,a)==2):\r\n\tprint('S')\r\n\texit()\r\nprint('?')\r\n\r\n",
"f = input()\nm = input()\ns = input()\n\nif f == m == s:\n print(\"?\")\nelif (f, m, s) == (\"rock\", \"rock\", \"scissors\"):\n print(\"?\")\nelif (f, m, s) == (\"rock\", \"rock\", \"paper\"):\n print(\"S\")\nelif (f, m, s) == (\"rock\", \"scissors\", \"rock\"):\n print(\"?\")\nelif (f, m, s) == (\"rock\", \"scissors\", \"scissors\"):\n print(\"F\")\nelif (f, m, s) == (\"rock\", \"scissors\", \"paper\"):\n print(\"?\")\nelif (f, m, s) == (\"rock\", \"paper\", \"rock\"):\n print(\"M\")\nelif (f, m, s) == (\"rock\", \"paper\", \"scissors\"):\n print(\"?\")\nelif (f, m, s) == (\"rock\", \"paper\", \"paper\"):\n print(\"?\")\nelif (f, m, s) == (\"scissors\", \"rock\", \"rock\"):\n print(\"?\")\nelif (f, m, s) == (\"scissors\", \"rock\", \"scissors\"):\n print(\"M\")\nelif (f, m, s) == (\"scissors\", \"rock\", \"paper\"):\n print(\"?\")\nelif (f, m, s) == (\"scissors\", \"scissors\", \"rock\"):\n print(\"S\")\nelif (f, m, s) == (\"scissors\", \"scissors\", \"paper\"):\n print(\"?\")\nelif (f, m, s) == (\"scissors\", \"paper\", \"rock\"):\n print(\"?\")\nelif (f, m, s) == (\"scissors\", \"paper\", \"scissors\"):\n print(\"?\")\nelif (f, m, s) == (\"scissors\", \"paper\", \"paper\"):\n print(\"F\")\nelif (f, m, s) == (\"paper\", \"rock\", \"rock\"):\n print(\"F\")\nelif (f, m, s) == (\"paper\", \"rock\", \"scissors\"):\n print(\"?\")\nelif (f, m, s) == (\"paper\", \"rock\", \"paper\"):\n print(\"?\")\nelif (f, m, s) == (\"paper\", \"scissors\", \"rock\"):\n print(\"?\")\nelif (f, m, s) == (\"paper\", \"scissors\", \"scissors\"):\n print(\"?\")\nelif (f, m, s) == (\"paper\", \"scissors\", \"paper\"):\n print(\"M\")\nelif (f, m, s) == (\"paper\", \"paper\", \"rock\"):\n print(\"?\")\nelif (f, m, s) == (\"paper\", \"paper\", \"scissors\"):\n print(\"S\")\n",
"import itertools\r\n\r\n\r\ndef main():\r\n table = {\r\n \"scissors\": {\"paper\": 1, \"rock\": 0, \"scissors\": 0},\r\n \"paper\": {\"scissors\": 0, \"rock\": 1, \"paper\": 0},\r\n \"rock\": {\"paper\": 0, \"scissors\": 1, \"rock\": 0}}\r\n f = input().strip()\r\n m = input().strip()\r\n s = input().strip()\r\n data = [0, 0, 0]\r\n data[0] = table[f][m] + table[f][s]\r\n data[1] = table[m][f] + table[m][s]\r\n data[2] = table[s][f] + table[s][m]\r\n if data[0]>data[1] and data[0]>data[2]:\r\n print(\"F\")\r\n elif data[1]>data[2] and data[1]>data[0]:\r\n print(\"M\")\r\n elif data[2]>data[0] and data[2]>data[1]:\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"f = str(input())\r\nm = str(input())\r\ns = str(input())\r\nif f == \"rock\" and m == s == \"scissors\":\r\n print(\"F\")\r\nelif m == \"rock\" and f == s == \"scissors\":\r\n print(\"M\")\r\nelif s == \"rock\" and f == m == \"scissors\":\r\n print(\"S\")\r\nelif m == \"scissors\" and f == s == \"paper\":\r\n print(\"M\")\r\nelif f == \"scissors\" and m == s == \"paper\":\r\n print(\"F\")\r\nelif s == \"scissors\" and f == m == \"paper\":\r\n print(\"S\")\r\nelif m == \"paper\" and f == s == \"rock\":\r\n print(\"M\")\r\nelif f == \"paper\" and m == s == \"rock\":\r\n print(\"F\")\r\nelif s == \"paper\" and f == m == \"rock\":\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"#----Kuzlyaev-Nikita-Codeforces-----\r\n#------------03.04.2020-------------\r\n\r\nalph=\"abcdefghijklmnopqrstuvwxyz\"\r\n\r\n#-----------------------------------\r\n\r\nf=str(input())\r\nm=str(input())\r\ns=str(input())\r\nif f==m or f==s or m==s:\r\n if f==m and f==s:\r\n print(\"?\")\r\n else:\r\n if f==m:\r\n if s==\"rock\" and f==\"scissors\":\r\n print(\"S\")\r\n elif s==\"scissors\" and f==\"paper\":\r\n print(\"S\")\r\n elif s==\"paper\" and f==\"rock\":\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\n elif f==s:\r\n if m==\"rock\" and f==\"scissors\":\r\n print(\"M\")\r\n elif m==\"scissors\" and f==\"paper\":\r\n print(\"M\")\r\n elif m==\"paper\" and f==\"rock\":\r\n print(\"M\")\r\n else:\r\n print(\"?\") \r\n else:\r\n if f==\"rock\" and m==\"scissors\":\r\n print(\"F\")\r\n elif f==\"scissors\" and m==\"paper\":\r\n print(\"F\")\r\n elif f==\"paper\" and m==\"rock\":\r\n print(\"F\")\r\n else:\r\n print(\"?\") \r\n \r\nelse:\r\n print(\"?\")",
"r = { 's': 'p', 'p': 'r', 'r': 's'}\na = tuple(input() for i in \"'''\")\nfor i in (0, 1, 2):\n if a.count(a[i]) == 1 and a.count(a[(i + 1) % 3]) == 2 and r[a[i][0]] == a[(i + 1) % 3][0]:\n exit(print('FMS'[i]))\nprint('?')",
"def exclude(rps, idx):\r\n exc = []\r\n for i in range(0, 3):\r\n if i != idx:\r\n exc.append(rps[i])\r\n return exc\r\n\r\ndef match_(idx):\r\n if idx == 0:\r\n return \"F\"\r\n elif idx == 1:\r\n return \"M\"\r\n elif idx == 2:\r\n return \"S\"\r\n\r\ndef solve(rps):\r\n victor = \"?\"\r\n \r\n for i in range(0, 3):\r\n sc = True\r\n exc = exclude(rps, i)\r\n for i2 in exc:\r\n if rps[i] == \"rock\" and i2 == \"scissors\":\r\n continue\r\n elif rps[i] == \"scissors\" and i2 == \"paper\":\r\n continue\r\n elif rps[i] == \"paper\" and i2 == \"rock\":\r\n continue\r\n else:\r\n sc = False\r\n break\r\n if sc:\r\n victor = match_(i)\r\n return victor\r\n\r\ndef main():\r\n rps = [] # 1 -> F; 2 -> M; 3 -> S\r\n for i in range(0, 3):\r\n rps.append(input())\r\n print(solve(rps))\r\nmain()\r\n",
"def get_key(d, value):\r\n for k, v in d.items():\r\n if v == value:\r\n return k\r\n\r\nd = {}\r\ns = []\r\nans = ''\r\n\r\ns1 = input()\r\ns2 = input()\r\ns3 = input()\r\n\r\ns.append(s1)\r\ns.append(s2)\r\ns.append(s3)\r\n\r\nd['F'] = s1\r\nd['M'] = s2\r\nd['S'] = s3\r\n\r\nif s.count('rock') == 1 and s.count('scissors') == 2:\r\n ans = get_key(d, 'rock')\r\n\r\nelif s.count('paper') == 1 and s.count('rock') == 2:\r\n ans = get_key(d, 'paper')\r\n \r\nelif s.count('scissors') == 1 and s.count('paper') == 2:\r\n ans = get_key(d, 'scissors')\r\n\r\nelse:\r\n ans = '?'\r\n\r\nprint(ans) \r\n\r\n",
"s = ''\r\nfor i in range(3):\r\n s += input()[0]\r\n\r\nif s in ('rss', 'prr', 'spp'):\r\n print('F')\r\nelif s in ('srs', 'rpr', 'psp'):\r\n print('M')\r\nelif s in ('ssr', 'rrp', 'pps'):\r\n print('S')\r\nelse:\r\n print('?')",
"def wins(x, y, z):\r\n # return True if x beats y and x beats z\r\n return (x==\"rock\" and y==z==\"scissors\") or \\\r\n (x==\"scissors\" and y==z==\"paper\") or \\\r\n (x==\"paper\" and y==z==\"rock\")\r\n\r\nn = [\"F\", \"M\", \"S\"] \r\na = [input() for i in range(3)]\r\nfor i in range(3):\r\n if wins(a[i], a[(i+1)%3], a[(i+2)%3]):\r\n print(n[i])\r\n quit()\r\nprint(\"?\")",
"s1=input()\r\ns2=input()\r\ns3=input()\r\nif s1==\"paper\" and s3==s2==\"rock\" or s1==\"scissors\" and s3==s2==\"paper\" or s1==\"rock\" and s3==s2==\"scissors\":\r\n print(\"F\")\r\nelif s2==\"paper\" and s1==s3==\"rock\" or s2==\"scissors\" and s1==s3==\"paper\" or s2==\"rock\" and s1==s3==\"scissors\":\r\n print(\"M\")\r\nelif s3==\"paper\" and s1==s2==\"rock\" or s3==\"scissors\" and s1==s2==\"paper\" or s3==\"rock\" and s1==s2==\"scissors\":\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n",
"def win(x, y):\r\n r = 'rock'\r\n p = 'paper'\r\n s = 'scissors'\r\n if x == y:\r\n return '?'\r\n if x == r:\r\n if y == p:\r\n return 2\r\n else:\r\n return 1\r\n if x == p:\r\n if y == s:\r\n return 2\r\n else:\r\n return 1\r\n if x == s:\r\n if y == r:\r\n return 2\r\n else:\r\n return 1\r\nF = input()\r\nM = input()\r\nS = input()\r\nif F == M == S or ((M != F) and (M != S) and (S != F)):\r\n print('?')\r\nelse:\r\n if F == M:\r\n if win(S, F) != 2:\r\n print('S')\r\n else:\r\n print('?')\r\n if F == S:\r\n if win(M, F) != 2:\r\n print('M')\r\n else:\r\n print('?')\r\n if S == M:\r\n if win(F, S) != 2:\r\n print('F')\r\n else:\r\n print('?')",
"def checkWinner(gesture1, gesture2, gesture3):\r\n if gesture1 == \"rock\":\r\n if gesture2 == \"scissors\" and gesture3 == \"scissors\":\r\n return True\r\n else:\r\n return False\r\n elif gesture1 == \"paper\":\r\n if gesture2 == \"rock\" and gesture3 == \"rock\":\r\n return True\r\n else:\r\n return False\r\n elif gesture1 == \"scissors\":\r\n if gesture2 == \"paper\" and gesture3 == \"paper\":\r\n return True\r\n else:\r\n return False\r\n\r\ngestureF = input()\r\ngestureM = input()\r\ngestureS = input()\r\n\r\nif checkWinner(gestureF, gestureM, gestureS):\r\n print(\"F\")\r\nelif checkWinner(gestureM, gestureF, gestureS):\r\n print(\"M\")\r\nelif checkWinner(gestureS, gestureM, gestureF):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"f=input()\nm=input()\ns=input()\nd=dict()\nd[\"rock\"]=\"paper\"\nd[\"scissors\"]=\"rock\"\nd[\"paper\"]=\"scissors\"\nif f==m and f==s:\n\tprint(\"?\")\n\texit()\nelif f!=m and f!=s and s!=m:\n\tprint(\"?\")\n\texit()\nif f==m:\n\tif d[f]==s:\n\t\tprint(\"S\")\n\t\texit()\n\telse:\n\t\tprint(\"?\")\n\t\texit()\nelif f==s and len(d)==3:\n\tif d[f]==m:\n\t\tprint(\"M\")\n\t\texit()\n\telse:\n\t\tprint(\"?\")\n\t\texit()\nelif s==m:\n\tif d[s]==f:\n\t\tprint(\"F\")\n\t\texit()\n\telse:\n\t\tprint(\"?\")",
"f=input()\r\nm=input()\r\ns=input()\r\nif(f==\"paper\"and m==s==\"rock\"):\r\n print(\"F\")\r\nelif(m==\"paper\"and f==s==\"rock\"):\r\n print(\"M\")\r\nelif(s==\"paper\"and m==f==\"rock\"):\r\n print(\"S\")\r\nelif(f==\"scissors\"and m==s==\"paper\"):\r\n print(\"F\")\r\nelif(m==\"scissors\"and f==s==\"paper\"):\r\n print(\"M\")\r\nelif(s==\"scissors\"and m==f==\"paper\"):\r\n print(\"S\")\r\nelif(f==\"rock\"and m==s==\"scissors\"):\r\n print(\"F\")\r\nelif(m==\"rock\"and f==s==\"scissors\"):\r\n print(\"M\")\r\nelif(s==\"rock\"and m==f==\"scissors\"):\r\n print(\"S\") \r\nelse:\r\n print(\"?\") \r\n ",
"f=input()\r\nm=input()\r\ns=input()\r\nwin=0\r\nlist=[f,m,s]\r\nlist1=list.copy()\r\ndict={0:'F',1:'M',2:'S'}\r\nif 'rock' in list and 'scissors' in list:\r\n win+=1\r\n list.remove('rock')\r\n list.remove('scissors')\r\n if 'scissors' not in list:\r\n win+=1\r\n name=list1.index('rock')\r\nelif 'paper' in list and 'rock' in list:\r\n win+=1\r\n list.remove('paper')\r\n list.remove('rock')\r\n if 'rock' not in list:\r\n win+=1\r\n name=list1.index('paper')\r\nelif 'scissors' in list and 'paper' in list:\r\n win+=1\r\n list.remove('scissors')\r\n list.remove('paper')\r\n if 'paper' not in list:\r\n win+=1\r\n name=list1.index('scissors')\r\nif win==0 or win>1:\r\n print('?')\r\nelse:\r\n print(dict[name])",
"a=input()\nb=input()\nc=input()\nif (a==\"rock\" and b==\"scissors\" and c==\"scissors\") or (a==\"paper\" and b==\"rock\" and c==\"rock\") or (a==\"scissors\" and b==\"paper\" and c==\"paper\"):\n print(\"F\")\nelif (b==\"rock\" and a==\"scissors\" and c==\"scissors\") or (b==\"paper\" and a==\"rock\" and c==\"rock\") or (b==\"scissors\" and a==\"paper\" and c==\"paper\"):\n print(\"M\")\nelif (c==\"rock\" and b==\"scissors\" and a==\"scissors\") or (c==\"paper\" and b==\"rock\" and a==\"rock\") or (c==\"scissors\" and b==\"paper\" and a==\"paper\"):\n print(\"S\")\nelse:\n print(\"?\")",
"def conv(s):\n if s == \"scissors\":\n return 0\n elif s == \"paper\":\n return 1\n else:\n return 2\nf = conv(input())\nm = conv(input())\ns = conv(input())\nif (f*m*s==0 and f+m+s==2) or (f*m*s==4 and f+m+s==5):\n if f==m:\n print(\"S\")\n elif f==s:\n print(\"M\")\n else:\n print(\"F\")\nelse:\n print(\"?\")",
"f = input()\r\nm = input()\r\ns = input()\r\nt = [f, m, s]\r\nif t.count('rock') == 3 or t.count('paper') == 3 or t.count('scissors') == 3:\r\n print('?')\r\n exit()\r\nif t.count('rock') == 1 and t.count('paper') == 1 and t.count('scissors') == 1:\r\n print('?')\r\n exit()\r\n\r\nif t.count('rock') == 2:\r\n if t.count('paper') == 1:\r\n d = t.index('paper')\r\n if d == 0:\r\n print('F')\r\n exit()\r\n if d == 1:\r\n print('M')\r\n exit()\r\n if d == 2:\r\n print('S')\r\n exit()\r\n if t.count('scissors'):\r\n print('?')\r\n exit()\r\n\r\nif t.count('paper') == 2:\r\n if t.count('scissors') == 1:\r\n d = t.index('scissors')\r\n if d == 0:\r\n print('F')\r\n exit()\r\n if d == 1:\r\n print('M')\r\n exit()\r\n if d == 2:\r\n print('S')\r\n exit()\r\n if t.count('rock'):\r\n print('?')\r\n exit()\r\nif t.count('scissors') == 2:\r\n if t.count('rock') == 1:\r\n d = t.index('rock')\r\n if d == 0:\r\n print('F')\r\n exit()\r\n if d == 1:\r\n print('M')\r\n exit()\r\n if d == 2:\r\n print('S')\r\n exit()\r\n if t.count('paper'):\r\n print('?')\r\n exit()",
"a=input()\r\nb=input()\r\nc=input()\r\ndic={a:\"F\",b:\"M\",c:\"S\"}\r\nif(a==b and a!=c):\r\n if(a==\"paper\"and c==\"scissors\"):\r\n print(dic[c])\r\n elif(c==\"paper\" and a==\"rock\"):\r\n print(dic[c])\r\n elif(a==\"scissors\" and c==\"rock\"):\r\n print(dic[c])\r\n else:\r\n print(\"?\")\r\nelif(b==c and a!=c):\r\n if(b==\"paper\"and a==\"scissors\"):\r\n print(dic[a])\r\n elif(a==\"paper\" and b==\"rock\"):\r\n print(dic[a])\r\n elif(c==\"scissors\" and a==\"rock\"):\r\n print(dic[a])\r\n else:\r\n print(\"?\")\r\nelif(a==c and b!=c):\r\n if(a==\"paper\"and b==\"scissors\"):\r\n print(dic[b])\r\n elif(b==\"paper\" and c==\"rock\"):\r\n print(dic[b])\r\n elif(a==\"scissors\" and b==\"rock\"):\r\n print(dic[b])\r\n else:\r\n print(\"?\")\r\nelse:\r\n print(\"?\")\r\n\r\n",
"f = input()\r\nm = input()\r\ns = input()\r\n\r\nout = 0\r\n\r\nif f == \"rock\":\r\n if m == \"scissors\" and s == \"scissors\":\r\n out = 1\r\n elif m == \"rock\" and s == \"paper\":\r\n out = 3\r\n elif s == \"rock\" and m == \"paper\":\r\n out = 2\r\n\r\nelif f == \"paper\":\r\n if m == \"rock\" and s == \"rock\":\r\n out = 1\r\n elif m == \"paper\" and s == \"scissors\":\r\n out = 3\r\n elif s == \"paper\" and m == \"scissors\":\r\n out = 2\r\n\r\nelif f == \"scissors\":\r\n if m == \"paper\" and s == \"paper\":\r\n out = 1\r\n elif m == \"scissors\" and s == \"rock\":\r\n out = 3\r\n elif s == \"scissors\" and m == \"rock\":\r\n out = 2\r\n\r\nif (out == 0):\r\n print(\"?\")\r\nelif out == 1:\r\n print(\"F\")\r\nelif out == 2:\r\n print(\"M\")\r\nelse:\r\n print(\"S\")",
"f=str(input())\r\nm=str(input())\r\ns=str(input())\r\n \r\nh={\"rock\":\"paper\",\"paper\":\"scissors\",\"scissors\":\"rock\"}\r\n \r\nif(f==m and s==h[f]):\r\n print(\"S\")\r\nelif(f==s and m==h[f]):\r\n print(\"M\")\r\nelif(s==m and f==h[s]):\r\n print(\"F\")\r\nelse:\r\n print(\"?\")\r\n",
"f=str(input())\r\nm=str(input())\r\ns=str(input())\r\nL=set()\r\nL.add(f)\r\nL.add(m)\r\nL.add(s)\r\nif(len(L)!=2):\r\n\tprint(\"?\")\r\nelse:\r\n\tif(f==m==\"rock\" and s==\"paper\") or (f==m==\"paper\" and s==\"scissors\") or (f==m==\"scissors\" and s==\"rock\"):\r\n\t\tprint(\"S\")\r\n\telif(s==m==\"rock\" and f==\"paper\") or (s==m==\"paper\" and f==\"scissors\") or (s==m==\"scissors\" and f==\"rock\"):\r\n\t\tprint(\"F\")\r\n\telif(f==s==\"rock\" and m==\"paper\") or (f==s==\"paper\" and m==\"scissors\") or (f==s==\"scissors\" and m==\"rock\"):\r\n\t\tprint(\"M\")\r\n\telse:\r\n\t\tprint(\"?\")\r\n",
"def g(s):\r\n if s=='rock':\r\n return 1\r\n elif s=='scissors':\r\n return 2\r\n else:\r\n return 3\r\ndef win(a,b):\r\n if a==1 and b==2 or a==2 and b==3 or a==3 and b==1:\r\n return a\r\n else:\r\n return b\r\na=str(input())\r\nb=str(input())\r\nc=str(input())\r\naa=g(a)\r\nbb=g(b)\r\ncc=g(c)\r\nif aa!=bb and bb!=cc and aa!=cc or aa==bb and bb==cc or aa==bb and win(bb,cc)==bb or bb==cc and win(bb,aa)==bb or aa==cc and win(aa,bb)==aa:\r\n print('?')\r\nelif aa==bb and win(aa,cc)==cc:\r\n print('S')\r\nelif aa==cc and win(bb,cc)==bb:\r\n print('M')\r\nelse:\r\n print('F')",
"a=input()\r\nb=input()\r\nc=input()\r\nif (a==b and b==c) or (a!=b and b!=c and a!=c):\r\n print('?')\r\nelif (a=='rock' and b=='scissors' and b==c) or (a=='paper' and b=='rock' and b==c) or (a=='scissors' and b=='paper' and b==c):\r\n print('F')\r\nelif (b=='rock' and a=='scissors' and a==c) or (b=='paper' and a=='rock' and a==c) or (b=='scissors' and a=='paper' and a==c):\r\n print('M')\r\nelif (a=='rock' and ((b=='rock' and c=='scissors') or (c=='rock' and b=='scissors'))) or (b=='rock' and ((a=='rock' and c=='scissors') or (c=='rock' and a=='scissors'))) or (c=='rock' and ((b=='rock' and a=='scissors') or (a=='rock' and b=='scissors'))):\r\n print('?')\r\nelif (a=='paper' and ((b=='paper' and c=='rock') or (c=='paper' and b=='rock'))) or (b=='paper' and ((a=='rock' and c=='paper') or (c=='rock' and a=='paper'))) or (c=='paper' and ((b=='rock' and a=='paper') or (a=='rock' and b=='paper'))):\r\n print('?')\r\nelif (a=='scissors' and ((b=='paper' and c=='scissors') or (c=='paper' and b=='scissors'))) or (b=='scissors' and ((a=='scissors' and c=='paper') or (c=='scissors' and a=='paper'))) or (c=='scissors' and ((b=='scissors' and a=='paper') or (a=='scissors' and b=='paper'))):\r\n print('?')\r\nelse:\r\n print('S')",
"a=input()\r\nb=input()\r\nc=input()\r\nv=[]\r\nv.append(a)\r\nv.append(b)\r\nv.append(c)\r\nif(v.count(a) == 3):\r\n print(\"?\")\r\nelse:\r\n if((v.count(a) == 2)or(v.count(b) == 2)or(v.count(c) == 2)):\r\n if(a == 'paper' and b=='rock' and c=='rock'):\r\n print(\"F\")\r\n elif(a == 'scissors' and b == 'paper' and c == 'paper'):\r\n print(\"F\")\r\n elif(a == 'rock' and b == 'scissors' and c == 'scissors'):\r\n print(\"F\")\r\n elif(b == 'paper' and a=='rock' and c=='rock'):\r\n print(\"M\")\r\n elif(b == 'scissors' and a == 'paper' and c == 'paper'):\r\n print(\"M\")\r\n elif(b == 'rock' and a == 'scissors' and c == 'scissors'):\r\n print(\"M\")\r\n elif(c == 'paper' and a=='rock' and b=='rock'):\r\n print(\"S\")\r\n elif(c == 'scissors' and a == 'paper' and b == 'paper'):\r\n print(\"S\")\r\n elif(c == 'rock' and a == 'scissors' and b == 'scissors'):\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\n else:\r\n print(\"?\")",
"\r\nmanos = [input(),input(),input()]\r\n\r\nindice_ganador = None\r\njugadores = ['F','M','S']\r\n#manos = ['rock','paper','scissors']\r\nreglas = ['paper','rock','scissors','paper']\r\n\r\nfor i in range(3):\r\n for j in range(4):\r\n if manos[i] == reglas[j]:\r\n if reglas[j+1] == manos[(i+1)%3] and reglas[j+1] == manos[(i+2)%3]:\r\n indice_ganador = i\r\n break\r\n\r\nif indice_ganador != None:\r\n print(jugadores[indice_ganador])\r\nelse:\r\n print('?')",
"f,m,s=input(),input(),input()\r\nif f=='rock' and m=='scissors'and s==\"scissors\" :\r\n\tprint(\"F\")\r\nelif m=='rock' and f=='scissors'and s==\"scissors\":\r\n\tprint(\"M\")\r\nelif s=='rock' and m=='scissors'and f==\"scissors\": \r\n\tprint(\"S\")\r\nelif f=='paper' and m=='rock'and s==\"rock\":\r\n\tprint(\"F\")\r\nelif m=='paper' and s=='rock'and f==\"rock\":\r\n\tprint(\"M\")\r\nelif s=='paper' and m=='rock'and f==\"rock\":\r\n\tprint(\"S\")\r\nelif f=='scissors' and m=='paper'and s==\"paper\":\r\n\tprint(\"F\")\r\nelif m=='scissors' and s=='paper'and f==\"paper\":\r\n\tprint(\"M\")\r\nelif s=='scissors' and m=='paper'and f==\"paper\":\r\n\tprint(\"S\")\t\r\nelse:\r\n\tprint('?')\r\n",
"def esMejor(yo, otro):\r\n if yo == \"rock\" and otro == \"scissors\":\r\n return True\r\n if yo == \"scissors\" and otro == \"paper\":\r\n return True\r\n if yo == \"paper\" and otro == \"rock\":\r\n return True\r\n return False\r\n \r\n\r\nif __name__ == \"__main__\":\r\n a = input()\r\n b = input()\r\n c = input()\r\n if esMejor(a, b) and esMejor(a, c):\r\n print(\"F\")\r\n elif esMejor(b, a) and esMejor(b, c):\r\n print(\"M\")\r\n elif esMejor(c, a) and esMejor(c, b):\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\n",
"a=input()\r\nb=input()\r\nc=input()\r\ndef d(x):\r\n if x==\"rock\":\r\n return 0\r\n if x==\"scissors\":\r\n return 2\r\n if x==\"paper\":\r\n return 1\r\nif d(a)==d(b) and d(b)==((d(c)-1)%3):\r\n print(\"S\")\r\nelif d(b)==d(c) and d(c)==((d(a)-1)%3):\r\n print(\"F\")\r\nelif d(c)==d(a) and d(a)==((d(b)-1)%3):\r\n print(\"M\")\r\nelse:\r\n print(\"?\")",
"def rockpaperscissors(player, play, char):\n if player == \"rock\" and play == \"scissors\":\n print(char)\n elif player == \"paper\" and play == \"rock\":\n print(char)\n elif player == \"scissors\" and play == \"paper\":\n print(char)\n else:\n print(\"?\")\n\nuncle_fyodor = input()\nmatroskin = input()\nsharic = input()\n\nif uncle_fyodor == matroskin:\n rockpaperscissors(sharic, uncle_fyodor, \"S\")\nelif sharic == uncle_fyodor:\n rockpaperscissors(matroskin, sharic, \"M\")\nelif matroskin == sharic:\n rockpaperscissors(uncle_fyodor, matroskin, \"F\")\nelse:\n print(\"?\")\n\t \t \t\t\t \t \t \t \t\t \t\t \t\t\t",
"F, M, S = input(), input(), input()\nB = {\"rock\": \"paper\", \"paper\": \"scissors\", \"scissors\": \"rock\"}\nif (F == M and S == B[F]):\n print(\"S\")\nelif (F == S and M == B[F]):\n print(\"M\")\nelif (S == M and F == B[S]):\n print(\"F\")\nelse:\n print(\"?\")\n",
"def beats(a, b):\n return a == \"rock\" and b == \"scissors\" or a == \"scissors\" and b == \"paper\" or a == \"paper\" and b == \"rock\"\n\ns = [input(), input(), input()]\n\nif beats(s[0], s[1]) and beats(s[0], s[2]):\n print(\"F\")\nelif beats(s[1], s[0]) and beats(s[1], s[2]):\n print(\"M\")\nelif beats(s[2], s[0]) and beats(s[2], s[1]):\n print(\"S\")\nelse:\n print(\"?\")",
"from collections import defaultdict\r\n# from sys import stdin\r\n# import itertools\r\n# import bisect\r\n# from math import sqrt,ceil,floor\r\n\r\ndef func(put,mapping,unpack):\r\n game = {'rock': 1,'paper': 2,'scissors': 3}\r\n f,m,s=put(str),put(str),put(str)\r\n st = defaultdict(int)\r\n st[f] += 1\r\n st[m] += 1\r\n st[s] += 1\r\n f,m,s=game[f],game[m],game[s]\r\n if len(st) == 1 or len(st) == 3: print('?'); return\r\n rock,paper,scissor = st['rock'],st['paper'],st['scissors']\r\n if not rock:\r\n if scissor == 2: print('?')\r\n else:\r\n if f==3: print('F')\r\n elif m==3: print('M')\r\n else: print('S')\r\n elif not paper:\r\n if rock == 2: print('?')\r\n else:\r\n if f==1: print('F')\r\n elif m==1: print('M')\r\n else: print('S')\r\n else:\r\n if paper == 2: print('?')\r\n else:\r\n if f==2: print('F')\r\n elif m==2: print('M')\r\n else: print('S')\r\n \r\ndef init(TestCases=True):\r\n put = lambda s: s(input().strip())\r\n mapping = lambda s: list(map(s,input().split()))\r\n unpack = lambda s: map(s,input().split())\r\n for _ in range(int(input()) if TestCases else 1):\r\n func(put,mapping,unpack)\r\n\r\nif __name__ == '__main__':\r\n init(False)",
"if __name__ == \"__main__\":\r\n t = 3\r\n info = []\r\n R = 0\r\n P = 0\r\n S = 0\r\n while t:\r\n x = input()\r\n if x=='rock':\r\n R=R+1\r\n elif x==\"scissors\":\r\n S=S+1\r\n else:\r\n P=P+1 \r\n info.append(x)\r\n t -= 1 \r\n d = {info[0]:'F',info[1]:'M',info[2]:'S'} \r\n if (R==1 and S==1 and P==1) or (R==3 or S==3 or P==3):\r\n print('?')\r\n else:\r\n if R==1 and S==2:\r\n print(d['rock'])\r\n elif S==1 and P==2:\r\n print(d['scissors'])\r\n elif P==1 and R==2:\r\n print(d['paper'])\r\n else:\r\n print(\"?\") \r\n\r\n",
"f=input()\r\nm=input()\r\nsh=input()\r\nk=f+' '+m+' '+sh\r\na=[]\r\na.append(f)\r\na.append(m)\r\na.append(sh)\r\ny=['F','M','S']\r\nif (k=='rock scissors paper') or (k=='rock paper scissors') or (k=='scissors paper rock') or (k=='scissors rock paper') or (k=='paper scissors rock') or (k=='paper rock scissors'):\r\n print('?')\r\nif (k=='rock rock rock') or (k=='paper paper paper') or (k=='scissors scissors scissors'):\r\n print('?')\r\nif (k=='rock scissors scissors') or (k=='scissors rock scissors') or (k=='scissors scissors rock'):\r\n for i in range(3):\r\n if a[i]=='rock':\r\n print(y[i])\r\nif (k=='scissors paper paper') or (k=='paper scissors paper') or (k=='paper paper scissors'):\r\n for i in range(3):\r\n if a[i]=='scissors':\r\n print(y[i])\r\nif (k=='paper rock rock') or (k=='rock paper rock') or (k=='rock rock paper'):\r\n for i in range(3):\r\n if a[i]=='paper':\r\n print(y[i])\r\nif (k=='paper scissors scissors') or (k=='scissors paper scissors') or (k=='scissors scissors paper'):\r\n print('?')\r\nif (k=='paper paper rock') or (k=='paper rock paper') or (k=='rock paper paper'):\r\n print('?')\r\nif (k=='rock rock scissors') or (k=='rock scissors rock') or (k=='scissors rock rock'):\r\n print('?')\r\n",
"import sys, io, os\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport string\r\nfrom collections import defaultdict,Counter,deque\r\ninput = sys.stdin.readline\r\n \r\ndef I():\r\n return input()\r\n \r\ndef II():\r\n return int(input())\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \r\ndef LI():\r\n return list(input().split())\r\n \r\ndef LII():\r\n return list(map(int, input().split()))\r\n \r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n \r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n \r\ndef WRITE(out):\r\n return print('\\n'.join(map(str, out)))\r\n \r\ndef WS(out):\r\n return print(' '.join(map(str, out)))\r\n \r\ndef WNS(out):\r\n return print(''.join(map(str, out)))\r\n\r\n'''\r\nimplement\r\nTwo pass -> 1) min(a[i] and a[i-2]) 2) max(a[i] and a[i-1])\r\n\r\n'''\r\ndef isPalindrome(s):\r\n l = 0\r\n r = len(s) - 1\r\n while l <= r:\r\n if s[l] != s[r]:\r\n return False\r\n l += 1\r\n r -= 1\r\n return True\r\n\r\ndef outcome(p1, p2):\r\n if p1 == 'rock' and p2 == 'scissors':\r\n return True\r\n if p1 == 'scissors' and p2 == 'paper':\r\n return True\r\n if p1 == 'paper' and p2 == 'rock':\r\n return True\r\n return False\r\n\r\ndef solve():\r\n f = I().strip()\r\n m = I().strip()\r\n s = I().strip()\r\n moves = set([f,m,s])\r\n ans = '?'\r\n\r\n if len(moves) == 2:\r\n # Need to check if the 1 beats the other 2\r\n if f == m and outcome(s, f):\r\n ans = 'S'\r\n elif f == s and outcome(m, f):\r\n ans = 'M'\r\n elif s == m and outcome(f, s):\r\n ans = 'F'\r\n \r\n print(ans)\r\n\r\nsolve()",
"f = input()\r\nm = input()\r\ns = input()\r\ngame = [f, m, s]\r\nwin = 3\r\nif (game.count(\"rock\")== 1 and game.count(\"scissors\") == 2):\r\n\twin = game.index(\"rock\")\r\nelif (game.count(\"scissors\") == 1 and game.count(\"paper\") == 2):\r\n\twin = game.index(\"scissors\")\r\nelif (game.count(\"paper\") == 1 and game.count(\"rock\") == 2):\r\n\twin = game.index(\"paper\")\r\nelse:\r\n\tprint(\"?\")\r\nif (win == 0):\r\n\tprint(\"F\")\r\nelif (win == 1):\r\n\tprint(\"M\")\r\nelif (win == 2):\r\n\tprint(\"S\")",
"t = ['rock','paper','scissors','rock']\nn = ['F','M','S']\nl = []\nl.append (input())\nl.append (input())\nl.append (input())\nf = True\nfor i in range(2):\n for k in range(1,3):\n if l[i] == l[i-k]:\n for z in range(3):\n if l[i] == t[z]:\n if k == 1 and l[i-2] == t[z+1]:\n print(n[i-2])\n f = False\n break\n elif k==2 and l[i-1] ==t[z+1]:\n print(n[i-1])\n f = False\n break\n if f == False:\n break\n if f == False:\n break\nif f:\n print('?')",
"def wins(x, y, z):\n # return True if x beats y and x beats z\n return (x =='rock' and y == z == 'scissors') or \\\n (x == 'scissors' and y == z == 'paper') or \\\n (x == 'paper' and y == z == 'rock')\n\nf = input()\nm = input()\ns = input()\n\nif wins(f, m, s):\n print('F')\nelif wins(m, f, s):\n print('M')\nelif wins(s, m, f):\n print('S')\nelse:\n print('?')\n",
"fm=input()\r\nmm=input()\r\nsm=input()\r\nf=0\r\nm=0\r\ns=0\r\na=[]\r\nb=['F','M','S']\r\nif fm==\"rock\" and sm==\"scissors\":\r\n f=f+1\r\nif fm==\"paper\" and sm==\"rock\":\r\n f=f+1\r\nif fm==\"scissors\" and sm==\"paper\":\r\n f=f+1\r\nif fm==\"rock\" and mm==\"scissors\":\r\n f=f+1\r\nif fm==\"paper\" and mm==\"rock\":\r\n f=f+1\r\nif fm==\"scissors\" and mm==\"paper\":\r\n f=f+1\r\n \r\nif mm==\"rock\" and sm==\"scissors\":\r\n m=m+1\r\nif mm==\"paper\" and sm==\"rock\":\r\n m=m+1\r\nif mm==\"scissors\" and sm==\"paper\":\r\n m=m+1\r\nif mm==\"rock\" and fm==\"scissors\":\r\n m=m+1\r\nif mm==\"paper\" and fm==\"rock\":\r\n m=m+1\r\nif mm==\"scissors\" and fm==\"paper\":\r\n m=m+1\r\n \r\nif sm==\"rock\" and mm==\"scissors\":\r\n s=s+1\r\nif sm==\"paper\" and mm==\"rock\":\r\n s=s+1\r\nif sm==\"scissors\" and mm==\"paper\":\r\n s=s+1\r\nif sm==\"rock\" and fm==\"scissors\":\r\n s=s+1\r\nif sm==\"paper\" and fm==\"rock\":\r\n s=s+1\r\nif sm==\"scissors\" and fm==\"paper\":\r\n s=s+1\r\na.append(f)\r\na.append(m)\r\na.append(s)\r\nk=max(a)\r\nc=0\r\nfor i in a:\r\n if k==i:\r\n c=c+1\r\nif c==1:\r\n print(b[a.index(k)])\r\nelse:\r\n print(\"?\")",
"fedor = input()\r\nmatroskin = input()\r\nsharik = input()\r\nif fedor == matroskin and matroskin == sharik:\r\n result = '?'\r\nelif (fedor == 'rock' and matroskin == 'scissors' and sharik == 'scissors') or \\\r\n (matroskin == 'paper' and fedor == 'scissors' and sharik == 'paper') or \\\r\n (sharik == 'rock' and fedor == 'paper' and matroskin == 'rock'):\r\n result = 'F'\r\nelif (fedor == 'paper' and matroskin == 'scissors' and sharik == 'paper') or \\\r\n (matroskin == 'rock' and fedor == 'scissors' and sharik == 'scissors') or \\\r\n (sharik == 'rock' and fedor == 'rock' and matroskin == 'paper'):\r\n result = 'M'\r\nelif (fedor == 'scissors' and matroskin == 'scissors' and sharik == 'rock') or \\\r\n (matroskin == 'paper' and fedor == 'paper' and sharik == 'scissors') or \\\r\n (sharik == 'paper' and fedor == 'rock' and matroskin == 'rock'):\r\n result = 'S'\r\nelse:\r\n result = '?'\r\nprint(result)",
"z = [input(), input(), input()]\r\n\r\nnames = {\r\n 0: 'F',\r\n 1: 'M',\r\n 2: 'S'\r\n}\r\n\r\nif (z.count('paper') == 1 and z.count('rock') == 2): print(names[z.index('paper')])\r\nelif (z.count('rock') == 1 and z.count('scissors') == 2): print(names[z.index('rock')])\r\nelif (z.count('scissors') == 1 and z.count('paper') == 2): print(names[z.index('scissors')])\r\n\r\nelse: print('?')\r\n",
"#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-28 16:21:09\nLastEditTime: 2021-11-28 16:31:45\nDescription: Rock-paper-scissors\nFilePath: CF48A.py\n'''\n\n\ndef func():\n gesture = []\n for _ in range(3):\n gesture.append(input().strip())\n \n if gesture.count(\"rock\") == 2 and gesture.count(\"paper\") == 1:\n result = gesture.index(\"paper\")\n elif gesture.count(\"paper\") == 2 and gesture.count(\"scissors\") == 1:\n result = gesture.index(\"scissors\")\n elif gesture.count(\"scissors\") == 2 and gesture.count(\"rock\") == 1:\n result = gesture.index(\"rock\")\n else:\n result = 3\n print([\"F\", \"M\", \"S\", \"?\"][result])\n \n\n\nif __name__ == '__main__':\n func()\n ",
"a=input()\r\nb=input()\r\nc=input()\r\nl=sorted([a,b,c])\r\nif l in [['paper','rock','rock'],['rock','scissors','scissors'],['paper','paper','scissors']]:\r\n for i in range(1,4):\r\n if l.count([a,b,c][i-1])==1:\r\n break\r\n if i==1:\r\n print('F')\r\n elif i==2:\r\n print('M')\r\n else:\r\n print('S')\r\nelse:\r\n print('?')",
"r='rock'\r\ns='scissors'\r\np='paper'\r\nF=input()\r\nM=input()\r\nS=input()\r\ndef win(F,M,S):\r\n if F==r:\r\n if M==s and S==s:\r\n return(\"F\")\r\n elif M==p and S==r:\r\n return(\"M\")\r\n elif S==p and M==r:\r\n return(\"S\")\r\n else:\r\n return(\"?\")\r\n if F==s:\r\n if M==p and S==p:\r\n return(\"F\")\r\n elif M==r and S==s:\r\n return(\"M\")\r\n elif S==r and M==s:\r\n return(\"S\")\r\n else:\r\n return(\"?\")\r\n if F==p:\r\n if M==r and S==r:\r\n return(\"F\")\r\n elif M==s and S==p:\r\n return(\"M\")\r\n elif S==s and M==p:\r\n return(\"S\")\r\n else:\r\n return(\"?\")\r\nprint(win(F,M,S))",
"z=[input()for i in' '*3]\r\nl=['F','S','M']\r\nfor i in range(3):\r\n f,m,s=z\r\n if m==s and(f[0]=='s'and m[0]=='p'or f[0]=='r'and m[0]=='s'or f[0]=='p'and m[0]=='r'):print(l[i]);break\r\n z=[z[-1]]+z[:2]\r\nelse:print('?')\r\n",
"from collections import Counter\r\ndef solve():\r\n f=input();m=input();s=input();a=[\"F\",f,\"M\",m,\"S\",s];t=[f,m,s];v=Counter(t)\r\n if len(v)==1 or len(v)==3:print(\"?\");return\r\n r,p,si=v.get(\"rock\",0),v.get(\"paper\",0),v.get(\"scissors\",0)\r\n if si==2 and p==1:print(\"?\");return\r\n if si==1 and p==2:print(a[a.index(\"scissors\")-1]);return\r\n if r==2 and si==1:print(\"?\");return\r\n if r==1 and si==2:print(a[a.index(\"rock\")-1])\r\n if p==2 and r==1:print(\"?\");return\r\n if p==1 and r==2:print(a[a.index(\"paper\")-1])\r\nsolve()\r\n\r\n",
"o = input()\nd = input()\nq = input()\nif (o == 'rock') and (d == 'scissors') and (q == 'scissors'):\n print('F')\nelif (o == 'scissors') and (d == 'paper') and (q == 'paper'):\n print('F')\nelif (o == 'paper') and (d == 'rock') and (q == 'rock'):\n print('F')\nelif (d == 'rock') and (o == 'scissors') and (q == 'scissors'): \n print('M')\nelif (d == 'scissors') and (o == 'paper') and (q == 'paper'):\n print('M') \nelif (d == 'paper') and (o == 'rock') and (q == 'rock'):\n print('M')\nelif (q == 'rock') and (o == 'scissors') and (d == 'scissors'): \n print('S')\nelif (q == 'scissors') and (o == 'paper') and (d == 'paper'):\n print('S') \nelif (q == 'paper') and (o == 'rock') and (d == 'rock'):\n print('S') \nelse:\n print('?')",
"f=input()\r\nm=input()\r\ns=input()\r\nif (f==\"rock\" and m==\"scissors\" and s==\"scissors\") or (f==\"scissors\" and m==\"paper\" and s==\"paper\") or (f==\"paper\" and m==\"rock\" and s==\"rock\"):\r\n print(\"F\")\r\nelif (f==\"scissors\" and m==\"rock\" and s==\"scissors\") or (f==\"paper\" and m==\"scissors\" and s==\"paper\") or (f==\"rock\" and m==\"paper\" and s==\"rock\"):\r\n print(\"M\")\r\nelif (f==\"scissors\" and m==\"scissors\" and s==\"rock\") or (f==\"paper\" and m==\"paper\" and s==\"scissors\") or (f==\"rock\" and m==\"rock\" and s==\"paper\"):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"def winner_search(a, b, c):\r\n if a == 'rock' and b == c == 'scissors':\r\n print('F')\r\n elif b == 'rock' and a == c == 'scissors':\r\n print('M')\r\n elif c == 'rock' and a == b == 'scissors':\r\n print('S')\r\n elif a == 'paper' and b == c == 'rock':\r\n print('F')\r\n elif b == 'paper' and a == c == 'rock':\r\n print('M')\r\n elif c == 'paper' and a == b == 'rock':\r\n print('S')\r\n elif a == 'scissors' and b == c == 'paper':\r\n print('F')\r\n elif b == 'scissors' and a == c == 'paper':\r\n print('M')\r\n elif c == 'scissors' and a == b == 'paper':\r\n print('S')\r\n else:\r\n print('?')\r\na, b, c = input(), input(), input()\r\nwinner_search(a, b, c)",
"def wins(x, y, z):\n # return True if x beats y and x beats z\n return (x =='rock' and y == z == 'scissors') or \\\n (x == 'scissors' and y == z == 'paper') or \\\n (x == 'paper' and y == z == 'rock')\n\nn = ['F', 'M', 'S']\na = [input() for i in range(3)] # a[0], a[1], a[2] being the three lines of input\nfor i in range(3):\n if wins(a[i], a[(i+1)%3], a[(i+2)%3]): # loop through all possibilities/arrangements\n print(n[i])\n quit()\nprint('?')\n",
"def fu(a,b):\r\n\tif a==\"scissors\" and b==\"paper\":\r\n\t\treturn True\r\n\telif a==\"rock\" and b==\"scissors\":\r\n\t\treturn True\r\n\telif a==\"paper\" and b==\"rock\":\r\n\t\treturn True\r\n\treturn False\r\n\r\nf=input()\r\nm=input()\r\ns=input()\r\n\r\nif fu(f,m) and fu(f,s):\r\n\tprint(\"F\")\r\nelif fu(m,f) and fu(m,s):\r\n\tprint(\"M\")\r\nelif fu(s,f) and fu(s,m):\r\n\tprint(\"S\")\r\nelse:\r\n\tprint(\"?\")",
"jokenpo = [\"rock\", \"paper\", 'scissors']\n\nF = input()\nM = input()\nS = input()\n\n\"\"\"\nfrom itertools import cycle\npool = cycle(jokenpo)\n\"\"\"\n\ncontF = 0\ncontM = 0\ncontS = 0\n\nfor i in range(0, 3):\n if(jokenpo[i] == F):\n saveF = i\n\nfor i in range(0, 3):\n if(jokenpo[i] == M):\n saveM = i\n\n\nfor i in range(0, 3):\n if(jokenpo[i] == S):\n saveS = i\n\n#jokenpo.append('rock')\n\n#print(saveS,saveM,saveF)\nif(M == jokenpo[saveF-1] ):\n contF+=1\nif(S == jokenpo[saveF-1]):\n contF+=1\n#print(contF, jokenpo[saveF-1])\n\nif(F == jokenpo[saveM-1]):\n contM+=1\nif(S == jokenpo[saveM-1]):\n contM+=1\n\n\nif(M == jokenpo[saveS-1]):\n contS+=1\nif(F == jokenpo[saveS-1]):\n contS+=1\n\nif contS == 2:\n print('S')\nelif contM == 2:\n print('M')\nelif contF == 2:\n print('F')\nelse:\n print('?')\n\n \t\t\t\t\t\t\t\t \t\t\t\t \t\t \t\t\t \t\t\t\t",
"f = input()\r\nm = input()\r\ns = input()\r\n\r\ncondition = {'rock': 'scissors', 'paper': 'rock', 'scissors': 'paper'}\r\nif condition[f] == m and m == s:\r\n print('F')\r\nelif condition[m] == f and f == s:\r\n print('M')\r\nelif condition[s] == m and m == f:\r\n print('S')\r\nelse:\r\n print('?')\r\n",
"a = input()\r\nb = input()\r\nc = input()\r\nrock = 'rock'\r\npaper = 'paper'\r\nscissors = 'scissors'\r\nif ((a==rock)&(b==scissors)&(c==scissors))or((a==scissors)&(b==paper)&(c==paper))or((a==paper)&(b==rock)&(c==rock)):\r\n print('F')\r\nelif ((a==scissors)&(b==rock)&(c==scissors))or((a==paper)&(b==scissors)&(c==paper))or((a==rock)&(b==paper)&(c==rock)): \r\n print('M')\r\nelif ((a==scissors)&(b==scissors)&(c==rock))or((a==paper)&(b==paper)&(c==scissors))or((a==rock)&(b==rock)&(c==paper)): \r\n print('S')\r\nelse:\r\n print('?')",
"f = input()\nm = input()\ns = input()\nv = [f, m, s]\nt = [\"F\", \"M\", \"S\"]\nx = set(v)\nif len(x) == 3 or len(x) == 1:\n print('?')\n exit()\nc = [[\"paper\", \"rock\"], [\"rock\", \"scissors\"], [\"scissors\", \"paper\"]]\nw = [w for w in c if x == set(w)][0]\nif v.count(w[0]) == 2:\n print('?')\nelse:\n print(t[v.index(w[0])])\n",
"#q17 Rock-paper-scissors\r\nF=input()\r\nM=input()\r\nS=input()\r\ndic1={'rock':'paper','paper':'scissors','scissors':'rock'}\r\n\r\nif F==M and dic1[F]==S: print('S')\r\nelif S==M and dic1[S]==F: print('F')\r\nelif F==S and dic1[F]==M: print('M')\r\nelse: print('?')",
"d = {0:'F', 1:'M', 2:'S'}\r\ng = []\r\nfor i in range(3):\r\n g.append(input())\r\nif g.count('rock') == 1 and g.count('scissors') == 2:\r\n print(d[g.index('rock')])\r\nelif g.count('paper') == 1 and g.count('rock') == 2:\r\n print(d[g.index('paper')])\r\nelif g.count('scissors') == 1 and g.count('paper') == 2:\r\n print(d[g.index('scissors')])\r\nelse:\r\n print('?')\r\n",
"t=[]\r\ns=['F','M','S']\r\nfor i in range(3):\r\n t.append(input())\r\n\r\n\r\nif t.count('rock')==1 and t.count('scissors')==2:\r\n print(s[t.index('rock')])\r\nelif t.count('paper')==1 and t.count('rock')==2:\r\n print(s[t.index('paper')])\r\nelif t.count('scissors')==1 and t.count('paper')==2:\r\n print(s[t.index('scissors')])\r\nelse:\r\n print('?')\r\n \r\n\r\n\r\n \r\n",
"\r\ndef who_wins():\r\n players = {\"F\":\"\" , \"M\":\"\" , \"S\":\"\"}\r\n choices = []\r\n for i in players.keys():\r\n players.update({i:input()})\r\n for i in players.values():\r\n choices.append(i)\r\n\r\n number_of_each_choice = {x:choices.count(x) for x in set(choices)}\r\n #print(number_of_each_choice)\r\n max_choice = max(number_of_each_choice, key= lambda x: number_of_each_choice[x])\r\n #key function here is called for each key in dictonary\r\n #print(max_choice)\r\n min_choice = min(number_of_each_choice, key= lambda x: number_of_each_choice[x])\r\n #print(min_choice)\r\n if number_of_each_choice[max_choice] == 2:\r\n if min_choice[0] == \"r\" and max_choice[0] == \"s\":\r\n winner = [i for i in players if players[i] == min_choice]\r\n elif min_choice[0] == \"p\" and max_choice[0] == \"r\":\r\n winner = [i for i in players if players[i] == min_choice]\r\n elif min_choice[0] == \"s\" and max_choice[0] == \"p\":\r\n winner = [i for i in players if players[i] == min_choice]\r\n else:\r\n winner = \"?\"\r\n print(winner[0])\r\n else:\r\n print(\"?\") \r\n\r\n \r\n\r\n \r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n who_wins()",
"a=[input()[0] for _ in \" \"*3];i=set(a);p=len(set(a));e=[\"F\",\"M\",\"S\"];k={\"pr\":\"p\",\"rs\":\"r\",\"ps\":\"s\"}\r\nif p==1 or p==3:print(\"?\")\r\nelse :\r\n s=k.get(\"\".join(sorted(i)))\r\n if a.count(s)>1:print(\"?\")\r\n else:print(e[a.index(s)])\r\n\r\n\r\n",
"f=input()\r\nm=input()\r\ns=input()\r\nf=f[0]\r\nm=m[0]\r\ns=s[0]\r\nif (f==\"r\" and m==\"s\" and s==\"s\") or (f==\"s\" and m==\"p\" and s==\"p\") or (f==\"p\" and m==\"r\" and s==\"r\"):\r\n print(\"F\")\r\nelif (f==\"s\" and m==\"r\" and s==\"s\") or (f==\"p\" and m==\"s\" and s==\"p\") or (f==\"r\" and m==\"p\" and s==\"r\"):\r\n print(\"M\")\r\nelif (f==\"s\" and m==\"s\" and s==\"r\") or (f==\"p\" and m==\"p\" and s==\"s\") or (f==\"r\" and m==\"r\" and s==\"p\"):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")\r\n",
"l=[]\r\nfor i in range(3):\r\n l.append(str(input( )))\r\n\r\nx=l[:]\r\nx= set(x)\r\n\r\nif len(x)!=2:\r\n print(\"?\")\r\nelse:\r\n if l[1]==l[2] and l[0]!=l[1]:\r\n if l[1]== 'rock' and l[0]=='paper' or l[1]=='paper' and l[0]=='scissors' or l[1]=='scissors' and l[0]=='rock':\r\n print(\"F\")\r\n else:\r\n print(\"?\")\r\n elif l[1]==l[0] and l[0]!=l[2]:\r\n if l[1]== 'rock' and l[2]=='paper' or l[1]=='paper' and l[2]=='scissors' or l[1]=='scissors' and l[2]=='rock':\r\n\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\n elif l[2]==l[0] and l[0]!=l[1]:\r\n if l[0]== 'rock' and l[1]=='paper' or l[0]=='paper' and l[1]=='scissors' or l[0]=='scissors' and l[1]=='rock':\r\n\r\n print(\"M\")\r\n else:\r\n print(\"?\")\r\n",
"game = []\r\nc = {0: 'F', 1: 'M', 2: 'S'}\r\nfor i in range(3):\r\n game.append(input()[0])\r\nif game.count('p') == 1 and game.count('r') == 2:\r\n print(c[game.index('p')])\r\nelif game.count('s') == 1 and game.count('p') == 2:\r\n print(c[game.index('s')])\r\nelif game.count('r') == 1 and game.count('s') == 2:\r\n print(c[game.index('r')])\r\nelse:\r\n print('?')\r\n\r\n# CodeForcesian\r\n# ♥\r\n# اگه میتونی تصور کنی پس حتما میتونی انجامش بدی\r\n",
"f=input()\r\nm=input()\r\ns=input()\r\n\r\ndef win(s1, s2):\r\n # Returns True if s2 beats s1\r\n if s1=='rock' and s2=='paper':\r\n return True\r\n if s1=='paper' and s2=='scissors':\r\n return True\r\n if s1=='scissors' and s2=='rock':\r\n return True\r\n return False\r\n\r\nif win(m, f) and win(s, f):\r\n print('F')\r\nelif win(f, m) and win(s, m):\r\n print('M')\r\nelif win(m, s) and win(f, s):\r\n print('S')\r\nelse:\r\n print('?')",
"ROCK = \"rock\"\nPAPER = \"paper\"\nSCISSORS = \"scissors\"\n\nSCORE = {ROCK: 0, PAPER: 1, SCISSORS: 2}\n\nfyodor = SCORE[input()]\nmatroskin = SCORE[input()]\nsharic = SCORE[input()]\n\n\ndef wins(move1, move2):\n return (3 + move1 - move2) % 3 == 1\n\n\nif wins(fyodor, matroskin) and wins(fyodor, sharic):\n print(\"F\")\nelif wins(matroskin, fyodor) and wins(matroskin, sharic):\n print(\"M\")\nelif wins(sharic, fyodor) and wins(sharic, matroskin):\n print(\"S\")\nelse:\n print(\"?\")\n",
"r = { 'scissors': 'paper', 'paper': 'rock', 'rock': 'scissors'}\na = tuple(input() for i in \"'''\")\nfor i in (0, 1, 2):\n if a.count(a[i]) == 1 and a.count(a[(i + 1) % 3]) == 2 and r[a[i]] == a[(i + 1) % 3]:\n exit(print('FMS'[i]))\nprint('?')",
"a=[input()for _ in[0]*3]\r\nd=dict(zip('rsp','spr'))\r\nr='FMS'\r\nfor i in range(3):\r\n if sum(x[0]==d[a[i][0]] for x in a)==2:\r\n print(r[i])\r\n exit()\r\nprint('?')",
"a = []\r\na.append(input())\r\na.append(input())\r\na.append(input())\r\n\r\nfor i in range(3):\r\n if a[i] == 'rock':\r\n a[i] = 1\r\n elif a[i] == 'paper':\r\n a[i] = 2\r\n else:\r\n a[i] = 3\r\n\r\nc = list(a)\r\nc.sort()\r\nif c == [1, 3, 3]:\r\n if a[0] == 1:\r\n print('F')\r\n elif a[1] == 1:\r\n print('M')\r\n else:\r\n print('S')\r\nelif c == [1, 1, 2]:\r\n if a[0] == 2:\r\n print('F')\r\n elif a[1] == 2:\r\n print('M')\r\n else:\r\n print('S')\r\nelif c == [2, 2, 3]:\r\n if a[0] == 3:\r\n print('F')\r\n elif a[1] == 3:\r\n print('M')\r\n else:\r\n print('S')\r\nelse:\r\n print('?')\r\n \r\n \r\n \r\n \r\n \r\n \r\n",
"n, v = ['F', 'M', 'S'], [['rock', 'paper', 'scissors'].index(input()) for i in range(3)]\nfor i in range(3):\n if v[(i - 1) % 3] == (v[i] - 1) % 3 and v[(i + 1) % 3] == (v[i] - 1) % 3:\n print(n[i])\n exit()\nprint('?')\n",
"a=input()\r\nb=input()\r\nc=input()\r\nif (a==b or b==c or a==c) and not(a==b==c):\r\n if b==c:\r\n if a=='rock' and b=='scissors': print('F')\r\n elif a=='paper' and b=='rock': print('F')\r\n elif a=='scissors' and b=='paper': print('F')\r\n else: print('?')\r\n if a==c:\r\n if b=='rock' and a=='scissors': print('M')\r\n elif b=='paper' and a=='rock': print('M')\r\n elif b=='scissors' and a=='paper': print('M')\r\n else: print('?')\r\n if b==a:\r\n if c=='rock' and b=='scissors': print('S')\r\n elif c=='paper' and b=='rock': print('S')\r\n elif c=='scissors' and b=='paper': print('S')\r\n else: print('?')\r\nelse: print('?')\r\n",
"F=input()\r\nM=input()\r\nS=input()\r\n \r\nBeater={\"rock\":\"paper\",\"paper\":\"scissors\",\"scissors\":\"rock\"}\r\n \r\nif(F==M and S==Beater[F]):\r\n print(\"S\")\r\nelif(F==S and M==Beater[F]):\r\n print(\"M\")\r\nelif(S==M and F==Beater[S]):\r\n print(\"F\")\r\nelse:\r\n print(\"?\")",
"def win(a,b):\r\n if a == \"rock\":\r\n if(b == \"scissors\"):\r\n return True\r\n elif a == \"scissors\":\r\n if(b == \"paper\"):\r\n return True\r\n elif a == \"paper\":\r\n if(b == \"rock\"):\r\n return True\r\n return False\r\n\r\n\r\nli = str(input()), str(input()) , str(input())\r\n\r\n\r\nif li[0] == li[1] == li[2] or (li[0]!=li[1] and li[1]!=li[2] and li[0]!=li[2]):\r\n print('?')\r\nelse:\r\n winner = \"?\"\r\n if win(li[0],li[1]) and win(li[0],li[2]):\r\n winner = \"F\"\r\n elif win(li[1],li[0]) and win(li[1],li[2]):\r\n winner = \"M\"\r\n elif win(li[2],li[0]) and win(li[2],li[1]):\r\n winner = \"S\"\r\n print(winner)\r\n ",
"def beats(a,b,c):\r\n return b == c and (a == \"rock\" and b == \"scissors\" or a == \"paper\" and b == \"rock\" or a == \"scissors\" and b == \"paper\")\r\nf,m,s = input().lower(), input().lower(), input().lower()\r\nif beats(f,m,s):\r\n print(\"F\")\r\nelif beats(m,f,s):\r\n print(\"M\")\r\nelif beats(s,m,f):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"from collections import defaultdict\nF = None\nM = None\nS = None\nc = defaultdict(set)\n\nfor i in range(3):\n if i == 0:\n F = input()\n c[F].add('F')\n elif i == 1:\n M = input()\n c[M].add('M')\n elif i == 2:\n S = input()\n c[S].add('S')\n else:\n raise Exception\n\nif len(c) == 3 or len(c) == 1:\n print('?')\nelse:\n keys = set()\n for key in c:\n keys.add(key)\n if 'rock' in keys and 'scissors' in keys:\n if len(c['rock']) == 2:\n print('?')\n else:\n print(next(iter(c['rock'])))\n\n if 'scissors' in keys and 'paper' in keys:\n if len(c['scissors']) == 2:\n print('?')\n else:\n print(next(iter(c['scissors'])))\n\n if 'paper' in keys and 'rock' in keys:\n if len(c['paper']) == 2:\n print('?')\n else:\n print(next(iter(c['paper'])))\n",
"f = input()\r\nm = input()\r\ns = input()\r\nlst = [f, m, s]\r\norder = [\"rock\", \"scissors\", \"paper\"]\r\nif (f==m and m==s) or (f!=m and f!=s and m!=s):\r\n print(\"?\")\r\nelif f==m:\r\n if f==\"rock\":\r\n if s==\"scissors\":\r\n print(\"?\")\r\n else:\r\n print(\"S\")\r\n elif f==\"scissors\":\r\n if s==\"paper\":\r\n print(\"?\")\r\n else:\r\n print(\"S\")\r\n elif f==\"paper\":\r\n if s==\"rock\":\r\n print(\"?\")\r\n else:\r\n print(\"S\")\r\n\r\nelif s==m:\r\n if s==\"rock\":\r\n if f==\"scissors\":\r\n print(\"?\")\r\n else:\r\n print(\"F\")\r\n elif s==\"scissors\":\r\n if f==\"paper\":\r\n print(\"?\")\r\n else:\r\n print(\"F\")\r\n elif s==\"paper\":\r\n if f==\"rock\":\r\n print(\"?\")\r\n else:\r\n print(\"F\")\r\n\r\nelif f==s:\r\n if f==\"rock\":\r\n if m==\"scissors\":\r\n print(\"?\")\r\n else:\r\n print(\"M\")\r\n elif f==\"scissors\":\r\n if m==\"paper\":\r\n print(\"?\")\r\n else:\r\n print(\"M\")\r\n elif f==\"paper\":\r\n if m==\"rock\":\r\n print(\"?\")\r\n else:\r\n print(\"M\")\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n",
"gestures = {\r\n 'rock': 1,\r\n 'scissors': 2,\r\n 'paper': 3\r\n}\r\n\r\nrules = {\r\n (1, 1): 0,\r\n (1, 2): 1,\r\n (1, 3): 0,\r\n (2, 1): 0,\r\n (2, 2): 0,\r\n (2, 3): 1,\r\n (3, 1): 1,\r\n (3, 2): 0,\r\n (3, 3): 0\r\n}\r\n\r\n\r\ndef get_input():\r\n f = input()\r\n m = input()\r\n s = input()\r\n return {\r\n 'F': gestures[f],\r\n 'M': gestures[m],\r\n 'S': gestures[s]\r\n }\r\n\r\n\r\ndef play(gestures: dict) -> str:\r\n result = dict()\r\n for k in gestures:\r\n result[k] = 0\r\n\r\n for i in gestures:\r\n for j in gestures:\r\n pair = (gestures[i], gestures[j])\r\n result[i] += rules[pair]\r\n\r\n for k in result:\r\n if result[k] == 2:\r\n return k\r\n return '?'\r\n\r\n\r\nif __name__ == \"__main__\":\r\n gstrs = get_input()\r\n r = play(gstrs)\r\n print(r)",
"F = input()\nM = input()\nS = input()\n\ndef convert(a, b):\n if a == \"rock\" and b == \"scissors\":\n return a\n elif a == \"rock\" and b == \"paper\":\n return b\n elif a == \"scissors\" and b == \"rock\":\n return b\n elif a == \"scissors\" and b == \"paper\":\n return a\n elif a == \"paper\" and b == \"rock\":\n return a\n elif a == \"paper\" and b == \"scissors\":\n return b\n \n\nif F == M and M == S:\n print(\"?\")\nelif F != M and M != S and F != S:\n print(\"?\")\nelif F != M and M == S:\n if convert(F, M) == F:\n print(\"F\")\n else:\n print(\"?\")\nelif M != F and F == S:\n if convert(F, M) == M:\n print(\"M\")\n else:\n print(\"?\")\nelif S != M and M == F:\n if convert(S, M) == S:\n print(\"S\")\n else:\n print(\"?\")\n",
"a = input()\r\nb = input()\r\nc = input()\r\nif((a==b==\"paper\" and c==\"rock\")or(a==b==\"rock\" and c==\"scissors\")or(a==b==\"scissors\" and c==\"paper\")or(b==c==\"paper\" and a==\"rock\")or(b==c==\"rock\" and a==\"scissors\")or(b==c==\"scissors\" and a==\"paper\")or(a==c==\"paper\" and b==\"rock\")or(a==c==\"rock\" and b==\"scissors\")or(a==c==\"scissors\" and b==\"paper\")):\r\n print(\"?\")\r\nelif((b==c==\"rock\" and a==\"paper\")or(b==c==\"scissors\" and a==\"rock\")or(b==c==\"paper\" and a==\"scissors\")):\r\n print(\"F\")\r\nelif((a==c==\"rock\" and b==\"paper\")or(a==c==\"scissors\" and b==\"rock\")or(a==c==\"paper\" and b==\"scissors\")):\r\n print(\"M\")\r\nelif((a==b==\"rock\" and c==\"paper\")or(a==b==\"scissors\" and c==\"rock\")or(a==b==\"paper\" and c==\"scissors\")):\r\n print(\"S\")\r\nelif(a!=b!=c):\r\n print(\"?\")\r\nelse:\r\n print(\"?\")\r\n \r\n\r\n",
"n = 3\r\nls =[]\r\nwhile n > 0:\r\n ls.append(input())\r\n n -= 1\r\n\r\nplayers = ['F', 'M', 'S']\r\n\r\nr = ls.count('rock')\r\np = ls.count('paper')\r\ns = ls.count('scissors')\r\n\r\nif r == 3 or p == 3 or s == 3:\r\n print('?')\r\nelif r == 2 and p == 1:\r\n x = ls.index('paper')\r\n print(players[x])\r\nelif r == 2 and s == 1:\r\n print('?')\r\nelif r == 1 and p == 2 :\r\n print('?')\r\nelif r == 1 and s ==2:\r\n x = ls.index('rock')\r\n print(players[x])\r\nelif r == 1 and p == 1 and s == 1:\r\n print('?')\r\nelif p ==2 and s ==1:\r\n x = ls.index('scissors')\r\n print(players[x])\r\nelif p==1 and s == 2:\r\n print('?')\r\n ",
"f=input()\r\nm=input()\r\ns=input()\r\nif f==m or f==s or m==s:\r\n if f==m and f==s and m==s:\r\n print(\"?\")\r\n else:\r\n if f==m:\r\n if s[0]=='p' and f[0]=='r':\r\n print('S')\r\n elif s[0]=='s' and f[0]=='p':\r\n print('S')\r\n elif s[0]=='r' and f[0]=='s':\r\n print('S')\r\n else:\r\n print('?')\r\n elif f==s:\r\n if m[0]=='p' and f[0]=='r':\r\n print('M')\r\n elif m[0]=='s' and f[0]=='p':\r\n print('M')\r\n elif m[0]=='r' and f[0]=='s':\r\n print('M')\r\n else:\r\n print('?')\r\n elif m==s:\r\n if f[0]=='p' and m[0]=='r':\r\n print('F')\r\n elif f[0]=='s' and m[0]=='p':\r\n print('F')\r\n elif f[0]=='r' and m[0]=='s':\r\n print('F')\r\n else:\r\n print('?')\r\nelse:\r\n print(\"?\")",
"f = input()\r\nm = input()\r\ns = input()\r\nif (f == \"paper\" and (m == s and m == \"rock\")):\r\n print(\"F\")\r\nelif (f == \"scissors\" and (m == s and m == \"paper\")):\r\n print(\"F\")\r\nelif (f == \"rock\" and (m == s and m == \"scissors\")):\r\n print(\"F\")\r\nelif (m == \"paper\" and (f == s and f == \"rock\")):\r\n print(\"M\")\r\nelif (m == \"rock\" and (f == s and f == \"scissors\")):\r\n print(\"M\")\r\nelif (m == \"scissors\" and (f == s and f == \"paper\")):\r\n print(\"M\")\r\nelif (s == \"paper\" and (f == m and f == \"rock\")):\r\n print(\"S\")\r\nelif (s == \"scissors\" and (f == m and f == \"paper\")):\r\n print(\"S\")\r\nelif (s == \"rock\" and (f == m and f == \"scissors\")):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"\"\"\"####///*drunk\"\"\"\r\ndef ind(x):\r\n if x==0:\r\n print(\"F\")\r\n exit()\r\n elif x==1:\r\n print(\"M\")\r\n exit()\r\n elif x==2 :\r\n print(\"S\")\r\n exit()\r\nll=[]\r\nfor i in range(3):\r\n ll.append(input())\r\nx=len(set(ll))\r\nif ll.count(\"rock\")==1 and x==2 and \"scissors\" in ll:\r\n print(ind(ll.index(\"rock\")))\r\nelif ll.count(\"scissors\")==1 and x==2 and \"paper\" in ll:\r\n print(ind(ll.index(\"scissors\")))\r\nelif ll.count(\"paper\")==1 and x==2 and \"rock\" in ll:\r\n print(ind(ll.index(\"paper\")))\r\n exit()\r\nelse:\r\n print(\"?\")",
"__author__ = 'widoc'\r\n\r\nwin_combo = {'rock': ['scissors', 'paper'],\r\n 'paper': ['rock', 'scissors'],\r\n 'scissors': ['paper', 'rock']}\r\n\r\nF = input()\r\nM = input()\r\nS = input()\r\n\r\nif (win_combo[F][0] == M) and (win_combo[F][0] == S):\r\n print('F')\r\nelif (win_combo[M][0] == F) and (win_combo[M][0] == S):\r\n print('M')\r\nelif (win_combo[S][0] == F) and (win_combo[S][0] == M):\r\n print('S')\r\nelse:\r\n print('?')\r\n\r\n",
"import sys\r\n\r\nplayers = sys.stdin.read().splitlines()\r\n\r\nif (players[0] == \"rock\" and players[1] == \"scissors\" and players[2] == \"scissors\") or (players[0] == \"scissors\" and players[1] == \"paper\" and players[2] == \"paper\") or (players[0] == \"paper\" and players[1] == \"rock\" and players[2] == \"rock\"):\r\n print(\"F\")\r\nelif (players[1] == \"rock\" and players[0] == \"scissors\" and players[2] == \"scissors\") or (players[1] == \"scissors\" and players[0] == \"paper\" and players[2] == \"paper\") or (players[1] == \"paper\" and players[0] == \"rock\" and players[2] == \"rock\"):\r\n print(\"M\")\r\nelif (players[2] == \"rock\" and players[1] == \"scissors\" and players[0] == \"scissors\") or (players[2] == \"scissors\" and players[1] == \"paper\" and players[0] == \"paper\") or (players[2] == \"paper\" and players[1] == \"rock\" and players[0] == \"rock\"):\r\n print(\"S\")\r\nelse:\r\n print(\"?\")# 1690039481.267251",
"uncle = input()\ncat = input()\ndog = input()\n\nif ((uncle == 'rock' and cat == 'scissors' and dog == 'scissors') or \n (uncle == 'scissors' and cat == 'paper' and dog == 'paper') or\n (uncle == 'paper' and cat == 'rock' and dog == 'rock')):\n print('F')\nelif ((cat == 'rock' and uncle == 'scissors' and dog == 'scissors') or \n (cat == 'scissors' and uncle == 'paper' and dog == 'paper') or\n (cat == 'paper' and uncle == 'rock' and dog == 'rock')):\n print('M')\nelif ((dog == 'rock' and uncle == 'scissors' and cat == 'scissors') or \n (dog == 'scissors' and uncle == 'paper' and cat == 'paper') or\n (dog == 'paper' and uncle == 'rock' and cat == 'rock')):\n print('S')\nelse:\n print('?')\n\t\t\t \t\t \t\t \t\t \t \t\t \t\t \t \t\t\t",
"d={\r\n \"paper\":\"rock\",\r\n \"rock\":\"scissors\",\r\n \"scissors\":\"paper\"\r\n}\r\nf=input()\r\nm=input()\r\ns=input()\r\nif (f==m and m==s) or (f!=m and f!=s and m!=s):\r\n print(\"?\")\r\nelif d[f]==m and d[f]==s:\r\n print(\"F\")\r\nelif d[m]==f and d[m]==s:\r\n print(\"M\")\r\nelif d[s]==m and d[s]==f:\r\n print(\"S\")\r\nelse:\r\n print(\"?\")",
"uncle_fedor = input()\r\ncat_seaman = input()\r\ndog_baloon = input()\r\ngame = {'F':uncle_fedor, 'M':cat_seaman, 'S':dog_baloon}\r\nvalues = list(game.values())\r\nwin_value = '?'\r\nif values.count('paper') == 2:\r\n\tif values.count('scissors') == 1:\r\n\t\twin_value = 'scissors'\r\nelif values.count('scissors') == 2:\r\n\tif values.count('rock') == 1:\r\n\t\twin_value = 'rock'\r\nelif values.count('rock') == 2:\r\n\tif values.count('paper') == 1:\r\n\t\twin_value = 'paper'\r\n\r\nif win_value == '?':\r\n\tprint('?')\r\nelse:\r\n\tfor key in game.keys():\r\n\t\tif game[key] == win_value:\r\n\t\t\tprint(key)",
"b = []\r\nfor i in range(3):\r\n b.append(input())\r\nplayers =['F','M','S']\r\nif 'paper' in b and b.count('rock')==2:\r\n print(players[(b.index('paper'))])\r\nelif 'rock' in b and b.count('scissors')==2:\r\n print(players[(b.index('rock'))])\r\nelif 'scissors' in b and b.count('paper')==2:\r\n print(players[(b.index('scissors'))])\r\nelse:\r\n print('?')",
"# LUOGU_RID: 101450719\na=[*open(0)]\r\nfor i in range(3):\r\n if sum(x[0]==dict(zip('rsp','spr'))[a[i][0]]for x in a)==2:\r\n exit(print('FMS'[i]))\r\nprint('?')",
"F = input()\r\nM = input()\r\nS = input()\r\nl = [F, M, S]\r\nw = ['F', 'M', 'S']\r\nif len(set(l)) == 3 or len(set(l)) == 1:\r\n print('?')\r\nelse:\r\n if l.count('scissors') == 1 and 'paper' in l:\r\n print(w[l.index('scissors')])\r\n elif l.count('paper') == 1 and 'rock' in l:\r\n print(w[l.index('paper')])\r\n elif l.count('rock') == 1 and 'scissors' in l:\r\n print(w[l.index('rock')])\r\n else:\r\n print('?')\r\n \r\n \r\n",
"from sys import stdin; inp = stdin.readline\r\nfrom math import dist, ceil, floor, sqrt, log\r\nfrom collections import defaultdict, Counter, deque\r\ndef IA(sep=' '): return list(map(int, inp().split(sep)))\r\ndef QA(sep=' '): return deque(map(int, inp().split(sep)))\r\ndef FA(): return list(map(float, inp().split()))\r\ndef SA(): return inp().split()\r\ndef I(): return int(inp())\r\ndef F(): return float(inp())\r\ndef S(): return input()\r\ndef O(l:list): return ' '.join(map(str, l))\r\n# def win(plr:str, sel:str):\r\n # opp_tool = \r\n\r\ndef main():\r\n d = {'rock': 'scissors', 'paper':'rock', 'scissors': 'paper'}\r\n f = S()\r\n m = S()\r\n s = S()\r\n if d[f] == m and d[f] == s:\r\n return 'F'\r\n elif d[m] == f and d[m] == s:\r\n return 'M'\r\n elif d[s] == f and d[s] == m:\r\n return 'S'\r\n else:\r\n return '?'\r\n \r\nif __name__ == '__main__':\r\n print(main())",
"r=input\r\nf,m,s=r()[0],r()[0],r()[0]\r\nl=[['r','s','s'],['p','r','r'],['s','p','p']]\r\nif[f,m,s]in l:print('F')\r\nelif[m,f,s]in l:print('M')\r\nelif[s,m,f]in l:print(\"S\")\r\nelse:print(\"?\")",
"f = input()\r\nm = input()\r\ns = input()\r\n\r\nif f == m and m == s:\r\n print(\"?\")\r\nelif f == m and m != s:\r\n if s == \"rock\" and m == \"scissors\":\r\n print(\"S\")\r\n elif s == \"paper\" and m == \"rock\":\r\n print(\"S\")\r\n elif s == \"scissors\" and m == \"paper\":\r\n print(\"S\")\r\n else:\r\n print(\"?\")\r\nelif m == s and s != f:\r\n if f == \"rock\" and m == \"scissors\":\r\n print(\"F\")\r\n elif f == \"paper\" and m == \"rock\":\r\n print(\"F\")\r\n elif f == \"scissors\" and m == \"paper\":\r\n print(\"F\")\r\n else:\r\n print(\"?\")\r\nelif f == s and f != m:\r\n if m == \"rock\" and s == \"scissors\":\r\n print(\"M\")\r\n elif m == \"paper\" and s == \"rock\":\r\n print(\"M\")\r\n elif m == \"scissors\" and s == \"paper\":\r\n print(\"M\")\r\n else:\r\n print(\"?\")\r\nelse:\r\n print(\"?\")\r\n"
] | {"inputs": ["rock\nrock\nrock", "paper\nrock\nrock", "scissors\nrock\nrock", "scissors\npaper\nrock", "paper\npaper\nrock", "rock\npaper\nrock", "rock\nscissors\nrock", "paper\nscissors\nrock", "scissors\nscissors\nrock", "rock\nrock\npaper", "paper\nrock\npaper", "scissors\nrock\npaper", "rock\npaper\npaper", "paper\npaper\npaper", "scissors\npaper\npaper", "rock\nscissors\npaper", "paper\nscissors\npaper", "scissors\nscissors\npaper", "rock\nrock\nscissors", "paper\nrock\nscissors", "scissors\nrock\nscissors", "rock\npaper\nscissors", "paper\npaper\nscissors", "scissors\npaper\nscissors", "rock\nscissors\nscissors", "paper\nscissors\nscissors", "scissors\nscissors\nscissors"], "outputs": ["?", "F", "?", "?", "?", "M", "?", "?", "S", "S", "?", "?", "?", "?", "F", "?", "M", "?", "?", "?", "M", "?", "S", "?", "F", "?", "?"]} | UNKNOWN | PYTHON3 | CODEFORCES | 212 | |
2d13ff2f926ab901a329406d9816deef | Sereja and Contests | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: *Div*1 (for advanced coders) and *Div*2 (for beginner coders). Two rounds, *Div*1 and *Div*2, can go simultaneously, (*Div*1 round cannot be held without *Div*2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the *Div*1 round is always greater.
Sereja is a beginner coder, so he can take part only in rounds of *Div*2 type. At the moment he is taking part in a *Div*2 round, its identifier equals to *x*. Sereja remembers very well that he has taken part in exactly *k* rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.
Sereja is wondering: what minimum and what maximum number of *Div*2 rounds could he have missed? Help him find these two numbers.
The first line contains two integers: *x* (1<=≤<=*x*<=≤<=4000) — the round Sereja is taking part in today, and *k* (0<=≤<=*k*<=<<=4000) — the number of rounds he took part in.
Next *k* lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 *num*2 *num*1" (where *num*2 is the identifier of this *Div*2 round, *num*1 is the identifier of the *Div*1 round). It is guaranteed that *num*1<=-<=*num*2<==<=1. If Sereja took part in a usual *Div*2 round, then the corresponding line looks like: "2 *num*" (where *num* is the identifier of this *Div*2 round). It is guaranteed that the identifiers of all given rounds are less than *x*.
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
Sample Input
3 2
2 1
2 2
9 3
1 2 3
2 8
1 4 5
10 0
Sample Output
0 02 35 9 | [
"k, n = map(int, input().split())\r\nli = [0 for i in range(k-1)]\r\nfor i in range(n):\r\n x = input()\r\n if x.count(' ') == 1:\r\n a, b=map(int, x.split())\r\n li[b-1] = 1\r\n else:\r\n a, b, c= map(int, x.split())\r\n li[b-1] = 1\r\n li[c-1] = 1\r\nconsecutive = 0\r\nmn = 0\r\nmx = 0\r\nfor i in li:\r\n if i == 0:\r\n consecutive += 1\r\n else:\r\n mn += (consecutive+1)//2\r\n mx += consecutive\r\n consecutive = 0\r\nmn += (consecutive+1)//2\r\nmx += consecutive\r\nprint(mn, mx)",
"import math\r\nx,k=map(int,input().split(\" \"))\r\ngiven=[0 for x in range(x-1)]\r\nfor _ in range(k):\r\n a=list(map(int,input().split(\" \")))\r\n if a[0]==2:\r\n given[a[1]-1]=1\r\n else:\r\n given[a[2]-1]=1\r\n given[a[1]-1]=1\r\ncmax=0\r\nfor y in range(x-1):\r\n if given[y]==0:\r\n cmax=cmax+1\r\npp=0\r\nt=0\r\nss=x-1\r\nwhile t<ss:\r\n if t<ss-1 and given[t]==0 and given[t+1]==0:\r\n pp=pp+1\r\n t=t+2\r\n else:\r\n t=t+1\r\nprint(cmax-pp,cmax)\r\n\r\n\r\n\r\n \r\n\r\n ",
"n,k=map(int,input().split())\nrounds=[]\nrounds.append(0)\nrounds.append(n)\nfor i in range(k):\n arr=[int(i) for i in input().split()]\n if arr[0]==1:\n rounds.append(arr[1])\n rounds.append(arr[2])\n else:\n rounds.append(arr[1])\nrounds.sort()\nansmax=0\nansmin=0\nfor i in range(len(rounds)-1):\n if rounds[i+1]-rounds[i]-1>0:\n ansmin+=((rounds[i+1]-rounds[i]-1)//2)+((rounds[i+1]-rounds[i]-1)%2)\n ansmax+=rounds[i+1]-rounds[i]-1\nprint(ansmin,ansmax)\n\n\t \t \t\t \t \t \t\t\t \t\t \t \t \t",
"import sys\r\n\r\ninp = sys.stdin.readlines(); ii = 0\r\n\r\nout = []\r\n\r\nx, k = map(int, inp[ii].split())\r\nii += 1\r\n\r\nroundshappened = []\r\nfor round in range(k):\r\n data = [int(d) for d in inp[ii].split()]\r\n ii += 1\r\n for d in data[1:]:\r\n roundshappened.append(d)\r\n\r\nskipped = []\r\n\r\nfor x in range(1, x):\r\n if x not in roundshappened:\r\n skipped.append(x)\r\n\r\nused = []\r\n\r\nminimum = 0\r\n\r\nfor i in range(1, len(skipped)):\r\n if skipped[i - 1] + 1 == skipped[i] and skipped[i] not in used and skipped[i - 1] not in used:\r\n minimum += 1\r\n used.append(skipped[i - 1])\r\n used.append(skipped[i])\r\n\r\nminimum += len(skipped) - len(used)\r\n\r\nmaximum = len(skipped)\r\nsys.stdout.write(str(minimum) + ' ' + str(maximum))\r\n\r\n\r\n\r\n\r\n",
"I = lambda: map(int, input().split())\n\nx, k = I()\nR = [0, x]\n\nfor _ in range(k):\n _, *r = I()\n R += r\n\nR.sort()\nmax_ = min_ = 0\n\nfor i in range(len(R)-1):\n min_ += (R[i+1]-R[i]) // 2\n max_ += R[i+1]-R[i]-1\n\nprint(min_, max_)\n \t \t\t \t \t\t \t \t\t \t\t",
"R = lambda: map(int, input().split())\nx, k = R()\nli = [-1] * (x + 1)\nfor i in range(k):\n inp = list(R())\n if inp[0] == 2:\n li[inp[1]] = 2\n else:\n li[inp[1]] = 2\n li[inp[2]] = 1\nminm = 0\nmaxm = 0\nd = 0\nfor i in range(1, x):\n if li[i] > 0:\n d = 0\n else:\n d ^= 1\n minm += d\n maxm += 1\nprint(minm, maxm)",
"import math\nx, k = map(int, input().split())\nv = [0 for i in range(x+1)]\nv[0] = 1\nv[x] += 1\nfor i in range(k):\n p = [int(i) for i in input().split()]\n v[p[1]]+=1\n if p[0] == 1:\n v[p[2]]+=1\n\nmin = 0\nmax = 0\nflag = 0\nfor i in range(x):\n if v[i] == 0:\n max+=1\n if v[i+1] == 0 and flag == 0:\n # print(flag)\n min += 1\n flag = 1\n # flag %=2\n else:\n flag = 0\n\n# if min != 0 and flag = 0:\n# min //=2\n# min+=1\n\nprint(max - min, max)\n",
"x,k = list(map(int,input().split()))\r\narr = [1]*(x-1)\r\nfor i in range(k):\r\n a = list(map(int,input().split()))\r\n if a[0]==1:\r\n arr[a[2]-1]=0\r\n arr[a[1]-1]=0\r\nmaxv = sum(arr)\r\narrn = []\r\ncl = 0\r\nfor i in range(x-1):\r\n if arr[i]==1:\r\n arrn.append(i)\r\n cl+=1\r\nminv = 0\r\nif arrn:\r\n c = 0\r\n i = 0\r\n while i<cl-1:\r\n if arrn[i+1]-arrn[i]==1:\r\n c+=1\r\n i+=2\r\n else:\r\n i+=1\r\n minv = maxv - c\r\nprint(minv,maxv)",
"x,k = list(map(int,input().split()))\narr = [1]*(x-1)\nfor i in range(k):\n a = list(map(int,input().split()))\n if a[0]==1:\n arr[a[2]-1]=0\n arr[a[1]-1]=0\nmaxv = sum(arr)\narrn = []\ncl = 0\nfor i in range(x-1):\n if arr[i]==1:\n arrn.append(i)\n cl+=1\nminv = 0\nif arrn:\n c = 0\n i = 0\n while i<cl-1:\n if arrn[i+1]-arrn[i]==1:\n c+=1\n i+=2\n else:\n i+=1\n minv = maxv - c\nprint(minv,maxv)\n",
"from itertools import groupby\r\nR = lambda: map(int, input().split())\r\nx, k = R()\r\na = [0] * (x - 1)\r\nfor _ in range(k):\r\n l = list(R())\r\n if l[0] == 1:\r\n a[l[2] - 1] = 1\r\n a[l[1] - 1] = 1\r\nb = [len(list(g)) for k, g in groupby(a) if k == 0]\r\nprint(sum(l // 2 + l % 2 for l in b), sum(b))",
"import sys\r\ninput = sys.stdin.readline\r\n\r\na = set()\r\nb = set()\r\nx, k = map(int, input().split())\r\nfor i in range(k):\r\n w = list(map(int, input().split()))\r\n if w[0] == 1:\r\n a.add(w[1])\r\n b.add(w[2])\r\n else:\r\n a.add(w[1])\r\n\r\nc = set(range(1, x))\r\nc = c-a-b\r\nc = sorted(c)\r\nc2 = len(c)\r\nc1 = 0\r\ni = 0\r\nwhile i < c2-1:\r\n if c[i] == c[i+1] - 1:\r\n c1 += 1\r\n i += 1\r\n i += 1\r\nprint(c2-c1, c2)",
"x, k = [int(x) for x in input().split()]\r\nused = [0, x]\r\n\r\nfor i in range(k):\r\n a, *l = [int(x) for x in input().split()]\r\n used += l\r\n\r\nused.sort()\r\nm = M = 0\r\n\r\nfor i in range(len(used) - 1):\r\n M += used[i + 1] - used[i] - 1\r\n m += (used[i + 1] - used[i]) // 2\r\n\r\nprint(m, M)",
"x, k = map(int, input().split())\r\n\r\nnum = [0, x]\r\n\r\nfor _ in range(k):\r\n lst = list(map(int, input().split()))[1:]\r\n num.extend(lst)\r\n\r\nnum.sort()\r\n\r\na, b = 0, 0\r\n\r\nfor i in range(len(num) - 1):\r\n gap = num[i + 1] - num[i]\r\n a += gap // 2\r\n b += gap - 1\r\n\r\nprint(a, b)# 1692887859.291641",
"I = lambda: map(int, input().split())\r\n\r\nx, k = I()\r\nR = [0, x]\r\n\r\nfor _ in range(k):\r\n _, *r = I()\r\n R += r\r\n\r\nR.sort()\r\nmax_ = min_ = 0\r\n\r\nfor i in range(len(R)-1):\r\n min_ += (R[i+1]-R[i]) // 2\r\n max_ += R[i+1]-R[i]-1\r\n\r\nprint(min_, max_)",
"x,k=map(int,input().split())\r\nvis=[0]*(x)\r\n\r\nfor i in range(k):\r\n a=[int(x) for x in input().split()]\r\n if len(a)==2:\r\n q=a[1]\r\n vis[q]=1\r\n \r\n else:\r\n q,r=a[1],a[2]\r\n vis[q]=1\r\n vis[r]=1\r\nmaxi=0\r\nfor i in range(1,x):\r\n if vis[i]==0:\r\n maxi+=1\r\n \r\n#print(vis)\r\nmini=maxi\r\ni=2\r\nwhile i<x:\r\n if vis[i]==0 and vis[i-1]==0:\r\n mini-=1\r\n i+=1\r\n i+=1\r\nprint(mini,maxi)\r\n \r\n \r\n",
"x, k = [int(i) for i in input().split()]\nmissed = [0] * x\n\nfor i in range(k):\n divs = [int(i) for i in input().split()]\n if divs[0] == 1:\n missed[divs[1]] = 1\n missed[divs[2]] = 1\n else:\n missed[divs[1]] = 1\n\nmax_answer = missed.count(0) - 1\ngood_subarrs = 0\ni = 1\nwhile i <= x-1:\n if i < x-1 and missed[i] == 0 and missed[i+1] == 0:\n good_subarrs += 1\n i += 2\n else:\n i += 1\n\nprint(max_answer - good_subarrs, max_answer)"
] | {"inputs": ["3 2\n2 1\n2 2", "9 3\n1 2 3\n2 8\n1 4 5", "10 0", "10 2\n1 1 2\n1 8 9", "9 3\n1 4 5\n1 1 2\n1 6 7", "7 2\n2 3\n1 5 6", "81 28\n1 77 78\n1 50 51\n2 9\n1 66 67\n1 12 13\n1 20 21\n1 28 29\n1 34 35\n1 54 55\n2 19\n1 70 71\n1 45 46\n1 36 37\n2 47\n2 7\n2 76\n2 6\n2 31\n1 16 17\n1 4 5\n1 73 74\n1 64 65\n2 62\n2 22\n2 1\n1 48 49\n2 24\n2 40", "12 8\n1 4 5\n1 9 10\n2 3\n1 6 7\n2 1\n2 2\n2 8\n2 11", "54 25\n1 40 41\n2 46\n2 32\n2 8\n1 51 52\n2 39\n1 30 31\n2 53\n1 33 34\n1 42 43\n1 17 18\n1 21 22\n1 44 45\n2 50\n2 49\n2 15\n1 3 4\n1 27 28\n1 19 20\n1 47 48\n2 13\n1 37 38\n1 6 7\n2 35\n2 26", "90 35\n2 83\n2 86\n2 46\n1 61 62\n2 11\n1 76 77\n2 37\n2 9\n1 18 19\n2 79\n1 35 36\n1 3 4\n2 78\n2 72\n1 44 45\n2 31\n2 38\n2 65\n1 32 33\n1 13 14\n2 75\n2 42\n2 51\n2 80\n2 29\n1 22 23\n1 5 6\n2 53\n1 7 8\n1 24 25\n1 54 55\n2 84\n1 27 28\n2 26\n2 12", "98 47\n1 48 49\n2 47\n1 25 26\n2 29\n1 38 39\n1 20 21\n2 75\n2 68\n2 95\n2 6\n1 1 2\n1 84 85\n2 66\n1 88 89\n2 19\n2 32\n1 93 94\n1 45 46\n2 50\n1 15 16\n1 63 64\n1 23 24\n1 53 54\n1 43 44\n2 97\n1 12 13\n2 86\n2 74\n2 42\n1 40 41\n1 30 31\n1 34 35\n1 27 28\n2 81\n1 8 9\n2 73\n1 70 71\n2 67\n2 60\n2 72\n1 76 77\n1 90 91\n1 17 18\n2 11\n1 82 83\n1 58 59\n2 55", "56 34\n2 22\n2 27\n1 18 19\n1 38 39\n2 49\n1 10 11\n1 14 15\n2 40\n2 34\n1 32 33\n2 17\n1 24 25\n2 23\n2 52\n1 45 46\n2 28\n2 7\n1 4 5\n1 30 31\n2 21\n2 6\n1 47 48\n1 43 44\n1 54 55\n2 13\n1 8 9\n1 2 3\n2 41\n1 35 36\n1 50 51\n2 1\n2 29\n2 16\n2 53", "43 27\n1 40 41\n1 2 3\n1 32 33\n1 35 36\n1 27 28\n1 30 31\n1 7 8\n2 11\n1 5 6\n2 1\n1 15 16\n1 38 39\n2 12\n1 20 21\n1 22 23\n1 24 25\n1 9 10\n2 26\n2 14\n1 18 19\n2 17\n2 4\n2 34\n2 37\n2 29\n2 42\n2 13", "21 13\n1 6 7\n2 12\n1 8 9\n2 19\n1 4 5\n1 17 18\n2 3\n2 20\n1 10 11\n2 14\n1 15 16\n1 1 2\n2 13", "66 1\n1 50 51", "62 21\n2 34\n1 39 40\n1 52 53\n1 35 36\n2 27\n1 56 57\n2 43\n1 7 8\n2 28\n1 44 45\n1 41 42\n1 32 33\n2 58\n1 47 48\n2 10\n1 21 22\n2 51\n1 15 16\n1 19 20\n1 3 4\n2 25", "83 56\n2 24\n2 30\n1 76 77\n1 26 27\n1 73 74\n1 52 53\n2 82\n1 36 37\n2 13\n2 4\n2 68\n1 31 32\n1 65 66\n1 16 17\n1 56 57\n2 60\n1 44 45\n1 80 81\n1 28 29\n2 23\n1 54 55\n2 9\n2 1\n1 34 35\n2 5\n1 78 79\n2 40\n2 42\n1 61 62\n2 49\n2 22\n2 25\n1 7 8\n1 20 21\n1 38 39\n2 43\n2 12\n1 46 47\n2 70\n1 71 72\n2 3\n1 10 11\n2 75\n2 59\n1 18 19\n2 69\n2 48\n1 63 64\n2 33\n1 14 15\n1 50 51\n2 6\n2 41\n2 2\n2 67\n2 58", "229 27\n2 7\n1 64 65\n1 12 13\n2 110\n1 145 146\n2 92\n2 28\n2 39\n1 16 17\n2 164\n2 137\n1 95 96\n2 125\n1 48 49\n1 115 116\n1 198 199\n1 148 149\n1 225 226\n1 1 2\n2 24\n2 103\n1 87 88\n2 124\n2 89\n1 178 179\n1 160 161\n2 184", "293 49\n2 286\n2 66\n2 98\n1 237 238\n1 136 137\n1 275 276\n2 152\n1 36 37\n2 26\n2 40\n2 79\n2 274\n1 205 206\n1 141 142\n1 243 244\n2 201\n1 12 13\n1 123 124\n1 165 166\n1 6 7\n2 64\n1 22 23\n2 120\n1 138 139\n1 50 51\n2 15\n2 67\n2 45\n1 288 289\n1 261 262\n1 103 104\n2 249\n2 32\n2 153\n2 248\n1 162 163\n2 89\n1 94 95\n2 21\n1 48 49\n1 56 57\n2 102\n1 271 272\n2 269\n1 232 233\n1 70 71\n1 42 43\n1 267 268\n2 292", "181 57\n1 10 11\n1 4 5\n1 170 171\n2 86\n2 97\n1 91 92\n2 162\n2 115\n1 98 99\n2 134\n1 100 101\n2 168\n1 113 114\n1 37 38\n2 81\n2 169\n1 173 174\n1 165 166\n2 108\n2 121\n1 31 32\n2 67\n2 13\n2 50\n2 157\n1 27 28\n1 19 20\n2 109\n1 104 105\n2 46\n1 126 127\n1 102 103\n2 158\n2 133\n2 93\n2 68\n1 70 71\n2 125\n2 36\n1 48 49\n2 117\n1 131 132\n2 79\n2 23\n1 75 76\n2 107\n2 138\n1 94 95\n2 54\n1 87 88\n2 41\n1 153 154\n1 14 15\n2 60\n2 148\n1 159 160\n2 58", "432 5\n1 130 131\n2 108\n1 76 77\n1 147 148\n2 137", "125 45\n2 70\n2 111\n2 52\n2 3\n2 97\n2 104\n1 47 48\n2 44\n2 88\n1 117 118\n2 82\n1 22 23\n1 53 54\n1 38 39\n1 114 115\n2 93\n2 113\n2 102\n2 30\n2 95\n2 36\n2 73\n2 51\n2 87\n1 15 16\n2 55\n2 80\n2 121\n2 26\n1 31 32\n1 105 106\n1 1 2\n1 10 11\n2 91\n1 78 79\n1 7 8\n2 120\n2 75\n1 45 46\n2 94\n2 72\n2 25\n1 34 35\n1 17 18\n1 20 21", "48 35\n1 17 18\n2 20\n1 7 8\n2 13\n1 1 2\n2 23\n1 25 26\n1 14 15\n2 3\n1 45 46\n1 35 36\n2 47\n1 27 28\n2 30\n1 5 6\n2 11\n2 9\n1 32 33\n2 19\n2 24\n2 16\n1 42 43\n1 21 22\n2 37\n2 34\n2 40\n2 31\n2 10\n2 44\n2 39\n2 12\n2 29\n2 38\n2 4\n2 41", "203 55\n2 81\n2 65\n1 38 39\n1 121 122\n2 48\n2 83\n1 23 24\n2 165\n1 132 133\n1 143 144\n2 35\n2 85\n2 187\n1 19 20\n2 137\n2 150\n2 202\n2 156\n2 178\n1 93 94\n2 73\n2 167\n1 56 57\n1 100 101\n1 26 27\n1 51 52\n2 74\n2 4\n2 79\n2 113\n1 181 182\n2 75\n2 157\n2 25\n2 124\n1 68 69\n1 135 136\n1 110 111\n1 153 154\n2 123\n2 134\n1 36 37\n1 145 146\n1 141 142\n1 86 87\n2 10\n1 5 6\n2 131\n2 116\n2 70\n1 95 96\n1 174 175\n2 108\n1 91 92\n2 152", "51 38\n2 48\n2 42\n2 20\n2 4\n2 37\n2 22\n2 9\n2 13\n1 44 45\n1 33 34\n2 8\n1 18 19\n1 2 3\n2 27\n1 5 6\n1 40 41\n1 24 25\n2 16\n2 39\n2 50\n1 31 32\n1 46 47\n2 15\n1 29 30\n1 10 11\n2 49\n2 14\n1 35 36\n2 23\n2 7\n2 38\n2 26\n2 1\n2 17\n2 43\n2 21\n2 12\n2 28", "401 40\n1 104 105\n2 368\n1 350 351\n1 107 108\n1 4 5\n1 143 144\n2 369\n1 337 338\n2 360\n2 384\n2 145\n1 102 103\n1 88 89\n1 179 180\n2 202\n1 234 235\n2 154\n1 9 10\n1 113 114\n2 398\n1 46 47\n1 35 36\n1 174 175\n1 273 274\n1 237 238\n2 209\n1 138 139\n1 33 34\n1 243 244\n1 266 267\n1 294 295\n2 219\n2 75\n2 340\n1 260 261\n1 245 246\n2 210\n1 221 222\n1 328 329\n1 164 165", "24 16\n1 16 17\n1 1 2\n1 8 9\n1 18 19\n1 22 23\n1 13 14\n2 15\n2 6\n2 11\n2 20\n2 3\n1 4 5\n2 10\n2 7\n2 21\n2 12", "137 37\n2 108\n1 55 56\n2 20\n1 33 34\n2 112\n2 48\n2 120\n2 38\n2 74\n2 119\n2 27\n1 13 14\n2 8\n1 88 89\n1 44 45\n2 124\n2 76\n2 123\n2 104\n1 58 59\n2 52\n2 47\n1 3 4\n1 65 66\n2 28\n1 102 103\n2 81\n2 86\n2 116\n1 69 70\n1 11 12\n2 84\n1 25 26\n2 100\n2 90\n2 83\n1 95 96", "1155 50\n1 636 637\n1 448 449\n2 631\n2 247\n1 1049 1050\n1 1103 1104\n1 816 817\n1 1127 1128\n2 441\n2 982\n1 863 864\n2 186\n1 774 775\n2 793\n2 173\n2 800\n1 952 953\n1 492 493\n1 796 797\n2 907\n2 856\n2 786\n2 921\n1 558 559\n2 1090\n1 307 308\n1 1152 1153\n1 578 579\n1 944 945\n1 707 708\n2 968\n1 1005 1006\n1 1100 1101\n2 402\n1 917 918\n1 237 238\n1 191 192\n2 460\n1 1010 1011\n2 960\n1 1018 1019\n2 296\n1 958 959\n2 650\n2 395\n1 1124 1125\n2 539\n2 152\n1 385 386\n2 464", "1122 54\n2 1031\n1 363 364\n1 14 15\n1 902 903\n1 1052 1053\n2 170\n2 36\n2 194\n1 340 341\n1 1018 1019\n1 670 671\n1 558 559\n2 431\n2 351\n2 201\n1 1104 1105\n2 1056\n2 823\n1 274 275\n2 980\n1 542 543\n1 807 808\n2 157\n2 895\n1 505 506\n2 658\n1 484 485\n1 533 534\n1 384 385\n2 779\n2 888\n1 137 138\n1 198 199\n2 762\n1 451 452\n1 248 249\n2 294\n2 123\n2 948\n2 1024\n2 771\n2 922\n1 566 567\n1 707 708\n1 1037 1038\n2 63\n1 208 209\n1 738 739\n2 648\n1 491 492\n1 440 441\n2 651\n1 971 972\n1 93 94", "2938 48\n2 1519\n2 1828\n1 252 253\n1 2275 2276\n1 1479 1480\n2 751\n2 972\n2 175\n2 255\n1 1837 1838\n1 1914 1915\n2 198\n1 1686 1687\n1 950 951\n2 61\n1 840 841\n2 277\n1 52 53\n1 76 77\n2 795\n2 1680\n1 2601 2602\n2 2286\n2 2188\n2 2521\n2 1166\n2 1171\n2 2421\n1 1297 1298\n1 1736 1737\n1 991 992\n1 1048 1049\n2 756\n2 2054\n1 2878 2879\n1 1445 1446\n1 2539 2540\n2 1334\n2 2233\n2 494\n2 506\n1 1942 1943\n2 2617\n1 1991 1992\n2 1501\n1 2488 2489\n1 752 753\n2 2623", "2698 39\n2 710\n1 260 261\n2 174\n2 1697\n2 915\n1 2029 2030\n2 916\n2 2419\n2 323\n1 2130 2131\n2 1350\n1 64 65\n1 763 764\n1 939 940\n2 1693\n2 659\n2 2281\n2 761\n2 909\n1 1873 1874\n1 1164 1165\n2 2308\n2 504\n1 1035 1036\n1 2271 2272\n1 1085 1086\n1 1757 1758\n2 1818\n1 1604 1605\n1 517 518\n1 2206 2207\n2 636\n1 519 520\n2 1928\n1 1894 1895\n2 573\n2 2313\n1 42 43\n2 1529", "3999 0", "1 0", "10 5\n1 1 2\n2 3\n2 8\n1 4 5\n1 6 7", "4000 0"], "outputs": ["0 0", "2 3", "5 9", "3 5", "2 2", "2 3", "22 36", "0 0", "10 14", "25 40", "18 24", "5 5", "0 0", "0 0", "32 63", "16 27", "0 0", "98 187", "121 217", "61 98", "214 423", "40 62", "0 0", "71 123", "0 0", "177 333", "0 0", "52 86", "548 1077", "532 1038", "1444 2867", "1327 2640", "1999 3998", "0 0", "1 1", "2000 3999"]} | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
2d14cbaed2e88019a8850c627c775f85 | Analysis of Pathes in Functional Graph | You are given a functional graph. It is a directed graph, in which from each vertex goes exactly one arc. The vertices are numerated from 0 to *n*<=-<=1.
Graph is given as the array *f*0,<=*f*1,<=...,<=*f**n*<=-<=1, where *f**i* — the number of vertex to which goes the only arc from the vertex *i*. Besides you are given array with weights of the arcs *w*0,<=*w*1,<=...,<=*w**n*<=-<=1, where *w**i* — the arc weight from *i* to *f**i*.
Also you are given the integer *k* (the length of the path) and you need to find for each vertex two numbers *s**i* and *m**i*, where:
- *s**i* — the sum of the weights of all arcs of the path with length equals to *k* which starts from the vertex *i*; - *m**i* — the minimal weight from all arcs on the path with length *k* which starts from the vertex *i*.
The length of the path is the number of arcs on this path.
The first line contains two integers *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1010). The second line contains the sequence *f*0,<=*f*1,<=...,<=*f**n*<=-<=1 (0<=≤<=*f**i*<=<<=*n*) and the third — the sequence *w*0,<=*w*1,<=...,<=*w**n*<=-<=1 (0<=≤<=*w**i*<=≤<=108).
Print *n* lines, the pair of integers *s**i*, *m**i* in each line.
Sample Input
7 3
1 2 3 4 3 2 6
6 3 1 4 2 2 3
4 4
0 1 2 3
0 1 2 3
5 3
1 2 3 4 0
4 1 2 14 3
Sample Output
10 1
8 1
7 1
10 2
8 2
7 1
9 3
0 0
4 1
8 2
12 3
7 1
17 1
19 2
21 3
8 1
| [
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn,k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nw = list(map(int, input().split()))\r\npow_pos = a[:]\r\npow_mi = w[:]\r\npow_s = w[:]\r\npos = list(range(n))\r\nmi = [10 ** 18] * n\r\ns = [0] * n\r\nfor i in range(35):\r\n if k & (1 << i):\r\n s = [s[pow_pos[i]] + pow_s[i] for i in range(n)]\r\n mi = [min(pow_mi[i],mi[pow_pos[i]]) for i in range(n)]\r\n pos = [pos[j] for j in pow_pos]\r\n pow_s = [pow_s[pow_pos[i]] + pow_s[i] for i in range(n)]\r\n pow_mi = [min(pow_mi[i],pow_mi[pow_pos[i]]) for i in range(n)]\r\n pow_pos = [pow_pos[j] for j in pow_pos]\r\nfor i in range(n):\r\n print(s[i],mi[i])",
"n,k=map(int,input().split())\r\np=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\n\r\ndef calc(func,e):\r\n table1=[]\r\n table2=[p]\r\n now=[e]*n\r\n for i in range(n):\r\n now[i]=a[i]\r\n table1.append(now)\r\n for _ in range(35):\r\n now1=[0]*n\r\n now2=[0]*n\r\n for i in range(n):\r\n to=table2[-1][i]\r\n now1[i]=func(table1[-1][i],table1[-1][to])\r\n now2[i]=table2[-1][to]\r\n table1.append(now1)\r\n table2.append(now2)\r\n \r\n ans=[0]*n\r\n for i in range(n):\r\n tmp=k\r\n res=e\r\n now=i\r\n for j in range(35,-1,-1):\r\n if (tmp>>j)&1:\r\n res=func(res,table1[j][now])\r\n now=table2[j][now]\r\n tmp-=1<<j\r\n ans[i]=res\r\n \r\n return ans\r\n\r\nans1=calc(lambda x,y:x+y,0)\r\nans2=calc(min,10**18)\r\n\r\nfor x,y in zip(ans1,ans2):\r\n print(x,y)",
"LOG = 40\r\nMAXN = 101000\r\nn, k = map(int, input().split())\r\np = list(map(int, input().split()))\r\nw = list(map(int, input().split()))\r\ngo = [[0] * MAXN for _ in range(LOG)]\r\nsm = [[0] * MAXN for _ in range(LOG)]\r\nmn = [[0] * MAXN for _ in range(LOG)]\r\nfor i in range(n):\r\n go[0][i] = p[i]\r\n sm[0][i] = w[i]\r\n mn[0][i] = w[i]\r\nfor i in range(1, LOG):\r\n for j in range(n):\r\n go[i][j] = go[i - 1][go[i - 1][j]]\r\n sm[i][j] = sm[i - 1][j] + sm[i - 1][go[i - 1][j]]\r\n mn[i][j] = min(mn[i - 1][j], mn[i - 1][go[i - 1][j]])\r\nfor i in range(n):\r\n mni = 1e9\r\n total_sum = 0\r\n nk = k\r\n now = i\r\n for j in range(LOG - 1, -1, -1):\r\n if (1 << j) <= nk:\r\n nk -= (1 << j)\r\n total_sum += sm[j][now]\r\n mni = min(mni, mn[j][now])\r\n now = go[j][now]\r\n print(total_sum, mni)# 1691164312.8462024"
] | {"inputs": ["7 3\n1 2 3 4 3 2 6\n6 3 1 4 2 2 3", "4 4\n0 1 2 3\n0 1 2 3", "5 3\n1 2 3 4 0\n4 1 2 14 3", "1 1\n0\n10000", "1 2\n0\n10000", "1 10000000000\n0\n10000", "2 3\n0 0\n4 7", "2 3\n0 1\n4 7", "2 3\n1 0\n4 7", "2 3\n1 1\n4 7", "3 10\n0 1 2\n9240 5331 6721", "4 10\n2 1 2 1\n960 2596 3752 8303", "5 10\n0 2 2 0 2\n8473 9299 7399 4396 7275", "6 10\n0 3 3 5 3 5\n4845 6494 579 5025 2998 4787", "7 10\n4 6 4 6 4 2 0\n5590 6764 2775 3854 4798 348 3954", "8 10\n7 5 0 0 2 3 6 3\n2948 525 5789 4809 3961 6111 5209 8128", "20 10\n13 10 5 6 18 5 12 13 15 1 10 3 9 16 7 9 7 11 9 13\n2634 7980 171 3503 6601 9378 4618 8243 9343 1979 4172 7441 9722 9863 6041 4790 1737 7586 6461 228"], "outputs": ["10 1\n8 1\n7 1\n10 2\n8 2\n7 1\n9 3", "0 0\n4 1\n8 2\n12 3", "7 1\n17 1\n19 2\n21 3\n8 1", "10000 10000", "20000 10000", "100000000000000 10000", "12 4\n15 4", "12 4\n21 7", "15 4\n18 4", "18 4\n21 7", "92400 9240\n53310 5331\n67210 6721", "34728 960\n25960 2596\n37520 3752\n31667 2596", "84730 8473\n75890 7399\n73990 7399\n80653 4396\n73866 7275", "48450 4845\n49815 4787\n43900 579\n48108 4787\n46319 2998\n47870 4787", "48772 4798\n49894 3954\n45957 2775\n46984 3854\n47980 4798\n41507 348\n47928 3954", "50603 2948\n46163 525\n53444 2948\n52464 2948\n52596 2948\n53766 2948\n52090 5209\n55783 2948", "62163 1737\n45528 4172\n84573 171\n48662 1979\n48053 1979\n93780 9378\n49331 1979\n67772 1737\n49124 1979\n43335 1979\n41720 4172\n51931 1979\n48885 1979\n69392 1737\n65570 1737\n43953 1979\n61266 1737\n55345 1979\n45624 1979\n59757 228"]} | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
2d174b69461e55ae9529cf4af4ca99b1 | Area of Two Circles' Intersection | You are given two circles. Find the area of their intersection.
The first line contains three integers *x*1,<=*y*1,<=*r*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109,<=1<=≤<=*r*1<=≤<=109) — the position of the center and the radius of the first circle.
The second line contains three integers *x*2,<=*y*2,<=*r*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109,<=1<=≤<=*r*2<=≤<=109) — the position of the center and the radius of the second circle.
Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
Sample Input
0 0 4
6 0 4
0 0 5
11 0 5
Sample Output
7.25298806364175601379
0.00000000000000000000
| [
"from math import pi, sqrt\r\nfrom decimal import *\r\n\r\ngetcontext().prec = 100\r\ndef cos(x):\r\n getcontext().prec += 2\r\n i, lasts, s, fact, num, sign = 0, 0, 1, 1, 1, 1\r\n while s != lasts:\r\n lasts = s\r\n i += 2\r\n fact *= i * (i-1)\r\n num *= x * x\r\n sign *= -1\r\n s += num / fact * sign\r\n getcontext().prec -= 2\r\n return +s\r\n \r\n \r\ndef acos(x):\r\n mn, mx = Decimal(0), Decimal(pi)\r\n for i in range(1000):\r\n md = (mn+mx)/2\r\n if cos(md) <= x:\r\n mx = md\r\n else:\r\n mn = md\r\n return mx\r\n\r\ndef dis(x1,y1,x2,y2):\r\n return sqrt((x1-x2)**2+(y1-y2)**2)\r\n\r\ndef calculate_angle(x1,y1,x2,y2,x3,y3):\r\n v1 = (x1 - x2, y1 - y2)\r\n v2 = (x3 - x2, y3 - y2)\r\n dot_product = v1[0] * v2[0] + v1[1] * v2[1]\r\n magnitude_v1 = sqrt(v1[0] ** 2 + v1[1] ** 2)\r\n magnitude_v2 = sqrt(v2[0] ** 2 + v2[1] ** 2)\r\n \r\n # Calculate the angle in radians\r\n angle_radians = acos(dot_product / (magnitude_v1 * magnitude_v2))\r\n \r\n return angle_radians\r\n\r\ndef herons(x1,y1,x2,y2,x3,y3):\r\n side1 = dis(x1,y1,x2,y2)\r\n side2 = dis(x1,y1,x3,y3)\r\n side3 = dis(x3,y3,x2,y2)\r\n semip = (side1+side2+side3) / 2\r\n area = sqrt(semip*(semip-side1)*(semip-side2)*(semip-side3))\r\n return area\r\n\r\ndef solve():\r\n x1, y1, r1 = map(int, input().split())\r\n x2, y2, r2 = map(int, input().split())\r\n \r\n x1, y1, r1 = Decimal(x1), Decimal(y1), Decimal(r1)\r\n x2, y2, r2 = Decimal(x2), Decimal(y2), Decimal(r2)\r\n \r\n \r\n dcx, dcy = x2-x1, y2-y1\r\n d = dcx**2 + dcy**2\r\n \r\n if d >= (r1+r2)**2:\r\n print(\"0\")\r\n return\r\n \r\n if d <= (r2-r1)**2:\r\n print(\"%.7f\"%(Decimal(pi)*r1.min(r2)**2))\r\n return\r\n \r\n d = d.sqrt()\r\n \r\n ans = r1*r1*acos((d*d+r1*r1-r2*r2)/(2*d*r1)) + r2*r2*acos((d*d+r2*r2-r1*r1)/(2*d*r2))\r\n ans = ans - Decimal((d + r1 + r2) * (-d + r1 + r2) * (d + r1 - r2) * (d + r2 - r1)).sqrt()/2\r\n \r\n print(\"%.20f\"%(ans))\r\nsolve()\r\n\r\n",
"import math\r\nimport sys\r\nfrom random import randint as rn\r\nimport random\r\nimport functools\r\nfrom heapq import heappop, heappush\r\nimport decimal\r\nfrom decimal import Decimal\r\n\r\ndecimal.getcontext().prec = 100\r\n\r\npi = Decimal('3.141592653589793238462643383279502884197169399')\r\n\r\n\r\ndef dec_sin(x):\r\n res = Decimal(x)\r\n it = -1\r\n for i in range(3, 29 + 1, 2):\r\n res += Decimal(x) ** i / Decimal(math.factorial(i)) * it\r\n it *= -1\r\n\r\n return res\r\n\r\n\r\ndef dec_acos(x):\r\n return Decimal(math.atan2((1 - x ** 2).sqrt(), x))\r\n\r\n\r\ndef solve():\r\n x1, y1, r1 = map(int, input().split())\r\n x2, y2, r2 = map(int, input().split())\r\n\r\n if (x1 - x2) ** 2 + (y1 - y2) ** 2 >= (r1 + r2) ** 2:\r\n print('0.00000000000000000')\r\n return\r\n\r\n d = math.dist([x1, y1], [x2, y2])\r\n\r\n if max(r1, r2) >= min(r1, r2) + d:\r\n print('%.18f' % (math.pi * min(r1, r2) ** 2))\r\n return\r\n\r\n res = Decimal(0)\r\n d = Decimal((x1 - x2) ** 2 + (y1 - y2) ** 2)\r\n d = d.sqrt()\r\n\r\n for rr1, rr2 in [[r1, r2], [r2, r1]]:\r\n rr1 = Decimal(rr1)\r\n rr2 = Decimal(rr2)\r\n\r\n angle = dec_acos((rr2 ** 2 + d ** 2 - rr1 ** 2) / Decimal(2 * rr2 * d))\r\n seg = angle * rr2 ** 2 - rr2 ** 2 * (dec_sin(2 * angle) / 2)\r\n\r\n res += seg\r\n\r\n print('%.18f' % res)\r\n return\r\n\r\n\r\nif __name__ == '__main__':\r\n\r\n multitest = 0\r\n\r\n if multitest:\r\n t = int(sys.stdin.readline())\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n # gen()\r\n"
] | {"inputs": ["0 0 4\n6 0 4", "0 0 5\n11 0 5", "0 0 10\n9 0 1", "0 0 2\n2 2 2", "0 0 10\n5 0 5", "-9 8 7\n-9 8 5", "-60 -85 95\n-69 -94 95", "159 111 998\n161 121 1023", "6008 8591 6693\n5310 8351 7192", "-13563 -6901 22958\n-19316 -16534 18514", "-875463 79216 524620\n-891344 76571 536598", "-8907963 -8149654 8808560\n-8893489 -8125053 8830600", "-56452806 56199829 45467742\n-56397667 56292048 45489064", "-11786939 388749051 844435993\n-11696460 388789113 844535886", "-944341103 -3062765 891990581\n-943884414 -3338765 891882754", "808468733 166975547 650132512\n807140196 169714842 655993403", "-16 -107 146\n75 25 19", "468534418 -876402362 779510\n392125478 -856995174 1", "368831644 125127030 959524552\n690900461 -368007601 1000000000", "638572730 86093565 553198855\n-151099010 -5582761 1000000000", "567845488 379750385 112902105\n567845488 379750385 112902105", "817163584 -145230792 164258581\n826720200 -149804696 98", "-812130546 -209199732 799576707\n-728169661 -278950375 4385", "-36140638 -933845433 250828868\n90789911 -245130908 328547", "34537868 -531411810 591044372\n34536968 -531411968 58", "-410889750 -716765873 303980004\n-410889749 -716765874 7", "-304 -310 476\n120 -294 1", "-999999999 0 1000000000\n999999999 0 1000000000", "-1000000000 0 1000000000\n999999999 0 1000000000", "-99999999 0 100000000\n99999999 0 100000000", "-999999999 0 1000000000\n999999999 1 1000000000", "-1000000000 0 999999999\n999999997 0 999999999", "0 1000000000 1\n0 0 1000000000", "10000000 0 10000001\n-10000000 0 10000000", "1000000000 0 1000000000\n-999999999 1 1000000000", "44721 999999999 400000000\n0 0 600000000", "-1000000000 1 1000000000\n999999998 0 1000000000", "0 0 500000000\n431276 999999907 500000000", "1000000000 0 1000000000\n-999999998 -87334 1000000000", "0 0 10\n0 0 25", "0 0 1000000000\n707106781 707106781 1", "100 10 10\n100 20 10", "1000000000 0 1000000000\n-999999998 -88334 1000000000", "0 0 999999999\n1000000000 0 2", "-99999999 0 100000000\n99999999 1 100000000", "1000000000 0 1000000000\n-999999999 60333 1000000000", "1000000000 0 1000000000\n-999999999 58333 1000000000", "1000000000 0 1000000000\n-999999998 -85334 1000000000", "0 0 1000000000\n999999999 1 2", "0 0 1000000000\n999999998 0 3", "141 9999 5000\n0 0 5000", "-1000000000 0 1000000000\n999999998 0 1000000000", "0 0 10\n1 0 10", "0 0 1000000000\n707106782 707106781 2"], "outputs": ["7.25298806364175601379", "0.00000000000000000000", "3.14159265358979311600", "2.28318530717958647659", "78.53981633974482789995", "78.53981633974482789995", "25936.37843115316246844770", "3129038.84934604830277748988", "138921450.46886559338599909097", "868466038.83295116270892322063", "862534134678.47474157810211181641", "243706233220003.66226196289062500000", "6487743741270471.46582031250000000000", "2240182216213578196.25000000000000000000", "2498325849744150942.00000000000000000000", "1327864139649690571.00000000000000000000", "75.73941676175987183783", "0.00000000000000000000", "1877639096067727828.75000000000000000000", "648156847022339121.87500000000000000000", "40045521256826535.57031250000000000000", "30171.85584507637308604444", "60407250.40157159973750822246", "0.00000000000000000000", "10568.31768667606404221715", "153.93804002589986268390", "3.14159265358979311600", "119256.95877838134765625000", "42163.70213317871093750000", "37712.36160683631896972656", "119256.95874786376953125000", "42163.70211410522460937500", "1.57079632649338855020", "4216.37028734199702739716", "42163.70212173461914062500", "0.00188343226909637451", "119256.95874786376953125000", "0.33492207527160644531", "1199.53919601440429687500", "314.15926535897931159980", "2.09224628662147114737", "122.83696986087568455565", "461.20431423187255859375", "2.45673939563023624650", "37712.36153602600097656250", "1138.08371162414550781250", "2432.73669052124023437500", "3207.25725555419921875000", "10.10963121370591567653", "25.17685179846658691770", "0.04272695172407026121", "119256.95877838134765625000", "294.16760182010623145277", "4.52465731000908907454"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2d1c15eaa6b2e5c07888d4cc3cc6634d | Tree | Recently Bob invented a new game with a tree (we should remind you, that a tree is a connected graph without cycles): he deletes any (possibly, zero) amount of edges of the tree, and counts the product of sizes of the connected components left after the deletion. Your task is to find out the maximum number that Bob can get in his new game for a given tree.
The first input line contains integer number *n* (1<=≤<=*n*<=≤<=700) — amount of vertices in the tree. The following *n*<=-<=1 lines contain the description of the edges. Each line contains the pair of vertices' indexes, joined by an edge, *a**i*, *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*). It's guaranteed that the graph described in the input is a tree.
Output the only number — the maximum product of sizes of the connected components, that Bob can get after deleting some of the tree's edges.
Sample Input
5
1 2
2 3
3 4
4 5
8
1 2
1 3
2 4
2 5
3 6
3 7
6 8
3
1 2
1 3
Sample Output
6183 | [
"n=int(input())\r\nw=[[] for i in range(n+1)]\r\nsz=[0]*(n+1)\r\np=[0]*(n+1)\r\nf=[[0]*(n+1) for i in range(n+1)]\r\ndef dfs(u,p):\r\n\tf[u][1]=sz[u]=1\r\n\tfor v in w[u]:\r\n\t\tif v!=p:\r\n\t\t\tdfs(v,u)\r\n\t\t\tfor j in range(sz[u],-1,-1):\r\n\t\t\t\tfor k in range(sz[v],-1,-1):\r\n\t\t\t\t\tf[u][j+k]=max(f[u][j+k],f[u][j]*f[v][k])\r\n\t\t\tsz[u]+=sz[v]\r\n\tfor i in range(1,sz[u]+1):f[u][0]=max(f[u][0],f[u][i]*i)\r\n \r\nfor i in range(n-1):\r\n\tx,y=map(int,input().split())\r\n\tw[x]+=[y]\r\n\tw[y]+=[x]\r\ndfs(1,0)\r\nprint(f[1][0])",
"n = int(input())\nnode = [[] for i in range(n)]\nfor i in range(1,n):\n a,b = map(int,input().split())\n node[a-1].append(b-1)\n node[b-1].append(a-1)\n\ndp = [[] for i in range(n)]\ndef combine(a, b):\n c = [0]*(len(a)+len(b)-1)\n for i,va in enumerate(a):\n for j,vb in enumerate(b):\n c[i+j] = max(c[i+j],va*vb)\n return c\n\ndef dfs(p,par=-1):\n dp[p] = [0,1]\n for i in node[p]:\n if i == par: continue\n dfs(i,p)\n dp[p] = combine(dp[i],dp[p])\n ma = 0\n for i,v in enumerate(dp[p]):\n ma = max(ma, i*v)\n dp[p][0] = ma\ndfs(0)\nprint(dp[0][0])\n",
"n = int(input())\r\n\r\nadj = [[] for i in range(n+5)]\r\naux = [[] for i in range(n+5)]\r\nf = [1 for i in range(n+5)]\r\nh = [1 for i in range(n+5)]\r\n\r\nfor i in range(n-1):\r\n u, v = map(int, input().split())\r\n adj[u].append(v)\r\n adj[v].append(u)\r\ndef solve(u, p):\r\n for v in adj[u]:\r\n if v != p:\r\n solve(v, u)\r\n f[u] *= h[v]\r\n aux[u].append(v)\r\n #sorted(aux[u], key = lambda i : f[i] / h[i], reverse=True)\r\n aux[u].sort(key = lambda i : h[i] / f[i])\r\n h[u] = f[u]\r\n cnt = 1\r\n up = f[u]\r\n for v in aux[u]:\r\n cnt+=1\r\n up //= h[v]\r\n up *= f[v]\r\n h[u] = max(h[u], up*cnt)\r\n for v in aux[u]:\r\n up = (f[u]//h[v])*f[v]\r\n cnt = 2\r\n for w in aux[v]:\r\n cnt += 1\r\n up //= h[w]\r\n up *= f[w]\r\n h[u] = max(h[u], up*cnt)\r\n\r\nsolve(1, -1)\r\nprint(h[1])",
"n = int(input())\r\ng = [[] for i in range(n + 1)]\r\n\r\nfor i in range(n - 1):\r\n u, v = map(int, input().split())\r\n g[u].append(v)\r\n g[v].append(u)\r\n\r\n\r\nsz = [0 for i in range(n + 1)]\r\ndp = [[0 for i in range(n + 1)] for j in range(n + 1)]\r\n\r\n\r\ndef dfs(v, p = -1):\r\n dp[v][1] = 1\r\n sz[v] = 1\r\n\r\n for u in g[v]: \r\n if u != p:\r\n\r\n dfs(u, v)\r\n\r\n for i in range(sz[v], -1, -1):\r\n for j in range(sz[u], -1, -1):\r\n dp[v][i + j] = max(dp[v][i + j], dp[v][i] * dp[u][j])\r\n \r\n sz[v] += sz[u]\r\n\r\n for i in range(sz[v] + 1):\r\n dp[v][0] = max(dp[v][0], dp[v][i] * i)\r\n\r\n\r\ndfs(1)\r\n\r\nprint(dp[1][0])",
"g=[]\r\ndp=[]\r\nsiz=[]\r\ndef dfs(x,fa):\r\n\tglobal dp\r\n\tglobal siz\r\n\tdp[x][1]=1\r\n\tsiz[x]=1\r\n\tfor i in g[x]:\r\n\t\tif i==fa:\r\n\t\t\tcontinue\r\n\t\tdfs(i,x)\r\n\t\tfor j in range(siz[x],-1,-1):\r\n\t\t\tfor k in range(siz[i],-1,-1):\r\n\t\t\t\tdp[x][j+k]=max(dp[x][j+k],dp[x][j]*dp[i][k])\r\n\t\tsiz[x]=siz[x]+siz[i]\r\n\tfor i in range(1,siz[x]+1):\r\n\t\tdp[x][0]=max(dp[x][0],dp[x][i]*i)\r\nn=int(input())\r\nfor i in range(0,n+1):\r\n\tinit=[]\r\n\tg.append(init)\r\nfor i in range(0,n+1):\r\n\tinit=[]\r\n\tfor j in range(0,n+1):\r\n\t\tinit.append(0)\r\n\tdp.append(init)\r\nfor i in range(0,n+1):\r\n\tsiz.append(0)\r\nfor i in range(1,n):\r\n\ta,b=map(int,input().split())\r\n\tg[a].append(b)\r\n\tg[b].append(a)\r\ndfs(1,-1)\r\nprint(dp[1][0])",
"import copy\r\n\r\nn = int(input())\r\n\r\nedges = []\r\n\r\nfor i in range(0, n + 1):\r\n edges.append([])\r\n\r\nfor i in range(1, n):\r\n ab = input().split(' ')\r\n a = int(ab[0])\r\n b = int(ab[1])\r\n edges[a].append(b + 0)\r\n edges[b].append(a + 0)\r\n\r\nans = []\r\nsz = []\r\ntmp = []\r\n\r\nfor i in range(0, n + 1):\r\n ans.append([])\r\n sz.append(0)\r\n\r\ndef search(curr, prev):\r\n sz[curr] = 1\r\n ans[curr] = [0, 1];\r\n for nex in edges[curr]:\r\n if nex == prev:\r\n continue\r\n search(nex + 0, curr + 0)\r\n tmp = [0] * (sz[curr] + sz[nex] + 1)\r\n for s in range(1, sz[curr] + 1):\r\n for t in range(1, sz[nex] + 1):\r\n tmp[s + t] = max(tmp[s + t], ans[curr][s] * ans[nex][t])\r\n tmp[s] = max(tmp[s], ans[curr][s] * ans[nex][t] * t)\r\n ans[curr] = copy.deepcopy(tmp)\r\n sz[curr] = sz[curr] + sz[nex]\r\n\r\nsearch(1, 0)\r\n\r\nout = 0\r\n\r\nfor i in range(1, n + 1):\r\n out = max(out, ans[1][i] * i)\r\n\r\nprint(out)",
"n = int(input())\r\ng = [[] for i in range(n)]\r\nfor i in range(n - 1):\r\n\tv, u = map(int, input().split())\r\n\tv -= 1\r\n\tu -= 1\r\n\tg[v].append(u)\r\n\tg[u].append(v)\r\n\r\nsiz = [0 for i in range(n)]\r\ndp = [[0 for i in range(n + 1)] for j in range(n)]\r\n\r\ndef dfs(v, p = -1):\r\n\tsiz[v] = 1\r\n\tfor u in g[v]:\r\n\t\tif (u != p):\r\n\t\t\tdfs(u, v)\r\n\t\t\tsiz[v] += siz[u]\r\n\tdp2 = [[], []]\r\n\tdp2[0] = [0 for i in range(siz[v] + 1)]\r\n\tdp2[1] = [0 for i in range(siz[v] + 1)]\r\n\tdp2[0][1] = 1\r\n\tcur = 0\r\n\tfor u in g[v]:\r\n\t\tif (u != p):\r\n\t\t\ti = cur & 1\r\n\t\t\tni = i ^ 1\r\n\t\t\tcur += 1\r\n\t\t\tdp2[ni] = [0 for i in range(siz[v] + 1)]\r\n\t\t\tfor j in range(siz[v] + 1):\r\n\t\t\t\tif (dp2[i][j] == 0):\r\n\t\t\t\t\tcontinue\r\n\t\t\t\tfor k in range(1, siz[u] + 1):\r\n\t\t\t\t\tdp2[ni][j] = max(dp2[ni][j], (dp2[i][j] // j) * j * dp[u][k])\r\n\t\t\t\t\tdp2[ni][j + k] = max(dp2[ni][j + k], (dp2[i][j] // j) * (j + k) * (dp[u][k] // k))\r\n\tdp[v] = dp2[cur & 1]\r\n\r\ndfs(0)\r\nprint(max(dp[0]))",
"def run(E, F, G, curr, prev):\n for nex in E[curr]:\n if nex == prev:\n continue\n run(E, F, G, nex, curr)\n G[curr].append(F[nex])\n\n G[curr].sort(key=lambda x: x[0] / x[1], reverse=True)\n\n F[curr][0] = 1\n for i in range(len(G[curr])):\n F[curr][0] *= G[curr][i][1]\n\n x = F[curr][0]\n for i in range(len(G[curr])):\n x = x * G[curr][i][0] // G[curr][i][1]\n F[curr][1] = max(F[curr][1], x * (i + 2))\n\n for i in range(len(E[curr])):\n p = E[curr][i]\n if p == prev:\n continue\n\n x = F[curr][0] * F[p][0] // F[p][1]\n for j in range(len(G[p])):\n x = x * G[p][j][0] // G[p][j][1]\n F[curr][1] = max(F[curr][1], x * (j + 3))\n\n\nn = int(input())\n\nE = [[] for i in range(n)]\nfor i in range(n - 1):\n a, b = map(lambda x: int(x) - 1, input().split())\n E[a].append(b)\n E[b].append(a)\n\n\nF = [[1] * 2 for i in range(n)]\nG = [[] for i in range(n)]\n\nrun(E, F, G, 0, -1)\n\nprint(max(F[0]))\n",
"def dfs (u,fa) :\r\n dp[u][1] = 1;sz[u] = 1\r\n for v in g[u] :\r\n if v == fa : continue\r\n dfs (v,u)\r\n sz[u] += sz[v]\r\n for i in range (sz[u],-1,-1) :\r\n for j in range (max (0,i - sz[u] + sz[v]),min (i,sz[v]) + 1) :\r\n dp[u][i] = max (dp[u][i],dp[u][i - j] * dp[v][j]) \r\n for i in range (1,n + 1) :\r\n dp[u][0] = max (dp[u][0],dp[u][i] * i)\r\nn = int (input ())\r\ndp = [[0 for i in range (n + 1)] for j in range (n + 1)]\r\nsz = [0 for i in range (n + 1)]\r\ng = [[] for i in range (n + 1)]\r\nfor i in range (n - 1) :\r\n x,y = map (int,input ().split ())\r\n g[x].append (y);g[y].append (x)\r\nans = 0\r\ndfs (1,-1)\r\nfor i in range (1,n + 1) :\r\n ans = max (dp[i][0],ans)\r\nprint (ans)",
"def dfs(v, pr = -1):\r\n dp[v][1] = 1\r\n sz[v] = 1\r\n for to in g[v]:\r\n if to == pr:\r\n continue\r\n dfs(to, v)\r\n for x in range(sz[v], 0, -1):\r\n for y in range(sz[to], -1, -1):\r\n #print(v, x, y, dp[v][x], dp[to][y])\r\n dp[v][x + y] = max(dp[v][x + y], dp[v][x] * dp[to][y])\r\n sz[v] += sz[to]\r\n for i in range(1, sz[v] + 1):\r\n dp[v][0] = max(dp[v][0], dp[v][i] * i)\r\n\r\nn = int(input())\r\nsz = [0 for i in range(n)]\r\ng = [[] for i in range(n)]\r\ndp = [[0 for j in range(n + 1)] for i in range(n + 1)]\r\nfor i in range(n - 1):\r\n x, y = map(int, input().split())\r\n x -= 1\r\n y -= 1\r\n g[x].append(y)\r\n g[y].append(x)\r\ndfs(0)\r\nprint(dp[0][0])\r\n",
"n=int(input())\r\nadj=[[] for i in range(n+1)]\r\nsize=[0]*(n+1)\r\np=[0]*(n+1)\r\ndp=[[0]*(n+1) for i in range(n+1)]\r\n# why didn't you just make the answer mod 1e9+7 or something WHYYYY\r\ndef dfs(cur, prev):\r\n\tdp[cur][1]=size[cur]=1\r\n\tfor nxt in adj[cur]:\r\n\t\tif nxt!=prev:\r\n\t\t\tdfs(nxt,cur)\r\n\t\t\tfor j in range(size[cur],-1,-1):\r\n\t\t\t\tfor k in range(size[nxt],-1,-1):\r\n\t\t\t\t\tdp[cur][j+k]=max(dp[cur][j+k],dp[cur][j]*dp[nxt][k])\r\n\t\t\tsize[cur]+=size[nxt]\r\n\tfor i in range(1,size[cur]+1):dp[cur][0]=max(dp[cur][0],dp[cur][i]*i)\r\n \r\nfor i in range(n-1):\r\n\tx,y=map(int,input().split())\r\n\tadj[x]+=[y]\r\n\tadj[y]+=[x]\r\n\r\ndfs(1,0)\r\nprint(dp[1][0])\r\n",
"from math import *\r\nn=int(input())\r\ng=[]\r\ndp=[]\r\nfor i in range(n+1):\r\n g.append([])\r\n dp.append([1])\r\nfor i in range(n-1):\r\n [u,v]=[int(s) for s in input().split()]\r\n g[u].append(v)\r\n g[v].append(u)\r\nans=0\r\n\r\ndef dfs(u,f):\r\n sz=0\r\n for i in range(n):\r\n dp[u].append(0)\r\n for v in g[u]:\r\n if v!=f:\r\n szv=dfs(v,u)\r\n sz+=szv\r\n m=max([dp[v][i]*i for i in range(szv+1)])\r\n for i in range(sz,-1,-1):\r\n li=[dp[u][i-j]*dp[v][j] for j in range(max(1,i-sz+szv),min(i,szv)+1)]\r\n dp[u][i]=max(dp[u][i]*m,max(li) if len(li)>0 else 0)\r\n global ans\r\n for i in range(n,0,-1):\r\n dp[u][i]=dp[u][i-1]\r\n ans=max(ans,dp[u][i]*i)\r\n return sz+1\r\n\r\ndfs(1,0)\r\nprint(ans)\r\n",
"n=int(input())\r\nsz=[0]*(n+1)\r\ng=[[] for _ in range(n+1)]\r\ndp=[[0]*(n+1) for _ in range(n+1)]\r\ndef dfs(u,pr):\r\n sz[u]=dp[u][1]=1\r\n for v in g[u]:\r\n if(v==pr):continue\r\n dfs(v,u)\r\n for i in range(sz[u],-1,-1):\r\n for j in range(sz[v],-1,-1):\r\n dp[u][i+j]=max(dp[u][i+j],dp[u][i]*dp[v][j])\r\n sz[u]+=sz[v]\r\n for i in range(sz[u]+1):\r\n dp[u][0]=max(dp[u][0],dp[u][i]*i);\r\nfor _ in range(n-1):\r\n a,b=map(int,input().split())\r\n g[a].append(b)\r\n g[b].append(a)\r\ndfs(1,-1)\r\nprint(dp[1][0])\r\n",
"from fractions import Fraction\r\n\r\nn = int(input())\r\nG = [[] for i in range(n)]\r\n\r\nfor i in range(n-1):\r\n a, b = (int(x)-1 for x in input().split())\r\n G[a].append(b)\r\n G[b].append(a)\r\n\r\nf, g, h = [1]*n, [1]*n, [1]*n\r\n\r\ndef dfs(v, p):\r\n if p != -1:\r\n G[v].remove(p)\r\n\r\n for e in G[v]:\r\n dfs(e, v)\r\n h[v] *= f[e]\r\n\r\n tmp = []\r\n f[v], g[v] = h[v], h[v]*2\r\n\r\n for e in G[v]:\r\n f[v] = max(f[v], h[v] // f[e] * g[e])\r\n tmp.append((f[e], h[e]))\r\n\r\n fPart, hPart = h[v], 1\r\n tmp.sort(key=lambda x: Fraction(*x))\r\n\r\n for i in range(len(tmp)):\r\n fPart //= tmp[i][0]\r\n hPart *= tmp[i][1]\r\n f[v] = max(f[v], fPart*hPart*(i+2))\r\n g[v] = max(g[v], fPart*hPart*(i+3))\r\n\r\ndfs(0, -1)\r\nprint(f[0])\r\n",
"def II():\r\n return(int(input()))\r\ndef LMI():\r\n return(list(map(int,input().split())))\r\ndef I():\r\n return(input())\r\ndef MII():\r\n return(map(int,input().split()))\r\n# import sys\r\n# input=sys.stdin.readline\r\n# import io,os\r\n# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n# from collections import Counter\r\n# int(math.log(len(L)))\r\n# import math\r\n# from collections import defaultdict\r\n# mod=10**9+7\r\nfrom collections import deque\r\n# import math\r\n\r\nfor _ in range(1):\r\n n=int(input())\r\n G=[[] for _ in range(n+1)]\r\n for _ in range(n-1):\r\n a,b=MII()\r\n G[a].append(b)\r\n G[b].append(a)\r\n if n==1:\r\n print(1)\r\n # return\r\n break\r\n if n==2:\r\n print(2)\r\n # return\r\n break\r\n f=[1]*(n+1)\r\n h=[1]*(n+1)\r\n D=deque()\r\n D.append(1)\r\n seq=[]\r\n Parent=[0]*(n+1)\r\n Parent[1]=1\r\n while D:\r\n a=D.popleft()\r\n seq.append(a)\r\n for j in G[a]:\r\n if j!=Parent[a]:\r\n Parent[j]=a\r\n D.append(j)\r\n for i in range(1,n+1):\r\n if len(G[i])==1:\r\n f[i]=1\r\n h[i]=1\r\n X=[[] for _ in range(n+1)]\r\n for i in seq[::-1]:\r\n for j in G[i]:\r\n if j==Parent[i]:continue\r\n f[i]*=h[j]\r\n h[i]=max(h[i],f[i])\r\n for j in G[i]:\r\n if j!=Parent[i]:\r\n X[i].append([f[j],h[j]])\r\n X[i].sort(key=lambda x: x[0] / x[1], reverse=True)\r\n for j in range(1,len(X[i])):\r\n X[i][j][0]*=X[i][j-1][0]\r\n for j in range(len(X[i])-2,-1,-1):\r\n X[i][j][1]*=X[i][j+1][1]\r\n for j in range(len(X[i])):\r\n if j==len(X[i])-1:\r\n h[i]=max(h[i],X[i][j][0]*(j+2))\r\n else:\r\n h[i]=max(h[i],X[i][j][0]*X[i][j+1][1]*(j+2))\r\n\r\n # print(h[1])\r\n Ypre=[]\r\n Ysuf=[1]\r\n alp=1\r\n child=[]\r\n for j in G[i]:\r\n if j!=Parent[i]:\r\n child.append(j)\r\n\r\n for j in child:\r\n alp*=h[j]\r\n Ypre.append(alp)\r\n alp=1\r\n for j in child[::-1]:\r\n alp*=h[j]\r\n Ysuf.append(alp)\r\n # print(h[1])\r\n for j in range(len(child)):\r\n if j==0:\r\n alp=Ysuf[len(child)-1-j]\r\n else:\r\n alp=Ysuf[len(child)-1-j]*Ypre[j-1]\r\n for k in range(len(X[child[j]])):\r\n if k==len(X[child[j]])-1:\r\n h[i]=max(h[i],alp*(k+3)*X[child[j]][k][0])\r\n\r\n else:\r\n h[i]=max(h[i],alp*(k+3)*X[child[j]][k][0]*X[child[j]][k+1][1])\r\n print(h[1])\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n # return\r\n\r\n\r\n\r\n# if __name__==\"__main__\":\r\n\r\n # for _ in range(II()):\r\n # t()\r\n # t()\r\n",
"def main():\n n = int(input())\n gr = list([] for i in range(n + 1))\n for i in range(n - 1):\n u, v = map(int, input().split())\n gr[u].append(v)\n gr[v].append(u)\n \n topo = [1]\n par = [1] * (n + 1)\n it = 0\n while it < len(topo):\n u = topo[it]\n for v in gr[u]:\n if v == par[u]:\n continue\n par[v] = u\n topo.append(v)\n it += 1\n # print(topo) \n \n subsize = [1] * (n + 1)\n dp = list([0, 1] for i in range(n + 1))\n \n def combine(u, v):\n ans = [0] * (len(u) + len(v) - 1)\n for i in range(len(u)):\n for f in range(len(v)):\n ans[i + f] = max(ans[i + f], u[i] * v[f])\n return ans\n \n for u in reversed(topo):\n for sz in range(len(dp[u])):\n dp[u][0] = max(dp[u][0], dp[u][sz] * sz)\n if par[u] != u:\n dp[par[u]] = combine(dp[par[u]], dp[u])\n print(dp[1][0])\n \nmain()\n",
"N = int(input())\r\nsz = [0] * (N + 1)\r\ndp = [[0] * (N+1) for i in range(0, N + 1)]\r\ng = [[] for i in range(0, N + 1)]\r\n\r\ndef dfs(v, p):\r\n sz[v] = 1\r\n dp[v][1] = 1\r\n for nv in g[v]:\r\n if nv != p:\r\n dfs(nv, v)\r\n for x in range(sz[v], -1, -1):\r\n for y in range(sz[nv], -1, -1):\r\n dp[v][x + y] = max(dp[v][x + y], dp[v][x] * dp[nv][y])\r\n sz[v] += sz[nv]\r\n \r\n for i in range(1, sz[v] + 1):\r\n dp[v][0] = max(dp[v][0], dp[v][i] * i)\r\n\r\nfor i in range(1, N):\r\n u, v = map(int, input().split())\r\n g[u] += [v]\r\n g[v] += [u]\r\n\r\ndfs(1, 0)\r\nprint(dp[1][0])\r\n\r\n",
"from fractions import Fraction\nn = int(input())\n\nadj = [list() for x in range(n)]\nH = [0] * n\nF = [0] * n\nFoH = [list() for x in range(n)]\nsz = 0\norder = [0] * n\npi = [-1] * n\n\ndef dfs(u, p = -1):\n global pi, order, sz\n pi[u] = p\n for v in adj[u]:\n if v != p:\n dfs(v, u)\n order[sz] = u\n sz += 1\n\n\nT1 = [0] * n\nT2 = [0] * n\nT3 = [0] * n\n\ndef solve(u, p = -1):\n global H, F, FoH\n F[u] = 1\n for v in adj[u]:\n if v != p:\n F[u] *= H[v]\n FoH[u].append(Fraction(F[v], H[v]))\n ans = F[u]\n FoH[u].sort()\n FoH[u].reverse()\n pd = 1\n s = 0\n for x in FoH[u]:\n pd *= x\n s += 1\n ans = max(ans, int(pd * F[u]) * (s+1))\n for v in adj[u]:\n if v != p:\n pd = 1\n s = 0\n for x in FoH[v]:\n pd *= x\n s += 1\n ans = max(ans, int(pd * F[u] * F[v]) // H[v] * (s+2))\n #print(u+1, ':', FoH[u], ans)\n H[u] = ans\n\nfor i in range(1, n):\n u, v = [int(x) for x in input().split()]\n u -= 1\n v -= 1\n adj[u].append(v)\n adj[v].append(u)\n\ndfs(0)\nfor x in order:\n solve(x, pi[x])\nprint(H[0])\n\n",
"from sys import stdin\n\nN = int(stdin.readline())\ntree = [set() for _ in range(N + 1)]\ncounter = [0] * (N + 1)\ndp =[[0] * (N + 1) for _ in range(N + 1)]\nfor i in range(N - 1):\n u, v = [int(w) for w in stdin.readline().split()]\n tree[u].add(v)\n tree[v].add(u)\n\ndef dfs(node:int, parent:int) -> int:\n tree[node].discard(parent)\n dp[node][1] = counter[node] = 1\n for child in tree[node]:\n dfs(child, node)\n for j in range(counter[node], -1, -1):\n for k in range(counter[child], -1, -1):\n dp[node][j + k] = max(dp[node][j + k], dp[node][j] * dp[child][k])\n counter[node] += counter[child]\n dp[node][0] = max(dp[node][i] * i for i in range(1, counter[node] + 1))\n return dp[node][0]\n\nprint(dfs(1, 0))\n# print(sz)",
"\r\n\r\nn = int(input())\r\nedges = [[] for i in range(n)]\r\nch = [[] for i in range(n)]\r\n\r\nfor i in range(n - 1):\r\n\ta, b = map(int, input().split())\r\n\ta -= 1\r\n\tb -= 1\r\n\tedges[a].append(b)\r\n\tedges[b].append(a)\r\n\t\r\ndp = [1 for i in range(n)]\r\nprod = [1 for i in range(n)]\r\n\r\ndef dfs(v, pr):\r\n\tprod[v] = 1\r\n\t\r\n\tfor to in edges[v]:\r\n\t\tif to != pr:\r\n\t\t\tdfs(to, v)\r\n\t\t\tch[v].append(to)\r\n\t\t\tprod[v] *= dp[to]\r\n\r\n\tch[v].sort(key = lambda i : dp[i] / prod[i])\t\t\t\r\n\t\r\n\tdp[v] = prod[v]\r\n\tnow = prod[v]\r\n\tcnt = 1\r\n\r\n\tfor to in ch[v]:\r\n\t\tcnt += 1\r\n\t\tnow //= dp[to]\r\n\t\tnow *= prod[to]\r\n\t\tdp[v] = max(dp[v], now * cnt)\r\n\r\n\tfor to in ch[v]:\r\n\t\tnow = prod[v] // dp[to] * prod[to]\r\n\t\tcnt = 2\r\n\t\tfor gr in ch[to]:\r\n\t\t\tcnt += 1\r\n\t\t\tnow //= dp[gr]\r\n\t\t\tnow *= prod[gr]\r\n\t\t\tdp[v] = max(dp[v], now * cnt)\r\n\r\ndfs(0, -1)\r\nprint(dp[0])\r\n"
] | {"inputs": ["5\n1 2\n2 3\n3 4\n4 5", "8\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n6 8", "3\n1 2\n1 3", "5\n3 2\n1 5\n4 5\n5 3", "5\n2 1\n3 4\n3 5\n5 2", "5\n1 4\n4 5\n4 3\n4 2", "5\n2 3\n3 4\n3 5\n3 1", "10\n4 8\n10 2\n6 3\n10 9\n2 3\n4 1\n7 10\n2 1\n5 1", "15\n4 6\n15 1\n3 8\n15 2\n13 11\n9 10\n14 4\n9 12\n11 6\n8 10\n4 5\n2 11\n7 8\n8 4", "50\n45 39\n18 12\n13 6\n48 45\n46 36\n46 8\n40 36\n29 28\n2 18\n43 26\n25 14\n43 31\n13 30\n12 35\n38 42\n20 5\n7 35\n10 50\n27 13\n1 41\n24 21\n25 5\n7 31\n15 45\n32 25\n43 23\n4 50\n46 11\n40 14\n37 21\n50 2\n41 42\n43 30\n14 22\n36 48\n8 24\n49 20\n19 26\n32 10\n35 29\n1 6\n34 33\n29 3\n6 9\n34 39\n5 47\n16 9\n31 44\n33 17", "10\n8 10\n5 7\n1 6\n4 9\n3 8\n8 9\n2 3\n5 8\n8 1", "5\n1 5\n4 3\n2 4\n4 1", "1", "2\n2 1", "3\n1 2\n2 3"], "outputs": ["6", "18", "3", "6", "6", "5", "5", "36", "243", "68024448", "32", "6", "1", "2", "3"]} | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
2d40ef94f714e4d7728707c478647ad9 | Parliament of Berland | There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.
The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.
If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.
Sample Input
3 2 2
8 4 3
10 2 2
Sample Output
0 3
1 2
7 8 3
0 1 4
6 0 5
0 2 0
-1
| [
"n, a, b = map(int, input().split())\nans = [[0] * b for _ in range(a)]\nif n > a * b:\n print(-1)\nelse:\n for i in range(n):\n ans[i // b][i % b] = i + 1\n for i in range(a):\n if b % 2 == 0 and i % 2 == 1:\n ans[i] = ans[i][1:] + [ans[i][0]]\n print(*ans[i])",
"n, a, b = (int(s) for s in input().split())\nif a*b < n:\n print(-1)\nelif b%2:\n for i in range(a):\n print(*[j if j<=n else 0 for j in range(i*b+1, (i+1)*b+1)])\nelse:\n for i in range(a):\n if i%2:\n print(*[j if j<=n else 0 for j in range(i*b+1, (i+1)*b+1)])\n else:\n print(*[j if j<=n else 0 for j in range(i*b+1, (i+1)*b+1)][::-1])\n",
"if __name__ == \"__main__\":\r\n in_values = list(map(int, input().split()))\r\n nr_of_parliaments = in_values[0]\r\n rows = in_values[1]\r\n chairs = in_values[2]\r\n if chairs * rows < nr_of_parliaments:\r\n print('-1')\r\n else:\r\n p = 0\r\n for i in range(rows):\r\n out_row = []\r\n for j in range(chairs):\r\n p += 1\r\n if p <= nr_of_parliaments:\r\n out_row.append(p)\r\n else:\r\n out_row.append(0)\r\n if chairs % 2 == 0 and i % 2 == 0:\r\n out_row = out_row[::-1]\r\n print(*out_row)",
"n,a,b = map(int,input().split())\r\ns = a*b\r\n\r\nif s < n:\r\n print(-1)\r\n\r\nelse:\r\n if b%2 == 1:\r\n for i in range(a):\r\n for j in range(b):\r\n x = i*b +j + 1\r\n if x > n:\r\n print(0, end=' ')\r\n else:\r\n print(x, end=' ')\r\n print()\r\n else:\r\n for i in range(a):\r\n for j in range(b):\r\n x = i*b +j + 1\r\n if i%2 == 1:\r\n x = i*b + b - j\r\n if x > n:\r\n print(0, end=' ')\r\n else:\r\n print(x, end=' ')\r\n print() ",
"n, a, b = input().split(' ')\r\nn = int(n)\r\na = int(a)\r\nb = int(b)\r\n\r\n\r\ndef print_list(li):\r\n res=''\r\n for i in li:\r\n res+=str(i)+' '\r\n print(res[:-1])\r\n \r\ndef solve():\r\n k=1\r\n if (n>(a*b)):\r\n print('-1')\r\n return\r\n else:\r\n for i in range(0,a):\r\n temp=[]\r\n for j in range(0,b):\r\n if (k <= n):\r\n temp.append(k)\r\n k+=1\r\n else:\r\n temp.append('0')\r\n if ((i%2)==0):\r\n temp=reversed(temp)\r\n print_list(temp)\r\nsolve()",
"def main():\r\n n, a, b = (int(i) for i in input().split())\r\n\r\n if a * b < n:\r\n print(\"-1\")\r\n return\r\n\r\n res = list(range(1, n + 1)) + [0] * (a*b - n)\r\n res = [res[i*b:b*(i + 1)] for i in range(0, (a*b + b - 1) // b)]\r\n\r\n if b % 2 == 0:\r\n res = [list(reversed(l)) if i % 2 == 1 else l for i, l in enumerate(res)]\r\n\r\n print('\\n'.join(' '.join(map(str, l)) for l in res))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"n, string, column = map(int, input().split())\r\nseats = [[0 for i in range(column)] for j in range(string)]\r\nmemberss = []\r\nmembersf = []\r\nfor i in range(2, n + 1):\r\n if not i % 2:\r\n membersf.append(i)\r\n else:\r\n memberss.append(i)\r\n\r\nfor i in range(string):\r\n for j in range(column):\r\n if not i and not j:\r\n seats[i][j] = 1\r\n elif not i:\r\n if seats[i][j - 1] % 2 and membersf:\r\n seats[i][j] = membersf.pop()\r\n elif not seats[i][j - 1] % 2 and memberss:\r\n seats[i][j] = memberss.pop()\r\n else:\r\n if seats[i - 1][j] % 2 and membersf:\r\n seats[i][j] = membersf.pop()\r\n elif not seats[i - 1][j] % 2 and memberss:\r\n seats[i][j] = memberss.pop()\r\n\r\nif not memberss and not membersf:\r\n for i in range(string):\r\n for j in range(column):\r\n print(seats[i][j], end = ' ')\r\n print('')\r\nelse:\r\n for i in range(1, n + 1):\r\n if i == 2:\r\n continue\r\n elif not i % 2:\r\n membersf.append(i)\r\n else:\r\n memberss.append(i)\r\n for i in range(string):\r\n for j in range(column):\r\n if not i and not j:\r\n seats[i][j] = 2\r\n elif not i:\r\n if seats[i][j - 1] % 2 and membersf:\r\n seats[i][j] = membersf.pop()\r\n elif not seats[i][j - 1] % 2 and memberss:\r\n seats[i][j] = memberss.pop()\r\n else:\r\n if seats[i - 1][j] % 2 and membersf:\r\n seats[i][j] = membersf.pop()\r\n elif not seats[i - 1][j] % 2 and memberss:\r\n seats[i][j] = memberss.pop()\r\n if not memberss and not memersf:\r\n for i in range(string):\r\n for j in range(column):\r\n print(seats[i][j], end = ' ')\r\n print('')\r\n else:\r\n print('-1')",
"n, a, b = map(int, input().split())\r\npole = [[1 for i in range(b + 2)] for j in range(a + 2)]\r\nfor i in range(1, a + 1):\r\n for j in range(1, b + 1):\r\n pole[i][j] = 0\r\nnow = 1\r\nflag = False\r\ni = 1\r\nj = 1\r\nif n <= a * b:\r\n while True:\r\n while pole[i][j] == 0:\r\n pole[i][j] = now\r\n now += 1\r\n if now == n + 1:\r\n flag = True\r\n break\r\n i += 1\r\n i -= 1\r\n j += 1\r\n if flag:\r\n break\r\n while pole[i][j] == 0:\r\n pole[i][j] = now\r\n now += 1\r\n if now == n + 1:\r\n flag = True\r\n break\r\n j += 1 \r\n j -= 1\r\n i -= 1\r\n if flag:\r\n break\r\n while pole[i][j] == 0:\r\n pole[i][j] = now\r\n now += 1\r\n if now == n + 1:\r\n flag = True\r\n break\r\n i -= 1 \r\n i += 1\r\n j -= 1\r\n if flag:\r\n break\r\n while pole[i][j] == 0:\r\n pole[i][j] = now\r\n now += 1\r\n if now == n + 1:\r\n flag = True\r\n break\r\n j -= 1 \r\n if flag:\r\n break\r\n j += 1\r\n i += 1\r\n for i in range(1, len(pole) - 1):\r\n print(*pole[i][1:-1])\r\nelse:\r\n print(-1)\r\n \r\n \r\n",
"\r\nnum_inp=lambda: int(input())\r\narr_inp=lambda: list(map(int,input().split()))\r\nsp_inp=lambda: map(int,input().split())\r\nstr_inp=lambda:input()\r\nn,a,b=map(int, input().split())\r\nif n>a*b: print(-1)\r\nelse: \r\n s=[]\r\n for i in range(n):\r\n s.append(i+1)\r\n for i in range(a*b-n):\r\n s.append(0)\r\n p=1\r\n for i in range(0,a*b+1,b):\r\n print(*s[i:i+b][::p])\r\n p*=-1\r\n ",
"n, a, b=list(map(int, input().split()))\r\narr=[]\r\ndef che():\r\n global n, a, b, arr\r\n arr=list([0]*b for i in range(a))\r\n k=1\r\n for x in range(a):\r\n if x%2==0:\r\n y0=-1\r\n q=1\r\n else:\r\n y0=b\r\n q=-1\r\n for y in range(b):\r\n if k<=n:\r\n y0+=q\r\n arr[x][y0]=k\r\n k+=1\r\ndef neche():\r\n global n, a, b, arr\r\n arr=list([0]*b for i in range(a))\r\n k=1\r\n for x in range(a):\r\n for y in range(b):\r\n if k<=n:\r\n arr[x][y]=k\r\n k+=1\r\ndef pri():\r\n global arr, a, b\r\n for x in range(a):\r\n for y in range(b):\r\n print(arr[x][y], end=' ')\r\n print()\r\nif n>a*b:\r\n print(-1)\r\nelif b%2==0:\r\n che()\r\n pri()\r\nelse:\r\n neche()\r\n pri()",
"N = [int(i) for i in input().split()]\r\n\r\nn = N[0]\r\na = N[1]\r\nb = N[2]\r\n\r\nif n > a*b :\r\n\tprint (-1)\r\nelse :\r\n\tdem = [int (i) for i in range (1,n+1,2)]\r\n\tresp = [int (i) for i in range (2,n+1,2)]\r\n\ti = 0\r\n\tres = []\r\n\r\n\tl_r = len(resp)\r\n\ti_r = 0\r\n\r\n\tl_d = len(dem)\r\n\ti_d = 0\r\n\tk = 0\r\n\tfor i in range(a) :\r\n\t\tif k == 0 :\r\n\t\t\tk = 1\r\n\t\telse :\r\n\t\t\tk = 0\r\n\t\tres = []\r\n\t\tfor j in range (b) :\r\n\t\t\tif k == 1 :\r\n\t\t\t\tif j % 2 == 0 :\r\n\t\t\t\t\tif i_d < l_d:\r\n\t\t\t\t\t\tres.append (dem[i_d])\r\n\t\t\t\t\t\ti_d += 1\r\n\t\t\t\t\telse :\r\n\t\t\t\t\t\tres.append (0)\r\n\t\t\t\telse :\r\n\t\t\t\t\tif i_r < l_r :\r\n\t\t\t\t\t\tres.append (resp[i_r])\r\n\t\t\t\t\t\ti_r += 1\r\n\t\t\t\t\telse :\r\n\t\t\t\t\t\tres.append (0)\r\n\t\t\telse :\r\n\t\t\t\tif j % 2 == 1 :\r\n\t\t\t\t\tif i_d < l_d:\r\n\t\t\t\t\t\tres.append (dem[i_d])\r\n\t\t\t\t\t\ti_d += 1\r\n\t\t\t\t\telse :\r\n\t\t\t\t\t\tres.append (0)\r\n\t\t\t\telse :\r\n\t\t\t\t\tif i_r < l_r :\r\n\t\t\t\t\t\tres.append (resp[i_r])\r\n\t\t\t\t\t\ti_r += 1\r\n\t\t\t\t\telse :\r\n\t\t\t\t\t\tres.append (0)\r\n\t\tprint (*res)",
"import sys, math\r\nreadline = sys.stdin.readline\r\n\r\nn, a, b = map(int,readline().split())\r\n\r\nif a * b < n:\r\n print( -1)\r\nelse:\r\n tmp = []\r\n for i in range(a):\r\n for j in range(b):\r\n t = 1 + b * i + j\r\n if t > n:\r\n t = 0\r\n tmp.append(t)\r\n if b % 2 == 0:\r\n for i in range(1,a,2):\r\n for j in range(0,b,2):\r\n t = b * i + j\r\n tmp[t], tmp[t+1] = tmp[t + 1], tmp[t]\r\n for i in range(a * b):\r\n print(tmp[i], end=' ')\r\n if i != 0 and n % i == 0:\r\n print()",
"n, a, b = map(lambda x: int(x), input().split())\n\nresult = [[0 for _ in range(b)] for _1 in range(a)]\n\nnumber = 1\nfor row in range(a):\n for col in range(b):\n if number <= n:\n result[row][(col if b % 2 or row % 2 == 0 else b - col - 1)] = number\n number += 1\n\nif number == n + 1:\n print('\\n'.join(map(lambda x: ' '.join(map(lambda y: str(y), x)), result)))\nelse:\n print('-1')\n",
"k,n,m=map(int,input().split())\r\nif k>m*n: print(-1)\r\nelse:\r\n for i in range(n):\r\n t=[0]*m\r\n for j in range(i*m,min(k,i*m+m)): t[j-i*m if i%2 else m-j+i*m-1]=j+1 \r\n print(' '.join(map(str,t)))",
"#!/usr/bin/env python3\n\nn, a, b = [int(x) for x in input().split()]\n\nif n > a*b:\n print(-1)\nelse:\n for i in range(0, a):\n if i % 2 == 0:\n for j in range(b*i, b * (i + 1)):\n if j >= n:\n print(0, end=' ')\n else:\n print(j + 1, end=' ')\n else:\n for j in range(b * (i + 1) - 1, b*i - 1, -1):\n if j >= n:\n print(0, end=' ')\n else:\n print(j + 1, end=' ')\n print()\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn, a, b = map(int, input().split())\r\n\r\nif n > a*b:\r\n print(-1)\r\nelse:\r\n for i in range(a):\r\n if i%2 == 0:\r\n w = list(range(i*b+1, i*b + b+1))\r\n for _ in range(b):\r\n if w[_] > n:\r\n w[_] = 0\r\n print(' '.join(map(str, w)))\r\n else:\r\n w = list(range(i*b+1, i*b + b+1))[::-1]\r\n for _ in range(b):\r\n if w[_] > n:\r\n w[_] = 0\r\n print(' '.join(map(str, w)))",
"def e(x, n):\n if x > n:\n return 0\n else:\n return x\n\n\nclass CodeforcesTask644ASolution:\n def __init__(self):\n self.result = ''\n self.n_a_b = []\n\n def read_input(self):\n self.n_a_b = [int(x) for x in input().split(\" \")]\n\n def process_task(self):\n if self.n_a_b[0] > self.n_a_b[1] * self.n_a_b[2]:\n self.result = \"-1\"\n else:\n result = []\n for x in range(self.n_a_b[1]):\n row = []\n for y in range(self.n_a_b[2]):\n row.append(x * self.n_a_b[2] + y + 1)\n result.append(row)\n if not self.n_a_b[2] % 2:\n for x in range(self.n_a_b[1]):\n if x % 2:\n result[x] = result[x][::-1]\n printable = [\" \".join([str(e(x, self.n_a_b[0])) for x in row]) for row in result]\n self.result = \"\\n\".join(printable)\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask644ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n",
"n, a, b = map(int, input().split())\r\nif n > a * b:\r\n print(-1)\r\nelse:\r\n ch = 2\r\n ne = 1\r\n for y in range(a):\r\n for x in range(b):\r\n if (x + y) % 2:\r\n val = ch if ch <= n else 0\r\n ch += 2\r\n else:\r\n val = ne if ne <= n else 0\r\n ne += 2\r\n print(val, end=\" \")\r\n print()",
"def solve(n, a, b):\n if n > a * b: return False\n M = [[0 for j in range(b)] for i in range(a)]\n for x in range(n):\n i, j = divmod(x, b)\n M[i][b - 1 - j if i%2 else j] = x + 1\n return M\n\nn, a, b = [int(x) for x in input().split()]\nM = solve(n, a, b)\nif not M:\n print(-1)\nelse:\n for i in range(a):\n print(' '.join(map(str, M[i])))\n",
"import sys\r\nn, a, b = map(int, input().split())\r\nif n > a*b:\r\n print(-1)\r\n sys.exit(0)\r\npar = []\r\nfor i in range(1, n+1, b):\r\n s = ['0']*b\r\n for j in range(b):\r\n if i+j <= n:\r\n s[j] = str(i+j)\r\n par.append(s)\r\nwhile len(par) < a:\r\n par.append(['0']*b)\r\nfor i in range(a):\r\n if i%2 == 0:\r\n par[i].reverse()\r\n print(' '.join(par[i]))\r\n else:\r\n print(' '.join(par[i]))",
"s = input()\r\nn, a, b = s.split(' ')\r\nn = int(n)\r\na = int(a)\r\nb = int(b)\r\nif (n>a*b):\r\n\tprint(-1)\r\nelse:\r\n\tfor i in range(0, a*b):\r\n\t\tnRow = i // b\r\n\t\tif (nRow % 2 == 0):\r\n\t\t\tx = i\t\t\r\n\t\telse:\r\n\t\t\tx = nRow*b + b - (i%b) - 1\r\n\t\r\n\t\tx=x+1\r\n\t\tif (x>n):\r\n\t\t\tx='0'\r\n\t\tprint(x, ' ', end='')\r\n\t\tif ((i+1) % b == 0):\r\n\t\t\tprint()\r\n",
"parliamentrian , rows , columns = map(lambda x: int(x) , input().split())\r\nseats = rows*columns\r\n\r\nif (seats < parliamentrian):\r\n print(-1)\r\n\r\nelse:\r\n lst = [str(i) for i in range(1, parliamentrian+1)] + ['0']*(seats-parliamentrian)\r\n \r\n lock = 0\r\n \r\n for i in range(0,len(lst),columns):\r\n if (lock == 0):\r\n print(' '.join(lst[i:i+columns]))\r\n lock = 1\r\n elif (lock == 1):\r\n print(' '.join(list(reversed(lst[i:i+columns]))))\r\n lock = 0",
"import sys\n\ndef check(c, n):\n have = [0] * (n + 1)\n for i in range(len(c)):\n for j in range(len(c[i])):\n \t have[c[i][j]] = 1\n return sum(have[1:]) == n\n\n(n, a, b) = map(int, input().split())\nt = [[0] * b for i in range(a)]\nfor i in range(a):\n for j in range(b):\n t[i][j] = ((i + j) & 1)\ncur = 1\nc = [[0] * b for i in range(a)]\nfor i in range(a):\n for j in range(b):\n if cur > n:\n break\n if t[i][j]:\n c[i][j] = cur\n cur += 2\ncur = 2\nfor i in range(a):\n for j in range(b):\n if cur > n:\n break\n if not t[i][j]:\n c[i][j] = cur\n cur += 2\nif check(c, n):\n for i in c:\n print(*i)\n sys.exit(0)\nfor i in range(a):\n for j in range(b):\n t[i][j] ^= 1\ncur = 1\nc = [[0] * b for i in range(a)]\nfor i in range(a):\n for j in range(b):\n if cur > n:\n break\n if t[i][j]:\n c[i][j] = cur\n cur += 2\ncur = 2\nfor i in range(a):\n for j in range(b):\n if cur > n:\n break\n if not t[i][j]:\n c[i][j] = cur\n cur += 2\nif check(c, n):\n for i in c:\n print(*i)\n sys.exit(0)\nprint(-1)\n",
"n,a,b=[int(x) for x in input().split()]\r\nif n>a*b:\r\n print(-1)\r\n quit()\r\nfor i in range(a):\r\n if i%2==0:\r\n for j in range(b):\r\n if n>0:\r\n print(n,end=' ')\r\n n-=1\r\n else:\r\n print(0,end=' ')\r\n else:\r\n mas=[]\r\n for j in range(b):\r\n if n > 0:\r\n mas.append(n)\r\n n -= 1\r\n else:\r\n mas.append(n)\r\n for k in mas[::-1]:\r\n print(k,end=' ')\r\n print()\r\n",
"n, a, b = [int(x) for x in input().split()]\ns = [ [0 for j in range(b)] for i in range(a) ]\nx, y = 1, 2\ni, j = 0, 0\nlast = 0\nwhile i < a and (x <= n or y <= n):\n parity = True\n while j < b and (x <= n or y <= n):\n if parity and x<=n:\n s[i][j] = x \n x += 2\n elif not parity: \n s[i][j] = y\n y += 2\n parity = not parity\n last = max(last, s[i][j])\n j += 1\n i += 1\n j = 0\n x, y = y, x\nif last == n:\n print('\\n'.join(' '.join(str(x) for x in ln) for ln in s))\nelse:\n print(-1)\n",
"#! /usr/bin/env python3\n'''\n' Title:\t\n' Author:\tCheng-Shih, Wong\n' Date:\t\t\n'''\n\nn, a, b = map(int, input().split())\n\nif n > a*b:\n\tprint(-1)\nelse:\n\tfor i in range(a):\n\t\ts = []\n\n\t\tfor j in range(b):\n\t\t\ts.append(n)\n\t\t\tif n > 0: n -= 1\n\n\t\tif i&1 == 1:\n\t\t\ts.reverse()\n\n\t\tprint( ' '.join(str(v) for v in s) )\n",
"n, a, b = map(int, input().split())\r\n\r\nif n > a * b:\r\n print(-1)\r\nelse:\r\n k = 1\r\n for i in range(a):\r\n s = \"\"\r\n for j in range(b):\r\n if k <= n:\r\n if b % 2 == 0 and i % 2 == 0:\r\n s = str(k) + \" \" + s\r\n else:\r\n s += \" \" + str(k)\r\n k += 1\r\n else:\r\n if b % 2 == 0 and i % 2 == 0:\r\n s = \"0 \" + s\r\n else:\r\n s += \" 0\"\r\n print(s)\r\n",
"n, a, b = map(int, input().split())\r\nif n > a * b:\r\n print(-1)\r\nelse:\r\n data = [[ i + 1 + b * j for i in range(b)][::pow(-1, j)] for j in range(a)]\r\n for i in range(a):\r\n for j in range(b):\r\n if data[i][j] > n:\r\n print(0, end=' ')\r\n else:\r\n print(data[i][j], end=' ')\r\n print()",
"n,a,b=map(int,input().split())\r\ncO = 1\r\ncE = 2\r\nif n>a*b:\r\n print(-1) \r\n exit()\r\nfor i in range(a):\r\n print()\r\n for j in range(b):\r\n if (i+j)&1:\r\n if cE<=n: print(cE, end=' ')\r\n else: print(0,end=' ')\r\n cE+=2\r\n else:\r\n if cO<=n: print(cO,end=' ')\r\n else: print(0,end=' ')\r\n cO+=2",
"A = input().split()\r\na = [[0] * int(A[2]) for i in range(int(A[1]))]\r\ncount = 1\r\nif int(A[1]) * int(A[2]) < int(A[0]):\r\n print(-1)\r\nelse:\r\n for i in range(int(A[1])):\r\n if i % 2 == 0:\r\n for j in range(int(A[2])-1, -1, -1):\r\n a[i][j] = count\r\n count += 1\r\n if count > int(A[0]):\r\n break\r\n else:\r\n for j in range(int(A[2])):\r\n a[i][j] = count\r\n count += 1\r\n if count > int(A[0]):\r\n break\r\n\r\n if count > int(A[0]):\r\n break\r\n\r\n for row in a:\r\n print(' '.join([str(elem) for elem in row]))\r\n",
"#!/bin/python\nimport collections\nimport random\nimport sys\ntry:\n from tqdm import tqdm\nexcept:\n def tqdm(iterable):\n return iterable\n\n\n__taskname = ''\nif __taskname:\n sys.stdin = open(__taskname + '.in')\n sys.stdout = open(__taskname + '.out', 'w')\n\nn, a, b = map(int, input().split())\nif a * b < n: \n print(-1)\n exit(0)\nfor i in range(a):\n if i & 1:\n print(*list(range(n, max(0, n - b), -1)) + [0] * max(0, b - n))\n else:\n print(*[0] * max(0, b - n) + list(range(max(0, n - b) + 1, n + 1)))\n n = max(n - b, 0)\n",
"a, b, c = map(int, input().split(' '))\r\nif b*c<a:\r\n print(-1)\r\n quit()\r\nk = []\r\nfor i in range(b):\r\n l = []\r\n for j in range(c):\r\n if (i*c+j+1 <= a):\r\n l.append(str(i*c+j+1))\r\n else:\r\n l.append('0')\r\n if (c%2 == 0 and i%2 == 0):\r\n l.reverse()\r\n print(' '.join(l))\r\n",
"n, a, b = map(int, input().split())\r\nif a * b < n:\r\n print(-1)\r\nelse:\r\n for i in range(a):\r\n if b % 2 == 1 or i % 2 == 0:\r\n for j in range(1, b + 1):\r\n k = b* i + j\r\n if k > n:\r\n k = 0\r\n print(k, end = ' ')\r\n print(' ')\r\n else:\r\n for j in range(b, 0, -1):\r\n k = b* i + j\r\n if k > n:\r\n k = 0\r\n print(k, end = ' ')\r\n print(' ')\r\n \r\n",
"import sys\n\n# with open('input.txt') as in_f:\nn, a, b = [int(x) for x in sys.stdin.readline().split()]\n\ni, j = 0, 0\nans = [[0 for _ in range(b)] for __ in range(a)]\ncur = 1\ninc = True\n\nif n > a * b:\n print(-1)\n exit()\n\nwhile cur != n + 1:\n ans[i][j] = cur\n cur += 1\n if inc:\n j += 1\n if j == b:\n j -= 1\n i += 1\n inc = False\n else:\n j -= 1\n if j == -1:\n j += 1\n i += 1\n inc = True\n\nfor i in range(a):\n for j in range(b):\n print(ans[i][j], end=' ')\n print()\n",
"n, a, b = map(int,input().split())\r\na1 = 1\r\na2 = 2\r\nif a * b < n:\r\n print(-1)\r\nelse:\r\n for i in range(a):\r\n for j in range(b):\r\n if (i+j)%2:\r\n if a2 <= n:\r\n print (a2,end=' ')\r\n a2 += 2\r\n else:\r\n print (0,end= ' ' )\r\n else:\r\n if a1 <= n:\r\n print (a1,end=' ')\r\n a1 += 2\r\n else:\r\n print (0,end= ' ' )\r\n print()",
"n, a, b = map(int, input().split())\r\n\r\nif n > a * b:\r\n print(-1)\r\nelse:\r\n for i in range(a):\r\n for j in range(b):\r\n val = i * b + 1\r\n val += (j if i % 2 == 0 else b - 1 - j)\r\n print(val if val <= n else 0, end = ' ')\r\n print()\r\n ",
"from functools import reduce\n\nn, a, b = [int(x) for x in input().split(' ')]\n\ngrid = [[0 for c in range(b)] for r in range(a)]\n\nif n > (a * b):\n print('-1')\nelse:\n i = 1\n r = 0\n c = 0\n direction = 1\n while i <= n:\n # print(\"r = {0}, c = {1}\".format(r, c))\n grid[r][c] = i\n c += direction\n i += 1\n if c == b or c < 0:\n r += 1\n direction *= -1\n c += direction\n for r in range(a):\n # print('Row {0}: {1}'.format(r, grid[r]))\n st = reduce(lambda x, y: '{0} {1}'.format(x, y), grid[r])\n print(st)\n \n\n\n",
"from collections import deque, defaultdict, Counter\r\nfrom itertools import product, groupby, permutations, combinations\r\nfrom math import gcd, floor, inf, log2, sqrt, log10\r\nfrom bisect import bisect_right, bisect_left\r\nfrom statistics import mode\r\nfrom string import ascii_uppercase\r\n\r\nn, c, r = map(int, input().split())\r\n\r\nif n > c*r:\r\n print(-1)\r\nelse:\r\n odds = [i for i in range(1, n+1, 2)]\r\n evens =[i for i in range(0, n+1, 2)]\r\n ans = [[0] * r for i in range(c)]\r\n for i in range(c):\r\n for j in range(r):\r\n if (i+j)%2 == 0:\r\n if odds:\r\n ans[i][j] = odds.pop()\r\n else:\r\n break\r\n else:\r\n if evens:\r\n ans[i][j] = evens.pop()\r\n else:\r\n break\r\n for row in ans:\r\n print(*row)\r\n\r\n\r\n\r\n\r\n",
"def main():\r\n x = input().split()\r\n amount = int(x[0])\r\n a = int(x[1])\r\n b = int(x[2])\r\n if a*b < amount:\r\n print(\"-1\")\r\n else:\r\n odd = []\r\n even = []\r\n loppu = []\r\n for i in range(amount):\r\n if (i % 2) == 0:\r\n odd.append(i + 1)\r\n else:\r\n even.append(i + 1)\r\n\r\n for i in range(a):\r\n y = []\r\n if len(loppu) == 0 or (loppu[i-1][0] % 2) == 0:\r\n for j in range(b):\r\n if len(y) == 0 or (y[j-1] % 2) == 0:\r\n if len(odd) != 0:\r\n y.append(odd[0])\r\n odd.pop(0)\r\n else:\r\n y.append(0)\r\n else:\r\n if len(even) != 0:\r\n y.append(even[0])\r\n even.pop(0)\r\n else:\r\n y.append(0)\r\n loppu.append(y)\r\n\r\n else:\r\n for j in range(b):\r\n if len(y) == 0 or (y[j-1] % 2) != 0:\r\n if len(even) != 0:\r\n y.append(even[0])\r\n even.pop(0)\r\n\r\n else:\r\n y.append(0)\r\n else:\r\n if len(odd) != 0:\r\n y.append(odd[0])\r\n odd.pop(0)\r\n\r\n else:\r\n y.append(0)\r\n loppu.append(y)\r\n\r\n for i in range(a):\r\n for j in range(b):\r\n print(loppu[i][j], end='')\r\n if j < b-1:\r\n print(\" \", end='')\r\n else:\r\n print(\"\")\r\n\r\n\r\nmain()",
"n,a,b=map(int,input().split())\r\nif a*b<n:print(-1);exit()\r\nfor i in range(a):\r\n x = [str(j)if j<=n else'0'for j in range(i*b+1,(i+1)*b+1)]\r\n if i&1==0:\r\n x=list(reversed(x))\r\n print(' '.join(x))\r\n",
"n, a, b = [int(i) for i in input().split()]\r\nif n <= a * b:\r\n for i in range(a):\r\n for j in range(b):\r\n if (i+1) % 2:\r\n if i * b + j + 1 <= n: \r\n print(i * b + j + 1, end = ' ')\r\n else:\r\n print(0, end = ' ')\r\n else:\r\n if i * b + b - j <= n: \r\n print(i * b + b - j, end = ' ')\r\n else:\r\n print(0, end = ' ')\r\n print()\r\nelse:\r\n print(-1)\r\n",
"#!/usr/bin/python3\n\nn, a, b = map(int, input().split())\n\nans = [[0 for i in range(b)] for j in range(a)]\n\nx = 0\ny = 0\n\nfor i in range(1, n + 1, 2):\n if 0 <= x < a and 0 <= y < b:\n ans[x][y] = i\n else:\n print(-1)\n exit(0)\n \n y += 2\n while y >= b:\n x += 1\n y = x % 2\n \nx = 0\ny = 1\nwhile y >= b:\n x += 1\n y = (1 + x) % 2\nfor i in range(2, n + 1, 2):\n if 0 <= x < a and 0 <= y < b:\n ans[x][y] = i\n else:\n print(-1)\n exit(0)\n\n y += 2\n while y >= b:\n x += 1\n y = (1 + x) % 2\n\nfor i in range(a):\n print(\" \".join(map(str, ans[i])))\n",
"n, a, b = map(int, input().split())\r\nans = []\r\nif n <= a*b:\r\n if b % 2 == 1:\r\n for i in range(1, a*b+1):\r\n if i <= n:\r\n ans.append(i)\r\n else:\r\n ans.append(0)\r\n if len(ans) % b == 0:\r\n print(*ans)\r\n ans = []\r\n else:\r\n for i in range(1, a*b+1):\r\n if i <= n:\r\n ans.append(i)\r\n else:\r\n ans.append(0)\r\n if len(ans) % b == 0 and (i//b)%2 == 1:\r\n print(*ans)\r\n ans = []\r\n elif len(ans) % b == 0 and (i//b)%2 == 0:\r\n print(*ans[::-1])\r\n ans = []\r\nelse:\r\n print(-1)",
"from _operator import le\r\n\r\n\r\n\r\n\r\n\r\n\r\nhead=list(map(int,input().split()))\r\n\r\nn=head[0]\r\na=head[1]\r\nb=head[2]\r\nif a*b>= n:\r\n arr= matrix = [[int(0)]*b for i in range(a)]\r\n\r\n flag = 0\r\n x=1\r\n for i in range(0,a):\r\n\r\n for j in range(flag,b,2):\r\n if x>n:\r\n flag=-1\r\n break\r\n arr[i][j]= x\r\n x+=2\r\n if flag==-1:\r\n break\r\n flag = 1 if flag==0 else 0\r\n\r\n flag = 1\r\n x=2\r\n for i in range(0,a):\r\n\r\n for j in range(flag,b,2):\r\n if x>n:\r\n flag=-1\r\n break\r\n arr[i][j]= x\r\n x+=2\r\n if flag==-1:\r\n break\r\n flag = 1 if flag==0 else 0\r\n\r\n for i in range(0,a):\r\n for j in range(0,b):\r\n print(arr[i][j],end=' ')\r\n print()\r\nelse:\r\n print(-1)",
"n,a,b=map(int,input().split())\r\nif a*b<n:\r\n print(-1)\r\nelse:\r\n ll=[i for i in range(1,n+1)]\r\n ll+=[0 for i in range((a*b)-n)]\r\n x=0\r\n t=0\r\n while t<a :\r\n k=ll[x:x+b]\r\n if t%2!=0:\r\n k.reverse()\r\n t+=1\r\n x+=b\r\n print(*k)\r\n\r\n",
"members, row, column = [int(a) for a in input().split(' ')]\nif members <= row * column:\n current_row = []\n current_members_in_current_row = 0\n flip = 1\n for row_number in range(row):\n while current_members_in_current_row != column:\n current_row.append(str(members))\n current_members_in_current_row += 1\n if members != 0:\n members -= 1\n print(' '.join(current_row[::flip]))\n current_row = []\n current_members_in_current_row = 0\n flip *= -1\nelse:\n print(-1)",
"from sys import exit\nn, a, b = map(int, input().split())\nodd1 = (a * b) % 2 == 1\nodd2 = n % 2 == 1\nif odd1 == odd2:\n if n > a * b:\n print(-1)\n exit()\nelse:\n if n + 1 > a * b:\n print(-1)\n exit()\nnumb = [1, 2]\nfor i in range(a):\n for j in range(b):\n party = (i % 2 + j % 2 + odd1 + 1) % 2\n c = numb[party]\n if c > n:\n c = 0\n numb[party] += 2\n print(c, end=\" \")\n print()\n",
"#!/usr/bin/env python\r\n\r\nn, a, b = [int(x) for x in input().split()]\r\n\r\nif a * b < n:\r\n print(-1)\r\nelse:\r\n odd = iter(range(1, n + 1, 2))\r\n even = iter(range(2, n + 1, 2))\r\n for i in range(a):\r\n for j in range(b):\r\n if (i + j) % 2 == 0:\r\n print(next(odd, 0), end=' ')\r\n else:\r\n print(next(even, 0), end=' ')\r\n print()\r\n",
"import sys\r\nn, a, b = map(int, input().split())\r\nseats = list(range(1, n + 1)) + [0] * (a * b - n)\r\n\r\nif n > a * b:\r\n\tprint(-1); sys.exit()\r\nelse:\r\n\tfor i in range(a):\r\n\t\tr = seats[i * b: i * b + b]\r\n\t\tprint(' '.join(map(str, r if b & 1 or i & 1 else r[::-1])))",
"n,a,b=(int(z) for z in input().split())\nif a*b<n:\n print(-1)\nelse:\n i=1\n s=''\n if b%2==1:\n while i<=n:\n if i%b!=0:\n s+=str(i)+' '\n else:\n print(s+str(i))\n s=''\n i+=1\n while i<=a*b:\n if i%b!=0:\n s+='0 '\n else:\n print(s+'0')\n s=''\n i+=1\n else:\n i=1\n r=1\n s=''\n while i<=n:\n if (i%b!=0 and r==1) or ((i-1)%b!=0 and r==-1):\n s+=str(i)+' '\n i+=r\n else:\n print(s+str(i))\n s=''\n i+=b\n r*=-1\n if i>n>i+r*b:\n while (i-1)%b!=0:\n if i <=n:\n s+=str(i)+' '\n else:\n s+='0 '\n i-=1\n print (s+str(i))\n s=''\n i+=b\n while i <=a*b:\n if i%b!=0:\n s+='0 '\n else:\n print (s+'0')\n s=''\n i+=1\n \n \n \n",
"n,r,c = [int(i) for i in input().split()]\nif n > r*c:\n print(-1)\n import sys\n sys.exit(0)\np = [[0 for i in range(c)] for j in range(r)] \nif c % 2:\n num = 1\n x = 0\n y = 0\n while num <= n:\n p[x][y] = num\n \n num += 1\n y += 1\n \n if y == c:\n y = 0\n x += 1\nelif r % 2:\n num = 1\n x = 0\n y = 0\n while num <= n:\n p[x][y] = num\n num += 1\n x += 1\n if x == r:\n x = 0\n y += 1\nelse:\n num = 1\n x = 0\n y = 0\n while num <= n:\n p[x][y] = num\n num += 1\n y += 1\n if y == c-1:\n y = 0\n x += 1\n if x == r:\n break\n if num%2 == 0:\n for i in range(r):\n if num > n:\n break\n p[i][c-1] = num\n num += 1\n else:\n for i in range(r-1, -1, -1):\n if num > n:\n break\n p[i][c-1] = num\n num += 1\nfor row in p:\n print(*row)\n \n \n",
"n, a, b = map(int, input().split())\r\n\r\nfrom sys import exit\r\n\r\nfor k in range(2):\r\n A, even, odd = [], 2, 1\r\n if k == 1:\r\n even, odd = 1, 2\r\n for i in range(a):\r\n r = []\r\n for j in range(b):\r\n if (i + j) % 2 == 0:\r\n if even > n:\r\n r += [0]\r\n continue\r\n r += [even]\r\n even += 2\r\n else:\r\n if odd > n:\r\n r += [0]\r\n continue\r\n r += [odd]\r\n odd += 2\r\n A += [r]\r\n\r\n if even > n and odd > n:\r\n for r in A:\r\n print(*r, sep = ' ')\r\n exit(0)\r\nelse:\r\n print(-1)\r\n\r\n",
"n,a,b=map(int,input().split())\r\nl=[['0']*b for i in range(a)]\r\nif n>a*b: print(-1)\r\nelse:\r\n for i in range(n):\r\n ii=i//b\r\n jj=i%b if ii%2==0 else b-i%b-1\r\n l[ii][jj]=str(i+1)\r\n print('\\n'.join(map(' '.join,l)))",
"parliamentarian_quantity, hight, width = map(int, input().split())\r\nif parliamentarian_quantity <= hight*width:\r\n assembly_hall = [[0]*width for row in range(hight)]\r\n current = 1\r\n parity = 1 if width%2 == 0 else 0\r\n occupied_chairs = 0\r\n for i in range(hight):\r\n for j in range(width):\r\n if occupied_chairs <= parliamentarian_quantity:\r\n parliamentarian_number = j + 1 + i*width + parity*(i%2)\r\n if parliamentarian_number <= parliamentarian_quantity:\r\n assembly_hall[i][j] = parliamentarian_number\r\n occupied_chairs += 1\r\n parity = -parity\r\n else:\r\n break\r\n [print(\" \".join(map(str, row))) for row in assembly_hall]\r\nelse:\r\n print(-1)",
"#!/usr/bin/python3\n\ndef is_black(i, j):\n\treturn i%2 == j%2\n\n\ndef main():\n\tn, a, b = map(int, input().split())\n\t# n,a,b = 3,2,2\n\n\tif n > a*b:\n\t\tprint(-1)\n\t\treturn\n\n\tswap = b%2 == 0\n\n\tnext_odd = 1\n\tnext_even = 2\n\n\tdef print_val(val):\n\t\tif val > n:\n\t\t\tprint(0, end=' ')\n\t\telse:\n\t\t\tprint(val, end=' ')\n\n\tfor i in range(a):\n\t\tfor j in range(b):\n\t\t\tif is_black(i, j):\n\t\t\t\tprint_val(next_odd)\n\t\t\t\tnext_odd += 2\n\t\t\telse:\n\t\t\t\tprint_val(next_even)\n\t\t\t\tnext_even += 2\n\n\t\tprint()\n\n\nif __name__ == '__main__':\n\tmain()\n",
"n, a, b = map(int, input().split())\nif a * b < n:\n print(-1)\nelse:\n chairs = list(map(str, list(range(1, n + 1)) + [0] * (a*b - n)))\n for i, (start, end) in enumerate(zip(range(0, a*b, b), range(b, a*b + 1, b))):\n if i % 2:\n print(' '.join(reversed(chairs[start:end])))\n else:\n print(' '.join(chairs[start:end]))\n",
"n, a, b = [int(i) for i in input().split()]\r\nres = [[0 for j in range(b)] for i in range(a)]\r\nif n > a * b:\r\n print(-1)\r\n exit(0)\r\nfor i in range(n):\r\n res[i // b][i % b] = i + 1\r\nif b % 2 == 0:\r\n for i in range(1, a, 2):\r\n res[i] = res[i][::-1]\r\nfor i in range(a):\r\n print(' '.join(list(map(str, res[i]))))\r\n \r\n",
"n,a,b=map(int,input().split())\r\nif a*b<n:\r\n\tprint(-1)\r\nelse:\r\n\ti=1\r\n\tfor k in range(a):\r\n\t\tl=[]\r\n\t\tj=0\r\n\t\tif k%2==0:\r\n\t\t\twhile i<=a*b and j<b:\r\n\t\t\t\tif i<=n:\t\r\n\t\t\t\t\tl.append(i)\r\n\t\t\t\telse:\r\n\t\t\t\t\tl.append(0)\r\n\t\t\t\ti+=1\t\r\n\t\t\t\tj+=1\r\n\t\telse:\r\n\t\t\twhile i<=a*b and j<b:\r\n\t\t\t\tif i<=n:\r\n\t\t\t\t\tl.insert(0,i)\r\n\t\t\t\telse:\r\n\t\t\t\t\tl.insert(0,0)\r\n\t\t\t\ti+=1\r\n\t\t\t\tj+=1\r\n\t\tprint(*l)\t\t",
"n,a,b=map(int,input().split())\r\nif a*b<n:print(-1)\r\nelse:\r\n x=1\r\n for i in range(a):\r\n a=*map(lambda x:[x,0][x>n],range(x,x+b)),\r\n if b%2<1 and i%2:a=a[::-1]\r\n print(*a)\r\n x+=b",
"import sys\r\nimport math\r\n\r\ninp = sys.stdin.readline().split(' ')\r\nn = int(inp[0])\r\nrow = int(inp[1])\r\ncol = int(inp[2])\r\nif n > row * col:\r\n sys.stdout.write('-1')\r\nelse:\r\n arr = [[0 for i in range(col)] for j in range(row)]\r\n for x in range(n):\r\n rows = math.floor(x/col)\r\n cols = x%col\r\n if col % 2 == 1 or rows % 2 == 1:\r\n arr[rows][cols] = x + 1\r\n else:\r\n arr[rows][col-cols-1] = x + 1\r\n for x in range(len(arr)):\r\n for y in range(len(arr[0])):\r\n sys.stdout.write(str(arr[x][y]) + ' ')\r\n sys.stdout.write('\\n')",
"n, a, b = map(int, input().split())\nif n > a * b:\n print(-1)\n exit(0)\nl = list(map(str, range(1, n + 1))) + ['0'] * (a * b - n)\nfor i in range(a):\n print(' '.join(l[(i + 1) * b - 1:i * b - 1:-1] if i & 1 else l[i * b:(i + 1) * b]))",
"n, a, b = map(int, input().split())\r\ns = [[0 for i in range(b)] for j in range(a)]\r\nc = 1\r\ni = 0\r\nj = 0\r\nf = 1\r\nif n > a*b:\r\n print(-1)\r\n exit(0)\r\nwhile c <= n:\r\n s[i][j] = c\r\n #print(i, j)\r\n if (i == (a - 1)) and (f == 1):\r\n f *= -1\r\n j += 1\r\n elif (i == 0) and (f == -1):\r\n f *= -1\r\n j += 1\r\n else:\r\n i += f\r\n c += 1\r\nfor i in s:\r\n for j in i:\r\n print(j, end = ' ')\r\n print()",
"n, a, b = map(int, input().split())\r\n\r\nif n > a * b:\r\n print(-1)\r\nelse:\r\n daf = [x+1 for x in range(n)]\r\n zero = (a * b) - n\r\n daf = [0] * zero + daf\r\n for i in range(a):\r\n has = daf[b * i: b * (i + 1)]\r\n if i%2 == 1:\r\n has = has[::-1]\r\n print(*has)\r\n",
"n, r, c = map(int, input().split())\r\ng = [[0 for _ in range(c)] for _ in range(r)]\r\nmiss = [i for i in range(1, n+1)]\r\nfor i in range(r):\r\n for j in range(c):\r\n tmp = list()\r\n cant = True\r\n while cant and miss:\r\n cant = False\r\n first = miss.pop()\r\n if i > 0 and g[i-1][j] != 0 and (g[i-1][j] % 2) == (first % 2):\r\n cant = True\r\n elif j > 0 and g[i][j-1] != 0 and (g[i][j-1] % 2) == (first % 2):\r\n cant = True\r\n if not cant:\r\n g[i][j] = first\r\n else:\r\n tmp.append(first)\r\n for v in tmp:\r\n miss.append(v)\r\nif not miss:\r\n for l in g:\r\n print(\" \".join(map(str, l)))\r\nelse:\r\n print(-1)\r\n",
"n, a, b = (int(i) for i in input().split())\nif n > a * b:\n print(-1)\nelse:\n res = [[0] * b for _ in range(a)]\n for r in range(a):\n for c in range(b):\n x = r * b + c + 1\n if x > n:\n break\n res[r][c if r & 1 == 0 else b - 1 - c] = x\n if x > n:\n break\n for r in res:\n print(*r)\n",
"n, a, b = map(int, input().split())\r\nt = 1\r\nif a*b < n:\r\n print(-1)\r\nelse:\r\n if b%2:\r\n for i in range(a):\r\n ar = [x+i*b for x in range(1, b+1)]\r\n for j in range(b):\r\n if ar[j] <= n:\r\n print(ar[j], end = ' ')\r\n else:\r\n print(0, end = ' ')\r\n print()\r\n else:\r\n for i in range(a):\r\n if i % 2 == 0:\r\n ar = [x+i*b for x in range(1, b+1)]\r\n else:\r\n ar = [b+i*b] + [x+i*b for x in range(1, b)]\r\n for j in range(b):\r\n if ar[j] <= n:\r\n print(ar[j], end = ' ')\r\n else:\r\n print(0, end = ' ')\r\n print() ",
"n, a, b = map(int, input().split())\r\nif n>a*b:\r\n print(\"-1\")\r\nelse:\r\n ans = [[0 for i in range(b)] for j in range(a)]\r\n k = 1\r\n for i in range(a):\r\n if i%2==0:\r\n for j in range(b):\r\n if k<=n:\r\n ans[i][j] = k\r\n k += 1\r\n else:\r\n for j in range(b-1, -1, -1):\r\n if k<=n:\r\n ans[i][j] = k\r\n k += 1\r\n for i in ans:\r\n print(*i)\r\n\r\n",
"import sys\r\n\r\n# sys.stdin = open(\"ivo.in\")\r\nn, a, b = map(int, sys.stdin.readline().split())\r\n\r\nif n > a * b:\r\n print(-1)\r\n sys.exit(0)\r\n\r\nres = []\r\nfor i in range(a):\r\n res.append([])\r\n for j in range(b):\r\n res[i].append(0)\r\nfor i in range(n):\r\n res[i // b][i % b] = i + 1\r\n\r\nfor j in range(1, a, 2):\r\n res[j].reverse()\r\n\r\nfor i in range(a):\r\n print(\" \".join(map(str, res[i])))\r\n",
"import sys, io, os\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport string\r\nimport re\r\nfrom decimal import *\r\nfrom collections import defaultdict,Counter,deque\r\n \r\ndef I():\r\n return input()\r\n \r\ndef II():\r\n return int(input())\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \r\ndef LI():\r\n return list(input().split())\r\n \r\ndef LII():\r\n return list(map(int, input().split()))\r\n \r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n \r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n \r\ndef WRITE(out):\r\n return print('\\n'.join(map(str, out)))\r\n \r\ndef WS(out):\r\n return print(' '.join(map(str, out)))\r\n \r\ndef WNS(out):\r\n return print(''.join(map(str, out)))\r\n\r\ndef WSNOPRINT(out):\r\n return ''.join(map(str, out))\r\n\r\n\"\"\"\r\n\"\"\"\r\ndef solve():\r\n n,a,b = MII()\r\n if a*b < n:\r\n print(-1)\r\n else:\r\n for r in range(a):\r\n if r&1:\r\n WS([x+1 if x<n else 0 for x in range(r*b, (r+1)*b)][::-1])\r\n else:\r\n WS([x+1 if x<n else 0 for x in range(r*b, (r+1)*b)])\r\n\r\ndef main():\r\n solve()\r\n\r\nmain()",
"n,a,b=map(int,input().split())\nif n>a*b:\n\tprint(-1);exit()\nseats=list(range(1,n+1))+[0]*(a*b-n)\nfor i in range(a):\n\trow=seats[i*b:i*b+b]\n\tprint(' '.join(map(str,row if b%2 or i%2 else row[::-1])))\n",
"n,a,b = (int(i) for i in input().split())\nans = [[0 for i in range(b)] for j in range(a)]\nif n>a*b:\n print(-1)\nelse:\n k = 1\n for i in range(a):\n for j in range(b):\n if n == 0 :\n break\n else:\n ans[i][j] = k\n k+=1\n n-=1\n if b%2 == 1:\n for i in range(a):\n print(' '.join(list(map(str,ans[i]))))\n else:\n for i in range(a):\n if i%2 == 0:\n print(' '.join(list(map(str,ans[i]))))\n else:\n ans[i] = [ans[i][-1]]+ans[i][0:-1]\n print(' '.join(list(map(str,ans[i]))))\n \n \n \n \n ",
"n, a, b = map(int, input().split())\r\n\r\nif n > a * b:\r\n print(-1)\r\nelse:\r\n now = 1\r\n flag = False\r\n for i in range(a):\r\n ans = []\r\n for _ in range(b):\r\n if i % 2 == 0:\r\n ans.append(now)\r\n else:\r\n ans.insert(0, now)\r\n if not flag:\r\n now += 1\r\n if now > n:\r\n now = 0\r\n flag = True\r\n print(*ans)",
"n, a, b = map(int, input().split())\nif n > a * b:\n print(-1)\nelse:\n for i in range(a):\n for j in range(b):\n z = i * b + j + 1 if b % 2 == 1 or i % 2 == 0 else (i + 1) * b - j\n print(0 if z > n else z, end=' ')\n print()\n",
"import math\r\nfrom collections import deque\r\n\r\n\r\nalfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26}\r\nrasp=''\r\n#c=int(input())\r\nfor i in range(0,1):\r\n n,a,b=map(int,input().split())\r\n #n=int(input())\r\n #print(n,a,b)\r\n #stringul=input()\r\n \r\n #lista=list(map(int,input().split()))\r\n #lista.sort()\r\n #primul=str(lista[0])\r\n cd=1\r\n cr=2\r\n ct=0\r\n \r\n if n>a*b:\r\n print(-1)\r\n else: \r\n for i in range(0,a):\r\n for j in range(0,b):\r\n if (i&1)==(j&1):\r\n if cd<=n:\r\n print(cd,end=' ')\r\n cd+=2\r\n else:\r\n print(0, end=' ')\r\n else:\r\n if cr<=n:\r\n print(cr,end=' ')\r\n cr+=2\r\n else:\r\n print(0, end=' ')\r\n print()\r\n# print(dictionar)\r\n \r\n \r\n#print(rasp) ",
"n, a, b = map(int, input().split())\r\nif n > a * b:\r\n print(-1)\r\nelse:\r\n for i in range(a):\r\n c = list(range(i * b + 1, min((i + 1) * b, n) + 1))\r\n c += [0] * (b - len(c))\r\n if b % 2 == 0 and i % 2 == 1:\r\n c.reverse()\r\n print(' '.join(map(str, c)))",
"read = lambda: map(int, input().split())\r\nn, a, b = read()\r\ncur1, cur2 = 1, 2\r\np = [[0] * b for i in range(a)]\r\nfor i in range(a):\r\n for j in range(b):\r\n cur = i * b + j + 1\r\n if cur <= n: p[i][j] = cur\r\nif b % 2 == 0:\r\n for i in range(1, a, 2):\r\n p[i] = p[i][1:] + [p[i][0]]\r\nif a * b >= n: [print(*i) for i in p]\r\nelse: print(-1)\r\n",
"n, a, b = map(int, input().split())\r\nif n > a * b:\r\n print(-1)\r\nelse:\r\n c = [[0 for j in range(b)] for i in range(a)]\r\n p = 1\r\n i = 0\r\n j = 0\r\n while p <= n:\r\n if i % 2 == 0:\r\n for j in range(b):\r\n if p > n:\r\n break\r\n c[i][j] = p\r\n p += 1\r\n else:\r\n for j in reversed(range(b)):\r\n if p > n:\r\n break\r\n c[i][j] = p\r\n p += 1\r\n i += 1\r\n for i in range(a):\r\n print(*c[i])\r\n",
"n, a, b = map(int, (input().split()))\r\nif n > (a * b):\r\n print(-1)\r\nelse:\r\n for i in range(a):\r\n if (b % 2 == 0) and ((i + 1) % 2 == 0):\r\n for c in range(b * (i + 1), b * (i + 1) - b, -1):\r\n if c <= n:\r\n print(c, end='\\t')\r\n else:\r\n print(0, end='\\t')\r\n else:\r\n for c in range((b * (i + 1) - b) + 1, b * (i + 1) + 1):\r\n if c <= n:\r\n print(c, end='\\t')\r\n else:\r\n print(0, end='\\t')\r\n print()\r\n\r\n\r\n # n, a, b = map(int, (input().split()))\r\n # if n > (a * b):\r\n # print(-1)\r\n # else:\r\n # c = 0\r\n # for i in range(a):\r\n # if (b % 2 == 0) and (i % 2 == 1):\r\n # c += b + 1\r\n # for _ in range(b):\r\n # if b % 2 == 0 and (i % 2 == 1):\r\n # c -= 1\r\n # else:\r\n # c += 1\r\n # if c <= n:\r\n # print(c, end='\\t')\r\n # else:\r\n # print(0, end='\\t')\r\n # print()\r\n # if (b % 2 == 0) and (i % 2 == 1):\r\n # c += b - 1\r\n",
"n,a,b=list(int(x) for x in input().split(' '))\n\ndef parlament(n,a,b):\n if n>a*b:\n print(-1)\n return 0\n if(n>=b):\n up=list(range(1,b+1))\n current=list(range(1,b+1))\n else:\n up=list(range(1,n+1))\n current=list(range(1,n+1))\n for x in range(b-n):\n current.append(0)\n print(*current)\n current=list()\n chet=b-(b%2)\n nechet=(b-1)+(b-chet)+2\n chet+=2\n\n\n for i in range(a-1):\n\n for j in range(b):\n\n\n if(nechet<=n and up[j]%2==0):\n\n print(nechet,end=' ')\n\n current.append(nechet)\n nechet=(nechet+2)\n elif(chet<=n and up[j]%2!=0):\n\n print(chet,end=' ')\n\n current.append(chet)\n chet=(chet+2)\n else:\n print(0, end=' ')\n up=list(current)\n current=list()\n\n\n\n\n print()\n\n\n\nparlament(n,a,b)",
"n, a, b = [int(s) for s in input().split()]\nif (n > a * b):\n print(-1)\nelse:\n m = [[0 for i in range(b)] for j in range(a)]\n i, j = 0, 0\n dj = 1\n for cur in range(1, n + 1):\n m[i][j] = cur\n j = j + dj\n if (j == -1):\n i, j = i+1, 0\n dj = 1\n if (j == b):\n i, j = i+1, b-1 \n dj = -1\n for row in m:\n print(' '.join([str(elem) for elem in row]))\n\n",
"def main():\n n, a, b = map(int, input().split())\n if n > a * b:\n print(-1)\n return\n res = [[0] * b for _ in range(a)]\n for i in range(n):\n y, x = divmod(i, b)\n res[y][b - x - 1 if y & 1 else x] = i + 1\n for row in res:\n print(' '.join(map(str, row)))\n\n\nif __name__ == '__main__':\n main()\n",
"# You lost the game.\nn, a, b = map(int, input().split())\ndem = n//2 + n%2\ni = 1\nwhile dem > 0 and i <= a:\n dem -= b//2 + (i%2)*(b%2)\n i += 1\nif dem > 0:\n print(-1)\nelse:\n dem = n//2 + n%2\n demo = [2*k+1 for k in range(dem)]\n rep = [2*k for k in range(1,n//2+1)]\n d = 0\n r = 0\n l = 0\n for i in range(a):\n l = 1-l\n e = l\n for j in range(b):\n if e and d < dem:\n print(demo[d],end=\" \")\n d += 1\n elif e == 0 and r < n//2:\n print(rep[r],end=\" \")\n r += 1\n else:\n print(0,end=\" \")\n e = 1-e\n print()\n \n ",
"n,a,b=map(int,input().split())\r\nans=[0]*b\r\nm=1\r\nif a*b<n: print('-1')\r\nelse:\r\n for i in range(a):\r\n for j in range(b):\r\n if m<=n: ans[j]=m\r\n m+=1\r\n if i%2==0: print(*ans)\r\n else: print(*ans[::-1])\r\n ans=[0]*b",
"n,a,b = map(int, input().split())\r\n\r\nif(a*b<n):\r\n print(\"-1\")\r\nelif(b%2!=0):\r\n for i in range(a):\r\n for j in range(1,b+1):\r\n if(i*b+j<=n):\r\n print(i*b+j, end=\" \")\r\n else:\r\n print(\"0\", end=\" \")\r\n print()\r\nelse:\r\n for i in range(a):\r\n if(i%2==0):\r\n for j in range(1,b+1):\r\n if(i*b+j<=n):\r\n print(i*b+j, end=\" \")\r\n else:\r\n print(\"0\", end=\" \")\r\n else:\r\n for j in range(b,0,-1):\r\n if(i*b+j<=n):\r\n print(i*b+j, end=\" \")\r\n else:\r\n print(\"0\", end=\" \")\r\n print()",
"st = list(map(int, input().split()))\r\nn = st[0]\r\na = st[1]\r\nb = st[2]\r\nk = 1\r\ndata = [[0] * b for i in range(a)]\r\nif n <= a * b:\r\n for i in range(a):\r\n for j in range(b):\r\n if k <= n:\r\n data[i][j] = k\r\n k += 1\r\n if b % 2 == 0:\r\n for i in range(1, a, 2):\r\n data[i] = reversed(data[i])\r\n for i in range(a):\r\n print(*data[i])\r\nelse:\r\n print(-1)",
"n, a, b = map(int, input().split())\r\nif n > a * b:\r\n\tprint(-1)\r\nelif b % 2:\r\n\tfor i in range(a):\r\n\t\tfor j in range(b):\r\n\t\t\tx = b * i + j +1\r\n\t\t\tprint(x if x <= n else 0,end = \" \")\r\n\t\tprint()\r\nelse:\r\n\tfor i in range(a):\r\n\t\tif i % 2 == 0:\r\n\t\t\tfor j in range(b):\r\n\t\t\t\tx = b * i + j +1\r\n\t\t\t\tprint(x if x <= n else 0,end = \" \")\r\n\t\telse:\r\n\t\t\tfor j in range(b):\r\n\t\t\t\tx = b * (i+1) - j\r\n\t\t\t\tprint(x if x <= n else 0,end = \" \")\r\n\t\tprint()\r\n"
] | {"inputs": ["3 2 2", "8 4 3", "10 2 2", "1 1 1", "8 3 3", "1 1 100", "1 100 1", "12 4 3", "64 8 9", "13 2 6", "41 6 7", "9999 100 100", "10000 100 100", "2099 70 30", "2098 30 70", "10000 1 1", "1583 49 36", "4825 77 88", "26 1 33", "274 25 77", "694 49 22", "3585 77 62", "3 1 6", "352 25 59", "150 53 3", "4227 91 80", "378 19 25", "2357 43 65", "232 71 9", "2362 91 62", "4601 59 78", "4439 74 60", "3733 89 42", "335 12 28", "440 26 17", "109 37 3", "4416 52 85", "5025 75 67", "4983 89 56", "950 17 56", "1637 40 41", "1142 52 22", "907 70 13", "7279 80 91", "1653 87 19", "15 2 8", "1459 17 86", "3035 40 76", "3095 50 62", "3055 65 47", "2638 80 33", "29 3 11", "16 18 1", "2240 27 83", "1264 55 23", "5400 75 72", "46 3 16", "1512 27 56", "4206 86 12", "2358 14 56", "5420 35 96", "7758 63 41", "9806 87 93", "99 1 97", "1053 25 42", "4217 49 86", "2312 77 30", "74 1 71", "1 99 100", "1 57 99", "4785 55 87", "4611 53 87", "9801 99 99", "8096 92 88", "5916 68 87", "8928 93 96", "7743 89 87", "3128 46 68", "3800 40 95", "5368 61 88", "2583 41 63", "4056 52 78", "3822 42 91", "5358 57 94", "2961 47 63"], "outputs": ["1 2 \n0 3 ", "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 ", "-1", "1 ", "1 2 3 \n4 5 6 \n7 8 0 ", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "1 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 ", "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 ", "1 2 3 4 5 6 7 8 9 \n10 11 12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 26 27 \n28 29 30 31 32 33 34 35 36 \n37 38 39 40 41 42 43 44 45 \n46 47 48 49 50 51 52 53 54 \n55 56 57 58 59 60 61 62 63 \n64 0 0 0 0 0 0 0 0 ", "-1", "1 2 3 4 5 6 7 \n8 9 10 11 12 13 14 \n15 16 17 18 19 20 21 \n22 23 24 25 26 27 28 \n29 30 31 32 33 34 35 \n36 37 38 39 40 41 0 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 \n32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 \n61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 \n92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 \n121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 \n152 151 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 \n72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 \n141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "-1", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 \n38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 \n73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 \n110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 \n145 146 147 148 149 150 151 152 153...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 0 0 0 0 0 0 0 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 \n78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 \n...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 \n45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 \n89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 \n112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 0 0 0 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 \n60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 \n119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 \n13 14 15 \n16 17 18 \n19 20 21 \n22 23 24 \n25 26 27 \n28 29 30 \n31 32 33 \n34 35 36 \n37 38 39 \n40 41 42 \n43 44 45 \n46 47 48 \n49 50 51 \n52 53 54 \n55 56 57 \n58 59 60 \n61 62 63 \n64 65 66 \n67 68 69 \n70 71 72 \n73 74 75 \n76 77 78 \n79 80 81 \n82 83 84 \n85 86 87 \n88 89 90 \n91 92 93 \n94 95 96 \n97 98 99 \n100 101 102 \n103 104 105 \n106 107 108 \n109 110 111 \n112 113 114 \n115 116 117 \n118 119 120 \n121 122 123 \n124 125 126 \n127 128 129 \n130 131 132 \n133...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \n82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \n26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \n51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 \n76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 \n126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 \n151 152...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 \n66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 \n131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 \n10 11 12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 26 27 \n28 29 30 31 32 33 34 35 36 \n37 38 39 40 41 42 43 44 45 \n46 47 48 49 50 51 52 53 54 \n55 56 57 58 59 60 61 62 63 \n64 65 66 67 68 69 70 71 72 \n73 74 75 76 77 78 79 80 81 \n82 83 84 85 86 87 88 89 90 \n91 92 93 94 95 96 97 98 99 \n100 101 102 103 104 105 106 107 108 \n109 110 111 112 113 114 115 116 117 \n118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 \n136 137 138 139 140 141 142 143 144 \n145 146 147...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 \n80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \n62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 \n121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 \n44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 \n85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 \n30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 \n57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 \n86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 \n142 141 144 143 146 145 148 147 150 149 152 151 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 \n18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 \n35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 \n52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 \n69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 \n86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 \n103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 \n120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 \n137 138 139 140 141 142 143 144 145 146 147 148 149 150 151...", "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 \n13 14 15 \n16 17 18 \n19 20 21 \n22 23 24 \n25 26 27 \n28 29 30 \n31 32 33 \n34 35 36 \n37 38 39 \n40 41 42 \n43 44 45 \n46 47 48 \n49 50 51 \n52 53 54 \n55 56 57 \n58 59 60 \n61 62 63 \n64 65 66 \n67 68 69 \n70 71 72 \n73 74 75 \n76 77 78 \n79 80 81 \n82 83 84 \n85 86 87 \n88 89 90 \n91 92 93 \n94 95 96 \n97 98 99 \n100 101 102 \n103 104 105 \n106 107 108 \n109 0 0 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 \n86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 \n68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 \n135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 \n42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 \n83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 \n124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 \n45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 \n89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 \n112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152...", "1 2 3 4 5 6 7 8 9 10 11 12 13 \n14 15 16 17 18 19 20 21 22 23 24 25 26 \n27 28 29 30 31 32 33 34 35 36 37 38 39 \n40 41 42 43 44 45 46 47 48 49 50 51 52 \n53 54 55 56 57 58 59 60 61 62 63 64 65 \n66 67 68 69 70 71 72 73 74 75 76 77 78 \n79 80 81 82 83 84 85 86 87 88 89 90 91 \n92 93 94 95 96 97 98 99 100 101 102 103 104 \n105 106 107 108 109 110 111 112 113 114 115 116 117 \n118 119 120 121 122 123 124 125 126 127 128 129 130 \n131 132 133 134 135 136 137 138 139 140 141 142 143 \n144 145 146 147 148 149 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 \n92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \n20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 \n39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 \n58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 \n96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 \n115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 \n134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 1...", "1 2 3 4 5 6 7 8 \n10 9 12 11 14 13 0 15 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 \n88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 \n153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 \n48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 \n95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 \n142 143 144 145 146 147 148 149 150 151 152 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 \n34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 \n100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153...", "1 2 3 4 5 6 7 8 9 10 11 \n12 13 14 15 16 17 18 19 20 21 22 \n23 24 25 26 27 28 29 0 0 0 0 ", "1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n0 \n0 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 \n84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 \n24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 \n47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 \n70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 \n93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 \n116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 \n139 140 141 142 143 144 145 146 147 148 149 150 151 152...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 \n74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 \n145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \n18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 \n33 34 35 36 37 38 39 40 41 42 43 44 45 46 0 0 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 \n100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 \n98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 \n88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 \n70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 \n137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 \n96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 \n64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 \n80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 \n92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 \n96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1...", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 \n64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."]} | UNKNOWN | PYTHON3 | CODEFORCES | 86 | |
2d41028b2f20a6fa7a921b8da75abb0f | Constructing Tests | Let's denote a *m*-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size *m*<=×<=*m* of this matrix contains at least one zero.
Consider the following problem:
You are given two integers *n* and *m*. You have to construct an *m*-free square matrix of size *n*<=×<=*n* such that the number of 1's in this matrix is maximum possible. Print the maximum possible number of 1's in such matrix.
You don't have to solve this problem. Instead, you have to construct a few tests for it.
You will be given *t* numbers *x*1, *x*2, ..., *x**t*. For every , find two integers *n**i* and *m**i* (*n**i*<=≥<=*m**i*) such that the answer for the aforementioned problem is exactly *x**i* if we set *n*<==<=*n**i* and *m*<==<=*m**i*.
The first line contains one integer *t* (1<=≤<=*t*<=≤<=100) — the number of tests you have to construct.
Then *t* lines follow, *i*-th line containing one integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Note that in hacks you have to set *t*<==<=1.
For each test you have to construct, output two positive numbers *n**i* and *m**i* (1<=≤<=*m**i*<=≤<=*n**i*<=≤<=109) such that the maximum number of 1's in a *m**i*-free *n**i*<=×<=*n**i* matrix is exactly *x**i*. If there are multiple solutions, you may output any of them; and if this is impossible to construct a test, output a single integer <=-<=1.
Sample Input
3
21
0
1
Sample Output
5 2
1 1
-1
| [
"def main():\r\n\tt = int(input())\r\n\tfor _ in range(t):\r\n\t\tnum = int(input())\r\n\t\tif num == 0:\r\n\t\t\tprint(1, 1)\r\n\t\telse:\r\n\t\t\tok = False\r\n\t\t\tdiv = 1\r\n\t\t\twhile div * div <= num:\r\n\t\t\t\tif num % div == 0:\r\n\t\t\t\t\tadd = max(num // div, div)\r\n\t\t\t\t\tsub = min(num // div, div)\r\n\t\t\t\t\tif (add + sub) % 2 == 0:\r\n\t\t\t\t\t\tn = (add + sub) // 2\r\n\t\t\t\t\t\tnum_zeros = (add - sub) // 2\r\n\t\t\t\t\t\tif num_zeros != 0:\r\n\t\t\t\t\t\t\tk = n // num_zeros\r\n\t\t\t\t\t\t\tif n ** 2 - (n // k) ** 2 == num:\r\n\t\t\t\t\t\t\t\tok = True\r\n\t\t\t\t\t\t\t\tbreak\r\n\t\t\t\tdiv += 1\r\n\t\t\tif ok:\r\n\t\t\t\tprint(n, k)\r\n\t\t\telse:\r\n\t\t\t\tprint(-1)\r\n\r\n\r\nif __name__ == '__main__':\r\n\tmain()\r\n",
"import math \r\n \r\ndef div(k):\r\n res = []\r\n for i in range(1,int(math.sqrt(k))+2):\r\n if k % i == 0:\r\n res.append(i)\r\n return res\r\n \r\nt = int(input())\r\nfor i in range(t):\r\n x = int(input())\r\n if x == 0:\r\n print(\"1 1\")\r\n elif x == 1:\r\n print(-1)\r\n else: \r\n flag = False\r\n di = div(x)\r\n for d in di:\r\n a = x // d\r\n if ((a+d) % 2 == 0) and (a > d):\r\n n = (a+d)//2\r\n lower = (a+d) / (a-d+2)\r\n upper = (a+d) / (a-d)\r\n if int(lower) < int(upper):\r\n m = int(upper)\r\n res = [n,m]\r\n flag = True\r\n break\r\n if flag == True:\r\n print(' '.join(map(str, res)))\r\n else:\r\n print(-1)\r\n",
"import math\r\nt = int(input())\r\nfor _ in range(t):\r\n suc = False\r\n x = int(input())\r\n for n in range(int(x**0.5)+1,int((4*x/3)**0.5)+2):\r\n if int((n**2-x)**0.5)**2 == n**2-x:\r\n mm = int((n**2-x)**0.5)\r\n m = math.floor(n/mm)\r\n if n**2-(n//m)**2 == x:\r\n print(n,m)\r\n suc = True\r\n break\r\n if not suc: print(-1)",
"import sys,math,itertools\r\nfrom collections import Counter,deque,defaultdict\r\nfrom bisect import bisect_left,bisect_right \r\nfrom heapq import heappop,heappush,heapify\r\nfrom copy import deepcopy\r\nmod = 10**9+7\r\nINF = float('inf')\r\ndef inp(): return int(sys.stdin.readline())\r\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\r\ndef inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split()))\r\ndef inps(): return sys.stdin.readline()\r\ndef inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x])\r\ndef err(x): print(x); exit()\r\n\r\nfor _ in range(inp()):\r\n X = inp()\r\n if X == 0: print(1,1); continue\r\n elif X == 1: print(-1); continue\r\n res = -1\r\n for n in range(2,5*10**4):\r\n k2 = n**2-X\r\n if k2 <= 0: continue\r\n k = math.sqrt(k2)\r\n if k>=1 and k.is_integer():\r\n k = int(k)\r\n M = n//k\r\n for m in range(M-3,M+3):\r\n if m>=1 and n//m == k:\r\n res = [n,m]; break\r\n if res != -1: break\r\n if res == -1: print(-1)\r\n else: print(*res)",
"import heapq;\r\nimport math;\r\nfrom collections import Counter, deque;\r\nimport sys;\r\nmod = 10**9 + 7;\r\n\r\n\r\n\r\ninput = sys.stdin.readline;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nt = int(input())\r\n\r\n\r\nfor _ in range(t):\r\n x = int(input())\r\n\r\n\r\n\r\n def solve():\r\n\r\n def exec(n):\r\n\r\n leftPointer, rightPointer = 1, n;\r\n\r\n\r\n while rightPointer >= leftPointer:\r\n middlePointer = (leftPointer + rightPointer) // 2;\r\n\r\n rel = (n * n) - ((n // middlePointer)**2)\r\n if rel == x:\r\n return middlePointer;\r\n\r\n if rel > x:\r\n rightPointer = middlePointer - 1;\r\n else:\r\n leftPointer = middlePointer + 1;\r\n\r\n return None;\r\n\r\n for n in range(1, 4 * 10**4):\r\n if n * n >= x:\r\n ans = exec(n);\r\n if ans is not None:\r\n return n, ans;\r\n\r\n return -1, -1;\r\n\r\n left, right = solve();\r\n\r\n if left == -1:\r\n print(-1)\r\n else:\r\n print(left, right);\r\n",
"from math import ceil\nt = int(input())\nfor _ in range(t):\n x = int(input())\n if x == 1 or x % 4 == 2:\n print(-1)\n elif x == 0:\n print(1,1)\n else:\n z = 0\n for i in range(ceil((x/3)**0.5),ceil(x**0.5)):\n if x % i == 0 and (x//i-i) % 2 == 0:\n n = (i + x//i)//2\n k = (x//i - i)//2\n m = n//k\n if n//m == k:\n print(n,m)\n z = 1\n break\n if z == 0:\n print(-1)\n\n ",
"import math\r\ndef solve(n, x):\r\n if n * n <= x:\r\n return -1\r\n i = n * n\r\n low, high = 2, n\r\n while low <= high:\r\n mid = (low + high) // 2\r\n j = n // mid\r\n k1 = i - j * j\r\n if k1 == x:\r\n return mid\r\n elif k1 < x:\r\n low = mid + 1\r\n elif k1 > x:\r\n high = mid - 1\r\n return -1\r\nt = int(input())\r\nfor _ in range(t):\r\n x = int(input())\r\n if x == 0:\r\n n = m = 1\r\n else:\r\n for i in range(int(math.sqrt(x)), int(1e5)):\r\n if (i * i - (i // 2) * (i // 2)) > int(1e9):\r\n n = m = -1\r\n break\r\n m = solve(i, x)\r\n if m != -1:\r\n n = i\r\n break\r\n if n == -1:\r\n print(-1)\r\n else:\r\n print(n, m)# 1691673473.4074228",
"from math import *\nMAXX = 100000000\n\n\n'''**************Solution is Here***********'''\n\ndef construct(xi):\n n = int(sqrt(xi)) + 1\n n2 = n**2\n\n while( n2<=2*xi and n<=MAXX):\n nsm2 = n2-xi\n nsm = sqrt(nsm2)\n if( nsm==int(nsm)):\n m = n//nsm\n if( n2-(n//m)**2 == xi):\n return n, int(m)\n n += 1\n n2 = n**2\n return -1, -1\n\ndef solve():\n T = int(input())\n for _ in range(T):\n xi = int(input())\n # a = [int(x) for x in input().split(' ')]\n if(xi==0):\n print('1 1')\n continue\n n,m = construct(xi)\n if(m==-1):\n print(-1)\n else:\n print(n,m)\nsolve()\n \t \t\t\t\t \t \t\t \t\t\t \t \t\t\t\t",
"# ans = n^2 - (n//m)^2\r\n# let n // m = d\r\n# ans = (n - d)(n + d)\r\n# \r\n\r\nfrom math import sqrt\r\n\r\ndef check(ans, a):\r\n\tb = ans // a\r\n\t# n - d = a\r\n\t# n + d = b\r\n\t# 2n = a + b\r\n\tif (a + b) % 2:\r\n\t\treturn False\r\n\tn = (a + b) // 2\r\n\td = b - n\r\n\t\r\n\tif 1 <= d and d <= n:\r\n\t\tm = max(1, n // d - 1)\r\n\t\tfor i in range(3):\r\n\t\t\tif n // m == d:\r\n\t\t\t\tprint(n, m)\r\n\t\t\t\treturn True\r\n\t\t\tm += 1\r\n\telse:\r\n\t\treturn False\r\n\r\ndef main():\r\n\tT = int(input())\r\n\twhile T:\r\n\t\tT -= 1\r\n\t\tans = int(input())\r\n\t\t\r\n\t\tif ans == 0:\r\n\t\t\tprint(1, 1)\r\n\t\t\tcontinue\r\n\t\t\r\n\t\tfor i in range(1, int(sqrt(ans)) + 1):\r\n\t\t\tif ans % i == 0 and check(ans, i):\r\n\t\t\t\tbreak\r\n\t\telse:\r\n\t\t\tprint(-1)\r\nmain()",
"from math import *\r\n\r\ndef calcul(xi):\r\n\tn=int(sqrt(xi))+1\r\n\tn2=n**2\r\n\twhile n2<=2*xi and n<=1000000000:\r\n\t\tnsm2=n2-xi\r\n\t\tnsm=sqrt(nsm2)\r\n\t\tif nsm==int(nsm):\r\n\t\t\tm=n//nsm\r\n\t\t\tif n2 - (n//m)**2 == xi:\r\n\t\t\t\treturn n, int(m)\r\n\t\tn+=1\r\n\t\tn2=n**2\r\n\treturn -1,-1\r\n\r\nt=int(input())\r\nfor _ in range(t):\r\n\txi=int(input())\r\n\tif xi==0:\r\n\t\tprint(\"1 1\")\r\n\t\tcontinue\r\n\tn,m=calcul(xi)\r\n\tif m==-1:\r\n\t\tprint(-1)\r\n\telse:\r\n\t\tprint(n,m)\r\n",
"from math import sqrt\r\n\r\n# import sys\r\n# from io import StringIO\r\n# sys.stdin = StringIO(open(__file__.replace('.py', '.in')).read())\r\n\r\nt = int(input())\r\n\r\nfor _ in range(t):\r\n n = int(input())\r\n\r\n if n == 0:\r\n print(1, 1)\r\n continue\r\n\r\n sq = int(sqrt(n)) + 1\r\n while sq * sq <= 2 * n:\r\n zs = sqrt(sq * sq - n)\r\n if zs.is_integer():\r\n m = sq // zs\r\n if sq * sq - (sq // m) ** 2 == n:\r\n print(sq, int(m))\r\n break\r\n sq += 1\r\n else:\r\n print(-1)\r\n",
"\"\"\"Codeforces P938C. Constructing Tests\r\n (http://codeforces.com/problemset/problem/938/C)\r\n\r\nProblem tags: binary search, brute force\r\n\r\nTime Complexity: O(sqrt(x))\r\n\"\"\"\r\n\r\nimport atexit\r\nimport io\r\nimport math\r\nimport sys\r\n\r\n# IO Buffering\r\n_INPUT_LINES = sys.stdin.read().splitlines()\r\ninput = iter(_INPUT_LINES).__next__\r\n_OUTPUT_BUFFER = io.StringIO()\r\nsys.stdout = _OUTPUT_BUFFER\r\n\r\[email protected]\r\ndef write():\r\n sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())\r\n \r\n \r\ndef main():\r\n t = int(input())\r\n for _ in range(t):\r\n x = int(input())\r\n if x== 0:\r\n print(1, 1)\r\n continue\r\n \r\n n = math.ceil(x ** 0.5)\r\n while True:\r\n if n * n - (n // 2) ** 2 > x:\r\n print(-1)\r\n break\r\n \r\n t = math.floor((n * n - x) ** 0.5)\r\n if t > 0 and t * t == n * n - x:\r\n m = n // t\r\n if t == n // m:\r\n print(n, m)\r\n break\r\n n += 1\r\n\r\n \r\nif __name__ == '__main__':\r\n main()\r\n",
"def test(x):\r\n i=1\r\n flag=False\r\n while i**2 < x:\r\n if x % i==0:\r\n a,b=i,x//i\r\n if (a+b)%2==0:\r\n z=(a+b)//2\r\n y=b-z\r\n u=z//y\r\n if (z//u==y):\r\n y=u\r\n flag=True\r\n break\r\n i+=1\r\n if flag:\r\n print(str(z)+\" \"+str(y))\r\n\r\n else:\r\n if x==0:\r\n print(\"1 1\")\r\n else:\r\n print(\"-1\")\r\nn=int(input())\r\nfor j in range(n):\r\n test(int(input()))\r\n\r\n \r\n"
] | {"inputs": ["3\n21\n0\n1", "1\n420441920", "1\n4", "1\n297540", "1\n9", "1\n144", "1\n16", "1\n25", "1\n999944", "1\n6", "1\n14", "1\n81", "1\n2", "1\n36", "1\n2925", "1\n5704", "1\n4104", "1\n1980", "1\n10", "1\n4860", "1\n2601", "1\n28", "1\n56"], "outputs": ["5 2\n1 1\n-1", "-1", "-1", "546 22", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "77 5", "-1", "-1", "-1", "72 4", "-1", "-1", "-1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
2d4b95f543aaa58b6d6b05cdb200b4f4 | Alternating Sum | You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it's satisfied that $s_{i} = s_{i - k}$.
Find out the non-negative remainder of division of $\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}$ by $10^{9} + 9$.
Note that the modulo is unusual!
The first line contains four integers $n, a, b$ and $k$ $(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$.
The second line contains a sequence of length $k$ consisting of characters '+' and '-'.
If the $i$-th character (0-indexed) is '+', then $s_{i} = 1$, otherwise $s_{i} = -1$.
Note that only the first $k$ members of the sequence are given, the rest can be obtained using the periodicity property.
Output a single integer — value of given expression modulo $10^{9} + 9$.
Sample Input
2 2 3 3
+-+
4 1 5 1
-
Sample Output
7
999999228
| [
"def power(x, y):\r\n return pow(x, y, M)\r\ndef inv(y):\r\n return pow(y, M-2, M)\r\nn, a, b, k = map(int,input().split())\r\nM = 10**9 + 9\r\n\r\ns = [1 if c == \"+\" else -1 for c in input()]\r\n\r\n# Period k-1\r\nperiod = sum(s[i] * power(a, n-i) * power(b, i) for i in range(k))%M\r\n\r\n# Ratio (b/a)^k\r\n\r\nratio = power(b, k) * inv(power(a, k)) % M\r\n\r\n# Total terms\r\n\r\nterms = (n+1)//k\r\n\r\nif(ratio == 1):\r\n print(terms*period % M)\r\nelse:\r\n # Geometric Progression Formula\r\n print(period * (power(ratio, terms) - 1) * inv(ratio-1) %M)\r\n",
"M = 0x3b9aca09\ninv = lambda x: pow(x, M - 2, M)\nn, a, b, k = map(int, input().split())\ns = input()\nc = inv(a) * b % M\nq = pow(c, k, M)\nm = (n + 1) // k\np = (pow(q, m, M) - 1) * inv(q - 1) % M if q - 1 else m\nx = pow(a, n, M)\nr = 0\nfor i in range(k):\n r = (r + [-1, 1][s[i] == '+'] * x * p) % M\n x = (x * c) % M\nprint(r)\n\n \t \t \t\t\t\t \t \t\t \t \t\t\t\t",
"MOD = int(1e9+9)\r\nn, a, b, k = map(int, input().split())\r\ns = input()\r\n\r\ndef solve():\r\n res = 0\r\n q = pow(b, k, MOD) * pow(pow(a, k, MOD), MOD-2, MOD) % MOD\r\n max_pow = pow(a, n, MOD)\r\n c = b * pow(a, MOD-2, MOD) % MOD\r\n for i in range(k):\r\n res += max_pow if s[i] == '+' else -max_pow\r\n res = (res % MOD + MOD) % MOD\r\n max_pow = max_pow * c % MOD\r\n t = (n + 1) // k\r\n if q == 1:\r\n return t * res % MOD\r\n z = (pow(q, t, MOD) - 1) * pow(q-1, MOD-2, MOD) % MOD\r\n return z * res % MOD\r\n\r\nprint(solve())",
"n, a, b, k = map(int, input().split())\r\ns = input()\r\n\r\nm = int(1e9 + 9)\r\na_1 = pow(a, m - 2, m)\r\nx = (a_1 * b) % m\r\nxk = pow(x, k, m)\r\n# print(\"xk\", xk)\r\n\r\nC = 0\r\nfor i in range(0, k):\r\n\tz = 1 if s[i] == \"+\" else -1\r\n\tC = (C + z * pow(x, i, m)) % m\r\n# print(\"C\", C)\r\n\t\r\nkk = (n + 1) // k\r\nif xk > 1:\r\n\tv1 = (pow(xk, kk, m) - 1) % m\r\n\tv2 = pow( (xk - 1) % m, m - 2, m)\r\n\tD = (v1 * v2) % m\r\nelse:\r\n\tD = kk\r\n# print(\"D\", D)\r\n\t\r\nans = pow(a, n, m) * C * D\r\nans %= m\r\nprint(ans)\r\n",
"import sys\r\n\r\n\r\nMOD = 10**9 + 9\r\n\r\ndef inv(x):\r\n return pow(x, MOD-2, MOD)\r\n\r\ndef alternateSum(n,a,b,k,s):\r\n res = 0\r\n q = (pow(b, k, MOD) * inv(pow(a, k, MOD))) % MOD\r\n max_pow = pow(a, n, MOD)\r\n c = b * inv(a) % MOD\r\n for i in range(k):\r\n if s[i] == '+':\r\n res += max_pow\r\n elif s[i] == '-':\r\n res -= max_pow\r\n res %= MOD\r\n max_pow = (max_pow * c) % MOD\r\n t = (n+1) // k\r\n if q == 1:\r\n return (t*res) % MOD\r\n z = ((pow(q, t, MOD) - 1) * inv(q-1)) % MOD\r\n return z * res % MOD\r\n\r\nn, a, b, k, s = sys.stdin.read().split()\r\nresult = alternateSum(int(n), int(a), int(b), int(k), s)\r\n\r\nprint(result)",
"###From Jasnah bobb31\\\r\n###From Jasnah bobb31\r\n###From Jasnah bobb31\r\n###From Jasnah bobb31\r\nmod = 10**9 + 9\r\ndef quick_pow(a, b):\r\n ans = 1\r\n while b:\r\n if b % 2:\r\n ans = (ans * a) % mod\r\n a = (a * a) % mod\r\n b //= 2\r\n return ans\r\nn, a, b, k = map(int, input().split())\r\ns = input()\r\nx = quick_pow(a, n)\r\nxx = quick_pow(a, mod - 2)\r\nxxx = 1\r\ny = quick_pow(b, n)\r\nyy = quick_pow(b, mod - 2)\r\nyyy = 1\r\nmark = 0\r\nres = 0\r\nfor i in range(k):\r\n if s[i] == '+':\r\n mark = 1\r\n else:\r\n mark = -1\r\n res = (res + mark * x * yyy) % mod\r\n x = (x * xx) % mod\r\n yyy = (yyy * b) % mod\r\nnum = (n + 1) // k\r\ndivide = quick_pow(quick_pow(a, k), mod - 2)\r\nmul = quick_pow(b, k)\r\nq = (mul * divide) % mod\r\nif q == 1:\r\n ans = (num * res) % mod\r\nelse:\r\n ans = (res * ((1 - quick_pow(q, num)) % mod) * quick_pow(1 - q, mod - 2) % mod + mod) % mod\r\nnum = (n + 1) - num * k\r\nid = num - 1\r\nres = 0\r\nfor i in range(num):\r\n if s[id] == '+':\r\n mark = 1\r\n else:\r\n mark = -1\r\n res = (res + mark * y * xxx) % mod\r\n y = (y * yy) % mod\r\n xxx = (xxx * a) % mod\r\n id -= 1\r\nans = ((ans + res) % mod + mod) % mod\r\nprint(ans)",
"import sys\r\ninput=sys.stdin.readline\r\nn,a,b,k=map(int,input().split())\r\ns=input().rstrip()\r\nmod=10**9+9\r\npa=pow(a,n,mod)\r\ninv_a=pow(a,mod-2,mod)\r\npb=1\r\nxk=0\r\nfor i in range(k):\r\n if s[i]==\"+\":\r\n xk+=pa*pb%mod\r\n xk%=mod\r\n else:\r\n xk-=pa*pb%mod\r\n xk%=mod\r\n pa*=inv_a\r\n pa%=mod\r\n pb*=b\r\n pb%=mod\r\ny=(1-pow(inv_a*b%mod,n+1,mod))%mod\r\nzz=pow(inv_a*b%mod,k,mod)\r\nif zz!=1:\r\n z=(1-zz)%mod\r\n z=pow(z,mod-2,mod)\r\n print(xk*y*z%mod)\r\nelse:\r\n z=(n+1)//k\r\n print(z*xk%mod)",
"MOD = 1000000009\r\ndef AlternateSum(n,a,b,k,s):\r\n res = 0\r\n inv = lambda x: pow(x, MOD-2, MOD)\r\n q = pow(b, k, MOD) * inv(pow(a, k, MOD)) % MOD\r\n max_pow = pow(a, n, MOD)\r\n c = b * inv(a) % MOD\r\n for i in range(k):\r\n if s[i] == '+':\r\n res += max_pow\r\n else:\r\n res -= max_pow\r\n res %= MOD\r\n max_pow = max_pow * c % MOD\r\n t = (n + 1) // k\r\n if q == 1:\r\n return t * res % MOD\r\n z = (pow(q, t, MOD) - 1) * inv(q-1) % MOD\r\n return z * res % MOD\r\nn, a, b, k = [int(x) for x in input().split()]\r\ns = input()\r\nprint(AlternateSum(n, a, b, k, s))",
"MOD = 1000000009\r\n\r\ndef inv(n): # Calculate inverse of n modulo MOD\r\n return pow(n, MOD - 2, MOD)\r\n\r\nn, a, b, k = map(int, input().split()) # first line of input\r\nq = (n + 1) // k\r\n\r\nstring = input() # second line of input\r\n\r\ns = [] # list for storing +1 and -1 as and when + or - occur in the string\r\n\r\nfor char in string:\r\n if char == \"+\": s.append(1)\r\n else: s.append(-1)\r\n \r\nres = 0 # final answer\r\n\r\nfor i in range(k): # Calculating the sum till first period, i.e. from s_0 to s_(k-1)\r\n res += (s[i] * pow(a, n - i, MOD) * pow(b, i, MOD))\r\n res %= MOD\r\n\r\n# For checking if the sum R := 1 + T + T^2 + ... + T^(q-1) = (T^q - 1) / (T - 1) for T = (b/a)^k is divisible by MOD\r\n# becuase then the inverse of d1 modulo MOD doesn't exist (in this notation, T would be 1 modulo MOD, so the sum becomes 0/0 when modulo of numerator and denominator are taken)\r\n# and so the code in the following \"if\" part won't be valid in this case\r\nn1 = pow(b, k, MOD)\r\nn2 = pow(a, k, MOD)\r\nn2 = inv(n2)\r\nT = n1 * n2 % MOD\r\n\r\nif T != 1: # when inverse of d1 modulo MOD exists (and the sum (T^q - 1)/(T - 1) is not of the form 0/0)\r\n num = (pow(b, n + 1, MOD) - pow(a, n + 1, MOD)) % MOD # numerator\r\n d1 = (pow(b, k, MOD) - pow(a, k, MOD)) % MOD\r\n d1 = inv(d1) # one part of the denominator \r\n d2 = pow(a, n + 1 - k, MOD)\r\n d2 = inv(d2) # other part of the denominator\r\n\r\n R = (num * d1 * d2) % MOD # the sum R defined above in comments, modulo MOD\r\n\r\n res = (res * R) % MOD # final answer = res * R\r\n\r\n print(res)\r\n\r\nelse: # when T = 1, the sum 1 + T + T^2 + ... + T^(q-1) is simply q * T = q and so R = q\r\n res *= q # final answer = res * R\r\n res %= MOD\r\n print(res) \r\n \r\n",
"def pow_mod(x, y, p):\n number = 1\n while y:\n if y & 1:\n number = number * x % p\n y >>= 1\n x = x * x % p\n return number % p\n\ndef inv(x, p):\n if 1 < x:\n return p - inv(p % x, x) * p // x\n return 1\n \ndef v(p, a, b, k):\n i = 1\n while (pow_mod(a, k, (10 ** 9 + 9) ** i) - pow_mod(b, k, (10 ** 9 + 9) ** i)) == 0:\n i += 1\n return i-1\n\ndef main():\n p = 10 ** 9 + 9\n n, a, b, k = map(int, input().split())\n S = list(input())\n for i in range(k):\n if S[i] == '+':\n S[i] = 1\n else:\n S[i] = -1\n s=0\n if a != b:\n vp = p ** v(p, a, b, k)\n sum_mod = ((pow_mod(a, (n + 1), p * vp) - pow_mod(b, (n + 1), p * vp)) // vp) * inv(((pow_mod(a, k, p * vp) - pow_mod(b, k, p * vp)) // vp) % p, p)\n pa = pow_mod(a, k - 1, p)\n pb = 1\n inv_a = inv(a, p)\n for i in range(k):\n s += (S[i] * pa * pb * sum_mod) % p\n pa = (pa * inv_a) % p\n pb = (pb * b) % p\n else:\n for i in range(k):\n s += S[i] * (n + 1) // k\n s *= pow_mod(a, n, p)\n s %= p\n print(s)\n\nmain()\n\n\n#def giant_steps(start, target, n=2):\n #L = [target]\n #while L[-1] > start*n:\n #L = L + [L[-1]//n + 2]\n #return L[::-1]\n\n#def rshift(x, n):\n #if n >= 0: return x >> n\n #else: return x << (-n)\n\n#def lshift(x, n):\n #if n >= 0: return x << n\n #else: return x >> (-n)\n \n#def size(x):\n #return str(x).count('2')\n\n#def newdiv(p, q):\n #szp = size(p)\n #szq = size(q)\n #szr = szp - szq\n #if min(szp, szq, szr) < 2*START_PREC:\n #return p//q\n #r = (1 << (2*START_PREC)) // (q >> (szq - START_PREC))\n #last_prec = START_PREC\n #for prec in giant_steps(START_PREC, szr):\n #a = lshift(r, prec-last_prec+1)\n #b = rshift(r**2 * rshift(q, szq-prec), 2*last_prec)\n #r = a - b\n #last_prec = prec\n #return ((p >> szq) * r) >> szr\n",
"inp = input(\"\").split('\\n')\r\nnums = inp[0].split(' ')\r\n\r\nn = int(nums[0])\r\na = int(nums[1])\r\nb = int(nums[2])\r\nk = int(nums[3])\r\n\r\nst = str(input(\"\").strip())\r\n\r\ntot = 0\r\nmod = 10**9 + 9\r\n\r\ndef inv (a):\r\n return pow (a, mod - 2, mod)\r\n \r\nfor i in range (0, k):\r\n vl = 1\r\n if (st[i] == '-'):\r\n vl = -1\r\n \r\n tot += vl * pow(a, n - i, mod) * pow(b, i, mod)\r\n tot %= mod\r\n\r\nmult = (pow(b, k, mod) * inv(pow(a, k, mod))) % mod\r\n\r\np = ((n + 1) // k) - 1\r\n\r\n# tot + tot * mult + .... tot * mult^p\r\n\r\nif (mult == 1):\r\n print((tot * (p + 1)) % mod)\r\nelse:\r\n num = (pow(mult, p + 1, mod) - 1) % mod\r\n den = (mult - 1) % mod\r\n num = (num * inv(den)) % mod\r\n \r\n print((num * tot)%mod)\r\n\r\n\r\n ",
"MOD = 10 ** 9 + 9\r\nn, a, b, k = map (int, input ().split ())\r\ns = input (); ans = 0\r\n\r\ndef qsm (x, p) -> int :\r\n ans = 1\r\n while p :\r\n if p & 1 : ans = (ans * x) % MOD\r\n p //= 2; x = (x * x) % MOD\r\n return ans\r\n\r\nx = qsm (b, k) * qsm (qsm (a, k), MOD - 2) % MOD\r\ny = (n + 1) // k; z = (1 - qsm (x, y)) * qsm (1 - x, MOD - 2) % MOD\r\n#print (z)\r\nif z == 0 : z = y\r\nca = qsm (a, n); cb = 1; inva = qsm (a, MOD - 2)\r\nfor i in range (k) :\r\n ans = ans + (1 if s[i] == '+' else -1) * ca * cb * z\r\n ans = ((ans % MOD) + MOD) % MOD\r\n ca = ca * inva % MOD; cb = cb * b % MOD\r\nans = ((ans % MOD) + MOD) % MOD\r\nprint (ans)\r\n"
] | {"inputs": ["2 2 3 3\n+-+", "4 1 5 1\n-", "1 1 4 2\n-+", "3 1 4 4\n+--+", "5 1 1 6\n++---+", "5 2 2 6\n+--++-", "686653196 115381398 884618610 3\n+-+", "608663287 430477711 172252358 8\n-+--+-+-", "904132655 827386249 118827660 334\n+++-+++++--+++----+-+-+-+-+--+-+---++--++--++--+-+-+++-+++--+-+-+----+-+-++++-----+--++++------+++-+-+-++-++++++++-+-++-+++--+--++------+--+-+++--++--+---++-++-+-+-++---++-++--+-+-++-+------+-+----+++-+++--+-+-+--+--+--+------+--+---+--+-++--+++---+-+-++--------+-++--++-+-+-+-+-+-+--+-++++-+++--+--++----+--+-++-++--+--+-+-++-+-++++-", "234179195 430477711 115381398 12\n++++-+-+-+++", "75952547 967294208 907708706 252\n++--++--+++-+-+--++--++++++---+++-++-+-----++++--++-+-++------+-+-+-++-+-+-++++------++---+-++++---+-+-++++--++++++--+-+++-++--+--+---++++---+-+++-+++--+-+--+++++---+--++-++++--++++-+-++-+++-++-----+-+++++----++--+++-+-+++++-+--++-++-+--+-++++--+-+-+-+", "74709071 801809249 753674746 18\n++++++-+-+---+-+--", "743329 973758 92942 82\n++----+-++++----+--+++---+--++++-+-+---+++++--+--+++++++--++-+++----+--+++++-+--+-", "18111 291387 518587 2\n++", "996144 218286 837447 1\n-", "179358 828426 548710 67\n++++---+--++----+-+-++++----+--+---+------++-+-++++--+----+---+-+--", "397521 174985 279760 1\n+", "613632 812232 482342 1\n-", "936810 183454 647048 1\n+", "231531 250371 921383 28\n++-+------+--+--++++--+-+++-", "947301 87242 360762 97\n--+++--+++-++--++-++--++--+++---+++--++++--+++++--+-++-++-----+-++-+--++-----+-++-+--++-++-+-----", "425583346 814209084 570987274 1\n+", "354062556 688076879 786825319 1\n+", "206671954 13571766 192250278 1\n+", "23047921 621656196 160244047 1\n-", "806038018 740585177 987616107 293\n-+++++--++++---++-+--+-+---+-++++--+--+++--++---++++++++--+++++-+-++-+--+----+--+++-+-++-+++-+-+-+----------++-+-+++++++-+-+-+-++---+++-+-+-------+-+-++--++-++-++-++-+---+--++-++--+++--+++-+-+----++--+-+-++-+---+---+-+-+++------+-+++-+---++-+--+++----+++++---++-++--+----+++-+--+++-+------+-++", "262060935 184120408 148332034 148\n+--+-------+-+-+--++-+++--++-+-++++++--++-+++-+++--+-------+-+--+++-+-+-+---++-++-+-++---+--+-+-+--+------+++--+--+-+-+---+---+-+-++++---+++--+++---", "919350941 654611542 217223605 186\n++-++-+++++-+++--+---+++++++-++-+----+-++--+-++--++--+++-+++---+--+--++-+-+++-+-+++-++---+--+++-+-+++--+-+-------+-++------++---+-+---++-++-++---+-+--+-+--+++++---+--+--++++-++-++--+--++", "289455627 906207104 512692624 154\n-------++--+++---++-++------++----------+--+++-+-+++---+---+++--++++++--+-+-+--+---+-+-++-++--+-++--++++---+-+---+-----+--+-+---------+++-++---++-+-+-----", "258833760 515657142 791267045 1\n-", "691617927 66917103 843055237 8\n--+++---", "379582849 362892355 986900829 50\n++-++---+-+++++--++++--+--++--++-----+------++--+-", "176799169 363368399 841293419 1\n+", "144808247 203038656 166324035 4\n-+-+", "477607531 177367565 20080950 2\n++", "682074525 289438443 917164266 1\n+", "938449224 59852396 219719125 1\n-", "395171426 872478622 193568600 147\n+---++---+-+--+++++--+---+-++++-+-++---++++--+--+-+-++-+-++--------++---+++-+---++---+---+-+--+-++++-+++-+-+-++-+--+++-++-+-+-+-++++++-+---+---++--", "403493428 317461491 556701240 1\n-", "917751169 330191895 532837377 70\n-+-+++++++--++---++-+++++-+++-----+-+++---+--+-+-++-++-+-+-++-++-+----", "252089413 552678586 938424519 1\n-", "649316142 320010793 200197645 1\n-", "116399299 784781190 299072480 5\n++++-"], "outputs": ["7", "999999228", "3", "45", "0", "0", "542231211", "594681696", "188208979", "549793323", "605712499", "13414893", "299311566", "724471355", "549104837", "759716474", "25679493", "891965141", "523548992", "134450934", "405016159", "63271171", "545304776", "717117421", "101533009", "441468166", "700325386", "116291420", "48198216", "935800888", "147768186", "927469713", "746494802", "909066471", "928662830", "28048785", "648647459", "460881399", "936516261", "908035409", "627032736", "323650777", "754650814"]} | UNKNOWN | PYTHON3 | CODEFORCES | 12 | |
2d58be359632795d42ddf9dc59da7fee | MYSTERIOUS LANGUAGE | You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language.
This program has only one test, and it's empty (it doesn't give your program anything to read).
Output the name of the mysterious language.
Sample Input
Sample Output
| [
"print(\"INTERCAL\");",
"print(\"INTERCAL\")\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 1\n \t\t \t\t\t\t\t\t\t \t \t\t \t\t \t\t\t\t\t\t \t\t",
"print(\"INTERCAL\") ",
"# LUOGU_RID: 119297272\nprint(\"INTERCAL\")",
"# Flamire senpai AK IOI\nprint('INTERCAL')",
"print(\"INTERCAL\")\n# This is my code",
"n=input()\r\nprint(\"INTERCAL\")",
"n=input();print(\"INTERCAL\")",
"a,b,c=1,2,3\nprint(\"INTERCAL\")",
"print(\"INTERCAL\\n\")",
"n= input()\r\nprint(\"INTERCAL\")\r\n",
"print(\"INTERCAL\")\n#233333",
"#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-29 23:41:34\nLastEditTime: 2021-11-29 23:41:35\nDescription: MYSTERIOUS LANGUAGE\nFilePath: CF171E.py\n'''\n\n\ndef func():\n print(\"INTERCAL\")\n\n\nif __name__ == '__main__':\n func()\n"
] | {"inputs": ["1"], "outputs": ["INTERCAL"]} | UNKNOWN | PYTHON3 | CODEFORCES | 13 | |
2d5b514c88c7afb88eed33428014607a | Efim and Strange Grade | Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are *t* seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than *t* seconds. Note, that he can choose to not use all *t* seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the *n*-th digit one has to take a look at the digit *n*<=+<=1. If it is less than 5 than the *n*-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the *n*<=+<=1 digit is greater or equal to 5, the digit at the position *n* is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
The first line of the input contains two integers *n* and *t* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*t*<=≤<=109) — the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Print the maximum grade that Efim can get in *t* seconds. Do not print trailing zeroes.
Sample Input
6 1
10.245
6 2
10.245
3 100
9.2
Sample Output
10.25
10.3
9.2
| [
"n,t = map(int,input().split())\r\nnum = input()\r\nidx = num.index(\".\")\r\ncnt=1\r\nfor i in range(idx+1,n):\r\n if num[i]<\"5\":\r\n if 5-int(num[i])==1:cnt+=1\r\n else:cnt=1\r\n if num[i]>=\"5\":\r\n j = min(cnt,t)\r\n if num[i-j]!=\".\":\r\n num = num[:i-j]+str(int(num[i-j])+1)\r\n else:\r\n curr = 0\r\n while num[idx-curr-1]==\"9\" and (idx-curr)!=0:\r\n curr+=1\r\n num = num[:idx-curr-1]+str(int(num[idx-curr-1])+1)+\"0\"*curr if curr!=idx else \"1\"+\"0\"*curr\r\n break\r\nprint(num)\r\n",
"R = lambda: map(int, input().split())\r\nn, t = R()\r\ns = list(input())\r\nr = -1\r\nl = s.index('.') + 1\r\nfor i in range(l, n):\r\n if s[i] >= '5':\r\n r = i\r\n break\r\nfor i in range(r, max(l - 1, r - t), -1):\r\n if s[i] >= '5':\r\n if i - 1 != l - 1:\r\n s[i - 1] = str((int(s[i - 1]) + 1) % 10)\r\n r = i - 1\r\n else:\r\n s[i - 2] = str((int(s[i - 2]) + 1) % 10)\r\n r = l - 2\r\n if s[r] == '0':\r\n for j in range(r - 1, -1, -1):\r\n if s[j] == '9':\r\n s[j] = '0'\r\n else:\r\n s[j] = str((int(s[j]) + 1) % 10)\r\n break\r\n if s[0] == '0':\r\n s = ['1'] + s\r\n r += 1\r\nprint(''.join(s[:r + 1]) if r >= 0 else ''.join(s))",
"n, t = map(int, input().split())\r\ns = '0' + input()\r\nf = s.find('.')\r\nif f == -1:\r\n\tprint(s[1:])\r\n\texit()\r\nr = list(s[:f] + s[f+1:])\r\nfor i in range(f, len(r)):\r\n execute = False\r\n while r[i] >= '5' and r[i] <= '9':\r\n if i < f or t <= 0:\r\n break\r\n i -= 1\r\n z = ord(r[i]) + 1\r\n while z == ord(\"9\") + 1:\r\n i -= 1\r\n z = ord(r[i])+1\r\n while len(r) != i+1:\r\n r.pop()\r\n r[-1] = chr(z)\r\n t -= 1\r\n execute = True\r\n if execute:\r\n break\r\nif r[0] == '0':\r\n\tr = r[1:]\r\n\tf -= 1\r\nr += ['0'] * max(f - len(r), 0)\r\nif len(r) == f:\r\n\tprint(''.join(map(str, r)))\r\nelse:\r\n\tprint(*r[:f], '.', *r[f:], sep='')\r\n",
"#import sys\r\n#sys.stdin = open('input.txt')\r\n\r\nn, t = map(int, input().split())\r\ns = input()\r\npp, ap = s.split('.')\r\npp = list(map(int, pp))\r\n\r\nfor i, c in enumerate(map(int, ap)):\r\n if c >= 5:\r\n break\r\n\r\nt -= 1 \r\nrnd = len(ap)\r\nif c >= 5:\r\n rnd = i-1\r\n while t>0 and rnd >= 0 and int(ap[rnd])+1 >= 5:\r\n rnd -= 1\r\n t -= 1\r\n\r\nif rnd == -1:\r\n i = len(pp) - 1\r\n while i >= 0:\r\n pp[i] += 1\r\n if pp[i] > 9:\r\n pp[i] -= 10\r\n i -= 1\r\n else:\r\n break\r\n if i < 0:\r\n pp.insert(0, 1)\r\n\r\nap = list(map(int, ap))\r\nif 0 <= rnd < len(ap):\r\n ap[rnd] += 1\r\n\r\nif rnd >= 0:\r\n print(\"\".join(map(str, pp)), \".\", \"\".join(map(str, ap[:rnd+1])), sep=\"\")\r\nelse:\r\n print(\"\".join(map(str, pp)))\r\n",
"#!/usr/bin/env\tpython\r\n#-*-coding:utf-8 -*-\r\nimport sys\r\nfrom decimal import*\r\nn,t=map(int,input().split())\r\nx=input()\r\ni=x.find('.')\r\nif 0>i:\r\n\tprint(x)\r\n\tsys.exit()\r\nif 1>i:\r\n\ti=1\r\n\tn+=1\r\n\tx='0'+x\r\nfor j in range(1+i,n):\r\n\tif'4'<x[j]:break\r\nelse:\r\n\tprint(x)\r\n\tsys.exit()\r\nwhile 0<t:\r\n\tj-=1\r\n\tif'4'!=x[j]:break\r\n\tt-=1\r\ngetcontext().prec=1+j\r\nx=pow(Decimal(10),i-j)+Decimal(x[:1+j])\r\nprint(x if x!=x.to_integral_value()else x.quantize(Decimal(1)))\r\n",
"n,t=map(int,input().split())\r\ns=input()\r\nans=[]\r\nte=[]\r\nfor i in range(len(s)):\r\n if(s[i]=='.'):\r\n for j in range(i+1,len(s)):\r\n ans.append(int(s[j]))\r\n break;\r\n te.append(int(s[i]))\r\n \r\nflag=0\r\nfor i in range(len(ans)):\r\n if(ans[i]>=5):\r\n flag=1\r\n break;\r\nif(flag==0):\r\n print(s)\r\n exit()\r\nans=ans[0:i+1]\r\npre=[0 for i in range(len(ans))]\r\nfor i in range(1,len(ans)):\r\n if(ans[i-1]>=5):\r\n pre[i]=pre[i-1]+1\r\n else:\r\n pre[i]=pre[i-1]\r\n \r\nshrink=[0 for i in range(len(ans))]\r\ncar=0\r\nfor i in range(len(ans)-1,-1,-1):\r\n if(i==len(ans)-1):\r\n car=1\r\n shrink[i]=1\r\n t-=1\r\n else:\r\n if(car==1):\r\n ans[i]+=1\r\n \r\n if(ans[i]<5):\r\n car=0\r\n continue;\r\n elif(5<=ans[i]<=9):\r\n car=0\r\n if(pre[i]>0):\r\n continue;\r\n else:\r\n if(t==0):\r\n car=0\r\n break;\r\n else:\r\n t-=1\r\n shrink[i]=1\r\n car=1\r\n else:\r\n shrink[i]=1\r\n car=1\r\n \r\nif(car==1):\r\n for i in range(len(te)-1,-1,-1):\r\n if(te[i]==9 and i>0):\r\n te[i]=0\r\n elif(te[i]<9):\r\n te[i]+=1\r\n car=0\r\n break;\r\nif(car==1):\r\n te=[1]+[0]*len(te)\r\n\r\nx=shrink.index(1)\r\nif(x==0):\r\n print(''.join(map(str,te)))\r\n exit()\r\nelse:\r\n ans=ans[0:x]\r\n print(''.join(map(str,te))+'.'+''.join(map(str,ans)))\r\n \r\n \r\n \r\n \r\n \r\n \r\n",
"def main():\n n, t = map(int, input().split())\n s = input()\n dot = s.find('.')\n for i in range(dot + 1, n):\n if s[i] > '4':\n break\n else:\n print(s)\n return\n while t:\n i -= 1\n t -= 1\n if s[i] < '4':\n break\n if i > dot:\n print(s[:i], chr(ord(s[i]) + 1), sep='')\n return\n else:\n l = list(s[dot - 1::-1])\n for i, c in enumerate(l):\n if c == '9':\n l[i] = '0'\n else:\n l[i] = chr(ord(c) + 1)\n break\n else:\n l.append('1')\n print(''.join(reversed(l)))\n\n\nif __name__ == '__main__':\n main()\n",
"import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\ndef fix(S2, carry): \r\n while True:\r\n if len(S2)==0:\r\n return S2, carry\r\n S2[-1]+=carry\r\n if S2[-1]==0:\r\n S2.pop()\r\n carry = 0\r\n elif S2[-1]==10:\r\n S2.pop()\r\n carry = 1\r\n else:\r\n carry = 0\r\n return S2, carry\r\n \r\ndef process(S, t):\r\n S1, S2 = S.split('.')\r\n S2 = [int(x) for x in list(S2)]\r\n n = len(S2)\r\n first_poss = n-1\r\n for i in range(n):\r\n if S2[i] >= 5:\r\n first_poss = i \r\n break\r\n while len(S2) > first_poss+1:\r\n S2.pop()\r\n carry = 0\r\n I = 0\r\n while True:\r\n S2, carry = fix(S2, carry)\r\n if len(S2)==0:\r\n break\r\n if S2[-1] <=4:\r\n carry = 0\r\n break\r\n else:\r\n S2.pop()\r\n carry = 1\r\n I+=1\r\n if I==t:\r\n break\r\n S2, carry = fix(S2, carry)\r\n if carry != 0:\r\n S1 = str(int(S1)+1)\r\n if len(S2)==0:\r\n print(S1)\r\n else:\r\n print(S1+'.'+''.join(map(str, S2)))\r\n \r\n \r\n \r\n \r\n \r\n \r\nn, t = [int(x) for x in input().split()]\r\nS = input().decode().strip()\r\nprocess(S, t)",
"import math,sys,bisect,heapq\r\nfrom collections import defaultdict,Counter,deque\r\nfrom itertools import groupby,accumulate\r\n#sys.setrecursionlimit(200000000)\r\nint1 = lambda x: int(x) - 1\r\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\nilele = lambda: map(int,input().split())\r\nalele = lambda: list(map(int, input().split()))\r\nilelec = lambda: map(int1,input().split())\r\nalelec = lambda: list(map(int1, input().split()))\r\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\r\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\r\n#MOD = 1000000000 + 7\r\ndef Y(c): print([\"NO\",\"YES\"][c])\r\ndef y(c): print([\"no\",\"yes\"][c])\r\ndef Yy(c): print([\"No\",\"Yes\"][c])\r\n\r\nn,t = ilele()\r\nnum = input()\r\na,b= num.split('.')\r\nAns = [a]\r\nAns.append('.')\r\n\r\ndef fun():\r\n x = ['0'] + [*a]\r\n for i in range(len(x)-1,-1,-1):\r\n if x[i] == '9':\r\n x[i] = '0'\r\n else:\r\n x[i] = str(int(x[i]) + 1)\r\n break\r\n if x[0] == '0':\r\n for i in range(1,len(x)):\r\n print(x[i],end = '')\r\n else:\r\n print(\"\".join(x))\r\n \r\nfor i in b:\r\n Ans.append(i)\r\n if int(i) >= 5:\r\n #print(Ans)\r\n if Ans[-1] == '.':\r\n fun()\r\n exit(0)\r\n else:\r\n while t > 0:\r\n #print(Ans)\r\n t -= 1\r\n if Ans[-1] == '.':\r\n fun()\r\n exit(0)\r\n if int(Ans[-1]) >= 5:\r\n Ans.pop()\r\n if Ans[-1] == '.':\r\n fun()\r\n exit(0)\r\n else:\r\n Ans[-1]= str(int(Ans[-1]) + 1)\r\n else:\r\n break\r\n break\r\n\r\nprint(\"\".join(Ans))",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Sep 17 19:15:41 2016\r\n\r\n@author: bigu\r\n\"\"\"\r\n\r\n\r\nn,t = map(int, input().split(' '))\r\nnum = input()\r\n \r\n\r\nnum = ['0']+list(num)\r\nstack = []\r\n\r\ndot = num.index('.')\r\n#print(dot)\r\n\r\n\r\nfor i,x in enumerate(num):\r\n if i>dot and int(x) >= 5:\r\n stack.append(i)\r\n break\r\n \r\nind = len(num)-1\r\nfor i in range(t):\r\n if len(stack) == 0 or stack[0] < dot:\r\n break\r\n ind = stack[0]\r\n \r\n while True:\r\n ind -= 1\r\n if num[ind] == '.': ind -= 1\r\n tmp = int(num[ind])+1\r\n \r\n #print(ind, tmp)\r\n \r\n if tmp<10:\r\n num[ind]=str(tmp)\r\n break\r\n else:\r\n num[ind]='0'\r\n\r\n stack.pop()\r\n if int(num[ind])>=5:\r\n stack.append(ind)\r\n \r\nnum = num[:max(ind+1,dot)]\r\nif num[0] == '0':\r\n num = num[1:]\r\n\r\nprint(''.join(num))\r\n\r\n \r\n\r\n# 12 5\r\n# 872.04488525",
"n, k = map(int, input().split())\r\ns = list(input())\r\ndot = s.index(\".\")\r\n\r\npos =-1\r\nfor i in range(dot+1, n):\r\n if s[i] > \"4\":\r\n pos = i\r\n break\r\n \r\nif pos < 0:\r\n print(\"\".join(s))\r\nelse: \r\n for j in range(k):\r\n if s[pos-1-j] != \"4\":\r\n break\r\n pos = pos-1-j \r\n while pos >= 0 and (s[pos] == \"9\" or pos == dot):\r\n pos -= 1\r\n \r\n if pos < 0:\r\n print(\"1\", end = \"\")\r\n print(\"0\"*dot)\r\n elif pos < dot: \r\n print(\"\".join(s[:pos]), end = \"\")\r\n print(chr(ord(s[pos])+1), end = \"\")\r\n print(\"0\"*(dot-pos-1))\r\n else: \r\n print(\"\".join(s[:pos]), end = \"\")\r\n print(chr(ord(s[pos])+1))",
"import sys\nn, t = map(int,sys.stdin.readline().split())\nx = sys.stdin.readline()\ny = x.find('.')\nfor i in range(y+1,n):\n if x[i] > '4':\n for j in range(t):\n i -= 1\n if x[i] != '4': break\n if i == y:\n i -= 1\n while i and x[i] == '9':\n i -= 1\n x = x[:i] + str(int(x[i]) + 1) + '0' * (y - i - 1)\n else:\n x = x[:i] + str(int(x[i]) + 1)\n break\nprint(x)\n\n \n\n\t \t \t \t \t\t\t\t\t\t\t \t \t\t\t \t",
"n,t=map(int,input().split())\r\nx=input()\r\ni=x.find(\".\")\r\nfor j in range(i+1,n):\r\n if x[j]>\"4\":\r\n for k in range(t):\r\n j-=1\r\n if x[j]!=\"4\":\r\n break\r\n if j==i:\r\n j-=1\r\n while j and x[j]==\"9\":\r\n j-=1\r\n x=x[:j]+str(int(x[j])+1)+\"0\"*(i-j-1)\r\n else:\r\n x=x[:j]+str(int(x[j])+1)\r\n break\r\nprint(x)\r\n ",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nN,t = map(int, input().split())\r\nS = input()\r\n\r\nsign = 0\r\nA = []\r\nfor i in range(N):\r\n if S[i]=='.':\r\n sign = 1\r\n elif sign:\r\n a = int(S[i])\r\n if a>=5:\r\n A = [c for c in S[:i+1]]\r\n break\r\n \r\nif not A:\r\n exit(print(S))\r\n \r\nflag = 0\r\nwhile A and (A[-1]!='.' and int(A[-1])>4) and t>0:\r\n a = int(A.pop())\r\n if a>4:\r\n if A[-1]=='.':\r\n A.pop()\r\n flag = 1\r\n break\r\n else:\r\n A[-1] = str(int(A[-1])+1)\r\n t-=1\r\n else:\r\n break\r\n \r\nif flag and t>0:\r\n idx = len(A)-1\r\n A[idx] = int(A[idx])+1\r\n while A[idx]>9:\r\n A[idx] = A[idx]%10\r\n idx-=1\r\n if idx>=0:\r\n A[idx] = int(A[idx])+1\r\n else:\r\n A = [1]+A\r\n break\r\n\r\nprint(''.join(str(i) for i in A))\r\n \r\n \r\n\r\n",
"# [https://codeforces.com/contest/718/submission/30690808]\r\n\r\n(n, t) = map(int, input().split())\r\nx = input()\r\ni = x.find('.')\r\nfor j in range(i + 1, n):\r\n if x[j] > '4':\r\n for k in range(t):\r\n j -= 1\r\n if x[j] != '4': break\r\n if j == i:\r\n j -= 1\r\n while j and x[j] == '9': j -= 1\r\n x = x[:j] + str(int(x[j]) + 1) + '0' * (i - j - 1)\r\n else:\r\n x = x[:j] + str(int(x[j]) + 1)\r\n break\r\nprint(x)",
"from sys import *\r\ninput = stdin.readline\r\nn,t = map(int,input().split())\r\nnum = input()\r\nidx = num.find(\".\")\r\nif idx<0:\r\n print(num)\r\n exit()\r\ncnt=1\r\nfor i in range(idx+1,n):\r\n if num[i]<\"5\":\r\n if 5-int(num[i])==1:cnt+=1\r\n else:cnt=1\r\n if num[i]>=\"5\":\r\n j = min(cnt,t)\r\n if num[i-j]!=\".\":\r\n num = num[:i-j]+str(int(num[i-j])+1)\r\n else:\r\n curr = 0\r\n while num[idx-curr-1]==\"9\" and (idx-curr)!=0:\r\n curr+=1\r\n num = num[:idx-curr-1]+str(int(num[idx-curr-1])+1)+\"0\"*curr if curr!=idx else \"1\"+\"0\"*curr\r\n break\r\nprint(num)\r\n"
] | {"inputs": ["6 1\n10.245", "6 2\n10.245", "3 100\n9.2", "12 5\n872.04488525", "35 8\n984227318.2031144444444444494637612", "320 142\n2704701300865535.432223312233434114130011113220102420131323010344144201124303144444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444447444444444444444444444444444444615444444482101673308979557675074444444444444446867245414595534444693160202254444449544495367", "5 10\n1.555", "6 1\n0.9454", "7 1000000000\n239.923", "7 235562\n999.999", "9 2\n23999.448", "9 3\n23999.448", "13 1\n761.044449428", "3 1\n0.1", "3 1\n9.9", "3 1\n0.9", "31 15\n2707786.24030444444444444724166", "4 100\n99.9", "3 10\n9.9", "22 100\n11111111111111111111.5", "3 1\n9.5", "8 100\n9.444445", "6 2\n999.45", "3 100\n9.9", "18 100\n9.4444444444454444", "16 999\n9595959.95959595", "4 100\n99.5", "5 1\n999.9", "4 1\n5.59", "4 1\n99.5", "4 1\n99.9", "18 6\n102345678999.44449", "3 3\n9.9", "5 1\n99.99", "7 1\n99999.9", "3 121\n9.9", "8 6\n9.444445", "3 100\n8.9", "10 1\n999.999999", "5 100\n6.666", "4 100\n9.99", "6 1\n9.9999", "4 10\n99.9", "5 1\n9.999", "3 1231\n9.9", "5 2\n999.9", "5 100\n144.5", "5 100\n99.45", "10 1\n0.50444445", "7 1\n1.51111", "5 1\n199.9", "3 100\n9.5", "7 1000\n409.659", "4 10\n99.5", "4 10\n10.9", "4 1\n19.5"], "outputs": ["10.25", "10.3", "9.2", "872.1", "984227318.2031144445", "2704701300865535.4322233122334341141300111132201024201313230103441442011243032", "2", "1", "240", "1000", "23999.5", "24000", "761.04445", "0.1", "10", "1", "2707786.24031", "100", "10", "11111111111111111112", "10", "10", "1000", "10", "10", "9595960", "100", "1000", "6", "100", "100", "102345679000", "10", "100", "100000", "10", "10", "9", "1000", "7", "10", "10", "100", "10", "10", "1000", "145", "100", "1", "2", "200", "10", "410", "100", "11", "20"]} | UNKNOWN | PYTHON3 | CODEFORCES | 16 | |
2d6458ca956b28b24231b7eba658436d | z-sort | A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold:
1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=><=1.
For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2,3,4] isn’t *z*-sorted.
Can you make the array *z*-sorted?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array *a*.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
If it's possible to make the array *a* *z*-sorted print *n* space separated integers *a**i* — the elements after *z*-sort. Otherwise print the only word "Impossible".
Sample Input
4
1 2 2 1
5
1 3 2 2 5
Sample Output
1 2 1 2
1 5 2 3 2
| [
"n = int(input())\na = [int(x) for x in input().split()]\na = sorted(a)\nsaida = []\nfor i in range(n):\n if i%2 == 0:\n saida.append(a[i//2])\n else:\n saida.append(a[n-1-i//2])\nprint(*saida)\n\t\t\t\t\t\t \t \t\t\t\t\t\t \t \t \t \t \t",
"n = int(input())\r\nxs = sorted([int(x) for x in input().split()])\r\nr = [0] * n\r\nfor i in range(0, n, 2):\r\n r[i] = xs[i // 2]\r\n if i != n - 1:\r\n r[i + 1] = xs[-(i // 2 + 1)]\r\nprint(*r)\r\n",
"import math\r\nimport sys\r\n\r\n\r\ndef scan():\r\n return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\n\r\ndef solution():\r\n n = int(input())\r\n a = scan()\r\n b = []\r\n c = []\r\n a.sort()\r\n for i in range(n//2):\r\n b.append(a[i])\r\n for j in range(n//2, n):\r\n c.append(a[j])\r\n j = 0\r\n c.reverse()\r\n for i in range(n//2+1):\r\n if i < len(b):\r\n print(b[i], end=' ')\r\n if i < len(c):\r\n print(c[i], end=' ')\r\n # print(b, c)\r\n\r\n\r\nif __name__ == '__main__':\r\n solution()\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nfor i in range(n-1):\r\n if i%2:\r\n if l[i] < l[i+1]:\r\n l[i],l[i+1] = l[i+1],l[i] \r\n else: \r\n if l[i] > l[i+1]:\r\n l[i],l[i+1] = l[i+1],l[i] \r\nfor i in l:\r\n print(i, end = ' ') ",
"_ = input()\narray = sorted(list(map(int, input().split())))\n\ndef quit():\n print(\"Impossible\")\n exit()\n\nfor i in range(1, len(array)):\n if i%2:\n el, pos = max(map(lambda x: x[::-1], enumerate(array[i:], i)))\n if el < array[i-1]:\n quit()\n else:\n el, pos = min(map(lambda x: x[::-1], enumerate(array[i:], i)))\n if el > array[i-1]:\n quit()\n\n array[i], array[pos] = array[pos], array[i]\n\n\nprint(' '.join(map(str, array)))\n\n\t \t\t \t \t \t \t \t\t \t\t \t\t \t\t \t",
"n = int(input())\r\nli = list(map(int, input().split()))\r\n\r\nli.sort()\r\n\r\nfor i in range(len(li) - 1):\r\n if(i%2==1):\r\n tp = li[i]\r\n li[i] = li[i+1]\r\n li[i+1] = tp\r\n\r\nfor i in range(len(li)):\r\n print(li[i], end=\" \")\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"a=int(input())\r\nb=sorted(map(int,input().split()))\r\ni=0\r\nwhile(i<a//2):\r\n print(b[i],b[-i-1],end=\" \")\r\n i+=1\r\nif a%2:print(b[a//2])",
"import sys\r\nfrom os import path\r\nif path.exists('input.txt'):\r\n sys.stdin=open('input.txt','r')\r\n sys.stdout=open('output.txt','w')\r\n\r\nn, s = int(input()), sorted( map(int, input().split()) )\r\nfor i in range(1, n - 1, 2):\r\n s[i], s[i + 1] = s[i + 1], s[i]\r\nprint(*s)",
"\r\nitr = int(input())\r\nl=sorted(list(map(int,input().split())))\r\nk=len(l)\r\nwhile len(l):\r\n if k%2==0:\r\n print(l[0],l[-1],end=' ')\r\n del(l[0])\r\n del(l[-1])\r\n else:\r\n if len(l)>2:\r\n print(l[0],l[-1],end=' ')\r\n del(l[0])\r\n del(l[-1])\r\n else:\r\n print(l[0],end=' ')\r\n del(l[0])\r\n\r\n\r\n",
"n = int(input())\r\nA = sorted(map(int, input().split()))\r\nB = [0]*n\r\nB[::2] = A[:(n+1)//2]\r\nB[1::2] = A[(n+1)//2:]\r\n\r\nprint(*B)",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nlst.sort()\r\nlst1=[]\r\nfor i in range(n//2):\r\n lst1.extend([str(lst[i]),str(lst[-(i+1)])])\r\nif n%2==0:\r\n print(\" \".join((lst1)))\r\nelse:\r\n print(\" \".join((lst1)),lst[n//2])",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\np = n // 2 if n % 2 == 0 else n // 2 + 1\r\nt = [0] * n\r\nj = 0\r\nfor i in range(n):\r\n\tif i % 2 == 0:\r\n\t\tt[i] = a[j]\r\n\t\tj += 1\r\n\telse:\r\n\t\tt[i] = a[p]\r\n\t\tp += 1\r\n\r\npos = True\r\nfor i in range(n):\r\n\tif i % 2 == 1:\r\n\t\tif t[i] < t[i - 1]:\r\n\t\t\tpos = False\r\n\t\t\tbreak\r\n\t\tif i + 1 < n and t[i] < t[i + 1]:\r\n\t\t\tpos = False\r\n\t\t\tbreak\r\n\r\nif not pos:\r\n\tprint(\"impossible\")\r\nelse:\r\n\tprint(\" \".join([str(i) for i in t]))",
"n = int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\na = [0] * n\r\nfor i in range(0, n, 2):\r\n a[i] = l[i // 2]\r\n if i != n - 1:\r\n a[i + 1] = l[-(i // 2 + 1)]\r\nprint(*a)\r\n",
"n = int(input())\narr = sorted(list(map(int, input().split())))\nres = []\nfor i in range(n//2):\n res.append(arr[i])\n res.append(arr[- 1 - i])\n\nif n % 2 != 0:\n res.append(arr[n//2])\n\nfor i in res:\n print(i, end=' ')\nprint('')\n\n\n",
"n = int(input())\r\na = list(map(int ,input() .split()))\r\nif n % 2 == 0:\r\n for j in range(n // 2):\r\n print(min(a) ,end = ' ')\r\n print(max(a) ,end = ' ')\r\n a .pop(a .index(min(a)))\r\n a .pop(a .index(max(a)))\r\nelse:\r\n for j in range(n // 2):\r\n print(min(a) ,end = ' ')\r\n print(max(a) ,end = ' ')\r\n a .pop(a .index(min(a)))\r\n a .pop(a .index(max(a)))\r\nprint(*a)",
"num = int(input())\r\nans = \"\"\r\nz_sort = [int(i) for i in input().split()]\r\nz_sort.sort()\r\nz_small = z_sort[:-(-num//2)]\r\nz_big = z_sort[-(-num//2):]\r\n\r\nif len(z_sort) % 2 == 0:\r\n for i in range(len(z_small)):\r\n ans += str(z_small[i]) + \" \"\r\n ans += str(z_big[i]) + \" \"\r\n ans = ans[:-1]\r\nelse:\r\n for i in range(len(z_small)-1):\r\n ans += str(z_small[i]) + \" \"\r\n ans += str(z_big[i]) + \" \"\r\n ans += str(z_small[-1])\r\nprint(ans)\r\n",
"\r\nn = int(input())\r\nL = list(map(int, input().split()))\r\n\r\n\r\ndef z_sort(L):\r\n \r\n j = 0\r\n r = len(L)-1\r\n for i in range(0,len(L)):\r\n if i%2 ==0:\r\n newL[i] = L[j]\r\n j+=1\r\n else:\r\n newL[i] = L[r]\r\n r-=1\r\n\r\nL.sort()\r\nnewL = [0]*len(L)\r\nz_sort(L)\r\nfor i in newL:\r\n print(i, end=\" \")\r\n",
"def msort(a, n):\n if n > 1:\n m = n // 2\n k = []\n t = []\n for i in range(m):\n k.append(a[i])\n for i in range(m, n):\n t.append(a[i])\n k = msort(k, m)\n t = msort(t, n - m)\n a = merge(a, k, t, m, n - m)\n return a\n\ndef merge(a, b, c, bl, cl):\n pos1, pos2, pos = 0, 0, 0\n while(pos1 < bl and pos2 < cl):\n if b[pos1] <= c[pos2]:\n a[pos] = b[pos1]\n pos += 1\n pos1 += 1\n else:\n a[pos] = c[pos2]\n pos += 1\n pos2 += 1\n while pos1 < bl:\n a[pos] = b[pos1]\n pos += 1\n pos1 += 1\n while pos2 < cl:\n a[pos] = c[pos2]\n pos += 1\n pos2 += 1\n return a\n\nn = int(input())\nk = [int(i) for i in input().split()]\nk = msort(k, n)\nt = [k[0]]\nk = k[1:]\ni = 1\nwhile len(k) > 0:\n if i % 2 == 1:\n t.append(k[-1])\n k = k[:-1]\n else:\n t.append(k[0])\n k = k[1:]\n i += 1\ne = True\nfor i in range(1, len(t)):\n if i % 2 == 0:\n if t[i] > t[i - 1]:\n print(\"Impossible\")\n e = False\n break\n else:\n if t[i] < t[i - 1]:\n print(\"Impossible\")\n e = False\n break\nif e:\n print(*t)\n\t\t\t\t\t\t\t \t \t \t \t\t\t\t\t \t \t\t\t\t \t",
"\r\nn = int(input())\r\na = sorted(list(map(int, input().split())))\r\n\r\ni, b = 0, [0] * n\r\nfor j in range(2):\r\n while j < n:\r\n b[j] = a[i]\r\n j += 2\r\n i += 1\r\n\r\nprint(*b)\r\n\r\n",
"n = int(input())\r\n\r\na = sorted(map(int, input().split()))\r\n\r\nres = [10**18]\r\n\r\ni = 0; j = n-1;\r\nstep = 0\r\nwhile i <= j:\r\n if step == 0:\r\n res.append(a[i])\r\n i+=1\r\n if res[-1] > res[-2]:\r\n print(\"Impossible\")\r\n break\r\n else:\r\n res.append(a[j])\r\n j-=1\r\n if res[-1] < res[-2]:\r\n print(\"Impossible\")\r\n break\r\n step = step ^ 1\r\nelse:\r\n print(\" \".join(map(str, res[1:])))\r\n \r\n ",
"n=int(input())\r\nmas=[int(x) for x in input().split()]\r\nmas.sort()\r\nk=0\r\nl=n-1\r\nfor i in range(n):\r\n if i&1:\r\n print(mas[l],end=' ')\r\n l-=1\r\n else:\r\n print(mas[k],end=' ')\r\n k+=1",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nif len(a)%2!=0:\r\n list1=a[1:(len(a)//2)+1]\r\n list2=a[(len(a)//2)+1:len(a)]\r\n res=[[]for i in range(n)]\r\n res[0]=a[0]\r\n k1=0\r\n k2=len(list2)-1\r\n for i in range(2,len(a)+1):\r\n if i%2!=0:\r\n res[i-1]=list1[k1]\r\n k1=k1+1\r\n if i%2==0:\r\n res[i-1]=list2[k2]\r\n k2=k2-1\r\nif len(a)%2==0:\r\n \r\n list1=a[0:(len(a)//2)]\r\n list2=a[(len(a)//2):len(a)]\r\n res=[[]for i in range(n)]\r\n res[0]=a[0]\r\n k1=1\r\n k2=len(list2)-1\r\n for i in range(2,len(a)+1):\r\n if (i)%2!=0:\r\n res[i-1]=list1[k1]\r\n k1=k1+1\r\n if (i)%2==0:\r\n res[i-1]=list2[k2]\r\n k2=k2-1 \r\nprint(*res)\r\n ",
"import sys\n\n\nif __name__ == '__main__':\n\tn = int(input())\n\ta = [int(x) for x in input().split()]\n\n\ta.sort()\n\tb = [0] * (n + 1)\n\tindex = 0\n\n\tfor i in range(1, n + 1, 2):\n\t\tb[i] = a[index]\n\t\tindex += 1\n\n\tfor i in range(2, n + 1, 2):\n\t\tb[i] = a[index]\n\t\tindex += 1\n\n\n\n\tfor i in range(1, n + 1):\n\t\tif i % 2 == 0 and b[i] < b[i - 1]:\n\t\t\tprint(\"Impossible\")\n\t\t\tsys.exit(1)\n\t\telif i % 2 == 1 and i > 1 and b[i] > b[i - 1]:\n\t\t\tprint(\"Impossible\")\n\t\t\tsys.exit(1)\n\n\tprint(\" \".join(str(x) for x in b[1:]))",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\n\r\nans = [0] * n\r\np, q = 0, n - 1\r\n\r\nfor i in range(n):\r\n if i % 2 == 1:\r\n ans[i] = a[q]\r\n q -= 1\r\n else:\r\n ans[i] = a[p]\r\n p += 1\r\n\r\nprint(\" \".join(map(str, ans)))",
"n=int(input())\nodd=0;even=n//2\nz=sorted(list(map(int,input().split())))\nif n%2 != 0 :\n even+=1\nf=even\nwhile odd < f :\n print(z[odd],end=' ') \n if even < n :\n print(z[even],end=' ')\n odd+=1;even+=1\n\t \t \t \t \t\t\t \t\t\t \t\t\t\t \t\t \t",
"n = int(input())\r\n\r\narr = list(map(int, input().split()))\r\n\r\narr.sort()\r\n\r\nleft = 0\r\nright = n - 1\r\nans = []\r\nl = True\r\nwhile left <= right:\r\n if l:\r\n ans.append(arr[left])\r\n left += 1\r\n else:\r\n ans.append(arr[right])\r\n right -= 1\r\n l = not l\r\n\r\nprint(*ans)",
"n = int(input())\r\nA = list(map(int, input().split()))\r\nA.sort()\r\nfrom collections import deque\r\nB = []\r\nA = deque(A)\r\nfor i in range(n):\r\n if i%2 == 0:\r\n a = A.popleft()\r\n else:\r\n a = A.pop()\r\n B.append(a)\r\nflag = True\r\nfor i in range(1, n):\r\n if i%2 == 1:\r\n if B[i] >= B[i-1]:\r\n continue\r\n else:\r\n flag = False\r\n break\r\n else:\r\n if B[i] <= B[i-1]:\r\n continue\r\n else:\r\n flag = False\r\n break\r\nif flag:\r\n print(*B)\r\nelse:\r\n print('Impossible')\r\n",
"n=int(input())\r\nls=list(map(int,input().split()))\r\nls.sort()\r\nlz=[]\r\nfor i in range(n//2):\r\n lz.append(ls.pop(0))\r\n lz.append(ls.pop())\r\nif len(ls)!=0:\r\n lz.append(ls[0])\r\nprint(\" \".join(map(str,lz)))",
"#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n\r\nimport array\r\n\r\n\r\ndef z_sorted(length, sequence):\r\n sorted_sequence = sorted(sequence)\r\n answer = []\r\n for i in range(length // 2):\r\n answer.append(sorted_sequence[i])\r\n answer.append(sorted_sequence[length - i - 1])\r\n if length % 2 == 1:\r\n answer.append(sorted_sequence[length // 2])\r\n return answer\r\n\r\n\r\ndef main():\r\n length = int(input())\r\n sequence = array.array(\"L\", map(int, input().split()))\r\n print(\" \".join(map(str, z_sorted(length, sequence))))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"n = int(input())\r\nls = sorted(list(map(int, input().split())))\r\nfor i in range(1, n):\r\n if i%2 and i != n - 1:\r\n ls[i], ls[i+1] = ls[i+1], ls[i]\r\nprint(*ls)\r\n\r\n",
"n = int(input())\nm = list(map(int, input().split()))\na = []\nm.sort()\ni = 0\nj = len(m) - 1\nwhile len(m) != len(a):\n if len(a) % 2 != 0:\n a.append(m[j])\n j -= 1\n else:\n a.append(m[i])\n i += 1\nprint(*a)",
"n=int(input())\r\nx=[int(x) for x in input().split()]\r\nx.sort()\r\nmax_l=x[n-1 : n//2 + n%2 -1 : -1]\r\nmin_l=x[0 : n//2 + n%2]\r\nfor i in range(n):\r\n if i%2==0:\r\n print(min_l[i//2],end=\" \")\r\n else:\r\n print(max_l[i//2],end=\" \")\r\n",
"import sys\ninput = sys.stdin.readline\n\nn = int(input())\nk = list(map(int, input().split()))\nk.sort()\n\nbigs = k[n//2+1:]\nsmalls = k[:n//2+1]\nstring = ''\nwhile len(smalls) != 0:\n try:\n cat = str(bigs.pop(0)) + \" \"\n except:\n cat = \"\"\n string += (str(smalls.pop(0)) + \" \" + cat)\nprint(string)\n\n\t \t \t \t \t\t \t \t \t \t \t \t",
"n=int(input())\na=input().split()[:]\nfor i in range(n):\n a[i]=int(a[i])\nb=sorted(a)\nfor i in range(1,len(a),2):\n b.insert(i,b[len(b)-1])\n b.pop(len(b)-1)\nfor i in range(len(b)):\n print(b[i],end=' ')\n\n \t\t \t \t\t \t\t\t\t\t\t\t\t\t\t\t\t \t\t",
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nif (n == 3):\r\n a[1], a[2] = a[2], a[1]\r\nelse:\r\n d = n - 2 + n % 2\r\n for i in range (1, n//2, 2):\r\n a[i], a[d] = a[d], a[i]\r\n d -= 2\r\nfor i in range (n):\r\n print(a[i], end=\" \")\r\n",
"n = int(input())\na = list(map(int,input().split()))\n\nfor i in range(n-1):\n\tif (i+1)%2==1:\n\t\tif a[i]>a[i+1]:\n\t\t\tt = a[i]\n\t\t\ta[i] = a[i+1]\n\t\t\ta[i+1] = t\n\t\telse:\n\t\t\tpass\n\telse:\n\t\tif a[i]<a[i+1]:\n\t\t\tt = a[i]\n\t\t\ta[i] = a[i+1]\n\t\t\ta[i+1] = t\n\t\telse:\n\t\t\tpass\n\n\nfor i in range(n):\n\tprint(a[i], end = ' ')\n\t\n",
"import math\r\nn = int(input())\r\nmid = math.ceil(n/2) #index of the first number in the upper half\r\na = [int(x) for x in input().split()]\r\na.sort()\r\nb = [None]*n\r\nfor i in range(n):\r\n b[(i>=mid) + 2*(i-mid) if (i>=mid) else 2*i] = a[i]\r\ns = ''\r\nfor x in b:\r\n s += str(x) + ' '\r\nprint(s)\r\n",
"def z_sort(n,seq) :\r\n seq.sort()\r\n index = 0\r\n while index < n-1 :\r\n if index%2 != 0 :\r\n seq[index], seq[index+1] = seq[index+1], seq[index]\r\n index += 1\r\n \r\n return list(map(str,seq))\r\n \r\n \r\nn = int(input())\r\nseq = list(map(int,input().split()))\r\n\r\nzsorted = z_sort(n,seq)\r\n\r\nprint (\" \".join(zsorted))\r\n \r\n \r\n ",
"n = int(input())\nval = list(map(int, input().split()))\n\nres = [0] * n\nval = sorted(val)\n\nfor i in range(1, n + 1):\n if i & 1:\n res[i - 1] = val[i // 2]\n else:\n res[i - 1] = val[n - (i // 2)]\n\nprint(*res)",
"n = int(input())\nx = sorted(list(map(int, input().split())))\na = []\nfor i in range(n // 2):\n a.append(x[i])\n a.append(x[-i - 1])\nif n % 2 != 0:\n a.append(x[n // 2])\nfor j in range(1, n):\n if j % 2 != 0:\n if a[j] < a[j - 1]:\n print('Impossible')\n exit()\n else:\n if a[j] > a[j - 1]:\n print('Impossible')\n exit()\nprint(*a)\n",
"n, a = int(input()), sorted(map(int, input().split()))\r\nfor i in range(2, n, 2):\r\n a[i - 1], a[i] = a[i], a[i - 1]\r\nprint(' '.join(map(str, a)))",
"from math import ceil \r\nn = int(input()) \r\na = sorted([int(i) for i in input().split()]) \r\nodd = a[:ceil(n/2)] \r\neven = sorted(a[ceil(n/2):], reverse = True) \r\nres = [] \r\ni, j = 0, 0 \r\nwhile i<len(odd) or j<len(even) : \r\n if (i+j)%2 : res.append(even[j]) ; j+=1\r\n else : res.append(odd[i]) ; i+=1\r\nfor i in res : print(i, end = ' ')",
"a = int(input())\r\nb = sorted(map(int, input().split()))\r\ni = 0\r\nwhile i < a // 2:\r\n print(b[i], b[-i - 1], end=\" \")\r\n i += 1\r\nif a % 2:\r\n print(b[a // 2])\r\n",
"from collections import deque\r\n\r\n\r\nn = int(input())\r\nlst = deque(sorted(list(map(int,input().split()))))\r\n# print(lst)\r\nb = False\r\nwhile lst:\r\n if b:\r\n print(lst.pop(), end=\" \")\r\n else:\r\n print(lst.popleft(),end= \" \")\r\n b = not b\r\n \r\n",
"n = int(input())\r\nln = list(map(int, input().split()))\r\nln.sort()\r\nans = [0 for _ in range(n)]\r\ni = 0\r\nj = 0\r\nwhile i < n:\r\n ans[i] = ln[j]\r\n j += 1\r\n i += 2\r\ni = 1\r\nwhile i < n:\r\n ans[i] = ln[j]\r\n j += 1\r\n i += 2\r\nfor e in ans:\r\n print(e, end=\" \")\r\nprint('')",
"#from collections import Counter\r\n#h1,h2=map(int,input().split())\r\n#a,b=map(int,input().split())\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nc=0\r\na.sort()\r\ns=[]\r\nl=round((n//2)+0.1)\r\nif n%2==0:\r\n mn=a[:l]\r\n mx=(a[l:])\r\nelse:\r\n l+=1\r\n c=1\r\n mn = a[:l]\r\n mx = (a[l:])[::-1]\r\nfor i in range(len(mx)):\r\n s.append(mn[i])\r\n s.append(mx[i])\r\nif c==1:\r\n s.append(mn[-1])\r\nprint(*s)",
"n = int(input())\r\nx = input()\r\nx = x.split()\r\nfor i in range(n):\r\n x[i] = int(x[i])\r\na1 = list()\r\na2 = list()\r\nx = sorted(x)\r\nfor i in range(int(n/2)):\r\n a1.append(x[i])\r\nfor i in range(int(n/2),n):\r\n a2.append(x[i])\r\na1.sort()\r\na2.sort()\r\na2 = a2[::-1]\r\nres = list()\r\nfor i in range(len(a2)):\r\n if(i < len(a1)):\r\n res.append(a1[i])\r\n res.append(a2[i])\r\nf = \"\"\r\nfor i in range(n):\r\n f += str(res[i])+\" \"\r\nprint(f)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl=sorted(l)\r\nL=[]\r\nfor i in range(n) :\r\n if i%2==0 :\r\n L.append(l[i//2])\r\n else :\r\n L.append(l[n-1-i//2])\r\nprint(*L)\r\n",
"t=int(input())\r\na=list(map(int,input().split()))[:t]\r\na.sort()\r\nif t%2==0:\r\n for i in range(len(a)//2):\r\n print(a[i],end=\" \")\r\n print(a[-i-1],end=\" \")\r\nelse:\r\n for i in range(len(a)//2):\r\n print(a[i],end=\" \")\r\n print(a[-i-1],end=\" \")\r\n print(a[len(a)//2],end=\" \")\r\n",
"n = int(input())\r\na = list(sorted(map(int, input().split())))\r\ni, l, r = 0, 0, 1\r\nb = [0] * n\r\nwhile l < n:\r\n b[l] = a[i]\r\n i += 1\r\n l += 2\r\nwhile r < n:\r\n b[r] = a[i]\r\n i += 1\r\n r += 2\r\nprint(' '.join(map(str, b)))",
"import sys\r\nreadline=sys.stdin.readline\r\n\r\nN=int(readline())\r\nA=list(map(int,readline().split()))\r\nA.sort(reverse=True)\r\nans_lst=[None]*N\r\nfor i in range(0,N,2):\r\n ans_lst[i]=A.pop()\r\nfor i in range(1,N,2):\r\n ans_lst[i]=A.pop()\r\nprint(*ans_lst)",
"n = int(input())\r\na = list(map(int,input().split()))\r\nk = []\r\na.sort()\r\nfor i in range((n+1)//2):\r\n k.append(a[i])\r\n a.reverse()\r\n k.append(a[i])\r\n a.reverse()\r\nif n%2==1:\r\n k.pop()\r\nprint(*k)\r\n\r\n",
"n = int(input())\r\nL = [int(s) for s in input().split()]\r\ndef zsort(l):\r\n if len(l) == 1:\r\n return l \r\n if len(l) == 2:\r\n if l[0] > l[1]:\r\n return l[::-1]\r\n else:\r\n return l\r\n l1 = zsort(l[:2])\r\n l2 = zsort(l[2:])\r\n result = l1 + l2\r\n if result[1] < result[2]:\r\n result[1], result[2] = result[2], result[1]\r\n return result\r\n\r\nresult = [str(i) for i in zsort(L)]\r\nprint(' '.join(result))",
"#!/usr/bin/env python3.5\r\nimport sys\r\n\r\ndef read_data():\r\n n = int(next(sys.stdin).strip())\r\n numbers = list(map(int, next(sys.stdin).split()))\r\n return numbers\r\n\r\n\r\ndef solve(numbers):\r\n N = len(numbers)\r\n numbers.sort()\r\n lN, rN = numbers[:(N+1)//2], numbers[(N+1)//2:]\r\n ans = [0] * N\r\n for i in range((N+1) // 2):\r\n ans[2*i] = lN[i]\r\n if 2*i + 1 < N:\r\n ans[2*i + 1] = rN[i]\r\n return ans\r\n\r\n\r\nif __name__ == \"__main__\":\r\n print(*solve(read_data()))\r\n",
"n=int(input())\nls=list(map(int,input().split()))\nls.sort()\ni=0\nj=len(ls)-1\nlsN=[]\nwhile i<=j:\n\tif i<j:\n\t\tlsN.append(ls[i])\n\t\tlsN.append(ls[j])\n\telif i==j:\n\t\tlsN.append(ls[i])\n\ti=i+1\n\tj=j-1\ns=''\nfor i in range(n):\n\tif i<n-1:\n\t\ts=s+str(lsN[i])+' '\n\telif i==n-1:\n\t\ts=s+str(lsN[i])\nprint(s)\n \t\t \t\t\t \t\t\t\t \t\t \t \t\t\t\t\t\t\t \t",
"a=int(input())\nb=list(map(int,input().split()))\nb.sort()\ni=0\nwhile (i<a//2):\n print(b[i],b[-i-1],end=' ')\n i+=1\nif a%2:\n print(b[a//2])\n\n \t\t\t \t \t \t\t\t\t \t\t\t \t\t\t\t\t \t",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\ndef solve(a):\r\n a.sort()\r\n if len(a) < 3:\r\n return ' '.join(map(str, a)) \r\n \r\n mid = len(a)//2 + 1\r\n x, y = a[:mid], a[mid:][::-1]\r\n for i, j in enumerate(y):\r\n x.insert(2*i+1, j)\r\n \r\n for i in range(1, len(x)):\r\n if (i%2 and x[i] < x[i-1]) or (i%2 == 0 and x[i] > x[i-1]):\r\n return 'Impossible'\r\n\r\n return ' '.join(map(str, x))\r\n\r\nprint(solve(arr))",
"from collections import deque\r\n\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nd=deque(a)\r\nans=[]\r\nfor i in range(n):\r\n if i%2==0:\r\n ans.append(d.popleft())\r\n else:\r\n ans.append(d.pop())\r\nprint(*ans)",
"n = int(input())\r\nl = sorted(list(map(int,input().split())))\r\nl1 = []\r\nfor i in range(n//2):\r\n l1.append(l[i])\r\n l1.append(l[-(i+1)])\r\nif n%2!=0:\r\n l1.append(l[n//2])\r\nprint(*l1)",
"\r\nn = int(input())\r\narr = sorted(list(map(int, input().split())))\r\nodd = [arr[i] for i in range(1,n,2)]\r\neven = [arr[i] for i in range(0,n,2)]\r\n\r\nans = []\r\nfor i in range(1,n+1):\r\n if i % 2 != 0:\r\n ans.append(arr[0])\r\n arr.pop(0)\r\n else:\r\n ans.append(arr[-1])\r\n arr.pop(-1)\r\nprint (*ans)",
"def fv(v,n):\r\n\t\"\"\"fill vector\"\"\"\r\n\tnv=n*[0]\r\n\tm=(n+1)//2\r\n\tfor c in range(m):\r\n\t\tnv[2*c]=v[c]\r\n\ts=v[m:][::-1]\r\n\tfor c in range(n-m):\r\n\t\tnv[2*c+1]=s[c]\r\n\treturn nv\r\n\r\nn=int(input())\r\nv=[int(c) for c in input().split()]\r\nv.sort()\r\nfor c in fv(v,n):\r\n\tprint(c,end=' ')",
"n = int(input())\r\nr = lambda : list(map(int, input().split()))\r\narr = r()\r\n\r\narr.sort()\r\n# print(arr)\r\nx = arr[:(n+1)//2]\r\ny = arr[(n+1)//2:]\r\n\r\nfor i,j in zip(x,y):\r\n print(i,j,end = \" \")\r\n\r\nif n%2: print(x[-1])\r\n",
"I=lambda: map(int,input().split())\r\nn=int(input())\r\na=sorted(list(I()))\r\naev=a[n-n//2:]\r\nev=0\r\naod=a[:n-n//2]\r\nod=0\r\nb=[0]*n\r\nfor i in range(n):\r\n if i%2==0:\r\n b[i]=aod[od]\r\n od=od+1\r\n else:\r\n b[i]=aev[ev]\r\n ev=ev+1\r\nprint(*b)",
"N = int(input())\r\nX = sorted(list(map(int, input().split())))\r\ni, j = 0, N - 1\r\nStep, Check = 0, True\r\nAnswer = []\r\nwhile Step != N:\r\n if Check:\r\n Answer.append(X[i])\r\n i += 1\r\n else:\r\n Answer.append(X[j])\r\n j -= 1\r\n Check = not Check\r\n Step += 1\r\nprint(*Answer)\r\n\r\n# UB_CodeForces\r\n# Advice: Falling down is an accident, staying down is a choice\r\n# Location: Here in Bojnurd\r\n# Caption: So Close man!! Take it easy!!!!\r\n# CodeNumber: 640\r\n",
"def z_sort(array):\n\tarray_sorted = []\n\tpos = 0\n\n\tfor i in range(len(array)):\n\t\tif(i%2==0):\n\t\t\tarray_sorted.append(array[pos])\n\t\telse:\n\t\t\tarray_sorted.append(array[-(pos+1)])\n\t\t\tpos += 1\n\n\treturn array_sorted\n\n\ndef main():\n\ttotal_elements = int(input())\n\telements_input = input()\n\telements = [int(element) for element in elements_input.split(' ')]\n\n\telements.sort()\n\tarray_z_sort = z_sort(elements)\n\n\tfor element in array_z_sort:\n\t\tprint(element, end=' ')\n\n\tprint()\n\nif __name__ == '__main__':\n\tmain()\n\t \t \t \t \t \t \t\t\t \t\t\t \t\t\t",
"n = int(input())\r\na = sorted(list(map(int, input().split())))\r\ni = 0\r\nj = n - 1\r\nb = []\r\nfor k in range(n):\r\n if k % 2 == 1:\r\n b.append(a[j])\r\n j -= 1\r\n else:\r\n b.append(a[i])\r\n i += 1\r\nprint(*b)",
"nums = int(input())\r\nlist_num = input().split()\r\nfor num in range(int(nums)):\r\n list_num[num] = int(list_num[num])\r\nlist_num.sort()\r\nresult = ''\r\nstart = 0\r\nend = nums-1\r\nfor n in range(int(nums)):\r\n if n%2 ==0:\r\n result += (str(list_num[start]) + ' ')\r\n start+=1\r\n else:\r\n result +=(str(list_num[end]) + ' ')\r\n end+=-1\r\nprint(result)\r\n\r\n",
"import re\n\nnumDigits = int(input())\ndigits = [int(x) for x in re.split(\"\\\\s\", input())]\n\ntotal = 0\n\ndigits.sort()\nx = 0\nfirst = True\nwhile x < int(len(digits)/2):\n if first:\n print(digits[x], end=\"\")\n first = False\n else:\n print(\" \", end=\"\")\n print(digits[x], end=\"\")\n print(\" \", end=\"\")\n print(digits[-(x+1)], end=\"\")\n x += 1\n \nif len(digits)%2 != 0:\n print(\" \", end=\"\")\n print(digits[x])\n\t \t\t \t\t \t \t \t \t \t",
"from math import ceil\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\n\r\nl.sort(reverse = True)\r\nans = [0] * n\r\n\r\nfor i in range(0,n//2): \r\n ans[i*2+1] = l[i]\r\n \r\n\r\nfor i in range(ceil(n/2)):\r\n ans[2*i] = l[n//2 + i]\r\n \r\nflag = True\r\n\r\nfor i in range(n):\r\n if i % 2 == 1:\r\n if not(ans[i] >= ans[i-1]):\r\n flag = False \r\n break\r\n elif i % 2 == 0 and i != 0:\r\n if not(ans[i] <= ans[i-1]):\r\n flag = False\r\n\r\nif flag:\r\n print(*ans)\r\nelse:\r\n print(\"Impossible\")",
"n = int(input())\na = map(int, input().split())\na = sorted(a)\nb = []\nfor i in range(n//2):\n b.append(a[i])\n b.append(a[n-1-i])\nif len(a) % 2:\n b.append(a[n//2])\n#print(a)\nprint(*b)\n\n",
"n = int(input())\n\nlist = sorted(map(int, input().split(' ')))\n\nhalf = n // 2\n\nfirst_half = list[:half]\nsecond_half = list[half:]\nsecond_half = second_half[::-1]\n\nfor i in range(0,half):\n print(first_half[i], end=' ')\n print(second_half[i], end=' ')\nelse:\n if n % 2 == 1:\n print(second_half[-1])\n",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\na.sort()\r\ni=0\r\nj=n-1\r\nwhile i<j:\r\n print(a[i],end=\" \")\r\n print(a[j],end=\" \")\r\n i+=1\r\n j-=1\r\nif n%2:\r\n print(a[i])\r\n",
"def main():\n n = int(input())\n l = sorted(map(int, input().split()))\n res = [0] * n\n res[::2], res[1::2] = l[:n - n // 2], l[:-(n // 2) - 1:-1]\n print(*res)\n\n\nif __name__ == '__main__':\n main()\n",
"import sys\r\nimport math\r\n\r\nn = int(sys.stdin.readline().strip())\r\narray = [int(x) for x in sys.stdin.readline().strip().split()]\r\n\r\ndef main(n, array):\r\n array.sort()\r\n result = []\r\n for i in range(len(array) // 2): # Alternate between adding from beginning and end of sorted list to satisfy z sort condition\r\n result.append(array[i])\r\n result.append(array[-(i + 1)])\r\n if len(array) % 2 == 1:\r\n result.append(array[len(array) // 2])\r\n print(' '.join((str(x) for x in result)))\r\n\r\nmain(n, array)",
"n = int(input())\ns = [int(x) for x in input().split()]\ns.sort()\nq = [s[n//2]] * n\nfor i in range(n//2):\n q[2*i] = s[i]\n q[2*i + 1] = s[n - i - 1]\nprint(' '.join(map(str, q)))\n",
"#!/usr/bin/python3\n# -*- config:utf-8 -*-\n\nimport sys\n\n# get source data\ndef getSrcData():\n f = sys.stdin\n buf = f.read()\n buf=buf.split('\\n')\n cnt=int(buf[0])\n if cnt!=0:\n src=buf[1].split(' ')\n src=[int(i) for i in src]\n else:\n src=[]\n return cnt,src\n\n# find transform to zsort\ndef getTransform(cnt,src):\n src.sort()\n result=[]\n for i in range(0,cnt//2):\n result.append(src[i])\n result.append(src[cnt-1-i])\n if cnt%2==1:\n result.append(src[cnt//2])\n return result\n\n# save result\ndef saveResult(result):\n if len(result)==0:\n pbuf='Impossible'\n else:\n pbuf=[str(i) for i in result]\n pbuf=' '.join(pbuf)\n f = sys.stdout\n f.write(pbuf)\n f.flush()\n\n# start\ndef run():\n cnt,src=getSrcData()\n if cnt!=0:\n result=getTransform(cnt,src)\n else:\n result=[]\n saveResult(result)\n\nif __name__ == '__main__':\n run()\n",
"length = int(input())\r\nnumbers = sorted(map(int, input().split()))\r\nhalf = length//2\r\nfor i in range(half):\r\n print(numbers[i], numbers[-i-1], sep=' ', end=' ')\r\nif length - 2*half:\r\n print(numbers[half])",
"import sys\ninput = sys.stdin.readline\n\n############ ---- Input Functions ---- ############\n\n\ndef inp(): # integer inputs\n return(int(input()))\n\n\ndef inlt(): # list inputs\n return(list(map(int, input().split())))\n\n\ndef insr(): # string inputs\n s = input()\n return(list(s[:len(s) - 1]))\n\n\ndef invr(): # integer variable inputs\n return(map(int, input().split()))\n\n\ndef main():\n n = inp()\n arr = inlt()\n arr.sort()\n new_arr = []\n\n index = 0\n forward = False\n while len(new_arr) < n:\n if forward == False:\n new_arr.append(arr[index])\n forward = True\n else:\n forward = False\n new_arr.append(arr[-(index+1)])\n index += 1\n\n print(\" \".join(map(str, new_arr)))\n\n\nif __name__ == \"__main__\":\n main()\n",
"n = int(input())\r\nl = sorted(list(map(int, input().split())))\r\nfor i in range(1,n):\r\n if(i%2 and i!=n-1):\r\n l[i], l[i+1] = l[i+1],l[i]\r\nprint(*l)",
"a=int(input())\r\nb=sorted(list(map(int,input().split())))\r\nc=[]\r\nfor i in range(a):\r\n if i%2==0:c.append(b.pop(0))\r\n else:c.append(b.pop(-1))\r\nprint(' '.join(map(str,c)))",
"n=int(input())\r\nx=[int(q) for q in input().split()]\r\n\r\ny=sorted(x)\r\nz=[]\r\n\r\nif n&1==0:\r\n for i in range(0,n//2):\r\n z.append(y[i])\r\n z.append(y[n-i-1])\r\n print(*z)\r\nelse:\r\n for i in range(0,1+ n//2):\r\n z.append(y[i])\r\n z.append(y[n-i-1])\r\n z.pop()\r\n print(*z)",
"# Collaborated with no one [L]\nlength = int(input())\ninput1 = list(map(int,input().split(\" \")))\ninput1.sort(reverse=True)\ni = 0\nj = 1\nanswer = [0]*length\nwhile(j<length):\n answer[j]=input1[i]\n i+=1\n j+=2\nj=0\nwhile(j<length):\n answer[j]=input1[i]\n i+=1\n j+=2\nfor i in range(0, len(answer)):\n print(answer[i], end=\" \")\n \t\t\t\t\t\t \t \t\t\t\t \t \t\t\t\t\t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\ns = []\r\nfor i in range(0, len(a) // 2):\r\n s.append(a[i])\r\n s.append(a[len(a) - 1 - i])\r\nif n % 2 == 1:\r\n s.append(a[len(a) // 2])\r\n\r\nPo = 1\r\nfor k in range(2, len(s) - 1):\r\n if k % 2 == 1:\r\n if s[k] >= s[k - 1]:\r\n pass\r\n else:\r\n print('Impossible')\r\n Po = 0\r\n break\r\n elif k == 1:\r\n pass\r\n else:\r\n if s[k] <= s[k - 1]:\r\n pass\r\n else:\r\n print('Impossible')\r\n Po = 0\r\n break \r\nif Po == 1:\r\n print(' '.join(map(str, s)))",
"import math\r\n\r\nn = int(input())\r\nnums = sorted(list(map(int, input().split())))\r\n\r\nfront = nums[0:math.ceil(len(nums) / 2)]\r\nback = list(reversed(nums[math.ceil(len(nums) / 2):]))\r\ni = 0\r\nj = 0\r\nout = \"\"\r\n\r\nfor x in range(math.ceil(n / 2)):\r\n out += str(front[i])\r\n if j < len(back):\r\n out += \" \"+str(back[j])+\" \"\r\n i += 1\r\n j += 1\r\n\r\nprint(out)\r\n\r\n\r\n\r\n\r\n\r\n",
"\nn = int(input())\nn2 = (n+1)//2\nL = sorted(map(int, input().split()))\nR = L[:]\nR[::2], R[1::2] = L[:n2], L[n2:][::-1] # don't actually need to reverse\nprint(' '.join(map(str, R)))\n\n \t \t\t\t \t\t \t \t\t\t\t \t\t\t",
"n = int(input())\r\narr = [int(i) for i in input().split()]\r\n\r\narr.sort()\r\nres = [-1 for i in range(n)]\r\n\r\nleft, right = 0, n - 1\r\nfor i in range(n):\r\n\tif (i + 1) % 2 == 1:\r\n\t\tres[i] = arr[left]\r\n\t\tleft += 1\r\n\r\n\tif (i + 1) % 2 == 0:\r\n\t\tres[i] = arr[right]\r\n\t\tright -= 1\r\n\r\nfor r in res:\r\n\tprint(r, end=' ')",
"\r\nn = int(input())\r\n\r\nnumero = input().split()\r\nfor i in range(n):\r\n numero[i] = int(numero[i])\r\n\r\n\r\nif n == 1:\r\n print(numero[0])\r\nelse:\r\n for i in range(1,n):\r\n if i % 2 != 0 and numero[i] < numero[i-1]:\r\n auxiliar = numero[i]\r\n numero[i] = numero[i-1]\r\n numero[i-1] = auxiliar\r\n elif i % 2 == 0 and numero[i] > numero[i-1]:\r\n auxiliar = numero[i]\r\n numero[i] = numero[i-1]\r\n numero[i-1] = auxiliar\r\n\r\n respuesta = str(numero[0])\r\n for i in range(1,n):\r\n respuesta = respuesta + ' ' + str(numero[i]) \r\n print(respuesta)",
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\n \r\nl = 0\r\nr = n - 1\r\nwhile(l < r) :\r\n print(a[l], a[r], end = \" \")\r\n l+=1\r\n r-=1\r\nif(l == r) :\r\n print(a[l])",
"n=int(input())\r\narr=list(map(int,input().split()))\r\narr=sorted(arr)\r\nfor i in range(1,n):\r\n if i%2==1 and i != n-1:\r\n arr[i],arr[i+1]=arr[i+1],arr[i]\r\nprint(*arr)",
"n=int(input())\na=list(map(int,input().split()))\nb=[]\ns=0\ntry:\n for i in range(n):\n b+=[min(a)]\n a=a[:a.index(min(a))]+a[a.index(min(a))+1:]\n b+=[max(a)]\n a=a[:a.index(max(a))]+a[a.index(max(a))+1:]\nexcept:\n for j in range(1,n):\n if j%2==1:\n if b[j]<b[j-1]:\n s+=1\n break\n elif j%2==0:\n if b[j]>b[j-1]:\n s+=1\n break\n if s==0:\n print(*b)\n else:\n print('Impossible')\n\n\t \t\t\t\t\t\t\t\t\t\t \t \t \t\t",
"import sys\ninput=sys.stdin.readline\nn=int(input())\nunsort=list(map(int,input().strip().split()))\nunsort.sort()\nfor i in range(n//2):\n print(unsort[i], end=' ')\n print(unsort[i+(n-1)//2+1], end=' ')\nif n%2==1:\n print(unsort[n//2])\n \t\t\t \t \t\t\t \t \t\t\t \t\t\t \t \t",
"\t# https://vjudge.net/contest/385874#problem/H\r\n\r\nn=int(input())\r\nodd=0;even=n//2\r\nz=sorted(list(map(int,input().split())))\r\nif n%2 != 0 :\r\n even+=1\r\nf=even\r\nwhile odd < f :\r\n print(z[odd],end=' ') \r\n if even < n :\r\n print(z[even],end=' ')\r\n odd+=1;even+=1",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nl.sort(reverse = True)\r\nmas = [0 for i in range(n)]\r\nt = 0\r\nfor i in range(1, n, 2):\r\n mas[i] = l[t]\r\n t += 1\r\nfor i in range(0, n, 2):\r\n mas[i] = l[t]\r\n t += 1\r\nprint(*mas)",
"n = int(input())\r\na = list(map(int,input().split()))\r\nb = n//2\r\nc = []\r\na.sort()\r\nfor i in range(b):\r\n c.append(a[i])\r\n c.append(a[n-i-1])\r\nif n%2!=0:\r\n c.append(a[b])\r\nprint(*c)",
"n=int(input())\r\nt=list(map(int,input().split()))\r\nt.sort()\r\nfor i in range(len(t)//2):\r\n print(t[i],end=\" \")\r\n print(t[len(t)-1-i],end=\" \")\r\nif len(t)%2:\r\n print(t[len(t)//2])\r\n",
"t = int(input())\r\nc = 0 \r\na = list(map(int , input().split()))\r\na = sorted(a)\r\nb = []\r\nfor i in range(t//2):\r\n b.append(a[i])\r\n b.append(a[t-1-i])\r\n\r\nif(t % 2 == 1):\r\n b.append(a[t//2])\r\n\r\nprint(*b)",
"n = int(input())\r\na = sorted(list(map(int, input().split())))\r\nans = [0] * n\r\nleft, right = 0, n - 1\r\nfor i in range(n):\r\n if i % 2 == 0:\r\n ans[i] = a[left]\r\n left += 1\r\n else:\r\n ans[i] = a[right]\r\n right -= 1\r\nprint(*ans)",
"def main():\n n = int(input())\n a, r = sorted(map(int, input().split())), [0] * n\n r[::2], r[1::2] = a[:n - n // 2], a[-1:n - n // 2 - 1:-1]\n print(' '.join(map(str, r)))\n\n\nif __name__ == '__main__':\n main()\n",
"n = int(input())\r\n\r\ndaf = list(map(int, input().split()))\r\ndaf.sort()\r\nfor i in range((n - 1) // 2):\r\n daf[2 * i + 1], daf[2 * i + 2] = daf[2 * i + 2], daf[2 * i + 1]\r\n\r\nprint(*daf)\r\n",
"#collaborated with Prasoon\nn=int(input())\nline=input()\narray=[]\nsecond_array=[]\nodd_var=(n+1)//2\neven_var=0\nx=line.split()\nfor i in range(n):\n array.append(int(x[i]))\narray = sorted(array)\nfor i in range(n):\n if i%2==0:\n second_array.append(array[even_var])\n even_var+=1\n else:\n second_array.append(array[odd_var])\n odd_var+=1\n print(str(second_array[i]),sep=\" \",end=\" \")\n\n\t \t\t \t\t\t \t\t\t\t\t \t\t\t\t\t\t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nl, r = 0, n - 1\r\nwhile l <= r:\r\n if l == r:\r\n print(a[l])\r\n else:\r\n print(a[l], a[r], end=\" \")\r\n l += 1\r\n r -= 1",
"n = int(input())\na = [int(_) for _ in input().split()]\na.sort()\nna = []\nfor i in range(len(a)):\n if i%2==0:\n na.append(a.pop(0))\n else:\n na.append(a.pop(-1))\nprint(\" \".join(map(str,na)))\n\n\t\t \t\t \t\t\t \t \t\t \t \t \t \t\t",
"l = int(input())\r\nn = list(map(int , input().split()))\r\nn.sort()\r\nans = []\r\ni = 0\r\nwhile len(ans)<l:\r\n ans.append(n[i])\r\n ans.append(n[l-i-1])\r\n i = i+1\r\nans = ans[:l]\r\nprint(*ans)\r\n",
"n = int(input())\r\narr = [int(x) for x in input().split(\" \")]\r\n\r\nsorted_arr = sorted(arr, reverse=True)\r\n\r\nz_sorted_arr = []\r\n\r\nj = n - 1\r\nfor i in range(0,int(n/2)):\r\n z_sorted_arr.append(sorted_arr[j])\r\n z_sorted_arr.append(sorted_arr[i])\r\n j = j - 1\r\n\r\n\r\nif n % 2 != 0:\r\n z_sorted_arr.append(sorted_arr[int(n/2)])\r\n\r\nprint(\" \".join([str(x) for x in z_sorted_arr]))\r\n",
"n = int(input())\na = sorted(list(map(int,input().split())))\nd = []\nfor i in range(len(a)):\n d += [a[i]]\n d += [a[n - 1 - i]]\nif n+n<n:\n d += [a[n]]\nprint(*d[0:len(a)])\n\n \t\t\t\t \t \t\t \t \t\t\t\t\t \t\t \t",
"__author__ = 'Esfandiar'\nn = int(input())\na = sorted(list(map(int,input().split())))\nt=n-1\nfor i in range(n//2):\n print(a[i],end=\" \")\n print(a[t],end=\" \")\n t-=1\n\nif n % 2:\n print(a[n//2],end=\" \")",
"n=int(input())\narray=list(map(int,input().split()))\narray.sort()\nans=[]\n\nfor i in range(n//2):\n\tans.append(array[i])\n\tans.append(array[n-i-1])\n\nif len(array)%2!=0:\n\tans.append(array[n//2])\nprint(\" \".join([str(i) for i in ans]))",
"n = int(input())\r\na = [int(c) for c in input().split()]\r\na.sort()\r\ns1 = 0\r\ns2 = n-1\r\nfor i in range(1, n+1):\r\n if i%2==1:\r\n print(a[s1], end = ' ')\r\n s1+=1\r\n else:\r\n print(a[s2], end = ' ')\r\n s2-=1",
"_=input()\r\n\r\na=sorted(map(int, input().split()))\r\n\r\ni=0\r\nj=len(a)-1\r\n\r\nwhile i < j:\r\n\tprint(a[i] , a[j], end=\" \")\r\n\ti+=1\r\n\tj-=1\r\n\r\nif i == j:\r\n\tprint(a[i])",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\na.sort()\r\nif n%2==0:\r\n for i in range(n//2):\r\n print(a[i],end=' ')\r\n print(a[n-1-i],end=' ')\r\nelse:\r\n for i in range(n//2):\r\n print(a[i],end=' ')\r\n print(a[n-1-i],end=' ')\r\n print(a[n//2])",
"from sys import stdin\nn = int(stdin.readline())\na = list(map(int, stdin.readline().split()))\na.sort()\n\nhalf = int(len(a) / 2)\nif len(a) % 2 == 1:\n half += 1\n\n\nodd = sorted(a[:half])\neven = sorted(a[half:], reverse=True)\n\nl = zip(odd, even)\n\n\nnext_ind = 0\nnext_left = 1\nwhile 1:\n if next_left:\n if next_ind >= len(odd):\n break;\n print(odd[next_ind], '', end=\"\")\n else:\n if next_ind >= len(even):\n break;\n print(even[next_ind], '', end=\"\")\n next_ind += 1\n next_left = 1 - next_left",
"#!/usr/bin/env/python\r\n# -*- coding: utf-8 -*-\r\nm = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nl, r = 0, m - 1\r\nwhile l < r:\r\n print(a[l], a[r], end=' ')\r\n l += 1\r\n r -= 1\r\nif l == r:\r\n print(a[l])",
"n = int(input())\r\na = list(map(int, input().strip().split()))\r\n\r\na.sort()\r\n\r\nres = [0]*n\r\n\r\ni = 0\r\nwhile 2*i < n:\r\n res[2*i] = a[i]\r\n i += 1\r\n\r\nj = 0\r\nwhile 2*j + 1 < n:\r\n res[2*j+1] = a[i]\r\n i += 1\r\n j += 1\r\n \r\nprint(\" \".join(map(str, res)))",
"import sys\r\nfrom sys import stdin,stdout\r\nfrom math import *\r\nimport math, random, operator\r\nfrom itertools import product, permutations, combinations\r\nfrom collections import deque, defaultdict, Counter\r\ninput=sys.stdin.readline\r\ndef hi():\r\n # print(\"HI\")\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n l.sort()\r\n # res=[0]*n\r\n res=[]\r\n p=0\r\n q=n-1\r\n # k=(n+1)//2\r\n for i in range(n):\r\n if i&1:\r\n # print(l[i],end=' ')\r\n res.append(l[q])\r\n q-=1\r\n else:\r\n # print(l[i],end=' ')\r\n res.append(l[p])\r\n p+=1\r\n print(*res,sep=' ')\r\n\r\nif __name__==\"__main__\":hi()\r\n # for _ in range(int(input())):hi()",
"#ROUNIAAUDI\r\nnum1=int(input())\r\nlist1=sorted(map(int,input().split()))\r\ni=0\r\nj=num1-1\r\nlist2=[]\r\nwhile j>i:\r\n list2.append(list1[i])\r\n list2.append(list1[j])\r\n i+=1\r\n j-=1\r\nif i==j:\r\n list2.append(list1[j])\r\nfor i in list2:\r\n print(i,end=\" \")\r\n",
"n = int(input())\r\ninp = list(map(int , input().split()))\r\nsrt = sorted(inp)\r\nans = []\r\nif n % 2 == 0:\r\n for i in range(n // 2):\r\n ans.append(str(srt[i]))\r\n ans.append(str(srt[-(i + 1)]))\r\n print(\" \".join(ans))\r\nelse:\r\n for i in range(n // 2 + 1):\r\n ans.append(str(srt[i]))\r\n ans.append(str(srt[-(i + 1)]))\r\n ans.pop(-1)\r\n print(\" \".join(ans))\r\n",
"#!/usr/bin/python3\n\nn = int(input())\na = sorted([int(i) for i in input().split()])\n\ni = 0\nd = 1\ns = n-1\n\nwhile s >= 0:\n\tprint(a[i], end=' ')\n\ti += d * s\n\ts -= 1\n\td *= -1\n",
"n = int(input())\r\n*a, = sorted(map(int, input().split()))\r\nfor i in range(n):\r\n if i % 2 == 0:\r\n print(a[0])\r\n del a[0]\r\n else:\r\n print(a[-1])\r\n del a[-1]",
"n = int(input())\r\n\r\narr = list(map(int, input().split()))\r\n\r\narr = sorted(arr)\r\n\r\nwhile len(arr) > 1:\r\n print(arr.pop(0), end=\" \")\r\n print(arr.pop(), end=\" \")\r\n\r\nif len(arr) == 1:\r\n print(arr[0]) \r\n",
"n = int(input())\na = sorted(map(int, input().split(' ')))\n\nans = [0]*n\nfor i in range(n):\n ans[i] = a[i//2] if i%2 == 0 else a[(i+n)//2]\n\nprint(' '.join(map(str, ans)))\n",
"n = int(input())\r\na = sorted(list(map(int, input().split())))\r\nli = [0] * n\r\ncnt = 0\r\ncnt2 = 1\r\nif n != 1:\r\n if n % 2 == 0:\r\n for i in range(n // 2):\r\n li[i+cnt] = a[i]\r\n cnt += 1\r\n\r\n for i in range(n//2, n):\r\n li[cnt2] = a[i]\r\n cnt2 += 2\r\n print(*li)\r\n else:\r\n for i in range(n // 2 + 1):\r\n li[i + cnt] = a[i]\r\n cnt += 1\r\n for i in range(n // 2 + 1, n):\r\n li[cnt2] = a[i]\r\n cnt2 += 2\r\n print(*li)\r\nelse:\r\n print(*a)",
"from sys import stdin\r\n\r\nn = int(stdin.readline().strip())\r\nnums = sorted([int(i) for i in stdin.readline().strip().split()])\r\n\r\na = []\r\nif n % 2 == 0:\r\n for i in range(0,int(n/2)):\r\n a.append(str(nums[i]))\r\n a.append(str(nums[n-1-i]))\r\nelse:\r\n for i in range(0,int((n-1)/2)):\r\n a.append(str(nums[i]))\r\n a.append(str(nums[n-1-i]))\r\n a.append(str(nums[int((n-1)/2)]))\r\n\r\nprint(' '.join(a))",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nl=n//2+1 if n%2 else n//2\r\nj=0\r\nq=True\r\nfor i in range(n):\r\n if q:\r\n print(a[j],end=' ')\r\n q=False\r\n j+=1\r\n else:\r\n print(a[l],end=' ')\r\n q=True\r\n l+=1\r\n\r\n\r\n \r\n",
"m = int(input())\r\nspi=list(map(int,input().split()))\r\nspi.sort()\r\nans=[]\r\nfor i in range(len(spi)):\r\n if i%2==0:\r\n ans.append(spi[0])\r\n spi.pop(0)\r\n else:\r\n ans.append(spi[-1])\r\n spi.pop(-1)\r\nprint(*ans)",
"def zsort(n, A):\n A.sort()\n return [A[-(i+1)//2] if i % 2 else A[i//2] for i in range(n)]\n\n\ndef main():\n n = readint()\n A = readintl()\n print(' '.join(map(str, zsort(n, A))))\n\n##########\n\nimport sys\n\n\ndef readint():\n return int(input())\n\n\ndef readinti():\n return map(int, input().split())\n\n\ndef readintl():\n return list(readinti())\n\n\ndef readintll(k):\n return [readintl() for _ in range(k)]\n\n\ndef log(*args, **kwargs):\n print(*args, **kwargs, file=sys.stderr)\n\n\nif __name__ == '__main__':\n main()\n",
"def solve():\n N = int(input())\n A = list(map(int, input().split()))\n\n A.sort()\n h = (N + 1) // 2\n f = A[:h]\n l = A[h:]\n\n ans = [0] * N\n\n for i in range(N):\n if i % 2 == 0:\n ans[i] = str(f[i//2])\n else:\n ans[i] = str(l[i//2])\n print(' '.join(ans))\n\n\nif __name__ == '__main__':\n solve()\n",
"def main(n, a):\n a1 = sorted(a)\n a2 = list(reversed(sorted(a)))\n r = []\n for i in range(n//2):\n r.append(a1[i])\n r.append(a2[i])\n if n % 2 == 1:\n r.append(a1[n // 2])\n return ' '.join(list(map(str,r)))\n\nprint(main(int(input()), list(map(int, input().split(' ')))))\n",
"n = int(input(\"\"))\nA = list(map(int, input(\"\").split(\" \")))\nA.sort()\nB = list()\n\nleft = 0\nright = len(A) - 1\n\nwhile(left<=right):\n if(left == right):\n B.append(A[left])\n else:\n B.append(A[left])\n B.append(A[right])\n\n left += 1\n right -= 1\n\n# check Array B\nz_sort = True\nfor i in range(1, len(B)):\n if (i+1) % 2 == 0:\n if B[i] < B[i-1]:\n z_sort = False\n break\n else:\n if B[i] > B[i-1]:\n z_sort = False\n break\n\nif z_sort:\n for x in B:\n print(x, end=\" \")\n print(\"\")\nelse:\n print(\"Impossible\")\n\n \t\t\t\t \t\t\t \t\t \t\t\t\t\t\t \t \t\t\t\t",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\nlst.sort()\r\nres = []\r\nfor m in range(len(lst)):\r\n if m % 2 == 0:\r\n res.append(lst[m//2])\r\n else:\r\n res.append(lst[-(m+1)//2])\r\nprint(' '.join(str(x) for x in res))",
"from itertools import zip_longest\n\nn, a = int(input()), sorted(int(i) for i in input().split())\nmid = (n + 1)//2\nres = [i for x, y in zip_longest(a[:mid], a[mid:][::-1], fillvalue=0) for i in (x, y)]\nif n & 1 == 1:\n res.pop()\nprint(*res)\n",
"import sys, math\r\ninput=sys.stdin.readline\r\nINF=int(1e9)+7\r\n\r\ndef solve(): \r\n n=int(input())\r\n data=list(map(int,input().split()))\r\n data.sort()\r\n result=[0]*(n+1)\r\n for i in range(n//2):\r\n result[2*i+2]=data[-1-i]\r\n for i in range((n+1)//2):\r\n result[2*i+1]=data[i]\r\n print(*result[1:],sep=' ')\r\n \r\nt=1\r\nwhile t:\r\n t-=1\r\n solve()\r\n",
"n=int(input())\r\na=sorted(map(int,input().split()))\r\na=[x for l in zip(a[:0--n//2],a[0--n//2:]) for x in l]+[a[n//2]]\r\nprint(*a[:n])",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nl=[]\r\np=0\r\ni=0\r\nwhile len(l)!=n:\r\n\tif p==0:\r\n\t\tl.append(a[i])\r\n\telse:\r\n\t\tl.append(a[n-i-1])\r\n\t\ti+=1\r\n\tp=p^1\r\nprint(*l) ",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans = []\r\ncheck = sorted(a)\r\ni, j = 0, n-1\r\nwhile i < j :\r\n ans.append(check[i])\r\n ans.append(check[j])\r\n i += 1\r\n j -= 1\r\nif i == j:\r\n ans.append(check[i])\r\nprint(*ans)",
"import logging\r\nimport copy\r\nimport sys\r\n\r\nlogging.basicConfig(stream=sys.stderr, level=logging.DEBUG)\r\n\r\n#def solve(firstLine):\r\ndef solve(length, line):\r\n length = length[0]\r\n line.sort()\r\n r = [-1] * length\r\n\r\n for i in range(0,length,2):\r\n r[i] = line[0]\r\n del line[0]\r\n\r\n line.sort(reverse=True)\r\n\r\n for i in range(1,length,2):\r\n r[i] = line[0]\r\n del line[0]\r\n\r\n resultStr= ' '.join(str(e) for e in r)\r\n return resultStr\r\n\r\ndef main():\r\n firstLine = input().split()\r\n firstLine = list(map(int, firstLine))\r\n inputLines = input().split()\r\n inputLines = list(map(int, inputLines))\r\n\r\n \r\n #solve(firstLine)\r\n print(solve(firstLine, inputLines))\r\n\r\ndef log(*message):\r\n logging.debug(message)\r\n \r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n = int(input())\nd = list(map(int,input().split()))\nd.sort()\nl = 0\nr = n - 1\np = []\nx = 1\nfor i in range(n):\n if x == 1:\n x *= -1\n # l += 1\n p += [d[l]]\n l += 1\n else:\n x *= -1\n #r -= 1\n p += [d[r]]\n r -= 1\nans= 0\nfor i in range(2,n + 1):\n if i % 2 == 0:\n if p[i - 1] < p[i - 2]:\n ans = 1\n else:\n if p[i - 1] > p[i - 2]:\n ans = 1\nif ans == 1:\n print('Impossible')\nelse:\n print(*p)\n \n \n\n \t \t\t \t\t \t \t \t \t \t \t",
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\na.sort()\r\nresults=[None]*n\r\nhalf_len=n//2\r\nfor i in range(half_len):\r\n\tresults[i*2]=a[i]\r\n\tresults[i*2+1]=a[~i]\r\nif n%2==1:\r\n\tresults[-1]=a[half_len]\r\nprint(' '.join(map(str,results)))",
"def main():\r\n\tn = int(input())\r\n\ta = sorted(map(int, input().split()))\r\n\tresult = [0]*n\r\n\t# print(result)\r\n\t# basic = 0\r\n\t# # a.sort()\r\n\t# # print(a)\r\n\t# count = 0 \r\n\t# if n&1==0:\r\n\t# \twhile basic<n:\r\n\t# \t\t# print(basic, count)\r\n\t# \t\tresult[count] = a[basic]\r\n\t# \t\tif count==n-2:\r\n\t# \t\t\tcount = 1\r\n\t# \t\t\tbasic+=1\r\n\t# \t\t\t# print(basic, count)\r\n\t# \t\t\tresult[count] = a[basic]\r\n\t# \t\tbasic+=1\r\n\t# \t\tcount+=2\r\n\t# else:\r\n\t# \twhile basic<n:\r\n\t# \t\t# print(basic, count)\r\n\t# \t\tresult[count] = a[basic]\r\n\t# \t\tif count==n-1:\r\n\t# \t\t\tcount = 1\r\n\t# \t\t\tbasic+=1\r\n\t# \t\t\t# print(basic, count)\r\n\t# \t\t\tresult[count] = a[basic]\r\n\t# \t\tbasic+=1\r\n\t# \t\tcount+=2\r\n\r\n\tresult[::2] = a[:(n+1)//2]\r\n\tresult[1::2] = a[(n+1)//2:]\r\n\t# print(a[basic])\r\n\tprint(*result)\r\n\t\r\nmain()",
"n=int(input())\r\nch=input()\r\nd=ch.split()\r\nfor i in range(n):\r\n d[i]=int(d[i])\r\nd.sort()\r\nd1=[]\r\ni=0\r\nj=0\r\nwhile j<n:\r\n d1.append(d[i])\r\n j+=1\r\n if j<n:\r\n j+=1\r\n d1.append(d[n-i-1])\r\n i+=1\r\nB=False\r\nfor i in range(n):\r\n if d1[i]<d1[i-1] and (i+1)%2==0:\r\n B=True\r\n if d1[i]>d1[i-1] and (i+1)%2!=0:\r\n B=True\r\nif B==False:\r\n for i in d1:\r\n print(i,end=\" \")\r\nelse:\r\n print( \"Impossible\")\r\n",
"def main():\r\n n = int(input())\r\n nums = sorted(list(map(int, input().split())))\r\n\r\n for i in range(n//2+1):\r\n print(nums[i], end=\" \")\r\n if n//2 + i + 1 < n:\r\n print(nums[n//2+i+1], end=\" \")\r\n \r\n\r\nmain()",
"import sys,math\nsys.setrecursionlimit(10**8)\n'''\ndef fun():\n for i in range(16):\n for j in range(4):\n if i&(1<<j):\n print(j,end='')\n print()\nimport binarytree\nfrom collections import deque\nbst = binarytree.tree(height=4,is_perfect=True)\nprint(bst)\ndef s(bst):\n if bst:\n bst.left,bst.right = bst.right,bst.left\n s(bst.right)\n s(bst.left)\ns(bst)\nprint(bst)\n'''\nn = int(input())\narr = list(map(int,input().split()))\narr.sort()\nx = []\nz = 1\nfor i in range(n//2):\n x.append(arr[i])\n x.append(arr[len(arr)-i-1])\nif n%2 == 1:\n x.append(arr[(n//2)])\nfor i in range(n):\n if i%2 == 1:\n if x[i]<x[i-1]:\n print(\"Impossible\")\n z=0\n break\n else:\n if x[i]>x[i-1]:\n print(\"Impossible\")\n z=0\n break\nif z!=0:\n print(' '.join(map(str,x)))\n",
"import sys\r\n\r\nn = int(input())\r\na = sorted(map(int, input().split()))\r\nans = [0]*n\r\n\r\nj = 0\r\nfor i in range((n+1) >> 1):\r\n ans[j] = a[i]\r\n j += 2\r\n\r\nj = 1\r\nfor i in range((n+1) >> 1, n):\r\n ans[j] = a[i]\r\n j += 2\r\n\r\nprint(*ans)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nfor i in range(n):\r\n for j in range(1, n):\r\n if (j + 1) % 2 == 0 and a[j] < a[j - 1]:\r\n a[j], a[j - 1] = a[j - 1], a[j]\r\n if (j + 1) % 2 != 0 and a[j] > a[j - 1]:\r\n a[j], a[j - 1] = a[j - 1], a[j]\r\nprint(*a)\r\n",
"a=int(input())\r\nb=(input())\r\nb=b.split(' ')\r\nb=map(int,b)\r\nb=list(b)\r\nfor i in range(1,len(b),2):\r\n if b[i]<b[i-1]:\r\n t=b[i-1]\r\n b[i-1]=b[i]\r\n b[i]=t\r\nfor i in range(2,len(b),2):\r\n if b[i]>b[i-1]:\r\n t=b[i-1]\r\n b[i-1]=b[i]\r\n b[i]=t\r\nv=b.copy()\r\nfor i in range(1,len(b),2):\r\n if b[i]<b[i-1]:\r\n t=b[i-1]\r\n b[i-1]=b[i]\r\n b[i]=t\r\nif v==b:\r\n v=map(str,v)\r\n print(' '.join(v))\r\nelse:\r\n print('Impossible')\r\n \r\n",
"def main():\r\n input()\r\n numbers = list(map(int, input().split()))\r\n numbers = sorted(numbers)\r\n n = len(numbers)\r\n result = [0 for _ in range(n)]\r\n j = 0\r\n k = n - 1\r\n for i in range(len(result)):\r\n if i % 2 == 1:\r\n result[i] = numbers[k]\r\n k -= 1\r\n else:\r\n result[i] = numbers[j]\r\n j += 1\r\n result = [str(el) for el in result]\r\n print(\" \".join(result))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\na.sort()\r\nfor c in range(2,n,2):\r\n a[c-1], a[c] = a[c], a[c-1]\r\nprint(*a)\r\n",
"def solve():\r\n print(l[0],l[-1],end=' ')\r\n del(l[0])\r\n del(l[-1])\r\nitr = int(input())\r\nl=sorted(list(map(int,input().split())))\r\nwhile len(l):\r\n if itr%2==0:solve()\r\n else:\r\n if len(l)>2:solve()\r\n else:print(l[0],end=' ');del(l[0])\r\n\r\n\r\n",
"import math\r\nn = int(input())\r\n\r\narr = [int(x) for x in input().split(' ')]\r\nres = [0]*n\r\n\r\narr.sort()\r\n\r\nres = [0]*n\r\nidx = 0\r\nfor i in range(n, 0, -1):\r\n\tif(i%2 == 1):\r\n\t\tres[i-1] = arr[idx]\r\n\t\tidx += 1\r\n\r\nfor i in range(1, n+1):\r\n\tif(i%2 == 0):\r\n\t\tres[i-1] = arr[idx]\r\n\t\tidx += 1\r\n\r\nfor i in range(n):\r\n\tprint(res[i], end = \" \")",
"#652B (72No. Problem B)\r\nn = int(input())\r\narr = sorted(list(map(int,input().split())))\r\ntemp = [0]*n\r\nfor i in range(len(arr),0,-1):\r\n if (i%2 == 0):\r\n temp[i-1] = max(arr)\r\n arr.pop()\r\n else:\r\n temp[i-1] = min(arr)\r\n arr.pop(0)\r\nprint(*temp) \r\n\r\n",
"#!/usr/bin/python3\r\n#coding=utf-8\r\n\r\n__metaclass__ = type\r\n__author__ = 'xdlove'\r\n\r\nn = int(input())\r\nlt = list(map(int,input().split()))\r\n\r\nlt.sort()\r\nres = list()\r\n\r\nn += 1\r\nfor i in range(n // 2):\r\n res.append(lt[i])\r\n if i + n // 2 == n - 1:\r\n break\r\n res.append(lt[i + n // 2])\r\n\r\nprint(' '.join(map(str,res)))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nans=[]\r\nfor i in range(n):\r\n if i%2==0:\r\n ans.append(str(a[i//2]))\r\n else:\r\n ans.append(str(a[-i//2]))\r\n\r\n\r\n\r\nprint(\" \".join(ans))\r\n",
"#remember me in your prayers\r\nn = int(input())\r\na = sorted(map(int, input().split()))\r\nfor i in range(2, n, 2):\r\n a[i - 1], a[i] = a[i], a[i - 1]\r\nprint(*a)\r\n",
"import sys \r\ninput = sys.stdin.readline \r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\nb = []\r\ni, j = 0, n - 1 \r\nc = n // 2 \r\nwhile(c):\r\n b.append(a[i])\r\n b.append(a[j])\r\n c -= 1 \r\n i += 1 \r\n j -= 1 \r\n\r\nif(n % 2): \r\n b.append(a[n // 2])\r\n\r\n# print(b)\r\nfor i in range(1, n):\r\n if(i % 2):\r\n if(b[i] < b[i - 1]):\r\n print(\"Impossible\")\r\n break\r\n \r\n else:\r\n if(b[i] > b[i - 1]):\r\n print(\"Impossible\")\r\n break \r\nelse:\r\n print(*b)\r\n \r\n \r\n",
"#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Tue Jun 30 11:36:12 2020\n\n@author: shailesh\n\"\"\"\n\nn = int(input())\n\n\na = [int(i) for i in input().split()]\n\n\na.sort()\n\neven_positions = a[(n+1)//2:]\n\nodd_positions = a[:(n+1)//2]\n\nl = []\nfor i in range(len(even_positions)):\n l.append(str(odd_positions[0]))\n l.append(str(even_positions[0]))\n odd_positions.pop(0)\n even_positions.pop(0)\n\nif len(odd_positions)!= 0:\n l.append(str(odd_positions[0]))\n\n\nprint(' '.join(l))",
"n=int(input())\r\narr=list(map(int,input().split()))\r\narr.sort()\r\nans=[]\r\ni=0\r\nwhile len(ans)<n:\r\n if i%2==0:\r\n ele=arr.pop(0)\r\n ans.append(ele)\r\n else:\r\n ele=arr.pop(-1)\r\n ans.append(ele)\r\n i+=1\r\nprint(*ans)",
"n = int(input())\n\na = [int(x) for x in input().split()]\n\na.sort()\nb = [0] * n\nj = 0\n\nfor i in range(n//2):\n b[j] = a[i]\n b[j+1] = a[-1-i]\n j += 2\n\nif n%2:\n b[j] = a[n//2]\n\nfor x in b:\n print(x, end=' ')\n\nprint()\n",
"n, a = int(input()), list(sorted(map(int, input().split())))\r\nb = [0] * n\r\nb[::2] = a[0:(n + 1) // 2]\r\nb[1::2] = list(reversed(a[(n + 1) // 2:]))\r\nprint(*b)\r\n",
"n=int(input())\r\nn1=list(map(int,input().split()))\r\nn1.sort()\r\nlst=[]\r\nk=0\r\nfor i in range(n//2):\r\n lst.append(n1[0])\r\n lst.append(n1[-1])\r\n n1.remove(n1[0])\r\n n1.remove(n1[-1])\r\nif(n1!=[]):\r\n lst.append(n1[0])\r\nfor j in range(1,len(lst)-1):\r\n if((j-1)==0):\r\n continue\r\n else:\r\n if((j)%2==0):\r\n if(lst[j-1]>=lst[j-2]):\r\n continue\r\n else:\r\n k=k+1\r\n break\r\n else:\r\n if(lst[j-1]<=lst[j-2]):\r\n continue\r\n else:\r\n k=k+1\r\n break\r\nif(k>0):\r\n print('IMPOSSIBLE')\r\nelse:\r\n for j in lst:\r\n print(j,end=' ')\r\n\r\n",
"n = int(input())\r\na = sorted(map(int,input().split()))\r\np,q = 0,n-1\r\nb = [0]*n\r\nfor i in range(n):\r\n if i&1:\r\n b[i]=a[q]\r\n q-=1\r\n else:\r\n b[i]=a[p]\r\n p+=1\r\nprint(*b)",
"n = int(input())\r\na = sorted(map(int,input().split())) #List\r\n\r\nfor i in range(1, len(a)):\r\n if (i+1)%2 == 0:\r\n if a[i] < a[i-1]:\r\n temp = a[i]\r\n a[i] = a[i-1]\r\n a[i-1] = temp\r\n i = 1\r\n else:\r\n if a[i] > a[i-1]:\r\n temp = a[i]\r\n a[i] = a[i-1]\r\n a[i-1] = temp\r\n i = 1\r\n\r\nfor i in range(n):\r\n print(a[i], end=\" \")\r\nprint()\r\n",
"n = int(input())\r\nmas = list(map(int, input().split()))\r\nmas.sort()\r\nzmas = []\r\nfor i in range(len(mas)//2):\r\n zmas.append(mas[i])\r\n zmas.append(mas[n-i-1])\r\nif n%2 == 1:\r\n zmas.append(mas[n//2])\r\nprint(*zmas)\r\n",
"#import sys\r\n#sys.stdin = open('in', 'r')\r\nn = int(input())\r\na = sorted([int(x) for x in input().split()])\r\n#n,m = map(int, input().split())\r\n\r\ni = 0\r\nj = (n + 1) // 2\r\n\r\nwhile i < (n // 2):\r\n print(a[i], end=' ')\r\n print(a[i + j], end=' ')\r\n i += 1\r\n\r\nif n & 1:\r\n print (a[i])\r\n",
"# http://codeforces.com/problemset/problem/652/B\r\nn = int(input())\r\nq = [int(x) for x in input().split()]\r\ni = 0\r\nj = n-1\r\nq.sort()\r\nwhile(i <= j):\r\n\tprint(q[i], end=' ')\r\n\ti += 1\r\n\tif (i <= j):\r\n\t\tprint(q[j], end=' ')\r\n\t\tj -= 1\r\nprint()",
"import sys\r\n\r\nn = int(input()) \r\nd = list(map(int, input().split()))\r\nd.sort()\r\nwhile d:\r\n u = d.pop(0)\r\n print(u, end=' ')\r\n if d:\r\n u = d.pop() \r\n print(u, end=' ')\r\n\r\n",
"n = int(input())\r\na = sorted(list(map(int, input().split())))\r\nans = [0] * n\r\ni = 0\r\nwhile 2 * i < n:\r\n ans[2 * i] = a[i]\r\n i += 1\r\nj = 0\r\nwhile 2 * j + 1 < n:\r\n ans[2 * j + 1] = a[i]\r\n i += 1\r\n j += 1\r\nprint(*ans)",
"\nfrom sys import stdin\n\nn = int(stdin.readline().strip())\nnums = sorted([int(i) for i in stdin.readline().strip().split()])\n\nans, flag = [nums[0]], True\nfor i in range(1, n):\n\tidx = i // 2 if i % 2 == 0 else n - ((i + 1) // 2)\n\tans.append(nums[idx])\n\tif i % 2 == 1:\n\t\tif ans[-1] < ans[-2]:\n\t\t\tflag = False\n\t\t\tbreak\n\telse:\n\t\tif ans[-1] > ans[-2]:\n\t\t\tflag = False\n\t\t\tbreak\n\nif flag:\n\tfor i in ans:\n\t\tprint(i, end = ' ')\n\tprint()\nelse:\n\tprint(\"Impossible\")\n\n \t \t \t\t \t \t\t \t \t\t\t\t \t \t",
"from math import ceil\r\nn=int(input())\r\na=sorted(list(map(int,input().split())))\r\nif(n==1):\r\n print(a[0])\r\nelse:\r\n b=a[:ceil(n/2)]\r\n c=a[ceil(n/2):]\r\n for i in range(n//2):\r\n print(b[i],c[i],end=' ')\r\n if(n&1):\r\n print(b[-1])",
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nb = [a[0]]\r\ni, j = 1, len(a)-1\r\nboo = True\r\nwhile i <= j and boo:\r\n if b[len(b) - 1] > a[j]:\r\n boo = False\r\n elif a[j] < a[i]:\r\n boo = False\r\n elif i == j:\r\n b.append(a[i])\r\n else:\r\n b.append(a[j])\r\n b.append(a[i])\r\n i += 1\r\n j -= 1\r\nif i < j:\r\n print(\"Impossible\")\r\nelse:\r\n print(\" \".join(map(str,b)))",
"n = int(input())\r\nl = list(map(int,input().split()))\r\n\r\nfor i in range(n):\r\n if(i%2==0):\r\n if(l[i]>=l[i-1]):\r\n l[i],l[i-1] = l[i-1],l[i]\r\n else:\r\n if(l[i]<=l[i-1]):\r\n l[i],l[i-1] = l[i-1],l[i]\r\n\r\nprint(*l)",
"n = int(input())\r\nl = sorted(list(map(int,input().split())))\r\nans = []\r\nfor i in range(n//2):\r\n ans.append(l[i])\r\n ans.append(l[-(i+1)])\r\nif n%2 != 0:\r\n ans.append(l[n//2])\r\nprint(*ans)",
"from collections import deque, defaultdict, Counter\r\nfrom itertools import product, groupby, permutations, combinations\r\nfrom math import gcd, floor, inf\r\nfrom bisect import bisect_right, bisect_left\r\n\r\nn = int(input())\r\narr = deque(sorted(map(int, input().split())))\r\n\r\nans = []\r\n\r\nwhile arr:\r\n ans.append(arr.popleft())\r\n if arr:\r\n ans.append(arr.pop())\r\n\r\nprint(*ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ni=0\r\nj=n-1\r\nd=[]\r\nwhile(i<j):\r\n d.append(l[i])\r\n d.append(l[j])\r\n i=i+1\r\n j=j-1\r\nif(n%2==1):\r\n d.append(l[n//2])\r\nprint(*d)\r\n",
"I=input\r\nR=range\r\nn=int(I())\r\nl=n//2\r\nt=l+n%2\r\na=sorted(map(int,I().split()))\r\nb=[]\r\nfor i in R(l):b+=[a[i],a[i+t]]\r\nif n%2:b+=[a[l]]\r\nt=' '.join(map(str,b))\r\nfor i in R(1,n):\r\n\tif i%2 and b[i-1]>b[i] or i%2-1 and b[i-1]<b[i]:t='Impossible'\r\nprint(t)",
"n = int(input())\r\ndata = list(map(int, input().split()))\r\nsdata = sorted(data)\r\na = sdata[:(n + 1) // 2]\r\nb = sdata[(n + 1) // 2:]\r\nfor i in range((n + 1) // 2):\r\n print(a[i], end=' ')\r\n if i < len(b):\r\n print(b[i], end=' ')",
"n=int(input())\r\na=[int(x) for x in input().split(' ')]\r\na.sort()\r\nif n%2==0:m=n//2\r\nelse:m=(n//2)+1\r\nb=a[0:m:]\r\nc=a[m:n:]\r\nj=0\r\nk=0\r\nfor i in range(n):\r\n if i%2==0:\r\n print(b[j],end=' ')\r\n j+=1\r\n else:\r\n print(c[k],end=' ')\r\n k+=1\r\n\r\n\r\n",
"def swap(a: list, aux, i, j):\n a[j] = a[i]\n a[i] = aux\n\n\ndef z_sort(n: int, a: list):\n a = sorted(a)\n j = 1\n for i in range(2, n, 2):\n if a[i] > a[i - 1]:\n swap(a, a[j], i, j)\n j += 2\n\n for i in range(n - 1):\n print(a[i], end=' ')\n print(a[n - 1])\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n z_sort(n, a)\n\n\nif __name__ == '__main__':\n main()\n\t\t\t \t \t \t\t\t \t\t\t \t \t\t\t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\n\r\nfor i in range(1, n-1, 2):\r\n a[i], a[i+1] = a[i+1], a[i]\r\n\r\nif all(a[i] >= a[i-1] for i in range(1, n, 2)) and all(a[i] <= a[i-1] for i in range(2, n, 2)):\r\n print(\" \".join(map(str, a)))\r\nelse:\r\n print(\"Impossible\")",
"from sys import stdin\r\nn = int(stdin.readline())\r\na = sorted(map(int, stdin.readline().split()))\r\nans = [0] * n\r\nfor i in range(0, n, 2):\r\n ans[i] = a.pop(0)\r\n if a:\r\n ans[i+1] = a.pop()\r\nprint(*ans)",
"n = int(input())\r\na = sorted(list(map(int, input().split())))\r\nans=[]\r\nleft=0\r\nright=n-1\r\nfor i in range (n):\r\n if i%2==0:\r\n ans.append(a[left])\r\n left+=1\r\n else:\r\n ans.append (a[right])\r\n right-=1\r\nprint (*ans)\r\n ",
"n = int(input())\r\ns = list(map(int, input().split()))\r\ns.sort()\r\np = n // 2\r\nans = [0] * (n)\r\nq = n\r\nfor i in range(1, n, 2):\r\n q -= 1\r\n ans[i] = s[q]\r\nfor i in range(0, n, 2):\r\n q -= 1\r\n ans[i] = s[q]\r\nprint(*ans)",
"size = int(input())\r\na = input()\r\na = a.split()\r\nfor i in range(size):\r\n a[i] = int(a[i])\r\na = sorted(a)\r\nfor i in range(1,size,2):\r\n try:\r\n a[i],a[i+1] = a[i+1],a[i]\r\n except:\r\n pass\r\nfor i in range(size):\r\n print(f'{a[i]}',end = ' ')",
"#! /usr/bin/env python3\n'''\n' Title:\t\n' Author:\tCheng-Shih, Wong\n' Date:\t\t\n'''\n\nimport math\n\nn = int(input())\na = [int(v) for v in input().split()]\n\na.sort()\nhalf = math.ceil(n/2)\nb = [0]*n\n\nfor i in range(0,half):\n\tb[i*2] = a[i]\nfor i in range(half,n):\n\tb[(i-half)*2+1] = a[i]\n\nprint( ' '.join([str(v) for v in b]) )\n",
"N = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\n\r\nans = []\r\nfor n in range(N):\r\n\tr = n//2\r\n\tif n % 2 == 0:\r\n\t\tx = a[r]\r\n\telse:\r\n\t\tx = a[N-1-r]\r\n\tans.append(x)\r\nprint(' '.join(map(str, ans)))\r\n",
"n = int(input()) - 1\r\na = sorted(map(int, input().split()))\r\nfor i in range(n):\r\n print(a[int((n + i + 1 if i % 2 else i) / 2)], end = ' ')\r\nprint(a[n if n % 2 else int(n / 2)])",
"# link : https://codeforces.com/problemset/problem/652/B\r\n# sorting \r\n\r\ndef check(l):\r\n for i in range(len(l)):\r\n if (i+1)%2==0:\r\n if not l[i]>=l[i-1]:\r\n return False\r\n else:\r\n if not l[i]<=l[i-1]:\r\n return False\r\n return True\r\n\r\n\r\n\r\nn = int(input())\r\n\r\nl = [int(x) for x in input().split()]\r\n\r\nl.sort()\r\n# print (l)\r\n\r\nresult = [l[0]]\r\nl.pop(0)\r\n\r\nfor i in range(1,len(l)+1):\r\n if (i+1)%2==0:\r\n result.append(l[-1])\r\n if not check(result):\r\n print('Impossible')\r\n break\r\n else:\r\n l.pop(-1)\r\n # print('even',result)\r\n \r\n else:\r\n result.append(l[0])\r\n if not check(result):\r\n print('Impossible')\r\n break\r\n else:\r\n l.pop(0)\r\n # print('odd',result)\r\n\r\nelse:\r\n print(*result)\r\n\r\n\r\n \r\n\r\n\r\n\r\n"
] | {"inputs": ["4\n1 2 2 1", "5\n1 3 2 2 5", "1\n1", "10\n1 1 1 1 1 1 1 1 1 1", "10\n1 9 7 6 2 4 7 8 1 3", "100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91", "3\n1 2 6", "136\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "3\n1 2 3", "7\n999999998 999999999 999999999 999999999 999999999 999999999 1000000000", "3\n100 1 2"], "outputs": ["1 2 1 2", "1 5 2 3 2", "1", "1 1 1 1 1 1 1 1 1 1", "1 9 1 8 2 7 3 7 4 6", "3 100 3 100 3 99 4 98 7 97 8 92 8 92 8 92 9 92 9 91 10 89 12 87 12 87 13 87 14 86 14 85 15 84 15 82 16 82 17 81 17 81 20 80 21 79 21 78 22 78 22 77 23 77 25 76 29 76 31 74 36 72 37 71 37 71 38 70 39 69 40 66 41 64 41 63 41 63 42 62 43 60 44 59 45 59 46 59 46 55 47 54 47 53 49 52 49 52 49 51", "1 6 2", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "1 3 2", "999999998 1000000000 999999999 999999999 999999999 999999999 999999999", "1 100 2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 185 | |
2d6ce72a85e606a5171c5872b40f1b6b | Image Preview | Vasya's telephone contains *n* photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo *n*. Similarly, by swiping right from the last photo you reach photo 1. It takes *a* seconds to swipe from photo to adjacent.
For each photo it is known which orientation is intended for it — horizontal or vertical. Phone is in the vertical orientation and can't be rotated. It takes *b* second to change orientation of the photo.
Vasya has *T* seconds to watch photos. He want to watch as many photos as possible. If Vasya opens the photo for the first time, he spends 1 second to notice all details in it. If photo is in the wrong orientation, he spends *b* seconds on rotating it before watching it. If Vasya has already opened the photo, he just skips it (so he doesn't spend any time for watching it or for changing its orientation). It is not allowed to skip unseen photos.
Help Vasya find the maximum number of photos he is able to watch during *T* seconds.
The first line of the input contains 4 integers *n*,<=*a*,<=*b*,<=*T* (1<=≤<=*n*<=≤<=5·105, 1<=≤<=*a*,<=*b*<=≤<=1000, 1<=≤<=*T*<=≤<=109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo.
Second line of the input contains a string of length *n* containing symbols 'w' and 'h'.
If the *i*-th position of a string contains 'w', then the photo *i* should be seen in the horizontal orientation.
If the *i*-th position of a string contains 'h', then the photo *i* should be seen in vertical orientation.
Output the only integer, the maximum number of photos Vasya is able to watch during those *T* seconds.
Sample Input
4 2 3 10
wwhw
5 2 4 13
hhwhh
5 2 4 1000
hhwhh
3 1 100 10
whw
Sample Output
2
4
5
0
| [
"read = lambda: map(int, input().split())\r\nper = lambda L, R: R - L - 1 + min(R - n - 1, n - L)\r\nn, a, b, T = read()\r\nf = [1 + (i == 'w') * b for i in input()] * 2\r\nL, R = 0, n\r\nans = 0\r\ncur = sum(f) // 2\r\nwhile L <= n and R < n * 2:\r\n cur += f[R]; R += 1\r\n while R - L > n or cur + per(L, R) * a > T:\r\n cur -= f[L]; L += 1\r\n ans = max(ans, R - L)\r\nprint(ans)\r\n",
"# [https://codeforces.com/contest/650/submission/16709913]\r\n\r\n(n, a, b, t) = map(int, input().split())\r\nb += 1\r\nl = [b if char == \"w\" else 1 for char in input()]\r\nt -= sum(l) - a * (n + 2)\r\nhi = n\r\nn2 = n * 2\r\nn3 = n2 + 1\r\nlo = 0\r\nres = 0\r\nl *= 2\r\nwhile lo <= n and hi < n2:\r\n t -= l[hi]\r\n hi += 1\r\n while (hi - lo + (hi if hi < n3 else n3)) * a > t or lo < hi - n:\r\n t += l[lo]\r\n lo += 1\r\n n3 -= 1\r\n if res < hi - lo:\r\n res = hi - lo\r\n if res == n:\r\n break\r\nprint(res)"
] | {"inputs": ["4 2 3 10\nwwhw", "5 2 4 13\nhhwhh", "5 2 4 1000\nhhwhh", "3 1 100 10\nwhw", "10 2 3 32\nhhwwhwhwwh", "1 2 3 3\nw", "100 20 100 10202\nwwwwhhwhhwhhwhhhhhwwwhhhwwwhwwhwhhwwhhwwwhwwhwwwhwhwhwwhhhwhwhhwhwwhhwhwhwwwhwwwwhwhwwwwhwhhhwhwhwww", "20 10 10 1\nhwhwhwhwhwhwhwhwhhhw", "12 10 10 1\nwhwhwhwhwhwh", "2 5 5 1000000000\nwh", "16 1 1000 2100\nhhhwwwhhhwhhhwww", "5 2 4 13\nhhhwh", "7 1 1000 13\nhhhhwhh", "10 1 1000 10\nhhhhhhwwhh", "7 1 100 8\nhhhwwwh", "5 2 4 12\nhhhwh"], "outputs": ["2", "4", "5", "0", "7", "0", "100", "1", "0", "2", "5", "4", "6", "5", "4", "4"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
2d807654d96829234b558af3cc2ac5d3 | Our Tanya is Crying Out Loud | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*. Can be performed only if *x* is divisible by *k*. This operation costs you *B* coins.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109).
Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1.
Sample Input
9
2
3
1
5
5
2
20
19
3
4
2
Sample Output
6
8
12
| [
"n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\nres = 0\nwhile n!=1:\n\tif k==1 or k>n:\n\t\tres+=a*(n-1)\n\t\tbreak\n\tif n%k!=0:\n\t\tres+=a*(n%k)\n\t\tn = n-n%k\n\telse:\n\t\ttemp = n//k\n\t\tres+=min(b,a*(n-temp))\n\t\tn = temp\nprint(res)\n\t\t\t \t\t\t \t \t\t\t\t \t\t \t\t \t",
"n=int(input())\r\nk=int(input())\r\na=int(input())\r\nb=int(input())\r\nif(k==1):\r\n print ((n-1)*a)\r\nelse:\r\n t=(b*k)/(a*(k-1))\r\n ans=n\r\n c=0\r\n while(ans>1):\r\n if(ans>=t and ans%k==0):\r\n c+=b\r\n ans=ans//k\r\n else:\r\n if(ans>=t and ans>k):\r\n h=ans%k\r\n ans-=h\r\n c+=a*h\r\n else:\r\n c+=a*(ans-1)\r\n ans=1\r\n print(c)\r\n \r\n \r\n ",
"n,k,a,b = int(input()),int(input()),int(input()),int(input())\r\nif k==1: print(a*(n-1))\r\nelse:\r\n ans = 0\r\n while n>1:\r\n if n%k==0:\r\n nw = n//k\r\n diff = n-nw\r\n if a*diff<b:\r\n ans += a*diff\r\n else: ans += b\r\n n = nw\r\n else:\r\n tosub = n%k\r\n ans += a*tosub\r\n n -= tosub\r\n if n==0: ans -= a\r\n print(ans)",
"n=int(input())\r\nk=int(input())\r\na=int(input())\r\nb=int(input())\r\n\r\nif k==1:\r\n\tprint(a*(n-1))\r\n\texit()\r\nans=0\r\nwhile n>1:\r\n\tif n<k:\r\n\t\tans+=a*(n-1)\r\n\t\tbreak\r\n\tif n%k==0:\r\n\t\tans+=min(a*(n-n//k),b)\r\n\t\tn=n//k\r\n\telse:\r\n\t\tans+=a*(n-n//k*k)\r\n\t\tn=n//k*k\r\nprint(ans)",
"n=int(input())\r\nk=int(input())\r\na=int(input())\r\nb=int(input())\r\nans=0\r\nwhile n>1:\r\n if n%k==0:\r\n if (n-n//k)*a<b:\r\n ans+=a*(n-1)\r\n break\r\n ans+=min((n-n//k)*a,b)\r\n n//=k\r\n elif n>k:\r\n ans+=a*(n-k*(n//k))\r\n n=k*(n//k)\r\n else :\r\n ans+=a*(n-1)\r\n break\r\nprint(ans)\r\n ",
"#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport array\nfrom bisect import *\nfrom collections import *\nimport fractions\nimport heapq \nfrom itertools import *\nimport math\nimport random\nimport re\nimport string\n\nN = int(input())\nK = int(input())\nA = int(input())\nB = int(input())\n\nif K == 1:\n print ((N - 1) * A)\nelse:\n ans = 0\n x = N\n while x > 1:\n if x < K:\n ans += (x - 1) * A\n break\n elif x % K != 0:\n new_x = (x // K) * K\n ans += (x - new_x) * A\n x = new_x\n else:\n new_x = x // K\n cost1 = B\n cost2 = (x - new_x) * A\n ans += min(cost1, cost2)\n x = new_x\n # print(\"x, ans = \", x, ans)\n print(ans)\n",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\n\r\ncoin = 0;\r\n\r\nif k==1:\r\n print(int(A*(n-1)))\r\nelse:\r\n while n > 1:\r\n if n % k == 0:\r\n cur = (n - (n / k)) * A\r\n if cur > B:\r\n coin += B\r\n else:\r\n coin += cur\r\n n /= k\r\n else:\r\n cur = (n % k) * A\r\n n -= (n % k)\r\n coin += cur\r\n if n == 0:\r\n coin -= A;\r\n\r\n print(int(coin))",
"n=int(input())\r\nk=int(input())\r\nA=int(input())\r\nB=int(input())\r\n\r\nx=n\r\ncost = 0\r\n\r\nwhile (x!=1):\r\n\tif (k==1):\r\n\t\tcost+=A*(x-1)\r\n\t\tx=1\r\n\telif (x%k==0):\r\n\t\tx=x/k\r\n\t\tcost+=min(B,A*(x*k-x))\r\n\r\n\telif (x%k==1):\r\n\t\tx=x-1\r\n\t\tcost+=A\r\n\t\t\r\n\telse:\r\n\t\tcost+=A*((x%k)-1)\r\n\t\tx=x-((x%k)-1)\r\n\t\t\r\nprint(int(cost))",
"n = int(input())\r\nk = int(input())\r\na_cost = int(input())\r\nb_cost = int(input())\r\n\r\nx = n\r\n\r\nif k == 1:\r\n result = (x - 1) * a_cost\r\n\r\nelse:\r\n result = 0\r\n result += (x % k) * a_cost\r\n x -= x % k\r\n while b_cost < (x - x//k) * a_cost:\r\n result += b_cost\r\n x //= k\r\n result += (x % k) * a_cost\r\n x -= x % k\r\n if x != 0:\r\n result += (x - 1) * a_cost\r\n else:\r\n result -= a_cost\r\n\r\n\r\nprint(result)\r\n",
"n, k, A, B, v = int(input()), int(input()), int(input()), int(input()), 0\r\nwhile n > 1:\r\n if k == 1 or n < k:\r\n v += A * (n - 1)\r\n n = 1\r\n elif n % k:\r\n v += A * (n % k)\r\n n -= n % k\r\n else:\r\n v += min(A * (n - n // k), B)\r\n n //= k\r\nprint(v)",
"n,k,a,b=[int(input()) for i in range(4)]\r\nc=0\r\nwhile(n!=1):\r\n if(n%k):\r\n c+=(n%k)*a\r\n n=n-n%k\r\n else:\r\n if(b/max(n-n//k,10**(-9))<a):\r\n c+=b\r\n n=n//k\r\n else:\r\n c+=(n-1)*a\r\n break\r\nprint(c)\r\n ",
"n=int(input())#19\r\nk=int(input())#3\r\na=int(input())#4\r\nb=int(input())#2\r\nc=0\r\nwhile n!=1:#2\r\n if n%k==0 and k!=1:\r\n v=n//k\r\n d=(n-v)*a\r\n if d<b:\r\n n=v\r\n c+=d\r\n else:\r\n n=n//k\r\n c+=b\r\n elif k==1:\r\n var=(n-1)*a\r\n n=1\r\n c+=var\r\n else:\r\n if n>k:\r\n f=n%k\r\n n-=f\r\n c+=(a*f)\r\n else:\r\n ans=(n-1)*a\r\n n=1\r\n c+=ans\r\nprint(c)",
"n = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\ncost = 0\r\nif k != 1:\r\n\twhile n != 1 and n > 0:\r\n\t\tif n % k == 0:\r\n\t\t\tn = n // k\r\n\t\t\tcost = cost + min(n * (k-1) * a, b)\r\n\t\telse:\r\n\t\t\tcost = cost + (n % k) * a\r\n\t\t\tn = n - (n % k)\r\n\t\t\tif n == 0:\r\n\t\t\t\tcost = cost - a\r\n\t\t\t\tn = 1\r\n\tprint(cost)\r\nelse:\r\n\tprint((n-1) * a)",
"import sys\r\n#from io import StringIO\r\n#sys.stdin = StringIO(open(__file__.replace('.py', '.in')).read())\r\n\r\nn = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\n\r\n\r\nif k == 1:\r\n print((n - 1) * a)\r\n sys.exit()\r\n\r\ns = 0\r\n\r\nwhile n > 1:\r\n if n % k == 0:\r\n d = n - (n // k)\r\n if b > a * d:\r\n n -= d\r\n s += a * d\r\n else:\r\n n //= k\r\n s += b\r\n else:\r\n if n // k == 0:\r\n s += (n % k - 1) * a\r\n n -= n % k - 1\r\n else:\r\n s += (n % k) * a\r\n n -= n % k\r\nprint(s)\r\n",
"\ndef solve(n, k, A, B):\n x = n\n\n if n < k or k == 1:\n return A * (n - 1)\n\n allsub = A * (n - 1)\n divonce = (x % k) * A + B + A * (x // k - 1)\n if allsub <= divonce:\n return allsub\n\n ret = (x % k) * A + B\n x = x // k\n ret += solve(x, k, A, B)\n return ret\n\n\nn, k, A, B = [int(input()) for _ in range(4)]\nprint(solve(n, k, A, B))\n",
"n = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\nif k == 1:\r\n print((n-1) * a)\r\nelse:\r\n ans = 0\r\n while n > 0:\r\n ans += n % k * a\r\n n -= n % k\r\n if n == 0:\r\n break\r\n n //= k\r\n ans += min(n*(k-1) * a, b)\r\n print(ans - a)\r\n \r\n",
"n=int(input())\r\nk=int(input())\r\nA=int(input())\r\nB=int(input())\r\nmi=0\r\nif k==1 :\r\n print((n-1)*A)\r\n exit()\r\nwhile (n!=1) :\r\n if n%k!=0 :\r\n mi+=(n%k)*A\r\n n-=n%k\r\n if n<=0 :\r\n mi-=A*abs(n-1)\r\n n=1\r\n else :\r\n p=n\r\n n/=k\r\n mi+=min(B,(p-n)*A)\r\n \r\nprint(int(mi))\r\n \r\n",
"n, k, a, b = int(input()), int(input()), int(input()), int(input())\nans = 0\nif k == 1:\n\tprint(a * (n - 1))\n\texit()\nwhile n > 1:\n\tt = n % k\n\tif n - t == 0:\n\t\tans += a * (t - 1)\n\telse:\n\t\tans += a * t\n\tn -= t\n\tans += min(b, a * (n - n // k))\n\tn //= k\n\nprint(ans)",
"n = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\nc=0\r\nx=n\r\nif k==1:\r\n c=a*(n-1)\r\nelse:\r\n while(x>=k):\r\n y=x%k\r\n c+=y*a\r\n x-=y\r\n c+=min(b,a*(x-x//k))\r\n x=x//k\r\n c+=a*(x-1)\r\nprint(c)",
"x,k,a,b=int(input()),int(input()),int(input()),int(input())\r\nres=0\r\nif k==1:print(a*(x-1));from sys import exit;exit()\r\nwhile x>1:\r\n mod=x%k\r\n if mod==0:\r\n y=x//k\r\n c=a*(x-y)\r\n if b>c:res+=c\r\n else:res+=b\r\n x=y\r\n else:res+=a*mod;x-=mod\r\nif x==0:res-=a\r\nprint(res)",
"n,k,a,b=int(input()),int(input()),int(input()),int(input())\r\ns=0\r\nwhile n>1:\r\n if(n<k or k==1):\r\n s+=(n-1)*a\r\n n=1\r\n continue\r\n if(n%k==0):\r\n if(b<a*(n-(n//k))):\r\n s+=b\r\n else:\r\n s+=a*(n-(n//k))\r\n n//=k\r\n else:\r\n s+=(n%k)*a\r\n n-=(n%k)\r\nprint(int(s))",
"n=int(input())\r\nk=int(input())\r\nA=int(input())\r\nB=int(input())\r\n\r\nc=0\r\nif(k>1):\r\n while(((n//k)*A*(k-1))>B):\r\n c+=(n%k)*A+B\r\n n//=k\r\n\r\nc+=(n-1)*A\r\nprint(c)\r\n",
"#940B\r\nn=int(input());k=int(input());a=int(input());b=int(input())\r\ncount=0\r\nif n==1:\r\n print('0')\r\n exit(0)\r\nwhile((n//k)*a*(k-1)>b):\r\n count+=(n%k)*a+b\r\n n=n//k\r\ncount+=(n-1)*a\r\nprint(count)",
"n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\n\n\ncost = 0\nif k==1:\n cost = (n-1)*a\nelse:\n while n != 1:\n #print(\"n: \"+str(n))\n if n < k:\n cost += (n-1)*a\n break\n if n%k == 0:\n while n%k==0:\n nn = n//k\n #print(\" nn: \"+str(nn))\n if (n-nn)*a <= b:\n #print(\" subtraction with cost: \"+str((n-nn)*a))\n cost = cost + (n-nn)*a\n n = nn\n else:\n #print(\" division with cost: \"+str(b))\n n = nn\n cost += b\n else:\n cost += (n%k)*a\n n -= n%k\n\nprint(cost)\n",
"#besme taala\r\n#ya_hossein\r\nn, k, a, b, s = int(input()), int(input()), int(input()), int(input()), 0\r\nans = 0\r\nif n == 1:\r\n print(0)\r\n exit(0)\r\nwhile n > 1:\r\n if k == 1:\r\n print((n - 1)*a)\r\n exit(0)\r\n if k > n:\r\n print(ans + (n -1)*a)\r\n exit(0)\r\n if n % k == 0:\r\n ans = ans + min(b, (n - int(n/k))*a)\r\n n = int(n/k)\r\n #print(n, ans)\r\n continue\r\n ans += (n%k)*a\r\n n = n - n%k\r\n #print(n, ans)\r\nprint(int(ans))",
"n,k,a,b,s=int(input()),int(input()),int(input()),int(input()),0\r\nif(k>1):\r\n while(((n//k)*(k-1)*a)>b):\r\n s+=(n%k)*a+b\r\n n//=k\r\nprint(int(s+(n-1)*a))",
"n=int(input())\r\nk=int(input())\r\nA=int(input())\r\nB=int(input())\r\n\r\nif k==1:\r\n n-=1\r\n print(n*A)\r\n exit(0)\r\n\r\ncnt=0\r\nwhile n>1:\r\n\r\n if n<k:\r\n x=n-1\r\n cnt+=(x*A)\r\n break\r\n \r\n r=n%k\r\n\r\n if r!=0:\r\n cnt+=(A*r)\r\n n-=r\r\n else:\r\n x=n-n//k\r\n cnt+=min(B,x*A)\r\n n//=k\r\n\r\nprint(cnt)\r\n\r\n",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\nif k == 1:\r\n ans = (n - 1) * a\r\n print(ans)\r\n exit()\r\nans = (n - 1) * a\r\nnow = 0\r\nu = n % k\r\nnow += u * a\r\nn -= u\r\nwhile n:\r\n now += b\r\n n //= k\r\n ans = min(ans, now + (n - 1) * a)\r\n u = n % k\r\n now += u * a\r\n n -= u\r\nprint(ans)",
"n = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\ntot = 0\r\nwhile n>1:\r\n if n%k == 0:\r\n if (n-n//k)*a < b:\r\n\r\n tot+=(n-1)*a\r\n n = 1\r\n break\r\n else:\r\n\r\n tot+=b\r\n n //= k\r\n else:\r\n\r\n tot+=(n%k)*a\r\n n -= n%k\r\nif n == 0:\r\n tot-=a\r\nprint(int(tot))",
"z=input;c,n,k,a,b=0,int(z()),int(z()),int(z()),int(z())\r\nif k>1:\r\n while(((n//k)*a*(k-1))>b):c+=(n%k)*a +b;n=n//k\r\nc+=(n-1)*a;print(c)",
"n = int(input())\nk = int(input())\nA = int(input())\nB = int(input())\n\ncost = 0\nif k == 1:\n print((n - 1) * A)\nelse:\n while n != 0:\n q, r = divmod(n, k)\n cost += r * A\n n -= r\n cost += min((n - q) * A, B)\n n = q\n print(cost-A)\n",
"n, k, a, b = [int(input()) for i in range(4)]\nr = 0\nif k - 1:\n while n:\n m, t = divmod(n, k)\n r += t * a\n n -= t\n r += min(b, (n - m) * a)\n n = m\nelse:\n r += n * a\nprint(r - a)\n",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\ncoins = 0\r\nwhile (n!=1):\r\n\tif(n%k == 0 and ((n-n/k)*A) > B):\r\n\t\tcoins += B\r\n\t\tn/=k\r\n\telif (n%k == 0):\r\n\t\tcoins += A*(n-1)\r\n\t\tn = 1\r\n\telse:\r\n\t\tcoins += A*(n%k)\r\n\t\tn = n - (n%k)\r\nprint(int(coins))",
"n = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\nif k == 1:\r\n print(a * (n - 1))\r\n exit(0)\r\nres = 0\r\nwhile n > 1:\r\n if n % k == 0:\r\n res += min(a * (n - n // k), b)\r\n n = n // k\r\n else:\r\n res += a * (n % k if n > k else n - 1)\r\n n = n // k * k\r\nprint(res)",
"def cryingoutloud(n, k, a, b):\r\n \r\n c = 0\r\n ca = (n-1)*a\r\n \r\n while k>1 and n > 1: \r\n if n%k == 0:\r\n n = n//k\r\n c = c + b\r\n else:\r\n c = c + a*(n%k)\r\n m = n%k\r\n n = n - m \r\n \r\n if n!=1:\r\n c = c + a*(n-1) \r\n \r\n return min(c, ca)\r\n \r\n \r\ndef Tanyacryingoutloud(n, k, A, B):\r\n \r\n if k==1:\r\n n = n - 1\r\n return n*A\r\n\r\n cnt=0\r\n while n>1:\r\n if n<k:\r\n x=n-1\r\n cnt+=(x*A)\r\n break\r\n r=n%k\r\n if r!=0:\r\n cnt+=(A*r)\r\n n-=r\r\n else:\r\n x=n-n//k\r\n cnt+=min(B,x*A)\r\n n//=k\r\n\r\n return cnt\r\n \r\nn = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\n\r\n\r\nans = Tanyacryingoutloud(n, k, a, b) \r\n#ans = cryingoutloud(n, k, a, b)\r\nprint(ans)\r\n\r\n\r\n#1999888325\r\n#3\r\n#2\r\n#2000000000\r\n\r\n#Output\r\n#3999776648\r\n#Answer\r\n#3333258884\r\n",
"n=int(input());k=int(input());a=int(input());b=int(input())\r\ncost=0\r\nwhile True:\r\n if n%k==0:\r\n if k==1:\r\n cost=(n-1)*a\r\n break\r\n if b<=(n-(n//k))*a:\r\n cost+=b;n=(n//k)\r\n else:\r\n cost+=(n-(n//k))*a;n=(n//k)\r\n else:\r\n if n>k:\r\n cost+=(n%k)*a\r\n n=(n-(n%k))\r\n else:\r\n cost+=((n%k)*a-a)\r\n n=((n-(n%k))+1)\r\n if n==1:\r\n break\r\nprint(cost)",
"n = int(input())\nk = int(input())\na = int(input())\nb = int(input())\naux = 0\n\nif(k > 1):\n while(((n // k) * (k-1) * a) > b):\n aux += (n%k) * a + b\n n //= k\n \nprint(int((n-1) * a + aux))\n# 1536878863521\n",
"# cook your dish here\r\nn=int(input())\r\nk=int(input())\r\na=int(input())\r\nb=int(input())\r\nif k==1 or k>n:\r\n print((n-1)*a)\r\nelse:\r\n count=0\r\n while n>1:\r\n if n%k==0:\r\n s=min(b,(n-n//k)*a)\r\n n=n//k\r\n else:\r\n if n>k:\r\n s=(n%k)*a\r\n n=n-n%k\r\n else:\r\n s=(n-1)*a\r\n n=1\r\n count+=s\r\n #print(count,n)\r\n print(count)",
"x = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\nif (x < k):\r\n print(A*(x-1))\r\nelse:\r\n if (k == 1):\r\n print (A*(x-1))\r\n else :\r\n ans = 0\r\n while (x != 1):\r\n if (x % k == 0):\r\n ans += min ((x - (x//k)) * A, B)\r\n x = x // k\r\n else :\r\n if (x < k):\r\n ans += ((x % k)-1) * A;\r\n x -= ((x % k) - 1)\r\n else:\r\n ans += (x % k) * A;\r\n x -= (x%k)\r\n print(ans)",
"n = int(input());k = int(input());A = int(input());B = int(input());\r\nr = 0;\r\nif(k == 1):\r\n r = n * A - A\r\nwhile(n > 1 and k > 1):\r\n if(n < k):\r\n r += n * A - A;break;\r\n r += (n % k) * A;\r\n n -= n % k;\r\n r += min((n - n // k) * A , B)\r\n n = n // k\r\nprint(r)\r\n",
"n = int(input())\r\nk = int(input())\r\na = int(input())\r\nb = int(input())\r\nanw = 0\r\n\r\nif k == 1:\r\n print(a*(n-1))\r\n exit(0)\r\n\r\nwhile n > 1:\r\n if n%k != 0:\r\n if n<k:\r\n n -= 1\r\n anw += a*(n%k)\r\n n -= n%k\r\n \r\n else:\r\n toMinus = (n-n//k)*a\r\n anw += min(toMinus, b)\r\n n //= k\r\n \r\nprint(anw)",
"n=int(input())\r\nk=int(input())\r\na=int(input())\r\nb=int(input())\r\ncost=0\r\nwhile(n>1):\r\n cost+=(n%k)*a\r\n n-=(n%k)\r\n if((n-n//k)*a<b):\r\n cost+=(n-1)*a\r\n break\r\n else:\r\n n = n//k\r\n cost+=b\r\nprint(cost)",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\n\r\nif k == 1:\r\n print((n-1)*A)\r\nelse:\r\n ct = 0\r\n while n >= k:\r\n q = n%k\r\n n -= q\r\n ct += q*A\r\n \r\n tg = n//k\r\n ct += min(B, (n-tg)*A)\r\n n = tg\r\n \r\n ct += (n-1)*A\r\n \r\n print(ct)",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\n\r\ncost = 0\r\n\r\nif k != 1:\r\n while n != 1:\r\n #print(n) \r\n if n // k > 0:\r\n cost += (n - n // k * k) * A\r\n #print('\\t' + str(cost)) \r\n n = n // k * k\r\n if (n - n // k) * A < B:\r\n break\r\n #print('dividing ' + str(n) + ' by ' + str(k) + ' to get ' + str(n // k) + ' and total cost ' + str(cost + B)) \r\n n = n // k\r\n cost += B\r\n else:\r\n break\r\n\r\ncost += (n - 1)*A\r\n\r\nprint(cost)\r\n\r\n",
"ans=0\nn=input()\nk=input()\na=input()\nb=input()\nn=int(n)\nk=int(k)\na=int(a)\nb=int(b)\nif k==1:\n print((n-1)*a)\n exit(0)\nwhile n>1:\n if n<k:\n ans+=(n-1)*a\n n=1\n break\n t=int(n/k)\n if(n%k):\n r=n-t*k\n ans+=min(r*a+b,(n-t)*a)\n else:\n ans+=min((n-t)*a,b)\n n=int(n/k)\nprint(ans)",
"n = int(input())\r\nk= int(input())\r\na=int(input())\r\nb=int(input())\r\nif(k==1):\r\n print((n-1)*a)\r\nelse:\r\n cost=0\r\n while(n>1):\r\n if(n%k==0):\r\n if(((n- (n/k))*a) > b):\r\n cost += b\r\n n/=k\r\n else:\r\n cost += (n-1)*a;\r\n n=1\r\n else:\r\n cost += (n%k)*a\r\n n = n-(n%k)\r\n print(int(cost - (abs(n-1)*a)))\r\n\r\n \r\n",
"n,k,a,b=int(input()),int(input()),int(input()),int(input())\r\nans=0\r\nx=n\r\nif k==1:\r\n print( (x-1)*a )\r\n exit(0)\r\nwhile x>1:\r\n if x<k:\r\n ans+=(x-1)*a\r\n break\r\n if x==k:\r\n ans+=min(b,(x-1)*a)\r\n break\r\n tmp=x%k\r\n x-=tmp\r\n ans+=tmp*a\r\n if x%k==0:\r\n ans+=min(b,(x-x/k)*a)\r\n x=x/k\r\nprint(int(ans))\r\n",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\nans = 0\r\n\r\nif k==1:\r\n print((n-1)*A)\r\n exit()\r\n\r\nwhile n>1:\r\n if n%k!=0:\r\n if n<k:\r\n ans += (n-1)*A\r\n n = 1\r\n else:\r\n ans += (n-n//k*k)*A\r\n n = n//k*k\r\n else:\r\n ans += min((n-n//k)*A, B)\r\n n //= k\r\n\r\nprint(ans)\r\n",
"n = int(input())\nk = int(input())\nA = int(input())\nB = int(input())\n\nkapa = 0\n\nif k == 1:\n print((n - 1) * A)\nelse:\n while n != 1:\n if n < k:\n kapa += (n - 1) * A\n n = 1\n elif n % k == 0:\n kapa += min(B, (n - (n // k)) * A)\n n //= k\n else:\n kapa += A * (n - (n // k) * k)\n n = (n // k) * k\n\n if n == 0:\n kapa += 1\n print(kapa)\n",
"copys=int(input())\r\nk=int(input())\r\nA=int(input())\r\nB=int(input())\r\ntime=0\r\nwhile copys!=1:\r\n b=copys%k\r\n if b!=0 and copys >= k and k!=1:\r\n time+=A*b\r\n copys-=b\r\n elif b==copys or k==1:\r\n time+=A*(copys-1)\r\n copys=1\r\n break\r\n elif b==0 and B>=A*(copys-copys//k) and k!=1:\r\n time += A * (copys - copys // k)\r\n copys //= k\r\n if copys!=1 and b==0 and B<A*(copys-copys//k) and k!=1:\r\n time+=B\r\n copys //= k\r\nprint(time)",
"n, k, A, B = int(input()), int(input()), int(input()), int(input())\r\ns = 0\r\nif k==1: print((n-1)*A)\r\nelse:\r\n while (((n//k)*(k-1)*A)>B):\r\n s+=(n%k)*A+B\r\n n//=k\r\n print(s+(n-1)*A)\r\n",
"n=int(input())\r\nk=int(input())\r\na=int(input())\r\nb=int(input())\r\ns=0\r\nif k>1:\r\n while (n//k)*(k-1)*a>b:\r\n s+=(n%k)*a+b\r\n n//=k\r\nprint(s+(n-1)*a)",
"n = int(input())\nk = int(input())\n\nA = int(input())\nB = int(input())\n\nc = 0\nif k > 1:\n while (n // k) * k > (B / A) * k / (k - 1):\n c += (n % k) * A + B\n n = n // k\n\nc += (n - 1) * A\nprint(c)\n\n",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\nzen = 0\r\nif k == 1:\r\n print(A * (n - 1))\r\n exit(0)\r\nwhile n >= k:\r\n zen += ((n % k) * A)\r\n n -= (n % k)\r\n if B <= (n - (n // k)) * A:\r\n zen += B\r\n n //= k\r\n else:\r\n zen += (n - (n // k)) * A\r\n n //= k\r\nzen += A * (n - 1)\r\nprint(zen)",
"n=int(input())\r\nk=int(input())\r\na=int(input())\r\nb=int(input())\r\n\r\ndef func(n,k,a,b):\r\n #print(n)\r\n if(n==1):\r\n return 0\r\n if(k==1):\r\n return (a*(n-1))\r\n if(n<k):\r\n #print((n-1)*a)\r\n return ((n-1)*a)\r\n \r\n elif(n%k!=0):\r\n #print((n%k)*a)\r\n return (((n%k)*a)+func(n-(n%k),k,a,b))\r\n \r\n else:\r\n #print(min((n-(n//k))*a,b))\r\n return (min((n-(n//k))*a,b)+func((n//k),k,a,b))\r\n \r\n \r\n \r\nprint(func(n,k,a,b))",
"#Complexity - O(n)\nn = int(input())\nk = int(input())\na = int(input())\nb = int(input())\nif k == 1:\n print((n-1)*a)\n exit(0)\ncost = 0\nwhile n > k:\n rem = n % k\n cost += rem*a\n n -= rem\n cost_a = (n - (n // k))*a\n n = n//k\n cost += min(cost_a, b)\nif n == k:\n cost += min((n-1)*a, b)\nelse:\n cost += (n-1)*a\nprint(cost)\n",
"n=int(input())\nk=int(input())\na=int(input())\nb=int(input())\nif k==1:\n print(a*(n-1))\nelse:\n y=0\n ans=a*(n-1)\n while n>1:\n x=int(n/k)\n y+=a*(n-x*k)+b\n n=x\n ans=min(ans,y+a*(n-1))\n print(ans)\n\n\t \t \t \t\t \t\t\t \t\t\t \t\t\t \t",
"n=int(input())\nk=int(input())\na=int(input())\nb=int(input())\ns=0\nif k==1:\n print((n-1)*a)\nelif n<k:\n print((n-1)*a)\nelse:\n while n!=1:\n if n<k:\n s+=(n-1)*a\n n=1\n elif n%k!=0:\n p=n%k\n s+=p*a\n n-=p\n else:\n p=n/k\n if b<(n-p)*a:\n s+=b\n else:\n s+=(n-p)*a\n n/=k\n print(int(s))\n\n\n",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\n\r\nans = 0\r\nwhile n >= k:\r\n a = n % k\r\n n -= a\r\n ans += a * A\r\n if A * (n - (n // k)) <= B:\r\n break\r\n ans += B\r\n n = n // k\r\n \r\nprint(ans + (n-1)*A)\r\n",
"def main():\r\n n = int(input())\r\n k = int(input())\r\n A = int(input())\r\n B = int(input())\r\n\r\n cost = 0\r\n\r\n if k == 1:\r\n print((n - 1) * A)\r\n exit(0)\r\n\r\n if n == 1:\r\n print(0)\r\n exit(0)\r\n\r\n while n > 1:\r\n if n % k != 0:\r\n mul = n - k * (n // k)\r\n cost += A * mul\r\n n -= mul\r\n else:\r\n subCost = A * (n - n // k)\r\n cost += min(subCost, B)\r\n n //= k\r\n\r\n if n == 0:\r\n cost -= A\r\n\r\n print(cost)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"def tanya(n, k, a, b):\r\n if k == 1:\r\n return (n - 1) * a\r\n s = 0\r\n while n > 1:\r\n if n % k != 0 and n < k:\r\n s += a * (n - 1)\r\n n -= n - 1\r\n elif n % k != 0:\r\n s += (a * (n % k))\r\n n -= n % k\r\n elif n % k == 0:\r\n s += min(b, (n - (n // k)) * a)\r\n n = n // k\r\n return s\r\n\r\n\r\nN = int(input())\r\nK = int(input())\r\nA = int(input())\r\nB = int(input())\r\nprint(tanya(N, K, A, B))\r\n",
"n=int(input())\nk=int(input())\na=int(input())\nb=int(input())\nsum=0\nwhile(n!=1):\n\tif(k>1):\n\t\tif(n%k==0):\n\t\t\tf=n//k\n\t\t\th=n-f\n\t\t\tn=f\n\t\t\tsum+=min(h*a,b)\n\t\telse:\n\t\t\tif(n>k):\n\t\t\t\tsum+=a*(n%k)\n\t\t\t\tn=n-n%k\n\t\t\telse:\n\t\t\t\tsum+=a*(n-1)\n\t\t\t\tn=1\n\telse:\n\t\tsum+=(n-1)*a\n\t\tn=1\nprint(sum)",
"n=int(input())\r\nk=int(input())\r\na=int(input())\r\nb=int(input())\r\ntotal=0\r\nif n==1:\r\n print(0)\r\n exit()\r\nif k==1:\r\n print((n-1)*a)\r\n exit()\r\nwhile n>1:\r\n if n<k:\r\n print(total+(n-1)*a)\r\n exit()\r\n if n%k!=0:\r\n total+=(n%k)*a\r\n n-=n%k\r\n else:\r\n if ((n-n//k)*a)<=b:\r\n total+=(n-1)*a\r\n print(total)\r\n exit()\r\n else:\r\n n//=k\r\n total+=b\r\nprint(total)",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\ns = 0\r\nwhile n!=1:\r\n if k>n or k==1:\r\n s+= A*(n-1)\r\n break\r\n if n%k!=0:\r\n s+= (A*(n%k))\r\n n = n-(n%k)\r\n else:\r\n nxt = n//k\r\n if (n-nxt)*A<B:\r\n s+=(n-nxt)*A\r\n else:\r\n s+= B\r\n n = nxt\r\nprint(int(s))",
"x=int(input())\nk=int(input())\na=int(input())\nb=int(input())\ncost=0\nav_a=0\nav_b=0\n\nif a==0: \n \n cost=0\n \nelif k==1:\n \n cost=(x-1)*a\n \n\nelse: \n while x >1:\n if x%k!=0:## bu neng zheng chu\n if x>k:\n w=x%k ##w is yushu\n x=x-w\n cost=cost+(w)*a\n else: \n cost=cost+(x-1)*a\n x=1\n \n elif x%k==0:\n av_a=a\n av_b=b/(x-x/k)\n if av_a>=av_b:\n x=x/k\n cost=cost+b\n elif av_a<av_b:\n cost=cost+a*(x-x/k)\n x=x/k\n \nprint('%d'%(cost))",
"\r\ndef solve():\r\n\tn = int(input())\r\n\tk = int(input())\r\n\tA = int(input())\r\n\tB = int(input())\r\n\t\r\n\tscore = 0\r\n\twhile n > 1:\r\n\t\tif n % k == 0:\r\n\t\t\tif B < (n - n//k) * A:\r\n\t\t\t\tn //= k\r\n\t\t\t\tscore += B\r\n\t\t\telse:\r\n\t\t\t\tscore += (n-1) * A\r\n\t\t\t\treturn score\r\n\r\n\t\telse:\r\n\t\t\tscore += n % k * A\r\n\t\t\tn -= n % k\r\n\tif n == 0:\r\n\t\treturn score - A\r\n\treturn score\r\n\r\nprint(solve())\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Feb 27 16:49:50 2018\r\n\r\n@author: mbinkowski\r\n\"\"\"\r\n\r\nn = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\n\r\nx = n\r\ncost = 0\r\nworth_div = True\r\nwhile x > 1:\r\n# print('x, cost', x, cost)\r\n if (x % k == 0) and worth_div:\r\n worth_div = ((x - int(x/k)) * A > B)\r\n if worth_div:\r\n cost += B\r\n x = int(x/k)\r\n else:\r\n cost += A * (x - 1)\r\n x = 1\r\n elif (x % k == 0) or (x < k):\r\n cost += A * (x - 1)\r\n x = 1\r\n else:\r\n cost += (x % k) * A \r\n x -= (x % k)\r\nprint(cost)",
"n = int(input())\r\nk = int(input())\r\nA = int(input())\r\nB = int(input())\r\nx = n\r\nans = 0\r\nif k > 1:\r\n while x > 1:\r\n if x % k == 0:\r\n if A * (x - x // k) < B:\r\n ans += A * (x - x // k)\r\n else:\r\n ans += B\r\n x //= k\r\n else:\r\n if x < k:\r\n ans += A * (x - 1)\r\n x = 1\r\n else:\r\n ans += A * (x % k)\r\n x -= x % k\r\nelse:\r\n ans = A * (x - 1)\r\nprint(ans)",
"import sys\nn = int(input())\nk = int(input())\nA = int(input())\nB = int(input())\n\nx = n\ncst = 0\n\nif k==1:\n\tprint((x-1)*A)\n\tsys.exit(0)\n\nwhile x!=1:\n\tif x%k == 0:\n\t\tcst += min( (x-x//k) * A , B)\n\t\tx = x//k\n\telse:\n\t\tif x < k:\n\t\t\tcst += (x-1) * A\n\t\t\tx = 1\n\t\telse:\n\t\t\tcst += (x%k) * A\n\t\t\tx -= (x%k)\n\nprint(cst)\n\t\t\n"
] | {"inputs": ["9\n2\n3\n1", "5\n5\n2\n20", "19\n3\n4\n2", "1845999546\n999435865\n1234234\n2323423", "1604353664\n1604353665\n9993432\n1", "777888456\n1\n98\n43", "1162261467\n3\n1\n2000000000", "1000000000\n1999999999\n789987\n184569875", "2000000000\n2\n1\n2000000000", "1999888325\n3\n2\n2000000000", "1897546487\n687\n89798979\n879876541", "20\n1\n20\n1", "16\n5\n17\n3", "19\n19\n19\n1", "18\n2\n3\n16", "1\n11\n8\n9", "9\n10\n1\n20", "19\n10\n19\n2", "16\n9\n14\n2", "15\n2\n5\n2", "14\n7\n13\n1", "43\n3\n45\n3", "99\n1\n98\n1", "77\n93\n100\n77", "81\n3\n91\n95", "78\n53\n87\n34", "80\n3\n15\n1", "97\n24\n4\n24", "100\n100\n1\n100", "87\n4\n17\n7", "65\n2\n3\n6", "1000000\n1435\n3\n999999", "783464\n483464\n2\n966928", "248035\n11\n3\n20", "524287\n2\n945658\n999756", "947352\n78946\n85\n789654", "1000000\n1\n999899\n60", "753687\n977456\n6547\n456", "1000000\n500000\n1\n999997", "997458\n843596\n1\n843596", "821109\n92\n6547\n98787", "1073741823\n2\n9543\n8923453", "1000999777\n1934999345\n2356346\n34534565", "2000000000\n1\n2000000000\n98", "1999324353\n978435356\n1\n978435356", "2000000000\n2\n2000000000\n2000000000", "241375690\n17\n2\n1998789654", "171507000\n350\n789\n6548687", "1100220011\n10001\n2\n1999778654", "1867622656\n43216\n789644\n12315468", "1867622656\n43216\n1\n1879865413", "1999999999\n1000000000\n789987\n184569875", "1987987897\n103546\n7\n98754563", "10\n2\n2\n5", "7\n2\n1\n100000", "7\n2\n3\n1", "2000000000\n666666667\n1\n1", "1999999997\n666666666\n2\n2"], "outputs": ["6", "8", "12", "1044857680578777", "16032999235141416", "76233068590", "1162261466", "789986999210013", "1999999999", "3333258884", "110398404423", "380", "54", "1", "40", "0", "8", "173", "100", "21", "14", "189", "9604", "7600", "380", "2209", "108", "40", "99", "106", "36", "1005804", "1566926", "202", "34963354", "790589", "999898000101", "4934382242", "999998", "997457", "394566", "188412866", "2358701818178496", "3999999998000000000", "1020888998", "84000000000", "482751378", "14216965", "1999998674", "24630936", "1867622655", "789987183779888", "98946650", "13", "6", "8", "666666668", "1333333334"]} | UNKNOWN | PYTHON3 | CODEFORCES | 69 | |
2dfa063f0f70a652c3e61aa500d3bd6d | none | One day in the IT lesson Anna and Maria learned about the lexicographic order.
String *x* is lexicographically less than string *y*, if either *x* is a prefix of *y* (and *x*<=≠<=*y*), or there exists such *i* (1<=≤<=*i*<=≤<=*min*(|*x*|,<=|*y*|)), that *x**i*<=<<=*y**i*, and for any *j* (1<=≤<=*j*<=<<=*i*) *x**j*<==<=*y**j*. Here |*a*| denotes the length of the string *a*. The lexicographic comparison of strings is implemented by operator < in modern programming languages.
The teacher gave Anna and Maria homework. She gave them a string of length *n*. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the *k*-th string from the list. Help Anna and Maria do the homework.
The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer *k* (1<=≤<=*k*<=≤<=105).
Print the string Anna and Maria need — the *k*-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than *k*, print a string saying "No such line." (without the quotes).
Sample Input
aa
2
abc
5
abab
7
Sample Output
a
bc
b
| [
"from heapq import *\n \nl=input()\nkill=int(input())\nn=len(l) \nif kill>n*(n+1)/2: \n print(\"No such line.\") \n quit()\nss=[(l[i],i) for i in range(n)]\nheapify(ss)\nwhile kill:\n kill-=1\n t=heappop(ss)\n if kill==0:\n print(t[0])\n else: \n if t[1]<n-1:\n heappush(ss,(t[0]+l[t[1]+1],t[1]+1))\n \t \t\t \t\t\t \t \t\t \t \t \t\t\t \t\n \t\t\t \t \t \t\t\t \t \t\t \t \t",
"from collections import defaultdict\r\n\r\ndef solve():\r\n ss = list(input())\r\n k = int(input())\r\n n = len(ss)\r\n\r\n if n*(n+1)//2 < k:\r\n print (\"No such line.\")\r\n return\r\n\r\n kiss = defaultdict(int)\r\n\r\n for i,s in enumerate( ss ):\r\n kiss[s] += n-i\r\n\r\n alpha = 'abcdefghijklmnopqrstuvwxyz'\r\n\r\n\r\n ans = \"\"\r\n\r\n pos = [ i for i in range(n) ]\r\n\r\n while True:\r\n\r\n cur = \"\"\r\n for a in alpha:\r\n\r\n if kiss[a] >= k:\r\n cur = a\r\n break\r\n else:\r\n k -= kiss[a]\r\n # print(kiss['c']) \r\n ans += cur\r\n\r\n pos = [ i for i in pos if ss[i] == cur ]\r\n\r\n #single character \r\n\r\n if len(pos) >= k:\r\n # print(\"brok here\", pos , k)\r\n break\r\n\r\n k -= len(pos)\r\n\r\n # get the next elements\r\n\r\n for a in alpha:\r\n kiss[a] = 0\r\n\r\n nchar = [ (ss[i+1] , i+1) for i in pos if i+1 < n ]\r\n\r\n # print(pos , nchar)\r\n\r\n pos = []\r\n for c,i in nchar:\r\n kiss[c] += n-i\r\n pos.append(i)\r\n\r\n\r\n print(ans)\r\n \r\n \r\nsolve()",
"import heapq as hq\r\ns = input()\r\nk = int(input())\r\n\r\nn = len(s)\r\nnews = [([s[i]], i + 1) for i in range(n)]\r\nif k > n * (n + 1) // 2:\r\n print('No such line.')\r\n exit() \r\nhq.heapify(news)\r\n\r\nfor i in range(k):\r\n t, nxt = hq.heappop(news)\r\n if nxt < n and i + 1 < k:\r\n t.append(s[nxt])\r\n hq.heappush(news, (t, nxt + 1))\r\n\r\nprint(''.join(t))",
"from heapq import *\r\ns=input()\r\nk=int(input())\r\nn=len(s)\r\nss=[(s[i],i) for i in range(n)]\r\nheapify(ss)\r\nif k>n*(n+1)/2:\r\n print('No such line.')\r\nelse:\r\n while k:\r\n k-=1\r\n t=heappop(ss)\r\n if k==0:\r\n print(t[0])\r\n else:\r\n if t[1]<len(s)-1:\r\n heappush(ss,(t[0]+s[t[1]+1],t[1]+1))",
"def get_input():\r\n s = input()\r\n l = len(s)\r\n k = int(input())\r\n return s, l, k\r\n\r\ndef find_kth_sum(s, l, k):\r\n if l * (l + 1) / 2 < k:\r\n return 'No such line.'\r\n \r\n a = [i for i in range(l)]\r\n p = 0\r\n ans = ''\r\n \r\n while True:\r\n t = [(s[i + p], i) for i in a]\r\n t = sorted(t)\r\n i = j = 0\r\n prod = 0\r\n \r\n while i < len(t):\r\n pre = prod\r\n while j < len(t) and t[i][0] == t[j][0]:\r\n prod += l - t[j][1] - p\r\n j += 1\r\n if prod >= k:\r\n break\r\n i = j\r\n \r\n ans += t[i][0]\r\n if pre + j - i >= k:\r\n break\r\n k -= pre + j - i\r\n p += 1\r\n a = [t[q][1] for q in range(i, j) if t[q][1] + p < l]\r\n \r\n return ans\r\n\r\ndef main():\r\n s, l, k = get_input()\r\n result = find_kth_sum(s, l, k)\r\n print(result)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"import heapq\r\ns,k=input(),int(input())\r\np=len(s)\r\nl=[]\r\nif k>(p+1)*p//2:\r\n print(\"No such line.\")\r\nelse: \r\n for i in range(p):\r\n heapq.heappush(l,[s[i],i+1])\r\n for i in range(k):\r\n a,b=heapq.heappop(l)\r\n if b<p:\r\n heapq.heappush(l,[a+s[b],b+1])\r\n print(a)",
"#128B:String\n\ns=input()\nl=len(s)\nk=int(input())\nif l*(l+1)/2<k: print('No such line.')\nelse:\n\ta=[i for i in range(l)]\n\tp=0\n\tans=''\n\twhile True:\n\t\tt=[(s[i+p],i) for i in a]\n\t\tt=sorted(t)\n\t\ti=j=0\n\t\tprod=0\n\t\twhile i<len(t):\n\t\t\tpre=prod\n\t\t\twhile j<len(t) and t[i][0]==t[j][0]:\n\t\t\t\tprod+=l-t[j][1]-p\n\t\t\t\tj+=1\n\t\t\tif prod>=k: break\n\t\t\ti=j\n\t\tans+=t[i][0]\n\t\tif pre+j-i>=k: break\n\t\tk-=pre+j-i\n\t\tp+=1\n\t\ta=[t[q][1] for q in range(i,j) if t[q][1]+p<l]\n\tprint(ans)\n",
"import heapq\ns = input()\nl = len(s)\nk = int(input())\nif l * (l+1) / 2 < k:\n\tprint('No such line.')\nelse:\n\tind = [i for i in range(l)]\n\tpos = 0\n\tans = ''\n\twhile True:\n\t\tt = [(s[i + pos], i) for i in ind]\n\t\tt = sorted(t)\n\t\ti = j = 0\n\t\tprod = 0\n\t\twhile i < len(t):\n\t\t\tpre = prod\n\t\t\twhile j < len(t) and t[i][0] == t[j][0]:\n\t\t\t\tprod += l - t[j][1] - pos\n\t\t\t\tj += 1\n\t\t\tif prod >= k:\n\t\t\t\tbreak\n\t\t\ti = j\n\t\tans += t[i][0]\n\t\tif pre + j - i >= k:\n\t\t\tbreak\n\t\tk -= pre + j - i\n\t\tpos += 1\n\t\tind = [t[q][1] for q in range(i, j) if t[q][1] + pos < l]\n\tprint(ans)\n",
"import heapq\r\ns = str(input())\r\nk = int(input())\r\n\r\nn = len(s)\r\nl = []\r\nif k>(n*(n+1))//2:\r\n print('No such line.')\r\nelse:\r\n for i in range(n):\r\n heapq.heappush(l,(s[i],i+1))\r\n while k>0:\r\n k -= 1\r\n x,y = heapq.heappop(l)\r\n if y<n:\r\n heapq.heappush(l,(x+s[y],y+1))\r\n\r\n print(x)",
"from heapq import *\n\nstring = input()\nk = int(input())\nn = len(string)\n\nif k > n * (n + 1) / 2:\n print(\"No such line.\")\n quit()\n\nheap = []\n\n\nfor i in range(n):\n heap.append((string[i], 1, i))\n\nheapify(heap)\n\nfor _ in range(k):\n val, length, start_index = heappop(heap)\n\n if _ == k - 1:\n print(val)\n break\n\n if start_index + length < n:\n heappush(heap, (val + string[start_index + length], length + 1, start_index))\n \t \t\t\t \t \t\t \t\t \t \t\t \t \t\t\t",
"import heapq\r\n\r\ns = input()\r\nk = int(input())\r\nN = len(s)\r\n\r\nif k > N * (N + 1) // 2:\r\n print('No such line.')\r\n exit()\r\n\r\nA = [(c, j) for j, c in enumerate(list(s))]\r\nheapq.heapify(A)\r\n\r\nfor i in range(k):\r\n if not A:\r\n break\r\n min_item, index = heapq.heappop(A)\r\n if index + 1 < N:\r\n heapq.heappush(A, (min_item + s[index + 1], index + 1))\r\nprint(min_item)"
] | {"inputs": ["aa\n2", "abc\n5", "abab\n7", "codeforces\n1", "cccc\n8", "abcdefghijklmnopqrstuvwxyz\n27", "cba\n6", "z\n100000", "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n17416", "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n32912", "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n84480", "llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll\n83252", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n18883", "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n14594", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n87315", "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n27016", "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n9184", "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n99590", "aaaaaaaaaa\n90"], "outputs": ["a", "bc", "b", "c", "ccc", "b", "cba", "No such line.", "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu", "No such line.", "No such line.", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", "No such line.", "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", "ssssssssssssssssssssssssssss", "No such line.", "No such line."]} | UNKNOWN | PYTHON3 | CODEFORCES | 11 | |
2dfeeee0e26e0696e414b354a207adb8 | Polycarp's Pockets | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.
Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Sample Input
6
1 2 4 3 3 2
1
100
Sample Output
2
1
| [
"n= int(input())\r\na= list(map(int, input().split()))\r\n\r\nx= [a.count(i) for i in a]\r\nx.sort()\r\nprint(x[n-1])",
"n= int(input())\r\narr = list(map(int, input().split()))\r\na = []\r\nfor i in arr:\r\n a.append(arr.count(i))\r\nprint(max(a))",
"n = int(input())\r\na=[int(d) for d in input().split()]\r\nmax=0\r\nfor i in range(n):\r\n if a.count(a[i])>max:\r\n max=a.count(a[i])\r\nprint(max)",
"n = int(input())\r\nl = [0] * 101\r\ns = [int(i) for i in input().split()]\r\nfor i in s:\r\n l[i] += 1\r\nprint(max(l))",
"from collections import Counter\r\ninput()\r\nprint(max(Counter(list(map(int, input().split()))).values()))\r\n",
"import collections\n\nn = int(input())\nc = collections.Counter(int(x) for x in input().split())\nprint(max(c.values()))",
"n=int(input())\r\nl=input().split()\r\nli=[int(i) for i in l]\r\nmaxa=0\r\nhashi=dict()\r\nfor i in li:\r\n if i in hashi:\r\n hashi[i]+=1\r\n else:\r\n hashi[i]=1\r\nfor i in hashi:\r\n maxa=max(maxa,hashi[i])\r\nprint(maxa)\r\n",
"a = int(input())\r\nk = input().split()\r\no = 0\r\nfor n in range(a):\r\n j = k.count((k[n]))\r\n if o < j:\r\n o = j\r\nprint(o)",
"n = input()\r\narr = list(map(int,input().split()))\r\nnew_arr = list(set(arr))\r\nmaxx = 0\r\nfor i in new_arr:\r\n ans = arr.count(i)\r\n if ans>=maxx:\r\n maxx = ans\r\nprint(maxx)\r\n",
"import collections\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nC = collections.Counter(a).most_common()\r\nprint(C[0][1])\r\n",
"input()\r\nt = input().split()\r\nprint (max(t.count(x) for x in t))",
"n=int(input())\r\na=[int(_) for _ in input().split()]\r\nmax=0\r\nfor ele in set(a):\r\n\tif a.count(ele)>max:\r\n\t\tmax=a.count(ele)\r\nprint(max)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nc = {}\r\nfor i in a:\r\n if i in c:\r\n c[i] += 1\r\n else:\r\n c[i] = 1\r\nm = max(c.values())\r\nprint(m)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nres=list(set(l))\r\nans=0\r\nfor i in res:\r\n ans=max(ans,l.count(i))\r\nprint(ans)\r\n\r\n \r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = max(a, key=a.count)\r\nc = a.count(b)\r\nprint(min(n,c))",
"n = int(input())\r\nlists = list(map(int, input().split()))\r\nsets= set(lists)\r\nmaks=0\r\nfor i in range (n):\r\n sk = lists.count(lists[i])\r\n if sk > maks:\r\n maks=sk\r\n\r\nprint(maks)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nfrom collections import Counter\r\ndic=Counter(l)\r\nprint(max(dic.values()))",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nmaxi=0\r\nfor i in a:\r\n if maxi<a.count(i):\r\n maxi=a.count(i)\r\nprint(maxi)",
"'''\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nC#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n'''\nn=int(input())\na=list(map(int,input().split()))\nc=list(map(a.count,a)) \nprint (max(c))",
"T_ON = 0\r\nDEBUG_ON = 0\r\nMOD = 998244353\r\n\r\n\r\ndef solve():\r\n n = read_int()\r\n A = read_ints()\r\n C = Counter(A)\r\n print(max(C.values()))\r\n\r\n\r\ndef main():\r\n T = read_int() if T_ON else 1\r\n for i in range(T):\r\n solve()\r\n\r\n\r\ndef debug(*xargs):\r\n if DEBUG_ON:\r\n print(*xargs)\r\n\r\n\r\nfrom collections import *\r\nimport math\r\n\r\n\r\n#---------------------------------FAST_IO---------------------------------------\r\n\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n# region fastio\r\n\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n#----------------------------------IO_WRAP--------------------------------------\r\n\r\ndef read_int():\r\n return int(input())\r\n\r\n\r\ndef read_ints():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef print_nums(nums):\r\n print(\" \".join(map(str, nums)))\r\n\r\n\r\ndef YES():\r\n print(\"YES\")\r\n\r\n\r\ndef Yes():\r\n print(\"Yes\")\r\n\r\n\r\ndef NO():\r\n print(\"NO\")\r\n\r\n\r\ndef No():\r\n print(\"No\")\r\n\r\n#----------------------------------FIB--------------------------------------\r\n\r\ndef fib(n):\r\n a, b = 0, 1\r\n for _ in range(n):\r\n a, b = b, a + b\r\n return a\r\n\r\n\r\ndef fib_ns(n):\r\n assert n >= 1\r\n f = [0 for _ in range(n + 1)]\r\n f[0] = 0\r\n f[1] = 1\r\n for i in range(2, n + 1):\r\n f[i] = f[i - 1] + f[i - 2]\r\n return f\r\n\r\n#----------------------------------MOD--------------------------------------\r\n\r\ndef gcd(a, b):\r\n if a == 0:\r\n return b\r\n return gcd(b % a, a)\r\n\r\n\r\ndef xgcd(a, b):\r\n \"\"\"return (g, x, y) such that a*x + b*y = g = gcd(a, b)\"\"\"\r\n x0, x1, y0, y1 = 0, 1, 1, 0\r\n while a != 0:\r\n (q, a), b = divmod(b, a), a\r\n y0, y1 = y1, y0 - q * y1\r\n x0, x1 = x1, x0 - q * x1\r\n return b, x0, y0\r\n\r\n\r\ndef modinv(a, m):\r\n \"\"\"return x such that (a * x) % m == 1\"\"\"\r\n g, x, _ = xgcd(a, m)\r\n if g != 1:\r\n raise Exception('gcd(a, m) != 1')\r\n return x % m\r\n\r\n\r\ndef mod_add(x, y):\r\n x += y\r\n while x >= MOD:\r\n x -= MOD\r\n while x < 0:\r\n x += MOD\r\n return x\r\n\r\n\r\ndef mod_mul(x, y):\r\n return (x * y) % MOD\r\n\r\n\r\ndef mod_pow(x, y):\r\n if y == 0:\r\n return 1\r\n if y % 2:\r\n return mod_mul(x, mod_pow(x, y - 1))\r\n p = mod_pow(x, y // 2)\r\n return mod_mul(p, p)\r\n\r\n\r\ndef mod_inv(y):\r\n return mod_pow(y, MOD - 2)\r\n\r\n\r\ndef mod_div(x, y):\r\n # y^(-1): Fermat little theorem, MOD is a prime\r\n return mod_mul(x, mod_inv(y))\r\n\r\n#---------------------------------PRIME---------------------------------------\r\n\r\ndef is_prime(n):\r\n if n == 1:\r\n return False\r\n for i in range(2, int(n ** 0.5) + 1):\r\n if n % i:\r\n return False\r\n return True\r\n\r\n\r\ndef gen_primes(n):\r\n \"\"\"\r\n generate primes of [1..n] using sieve's method\r\n \"\"\"\r\n P = [True for _ in range(n + 1)]\r\n P[0] = P[1] = False\r\n for i in range(int(n ** 0.5) + 1):\r\n if P[i]:\r\n for j in range(2 * i, n + 1, i):\r\n P[j] = False\r\n return P\r\n\r\n#---------------------------------MAIN---------------------------------------\r\n\r\nmain()\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nd={}\r\nfor i in l:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i]=1\r\nans=1\r\nfor i in d:\r\n ans=max(ans,d[i])\r\nprint(ans)",
"count_time=False\r\nif count_time:\r\n import time\r\n start_time = time.time()\r\n#-----------------------------------------\r\nfrom collections import Counter\r\nn=int(input())\r\na=Counter(input().split())\r\nprint(max(a.values()))\r\n#------------------------------------------\r\nif count_time:\r\n end_time = time.time()\r\n print('----------------\\nRunning time: {} s'\r\n .format(end_time - start_time))\r\n",
"n = int(input())\r\na = input().split(' ')\r\nb = set(a)\r\ns = []\r\nfor i in b:\r\n s.append(a.count(i))\r\nprint(max(s))",
"u=int(input())\r\ni=map(int,input().split())\r\nlst=[]\r\no=list(i)\r\no1=set(o)\r\nfor x in o1:\r\n lst.append(o.count(x))\r\nprint(max(lst))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=[0]*101\r\nfor i in range(n):\r\n b[a[i]]+=1\r\nprint(max(b))",
"from collections import Counter\r\n\r\nn = int(input())\r\na = [int(s) for s in input().split(' ')]\r\nc = Counter(a)\r\nprint(c.most_common(1)[0][1])\r\n",
"#python 3.7\r\na=int(input())\r\nb=sorted(list(map(int, input().split())))\r\nc=[]\r\nfor i in b:\r\n c. append(b.count(i))\r\nprint(max(c))\r\n \r\n \r\n \r\n \r\n\r\n",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nmaxi=0\r\nfor i in lst:\r\n maxi=max(lst.count(i),maxi)\r\n lst=[j for j in lst if j!=i]\r\nprint(maxi)\r\n ",
"from collections import Counter\r\nn = int(input())\r\na = list(map(int, input(). split()))\r\np = Counter(a)\r\nmx = 0\r\nfor i in set(a):\r\n mx = max(p[i], mx)\r\nprint(mx)\r\n",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nunique_values = set(a)\r\nmax_elements_with_same_values = 0\r\n\r\nfor x in unique_values:\r\n if a.count(x) > max_elements_with_same_values:\r\n max_elements_with_same_values = a.count(x)\r\n\r\nprint(max_elements_with_same_values)\r\n",
"from collections import defaultdict\r\nn = int(input())\r\narr = list(map(int,input().split()))\r\nmaxm = -10**18\r\nfreq = defaultdict(int)\r\nfor ele in arr:\r\n freq[ele]+=1\r\n maxm = max(freq[ele],maxm)\r\nprint(maxm)",
"n=int(input())\r\nk=list(map(int,input().split()))\r\ns=[0]*101\r\nfor x in k:\r\n s[x]+=1\r\nprint(max(s))\r\n\r\n",
"# main >>> Version 16.0\r\ndef main() -> None:\r\n length = ii()\r\n l = li()\r\n ll = [0]*(101)\r\n for i in l: ll[i]+=1\r\n p(max(ll))\r\n\r\n\r\n\r\n\r\n \r\nif __name__ == \"__main__\":\r\n import os, sys, math, itertools, bisect; from collections import deque, defaultdict, OrderedDict, Counter\r\n ii,si = lambda : int(input()), lambda : input() \r\n mi, msi = lambda : map(int,input().strip().split(\" \")), lambda : map(str,input().strip().split(\" \")) \r\n li, lsi = lambda : list(mi()), lambda : list(msi())\r\n out, export, p, pp = [], lambda : print('\\n'.join(map(str, out))), lambda x : out.append(x), lambda array : p(' '.join(map(str,array)))\r\n try: exec('from hq import L, LT, see, info, cmdIO, _generator_ \\nline = [cmdIO(), main(), export(), _generator_()] \\nfor l in line: l')\r\n except (FileNotFoundError,ModuleNotFoundError): main(); export()",
"def solve():\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n f = dict()\r\n for i in a:\r\n try:\r\n f[i] += 1\r\n except KeyError:\r\n f[i] = 1\r\n return max(f.values())\r\nprint(solve())",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nd={}\r\nfor i in range(n):\r\n if l[i] not in d:\r\n d[l[i]]=1\r\n else:\r\n d[l[i]]+=1\r\nd=dict(sorted(d.items(),key= lambda item:item[1],reverse=True))\r\nfor i in d:\r\n print(d[i])\r\n break\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n",
"n = input()\r\nl = list(map(int,input().split()))\r\n\r\nd = {}\r\nm = []\r\ncount = 1\r\nfor i in l:\r\n\tif len(l) == 1:\r\n\t\tprint(1)\r\n\t\ts = True\r\n\t\tbreak\r\n\telif i in d:\r\n\t\td[i] += 1\r\n\t\ts = False\r\n\t\tm.append(d[i])\r\n\telse:\r\n\t\td[i] = 1\r\n\t\ts = False\r\n\t\tm.append(d[i])\r\n\r\nif s == False:\r\n\tprint(max(m))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nd={}\r\nfor i in l:\r\n d[i]=d.get(i,0)+1\r\nmi=-1000\r\nfor i in d:\r\n if d[i]>mi:\r\n mi=d[i]\r\nprint(mi)\r\n",
"sl = {}\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\nfor x in lst:\r\n if x not in sl.keys():\r\n sl[x] = 1\r\n else:\r\n sl[x] += 1\r\nprint(max(sl.values()))\r\n",
"from collections import Counter\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nc=Counter(l)\r\n\r\na=c.values()\r\nprint(max(a))\r\n",
"import math\nimport bisect\n\nfrom math import gcd, floor, sqrt, log\nfrom collections import defaultdict as dd\nfrom collections import Counter\n\nI = lambda: int(input())\ntup = lambda: map(int, input().split())\nlst = lambda: list(map(int, input().split()))\n\nt = 1\n#t = I()\n\n\nwhile t:\n\n n = I()\n arr = lst()\n\n temp = Counter(arr)\n max = max(list(temp.values()))\n print(max)\n\n\n \n t -= 1\n\n\n ",
"n = int(input());ans = 0\r\n*l, = map(int, input().split(' '))\r\n\r\nfor i in l:\r\n ans = max(l.count(i), ans)\r\n\r\nprint(ans)\r\n",
"input()\r\nli = list(map(int,input().split()))\r\nd = dict()\r\nfor e in li:\r\n\ttry:\r\n\t\td[e]+=1\r\n\texcept KeyError:\r\n\t\td[e]=1\r\nprint(sorted(d.values())[-1])",
"from collections import Counter\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nd=Counter(l)\r\nm=0\r\nfor i in d.values():\r\n if i>m:\r\n m=i\r\nprint(m)\r\n\r\n\r\n",
"n = int(input())\r\ns = list(map(int, input().split()))\r\na = {}\r\nmaxi = 0\r\nfor i in range(n):\r\n if s[i] not in a:\r\n a[s[i]] = 1\r\n else:\r\n a[s[i]] += 1\r\nfor i in a:\r\n if a[i] >= maxi:\r\n maxi = a[i]\r\nprint(maxi)",
"g = int(input())\r\np = list(map(int,input().split()))\r\np.sort()\r\n\r\n\r\nbig = 1\r\ncurrent = 1\r\n\r\n\r\nprevious = p[0]\r\np.remove(p[0])\r\nfor element in p:\r\n\r\n if element == previous:\r\n current += 1\r\n \r\n \r\n if current > big:\r\n big = current\r\n else:\r\n if current > big:\r\n big = current\r\n \r\n \r\n current = 1\r\n previous = element\r\nprint(big)\r\n \r\n",
"from collections import Counter\r\n\r\ninput()\r\na = Counter(int(x) for x in input().split()).values()\r\nprint(max(a))",
"num=int(input())\r\narr=list(map(int,input().split()))\r\nset_=set(arr)\r\nanother=[]\r\nfor i in set_:\r\n another.append(arr.count(i))\r\nprint(max(another))",
"n=int(input())\r\nl=[int(x) for x in input().split()]\r\nt=[]\r\nfor i in l:\r\n t.append(l.count(i))\r\nprint(max(t))",
"n = int(input())\r\nv = list(map(int, input().split()))\r\n\r\npockets = [[] for _ in range(n)]\r\n\r\nfor k in range(n):\r\n m = v[k]\r\n for pocket in pockets:\r\n count = pocket.count(m)\r\n if count == 0:\r\n pocket.append(m)\r\n break\r\n\r\ncount = 0\r\n\r\nfor pocket in pockets:\r\n l = len(pocket)\r\n if l > 0:\r\n count += 1\r\n\r\nprint(count)",
"import math\r\nimport collections\r\nN = int(input())\r\nA = list(map(int,input().split()))\r\nprint(max(collections.Counter(A).values()))\r\n",
"x=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nfor i in l:\r\n\ts=0\r\n\tfor j in l:\r\n\t\tif i==j:\r\n\t\t\ts+=1\r\n\tif s>c:\r\n\t\tc=s\r\nprint(c)",
"n = int(input())\r\na = list(map(int,input().split(\" \")))\r\na.sort()\r\ni = 0\r\nma = 0\r\nwhile i < n:\r\n j = i + 1\r\n while (j < n and a[j] == a[i]):\r\n j += 1\r\n ma = max(ma, j - i)\r\n i = j\r\n \r\nprint(ma)\r\n",
"a=int(input())\r\nsus=0\r\nb=[int(i) for i in input().split()]\r\nfor i in range(a):\r\n if b.count(b[i])>sus:\r\n sus=b.count(b[i])\r\n \r\nprint(sus)\r\n",
"n = int(input())\nlist = [int(x) for x in input().split()]\ncnt = {}\nans = 0\nfor i in range(n):\n if list[i] not in cnt:\n cnt[list[i]] = 1\n else:\n cnt[list[i]] += 1\n \n if ans < cnt[list[i]]:\n ans = cnt[list[i]]\nprint(ans)\n \t\t\t\t \t\t \t\t\t \t \t\t \t \t\t \t\t",
"n=int(input())\r\nl=[int(x) for x in input().split()]\r\nd={}\r\nfor i in l:\r\n d[i]=l.count(i)\r\nl2=list(d.values())\r\nl2.sort(reverse=True)\r\nprint(l2[0])",
"d={}\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\n\r\nfor i in l:\r\n\tif i not in d:\r\n\t\td[i]=1\r\n\telse:\r\n\t\td[i]+=1\r\nprint(max(d.values()))",
"from collections import Counter\r\n\r\ndef sol(n,l):\r\n d = dict(Counter(l))\r\n return max(d.values())\r\n\r\n\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nprint(sol(n, l))\r\n ",
"input()\r\nl = input().split()\r\nprint(max(l.count(x) for x in l))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n'''\r\n----------------------------------------------------------------\r\n255A - Greg's Workout\r\n\r\ninput()\r\nl = [*map(int, input().split())]\r\nprint(['chest','biceps','back'][max(0, 1, 2, key = lambda x: sum(l[x::3]))]) #trick\r\n\r\ninput()\r\nl = [*map(int, input().split())]\r\ns = sum(l[::3]), sum(l[1::3]), sum(l[2::3])\r\nif s[0] > s[1] and s[0] > s[2]:\r\n print(\"chest\")\r\n exit()\r\nprint('biceps 'if s[0] < s[1] and s[1] > s[2] else 'back')\r\n----------------------------------------------------------------\r\n1497A - Meximization\r\n\r\nfor _ in range(int(input())):\r\n input()\r\n l = list(map(int, input().split()))\r\n s = set(l)\r\n [l.remove(i) for i in s] #to review\r\n l = list(s) + l\r\n print(*l)\r\n\r\nfor _ in range(int(input())):\r\n input()\r\n l = sorted(input().split())\r\n i = 0\r\n s = []\r\n while i < len(l) - 1:\r\n if l[i] == l[i + 1]:\r\n s.append(l.pop(l.index(l[i])))\r\n i -= 1 \r\n i += 1 \r\n print(*(l+s))\r\n----------------------------------------------------------------\r\n1554A - Cherry\r\n\r\nfor _ in range(int(input())):\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n print(max(l[i] * l[i + 1] for i in range(n - 1)))\r\n----------------------------------------------------------------\r\n894A - QAQ\r\n\r\ns = input()\r\nsum = 0\r\nfor i in range(len(s)): \r\n if s[i] == 'A':\r\n sum += s[i:].count('Q') * s[:i].count('Q') #trick\r\nprint(sum)\r\n\r\nimport itertools\r\nprint(sum(map(lambda x:(x == (\"Q\",\"A\",\"Q\")),itertools.combinations(input(),3)))) # to review\r\n----------------------------------------------------------------\r\n1077A - Frog Jumping\r\n\r\nfor _ in range(int(input())):\r\n l = list(map(int, input().split()))\r\n print(l[0] * (l[2] // 2 + l[2] % 2) + - l[1] * (l[2] // 2))\r\n----------------------------------------------------------------\r\n1382A - Common Subsequence\r\n\r\nfor _ in range(int(input())):\r\n input()\r\n s1 = set(input().split())\r\n s2 = set(input().split())\r\n print(f\"YES\\n1 {list(s1 & s2)[0]}\" if s1 & s2 else \"NO\")\r\n\r\n#any(i in a for i in b) in order to check the presence #other method l1.intersection(l2) \r\n----------------------------------------------------------------\r\n1537A - Arithmetic Array\r\n\r\nfor _ in range(int(input())):\r\n l = int(input())\r\n s = sum(map(int, input().split()))\r\n print(1 if s < l else s - l)\r\n----------------------------------------------------------------\r\n80A - Panoramix's Prediction\r\n\r\nl = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, None]\r\na , b = map(int, input().split())\r\nprint (['YES', 'NO'][l[l.index(a) + 1] != b])\r\n----------------------------------------------------------------\r\n1473A - Replacing Elements\r\n\r\nfor _ in range(int(input())):\r\n _, d = map(int, input().split(' '))\r\n l = sorted(list(map(int, input().split(' '))))\r\n print(\"YES\" if max(l) <= d or sum(l[:2]) <= d else print(\"NO\"))\r\n----------------------------------------------------------------\r\n1337A - Ichihime and Triangle\r\n\r\nfor _ in range(int(input())):\r\n _, b, c, _ = map(int, input().split(' '))\r\n print(b, c, c)\r\n----------------------------------------------------------------\r\n1372A - Omkar and Completion\r\n\r\nfor _ in range(int(input())): print('1 ' * int(input())) #easy\r\n\r\nfor i in[*open(0)][1:]:print(*[\"1\"]*int(i))\r\n----------------------------------------------------------------\r\n1325A -\tEhAb AnD gCd\r\n\r\nfor _ in range(int(input())):print(1,int(input())-1)\r\nexec(int(input())*'print(1,int(input())-1);') #to review # math trick\r\n----------------------------------------------------------------\r\n32B - Borze\r\n\r\nstring = input()\r\nfor word, initial in {'--': '2',\"-.\":\"1\", \".\":\"0\"}.items():\r\n string = string.replace(word, initial)\r\nprint(string)\r\n\r\nprint(input().replace('--','2').replace('-.','1').replace('.','0')) #using multiple replace together\r\n----------------------------------------------------------------\r\n1535A - Fair Playoff\r\n\r\nfor _ in range(int(input())):\r\n a = list(map(int, input().split(' ')))\r\n print(['YES', 'NO'][max(a[:2])+max(a[2:])<sum(sorted(a)[2:])])\r\n\r\nfor i in[*open(0)][1:]:\r\n a=*map(int,i.split()),\r\n print(['YES', 'NO'])[max(a[:2])+max(a[2:])<sum(sorted(a)[2:])::2]) #math plus pythonic\r\n----------------------------------------------------------------\r\nA - Alex and a Rhombus\r\n\r\nnumber = int(input())\r\nprint(1 + 2*(number)*(number-1)) #mathematical formula\r\n----------------------------------------------------------------\r\n112A - Petya and Strings\r\n\r\nstring1, string2 = input().lower(), input().lower()\r\nprint((string1 > string2) - (string1 < string2)) #pythonic thing\r\n----------------------------------------------------------------\r\n263A - Beautiful Matrix\r\n\r\nfor i in range(2, -3, -1):\r\n l = input()\r\n if '1' in l: print(abs(i) + abs(l.index('1') // 2 - 2))\r\n----------------------------------------------------------------\r\n282A - Bit++\r\n\r\nprint(sum(44 - ord(input()[1]) for i in [0] * int(input())))\r\n----------------------------------------------------------------\r\n50A - Domino piling\r\n\r\nM, N = list(map(int, input().split(' ')))\r\nprint(M*N//2)\r\n----------------------------------------------------------------\r\n158A - Next Round\r\n\r\nn, k = list(map(int, input().split(' ')))\r\nscoreParticipants = list(map(int, input().split(' ')))\r\nprint(sum(x >= max(scoreParticipants[k-1], 1) for x in scoreParticipants))\r\n----------------------------------------------------------------\r\n231A - Team\r\n\r\nnumberLines = int(input())\r\nsumLines = 0\r\n\r\nfor i in range(numberLines):\r\n participantsConfidence = sum(list(map(int, input().split(' '))))\r\n if participantsConfidence >= 2:\r\n sumLines += 1\r\n\r\nprint(sumLines)\r\n----------------------------------------------------------------\r\n71A - Way Too Long Words\r\n\r\nnumberLines = int(input())\r\nfor i in range(numberLines):\r\n word = input()\r\n lenword = len(word)\r\n if lenword <= 10:\r\n print(word)\r\n else: \r\n print(f\"{word[0]}{lenword-2}{word[-1]}\")\r\n----------------------------------------------------------------\r\n1547B - Alphabetical Strings \r\n\r\nnumberLines = int(input())\r\nl = True\r\n\r\ndef exitProcess():\r\n print('NO')\r\n\r\n\r\nfor j in range(numberLines):\r\n alphabetical = list(input())\r\n i = len(alphabetical)\r\n while i > 0:\r\n if alphabetical[0] > alphabetical[len(alphabetical) - 1]:\r\n if ord(alphabetical.pop(0)) - 96 != i:\r\n print('NO')\r\n i = 0 \r\n else:\r\n if ord(alphabetical.pop()) - 96 != i:\r\n print('NO')\r\n i = 0 \r\n i -= 1\r\n if i != -1:\r\n print('YES')\r\n------------------------------------------------------------------------------\r\nWatermelon\r\n\r\nrows , columns = map(int , input().split())\r\n\r\ndef getAns():\r\n ans = \"YES\"\r\n for i in range(rows):\r\n str = input()\r\n for j in range(1, columns):\r\n if str[0] != str[j]:\r\n ans = \"NO\"\r\n if i > 0 and pre == str:\r\n ans = \"NO\"\r\n pre = str\r\n return ans\r\n\r\nprint(getAns())\r\n'''",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nfreq = {}\r\nfor i in range(n):\r\n freq[arr[i]] = freq.get(arr[i], 0) + 1\r\nhighestFreq = max(freq, key=freq.get)\r\nprint(freq[highestFreq])\r\n",
"from collections import Counter\r\nfor _ in range(1):\r\n n=int(input())\r\n li=list(map(int,input().split()))\r\n dic=Counter(li)\r\n print(max(dic.values()))",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\ndict1={}\r\n\r\nfor i in range(len(lst)):\r\n if(lst[i] not in dict1):\r\n dict1.update({lst[i]:1})\r\n else:\r\n temp=dict1[lst[i]]\r\n dict1.update({lst[i]:temp+1})\r\nprint(max(dict1.values()))",
"arr = [0] * 101\n\nn = int(input())\na = list(map(int, input().split()))\n\nfor i in a:\n arr[i] += 1\n\ncount = 0\nrun = True\n\nwhile run:\n run = False\n\n for i in range(1, 101):\n if arr[i] > 0:\n arr[i] -= 1\n if arr[i] > 0:\n run = True\n count += 1\n\nprint(count)",
"n=int(input())\r\nlist=input().split(\" \")\r\nm=[]\r\nfor i in range(0,n):\r\n x=list.count(list[0])\r\n m.append(x)\r\n list.remove(list[0])\r\nm.sort()\r\nprint(m[-1])",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\na.sort()\r\nl = 0\r\nc = 0\r\nma = 0\r\nfor i in a:\r\n if i == l:\r\n c += 1\r\n else:\r\n ma = max(ma, c)\r\n c = 1\r\n l = i\r\nma = max(ma, c)\r\nprint(ma)",
"n = int(input())\na = [int(i) for i in input().split(\" \")]\n\nans = 1\nd = {}\nfor i in a:\n\tif i not in d.keys():\n\t\td[i] = 0\n\td[i] += 1\n\tans = max(ans, d[i])\n\nprint(ans)\n",
"n = int(input())\r\nlist=list(map(int,input().split()))\r\nmax=0\r\n\r\nfor i in range(n):\r\n v=list.count(list[i])\r\n if v>max:\r\n max=v\r\n\r\nprint(max)\r\n\r\n\r\n\r\n",
"from collections import *\r\nfrom heapq import *\r\nfrom bisect import *\r\nfrom itertools import *\r\nfrom functools import *\r\nfrom math import *\r\nfrom string import *\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n A = list(map(int, input().split()))\r\n print(max(Counter(A).values()))\r\n\r\n\r\ndef main():\r\n tests = 1\r\n for _ in range(tests):\r\n solve()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"from collections import Counter\r\n\r\nn = int(input())\r\ncoins = list(map(int, input().split()))\r\n\r\ncoin_counts = Counter(coins)\r\nmax_count = max(coin_counts.values())\r\n\r\nprint(max_count)\r\n",
"num = int(input())\r\nli = list(map(int,input().split()))\r\nli2=[]\r\nfor i in range(num):\r\n a = li.count(li[i])\r\n li2.append(a)\r\nprint(max(li2))\r\n",
"from collections import Counter\r\nn = int(input())\r\nprint(max(Counter(map(int, input().split())).values()))",
"from collections import Counter\r\n\r\nn=int(input())\r\nlis=list(map(int,input().split()))\r\np=Counter(lis)\r\nprint(max(p.values()))",
"a=int(input())\r\nl=sorted(list(input().split()))\r\nf=0\r\nc=1\r\nc1=1\r\nfor i in range(a-1):\r\n if l[i]==l[i+1] and f==0:\r\n c+=1\r\n elif l[i]==l[i+1] and f==1:\r\n c1+=1\r\n else:\r\n if c1>=c:\r\n c=1\r\n f=0\r\n elif c>c1:\r\n c1=1\r\n f=1\r\nif c1>c:\r\n print(c1)\r\nelse:\r\n print(c)",
"a = int(input())\r\narr = list(map(int, input().split()))\r\nm = 0\r\nfor i in arr:\r\n if arr.count(i) > m:\r\n m = arr.count(i)\r\nprint(m)",
"def solve():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n cnt = [0]*101 # maximum value of a[i] is 100\r\n for i in a:\r\n cnt[i] += 1\r\n print(max(cnt))\r\n\r\nsolve()",
"n=int(input())\r\na=list(map(int,input().split()))\r\nt=0\r\nfor i in range(n):\r\n t=max(t,a.count(a[i]))\r\nprint(t)",
"n = int(input())\r\n\r\na = [int(x) for x in input().split()]\r\n\r\nunique_values = set(a)\r\n\r\nmax_elements_with_same_value = 0\r\n\r\nfor x in unique_values:\r\n if a.count(x) > max_elements_with_same_value:\r\n max_elements_with_same_value = a.count(x)\r\n\r\nprint(max_elements_with_same_value)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc=[a.count(i) for i in a]\r\nprint(max(c))",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ncount = []\r\nfor i in arr:\r\n if arr.count(i) not in count:\r\n count.append(arr.count(i))\r\nprint(max(count))",
"from collections import Counter\r\nn=int(input())\r\na=[int(i) for i in input().split()]\r\nc= dict(Counter(a))\r\nprint(max(c.values()))",
"# https://codeforces.com/contest/1003\n\nimport sys\nfrom collections import Counter\n\ninput = lambda: sys.stdin.readline().rstrip() # faster!\n\nn = int(input())\na = list(map(int, input().split()))\n\nc = Counter(a)\nans = c.most_common()[0][1]\nprint(ans)\n",
"from math import ceil,gcd\r\nfrom math import factorial as fact, comb as ncr \r\nfrom math import sqrt\r\nfrom bisect import bisect_left as bl\r\nfrom bisect import bisect_right as br\r\nfrom array import array\r\nfrom collections import Counter as ctr\r\nfrom collections import deque as dq\r\n\r\ndef li():\r\n return list(map(int,input().split()))\r\ndef arr(a):\r\n return array('i',a)\r\n\r\ndef solve():\r\n #for _ in range(int(input())):\r\n n=int(input())\r\n s=ctr(li())\r\n print(max(s.values()))\r\nsolve()\r\n",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nchecked = []\r\nlargest = 0\r\nfor x in a:\r\n if x in checked:\r\n continue\r\n checked.append(x)\r\n temp = a.count(x)\r\n if temp > largest:\r\n largest = temp\r\nprint(largest)\r\n",
"n=int(input())\r\nx=input().split()\r\nls=[]\r\nfor i in range(n):\r\n ls.append(x.count(x[i]))\r\nprint(max(ls))",
"n=int(input())\r\nj=input().split()\r\nl=list(map(int,j))\r\n\r\n\r\n\r\n\r\n\r\ndef q(l,n):\r\n l.sort()\r\n l1=[]\r\n s=0\r\n for i in range(n-1):\r\n if l[i]==l[i+1]:\r\n s+=1\r\n else:\r\n l1.append(s)\r\n l1.append(s) \r\n return l1 ,len(l1) \r\n\r\ndef h(l,n):\r\n l1=[l[0]]\r\n for i in range(n-1):\r\n l1.append(l[i+1]-l[i])\r\n return l1 \r\n\r\ndef q2(l,n):\r\n l1,n1=q(l,n)\r\n l2=h(l1,n1)\r\n return max(l2)+1\r\nprint(q2(l,n)) ",
"import sys\r\nimport math\r\nimport collections\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\nimport string\r\nfor t in range(1):\r\n n=int(input())\r\n ans=get_list()\r\n counter=collections.Counter(ans)\r\n val=0\r\n for i in counter:\r\n val=max(val,counter[i])\r\n print(val)",
"input()\r\nx = list(map(int, input().split()))\r\ny = {}\r\nfor a in x:\r\n if a in y:\r\n y[a] += 1\r\n else:\r\n y[a] = 1\r\nprint(max(y.values()))",
"from collections import Counter\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nb = (Counter(a).most_common())\r\nc = [i for i in b]\r\nd = [i[1] for i in c]\r\nprint(max(d))",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\ni=0\r\nmx=0\r\nwhile i<n:\r\n x=a.count(a[i])\r\n i+=x\r\n if x > mx:\r\n mx=x\r\nprint(mx)",
"n = int(input())\r\nvalues = input().split(\" \")\r\nfor x in range(0,len(values)):\r\n values[x] = int(values[x])\r\nvalues.sort()\r\nlowest = values[0]\r\nhighest = values[-1]\r\nmostCommon = 0\r\nfor x in range(lowest, highest + 1):\r\n y = values.count(x)\r\n if y > mostCommon:\r\n mostCommon = y\r\nprint(mostCommon)\r\n",
"n=int(input())\r\nv=list(map(int,input().split()))\r\ndict1={}\r\nfor i in v:\r\n dict1[i]=dict1.get(i,0)+1\r\nprint(max(dict1.values()))",
"n, lst, cnt, res = input(), list(map(int, input().split())), [0] * 101, 0\r\nfor x in lst: cnt[x] += 1\r\nfor x in cnt: res = max(res, x)\r\nprint(res)",
"from itertools import groupby\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\n\r\nli = []\r\nfor k, v in groupby(a):\r\n\tli.append(len(list(v)))\r\n\r\nprint(max(li))",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nm = []\r\nfor i in l:\r\n a = l.count(i)\r\n m.append(a)\r\nprint(max(m))\r\n\r\n\r\n\r\n\r\n\r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\na={}\r\nm=0\r\nfor i in l:\r\n if i not in a:\r\n a[i]=1\r\n else:\r\n a[i]+=1\r\n \r\n if a[i]>m:\r\n m=a[i]\r\n\r\nprint(m)\r\n",
"import os\r\nimport sys\r\nimport math\r\nimport heapq\r\nfrom decimal import *\r\nfrom io import BytesIO, IOBase\r\nfrom collections import defaultdict, deque\r\n\r\ndef r():\r\n return int(input())\r\ndef rm():\r\n return map(int,input().split())\r\ndef rl():\r\n return list(map(int,input().split()))\r\n\r\n'''a'''\r\nn=r()\r\na=rl()\r\nhave=defaultdict(int)\r\nfor i in a:\r\n have[i]+=1\r\nprint(max(have.values()))\r\n",
"nc=[0 for _ in range(105)]\r\ninput()\r\na=input().split()\r\nfor x in a:\r\n nc[int(x)]+=1\r\nprint(max(nc))",
"n = int(input())\r\na = list(map(int, input().split()))\r\ncnt = {}\r\nfor i in range(n):\r\n if a[i] not in cnt:\r\n cnt[a[i]] = 0\r\n cnt[a[i]] += 1\r\nans = 0\r\nfor k in cnt:\r\n ans = max(ans, cnt[k])\r\nprint(ans)",
"n=int(input())\r\nm=list(map(int, input().split()))\r\nmax1=0\r\nfor i in set(m):\r\n if m.count(i)>max1:\r\n max1=m.count(i)\r\nprint(max1)",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nc=[0]*101\r\nfor i in range(len(b)):\r\n c[b[i]]+=1\r\nprint(max(c))",
"from collections import Counter\r\n\r\nn = int(input())\r\nlist_values=list(map(int,input().strip().split()))[:n]\r\noccurence_count = Counter(list_values)\r\n\r\nmax_coins=1\r\nfor key in occurence_count:\r\n if occurence_count[key]>=max_coins:\r\n max_coins=occurence_count[key]\r\nprint(max_coins)",
"n = int(input())\nA = list(map(int, input().split()))\nfrom collections import Counter\nC = Counter(A)\nans = 1\nfor v in C.values():\n ans = max(ans, v)\nprint(ans)\n",
"from collections import defaultdict\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nd=defaultdict(int)\r\nfor i in l:\r\n d[i]+=1\r\nprint(max(d.values()))\r\n",
"n=input()\r\nl=list(map(int,input().split()))\r\nprint(max(l.count(i) for i in l))",
"t=int(input()) \r\nn=list(map(int,input().split()))\r\nma=0\r\nfor x in n:\r\n ma=max(ma,n.count(x))\r\nprint(ma)",
"from collections import Counter\r\ndef main():\r\n n = input()\r\n print(max(Counter([int(i) for i in input().split()]).values()))\r\n\r\nmain()",
"a = int(input())\r\nb = input().split()\r\nc = set(b)\r\nd = 1\r\nfor i in c:\r\n if b.count(i) >= d:\r\n d =b.count(i) \r\nprint(d)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=0\r\nfor i in set(l):\r\n m=max(m,l.count(i))\r\nprint(m)",
"n = input()\r\na = input().split()\r\nprint(max(a.count(i) for i in a))\r\n",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\na=[]\r\nfor i in lst:\r\n c=lst.count(i)\r\n a.append(c)\r\nprint(max(a))\r\n ",
"t = int(input())\ns = list(map(int, input().split()))\nx = max(set(s), key=s.count)\nprint(s.count(x))\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ndef main():\r\n n = int(input())\r\n A = list(map(int, input().split()))\r\n cnt = {}\r\n for a in A:\r\n cnt[a] = cnt.get(a, 0) + 1\r\n print(max(cnt.values()))\r\n \r\nfor _ in range(1):\r\n main()",
"t = int(input())\r\na = list(map(str, input().split()))\r\nans = 1\r\nfor i in range(t):\r\n if a.count(a[i]) > ans:\r\n ans = a.count(a[i])\r\nprint(ans)\r\n",
"n = int(input())\r\na = list(map(int,input().strip().split()))[:n]\r\n\r\nflag = 1\r\nb = []\r\nfor i in range(n) :\r\n x = a[i+1:n]\r\n y = x.count(a[i])\r\n b.append(y+1)\r\nprint(max(b))",
"import collections\r\nfrom math import sqrt\r\nfrom collections import *\r\nfrom itertools import permutations\r\nmod = 10 ** 9 + 7\r\ndef main():\r\n n=int(input())\r\n a=list(map(int, input().split()))\r\n mx = 0\r\n cnt = Counter()\r\n for x in a:\r\n cnt[x]+=1\r\n mx = max(mx, cnt[x])\r\n print(mx)\r\n # test = int(input())\r\n # for _ in range(test):\r\n # n = int(input())\r\n # a = list(map(int, input().split()))\r\n # flag = 0\r\n # for x in a:\r\n # if sqrt(x)!=int(sqrt(x)):\r\n # flag = 1\r\n # break\r\n # print(\"YES\") if flag==1 else print(\"NO\")\r\nif __name__ == \"__main__\":\r\n main()",
"from collections import Counter\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nb=Counter(a)\r\nc=[]\r\nfor k,v in b.items():\r\n\tc.append(v)\r\nprint(max(c))\t",
"\r\nn, ans, cnt = int(input()), 1, 1\r\na = list(map(int, input().split()))\r\na.sort()\r\nfor i in range(1, n):\r\n if a[i] == a[i-1]:\r\n cnt += 1\r\n else:\r\n ans = max(ans, cnt)\r\n cnt = 1\r\nprint(max(ans, cnt))",
"n=int(input())\r\na=input().split()\r\nans=[]\r\nfor i in a:\r\n ans.append(a.count(i))\r\nprint(max(ans))",
"_ = int(input())\r\na = list(map(int, input().split()))\r\ncnt = {}\r\nfor x in a:\r\n if x not in cnt:\r\n cnt[x] = 0\r\n cnt[x] += 1\r\nans = 0\r\nfor k in cnt.keys():\r\n ans = max(ans, cnt[k])\r\nprint(ans)",
"input()\r\ns = list(map(int, input().split()))\r\nprint(max([s.count(i) for i in s]))",
"input()\r\na=[int(i) for i in input().split()]\r\nc=a.count(a[0])\r\nfor i in set(a):\r\n if(c<a.count(i)):\r\n c=a.count(i)\r\nprint(c)",
"input()\na=input().split()\nprint(max(a.count(x) for x in a))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=list(set(l))\r\nc=0\r\nfor i in range(len(s)):\r\n t=l.count(s[i])\r\n if t>c:\r\n c=t \r\nprint(c)\r\n",
"#!/usr/bin/python\r\n# -*- coding: utf-8 -*-\r\n\r\nb = input()\r\na = input().split(\" \")\r\nlst = [int(char) for char in a]\r\ndct = {}\r\nfor elem in lst:\r\n dct.setdefault(elem, 0)\r\n dct[elem] += 1\r\n\r\nmax = 0\r\nfor v in dct.values():\r\n if v >= max:\r\n max = v\r\nprint(max)",
"class Main:\r\n def __init__(self):\r\n self.n = int(input())\r\n self.a = [int(x) for x in input().split()]\r\n\r\n def main(self):\r\n self.a.sort()\r\n print(max(self.a.count(x) for x in set(self.a)))\r\n\r\nif __name__ == \"__main__\":\r\n Main().main()",
"n=int(input())\r\nls=list(map(int,input().split(\" \")))\r\nss=set(ls)\r\ncnt=0\r\nfor x in ss:\r\n if ls.count(x)>cnt:\r\n cnt=ls.count(x)\r\n\r\nprint(cnt)",
"def solve(a):\n return max([a.count(x) for x in a])\n\nif __name__ == '__main__':\n input()\n a = list(map(int, input().split()))\n print(solve(a))",
"test_cases=int(input())\r\ni=0\r\nj=0\r\ntest_cases1=input().split()\r\nfor k in test_cases1:\r\n\tj=test_cases1.count(k)\r\n\tif j>=i:\r\n\t\ti=j\r\n\t\r\nprint(i)\r\n\t\r\n\t\t\r\n\t\r\n\t\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nlk = []\r\nk = set(l)\r\np = list(k)\r\n\r\nfor i in p:\r\n lk.append(l.count(i))\r\nprint(max(lk))\r\n",
"freq = [0 for _ in range(101)]\nn = int(input())\nfor x in [int(x) for x in input().split()]:\n freq[x] += 1\n\nprint(max(freq))\n \t \t \t \t \t \t\t\t\t \t \t\t \t",
"n = int(input())\nmaxx = 0\na = list(map(int, input().split()))\nfor i in set(a):\n maxx = max(maxx, a.count(i))\nprint(maxx)\n",
"input()\r\na = [0] * 101\r\nfor i in input().split():\r\n a[int(i)] += 1\r\nprint(max(a))",
"n = int(input())\r\na = sorted(list(map(int, input().split())))\r\nans = []\r\n\r\nfor x in set(a):\r\n ans.append(a.count(x))\r\n\r\nprint(max(ans))",
"n = int(input())\r\nm = list(map(int, input().split()))\r\nk = list()\r\nfor i in m:\r\n k.append(m.count(i))\r\nprint(max(k))\r\n",
"while True:\r\n try:\r\n n = eval(input())\r\n list0 = list(map(int, input().split()))\r\n list1 = list(set(list0))\r\n max1 = 0\r\n len1 = len(list1)\r\n for i in range(len1):\r\n if list0.count(list1[i]) > max1:\r\n max1 = list0.count(list1[i])\r\n print(max1)\r\n except:\r\n break",
"n=int(input())\r\narr=[int(x) for x in input().split()]\r\narr.sort()\r\npocket=1\r\ni=0\r\nwhile i<n:\r\n j=0\r\n count=0\r\n while j<n:\r\n if arr[i]==arr[j]:\r\n count+=1\r\n j+=1\r\n if count>pocket:\r\n pocket+=(count-pocket)\r\n i+=1\r\nprint(pocket)",
"# URL: https://codeforces.com/problemset/problem/1003/A\n\nimport io\nimport os\nimport sys\nfrom collections import Counter\n\ninput_buffer = io.BytesIO(os.read(0, os.fstat(0).st_size))\ninp = lambda: input_buffer.readline().rstrip(b\"\\n\").rstrip(b\"\\r\")\nout = sys.stdout.write\n\ninp()\nc = Counter(map(int, inp().split()))\nans = c.most_common()[0][1]\nout(f\"{ans}\\n\")\n",
"n = int(input())\r\nx = [int(a) for a in input().strip().split(' ')]\r\ns = set(x)\r\nans = [x.count(y) for y in s]\r\nprint(max(ans))",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nprint(max([a.count(_a) for _a in a]))",
"n = int(input())\ncoins = list(map(int, input().split(' ')))\nmax_coins_count = 0\n\nfor coin in coins:\n if coins.count(coin) > max_coins_count:\n max_coins_count = coins.count(coin)\n \nprint(max_coins_count)\n",
"import sys\r\ninput = sys.stdin.readline\r\n \r\n'''\r\n \r\n'''\r\n\r\nfrom collections import Counter\r\n\r\nn = int(input())\r\na = Counter(map(int, input().split()))\r\nmx = max(a.values())\r\nprint(mx)",
"# cook your dish here\r\nt=int(input())\r\nl=[int(x) for x in input().strip().split()]\r\nx=dict();\r\nfor i in l:\r\n if(i not in x.keys()):\r\n x[i]=1\r\n else:\r\n x[i]=x[i]+1;\r\nmx=0\r\nfor i in x.keys():\r\n mx=max(mx,x[i])\r\nprint(mx)\r\n ",
"import os\r\n\r\nimport sys\r\n\r\ndebug = True\r\n\r\nif debug and os.path.exists(\"input.in\"):\r\n input = open(\"input.in\", \"r\").readline\r\nelse:\r\n debug = False\r\n input = sys.stdin.readline\r\n\r\n\r\ndef inp():\r\n return (int(input()))\r\n\r\n\r\ndef inlt():\r\n return (list(map(int, input().split())))\r\n\r\n\r\ndef insr():\r\n s = input()\r\n return s[:len(s) - 1] # Remove line char from end\r\n\r\n\r\ndef invr():\r\n return (map(int, input().split()))\r\n\r\n\r\nn = inp()\r\na = inlt()\r\nans = 0\r\nfor x in a:\r\n ans = max(ans, a.count(x))\r\nprint(ans)\r\n",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nimport math\r\nimport random\r\nfrom bisect import bisect_right, bisect_left\r\nfrom itertools import product, permutations, combinations, combinations_with_replacement \r\nfrom collections import deque, defaultdict, Counter\r\nfrom heapq import heapify, heappush, heappop\r\nfrom functools import lru_cache, reduce\r\ninf = float('inf')\r\ndef error(*args, sep=' ', end='\\n'):\r\n print(*args, sep=sep, end=end, file=sys.stderr)\r\n# mod = 1000000007\r\n# mod = 998244353\r\n\r\n# ----------------------- #\r\n\r\nn = int(input())\r\nA = list(map(int, input().split()))\r\nans = 0\r\nfor i in range(101):\r\n ans = max(ans, A.count(i))\r\nprint(ans)\r\n",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nc=0\r\nl=[]\r\nfor i in arr:\r\n l.append(arr.count(i))\r\nprint(max(l))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=0\r\nfor i in range(len(l)):\r\n if l.count(l[i])>m:\r\n m=l.count(l[i])\r\nprint(m)",
"from collections import Counter\r\n\r\nn = int(input())\r\na = list(map(int,input().split()))\r\n\r\nd = Counter(a)\r\nm = max(d.values())\r\n\r\nprint(m)",
"n = int(input())\r\ncoins = list(map(int, input().split()))\r\n\r\nfrequency = {}\r\nfor coin in coins:\r\n if coin in frequency:\r\n frequency[coin] += 1\r\n else:\r\n frequency[coin] = 1\r\n\r\nmin_pockets = max(frequency.values())\r\nprint(min_pockets)\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nzxc = {}\r\ncnt = 0\r\nfor i in arr:\r\n if(i not in zxc):\r\n zxc[i] = 0\r\n zxc[i] += 1\r\n if(zxc[i] > cnt): cnt = zxc[i]\r\nprint(cnt)",
"from collections import Counter\r\nn = int(input())\r\nprint(max(Counter(list(map(int, input().split()))).values()))\r\n",
"# cook your dish here\r\nfrom collections import Counter\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nc=Counter(a)\r\nprint(max(list(c.values())))\r\n\r\n\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\naSet = set(a)\r\nmax = 0\r\nfor item in aSet:\r\n count = a.count(item)\r\n if count > max:\r\n max = count\r\nprint(max) ",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nprint(max(b.count(i) for i in b))\r\n",
"def findAns(a,n):\r\n ele_dict = {}\r\n for i in a:\r\n if i not in ele_dict:\r\n ele_dict[i] = 0\r\n ele_dict[i] += 1\r\n max_el = ele_dict[i]\r\n for j in ele_dict.values():\r\n if j > max_el:\r\n max_el = j\r\n return max_el\r\n\r\nn = int(input())\r\na = list(map(int,input().strip().split()))[:n]\r\nresult = findAns(a,n)\r\nprint(result)",
"n = int(input())\r\nx = list(map(int,input().split()))\r\na=[0]*101\r\nfor r in x:\r\n a[r]+=1\r\nprint(max(a))",
"n = int(input())\r\na = {}\r\nmas = list(map(int, input().split()))\r\nfor i in mas:\r\n a[i] = a.get(i,0)+1\r\nprint(max(a.values()))",
"n=int(input())\r\nl=list(map(int,input().split()))[:n]\r\nl1=[]\r\nfor i in l:\r\n k=l.count(i)\r\n l1.append(k)\r\nprint(max(l1))",
"n = int(input())\r\ncoins = list(map(int, input().split()))\r\ncoin_freq = {}\r\nfor coin in coins:\r\n coin_freq[coin] = coin_freq.get(coin, 0) + 1\r\nmax_freq = max(coin_freq.values())\r\nprint(max_freq)",
"from collections import Counter\r\n\r\ninput()\r\narr = Counter([int(i) for i in input().split()])\r\n\r\nprint(arr.most_common()[0][1])",
"n = int(input())\r\n\r\nlist = list(map(int , input().split()))\r\n\r\nm = 0\r\nfor l in list:\r\n if list.count(l) > m:\r\n m = list.count(l)\r\n\r\nprint(m)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ncnt,cnt1,ans=0,0,0\r\nfor i in a:\r\n cnt1=a.count(i)\r\n if cnt1 >= cnt:\r\n cnt = cnt1\r\n ans = cnt1\r\n else:\r\n ans = cnt\r\nprint(ans)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nif n==1:\r\n print(1)\r\n exit()\r\nmp={}\r\n\r\nfor i in a:\r\n if i not in mp:\r\n mp[i]=1\r\n else:\r\n mp[i]+=1\r\nprint(mp.get(max(mp, key=mp.get)))",
"from collections import Counter\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\nc = Counter(lst)\r\nprint(max(c.values()))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=list(set(a))\r\nl=[]\r\nfor i in b:\r\n l.append(a.count(i))\r\nprint(max(l))\r\n",
"#t = int(input())\r\n#for _ in range(t):\r\nn = int(input())\r\nq = list(map(int, input().split()))\r\nprint(q.count(max(q, key=q.count)))",
"import sys\r\na = int(input(\"\"))\r\nb = [int(i) for i in sys.stdin.readline().split()]\r\nc = 0\r\nfor i in range(0, a):\r\n d = b.count(b[i])\r\n if d > c:\r\n c = d\r\nprint(c)\r\n",
"input()\r\na=input().split()\r\nprint(max(a.count(x) for x in a))",
"import sys\r\n\r\n\r\nLI = lambda: list(map(int, sys.stdin.readline().split()))\r\nMI = lambda: map(int, sys.stdin.readline().split())\r\nSI = lambda: sys.stdin.readline().strip('\\n')\r\nII = lambda: int(sys.stdin.readline())\r\n\r\n# sys.stdin = open(\"input.txt\", \"r\")\r\n\r\nn = II()\r\na = LI()\r\n\r\nif n == 1:\r\n print(1)\r\nelse:\r\n h = {}\r\n for num in a:\r\n if num in h:\r\n h[num] += 1\r\n else:\r\n h[num] = 1\r\n\r\n biggest = 0\r\n for k in h:\r\n if biggest < h[k]:\r\n biggest = h[k]\r\n\r\n print(biggest) \r\n",
"n = input()\r\nd = dict()\r\na = [int(tmp) for tmp in input().split()]\r\nmaxx = 0\r\nfor el in a:\r\n d[el] = d.get(el, 0) + 1\r\n if d[el] > maxx:\r\n maxx = d[el]\r\nprint(maxx)\r\n",
"n=int(input())\r\nx=list(map(int,input().split()))\r\ntemp=0\r\nfor i in x:\r\n if(x.count(i)>temp):\r\n temp=x.count(i)\r\nprint(temp) \r\n ",
"n = int(input())\nlist = [int(x) for x in input().split()]\nans = 0\nfor i in range(n):\n cnt = list.count(list[i])\n if ans < cnt:\n ans = cnt\nprint(ans)\n\t\t \t\t \t \t \t\t\t\t \t \t\t \t \t\t",
"n = int(input())\r\na = list(map(int,input().strip().split()))[:n]\r\nx=[]\r\nfor i in a:\r\n b=a.count(i)\r\n x.append(b)\r\ny=max(x)\r\nprint(y)",
"from collections import Counter\r\ninput()\r\na = list(map(int, input().split(' ')))\r\n\r\nprint(Counter(a).most_common()[0][1])\r\n",
"n=int(input())\r\nl=[int(l) for l in input().split()]\r\ncounter=0\r\nfor i in l:\r\n curr_freq=l.count(i)\r\n if curr_freq>counter:\r\n counter=curr_freq\r\nprint(counter)",
"n=int(input())\na=[int(x) for x in input().split()]\nd={}\nfor i in a:\n if i not in d:\n d[i]=1\n else:\n d[i]=d[i]+1\nans=0\nfor i in d:\n if d[i]>ans:\n ans=d[i]\nprint(ans)\n",
"import collections\r\nn = int(input())\r\nA = list(map(int,input().split()))\r\nC = collections.Counter(A)\r\nans = max(C.values())\r\nprint(ans)\r\n",
"t=int(input())\r\nl=[int(x) for x in input().split()]\r\nm=[]\r\nj=[]\r\nwhile t>0:\r\n if l[0] not in m:\r\n j.append(l.count(l[0]))\r\n l.pop(0) \r\n t-=1 \r\nprint(max(j)) ",
"if __name__ == \"__main__\":\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n\r\n i = 0\r\n curr = []\r\n pocket = []\r\n while a.count(\"_\") != n:\r\n if i == n:\r\n i = 0\r\n pocket.append(curr)\r\n curr = []\r\n\r\n num = a[i]\r\n if num != \"_\" and num not in curr:\r\n curr.append(num)\r\n a[i] = \"_\"\r\n\r\n i += 1\r\n\r\n pocket.append(curr)\r\n\r\n print(len(pocket))\r\n",
"count_of_pockets = int(input())\r\ncoins = [int(x) for x in input().split()]\r\nmax_pockets = 1\r\nfor el in coins:\r\n\tif coins.count(el) > max_pockets:\r\n\t\tmax_pockets = coins.count(el)\r\nprint(max_pockets)",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nb = [0] * 101\r\nfor i in a:\r\n b[i] += 1\r\n\r\nprint(max(b))",
"# import sys\r\n# input=sys.stdin.readline\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nb=list(set(a))\r\nc=[]\r\nfor i in range(len(b)):\r\n c.append(a.count(b[i]))\r\nprint(max(c))",
"input()\nn = [int(i) for i in input().split(\" \")]\n\ntime = []\n\nfor i in set(n):\n time.append(n.count(i))\n\nprint(max(time))\n\n\t \t\t \t \t\t\t\t\t \t\t\t\t\t \t \t",
"from collections import Counter\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nc=Counter(arr)\r\nm=1\r\nfor key,value in c.items():\r\n\t\tif(value>m):\r\n\t\t\tm=value\r\nprint(m)\r\n",
"n = int(input())\r\nlis = [int(i) for i in input().split()]\r\ndic = {}\r\nfor i in set(lis):\r\n dic[i] =0\r\nfor i in lis:\r\n dic[i] +=1\r\nmax = 0\r\nfor i in dic:\r\n if dic[i] > max:\r\n max = dic[i]\r\nprint(max)\r\n",
"from collections import defaultdict\r\n\r\nn = int(input())\r\ncoins = [int(i) for i in input().split()]\r\ndic = defaultdict(lambda: 0)\r\n\r\nfor i in coins:\r\n dic[i] += 1\r\n\r\nprint(max(dic.values()))\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\npockets = []\r\nfor coin in a:\r\n added = False\r\n for pocket in pockets:\r\n if coin not in pocket:\r\n pocket.append(coin)\r\n added = True\r\n break\r\n if not added:\r\n pockets.append([coin])\r\nprint(len(pockets))",
"# Hydro submission #6182a8204d64c9b7688ec491@1635952673183\ndef getint():\r\n return [int(i) for i in input().split()]\r\ndef get():\r\n return int(input())\r\ndef getstr():\r\n return [i for i in input().split()]\r\ndef S():\r\n for test in range(int(input())):\r\n solve()\r\nimport math\r\nimport itertools as it\r\nimport bisect\r\nimport time\r\nimport collections as ct\r\n\r\ndef solve():\r\n n=get()\r\n a=getint()\r\n ans=-1000\r\n for i in a:\r\n ans=max(ans,a.count(i))\r\n print(ans)\r\n\r\nsolve()",
"n = int(input())\r\ncnt = [0] * 101\r\n\r\nfor x in map(int, input().split()):\r\n cnt[x] += 1\r\n\r\nprint(max(cnt))",
"n = int(input())\r\na = [0] * 101\r\nb = list(int(i) for i in input().split())\r\nans = 0\r\nfor i in range(n):\r\n a[b[i]] += 1\r\n ans = max(ans, a[b[i]])\r\nprint(ans)\r\n",
"n=int(input())\r\na=[int(a) for a in input().split()]\r\nc=[a.count(y) for y in a ]\r\nprint(max(c))",
"# Polycarp's Pockets\r\nn = int(input())\r\nelements = list(map(int, input().split()))\r\nmax = 0\r\nif n == 1:\r\n print(1)\r\nelse:\r\n for x in elements:\r\n if max < elements.count(x):\r\n max = elements.count(x)\r\n print(max)\r\n",
"n=int(input())\r\nlist=[int(i) for i in input().split()]\r\nlarge=0\r\nfor i in range(1,101):\r\n if(large<list.count(i)):\r\n large=list.count(i)\r\nprint(large) \r\n",
"n = int(input())\r\ncoins = input().split()\r\nmax_count = 0\r\nfor i in coins:\r\n if coins.count(i)>max_count:\r\n max_count = coins.count(i)\r\nprint(max_count)",
"import collections\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nd = collections.defaultdict(lambda : 0)\r\nfor i in a:\r\n d[i]+=1\r\nans = max(d.values())\r\nprint(ans)\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\n\r\ndict = {}\r\n\r\nfor ele in arr :\r\n if ele in dict:\r\n dict[ele] = dict[ele] + 1\r\n else:\r\n dict[ele] = 1\r\n \r\n\r\nmaxPockets = 0\r\n\r\nfor key in dict:\r\n maxPockets = max (maxPockets , dict[key])\r\n\r\nprint(maxPockets)\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ncnt = [0] * 101\r\nfor elem in arr:\r\n cnt[elem] += 1\r\nprint(max(cnt))\r\n",
"import sys\r\nimport math\r\nfrom collections import defaultdict,Counter\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef I():\r\n return input()\r\n \r\ndef II():\r\n return int(input())\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \r\ndef LI():\r\n return list(input().split())\r\n \r\ndef LII():\r\n return list(map(int, input().split()))\r\n \r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n \r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n \r\ndef WRITE(out):\r\n return print('\\n'.join(map(str, out)))\r\n\r\n'''\r\n1 by x always doable\r\n\r\n\r\n'''\r\nt=II()\r\na=LII()\r\nc=Counter(a)\r\nprint(c.most_common(1)[0][1])",
"n=int(input())\r\na=list(map(int,input().split()))\r\nx=a.count(a[0])\r\nfor i in range(1,n):\r\n if(a.count(a[i])>x):\r\n x=a.count(a[i])\r\nprint(x)\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ndi={}\r\nfor i in a:\r\n if i not in di:\r\n di[i]=0\r\n di[i]+=1\r\nk=sorted(di,key=lambda x:di[x])\r\nprint(di[k[-1]])\r\n",
"num = int(input())\r\nz = [int(i) for i in input().split()]\r\nd = {}\r\nfor i in z:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i] = 1\r\nd = sorted(d.items(), key = lambda x: x[1] )\r\nprint(d[-1][1])",
"n=int(input())\r\na=list(map(int , input().split()))\r\nd=1\r\nfor i in range(n):\r\n c=0\r\n for j in range(n):\r\n if a[i]==a[j]:\r\n c+=1\r\n if c>=d:\r\n d=c\r\n\r\nprint(d)",
"input()\r\nmaxs = 0\r\nn = list(map(int,input().split()))\r\nfor i in n:\r\n maxs = max(maxs,n.count(i))\r\nprint(maxs)",
"\r\nn = int(input())\r\nk = [int(i) for i in input().split()]\r\nc = [0]*100\r\nfor i in k:\r\n c[i-1] += 1\r\nprint(max(c))",
"# https://codeforces.com/problemsets/acmsguru/problem/1003/A\r\n\r\nn, arr = int(input()), list(map(int, input().split()))\r\nd = {}\r\n\r\nfor num in arr:\r\n if num not in d:\r\n d[num] = 1\r\n else:\r\n d[num] += 1\r\n\r\nprint(max(d.values()))",
"\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nfor i in l:\r\n\tif l.count(i)>c:\r\n\t\tc=l.count(i)\r\nprint(c)",
"n = int(input())\r\ncoins = list(map(int,input().split()))\r\n\r\nres = 0\r\nfor i in set(coins):\r\n res = max(res,coins.count(i))\r\nprint(res)",
"input()\nl = list(map(int, input().split(\" \")))\ncnt = {}\nfor e in l:\n if e in cnt:\n cnt[e] += 1\n else:\n cnt[e] = 1\nmaks=0\nfor key in cnt:\n maks=max(maks, cnt[key])\nprint (maks)\n\n",
"from collections import Counter\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\na=Counter(l)\r\nv=a.values()\r\nprint(max(v))",
"from collections import Counter\r\ninput()\r\ns = str(input()).split(' ')\r\nprint(max(Counter(s).values()))",
"from collections import Counter\r\nn = int(input())\r\na = Counter(map(int, input().split()))\r\nprint(max(a.values()))",
"n=int(input())\r\nlist1=list(map(int,input().split()))\r\nlist2=[]\r\nfor i in list1:\r\n list2.append(list1.count(i))\r\nprint(max(list2))",
"n = int(input())\r\nar = list(map(int, input().split()))\r\n\r\nar.sort()\r\ndic = {}\r\nfor i in ar:\r\n if i in dic:\r\n dic[i] += 1\r\n else:\r\n dic[i] = 1\r\n \r\nm = 0\r\nfor i in dic:\r\n if dic[i] > m:\r\n m = dic[i]\r\n \r\nprint(m)",
"n = int(input())\r\ntab = list(map(int, input().split()))\r\ntest = []\r\nfor i in tab:\r\n test.append(tab.count(i))\r\ntest.sort()\r\nprint(test[-1]) ",
"from collections import Counter\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\nl = len(set(a))\r\nc = 0\r\nd = Counter(a)\r\nif l == len(a):\r\n print(1)\r\nelse:\r\n print(max(d.values()))\r\n",
"from sys import stdin\r\n_input = stdin.readline\r\n_int = int\r\nfrom collections import Counter\r\n\r\n\r\ndef solution():\r\n n = _int(_input())\r\n arr = Counter([_int(i) for i in _input().split()])\r\n z = arr.most_common(1)[0]\r\n print(z[1])\r\nsolution()",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nmaxi=0\r\nfor i in range(n):\r\n if(l.count(l[i])>=maxi):\r\n maxi=l.count(l[i])\r\nprint(maxi)\r\n ",
"from collections import Counter\r\n\r\nn = int(input())\r\na = input().split()\r\n\r\nprint(max(Counter(a).values()))\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans = []\r\nfor i in a:\r\n ans.append(a.count(i))\r\nprint(max(ans))",
"n=int(input())\r\nli=[int(x) for x in input().split()]\r\nm=0\r\nfor i in range(n):\r\n\tif li.count(li[i]) > m:\r\n\t\tm=li.count(li[i])\r\nprint(m)\r\n",
"def pockets(a):\r\n aa = set(a)\r\n ca = []\r\n for i in aa:\r\n ca.append(a.count(i))\r\n return max(ca)\r\n\r\n\r\nn = int(input())\r\nnn = list(map(int, input().split()))\r\nprint(pockets(nn))",
"input()\r\na = sorted(list(map(int, input().split())))\r\nkol = 1\r\nm = [1]\r\nfor i in range(len(a)-1):\r\n if a[i] == a[i+1]:\r\n kol += 1\r\n else:\r\n kol = 1\r\n m.append(kol)\r\nprint(max(m))",
"def pockets(a):\r\n m=0\r\n for i in a:\r\n m=max(a.count(i),m)\r\n return m\r\nt=int(input())\r\ng=[int(i) for i in input().split()]\r\nprint(pockets(g))",
"n=int(input())\r\nl=list(map(int,input().split())) \r\ncount=0\r\nfor i in range(len(l)):\r\n if(l.count(l[i])>=count):\r\n count=l.count(l[i]) \r\nprint(count)\r\n ",
"n=int(input())\r\nli=list(map(int,input().split()))\r\nl=[]\r\nfor i in li:\r\n l.append(li.count(i))\r\nprint(max(l))",
"n= int(input())\r\ns= [int(i) for i in input().split()]\r\nd=dict()\r\nfor i in s:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i]=1\r\nans=0\r\nfor i in d:\r\n if ans<d[i]:\r\n ans=d[i]\r\nprint(ans)",
"x = int(input())\r\ny = list(map(int, input().split()))\r\nprint(max([y.count(i) for i in y]))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = set(a)\r\nm =1\r\nfor i in b:\r\n m = max(m,a.count(i))\r\nprint(m)",
"from collections import Counter\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nx=list(Counter(l).values())\r\nprint(max(x))",
"n=int(input())\r\na=list(map(int,input().split()))\r\np=0\r\nm=[]\r\nfor i in range(n):\r\n\tm.append(a.count(a[i]))\r\nm=sorted(m)\r\nprint(m[n-1])",
"n=int(input())\r\nl=input().split()\r\nb=[]\r\nfor i in l:\r\n (b.append(l.count(i)))\r\nprint(max(b))",
"def max_pockets(n):\r\n a = input().split()\r\n m = 1\r\n for i in a:\r\n if m < a.count(i):\r\n m = a.count(i)\r\n\r\n return m\r\n\r\n\r\nprint(max_pockets(int(input())))\r\n",
"def Bitplus():\r\n n = int(input())\r\n x = 0\r\n for i in range(n):\r\n a = input()\r\n if \"+\" in a:\r\n x += 1\r\n else:\r\n x -= 1\r\n print(x)\r\n\r\ndef GiftSetidk():\r\n n = int(input())\r\n for i in range(n):\r\n all = input().split(\" \")\r\n x = int(all[0])\r\n y = int(all[1])\r\n a = int(all[2])\r\n b = int(all[3])\r\n counter = 0\r\n count = True\r\n while count:\r\n if x >= a and y >= b:\r\n x -= a\r\n y -= b\r\n counter += 1\r\n elif x >= b and y >= a:\r\n x -= b\r\n y -= a\r\n counter += 1\r\n else:\r\n count = False\r\n print(counter)\r\n\r\n\r\ndef Team():\r\n n = int(input())\r\n problemcount = 0\r\n for i in range(n):\r\n count = 0\r\n answer = input().split(\" \")\r\n for i in range(len(answer)):\r\n answer[i] = int(answer[i])\r\n for i in answer:\r\n if i == 1:\r\n count += 1\r\n if count >= 2:\r\n problemcount += 1\r\n print(problemcount)\r\n\r\ndef NextRound():\r\n nk = input().split(\" \")\r\n n = int(nk[0])\r\n k = int(nk[1])\r\n print(n, k)\r\n scores = input().split(\" \")\r\n count = 0\r\n for i in range(n):\r\n scores[i] = int(scores[i])\r\n five = scores[k]\r\n for i in range(n):\r\n if scores[i] >= five and scores[i] > 0:\r\n count += 1\r\n print(count)\r\n\r\n\r\ndef Beautifulmatrix():\r\n steps = 0\r\n matrixes = []\r\n for i in range(5):\r\n i = [input().split(\" \")]\r\n matrixes += i\r\n for i in range(5):\r\n for j in range(5):\r\n matrixes[i][j] = int(matrixes[i][j])\r\n for i in range(5):\r\n for j in range(5):\r\n if matrixes[i][j] > 0:\r\n x = j\r\n y = i\r\n break\r\n while x != 2 or y != 2:\r\n if x > 2:\r\n x -= 1\r\n steps += 1\r\n elif x < 2:\r\n x += 1\r\n steps += 1\r\n elif y > 2:\r\n y -= 1\r\n steps += 1\r\n elif y < 2:\r\n y += 1\r\n steps += 1\r\n print(steps)\r\n\r\n\r\ndef HelpfulMahts():\r\n s = input().split(\"+\")\r\n s.sort()\r\n print(\"+\".join(s))\r\n\r\ndef WordCapitalization():\r\n word = input()\r\n List = []\r\n for i in word:\r\n List.append(i)\r\n List[0] = List[0].upper()\r\n s = \"\"\r\n for i in List:\r\n s += i\r\n print(s)\r\n\r\ndef Stonesonthetable():\r\n n = int(input())\r\n stones = []\r\n rrg = input()\r\n counter = 0\r\n for i in rrg:\r\n stones.append(i)\r\n for i in range(n - 1):\r\n if stones[i] == stones[i + 1]:\r\n counter += 1\r\n print(counter)\r\n\r\ndef BearandBigBrother():\r\n inpuut = input().split(\" \")\r\n a = int(inpuut[0])\r\n b = int(inpuut[1])\r\n year = 0\r\n while a <= b:\r\n a *= 3\r\n b *= 2\r\n year += 1\r\n print(year)\r\n\r\ndef Wrongsubtraction():\r\n nk = input().split(\" \")\r\n n = int(nk[0])\r\n k = int(nk[1])\r\n for i in range(k):\r\n p = str(n)\r\n if p[len(p) - 1] == \"0\":\r\n n //= 10\r\n else:\r\n n -= 1\r\n print(n)\r\n\r\nimport string\r\ndef Word():\r\n word = input()\r\n lower = 0\r\n upper = 0\r\n for i in word:\r\n if i in string.ascii_lowercase:\r\n lower += 1\r\n else:\r\n upper += 1\r\n if upper > lower:\r\n word = word.upper()\r\n else:\r\n word = word.lower()\r\n print(word)\r\n\r\ndef QueueattheSchool():\r\n nt = input().split(\" \")\r\n n = nt[0]\r\n t = int(nt[1])\r\n a = input()\r\n b = []\r\n ref = \"\"\r\n for i in a:\r\n b.append(i)\r\n for k in range(t):\r\n whre = []\r\n for i in range(len(b) - 1):\r\n if b[i] == \"B\" and b[i + 1] != \"B\":\r\n whre.insert( 0,i)\r\n for j in whre:\r\n b.pop(j)\r\n b.insert(j + 1, \"B\")\r\n for i in b:\r\n ref += i\r\n print(ref)\r\n\r\ndef Nearlyluckynumber():\r\n n = input()\r\n if n.count(\"7\") + n.count(\"4\") == 7 or n.count(\"7\") + n.count(\"4\") == 4:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\ndef Translation():\r\n s = input()\r\n t = input()\r\n n = []\r\n for i in t:\r\n n.insert(0, i)\r\n t = \"\"\r\n for i in n:\r\n t += i\r\n if t == s:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\ndef ANTONandDanik():\r\n n = int(input())\r\n s = input()\r\n A = s.count(\"A\")\r\n D = s.count(\"D\")\r\n if A > D:\r\n print(\"Anton\")\r\n elif D > A:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\n\r\n\r\ndef GeorgeandAccomodation():\r\n n = int(input())\r\n rooms = 0\r\n for i in range(n):\r\n pq = input().split(\" \")\r\n p = int(pq[0])\r\n q = int(pq[1])\r\n if q - p >= 2:\r\n rooms += 1\r\n print(rooms)\r\n\r\ndef Magnets():\r\n n = int(input())\r\n Rows = []\r\n groups = 1\r\n for i in range(n):\r\n Rows += [input()]\r\n for i in range(n - 1):\r\n if Rows[i] != Rows[i + 1]:\r\n groups += 1\r\n print(groups)\r\n\r\n\r\ndef InSearcoanEasyProblem():\r\n n = int(input())\r\n counter = 0\r\n s = input().split(\" \")\r\n if \"1\" in s:\r\n print(\"HARD\")\r\n else:\r\n print(\"EASY\")\r\n\r\ndef Hulk():\r\n c = int(input())\r\n i = \"I\"\r\n s = \"\"\r\n it = \"it\"\r\n for i in range(1, c + 1):\r\n if i == 1:\r\n s += \"hate \"\r\n elif i % 2 == 0:\r\n s += \"that I love \"\r\n else:\r\n s += \"that I hate \"\r\n print(f\"I {s}it\")\r\n\r\ndef CalculatingFunctionidk():\r\n n = int(input())\r\n c = 0\r\n for i in range(1, n + 1):\r\n if i % 2 != 0:\r\n c -= i\r\n else:\r\n c += i\r\n print(c)\r\n\r\ndef IWannaBetheGuyidk():\r\n n = int(input())\r\n p = input().split(\" \")\r\n q = input().split(\" \")\r\n counter = 0\r\n for i in range(1, n + 1):\r\n if str(i) in p or str(i) in q:\r\n counter += 1\r\n if counter == n:\r\n print(\"I become the guy.\")\r\n else:\r\n print(\"Oh, my keyboard!\")\r\n\r\ndef horsesheo():\r\n n = input().split(\" \")\r\n many = 4\r\n whatwas = []\r\n for i in range(len(n)):\r\n n[i] = int(n[i])\r\n if n[i] not in whatwas:\r\n whatwas.append(n[i])\r\n print(many - len(whatwas))\r\n\r\ndef ArrivaloftheGeneralidk():\r\n n = int(input())\r\n a = input().split(\" \")\r\n max = 0\r\n minlist = []\r\n for i in range(n):\r\n a[i] = int(a[i])\r\n for i in a:\r\n if i > max:\r\n max = i\r\n maxloc = a.index(max)\r\n for i in a:\r\n minlist.insert(0, i)\r\n min = max\r\n for i in a:\r\n if i < min:\r\n min = i\r\n minloc = minlist.index(min)\r\n print(minloc + maxloc)\r\n\r\n\r\n\r\ndef UltraFastMathematician():\r\n first = input()\r\n second = input()\r\n s = \"\"\r\n for i in range(len(first)):\r\n if first[i] == \"0\" and second[i] == \"1\":\r\n s += \"1\"\r\n elif first[i] == \"1\" and second[i] == \"0\":\r\n s += \"1\"\r\n elif first[i] == \"0\" and second[i] == \"0\":\r\n s += \"0\"\r\n elif first[i] == \"1\" and second[i] == \"1\":\r\n s += \"0\"\r\n print(s)\r\n\r\ndef Insomniacure():\r\n klmn = []\r\n for i in range(4):\r\n klmn.append(int(input()))\r\n d = int(input())\r\n List = []\r\n if 1 in klmn:\r\n return d\r\n for i in range(4):\r\n mulit = klmn[i]\r\n while klmn[i] <= d:\r\n if klmn[i] not in List:\r\n List.append(klmn[i])\r\n klmn[i] += mulit\r\n return len(List)\r\n\r\n\r\ndef AntonandLetters():\r\n first = input()\r\n List = []\r\n for i in first:\r\n if i not in List and i in string.ascii_lowercase:\r\n List.append(i)\r\n print(len(List))\r\n\r\n\r\ndef Pangram():\r\n n = int(input())\r\n word = input().lower()\r\n List = []\r\n if n >= 26:\r\n for i in word:\r\n if i not in List:\r\n List.append(i)\r\n if len(List) == 26:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\ndef Collectingcoons():\r\n n = int(input())\r\n for i in range(n):\r\n abcd = input().split(\" \")\r\n for i in range(len(abcd)):\r\n abcd[i] = int(abcd[i])\r\n d = abcd[3]\r\n abcd.pop()\r\n maxi = 0\r\n for i in abcd:\r\n if i > maxi:\r\n maxi = i\r\n allindexes = [0, 1, 2]\r\n indexmax = abcd.index(maxi)\r\n allindexes.pop(indexmax)\r\n allminus = 0\r\n for i in allindexes:\r\n allminus += abcd[indexmax] - abcd[i]\r\n d -= allminus\r\n if d % 3 == 0 and d >= 0:\r\n print('YES')\r\n else:\r\n print(\"NO\")\r\n\r\n\r\ndef Brainsphotos():\r\n nm = input().split(\" \")\r\n colors = []\r\n for i in range(int(nm[0])):\r\n colors += input().split(\" \")\r\n for i in colors:\r\n if i == 'C' or i == 'M' or i == 'Y':\r\n return \"#Color\"\r\n return \"#Black&White\"\r\n\r\ndef SerejaandDima():\r\n n = int(input())\r\n card = input().split(\" \")\r\n S = 0\r\n D = 0\r\n sturn = True\r\n for i in range(n):\r\n if int(card[0]) > int(card[len(card) - 1]):\r\n if sturn:\r\n S += int(card[0])\r\n card.pop(0)\r\n sturn = False\r\n else:\r\n D += int(card[0])\r\n card.pop(0)\r\n sturn = True\r\n else:\r\n if sturn:\r\n S += int(card[len(card) - 1])\r\n card.pop(len(card) - 1)\r\n sturn = False\r\n else:\r\n D += int(card[len(card) - 1])\r\n card.pop(len(card) - 1)\r\n sturn = True\r\n print(f\"{S} {D}\")\r\n\r\n\r\ndef Vanyaandcubes():\r\n n = int(input())\r\n counter = 1\r\n countdodo = 0\r\n rows = 0\r\n while n > 0:\r\n countdodo += counter\r\n counter += 1\r\n rows += 1\r\n n -= countdodo\r\n if n == 0:\r\n print(rows)\r\n else:\r\n print(rows - 1)\r\n\r\ndef GennadyandaCarGame():\r\n card = input()\r\n cards = input().replace(\" \", \"\")\r\n for i in card:\r\n for j in cards:\r\n if i == j:\r\n return \"YES\"\r\n return \"NO\"\r\n\r\ndef FafaandhisCompany():\r\n n = int(input())\r\n ways = 0\r\n for i in range(1, n):\r\n a = n\r\n a -= i\r\n if a%i == 0:\r\n ways += 1\r\n print(ways)\r\n\r\ndef Mahmoudandehabandtheevenoddgame():\r\n n = int(input())\r\n Mahmoudsturn = True\r\n Mahmoudlsot = False\r\n Ehablost = False\r\n a = 0\r\n while not Mahmoudlsot and not Ehablost:\r\n if Mahmoudsturn:\r\n if n%2 == 0 and n >= 2:\r\n Ehablost = True\r\n\r\n elif n%2 != 0 and n >= 2:\r\n a = n - 1\r\n else:\r\n Mahmoudlsot = True\r\n else:\r\n if n%2 == 1 and n >= 1:\r\n Mahmoudlsot = True\r\n elif n%2 == 0 and n >= 1:\r\n a = n - 1\r\n else:\r\n Ehablost = False\r\n n -= a\r\n if Mahmoudsturn == True:\r\n Mahmoudsturn = False\r\n else:\r\n Mahmoudsturn = True\r\n if Mahmoudlsot == True:\r\n print(\"Ehab\")\r\n else:\r\n print(\"Mahmoud\")\r\n\r\n\r\ndef FloorNumber():\r\n t = int(input())\r\n for i in range(t):\r\n nx = input().split(\" \")\r\n n = int(nx[0])\r\n x = int(nx[1])\r\n aparteements = 2\r\n floor = 1\r\n while n > aparteements:\r\n aparteements += x\r\n floor += 1\r\n print(floor)\r\n\r\n\r\ndef VustheCossackandaContest():\r\n nmk = input().split(\" \")\r\n n = int(nmk[0])\r\n m = int(nmk[1])\r\n k = int(nmk[2])\r\n if n <= m and n <= k:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")\r\n\r\ndef NightattheMuseum():\r\n word = input()\r\n rotations = 0\r\n lower = string.ascii_lowercase + string.ascii_lowercase + string.ascii_lowercase\r\n loc = lower.index(\"a\", 26, 2 * 26)\r\n\r\n for i in word:\r\n cplus = loc\r\n cminus = loc\r\n keep = True\r\n while keep:\r\n if i == lower[cplus] or i == lower[cminus]:\r\n keep = False\r\n else:\r\n cplus += 1\r\n cminus -= 1\r\n rotations += 1\r\n loc = lower.index(i, 26, 2 * 26)\r\n print(rotations)\r\n\r\n\r\ndef OrdinarYnumbers():\r\n n = int(input())\r\n for i in range(n):\r\n k = int(input())\r\n counter = 0\r\n for j in range(1, k + 1):\r\n a = str(j)\r\n if len(a) == a.count(a[0]):\r\n counter += 1\r\n print(counter)\r\n\r\n\r\ndef DieRoll():\r\n n = input().split(\" \")\r\n y = int(n[0])\r\n w = int(n[1])\r\n number = 0\r\n dec = 6\r\n if y >= w:\r\n for i in range(y, 7):\r\n number += 1\r\n else:\r\n for i in range(w, 7):\r\n number += 1\r\n if number%6 == 0:\r\n number = number // 6\r\n dec = 1\r\n elif number%3 == 0:\r\n number = number//3\r\n dec = 2\r\n elif number%2 == 0:\r\n number = number // 2\r\n dec = 3\r\n print(f\"{number}/{dec}\")\r\n\r\ndef Borze():\r\n n = input()\r\n l = \"\"\r\n k = \"\"\r\n for i in n:\r\n if i == \".\" and len(l) == 0:\r\n k += \"0\"\r\n else:\r\n l += i\r\n if len(l) == 2:\r\n if l == \"-.\":\r\n k += \"1\"\r\n l = \"\"\r\n else:\r\n k += \"2\"\r\n l = \"\"\r\n print(k)\r\n\r\ndef FairPlayoff():\r\n n = int(input())\r\n for i in range(n):\r\n loser = {}\r\n winner = {}\r\n count = 0\r\n k = input().split(\" \")\r\n if int(k[0]) > int(k[1]):\r\n loser[\"one\"] = int(k[1])\r\n winner[\"two\"] = int(k[0])\r\n else:\r\n loser[\"one\"] = int(k[0])\r\n winner[\"two\"] = int(k[1])\r\n if int(k[2]) > int(k[3]):\r\n loser[\"two\"] = int(k[3])\r\n winner[\"one\"] = int(k[2])\r\n else:\r\n loser[\"two\"] = int(k[2])\r\n winner[\"one\"] = int(k[3])\r\n for i in loser:\r\n if loser[i] < winner[i]:\r\n count += 1\r\n if count >= 2:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\ndef Bustoudaylanbd():\r\n n = int(input())\r\n s = []\r\n rem = -1\r\n first = True\r\n ss = \"\"\r\n for i in range(n):\r\n s += input().split(\"|\")\r\n for i in range(len(s)):\r\n if s[i] == \"OO\" and first:\r\n rem = i\r\n s[i] = \"++\"\r\n first = False\r\n for i in range(len(s)):\r\n if i % 2 == 0:\r\n ss += s[i] + \"|\"\r\n\r\n else:\r\n ss += s[i] + \"\\n\"\r\n if not first:\r\n print(\"YES\")\r\n print(ss)\r\n else:\r\n print(\"NO\")\r\n\r\ndef Maximumincrease():\r\n n = int(input())\r\n arraa = input().split(\" \")\r\n for i in range(len(arraa)):\r\n arraa[i] = int(arraa[i])\r\n counter = {}\r\n for i in range(n):\r\n counter[i] = 0\r\n count = 0\r\n last = 0\r\n for i in arraa:\r\n if i > last:\r\n last = i\r\n counter[count] += 1\r\n else:\r\n last = i\r\n count += 1\r\n counter[count] += 1\r\n max = 0\r\n for i in range(n):\r\n if counter[i] > max:\r\n max = counter[i]\r\n print(max)\r\n\r\n\r\ndef Jugglingletters():\r\n n = int(input())\r\n\r\n for i in range(n):\r\n k = int(input())\r\n s = \"\"\r\n map = {}\r\n possible = True\r\n for i in range(k):\r\n s += input()\r\n for i in s:\r\n if i not in map:\r\n map[i] = 1\r\n else:\r\n map[i] += 1\r\n for i in map:\r\n if map[i] % k != 0:\r\n possible = False\r\n if possible:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\ndef Panoramixsprediction():\r\n nm = input().split(\" \")\r\n n = int(nm[0])\r\n m = int(nm[1])\r\n first = True\r\n for i in range(n + 1, m):\r\n count = 0\r\n for j in range(2, i):\r\n if i % j == 0:\r\n count += 1\r\n if count == 0:\r\n first = False\r\n break\r\n if first:\r\n count = 0\r\n for j in range(2, m):\r\n if m % j == 0:\r\n count += 1\r\n if count == 0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\ndef ThreepilesofCanides():\r\n k = int(input())\r\n for i in range(k):\r\n n = input().split(\" \")\r\n canides = 0\r\n for i in n:\r\n canides += int(i)\r\n if canides % 2 != 0:\r\n canides -=1\r\n print(canides//2)\r\n\r\n\r\ndef filename():\r\n n = int(input())\r\n name = input()\r\n more = 0\r\n map = {}\r\n map[more] = 0\r\n count = 0\r\n for i in name:\r\n if i == \"x\":\r\n map[more] += 1\r\n elif map[more] != 0:\r\n more += 1\r\n map[more] = 0\r\n for i in map:\r\n if map[i] >= 3:\r\n while map[i] > 2:\r\n map[i] -= 1\r\n count += 1\r\n print(count)\r\n\r\n\r\ndef Football():\r\n map = {}\r\n current = 0\r\n s = input()\r\n f= s[0]\r\n map[current] = 0\r\n check = False\r\n for i in s:\r\n if i == f:\r\n map[current] += 1\r\n else:\r\n current += 1\r\n map[current] = 1\r\n f = i\r\n for i in map:\r\n if map[i] >= 7:\r\n check = True\r\n if check:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\ndef CombinationLock1():\r\n n = int(input())\r\n fl = input()\r\n sl = input()\r\n count = 0\r\n for i in range(n):\r\n goup = int(fl[i])\r\n god = int(fl[i])\r\n cu = 0\r\n cd = 0\r\n keep = True\r\n while keep:\r\n if goup + 1 <= 9:\r\n goup += 1\r\n cu += 1\r\n else:\r\n goup = 0\r\n cu += 1\r\n if god - 1 >= 0:\r\n god -= 1\r\n cd += 1\r\n else:\r\n god = 9\r\n cd += 1\r\n if goup == int(sl[i]):\r\n count += cu\r\n keep = False\r\n elif god == int(sl[i]):\r\n count += cd\r\n keep = False\r\n print(count)\r\n\r\ndef Watermelon():\r\n n = int(input())\r\n down = n//2\r\n up = n - down\r\n rge = up\r\n for i in range(rge):\r\n if up%2 == 0 and down%2 == 0:\r\n return print(\"YES\")\r\n else:\r\n if up + 1 < n and down - 1 > 0:\r\n up += 1\r\n down -= 1\r\n else:\r\n return print(\"NO\")\r\n\r\n\r\ndef Dominopiling():\r\n nk = input().split(\" \")\r\n n = int(nk[0])\r\n k = int(nk[1])\r\n mnk = n * k\r\n print(mnk//2)\r\n\r\ndef yetanotherBookshelf():\r\n n = int(input())\r\n for i in range(n):\r\n le = int(input())\r\n K = input().split(\" \")\r\n SK = []\r\n lili = []\r\n for i in range(le):\r\n if i + 1 <= le - 1:\r\n if K[i] == \"1\" and K[i + 1] == \"1\":\r\n lili.append(i)\r\n lili.reverse()\r\n for i in lili:\r\n K.pop(i)\r\n coun = 0\r\n while K.count(\"1\") > 1:\r\n f = K.index(\"1\")\r\n K.pop(f)\r\n K.insert(f + 1, \"1\")\r\n f += 1\r\n if K[f + 1] == \"1\":\r\n K.pop(f)\r\n coun += 1\r\n print(coun)\r\n\r\ndef Combinationlockittakestolong():\r\n n = int(input())\r\n fl = input()\r\n sl = input()\r\n counter = 0\r\n for i in range(n):\r\n up = int(fl[i])\r\n down = int(fl[i])\r\n while True:\r\n if up + 1 <= 9:\r\n up += 1\r\n else:\r\n up = 0\r\n if down - 1 >= 0:\r\n down -= 1\r\n else:\r\n down = 9\r\n counter += 1\r\n if up == int(sl) or down == int(sl):\r\n break\r\n\r\n\r\ndef iwannabetheguytolong():\r\n n = int(input())\r\n lvl = input().split(\" \")\r\n lvls = input().split(\" \")\r\n for i in range(1, n + 1):\r\n if str(i) not in lvl and str(i) not in lvls:\r\n return print(\"Oh, my keyboard!\")\r\n return print(\"I become the guy.\")\r\n\r\ndef giftsettolong():\r\n n = int(input())\r\n for i in range(n):\r\n rb = input().split(\" \")\r\n x = int(rb[0])\r\n y = int(rb[1])\r\n a = int(rb[2])\r\n b = int(rb[3])\r\n giftset = 0\r\n while True:\r\n if x - a >= 0 and y - b >= 0:\r\n x -= a\r\n y -= b\r\n giftset += 1\r\n elif x - b >= 0 and y - a >= 0:\r\n x -= b\r\n y -= a\r\n giftset += 1\r\n else:\r\n break\r\n print(giftset)\r\n\r\n\r\n\r\ndef uniquwbidauctiontime():\r\n n = int(input())\r\n for i in range(n):\r\n k = int(input())\r\n list = input().split(\" \")\r\n o = -1\r\n for i in range(k):\r\n if list.count(list[i]) == 1:\r\n if o == -1 or list[i] < o:\r\n o = list[i]\r\n if o != -1:\r\n print(list.index(o) + 1)\r\n else:\r\n print(o)\r\n\r\n\r\ndef equalizepriceagain():\r\n n = int(input())\r\n for i in range(n):\r\n k = int(input())\r\n numbers = input().split(\" \")\r\n for i in range(len(numbers)):\r\n numbers[i] = int(numbers[i])\r\n total = 0\r\n for i in numbers:\r\n total += i\r\n if total%k == 0:\r\n print(total//k)\r\n else:\r\n while total%k != 0:\r\n total += 1\r\n print(total//k)\r\n\r\ndef shortsubstrings():\r\n n = int(input())\r\n for i in range(n):\r\n s = input()\r\n laist = []\r\n for i in range(len(s)):\r\n if i%2 != 0 and i != len(s) - 1:\r\n laist.append(i)\r\n laist.reverse()\r\n s = list(s)\r\n for i in laist:\r\n s.pop(i)\r\n sa = \"\"\r\n for i in s:\r\n sa += i\r\n print(sa)\r\n\r\ndef policerecruits():\r\n n = int(input())\r\n k = input().split(\" \")\r\n officers = 0\r\n crimes = 0\r\n for i in k:\r\n if int(i) == -1:\r\n if officers == 0:\r\n crimes += 1\r\n else:\r\n officers -= 1\r\n else:\r\n officers += int(i)\r\n print(crimes)\r\n\r\n\r\ndef thenewyear():\r\n xxx = input().split(\" \")\r\n for i in range(len(xxx)):\r\n xxx[i] = int(xxx[i])\r\n xxx.sort()\r\n way = 0\r\n way += abs(int(xxx[1]) - int(xxx[0]))\r\n way += abs(int(xxx[1]) - int(xxx[2]))\r\n print(way)\r\n\r\n\r\ndef frogjumpingtimelimit():\r\n n = int(input())\r\n for i in range(n):\r\n abk = input().split(\" \")\r\n a = int(abk[0])\r\n b = int(abk[1])\r\n k = int(abk[2])\r\n all = 0\r\n for i in range(k):\r\n if i % 2 == 0:\r\n all += a\r\n else:\r\n all -= b\r\n print(all)\r\n\r\n\r\ndef patrickandshopping():\r\n d = input().split(\" \")\r\n d3 = 0\r\n for i in range(len(d)):\r\n if int(d[i]) > d3:\r\n d3 = int(d[i])\r\n d.pop(d.index(str(d3)))\r\n d1 = int(d[0])\r\n d2 = int(d[1])\r\n distance = d1 + d2\r\n if d3 <= distance:\r\n distance += d3\r\n else:\r\n distance += distance\r\n print(distance)\r\n\r\n\r\ndef Freeicecream():\r\n nx = input().split(\" \")\r\n n = int(nx[0])\r\n ice = int(nx[1])\r\n diskid = 0\r\n for i in range(n):\r\n k = input().split(\" \")\r\n if k[0] == \"+\":\r\n ice += int(k[1])\r\n else:\r\n if ice >= int(k[1]):\r\n ice -= int(k[1])\r\n else:\r\n diskid += 1\r\n print(ice, diskid)\r\n\r\ndef Reviewsite():\r\n t = int(input())\r\n for i in range(t):\r\n n = int(input())\r\n upvotes = 0\r\n votes = input().split(\" \")\r\n for i in votes:\r\n if i != \"2\":\r\n upvotes += 1\r\n print(upvotes)\r\n\r\ndef Lastyeasrtssubstring():\r\n t = int(input())\r\n for i in range(t):\r\n n = int(input())\r\n s = input()\r\n if s[0:4] == \"2020\" or s[n - 4: n] == \"2020\":\r\n print(\"YES\")\r\n elif s[0:3] == \"202\" and s[n - 1] == \"0\":\r\n print(\"YES\")\r\n elif s[n - 3: n] == \"020\" and s[0] == \"2\":\r\n print(\"YES\")\r\n elif s[0:2] == \"20\" and s[n - 2] == \"20\":\r\n print(\"YES\")\r\n elif s[n - 2: n] == \"20\" and s[0:2] == \"20\":\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\ndef Arena():\r\n t = int(input())\r\n for i in range(t):\r\n n = int(input())\r\n heros = input().split(\" \")\r\n heorsint = [int(i) for i in heros]\r\n heorsint.sort()\r\n min = heorsint[0]\r\n winner = n - (heorsint.count(min))\r\n print(winner)\r\n\r\ndef twoRabbitstoolongbutright():\r\n t = int(input())\r\n for i in range(t):\r\n xyab = input().split(\" \")\r\n x = int(xyab[0])\r\n y = int(xyab[1])\r\n a = int(xyab[2])\r\n b = int(xyab[3])\r\n seconds = 0\r\n while x < y:\r\n x += a\r\n y -= b\r\n seconds += 1\r\n if x == y:\r\n print(seconds)\r\n else:\r\n print(-1)\r\n\r\n\r\ndef systemofequations():\r\n nm = input().split(\" \")\r\n n = int(nm[0])\r\n m = int(nm[1])\r\n nm = [int(i) for i in nm]\r\n nm.sort()\r\n count = 0\r\n for i in range(nm[0] + 1):\r\n for j in range(nm[0] + 1):\r\n if i**2 + j == n and j**2 + i == m:\r\n count += 1\r\n print(count)\r\n\r\n\r\ndef polycarpwspockets():\r\n n = int(input())\r\n coins = input().split(\" \")\r\n coins = [int(i) for i in coins]\r\n pocket = 0\r\n for i in coins:\r\n nmumbver = coins.count(i)\r\n if nmumbver > pocket:\r\n pocket = nmumbver\r\n print(pocket)\r\n\r\n\r\npolycarpwspockets()",
"n=int(input())\nl=list(map(int,input().split()))\nm=0\nfor i in l:\n if m<l.count(i):\n m=l.count(i)\nprint(m)\n",
"from collections import Counter\r\nn=int(input())\r\nl=input().split()\r\nk=Counter(l)\t\r\nprint(max(k.values()))\t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl2=[]\r\nfor i in range(n):\r\n\tl2.append(l.count(l[i]))\r\nprint(max(l2))",
"n = int(input())\r\nli = list(map(int, input().split()))\r\nk = set(li)\r\nm = 1\r\nfor i in k:\r\n if li.count(i)>m:\r\n m = li.count(i)\r\nprint(m)\r\n",
"n = int(input())\r\nd = {}\r\nl = list(map(int,input().split()))\r\nfor i in l:\r\n\tif i in d:\r\n\t\td[i] += 1\r\n\telse:\r\n\t\td[i] = 1 \r\nprint(max(d.values()))",
"input()\r\nli=list(map(int,input().split()))\r\nprint(max([li.count(i) for i in set(li)]))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nx=[]\r\ng=[1]\r\nfor i in a:\r\n\tif i not in x:\r\n\t\tc=a.count(i)\r\n\t\tif c>1:\r\n\t\t\tg.append(c)\r\n\r\nprint(max(g))",
"n=int(input())\r\na = [int(i) for i in input().split()]\r\nma=0\r\nfor i in range(n):\r\n x=a.count(a[i])\r\n if x>ma:\r\n ma=x\r\nprint(ma)",
"n = int(input())\r\ns = list(map(int,input().strip().split()))[:n]\r\na ={}\r\nc = 0\r\nfor i in s:\r\n if i in a:\r\n a[i] += 1\r\n else:\r\n a[i]=1\r\n\r\nfor i in a:\r\n c = max(c,a[i])\r\nprint (c)\r\n",
"from collections import Counter \r\nn = int(input())\r\na = list(map(int, input().split()))\r\nc = Counter(a)\r\n \r\nm = float(\"-inf\")\r\n\r\nfor i in c:\r\n if c[i] > m:\r\n m = c[i]\r\n\r\nprint(m)",
"# 1003A - Polycarp's Pockets\r\nn, l, i, a = int(input()), sorted(list(map(int, input().split()))), 0, 0\r\nwhile i < n:\r\n x = l.count(l[i])\r\n a = max(a, x)\r\n i += x\r\nprint(a)\r\n",
"n = int(input())\na = list((map(int,input().split())))\nmx = -1\nfor x in a:\n mx = max(mx,a.count(x))\nprint(mx)",
"if __name__ == \"__main__\":\r\n n = int(input())\r\n arr = list(map(int,input().split()))\r\n count = 0\r\n max = 0\r\n\r\n for i in range(n):\r\n if(arr.count(arr[i]) > max):\r\n max = arr.count(arr[i])\r\n\r\n \r\n print(max)",
"n=int(input())\r\nL=list(map(int, input().split()))\r\nC=[0 for i in range(100)]\r\nfor i in L:\r\n C[i-1]=C[i-1]+1\r\nprint(max(C))\r\n ",
"n=int(input())\r\nr=[]\r\nw=[]\r\ns=input()\r\nl=s.split()\r\nl=[int(i) for i in l]\r\nfor i in l:\r\n r.append(l.count(i))\r\nprint(max(r))",
"n=int(input()) \r\na=list(map(int,input().split()))\r\nma=0\r\nfor i in set(a):\r\n if ma<a.count(i):\r\n ma=a.count(i)\r\nprint(ma)",
"# import sys\n# sys.stdin=open('input.in','r')\n# sys.stdout=open('output.out','w')\nn=int(input())\nk=list(map(int,input().strip().split()[:n]))\nd={}\nl=[]\nfor x in k:\n\tif len(k)==1:\n\t\tprint(1)\n\t\tp=True\n\t\tbreak\n\telif x in d:\n\t\td[x]+=1\n\t\tp=False\n\t\tl.append(d[x])\n\telse:\n\t\td[x]=1\n\t\tp=False\n\t\tl.append(d[x])\nif p==False:\n\tprint(max(l))",
"n, s, m = int(input()), input().split(), 0\r\nfor i in range(len(s)):\r\n if s.count(s[i]) > m:\r\n m = s.count(s[i])\r\nprint(m)",
"x=int(input())\nz=input().split()\nlist1=[]\nfor i in range(len(z)):\n list1.append(z.count(z[i]))\nprint(max(list1)) \n \t \t \t\t\t \t\t \t \t \t \t\t \t",
"from collections import Counter\r\nn=int(input())\r\narr=[int(i) for i in input().split()]\r\nx=Counter(arr)\r\nprint(max(x.values()))\r\n",
"from sys import stdin\r\ninput = stdin.readline\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\nf = [0]*101\r\nfor i in a:\r\n f[i] += 1\r\nprint(max(f))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nsa=set(a)\r\nans=0\r\nfor x in sa:\r\n ans=max(ans,a.count(x))\r\nprint(ans)",
"n = int(input())\r\ns = map(int, input().strip().split(' '))\r\nt = [0 for i in range(101)]\r\nfor i in s:\r\n t[i] += 1\r\nprint(max(t))",
"from collections import*\r\nn=int(input())\r\nprint(max(Counter(map(int,input().split())).values()))",
"a=int(input())\r\nt=[int(i) for i in input().split()]\r\ncommon_count=numberkaamka=0\r\nfor z in t:\r\n if t.count(z)>common_count:\r\n common_count=t.count(z)\r\n numberkaamka=z\r\n# print(common_count,numberkaamka)\r\nprint(common_count)",
"# coding: utf-8\r\n\r\nfrom collections import Counter\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nprint(Counter(a).most_common(1)[0][1])",
"n=int(input())\r\na=list(map(int, input().split()))\r\nm=0\r\nfor i in range(n):\r\n f=a.count(a[i])\r\n if f>m:\r\n m=f\r\nprint(m)",
"# import numpy \n\nn = int(input())\nlis = input().split(\" \")\n# count=numpy.zeros(n)\ncount=[]\nMax=0\n\ndef func(data=[]):\n data.append(0)\n\n\nfor i in range(0,len(lis)):\n func(count)\n for k in range(i+1,len(lis)):\n if lis[i]==lis[k]:\n count[i]+=1\n\n if count[i]>Max:\n Max=count[i]\n\nMax+=1 \nprint(int(Max))\n\n",
"n = int(input())\r\nl = list(map(int,input().split()))+[1000]\r\nl.sort()\r\nc = 1\r\nmx = 0\r\nfor i in range(n):\r\n if l[i]==l[i+1]:\r\n c+=1\r\n else:\r\n if c>mx:\r\n mx = c\r\n c = 1\r\nprint(mx)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl1=[0]*101\r\nfor i in range(n):\r\n l1[l[i]]+=1\r\nprint(max(l1))",
"n = int(input())\r\ncoins = list(map(int, input().split()))\r\ndif_coins = {}\r\nfor c in coins:\r\n\tdif_coins[c] = dif_coins.get(c,0) + 1\r\nprint(max(dif_coins.values()))",
"n=int(input())\r\na=list(map(int,input().split()))\r\ndi={}\r\nj=set()\r\nfor i in range(0,n):\r\n\tif a[i] in j:\r\n\t\tdi[a[i]]+=1\r\n\telse:\r\n\t\tj.add(a[i])\r\n\t\tdi[a[i]]=1\r\nk=1\r\nj=list(j)\r\nn=len(j)\r\nfor i in range(0,n):\r\n\tif di[j[i]]>k:\r\n\t\tk=di[j[i]]\r\nprint(k)",
"n = int(input())\r\na = list(map(int,input().split()))\r\not = 1\r\na1 = set(a)\r\na1 = list(a1)\r\nfor x in range(len(a1)):\r\n if a.count(a1[x])>ot:\r\n ot = a.count(a1[x])\r\nprint(ot)\r\n",
"from collections import Counter\r\n\r\ndef solve():\r\n # Get the number of coins\r\n n = int(input())\r\n \r\n # Get the coins list\r\n coins_list = list(map(int, input().split()))\r\n \r\n # Get the frequency of all items in the array\r\n coin_frequency = Counter(coins_list)\r\n \r\n # Ans will be the coin with maximum frequency\r\n print(max(coin_frequency.values()))\r\n\r\nsolve()",
"number_of_coins=int(input())\r\ncoins=list(map(int,input().split()))\r\n\r\nunique_coins=set(coins)\r\nunique_coins=list(unique_coins)\r\n#print(type(unique_coins))\r\n#print(unique_coins)\r\nflag=0\r\nfor x in range(len(unique_coins)):\r\n if coins.count(unique_coins[x]) > flag:\r\n flag=coins.count(unique_coins[x])\r\nprint(flag)",
"from sys import stdin, stdout\r\nn = int(input())\r\nl = list(map(int, stdin.readline().split()))\r\ns = set(l)\r\nl2 = []\r\nfor i in s:\r\n l2.append(l.count(i))\r\nstdout.write(str(max(l2)))",
"n = int(input())\r\na = sorted(list(map(int,input().split())))\r\nans = 1\r\nf = 1\r\nfor i in range(1,len(a)):\r\n if a[i] == a[i-1]:\r\n f += 1\r\n else :\r\n f = 1\r\n if ans < f :\r\n ans = f\r\nprint(ans)\r\n",
"n = int(input())\n\ncoins = {}\n\nfor i in map(int, input().split()):\n coins.setdefault(i, 0)\n coins[i] += 1\n\nprint(max(coins.values()))",
"n = int(input())\r\na = list(map(int,input().split()))\r\na.sort()\r\nbig = 1\r\ncurr = 1\r\nprev = a[0]\r\na.remove(a[0])\r\nfor elem in a:\r\n\r\n if elem == prev:\r\n curr += 1\r\n if curr > big:\r\n big = curr\r\n else:\r\n if curr > big:\r\n big = curr\r\n curr = 1\r\n prev = elem\r\n\r\nprint(big)\r\n \r\n",
"\nimport sys\ndef get_single_int ():\n return int (sys.stdin.readline ().strip ())\ndef get_string ():\n return sys.stdin.readline ().strip ()\ndef get_ints ():\n return map (int, sys.stdin.readline ().strip ().split ())\ndef get_list ():\n return list (map (int, sys.stdin.readline ().strip ().split ()))\n\n#code starts here\nn = get_single_int ()\nar = get_list ()\nm = {}\nfor i in range (1, 101):\n m [i] = 0\nfor i in ar:\n m [ i] += 1\nprint (max (m.values ()))\n",
"from collections import Counter\r\n\r\nn = int(input())\r\nnumbers = list(map(int, input().split()))\r\n\r\ncounter = Counter(numbers)\r\nmost_common_number = max(counter, key=counter.get)\r\nfrequency = counter[most_common_number]\r\n\r\nprint(frequency)\r\n",
"from collections import Counter\n\nn = int(input())\na = input().split()\n\ncounts = Counter(a)\n\nmaximum = 0\n\nfor value in counts.values():\n if value > maximum:\n maximum = value\n\nprint(maximum)\n",
"n=(int)(input())\r\nl=list(map(int,input().split()))\r\n # a,b=map(int,input().split())\r\nar=[0]*101\r\nfor i in range(n):\r\n ar[l[i]]+=1\r\nar.sort()\r\nprint(ar[100])",
"n = int(input())\r\nA = list(map(int, input().split()))\r\nMax = 1\r\nfor i in set(A):\r\n Max = max(Max, A.count(i))\r\nprint(Max)",
"import sys\nfrom collections import Counter\ninput = sys.stdin.readline\n\nL = int(input())\nA = list(map(int, input().split()))\nprint(Counter(A).most_common()[0][1])",
"n=int(input())\r\na=input().split()\r\naux=list(set(a))\r\nlista=[]\r\nfor i in range(len(aux)):\r\n lista.append([aux[i],0])\r\nfor i in range(len(aux)):\r\n for j in range(n):\r\n if(lista[i][0]==a[j]):\r\n lista[i][1]+=1\r\nmaximo=0\r\nfor i in range(len(aux)):\r\n if(lista[i][1]>maximo):\r\n maximo=lista[i][1]\r\nprint(maximo)",
"#code\r\ntry:\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n res=0\r\n for ele in arr:\r\n res=max(res,arr.count(ele))\r\n print(res)\r\n pass\r\nexcept Exception:\r\n pass",
"n = int(input())\r\na = [0] * 101\r\nb = list(map(int, input().split()))\r\nfor i in range(n):\r\n a[b[i]] += 1\r\nprint(max(a))",
"from collections import defaultdict\r\nx = int(input())\r\nhas = defaultdict(int)\r\narr = [*map(int, input().split())]\r\nfor i in arr:\r\n has[i] += 1\r\nprint(max(has.values()))\r\n\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Jan 4 19:21:48 2021\r\n\r\n@author: lenovo\r\n\"\"\"\r\n\r\n\r\ndef pockert(values):\r\n dict1={}\r\n for i in range(len(values)):\r\n if values[i] not in dict1:\r\n dict1[values[i]]=1\r\n else:\r\n dict1[values[i]]=dict1[values[i]]+1\r\n return max(dict1.values())\r\nn=int(input())\r\nvalues=list(map(int,input().split()))\r\nprint(pockert(values))",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\nfrequencies = {num: 0 for num in nums}\r\nfor num in nums:\r\n frequencies[num] += 1\r\n\r\nprint(max(frequencies.values()))\r\n",
"x = input()\r\ncoins = [int(x) for x in input().split()]\r\n\r\npockets = 0\r\n\r\nfor i in range(max(coins)+1):\r\n num = coins.count(i)\r\n if num > pockets:\r\n pockets = num\r\n\r\nprint(pockets)\r\n",
"lenz = int(input())\r\n\r\narr = input()\r\narr = arr.split(\" \")\r\n\r\narr = [arr.count(x) for x in arr]\r\n\r\nprint(max(arr))",
"n=int(input())\r\nmin=0\r\nk=list(map(int,input().split()))\r\nfor i in range(n):\r\n s=k.count(k[i])\r\n if s>min:\r\n min=s\r\nprint(min)\r\n",
"num = int(input(\"\"))\r\nvalues = input(\"\")\r\nvList = values.split()\r\n\r\nmaxNum = 0\r\n\r\n\r\nfor i in range(0, num):\r\n currentNum = 0\r\n\r\n for x in range(0,num):\r\n\r\n currentCheck = vList[i]\r\n\r\n if currentCheck == vList[x]:\r\n currentNum = currentNum + 1\r\n\r\n if currentNum > maxNum:\r\n maxNum = currentNum\r\n\r\n\r\nprint(maxNum)\r\n",
"b=int(input())\r\na=[int(i) for i in input().split()]\r\np=0\r\npp=0\r\nkk=0\r\nfor el in a:\r\n pp=0\r\n kk=el\r\n for el in a:\r\n if kk==el:\r\n pp+=1\r\n if pp>p:\r\n p=pp\r\nprint(p)",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nd = {}\r\nfor i in l:\r\n if i in d:\r\n d[i] += 1\r\n\r\n else:\r\n d[i] = 1\r\n\r\n\r\nm = 0\r\nfor i in d:\r\n if d[i] > m:\r\n m = d[i]\r\n\r\nprint(m)",
"a= int(input())\r\nb= list(map(int,input().split()))\r\ndict={}\r\npoint1= 0\r\npoint2= b[0]\r\nfor k in b:\r\n if k not in dict:\r\n dict[k] = 1\r\n else:\r\n dict[k] += 1\r\n if dict[k] > point1:\r\n point1= dict[k]\r\n point2= k\r\n first= k\r\nprint(point1)\r\n \r\n",
"from collections import Counter\r\n\r\nn = int(input())\r\narr = map(int, input().split())\r\nprint(Counter(arr).most_common(1)[0][1])\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Sep 24 05:11:04 2020\r\n\r\n@author: Dark Soul\r\n\"\"\"\r\n\r\nn=int(input(''))\r\narr=list(map(int,input().split()))\r\ncnt=[0]*101\r\nfor i in arr:\r\n cnt[i]+=1\r\nprint(max(cnt))",
"n=int(input())\r\nx=list(map(int,input().split()))\r\nd={}\r\nfor i in x:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i]=1\r\nmax_value=0\r\nfor j in d:\r\n if d[j]>max_value :\r\n max_value=d[j]\r\n else:\r\n continue\r\nprint(max_value)\r\n",
"def repetitions(e, set):\r\n count=0\r\n for i in set:\r\n if(i==e):\r\n count+=1\r\n return count\r\n\r\nnumCoins = eval(input())\r\ncoins = input().split(' ')\r\npockets=0\r\nfor i in coins:\r\n if(repetitions(i, coins)>pockets):\r\n pockets=repetitions(i, coins)\r\nprint(pockets)",
"n=int(input())\r\nlist1=list(map(int,input().split(\" \")))\r\nhashi=[0]*101\r\nfor j in list1:\r\n hashi[j]+=1\r\nhashi.sort()\r\nprint(hashi[-1])\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nd={}\r\nc=0\r\nfor i in l:\r\n if i in d:\r\n d[i] += 1\r\n else:\r\n d[i] = 1\r\nfor i in d:\r\n c=max(c,d[i])\r\nprint(c)",
"n=int(input())\r\nl1=list(map(int,input().split()))\r\nl2=[]\r\nfor i in l1:\r\n l2.append(l1.count(i))\r\nprint(max(l2))",
"n=int(input())\nx=list(map(int,input().split()))\nc={}\nfor i in x:\n if i not in c:\n c[i]=0\n if i in c:\n c[i]+=1\nprint(max(c.values()))\n \t \t \t\t\t \t \t\t \t\t\t \t\t\t\t\t\t",
"n=int(input(\"\"))\r\na=list(map(int,input(\"\").split()))\r\nd=[0 for i in range (101)]\r\ndem=0\r\nfor i in range (len(a)):\r\n d[a[i]]+=1\r\nfor i in range (101):\r\n dem=max(dem,d[i])\r\nprint(dem)",
"n=int(input())\r\narr=[int(i) for i in input().split()]\r\nx=list(map(lambda x:arr.count(x),arr))\r\nprint(max(x))\r\n",
"from sys import stdin, stdout\r\n\r\nget_string = lambda: stdin.readline().strip('\\n')\r\nget_intmap = lambda: map( int, get_string().split(' ') )\r\n#get_intmap\r\n\r\ndef ncr_generator(n,r):\r\n ncrr = 1\r\n while True:\r\n yield ncrr\r\n n += 1\r\n ncrr = ( ncrr * n // (n - r) ) \r\n\r\ndef testcase():\r\n n = int(input())\r\n cnt = [0] * 101 # could use a hash map here\r\n for i in get_intmap():\r\n cnt[i] += 1\r\n print(max(cnt))\r\n\r\ntestcase()\r\n#for t in range(int(input())):\r\n# testcase()\r\n",
"from collections import Counter\r\na=input()\r\nb=map(int, input().split())\r\nc=Counter(b)\r\nprint(max(c.values()))\r\n",
"n=int(input())\r\ncoins=list(map(int, input().split()))\r\nm = 0\r\nc = 0\r\nfor i in coins:\r\n k = coins.count(i)\r\n if k > m:\r\n m = k\r\n c = i\r\nprint(m)\r\n",
"n = int(input())\r\n\r\na = [int(x) for x in input().split()]\r\n#print(*a)\r\n\r\ncnt=0\r\nfor x in a:\r\n if a.count(x)>cnt:\r\n cnt=a.count(x)\r\n\r\nprint(cnt)\r\n\r\n#print(max(a.count(i)for i in a))\r\n\r\n\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nx=0\r\np=[]\r\nfor i in l:\r\n x=l.count(i)\r\n p.append(x)\r\nprint(max(p))",
"n = int(input())\r\na = list(map(int,input().split()))\r\nmx = 0\r\nfor i in a:\r\n mx = max(a.count(i), mx)\r\n a = [j for j in a if j != i]\r\nprint(mx)",
"n = int(input())\r\na = input().split()\r\nmx = 0\r\n\r\ncoins = {coin: 0 for coin in set(a)}\r\n\r\nfor coin in a:\r\n coins[coin] += 1\r\n\r\nfor coin in coins:\r\n if coins[coin] > mx:\r\n mx = coins[coin]\r\n\r\nprint(mx)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nmaximum=0\r\nfor i in l:\r\n if l.count(i)>maximum:\r\n maximum=l.count(i)\r\nprint(maximum)",
"def solve(a):\r\n value_to_count = {}\r\n for value in a:\r\n value_to_count[value] = value_to_count.get(value, 0) + 1\r\n\r\n return max(value_to_count.values())\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n print(solve(a))",
"x=int(input())\r\nd=[]\r\ny=list(map(int,input().split()))\r\nfor i in y:\r\n d.append(y.count(i))\r\nprint(max(d))\r\n",
"a=input()\r\ns=list(map(int,input().split()))\r\nc=[]\r\nfor i in s:\r\n c.append(s.count(i))\r\nprint(max(c))",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nif(n==1):\r\n print(1)\r\nelse:\r\n d = {}\r\n for i in l:\r\n if i not in d:\r\n d[i] = l.count(i)\r\n print(max(d.values()))",
"n = int(input())\r\ncoins = list(map(int, input().split()))\r\n \r\n# Dictionary which holds the number of coins which have a certain value\r\nvalue_counter = {}\r\n \r\n# Maximum number of pockets needed\r\nmax_pockets = 0\r\n \r\nfor coin in coins:\r\n if coin in value_counter:\r\n value_counter[coin] += 1\r\n else:\r\n value_counter[coin] = 1\r\n \r\n if value_counter[coin] > max_pockets:\r\n max_pockets = value_counter[coin]\r\n \r\n# Print the required result\r\nprint(max_pockets)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=set(a)\r\nc=0\r\nfor j in b:\r\n if(a.count(j)>c):\r\n c=a.count(j)\r\nprint(c)",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\nd={}\r\nfor i in a:\r\n if i in d:\r\n d[i]=d[i]+1\r\n else:\r\n d[i]=1\r\n m=0\r\n for i in d:\r\n m=max(d[i],m)\r\nprint(m)",
"import math\r\n\r\na= int(input())\r\nls = list(map(int,input().split()))\r\ns = 0\r\nfor i in ls:\r\n if ls.count(i)>=s:\r\n s = ls.count(i)\r\nprint(s)\r\n\r\n",
"from collections import Counter\r\n\r\nn = int(input())\r\na = [int(s) for s in input().split()]\r\n\r\nprint(Counter(a).most_common(1)[0][1])\r\n",
"n=int(input())\r\nl=list(map(int,input().split(' ')))\r\nm=[]\r\nfor i in range(0,len(l)):\r\n p=l.count(l[i])\r\n m.append(p)\r\nif len(l)==1:\r\n print(1)\r\nelse:\r\n print(max(m))",
"a=int(input())\r\nls=list(map(int,input().split()))\r\nfreq=[0]*((max(ls))+1)\r\nfor j in range(len(ls)):\r\n c=ls[j]\r\n freq[c]+=1\r\nprint(max(freq))",
"from collections import Counter\n\ninput()\nprint(Counter(input().split()).most_common(1)[0][1])\n",
"from collections import Counter\r\nn=int(input())\r\nprint(max(Counter(list(map(int,input().split(\" \")))).values()))\r\n\r\n\r\n",
"n = int(input())\r\nls = list(map(int,input().split()))\r\nkq = 0\r\nfor item in ls:\r\n kq = max(kq,ls.count(item))\r\nprint(kq)",
"import re\r\nimport sys\r\nexit=sys.exit\r\nfrom bisect import bisect_left as bsl,bisect_right as bsr\r\nfrom collections import Counter,defaultdict as ddict,deque\r\nfrom functools import lru_cache\r\ncache=lru_cache(None)\r\nfrom heapq import *\r\nfrom itertools import *\r\nfrom math import inf\r\nfrom pprint import pprint as pp\r\nenum=enumerate\r\nri=lambda:int(rln())\r\nris=lambda:list(map(int,rfs()))\r\nrln=sys.stdin.readline\r\nrl=lambda:rln().rstrip('\\n')\r\nrfs=lambda:rln().split()\r\nmod=1000000007\r\nd4=[(0,-1),(1,0),(0,1),(-1,0)]\r\nd8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]\r\n########################################################################\r\n\r\nn=ri()\r\na=ris()\r\nprint(max(Counter(a).values()))\r\n",
"from statistics import mode\r\nn = int(input())\r\nli = list(map(int,input().split()))\r\nprint(li.count(max(set(li), key = li.count)))",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nprint(max(l.count(i) for i in l))\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))[:n]\r\ncount=[0 for i in range(101)]\r\nfor i in l:\r\n count[i]=count[i]+1\r\nprint(max(count))",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nr=0\r\nfor i in range(len(a)):\r\n if a.count(a[i])>r:\r\n r=a.count(a[i])\r\nprint(r)\r\n",
"from collections import Counter\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nx=Counter(l)\r\nprint(x.most_common(1)[0][1])",
"import sys\r\nsys.setrecursionlimit(100000000)\r\ninput=lambda:sys.stdin.readline().strip()\r\nwrite=lambda x:sys.stdout.write(str(x)+'\\n')\r\n\r\n# from random import randint\r\n# from copy import deepcopy\r\nfrom collections import deque,Counter\r\n# from heapq import heapify,heappush,heappop\r\n# from bisect import bisect_left,bisect,insort\r\n# from math import inf,sqrt,gcd,ceil,floor,log,log2,log10,pi\r\n# from functools import cmp_to_key\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nb=Counter(a)\r\nprint(max(b.values()))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nd={}\r\nfor i in a:\r\n if i in d:\r\n d[i]=d[i]+1\r\n else:\r\n d[i]=1\r\nc=max(d.values())\r\nprint(c)",
"# Polycarp's Pockets\ndef pockets(arr):\n di = {}\n for i in arr:\n if i in di:\n di[i] += 1\n else:\n di[i] = 1\n big = 0\n for i in di:\n big = max(di[i], big)\n return big\n \n\n\nn = int(input())\narr = list(map(int, input().rstrip().split()))\nprint(pockets(arr))",
"from collections import Counter\r\nn=int(input())\r\na=Counter(list(map(int,input().split())))\r\nmaa=0\r\nfor key,cont in a.items():\r\n if cont>maa:\r\n maa=cont\r\nprint(maa)",
"import sys\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\ndef iinput(): return int(input())\r\ndef rinput(): return map(int, sys.stdin.readline().strip().split()) \r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split())) \r\n\r\n\r\nn=iinput()\r\ns=list(map(int,input().split()))\r\nl=list(set(s))\r\na=[]\r\nfor i in range(len(l)):\r\n a.append(s.count(l[i]))\r\n\r\nprint(max(a))",
"coins = int(input())\r\narray = list(map(int, input().split()))\r\ncounter = 1\r\nmaxPockets = 1\r\n\r\nfor i in array:\r\n \r\n if array.count(i) == 1:\r\n continue\r\n else:\r\n counter = array.count(i)\r\n if counter >= maxPockets:\r\n maxPockets = counter\r\n \r\nprint(maxPockets)",
"n = int(input())\na = list(map(int, input().split()))\na = sorted(a)\nlen = 1\nlenmax = 1\nfor i in range(1, n):\n if a[i] != a[i - 1]:\n lenmax = max(lenmax, len)\n len = 1\n else:\n len += 1\nlenmax = max(lenmax, len)\nprint(lenmax)\n",
"# A. Polycarp's Pockets\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ns=set(a)\r\nl=[]\r\nfor x in s:\r\n l.append(a.count(x))\r\nprint(max(l))",
"n=int(input())\r\nl=[int(i) for i in input().split()]\r\nl.sort()\r\nc,m=1,1\r\nfor i in range(len(l)-1):\r\n if l[i]==l[i+1]:\r\n c+=1\r\n else:\r\n m=max(m,c) \r\n c=1\r\nm=max(m,c) \r\nprint(m)\r\n ",
"from collections import Counter\r\nn=int(input())\r\nli=list(map(int,input().split()))\r\ndic={}\r\nc=Counter(li)\r\n# print(c)\r\nmax=0\r\ndic=c\r\n# print(dic.values())\r\nfor i in dic.values():\r\n if(i>max):\r\n max=i\r\nprint(max)",
"n = int(input())\r\na = list(map(int,input().split()))\r\nq = 0\r\nfor i in range(n):\r\n f = 0\r\n for j in range(n):\r\n if a[i] == a[j] and i != j:\r\n f += 1\r\n if q < f:\r\n q = f\r\nprint(q + 1)",
"n = int(input())\r\ncoins = list(map(int, input().split()))\r\ncoins_count = {}\r\nfor coin in coins:\r\n if coin in coins_count:\r\n coins_count[coin] += 1\r\n else:\r\n coins_count[coin] = 1\r\nmax_count = max(coins_count.values())\r\nprint(max_count)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=list(set(a))\r\nc=1\r\nfor i in s:\r\n m=a.count(i)\r\n if c<m:\r\n c=m\r\nprint(c)",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nans = [arr.count(i) for i in arr]\r\nprint(max(ans))\r\n",
"\r\nimport sys\r\ninput = sys.stdin.buffer.readline\r\n\r\nn=int(input())\r\narr=[int(x) for x in input().split()]\r\nd={}\r\nfor i in arr:\r\n if i in d:\r\n d[i]=d[i]+1\r\n else:\r\n d[i]=1\r\n\r\nm=max(d.values())\r\nprint(m)",
"n = int(input())\r\narr = list(map(int,input().split()))\r\n\r\ndit = {}\r\nval = []\r\nfor i in arr:\r\n dit.update({i:arr.count(i)})\r\n val.append(arr.count(i))\r\nmx = max(val)\r\nans = 0\r\nfor k,v in dit.items():\r\n if v==mx:\r\n ans=v\r\nprint(ans)",
"n = int(input())\nrepeticoes = {}\nfor coin in input().split():\n if coin not in repeticoes:\n repeticoes[coin] = 0\n repeticoes[coin] += 1\n\nmaior_repeticao = 0\nfor coin in repeticoes.keys():\n if repeticoes[coin] > maior_repeticao:\n maior_repeticao = repeticoes[coin]\n\nprint(maior_repeticao)\n \t \t \t \t \t \t\t \t \t\t",
"n = int(input())\r\na = list(map(int,input().split()))\r\ns = set(a)\r\nmaxi = 0\r\nfor i in s:\r\n if a.count(i) >= maxi:\r\n maxi = a.count(i)\r\nprint(maxi)",
"n = int(input())\narr = [int(_) for _ in input().split()]\n\nc = 0\n\nfor num in arr:\n if arr.count(num) > c:\n c = arr.count(num)\n\nprint(c)",
"n = int(input())\na = list(map(int, input().split()))\np = [0 for i in range(100)]\nfor coin in a:p[coin-1] += 1\nprint(max(p))\n\n \t \t \t\t\t\t \t\t\t \t\t \t \t \t",
"n=int(input())\r\na=list(map(int,input().split()))\r\nd = {}\r\nmx=0\r\nfor i in a:\r\n if i in d: d[i] += 1\r\n else: d[i]=1\r\n mx=max(mx,d[i])\r\nprint(mx)",
"# import sys\r\n# sys.stdout = open('DSA/Stacks/output.txt', 'w')\r\n# sys.stdin = open('DSA/Stacks/input.txt', 'r')\r\n\r\n\r\nn = int(input())\r\nll = list(map(int, input().split()))\r\nd = {x: ll.count(x) for x in ll}\r\nz = max(list(d.values()))\r\nif z == 1:\r\n print(1)\r\nelse:\r\n print(z)\r\n",
"n=int(input())\r\na=list(map(str,input().split()))\r\nx=[a.count(i) for i in a]\r\nprint(max(x))\r\n",
"t=int(input())\r\nlst=list(map(int,input().split()))\r\nd={}\r\nfor i in lst:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i]=1\r\nprint(max(d.values()))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=0\r\nk=set(l)\r\nfor i in k:\r\n if l.count(i)>m:\r\n m=l.count(i)\r\nprint(m)\r\n",
"n=int(input())\r\nl=[int(x) for x in input().split()]\r\ns=set(l)\r\nt=[]\r\nfor i in s:\r\n t.append(l.count(i))\r\nprint(max(t))",
"n=int(input())\r\nlist1=list(map(int,input().split()))\r\nmax=0\r\nfor x in list1:\r\n a=list1.count(x)\r\n if a>max:\r\n max=a\r\nprint(max)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nd = {}; mx = 0\r\nfor i in range(n):\r\n d[a[i]] = d.get(a[i],0) + 1\r\n if d[a[i]] > mx:\r\n mx = d[a[i]]\r\nprint(mx)",
"import statistics\r\nn=int(input())\r\nw=input()\r\nw=w.split()\r\na=[]\r\nfor i in range(n):\r\n a.append(int(w[i]))\r\nx=statistics.mode(a)\r\nk=0\r\nfor i in range(n):\r\n if a[i]==x:\r\n k+=1\r\nprint(k)",
"n=int(input())\r\nx=list(map(int,input().strip().split(' ')))\r\n\r\nc=0\r\nfor i in range(n):\r\n if x[i]>0:\r\n z=x[i]\r\n t=0\r\n for j in range(i,n):\r\n if x[j]==z:\r\n t+=1\r\n x[j]=0\r\n if t>c:\r\n c=t\r\n\r\nprint(c)\r\n \r\n \r\n",
"from collections import Counter\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nc=Counter(l)\r\nprint(max(c.values()))",
"n=int(input())\r\nl=[int(i) for i in input().split()]\r\nans=[]\r\nfor i in l:\r\n ans.append(l.count(i))\r\nprint(max(ans))",
"n=int(input())\r\nd={}\r\ns=list(map(int,input().split()))\r\nfor i in s:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i]=1\r\nprint(max(d.values()))\r\n",
"n=int(input())\r\nc=list(map(int,input().split()))\r\ncount1=[]\r\nfor i in c:\r\n a=c.count(i)\r\n count1.append(a)\r\nprint(max(count1))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nmaxi=0\r\nfor i in list(set(l)):\r\n c=l.count(i)\r\n maxi=max(maxi,c)\r\nprint(maxi)",
"# cook your dish here\r\n\r\n#from math import factorial, ceil, pow, sqrt, floor, gcd\r\nfrom sys import stdin, stdout\r\nfrom collections import defaultdict, Counter, deque\r\n#from bisect import bisect_left, bisect_right\r\n#import sympy\r\n#from itertools import permutations\r\n#import numpy as np\r\n\r\n# n = int(stdin.readline())\r\n# stdout.write(str())\r\n# s = stdin.readline().strip('\\n')\r\n# map(int, stdin.readline().split())\r\n# l = list(map(int, stdin.readline().split()))\r\n\r\nn = int(stdin.readline())\r\nl = list(map(int, stdin.readline().split()))\r\nd = dict(Counter(l))\r\nm = 0\r\nfor i, j in d.items():\r\n m = max(m, j)\r\nprint(m)",
"from collections import Counter\r\nn=input()\r\nl=[int(i) for i in input().split()]\r\nc=Counter(l)\r\nprint(c.most_common(1)[0][1])",
"from sys import stdin, stdout\r\ninput, print = stdin.readline, stdout.write\r\n\r\n\r\ndef str_input():\r\n s = input()\r\n return s[:len(s)-1]\r\n\r\n\r\ndef char_list_input():\r\n s = input()\r\n return list(s[:len(s)-1])\r\n\r\n\r\ndef list_input(type):\r\n return list(map(type, input().split()))\r\n\r\n\r\ndef multi_input():\r\n return map(int, input().split())\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n a = list_input(int)\r\n ans = 0\r\n for i in range(1, 101):\r\n ans = max(ans, a.count(i))\r\n print(f\"{ans}\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"def most_frequent(list1):\r\n\tcounter=0\r\n\tnum=list1[0]\r\n\t\r\n\tfor i in list1:\r\n\t\tcurrent_frequency=list1.count(i)\r\n\t\tif current_frequency>counter:\r\n\t\t\tcounter=current_frequency\r\n\t\t\tnum=i\r\n\treturn counter\r\n\r\nn=int(input())\r\nlist1=list(map(int,input().split()))\r\nprint(most_frequent(list1))\r\n",
"n = int(input())\r\nL = input().split()\r\nL = [int(i) for i in L]\r\n\r\nfre = {}\r\nfor coin in L:\r\n if coin in fre:\r\n fre[coin] += 1\r\n else:\r\n fre[coin] = 1\r\n \r\n#check for max frequency\r\nmax_freq = 0\r\nfor key,val in fre.items():\r\n if val > max_freq:\r\n max_freq = val\r\nprint(max_freq)",
"#!/usr/bin/env python\n\nimport math\nimport sys\nimport itertools\nimport fractions\n\nif __name__ == '__main__':\n wtf = sys.stdin.read()\n wtf = wtf.strip().split('\\n')\n n = int(wtf[0])\n A = list(map(int, wtf[1].split()))\n tmp = [0] * 101\n for a in A:\n tmp[a] += 1\n print(max(tmp))\n",
"n=int(input())\r\na=input()\r\na1=a.split()\r\nfor i in range(n):\r\n a1[i]=int(a1[i])\r\nb=[] #unique\r\nc=[] #frequency\r\nfor i in range(n):\r\n if a1[i] not in b:\r\n b.append(a1[i])\r\n c.append(1)\r\n else:\r\n p=b.index(a1[i])\r\n c[p]=c[p]+1\r\nprint(max(c))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\na=sorted(a)\r\nc=1\r\nf=1\r\nfor i in range(0,n-1):\r\n if a[i]==a[i+1]:\r\n c=c+1\r\n if c>f:\r\n f=c\r\n else:\r\n c=1\r\n\r\nprint(f)\r\n",
"from collections import Counter \r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nx = Counter(arr)\r\nprint(max(x.values()))",
"#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-15 23:54:48\nLastEditTime: 2021-11-16 00:00:12\nDescription: Polycarp's Pockets\nFilePath: CF1003A.py\n'''\n\n\ndef func():\n _ = int(input())\n lst = list(map(int, input().strip().split()))\n maximum = 0\n for item in set(lst):\n count = lst.count(item)\n if maximum < count:\n maximum = count\n print(maximum)\n\n\nif __name__ == '__main__':\n func()\n",
"def mode(sample):\r\n if len(sample) == 0:\r\n return None\r\n else:\r\n return max(set(sample), key=sample.count)\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nm = mode(a)\r\n\r\nprint(a.count(m))",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nl = sorted(l)\r\ns = set(l)\r\nmax1 = 0\r\nfor i in s:\r\n if(l.count(i)>max1):\r\n max1 = l.count(i)\r\nprint(max1)",
"n = int(input())\r\narr = sorted(list(map(int, input().split())))\r\ncnt = 1\r\nx = 1\r\nfor i in range(n-1):\r\n if arr[i] != arr[i+1]:\r\n if cnt > x:\r\n x = cnt\r\n cnt = 1\r\n else:\r\n cnt += 1\r\nif cnt > x:\r\n x = cnt\r\nprint(x)",
"n = int(input())\r\nx = [int(x) for x in input().split()]\r\nm = list(set(x))\r\nl = [x.count(m[i]) for i in range(len(m))]\r\nprint(max(l))",
"n = int(input())\r\ndit={}\r\narr=list(map(int,input().split()))\r\nm=0\r\nfor e in arr:\r\n if e not in dit:\r\n dit[e]=0\r\n dit[e]+=1\r\n m=max(m,dit[e])\r\nprint(m)\r\n",
"from typing import Counter\r\n\r\n\r\nn = int(input())\r\narr = Counter(map(int, input().split()))\r\nprint(max(arr.values()))",
"def main():\n\tn = int(input())\n\tx = list(map(int,input().split()))\n\tdict1 = {}\n\tfor i in x:\n\t\tif i in dict1.keys():\n\t\t\tdict1[i] +=1\n\t\telse:\n\t\t\tdict1[i] =1\n\tprint(max(dict1.values()))\nmain()\n",
"n = int(input())\r\ns = list(map(int, input().split()))\r\nd = set(s)\r\nminimum = 0\r\nfor i in d:\r\n if s.count(i) > minimum:\r\n minimum = s.count(i)\r\nprint(minimum)",
"n = int(input())\r\na = map(int, input().split())\r\nd = {}\r\n\r\nfor i in a:\r\n if i in d:\r\n d[i] += 1\r\n else:\r\n d[i] = 1\r\nprint(max(d.values()))\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nans = 0\r\nk = set(l)\r\n\r\nfor i in k:\r\n c = l.count(i)\r\n if c > ans:\r\n ans = c\r\n else:\r\n continue\r\n\r\nprint(ans)",
"n = int(input())\r\nb = [int(x) for x in input().split()]\r\nd = {}\r\nfor i in b:\r\n if i not in d:\r\n d[i] = 0\r\n d[i] += 1\r\nprint(max(d.values()))",
"n=int(input())\r\na=list(map(int,input().split()))\r\na1=list(set(a))\r\nans=0\r\nfor x in range(len(a1)):\r\n if a.count(a1[x])>ans:\r\n ans=a.count(a1[x])\r\nprint(ans)",
"n = int(input())\r\nA = list(map(int,input().split()))\r\ncnt = [0 for i in range(max(A)+1)]\r\nans = 0\r\nfor i in A:\r\n cnt[i]+=1\r\n ans = max(cnt[i],ans)\r\nprint(ans)",
"n = int(input())\r\ncoins = input().split()\r\nans = 0\r\nfor i in coins:\r\n ans = max(ans, coins.count(i))\r\nprint(ans)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nmp = {}\r\n\r\nfor x in arr:\r\n if x in mp:\r\n mp[x] += 1\r\n else:\r\n mp[x] = 1\r\n\r\nc = max(mp.values())\r\nprint(c)\r\n",
"a=int(input())\r\nc=[]\r\nb=list(map(int,input().split()))\r\nfor i in b:\r\n c.append(b.count(i))\r\nprint(max(c))\r\n",
"coin = int(input())\nlist = [int(x) for x in input().split()][:coin]\ncount = {}\nminPocket = 0\nfor i in range(coin):\n\tif list[i] not in count:\n\t\tcount[list[i]] = 1\n\telse:\n\t\tcount[list[i]] += 1\n\tif count[list[i]] > minPocket:\n\t\tminPocket = count[list[i]]\nprint(minPocket)\n\n \t \t \t\t\t \t \t\t \t\t \t \t\t",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nb = set(a)\r\nb = list(b)\r\nmax = 0\r\n\r\nfor i in range(len(b)):\r\n sum1 = 0\r\n for j in range(n):\r\n if b[i] == a[j]:\r\n sum1 += 1\r\n if sum1 > max:\r\n max = sum1\r\n\r\nprint(max)",
"n = int(input())\r\nlst = list(map(int,input().strip().split()))[:n]\r\nval = 0\r\nfor i in lst:\r\n x = lst.count(i)\r\n val = max(val,x)\r\nprint(val)",
"from collections import defaultdict\r\nd=defaultdict(int)\r\nm=0\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nfor i in range(n):\r\n d[arr[i]]+=1\r\nfor j in d:\r\n if d[j]>m:\r\n m=d[j]\r\nprint(m)",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\nmax_ans = 0\r\ns = set(a)\r\nfor i in s:\r\n if a.count(i) > max_ans:\r\n max_ans = a.count(i)\r\nprint(max_ans)",
"n=int(input())\r\nd=[0]*n\r\nl=[int(i) for i in input().split()]\r\nfor i in l:\r\n d[l.index(i)]+=1\r\nprint(max(d))\r\n",
"from collections import Counter\r\nn = int(input())\r\na = sorted(list(map(int,input().split())))\r\nprint(max((Counter(a)).values()))",
"from collections import Counter as c\r\nn= int(input())\r\narr = list(map(int, input().split()))\r\na = c(arr)\r\nb = max([value for value in a.values()])\r\nprint(b)",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\ni=0\r\ncount=0\r\nwhile i<n:\r\n num=a.count(a[i])\r\n i+=num\r\n if num>count:\r\n count=num\r\nprint(count)",
"import sys\r\nfrom collections import Counter\r\n\r\ndef main():\r\n return Counter(sys.stdin.read().strip().split('\\n')[1].split()).most_common(1)[0][1]\r\n\r\nprint(main())\r\n",
"n=int(input())\r\narr=[int(i) for i in input().split()]\r\nmaxi=0\r\nfor i in set(arr):\r\n if arr.count(i)>maxi:\r\n maxi=arr.count(i)\r\nprint(maxi)",
"a = int(input())\r\ns = list(map(int, input().split()))\r\nc = []\r\nfor i in range(a):\r\n c.append(s.count(s[i]))\r\nprint(max(c))",
"a = int(input())\r\nb = [*map(int, input().split())]\r\nprint(max(b.count(i) for i in b))\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb={}\r\nfor i in a:\r\n\tif i in b.keys():\r\n\t\tb[i]+=1\r\n\telse:\r\n\t\tb[i]=1\r\nprint(max(b.values()))",
"input()\na = list(map(int, input().split()))\nm = 0\nd = {}\nfor item in a:\n d[item] = d.get(item, 0) + 1\n m = max(m, d[item])\nprint(m)\n",
"#import sys\r\n#import math\r\n#sys.stdout=open(\"C:/Users/pipal/OneDrive/Desktop/VS code/python/output.txt\",\"w\")\r\n#sys.stdin=open(\"C:/Users/pipal/OneDrive/Desktop/VS code/python/input.txt\",\"r\")\r\n#t=int(input())\r\n#for i in range(t): \r\n#n,m=map(int,input().split())\r\nn=int(input())\r\nc=0\r\nans=0\r\nl=list(map(int,input().split()))\r\nfor i in l:\r\n ans=max(ans,l.count(i))\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n ",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nmax_pocket = max([a.count(i) for i in a])\r\n\r\nprint(max_pocket)\r\n",
"from collections import Counter\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nd=Counter(l)\r\nprint(max(d.values()))\r\n",
"n=int(input())\r\nlst = map(int,input().split())\r\nd={}\r\nm=0\r\nfor i in lst:\r\n if i in d:\r\n d[i]+=1\r\n else:\r\n d[i]=1\r\nfor i in d:\r\n m = max(m,d[i])\r\nprint(m)",
"t=int(input())\r\nl=[int(i) for i in input().split()]\r\nk=list(set(l))\r\np=[]\r\nfor j in range(len(k)):\r\n p.append(l.count(k[j]))\r\nprint(max(p))",
"length = int(input())\ncoins = list(map(int, input().split()))\nprint(max([coins.count(i) for i in set(coins)]))",
"import math\nimport itertools\nfrom sys import stdin\nfrom functools import reduce\nfrom collections import deque\nfrom sys import setrecursionlimit\nfrom collections import defaultdict\nimport heapq\n# setrecursionlimit(10**7)\ninput = stdin.readline\ndef I():return int(input())\ndef IN():return map(int,input().split())\ndef LI():return list(map(int,input().split()))\ndef LIN(N):return [list(map(int,input().split())) for _ in range(N)]\n\ngcd = math.gcd\nInf = float(\"Inf\")\n\n\n\n\ndef solve():\n n = I() # number of coins \n coins = LI() \n mp = {}\n for coin in coins:\n mp[coin] = mp.get(coin, 0) + 1\n print(max(mp.values()))\n\ndef main():\n t = 1\n # t = I() \n for i in range(1, t+1):\n solve()\nif __name__ == '__main__':\n main()\n",
"# Hydro submission #6151cb01e1e9420537150a48@1632750338314\nn = int(input())\r\narr = input()\r\narr = [int(value) for value in arr.split(' ')]\r\n\r\n\r\ndef Polycarp_Pockets(a: [int]):\r\n count, count2, number = 0, 0, 0\r\n for i in range(len(a)):\r\n number = a[i]\r\n for j in range(len(a)):\r\n if a[j] == number:\r\n count += 1\r\n if count2 < count:\r\n count2 = count\r\n count = 0\r\n return count2\r\n\r\n\r\nprint(Polycarp_Pockets(arr))",
"n = int(input())\r\nv = sorted(list(map(int, input().split())))\r\nctr, max_ctr = 1, 1\r\nfor i in range(1, n):\r\n\tif v[i] == v[i-1]:\r\n\t\tctr += 1\r\n\t\tif ctr > max_ctr:\r\n\t\t\tmax_ctr += 1\r\n\telse:\r\n\t\tctr = 1\r\nprint(max_ctr)",
"numberCoins = input()\r\nvalueCoins = input().split(\" \")\r\nlargest = 0\r\nfor i in range(len(valueCoins)):\r\n numberValue = valueCoins.count(valueCoins[i])\r\n if numberValue > largest:\r\n largest = numberValue\r\nprint(largest)",
"n = int(input())\r\na = [int(s) for s in input().split()]\r\na.sort()\r\ncount = 1\r\nmax = 1\r\nfor i in range(len(a) - 1):\r\n if a[i] == a[i + 1]:\r\n count += 1\r\n else:\r\n if count > max:\r\n max = count\r\n count = 1\r\nif count > max:\r\n print(count)\r\nelse:\r\n print(max)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nd={}\r\nfor i in l:\r\n d[i]=d.get(i,0)+1\r\nv=d.values()\r\nprint(max(v))",
"n = int(input())\r\nnlist = list(map(int, input().split()))\r\ndict1 = {}\r\nfor i in nlist:\r\n if i not in dict1:\r\n dict1[i] = 1\r\n else:\r\n dict1[i] += 1\r\nlist1 = []\r\nfor i in dict1.values():\r\n list1.append(i)\r\n\r\nlist1.sort(reverse = 1)\r\nprint(list1[0])\r\n\r\n",
"from collections import deque\r\nimport os, io\r\n#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\nt = 1#int(input())\r\n\r\nfor _ in range(t):\r\n n = int(input())\r\n d = list(map(int,input().split()))\r\n cnt = [0] * 101\r\n for i in d:\r\n cnt[i] += 1\r\n print(max(cnt))\r\n",
"from collections import defaultdict\r\nimport sys\r\n \r\n\r\nfrom bisect import bisect_left, bisect_right\r\ndef is_sorted(l):\r\n return all(a <= b for a, b in zip(l, l[1:]))\r\ndef lower_bound(a, x):\r\n i = bisect_left(a, x)\r\n if i:\r\n return (i-1)\r\n else:\r\n return i\r\ndef upper_bound(a, x):\r\n i = bisect_right(a, x)\r\n if i != 0:\r\n return (i)\r\n else:\r\n return -1\r\ndef is_sorted(l):\r\n return all(a <= b for a, b in zip(l, l[1:]))\r\ndef generate_grid(n,m,default=0):\r\n dp=[]\r\n for i in range(n):\r\n dp.append([default]*m)\r\n return dp\r\ninput = sys.stdin.readline\r\nn=int(input())\r\nlst=list(map(int,input().split()))\r\nd=defaultdict(int)\r\nfor i in range(n):\r\n d[lst[i]]+=1\r\ncnt=0\r\nfor i in d:\r\n cnt=max(d[i],cnt)\r\nprint(cnt)",
"freq = [0 for _ in range(101)]\r\nn = int(input())\r\nfor x in [int(x) for x in input().split()]:\r\n freq[x] += 1\r\n\r\nprint(max(freq))",
"from collections import Counter\r\nl=int(input())\r\nl1=[int(i) for i in input().split()]\r\ns=Counter(l1)\r\nval=list(s.values())\r\nprint(max(val))\r\n",
"#from math import gcd\r\nfrom collections import Counter\r\n#t=int(input())\r\n#or q in range(t):\r\nn=int(input())\r\n #x,y,a,b=map(int,input().split())\r\na=list(Counter(list(map(int,input().split()))).values())\r\na.sort()\r\nprint(a[len(a)-1])\r\n \r\n",
"t=int(input())\r\nlm=[]\r\nls=list(map(int,input().split()))\r\nfor m in ls:\r\n lm.append(ls.count(m))\r\nprint(max(lm))",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\na.sort()\r\na.append(0)\r\nres,count=1,1 \r\nfor i in range(1,len(a)):\r\n if a[i]==a[i-1]:\r\n count+=1 \r\n else:\r\n if count>res:\r\n res=count \r\n count=1 \r\nprint(res)",
"n = input()\r\narr = list(map(int, input().split()))\r\narrS = set(arr)\r\nc=0\r\nfor x in arrS:\r\n y = arr.count(x)\r\n if y>c:\r\n c=y\r\nprint(c)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=[]\r\nfor i in range(n):\r\n b.append(a.count(a[i]))\r\nprint(max(b))",
"n = int(input())\narray = list(map(int, input().split()))\nhash_map = {}\nfor x in array:\n if x not in hash_map:\n hash_map[x] = 1\n else:\n hash_map[x] += 1\nprint(max(hash_map.values()))\n",
"from collections import defaultdict\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n \r\n mp = defaultdict(int)\r\n for num in a:\r\n mp[num] += 1\r\n \r\n mx = max(mp.values())\r\n print(mx)",
"n = int(input())\r\n\r\nn_list = [int(i) for i in input().split()]\r\n\r\nmax_count = 0\r\nfor i in range(len(n_list)):\r\n if n_list.count(n_list[i]) > max_count:\r\n max_count = n_list.count(n_list[i])\r\n\r\nprint(max_count)",
"n = int(input())\r\nli = list(map(int,input().split()))\r\nli1 = [li.count(i) for i in set(li)]\r\nprint(max(li1))",
"input()\r\na=[*map(int,input().split())]\r\nprint(max(a.count(i)for i in a))",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Mar 30 23:06:43 2021\r\n\r\n@author: nagan\r\n\"\"\"\r\n\r\nn = int(input())\r\ns = input().split()\r\nl = [int(i) for i in s]\r\nc = 1\r\nfor i in l:\r\n if l.count(i) > c:\r\n c = l.count(i)\r\nprint(c)",
"from collections import defaultdict\r\ndef sol(n,l):\r\n d=defaultdict(int)\r\n m=0\r\n for i in l:\r\n d[i]+=1\r\n m=max(m,d[i])\r\n return m\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nprint(sol(n,l))\r\n \r\n",
"n=int(input())\r\nx=[int(w) for w in input().split()]\r\na=0\r\nm=[]\r\nfor i in set(x):\r\n m.append(x.count(i))\r\nprint(max(m))",
"from collections import Counter\r\nn = int(input())\r\ncoins = input().split()\r\nmax_freq = 0\r\nhashmap = Counter(coins)\r\nfor freq in hashmap.values():\r\n max_freq = max(max_freq, freq)\r\nprint(max_freq)",
"n = int(input())\nli = list(map(int,input().split()))\nz = max(li.count(x) for x in li)\nprint(z)\n\n",
"a = int(input());b = list(map(int,input().split()))\r\nemptylist = []\r\nfor i in b:\r\n emptylist+=[b.count(i)]\r\nprint(max(emptylist))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nrepeats = [0] * n\r\nmax_repeats = 0\r\nfor i in range(n):\r\n\trepeats[i] = a.count(a[i])\r\n\tif repeats[i] > max_repeats:\r\n\t\tmax_repeats = repeats[i]\r\nprint(max_repeats)",
"from typing import Counter\r\nn, li = int(input()), map(int, input().split())\r\ncount = Counter(li)\r\nprint(max(count.values()))",
"from collections import Counter\nn = input()\narr = list(map(int,input().split()))\nprint(Counter(arr).most_common(1)[0][1])\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nmax=0\r\nfor i in range(n):\r\n c=0\r\n for j in range(n):\r\n if(a[i]==a[j]):\r\n c=c+1\r\n if(c>max):\r\n max=c\r\nprint(max)\r\n",
"# Author: S Mahesh Raju\r\n# Username: maheshraju2020\r\n# Date: 07/07/2020\r\n\r\nfrom sys import stdin,stdout\r\nfrom math import gcd, ceil, sqrt\r\nfrom collections import Counter\r\nii1 = lambda: int(stdin.readline().strip())\r\nis1 = lambda: stdin.readline().strip()\r\niia = lambda: list(map(int, stdin.readline().strip().split()))\r\nisa = lambda: stdin.readline().strip().split()\r\nmod = 1000000007\r\n\r\nn = ii1()\r\narr = iia()\r\npocket = [set()]\r\nfor i in arr:\r\n for j in pocket:\r\n if i not in j:\r\n j.add(i)\r\n break\r\n else:\r\n pocket.append(set([i]))\r\nprint(len(pocket))\r\n",
"from sys import *\r\n\r\ninput = stdin.readline\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nv = list(set(a))\r\nans = []\r\nfor i in v:\r\n ans.append(a.count(i))\r\nprint(max(ans))\r\n\r\n",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nn=a.count(a[0])\r\nfor i in a:\r\n m=a.count(i)\r\n if m>n:\r\n n=m\r\nprint(n)",
"from collections import defaultdict\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ncnt = defaultdict(lambda : 0)\r\nfor i in a:\r\n cnt[i] += 1\r\nans = 0\r\nfor i in cnt:\r\n ans = max(ans, cnt[i])\r\nprint(ans)",
"n = int(input())\r\nlst = []\r\nline = input()\r\nlst = line.split()\r\nconverint = map(int,lst)\r\nintlist = list(converint)\r\ncntlist = []\r\n#print(intlist)\r\nfor i in range(n):\r\n cnt = intlist.count(intlist[i])\r\n cntlist.append(cnt)\r\n\r\nprint(max(cntlist))\r\n\r\n ",
"n = int(input())\r\nw = [int(i) for i in input().split()]\r\nprint(w.count(max(w, key=w.count)))",
"\"\"\"n,k=map(int,input().split())\nl=list(map(int,input().split()))\nini=sum(l[:k:])\nmaxans=float(ini/k)\ni=k\nm=0\nwhile(i<n):\n\tini+=l[i]\n\tini-=l[m]\n\tm+=1\n\ti+=1\n\tif(float(ini/k)>maxans):\n\t\tmaxans=float(ini/k)\nprint(maxans)\"\"\"\n\nn=int(input())\nl=list(map(int,input().split()))\na=[0]*100\nmax1=0\nfor i in l:\n\ta[i-1]+=1\n\tif(a[i-1]>max1):\n\t\tmax1=a[i-1]\nprint(max1)\n",
"from collections import Counter\nn = int(input())\nlis = list(map(int, input().split()))\ncounter = Counter(lis)\nprint(max(list(counter.values())))\n",
"import collections\nn = int(input())\nl = list(map(int, input().split()))\nprint(max(collections.Counter(l).values()))",
"from collections import defaultdict\r\nn=int(input())\r\nd=defaultdict(int)\r\narr=list(map(int,input().split()))\r\nfor i in arr:\r\n d[i]+=1\r\nprint(max(d.values()))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nmax=0\r\nc=0\r\nfor i in l:\r\n if l.count(i)>max:\r\n max=l.count(i)\r\nprint(max)",
"n=input()\r\ns=list(map(int,input().split()))\r\ncoun=0\r\nfor i in s:\r\n if s.count(i)>coun:\r\n coun=s.count(i)\r\nprint(coun)",
"from collections import Counter\r\n\r\n\r\ndef solve(n, m):\r\n\r\n c = Counter(m)\r\n return c.most_common(1)[0][1]\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n, m = int(input()), input().split()\r\n print(solve(n, m))",
"input()\nlst = list(map(int, input().split()))\n_1st = max(lst.count(item) for item in set(lst))\nprint(_1st)\n\n\t\t \t \t\t \t \t \t \t \t\t \t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\ny = 0\r\n\r\nfor i in range(len(a)):\r\n x = a.count(a[i])\r\n if x > y:\r\n y = x\r\n\r\nprint(y)",
"a = input()\r\ncoins = [int(x) for x in input().split()]\r\nnumbers = dict()\r\n\r\nfor d in coins:\r\n if d in numbers:\r\n numbers[d] += 1\r\n else:\r\n numbers[d] = 1\r\npockets = 0\r\nfor v in numbers.values():\r\n if v > pockets:\r\n pockets = v\r\nprint(pockets)\r\n",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\n\r\nm = max(set(lst), key=lst.count)\r\n\r\nprint(lst.count(m))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl1,c=[],1 \r\nl.sort()\r\nfor i in range(n-1):\r\n if l[i]==l[i+1]:\r\n c+=1 \r\n else:\r\n l1.append(c)\r\n c=1 \r\nl1.append(c)\r\nprint(max(l1))",
"while True:\r\n try:\r\n s = input()\r\n l = list(map(int, input().split(' ')))\r\n if len(l) == len(set(l)):\r\n print(1)\r\n continue\r\n m = 0\r\n for i in l:\r\n m = max(m, l.count(i))\r\n if m == 1:\r\n print(1)\r\n else:\r\n print(m)\r\n except:\r\n break",
"from collections import Counter\r\n\r\nn = int(input())\r\na = Counter(input().split())\r\nprint(a.most_common()[0][1])",
"\r\nn = int(input())\r\n#(2 ** k - 1) * x = n\r\na = list(map(int,input().split()))\r\nans = -1\r\ni = 0\r\nfor i in range(n):\r\n tmp = a.count(a[i])\r\n if tmp > ans:\r\n ans = tmp\r\n\r\nprint(ans)",
"a=int(input())\r\ns=list(map(int,input().split()))\r\nprint(max(s.count(i) for i in s))",
"from collections import Counter\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nc=Counter(l)\r\nx=[c[i] for i in c]\r\nprint(max(x))",
"n = int(input())\n \ncoins = list(map(int,input().strip().split()))[:n]\n \nduplicateFrequencies = {}\nfor i in set(coins):\n duplicateFrequencies[i] = coins.count(i)\n\nprint(max(duplicateFrequencies.values()))\n\t \t \t\t \t\t\t \t \t\t\t \t\t\t\t \t\t",
"n=int(input())\r\ninp=map(int,input().split())\r\ndict1={}\r\nfor i in inp:\r\n n=dict1.get(i,0)\r\n dict1[i]=n+1\r\nprint(max(dict1.values()))",
"n=int(input())\r\nx=[int(i) for i in input().split()]\r\nn=x.count(x[0])\r\nfor i in x:\r\n m=x.count(i)\r\n if m>n:\r\n n=m\r\nprint(n)",
"n = int(input())\r\ncoins = input().split()\r\n\r\ncoin_list = []\r\nfrequency = {}\r\ncount = 0\r\n\r\nfor coin in coins:\r\n coin = int(coin)\r\n coin_list.append(coin)\r\n \r\nfor coin in coin_list:\r\n frequency[coin] = frequency.get(coin, 0) + 1\r\n if frequency[coin] >= count:\r\n count = frequency[coin]\r\n \r\nprint(count)",
"n=int(input())\r\na=[int(x)for x in input().rstrip().split()]\r\ns=list(set(a))\r\nmx=-99999\r\nfor i in range(0,len(s)):\r\n if a.count(s[i])>mx:\r\n mx=a.count(s[i])\r\nprint(mx)\r\n \r\n \r\n \r\n"
] | {"inputs": ["6\n1 2 4 3 3 2", "1\n100", "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100\n59 47 39 47 47 71 47 28 58 47 35 79 58 47 38 47 47 47 47 27 47 43 29 95 47 49 46 71 47 74 79 47 47 32 45 67 47 47 30 37 47 47 16 67 22 76 47 86 84 10 5 47 47 47 47 47 1 51 47 54 47 8 47 47 9 47 47 47 47 28 47 47 26 47 47 47 47 47 47 92 47 47 77 47 47 24 45 47 10 47 47 89 47 27 47 89 47 67 24 71", "100\n45 99 10 27 16 85 39 38 17 32 15 23 67 48 50 97 42 70 62 30 44 81 64 73 34 22 46 5 83 52 58 60 33 74 47 88 18 61 78 53 25 95 94 31 3 75 1 57 20 54 59 9 68 7 77 43 21 87 86 24 4 80 11 49 2 72 36 84 71 8 65 55 79 100 41 14 35 89 66 69 93 37 56 82 90 91 51 19 26 92 6 96 13 98 12 28 76 40 63 29", "100\n45 29 5 2 6 50 22 36 14 15 9 48 46 20 8 37 7 47 12 50 21 38 18 27 33 19 40 10 5 49 38 42 34 37 27 30 35 24 10 3 40 49 41 3 4 44 13 25 28 31 46 36 23 1 1 23 7 22 35 26 21 16 48 42 32 8 11 16 34 11 39 32 47 28 43 41 39 4 14 19 26 45 13 18 15 25 2 44 17 29 17 33 43 6 12 30 9 20 31 24", "50\n7 7 3 3 7 4 5 6 4 3 7 5 6 4 5 4 4 5 6 7 7 7 4 5 5 5 3 7 6 3 4 6 3 6 4 4 5 4 6 6 3 5 6 3 5 3 3 7 7 6", "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "7\n1 2 3 3 3 1 2", "5\n1 2 3 4 5", "7\n1 2 3 4 5 6 7", "8\n1 2 3 4 5 6 7 8", "9\n1 2 3 4 5 6 7 8 9", "10\n1 2 3 4 5 6 7 8 9 10", "3\n2 1 1", "11\n1 2 3 4 5 6 7 8 9 1 1", "12\n1 2 1 1 1 1 1 1 1 1 1 1", "13\n1 1 1 1 1 1 1 1 1 1 1 1 1", "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 1", "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "16\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "3\n1 1 1", "3\n1 2 3", "10\n1 1 1 1 2 2 1 1 9 10", "2\n1 1", "56\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "99\n35 96 73 72 70 83 22 93 98 75 45 32 81 82 45 54 25 7 53 72 29 2 94 19 21 98 34 28 39 99 55 85 44 23 6 47 98 2 33 34 19 57 49 35 67 4 60 4 4 23 55 6 57 66 16 68 34 45 84 79 48 63 4 9 46 88 98 13 19 27 83 12 4 63 57 22 44 77 44 62 28 52 44 64 9 24 55 22 48 4 2 9 80 76 45 1 56 22 92", "10\n1 2 2 3 3 3 4 4 4 4", "99\n97 44 33 56 42 10 61 85 64 26 40 39 82 34 75 9 51 51 39 73 58 38 74 31 13 99 58 1 28 89 76 19 52 7 40 56 12 27 72 72 67 75 62 46 22 55 35 16 18 39 60 63 92 42 85 69 34 61 73 50 57 95 30 4 45 63 76 58 32 35 48 81 10 78 95 79 55 97 21 21 22 94 30 17 78 57 89 93 100 44 16 89 68 55 19 46 42 73 21", "5\n5 5 5 5 1", "6\n2 3 2 5 2 6", "3\n58 59 58", "9\n1 2 3 4 5 6 7 8 8", "97\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "3\n95 95 4", "3\n2 2 5"], "outputs": ["2", "1", "100", "100", "51", "1", "2", "10", "99", "3", "1", "1", "1", "1", "1", "2", "3", "11", "13", "14", "15", "16", "3", "1", "6", "2", "56", "6", "4", "3", "4", "3", "2", "2", "97", "2", "2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 468 | |
2e0e65d582aa86344f25fa47e856073f | Valued Keys | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
Sample Input
ab
aa
nzwzl
niwel
ab
ba
Sample Output
ba
xiyez
-1
| [
"x = [i for i in input()]\ny = [i for i in input()]\n\nz = []\n\npossible = True\n\nfor i in range(len(x)):\n if x[i] == y[i]:\n z.append('z')\n elif x[i] > y[i]:\n z.append(y[i])\n else:\n possible = False\n break\n\nif possible:\n print(\"\".join(z))\nelse:\n print(-1)\n",
"x=input()\r\ny=input()\r\nz=[]\r\nboom=0\r\nfor i in range(len(x)):\r\n if x[i]<y[i]:\r\n boom+=1\r\n elif x[i]==y[i]:\r\n z.append(\"z\")\r\n else:\r\n z.append(y[i])\r\nif boom==0:\r\n print(\"\".join(z)) \r\nelse:\r\n print(-1)",
"#!/usr/local/bin/python3\n\ndef solve(x, y):\n return -1 if any(x[i] < y[i] for i in range(len(x))) else y\n\ndef f(x, y):\n return ''.join([min(x[i], y[i]) for i in range(len(x))])\n\nif __name__ == '__main__':\n print(solve(input(), input()))\n\n\n\n",
"x, y = input(), input()\r\nfor i in range(len(x)):\r\n if x[i] < y[i]:\r\n exit(print(\"-1\"))\r\nelse:\r\n print(y)",
"a=input()\r\nb=input()\r\n\r\nfor i in range(len(a)):\r\n if(ord(a[i]) <ord(b[i])):\r\n print('-1')\r\n break\r\nelse:\r\n print(b)\r\n ",
"\ndef f(x, y):\n a = []\n for i in range(len(x)):\n if x[i] < y[i]:\n return -1\n else:\n a.append(chr(ord(y[i])))\n return ''.join(a)\n\nx = input()\ny = input()\n\nprint(f(x, y))",
"import string\r\nx = input()\r\ny = input()\r\nalph = string.ascii_lowercase\r\nans = 1\r\nfor i in range(len(y)):\r\n if x[i] < y[i]:\r\n ans = 0\r\n break\r\nif ans == 0:\r\n print(-1)\r\nelse:\r\n print(y)\r\n",
"s1=input()\r\ns2=input()\r\ns3=''\r\nflag1=0\r\nfor i in range(0,len(s1)):\r\n if s1[i]<s2[i]:\r\n flag1=1\r\n break\r\n else :\r\n s3=s3+s2[i]\r\nif flag1==0:\r\n print(s3)\r\nelse :\r\n print(\"-1\")",
"x = input()\r\ny = input()\r\n\r\nn = len(x)\r\n\r\nz = \"\"\r\nfor i in range(n):\r\n z += min(x[i], y[i])\r\n\r\nif z != y: print(-1)\r\nelse: print(z)\r\n",
"x=input()\r\nz=input()\r\nl=[]\r\nfor i in range(len(x)):\r\n if x[i]==z[i]:\r\n l.append(\"z\")\r\n elif x[i]>z[i]:\r\n l.append(z[i])\r\n else:\r\n l.append(-1)\r\nif -1 in l:\r\n print(-1)\r\nelse:\r\n print(\"\".join(l))\r\n",
"s1 = input()\r\ns2 = input()\r\nlength = len(s1)\r\n\r\nword = [0] * length\r\n\r\nfor index in range(length) :\r\n if s1[index] == s2[index] :\r\n word[index] = \"z\"\r\n elif ord(s1[index]) < ord(s2[index]) :\r\n exit(print(-1))\r\n elif ord(s1[index]) > ord(s2[index]) :\r\n word[index] = s2[index]\r\n \r\nprint(\"\".join(word))",
"import sys\r\nimport math\r\nx = list(input())\r\ny = list(input())\r\nfor i in range(len(x)):\r\n if ord(x[i]) < ord(y[i]):\r\n print(-1)\r\n sys.exit()\r\nprint(''.join(y))",
"# Much easier solution, ripped from solved ones\r\nx=input()\r\ny=input()\r\nprint(-1 if any(x[i]<y[i] for i in range(len(x)))else y)",
"s = input()\r\nt = input()\r\nres = \"\"\r\npossible = True\r\nfor i in range(len(s)):\r\n if t[i] <= s[i]:\r\n res = res + t[i]\r\n elif t[i] > s[i]:\r\n possible = False\r\n break\r\nif possible:\r\n print(res)\r\nelse:\r\n print(-1)\r\n",
"x = input()\r\nz = input()\r\ny = \"\"\r\nr = True\r\n\r\nfor i in range( len(x) ):\r\n if x[i] == z[i]:\r\n y += \"z\"\r\n elif x[i] > z[i]:\r\n y += z[i]\r\n else:\r\n r = False\r\nif r:\r\n print(y)\r\nelse:\r\n print(\"-1\")\r\n",
"import string\r\ns1=input()\r\ns2=input()\r\nfor i,j in zip(s1,s2):\r\n if i<j:\r\n print(-1)\r\n exit(0)\r\nprint(s2)\r\n ",
"x, y = input(), input()\r\nn = len(x)\r\nz = y\r\nfor i in range(n):\r\n if x[i] < y[i]:\r\n print(-1)\r\n break\r\nelse:\r\n print(''.join(z))",
"import sys\nimport collections\n\nx = sys.stdin.readline()[:-1];\nz = sys.stdin.readline()[:-1];\ny = \"\";\nfor i in range(len(x)):\n if x[i] > z[i]:\n y+=z[i];\n elif x[i] == z[i]:\n y+='z';\n elif x[i] < z[i]:\n y = -1;\n break;\n\nprint(y)\n \n\n\n\n\n\n \n \n \n \n \n \n\n \n \n \n \n\n\t \t \t \t\t\t \t\t\t \t \t \t\t\t\t\t \t",
"a= input()\r\nb= input()\r\nfor i in range (a.__len__()):\r\n if a[i] < b[i]:\r\n print(-1)\r\n exit()\r\n\r\nprint(b)\r\n",
"x = input()\ny = input()\ncan = all(ord(fst) >= ord(scd) for fst, scd in zip(x, y))\nprint(y if can else -1)\n",
"s1 = input()\r\ns2 = input()\r\n\r\nfor i, j in zip(s1, s2):\r\n if i < j:\r\n print(-1)\r\n exit()\r\n\r\nprint(s2)\r\n\r\n",
"a=input()\r\ny=input()\r\nb=\"\".join(map(min,a,y))\r\nif b!=y:\r\n\tprint(-1)\r\nelse:\r\n\tprint(b)",
"def s():\r\n X = input()\r\n Y = input()\r\n \r\n \r\n Z = ''\r\n \r\n for i in range(len(X)):\r\n x = X[i]\r\n y = Y[i]\r\n \r\n if y > x:\r\n return '-1'\r\n Z += y\r\n return Z\r\n\r\nprint(s())",
"x=input()\r\ny=input()\r\n\r\ns=''\r\nfor i in range(len(x)):\r\n\tif x[i]<y[i]:\r\n\t\ts='-1'\r\n\t\tbreak\r\n\telse:\r\n\t\ts+=y[i]\r\n\r\nprint(s)",
"a=input()\r\nb=input()\r\na=[ord(i)for i in a]\r\nb=[ord(i)for i in b]\r\nc=[]\r\nfor i in range(len(a)):\r\n if a[i]<b[i]:\r\n print(-1)\r\n exit(0)\r\n else:\r\n c+=[b[i]]\r\nprint(''.join([chr(i) for i in c]))\r\n",
"def Y(x,z) :\r\n y=\"\"\r\n for i in range(len(x)) :\r\n if z[i]<x[i] :\r\n y+=z[i]\r\n elif z[i]==x[i] :\r\n y+=x[i]\r\n else :\r\n return \"-1\"\r\n return y \r\nx,z=input(),input()\r\nprint(Y(x,z))",
"# cook your dish here\r\nx=input().strip()\r\ny=input().strip()\r\nz=[\"z\"]*len(x)\r\n#print(z)\r\nflag=0\r\nfor i in range(0,len(x)):\r\n if(x[i]<y[i]):\r\n flag=1\r\n break\r\n else:\r\n z[i]=y[i]\r\n\r\nif(flag is not 1):\r\n ans=''.join(z) \r\n print(ans)\r\nelse:\r\n print(\"-1\")\r\n\r\n\r\n",
"x=input()\nz=input()\ny=''\nfor i in range(len(x)):\n\tif z[i]>x[i]:\n\t\tprint(-1)\n\t\tbreak\n\telif z[i]==x[i]:\n\t\ty+='z'\n\telse:\n\t\ty+=z[i]\nelse:\n\tprint(y)",
"def main(x,r):\r\n y=''\r\n flag=0\r\n for i in range(len(x)):\r\n if(r[i]<=x[i]):\r\n y+=r[i]\r\n else:\r\n flag=1\r\n break\r\n if(flag==1):\r\n print(-1)\r\n else:\r\n print(y)\r\nif __name__ == \"__main__\" :\r\n x=input()\r\n r=input()\r\n main(x,r)",
"x=input()\ny=input()\nif any(d > c for c, d in zip(x, y)):\n\tprint(-1)\nelse:\n\tprint(y)\n \t\t \t \t\t\t\t\t \t \t \t \t\t \t",
"x=input()\r\nz=input()\r\ns=''\r\nfor i,j in zip(x,z):\r\n if i==j:\r\n s+='z'\r\n elif j<i:\r\n s+=j\r\n else:\r\n exit(print(-1))\r\n break\r\nprint(s)",
"x = input()\r\ny = input()\r\nz = \"\"\r\nflag = 0\r\nfor i in range(len(x)):\r\n if ord(y[i]) < ord(x[i]):\r\n z += y[i]\r\n\r\n if ord(y[i]) == ord(x[i]):\r\n z += y[i]\r\n\r\n if ord(y[i]) > ord(x[i]):\r\n flag += 1\r\nif flag < 1:\r\n print(z)\r\nelse:\r\n print(-1) \r\n ",
"a = list(input())\r\nb = list(input())\r\nfor i in range(len(a)):\r\n if(a[i]<b[i]):\r\n print(-1)\r\n exit(0)\r\nprint(\"\".join(b))",
"def f(x,y):\r\n z = ''\r\n for i in range(len(x)):\r\n if x[i] < y[i]:\r\n return -1\r\n else:\r\n z += y[i]\r\n return z\r\n\r\nprint(f(input(), input()))",
"alpha = 'abcdefghijklmnopqrstuvwxyz'\r\ns1 = input()\r\ns2 = input()\r\nn = len(s1)\r\nproposed = ''\r\nfor i in range(n):\r\n if s1[i] == s2[i]:\r\n proposed += s1[i]\r\n elif s1[i] > s2[i]:\r\n proposed += s2[i]\r\n else:\r\n proposed = -1\r\n break\r\nprint(proposed)",
"s = input().strip()\r\nt = input().strip()\r\n\r\nl = len(s)\r\nfor i in range(l):\r\n if ord(s[i]) < ord(t[i]):\r\n print(-1)\r\n break\r\nelse:\r\n print(t)",
"x=input()\r\ny=input()\r\nif any(d > c for c, d in zip(x, y)):\r\n\tprint(-1)\r\nelse:\r\n\tprint(y)",
"a = input()\r\nb = input()\r\nk = ord('a')\r\ns = ''\r\nfor i in range(len(a)):\r\n\tif b[i] > a[i]:\r\n\t\ts = -1\r\n\t\tbreak\r\n\tif b[i] <= a[i]:\r\n\t\ts = s+b[i]\r\nprint(s)\r\n",
"#!/usr/bin/env python3\nfrom sys import stdin,stdout\n\n\ndef ri():\n return map(int, input().split())\n\nx = input()\ny = input()\n\nl = len(x)\nz = []\nfor i in range(l):\n if x[i] < y[i]:\n print(-1)\n exit()\n z.append(min(x[i], y[i]))\n\nprint(\"\".join(z))\n",
"x,y=input().strip(),input().strip()\r\nprint(y if all(x[i]>=y[i] for i in range(len(y))) else -1)\r\n",
"x=input();y=input()\r\nb=[]\r\nfor i in range(len(x)):\r\n if y[i]>x[i]:\r\n print(-1);exit(0)\r\n else:\r\n b.append(y[i])\r\nprint(''.join(b))",
"'''input\nab\nba\n'''\nx, y = input(), input()\nfor i in range(len(x)):\n\tif x[i] < y[i]:\n\t\tprint(-1)\n\t\tbreak\nelse:\n\tprint(y) \n",
"x, y = input(), input()\r\nprint(y if all(a >= b for a, b in zip(x, y)) else -1)",
"x, y = input(), input()\r\nprint(-1 if any(ch1 < ch2 for ch1, ch2 in zip(x, y)) else y)",
"a=list(input())\r\nb=list(input())\r\nfor i in range(len(a)):\r\n if ord(a[i]) < ord(b[i]):\r\n print(-1)\r\n exit()\r\nprint(''.join(b))",
"#Problem Set G: Collaborated with Rudransh Singh and Prasoon\n\nx = list(input())\ny = list(input())\n\nz = []\n\nflag = False\n\nfor i in range(len(x)):\n if x[i] < y[i]:\n flag = True\n break\n \n elif x[i] == y[i]:\n z.append(\"z\")\n\n else:\n z.append(y[i])\n\nif flag:\n print(-1)\n\nelse:\n print(\"\".join(z))\n\t \t\t \t\t \t \t \t \t\t\t \t",
"x = input()\r\ny = input()\r\n\r\ndef solve(x, y):\r\n string = \"\"\r\n for i in range(len(x)):\r\n if y[i] <= x[i]:\r\n string += y[i]\r\n else:\r\n return False\r\n \r\n return string\r\n\r\nanswer = solve(x,y)\r\nif answer:\r\n print(answer)\r\nelse:\r\n print(-1)",
"from sys import exit\r\nx=str(input())\r\ny=str(input())\r\nfor i in range(len(x)):\r\n if x[i]<y[i]:\r\n print(-1)\r\n exit(0)\r\nprint(y) ",
"\r\nx = input()\r\ny = input()\r\nn = len(x)\r\nflag = False\r\nres = ''\r\nfor i in range(n):\r\n if y[i] <= x[i]:\r\n res += y[i]\r\n else:\r\n flag = True\r\n break\r\nprint(-1 if flag else res)\r\n",
"x, y = input(), input()\r\nk = 0\r\nz = ''\r\nfor i in range(len(x)):\r\n if x[i]<y[i]:\r\n k = -1\r\n elif x[i]>y[i]:\r\n z += y[i]\r\n else:\r\n z += x[i]\r\nif k != -1:\r\n print(z)\r\nelse:\r\n print(k)",
"x = input()\ny = input()\n\nz = ''\n\nfor xi, yi in zip(x, y):\n if yi > xi:\n print(-1)\n exit(0)\n else:\n z += min(yi, xi)\n\nprint(z)\n",
"x = input()\ny = input()\n\nalf = 'abcdefghijklmnopqrstuvwxyz'\n\nz = ''\n\nfor i in range(len(x)):\n\tif y[i] == x[i]:\n\t\tz += x[i]\n\telif alf.find(x[i]) < alf.find(y[i]):\n\t\tprint('-1')\n\t\tbreak\n\telif alf.find(x[i]) > alf.find(y[i]):\n\t\tz += y[i]\n\nelse:\n\tprint(z)",
"def check(a,b):\r\n\tw=''\r\n\tfor i in range(len(a)):\r\n\t\tif a[i]<b[i]:\r\n\t\t\treturn -1\r\n\t\t\r\n\treturn b\r\n\t\r\n\r\na=input()\r\nb=input()\r\nprint(check(a,b))\r\n",
"x=input()\r\ny=input()\r\nz=y\r\nfor i in range(len(z)):\r\n if z[i]>x[i]:\r\n print(-1)\r\n break\r\n elif z[i]==x[i]:\r\n z=z[:i]+'z'+z[i+1:]\r\nelse:\r\n print(z)",
"x=input()\r\nz=input()\r\ny=\"\"\r\nt=1\r\nfor i in range(len(x)):\r\n if x[i]<z[i]:\r\n print(-1)\r\n t=0\r\n break\r\n elif x[i]==z[i]:\r\n y+=\"z\"\r\n else:\r\n y+=z[i]\r\nif t:\r\n print(y)",
"a = input()\r\nb = input()\r\no = True\r\nz = ''\r\nfor i in range(len(a)):\r\n if a[i]>b[i]:\r\n z = z + b[i]\r\n elif a[i]==b[i]:\r\n z = z + 'z'\r\n else:\r\n o = False\r\nif o:\r\n print(z)\r\nelse:\r\n print(-1)",
"x=input()\r\ny=input()\r\nflag=0\r\nz=\"\"\r\nfor i in range(len(x)):\r\n\tif ord(x[i])<ord(y[i]):\r\n\t\tprint(-1)\r\n\t\tflag=1\r\n\t\tbreak\r\n\telse:\r\n\t\tif x[i]==y[i]:\r\n\t\t\tz+=x[i]\r\n\t\telse:\r\n\t\t\tz+=y[i]\r\nif flag==0:\t\t\t\r\n\tprint(z)",
"a=input()\r\nb=input()\r\nans=\"\"\r\nfor i in range(len(a)):\r\n if a[i]==b[i]:\r\n ans+=a[i]\r\n elif a[i]>b[i]:\r\n ans+=b[i]\r\n else:\r\n print(-1)\r\n exit(0);\r\nprint(ans)",
"n=input();m=input();z=''\r\nfor i in range(len(m)):\r\n if n[i]<m[i]:print(-1);exit(0)\r\n elif n[i]==m[i]:z+='z'\r\n else:z+=m[i]\r\nprint(z)",
"a,b=open(0)\r\nprint([b,-1][any(y>x for x,y in zip(a,b))])",
"# Valued keys. Problem 801B\n\nx = input()\ny = input()\nz = ''\n\nfor i in range(len(x)):\n z = z + chr(min(ord(y[i]), ord(x[i]) + 1))\n\n if ord(y[i]) > ord(x[i]):\n z = -1\n break\nprint(z)\n",
"x, y= input(), input()\nprint((y, -1)[any(i < j for i, j in zip(x, y))])",
"def f(x, y):\n z = \"\"\n for i in range(len(x)):\n z += chr(min(ord(x[i]), ord(y[i])))\n return z\n\nx, y = input(), input()\nif f(x, y) == y:\n print(y)\nelse:\n print(-1)\n",
"def check(s1,s2):\n l = len(s1)\n for i in range(l):\n if s1[i] >= s2[i]:\n continue\n else:\n return False\n return True\n\n\nx = input()\ny = input()\n\nif check(x,y):\n print(y)\nelse:\n print(-1)\n\n\n\n",
"x=input()\r\ny=input()\r\ns=\"\"\r\nflag=0\r\nfor i in range(len(x)):\r\n if ord(x[i])<ord(y[i]):\r\n flag=1\r\n break\r\n else:\r\n s=s+chr(min(ord(x[i]),ord(y[i])))\r\nif flag:\r\n print(-1)\r\nelse:\r\n print(s)\r\n ",
"import sys\r\nreadline = sys.stdin.readline\r\nx = readline()\r\ny = readline()\r\nz = \"\"\r\nflag = 0\r\nfor i in range(len(x)):\r\n if ord(y[i]) < ord(x[i]):\r\n z += y[i]\r\n\r\n if ord(y[i]) == ord(x[i]):\r\n z += y[i]\r\n\r\n if ord(y[i]) > ord(x[i]):\r\n flag += 1\r\nif flag < 1:\r\n print(z)\r\nelse:\r\n print(-1) \r\n ",
"# due to time constraints (starting this on day it's due), adapting code from net\n# i should start doing this properly next assignment\n# source: https://cloud.tencent.com/developer/article/1086864\nimport sys\n\n\ndef get_string(): return sys.stdin.readline().strip()\n\n\nx = get_string()\ny = get_string()\n\nflag = False\n\nfor i in range(len(x)):\n if x[i] < y[i]:\n flag = True\n break\n\nif flag:\n print(\"-1\")\nelse:\n print(y)\n\n \t\t\t \t \t\t\t\t\t \t\t\t \t\t \t\t \t",
"s1=input()\ns2=input()\nfor i in range(len(s1)):\n\tif ord(s1[i])<ord(s2[i]):\n\t\tprint(-1)\n\t\texit(0)\nprint(s2)\n\t",
"s=[ord(n) for n in input()]\r\nz=[ord(n) for n in input()]\r\nt=[]\r\nl=0\r\nfor n in range(len(s)):\r\n\tif s[n]==z[n]:\r\n\t\tt.append(chr(s[n]))\r\n\telif s[n]>z[n]:\r\n\t\tt.append(chr(z[n]))\r\n\telse:\r\n\t\tprint(-1)\r\n\t\tl=1\r\n\t\tbreak\r\nif l==0:\r\n\tfor n in t:\r\n\t\tprint(n,end='')",
"from sys import stdin, stdout\r\na = stdin.readline().rstrip()\r\nc = stdin.readline().rstrip()\r\n\r\nb = ''\r\nfor idx , i in enumerate(a):\r\n if a[idx] < c[idx]:\r\n b = -1\r\n break\r\n else:\r\n b += c[idx]\r\n\r\nprint(b) ",
"string1 = list(input())\r\nstring2 = list(input())\r\n\r\nlength = len(string1)\r\n\r\nresString = \"\"\r\n\r\nfor i in range(length):\r\n if string1[i] == string2[i]:\r\n resString += string1[i]\r\n elif string1[i] > string2[i]:\r\n resString += string2[i]\r\n else:\r\n print(-1)\r\n exit()\r\n\r\nprint(''.join(resString))",
"x = input()\nz = input()\nfor i in range(len(x)):\n if x[i] < z[i]:\n print(-1)\n exit()\nprint(z)\n\t\t \t \t \t \t\t\t \t\t\t\t \t \t",
"s1 = input()\r\ns2 = input()\r\nlist = []\r\nfor i in range (len(s1)):\r\n if s1[i] == s2[i]:\r\n list.append(\"z\")\r\n if s1[i] > s2[i]:\r\n list.append(s2[i])\r\n if s1[i] < s2[i]:\r\n list.append(\"-1\")\r\nprint(\"-1\" if \"-1\" in list else \"\".join(list))",
"x = input()\r\ny = input()\r\nans = ''\r\nk = True\r\nfor i in range(len(x)):\r\n if x[i]<y[i]:\r\n print(-1)\r\n k = False\r\n break\r\n elif x[i]==y[i]:\r\n ans+=x[i]\r\n else:\r\n ans+=y[i]\r\nif k:\r\n print(ans)\r\n",
"x = input() \r\ny = input() \r\nans = \"\"\r\nfor i in range(len(y)): \r\n if x[i] == y[i]: \r\n ans += \"z\"\r\n else: \r\n if ord(y[i]) > ord(x[i]):\r\n print(-1)\r\n exit()\r\n else:\r\n ans += y[i]\r\nprint(ans)",
"x = input()\r\ny = input()\r\nz=''\r\nc=0\r\nfor i in range(len(y)):\r\n if y[i]==x[i]:\r\n if x[i]=='z':\r\n z+='z'\r\n else:\r\n z+=chr(ord(x[i])+1)\r\n elif y[i]<x[i]:\r\n z+=(y[i])\r\n else:\r\n c=-1\r\n break\r\nif c==-1:\r\n print(-1)\r\nelse:\r\n print(z)",
"x, y = input(), input()\r\nl_z = list()\r\n\r\nfor i in range(len(x)):\r\n if y[i] > x[i]:\r\n print(\"-1\")\r\n quit()\r\n elif y[i] < x[i]:\r\n l_z.append(y[i])\r\n else:\r\n l_z.append(x[i])\r\n\r\nprint(\"\".join(l_z))",
"s1=input()\ns2=input()\nfor i,c in enumerate(s1):\n if s2[i]>c:\n print(-1)\n exit()\nprint(s2)\n",
"import sys\r\na=input();b=input();c=''\r\nfor i,j in zip(a,b):\r\n if i<j:\r\n print(-1)\r\n sys.exit()\r\n elif i==j:\r\n c+=i\r\n else:\r\n c+=j\r\nprint(c)",
"from sys import maxsize, stdout, stdin, stderr\r\n# mod = int(1e9 + 7)\r\nimport re # can use multiple splits\r\ntup = lambda: map(int, stdin.readline().split())\r\nI = lambda: int(stdin.readline())\r\nlint = lambda: [int(x) for x in stdin.readline().split()]\r\nS = lambda: stdin.readline().replace('\\n', '').strip()\r\ndef grid(r, c): return [lint() for i in range(r)]\r\ndef debug(*args, c=6): print('\\033[3{}m'.format(c), *args, '\\033[0m', file=stderr)\r\nstpr = lambda x : stdout.write(f'{x}' + '\\n')\r\nstar = lambda x : print(' '.join(map(str , x)))\r\n\r\n# n = I()\r\n# ls =lint()\r\n# arr =[n]*n\r\n# d = n\r\n# for i in range(n):\r\n# if ls[i]==0:\r\n# d=0\r\n# else:\r\n# d+=1\r\n# arr[i] = d\r\n# d = n\r\n# for i in range(n-1,-1,-1):\r\n# if ls[i]==0:\r\n# d=0\r\n# else:\r\n# d+=1\r\n# arr[i] = min(d , arr[i])\r\n# star(arr)\r\n#\r\na = S()\r\nf= S()\r\nx = ''\r\nfor i in range(len(a)):\r\n if a[i] > f[i]:\r\n x +=f[i]\r\n else:\r\n x+=a[i]\r\nb =''\r\nfor i in range(len(a)):\r\n b+=min(a[i],x[i] )\r\nif b !=f:\r\n print(\"-1\")\r\nelse:print(x)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"x = input()\r\ny = input()\r\nz = []\r\n\r\nfor i in range(len(x)):\r\n z.append(min(x[i],y[i]))\r\nfor i in range(len(x)):\r\n if min(x[i],z[i]) != y[i]:\r\n print(-1)\r\n exit()\r\nprint(''.join(y))\r\n",
"x = input()\ny = input()\n\n\ndef f_reverse(first_string, target_string):\n if len(first_string) != len(target_string):\n return -1\n second_string = []\n for i in range(0, len(first_string)):\n if first_string[i] == target_string[i]:\n second_string.append(first_string[i])\n elif target_string[i] < first_string[i]:\n second_string.append(target_string[i])\n else:\n return -1\n return second_string\n\ns = f_reverse(x, y)\nif type(s) == list:\n print(''.join(s))\nelse:\n print(-1)",
"s1=input()\ns2=input()\ns3=''\nfor i in range(len(s1)):\n if s1[i]==s2[i]:\n s3+=s1[i]\n elif s1[i]>s2[i]:\n s3+=s2[i]\n else:\n pass\n \nif(len(s3)==len(s1)):\n print(s3)\nelse:\n print(-1)\n",
"s = input()\r\nt = input()\r\n\r\nfor i in range(len(s)):\r\n\tif ord(s[i]) < ord(t[i]):\r\n\t\tprint(-1)\r\n\t\texit()\r\n\r\nl = ['a'] * len(s)\r\nfor i in range(len(s)):\r\n\tl[i] = chr(min(ord(s[i]), ord(t[i])))\r\n\r\nprint(''.join(l))\r\n",
"s1=str(input())\r\nans=str(input())\r\nlist1=['z' for z in range(len(s1))]\r\nfor i in range(len(s1)):\r\n if ord(ans[i])>ord(s1[i]):\r\n print(-1)\r\n exit()\r\nfor i in range(len(s1)):\r\n if ans[i]!=s1[i]:\r\n list1[i]=ans[i]\r\nprint(''.join(list1))",
"x = input().strip()\ny = input().strip()\n\nz = ''\nfor a in zip(x, y):\n if a[0] >= a[1]:\n z += a[1]\n else:\n z = -1\n break\nprint(z)",
"x = input()\r\ny = input()\r\n\r\n\r\ndef checker(x, y):\r\n z = ''\r\n for cx, cy in zip(x, y):\r\n if min(cx, cy) < cy:\r\n return '-1'\r\n z += min(cx, cy)\r\n return z\r\n\r\nprint(checker(x, y))",
"a = input().strip()\r\nb = input().strip()\r\nlst = [b[i] if b[i] <= a[i] else -1 for i in range(len(b))]\r\nif -1 in lst:\r\n print(-1)\r\nelse:\r\n print(b)",
"#801A\r\nx = list(input())\r\ny = list(input())\r\nflag = 0\r\nfor i in range(len(x)):\r\n if y[i] > x[i]:\r\n flag = 1\r\nif flag == 1:\r\n print(-1)\r\nelse:\r\n print(\"\".join(y))\r\n",
"x = input()\ny = input()\ncan = all(ord(x[i]) >= ord(y[i]) for i in range(len(x)))\nprint(y if can else -1)\n",
"def f(w,v):\r\n s=''\r\n for i in range(len(w)):\r\n s=s+min(w[i],v[i])\r\n return(s)\r\n\r\nx=input()\r\ny=input()\r\nif(len(x)!=len(y)):\r\n print(\"imhere\")\r\n print(-1)\r\nelse:\r\n out=True\r\n i=0\r\n s=''\r\n while(out and i<len(x)):\r\n if(x[i]<y[i]):\r\n out=False\r\n elif(x[i]>y[i]):\r\n s=s+y[i]\r\n i=i+1\r\n else:\r\n if(x[i]=='z'):\r\n s=s+'z'\r\n else:\r\n s=s+chr(ord(x[i])+1)\r\n i=i+1\r\n if(out==False):\r\n print(-1)\r\n else:\r\n print(s)\r\n \r\n \r\n",
"import sys\r\nInput = sys.stdin.readline\r\nx, y = input(), input()\r\nfor i in range(len(x)):\r\n if ord(y[i]) > ord(x[i]):\r\n print(-1)\r\n exit()\r\nprint(y)\r\n",
"x = input()\ny = input()\na = ''\nfor i in range(len(x)):\n if(y[i] < x[i]):\n a += y[i]\n elif(y[i] == x[i]):\n a += 'z'\n else:\n a = '-1'\n break\nprint(a)\n\t\t\t \t\t\t\t\t\t \t\t \t \t\t\t\t\t\t \t\t \t \t",
"def findz (x,y):\n ans = \"\"\n for i in range(len(x)):\n if x[i] >= y[i] :\n ans += y[i]\n else:\n return -1\n\n return ans\n\n\nx = input()\ny = input()\nprint (findz(x,y))\n",
"a = input()\nb = input()\nprint([-1, b][all(ord(x) >= ord(y) for x, y in zip(a, b))])\n",
"import sys\r\n\r\ndef main():\r\n x=sys.stdin.readline().rstrip()\r\n y=sys.stdin.readline().rstrip()\r\n \r\n result=0\r\n z=['a']*len(x)\r\n for i in range(len(x)):\r\n if x[i]<y[i]: \r\n result=-1\r\n break\r\n else:\r\n z[i]=y[i]\r\n \r\n if result!=-1: result=''.join(z)\r\n sys.stdout.write(str(result)+'\\n')\r\n \r\nmain()\r\n\r\n",
"x = input()\r\ny = input()\r\nflag = 0\r\n\r\nfor i in range(len(x)):\r\n\r\n\tif (ord(x[i]) < ord(y[i])):\r\n\t\tflag = 1\r\n\t\tbreak\r\n\r\nif flag == 0:\r\n\tprint(y)\r\nelse:\r\n\tprint(-1)",
"from sys import stdin\n\nx = next(stdin).strip()\ny = next(stdin).strip()\n\nz = \"\"\n\nfor a, b in zip(x, y):\n if a == b:\n z += a\n elif a < b:\n z = -1\n break\n else: # b < a\n z += b\n\nprint(z)\n",
"x = input()\r\ny = input()\r\nz = []\r\n\r\nfor i in range(0, len(x)):\r\n if x[i] == y[i]:\r\n z.append(x[i])\r\n elif ord(y[i]) < ord(x[i]):\r\n z.append(y[i])\r\n else:\r\n print(-1)\r\n exit(0)\r\nz = ''.join(z)\r\nprint(z)",
"s = str(input())\r\nt = str(input())\r\nfor i in range(len(t)):\r\n if(t[i] > s[i]):\r\n print(-1)\r\n exit()\r\nprint(t)\r\n#kalay))",
"import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef list_input():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef float_compare(a, b):\r\n if abs(a-b) < float(1e-9):\r\n return True\r\n else:\r\n return False\r\n\r\n\r\ndef sub_mod(x, mod):\r\n x = x % mod\r\n if x < 0:\r\n x += mod\r\n return x\r\n\r\n\r\ndef divisor(n):\r\n i = 1\r\n dv = []\r\n while i*i <= n:\r\n if n % i == 0:\r\n dv.append(i)\r\n if i*i != n:\r\n dv.append(n//i)\r\n i += 1\r\n\r\n return dv\r\n\r\n\r\n#l = list_input()\r\n# print(divisor(25))\r\n# print(divisor(18))\r\n# print(float(1e-9))\r\n\r\na = input().strip()\r\nb = input().strip()\r\nflag = True\r\nfor i in range(len(a)):\r\n if a[i] < b[i]:\r\n flag = False\r\n break\r\n\r\nif flag:\r\n print(b)\r\nelse:\r\n print(-1)\r\n",
"a=list(input())\r\nb=list(input())\r\nn=len(a)\r\nc=[]\r\nfor i in range(n):\r\n if ord(a[i])>=ord(b[i]):\r\n c.append(min(a[i],b[i]))\r\n else:\r\n print(-1)\r\n exit(0)\r\nprint(''.join(c)) \r\n \r\n \r\n \r\n",
"\nInput=lambda:map(int,input().split())\n\nx, z = input(), input()\ny = \"\"\ni = len(x) - 1\nwhile i >= 0:\n if z[i] <= x[i]:\n y+=z[i]\n else:\n print(-1)\n exit()\n i-=1\nprint(y[::-1])\n\n \n \n\n\n\n",
"\n\ndef main():\n x = input()\n y = input()\n\n z = ''\n n = len(x)\n\n for i in range(n):\n if x[i] >= y[i]:\n z += y[i]\n elif x[i] < y[i]:\n print(-1)\n return\n print(z)\n\nmain()",
"def stroki(x, y):\r\n z = ''\r\n for i in range(len(y)):\r\n if y[i] <= x[i]:\r\n z += y[i]\r\n else:\r\n return -1\r\n return z\r\n\r\n\r\ns = input()\r\nt = input()\r\nprint(stroki(s, t))\r\n",
"x=input()\r\ny=input()\r\nn=len(x)\r\nans=[]\r\nf=1\r\nfor i in range(n):\r\n if x[i]>=y[i]:\r\n ans.append(y[i])\r\nif len(ans)==n:\r\n print(''.join(ans))\r\nelse:\r\n print(-1)",
"x=input()\r\ny=input()\r\nz=''\r\ncount=0\r\nfor i in range(len(y)):\r\n if ord(y[i])<=ord(x[i]):\r\n z+=y[i]\r\n else:\r\n count+=1\r\nif count==0:\r\n print(z)\r\nelse:\r\n print(-1)\r\n ",
"from sys import stdin\r\ninput = stdin.readline\r\n\r\nx = input().strip()\r\ny = input().strip()\r\n\r\ngood = True\r\nfor a,b in zip(x,y):\r\n if a < b:\r\n good = False\r\n break\r\n\r\nprint(y if good else -1)",
"x = input()\r\ny = input()\r\n# f(x,z) = y\r\nall_letters = \"abcdefghijklmnopqrstuxwxyz\"\r\ndef find_z(x: str, y: str):\r\n\tz = \"\"\r\n\tfor i, out_letter in enumerate(y):\r\n\t\tif x[i] < out_letter:\r\n\t\t\treturn -1\r\n\t\tif x[i] == out_letter:\r\n\t\t\tz += \"z\"\r\n\t\tif x[i] > out_letter:\r\n\t\t\tz += out_letter\r\n\treturn z\r\nprint(find_z(x,y))",
"x, y, z = input(), input(), ''\r\nfor xi, yi in zip(x, y):\r\n if xi < yi:\r\n z = '-1'\r\n break\r\n else:\r\n z = z + min(xi, yi)\r\nprint(z)",
"x=input()\nz=input()\ny=\"\"\nans=\"\"\ntm=True\nfor i in range(len(x)):\n\tif z[i]<=x[i]:\n\t\ty+=z[i]\n\telse:\n\t\tans=-1\n\t\ttm=False\n\t\tbreak\nif tm:\n\tans=y \nprint(ans)\n \t\t\t\t \t\t \t\t\t\t \t\t\t\t\t \t \t \t",
"X1 = input()\r\nX2 = input()\r\nfor i in range(len(X1)):\r\n if ord(X2[i]) > ord(X1[i]):\r\n print(-1)\r\n exit()\r\nelse:\r\n print(X2)\r\n",
"import string\r\n\r\nimport random\r\nletters = string.ascii_lowercase\r\nx = input()\r\ny = input()\r\nflag = False\r\nstring = ''\r\nfor i in range(len(x)):\r\n if y[i] > x[i]:\r\n flag = True\r\n break\r\n elif y[i] <= x[i]:\r\n minimun_letter = min(x[i],y[i])\r\n string += minimun_letter\r\nif flag:\r\n print (-1)\r\nelse:\r\n print (string)\r\n\r\n",
"x = input()\ny = input()\nnew_line = ''\nfor i in range(len(y)):\n if y[i] <= x[i]:\n new_line += y[i]\n else:\n new_line = -1\n break\nprint(new_line)\n",
"x = input()\nz = input()\ny = \"\"\nyExists = True\nfor i in range(len(x)):\n if x[i] < z[i]:\n yExists = False\n else:\n y += z[i]\n if not yExists:\n break\nif yExists:\n print(y)\nelse:\n print(-1)\n\t \t\t \t\t\t \t\t\t\t\t\t \t \t\t \t \t",
"import sys\r\nx, z, y = input(), input(), \"\"\r\nfor i in range(len(x)):\r\n if z[i] > x[i]:\r\n print(-1)\r\n sys.exit()\r\n y = y + z[i]\r\nprint(y)",
"x=input()\r\ny=input()\r\nf=1\r\nfor i in range(len(x)):\r\n if x[i]<y[i]:\r\n f=0\r\n break\r\nif f:\r\n print(y)\r\nelse:\r\n print(-1)",
"x = input()\r\ny = input()\r\nans = \"\"\r\n\r\nfor i in range(len(x)):\r\n if x[i] == y[i]:\r\n ans += \"z\"\r\n elif x[i] > y[i]:\r\n ans += y[i]\r\n elif x[i] < y[i]:\r\n print(\"-1\")\r\n exit()\r\nprint(ans)\r\n \r\n",
"x = input()\r\ny = input()\r\ndef checker():\r\n for i in range(len(x)):\r\n if ord(x[i]) < ord(y[i]):\r\n return -1\r\n return y\r\nprint(checker())",
"x = input()\r\ny = input()\r\nprint( -1 if any( ord( x[ i ] ) < ord( y[ i ] ) for i in range( len( x ) ) ) else y )\r\n",
"x=input()\r\ny=input()\r\nm=True\r\nfor i in range(len(x)):\r\n if x[i]<y[i]:\r\n print(-1)\r\n m=False\r\n break\r\nif m:\r\n print(y)\r\n\r\n \r\n \r\n \r\n",
"ch=input()\r\nz=input()\r\nk=True\r\nfor x in range(len(ch)):\r\n if z[x]>ch[x]:\r\n k=False\r\nif k:\r\n print(z)\r\nelse:\r\n print('-1')",
"from sys import stdin, stdout\n\n\nx = stdin.readline().rstrip()\ny = stdin.readline().rstrip()\n\nz=''\n\npossible=True\nfor i in range(len(x)):\n if x[i]==y[i]:\n z+='z'\n elif x[i]>y[i]:\n z+=y[i]\n else:\n possible=False\n\nif possible:\n print(z)\nelse:\n print(-1)\n \n",
"x = input()\r\ny = input()\r\nfor i in range(len(x)):\r\n if x[i]>=y[i]:\r\n y=y+y[i]\r\n else:\r\n print(-1)\r\n exit(0)\r\ny = y[len(x):]\r\nprint(y)",
"s = input()\nt = input()\nfor i in range(len(s)):\n if s[i] < t[i]:\n print(-1)\n exit(0)\nprint(t)",
"s1=input()\r\ns2=input()\r\ns=\"\"\r\nc=0\r\nfor i in range(len(s1)):\r\n if(s1[i]<s2[i]):\r\n c=1\r\n break\r\n elif(s1[i]==s2[i]):\r\n s+=s1[i]\r\n else:\r\n s+=s2[i]\r\nif(c==1):\r\n print(\"-1\")\r\nelse:\r\n print(s)\r\n",
"import string\r\ns1 = input()\r\ns2 = input() \r\ns=\"\"\r\nsol = True\r\nfor i in range(len(s1)):\r\n #print(i, s1[i],s2[i], len(s2))\r\n if s1[i]==s2[i]:\r\n s+=s1[i] \r\n #print(s1[i])\r\n else:\r\n indexs1= string.ascii_lowercase.index(s1[i])\r\n indexs2= string.ascii_lowercase.index(s2[i])\r\n if indexs2<indexs1:\r\n s+=s2[i]\r\n #print(indexs2)\r\n else:\r\n sol = False \r\n break\r\n #print(\"hi\")\r\nprint(-1) if sol==False else print(s)",
"a = input()\r\nb = input()\r\ns = True\r\ni = 0\r\nwhile s == True: \r\n if a[i]<b[i]:\r\n s = False\r\n print(-1)\r\n else:\r\n i+=1\r\n if ((i == len(a)) and (s)):\r\n print(b)\r\n s = False",
"x=[xx for xx in str(input())]\r\ny=[yy for yy in str(input())]\r\nz=[]\r\nn=len(x)\r\nfor i in range(n):\r\n if y[i]==x[i]:z.append('z')\r\n else:z.append(y[i])\r\ns=[]\r\nfor j in range(n):\r\n s.append(min(x[j],z[j]))\r\nss=''.join(s)\r\nif ss==''.join(y):print(''.join(z))\r\nelse:print(-1)",
"a = input()\r\nb = input()\r\nf = 0\r\nfor i in range(len(a)):\r\n\tif ord(a[i]) < ord(b[i]):\r\n\t\tf = 1\r\n\t\tbreak\r\nif f:\r\n\tprint(-1)\r\nelse:\r\n\tprint(b)\r\n",
"\r\nx = input()\r\nz = input()\r\n\r\nans = 0\r\n\r\nfor i in range(len(x)):\r\n\r\n if ord(x[i]) < ord(z[i]):\r\n ans = -1\r\n break\r\n\r\nif ans == 0:\r\n ans = z\r\n\r\nprint(ans)",
"def B_Valued_Keys(x,y,z):\r\n for i in range(len(x)):\r\n if x[i] < y [i]:\r\n return -1\r\n elif x[i] == y [i]:\r\n z.append(x[i])\r\n else:\r\n z.append(y[i])\r\n z = \"\".join(z)\r\n return z\r\n\r\nx = input()\r\ny = input()\r\nz = []\r\nres = B_Valued_Keys(x,y,z)\r\nprint(res)",
"str1, str2 = input(), input()\r\n\r\nss = ''.join([min(str1[i], str2[i]) for i in range(len(str1))])\r\n\r\n\r\nfor i in range(len(str1)):\r\n if (str1[i] != str2[i]) and (str1[i] < str2[i] or str1[i] == 'a'):\r\n ss = \"-1\"\r\n break\r\n\r\nprint(ss)\r\n",
"#!/usr/bin/env python3\n\ndef solve():\n x = input()\n y = input()\n for a, b in zip(x, y):\n if a < b:\n print(-1)\n return\n\n print(y)\n\n\nif __name__ == '__main__':\n solve()\n",
"# Collaborated with Rudransh Singh and Bhumi Patel\nx = list(input())\nz = list(input())\ny = []\ncantBeDone = False\n\nfor i in range(len(x)):\n if x[i] < z[i]:\n cantBeDone = True\n break\n elif x[i] == z[i]:\n y.append(\"z\")\n else:\n y.append(z[i])\nif cantBeDone == True:\n print(-1)\nelse:\n print(\"\".join(y))\n\t \t \t\t \t \t\t\t \t \t \t \t \t",
"x=input()\r\ny=input()\r\nz=\"\"\r\nfor i in range(len(x)):\r\n if y[i]> x[i]:\r\n print(\"-1\")\r\n exit(0)\r\n elif y[i]<x[i]:\r\n z=z+y[i]\r\n else:\r\n z=z+\"z\"\r\nprint(z)",
"#!/usr/bin/env python\n\nimport sys\n\nx = sys.stdin.readline().strip()\ny = sys.stdin.readline().strip()\n\nif all(a >= b for a,b in zip(x, y)):\n print(y)\nelse:\n print(-1)\n",
"# output of the function f is another string of the same length. \n# The i-th character of the output is \n# equal to the minimum of \n# the i-th character of s1 and the i-th character of s2.\n\nx = input()\ny = input()\n\nprint(\n -1 if any(\n x[i]<y[i] for i in range(len(x))\n )\n else y)\n\n",
"x = input()\r\ny = input()\r\ncan = True\r\nfor i in range(len(x)):\r\n if x[i] < y[i]:\r\n can = False\r\nif can:\r\n print(y)\r\nelse:\r\n print(-1)",
"def sol():\r\n x = input()\r\n y = input()\r\n\r\n z = \"\"\r\n for i in range(len(x)):\r\n if y[i] > x[i]:\r\n return -1\r\n return y\r\n\r\nprint(sol())",
"s1 = input()\ns2 = input()\nn = len(s1)\nans = ''\nfor i in range(n):\n if s1[i] < s2[i]:\n print(-1)\n exit()\n elif s1[i] == s2[i]:\n ans += s1[i]\n else:\n ans += s2[i]\nprint(ans)\n",
"import sys\n\nx = input()\ny = input()\n\nz = ''\nfor xi, yi in zip(x, y):\n if xi == yi:\n z += yi\n elif xi > yi:\n z += yi\n elif xi < yi:\n print(-1)\n exit()\nprint(z)\n\n#def test_function(s1, s2):\n# res = ''\n# for ch1, ch2 in zip(s1, s2):\n# res += min(ch1, ch2)\n# return res\n#\n#print(test_function(x, z) == y)\n",
"x = input()\r\ny = input()\r\n\r\nout = y\r\n\r\nfor xi, yi in zip(x,y):\r\n if ord(xi) < ord(yi):\r\n out = -1\r\n break\r\n \r\nprint(out)",
"# from collections import defaultdict\r\n# from sys import stdin\r\n# import itertools\r\n# import bisect\r\n# from math import sqrt,ceil,floor\r\n\r\ndef func(put,mapping,unpack):\r\n x,y = list(put(str)),list(put(str))\r\n z = ['$']*len(x)\r\n for i in range(len(x)):\r\n if x[i] < y[i]: print(-1); return\r\n elif x[i] == y[i]: z[i] = y[i]\r\n else: z[i] = y[i]\r\n print(''.join(z))\r\n \r\ndef init(TestCases=True):\r\n put = lambda s: s(input().strip())\r\n mapping = lambda s: list(map(s,input().split()))\r\n unpack = lambda s: map(s,input().split())\r\n for _ in range(int(input()) if TestCases else 1):\r\n func(put,mapping,unpack)\r\n\r\nif __name__ == '__main__':\r\n init(False)",
"X = input()\r\nAN = input()\r\n\r\nZ = []\r\n\r\nv= True\r\nfor i,q in enumerate(X):\r\n if ord(q) < ord(AN[i]):\r\n v = False\r\n break\r\n Z += [AN[i]]\r\n\r\nif not v:\r\n print(-1)\r\nelse:\r\n print(\"\".join(Z))\r\n ",
"a=input()\r\nb=input()\r\nn=len(a)\r\n\r\ndef f(a,b,n):\r\n\tfor i in range(n):\r\n\t\tif a[i]<b[i]:\r\n\t\t\treturn \"-1\"\r\n\treturn b\r\nprint(f(a,b,n))\r\n",
"s1 = str(input())\r\ns2 = str(input())\r\nsr = \"\"\r\nb = 0\r\nfor i in range(len(s1)):\r\n if s1[i] >= s2[i]:\r\n sr +=s2[i]\r\n else :\r\n print(\"-1\")\r\n b = 1\r\n break;\r\nif not b:\r\n print(sr)",
"x=input()\r\ny=input()\r\nz=''\r\ncheck=1\r\nfor i in range(len(x)):\r\n if x[i]==y[i]:\r\n z+='z'\r\n else:\r\n if y[i]>x[i]:\r\n check=0\r\n break\r\n else:\r\n z+=y[i]\r\nif check==1:\r\n print(z)\r\nelse:\r\n print(-1)",
"x = input()\r\ny = input()\r\nz = \"\"\r\nfor i,j in zip(x , y):\r\n if(i < j):\r\n print(-1)\r\n break\r\nelse:\r\n print(y)",
"__author__ = 'zihaozhu'\nfrom sys import stdin\n\nx = stdin.readline().rstrip()\ny = stdin.readline().rstrip()\n\n\nans = \"\"\nfor ch in range(len(y)):\n if y[ch] > x[ch]:\n print (\"-1\")\n exit()\n\n elif y[ch] == x[ch]:\n ans = ans + y[ch]\n\n else:\n ans = ans + y[ch]\n\nprint(ans)\n",
"def f(s1, s2):\r\n\treturn ''.join([min(s1[i], s2[i]) for i in range(len(s1))])\r\n\r\nx = input()\r\ny = input()\r\n\r\ncan = not any([x[i] < y[i] for i in range(len(x))])\r\n\r\nif can:\r\n\tprint(f(x, y))\r\nelse:\r\n\tprint(-1)\r\n",
"def main():\r\n x = input()\r\n y = input()\r\n i = 0\r\n while i < len(x) and x[i] >= y[i]:\r\n i += 1\r\n if i < len(x):\r\n print(-1)\r\n else:\r\n print(y)\r\nmain()",
"s1, s2 = str(input()), str(input())\r\noutput = ''\r\nfor j in range(len(s1)):\r\n if ord(s2[j]) <= ord(s1[j]):\r\n output += s2[j]\r\n else:\r\n output = -1\r\n break\r\nprint(output)\r\n",
"x = input()\r\ny = input()\r\n\r\nz = ''\r\n\r\nfor i, xi in enumerate(x):\r\n yi = y[i]\r\n if yi > xi:\r\n print('-1')\r\n exit()\r\n z += yi\r\n\r\nprint(z)\r\n",
"x, y = input(), input()\r\nprint(-1 if any(a<b for a,b in zip(x,y)) else y)",
"\r\ndef solve():\r\n s1 = input()\r\n s2 = input()\r\n for i in range(len(s1)):\r\n if s2[i] > s1[i]:\r\n print(-1)\r\n return\r\n print(s2)\r\n return\r\n\r\n\r\n\r\n\r\n# t = int(input())\r\n# for _ in range(t):\r\n# solve()\r\nsolve()",
"x = input().strip()\r\ny = input().strip()\r\nflag = 0\r\n\r\nfor i,j in zip(x,y):\r\n if i<j:\r\n flag = 1\r\n break\r\n\r\nif flag:\r\n print(-1)\r\nelse:\r\n print(y)\r\n",
"str1, str2 = input(), input()\r\n\r\nans = str2\r\n\r\nif any(map(lambda s1, s2: s1 < s2, str1, str2)):\r\n ans = \"-1\"\r\n\r\nprint(ans)\r\n",
"def main():\n a = input()\n b = input()\n c = ''\n\n for i in range(len(a)):\n if a[i] < b[i]:\n print(-1)\n return\n elif a[i] == b[i]:\n c += a[i]\n else:\n c += b[i]\n\n print(c)\n\nif __name__=='__main__':\n main()\n",
"a=input()\nb=input()\nl=len(a)\n#s=sort(a)\n#t=sort(b)\nfor i in range(l):\n if a[i]<b[i]:\n print(-1)\n #break\n exit()\nprint(b)\n\n\t \t \t\t\t\t \t \t\t \t\t\t \t \t\t",
"a, b = input(), input()\r\n\r\nprint(b if b == ''.join(min(x,y) for x,y in zip(a,b)) else -1)",
"x=input()\r\nz=input()\r\nk1=len(x)\r\nk2=len(z)\r\nfor i in range(min(k1,k2)):\r\n\tif ord(x[i])<ord(z[i]):\r\n\t\tprint(-1)\r\n\t\tbreak\r\nelse:print(z)",
"s = input()\r\nt = input()\r\nn = len(s)\r\nfor i in range(0, n):\r\n if s[i] < t[i]:\r\n print(-1)\r\n exit(0)\r\nprint(t)\r\n",
"x = input()\r\nz = input()\r\ny = ''\r\nfor c1, c2 in zip(x, z):\r\n if c1 < c2:\r\n print('-1')\r\n break\r\n y += c2\r\nelse:\r\n print(y)\r\n",
"#COLLABORATED WITH Bhumi Patel, Prasoon Shakya\nx=input()\nx=x.lower()\ny=input()\ny=y.lower()\nbool_var=False\narray=[]\nfor i in range(len(x)):\n if x[i]<y[i]:\n bool_var = True\n break\n elif x[i]==y[i]:\n array.append(\"z\")\n else:\n array.append(y[i])\nif bool_var==True:\n print(-1)\nelse:\n for i in range(len(array)): \n print(array[i],sep=\"\",end=\"\")\n \t\t \t\t\t\t\t \t\t \t \t\t\t \t\t\t\t \t \t",
"x = input()\r\ny = input()\r\n\r\nz = \"\"\r\n\r\nfault = False\r\n\r\nfor i in range(0, len(x)):\r\n if ord(y[i]) > ord(x[i]):\r\n fault = True\r\n break\r\n\r\nif fault == True:\r\n print(-1)\r\nelse:\r\n print(y)",
"string1=input()\r\nstring2=input()\r\nres=''\r\nfor i in range(len(string1)):\r\n if string1[i]<string2[i]:\r\n print(-1)\r\n break\r\n elif string1[i]>=string2[i]:\r\n res+=string2[i]\r\nelse:\r\n print(res)",
"x = input()\r\ny = input()\r\nastring = \"\"\r\n\r\nfor i in range(len(x)):\r\n if x[i] == y[i]:\r\n astring += x[i]\r\n elif y[i] > x[i]:\r\n astring = -1\r\n break\r\n else:\r\n astring += y[i]\r\n \r\nprint(astring)",
"s1 = input()\r\ns3 = input()\r\nesiste = True\r\nrisultato = ''\r\nfor i in range(len(s1)):\r\n if (s1[i]==s3[i]):\r\n x = s1[i]\r\n elif (s1[i]>s3[i]):\r\n x = s3[i]\r\n else:\r\n x = 'x'\r\n esiste = False\r\n# print(s1[i],s3[i],'->',x)\r\n risultato += x\r\nif esiste:\r\n print(risultato)\r\nelse:\r\n print('-1')",
"x = input()\r\ny = input()\r\n\r\nz = []\r\nans = 'yes'\r\nfor x_el, y_el in zip(x, y):\r\n if x_el == y_el:\r\n z.append(x_el)\r\n elif x_el > y_el:\r\n z.append(y_el)\r\n else:\r\n ans = 'no'\r\n break\r\n \r\nif ans == 'yes':\r\n print(''.join(z))\r\nelse:\r\n print(-1)\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Nov 26 02:37:49 2020\r\n\r\n@author: user\r\nLink :https://codeforces.com/problemset/problem/801/B\r\n\"\"\"\r\ns = input()\r\nl = input()\r\n\r\nfor i in range(len(s)):\r\n if s[i] < l[i]:\r\n ans = \"-1\"\r\n break\r\n else:\r\n ans = l\r\nprint(ans)\r\n",
"import sys\r\nx,y = [i.strip() for i in sys.stdin.readlines()]\r\nz = ''\r\nfor i in range(len(x)):\r\n if x[i]<y[i]:\r\n z = -1\r\n break\r\n else:\r\n z = z+y[i]\r\nprint (z)",
"inp=input()\nop=input()\ninter=\"\"\nflag=0\nfor i in range(len(inp)):\n\tif inp[i]>=op[i]:\n\t\tif inp[i]==op[i]:\n\t\t\tif inp[i]!='z':\n\t\t\t\tadd=chr(ord(inp[i])+1)\n\t\t\t\tinter=inter+add\n\t\t\telse:\n\t\t\t\tinter=inter+'z'\n\t\telse:\n\t\t\tinter=inter+op[i]\n\telse:\n\t\tflag=1\n\t\tprint(\"-1\")\n\t\tbreak\nif flag==0:\n\tprint(inter)\n",
"import sys\r\nx = str(input())\r\ny = str(input())\r\nz = \"\"\r\nfor i in range(len(x)):\r\n if x[i] == y[i]:\r\n z = z + \"z\"\r\n if x[i] > y[i]:\r\n z = z + y[i]\r\n if x[i] < y[i]:\r\n print ('-1')\r\n sys.exit()\r\nprint (z)",
"s=input()\r\nd=input()\r\nprint([d,-1][any(ord(s[i])<ord(d[i])for i in range(len(d)))])\r\n",
"s,t=input(),input()\r\na,u=len(s), ''\r\nif a!=len(t) : print(-1)\r\nelse :\r\n for i in range(a) :\r\n if s[i] < t[i] : \r\n print(-1)\r\n break\r\n else : u+=t[i]\r\n else : print(u)",
"'''\r\nx = input().split()\r\ny = input().split()\r\n\r\nstop = False\r\nans = \"\"\r\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\nfor i,j in zip(x,y):\r\n if i > j:\r\n ans += j\r\n if i == j:\r\n if alpha.index(i) == 25:\r\n print(-1)\r\n stop\r\n if i < j:\r\n print(-1)\r\n stop = True\r\n \r\nif stop == False:\r\n print(y[0])\r\n'''\r\n\r\nx = input().split()\r\ny = input().split()\r\n\r\nstop = False\r\n\r\nfor i,j in zip(x[0],y[0]):\r\n \r\n if i < j:\r\n print(-1)\r\n stop = True\r\n break\r\n \r\nif stop == False:\r\n print(y[0])\r\n\r\n",
"s=input()\r\ns1=input()\r\nflag=1\r\nz=\"\"\r\nfor i in range(len(s)):\r\n if(s[i]==s1[i]):\r\n if(s[i]<'z'):\r\n z+=chr(ord(s[i])+1)\r\n else:\r\n z+=s[i];\r\n elif(s[i]>s1[i]):\r\n z+=s1[i]\r\n elif(s[i]<s1[i]):\r\n flag=0\r\n break\r\nif(flag>0):\r\n print(z)\r\nelse:\r\n print(\"-1\")",
"x=input()\r\ny=input()\r\nval=True\r\n\r\nfor i in range(0,len(x)):\r\n if(x[i]<y[i]):\r\n val=False\r\nif val:\r\n print(y)\r\nelse:\r\n print(\"-1\")\r\n",
"\r\nif __name__ == \"__main__\":\r\n x = input()\r\n y = input()\r\n z = \"\"\r\n for i in range(x.__len__()):\r\n if(y[i] > x[i]):\r\n z = \"-1\"\r\n break\r\n z = z + y[i]\r\n \r\n print(z)",
"s=input()\r\nl=input()\r\nfor i in range(len(s)):\r\n if(s[i]<l[i]):\r\n print(-1)\r\n break\r\nelse:\r\n print(l)",
"def f(x,y):\r\n\tfor i in range(len(x)):\r\n\t\tif x[i]<y[i]:\r\n\t\t\treturn -1\r\n\treturn y\r\n\t\r\nx=input()\r\ny=input()\r\nprint(f(x,y))",
"s1, s2 = input(), input()\r\nret = ''\r\nfor i in range(len(s1)):\r\n if s1[i] < s2[i]:\r\n ret = -1\r\n break\r\n elif s1[i] > s2[i]:\r\n ret += s2[i]\r\n elif s1[i] == s2[i]:\r\n ret += 'z'\r\nprint(ret)\r\n",
"x=input()\r\ny=input()\r\nn=len(x)\r\nc=0\r\nz=''\r\nfor i in range(n):\r\n if x[i]<y[i]:\r\n c+=1\r\n else:\r\n z+=y[i]\r\nif c==0:\r\n print(z)\r\nelse:\r\n print(-1)\r\n",
"x = list(input()); y = list(input())\r\nif any(b>a for a, b in zip(x,y)): \r\n print(-1)\r\nelse: \r\n print(''.join(min(a,b) for a,b in zip(x,y)))",
"x = input()\ny = input()\nnew = \"\"\nfor i in range(len(x)):\n charx = x[i]\n chary = y[i]\n\n if charx < chary:\n new = -1\n break\n else:\n if chary == charx:\n new+=charx\n elif charx > chary:\n new+=chary\nprint(new)\n \t\t \t\t\t \t \t \t\t \t\t \t\t\t\t\t\t",
"x,y=input(''),input('')\r\nz=[]\r\nc=0\r\nfor i in range(len(x)):\r\n if ord(x[i])<ord(y[i]):\r\n c=1\r\n break\r\n elif x[i]==y[i]:\r\n z.append('z')\r\n else:\r\n z.append(y[i])\r\nif c==0:\r\n print(''.join(z))\r\nelse:\r\n print(-1)",
"s1 = str(input())\r\ns2 = str(input())\r\nans = ''\r\ni =0\r\nwhile i<len(s1):\r\n if s2[i]>s1[i]:\r\n ans = -1\r\n break\r\n i = i + 1\r\nif ans!=-1:\r\n ans = s2\r\nprint(ans)",
"x = input()\ny = input()\n\nz = \"\"\n\nfor i in range(len(y)):\n if y[i] <= x[i]:\n z += y[i]\n else:\n print(-1)\n exit()\nprint(z)\n\n",
"X = input()\nY = input()\n\nN = len(X)\nZ = []\nfor x, y in zip(X, Y):\n if x < y:\n print(-1)\n exit()\n else:\n Z.append(y)\nprint(\"\".join(Z))\n",
"x=input()\r\ny=input()\r\nif any(x[i]<y[i] for i in range(len(x))):\r\n print(-1)\r\nelse:\r\n print(y)",
"x,y=input(),input()\r\nif all(a>=b for a,b in zip(x,y)):\r\n print(y)\r\nelse:\r\n print(\"-1\")",
"x = input()\r\ny = input()\r\nz = []\r\nflag=0\r\nfor i in range(len(x)):\r\n if x[i]<y[i]:\r\n print(-1)\r\n flag=1\r\n break\r\n else:\r\n z.append(y[i])\r\nif flag==0:\r\n print(''.join(y))",
"x,z=input(),input();l=len(x)\r\ny='';f=1\r\nfor i in range(l):\r\n if x[i]<z[i]:f=0;break\r\n y+=min(x[i],z[i])\r\nprint(y if f else -1)",
"x=input()\r\ny=input()\r\nn=len(x)\r\nz=''\r\nfor i in range(n):\r\n if(y[i]<=x[i]):\r\n z+=y[i]\r\n else:\r\n n=-1\r\n break\r\nif(n==-1):\r\n print(-1)\r\nelse:\r\n print(z)",
"x=input()\r\nz=input()\r\ny=\"\"\r\np=0\r\nfor i in range(0,len(x)):\r\n if ord(x[i])>=ord(z[i]):\r\n p=p+1\r\n else:\r\n print(-1)\r\n p=-1\r\n \r\n break\r\nif p!=-1:\r\n print(z)",
"x, y = input(), input()\r\nw = ''.join(min(a,b) for a, b in zip(x,y))\r\nprint(y if w == y else -1)",
"import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\nx = input().rstrip()\r\ny = input().rstrip()\r\n\r\nchk = True\r\nfor i in range(len(x)):\r\n if ord(x[i]) < ord(y[i]):\r\n chk = False\r\n\r\nprint(y if chk else -1)",
"a = input()\r\nb = input()\r\n\r\nf = True\r\n\r\nfor i,j in zip(a , b):\r\n if j>i:\r\n f = False\r\n break\r\n\r\nif f:\r\n print(b)\r\n\r\nelse:\r\n print(-1)",
"x = input()\r\ny= input()\r\ndef res(x,y):\r\n arr= list()\r\n p = True\r\n for i in range(len(x)):\r\n if x[i] < y[i]:\r\n p = False\r\n break\r\n \r\n elif x[i] == y[i]:\r\n arr.append(x[i])\r\n else:\r\n arr.append(y[i])\r\n \r\n if p:\r\n print(*arr,sep = '')\r\n else:\r\n print(-1)\r\n\r\nres(x,y)",
"from sys import exit\r\nx=input()\r\nn=len(x)\r\ny=input()\r\nfor i in range(n):\r\n if x[i]<y[i]:\r\n print(-1)\r\n exit()\r\nprint(y)",
"a=input()\r\nop=input()\r\nb=''\r\nflag=0\r\nfor i,j in zip(a,op):\r\n if(i==j):\r\n b+='z'\r\n if(i>j):\r\n b+=j\r\n if(i<j):\r\n flag=1\r\n break\r\nif(flag==0):\r\n print(b)\r\nelse:\r\n print(-1)",
"x = str(input())\r\ny = str(input())\r\nc = ''\r\nv = 1\r\nfor j in range (len(x)):\r\n if y[j] <= x[j]:\r\n c += y[j]\r\n else:\r\n v = 0\r\n print (-1)\r\n break\r\nif v == 1:\r\n print (c)",
"x, y, z = input(), input(), ''\nfor i, j in zip(x, y):\n if i < j:\n print(- 1)\n exit()\n z += j if i > j else 'z'\nprint(z)",
"s1 = input()\r\ns2 = input()\r\n\r\ns = \"\"\r\nfor i in range(len(s1)):\r\n if s1[i] < s2[i]:\r\n print(-1)\r\n break\r\n else:\r\n if s1[i] == s2[i]:\r\n s+=s1[i]\r\n else:\r\n s+=s2[i]\r\n \r\nelse:\r\n print(s)\r\n",
"x, y = input().strip(), input().strip()\r\nprint(y if all(x[i] >= y[i] for i in range(len(y))) else -1)\r\n",
"x = input()\r\ny = input()\r\nres = \"\"\r\nf = False\r\nfor i in range(len(x)):\r\n if x[i] < y[i]:\r\n f = True\r\n break\r\n else:\r\n res += y[i]\r\nif f :\r\n print(-1)\r\nelse:\r\n print(res)",
"s1=list(input())\r\ns2=list(input())\r\nans=[]\r\nfor i in range(len(s1)):\r\n if s2[i]<=s1[i]:\r\n ans.append(s2[i])\r\nif len(ans)==len(s1):\r\n print(*ans,sep=\"\")\r\nelse:\r\n print(-1)",
"s1 = input()\r\ns2 = input()\r\nfor i in range(len(s1)):\r\n if s1[i] < s2[i]:\r\n print(-1)\r\n exit(0)\r\nprint(s2)\r\n",
"def main():\n (str1, str2) = (input(), input())\n n = len(str1)\n str3 = [''] * n\n impossible = False\n\n for i in range(n):\n if str2[i] > str1[i]:\n impossible = True\n break\n str3[i] = str2[i]\n\n print(-1 if impossible else ''.join(str3))\n\n\nif __name__ == '__main__':\n main()\n",
"import sys\r\nx=list(map(ord,list(input())))\r\nz=list(map(ord,list(input())))\r\n#x+y=z\r\ny=[]\r\nf=True\r\nfor i in range(len(x)):\r\n if x[i]>=z[i]:\r\n y.append(z[i])\r\n elif x[i]<z[i]:\r\n print(-1)\r\n f=False\r\n break\r\nif f:\r\n s=''\r\n for i in range(len(x)):\r\n s=s+chr(y[i])\r\n print(s)\r\n",
"x, y = input(), input()\nif ''.join(map(min, x, y)) != y:\n print(-1)\nelse:\n print(y)\n",
"s=str(input())\r\ns1=str(input())\r\nl=[]\r\nt=\"\"\r\nfor i in range(len(s)):\r\n f=chr(min(ord(s[i]),ord(s1[i])))\r\n t=t+f\r\n#print(t)\r\nif t==s1:\r\n print(s1)\r\nelse:\r\n print(-1)\r\n ",
"x=input()\r\ny=input()\r\nfor i in range(len(x)):\r\n if (x[i]<y[i]):\r\n print(-1)\r\n exit()\r\nprint(y)\r\n",
"x =(input())\ny =(input())\nn = len(x)\n\nfail = False\nfor (a,b) in zip(x,y):\n if (a<b):\n fail = True\n\nif fail:\n print(-1)\nelse:\n print(y)\n\n\n",
"s1 = input()\r\ns2 = input()\r\nfor index, x in enumerate(s1):\r\n if s2[index] > x:\r\n print(-1)\r\n break\r\nelse:\r\n print(s2)",
"x=input()\r\ny=input()\r\n\r\nflag=0\r\nfor i in range(len(x)):\r\n\tif y[i] > x[i] :\r\n\t\tflag=1\r\n\t\tbreak\r\nout =''\r\nif flag == 1:\r\n\tprint(-1)\r\nelse:\r\n\tfor j in range(len(x)):\r\n\t\tout += min(x[j],y[j])\r\n\tprint(out)",
"a = input()\nb = input()\nc = ''.join([min(a[i],b[i]) for i in range(0,len(a))])\nif c==b:\n print(c)\nelse:\n print(-1)",
"s1=input()\r\ns2=input()\r\nl=len(s1)\r\nx=\"\"\r\nfor i in range(l):\r\n if s1[i]==s2[i]:\r\n x+=\"z\"\r\n elif s1[i]<s2[i]:\r\n print(-1)\r\n break\r\n else:\r\n x+=s2[i]\r\nif len(x)==l:\r\n print(x)\r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n",
"x = input()\r\ny = input()\r\n\r\nl = len(x)\r\nimpossible = False\r\nz = [''] * l\r\nfor i in range(l):\r\n\tif y[i] > x[i]:\r\n\t\timpossible = True\r\n\t\tbreak\r\n\telif y[i] == x[i]:\r\n\t\tz[i] = 'z'\t\r\n\telse:\r\n\t\tz[i] = y[i]\r\n\t\t\r\nif impossible:\r\n\tprint(-1)\r\nelse:\r\n\tprint(''.join(z))\t\t",
"s1=input()\r\ns2=input()\r\ns=\"\"\r\nfor i in range(len(s1)):\r\n if ord(s1[i]) < ord(s2[i]):\r\n s=\"\"\r\n break\r\n else:\r\n s=s+s2[i]\r\nif s==\"\":\r\n print(-1)\r\nelse:\r\n print(s)\r\n",
"x=input()\ny=input()\ntam=len(x)\nz=['z']*tam\ncent=True\ni=0\nwhile (i<tam and cent):\n if x[i]>y[i]:\n z[i]=y[i]\n elif x[i]<y[i]:\n cent=False\n i+=1\nif cent:\n print(''.join(z))\nelse:\n print (-1)\n \t\t \t\t\t \t \t \t\t\t\t\t",
"x=input()\r\nz=input()\r\nf='YES'\r\nx1=''\r\nfor i in range (len (x)):\r\n if ord(z[i])>ord(x[i]):\r\n f=\"NO\"\r\n break\r\n else:\r\n #print(x[i],z[i],min(x[i],z[i]))\r\n x1+=min(x[i],z[i])\r\n #print(x1)\r\n \r\nif f=='YES':\r\n print(x1)\r\nelse:\r\n print(-1)\r\n",
"x = input()\ny = input()\n\nz = \"\"\n\nfor i, l in enumerate(y):\n if l > x[i]:\n z = \"-1\"\n break\n elif l <= x[i]:\n z += l\n\nprint(z)\n",
"x = input()\r\ny = input()\r\nz = []\r\n\r\nfor i in range(len(x)):\r\n if y[i] > x[i]:\r\n print(-1)\r\n break\r\n if x[i] > y[i]:\r\n z.append(y[i])\r\n else:\r\n z.append('z')\r\n if i == len(x)-1:\r\n print(''.join(z))",
"# bsdk idhar kya dekhne ko aaya hai, khud kr!!!\r\n# import math\r\n# from itertools import *\r\n# import random\r\n# import calendar\r\n# import datetime\r\n# import webbrowser\r\n\r\n\r\nstring1 = input()\r\nstring2 = input()\r\nans = \"\"\r\nfor i in range(len(string1)):\r\n if string2[i] == string1[i]:\r\n if string2[i] == \"z\":\r\n ans += \"z\"\r\n else:\r\n ans += chr(ord(string2[i]) + 1)\r\n elif string2[i] > string1[i]:\r\n print(-1)\r\n break\r\n elif string2[i] < string1[i]:\r\n ans += string2[i]\r\nelse:\r\n print(ans)\r\n",
"s1 = input()\ns2 = input()\nif ''.join(map(min, s1, s2)) != s2:\n print(-1)\nelse:\n print(s2)\n\n \t\t\t\t \t \t\t\t \t\t \t \t \t",
"x=input()\r\ny=input()\r\nz=\"\"\r\nfor i in range(len(x)):\r\n if x[i]>=y[i]:\r\n z+=y[i]\r\n else:\r\n z=\"-1\"\r\n break\r\nprint(z)\r\n",
"n=input()\r\nm=input()\r\nfor i in range(len(m)):\r\n if n[i]<m[i]:\r\n print(-1)\r\n exit(0)\r\nprint(m)",
"x = input()\r\ny = input()\r\nz = \"\"\r\nn = len(x)\r\nt = True\r\nfor i in range(n):\r\n if y[i]>x[i]:\r\n t = False\r\n break\r\n if y[i]<=x[i]:\r\n z += y[i]\r\n\r\nif t:\r\n print(z)\r\nelse:\r\n print(-1)",
"x=input()\r\nz=input()\r\ny=''\r\np=0\r\nfor i in range(len(x)):\r\n if x[i]<z[i]:\r\n p=1\r\n else:\r\n y=y+z[i]\r\nif p==1:\r\n print(-1)\r\nelse:\r\n print(y)\r\n",
"a = input()\nb = input()\ns = \"\"\nn = len(a)\nfor i in range(n):\n if b[i] > a[i]:\n print(-1)\n exit()\n if a[i] > b[i]:\n s += b[i]\n else:\n if ord(a[i]) < 122:\n s += chr(ord(a[i]) + 1)\n else:\n s += b[i]\nprint(s)",
"a=input()\r\nb=input()\r\nd=[]\r\nh=0\r\nfor i in range(len(a)):\r\n if b[i]<a[i]:\r\n d.append(b[i])\r\n elif b[i]>a[i]:\r\n h=1\r\n else:\r\n d.append('z')\r\nif h==1:\r\n print(-1)\r\nelse:\r\n print(*d,sep='')",
"\r\nimport math\r\ndef get():\r\n return list(map(int, input().split()))\r\ndef intput():\r\n return int(input())\r\n\r\ndef main():\r\n a=input()\r\n b=input()\r\n ans=''\r\n for i in range(len(a)):\r\n ans=ans+min(a[i],b[i],key=ord)\r\n print (b if b==ans else -1)\r\n\r\n\r\nmain()",
"a = input()\r\nb = input()\r\n\r\nanswer = list()\r\n\r\nfor i in range(len(a)):\r\n if a[i] < b[i]:\r\n print(-1)\r\n break\r\n elif a[i] == b[i]:\r\n answer.append('z')\r\n else:\r\n answer.append(b[i])\r\n\r\nelse:\r\n print(''.join(answer))\r\n",
"x = input().strip()\r\ny = input().strip()\r\nif any(map(lambda xx, yy: xx < yy, x, y)):\r\n print(-1) \r\nelse:\r\n print(y) ",
"x=input()\r\ny=input()\r\nflag=True\r\nfor i in range(len(x)):\r\n if(x[i]<y[i]):\r\n flag=False\r\n break\r\nif(flag):\r\n print(y)\r\nelse:\r\n print(-1)",
"x = list(input())\nz = list(input())\nn = len(x)\ny = []\nfor i in range(n):\n if z[i] == x[i]:\n y.append('z')\n elif z[i] < x[i]:\n y.append(z[i])\n else:\n exit(print(-1))\n\nprint(\"\".join(y))",
"\r\ndef f(x, y):\r\n res = \"\"\r\n\r\n for i in range(len(x)):\r\n if x[i] < y[i] :\r\n return -1\r\n \r\n if x[i] == y[i] :\r\n res += x[i]\r\n else :\r\n res += y[i]\r\n\r\n return res \r\n \r\n\r\nx = input()\r\ny = input()\r\n\r\n\r\nprint(f(x, y))",
"import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nx = input()[:-1]\r\ny = input()[:-1]\r\nfor i in range(len(x)):\r\n if ord(x[i]) < ord(y[i]):\r\n print(-1)\r\n break\r\nelse:\r\n print(y)",
"a=input()\r\nb=input()\r\nfor i in range(len(a)):\r\n if b[i]>a[i]:\r\n print(-1)\r\n exit(0)\r\nprint(b)",
"def f(x, y):\r\n return [min(x[i], y[i]) for i in range(len(x))]\r\n\r\nX = list(input())\r\nY = list(input())\r\nif f(X, Y) == Y:\r\n print(''.join(Y))\r\nelse:\r\n print(-1)",
"s = input()\r\nt = input()\r\nres = ''\r\nmi = 'a'\r\nflag = True\r\nfor i in range(len(s)):\r\n a = s[i]\r\n b = t[i]\r\n if a == b:\r\n res += a\r\n else:\r\n if b < a and b >= mi:\r\n res += b\r\n else:\r\n flag = False\r\n break\r\nif flag:\r\n print(res)\r\nelse:\r\n print(-1)",
"x = input()\r\n\r\ny = input()\r\n\r\nif any(x[i] < y[i] for i in range(len(x))):\r\n print(-1)\r\nelse:\r\n print(y)",
"s1 = input()\ns2 = input()\nfor i in range(len(s1)):\n\tif not s2[i]<=s1[i]:\n\t\tprint(-1)\n\t\texit(0)\n\t\nelse:\n\tprint(s2)\n",
"a = input()\r\nb = input()\r\nf = 1\r\ns=\"\"\r\nfor i in range(len(a)):\r\n if(a[i] >= b[i]):\r\n s += b[i]\r\n else:\r\n f = 0\r\n break\r\nif f == 1:\r\n print(s)\r\nelse:\r\n print(-1)",
"s=str(input())\r\ns1=str(input())\r\nd=''\r\nflag=0\r\nfor i in range(0,len(s)):\r\n if(s1[i]>s[i]):\r\n flag=1\r\n break\r\n elif(s1[i]==s[i]):\r\n d=d+'z'\r\n else:\r\n d=d+s1[i]\r\nif(flag>0):\r\n print(-1)\r\nelse:\r\n print(d)",
"def solve():\n a = input()\n c = input()\n b = \"\"\n\n n = len(a)\n for i in range(n):\n if a[i] == c[i]:\n b += 'z'\n elif a[i] > c[i]:\n b += c[i]\n else:\n print(-1)\n return\n\n print(b)\n return\n\n\ndef main():\n test = 1\n # test = int(input())\n for tc in range(1, test + 1):\n solve()\n\n\nif __name__ == \"__main__\":\n main()\n\n\t\t \t \t\t\t\t\t \t\t\t \t\t \t\t \t \t\t",
"x = input()\r\ny = input()\r\nz = ''\r\nst = False\r\nfor i in range(len(x)):\r\n if x[i] < y[i]:\r\n st = True\r\n break\r\n elif x[i] >= y[i]:\r\n z += y[i]\r\nif not st:\r\n print(z)\r\nelse:\r\n print(-1)",
"def main():\n x = input()\n y = input()\n z = \"\"\n for i in range(0, len(x)):\n \n if (ord(x[i]) - ord(y[i])) < 0:\n print(-1)\n return\n elif (ord(x[i]) - ord(y[i])) == 0:\n z += x[i]\n else:\n z += y[i]\n print(z)\n\n\nif __name__ == \"__main__\":\n main()\n\n",
"import sys\r\n\r\nx = input()\r\ny = input()\r\nz = \"\"\r\nfor i in range(len(x)):\r\n if ord(y[i])>ord(x[i]):\r\n print(\"-1\")\r\n sys.exit(0)\r\n elif ord(y[i]) == ord(x[i]):\r\n z = z+x[i]\r\n else:\r\n z = z+y[i]\r\nprint(z)",
"s=input()\r\nl=input()\r\nprint(-1 if any(s[i]<l[i] for i in range(0,len(s))) else l)\r\n \r\n \r\n ",
"x = input()\ny = input()\nres = ''\nfor k, v in enumerate(y):\n if v > x[k]:\n print(-1)\n break\n res += v\n\nif len(res) == len(y):\n print(res)\n",
"x,y=input(),input()\r\nprint('-1' if any(y[i]>x[i] for i in range(len(x))) else y)",
"def solve():\r\n x = input()\r\n y = input()\r\n result = \"\"\r\n \r\n for i in range(len(x)):\r\n if x[i] == y[i]:\r\n result += x[i]\r\n elif x[i] > y[i]:\r\n result += y[i]\r\n else:\r\n print(-1)\r\n \r\n return\r\n \r\n print(result)\r\n \r\n \r\nif __name__ == \"__main__\":\r\n solve()\r\n ",
"x=str(input())\ny=str(input())\nans=''\nb=0\nfor i in range(len(x)):\n if y[i]>x[i]:\n b=1\n break\n elif y[i]==x[i]:\n ans+=x[i]\n else:\n ans+=y[i]\nif b==0:\n print(ans)\nelse:\n print(-1)\n",
"\r\n\r\n\r\nR = lambda:map(int,input().split())\r\ns_one = input()\r\ns_two = input()\r\n\r\nprint([s_two, -1][any(y>x for x, y in zip(s_one, s_two))])\r\n\r\n",
"def solve():\r\n ans = ''\r\n s1, s2 = input(), input()\r\n for i in range(len(s1)):\r\n if s2[i] > s1[i]:\r\n return -1\r\n ans += min(s1[i], s2[i])\r\n return ans\r\nprint(solve())",
"s=input()\r\nr=input()\r\nx=0\r\nfor i in range(len(s)):\r\n if(s[i]<r[i]):\r\n x=1\r\n break\r\nif(x):\r\n print(-1)\r\nelse:\r\n print(r)",
"dic={\"a\":1,\"b\":2,\"c\": 3,\"d\": 4,\"e\": 5,\"f\": 6,\"g\": 7,\"h\": 8,\"i\": 9,\"j\": 10,\"k\": 12,\"l\": 13,\"m\": 14,\"n\": 15,\"o\": 16,\"p\": 17,\"q\": 18,\"r\": 19,\"s\": 20,\"t\": 21,\"u\": 22,\"v\": 23,\"w\": 24,\"x\": 25,\"y\": 26,\"z\":27}\r\nx=input()\r\nz=input()\r\ny=\"\"\r\nfor i in range(len(x)):\r\n if dic[x[i]]>dic[z[i]]:\r\n y+=z[i]\r\n elif dic[x[i]]==dic[z[i]]:\r\n y+=\"z\"\r\n else:\r\n y=-1\r\n break\r\nprint(y)",
"a,b=list(input()),list(input());t=''\r\nfor x,y in zip(a,b):\r\n if x>=y:t+=y\r\n else:t=-1;break\r\nprint(t)\r\n",
"s1=list(input())\r\ns2=list(input())\r\ns=[]\r\nfor i in range(len(s1)):\r\n s.append(min(s1[i],s2[i]))\r\nif(s==s2):\r\n print(''.join(s2))\r\nelse:\r\n print('-1')\r\n ",
"a, b = input(), input()\r\nfor i in range(len(a)):\r\n if (a[i] < b[i]): print(-1), exit(0)\r\nprint(b)",
"def f(s1, s2):\r\n res = ['0'] * len(s1)\r\n for i in range(len(s1)):\r\n sim1 = ord(s1[i])\r\n sim2 = ord(s2[i])\r\n res[i] = chr(min(sim1, sim2))\r\n \r\n return ''.join(res)\r\n \r\ns1 = input()\r\ns2 = input()\r\n\r\nif f(s1, s2) != s2:\r\n print(-1)\r\nelse:\r\n print(s2)",
"def main():\r\n x = input()\r\n y = input()\r\n \r\n for i in range(len(x)):\r\n if x[i] < y[i]:\r\n return -1\r\n \r\n return y\r\n\r\nprint(main())\r\n",
"import string\r\n\r\ndef main_funtion():\r\n alphabet = list(string.ascii_lowercase)\r\n x = input()\r\n y = input()\r\n answer = \"\"\r\n for i in range(len(x)):\r\n if x[i] == y[i]:\r\n answer += \"z\"\r\n elif x[i] > y[i]:\r\n answer += y[i]\r\n else:\r\n return \"-1\"\r\n return answer\r\n\r\n\r\n\r\n\r\n\r\n\r\nprint(main_funtion())",
"import sys\r\nx = input()\r\ny = input()\r\n\r\nneg = 0\r\nz = ''\r\nfor i in range(len(x)):\r\n if ord(y[i]) > ord(x[i]):\r\n neg = 1\r\n break\r\n else:\r\n if x[i] == y[i]:\r\n z += 'z'\r\n else:\r\n z += y[i]\r\nif neg == 1:\r\n print('-1')\r\nelse:\r\n print(z)",
"import string\r\nl= list(string.ascii_lowercase)\r\nn=input()\r\nx=input()\r\nt=1\r\nfor i in range(len(n)):\r\n if l.index(n[i])<l.index(x[i]):\r\n t=0\r\n break\r\nif t==1:\r\n print(x)\r\nelse:\r\n print(-1)\r\n",
"first = input()\r\nfinal = input()\r\nsecond = \"\"\r\nfor i in range(first.__len__()):\r\n if final[i] > first[i]:\r\n print(-1)\r\n quit()\r\n elif final[i] == first[i] or final[i] < first[i]:\r\n second += final[i]\r\nprint(second)",
"import math as mt \r\nimport sys,string,bisect\r\ninput=sys.stdin.readline\r\nimport random\r\nfrom collections import deque,defaultdict\r\nL=lambda : list(map(int,input().split()))\r\nLs=lambda : list(input().split())\r\nM=lambda : map(int,input().split())\r\nI=lambda :int(input())\r\nd=defaultdict(int)\r\na=input().strip()\r\nb=input().strip()\r\nz=''\r\nfor i in range(len(a)):\r\n if(a[i]<b[i]):\r\n print(-1)\r\n exit()\r\n if(a[i]>b[i]):\r\n z+=b[i]\r\n else:\r\n z+=a[i]\r\nprint(z)\r\n \r\n",
"z = []\nfor a, b in zip(input(), input()):\n if a < b:\n print(-1)\n break\n else:\n z.append(b)\nelse:\n print(''.join(z))",
"#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nx = input()\ny = input()\n\nY = ''.join(map(min, zip(x, y)))\n\nif Y != y:\n Y = -1\nprint(Y)\n",
"a, b = input(), input()\r\nans = ''\r\nif a.islower() and b.islower() and len(a) == len(b) and a.isalpha() and b.isalpha():\r\n for i in range(len(a)):\r\n if ord(a[i]) < ord(b[i]):\r\n print(-1)\r\n exit(0)\r\n print(b)\r\n\r\nelse:\r\n print(-1)\r\n\r\n",
"a=input()\r\nb=input()\r\nret=1\r\nfor i in range(0,len(a)):\r\n if(a[i]<b[i]):\r\n ret=-1\r\nif(ret==-1):\r\n print(-1)\r\nelse:\r\n print(b)\r\n",
"a=input()\r\nb=input()\r\nc=\"abcdefghijklmnopqrstuvwxyz\"\r\nd=[]\r\nh=0\r\nfor i in range(len(a)):\r\n if c.find(b[i])<c.find(a[i]):\r\n d.append(b[i])\r\n elif c.find(b[i])>c.find(a[i]):\r\n h=1\r\n else:\r\n d.append('z')\r\nif h==1:\r\n print(-1)\r\nelse:\r\n print(*d,sep='')",
"x = (input())\r\ny = list(input())\r\n\r\nflag = True\r\n\r\nfor i in range(len(y)):\r\n if y[i] > x[i]:\r\n flag = False\r\n break\r\n\r\nif flag == False:\r\n print('-1')\r\n\r\nelse:\r\n print(''.join(y))\r\n\r\n",
"x, y = input(), input()\nres = y if all(y[i] <= x[i] for i in range(len(x))) else -1\nprint(res)\n",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nx = list(input().rstrip())\r\ny = list(input().rstrip())\r\nans = []\r\nfor i, j in zip(x, y):\r\n if i < j:\r\n ans = [\"-1\"]\r\n break\r\n ans.append(chr(min(i, j)))\r\nsys.stdout.write(\"\".join(ans))",
"a = input()\r\nb = input()\r\nc=''\r\nfor i in range(len(a)):\r\n if b[i]>a[i]:\r\n print('-1')\r\n quit()\r\n else:\r\n c+=b[i] \r\nprint(c)\r\n\t",
"s1,s2 = input(), input()\r\nfor c1,c2 in zip(s1,s2):\r\n if ord(c1) < ord(c2):\r\n print(-1)\r\n quit()\r\nelse:\r\n print(s2)",
"x = list(input()); y = list(input())\r\nprint(-1 if any(b>a for a, b in zip(x,y)) else ''.join(y))",
"s=input()\ns1=input()\nflag=1\nz=\"\"\nfor i in range(len(s)):\n if(s[i]==s1[i]):\n if(s[i]<'z'):\n z+=chr(ord(s[i])+1)\n else:\n z+=s[i];\n elif(s[i]>s1[i]):\n z+=s1[i]\n elif(s[i]<s1[i]):\n flag=0\n break\nif(flag>0):\n print(z)\nelse:\n print(\"-1\")\n \t \t \t\t \t\t \t\t\t\t \t \t\t\t\t \t",
"s1, s2 = input(), input()\r\nout = ''\r\nfor i in range(0, len(s1)):\r\n if s1[i] >= s2[i]:\r\n out += s2[i]\r\n else:\r\n out = '-1'\r\n break\r\nprint(out)\r\n",
"a=input()\r\nb=input()\r\nx=''\r\nfor i in range(len(a)):\r\n if a[i]==b[i]:\r\n x+='z'\r\n elif a[i]>b[i]:\r\n x+=b[i]\r\n elif a[i]<b[i]:\r\n print('-1')\r\n quit()\r\nprint(x)\r\n \r\n",
"x=input()\r\nz=input()\r\ny=''\r\nfor i in range (len(z)):\r\n if z[i]<x[i]:\r\n y=y+z[i]\r\n elif z[i]==x[i] :\r\n y=y+'z'\r\n else :\r\n print (-1)\r\n break\r\nif len(y)==len(x):\r\n print(y)\r\n",
"import sys\r\nimport math\r\nimport bisect\r\nimport itertools\r\nimport random\r\nimport re\r\n\r\ndef solve(x, y):\r\n n = len(x)\r\n for i in range(n):\r\n if ord(y[i]) > ord(x[i]):\r\n return False\r\n return True\r\n\r\ndef main():\r\n x = input()\r\n y = input()\r\n if solve(x, y):\r\n print(y)\r\n else:\r\n print(-1)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"x = input()\ny = input()\nfor i in range(len(x)):\n\tif x[i] < y[i]:\n\t\tprint(-1)\n\t\texit()\nprint(y)\n\n\t\t\t\t \t\t \t\t \t \t \t\t\t \t\t \t \t"
] | {"inputs": ["ab\naa", "nzwzl\nniwel", "ab\nba", "r\nl", "d\ny", "yvowz\ncajav", "lwzjp\ninjit", "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm", "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs", "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf", "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen", "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb", "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym", "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib", "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew", "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv", "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns", "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf", "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp", "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp", "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej", "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe", "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang", "ftfr\nftfr", "ftr\nftr", "shftr\nshftr", "vkvkkv\nvkvkkv", "ftrd\nftrd", "fztr\nfztr", "frtr\nfrtr", "shdftr\nshdftr", "zzz\nzzz", "shtr\nshtr", "aaaaa\nzzzzz", "efr\nefr"], "outputs": ["ba", "xiyez", "-1", "l", "-1", "cajav", "-1", "eodnlemiicdedmkcgavqbnqmm", "-1", "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf", "-1", "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb", "-1", "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib", "-1", "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv", "-1", "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf", "-1", "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp", "-1", "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe", "-1", "ftfr", "ftr", "shftr", "vkvkkv", "ftrd", "fztr", "frtr", "shdftr", "zzz", "shtr", "-1", "efr"]} | UNKNOWN | PYTHON3 | CODEFORCES | 287 | |
2e1370625bc74674d7dc606d54188d02 | Almost Arithmetic Progression | Polycarp likes arithmetic progressions. A sequence $[a_1, a_2, \dots, a_n]$ is called an arithmetic progression if for each $i$ ($1 \le i < n$) the value $a_{i+1} - a_i$ is the same. For example, the sequences $[42]$, $[5, 5, 5]$, $[2, 11, 20, 29]$ and $[3, 2, 1, 0]$ are arithmetic progressions, but $[1, 0, 1]$, $[1, 3, 9]$ and $[2, 3, 1]$ are not.
It follows from the definition that any sequence of length one or two is an arithmetic progression.
Polycarp found some sequence of positive integers $[b_1, b_2, \dots, b_n]$. He agrees to change each element by at most one. In the other words, for each element there are exactly three options: an element can be decreased by $1$, an element can be increased by $1$, an element can be left unchanged.
Determine a minimum possible number of elements in $b$ which can be changed (by exactly one), so that the sequence $b$ becomes an arithmetic progression, or report that it is impossible.
It is possible that the resulting sequence contains element equals $0$.
The first line contains a single integer $n$ $(1 \le n \le 100\,000)$ — the number of elements in $b$.
The second line contains a sequence $b_1, b_2, \dots, b_n$ $(1 \le b_i \le 10^{9})$.
If it is impossible to make an arithmetic progression with described operations, print -1. In the other case, print non-negative integer — the minimum number of elements to change to make the given sequence becomes an arithmetic progression. The only allowed operation is to add/to subtract one from an element (can't use operation twice to the same position).
Sample Input
4
24 21 14 10
2
500 500
3
14 5 1
5
1 3 6 9 12
Sample Output
3
0
-1
1
| [
"n = int(input())\r\nsequence = list(map(int, input().split()))\r\nsequences = list()\r\nif(n < 3):\r\n print(0)\r\nelse:\r\n bigFlag = True\r\n minCount = float('inf')\r\n for i in [0,1,-1]:\r\n for j in [0,1,-1]:\r\n seq = sequence.copy()\r\n seq[0] = seq[0] + i\r\n seq[1] = seq[1] + j\r\n diff = seq[1] - seq[0]\r\n count = 0\r\n flag = True\r\n for k in range(1,n-1):\r\n if((seq[k+1] - seq[k])==1 + diff):\r\n seq[k+1] = seq[k+1] - 1\r\n count = count + 1\r\n elif((seq[k+1] - seq[k])==-1 + diff):\r\n seq[k+1] = seq[k+1] + 1\r\n count = count + 1\r\n elif((seq[k+1] - seq[k])==diff):\r\n continue\r\n else:\r\n flag = False\r\n break\r\n if flag:\r\n bigFlag = False\r\n if not i ==0:\r\n count = count + 1\r\n if not j == 0:\r\n count = count + 1\r\n if count<minCount:\r\n minCount = count\r\n else:\r\n continue\r\n if bigFlag:\r\n print(-1)\r\n else:\r\n print(minCount)",
"ints = lambda: list(map(int, input().split()))\r\n\r\nn = int(input())\r\na = ints()\r\nif len(a) < 3:\r\n print(0)\r\n exit()\r\nf, s = a[0], a[1]\r\nans = 10000000000000000\r\nfor x in range(-1, 2):\r\n for y in range(-1, 2):\r\n b = a + []\r\n b[0] = a[0] + x\r\n b[1] = a[1] + y\r\n d = b[1] - b[0]\r\n res = abs(x) + abs(y)\r\n ok = True\r\n for i in range(2, len(a)):\r\n if abs(b[i] - b[i - 1] - d) > 1:\r\n ok = False\r\n break\r\n if abs(b[i] - b[i - 1] - d) == 1:\r\n res += 1\r\n b[i] = b[i - 1] + d\r\n if ok:\r\n ans = min(res, ans)\r\n \r\nif ans != 10000000000000000:\r\n print(ans)\r\nelse:\r\n print(-1)",
"#!/usr/bin/env python3\r\n\r\nimport math\r\nimport sys\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\nfrom bisect import bisect_left as bs\r\n\r\ndef test_case():\r\n n = int(input())\r\n b = list(map(int, input().split()))\r\n\r\n if len(b) <= 2:\r\n print(0)\r\n return\r\n\r\n opt = [-1, 0, 1]\r\n ans = float(\"inf\")\r\n for o1 in opt:\r\n for o2 in opt:\r\n poss = True\r\n cnt = (1 if o1 != 0 else 0) + (1 if o2 != 0 else 0)\r\n a = b.copy()\r\n a[0] += o1\r\n a[1] += o2\r\n d = a[1]-a[0]\r\n for i in range(2, n):\r\n if a[i]-a[i-1] == d:\r\n continue\r\n if a[i]-a[i-1] == d-1:\r\n a[i] += 1\r\n cnt += 1\r\n elif a[i]-a[i-1] == d+1:\r\n a[i] -= 1\r\n cnt += 1\r\n else:\r\n poss = False\r\n break\r\n if poss:\r\n ans = min(ans, cnt)\r\n print(ans if ans != float(\"inf\") else -1)\r\n\r\n\r\n\r\n\r\ndef main():\r\n t = 1\r\n# t = int(input())\r\n for _ in range(t):\r\n test_case()\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"\r\ndef getint():\r\n return [int(i) for i in input().split()]\r\ndef get():\r\n return int(input())\r\ndef getstr():\r\n return [i for i in input().split()]\r\ndef S():\r\n for test in range(int(input())):\r\n solve()\r\nimport math\r\nimport itertools as it\r\nimport bisect\r\nimport time\r\nimport collections as ct\r\n\r\ndef lower_bound(a,x):\r\n l=-1\r\n r=len(a)\r\n while l+1!=r:\r\n mid=l+r>>1\r\n if a[mid]<x:\r\n l=mid\r\n else:\r\n r=mid\r\n return r\r\ndef upper_bound(a,x):\r\n l=-1\r\n r=len(a)\r\n while l+1!=r:\r\n mid=l+r>>1\r\n if a[mid]<=x:\r\n l=mid\r\n else:\r\n r=mid\r\n return r\r\ndef solve():\r\n n=get()\r\n\r\n\r\n\r\nn=get()\r\na=getint()\r\nans=[]\r\nfor i in range(1,n):\r\n ans.append(a[i]-a[i-1])\r\nx=set(ans)\r\nif len(x)==1 or n==1:\r\n print(0)\r\n exit(0)\r\nd=a[1]-a[0]\r\nd_list=[d+1,d-1,d+2,d-2,d]\r\nd=a[0]\r\na_list=[d+1,d-1,d]\r\nans=n+5\r\nfor d in d_list:\r\n for a0 in a_list:\r\n res=0\r\n if a[0]!=a0:\r\n res+=1\r\n for i in range(1,n):\r\n if a[i]-a0!=i*d:\r\n if a[i]-a0==i*d+1:\r\n res+=1\r\n elif a[i]-a0==i*d-1:\r\n res+=1\r\n else:\r\n break\r\n else:\r\n continue\r\n else:\r\n ans=min(ans,res)\r\nif ans==n+5:\r\n ans=-1\r\nprint(ans)",
"n = int(input())\r\nif n == 1:\r\n ans = 0\r\nelse:\r\n a = list(map(int, input().split()))\r\n ans = min(\r\n sum([0, 1, float('inf')][min(2, abs(v + (w - v) * i - x))] for i, x in enumerate(a))\r\n for v in range(a[0]-1,a[0]+2)\r\n for w in range(a[1]-1,a[1]+2))\r\nprint(ans if ans < float('inf') else -1)\r\n",
"# https://codeforces.com/contest/978\n\nimport sys\nimport math\n\ninput = lambda: sys.stdin.readline().rstrip() # faster!\n\nn = int(input())\nb = list(map(int, input().split()))\n\nif n == 1 or n == 2:\n print(0)\n exit()\n\nans = math.inf\nfor d0 in [-1, 0, 1]:\n for d1 in [-1, 0, 1]:\n a0 = b[0] + d0\n a1 = b[1] + d1\n delta = a1 - a0\n changes = 0\n ok = True\n for i in range(n):\n d = abs(a0 + i * delta - b[i])\n if d <= 1:\n changes += d\n else:\n ok = False\n break\n if ok:\n ans = min(ans, changes)\n\nif ans == math.inf:\n print(-1)\nelse:\n print(ans)\n",
"n = int(input())\r\narr = [int(i) for i in input().split()]\r\n\r\nif n<3:\r\n print(0)\r\n exit()\r\n\r\nans = []\r\n\r\nfor i in range(-1,2):\r\n for j in range(-1,2):\r\n a = arr[0] + i\r\n b = arr[1] + j\r\n changes = abs(i) + abs(j)\r\n diff = b-a\r\n curr = b+diff\r\n for k in range(2,n):\r\n add = abs(arr[k]-curr)\r\n curr += diff\r\n if add<2:\r\n changes += add\r\n else:\r\n changes = n+1\r\n break\r\n ans.append(changes)\r\n\r\nans = min(ans)\r\nif ans == n+1: print(-1)\r\nelse: print(ans)\r\n",
"from sys import stdin, stdout, stderr\n\nn = int(stdin.readline())\na = list(map(int, stdin.readline().split()))\n\nif n <= 2:\n print(0)\n exit()\n\nans = int(1e18)\nfor i in range(a[0] - 1, a[0] + 2):\n for j in range(a[1] - 1, a[1] + 2):\n diff = i - j \n ok = True\n cur = 0\n\n if i != a[0]:\n cur += 1\n if j != a[1]:\n cur += 1\n \n for k in range(2, n):\n val = i - diff * k\n if abs(val - a[k]) > 1:\n # stderr.write(\"{} {} {} {}\\n\".format(i, j, k, val))\n ok = False\n break\n elif abs(val - a[k]) == 1:\n cur += 1\n \n if ok:\n # stderr.write(\"{} {} {}\\n\".format(i, j, cur))\n ans = min(ans, cur)\n\nif ans == int(1e18):\n stdout.write(\"-1\\n\")\nelse:\n stdout.write(str(ans) + \"\\n\")",
"from collections import *\r\nfrom heapq import *\r\nfrom bisect import *\r\nfrom itertools import *\r\nfrom functools import *\r\nfrom math import *\r\nfrom string import *\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef query(A, prev, k):\r\n n = len(A)\r\n ans = 0\r\n for i in range(1, n):\r\n for x in range(A[i] - 1, A[i] + 2):\r\n if prev + k == x:\r\n ans += +(x != A[i])\r\n prev = x\r\n break\r\n else:\r\n return inf\r\n return ans\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n A = list(map(int, input().split()))\r\n\r\n if len(A) <= 2:\r\n return 0\r\n\r\n ans = inf\r\n first_val = A[0]\r\n\r\n for first in range(A[0] - 1, A[0] + 2):\r\n for second in range(A[1] - 1, A[1] + 2):\r\n changes = +(A[0] != first) + query(A, first, second - first)\r\n ans = min(ans, changes)\r\n\r\n return ans if ans < inf else -1\r\n\r\n\r\ndef main():\r\n print(solve())\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nprev = [(0, 'any', 'any')]\r\nfor num in arr:\r\n curr = []\r\n for cost, val, gap in prev:\r\n for op in [1, 0, -1]:\r\n new_cost, new_num = cost+abs(op), num+op\r\n if val == 'any':\r\n curr.append((new_cost, new_num, 'any'))\r\n elif gap == 'any':\r\n curr.append((new_cost, new_num, val-(new_num)))\r\n else:\r\n if val-(new_num) == gap:\r\n curr.append((new_cost, new_num, val-(new_num)))\r\n \r\n if curr:\r\n prev = curr\r\n else:\r\n print(-1)\r\n break\r\nelse:\r\n print(sorted(curr)[0][0])",
"import math\n\nn = int(input())\nb = list(map(int, input().split()))\nif len(b) <= 2:\n print(0)\n exit()\n\nopt = math.inf\nfor d0 in -1, 0, 1:\n start = b[0] + d0\n for d1 in -1, 0, 1:\n step = (b[1] + d1) - start\n total = abs(d0) + abs(d1)\n for i in range(2, n):\n d = abs(b[i] - (start + step * i))\n if d > 1:\n break\n total += d\n else:\n opt = min(opt, total)\nprint(-1 if opt is math.inf else opt)\n",
"def solve():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n if n <= 2:\r\n print(0)\r\n else:\r\n final_ans = float('inf')\r\n for i in [-1, 0, 1]:\r\n for j in [-1, 0, 1]:\r\n a0 = a[0] + i\r\n a1 = a[1] + j\r\n prev = a1\r\n cnt = abs(i) + abs(j)\r\n diff = a1 - a0\r\n\r\n for k in range(2, n):\r\n nxt_elm = prev + diff\r\n if abs(nxt_elm - a[k]) == 1:\r\n cnt += 1\r\n elif abs(nxt_elm - a[k]) > 1:\r\n cnt = float('inf')\r\n break\r\n\r\n prev = nxt_elm\r\n\r\n final_ans = min(cnt, final_ans)\r\n\r\n print(final_ans if final_ans != float('inf') else -1)\r\n\r\n\r\nsolve()\r\n",
"n = int (input())\r\narr = list (map (int, input().split(' ')) )\r\nif (n <= 2 ):\r\n print (0)\r\n exit() \r\nans = -1\r\none = [0,-1,1]\r\ntwo = [0,-1,1] \r\nfor i in one:\r\n for j in two: \r\n d = (arr[1]-j) - (arr[0]-i) \r\n x = arr[0] - i \r\n res = 0 \r\n if i != 0: \r\n res = 1 \r\n ok = True\r\n for ind in range (1, n) :\r\n y = x + d \r\n if y != arr[ind]: \r\n ok &= abs (arr[ind] - y ) <= 1 \r\n res+=1\r\n x = y \r\n if not ok:\r\n continue\r\n if ans != -1 : \r\n ans = min (ans, res) \r\n else :\r\n ans = res \r\nprint (ans)\r\n \r\n \r\n\r\n\r\n",
"def process(a1, a2, a, n):\r\n d = a2 - a1\r\n cur = a2\r\n res = 0\r\n for i in range(2, n):\r\n if abs(cur + d - a[i]) > 1:\r\n return float('inf')\r\n if abs(cur + d - a[i]) != 0:\r\n res += 1\r\n cur += d\r\n return res\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n if n <= 2:\r\n print(\"0\")\r\n else:\r\n res = float('inf')\r\n d1 = [-1, 0, 1]\r\n d2 = [-1, 0, 1]\r\n for i in d1:\r\n for j in d2:\r\n add = (i != 0) + (j != 0)\r\n res = min(res, process(a[0] + i, a[1] + j, a, n) + add)\r\n if res == float('inf'):\r\n res = -1\r\n print(res)\r\n",
"import sys\r\nfrom collections import deque\r\ninput = sys.stdin.readline\r\n\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nres = 10 ** 6\r\nf = True\r\nif n == 1:\r\n print(0)\r\nelse:\r\n for d1 in (-1, 0, 1):\r\n v1 = arr[0] + d1\r\n for d2 in (-1, 0, 1):\r\n v2 = arr[1] + d2\r\n d = v2 - v1\r\n\r\n changes = int(arr[0] != v1) + int(arr[1] != v2)\r\n\r\n for i in range(2, n):\r\n val = abs(d * i + v1 - arr[i])\r\n if val > 1:\r\n changes = 10 ** 6\r\n break\r\n changes += val\r\n\r\n res = min(changes, res)\r\n\r\n print(-1 if res == 10 ** 6 else res)\r\n"
] | {"inputs": ["4\n24 21 14 10", "2\n500 500", "3\n14 5 1", "5\n1 3 6 9 12", "1\n1000000000", "2\n1000000000 1", "3\n34 70 52", "3\n1 2 1", "6\n1 1 3 5 6 5", "3\n2 1 2", "10\n9 5 3 4 7 1 2 8 10 6", "4\n20 15 20 15", "4\n10 21 14 24", "3\n5 9 5", "10\n10 9 8 7 6 1 2 3 4 5", "4\n2 6 3 1", "5\n1 3 6 8 10", "4\n1 3 1 3", "3\n3 1 2", "3\n33 69 51", "4\n1 1000000000 1000000000 1000000000", "5\n2 1 3 4 5", "3\n1 9 4", "3\n2 1 3", "3\n9 3 6", "3\n1 10 5"], "outputs": ["3", "0", "-1", "1", "0", "0", "-1", "1", "4", "1", "-1", "-1", "-1", "-1", "-1", "-1", "2", "4", "2", "-1", "-1", "2", "-1", "2", "-1", "-1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
2e3e8778fe44cc6b2615f3f2a5de5634 | Roma and Poker | Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma started to play poker. He decided to spend no more than *k* virtual bourles — he will stop immediately if the number of his loses exceeds the number of his wins by *k*. Also Roma will leave the game if he wins enough money for the evening, i.e. if the number of wins exceeds the number of loses by *k*.
Next morning Roma found a piece of paper with a sequence on it representing his results. Roma doesn't remember the results exactly, and some characters in the sequence are written in a way such that it's impossible to recognize this character, so Roma can't recall whether he won *k* bourles or he lost.
The sequence written by Roma is a string *s* consisting of characters W (Roma won the corresponding hand), L (Roma lost), D (draw) and ? (unknown result). Roma wants to restore any valid sequence by changing all ? characters to W, L or D. The sequence is called valid if all these conditions are met:
- In the end the absolute difference between the number of wins and loses is equal to *k*; - There is no hand such that the absolute difference before this hand was equal to *k*.
Help Roma to restore any such sequence.
The first line contains two numbers *n* (the length of Roma's sequence) and *k* (1<=≤<=*n*,<=*k*<=≤<=1000).
The second line contains the sequence *s* consisting of characters W, L, D and ?. There are exactly *n* characters in this sequence.
If there is no valid sequence that can be obtained from *s* by replacing all ? characters by W, L or D, print NO.
Otherwise print this sequence. If there are multiple answers, print any of them.
Sample Input
3 2
L??
3 1
W??
20 5
?LLLLLWWWWW?????????
Sample Output
LDL
NO
WLLLLLWWWWWWWWLWLWDW
| [
"N,k=list(map(int,input().strip().split(' ')))\r\nS=input()\r\n# num of W-num of L=j, j>k means k-j\r\ndp=[[0 for j in range(2*k+1)]for i in range(N)]\r\n#print(dp) \r\nfor i in range(len(S)):\r\n if i==0:\r\n if S[0]=='W':\r\n dp[0][1]='W'\r\n elif S[0]=='L':\r\n dp[0][-1]='L'\r\n elif S[0]=='D':\r\n dp[0][0]='D'\r\n else:\r\n dp[0][1]='W'\r\n dp[0][-1]='L'\r\n dp[0][0]='D'\r\n elif i!=len(S)-1:\r\n if S[i]=='W':\r\n for j in range(0,k):\r\n if j==0:\r\n if dp[i-1][-1]!=0:\r\n dp[i][0]='W'\r\n else:\r\n if dp[i-1][j-1]!=0:\r\n dp[i][j]='W'\r\n for j in range(1,k):\r\n if j!=k-1:\r\n if dp[i-1][-j-1]!=0:\r\n dp[i][-j]='W'\r\n elif S[i]=='L':\r\n for j in range(0,k):\r\n if dp[i-1][j+1]!=0:\r\n dp[i][j]='L'\r\n for j in range(1,k):\r\n if j==1:\r\n if dp[i-1][0]!=0:\r\n dp[i][-1]='L'\r\n else:\r\n if dp[i-1][-j+1]!=0:\r\n dp[i][-j]='L'\r\n elif S[i]=='D':\r\n for j in range(0,2*k+1):\r\n if dp[i-1][j]!=0:\r\n dp[i][j]='D'\r\n else:\r\n for j in range(0,k):\r\n if j==0:\r\n if dp[i-1][-1]!=0:\r\n dp[i][j]='W'\r\n elif dp[i-1][1]!=0:\r\n dp[i][j]='L'\r\n elif dp[i-1][0]!=0:\r\n dp[i][j]='D'\r\n else:\r\n if dp[i-1][j-1]!=0:\r\n dp[i][j]='W'\r\n elif dp[i-1][j+1]!=0:\r\n dp[i][j]='L'\r\n elif dp[i-1][j]!=0:\r\n dp[i][j]='D'\r\n for j in range(1,k):\r\n if j==1:\r\n if dp[i-1][0]!=0:\r\n dp[i][-1]='L'\r\n elif dp[i-1][-1]!=0:\r\n dp[i][-1]='D'\r\n elif dp[i-1][-2]!=0:\r\n dp[i][-1]='W'\r\n else:\r\n if dp[i-1][-(j-1)]!=0:\r\n dp[i][-j]='L'\r\n elif dp[i-1][-j]!=0:\r\n dp[i][-j]='D'\r\n elif dp[i-1][-(j+1)]!=0:\r\n dp[i][-j]='W'\r\n else:\r\n if S[i]=='W':\r\n if dp[i-1][k-1]!=0:\r\n dp[i][k]='W'\r\n elif S[i]=='L':\r\n if dp[i-1][-(k-1)]!=0:\r\n dp[i][-k]='L'\r\n elif S[i]=='D':\r\n 1\r\n else:\r\n if dp[i-1][k-1]!=0:\r\n dp[i][k]='W'\r\n elif dp[i-1][-(k-1)]!=0:\r\n dp[i][-k]='L'\r\n \r\n#print(dp)\r\nif k>1 and N>=k:\r\n if dp[len(S)-1][k]==0 and dp[len(S)-1][-k]==0:\r\n print('NO')\r\n else:\r\n if dp[len(S)-1][k]!=0:\r\n ans=''\r\n cur=k\r\n for j in range(1,len(S)+1):\r\n temp=dp[len(S)-j][cur]\r\n if temp=='W':\r\n ans+=temp\r\n cur-=1\r\n elif temp=='D':\r\n ans+=temp\r\n elif temp=='L':\r\n ans+=temp\r\n cur+=1\r\n elif dp[len(S)-1][-k]!=0:\r\n ans=''\r\n cur=-k\r\n for j in range(1,len(S)+1):\r\n temp=dp[len(S)-j][cur]\r\n if temp=='W':\r\n ans+=temp\r\n cur-=1\r\n elif temp=='D':\r\n ans+=temp\r\n elif temp=='L':\r\n ans+=temp\r\n cur+=1\r\n ans=ans[::-1]\r\n print(ans)\r\nelif N<k:\r\n print('NO')\r\nelif k==1:\r\n shit=0\r\n \r\n for i in range(len(S)):\r\n if i<len(S)-1:\r\n if S[i]!='?':\r\n shit=1\r\n break\r\n if shit==1:\r\n print('NO')\r\n else:\r\n temp=''\r\n for i in range(len(S)-1):\r\n temp+='D'\r\n if S[-1]=='D':\r\n print('NO')\r\n elif S[-1]=='L':\r\n temp+='L'\r\n print(temp)\r\n else:\r\n temp+='W'\r\n print(temp)\r\n \r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n \r\n\r\n ",
"# by the authority of GOD author: manhar singh sachdev #\r\n\r\nimport os,sys\r\nfrom io import BytesIO,IOBase\r\n\r\ndef main():\r\n n,k = map(int,input().split())\r\n s = input().strip()\r\n dp = [[0]*(2*k+5) for _ in range(n+1)]\r\n # diff ; win/draw/lose\r\n dp[0][0] = 1\r\n prev = [[-1]*(2*k+5) for _ in range(n+1)]\r\n for i in range(1,n):\r\n for j in range(-k+1,k):\r\n if (s[i-1] == '?' or s[i-1] == 'L') and dp[i-1][j+1]:\r\n dp[i][j] = 1\r\n prev[i][j] = 'L'\r\n if (s[i-1] == '?' or s[i-1] == 'D') and dp[i-1][j]:\r\n dp[i][j] = 1\r\n prev[i][j] = 'D'\r\n if (s[i-1] == '?' or s[i-1] == 'W') and dp[i-1][j-1]:\r\n dp[i][j] = 1\r\n prev[i][j] = 'W'\r\n for j in range(-k,k+1):\r\n if (s[n-1] == '?' or s[n-1] == 'L') and dp[n-1][j+1]:\r\n dp[n][j] = 1\r\n prev[n][j] = 'L'\r\n if (s[n-1] == '?' or s[n-1] == 'D') and dp[n-1][j]:\r\n dp[n][j] = 1\r\n prev[n][j] = 'D'\r\n if (s[n-1] == '?' or s[n-1] == 'W') and dp[n-1][j-1]:\r\n dp[n][j] = 1\r\n prev[n][j] = 'W'\r\n if not dp[n][k] and not dp[n][-k]:\r\n print('NO')\r\n exit()\r\n elif dp[n][k]:\r\n st = k\r\n else:\r\n st = -k\r\n ans = []\r\n dct = {'L':1,'W':-1,'D':0}\r\n for i in range(n,0,-1):\r\n l = prev[i][st]\r\n ans.append(l)\r\n st += dct[l]\r\n print(''.join(ans[::-1]))\r\n\r\n# Fast IO Region\r\nBUFSIZE = 8192\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n def __init__(self,file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))\r\n self.newlines = b.count(b\"\\n\")+(not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd,self.buffer.getvalue())\r\n self.buffer.truncate(0),self.buffer.seek(0)\r\nclass IOWrapper(IOBase):\r\n def __init__(self,file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s:self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda:self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda:self.buffer.readline().decode(\"ascii\")\r\nsys.stdin,sys.stdout = IOWrapper(sys.stdin),IOWrapper(sys.stdout)\r\ninput = lambda:sys.stdin.readline().rstrip(\"\\r\\n\")\r\nif __name__ == \"__main__\":\r\n main()",
"import sys\r\n\r\ndef solve():\r\n n, k = map(int, input().split())\r\n s = input()\r\n\r\n dp = [[False]*(2*k + 1) for i in range(n + 1)]\r\n dp[0][0] = True\r\n\r\n keiro = [['']*(2*k + 1) for i in range(n + 1)]\r\n\r\n for i, ch in enumerate(s):\r\n if ch == 'W':\r\n for j in range(-(k - 2), k + 1):\r\n if dp[i][j - 1]:\r\n dp[i + 1][j] = True\r\n keiro[i + 1][j] = 'W'\r\n elif ch == 'L':\r\n for j in range(-k, k - 1):\r\n if dp[i][j + 1]:\r\n dp[i + 1][j] = True\r\n keiro[i + 1][j] = 'L'\r\n elif ch == 'D':\r\n for j in range(-(k - 1), k):\r\n if dp[i][j]:\r\n dp[i + 1][j] = True\r\n keiro[i + 1][j] = 'D'\r\n else:\r\n for j in range(-k, k + 1):\r\n if j + 1 < k and dp[i][j + 1]:\r\n dp[i + 1][j] = True\r\n keiro[i + 1][j] = 'L'\r\n elif -k < j < k and dp[i][j]:\r\n dp[i + 1][j] = True\r\n keiro[i + 1][j] = 'D'\r\n elif j - 1 > -k and dp[i][j - 1]:\r\n dp[i + 1][j] = True\r\n keiro[i + 1][j] = 'W'\r\n\r\n if dp[n][k] or dp[n][-k]:\r\n ans = ''\r\n\r\n if dp[n][k]:\r\n pos = k\r\n else:\r\n pos = -k\r\n\r\n for i in range(n, 0, -1):\r\n ans = keiro[i][pos] + ans\r\n\r\n if keiro[i][pos] == 'W':\r\n pos -= 1\r\n elif keiro[i][pos] == 'L':\r\n pos += 1\r\n else:\r\n ans = 'NO'\r\n\r\n print(ans)\r\n\r\nif __name__ == '__main__':\r\n solve()",
"n,k=map(int,input().split())\r\ns=input()\r\nm=2*k+1\r\ndp=[[0]*m for i in range(n+1)]\r\ndp[0][k]=1\r\nfor i in range(n):\r\n if s[i]=='L' or s[i]=='?':\r\n for j in range(m-1):\r\n dp[i+1][j]|=dp[i][j+1]\r\n if s[i]=='D' or s[i]=='?':\r\n for j in range(m):\r\n dp[i+1][j]|=dp[i][j]\r\n if s[i]=='W' or s[i]=='?':\r\n for j in range(1,m):\r\n dp[i+1][j]|=dp[i][j-1]\r\n \r\n if i!=n-1:\r\n dp[i+1][0]=0\r\n dp[i+1][2*k]=0\r\n\r\nif dp[n][0]:\r\n tmp=0\r\nelif dp[n][2*k]:\r\n tmp=2*k\r\nelse:\r\n print('NO')\r\n exit()\r\n\r\nans=''\r\nfor i in range(n-1,-1,-1):\r\n if s[i]=='L':\r\n ans+='L'\r\n tmp+=1\r\n elif s[i]=='D':\r\n ans+='D'\r\n elif s[i]=='W':\r\n ans+='W'\r\n tmp-=1\r\n else:\r\n if tmp>0 and dp[i][tmp-1]:\r\n ans+='W'\r\n tmp-=1\r\n elif dp[i][tmp]:\r\n ans+='D'\r\n elif tmp<2*k and dp[i][tmp+1]:\r\n ans+='L'\r\n tmp+=1\r\n else:\r\n raise Exception\r\n\r\nprint(ans[::-1])",
"n, k = map(int, input().split())\n*v, l = input()\nsets = [(0, 0)]\nd = {'W' : +1, 'D': 0, 'L': -1}\nfor c in v:\n ms, mx = sets[-1]\n ns = max(1 - k, ms + d.get(c, -1))\n nx = min(k - 1, mx + d.get(c, +1))\n if ns > nx:\n print('NO')\n exit(0)\n sets.append((ns, nx))\n\nms, mx = sets[-1]\nif mx == k - 1 and l in '?W':\n cur = k - 1\n ans = ['W']\nelif ms == 1 - k and l in '?L':\n cur = 1 - k\n ans = ['L']\nelse:\n print('NO')\n exit(0)\n\nans += list(reversed(v))\nfor i, (c, (s, x)) in enumerate(zip(reversed(v), sets[-2::-1])):\n if c == '?':\n ans[i + 1] = next(p for p, q in d.items() if s <= cur - q and cur - q <= x)\n cur -= d[ans[i + 1]]\n\nprint(''.join(reversed(ans)))\n",
"N, K = map( int, input().split() )\r\nS = input()\r\n\r\noffset = K + 1\r\ndp = [ [ False for i in range( offset * 2 ) ] for j in range( N + 1 ) ]\r\npre = [ [ 0 for i in range( offset * 2 ) ] for j in range( N + 1 ) ] # previous state\r\ndp[ 0 ][ offset ] = True\r\nfor i in range( N ):\r\n for j in range( offset * 2 ):\r\n if not dp[ i ][ j ]: continue\r\n if ( S[ i ] == 'W' or S[ i ] == '?' ) and not ( i + 1 < N and j + 1 >= offset + K ):\r\n if not dp[ i + 1 ][ j + 1 ]:\r\n dp[ i + 1 ][ j + 1 ] = True\r\n pre[ i + 1 ][ j + 1 ] = j\r\n if ( S[ i ] == 'L' or S[ i ] == '?' ) and not ( i + 1 < N and j - 1 <= offset - K ):\r\n if not dp[ i + 1 ][ j - 1 ]:\r\n dp[ i + 1 ][ j - 1 ] = True\r\n pre[ i + 1 ][ j - 1 ] = j\r\n if S[ i ] == 'D' or S[ i ] == '?':\r\n if not dp[ i + 1 ][ j ]:\r\n dp[ i + 1 ][ j ] = True\r\n pre[ i + 1 ][ j ] = j\r\n\r\nif not dp[ N ][ offset + K ] and not dp[ N ][ offset - K ]:\r\n print( \"NO\" )\r\nelse:\r\n ans = \"\"\r\n i, j = N, offset + K if dp[ N ][ offset + K ] else offset - K\r\n while i:\r\n pj = pre[ i ][ j ]\r\n if S[ i - 1 ] == '?':\r\n if pj + 1 == j:\r\n ans += \"W\"\r\n elif pj - 1 == j:\r\n ans += \"L\"\r\n else:\r\n ans += \"D\"\r\n else:\r\n ans += S[ i - 1 ]\r\n i, j = i - 1, pj\r\n print( ans[ : : -1 ] )\r\n",
"def ma():\r\n s=input()\r\n v=s.split(' ')\r\n n=int(v[0])\r\n k=int(v[1])\r\n s=input()\r\n dp=[[0,0] for _ in range(n+1)]\r\n flag=True\r\n for i in range (1,n):\r\n c=s[i-1]\r\n if c=='?':\r\n dp[i][0]=min(dp[i-1][0]+1 ,k-1)\r\n dp[i][1]=max(dp[i-1][1]-1 ,-k+1)\r\n elif c=='D':\r\n dp[i][0]=dp[i-1][0]\r\n dp[i][1]=dp[i-1][1]\r\n elif c=='W':\r\n dp[i][0]=min(dp[i-1][0]+1 ,k-1)\r\n dp[i][1]=dp[i-1][1]+1 \r\n if dp[i][1]==k:\r\n flag=False\r\n elif c=='L':\r\n dp[i][0]=dp[i-1][0]-1 \r\n dp[i][1]=max(dp[i-1][1]-1 ,-k+1)\r\n if dp[i][0]==-k:\r\n flag=False\r\n if not flag:\r\n print('NO')\r\n return\r\n i=n\r\n if s[i-1]=='?':\r\n dp[i][0]=dp[i-1][0]+1 \r\n dp[i][1]=dp[i-1][1]-1 \r\n elif s[i-1]=='D':\r\n dp[i][0]=dp[i-1][0]\r\n dp[i][1]=dp[i-1][1]\r\n elif s[i-1]=='W':\r\n dp[i][0]=dp[i-1][0]+1 \r\n dp[i][1]=dp[i-1][1]+1 \r\n \r\n elif s[i-1]=='L':\r\n dp[i][0]=dp[i-1][0]-1 \r\n dp[i][1]=dp[i-1][1]-1\r\n res=['?']*n\r\n if dp[i][0]==k or dp[i][1]==-k:\r\n if dp[i][0]==k:\r\n cur=k\r\n else:\r\n cur=-k\r\n for i in range(n-1,-1,-1):\r\n c=s[i]\r\n if c=='?':\r\n if cur>dp[i][0]:\r\n cur=cur-1\r\n res[i]='W'\r\n elif dp[i][1]<=cur<=dp[i][0]:\r\n cur=cur\r\n res[i]='D'\r\n elif cur<dp[i][1]:\r\n cur=cur+1\r\n res[i]='L'\r\n elif c=='D':\r\n cur=cur\r\n res[i]=c\r\n elif c=='W':\r\n cur=cur-1\r\n res[i]=c\r\n elif c=='L':\r\n cur=cur+1\r\n res[i]=c\r\n for i in range(n):\r\n print(res[i],end='')\r\n \r\n else:\r\n print('NO')\r\nma()",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\ns = list(input().rstrip())\r\nd = {\"W\":-1, \"D\":0, \"L\":1}\r\ndp = []\r\ndp0 = [0] * (2 * k + 1)\r\ndp0[k] = 1\r\ndp.append(list(dp0))\r\nfor i in range(n):\r\n si = s[i]\r\n dp1 = [0] * (2 * k + 1)\r\n if si == \"?\":\r\n for j in range(1, 2 * k):\r\n if dp0[j]:\r\n for l in range(j - 1, j + 2):\r\n dp1[l] = 1\r\n else:\r\n c = d[si]\r\n for j in range(1, 2 * k):\r\n if dp0[j]:\r\n dp1[j + c] = 1\r\n dp0 = list(dp1)\r\n dp.append(list(dp0))\r\nif not dp[n][0] and not dp[n][2 * k]:\r\n ans = list(\"NO\")\r\nelse:\r\n ans = []\r\n x = n - 1\r\n y = 0 if dp[n][0] else 2 * k\r\n for _ in range(n):\r\n dp[x][0], dp[x][2 * k] = 0, 0\r\n sx = s[x]\r\n if not sx == \"?\":\r\n ans.append(sx)\r\n y -= d[sx]\r\n else:\r\n ok = 0\r\n for i in list(\"LDW\"):\r\n c = -d[i]\r\n if 0 <= y + c <= 2 * k:\r\n if dp[x][y + c]:\r\n ans.append(i)\r\n y += c\r\n ok = 1\r\n if ok:\r\n break\r\n x -= 1\r\n ans.reverse()\r\nprint(\"\".join(ans))"
] | {"inputs": ["3 2\nL??", "3 1\nW??", "20 5\n?LLLLLWWWWW?????????", "5 5\n?WDDD", "5 3\n??D??", "10 1\nD??W?WL?DW", "10 3\nDWD?DL??LL", "10 2\nLWL?WWDDW?", "1 1\n?"], "outputs": ["LDL", "NO", "WLLLLLWWWWWWWWLWLWDW", "NO", "WWDDW", "NO", "DWDWDLLLLL", "NO", "W"]} | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
2e858831c5d5ca3e65edb181f56bc650 | Ancient Prophesy | A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").
The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.
A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.
Notice, that any year between 2013 and 2015 is not a leap year.
The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.
In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.
Sample Input
777-444---21-12-2013-12-2013-12-2013---444-777
Sample Output
13-12-2013 | [
"import sys\r\nfrom functools import lru_cache, cmp_to_key\r\nfrom heapq import merge, heapify, heappop, heappush\r\nfrom math import *\r\nfrom collections import defaultdict as dd, deque, Counter as C\r\nfrom itertools import combinations as comb, permutations as perm\r\nfrom bisect import bisect_left as bl, bisect_right as br, bisect, insort\r\nfrom time import perf_counter\r\nfrom fractions import Fraction\r\nimport copy\r\nfrom copy import deepcopy\r\nimport time\r\nstarttime = time.time()\r\nmod = int(pow(10, 9) + 7)\r\nmod2 = 998244353\r\n\r\ndef data(): return sys.stdin.readline().strip()\r\ndef out(*var, end=\"\\n\"): sys.stdout.write(' '.join(map(str, var))+end)\r\ndef L(): return list(sp())\r\ndef sl(): return list(ssp())\r\ndef sp(): return map(int, data().split())\r\ndef ssp(): return map(str, data().split())\r\ndef l1d(n, val=0): return [val for i in range(n)]\r\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\r\ntry:\r\n # sys.setrecursionlimit(int(pow(10,6)))\r\n sys.stdin = open(\"input.txt\", \"r\")\r\n # sys.stdout = open(\"output.txt\", \"w\")\r\nexcept:\r\n pass\r\ndef pmat(A):\r\n for ele in A: print(*ele,end=\"\\n\")\r\n\r\nfrom collections import Counter\r\n \r\nnumbers = '0123456789'\r\ndays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n \r\ndef check(s):\r\n if s[2] != '-' or s[5] != '-':\r\n return False\r\n if any(c not in numbers for (i, c) in enumerate(s) if i != 2 and i != 5):\r\n return False\r\n d = int(s[:2])\r\n m = int(s[3:5])\r\n y = int(s[6:])\r\n if y < 2013 or y > 2015:\r\n return False\r\n if m == 0 or m > 12:\r\n return False\r\n return d != 0 and d <= days[m - 1]\r\n \r\ns = input()\r\nprint(Counter(s[i:i+10] for i in range(len(s) - 9) if check(s[i:i+10])).most_common(1)[0][0])",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import defaultdict,deque\r\nfrom datetime import datetime\r\n\r\ndef validate(date_text):\r\n try:\r\n if date_text != datetime.strptime(date_text, \"%d-%m-%Y\").strftime('%d-%m-%Y'):\r\n raise ValueError\r\n return True\r\n except ValueError:\r\n return False\r\n \r\nS = input()\r\ncur = deque([])\r\n\r\nlib = defaultdict(int)\r\ndef check(cur):\r\n if len(cur)!=10:return\r\n if cur[3]!='-' and cur[5]!='-':return\r\n arr = ''.join(cur).split('-')\r\n if len(arr)!=3:return\r\n yy = arr[2]\r\n if not yy in ('2013','2014','2015'):return\r\n \r\n date_text = ''.join(cur)\r\n if validate(date_text):\r\n lib[date_text]+=1\r\n \r\n\r\nfor c in S:\r\n cur.append(c)\r\n if len(cur)>10:\r\n cur.popleft()\r\n check(cur)\r\n \r\nans = ''\r\ncnt = 0\r\nfor k,v in lib.items():\r\n if v>cnt:\r\n ans = k\r\n cnt=v\r\nprint(ans)\r\n\r\n",
"s = input()\r\nd={}\r\nfor i in range(len(s)-9):\r\n\tf=0\r\n\tt = s[i:i+10]\r\n\tif t[2]=='-' and t[5]=='-':\r\n\t\ttry:\r\n\t\t\tdatex = int(t[0:2])\r\n\t\t\tmonthx = int(t[3:5])\r\n\t\t\tyearx = int(t[6:10])\r\n\t\t\tif monthx>0 and monthx<13:\r\n\t\t\t\tif yearx>2012 and yearx<2016:\r\n\t\t\t\t\tif monthx in [1,3,5,7,8,10,12]:\r\n\t\t\t\t\t\tif datex>0 and datex<32:\r\n\t\t\t\t\t\t\tf=1\r\n\t\t\t\t\telif monthx in [4,6,9,11]:\r\n\t\t\t\t\t\tif datex>0 and datex<31:\r\n\t\t\t\t\t\t\tf=1\r\n\t\t\t\t\telif monthx==2:\r\n\t\t\t\t\t\tif datex>0 and datex<29:\r\n\t\t\t\t\t\t\tf=1\r\n\t\t\tif f:\r\n\t\t\t\ttry:\r\n\t\t\t\t\td[t]+=1\r\n\t\t\t\texcept:\r\n\t\t\t\t\td[t]=1\r\n\t\texcept:\r\n\t\t\tcontinue\r\n\r\nprint(max(d, key = lambda x: d[x]))\r\n\r\n",
"from re import compile\r\nfrom collections import defaultdict\r\nfrom time import strptime\r\n\r\ndef validDate(date):\r\n try:\r\n strptime(date, \"%d-%m-%Y\")\r\n return True\r\n except:\r\n return False\r\n\r\nmyFormat = compile(r'(?=([0-2]\\d|3[0-1])-(0\\d|1[0-2])-(201[3-5]))' )\r\nDict = defaultdict(int)\r\nfor d in myFormat.finditer(input()):\r\n temp = \"-\".join([d.group(1),d.group(2),d.group(3)])\r\n if validDate (temp):\r\n Dict[temp] = -~Dict[temp]\r\nprint(max(Dict, key=Dict.get))",
"from datetime import datetime\r\nfrom collections import defaultdict\r\n\r\n# Check if the string is a valid date, as specified in the problem statement\r\ndef is_valid_date(date_string):\r\n format = \"%d-%m-%Y\"\r\n try:\r\n date = datetime.strptime(date_string, format)\r\n if date.year >= 2013 and date.year <= 2015:\r\n return True\r\n else:\r\n return False\r\n except ValueError:\r\n return False\r\n\r\n\r\ndef solve():\r\n prophecy = input().strip()\r\n\r\n # List all valid dates\r\n dates = []\r\n for i in range(len(prophecy) - 9):\r\n possible_date = prophecy[i : i + 10]\r\n if is_valid_date(possible_date):\r\n dates.append(possible_date)\r\n\r\n # Find the date which is mentioned the maximum number of times\r\n count = defaultdict(int)\r\n for date in dates:\r\n count[date] += 1\r\n\r\n print(max(count, key=count.get))\r\n\r\n\r\nsolve()\r\n",
"from sys import *\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom itertools import *\r\nfrom fractions import *\r\n\r\nInput = []\r\n\r\n#stdin = open('in', 'r')\r\n#stdout = open('out', 'w')\r\n\r\n## for i, val in enumerate(array, start_i_value)\r\n\r\ndef Out(x):\r\n stdout.write(str(x) + '\\n')\r\n\r\ndef In():\r\n return stdin.readline().strip()\r\n\r\ndef inputGrab():\r\n for line in stdin:\r\n Input.extend(map(str, line.strip().split()))\r\n'''--------------------------------------------------------------------------------'''\r\n\r\nans = dict()\r\n\r\ndef dateConv(dd, mm, yy):\r\n dds = str()\r\n if(dd < 10):\r\n dds = '0'+str(dd)\r\n else:\r\n dds = str(dd)\r\n mms = str()\r\n if(mm < 10):\r\n mms = '0'+str(mm)\r\n else:\r\n mms = str(mm)\r\n return dds+'-'+mms+'-'+str(yy)\r\n \r\n\r\ndef main():\r\n s = In()\r\n \r\n Date = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n \r\n MaxCnt = 0\r\n ans = str()\r\n \r\n \r\n for mm in range(1, 13):\r\n for dd in range(1, Date[mm-1]+1):\r\n for yy in range(2013, 2016):\r\n #print(\"Search for\", dateConv(dd, mm, yy))\r\n \r\n cnt = s.count(dateConv(dd, mm, yy))\r\n if cnt > MaxCnt:\r\n ans = dateConv(dd, mm, yy)\r\n MaxCnt = cnt\r\n \r\n print(ans)\r\n \r\nif __name__ == '__main__':\r\n main()\r\n",
"from datetime import datetime, timedelta\r\nimport re\r\n\r\nprophecy = str(input())\r\n\r\ndef date_range(start, end):\r\n delta = end - start # as timedelta\r\n days = [start + timedelta(days=i) for i in range(delta.days + 1)]\r\n return days\r\n\r\nstart_date = datetime(2013, 1, 1)\r\nend_date = datetime(2015, 12, 31)\r\ncount = dict()\r\n\r\nfor date in date_range(start_date, end_date):\r\n if date.day >= 10:\r\n day = str(date.day)\r\n else :\r\n day = \"0\" + str(date.day)\r\n if date.month >= 10:\r\n month = str(date.month)\r\n else :\r\n month = \"0\" + str(date.month)\r\n date_pattern = day + \"-\" + month + \"-\" + str(date.year)\r\n indices_object = re.finditer(pattern=date_pattern, string=prophecy)\r\n indices = [index.start() for index in indices_object]\r\n count[date_pattern] = len(indices)\r\nprint(max(count, key=count.get))",
"from operator import itemgetter\n\ndef var(a):\n\tsim = 0\n\n\tmes = {1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}\n\tdia = 0\n\n\tif a[2] >= 2013 and a[2] <= 2015:\n\t\tsim += 1\n\n\tif a[1] in mes:\n\t\tsim += 1\n\n\t\tdia = mes[a[1]]\n\n\tif a[0] <= dia and a[0] > 0:\n\t\tsim += 1\n\n\treturn sim \n\n\ndata = input()\n\ntam = len(data)\ni = 0\nj = 10\n\ndatas = dict()\n\nwhile j <= tam:\n\n\ta = data[i:j]\n\n\tif a[2] == a[5] and a[2] == '-':\n\t\ta = a.split('-')\n\t\tif len(a)==3:\n\t\t\topa = var(list(map(int,a)))\n\n\t\t\tif opa == 3:\n\t\t\t\taux = '-'.join(a)\n\t\t\t\tif aux in datas:\n\t\t\t\t\tdatas[aux] += 1\n\t\t\t\telse:\n\t\t\t\t\tdatas[aux] = 1\n\ti +=1\n\tj +=1\n\nprint(sorted(datas.items(), key=itemgetter(1))[-1][0])",
"import re \ns = input()\n# print(re.findall(\"(?=(\\d\\d\\d))\", s))\nx = re.findall(\"(?=(\\d\\d-\\d\\d-\\d\\d\\d\\d))\", s)\n# print(x)\nans = \"\"\n# print(x)\n# input()\n# print(x.split('-'))\n# input()\ndate_count = {}\nmax_count = 0\nfor date in x:\n d, m, y = [int(x) for x in date.split('-')]\n if(2013 <= y <= 2015 and 1 <= d <= 31 and 1 <= m <= 12):\n if m in [1, 3, 5, 7, 8, 10, 12] and 1 <= d <= 31:\n try:\n date_count[date] += 1\n except KeyError:\n date_count[date] = 1\n elif m == 2 and 1 <= d <= 28:\n try:\n date_count[date] += 1\n except KeyError:\n date_count[date] = 1\n elif m in [4, 6, 9, 11] and 1 <= d <= 30:\n try:\n date_count[date] += 1\n except KeyError:\n date_count[date] = 1 \n if date in date_count and date_count[date] > max_count:\n max_count = date_count[date]\n ans = date \n else:\n pass\n\n# print(x)\n# print(date_count)\nprint(ans)",
"s=input()\r\nl=len(s)\r\nm=['01','02','03','04','05','06','07','08','09','10','11','12']\r\nd=[31,28,31,30,31,30,31,31,30,31,30,31]\r\nans={}\r\nfor i in range(l-9):\r\n if s[i+2] == '-':\r\n if s[i+3]+s[i+4] in m:\r\n if s[i+5] == '-':\r\n if s[i+6]+s[i+7]+s[i+8]+s[i+9] in ['2013','2014','2015']:\r\n if s[i] in '0123456789':\r\n if s[i+1] in '0123456789':\r\n if int(s[i]+s[i+1])>0 and int(s[i]+s[i+1]) <= d[int(s[i+3]+s[i+4])-1]:\r\n if s[i:i+10] in ans:\r\n ans[s[i:i+10]]+=1\r\n else:\r\n ans[s[i:i+10]]=1\r\n#print(ans)\r\nx=-1\r\na=None\r\nfor i in ans:\r\n if ans[i]>x:\r\n x=ans[i]\r\n a=i\r\nprint(a)",
"s = input().split('-')\r\n\r\nex = {}\r\nans = 0\r\nsans = ''\r\n\r\ndef solve(i):\r\n global ex\r\n global ans\r\n global sans\r\n global s\r\n \r\n day = s[i]\r\n month = s[i+1]\r\n year = s[i+2]\r\n \r\n if len(day) < 2 or len(month) != 2 or len(year) < 4:\r\n return\r\n \r\n day = day[-2:]\r\n year = year[:4]\r\n \r\n if int(year) < 2013 or int(year) > 2015:\r\n return\r\n \r\n if int(month) < 1 or int(month) > 12:\r\n return\r\n \r\n if int(day) < 1 or int(day) > 31:\r\n return\r\n \r\n # verifica dia de acordo com o mês (meu Deus...)\r\n tm = int(month)\r\n \r\n if tm in [1, 3, 5, 7, 8, 10, 12] and int(day) > 31:\r\n return\r\n \r\n if tm == 2 and int(day) > 28:\r\n return\r\n \r\n if tm in [4, 6, 9, 11] and int(day) > 30:\r\n return\r\n \r\n date = day+month+year\r\n \r\n if date in ex:\r\n ex[date] += 1\r\n \r\n if ex[date] > ans:\r\n ans = ex[date]\r\n sans = date\r\n \r\n else:\r\n ex[date] = 1\r\n \r\n if ans == 0:\r\n ans = 1\r\n sans = date\r\n\r\ndef c(s):\r\n print(f'{s[:2]}-{s[2:4]}-{s[4:]}')\r\n\r\nfor i in range(len(s)-2):\r\n if len(s[i]) <= 1:\r\n continue\r\n \r\n solve(i)\r\n \r\nc(sans)",
"years = {\"2013\", \"2014\", \"2015\"}\nbase = set()\nfor i in range(1, 29):\n if i < 10:\n base.add(\"0\" + str(i))\n else:\n base.add(str(i))\ninfo1 = base.copy()\ninfo1.add(\"29\")\ninfo1.add(\"30\")\ninfo2 = info1.copy()\ninfo2.add(\"31\")\nmonths = {\n \"02\": base\n}\nfor i in [4, 6, 9, 11]:\n if i < 10:\n months[\"0\" + str(i)] = info1\n else:\n months[str(i)] = info1\nfor i in [1, 3, 5, 7, 8, 10, 12]:\n k = (\"0\" + str(i)) if i < 10 else str(i)\n months[k] = info2\n\ns = input()\n\ndef solve(s, years, months):\n maps = {}\n i = 0\n while i < len(s) - 9:\n if s[i+2] != \"-\" or s[i+5] != \"-\":\n i += 1\n continue\n d, m, y = s[i:i+2], s[i+3:i+5], s[i+6:i+10]\n if y in years and m in months and d in months[m]:\n k = s[i:i+10]\n maps[k] = maps.get(k, 0) + 1\n i += 1\n ans, count = \"\", 0\n for k, v in maps.items():\n if count < v:\n ans, count = k, v\n return ans \n \n\nans = solve(s, years, months)\nprint(ans)\n \t \t\t \t\t \t\t \t\t\t\t \t \t\t\t\t",
"def solve(s):\r\n d={1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}\r\n valid_dates={}\r\n y=[\"2013\",\"2014\",\"2015\"]\r\n for year in y:\r\n k=\"\"\r\n j=0\r\n for i in range(len(s)):\r\n if s[i]==year[j]:\r\n if j==len(year)-1:\r\n flag=0\r\n j=0\r\n if s[i-4]==\"-\" and s[i-7]==\"-\":\r\n try:\r\n if (int(s[i-6:i-4])>=1 and int(s[i-6:i-4])<=12):\r\n if int(s[i-9 :i-7])>=1 and int(s[i-9 :i-7])<=d[int(s[i-6:i-4])]:\r\n if s[i-9:i+1] not in valid_dates:\r\n valid_dates[s[i-9:i+1]]=1\r\n else:\r\n valid_dates[s[i-9:i+1]]+=1\r\n else:\r\n flag=1\r\n else:\r\n flag=1\r\n except:\r\n flag=1\r\n else:\r\n flag=1\r\n else:\r\n j+=1\r\n else:\r\n j=0\r\n return valid_dates\r\n \r\n \r\n \r\n\r\ns=input()\r\nm=0\r\nv=solve(s)\r\nprophecy_date=\"\"\r\nfor i in v:\r\n if v[i]>m:\r\n m=v[i]\r\n prophecy_date=i\r\nprint(prophecy_date)\r\n\r\n",
"from statistics import mode\r\nimport re\r\ndef findall(r, str):\r\n lst = []\r\n while len(str):\r\n m = re.search(r, str)\r\n if m:\r\n lst.append(m.group())\r\n str = str[m.start() + 1:]\r\n else:\r\n break\r\n return lst\r\nlst = []\r\nstr = input()\r\nlst1 = findall(r'([1-2][0-9]|[3][01]|[0][1-9])[-]([0][13578]|[1][02])[-]([2][0][1][3-5])', str)\r\nlst2 = findall(r'([1-2][0-9]|[3][0]|[0][1-9])[-]([0][469]|[1][1])[-]([2][0][1][3-5])', str)\r\nlst3 = findall(r'([1-2][0-8]|[0][1-9]|[1][9])[-][0][2][-][2][0][1][3-5]', str)\r\nprint(mode(lst1+lst2+lst3))\r\n\r\n",
"from re import findall\r\nfrom calendar import monthrange\r\nfrom collections import defaultdict\r\nn=input()\r\ndic=defaultdict(int)\r\nfor i in findall('(?=(\\d\\d-\\d\\d-201[3-5]))',n):\r\n d,m,y=map(int,i.split('-'))\r\n if 1<=m<=12 and 1<=d<=monthrange(y,m)[1]:\r\n dic[i]+=1\r\nprint(max(dic, key = dic.get))\r\n",
"s=input()\r\ntemp=[]\r\ntem=[]\r\nc=0\r\nmon=[31,28,31,30,31,30,31,31,30,31,30,31]\r\nf={}\r\nfor i in range(len(s)-10+1):\r\n x=s[i:i+10]\r\n if x[2]=='-' and x[5]=='-' and x.count('-')==2:\r\n #print(i)\r\n y=int(x[0:2])\r\n yy=int(x[3:5])\r\n yyy=int(x[-4:])\r\n #print(y,yy,yyy)\r\n if yyy>=2013 and yyy<=2015:\r\n if yy>=1 and yy<=12: \r\n if y<=mon[yy-1] and y>=1:\r\n try:\r\n f[x]+=1\r\n except:\r\n f[x]=1\r\n\r\nff={v:k for k,v in f.items()} \r\nprint(ff[max(ff.keys())]) ",
"from collections import defaultdict\r\nfrom datetime import date\r\n\r\ndef is_correct(s):\r\n if s.count('-') != 2 or s[2] != '-' or s[5] != '-':\r\n return False\r\n dd, mm, yyyy = map(int, s.split('-'))\r\n if not (2012 < yyyy < 2016 and 0 < mm < 13):\r\n return False\r\n try:\r\n date(yyyy, mm, dd)\r\n return True\r\n except:\r\n return False\r\n\r\ns, d = input(), defaultdict(int)\r\n\r\nfor i in range(len(s) - 9):\r\n d[s[i:i+10]] += 1\r\n\r\nfor s, k in sorted(d.items(), key=lambda x: -x[1]):\r\n if is_correct(s):\r\n print(s)\r\n break",
"import re, calendar,collections\r\na,s=collections.defaultdict(int),input()\r\nfor x in re.findall('(?=(\\d\\d-\\d\\d-201[3-5]))',s):\r\n d,m,y=map(int,x.split('-'))\r\n if 1<=m<=12 and 1<=d<=calendar.monthrange(y,m)[1]: a[x]+=1\r\nm=max(a.values())\r\nfor s,v in a.items():\r\n if v==m:print(s)\r\n\r\n\r\n'''\r\nfrom re import findall\r\n \r\nfrom calendar import monthrange\r\n \r\nfrom collections import defaultdict\r\n \r\nS = input()\r\n \r\nbag = defaultdict(int)\r\n \r\nfor s in findall('(?=(\\d\\d-\\d\\d-201[3-5]))', S): # (?=...) implies that overlap is allowed\r\n \r\n d, m, y = map(int, s.split('-'))\r\n \r\n if 1 <= m <= 12 and 1 <= d <= monthrange(y, m)[1]:\r\n \r\n bag[s] += 1\r\n \r\nprint(max(bag, key = bag.get))\r\n''' \r\n",
"s = input()\r\nx = s.split('-')\r\ncnt = {}\r\ndays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\nfor i in range(2, len(x)):\r\n day = x[i - 2][-2:]\r\n month = x[i - 1]\r\n year = x[i][:4]\r\n if len(year) == 4 and 2013 <= int(year) <= 2015 and len(day) == 2 and len(month) == 2:\r\n d = int(day)\r\n m = int(month)\r\n if 1 <= m <= 12 and 1 <= d <= days[m - 1]:\r\n key = '%s-%s-%s' % (day, month, year)\r\n cnt[key] = cnt.get(key, 0) + 1\r\nm = 0\r\nfor key, val in cnt.items():\r\n if val > m:\r\n m = val\r\n res = key\r\nprint(res)\r\n",
"from re import findall\r\nfrom calendar import monthrange\r\nfrom collections import defaultdict\r\nS = input()\r\nbag = defaultdict(int)\r\nfor s in findall('(?=(\\d\\d-\\d\\d-201[3-5]))', S):\r\n d, m, y = map(int, s.split('-'))\r\n if 1 <= m <= 12 and 1 <= d <= monthrange(y, m)[1]:\r\n bag[s] += 1\r\nprint(max(bag, key = bag.get))"
] | {"inputs": ["777-444---21-12-2013-12-2013-12-2013---444-777", "30-12-201429-15-208830-12-2014", "14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013", "15-11-201413-02-20147-86-25-298813-02-201413-02-201434615-11-201415-11-201415-11-201415-11-2014", "19-07-201419-07-201424-06-201719-07-201419-07-201413-10-201419-07-201468-01-201619-07-20142", "01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08-20159533-45-00-1212", "23-11-201413-07-201412-06-2015124-03-20140-19-201323-11-201424-03-2014537523-11-20143575015-10-2014", "15-04-201413-08-201589-09-201013-08-20130-74-28-201620-8497-14-1063713-08-2013813-02-201513-08-2013", "13-05-201412-11-2013-12-11-201314-12-201329-05-201306-24-188814-07-201312-11-201312-04-2010", "14-01-201402-04-201514-01-201485-26-1443948-14-278314-01-2014615259-09-178413-06-201314-05-2014", "31-12-201331-11-201331-11-2013", "01-01-2014", "32-13-2100-32-13-2100-32-13-2100-12-12-2013", "15-1--201315-1--201301-01-2013", "00-12-2014-00-12-2014-00-12-2014-12-12-2014", "120110201311-10-20151201102013", "31-08-2013---31-08-2013---03-03-2013", "12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013", "21-12-201221-12-201221-12-201221-12-201213-12-2013", "29-02-2013-02-2013-29-02-2013", "20-12-2012----20-12-2012-----01-01-2013", "01-2-02013---01-2-02013----13-02-2014", "11111111111111111111---21-12-2013", "29-02-2014--29-02-2014--28-02-2014", "29-02-201329-02-201321-12-2013", "01--01--2013-12-2013-01--01--2013", "10-10-2023-10-10-2023-10-10-2013"], "outputs": ["13-12-2013", "30-12-2014", "14-08-2013", "15-11-2014", "19-07-2014", "01-04-2014", "23-11-2014", "13-08-2013", "12-11-2013", "14-01-2014", "31-12-2013", "01-01-2014", "12-12-2013", "01-01-2013", "12-12-2014", "11-10-2015", "31-08-2013", "12-12-2013", "13-12-2013", "13-02-2013", "01-01-2013", "13-02-2014", "21-12-2013", "28-02-2014", "21-12-2013", "13-12-2013", "10-10-2013"]} | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
2ed4f6b0ea75c25b51bae97215bfef0b | none | A positive integer is called a 2-3-integer, if it is equal to 2*x*·3*y* for some non-negative integers *x* and *y*. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [*l*,<=*r*], i. e. the number of sich 2-3-integers *t* that *l*<=≤<=*t*<=≤<=*r*.
The only line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=2·109).
Print a single integer the number of 2-3-integers on the segment [*l*,<=*r*].
Sample Input
1 10
100 200
1 2000000000
Sample Output
7
5
326
| [
"l,r=map(int,input().split())\r\nans=0\r\nfor i in range(31):\r\n for j in range(20):\r\n if l <= 2**i * 3**j <= r:\r\n ans+=1\r\nprint(ans)\r\n",
"def rec(x):\r\n s=0\r\n t=1\r\n u=1\r\n while(x>=(2**t)):\r\n s+=1\r\n t+=1\r\n while(x>=(3**u)):\r\n s+=1\r\n u+=1\r\n t=1\r\n u=1\r\n while(x>=(2**t)*(3**u)):\r\n s+=1\r\n v=u+1\r\n while(x>=(2**t)*(3**v)):\r\n s+=1\r\n v+=1\r\n t+=1\r\n return s\r\nl,r=map(int,input().split())\r\nans =0\r\nif l == 1:\r\n ans=1\r\nans +=rec(r)-rec(l-1)\r\nprint(ans)",
"l,r = list(map(int, input().split()))\r\nans = 0\r\nfor i in range(40):\r\n for j in range(40):\r\n v= int(2**i * 3**j);\r\n if(v >= l and v <= r):\r\n ans = ans + 1\r\n \r\nprint(ans)\r\n ",
"import math\r\nl,r = map(int, input().strip().split(' '))\r\n#lst = list(map(int, input().strip().split(' ')))\r\nc=0\r\nfor i in range(32):\r\n for j in range(21):\r\n p=(2**i)*(3**j)\r\n if p>=l and p<=r:\r\n c+=1\r\n \r\nprint(c)\r\n",
"#read l, r;\r\na = [int(x) for x in input().split()]\r\nl = a[0]\r\nr = a[1]\r\n#l = int(input())\r\n#r = int(input())\r\nres = 0\r\nfor x in range(0, 32):\r\n for y in range(0, 21):\r\n if ((((2**x)*(3**y)) >= l) and (((2**x)*(3**y)) <= r)):\r\n res = res + 1\r\nprint(res)\r\n",
"l, r = map(int, input().split())\nans = 0\nfor x in range(0, 35):\n for y in range(0, 25):\n if l <= (2 ** x) * (3 ** y) and (2 ** x) * (3 ** y) <= r:\n ans += 1\nprint(ans)\n",
"l, r = map(int, input().split())\nprint(sum(l <= 2 ** i * 3 ** j <= r for i in range(31) for j in range(20)))\n",
"l, r = map(int, input().split())\r\ntwo = []\r\nt = 1\r\ntwo.append(t)\r\nwhile t * 2 <= r:\r\n t *= 2\r\n two.append(t)\r\nt = 1\r\nthree = []\r\nthree.append(t)\r\nwhile t * 3 <= r:\r\n t *= 3\r\n three.append(t)\r\ncount = 0\r\nfor i in two:\r\n for j in three:\r\n if i * j <= r and i * j >= l:\r\n count += 1\r\nprint(count)\r\n\r\n\r\n",
"l,r=map(int,input().split())\r\nc=0\r\nfor i in range(32):\r\n if(2**i>=l and 2**i<=r):\r\n c+=1\r\nfor i in range(1,32):\r\n if(3**i>=l and (3**i<=r)):\r\n c+=1\r\nfor i in range(1,31,1):\r\n for j in range(1,31,1):\r\n if((2**i)*(3**j)>=l and (2**i)*(3**j)<=r):\r\n c+=1\r\nprint(c)",
"l, r = map(int, input().split())\r\ns = set()\r\nans = 0\r\ndef f(cur):\r\n global ans\r\n s.add(cur)\r\n\r\n if r >= cur >= l:\r\n ans += 1\r\n\r\n if cur * 2 <= r and cur * 2 not in s:\r\n f(cur * 2)\r\n if cur * 3 <= r and cur * 3 not in s:\r\n f(cur * 3)\r\nf(1)\r\nprint(ans)",
"from sys import stdin, stdout\r\nimport math\r\n\r\ndef main():\r\n l,r = map(int,stdin.readline().split())\r\n a, ans = 1, 0\r\n while a <= r:\r\n b = a\r\n while b <= r:\r\n if b >= l:\r\n ans += 1\r\n b *= 2\r\n a *= 3\r\n stdout.write(str(ans) + '\\n')\r\n\r\nmain()",
"l, r = [int(j) for j in input().split()]\r\ncount = 0\r\nfor j in range(32):\r\n for k in range(32):\r\n res = (2 ** j) * (3 ** k)\r\n if res >= l and res <= r:\r\n count += 1\r\nprint(count)\r\n",
"l, r = map(int, input().split())\r\n\r\na = []\r\nb = []\r\n\r\nfor i in range(31):\r\n x = 2 ** i\r\n a.append(x)\r\n\r\nfor i in range(20):\r\n y = 3 ** i\r\n b.append(y)\r\n\r\ns = set()\r\n\r\nfor i in range(31):\r\n for j in range(20):\r\n if a[i] * b[j] <= 2 * 10 ** 9:\r\n s.add(a[i] * b[j])\r\n\r\nans = 0\r\n\r\nfor x in s:\r\n if x >= l and x <= r:\r\n ans += 1\r\n\r\nprint(ans) \r\n",
"# https://algoprog.ru/material/pc926pA\r\n\r\nl, r = map(int, input().split())\r\n\r\nans = 0\r\n\r\nfor x in range(32):\r\n for y in range(21):\r\n num = 2 ** x * 3 ** y\r\n if l <= num <= r:\r\n ans += 1\r\n if num > r:\r\n break\r\n\r\nprint(ans)",
"l,r=map(int,input().split())\r\ns2=[]\r\ns3=[]\r\ni=1\r\nj=1\r\ns23=[]\r\nwhile 2**i<=r:\r\n test=2**i\r\n s2.append(test)\r\n i+=1\r\nwhile 3**j<=r:\r\n test=3**j\r\n s3.append(test)\r\n j+=1\r\ni=1\r\nj=1\r\nif len(s3)>0:\r\n while True:\r\n for k in range(len(s3)):\r\n if s3[k]*2**i<=r:\r\n s23.append(s3[k]*2**i)\r\n else:\r\n break\r\n i+=1\r\n if s3[0]*2**i>r:\r\n break\r\nif len(s2)>0:\r\n while True:\r\n for k in range(len(s3)):\r\n if s2[k]*3**j<=r:\r\n s23.append(s2[k]*3**j)\r\n else:\r\n break\r\n j+=1\r\n if s2[0]*3**j>r:\r\n break\r\nend=set()\r\nfor i in [1]+s2+s3+s23:\r\n if i>=l and i<=r:\r\n end.add(i)\r\nprint(len(end))\r\n \r\n",
"l, r = map(int, input().split())\r\n\r\nans = 0\r\nfor i in range(32):\r\n for j in range(21):\r\n if l <= 2**i * 3**j <= r:\r\n ans+=1\r\nprint(ans)\r\n",
"l, r = input().split()\r\ns = 0\r\nfor x in range(0, 34):\r\n for y in range(0, 34):\r\n m = (2**x)*(3**y)\r\n if int(l) <= m <= int(r):\r\n s += 1\r\nprint(s)\r\n",
"l, r = map(int, input().split())\r\nans = 0\r\n# z <= r\r\nfor x in range(100):\r\n if 2**x > r:\r\n break\r\n for y in range(100):\r\n if 2**x*3**y > r:\r\n ans += y\r\n break\r\n\r\n# z <= l-1\r\nfor x in range(100):\r\n if 2**x > l-1:\r\n break\r\n for y in range(100):\r\n if 2**x*3**y > l-1:\r\n ans -= y\r\n break\r\n\r\nprint(ans)",
"from collections import deque\r\ncnt=0\r\nl,r=input().strip().split(' ')\r\nl,r=[int(l),int(r)]\r\n\r\nflag=1\r\n\r\nq=deque([])\r\ncheck={}\r\nq.append(1)\r\nif(l==1):\r\n cnt+=1\r\n\r\nwhile(len(q)):\r\n x=q[0]\r\n q.popleft()\r\n\r\n y=2*x\r\n if(y<=r and not(y in check.keys())):\r\n if(y>=l):\r\n cnt+=1\r\n q.append(y)\r\n check[y]=-100\r\n\r\n y=3*x\r\n\r\n if(y<=r and not(y in check.keys())):\r\n if(y>=l):\r\n cnt+=1\r\n q.append(y)\r\n check[y]=-100\r\nprint(cnt)\r\n \r\n",
"def Count (n):\r\n cnt = 0\r\n x = 1\r\n while True:\r\n if x > n:\r\n break\r\n y = 1\r\n while True:\r\n if x * y > n:\r\n break\r\n cnt += 1\r\n y *= 3\r\n x *= 2\r\n return cnt\r\n\r\ndef Result (l, r):\r\n if l == 0:\r\n return Count (r)\r\n return Count (r) - Count (l - 1)\r\n\r\nl, r = map (int, input ().split ())\r\nprint (Result (l, r))",
"def f1(c):\r\n left = -1\r\n right = len(dp)\r\n while right - left > + 1: \r\n middle = (left + right) // 2 \r\n if dp[middle] >= c: \r\n right = middle \r\n else: \r\n left = middle \r\n return left\r\n \r\ndef f2(c):\r\n left = -1\r\n right = len(dp)\r\n while right - left > + 1: \r\n middle = (left + right) // 2 \r\n if dp[middle] > c: \r\n right = middle \r\n else: \r\n left = middle \r\n return left\r\n\r\ndp = set()\r\nfor i in range(40):\r\n for j in range(40):\r\n c = (2 ** i) * (3 ** j)\r\n dp.add(c)\r\ndp = list(dp)\r\ndp.sort()\r\nl, r = map(int, input().split())\r\nx = f1(l)\r\ny = f2(r)\r\nprint(y - x)",
"from bisect import bisect_right as bi\r\n\r\nb=[]\r\nfor i in range(32):\r\n for j in range(21):\r\n if (2**(i))*(3**(j))<3*(10**9):\r\n b.append((2**(i))*(3**(j))) \r\nb.sort()\r\n\r\nl,r=list(map(int,input().split()))\r\nprint(bi(b,r)-bi(b,l-1))",
"l,r = map(int,input().split())\r\nans = 0\r\nnum1 = 1\r\nfor i in range(31):\r\n num2 = 1\r\n for j in range(20):\r\n if(num1*num2 <= r and num1*num2 >= l):\r\n ans+= 1\r\n num2*= 3\r\n num1*= 2\r\nprint(ans)",
"A = input().split(' ')\r\nk = 0\r\nfor i in range(32):\r\n for j in range(20):\r\n if (2**i)*(3**j) >= int(A[0]) and (2**i)*(3**j) <= int(A[1]):\r\n k = k + 1\r\nprint(k)\r\n",
"l , r = map(int, input().split())\r\notv = 0\r\n \r\nfor x in range(32):\r\n for y in range(21):\r\n k = (2**x) * (3**y)\r\n if k >= l and k <= r:\r\n otv += 1\r\n \r\n \r\nprint(otv)",
"l,r=map(int,input().split())\r\nm=0\r\nfor i in range(50):\r\n\tfor j in range(50):\r\n\t\tif l<=(2**j)*(3**i)<=r:\r\n\t\t\tm+=1\r\nprint(m)",
"\n# all={1}\n# while max(all)<=10**14:\n# new=set()\n# for num in all:\n# new.add(num*2)\n# new.add(num*3)\n# all=all.union(new)\n# all=list(all)\n# all.sort()\n\nall=[1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 32, 36, 48, 54, 64, 72, 81, 96, 108, 128, 144, 162, 192, 216, 243, 256, 288, 324, 384, 432, 486, 512, 576, 648, 729, 768, 864, 972, 1024, 1152, 1296, 1458, 1536, 1728, 1944, 2048, 2187, 2304, 2592, 2916, 3072, 3456, 3888, 4096, 4374, 4608, 5184, 5832, 6144, 6561, 6912, 7776, 8192, 8748, 9216, 10368, 11664, 12288, 13122, 13824, 15552, 16384, 17496, 18432, 19683, 20736, 23328, 24576, 26244, 27648, 31104, 32768, 34992, 36864, 39366, 41472, 46656, 49152, 52488, 55296, 59049, 62208, 65536, 69984, 73728, 78732, 82944, 93312, 98304, 104976, 110592, 118098, 124416, 131072, 139968, 147456, 157464, 165888, 177147, 186624, 196608, 209952, 221184, 236196, 248832, 262144, 279936, 294912, 314928, 331776, 354294, 373248, 393216, 419904, 442368, 472392, 497664, 524288, 531441, 559872, 589824, 629856, 663552, 708588, 746496, 786432, 839808, 884736, 944784, 995328, 1048576, 1062882, 1119744, 1179648, 1259712, 1327104, 1417176, 1492992, 1572864, 1594323, 1679616, 1769472, 1889568, 1990656, 2097152, 2125764, 2239488, 2359296, 2519424, 2654208, 2834352, 2985984, 3145728, 3188646, 3359232, 3538944, 3779136, 3981312, 4194304, 4251528, 4478976, 4718592, 4782969, 5038848, 5308416, 5668704, 5971968, 6291456, 6377292, 6718464, 7077888, 7558272, 7962624, 8388608, 8503056, 8957952, 9437184, 9565938, 10077696, 10616832, 11337408, 11943936, 12582912, 12754584, 13436928, 14155776, 14348907, 15116544, 15925248, 16777216, 17006112, 17915904, 18874368, 19131876, 20155392, 21233664, 22674816, 23887872, 25165824, 25509168, 26873856, 28311552, 28697814, 30233088, 31850496, 33554432, 34012224, 35831808, 37748736, 38263752, 40310784, 42467328, 43046721, 45349632, 47775744, 50331648, 51018336, 53747712, 56623104, 57395628, 60466176, 63700992, 67108864, 68024448, 71663616, 75497472, 76527504, 80621568, 84934656, 86093442, 90699264, 95551488, 100663296, 102036672, 107495424, 113246208, 114791256, 120932352, 127401984, 129140163, 134217728, 136048896, 143327232, 150994944, 153055008, 161243136, 169869312, 172186884, 181398528, 191102976, 201326592, 204073344, 214990848, 226492416, 229582512, 241864704, 254803968, 258280326, 268435456, 272097792, 286654464, 301989888, 306110016, 322486272, 339738624, 344373768, 362797056, 382205952, 387420489, 402653184, 408146688, 429981696, 452984832, 459165024, 483729408, 509607936, 516560652, 536870912, 544195584, 573308928, 603979776, 612220032, 644972544, 679477248, 688747536, 725594112, 764411904, 774840978, 805306368, 816293376, 859963392, 905969664, 918330048, 967458816, 1019215872, 1033121304, 1073741824, 1088391168, 1146617856, 1162261467, 1207959552, 1224440064, 1289945088, 1358954496, 1377495072, 1451188224, 1528823808, 1549681956, 1610612736, 1632586752, 1719926784, 1811939328, 1836660096, 1934917632, 2038431744, 2066242608, 2176782336, 2293235712, 2324522934, 2415919104, 2448880128, 2579890176, 2717908992, 2754990144, 2902376448, 3057647616, 3099363912, 3265173504, 3439853568, 3486784401, 3623878656, 3673320192, 3869835264, 4076863488, 4132485216, 4353564672, 4586471424, 4649045868, 4897760256, 5159780352, 5435817984, 5509980288, 5804752896, 6115295232, 6198727824, 6530347008, 6879707136, 6973568802, 7346640384, 7739670528, 8153726976, 8264970432, 8707129344, 9172942848, 9298091736, 9795520512, 10319560704, 10460353203, 11019960576, 11609505792, 12230590464, 12397455648, 13060694016, 13759414272, 13947137604, 14693280768, 15479341056, 16529940864, 17414258688, 18345885696, 18596183472, 19591041024, 20639121408, 20920706406, 22039921152, 23219011584, 24794911296, 26121388032, 27518828544, 27894275208, 29386561536, 30958682112, 31381059609, 33059881728, 34828517376, 37192366944, 39182082048, 41278242816, 41841412812, 44079842304, 46438023168, 49589822592, 52242776064, 55788550416, 58773123072, 61917364224, 62762119218, 66119763456, 69657034752, 74384733888, 78364164096, 83682825624, 88159684608, 92876046336, 94143178827, 99179645184, 104485552128, 111577100832, 117546246144, 125524238436, 132239526912, 139314069504, 148769467776, 156728328192, 167365651248, 176319369216, 188286357654, 198359290368, 208971104256, 223154201664, 235092492288, 251048476872, 264479053824, 282429536481, 297538935552, 313456656384, 334731302496, 352638738432, 376572715308, 396718580736, 446308403328, 470184984576, 502096953744, 528958107648, 564859072962, 595077871104, 669462604992, 705277476864, 753145430616, 793437161472, 847288609443, 892616806656, 1004193907488, 1057916215296, 1129718145924, 1190155742208, 1338925209984, 1506290861232, 1586874322944, 1694577218886, 1785233613312, 2008387814976, 2259436291848, 2380311484416, 2541865828329, 2677850419968, 3012581722464, 3389154437772, 3570467226624, 4016775629952, 4518872583696, 5083731656658, 5355700839936, 6025163444928, 6778308875544, 7625597484987, 8033551259904, 9037745167392, 10167463313316, 12050326889856, 13556617751088, 15251194969974, 18075490334784, 20334926626632, 22876792454961, 27113235502176, 30502389939948, 40669853253264, 45753584909922, 61004779879896, 68630377364883, 91507169819844, 137260754729766, 205891132094649]\nl,r=list(map(int,input().split()))\nc=0\na=[]\nfor num in all:\n if num>=l and num<=r:\n c+=1\n a.append(num)\nprint(c)",
"a,b=map(int,input().split())\r\ntwo=[1]\r\nthree=[1]\r\nans=0\r\nwhile two[-1]<b:\r\n two.append(two[-1]*2)\r\nwhile three[-1]<b:\r\n three.append(three[-1]*3)\r\nfor j in three:\r\n for i in two:\r\n if j*i>=a and j*i<=b:\r\n ans+=1\r\nprint(ans)\r\n",
"import bisect\r\nli=[]\r\nl,r=map(int,input().split())\r\nfor i in range(32):\r\n for j in range(32):\r\n if (2**i)*(3**j)<=2*10**9:\r\n li.append((2**i)*(3**j))\r\nli.sort()\r\nprint(bisect.bisect_right(li,r)-bisect.bisect_left(li,l))",
"import sys\r\n\r\n\r\ndef log(n, k):\r\n p = 1\r\n s = 0\r\n while p < n:\r\n p *= k\r\n s += 1\r\n return s\r\n\r\n\r\ndef prov(n):\r\n k = n\r\n while k % 2 == 0:\r\n k //= 2\r\n while k % 3 == 0:\r\n k //= 3\r\n return k == 1\r\n\r\n\r\ndef solution():\r\n l, r = map(int, input().split())\r\n k = 0\r\n for i in range(log(r, 2)+1):\r\n for j in range(log(r, 3)+1):\r\n if l <= (2**i)*(3**j) <= r:\r\n k += 1\r\n print(k)\r\n\r\n\r\ndef perebor(l, r):\r\n k = 0\r\n for i in range(l, r+1):\r\n if prov(i):\r\n k += 1\r\n return k\r\n\r\n\r\ndef fast(l, r):\r\n k = 0\r\n for i in range(log(r, 2) + 1):\r\n for j in range(log(r, 3) + 1):\r\n if l <= (2 ** i) * (3 ** j) <= r:\r\n k += 1\r\n return k\r\n\r\n\r\nDEBAG = False\r\nif DEBAG:\r\n sys.stdin = open('test.3')\r\n t = int(input())\r\n for i in range(t):\r\n solution()\r\nelse:\r\n solution()\r\n\r\n\r\n# for i in range(1, 10000):\r\n# for j in range(i, 10000):\r\n# n = perebor(i, j)\r\n# m = fast(i, j)\r\n# if n != m:\r\n# print(n, m, i, j)",
"# Aniket Hend\r\n\r\nans=0\r\nl,r=map(int,input().split())\r\n\r\nfor i in range(100):\r\n for j in range(100):\r\n num=2**i*3**j\r\n if l<=num<=r:\r\n ans+=1\r\n\r\nprint(ans)\r\n",
"a=[pow(2,i) for i in range(40)]\r\nb=[pow(3,i) for i in range(30)]\r\nl=[i*j for i in a for j in b]\r\nl=list(set(l))\r\nx,y=map(int,input().split())\r\ncount=0\r\nfor i in l:\r\n\tif i>=x and i<=y:\r\n\t\tcount+=1\r\nprint(count)",
"\r\nl,r=input().split(\" \")\r\nl=int(l)\r\nr=int(r)\r\ns=set()\r\nans=0\r\ndef rec(i,l,r):\r\n ans=0\r\n if i>r or i in s:\r\n return 0;\r\n if i>=l:\r\n ans+=1\r\n s.add(i)\r\n ans+=rec(i*2,l,r)\r\n ans+=rec(i*3,l,r)\r\n return ans\r\n\r\n\r\n\r\nprint(rec(1,l,r))\r\n\r\n \r\n",
"a,b=map(int,input().split())\r\nans=0\r\nfor i in range(0,40):\r\n for j in range(0,40):\r\n if (2**i)*(3**j)>=a and (2**i)*(3**j)<=b:\r\n ans+=1\r\nprint(ans)",
"l, r = map(int, input().split())\r\n\r\nans = 0\r\nfor x in range (0, 35):\r\n\tfor y in range(0, 25):\r\n\t\tif (l <= 2**x * 3**y <= r): ans+=1\r\n\t\tif (2**x * 3**y > r): break\r\nprint(ans)",
"ar=list(map(int, input().split()))\r\na=[]\r\nb=[]\r\nc=1\r\nfor i in range(40):\r\n\ta.append(c)\r\n\tc*=2\r\nc=1\t\r\nfor i in range(40):\r\n\tb.append(c)\r\n\tc*=3\r\nct=0\r\n#print(a,b)\r\nfor x in range(40):\r\n\t\tfor y in range(40):\r\n\t\t\t\tif a[x]*b[y]>=ar[0] and a[x]*b[y]<=ar[1]:\r\n\t\t\t\t\tct+=1\r\nprint(ct)\r\n",
"def GetNumbers(x, OnlyThree, r):\r\n if(x > r):\r\n return 0\r\n if(OnlyThree):\r\n return GetNumbers(x * 3, True, r) + 1\r\n return GetNumbers(x * 3, True, r) + GetNumbers(x * 2, False, r) + 1\r\n\r\nl, r = map(int, input().split())\r\nprint(GetNumbers(1, False, r) - GetNumbers(1, False, l-1))",
"\n\ndef Gen(x, number, bound):\n result = 1\n if x == 0:\n if number * 2 <= bound:\n result += Gen(0, number * 2, bound)\n if number * 3 <= bound:\n result += Gen(1, number * 3, bound)\n return result\n\nl, r = map(int, input().split())\n\nLeft = 0\nif l != 1:\n Left = Gen(0, 1, l - 1)\nRight = Gen(0, 1, r)\nprint(Right - Left)\n \t \t \t \t \t\t\t \t \t \t \t \t\t",
"n, m = map(int, input().split())\r\ns = set()\r\nfor i in range(0, 40):\r\n for j in range(0, 40):\r\n if (n <= (2 ** i) * (3 ** j) <= m):\r\n s.add((2 ** i) * (3 ** j))\r\nprint(len(s))",
"s = input().split(' ')\na, b = int(s[0]), int(s[1]);\nres = 0\nfor i in range(0, 100) :\n for j in range(0, 100) :\n tmp = (2**i)*(3**j)\n if(a <= tmp and tmp <= b) :\n res = res+1\n \nprint(res)",
"mx = 2000000000\r\n\r\nl, r = map(int, input().split())\r\nans = 0\r\narr = []\r\nk = 1\r\nwhile k <= mx:\r\n\tc = k\r\n\twhile c <= mx:\r\n\t\tarr.append(c)\r\n\t\tc = 3 * c\r\n\tk = 2 * k\r\n\r\nfor x in arr:\r\n\tif x >= l and x <= r:\r\n\t\tans = ans + 1\r\n\r\nprint(ans)",
"l, r = map(int, input().split())\r\nans = 0\r\nfor i in range (40):\r\n for j in range (40):\r\n a = 2 ** i\r\n b = 3 ** j\r\n if (a * b >= l and a * b <= r):\r\n ans = ans + 1\r\nprint(ans)",
"dtnums = []\r\nfor x in range(0,40):\r\n for y in range(0,40):\r\n dtnums.append((2**x)*(3**y))\r\n\r\nx, y = map(int, input().split())\r\nans = 0\r\nfor i in dtnums:\r\n if x <= i <= y:\r\n ans += 1\r\nprint(ans) ",
"l,r=map(int, input().split())\ntwo = []\nthree = []\nfor i in range(31):\n two.append(2**i)\nfor i in range(21):\n three.append(3**i)\n\nans = 0\nfor x in two:\n for y in three:\n if l <= x*y <= r:\n ans += 1\nprint(ans)",
"lst=[]\r\n\r\nfac2=1\r\nfor i in range(33):\r\n\tfac3=1\r\n\tfor j in range(20):\r\n\t\tval=fac2*fac3\r\n\t\tif (val>2000000000):\r\n\t\t\tbreak\r\n\t\tlst.append(val)\r\n\t\tfac3*=3\r\n\tfac2*=2\r\n\r\nlst.sort()\r\nct=0\r\n[lower,upper]=input().split()\r\nlower=int(lower)\r\nupper=int(upper)\r\nfor item in lst:\r\n\tif (item>=lower and item<=upper):\r\n\t\tct+=1\r\nprint(ct)",
"l, r = map(int, input().split())\r\nans = 0\r\ni = j = 0\r\nwhile 2**i <= r:\r\n j = 0\r\n while 3**j <= r:\r\n x = 2**i*3**j\r\n if x >= l and x<= r:ans += 1\r\n j+= 1\r\n i += 1\r\nprint(ans)",
"l, r = map(int, input().split())\r\ns2 = 0\r\ns3 = 0\r\nwhile 2 ** s2 <= r:\r\n s2 += 1\r\n\r\nwhile 3 ** s3 <=r:\r\n s3 += 1\r\ncount = 0\r\nfor i in range(s3):\r\n for g in range(s2):\r\n if (2 ** g) * (3 ** i) >= l:\r\n if (2 ** g) * (3 ** i) <= r:\r\n count += 1\r\nprint(count)",
"\r\n\r\ndef bsl(l, rb, k):\r\n while l < rb:\r\n mid = (l + rb) // 2\r\n if nums[mid] >= k:\r\n rb = mid\r\n else:\r\n l = mid+1\r\n return l\r\n\r\n\r\ndef bsr(l, r, k):\r\n while l < r:\r\n mid = (l + r + 1) // 2\r\n if nums[mid] <= k:\r\n l = mid\r\n else:\r\n r = mid - 1\r\n return l\r\n\r\n\r\nif __name__ == '__main__':\r\n stop = int(2e9)\r\n\r\n nums = []\r\n i = 1\r\n while i <= stop:\r\n nums.append(i)\r\n i *= 2\r\n\r\n ts = len(nums)\r\n\r\n for i in range(ts):\r\n cur = nums[i] * 3\r\n while cur <= stop:\r\n nums.append(cur)\r\n cur *= 3\r\n nums.sort()\r\n\r\n ln = len(nums)\r\n l, r = map(int, input().split())\r\n\r\n le, re = 0, ln-1\r\n\r\n while le < ln and nums[le] < l:\r\n le += 1\r\n\r\n while re >= 0 and nums[re] > r:\r\n re -= 1\r\n\r\n #print(le, re, nums[le], nums[re], nums[le:re+1])\r\n\r\n # if l == r and nums[le] == l:\r\n # print(1)\r\n #else:\r\n # print(re - le + 1 )\r\n print(re-le+1)\r\n",
"l,r=(int(x)for x in input().split())\r\n\nsum=0\r\n\nfor i in range(0,32):\n \r\n for j in range(0,32):\n \r\n a=2**i\n \r\n b=3**j\n \r\n a=a*b\n \r\n if(a<=r and a>=l):\r\n\n sum=sum+1\nprint(sum)",
"l, r = map(int, input().split())\r\nans = 0\r\nfor x in range(32):\r\n\tfor y in range(32):\r\n\t\tans += l <= (2**x) * (3**y) <= r\r\nprint(ans)",
"s = input().split()\r\nl, r = int(s[0]), int(s[1])\r\nt = 0\r\ncount = 0\r\nwhile(2**t<=r):\r\n t+=1\r\nfor i in range(t):\r\n for j in range(t):\r\n x = (2**i)*(3**j)\r\n if x>=l and x<=r:\r\n count+=1\r\n\r\n\r\nprint(count)",
"a = input().strip().split()\r\nl = int(a[0])\r\nr = int(a[1])\r\nans = 0\r\nfor x in range(32):\r\n\tfor y in range(21):\r\n\t\tnum = (2 ** x) * (3 ** y)\r\n\t\tif ((num >= l) and (num <= r)):\r\n\t\t\tans += 1\r\nprint(ans)",
"l, r = map(int, input().split())\r\na = []\r\nfor i in range(31):\r\n\tfor j in range(31):\r\n\t\tx = 2**i * 3**j\r\n\t\tif x >= l and x <= r:\r\n\t\t\ta.append(x)\r\nprint (len(a))",
"import math\r\n\r\nl, r = [int(i) for i in input().split()]\r\n\r\n# 按含有因子3的个数来计算\r\n# 含有0个3 math.floor(r) - math.ceil(l) + 1\r\n# 含有1个3 math.floor(r / 3) - math.ceil(l / 3) + 1\r\n# ...\r\n\r\n# 改动,math.log存在舍入误差\r\ndef log(n, m):\r\n s = math.log(n, m)\r\n sint = int(s)\r\n if abs(s - sint) < 1e-9 and m**sint == n:\r\n return sint\r\n elif abs(s - sint - 1) < 1e-9 and m**(sint + 1) == n:\r\n return sint + 1\r\n else:\r\n return s\r\n\r\nprint(sum(math.floor(log(r / 3**i, 2)) - max(math.ceil(log(l / 3**i, 2)), 0) + 1 for i in range(int(log(r, 3)) + 1)))",
"l , r = map(int , input().split())\r\n\r\nc = 0\r\nfor x in range(100):\r\n\tfor y in range(100):\r\n\t\tif pow(2,x) * pow(3,y) >= l and pow(2,x) * pow(3,y) <= r:\r\n\t\t\tc += 1\r\n\r\n\r\nprint(c)",
"a,b = map(int, input().split())\r\naa=[]\r\nbb=[]\r\nfor i in range(0,40):\r\n aa.append(2**i)\r\nfor i in range(0,40):\r\n bb.append(3**i);\r\nans=0\r\nfor i in range(0,len(aa)):\r\n for j in range(0,len(bb)):\r\n if(aa[i]*bb[j]>=a and aa[i]*bb[j]<=b):\r\n ans+=1\r\nprint(ans)",
"l, r = map(int, input().split())\r\nmem = dict()\r\nfor i in range(31):\r\n for j in range(21):\r\n val = pow(2, i) * pow(3, j)\r\n if l <= val <= r:\r\n if val not in mem:\r\n mem[val] = 1\r\n\r\nprint(len(mem))\r\n",
"s = {512, 1, 2, 3, 4, 1536, 6, 4608, 8, 9, 344373768, 1679616, 12, 524288, 53747712, 1572864, 16, 104976, 18, 688747536, 3359232, 16384, 107495424, 24, 1033121304, 5038848, 27, 402653184, 161243136, 16777216, 32, 2592, 209952, 17006112, 36, 1377495072, 1024, 82944, 6718464, 544195584, 32768, 2654208, 8748, 214990848, 1719926784, 905969664, 48, 314928, 10077696, 54, 49152, 322486272, 1048576, 64, 576, 5184, 46656, 419904, 3779136, 34012224, 306110016, 72, 15116544, 2048, 65536, 589824, 5308416, 483729408, 47775744, 452984832, 81, 17496, 2097152, 96, 7776, 629856, 51018336, 3072, 612220032, 248832, 20155392, 1632586752, 98304, 7962624, 14348907, 108, 644972544, 95551488, 226492416, 169869312, 3145728, 128, 1152, 86093442, 10368, 26244, 93312, 839808, 7558272, 648, 68024448, 136048896, 2187, 13436928, 4096, 131072, 1179648, 144, 944784, 774840978, 30233088, 147456, 967458816, 12754584, 120932352, 536870912, 1610612736, 1990656, 4194304, 37748736, 429981696, 162, 339738624, 236196, 1073741824, 59049, 36864, 4718592, 34992, 229582512, 1119744, 35831808, 63700992, 33554432, 192, 1728, 15552, 139968, 1259712, 11337408, 102036672, 918330048, 5832, 1224440064, 6144, 196608, 1769472, 15925248, 143327232, 1289945088, 1146617856, 679477248, 50331648, 28697814, 216, 729, 45349632, 4478976, 67108864, 1451188224, 6291456, 56623104, 509607936, 603979776, 19683, 859963392, 9565938, 243, 1492992, 100663296, 256, 768, 2304, 6912, 172186884, 20736, 62208, 186624, 52488, 559872, 26873856, 262144, 516560652, 786432, 8192, 2359296, 1296, 8503056, 41472, 272097792, 80621568, 4374, 1327104, 157464, 134217728, 1207959552, 24576, 8388608, 288, 23328, 1889568, 153055008, 1549681956, 9216, 746496, 60466176, 1088391168, 294912, 241864704, 23887872, 1934917632, 150994944, 42467328, 3888, 25509168, 124416, 816293376, 3981312, 9437184, 764411904, 43046721, 13122, 324, 472392, 387420489, 6377292, 73728, 127401984, 118098, 995328, 114791256, 18432, 201326592, 1811939328, 17915904, 864, 69984, 5668704, 459165024, 2916, 27648, 2239488, 181398528, 884736, 71663616, 31850496, 254803968, 725594112, 573308928, 4782969, 28311552, 384, 3456, 31104, 279936, 2519424, 22674816, 258280326, 204073344, 4251528, 1836660096, 12288, 393216, 78732, 40310784, 663552, 3538944, 11664, 76527504, 373248, 84934656, 1528823808, 11943936, 1944, 408146688, 268435456, 805306368, 12582912, 113246208, 6561, 1019215872, 3188646, 21233664, 57395628, 497664, 1358954496, 382205952, 432, 2834352, 1458, 13824, 90699264, 8957952, 442368, 25165824, 362797056, 301989888, 129140163, 2125764, 39366, 38263752, 331776, 286654464, 972, 5971968, 14155776, 1594323, 1417176, 1162261467, 221184, 1062882, 10616832, 19131876, 75497472, 486, 191102976, 165888, 2985984, 708588, 18874368, 531441, 110592, 354294, 7077888, 177147, 55296}\r\n\r\nl,r = [int(i) for i in input().split()]\r\nans = 0\r\n\r\nfor e in s:\r\n if l<=e<=r:\r\n ans+=1\r\n\r\nprint(ans)\r\n",
"(a, b) = input().split()\r\n(a, b) = (int(a), int(b))\r\n\r\ni = 1\r\ncnt = 0\r\n\r\nwhile (True):\r\n j = 1\r\n if(i > b):\r\n break\r\n while(True):\r\n if(i * j > b): \r\n break\r\n if(i * j >= a):\r\n cnt += 1\r\n j *= 3\r\n i *= 2\r\n\r\nprint (cnt)\r\n ",
"l,r=map(int,input().split())\r\nla=[]\r\nfor i in range(0,32):\r\n for j in range(0,21):\r\n k=2**i\r\n y=3**j\r\n if(k*y<=2000000000):la.append(k*y)\r\nans=0\r\nfor i in la:\r\n if(i<=r):ans+=1\r\nfor i in la:\r\n if(i<l) :ans-=1\r\nprint(ans)",
"l, r = [int(w) for w in input().split()]\r\n\r\nn2, n3 = 1, 1\r\ntmp = 2\r\nwhile tmp < 2e9:\r\n tmp *= 2\r\n n2 += 1\r\n\r\ntmp = 3\r\nwhile tmp < 2e9:\r\n tmp *= 3\r\n n3 += 1\r\n\r\narr = []\r\nfor i in range(n2):\r\n for j in range(n3):\r\n tmp = 2 ** i * 3 ** j\r\n if tmp > 2e9:\r\n break\r\n arr.append(tmp)\r\n\r\narr.sort()\r\n\r\nres = len([a for a in arr if l <= a <= r])\r\nprint(res)",
"l, r = map(int, input().split())\r\ns = set()\r\n\r\nfor x in range(35):\r\n for y in range(35):\r\n if (2 ** x) * (3 ** y) <= 2000000000:\r\n s.add((2 ** x) * (3 ** y))\r\n\r\nans = 0\r\nfor x in s:\r\n if l <= x and x <= r:\r\n ans += 1\r\n \r\nprint(ans)",
"ans=0\r\nl=0\r\nr=0\r\nl, r = map(int, input().split())\r\na=1\r\nfor i in range(100):\r\n b=1\r\n for j in range(100):\r\n if a*b<=r:\r\n if a*b>=l:\r\n ans=ans+1\r\n else:\r\n break\r\n b=b*3\r\n a=2*a\r\nprint(ans) \r\n\r\n",
"r,l = map(int,input().split())\r\ntemp1 = 1\r\nans = 0\r\nwhile temp1 <= l:\r\n temp = temp1\r\n while temp <= l:\r\n if temp >= r:\r\n ans += 1\r\n temp = temp*3\r\n temp1 = temp1*2\r\nprint(ans)",
"r2=[ 2**i for i in range(31) ]\r\nr3=[ 3**i for i in range(21) ]\r\ns=set()\r\nl, r=map(int, input().split())\r\nfor i in range(31):\r\n for j in range(21):\r\n k=r2[i]*r3[j]\r\n if k<=2*10**9:\r\n if l<=k<=r:\r\n s.add(k)\r\n else:\r\n break\r\nprint(len(s))",
"l,r = map(int,input().split())\r\nls = []\r\ni = 0\r\nwhile 2**i <= 2*10**9 :\r\n j = 0\r\n while 2**i*3**j <= 2*10**9 :\r\n ls.append(2**i*3**j)\r\n j += 1\r\n i += 1\r\nls.sort()\r\ni = 0\r\nwhile i < 326 and ls[i] < l :\r\n i += 1\r\nj = 0\r\nwhile j < 326 and ls[j] <= r :\r\n j += 1\r\nprint(j-i)",
"import sys\r\ninput = sys.stdin.readline\r\nimport bisect\r\n\r\ns = set()\r\nfor i in range(32):\r\n for j in range(25):\r\n s.add(2**i * 3**j)\r\nd = sorted(s)\r\nl, r = map(int, input().split())\r\nprint(bisect.bisect_right(d, r) - bisect.bisect_right(d, l-1))",
"l, r = map(int, input().split())\r\nx = 31\r\ny = 20\r\ncount = 0\r\nfor i in range(x + 1):\r\n\tfor j in range(y + 1):\r\n\t\tif 2 ** i * 3 ** j >= l and 2 ** i * (3 ** j) <= r:\r\n\t\t\tcount += 1\r\nprint(count)\t\t\t\r\n",
"import math\r\n\r\nl, r = [int(x) for x in input().split()]\r\n\r\nans = 0\r\nd = []\r\nd.append(1)\r\nfor i in range(1, int(2*math.log2(r))) :\r\n d.append(d[i - 1]*2)\r\nx = 1\r\nwhile (True) :\r\n if (x > r) : break\r\n ll = 0\r\n rr = int(math.log2(r) + 1)\r\n while (rr - ll > 1) :\r\n m = (ll + rr) // 2\r\n if (x*d[m] <= r) :\r\n ll = m\r\n else :\r\n rr = m\r\n ans += ll\r\n ll = -1\r\n rr = int(math.log2(r) + 1)\r\n while (rr - ll > 1) :\r\n m = (ll + rr) // 2\r\n if (x*d[m] >= l) :\r\n rr = m\r\n else :\r\n ll = m\r\n ans -= ll\r\n x *= 3\r\n\r\nprint(ans)\r\n\r\n",
"def f2(x):\r\n\tr = 0\r\n\twhile x > 0:\r\n\t\tr += 1\r\n\t\tx //= 2\r\n\treturn r\r\n\r\ndef f3(x):\r\n\tr = 0\r\n\twhile x > 0:\r\n\t\tr += f2(x)\r\n\t\tx //= 3\r\n\treturn r\r\n\r\nl, r = map(int, input().split())\r\nfr = f3(r)\r\nfl = f3(l-1)\r\nf = fr-fl\r\nprint(f)\r\n",
"import sys\r\nfrom math import *\r\nfrom fractions import gcd\r\nreadints=lambda:map(int, input().strip('\\n').split())\r\n\r\nl,r=readints()\r\n\r\nmaxn=2*(10**9)\r\ntwos=set()\r\ni=2\r\nwhile i<=maxn:\r\n twos.add(i)\r\n i*=2\r\n\r\nthrees=set()\r\ni=3\r\nwhile i<=maxn:\r\n threes.add(i)\r\n i*=3\r\n\r\nnums=set()\r\nnums.add(1)\r\nfor x in twos:\r\n for y in threes:\r\n if x*y>maxn: continue\r\n nums.add(x*y)\r\nfor x in twos:\r\n nums.add(x)\r\nfor y in threes:\r\n nums.add(y)\r\n\r\n# nums=list(sorted(list(nums)))\r\n\r\n\r\nans=0\r\nfor x in nums:\r\n if l<=x and x<=r:\r\n ans+=1\r\nprint(ans)\r\n",
"import math\r\n\r\ndef solve():\r\n l, r = map(int, input().split())\r\n cnt = 0\r\n upx = int(math.log2(2000000000))\r\n lwx = int(math.log2(2000000000))\r\n nowx = 1\r\n for i in range(upx + 1):\r\n nowy = 1\r\n for j in range(lwx + 1):\r\n if l <= nowx * nowy <= r:\r\n cnt += 1\r\n nowy *= 3\r\n nowx *= 2\r\n print(cnt)\r\n\r\ndef main():\r\n # t = int(input())\r\n # for _ in range(t):\r\n solve()\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"import math\r\nl, r=map(int,input().split())\r\nans = 0\r\nif (l<=1) & (r>=1) : ans = ans + 1\r\nif (l<=2) & (r>=2) : ans = ans + 1\r\nif (l<=3) & (r>=3) : ans = ans + 1\r\nif (l<=4) & (r>=4) : ans = ans + 1\r\nif (l<=6) & (r>=6) : ans = ans + 1\r\nif (l<=8) & (r>=8) : ans = ans + 1\r\nif (l<=9) & (r>=9) : ans = ans + 1\r\nif (l<=12) & (r>=12) : ans = ans + 1\r\nif (l<=16) & (r>=16) : ans = ans + 1\r\nif (l<=18) & (r>=18) : ans = ans + 1\r\nif (l<=24) & (r>=24) : ans = ans + 1\r\nif (l<=27) & (r>=27) : ans = ans + 1\r\nif (l<=32) & (r>=32) : ans = ans + 1\r\nif (l<=36) & (r>=36) : ans = ans + 1\r\nif (l<=48) & (r>=48) : ans = ans + 1\r\nif (l<=54) & (r>=54) : ans = ans + 1\r\nif (l<=64) & (r>=64) : ans = ans + 1\r\nif (l<=72) & (r>=72) : ans = ans + 1\r\nif (l<=81) & (r>=81) : ans = ans + 1\r\nif (l<=96) & (r>=96) : ans = ans + 1\r\nif (l<=108) & (r>=108) : ans = ans + 1\r\nif (l<=128) & (r>=128) : ans = ans + 1\r\nif (l<=144) & (r>=144) : ans = ans + 1\r\nif (l<=162) & (r>=162) : ans = ans + 1\r\nif (l<=192) & (r>=192) : ans = ans + 1\r\nif (l<=216) & (r>=216) : ans = ans + 1\r\nif (l<=243) & (r>=243) : ans = ans + 1\r\nif (l<=256) & (r>=256) : ans = ans + 1\r\nif (l<=288) & (r>=288) : ans = ans + 1\r\nif (l<=324) & (r>=324) : ans = ans + 1\r\nif (l<=384) & (r>=384) : ans = ans + 1\r\nif (l<=432) & (r>=432) : ans = ans + 1\r\nif (l<=486) & (r>=486) : ans = ans + 1\r\nif (l<=512) & (r>=512) : ans = ans + 1\r\nif (l<=576) & (r>=576) : ans = ans + 1\r\nif (l<=648) & (r>=648) : ans = ans + 1\r\nif (l<=729) & (r>=729) : ans = ans + 1\r\nif (l<=768) & (r>=768) : ans = ans + 1\r\nif (l<=864) & (r>=864) : ans = ans + 1\r\nif (l<=972) & (r>=972) : ans = ans + 1\r\nif (l<=1024) & (r>=1024) : ans = ans + 1\r\nif (l<=1152) & (r>=1152) : ans = ans + 1\r\nif (l<=1296) & (r>=1296) : ans = ans + 1\r\nif (l<=1458) & (r>=1458) : ans = ans + 1\r\nif (l<=1536) & (r>=1536) : ans = ans + 1\r\nif (l<=1728) & (r>=1728) : ans = ans + 1\r\nif (l<=1944) & (r>=1944) : ans = ans + 1\r\nif (l<=2048) & (r>=2048) : ans = ans + 1\r\nif (l<=2187) & (r>=2187) : ans = ans + 1\r\nif (l<=2304) & (r>=2304) : ans = ans + 1\r\nif (l<=2592) & (r>=2592) : ans = ans + 1\r\nif (l<=2916) & (r>=2916) : ans = ans + 1\r\nif (l<=3072) & (r>=3072) : ans = ans + 1\r\nif (l<=3456) & (r>=3456) : ans = ans + 1\r\nif (l<=3888) & (r>=3888) : ans = ans + 1\r\nif (l<=4096) & (r>=4096) : ans = ans + 1\r\nif (l<=4374) & (r>=4374) : ans = ans + 1\r\nif (l<=4608) & (r>=4608) : ans = ans + 1\r\nif (l<=5184) & (r>=5184) : ans = ans + 1\r\nif (l<=5832) & (r>=5832) : ans = ans + 1\r\nif (l<=6144) & (r>=6144) : ans = ans + 1\r\nif (l<=6561) & (r>=6561) : ans = ans + 1\r\nif (l<=6912) & (r>=6912) : ans = ans + 1\r\nif (l<=7776) & (r>=7776) : ans = ans + 1\r\nif (l<=8192) & (r>=8192) : ans = ans + 1\r\nif (l<=8748) & (r>=8748) : ans = ans + 1\r\nif (l<=9216) & (r>=9216) : ans = ans + 1\r\nif (l<=10368) & (r>=10368) : ans = ans + 1\r\nif (l<=11664) & (r>=11664) : ans = ans + 1\r\nif (l<=12288) & (r>=12288) : ans = ans + 1\r\nif (l<=13122) & (r>=13122) : ans = ans + 1\r\nif (l<=13824) & (r>=13824) : ans = ans + 1\r\nif (l<=15552) & (r>=15552) : ans = ans + 1\r\nif (l<=16384) & (r>=16384) : ans = ans + 1\r\nif (l<=17496) & (r>=17496) : ans = ans + 1\r\nif (l<=18432) & (r>=18432) : ans = ans + 1\r\nif (l<=19683) & (r>=19683) : ans = ans + 1\r\nif (l<=20736) & (r>=20736) : ans = ans + 1\r\nif (l<=23328) & (r>=23328) : ans = ans + 1\r\nif (l<=24576) & (r>=24576) : ans = ans + 1\r\nif (l<=26244) & (r>=26244) : ans = ans + 1\r\nif (l<=27648) & (r>=27648) : ans = ans + 1\r\nif (l<=31104) & (r>=31104) : ans = ans + 1\r\nif (l<=32768) & (r>=32768) : ans = ans + 1\r\nif (l<=34992) & (r>=34992) : ans = ans + 1\r\nif (l<=36864) & (r>=36864) : ans = ans + 1\r\nif (l<=39366) & (r>=39366) : ans = ans + 1\r\nif (l<=41472) & (r>=41472) : ans = ans + 1\r\nif (l<=46656) & (r>=46656) : ans = ans + 1\r\nif (l<=49152) & (r>=49152) : ans = ans + 1\r\nif (l<=52488) & (r>=52488) : ans = ans + 1\r\nif (l<=55296) & (r>=55296) : ans = ans + 1\r\nif (l<=59049) & (r>=59049) : ans = ans + 1\r\nif (l<=62208) & (r>=62208) : ans = ans + 1\r\nif (l<=65536) & (r>=65536) : ans = ans + 1\r\nif (l<=69984) & (r>=69984) : ans = ans + 1\r\nif (l<=73728) & (r>=73728) : ans = ans + 1\r\nif (l<=78732) & (r>=78732) : ans = ans + 1\r\nif (l<=82944) & (r>=82944) : ans = ans + 1\r\nif (l<=93312) & (r>=93312) : ans = ans + 1\r\nif (l<=98304) & (r>=98304) : ans = ans + 1\r\nif (l<=104976) & (r>=104976) : ans = ans + 1\r\nif (l<=110592) & (r>=110592) : ans = ans + 1\r\nif (l<=118098) & (r>=118098) : ans = ans + 1\r\nif (l<=124416) & (r>=124416) : ans = ans + 1\r\nif (l<=131072) & (r>=131072) : ans = ans + 1\r\nif (l<=139968) & (r>=139968) : ans = ans + 1\r\nif (l<=147456) & (r>=147456) : ans = ans + 1\r\nif (l<=157464) & (r>=157464) : ans = ans + 1\r\nif (l<=165888) & (r>=165888) : ans = ans + 1\r\nif (l<=177147) & (r>=177147) : ans = ans + 1\r\nif (l<=186624) & (r>=186624) : ans = ans + 1\r\nif (l<=196608) & (r>=196608) : ans = ans + 1\r\nif (l<=209952) & (r>=209952) : ans = ans + 1\r\nif (l<=221184) & (r>=221184) : ans = ans + 1\r\nif (l<=236196) & (r>=236196) : ans = ans + 1\r\nif (l<=248832) & (r>=248832) : ans = ans + 1\r\nif (l<=262144) & (r>=262144) : ans = ans + 1\r\nif (l<=279936) & (r>=279936) : ans = ans + 1\r\nif (l<=294912) & (r>=294912) : ans = ans + 1\r\nif (l<=314928) & (r>=314928) : ans = ans + 1\r\nif (l<=331776) & (r>=331776) : ans = ans + 1\r\nif (l<=354294) & (r>=354294) : ans = ans + 1\r\nif (l<=373248) & (r>=373248) : ans = ans + 1\r\nif (l<=393216) & (r>=393216) : ans = ans + 1\r\nif (l<=419904) & (r>=419904) : ans = ans + 1\r\nif (l<=442368) & (r>=442368) : ans = ans + 1\r\nif (l<=472392) & (r>=472392) : ans = ans + 1\r\nif (l<=497664) & (r>=497664) : ans = ans + 1\r\nif (l<=524288) & (r>=524288) : ans = ans + 1\r\nif (l<=531441) & (r>=531441) : ans = ans + 1\r\nif (l<=559872) & (r>=559872) : ans = ans + 1\r\nif (l<=589824) & (r>=589824) : ans = ans + 1\r\nif (l<=629856) & (r>=629856) : ans = ans + 1\r\nif (l<=663552) & (r>=663552) : ans = ans + 1\r\nif (l<=708588) & (r>=708588) : ans = ans + 1\r\nif (l<=746496) & (r>=746496) : ans = ans + 1\r\nif (l<=786432) & (r>=786432) : ans = ans + 1\r\nif (l<=839808) & (r>=839808) : ans = ans + 1\r\nif (l<=884736) & (r>=884736) : ans = ans + 1\r\nif (l<=944784) & (r>=944784) : ans = ans + 1\r\nif (l<=995328) & (r>=995328) : ans = ans + 1\r\nif (l<=1048576) & (r>=1048576) : ans = ans + 1\r\nif (l<=1062882) & (r>=1062882) : ans = ans + 1\r\nif (l<=1119744) & (r>=1119744) : ans = ans + 1\r\nif (l<=1179648) & (r>=1179648) : ans = ans + 1\r\nif (l<=1259712) & (r>=1259712) : ans = ans + 1\r\nif (l<=1327104) & (r>=1327104) : ans = ans + 1\r\nif (l<=1417176) & (r>=1417176) : ans = ans + 1\r\nif (l<=1492992) & (r>=1492992) : ans = ans + 1\r\nif (l<=1572864) & (r>=1572864) : ans = ans + 1\r\nif (l<=1594323) & (r>=1594323) : ans = ans + 1\r\nif (l<=1679616) & (r>=1679616) : ans = ans + 1\r\nif (l<=1769472) & (r>=1769472) : ans = ans + 1\r\nif (l<=1889568) & (r>=1889568) : ans = ans + 1\r\nif (l<=1990656) & (r>=1990656) : ans = ans + 1\r\nif (l<=2097152) & (r>=2097152) : ans = ans + 1\r\nif (l<=2125764) & (r>=2125764) : ans = ans + 1\r\nif (l<=2239488) & (r>=2239488) : ans = ans + 1\r\nif (l<=2359296) & (r>=2359296) : ans = ans + 1\r\nif (l<=2519424) & (r>=2519424) : ans = ans + 1\r\nif (l<=2654208) & (r>=2654208) : ans = ans + 1\r\nif (l<=2834352) & (r>=2834352) : ans = ans + 1\r\nif (l<=2985984) & (r>=2985984) : ans = ans + 1\r\nif (l<=3145728) & (r>=3145728) : ans = ans + 1\r\nif (l<=3188646) & (r>=3188646) : ans = ans + 1\r\nif (l<=3359232) & (r>=3359232) : ans = ans + 1\r\nif (l<=3538944) & (r>=3538944) : ans = ans + 1\r\nif (l<=3779136) & (r>=3779136) : ans = ans + 1\r\nif (l<=3981312) & (r>=3981312) : ans = ans + 1\r\nif (l<=4194304) & (r>=4194304) : ans = ans + 1\r\nif (l<=4251528) & (r>=4251528) : ans = ans + 1\r\nif (l<=4478976) & (r>=4478976) : ans = ans + 1\r\nif (l<=4718592) & (r>=4718592) : ans = ans + 1\r\nif (l<=4782969) & (r>=4782969) : ans = ans + 1\r\nif (l<=5038848) & (r>=5038848) : ans = ans + 1\r\nif (l<=5308416) & (r>=5308416) : ans = ans + 1\r\nif (l<=5668704) & (r>=5668704) : ans = ans + 1\r\nif (l<=5971968) & (r>=5971968) : ans = ans + 1\r\nif (l<=6291456) & (r>=6291456) : ans = ans + 1\r\nif (l<=6377292) & (r>=6377292) : ans = ans + 1\r\nif (l<=6718464) & (r>=6718464) : ans = ans + 1\r\nif (l<=7077888) & (r>=7077888) : ans = ans + 1\r\nif (l<=7558272) & (r>=7558272) : ans = ans + 1\r\nif (l<=7962624) & (r>=7962624) : ans = ans + 1\r\nif (l<=8388608) & (r>=8388608) : ans = ans + 1\r\nif (l<=8503056) & (r>=8503056) : ans = ans + 1\r\nif (l<=8957952) & (r>=8957952) : ans = ans + 1\r\nif (l<=9437184) & (r>=9437184) : ans = ans + 1\r\nif (l<=9565938) & (r>=9565938) : ans = ans + 1\r\nif (l<=10077696) & (r>=10077696) : ans = ans + 1\r\nif (l<=10616832) & (r>=10616832) : ans = ans + 1\r\nif (l<=11337408) & (r>=11337408) : ans = ans + 1\r\nif (l<=11943936) & (r>=11943936) : ans = ans + 1\r\nif (l<=12582912) & (r>=12582912) : ans = ans + 1\r\nif (l<=12754584) & (r>=12754584) : ans = ans + 1\r\nif (l<=13436928) & (r>=13436928) : ans = ans + 1\r\nif (l<=14155776) & (r>=14155776) : ans = ans + 1\r\nif (l<=14348907) & (r>=14348907) : ans = ans + 1\r\nif (l<=15116544) & (r>=15116544) : ans = ans + 1\r\nif (l<=15925248) & (r>=15925248) : ans = ans + 1\r\nif (l<=16777216) & (r>=16777216) : ans = ans + 1\r\nif (l<=17006112) & (r>=17006112) : ans = ans + 1\r\nif (l<=17915904) & (r>=17915904) : ans = ans + 1\r\nif (l<=18874368) & (r>=18874368) : ans = ans + 1\r\nif (l<=19131876) & (r>=19131876) : ans = ans + 1\r\nif (l<=20155392) & (r>=20155392) : ans = ans + 1\r\nif (l<=21233664) & (r>=21233664) : ans = ans + 1\r\nif (l<=22674816) & (r>=22674816) : ans = ans + 1\r\nif (l<=23887872) & (r>=23887872) : ans = ans + 1\r\nif (l<=25165824) & (r>=25165824) : ans = ans + 1\r\nif (l<=25509168) & (r>=25509168) : ans = ans + 1\r\nif (l<=26873856) & (r>=26873856) : ans = ans + 1\r\nif (l<=28311552) & (r>=28311552) : ans = ans + 1\r\nif (l<=28697814) & (r>=28697814) : ans = ans + 1\r\nif (l<=30233088) & (r>=30233088) : ans = ans + 1\r\nif (l<=31850496) & (r>=31850496) : ans = ans + 1\r\nif (l<=33554432) & (r>=33554432) : ans = ans + 1\r\nif (l<=34012224) & (r>=34012224) : ans = ans + 1\r\nif (l<=35831808) & (r>=35831808) : ans = ans + 1\r\nif (l<=37748736) & (r>=37748736) : ans = ans + 1\r\nif (l<=38263752) & (r>=38263752) : ans = ans + 1\r\nif (l<=40310784) & (r>=40310784) : ans = ans + 1\r\nif (l<=42467328) & (r>=42467328) : ans = ans + 1\r\nif (l<=43046721) & (r>=43046721) : ans = ans + 1\r\nif (l<=45349632) & (r>=45349632) : ans = ans + 1\r\nif (l<=47775744) & (r>=47775744) : ans = ans + 1\r\nif (l<=50331648) & (r>=50331648) : ans = ans + 1\r\nif (l<=51018336) & (r>=51018336) : ans = ans + 1\r\nif (l<=53747712) & (r>=53747712) : ans = ans + 1\r\nif (l<=56623104) & (r>=56623104) : ans = ans + 1\r\nif (l<=57395628) & (r>=57395628) : ans = ans + 1\r\nif (l<=60466176) & (r>=60466176) : ans = ans + 1\r\nif (l<=63700992) & (r>=63700992) : ans = ans + 1\r\nif (l<=67108864) & (r>=67108864) : ans = ans + 1\r\nif (l<=68024448) & (r>=68024448) : ans = ans + 1\r\nif (l<=71663616) & (r>=71663616) : ans = ans + 1\r\nif (l<=75497472) & (r>=75497472) : ans = ans + 1\r\nif (l<=76527504) & (r>=76527504) : ans = ans + 1\r\nif (l<=80621568) & (r>=80621568) : ans = ans + 1\r\nif (l<=84934656) & (r>=84934656) : ans = ans + 1\r\nif (l<=86093442) & (r>=86093442) : ans = ans + 1\r\nif (l<=90699264) & (r>=90699264) : ans = ans + 1\r\nif (l<=95551488) & (r>=95551488) : ans = ans + 1\r\nif (l<=100663296) & (r>=100663296) : ans = ans + 1\r\nif (l<=102036672) & (r>=102036672) : ans = ans + 1\r\nif (l<=107495424) & (r>=107495424) : ans = ans + 1\r\nif (l<=113246208) & (r>=113246208) : ans = ans + 1\r\nif (l<=114791256) & (r>=114791256) : ans = ans + 1\r\nif (l<=120932352) & (r>=120932352) : ans = ans + 1\r\nif (l<=127401984) & (r>=127401984) : ans = ans + 1\r\nif (l<=129140163) & (r>=129140163) : ans = ans + 1\r\nif (l<=134217728) & (r>=134217728) : ans = ans + 1\r\nif (l<=136048896) & (r>=136048896) : ans = ans + 1\r\nif (l<=143327232) & (r>=143327232) : ans = ans + 1\r\nif (l<=150994944) & (r>=150994944) : ans = ans + 1\r\nif (l<=153055008) & (r>=153055008) : ans = ans + 1\r\nif (l<=161243136) & (r>=161243136) : ans = ans + 1\r\nif (l<=169869312) & (r>=169869312) : ans = ans + 1\r\nif (l<=172186884) & (r>=172186884) : ans = ans + 1\r\nif (l<=181398528) & (r>=181398528) : ans = ans + 1\r\nif (l<=191102976) & (r>=191102976) : ans = ans + 1\r\nif (l<=201326592) & (r>=201326592) : ans = ans + 1\r\nif (l<=204073344) & (r>=204073344) : ans = ans + 1\r\nif (l<=214990848) & (r>=214990848) : ans = ans + 1\r\nif (l<=226492416) & (r>=226492416) : ans = ans + 1\r\nif (l<=229582512) & (r>=229582512) : ans = ans + 1\r\nif (l<=241864704) & (r>=241864704) : ans = ans + 1\r\nif (l<=254803968) & (r>=254803968) : ans = ans + 1\r\nif (l<=258280326) & (r>=258280326) : ans = ans + 1\r\nif (l<=268435456) & (r>=268435456) : ans = ans + 1\r\nif (l<=272097792) & (r>=272097792) : ans = ans + 1\r\nif (l<=286654464) & (r>=286654464) : ans = ans + 1\r\nif (l<=301989888) & (r>=301989888) : ans = ans + 1\r\nif (l<=306110016) & (r>=306110016) : ans = ans + 1\r\nif (l<=322486272) & (r>=322486272) : ans = ans + 1\r\nif (l<=339738624) & (r>=339738624) : ans = ans + 1\r\nif (l<=344373768) & (r>=344373768) : ans = ans + 1\r\nif (l<=362797056) & (r>=362797056) : ans = ans + 1\r\nif (l<=382205952) & (r>=382205952) : ans = ans + 1\r\nif (l<=387420489) & (r>=387420489) : ans = ans + 1\r\nif (l<=402653184) & (r>=402653184) : ans = ans + 1\r\nif (l<=408146688) & (r>=408146688) : ans = ans + 1\r\nif (l<=429981696) & (r>=429981696) : ans = ans + 1\r\nif (l<=452984832) & (r>=452984832) : ans = ans + 1\r\nif (l<=459165024) & (r>=459165024) : ans = ans + 1\r\nif (l<=483729408) & (r>=483729408) : ans = ans + 1\r\nif (l<=509607936) & (r>=509607936) : ans = ans + 1\r\nif (l<=516560652) & (r>=516560652) : ans = ans + 1\r\nif (l<=536870912) & (r>=536870912) : ans = ans + 1\r\nif (l<=544195584) & (r>=544195584) : ans = ans + 1\r\nif (l<=573308928) & (r>=573308928) : ans = ans + 1\r\nif (l<=603979776) & (r>=603979776) : ans = ans + 1\r\nif (l<=612220032) & (r>=612220032) : ans = ans + 1\r\nif (l<=644972544) & (r>=644972544) : ans = ans + 1\r\nif (l<=679477248) & (r>=679477248) : ans = ans + 1\r\nif (l<=688747536) & (r>=688747536) : ans = ans + 1\r\nif (l<=725594112) & (r>=725594112) : ans = ans + 1\r\nif (l<=764411904) & (r>=764411904) : ans = ans + 1\r\nif (l<=774840978) & (r>=774840978) : ans = ans + 1\r\nif (l<=805306368) & (r>=805306368) : ans = ans + 1\r\nif (l<=816293376) & (r>=816293376) : ans = ans + 1\r\nif (l<=859963392) & (r>=859963392) : ans = ans + 1\r\nif (l<=905969664) & (r>=905969664) : ans = ans + 1\r\nif (l<=918330048) & (r>=918330048) : ans = ans + 1\r\nif (l<=967458816) & (r>=967458816) : ans = ans + 1\r\nif (l<=1019215872) & (r>=1019215872) : ans = ans + 1\r\nif (l<=1033121304) & (r>=1033121304) : ans = ans + 1\r\nif (l<=1073741824) & (r>=1073741824) : ans = ans + 1\r\nif (l<=1088391168) & (r>=1088391168) : ans = ans + 1\r\nif (l<=1146617856) & (r>=1146617856) : ans = ans + 1\r\nif (l<=1162261467) & (r>=1162261467) : ans = ans + 1\r\nif (l<=1207959552) & (r>=1207959552) : ans = ans + 1\r\nif (l<=1224440064) & (r>=1224440064) : ans = ans + 1\r\nif (l<=1289945088) & (r>=1289945088) : ans = ans + 1\r\nif (l<=1358954496) & (r>=1358954496) : ans = ans + 1\r\nif (l<=1377495072) & (r>=1377495072) : ans = ans + 1\r\nif (l<=1451188224) & (r>=1451188224) : ans = ans + 1\r\nif (l<=1528823808) & (r>=1528823808) : ans = ans + 1\r\nif (l<=1549681956) & (r>=1549681956) : ans = ans + 1\r\nif (l<=1610612736) & (r>=1610612736) : ans = ans + 1\r\nif (l<=1632586752) & (r>=1632586752) : ans = ans + 1\r\nif (l<=1719926784) & (r>=1719926784) : ans = ans + 1\r\nif (l<=1811939328) & (r>=1811939328) : ans = ans + 1\r\nif (l<=1836660096) & (r>=1836660096) : ans = ans + 1\r\nif (l<=1934917632) & (r>=1934917632) : ans = ans + 1\r\nprint(ans)\r\n",
"l, r = map(int, input().split())\r\nxLimit = 31 # 2^31 > 2M\r\nyLimit = 20 # 3^20 > 3M\r\nnumbers = set()\r\nfor i in range(xLimit):\r\n for j in range(yLimit):\r\n number = (2 ** i) * (3 ** j)\r\n if l <= number <= r:\r\n numbers.add(number)\r\nprint(len(numbers))",
"A = list(map(int,input().split()))\r\nl = A[0]\r\nr = A[1]\r\nn = 0\r\nfor i in range(0, 33):\r\n for j in range(0, 33):\r\n cur = pow(2,i) * pow(3, j)\r\n if (cur >= l and cur <= r):\r\n n += 1\r\nprint(n)",
"import math\r\nimport queue\r\n\r\nl,r=map(int,input().split())\r\n\r\ndef f(r):\r\n k=0\r\n num=1\r\n \r\n while num<=r:\r\n k+=1\r\n num*=2\r\n \r\n \r\n return k\r\n \r\nanswer=0\r\ny=1\r\n\r\nwhile y<=r:\r\n a=r//y\r\n if l%y==0:\r\n b=l//y-1\r\n else:\r\n b=l//y \r\n \r\n answer+=f(a)-f(b)\r\n \r\n y*=3\r\n \r\nprint(answer)\r\n ",
"from collections import defaultdict\r\n\r\nd = {}\r\n\r\nleft, right = map(int, input().split())\r\n\r\nN = max(left, right) + 1\r\n\r\nstack = [1]\r\nd[1] = 1\r\n\r\nwhile stack:\r\n p = stack.pop()\r\n for i in ( 2*p, 3*p):\r\n if i < N:\r\n if not i in d:\r\n d[i] = 1\r\n stack.append(i)\r\n\r\nans = 0\r\nfor a in d:\r\n if left <= a <= right:\r\n ans += 1\r\n \r\nprint(ans)",
"from math import log\r\nfrom math import ceil\r\nl,r = map(int,input().split())\r\n\r\nr1 = log(r,3)\r\n\r\nr1 = ceil(r1)\r\n# print(r1)\r\ns = pow(3,r1)\r\n# print(s)\r\ncount = 0\r\nwhile s >= 1:\r\n\r\n\tk = s\r\n\twhile k <= r:\r\n\t\tif k >= l:\r\n\t\t\tcount = count + 1\r\n\t\tk = k*2\r\n\ts = int(s/3)\r\nprint(count)",
"count=0;\r\nl,r=input().split();\r\nl=int(l);\r\nr=int(r);\r\nfor i in range(31):\r\n for j in range(20):\r\n if pow(2,i)*pow(3,j)>=l and pow(2,i)*pow(3,j)<=r :\r\n count=count+1;\r\nprint(count)",
"n, m = input().split()\r\nn = int(n)\r\nm = int(m)\r\nans = 0\r\nfor i in range(31):\r\n for j in range(20):\r\n if 2 ** i * 3 ** j >= n and 2 ** i * 3 ** j <= m:\r\n ans = ans + 1\r\nprint(ans)\r\n \r\n ",
"import math \r\nl,r=map(int,input().split())\r\ni=0\r\nc=0\r\nwhile 3**i<=r:\r\n a=3**i\r\n k1=0\r\n while a*2**k1<=r:\r\n if a*2**k1>=l:\r\n c=c+1\r\n k1=k1+1\r\n i=i+1 \r\nprint(c) ",
"l, r = input().split();\r\nl = int(l);\r\nr = int(r);\r\ncnt = 0;\r\nt = 1;\r\nwhile (t <= r):\r\n t1 = t;\r\n while (t1 <= r):\r\n if (t1 <= r and t1 >= l):\r\n cnt += 1\r\n t1 *= 3;\r\n t *= 2;\r\nprint(cnt);",
"re = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824]\r\nre1 = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489, 1162261467, 3486784401, 10460353203, 31381059609, 94143178827, 282429536481, 847288609443, 2541865828329, 7625597484987, 22876792454961, 68630377364883, 205891132094649]\r\nrr = []\r\nfor i in range(31):\r\n for k in range(31):\r\n rr.append(re1[i]*re[k])\r\nrr.sort()\r\nlenn = len(rr)+1\r\ns = list(map(int, input().split()))\r\nmm = []\r\nfor o in range(2):\r\n x = s[o]\r\n r = lenn\r\n l = -1\r\n while r-l > 1:\r\n m = (r+l) // 2\r\n if rr[m] < x:\r\n l = m\r\n else:\r\n r = m\r\n if o == 1:\r\n if rr[r] == x:\r\n r += 1\r\n mm.append(r)\r\nprint(mm[1]-mm[0])",
"def solve(a):\r\n\tt,d,rez=1,1,0\r\n\twhile t<=a:\r\n\t\td=1\r\n\t\twhile d*t<=a:\r\n\t\t\trez+=1\r\n\t\t\td*=2\r\n\t\tt*=3\r\n\treturn rez\r\n\r\nline=input()\r\nl=int(line.split()[0])\r\nr=int(line.split()[1])\r\n\r\nprint(\"{}\\n\".format(solve(r)-solve(l-1)))",
"def call():\r\n \r\n y=input()\r\n l=int(y.split()[0])\r\n r=int(y.split()[1])\r\n n=1\r\n ans=0\r\n \r\n # if((n>=l) & (n<=r)):\r\n # ans+=1\r\n for i in range(32):\r\n \r\n if((n>=l) & (n<=r)):\r\n #print(n)\r\n ans+=1\r\n temp=n\r\n for j in range(30):\r\n temp=temp*3\r\n if((temp>=l) & (temp<=r)):\r\n #print(temp)\r\n ans+=1\r\n n=n*2\r\n print(ans)\r\n return\r\n\r\ncall()\r\n",
"l, r = map(int, input().split())\r\nans = 0\r\nfor i in range(31):\r\n for j in range(31):\r\n if 2**i * 3 ** j >= l:\r\n if 2**i * 3**j <=r:\r\n ans = ans + 1\r\nprint(ans)",
"i = 0\r\nl,r = map(int,input().split())\r\nans = 0\r\nwhile 2**i <= r: \r\n temp = 2**i\r\n for k in range(0,60):\r\n if l <= temp*(3**k) <= r: \r\n ans += 1\r\n i += 1\r\nprint(ans)\r\n ",
"l,r=map(int,input().split())\r\nt=[1]\r\nd=[1]\r\nwhile t[-1]<10**9*2:\r\n t.append(t[-1]*3)\r\nwhile d[-1]<10**9*2:\r\n d.append(d[-1]*2)\r\ns=0\r\nfor i in range(len(t)):\r\n for j in range(len(d)):\r\n if t[i]*d[j]<=r and t[i]*d[j]>=l:\r\n s+=1\r\nprint(s)",
"l, r = map(int, input().split())\r\nmon = 0\r\nfor i in range(0, 31):\r\n for j in range(0, 31):\r\n if (2 ** j) * (3 ** i) > r:\r\n break\r\n if (2 ** j) * (3 ** i) <= r and (2 ** j) * (3 ** i) >= l:\r\n mon += 1\r\nprint(mon)",
"\r\na = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824]\r\nb = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489, 1162261467]\r\n\r\nl = list(map(int, input().split()))\r\n#print(l[0])\r\n#print(l[1])\r\n\r\nsc = 0\r\n\r\n\r\nfor i in a:\r\n for j in b:\r\n x = i*j\r\n #print(i)\r\n #print(j)\r\n #print(x)\r\n #print(sc)\r\n if (x >= l[0] and x <= l[1]):\r\n sc += 1\r\n\r\n\r\nprint(sc)",
"if __name__ == '__main__':\r\n\ta,b = map(int, input().split())\r\n\tcount = 0\r\n\tfor i in range (31):\r\n\t\tfor j in range (21):\r\n\t\t\tif a <= (2**i)*(3**j) <= b:\r\n\t\t\t\tcount+=1\r\n\tprint(count)",
"minn, maxx = map(int, input().split())\n\ngoodnums = set()\n\ncount = 0\ndef generate(num):\n global count\n if num > 2E9 or num > maxx:\n return\n if num in goodnums:\n return\n else:\n goodnums.add(num)\n if num >= minn and num <= maxx:\n count += 1\n generate(num*2)\n generate(num*3)\n\ngenerate(1)\nprint(count)\n",
"l, r = map(int, input().split())\r\nans = set()\r\nfor i in range(31):\r\n for j in range(21):\r\n val = pow(2, i) * pow(3, j)\r\n if l <= val <= r:\r\n ans.add(val)\r\nprint(len(ans))\r\n",
"a,b = list(map(int,input().split()))\r\np2 = 1\r\np3 = 1\r\nans = 0\r\n\r\nfor i in range(1, 1000):\r\n if p2 <= b:\r\n p3 = 1\r\n for j in range(1, 1000):\r\n if p2 * p3 > b:\r\n break\r\n if p2 * p3 >= a:\r\n ans = ans + 1\r\n p3 = p3 * 3\r\n else:\r\n break \r\n p2 = p2 * 2\r\nprint(ans)",
"def fun( l, r ):\r\n ret = 0\r\n pw_1 = 1\r\n pw_2 = 1\r\n for x in range( 32 ):\r\n pw_2 = 1\r\n \r\n for y in range( 32 ):\r\n num = pw_1 * pw_2\r\n if l <= num <= r:\r\n ret += 1\r\n pw_2 = pw_2 * 3\r\n\r\n pw_1 = pw_1 * 2\r\n\r\n return ret \r\n\r\nif __name__ == \"__main__\":\r\n l, r = map( int, input().split() )\r\n print( fun( l, r ) )\r\n",
"l,r = map(int,input().split())\r\nst = set()\r\ni = 0\r\nwhile 2**i <= 2*10**9 :\r\n j = 0\r\n while 2**i*3**j <= 2*10**9 :\r\n st.add(2**i*3**j)\r\n j += 1\r\n i += 1\r\nls = list(st) \r\nls.sort()\r\ni = 0\r\nwhile i < 326 and ls[i] < l :\r\n i += 1\r\nj = 0\r\nwhile j < 326 and ls[j] <= r :\r\n j += 1\r\nprint(j-i)",
"l,r = map(int,input().split())\r\nnum = []\r\nfor i in range(32):\r\n for j in range(20):\r\n num.append((2**i)*(3**j))\r\nans = 0\r\nfor i in num:\r\n if l<=i and r >=i:\r\n ans+=1\r\nprint(ans)\r\n",
"a , b = map(int , input().split())\r\nanswer = 0\r\nwhile(b >= 1):\r\n c = 0\r\n while(3**c <= b):\r\n if 3**c >= a:\r\n answer += 1\r\n c += 1\r\n b = b / 2\r\n a = a / 2\r\nprint(answer)",
"def before_solution():\n k = 0\n while 2**k <= 2 * 10**9:\n list_2.append(2**k)\n k += 1\n k = 0\n while 3**k <= 2 * 10**9:\n list_3.append(3**k)\n k += 1\n for i in list_2:\n for j in list_3:\n all_list.append(i*j)\n all_list.sort()\n\n\ndef solution(l, r):\n _i, _j = 0, 0\n for i in range(len(all_list)):\n if l > all_list[i]:\n _i = i\n else:\n break\n for j in range(len(all_list)-1, -1, -1):\n if r < all_list[j]:\n _j = j\n else:\n break\n return _j - _i - 1\n\n\nif __name__ == '__main__':\n _n, _m = map(int, input().rstrip().split())\n list_2 = []\n list_3 = []\n all_list = []\n before_solution()\n all_list.insert(0, 0)\n print(solution(_n, _m))",
"a,b=map(int,input().split())\r\nprint(sum(a<=(2**i*3**j)<=b for j in range(20) for i in range(31)))",
"l, r = input().split()\r\nl = int(l)\r\nr = int(r)\r\na = []\r\nb = []\r\ni = 1\r\nc = 1\r\nwhile i < 33:\r\n a.append(c)\r\n c = c * 2\r\n i = i + 1\r\ni = 1\r\nc = 1\r\nwhile i < 23:\r\n b.append(c)\r\n c = c * 3\r\n i = i + 1\r\ni = 0\r\nj = 1\r\nk = 0\r\nwhile i < 32:\r\n i = i + 1\r\n j = 1\r\n while j < 22:\r\n if a[i - 1] * b[j - 1] >= l and a[i - 1] * b[j - 1] <= r: k = k + 1\r\n j = j + 1\r\n\r\nprint(k)",
"\r\nl, r = (int(x)for x in input().split())\r\n\r\ncnt = 0\r\nfor i in range(35):\r\n for j in range(25):\r\n x = (2**i)*(3**j)\r\n if x>=l and x<=r :\r\n cnt += 1\r\nprint(cnt)",
"# --------------------------------------------------------------------------------------------------------#\r\n\"\"\"\"\r\n ------------------------------------------------\r\n\r\n creating by : Ali albohazim \r\n\r\n 2018-03-29 03:24:21.991998\r\n\r\n -------------------------------------------------\r\n\r\n\"\"\"\r\n\r\n# ---------------------------------------------------------------------------------------------------------#\r\n\r\nleft, right = map(int, input().split(' '))\r\nprint(sum([left <= 2 ** i * 3 ** j <= right for i in range(31) for j in range(31)]))\r\n\r\n# ---------------------------------------------------------------------------------------------------------#\r\n",
"from sys import *\r\nfrom bisect import *\r\nfrom collections import *\r\n\r\nInput = []\r\n\r\n#stdin = open('in', 'r')\r\n#stdout = open('out', 'w')\r\n\r\n## for i, val in enumerate(array, start_i_value)\r\n\r\ndef Out(x):\r\n stdout.write(str(x) + '\\n')\r\n\r\ndef In():\r\n return stdin.readline().strip()\r\n\r\ndef inputGrab():\r\n for line in stdin:\r\n Input.extend(map(str, line.strip().split()))\r\n'''--------------------------------------------------------------------------------'''\r\n\r\nSet = set()\r\nv = []\r\n\r\ndef calculate(x, y):\r\n for i in range(x):\r\n for j in range(y):\r\n val = pow(2, i) * pow(3, j)\r\n #print(\"val\", val)\r\n if val not in Set:\r\n Set.add(val)\r\n v.append(val)\r\n\r\n\r\ndef main():\r\n calculate(31, 31)\r\n \r\n v.sort()\r\n \r\n #for i, val in enumerate(v):\r\n # print(val, end = ' ')\r\n # if(i > 20):\r\n # break\r\n #print()\r\n \r\n n, m = map(int, In().split())\r\n l = bisect_left(v, n)\r\n r = bisect_right(v, m)\r\n \r\n print(r-l)\r\n \r\n\r\n \r\nif __name__ == '__main__':\r\n main()\r\n",
"l, r = map(int, input().split())\r\nz = 0\r\ntwo = 1\r\nwhile two <= r:\r\n three = two\r\n while three <= r:\r\n if l <= three and three <= r:\r\n z += 1\r\n three *= 3\r\n two *= 2\r\nprint(z)\r\n",
"l,r=(int(x) for x in input().split())\r\nans=0\r\nfor i in range (35):\r\n for j in range (25):\r\n x=(2**i)*(3**j)\r\n if x>=l and x<=r :\r\n ans+=1\r\nprint(ans)",
"a, b = map(int, input().split())\r\n\r\nres = 0\r\nfor i in range(31):\r\n\tfor j in range(20):\r\n\t\tif 2**i * 3**j <= b and 2**i * 3**j >= a:\r\n\t\t\tres += 1\r\n\r\nprint(res)",
"l, r = map(int, input().split())\r\nans = 0\r\n\r\nfor i in range(0, 31):\r\n\ttwos = 2 ** i\r\n\tfor j in range(0, 21):\r\n\t\tthrees = 3 ** j\r\n\t\tif twos * threes >= l and twos * threes <= r:\r\n\t\t\tans = ans + 1;\r\n\r\nprint(ans)",
"def rek(num):\r\n global l, r, been, ans\r\n \r\n if num > r:\r\n return \r\n \r\n for i in range(len(been)):\r\n if been[i] == num:\r\n return\r\n \r\n been.append(num)\r\n if num >= l and num <= r:\r\n ans += 1\r\n rek(num * 2)\r\n rek(num * 3)\r\n\r\nbeen = []\r\nans = 0\r\nl, r = [int(x) for x in input().split()]\r\nrek(1)\r\nprint(ans)",
"ns = []\r\n\r\nfor x in range(35):\r\n for y in range(35):\r\n ns.append(2 ** x * 3 ** y)\r\nns.sort()\r\n\r\nl, r = [int(x) for x in input().split()]\r\n\r\nres = 0\r\n\r\nfor n in ns:\r\n if l <= n <= r:\r\n res += 1\r\nprint(res)\r\n",
"l,r = map(int,input().split())\r\nans = 0\r\nb = []\r\nstepen_2= [1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384 ,32768, 65536 ,131072 ,262144, 524288 ,1048576, 2097152 ,4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824]\r\nstepen_3 = [1,3,9,27,81,243,729,2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489, 1162261467]\r\nfor i in range(len(stepen_2)):\r\n\tif stepen_2[i]>r:\r\n\t\tbreak\r\n\telse:\r\n\t\tfor j in range(len(stepen_3)):\r\n\t\t\tif stepen_2[i]*stepen_3[j]>r:\r\n\t\t\t\tbreak\r\n\t\t\telif stepen_2[i]*stepen_3[j]>=l and stepen_2[i]*stepen_3[j]<=r:\r\n\t\t\t\tans+=1\r\nprint(ans)\r\n# while min_stepen2<=r:\r\n# \tmin_stepen2*=2\r\n# \tans+=1\r\n# while min_stepen3<r:\r\n# \tmin_stepen3*=3\r\n# \tans+=1\r\n# for i in range(l,r+1):\r\n# \tif i%6==0:\r\n# \t\tmin_cratnoe6=i\r\n# \t\tbreak\r\n# while min_cratnoe6<r:\r\n# \tans+=1\r\n# \tmin_cratnoe6+=6\r\n# if l==1:\r\n# \tans-=1#потому что 1 является степенью двойки и тройки одновременно\r\n# print(ans)",
"l,r=map(int,input().split())\r\nx=1\r\ny=1\r\nc=0\r\nwhile x<=r:\r\n y=1\r\n while y<=r:\r\n if l<=x*y<=r:\r\n c+=1\r\n y*=3\r\n x*=2\r\nprint(c)",
"l, r = map(int, input().split())\r\nans = 0\r\nfor i in range(31):\r\n for j in range(20):\r\n if 2**i*3**j>=l and 2**i*3**j<=r:\r\n ans+=1\r\nprint(ans)",
"l,r=list(map(int,input().split()))\ncount=0\nfor i in range(0,32):\n\ttemp=(1<<i)\n\tif((temp >= l) and(temp<=r)):\n\t\tcount+=1\n\tfor j in range(1,21):\n\t\tn=3**j\n\t\tif(((n*temp)>= l) and((n*temp)<=r)):\n\t\t\tcount+=1\nprint(count)\n\n\n",
"l, r = input().split(\" \")\r\nl = int(l)\r\nr = int(r)\r\n\r\ncnt = 0\r\nfor x in range(32):\r\n for y in range(21):\r\n if 2**x * 3**y >= l and 2**x * 3**y <= r:\r\n cnt += 1\r\n\r\nprint(cnt)",
"l,r = map(int, input().split())\r\n\r\n\r\ndef main(l,r):\r\n\tc=0\r\n\ts = []\r\n\tfor x in range(0,31):\r\n\t\tfor y in range(0,20):\r\n\t\t\tt = (2**x)*(3**y)\r\n\t\t\ts.append(t)\r\n\t\r\n\tl = [*filter(lambda x: x >= l, s)]\r\n\tr = [*filter(lambda x: x <= r, s)]\r\n\t\r\n\treturn len(set(r).intersection(set(l)))\r\n\t\t\r\nprint(main(l,r))",
"import math\nl, r = map(int, input().split())\n\n\nans = 0\nfor i in range(0, 31):\n for j in range(0, 21):\n v = (2**i) * (3**j) \n if v >= l and v <= r:\n ans = ans + 1\nprint(ans)",
"l, r = map(int, input().split())\r\nmax_pow = 0\r\nwhile 2 ** max_pow <= r:\r\n max_pow += 1\r\nans = set()\r\nfor i in range(0, max_pow + 1):\r\n for j in range(0, max_pow + 1):\r\n num = 2 ** i * 3 ** j\r\n if l <= num <= r:\r\n ans.add(num)\r\nprint(len(ans))",
"\r\na, b = list(map(int, input().split()))\r\n\r\nx, y = 0, 0\r\nx_max, y_max = 0, 0\r\nwhile 2**x_max <= b:\r\n x_max += 1\r\nwhile 3**y_max <= b:\r\n y_max += 1\r\n \r\nk = 0\r\n\r\nfor x in range(x_max):\r\n for y in range(y_max):\r\n num = 2**x * 3**y\r\n if a <= num <= b:\r\n k += 1\r\n elif num > b:\r\n break\r\n else:\r\n continue\r\nprint(k)",
"l, r = input().split()\r\nl = int(l)\r\nr = int(r)\r\na, b = [0] * 50, [0] * 50\r\na[0] = 1\r\nb[0] = 1\r\nfor i in range(1, 40):\r\n a[i], b[i] = a[i - 1] * 2, b[i - 1] * 3\r\nans = 0\r\nfor i in range(40):\r\n for j in range(40):\r\n if a[i] * b[j] >= l and a[i] * b[j] <= r:\r\n ans += 1\r\nprint(ans)",
"l, r = map(int, input().split())\n\nprint(len([0 for i in range(31) for j in range(20) if l <= 2 ** i * 3 ** j <= r]))\n\n\n\n# Made By Mostafa_Khaled",
"import random\r\ndef pw(a, b):\r\n s = 1\r\n for i in range(b):\r\n s *= a\r\n return s\r\n\r\ndef quicksort(nums):\r\n if len(nums) <= 1:\r\n return nums\r\n else:\r\n q = random.choice(nums)\r\n l_nums = [n for n in nums if n < q]\r\n \r\n e_nums = [q] * nums.count(q)\r\n b_nums = [n for n in nums if n > q]\r\n return quicksort(l_nums) + e_nums + quicksort(b_nums)\r\n\r\nll = 0\r\nrr = 0\r\nll, rr = map(int, input().split())\r\nv = []\r\nfor i in range(31):\r\n for j in range(21):\r\n s = pw(2, i) * pw(3, j)\r\n v.append(s)\r\nv = quicksort(v)\r\nx = 0\r\ny = 0\r\nl = -1\r\nr = len(v)\r\nwhile l + 1 < r:\r\n mid = (l + r) // 2\r\n if v[mid] >= ll:\r\n r = mid\r\n else:\r\n l = mid\r\nx = r\r\nl = 0\r\nr = len(v)\r\nwhile l + 1 < r:\r\n mid = (l + r) // 2\r\n if v[mid] > rr:\r\n r = mid\r\n else:\r\n l = mid\r\ny = r\r\nprint(y - x)",
"l, r = map(int, input().split())\r\nans = 0\r\nx = 1\r\nwhile x <= r:\r\n y = x\r\n while y <= r:\r\n if l <= y:\r\n ans += 1\r\n y *= 3\r\n x *= 2\r\nprint(ans)\r\n",
"l,r = map(int,input().split())\r\nans = 0\r\nfor i in range(31):\r\n for j in range(21):\r\n if l<=((2**i)*(3**j))<=r:\r\n ans+=1\r\nprint(ans)",
"l, r = map(int, input().split())\r\ncounter = 0\r\nfor x in range(31):\r\n for y in range(20):\r\n num = 2 ** x * 3 ** y\r\n if l <= num <= r:\r\n counter += 1\r\n elif num > r:\r\n break\r\nprint(counter)\r\n",
"import sys\r\n\r\n\r\ndef prov(n):\r\n k = n\r\n while k % 2 == 0:\r\n k //= 2\r\n while k % 3 == 0:\r\n k //= 3\r\n return k == 1\r\n\r\n\r\ndef get_3(k):\r\n r = 0\r\n while k > 0:\r\n k //= 3\r\n r += 1\r\n return r\r\n\r\n\r\ndef get_2_3(k):\r\n r = 0\r\n while k > 0:\r\n r += get_3(k)\r\n k //= 2\r\n return r\r\n\r\n\r\ndef solution():\r\n l, r = map(int, input().split())\r\n print(get_2_3(r)-get_2_3(l-1))\r\n\r\n\r\ndef perebor(l, r):\r\n k = 0\r\n for i in range(l, r+1):\r\n if prov(i):\r\n k += 1\r\n return k\r\n\r\n\r\nDEBAG = False\r\nif DEBAG:\r\n sys.stdin = open('test.3')\r\n t = int(input())\r\n for i in range(t):\r\n solution()\r\nelse:\r\n solution()\r\n\r\n\r\n# for i in range(1, 10000, 10):\r\n# for j in range(i, 1000):\r\n# n = perebor(i, j)\r\n# m = get_2_3(j)-get_2_3(i-1)\r\n# if n != m:\r\n# print(n, m, i, j)",
"l, r= map ( int, input().split())\r\nc=0\r\nk=0\r\n\r\nfor x in range(0,31) :\r\n for p in range(0,20) :\r\n k=(2**x) * (3**p)\r\n\r\n if k in range(l,r+1) :\r\n c=c+1\r\nprint (c)",
"s = input().split(' ')\r\na, b = int(s[0]), int(s[1]);\r\nres = 0\r\nfor i in range(0, 100):\r\n for j in range(0, 100):\r\n tmp = (2 ** i) * (3 ** j)\r\n if (a <= tmp and tmp <= b):\r\n res = res + 1\r\n\r\nprint(res)",
"l, r =map(int,input().split())\r\ntwoes = [1]+[0]*30\r\nfor i in range(1, 31):\r\n twoes[i] = twoes[i-1]*2\r\nthrees = [1] + [0]*19\r\nfor i in range(1, 20):\r\n threes[i] = threes[i-1]*3\r\nmult = set()\r\nfor i in twoes:\r\n for j in threes:\r\n if i*j <= 2*10**9:\r\n mult.add(i*j)\r\nres = 0\r\nfor i in mult:\r\n if l <= i <= r:\r\n res += 1\r\nprint(res)",
"#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n__author__ = 'QAQ AutoMaton'\r\n\r\ndef count(x):\r\n y=0;\r\n while x>0:\r\n y+=1\r\n x//=3\r\n\r\n return y\r\ndef calc(x):\r\n y=0\r\n while x>0:\r\n y+=count(x)\r\n x//=2\r\n return y \r\nl,r=map(int,input().split())\r\nprint(calc(r)-calc(l-1))\r\n\r\n\r\n",
"a, b = map(int, input().split())\r\nans=0\r\nfor i in range(50):\r\n for j in range(30):\r\n if ((2**i)*(3**j)>=a) and ((2**i)*(3**j) <=b):\r\n ans=ans+1\r\n \r\nprint(ans)",
"l, r = map(int, input().split())\r\n\r\nans = 0\r\n\r\nfor i in range(32):\r\n for j in range(32):\r\n tmp = (2**i)*(3**j)\r\n if(l <= tmp and tmp <=r):\r\n ans += 1\r\n \r\nprint (ans)",
"two_three_nums = [2**i * 3**j for i in range(31) for j in range(20)]\nans = 0 \nl, r = map(int, input().split())\nfor two_three_num in two_three_nums:\n if l <= two_three_num <= r:\n ans += 1\nprint(ans)",
"from collections import deque\r\nq = deque()\r\nl, r = map(int, input().split())\r\nq.append(1);\r\nu = 1\r\np = 0\r\nif l <= 1:\r\n p += 1\r\nwhile u <= r*r:\r\n u = q.popleft()\r\n if q.count(u * 2) == 0:\r\n q.append(u * 2)\r\n if u * 2 >= l and u * 2 <= r:\r\n p += 1\r\n if q.count(u * 3) == 0:\r\n q.append(u * 3)\r\n if u * 3 >= l and u * 3 <= r:\r\n p += 1\r\nprint(p)\r\n",
"l,r = map(int,input().split())\nn=0\ncount=0\nfor pow2 in range(0,33):\n for pow3 in range(0,33):\n n = (2**pow2) * (3**pow3)\n if n<=r and n>=l:\n count+=1\nprint(count)\n\n\n",
"l, r = map(int, input().split())\r\nst2 = 1\r\nst3 = 1\r\nkol = 0\r\nfor i in range(0,31):\r\n if i>0:\r\n st2 = st2*2\r\n st3=1\r\n for j in range(0,20):\r\n if j>0:\r\n st3 = st3*3\r\n if st2*st3>=l and st2*st3<=r:\r\n kol = kol + 1\r\nprint(kol)",
"l,r=(int(x)for x in input().split())\r\nans=0\r\nfor i in range(35):\r\n\tfor j in range(25):\r\n\t\tx=(2**i)*(3**j)\r\n\t\tif x>=l and x<=r :\r\n\t\t\tans+=1\r\nprint(ans)\r\n",
"l, r = map(int, input().split())\r\nk1 = 1\r\nnum1 = 0\r\nwhile k1 <= r:\r\n k2 = k1\r\n while k2 <= r:\r\n k2 *= 3\r\n num1 += 1\r\n k1 *= 2\r\n\r\nk1 = 1\r\nnum2 = 0\r\nwhile k1 < l:\r\n k2 = k1\r\n while k2 < l:\r\n k2 *= 3\r\n num2 += 1\r\n k1 *= 2\r\n\r\n\r\nprint(num1 - num2)\r\n",
"ara = []\r\nfor i in range(0, 34):\r\n for j in range(0, 34):\r\n if (2**i)*(3**j) <= 2000000000:\r\n ara.append((2**i)*(3**j))\r\n else:\r\n break\r\n \r\nl, r = map(int, input().split())\r\nx = 0\r\nfor i in ara:\r\n if i >= l and i <= r:\r\n x = x+1\r\nprint(x)",
"s=input()\r\ns=s.split(\" \")\r\nl=int(s[0])\r\nr=int(s[1])\r\na=1\r\nb=1\r\ncnt=0\r\n\r\nfor i in range(70):\r\n for j in range(70):\r\n if a>=l:\r\n if a<=r:\r\n cnt=cnt+1\r\n a=a*3\r\n a=b*2\r\n b=b*2\r\n\r\nprint(cnt)\r\n",
"def f(r):\n x = 1\n res = 0\n while x <= r:\n y = 1\n while y <= r:\n if x * y <= r:\n res += 1\n y *= 2\n x *= 3\n return res\n\nl, r = map(int, input().split())\nprint(f(r) - f(l - 1))\n",
"from math import log\r\nfrom math import ceil\r\nl,r=map(int,input().split())\r\ni=0\r\ns=0\r\nwhile 2**i<=r:\r\n j=max(0,ceil(log(l*2**-i,3)))\r\n while (2**i)*(3**j)<=r:\r\n s+=1\r\n j+=1\r\n i+=1\r\nprint(s)\r\n",
"l, r = map(int, input().split())\r\nx = 0\r\ns = set()\r\nwhile 1:\r\n y = 0\r\n if 2 ** x * 3 ** y > r:\r\n break\r\n while 1:\r\n if 2**x*3**y > r:\r\n break\r\n if 2**x*3**y >= l:\r\n s.add(2**x*3**y)\r\n y += 1\r\n x += 1\r\nprint(len(s))",
"# LUOGU_RID: 102009371\nl, r = map(int, input().split())\r\nx = 1\r\nans = 0\r\nwhile x <= r:\r\n y = 1\r\n while x * y <= r:\r\n if x * y >= l:\r\n ans += 1\r\n y *= 3\r\n x <<= 1\r\nprint(ans)",
"l, r = [int(x) for x in input().split()]\n\nl2 = {2**x for x in range(32)}\nl3 = {3**x for x in range(21)}\n\nsvv = {x*y for x in l2 for y in l3}\n\ncounter = 0\nfor val in svv:\n if l <= val <= r:\n counter += 1\n\nprint(counter)\n",
"def main():\r\n a, b = map(int, input().split());\r\n count=0;\r\n for two_fact in range(0,40):\r\n for three_fact in range(0,40):\r\n if(a<=(2**two_fact)*(3**three_fact) and b>=(2**two_fact)*(3**three_fact)):\r\n count+=1;\r\n print(count);\r\nmain();\r\n",
"l, r = list(map(int, input().split()))\r\nlength3 = 0 \r\nwhile 3**(length3)<= r:\r\n length3 += 1\r\nlength2 = 0\r\nwhile 2**length2<=r:\r\n length2 += 1\r\nanswer = 0\r\nfor i in range(length3+1):\r\n for j in range(length2+1):\r\n if l <= (2**j)*(3**i) <= r:\r\n answer += 1\r\nprint(answer)",
"l, r = map(int, input().split())\r\nresult = set()\r\nfor x in range(31):\r\n for y in range(20):\r\n v = 2**x*3**y\r\n if l <= v <= r:\r\n result.add(v)\r\nprint(len(result))",
"l,r=[int(e) for e in input().split()]\r\nc=0\r\nx=1\r\nwhile x<=r:\r\n y=1\r\n while x*y<=r:\r\n if x*y>=l:\r\n c+=1\r\n y*=3\r\n x*=2\r\nprint(c)",
"count = 0\r\nl, r = map(int, input().split())\r\nfor i in range(50):\r\n for j in range(50):\r\n if l <= (2 ** i) * (3 ** j) <= r:\r\n count += 1\r\n if (2 ** i) * (3 ** j) > r:\r\n break\r\n\r\nprint(count)",
"s = input()\r\na = s.split(' ')\r\nl = int(a[0])\r\nr = int(a[1])\r\nans = 0\r\nfor i in range(0, 31):\r\n for j in range(0, 31):\r\n k = (2 ** i) * (3 ** j)\r\n if k >= l and k <= r:\r\n ans += 1\r\nprint(ans)",
"a, b = (int(x) for x in input().split(' '))\r\nnums = [1]\r\nmax1 = 1\r\nmax2 = 1\r\nfor i in range(500):\r\n if nums[max1 - 1] * 2 <= nums[max2 - 1] * 3:\r\n nums.append(nums[max1 - 1] * 2)\r\n if nums[max1 - 1] * 2 == nums[max2 - 1] * 3:\r\n max1 += 1\r\n max2 += 1\r\n else:\r\n max1 += 1\r\n else:\r\n nums.append(nums[max2 - 1] * 3)\r\n max2 += 1\r\ncnt = 0\r\nfor i in range(500):\r\n if nums[i] >= a and nums[i] <= b:\r\n cnt += 1\r\nprint(cnt)\r\n",
"l, r = map(int, input().split())\r\nc = 2 * 1e9\r\na = []\r\nb = []\r\nfor i in range(31):\r\n a.append(2**i)\r\n \r\nfor i in range(20):\r\n b.append(3**i)\r\n\r\nmulty = set()\r\nfor i in a:\r\n for j in b:\r\n if (i * j >= l) and (i * j <= r):\r\n multy.add(i * j)\r\n \r\nprint(len(multy))",
"l, r = map(int, input().split())\nans = 0\nfor i in range(100):\n\tfor j in range(100):\n\t\tif 2**i*3**j > 2000000000:\n\t\t\tbreak\n\t\tif l<=2**i*3**j:\n\t\t\tif r>=2**i*3**j:\n\t\t\t\tans = ans+1\nprint(ans)\n",
"l, r = map(int, input().split())\r\n\r\nnum_of_twos_and_threes = 0\r\nfor degree_of_two in range(31):\r\n for degree_of_three in range(31):\r\n if l <= pow(2, degree_of_two) * pow(3, degree_of_three) <= r:\r\n num_of_twos_and_threes += 1\r\n\r\nprint(num_of_twos_and_threes)\r\n",
"s = list(map(lambda x: int(x),input().split()))\r\nl,r = s[0],s[1]\r\nanswer = 0\r\narr = [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489, 1162261467, 3486784401, 10460353203, 31381059609, 94143178827, 282429536481, 847288609443, 2541865828329, 7625597484987, 22876792454961, 68630377364883, 205891132094649, 617673396283947, 1853020188851841, 5559060566555523, 16677181699666569, 2, 6, 18, 54, 162, 486, 1458, 4374, 13122, 39366, 118098, 354294, 1062882, 3188646, 9565938, 28697814, 86093442, 258280326, 774840978, 2324522934, 6973568802, 20920706406, 62762119218, 188286357654, 564859072962, 1694577218886, 5083731656658, 15251194969974, 45753584909922, 137260754729766, 411782264189298, 1235346792567894, 3706040377703682, 11118121133111046, 33354363399333138, 4, 12, 36, 108, 324, 972, 2916, 8748, 26244, 78732, 236196, 708588, 2125764, 6377292, 19131876, 57395628, 172186884, 516560652, 1549681956, 4649045868, 13947137604, 41841412812, 125524238436, 376572715308, 1129718145924, 3389154437772, 10167463313316, 30502389939948, 91507169819844, 274521509459532, 823564528378596, 2470693585135788, 7412080755407364, 22236242266222092, 66708726798666276, 8, 24, 72, 216, 648, 1944, 5832, 17496, 52488, 157464, 472392, 1417176, 4251528, 12754584, 38263752, 114791256, 344373768, 1033121304, 3099363912, 9298091736, 27894275208, 83682825624, 251048476872, 753145430616, 2259436291848, 6778308875544, 20334926626632, 61004779879896, 183014339639688, 549043018919064, 1647129056757192, 4941387170271576, 14824161510814728, 44472484532444184, 133417453597332552, 16, 48, 144, 432, 1296, 3888, 11664, 34992, 104976, 314928, 944784, 2834352, 8503056, 25509168, 76527504, 229582512, 688747536, 2066242608, 6198727824, 18596183472, 55788550416, 167365651248, 502096953744, 1506290861232, 4518872583696, 13556617751088, 40669853253264, 122009559759792, 366028679279376, 1098086037838128, 3294258113514384, 9882774340543152, 29648323021629456, 88944969064888368, 266834907194665104, 32, 96, 288, 864, 2592, 7776, 23328, 69984, 209952, 629856, 1889568, 5668704, 17006112, 51018336, 153055008, 459165024, 1377495072, 4132485216, 12397455648, 37192366944, 111577100832, 334731302496, 1004193907488, 3012581722464, 9037745167392, 27113235502176, 81339706506528, 244019119519584, 732057358558752, 2196172075676256, 6588516227028768, 19765548681086304, 59296646043258912, 177889938129776736, 533669814389330208, 64, 192, 576, 1728, 5184, 15552, 46656, 139968, 419904, 1259712, 3779136, 11337408, 34012224, 102036672, 306110016, 918330048, 2754990144, 8264970432, 24794911296, 74384733888, 223154201664, 669462604992, 2008387814976, 6025163444928, 18075490334784, 54226471004352, 162679413013056, 488038239039168, 1464114717117504, 4392344151352512, 13177032454057536, 39531097362172608, 118593292086517824, 355779876259553472, 1067339628778660416, 128, 384, 1152, 3456, 10368, 31104, 93312, 279936, 839808, 2519424, 7558272, 22674816, 68024448, 204073344, 612220032, 1836660096, 5509980288, 16529940864, 49589822592, 148769467776, 446308403328, 1338925209984, 4016775629952, 12050326889856, 36150980669568, 108452942008704, 325358826026112, 976076478078336, 2928229434235008, 8784688302705024, 26354064908115072, 79062194724345216, 237186584173035648, 711559752519106944, 2134679257557320832, 256, 768, 2304, 6912, 20736, 62208, 186624, 559872, 1679616, 5038848, 15116544, 45349632, 136048896, 408146688, 1224440064, 3673320192, 11019960576, 33059881728, 99179645184, 297538935552, 892616806656, 2677850419968, 8033551259904, 24100653779712, 72301961339136, 216905884017408, 650717652052224, 1952152956156672, 5856458868470016, 17569376605410048, 52708129816230144, 158124389448690432, 474373168346071296, 1423119505038213888, 4269358515114641664, 512, 1536, 4608, 13824, 41472, 124416, 373248, 1119744, 3359232, 10077696, 30233088, 90699264, 272097792, 816293376, 2448880128, 7346640384, 22039921152, 66119763456, 198359290368, 595077871104, 1785233613312, 5355700839936, 16067102519808, 48201307559424, 144603922678272, 433811768034816, 1301435304104448, 3904305912313344, 11712917736940032, 35138753210820096, 105416259632460288, 316248778897380864, 948746336692142592, 2846239010076427776, 8538717030229283328, 1024, 3072, 9216, 27648, 82944, 248832, 746496, 2239488, 6718464, 20155392, 60466176, 181398528, 544195584, 1632586752, 4897760256, 14693280768, 44079842304, 132239526912, 396718580736, 1190155742208, 3570467226624, 10711401679872, 32134205039616, 96402615118848, 289207845356544, 867623536069632, 2602870608208896, 7808611824626688, 23425835473880064, 70277506421640192, 210832519264920576, 632497557794761728, 1897492673384285184, 5692478020152855552, 17077434060458566656, 2048, 6144, 18432, 55296, 165888, 497664, 1492992, 4478976, 13436928, 40310784, 120932352, 362797056, 1088391168, 3265173504, 9795520512, 29386561536, 88159684608, 264479053824, 793437161472, 2380311484416, 7140934453248, 21422803359744, 64268410079232, 192805230237696, 578415690713088, 1735247072139264, 5205741216417792, 15617223649253376, 46851670947760128, 140555012843280384, 421665038529841152, 1264995115589523456, 3794985346768570368, 11384956040305711104, 34154868120917133312, 4096, 12288, 36864, 110592, 331776, 995328, 2985984, 8957952, 26873856, 80621568, 241864704, 725594112, 2176782336, 6530347008, 19591041024, 58773123072, 176319369216, 528958107648, 1586874322944, 4760622968832, 14281868906496, 42845606719488, 128536820158464, 385610460475392, 1156831381426176, 3470494144278528, 10411482432835584, 31234447298506752, 93703341895520256, 281110025686560768, 843330077059682304, 2529990231179046912, 7589970693537140736, 22769912080611422208, 68309736241834266624, 8192, 24576, 73728, 221184, 663552, 1990656, 5971968, 17915904, 53747712, 161243136, 483729408, 1451188224, 4353564672, 13060694016, 39182082048, 117546246144, 352638738432, 1057916215296, 3173748645888, 9521245937664, 28563737812992, 85691213438976, 257073640316928, 771220920950784, 2313662762852352, 6940988288557056, 20822964865671168, 62468894597013504, 187406683791040512, 562220051373121536, 1686660154119364608, 5059980462358093824, 15179941387074281472, 45539824161222844416, 136619472483668533248, 16384, 49152, 147456, 442368, 1327104, 3981312, 11943936, 35831808, 107495424, 322486272, 967458816, 2902376448, 8707129344, 26121388032, 78364164096, 235092492288, 705277476864, 2115832430592, 6347497291776, 19042491875328, 57127475625984, 171382426877952, 514147280633856, 1542441841901568, 4627325525704704, 13881976577114112, 41645929731342336, 124937789194027008, 374813367582081024, 1124440102746243072, 3373320308238729216, 10119960924716187648, 30359882774148562944, 91079648322445688832, 273238944967337066496, 32768, 98304, 294912, 884736, 2654208, 7962624, 23887872, 71663616, 214990848, 644972544, 1934917632, 5804752896, 17414258688, 52242776064, 156728328192, 470184984576, 1410554953728, 4231664861184, 12694994583552, 38084983750656, 114254951251968, 342764853755904, 1028294561267712, 3084883683803136, 9254651051409408, 27763953154228224, 83291859462684672, 249875578388054016, 749626735164162048, 2248880205492486144, 6746640616477458432, 20239921849432375296, 60719765548297125888, 182159296644891377664, 546477889934674132992, 65536, 196608, 589824, 1769472, 5308416, 15925248, 47775744, 143327232, 429981696, 1289945088, 3869835264, 11609505792, 34828517376, 104485552128, 313456656384, 940369969152, 2821109907456, 8463329722368, 25389989167104, 76169967501312, 228509902503936, 685529707511808, 2056589122535424, 6169767367606272, 18509302102818816, 55527906308456448, 166583718925369344, 499751156776108032, 1499253470328324096, 4497760410984972288, 13493281232954916864, 40479843698864750592, 121439531096594251776, 364318593289782755328, 1092955779869348265984, 131072, 393216, 1179648, 3538944, 10616832, 31850496, 95551488, 286654464, 859963392, 2579890176, 7739670528, 23219011584, 69657034752, 208971104256, 626913312768, 1880739938304, 5642219814912, 16926659444736, 50779978334208, 152339935002624, 457019805007872, 1371059415023616, 4113178245070848, 12339534735212544, 37018604205637632, 111055812616912896, 333167437850738688, 999502313552216064, 2998506940656648192, 8995520821969944576, 26986562465909833728, 80959687397729501184, 242879062193188503552, 728637186579565510656, 2185911559738696531968, 262144, 786432, 2359296, 7077888, 21233664, 63700992, 191102976, 573308928, 1719926784, 5159780352, 15479341056, 46438023168, 139314069504, 417942208512, 1253826625536, 3761479876608, 11284439629824, 33853318889472, 101559956668416, 304679870005248, 914039610015744, 2742118830047232, 8226356490141696, 24679069470425088, 74037208411275264, 222111625233825792, 666334875701477376, 1999004627104432128, 5997013881313296384, 17991041643939889152, 53973124931819667456, 161919374795459002368, 485758124386377007104, 1457274373159131021312, 4371823119477393063936, 524288, 1572864, 4718592, 14155776, 42467328, 127401984, 382205952, 1146617856, 3439853568, 10319560704, 30958682112, 92876046336, 278628139008, 835884417024, 2507653251072, 7522959753216, 22568879259648, 67706637778944, 203119913336832, 609359740010496, 1828079220031488, 5484237660094464, 16452712980283392, 49358138940850176, 148074416822550528, 444223250467651584, 1332669751402954752, 3998009254208864256, 11994027762626592768, 35982083287879778304, 107946249863639334912, 323838749590918004736, 971516248772754014208, 2914548746318262042624, 8743646238954786127872, 1048576, 3145728, 9437184, 28311552, 84934656, 254803968, 764411904, 2293235712, 6879707136, 20639121408, 61917364224, 185752092672, 557256278016, 1671768834048, 5015306502144, 15045919506432, 45137758519296, 135413275557888, 406239826673664, 1218719480020992, 3656158440062976, 10968475320188928, 32905425960566784, 98716277881700352, 296148833645101056, 888446500935303168, 2665339502805909504, 7996018508417728512, 23988055525253185536, 71964166575759556608, 215892499727278669824, 647677499181836009472, 1943032497545508028416, 5829097492636524085248, 17487292477909572255744, 2097152, 6291456, 18874368, 56623104, 169869312, 509607936, 1528823808, 4586471424, 13759414272, 41278242816, 123834728448, 371504185344, 1114512556032, 3343537668096, 10030613004288, 30091839012864, 90275517038592, 270826551115776, 812479653347328, 2437438960041984, 7312316880125952, 21936950640377856, 65810851921133568, 197432555763400704, 592297667290202112, 1776893001870606336, 5330679005611819008, 15992037016835457024, 47976111050506371072, 143928333151519113216, 431784999454557339648, 1295354998363672018944, 3886064995091016056832, 11658194985273048170496, 34974584955819144511488, 4194304, 12582912, 37748736, 113246208, 339738624, 1019215872, 3057647616, 9172942848, 27518828544, 82556485632, 247669456896, 743008370688, 2229025112064, 6687075336192, 20061226008576, 60183678025728, 180551034077184, 541653102231552, 1624959306694656, 4874877920083968, 14624633760251904, 43873901280755712, 131621703842267136, 394865111526801408, 1184595334580404224, 3553786003741212672, 10661358011223638016, 31984074033670914048, 95952222101012742144, 287856666303038226432, 863569998909114679296, 2590709996727344037888, 7772129990182032113664, 23316389970546096340992, 69949169911638289022976, 8388608, 25165824, 75497472, 226492416, 679477248, 2038431744, 6115295232, 18345885696, 55037657088, 165112971264, 495338913792, 1486016741376, 4458050224128, 13374150672384, 40122452017152, 120367356051456, 361102068154368, 1083306204463104, 3249918613389312, 9749755840167936, 29249267520503808, 87747802561511424, 263243407684534272, 789730223053602816, 2369190669160808448, 7107572007482425344, 21322716022447276032, 63968148067341828096, 191904444202025484288, 575713332606076452864, 1727139997818229358592, 5181419993454688075776, 15544259980364064227328, 46632779941092192681984, 139898339823276578045952, 16777216, 50331648, 150994944, 452984832, 1358954496, 4076863488, 12230590464, 36691771392, 110075314176, 330225942528, 990677827584, 2972033482752, 8916100448256, 26748301344768, 80244904034304, 240734712102912, 722204136308736, 2166612408926208, 6499837226778624, 19499511680335872, 58498535041007616, 175495605123022848, 526486815369068544, 1579460446107205632, 4738381338321616896, 14215144014964850688, 42645432044894552064, 127936296134683656192, 383808888404050968576, 1151426665212152905728, 3454279995636458717184, 10362839986909376151552, 31088519960728128454656, 93265559882184385363968, 279796679646553156091904, 33554432, 100663296, 301989888, 905969664, 2717908992, 8153726976, 24461180928, 73383542784, 220150628352, 660451885056, 1981355655168, 5944066965504, 17832200896512, 53496602689536, 160489808068608, 481469424205824, 1444408272617472, 4333224817852416, 12999674453557248, 38999023360671744, 116997070082015232, 350991210246045696, 1052973630738137088, 3158920892214411264, 9476762676643233792, 28430288029929701376, 85290864089789104128, 255872592269367312384, 767617776808101937152, 2302853330424305811456, 6908559991272917434368, 20725679973818752303104, 62177039921456256909312, 186531119764368770727936, 559593359293106312183808, 67108864, 201326592, 603979776, 1811939328, 5435817984, 16307453952, 48922361856, 146767085568, 440301256704, 1320903770112, 3962711310336, 11888133931008, 35664401793024, 106993205379072, 320979616137216, 962938848411648, 2888816545234944, 8666449635704832, 25999348907114496, 77998046721343488, 233994140164030464, 701982420492091392, 2105947261476274176, 6317841784428822528, 18953525353286467584, 56860576059859402752, 170581728179578208256, 511745184538734624768, 1535235553616203874304, 4605706660848611622912, 13817119982545834868736, 41451359947637504606208, 124354079842912513818624, 373062239528737541455872, 1119186718586212624367616, 134217728, 402653184, 1207959552, 3623878656, 10871635968, 32614907904, 97844723712, 293534171136, 880602513408, 2641807540224, 7925422620672, 23776267862016, 71328803586048, 213986410758144, 641959232274432, 1925877696823296, 5777633090469888, 17332899271409664, 51998697814228992, 155996093442686976, 467988280328060928, 1403964840984182784, 4211894522952548352, 12635683568857645056, 37907050706572935168, 113721152119718805504, 341163456359156416512, 1023490369077469249536, 3070471107232407748608, 9211413321697223245824, 27634239965091669737472, 82902719895275009212416, 248708159685825027637248, 746124479057475082911744, 2238373437172425248735232, 268435456, 805306368, 2415919104, 7247757312, 21743271936, 65229815808, 195689447424, 587068342272, 1761205026816, 5283615080448, 15850845241344, 47552535724032, 142657607172096, 427972821516288, 1283918464548864, 3851755393646592, 11555266180939776, 34665798542819328, 103997395628457984, 311992186885373952, 935976560656121856, 2807929681968365568, 8423789045905096704, 25271367137715290112, 75814101413145870336, 227442304239437611008, 682326912718312833024, 2046980738154938499072, 6140942214464815497216, 18422826643394446491648, 55268479930183339474944, 165805439790550018424832, 497416319371650055274496, 1492248958114950165823488, 4476746874344850497470464, 536870912, 1610612736, 4831838208, 14495514624, 43486543872, 130459631616, 391378894848, 1174136684544, 3522410053632, 10567230160896, 31701690482688, 95105071448064, 285315214344192, 855945643032576, 2567836929097728, 7703510787293184, 23110532361879552, 69331597085638656, 207994791256915968, 623984373770747904, 1871953121312243712, 5615859363936731136, 16847578091810193408, 50542734275430580224, 151628202826291740672, 454884608478875222016, 1364653825436625666048, 4093961476309876998144, 12281884428929630994432, 36845653286788892983296, 110536959860366678949888, 331610879581100036849664, 994832638743300110548992, 2984497916229900331646976, 8953493748689700994940928, 1073741824, 3221225472, 9663676416, 28991029248, 86973087744, 260919263232, 782757789696, 2348273369088, 7044820107264, 21134460321792, 63403380965376, 190210142896128, 570630428688384, 1711891286065152, 5135673858195456, 15407021574586368, 46221064723759104, 138663194171277312, 415989582513831936, 1247968747541495808, 3743906242624487424, 11231718727873462272, 33695156183620386816, 101085468550861160448, 303256405652583481344, 909769216957750444032, 2729307650873251332096, 8187922952619753996288, 24563768857859261988864, 73691306573577785966592, 221073919720733357899776, 663221759162200073699328, 1989665277486600221097984, 5968995832459800663293952, 17906987497379401989881856, 2147483648, 6442450944, 19327352832, 57982058496, 173946175488, 521838526464, 1565515579392, 4696546738176, 14089640214528, 42268920643584, 126806761930752, 380420285792256, 1141260857376768, 3423782572130304, 10271347716390912, 30814043149172736, 92442129447518208, 277326388342554624, 831979165027663872, 2495937495082991616, 7487812485248974848, 22463437455746924544, 67390312367240773632, 202170937101722320896, 606512811305166962688, 1819538433915500888064, 5458615301746502664192, 16375845905239507992576, 49127537715718523977728, 147382613147155571933184, 442147839441466715799552, 1326443518324400147398656, 3979330554973200442195968, 11937991664919601326587904, 35813974994758803979763712, 4294967296, 12884901888, 38654705664, 115964116992, 347892350976, 1043677052928, 3131031158784, 9393093476352, 28179280429056, 84537841287168, 253613523861504, 760840571584512, 2282521714753536, 6847565144260608, 20542695432781824, 61628086298345472, 184884258895036416, 554652776685109248, 1663958330055327744, 4991874990165983232, 14975624970497949696, 44926874911493849088, 134780624734481547264, 404341874203444641792, 1213025622610333925376, 3639076867831001776128, 10917230603493005328384, 32751691810479015985152, 98255075431437047955456, 294765226294311143866368, 884295678882933431599104, 2652887036648800294797312, 7958661109946400884391936, 23875983329839202653175808, 71627949989517607959527424, 8589934592, 25769803776, 77309411328, 231928233984, 695784701952, 2087354105856, 6262062317568, 18786186952704, 56358560858112, 169075682574336, 507227047723008, 1521681143169024, 4565043429507072, 13695130288521216, 41085390865563648, 123256172596690944, 369768517790072832, 1109305553370218496, 3327916660110655488, 9983749980331966464, 29951249940995899392, 89853749822987698176, 269561249468963094528, 808683748406889283584, 2426051245220667850752, 7278153735662003552256, 21834461206986010656768, 65503383620958031970304, 196510150862874095910912, 589530452588622287732736, 1768591357765866863198208, 5305774073297600589594624, 15917322219892801768783872, 47751966659678405306351616, 143255899979035215919054848, 17179869184, 51539607552, 154618822656, 463856467968, 1391569403904, 4174708211712, 12524124635136, 37572373905408, 112717121716224, 338151365148672, 1014454095446016, 3043362286338048, 9130086859014144, 27390260577042432, 82170781731127296, 246512345193381888, 739537035580145664, 2218611106740436992, 6655833320221310976, 19967499960663932928, 59902499881991798784, 179707499645975396352, 539122498937926189056, 1617367496813778567168, 4852102490441335701504, 14556307471324007104512, 43668922413972021313536, 131006767241916063940608, 393020301725748191821824, 1179060905177244575465472, 3537182715531733726396416, 10611548146595201179189248, 31834644439785603537567744, 95503933319356810612703232, 286511799958070431838109696]\r\nfor i in arr:\r\n\tif l <= i <= r:\r\n\t\tanswer += 1\r\nprint(answer)",
"l, r = input().split()\r\nl = (int(l))\r\nr = (int(r))\r\na = set()\r\nsc = 0\r\nfor i in range (0, 31):\r\n cur = 2**i\r\n for j in range (0, 21):\r\n if cur > r:\r\n break\r\n if cur >= l:\r\n a.add(cur)\r\n sc+=1\r\n cur *= 3\r\nprint(len(a))\r\n ",
"import math\r\n\r\nnumbers = []\r\n\r\nfor i in range(0,32):\r\n\tfor j in range(0,21):\r\n\r\n\t\tvar = (2**i)*(3**j)\r\n\t\tif var > (2*(10**9)):\r\n\t\t\tbreak\r\n\t\telse:\r\n\t\t\tnumbers.append(var)\r\n\r\nnumbers.sort()\r\nans = 0\r\narr = [int(x) for x in input().split()]\r\nl = arr[0]\r\nr = arr[1]\r\nfor i in range(0,len(numbers)):\r\n\tif numbers[i]>=l and numbers[i]<=r:\r\n\t\tans = ans + 1\r\nprint(ans)",
"l,r =map(int,input().split())\r\nans=0\r\nfor i in range(0,35):\r\n\tfor j in range(0,25):\r\n\t\tk=(2**i)*(3**j)\r\n\t\tif(k>r):\r\n\t\t\tbreak;\r\n\t\tif(l<=k and k<=r):\r\n\t\t\tans=ans+1\r\nprint(ans)",
"def solve(l, r):\n s = set()\n i = 0\n while True:\n a = 2**i\n i += 1\n if a > r: break\n j = 0\n while True:\n x = a * 3**j\n j += 1\n if x > r: break\n elif l <= x:\n s.add(x)\n return len(s)\n\ndef test():\n assert solve(1, 10) == 7\n assert solve(100, 200) == 5\n assert solve(1, 2000000000) == 326\n\nif __name__ == '__main__':\n l, r = [int(x) for x in input().split()]\n print(solve(l, r))\n # test()\n",
"import sys\n\narray = tuple(map(int,input().split()))\nl=array[0]\nr=array[1]\n\na=[]\nb=[]\nc=1\nwhile c<=2000000000:\n\ta.append(c)\n\tc*=2\nc=1\nwhile c<=2000000000:\n\tb.append(c)\n\tc*=3\np=0\nfor i in a:\n\tfor j in b:\n\t\t#print(i*j)\n\t\tif i*j<=r and i*j>=l:\n\t\t\tp+=1\nprint(p)",
"cnt = 0\r\nl,r = map(int,input().split())\r\na = 1\r\nfor i in range(0, 32):\r\n\tb = a\r\n\tfor j in range(0, 32):\r\n\t\tif l <= b and b <= r:\r\n\t\t\tcnt = cnt + 1\r\n\t\tb = b * 3\r\n\ta = a * 2\r\nprint(cnt)",
"l,r=[int(i) for i in input().split(' ')]\r\nans=0\r\nfor i in range(40):\r\n\tfor j in range(30):\r\n\t\ta=2**i*3**j\r\n\t\tif (a >= l and a<= r):\r\n\t\t\tans+=1\r\nprint(ans)",
"ans = 0\nl, r = map(int, input().split())\nfor i in range(100):\n for j in range(100):\n t = 2 ** i * 3 ** j\n if l <= t <= r: ans -= -1\nprint(ans)\n \t \t\t \t\t\t \t \t \t",
"l,r=map(int,input().split())\r\ncounter=0\r\nfor i in range(50):\r\n for j in range(50):\r\n if l<=(2**i)*(3**j)<=r:\r\n counter+=1\r\nprint(counter)",
"l, r = map(int, input().split());\r\ndef f(a):\r\n ans = 1;\r\n for q in range(2, a + 1):\r\n ans *= q;\r\n return ans;\r\ndef much(l):\r\n a = 1;\r\n cnt = -1;\r\n while a <= l:\r\n a = a * 3;\r\n cnt = cnt + 1;\r\n k3 = cnt;\r\n a1 = 1;\r\n cnt = -1;\r\n while a1 <= l:\r\n a1 = a1 * 2;\r\n cnt = cnt + 1;\r\n k2 = cnt; # (k3 + 2) \r\n ans = (k3 + 1) * (k3 + 2) // 2;\r\n #print(k2);\r\n for q in range(k3 + 1, k2 + 1):\r\n x = 2 ** q;\r\n while 1:\r\n ans += 1;\r\n x = x * 3 // 2;\r\n if x > l:\r\n break;\r\n return ans;\r\nk = much(r) - much(l - 1);\r\nprint(k);",
"def two_three(l, r):\r\n i, j = 1, 1\r\n s = list()\r\n s.append(i)\r\n t = list()\r\n t.append(j)\r\n while i <= 2 * (10 ** 9):\r\n i = 2 * i\r\n s.append(i)\r\n while j <= 2 * (10 ** 9):\r\n j = 3 * j\r\n t.append(j)\r\n m = list()\r\n for y in range(len(s)):\r\n for z in range(len(t)):\r\n m.append(s[y] * t[z])\r\n count = 0\r\n for x in range(0, len(m) - 1):\r\n if l <= m[x] <= r:\r\n count += 1\r\n return count\r\n\r\n\r\nn, m = [int(i) for i in input().split()]\r\nprint(two_three(n, m))\r\n",
"#import time\r\n\r\nl, r = map(int, input().split())\r\n\r\n\r\nchecked = set()\r\n\r\ndef howNums(num):\r\n if num in checked: return 0\r\n \r\n checked.add(num)\r\n c = 0\r\n \r\n subnum1 = num * 2\r\n subnum2 = num * 3\r\n \r\n if(subnum1 <= r and (subnum1 not in checked)): \r\n if(subnum1 >= l): c+=1\r\n c+=howNums(subnum1)\r\n #if(subnum1 >= l): print(subnum1)\r\n if(subnum2 <= r and (subnum2 not in checked)): \r\n if(subnum2 >= l): c+=1\r\n c+=howNums(subnum2)\r\n #if(subnum2 >= l): print(subnum2)\r\n \r\n if((subnum1 > r) and (subnum2 > r)): \r\n return 0\r\n \r\n return c\r\n\r\n\r\n\r\n\r\n#start_time = time.time()\r\ncount = howNums(1)\r\nif(l is 1): count+=1\r\n\r\n#print(\"ans:\" + str(count))\r\nprint(count)\r\n#print(str(time.time() - start_time))",
"a,b=input().split()\r\na=(int)(a)\r\nb=(int)(b)\r\nc=[1,2,3,4,6,8,9,12,16,18,24,27,32,36,48,54,64,72,81,96,108,128,144,162,192,216,243,256,288,324,384,432,486,512,576,648,729,768,864,972,1024,1152,1296,1458,1536,1728,1944,2048,2187,2304,2592,2916,3072,3456,3888,4096,4374,4608,5184,5832,6144,6561,6912,7776,8192,8748,9216,10368,11664,12288,13122,13824,15552,16384,17496,18432,19683,20736,23328,24576,26244,27648,31104,32768,34992,36864,39366,41472,46656,49152,52488,55296,59049,62208,65536,69984,73728,78732,82944,93312,98304,104976,110592,118098,124416,131072,139968,147456,157464,165888,177147,186624,196608,209952,221184,236196,248832,262144,279936,294912,314928,331776,354294,373248,393216,419904,442368,472392,497664,524288,531441,559872,589824,629856,663552,708588,746496,786432,839808,884736,944784,995328,1048576,1062882,1119744,1179648,1259712,1327104,1417176,1492992,1572864,1594323,1679616,1769472,1889568,1990656,2097152,2125764,2239488,2359296,2519424,2654208,2834352,2985984,3145728,3188646,3359232,3538944,3779136,3981312,4194304,4251528,4478976,4718592,4782969,5038848,5308416,5668704,5971968,6291456,6377292,6718464,7077888,7558272,7962624,8388608,8503056,8957952,9437184,9565938,10077696,10616832,11337408,11943936,12582912,12754584,13436928,14155776,14348907,15116544,15925248,16777216,17006112,17915904,18874368,19131876,20155392,21233664,22674816,23887872,25165824,25509168,26873856,28311552,28697814,30233088,31850496,33554432,34012224,35831808,37748736,38263752,40310784,42467328,43046721,45349632,47775744,50331648,51018336,53747712,56623104,57395628,60466176,63700992,67108864,68024448,71663616,75497472,76527504,80621568,84934656,86093442,90699264,95551488,100663296,102036672,107495424,113246208,114791256,120932352,127401984,129140163,134217728,136048896,143327232,150994944,153055008,161243136,169869312,172186884,181398528,191102976,201326592,204073344,214990848,226492416,229582512,241864704,254803968,258280326,268435456,272097792,286654464,301989888,306110016,322486272,339738624,344373768,362797056,382205952,387420489,402653184,408146688,429981696,452984832,459165024,483729408,509607936,516560652,536870912,544195584,573308928,603979776,612220032,644972544,679477248,688747536,725594112,764411904,774840978,805306368,816293376,859963392,905969664,918330048,967458816,1019215872,1033121304,1073741824,1088391168,1146617856,1162261467,1207959552,1224440064,1289945088,1358954496,1377495072,1451188224,1528823808,1549681956,1610612736,1632586752,1719926784,1811939328,1836660096,1934917632,2038431744,2066242608]\r\ni=0\r\nj=0\r\nwhile c[i]<a:\r\n\ti=i+1\r\nwhile c[j]<=b:\r\n\tj=j+1\r\nprint (j-i)"
] | {"inputs": ["1 10", "100 200", "1 2000000000", "1088391168 1934917632", "1088391167 1934917632", "1088391169 1934917632", "1088391168 1934917631", "1088391168 1934917633", "4 134217728", "209952 43046722", "25165825 43046719", "5183 25165825", "388645 455910", "472069 972050", "1 1", "2 2", "12 1999999931", "1999999999 1999999999", "2000000000 2000000000", "1934917632 1934917632", "1836660096 1836660096", "1811939328 1811939328", "1719926784 1719926784", "1632586752 1632586752", "1610612736 1610612736", "1207959552 1207959552", "129140163 129140163", "12345 54321", "1889569 25165826", "73 7077888", "7077888 45349631", "6144 7077886", "3779135 4194302", "214 161243134", "214 18874369", "28 863", "1417174 172186886", "27 102036671", "147458 102036672", "33554431 102036671", "1572863 33554433", "33554434 181398528", "373247 17915905", "4251526 68024450", "553599 555493", "69739 671621", "618583 755045", "838469 943236", "509607936 1836660096", "509607935 1836660096", "509607937 1836660096", "509607936 1836660095", "509607936 1836660097"], "outputs": ["7", "5", "326", "17", "17", "16", "16", "17", "250", "112", "13", "153", "3", "14", "1", "1", "319", "0", "0", "1", "1", "1", "1", "1", "1", "1", "1", "21", "56", "165", "43", "122", "2", "232", "180", "26", "112", "234", "138", "28", "68", "43", "81", "65", "0", "40", "4", "2", "38", "38", "37", "37", "38"]} | UNKNOWN | PYTHON3 | CODEFORCES | 169 | |
2ed76b685dc12befd8dabe6097fb961b | Sheldon and Ice Pieces | Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number *t*. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry".
Sheldon favourite number is *t*. He wants to have as many instances of *t* as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.
The first line contains integer *t* (1<=≤<=*t*<=≤<=10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.
Print the required number of instances.
Sample Input
42
23454
169
12118999
Sample Output
2
1
| [
"# https://codeforces.com/problemset/problem/328/B\n\nfrom collections import Counter\n\nt = Counter(input().replace('6', '9').replace('2', '5'))\ndigits = Counter(input().replace('6', '9').replace('2', '5'))\nprint(min(digits[d] // cnt for d, cnt in t.items()))",
"import sys\n\n\nt = int(sys.stdin.readline().strip())\ncubes = [int(c) for c in list(sys.stdin.readline().strip())]\n\n\ndef flip(d):\n if d == 6:\n return 9\n elif d == 9:\n return 6\n elif d == 2:\n return 5\n elif d == 5:\n return 2\n\ndef build(t, cubes):\n for d in str(t):\n d = int(d)\n df = flip(d)\n\n if d in cubes:\n cubes.remove(d)\n elif df in cubes:\n cubes.remove(df)\n else:\n return False, cubes\n\n return True, cubes\n\n\ni = 0\n\nwhile True:\n ok, cubes = build(t, cubes)\n\n if ok:\n i += 1\n else:\n break\n\nprint(i)\n",
"def solve():\r\n # read the favorite number\r\n fav = input().strip()\r\n # read the sequence\r\n seq = input().strip()\r\n # find the number of occurrences of each digit in the sequence\r\n occurrences = [0] * 10\r\n for d in seq:\r\n occurrences[int(d)] += 1\r\n # find the number of occurrences of each digit in the favorite number\r\n fav_occurrences = [0] * 10\r\n for d in fav:\r\n fav_occurrences[int(d)] += 1\r\n\r\n # since 6-9 and 2-5 can be used interchangeably we will move the occorencies of the bigger number into the small number\r\n fav_occurrences[6] += fav_occurrences[9]\r\n fav_occurrences[9] = 0\r\n\r\n fav_occurrences[2] += fav_occurrences[5]\r\n fav_occurrences[5] = 0\r\n\r\n occurrences[6] += occurrences[9]\r\n occurrences[9] = 0\r\n\r\n occurrences[2] += occurrences[5]\r\n occurrences[5] = 0\r\n\r\n # use the number of times each digit occurs in the favourite number\r\n # to find the minimum number of times the favourite number can be formed\r\n min_occurrences = float(\"inf\")\r\n for n in range(10):\r\n # do we have this number in the favorite number\r\n if fav_occurrences[n] > 0:\r\n min_occurrences = min(min_occurrences, occurrences[n] // fav_occurrences[n])\r\n\r\n # print the answer\r\n print(min_occurrences)\r\n\r\n\r\nsolve()\r\n",
"t = input().replace('5', '2').replace('9', '6')\r\ns = input().replace('5', '2').replace('9', '6')\r\n\r\nres = 10 ** 100\r\n\r\nfor i in t:\r\n res = min(res, s.count(i) // t.count(i))\r\nprint(res)",
"t = map(int, input().strip())\ns = map(int, input().strip())\n\ndigits1 = [0] * 10 # makes a list of size 10 filled with zeros.\ndigits2 = [0] * 10\n\nfor i in t:\n digits1[i] += 1\ndigits1[2] += digits1[5]\ndigits1[6] += digits1[9]\ndigits1[5] = digits1[9] = 0\n\nfor i in s:\n digits2[i] += 1\ndigits2[2] += digits2[5]\ndigits2[6] += digits2[9]\ndigits2[5] = digits2[9] = 0\n\nprint(min(map(lambda x : digits2[x] // digits1[x] if digits1[x] != 0 else 999999, range(10))))",
"t=input()\ns=input()\ns=list(s)\n\nn=len(s)\n\ncopies=0\nx=t.count('6')+t.count('9')\ny=s.count('6')+s.count('9')\na=t.count('2')+t.count('5')\nb=s.count('2')+s.count('5')\nif(x==0 and a==0):\n copies=100\nelif(x==0):\n copies=b//a\nelif(a==0):\n copies=y//x\nelse:\n copies=min(y//x,b//a)\n\nfor j in range(0,10):\n i=str(j)\n if(i=='6' or i=='9' or i=='2' or i=='5'):\n continue\n x=t.count(i)\n if(x==0):\n continue\n y=s.count(i)\n copies=min(copies,y//x)\n\nprint(copies)\n",
"def c(a, b):\r\n\ta = a.replace('6', '9')\r\n\ta = a.replace('2', '5')\r\n\tb = b.replace('6', '9')\r\n\tb = b.replace('2', '5')\r\n\tn = 10000\r\n\tfor i in '01345789':\r\n\t\tt = a.count(i)\r\n\t\tif t != 0:\r\n\t\t\tn = min(n, b.count(i)//t)\r\n\treturn n\r\na = input()\r\nb = input()\r\nprint(c(a, b))",
"# LUOGU_RID: 101540472\ns = input().replace('5', '2').replace('9', '6')\r\nt = input().replace('5', '2').replace('9', '6')\r\nprint(min(t.count(c) // s.count(c) for c in s))\r\n",
"def re(s):\r\n t = \"\"\r\n for i in s:\r\n if(i == \"2\" or i == \"5\"):\r\n t += \"a\"\r\n elif(i == \"6\" or i == \"9\"):\r\n t += \"b\"\r\n else:\r\n t += i\r\n return t\r\nfrom collections import defaultdict as dd\r\ndef main():\r\n t = re(input())\r\n s = re(input())\r\n req = dd(int)\r\n hv = dd(int)\r\n ans = 10**9\r\n for i in t:\r\n req[i] += 1\r\n for j in s:\r\n hv[j] += 1\r\n for i in t:\r\n ans = min(ans, hv[i] // req[i])\r\n print(ans)\r\nmain()",
"def check(d, st):\r\n for i in range(len(st)):\r\n x = st[i]\r\n if x == '9':\r\n x = '6'\r\n elif x == '5':\r\n x = '2'\r\n\r\n if x in d:\r\n d[x] += 1\r\n else:\r\n d[x] = 1\r\n\r\nt = input()\r\ns = input()\r\nds = dict()\r\ndt = dict()\r\n\r\ncheck(ds, s)\r\ncheck(dt, t)\r\n\r\nnum = len(s)\r\nfor key in dt:\r\n if key not in ds or dt[key] > ds[key]:\r\n num = 0\r\n break\r\n else:\r\n num = min(num, ds[key] // dt[key])\r\nprint(num)",
"from collections import defaultdict\r\nag=defaultdict(int)\r\nfor i in input():\r\n if i=='9':ag['6']+=1\r\n elif i=='5':ag['2']+=1\r\n else:ag[i]+=1\r\ng=defaultdict(int)\r\nfor i in input():\r\n if i=='9':g['6']+=1\r\n elif i=='5':g['2']+=1\r\n else:g[i]+=1\r\nans=999999999999999999\r\nfor i in ag:\r\n ans=min(ans,g[i]//ag[i])\r\nprint(ans)",
"t=input()\r\ns=input()\r\ns=s.replace('2','5')\r\ns=s.replace('6','9')\r\nt=t.replace('2','5')\r\nt=t.replace('6','9')\r\n \r\nans=100000\r\nfor i in t:\r\n ans=min(ans,(s.count(i)//t.count(i)))\r\n \r\nprint(ans)\r\n \r\n",
"'''\r\nLittle Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect \"Digital Mimicry\".\r\n\r\nSheldon favourite number is t. He wants to have as many instances of t as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.\r\n\r\nInput\r\nThe first line contains integer t (1 ≤ t ≤ 10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.\r\n\r\nOutput\r\nPrint the required number of instances.\r\n'''\r\n\r\nt=list(input())\r\ns=list(input())\r\ni=0\r\nfor x in t:\r\n if int(t[i]) == 5 :\r\n t[i]='2'\r\n if int(t[i]) == 9 :\r\n t[i]='6'\r\n i+=1\r\n\r\ni=0 \r\nfor x in s:\r\n if s[i] == '5' :\r\n s[i]='2'\r\n if s[i] == '9' :\r\n s[i]='6'\r\n i+=1\r\n\r\nf=0\r\n\r\nfor i in range(0,int(len(s)/len(t))):\r\n l=len(s)\r\n for x in t:\r\n if x in s:\r\n s.remove(x)\r\n if len(s)==l-len(t):\r\n f+=1\r\n else:\r\n break\r\n \r\nprint(f)\r\n",
"def convert_string(string_list,len_string_list):\r\n change_dict={}\r\n change_dict['9']='6'\r\n change_dict['5']='2'\r\n for i in range(len_string_list):\r\n if string_list[i] in change_dict:\r\n string_list[i]=change_dict[string_list[i]]\r\n #print(string_list)\r\ndef form_frequency_dict(given_list):\r\n freq_dict={}\r\n for i in given_list:\r\n if i in freq_dict:\r\n freq_dict[i]+=1\r\n else:\r\n freq_dict[i]=1\r\n return freq_dict\r\ndef find_max_repititions(required_string_freq_dict,given_string_freq_dict):\r\n max_repititions=201\r\n for key,value in required_string_freq_dict.items():\r\n if key in given_string_freq_dict:\r\n max_repititions_now_possible=given_string_freq_dict[key]//required_string_freq_dict[key]\r\n if(max_repititions_now_possible<max_repititions):\r\n max_repititions=max_repititions_now_possible\r\n if max_repititions==201:\r\n max_repititions=0\r\n return max_repititions\r\nimport sys\r\ninputlist=sys.stdin.readlines()\r\nrequired_string=list(inputlist[0].strip())\r\ngiven_string=list(inputlist[1].strip())\r\n#print(required_string,given_string)\r\nlen_required_string=len(required_string)\r\nlen_given_string=len(given_string)\r\nconvert_string(required_string,len_required_string)\r\nconvert_string(given_string,len_given_string)\r\n#print(required_string,given_string)\r\nrequired_string_freq_dict=form_frequency_dict(required_string)\r\ngiven_string_freq_dict=form_frequency_dict(given_string)\r\nmax_repititions=find_max_repititions(required_string_freq_dict,given_string_freq_dict)\r\nprint(max_repititions)",
"import sys\r\ndef main():\r\n s1 = input().strip()\r\n s2 = input().strip()\r\n cnt1 = [0] * 10\r\n cnt2 = [0] * 10\r\n for c in s1:\r\n if c == '9':\r\n c = '6'\r\n elif c == '5':\r\n c = '2'\r\n cnt1[int(c)] += 1\r\n for c in s2:\r\n if c == '9':\r\n c = '6'\r\n elif c == '5':\r\n c = '2'\r\n cnt2[int(c)] += 1\r\n ans = sys.maxsize\r\n for i in range(10):\r\n if cnt1[i] != 0:\r\n ans = min(ans, cnt2[i] // cnt1[i])\r\n print(ans)\r\nif __name__ == \"__main__\":\r\n main()# 1690821452.9949293",
"num = input()\r\nstr = input()\r\nd = dict()\r\nused = dict()\r\nnum = num.replace('5', '2')\r\nstr = str.replace('5', '2')\r\nnum = num.replace('9', '6')\r\nstr = str.replace('9', '6')\r\nres = 10 ** 1000\r\nfor i in num:\r\n res = min(res, str.count(i) // num.count(i))\r\nprint(res)\r\n ",
"s=input()\r\nt=input()\r\na=[0]*10\r\nb=[0]*10 \r\nfor i in range(len(s)):\r\n if s[i]=='5':\r\n a[2]+=1 \r\n elif s[i]=='9':\r\n a[6]+=1 \r\n else:\r\n a[int(s[i])]+=1\r\nfor i in range(len(t)):\r\n if t[i]=='5':\r\n b[2]+=1 \r\n elif t[i]=='9':\r\n b[6]+=1 \r\n else:\r\n b[int(t[i])]+=1\r\nans=10**9 \r\nfor i in range(10):\r\n if a[i]!=0:\r\n ans=min(ans,b[i]//a[i])\r\nprint(ans) \r\n ",
"t1 = map(int,input().strip())\r\nt2 = map(int,input().strip())\r\nar1 = [0] * 10\r\nar2 = [0]*10\r\nfor j in t1:\r\n ar1[j]+=1\r\nfor j in t2:\r\n ar2[j]+=1\r\nar1[2]+=ar1[5]\r\nar1[6]+=ar1[9]\r\nar1[5]=ar1[9]=0\r\nar2[2]+=ar2[5]\r\nar2[6]+=ar2[9]\r\nar2[5]=ar2[9]=0\r\nprint(int(min(map(lambda x:ar2[x]/ar1[x] if ar1[x]!=0 else 100500 ,range(10)))))",
"from collections import defaultdict\r\nfrom math import inf\r\na=input()\r\nb=input()\r\na1=defaultdict(int)\r\nb1=defaultdict(int)\r\nfor i in a:\r\n a1[i]+=1\r\nfor i in b:\r\n b1[i]+=1\r\n\r\na1['6']=a1['6']+a1['9']\r\na1['9']=0\r\nb1['6']=b1['6']+b1['9']\r\nb1['9']=0\r\na1['2']=a1['2']+a1['5']\r\na1['5']=0\r\nb1['2']=b1['2']+b1['5']\r\nb1['5']=0\r\n\r\nm=inf\r\n# print(a1,b1)\r\nfor i in a1:\r\n if a1[i]:\r\n if b1[i]==0:\r\n # print(i)\r\n m=0\r\n break\r\n else:\r\n # print(i,a1[i],b1[i])\r\n m=min(m,b1[i]//a1[i])\r\nprint(m)\r\n",
"import heapq \r\nfrom collections import defaultdict \r\nimport math \r\nimport collections\r\n\r\n\r\n\r\nmod=10**9+7\r\nalp='#abcdefghijklmnopqrstuvwxyz'\r\ncap='ABCDEFGHIJKLMNOPQRSTUVWXYZ'\r\ndigit='1234567890'\r\n\r\n\r\n\r\n#math.facorial(n)------>gives the factorial \r\n\r\n\r\n\r\n\r\n\r\n\r\nfor _ in range(1):\r\n \r\n t =(input())\r\n #n , m =map(int,input().split())\r\n #l=list(map(int,input().split()))\r\n s=input()\r\n d1=defaultdict(int)\r\n d2=defaultdict(int)\r\n for i in s:\r\n if i=='2':\r\n i='5' \r\n if i=='6':\r\n i='9' \r\n d1[i]+=1 \r\n for i in t:\r\n if i=='2':\r\n i='5' \r\n if i=='6':\r\n i='9' \r\n d2[i]+=1 \r\n mn =10**9\r\n for k in d2:\r\n z=d1[k]//d2[k]\r\n mn =min(z,mn)\r\n print(mn)\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import Counter\r\n\r\nt = input()\r\ns = input()\r\nsc = Counter(s)\r\ntc = Counter(t)\r\n\r\na = sc['6']\r\nb = sc['9']\r\nsc['6']=a+b\r\nsc['9']=a+b\r\n\r\na = sc['2']\r\nb = sc['5']\r\nsc['2']=a+b\r\nsc['5']=a+b\r\n\r\nans = float('inf')\r\ntc['2']+=tc['5']\r\ntc['6']+=tc['9']\r\n\r\nfor c in '01234678':\r\n if tc[c]>0:\r\n ans = min(ans, sc[c]//tc[c])\r\nprint(ans)",
"t=[*map(int,input())]\r\ns=[*map(int,input())]\r\nd={0:0,1:0,2:0,3:0,4:0,6:0,7:0,8:0}\r\ndi={0:0,1:0,2:0,3:0,4:0,6:0,7:0,8:0}\r\nfor i,x in enumerate(t):\r\n if x==6 or x==9:d[6]+=1\r\n elif x==2 or x==5:d[2]+=1\r\n else:d[x]+=1\r\nfor i,x in enumerate(s):\r\n if x==6 or x==9:di[6]+=1\r\n elif x==2 or x==5:di[2]+=1\r\n else:di[x]+=1\r\nres=10000000000000000000000000\r\nfor i,x in enumerate(d):\r\n if d[x]>0:\r\n res=min(res,di[x]//d[x])\r\nprint(res)",
"number_need = input()\r\nnumbers = input()\r\ndict_numbers = {'0':0, '1':0, '2':0, '3':0, '4':0, '5':0, '6':0, '7':0, '8':0, '9':0}\r\ndict_numbers_need = {'0':0, '1':0, '2':0, '3':0, '4':0, '5':0, '6':0, '7':0, '8':0, '9':0}\r\n\r\nfor i in number_need:\r\n dict_numbers_need[i] += 1 \r\n\r\nfor i in numbers:\r\n dict_numbers[i] += 1\r\n\r\ntotal = list(dict_numbers.values())\r\ntotal[2] += total[5]\r\ntotal[6] += total[9]\r\ndel total[5]\r\ndel total[8]\r\ntotal_need = list(dict_numbers_need.values())\r\ntotal_need[2] += total_need[5]\r\ntotal_need[6] += total_need[9]\r\ndel total_need[5]\r\ndel total_need[8]\r\nmaximum = 201\r\n\r\nfor i in range(8):\r\n if total_need[i] != 0:\r\n maximum = min(total[i] // total_need[i], maximum)\r\n \r\nprint(maximum)\r\n\r\n",
"favornumb={'0':0, '1':0, '2':0,\r\n '3':0, '4':0, '6':0,\r\n '7':0, '8':0}\r\nmass={'0':0, '1':0, '2':0,\r\n '3':0, '4':0, '6':0,\r\n '7':0, '8':0}\r\nfor i in input():\r\n if i=='2' or i=='5': favornumb['2']+=1\r\n elif i=='6' or i=='9': favornumb['6']+=1\r\n else: favornumb[i]+=1\r\nfor i in input():\r\n if i=='2' or i=='5': mass['2']+=1\r\n elif i=='6' or i=='9': mass['6']+=1\r\n else: mass[i]+=1\r\nans=200\r\nfor i in ['0', '1', '2', '3', '4', '6', '7', '8']:\r\n if favornumb[i]==0: continue\r\n else:\r\n pretend=int(mass[i]/favornumb[i])\r\n if pretend<=ans: ans=pretend\r\nprint(ans)",
"import sys\r\ninput = sys.stdin.readline\r\nfrom collections import Counter\r\n\r\nt = Counter(input()[:-1].replace('2', '5').replace('6','9'))\r\ns = Counter(input()[:-1].replace('2', '5').replace('6','9'))\r\na = 10**9\r\nfor i in t:\r\n a = min(a, s[i]//t[i])\r\nprint(a)\r\n",
"t = int(input())\r\ns = input()\r\nq = {'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '6': 0, '7': 0, '8': 0}\r\nfor d in s:\r\n if d == '5':\r\n q['2'] += 1\r\n elif d == '9':\r\n q['6'] += 1\r\n else:\r\n q[d] += 1\r\np = {'0': 0, '1': 0, '2': 0, '3': 0, '4': 0, '6': 0, '7': 0, '8': 0}\r\nwhile t != 0:\r\n d = str(t % 10)\r\n if d == '5':\r\n p['2'] += 1\r\n elif d == '9':\r\n p['6'] += 1\r\n else:\r\n p[d] += 1\r\n t //= 10\r\nc = len(s)\r\nfor d in p.keys():\r\n if p[d] != 0:\r\n c = min(c, q[d] // p[d])\r\nprint(c)\r\n",
"t=input()\r\nice=input()\r\nini={}\r\nout={}\r\nfor i in t:\r\n if i=='2' or i=='5':\r\n ini['2']=ini.get('2',0)+1\r\n elif i=='6' or i=='9':\r\n ini['6']=ini.get('6',0)+1\r\n else:\r\n ini[i]=ini.get(i,0)+1\r\nfor i in ice:\r\n if i=='2' or i=='5':\r\n out['2']=out.get('2',0)+1\r\n elif i=='6' or i=='9':\r\n out['6']=out.get('6',0)+1\r\n else:\r\n out[i]=out.get(i,0)+1\r\nmini=1289238479238\r\nfor i in ini:\r\n if out.get(i,0)!=0:\r\n mini=min(out[i]//ini[i],mini)\r\nprint(mini)\r\n \r\n",
"t,q,w,o=input(),{'0':0,'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,'7':0,'8':0,'9':0},0,1\r\nfor i in input():q[i]+=1 \r\nwhile o:\r\n for i in t:\r\n if i==\"2\":\r\n if q[i]:q[i]-=1\r\n elif q[\"5\"]:q[\"5\"]-=1\r\n else:o=0\r\n elif i==\"5\":\r\n if q[i]:q[i]-=1\r\n elif q[\"2\"]:q[\"2\"]-=1\r\n else:o=0\r\n elif i==\"6\":\r\n if q[i]:q[i]-=1\r\n elif q[\"9\"]:q[\"9\"]-=1\r\n else:o=0\r\n elif i==\"9\":\r\n if q[i]:q[i]-=1\r\n elif q[\"6\"]:q[\"6\"]-=1\r\n else:o=0\r\n elif q[i]:q[i]-=1\r\n else:o=0\r\n w+=o\r\nprint(w)",
"# init\r\nt, a = input(), input()\r\n\r\nt, a = t.replace('5','2'), a.replace('5','2')\r\nt, a = t.replace('9','6'), a.replace('9','6')\r\n\r\nac = dict().fromkeys([i for i in a], 0)\r\nfor i in a: ac[i] += 1\r\n\r\nprint(min([ac[i]//t.count(i) for i in t]))\r\n\r\n",
"import sys\n\ndef solve():\n first = list(input())\n second = list(input())\n first = map(int, first)\n second = map(int, second)\n count = [0] * 10\n for i in first:\n count[m(i)]+=1\n total = [0] * 10\n for i in second:\n total[m(i)]+=1\n res = 0\n while True:\n for i in range(10):\n total[i] -= count[i]\n for i in range(10):\n if total[i] < 0:\n return res\n res+=1\n return res\n\ndef m(c):\n if c == 9: return 6\n if c == 5: return 2\n return c\n\nif sys.hexversion == 50594544 : sys.stdin = open(\"test.txt\")\nprint(solve())",
"a = input()\r\nb = input()\r\n\r\nd = {}\r\nfor e in b:\r\n if e == '9':\r\n e = '6'\r\n if e == '5':\r\n e = '2'\r\n if e in d:\r\n d[e] = d[e] + 1\r\n else:\r\n d[e] = 1\r\n\r\nn = {}\r\nfor e in a:\r\n if e == '9':\r\n e = '6'\r\n if e == '5':\r\n e = '2'\r\n if e in n:\r\n n[e] += 1\r\n else:\r\n n[e] = 1\r\nresult = 10000000\r\nfor e in n:\r\n if e not in d:\r\n result = 0\r\n break\r\n else:\r\n temp_result = int(d[e] / n[e])\r\n if temp_result < result:\r\n result = temp_result\r\n \r\nprint(result)\r\n",
"# import numpy as np\n\ndef solution():\n number = input()\n book = {}\n book_of_repeats = {}\n for i in number:\n intermidiate = i\n if intermidiate == \"5\":\n intermidiate = \"2\"\n elif intermidiate == \"9\":\n intermidiate = \"6\"\n book_of_repeats[intermidiate] = 0\n if intermidiate in book:\n book[intermidiate] += 1\n else:\n book[intermidiate] = 1\n cubs = input()\n for i in cubs:\n intermidiate = i\n if intermidiate == \"5\":\n intermidiate = \"2\"\n elif intermidiate == \"9\":\n intermidiate = \"6\"\n if intermidiate in book_of_repeats:\n book_of_repeats[intermidiate] += 1\n result = len(cubs)//len(number)\n for i in book:\n intermidiate = book_of_repeats[i]//book[i]\n if intermidiate < result:\n result = intermidiate\n print(result)\n\n\ndef to_mixed_frac(first, second):\n while True:\n for i in range(2, first + 1):\n if first % i == 0 and second % i == 0:\n first //= i\n second //= i\n break\n else:\n break\n return str(first) + \"/\" + str(second)\n\n\ndef array_to_int(array):\n for i in range(len(array)):\n array[i] = int(array[i])\n return array\n\n\ndef join0(array):\n result = \"\"\n for i in array:\n result += str(i)\n return result\n\n\nsolution()\n# input-output by console\n",
"# LUOGU_RID: 118113823\na=input().replace('6','9').replace('2','5')\r\nmn=137984328768943028\r\nb=input().replace('6','9').replace('2','5')\r\nfor i in a:\r\n\tmn=min(mn,b.count(i)//a.count(i))\r\nprint(mn)",
"t = input()\r\ns = input()\r\nt = t.replace(\"2\", \"5\")\r\ns = s.replace(\"2\", \"5\")\r\nt = t.replace(\"6\", \"9\")\r\ns = s.replace(\"6\", \"9\")\r\nd = [] \r\nfor j in range(10):\r\n i = str(j)\r\n if t.count(i)>0:\r\n d.append(s.count(i)//t.count((i)))\r\nprint(min(d))",
"from collections import defaultdict\r\nimport math\r\nt=input()\r\ns=input()\r\ntomake=defaultdict(lambda:0)\r\nfor i in t:\r\n if(i=='5'):\r\n tomake['2']+=1\r\n elif(i=='9'):\r\n tomake['6']+=1\r\n else:\r\n tomake[i]+=1\r\nfro=defaultdict(lambda:0)\r\nfor i in s:\r\n if(i=='5'):\r\n fro['2']+=1\r\n elif(i=='9'):\r\n fro['6']+=1\r\n else:\r\n fro[i]+=1\r\nans=math.inf\r\nfor i in tomake.keys():\r\n ans=min(ans,fro[i]//tomake[i])\r\nprint(ans)\r\n"
] | {"inputs": ["42\n23454", "169\n12118999", "1\n1", "7\n777", "18\n8118", "33\n33333333", "1780\n8170880870810081711018110878070777078711", "2\n5255", "5\n22252", "9\n666969", "6\n9669969", "25\n52", "2591\n5291", "9697\n979966799976", "5518\n22882121", "533\n355233333332", "2569\n9592525295556669222269569596622566529699", "2559\n5252555622565626", "555\n225225252222255", "266\n565596629695965699", "22\n25552222222255", "99\n966969969696699969", "2591\n95195222396509125191259289255559161259521226176117", "9697\n76694996266995167659667796999669903799299696697971977966766996767667996967697669766777697969669669297966667776967677699767966667666769699790768276666766", "5518\n9827108589585181118358352282425981568508825302611217254345831149357236227288533838583629451589201341265988858338548185158221291825821019993179835186961954871454", "100\n11111000000000001010110010101100011011110101000000000001100110007111110010100000011000010011000011000010010000111101000010000000801000100111000410010100100000001011000000000101100010110001001100010001", "2569\n09629965966225566262579565696595696954525955599926383255926955906666526913925296256629966292216925259225261263256229509529259756291959568892569599592218262625256926619266669279659295979299556965525222", "2559\n52555995269265555695922255525995255259555259252562655622526292929555265526255252526255555296956995596262965522222225655655262255226222259622295225295525265995566255556225522559559295225625559595222652", "555\n25225222525252252255252525552255255522522522225252252525225555225552525255255252252225225255225552522252552252252522555255522225555252255555222225252525522252252255522522225252255522525552525225522552", "266\n26266956652996996666662666992669966292555295699956956255562529696222966929669665256625596629565696225696662556996969659952659665522965269529566599526566699292225569566599656596562966965669929996226599", "22\n35354953025524221524235223225255512262254275553262592555522123522225045753552560550228255220622552552252517202252456715552032250226729355222227262525262552362252277292927052612301558753527582221622055", "9\n99669996666966699999666999999666999699966669696969999696666669696967969666969696696696699669696999669669966696699666669996696666996699999696666696996666666969996996696696969666999999996666699966996696", "2569\n2569256925692569256925692569256925692569", "52\n222222222222222", "11\n1", "5\n2"], "outputs": ["2", "1", "1", "3", "2", "4", "10", "4", "5", "6", "7", "1", "1", "3", "2", "4", "10", "4", "5", "6", "7", "9", "10", "34", "23", "63", "44", "48", "66", "62", "66", "199", "10", "7", "0", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 35 | |
2ed9ecb5353cf9c74167e9d3a4305f94 | Bear and String Distance | Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and .
Limak gives you a nice string *s* and an integer *k*. He challenges you to find any nice string *s*' that . Find any *s*' satisfying the given conditions, or print "-1" if it's impossible to do so.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=106).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
If there is no string satisfying the given conditions then print "-1" (without the quotes).
Otherwise, print any nice string *s*' that .
Sample Input
4 26
bear
2 7
af
3 1000
hey
Sample Output
roardb
-1
| [
"n, k = map(int, input().split())\r\ns = input()\r\nans = ''\r\nfor j in range(n):\r\n a = ord(s[j]) - 97\r\n z = 25 - a\r\n if a > z:\r\n v = min(a, k)\r\n ans += chr(ord(s[j]) - v)\r\n k -= v\r\n else:\r\n v = min(z, k)\r\n ans += chr(ord(s[j]) + v)\r\n k -= v\r\nprint(ans if k == 0 else -1)",
"n,k=map(int,input().split())\r\ns=input()\r\nans=[]\r\nfor i in range(n):\r\n x=min(k,max(ord(s[i])-ord('a'),ord('z')-ord(s[i])))\r\n k-=x\r\n if x+ord(s[i])>ord('z'): ans.append(chr(ord(s[i])-x))\r\n else: ans.append(chr(ord(s[i])+x))\r\nif(k): print(-1)\r\nelse: print(''.join(ans))",
"n, k = map(int, input().split())\r\ns = input()\r\nl = ''\r\nfor letter in s:\r\n if letter < 'n':\r\n k -= (25 - ord(letter) % 97)\r\n if k <= 0:\r\n l += chr(122 + k)\r\n break;\r\n l += 'z'\r\n else:\r\n k -= ord(letter) % 97\r\n if k <= 0:\r\n l += chr(97 - k)\r\n break;\r\n l += 'a'\r\nif k > 0:\r\n print(-1)\r\nelse:\r\n l += s[len(l):]\r\n print(l)\r\n",
"def main():\n n, k = map(int, input().split())\n l = list(input())\n for i, c in enumerate(l):\n x = ord(c)\n if x < 110:\n if k + x < 123:\n l[i] = chr(x + k)\n break\n l[i] = 'z'\n k -= 122 - x\n else:\n if x - k > 96:\n l[i] = chr(x - k)\n break\n l[i] = 'a'\n k -= x - 97\n else:\n print(-1)\n return\n print(''.join(l))\n\n\nif __name__ == '__main__':\n main()\n",
"n,k = map(int,input().split())\r\nword = list(input())\r\nmaxx = ord('z')-ord('a')\r\nfor i in range(len(word)):\r\n forward = 122-ord(word[i])\r\n backward = ord(word[i])-97\r\n \r\n if(forward > backward):\r\n taken = min(k,forward)\r\n k-=taken\r\n word[i] = chr(ord(word[i])+taken)\r\n else:\r\n taken=min(k,backward)\r\n k-=taken\r\n word[i]=chr(ord(word[i])-taken)\r\nif(k):\r\n print(\"-1\")\r\nelse:\r\n print(\"\".join(word))",
"n, k = map(int, input().split())\r\ns = list(input())\r\nfor i in range(n):\r\n if s[i] < 'm':\r\n a = min(k, ord('z') - ord(s[i]))\r\n s[i] = chr(ord(s[i]) + a)\r\n k -= a\r\n else:\r\n a = min(k, ord(s[i]) - ord('a'))\r\n s[i] = chr(ord(s[i]) - a)\r\n k -= a\r\nif k:\r\n print('-1')\r\nelse:\r\n print(''.join(s))\r\n",
"n, k = [int(i) for i in input().split()]\r\ns = input().rstrip()\r\nans = []\r\n\r\nfor x in s:\r\n max_dist = max(ord(x) - ord(\"a\"), ord(\"z\") - ord(x))\r\n if k == 0:\r\n ans += [x]\r\n elif max_dist <= k:\r\n k -= max_dist\r\n ans += [\"a\"] if ord(x) - ord(\"a\") == max_dist else [\"z\"]\r\n else:\r\n for l in \"abcdefghijklmnopqrstuvwxyz\":\r\n if abs(ord(l) - ord(x)) == k:\r\n ans += [l]\r\n k = 0\r\n break\r\n\r\nprint(\"\".join(ans) if k == 0 else -1)",
"n, k = input().split()\r\nn = int(n)\r\nk = int(k)\r\n\r\nnew = str('')\r\n\r\ns = input()\r\ntot = 0\r\n\r\nfor x in s:\r\n gate = 0\r\n dif = ord('z')-ord(x)\r\n if dif < 13:\r\n gate = 1\r\n dif = 25 - dif\r\n tot = tot + dif\r\n if tot < k:\r\n if(gate):\r\n x = 'a'\r\n else:\r\n x = 'z'\r\n elif tot - dif < k:\r\n change = k - (tot - dif)\r\n if(gate):\r\n x = chr(ord(x) - change)\r\n else:\r\n x = chr(ord(x) + change)\r\n new = new + x\r\n\r\nif tot < k:\r\n print('-1')\r\nelse:\r\n print(new)\r\n",
"def val(k):\r\n i=ord(k)\r\n if abs(97-i)>(122-i):\r\n return 97-i\r\n return 122-i\r\ninf,n=input().split()\r\nstring=input()\r\nans=\"\"\r\nk=int(n)\r\ni=0\r\nwhile (k>0) and i<len(string):\r\n p=val(string[i])\r\n v=p\r\n if abs(v)>k:\r\n v=k\r\n if p<0:\r\n v= (-k)\r\n ans=ans+chr(ord(string[i])+v)\r\n k=k-abs(v)\r\n i=i+1\r\nans=ans+string[i:]\r\nif k>0:\r\n print(-1)\r\nelse:\r\n print(ans)\r\n",
"n , k = map(int,input().split())\r\ns=input()\r\nst=''\r\nfor i in s:\r\n if i<='m':\r\n t=(ord('z')-ord(i))\r\n if k>=t:\r\n k-=t\r\n st+='z'\r\n elif k<t and k!=0:\r\n st+=chr(ord(i)+k) \r\n k=0\r\n elif k==0:\r\n st+=i\r\n else:\r\n t=abs(ord(i)-ord('a'))\r\n if k>=t:\r\n k-=t\r\n st+='a'\r\n elif k<t and k!=0:\r\n st+=chr(ord(i)-k)\r\n k=0\r\n elif k==0:\r\n st+=i\r\nif k!=0:\r\n print('-1')\r\nelse: \r\n print(st)\r\n\r\n ",
"import sys\n\ndef dist(a,b):\n return abs(ord(a[0]) - ord(b[0]))\n\nnums = [int(i) for i in input().split(' ')]\nword = input()\n\nword = [c for c in word]\ntotal = nums[1]\n\nif len(word) * 25 < total:\n print('-1')\n sys.exit(0)\n\nfor i,_ in enumerate(word):\n c = word[i]\n dz = dist(c, 'z')\n da = dist(c, 'a')\n if dz > da:\n if total < dz:\n word[i] = chr(ord(c)+total)\n print(''.join(word))\n sys.exit(0)\n else:\n total -= dz\n word[i] = 'z'\n if da > dz:\n if total < da:\n word[i] = chr(ord(c)-total)\n print(''.join(word))\n sys.exit(0)\n else: \n total -= da\n word[i] = 'a'\n if total == 0:\n break\n if total < 0:\n print('SOMETHING HAS GONE HORRIBLY WRONG',total)\n\nif total != 0:\n print('-1')\nelse:\n print(''.join(word))\n",
"p=input().rstrip().split(' ')\r\ns=input().rstrip()\r\nx=list(s)\r\nW=int(p[1])\r\nl=[]\r\nfor i in range(0,len(x)):\r\n if W==0:\r\n l.append(x[i])\r\n else:\r\n t=abs(ord(x[i])-ord('z'))\r\n T=abs(ord(x[i])-ord('a'))\r\n if t>=T:\r\n if t<=W:\r\n l.append('z')\r\n W=W-t;\r\n else:\r\n F=chr(ord(x[i])+W)\r\n W=0;\r\n l.append(F)\r\n else:\r\n if T<=W:\r\n l.append('a')\r\n W=W-T;\r\n else:\r\n F=chr(ord(x[i])-W)\r\n W=0;\r\n l.append(F)\r\nif W!=0:\r\n print(-1)\r\nelse:\r\n C=''.join(l)\r\n print(C)\n# Sun Jul 03 2022 08:59:12 GMT+0000 (Coordinated Universal Time)\n",
"n,k=list(map(int,input().split()));\r\ns=list(input());\r\nfor i in range(len(s)):\r\n if s[i]<='m':\r\n x=min(k,ord('z')-ord(s[i]));\r\n s[i]=chr(ord(s[i])+x);\r\n k-=x;\r\n else:\r\n x=min(k,ord(s[i])-ord('a'));\r\n s[i]=chr(ord(s[i])-x);\r\n k-=x;\r\nprint(-1if k>0 else ''.join(s));",
"n, k = map(int, input().split())\r\nt = ''\r\nfor i in map(ord, input()):\r\n d = min(k, max(122 - i, i - 97))\r\n t += chr(i + d if i + d < 123 else i - d)\r\n k -= d\r\nprint(-1 if k else t)",
"size,dist = map(int,input().split())\r\nuserString,alpha = input(),'abcdefghijklmnopqrstuvwxyz'\r\ncapt = ''\r\nfor x in userString:\r\n num = ord(x)\r\n diff = max(122 - num, num - 97)\r\n if dist == 0:\r\n capt += x\r\n elif dist-diff < 0:\r\n if num - 97 + dist < 26: capt += alpha[ num-97+dist ]\r\n elif num - 97 - dist > -1: capt+= alpha[ num-97-dist ]\r\n else: print(-1); exit()\r\n dist = 0\r\n else:\r\n dist -= diff\r\n if num - 97 + diff < 26: capt += alpha[ num-97+diff ]\r\n elif num - 97 - diff > -1: capt+= alpha[ num-97-diff ]\r\nprint(capt if not dist else -1)\r\n",
"n, k = map(int, input().split())\r\ns = list(input())\r\nss = list(s)\r\nkk = k\r\nfor i in range(n):\r\n z = ord('z') - ord(s[i])\r\n a = ord(s[i]) - ord('a')\r\n if k == 0:\r\n break\r\n if z > a:\r\n s[i] = chr(ord(s[i]) + min(k, z))\r\n k -= min(k, z)\r\n else:\r\n s[i] = chr(ord(s[i]) - min(k, a))\r\n k -= min(k, a)\r\nsm = 0\r\nfor i in range(n):\r\n sm += abs(ord(s[i])-ord(ss[i]))\r\nif sm == kk:\r\n print(\"\".join(s))\r\nelse:\r\n print(-1)",
"n,k=map(int,input().split())\r\ns=input()\r\npzbl=[]\r\nfor i in range(n):\r\n pzbl.append(max(ord(s[i])-97,122-ord(s[i])))\r\nif k>sum(pzbl):\r\n print(-1)\r\nelse:\r\n ans=''\r\n req=k \r\n for i in range(n):\r\n if req==0:\r\n ans+=s[i]\r\n elif req>=pzbl[i]:\r\n req-=pzbl[i]\r\n if 122-ord(s[i])>ord(s[i])-97:\r\n ans+='z'\r\n else:\r\n ans+='a'\r\n elif req<pzbl[i]:\r\n c=req \r\n req=0 \r\n if ord(s[i])+c<=122:\r\n ans+=chr(ord(s[i])+c)\r\n elif ord(s[i])-c>=97:\r\n ans+=chr(ord(s[i])-c)\r\n print(ans)",
"n, k = map(int, input().split())\r\ns = input()\r\n\r\nres = \"\"\r\n\r\nfor i in range(n):\r\n lc = ord(s[i]) - ord('a')\r\n rc = ord('z') - ord(s[i])\r\n\r\n if lc < rc:\r\n if rc <= k:\r\n res += 'z'\r\n k -= rc\r\n else:\r\n res += chr(ord(s[i]) + k)\r\n k = 0\r\n else:\r\n if lc <= k:\r\n res += 'a'\r\n k -= lc\r\n else:\r\n res += chr(ord(s[i]) - k)\r\n k = 0\r\n\r\nprint(res if k == 0 else -1)\r\n",
"p = input().rstrip().split(' ')\ns = input().rstrip()\nx = list(s)\nw = int(p[1])\nl = []\nfor i in range(0,len(x)):\n if w == 0:\n l.append(x[i])\n else:\n t = abs(ord(x[i])-ord('z'))\n T = abs(ord(x[i])-ord('a'))\n if t >= T:\n if t <= w:\n l.append('z')\n w -= t;\n else:\n F = chr(ord(x[i])+w)\n w = 0;\n l.append(F)\n else:\n if T <= w:\n l.append('a')\n w -= T;\n else:\n F = chr(ord(x[i])-w)\n w = 0;\n l.append(F)\nif w != 0:\n print(-1)\nelse:\n C = ''.join(l)\n print(C)\n# Sun Jul 03 2022 10:39:49 GMT+0000 (Coordinated Universal Time)\n",
"n, k = map(int, input().split())\ns = input()\ns = [i for i in s]\n\nfor i in range(n):\n\ta = ord('z') - ord(s[i])\n\tb = ord(s[i]) - ord('a')\n\tif a > b:\n\t\tif k < a:\n\t\t\ta = k\n\t\ts[i] = chr(ord(s[i]) + a)\n\t\tk -= a\n\telse:\n\t\tif k < b:\n\t\t\tb = k\n\t\ts[i] = chr(ord(s[i]) - b)\n\t\tk -= b\n\tif not k:\n\t\tbreak\n\t\t\nif k > 0:\n\tprint (-1)\nelse:\n\ts = ''.join(s)\n\tprint (s)\n\n\n",
"def read():\n return [int(s) for s in input().split()]\n\ndef whichmax(a, b):\n xs = [a, b]\n m = max(xs)\n return (m, xs.index(m))\n\ndef dist(c, d):\n return abs(ord(d) - ord(c))\n\n(n, k) = read()\ns = input()\n\ntab = [0] * n\n\nfor i in range(n):\n (m, j) = whichmax(dist('a', s[i]), dist('z', s[i]))\n if m <= k:\n tab[i] = ['a', 'z'][j]\n k = k - m\n else:\n sign = [-1, 1][j]\n tab[i] = chr(ord(s[i]) + sign * k)\n k = 0\n\nresult = \"\".join(tab)\n\nprint(result if k == 0 else -1)\n",
"\nn, k = map(int, input().split())\nA = input()\n\nmax_dist = 0\nfor i in range(len(A)):\n max_dist += max([ord(A[i]) - ord('a'),\n ord('z') - ord(A[i])])\n\nresult = \"\"\n\nif k > max_dist:\n result = \"-1\"\nelse:\n for i in range(len(A)):\n dist_to_a = ord(A[i]) - ord('a')\n dist_to_z = ord('z') - ord(A[i])\n if dist_to_a > dist_to_z:\n d = min(dist_to_a, k)\n k -= d\n result += chr(ord(A[i]) - d)\n else:\n d = min(dist_to_z, k)\n k -= d\n result += chr(ord(A[i]) + d)\n\nprint(result)\n",
"nk = input().split()\r\ns = input()\r\nn, k = int(nk[0]), int(nk[1])\r\nd = k\r\ni = 0\r\nans = \"\"\r\nwhile d > 0 and i < n:\r\n x, y = abs(ord(s[i]) - ord('a')), abs(ord(s[i]) - ord('z'))\r\n if x > y:\r\n if x >= d:\r\n ans += chr(ord(s[i]) - d)\r\n d = 0\r\n else:\r\n ans += 'a'\r\n d -= x\r\n else:\r\n if y >= d:\r\n ans += chr(ord(s[i]) + d)\r\n d = 0\r\n else:\r\n ans += 'z'\r\n d -= y\r\n i += 1\r\nans += s[i::]\r\nif d > 0:\r\n ans = \"-1\"\r\nprint(ans)",
"def check(s, k):\r\n ans = 0\r\n for i in range(len(s)):\r\n ans += abs(ord(s[i]) - ord(k[i]))\r\n return ans\r\n\r\nn, k = map(int, input().split())\r\ns = input()\r\ncnt = 0\r\nfor i in s:\r\n cnt += max(ord('z') - ord(i), ord(i) - ord('a'))\r\nif k > cnt:\r\n print(-1)\r\n exit()\r\nelse:\r\n ans = ''\r\n cr = 0\r\n while k != 0:\r\n ps1 = ord(s[cr]) - ord('a')\r\n ps2 = ord('z') - ord(s[cr])\r\n if ps1 > k:\r\n ans += chr(ord(s[cr]) - k)\r\n k = 0\r\n elif ps2 > k:\r\n ans += chr(ord(s[cr]) + k)\r\n k = 0 \r\n else:\r\n if ps2 >= ps1:\r\n ans += 'z'\r\n k -= ps2\r\n else:\r\n ans += 'a'\r\n k -= ps1\r\n cr += 1\r\nans += s[len(ans):]\r\nprint(ans)\r\n#print(check(ans, s))",
"import math\r\nfrom math import *\r\nil,k = map(int, input().split(' '))\r\ns = input()\r\n#s = 'bear'\r\n#k = 26\r\ns2 = ''\r\nfor i in range(len(s)):\r\n l = ord(s[i]) - ord('a')\r\n r = ord('z') - ord(s[i])\r\n m = max(l,r)\r\n if k >= m:\r\n k -= m\r\n if l > r:\r\n s2 += chr(ord(s[i]) - l)\r\n else:\r\n s2 += chr(ord(s[i]) + r)\r\n else:\r\n if k == 0:\r\n s2 += s[i]\r\n else:\r\n if l > r:\r\n s2 += chr(ord(s[i]) - k)\r\n else:\r\n s2 += chr(ord(s[i]) + k)\r\n k = 0\r\nif k > 0:\r\n print(-1)\r\nelse:\r\n print(s2)",
"import sys\r\nni = lambda :int(input())\r\nna = lambda :list(map(int,input().split()))\r\nyes = lambda :print(\"yes\");Yes = lambda :print(\"Yes\");YES = lambda : print(\"YES\")\r\nno = lambda :print(\"no\");No = lambda :print(\"No\");NO = lambda : print(\"NO\")\r\n#######################################################################\r\n\r\nn, k = na()\r\ns = input()\r\nans = []\r\nfor i in range(n):\r\n x = ord(s[i])-97\r\n if x <= 12:\r\n d = min(k, 25-x)\r\n y = d + x\r\n k -= d\r\n else:\r\n d = min(k, x)\r\n y = x-d\r\n k -= d\r\n ans.append(chr(y+97))\r\n\r\nif k:\r\n print(-1)\r\nelse:\r\n print(\"\".join(ans))\r\n",
"n, k = map(int, input().split())\r\ns = str(input())\r\nt = []\r\nfor i, c in enumerate(s):\r\n c = ord(c)-ord('a')\r\n l = max(0, c-k)\r\n r = min(25, c+k)\r\n if r-c >= c-l:\r\n nc = chr(r+ord('a'))\r\n t.append(nc)\r\n k -= r-c\r\n else:\r\n nc = chr(l+ord('a'))\r\n t.append(nc)\r\n k -= c-l\r\nif k:\r\n print(-1)\r\n exit()\r\nprint(''.join(t))\r\n",
"letters={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14,'o':15,'p':16,'q':17,\r\n 'r':18,'s':19,'t':20,'u':21,'v':22,'w':23,'x':24,'y':25,'z':26}\r\n\r\n\r\ndef dist(string1,string2):\r\n if len(string1)==len(string2):\r\n if len(string1)==1:\r\n return abs(letters[string1]-letters[string2])\r\n elif len(string1)>1:\r\n letters1=list(string1)\r\n letters2=list(string2)\r\n sum=0\r\n for i in range(0,len(letters1)):\r\n distance=dist(letters1[i],letters2[i])\r\n sum+=distance\r\n return sum\r\n\r\n\r\ndef find_string(n,k,string1):\r\n nums={1:'a',2:'b',3:'c',4:'d',5:'e',6:'f',7:'g',8:'h',9:'i',10:'j',11:'k',12:'l',13:'m',14:'n',15:'o',16:'p',17:'q',\r\n 18:'r',19:'s',20:'t',21:'u',22:'v',23:'w',24:'x',25:'y',26:'z'}\r\n string1=[item for item in string1]\r\n for i in range(0,n):\r\n dist1=letters['z']-letters[string1[i]]\r\n dist2=letters[string1[i]]-letters['a']\r\n if dist1>dist2:\r\n if k<dist1:\r\n dist1=k\r\n D=letters[string1[i]]+dist1\r\n L=nums[D]\r\n string1[i]=L\r\n k-=dist1\r\n else:\r\n if k<dist2:\r\n dist2=k\r\n D=letters[string1[i]]-dist2\r\n L=nums[D]\r\n string1[i]=L\r\n k-=dist2\r\n if not k:\r\n break\r\n if k > 0:\r\n\t print (-1)\r\n else:\r\n\t word = ''.join(string1)\r\n\t print (word)\r\n\r\n\r\ndef main():\r\n n,k = map(int,input().split())\r\n string1 = input()\r\n find_string(n,k,string1)\r\n\r\nmain()",
"n, k = map(int, input().split(' '))\ns = list(input())\nif k <= n:\n for i in range(k):\n s[i] = chr(ord(s[i])-1) if s[i]!='a' else chr(ord(s[i])+1)\n print(''.join(s))\nelse:\n acc = 0\n for i in range(n):\n if ord(s[i]) <= ord('m'):\n if k - acc <= ord('z') - ord(s[i]):\n s[i] = chr(ord(s[i])+k-acc)\n acc = k\n else:\n acc += ord('z') - ord(s[i])\n s[i] = 'z'\n else:\n if k - acc <= ord(s[i]) - ord('a'):\n s[i] = chr(ord(s[i])-k+acc)\n acc = k\n else:\n acc += ord(s[i]) - ord('a')\n s[i] = 'a'\n if acc < k:\n print(-1)\n else:\n print(''.join(s))\n",
"\r\n# If you win, you live. You cannot win unless you fight.\r\n\r\nfrom sys import stdin\r\ninput=stdin.readline\r\nimport heapq\r\nimport string\r\nrd=lambda: map(lambda s: int(s), input().strip().split())\r\nri=lambda: int(input())\r\nrs=lambda :input().strip()\r\nfrom collections import defaultdict as unsafedict,deque,Counter as unsafeCounter\r\nfrom bisect import bisect_left as bl, bisect_right as br\r\nfrom random import randint\r\nfrom math import gcd, floor,log2,factorial,radians,sin,cos\r\nrandom = randint(1, 10 ** 9)\r\nmod=10**9+7\r\ndef ceil(a,b):\r\n\treturn (a+b-1)//b\r\nclass myDict:\r\n\tdef __init__(self,func):\r\n\t\tself.RANDOM = randint(0,1<<32)\r\n\t\tself.default=func\r\n\t\tself.dict={}\r\n\tdef __getitem__(self,key):\r\n\t\tmyKey=self.RANDOM^key\r\n\t\tif myKey not in self.dict:\r\n\t\t\tself.dict[myKey]=self.default()\r\n\t\treturn self.dict[myKey]\r\n\tdef get(self,key,default):\r\n\t\tmyKey=self.RANDOM^key\r\n\t\tif myKey not in self.dict:\r\n\t\t\treturn default\r\n\t\treturn self.dict[myKey]\r\n\tdef __setitem__(self,key,item):\r\n\t\tmyKey=self.RANDOM^key\r\n\t\tself.dict[myKey]=item\r\n\tdef getKeys(self):\r\n\t\treturn [self.RANDOM^i for i in self.dict]\r\n\tdef __str__(self):\r\n\t\treturn f'{[(self.RANDOM^i,self.dict[i]) for i in self.dict]}'\r\n\r\nal=string.ascii_lowercase\r\ndef geto(a):\r\n\treturn ord(a)-ord('a')\r\nn,k=rd()\r\ns=rs()\r\nans=['']*n\r\nfor i in range(n):\r\n\r\n\tif k==0:\r\n\t\tans[i]=s[i]\r\n\tx=geto(s[i])\r\n\tif x>k:\r\n\t\tans[i]=al[x-k]\r\n\t\tk=0\r\n\t\tcontinue\r\n\ty=25-geto(s[i])\r\n\tif y>k:\r\n\t\tans[i]=al[x+k]\r\n\t\tk=0\r\n\t\tcontinue\r\n\tif x>y:\r\n\t\tans[i]='a'\r\n\t\tk-=x\r\n\telse:\r\n\t\tans[i]=\"z\"\r\n\t\tk-=y\r\nif k:\r\n\tprint(-1)\r\nelse:\r\n\r\n\tprint(*ans,sep='')\r\n",
"import sys\r\nreadline=sys.stdin.readline\r\nwrite=sys.stdout.write\r\n\r\nN,K=map(int,readline().split())\r\nS=list(readline().rstrip())\r\nalp=[chr(i) for i in range(97,97+26)]\r\nans_lst=[None]*N\r\nfor i in range(N):\r\n ans_lst[i]=max(abs(ord(S[i])-ord(\"a\")),abs(ord(S[i])-ord(\"z\")))\r\ns=sum(ans_lst)\r\nif s<K:\r\n print(-1)\r\n exit()\r\nfor i in range(N):\r\n x=min(ans_lst[i],s-K)\r\n ans_lst[i]-=x\r\n s-=x\r\nfor i in range(N):\r\n for ans in alp:\r\n if abs(ord(S[i])-ord(ans))==ans_lst[i]:\r\n ans_lst[i]=ans\r\n break\r\nprint(*ans_lst,sep=\"\")",
"import sys\r\n\r\nmax_dist = [0]*26\r\ndist = [['*']*26 for _ in range(26)]\r\n\r\nfor cc in range(26):\r\n max_dist[cc] = max(cc, 25-cc)\r\n for i in range(max_dist[cc]+1):\r\n dist[cc][i] = chr(cc-i+97) if cc >= i else chr(cc+i+97)\r\n\r\nn, k = map(int, sys.stdin.buffer.readline().decode('utf-8').split())\r\ns = sys.stdin.buffer.readline().decode('utf-8').rstrip()\r\nans = ['']*n\r\n\r\nfor i, cc in enumerate(map(ord, s)):\r\n d = min(k, max_dist[cc-97])\r\n ans[i] = dist[cc-97][d]\r\n k -= d\r\n\r\nif k:\r\n print(-1)\r\nelse:\r\n sys.stdout.buffer.write((''.join(ans)).encode('utf-8'))\r\n",
"n,k = map(int, input().strip().split(' '))\r\n#n=int(input())\r\n#lst = list(map(int, input().strip().split(' ')))\r\ns=input()\r\ns=list(s)\r\nl=\"\"\r\nif k>25*n:\r\n print(-1)\r\nelse:\r\n for j in range(n):\r\n c1=ord(s[j])-ord('a')\r\n c2=ord('z')-ord(s[j])\r\n if k==0:\r\n l+=s[j]\r\n elif c1>=c2:\r\n if c1<=k:\r\n l+='a'\r\n k-=c1\r\n else:\r\n l+=chr(ord(s[j])-k)\r\n k=0\r\n else:\r\n if c2<=k:\r\n l+='z'\r\n k-=c2\r\n else:\r\n l+=chr(ord(s[j])+k)\r\n k=0\r\n if k==0:\r\n print(l)\r\n else:\r\n print(-1)\r\n \r\n ",
"from sys import stdin,stdout\r\na,b=map(int,stdin.readline().split())\r\nc=stdin.readline()\r\nz=list(c)\r\nfor i in range(a):\r\n x = ord(c[i])\r\n k=min(b,max(x-97,122-x))\r\n b-=k\r\n if x+k<=122:z[i]=chr(x+k)\r\n else:z[i]=chr(x-k)\r\nif b:stdout.write(\"-1\")\r\nelse:stdout.write(''.join(z))",
"n, k = list(map(int, input().split()))\r\ns = input()\r\n\r\nans = []\r\n\r\nfor i in range(len(s)):\r\n if k > 0:\r\n da = ord(s[i]) - ord('a')\r\n dz = ord('z') - ord(s[i])\r\n \r\n if k == da:\r\n ans.append('a')\r\n k -= da\r\n elif k == dz:\r\n ans.append('z')\r\n k -= dz\r\n elif k > dz and k > da:\r\n if dz > da:\r\n ans.append('z')\r\n k -= dz\r\n else:\r\n ans.append('a')\r\n k -= da\r\n \r\n elif k < da:\r\n ans.append(chr(ord(s[i])-k))\r\n k = 0\r\n elif k < dz:\r\n ans.append(chr(ord(s[i])+k))\r\n k = 0\r\n \r\n else:\r\n ans.append(s[i])\r\n \r\nif k > 0:\r\n print(-1)\r\nelse:\r\n print(''.join(ans))",
"n,k=map(int,input().split())\r\ns=list(input())\r\nflag=0\r\nfor i in range(n):\r\n x,y=ord('z')-ord(s[i]),ord(s[i])-ord('a')\r\n if x>y:\r\n if x>k:x=k\r\n s[i]=chr(x+ord(s[i]))\r\n k-=x\r\n else:\r\n if y>k:y=k\r\n s[i]=chr(ord(s[i])-y)\r\n k-=y\r\n if k==0:\r\n print(''.join(s));break\r\nelse:print(-1)",
"n,k = map(int,input().split())\r\ns = input()\r\nalth = \"abcdefghijklmnopqrstuvwxyz\"\r\nnum2 = 0\r\ns2 = \"\"\r\nfor i in s:\r\n num2 = alth.find(i)\r\n if k == 0:\r\n s2 += i\r\n else:\r\n if num2 > 12:\r\n num3 = min(num2,k)\r\n s2 += alth[num2-num3]\r\n k -= num3\r\n else:\r\n num3 = min(25-num2,k)\r\n s2 += alth[num2+num3]\r\n k -= num3\r\nif k > 0:\r\n print(-1)\r\nelse:\r\n print(s2)\r\n",
"a, b = map(int, input().split())\r\ns = input()\r\nif b / a > 25:\r\n print(-1)\r\nelse:\r\n ans = \"\"\r\n c = 0\r\n for i in s:\r\n if b == 0:\r\n ans += s[c:]\r\n break\r\n idx = ord(i) - 97\r\n if idx >= 13:\r\n if b > idx:\r\n ans += \"a\"\r\n b -= idx\r\n else:\r\n ans += chr(idx + 97 - b) # alepha[idx - b]\r\n b = 0\r\n\r\n else:\r\n if b > 25-idx:\r\n ans += \"z\"\r\n b -= 25 - idx\r\n else:\r\n ans += chr(idx + 97 + b) # alepha[idx + b]\r\n b = 0\r\n c += 1\r\n if b == 0:\r\n print(ans.lower())\r\n else:\r\n print(-1)",
"#!/usr/bin/python3\n\ndef char_dist(a, b):\n\td = ord(a) - ord(b)\n\tif d < 0: d = -d\n\n\treturn d\n\ndef mutate_char(c, delta):\n\treturn chr(ord(c) + delta)\n\ndef max_mutate_char(c, max_dist):\n\tdist2a = char_dist(c, 'a')\n\tdist2z = char_dist(c, 'z')\n\n\tif dist2z > dist2a:\n\t\tdelta = min(dist2z, max_dist)\n\t\tabsdelta = delta\n\telse:\n\t\tdelta = -min(dist2a, max_dist)\n\t\tabsdelta = -delta\n\n\treturn mutate_char(c, delta), absdelta\n\ndef main():\n\tn, k = [int(i) for i in input().split()]\n\ts = input()\n\n\tnew_s = []\n\n\tneed_mutation = True\n\n\tfor c in s:\n\t\tif need_mutation:\n\t\t\tnew_c, delta = max_mutate_char(c, k)\n\t\t\tk -= delta\n\t\t\tif k <= 0:\n\t\t\t\tneed_mutation = False\n\t\telse:\n\t\t\tnew_c = c\n\n\t\tnew_s.append(new_c)\n\t\t# print(new_c, end='')\n\t\t# print(c, '->', new_c)\n\t\t# print('Left:', k)\n\n\tif need_mutation:\n\t\tprint(-1)\n\telse:\n\t\tprint(''.join(new_s))\n\nif __name__\t == '__main__':\n\tmain()\n",
"n, k = input().split()\nn = int(n)\nk = int(k)\nstr0 = input()\nlist0 = []\nfor each in str0:\n list0.append(ord(each) - ord('a') + 1)\nres = ''\n# print(list0)\nfor each in list0:\n if each > 13.5:\n k -= (each - 1)\n if k >= 0:\n res += 'a'\n else:\n if k + each - 1 > 0:\n res += chr(each - (k + each - 1) + ord('a') - 1)\n else:\n res += chr(each + ord('a') - 1)\n else:\n # print(\"k = \", k)\n k -= (26 - each)\n if k >= 0:\n res += 'z'\n # print(res)\n else:\n if k + 26 - each > 0:\n res += chr(ord('a') - 1 + each + k + 26 - each)\n else:\n res += chr(ord('a') + each - 1)\n # print(res)\nif k > 0:\n print(-1)\nelse:\n print(res)\n\n\n\n# a b c d e f g h i j k l m n o p q r s t u v w x y z\n# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\n\t\t \t\t \t \t\t \t\t\t\t\t \t \t \t \t",
"\n# If you win, you live. You cannot win unless you fight.\n\nfrom sys import stdin\ninput=stdin.readline\nimport heapq\nimport string\nrd=lambda: map(lambda s: int(s), input().strip().split())\nri=lambda: int(input())\nrs=lambda :input().strip()\nfrom collections import defaultdict as unsafedict,deque,Counter as unsafeCounter\nfrom bisect import bisect_left as bl, bisect_right as br\nfrom random import randint\nfrom math import gcd, floor,log2,factorial,radians,sin,cos\nrandom = randint(1, 10 ** 9)\nmod=10**9+7\ndef ceil(a,b):\n\treturn (a+b-1)//b\nclass myDict:\n\tdef __init__(self,func):\n\t\tself.RANDOM = randint(0,1<<32)\n\t\tself.default=func\n\t\tself.dict={}\n\tdef __getitem__(self,key):\n\t\tmyKey=self.RANDOM^key\n\t\tif myKey not in self.dict:\n\t\t\tself.dict[myKey]=self.default()\n\t\treturn self.dict[myKey]\n\tdef get(self,key,default):\n\t\tmyKey=self.RANDOM^key\n\t\tif myKey not in self.dict:\n\t\t\treturn default\n\t\treturn self.dict[myKey]\n\tdef __setitem__(self,key,item):\n\t\tmyKey=self.RANDOM^key\n\t\tself.dict[myKey]=item\n\tdef getKeys(self):\n\t\treturn [self.RANDOM^i for i in self.dict]\n\tdef __str__(self):\n\t\treturn f'{[(self.RANDOM^i,self.dict[i]) for i in self.dict]}'\n\nal=string.ascii_lowercase\ndef geto(a):\n\treturn ord(a)-ord('a')\nn,k=rd()\ns=rs()\nans=['']*n\nfor i in range(n):\n\n\tif k==0:\n\t\tans[i]=s[i]\n\tx=geto(s[i])\n\tif x>k:\n\t\tans[i]=al[x-k]\n\t\tk=0\n\t\tcontinue\n\ty=25-geto(s[i])\n\tif y>k:\n\t\tans[i]=al[x+k]\n\t\tk=0\n\t\tcontinue\n\tif x>y:\n\t\tans[i]='a'\n\t\tk-=x\n\telse:\n\t\tans[i]=\"z\"\n\t\tk-=y\nif k:\n\tprint(-1)\nelse:\n\n\tprint(*ans,sep='')\n\n \t \t \t\t \t\t\t\t \t\t\t \t \t\t\t\t \t\t",
"import sys\r\nl=list(map(int,input().split()))\r\nn=l[0]\r\nk=l[1]\r\ns=list(input())\r\nl=[0]*n\r\np=0\r\nfor i in range(n):\r\n l[i]=[max(abs(ord(\"z\")-ord(s[i])),abs(ord(\"a\")-ord(s[i]))),i,\"a\"]\r\n if(abs(ord(\"z\")-ord(s[i]))>abs(ord(\"a\")-ord(s[i]))):\r\n l[i][2]=\"z\"\r\n p+=l[i][0]\r\nif(k>p):\r\n print(-1)\r\n sys.exit()\r\nelse:\r\n c=0\r\n l.sort(reverse=True)\r\n h=[0]*n\r\n while(k!=0):\r\n if(l[c][0]>=k):\r\n h[c]=k\r\n k=0\r\n else:\r\n h[c]=l[c][0]\r\n k-=h[c]\r\n c+=1\r\nfor i in range(c+1):\r\n if(l[i][2]==\"z\"):\r\n k=ord(s[l[i][1]])\r\n k+=h[i]\r\n s[l[i][1]]=chr(k)\r\n else:\r\n k=ord(s[l[i][1]])\r\n k-=h[i]\r\n s[l[i][1]]=chr(k)\r\nst = ''.join(s)\r\nprint(st)\r\n ",
"import sys\r\nn, k = map(int, input().split())\r\nline = list(input())\r\nfor i in range(n):\r\n if ord('z') - ord(line[i]) >= ord(line[i]) - ord('a'):\r\n s = ord('z') - ord(line[i])\r\n if s >= k:\r\n line[i] = chr(ord(line[i])+k)\r\n print(''.join(line))\r\n sys.exit()\r\n else:\r\n line[i] = 'z'\r\n k -= s\r\n else:\r\n s = ord(line[i]) - ord('a')\r\n if s >= k:\r\n line[i] = chr(ord(line[i])-k)\r\n print(''.join(line))\r\n sys.exit()\r\n else:\r\n line[i] = 'a'\r\n k -= s\r\nprint(-1)\r\n",
"n, k = map(int, input().split())\ns = input()\nans = \"\"\nfor i in range(n):\n left_dist = ord(s[i]) - ord('a')\n right_dist = ord('z') - ord(s[i])\n mn = 0\n if left_dist > right_dist:\n mn = min(left_dist, k)\n ans += chr(ord(s[i]) - mn)\n else:\n mn = min(right_dist, k)\n ans += chr(ord(s[i]) + mn)\n k -= mn\nif k:\n print(-1)\nelse:\n print(ans)\n",
"n,k=map(int,input().split())\r\nword=input()\r\nnum=[0]*n\r\nwordans=\"\"\r\nfor i in range(n):\r\n num[i]+=ord(word[i])-96\r\nsumma_izm=0\r\nfor i in num:\r\n a=(i-1)\r\n b=(26-i)\r\n if a>=b:\r\n summa_izm+=a\r\n else:\r\n summa_izm+=b\r\nif summa_izm>=k:\r\n for i in range(n):\r\n raz=26-num[i]\r\n if raz>=13:\r\n if raz<=k:\r\n wordans+=\"z\"\r\n k-=raz\r\n else:\r\n wordans += chr(96+k+num[i])+word[i+1:]\r\n break\r\n else:\r\n if (num[i]-1) <= k:\r\n wordans += \"a\"\r\n k -= num[i]-1\r\n else:\r\n wordans += chr(96 + num[i]-k) + word[i + 1:]\r\n break\r\n print(wordans)\r\nelse:\r\n print(-1)",
"from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn,k=map(int,input().split())\r\ns=input()\r\nans=[]\r\nfor i in s:\r\n mx=-1\r\n use=i\r\n for j in range(26):\r\n if mx<abs((ord(i)-97)-j)<=k:\r\n mx=abs((ord(i)-97)-j)\r\n use=chr(97+j)\r\n ans.append(use)\r\n k-=mx\r\nif k!=0:\r\n print(-1)\r\nelse:\r\n print(''.join(ans))",
"n,k=map(int,input().split())\r\ns=input()\r\na=[]\r\nfor i in range(n):\r\n t=min(k,max(ord(s[i])-ord('a'),ord('z')-ord(s[i])))\r\n if ord(s[i])+t>ord('z'):a.append(chr(ord(s[i])-t))\r\n else:a.append(chr(ord(s[i])+t))\r\n k-=t\r\nif k>0:exit(print('-1'))\r\nprint(''.join(a))\r\n ",
"n, k = map(int, input().split())\r\ns = input()\r\ns1 = [s[i] for i in range(n)]\r\ni = 0\r\nwhile k > 0 and i < n:\r\n c = ord(s[i])\r\n d1 = abs(ord('a') - c)\r\n d2 = abs(ord('z') - c)\r\n if k >= d1 >= d2: s1[i] = 'a'\r\n elif k >= d2 >= d1: s1[i] = 'z'\r\n elif c - k >= ord('a'): s1[i] = chr(c - k)\r\n else: s1[i] = chr(c + k)\r\n i += 1\r\n k -= max(d1, d2)\r\nif k > 0: ans = -1\r\nelse: ans = ''.join(map(str, s1))\r\nprint(ans)\r\n",
"n, k = map(int, input().split())\r\nb = list(input())\r\n \r\nfor i in range(n):\r\n\tx = ord('z') - ord(b[i])\r\n\ty = ord(b[i]) - ord('a')\r\n\tif x > y:\r\n\t\tif k < x:\r\n\t\t\tx = k\r\n\t\tb[i] = chr(ord(b[i]) + x)\r\n\t\tk -= x\r\n\telse:\r\n\t\tif k < y:\r\n\t\t\ty = k\r\n\t\tb[i] = chr(ord(b[i]) - y)\r\n\t\tk -= y\r\n\tif k==0:\r\n\t\tbreak\r\n\t\t\r\nif k > 0:\r\n\tprint (-1)\r\nelse:\r\n\ts = ''.join(b)\r\n\tprint (s)",
"n, k = map(int, input().split())\ns = input()\npt = 0\nfor x in s:\n pt += max(abs(122 - ord(x)), abs(97 - ord(x)))\nif pt < k:\n print(-1)\n exit()\nans = \"\"\ni = 0\nwhile i < n and k > 0:\n x = s[i]\n ord_x = ord(x)\n diff = max(abs(122 - ord_x), abs(97 - ord_x))\n q = min(k, diff)\n k -= q\n if ord_x + q <= 122:\n ans += chr(ord_x + q)\n else:\n ans += chr(ord_x - q)\n i += 1\nans += s[i:n]\n# t = 0\n# for i in range(n):\n# t += abs(ord(ans[i]) - ord(s[i]))\n# print(t)\nprint(ans)",
"\r\nn, k = map(int, input().split())\r\nst = input()\r\nans = ''\r\ni = 0\r\n\r\nwhile i < n and k > 0:\r\n\tif abs(ord(st[i]) - 97) > abs(ord(st[i]) - 122):\r\n\t\tans += chr(max(97, ord(st[i]) - k))\r\n\t\tk -= ord(st[i]) - ord(ans[-1])\r\n\r\n\telse:\r\n\t\tans += chr(min(122, ord(st[i]) + k))\r\n\t\tk -= ord(ans[-1]) - ord(st[i])\r\n\r\n\r\n\r\n\ti += 1\r\n\r\nif k == 0:\r\n\tprint(ans + st[i:])\r\n\r\nelse:\r\n\tprint(-1)\r\n",
"from sys import stdin, stdout\r\n\r\n\r\ndef main():\r\n n, k = map(int, stdin.readline().split())\r\n s = stdin.readline()\r\n ans = []\r\n for i in range(n):\r\n max_diff1 = ord('z') - ord(s[i])\r\n max_diff2 = ord(s[i]) - ord('a')\r\n if max_diff1 > max_diff2:\r\n max_diff = max_diff1\r\n max_ch = 'z'\r\n min_max_diff = max_diff2\r\n min_max_ch = 'a'\r\n else:\r\n max_diff = max_diff2\r\n max_ch = 'a'\r\n min_max_diff = max_diff1\r\n min_max_ch = 'z'\r\n if k >= max_diff:\r\n k -= max_diff\r\n ans.append(max_ch)\r\n elif k > 0:\r\n if ord('a') <= ord(s[i]) + k <= ord('z'):\r\n ans.append(chr(ord(s[i]) + k))\r\n elif ord('a') <= ord(s[i]) - k <= ord('z'):\r\n ans.append(chr(ord(s[i]) - k))\r\n k = 0\r\n else:\r\n ans.append(s[i])\r\n if k > 0:\r\n stdout.write('-1\\n')\r\n else:\r\n stdout.write(''.join(ans))\r\n stdout.write('\\n')\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"n,k=map(int,input().split())\r\ns=input()\r\nres=''\r\nflag=0\r\nindex=0\r\nfor i in range(n):\r\n x=max(ord(s[i])-ord('a'),ord('z')-ord(s[i]))\r\n #print(x)\r\n if x<=k:\r\n if x==ord(s[i])-ord('a'):\r\n res=res+chr(ord(s[i])-x)\r\n #print(res)\r\n k=k-x\r\n #print(k)\r\n elif x==ord('z')-ord(s[i]):\r\n res = res + chr(ord(s[i]) + x)\r\n #print(res)\r\n k = k - x\r\n #print(k)\r\n\r\n else:\r\n if ord(s[i])+k>122:\r\n res=res+chr(ord(s[i])-k)\r\n else:\r\n res=res+chr(ord(s[i])+k)\r\n #print(res)\r\n k=0\r\n if k==0:\r\n flag=1\r\n index=i\r\n break\r\nif flag==1:\r\n res=res+s[index+1:n]\r\n print(res)\r\nelif k!=0:\r\n print(-1)\r\nelse:\r\n print(res)",
"n,k = map(int,input().split())\r\ns = input()\r\ns = list(s)\r\nfor i in range(n):\r\n\tif ord(s[i])>=110:\r\n\t\tm = min(ord(s[i])-97,k)\r\n\t\tk-=m\r\n\t\ts[i]=chr(ord(s[i])-m)\r\n\telse:\r\n\t\tm = min(122-ord(s[i]),k)\r\n\t\tk-=m\r\n\t\ts[i]=chr(ord(s[i])+m)\r\nif k>0:\r\n\tprint(-1)\r\nelse:\r\n\tprint(''.join(s))\r\n\t",
"n,k=map(int,input().split())\r\ns=list(input())\r\nd=0\r\nfor i in range(len(s)):\r\n if(s[i]<='m'):\r\n p=min(k,ord('z')-ord(s[i]))\r\n s[i]=chr(ord(s[i])+p)\r\n k-=p\r\n else:\r\n q=min(k,ord(s[i])-ord('a'))\r\n s[i]=chr(ord(s[i])-q)\r\n k-=q\r\n \r\nprint(-1 if(k>0) else ''.join(s))",
"# read input\r\nn, k = map(int, input().split())\r\ns = input()\r\n\r\nresult = []\r\n\r\nfor c in s:\r\n # distance to 'a' and 'z'\r\n dist_a = ord(c) - ord('a')\r\n dist_z = ord('z') - ord(c)\r\n \r\n # find max possible change\r\n if dist_a > dist_z:\r\n max_change = dist_a\r\n change_char = 'a'\r\n else:\r\n max_change = dist_z\r\n change_char = 'z'\r\n \r\n # adjust change to not exceed k\r\n change = min(k, max_change)\r\n \r\n # decrease k and append the changed character\r\n k -= change\r\n if change_char == 'a':\r\n result.append(chr(ord(c) - change))\r\n else:\r\n result.append(chr(ord(c) + change))\r\n \r\n# output result\r\nif k == 0:\r\n print(\"\".join(result))\r\nelse:\r\n print(\"-1\")",
"s, s1 = \"\", \"\"\nn, k = map(int, input().split())\ns = input()\n\nfor i in range(len(s)):\n dis1 = ord('z') - ord(s[i])\n dis2 = ord(s[i]) - ord('a')\n if dis1 > dis2:\n ddd = min(dis1, k)\n k -= ddd\n s1 += chr(ord(s[i]) + ddd)\n else:\n ddd = min(dis2, k)\n k -= ddd\n s1 += chr(ord(s[i]) - ddd)\n\nif k > 0:\n print(\"-1\")\nelse:\n print(s1)\n\n \t\t \t\t \t \t \t\t\t\t\t\t \t\t \t\t",
"n, k = map(int, input().split())\ns = input()\n\ns_prime = list(s)\nfor i in range(n):\n dis1 = ord('z') - ord(s_prime[i])\n dis2 = ord(s_prime[i]) - ord('a')\n if dis1 > dis2:\n ddd = min(dis1, k)\n k -= ddd\n s_prime[i] = chr(ord(s_prime[i]) + ddd)\n else:\n ddd = min(dis2, k)\n k -= ddd\n s_prime[i] = chr(ord(s_prime[i]) - ddd)\n\nif k > 0:\n print(\"-1\")\nelse:\n print(\"\".join(s_prime))\n\n \t \t\t\t \t\t \t\t \t \t \t \t\t\t \t \t",
"nums = input().split()\r\nn = int(nums[0])\r\nk = int(nums[1])\r\ns = input()\r\n\r\ndef dist(a, b):\r\n\treturn abs(ord(a) - ord(b))\r\n\r\n# n, k = 7, 60\r\n# s = 'hellooo'\r\noutput = ''\r\ndistance = k\r\n\r\nfor ch in s:\r\n\tif distance > max(dist(ch, 'a'), dist(ch, 'z')):\r\n\t\tnew_char = 'a' if dist(ch, 'a') > dist(ch, 'z') else 'z'\r\n\t\tdistance -= dist(ch, new_char)\r\n\t\t# print(dist(ch, new_char))\r\n\t\toutput += new_char\r\n\t\t# print('condition true and distance is {}'.format(distance))\r\n\telse:\r\n\t\tnew_char = chr(ord(ch)-distance) if dist(ch, 'a') > dist(ch, 'z') else chr(ord(ch)+distance)\r\n\t\tdistance -= dist(ch, new_char)\r\n\t\t# print(dist(ch, new_char))\r\n\t\toutput += new_char\r\n\t\t# print('condition flase and distance is {}'.format(distance))\r\n\tif distance == 0:\r\n\t\tbreak\r\nif(distance != 0):\r\n\tprint(-1)\r\nelse:\r\n\td = n - len(output)\r\n\tl = len(output)\r\n\tif d > 0:\r\n\t\tfor i in range(l, l+d):\r\n\t\t\toutput += s[i]\r\n\tprint(output)\r\n\r\n\r\n\r\n",
"# 97 122\r\nn,k = map(int,input().split())\r\ns = input()\r\nss = \"\"\r\nsss = [ord(i) for i in s]\r\n\r\nfor i in range(0,n):\r\n k1 = 122-sss[i]\r\n k2 = sss[i]-97\r\n if k1 >= k2:\r\n go = sss[i]+min(k1,k)\r\n k -= min(k1,k)\r\n ss += chr(go)\r\n else:\r\n go = sss[i]-min(k2,k)\r\n k -= min(k2,k)\r\n ss += chr(go)\r\nprint(-1 if k else ss)\r\n\r\n\r\n",
"from math import *\r\nn,k = map(int,input().split())\r\ns = list(input())\r\nmaxx = 0\r\nans = s[::]\r\nfor i in range(n):\r\n\tif(s[i] <= 'm'):\r\n\t\tmaxx += ord('z') - ord(s[i])\r\n\t\tans[i] = 'z'\r\n\telse:\r\n\t\tmaxx += ord(s[i]) - ord('a') \r\n\t\tans[i] = 'a'\r\ni = 0\r\nwhile(i < n and maxx != k):\r\n\tx = ord(ans[i])\r\n\twhile(x != ord(s[i])):\r\n\t\tif(ans[i] == 'a'):\r\n\t\t\tx += 1\r\n\t\telse:\r\n\t\t\tx -= 1\r\n\t\tmaxx -= 1\r\n\t\tif(maxx == k):\r\n\t\t\tbreak\r\n\tans[i] = chr(x)\r\n\ti += 1\r\nif(maxx != k):\r\n\tprint(-1)\r\nelse:\r\n\tprint(\"\".join(ans))",
"n, k = list(map(int, input().split()))\r\ns = list(input())\r\n\r\nf = lambda x: ord(x) - ord('a') + 1\r\nalphabets = list(\"abcdefghijklmnopqrstuvwxyz\")\r\nmemo = {i+1:alphabets[i] for i in range(26)}\r\n\r\nfor i in range(n):\r\n char = s[i]\r\n if f(char) > 13:\r\n far = 'a'\r\n else:\r\n far = 'z'\r\n left = k - abs(f(char) - f(far))\r\n if left < 0:\r\n if f(char) > 13:\r\n s[i] = memo[f(char) - k]\r\n else:\r\n s[i] = memo[f(char) + k]\r\n k = 0\r\n break\r\n else:\r\n s[i] = far\r\n k = left\r\n\r\n\r\nif k == 0:\r\n print(\"\".join(s))\r\nelse:\r\n print(-1)\r\n\r\n\r\n\r\n",
"n, k = map(int, input().split())\r\ns = input()\r\nhelp = []\r\nd = dict()\r\nfor i in range(ord('a'), ord('z') + 1):\r\n if abs(ord('a') - i) > abs(ord('z') - i):\r\n d[chr(i)] = [abs(ord('a') - i), 'a']\r\n else:\r\n d[chr(i)] = [abs(ord('z') - i), 'z']\r\nhelp = 0\r\nfor i in s:\r\n help += d[i][0]\r\nif help < k:\r\n print(-1)\r\nelse:\r\n ans = ''\r\n for i in s:\r\n if d[i][0] < k:\r\n ans += d[i][1]\r\n k -= d[i][0]\r\n else:\r\n for j in range(ord('a'), ord('z') + 1):\r\n if abs(ord(i) - j) == k:\r\n ans += chr(j)\r\n k -= abs(ord(i) - j)\r\n break\r\n print(ans)\r\n\r\n",
"n, k = map(int, input().split())\r\ns = input()\r\ns1 = []\r\nfor char in s:\r\n if k < ord('z') - ord(char):\r\n s1.append(chr(ord(char) + k))\r\n k = 0\r\n elif k < ord(char) - ord('a'):\r\n s1.append(chr(ord(char) - k))\r\n k = 0\r\n else:\r\n if ord('z') - ord(char) > ord(char) - ord('a'):\r\n s1.append('z')\r\n else:\r\n s1.append('a')\r\n k -= max(ord('z') - ord(char), ord(char) - ord('a'))\r\nif k == 0:\r\n print(''.join(s1))\r\nelse:\r\n print(-1)\r\n",
"import sys\r\ndef get_array(): return list(map(int, sys.stdin.readline().split()))\r\ndef get_ints(): return map(int, sys.stdin.readline().split())\r\ndef input(): return sys.stdin.readline().strip('\\n')\r\n\r\nhh = 'abcdefghijklmnopqrstuvwxyz'\r\nn , k = map(int,input().split())\r\ns = input()\r\n\r\nans = []\r\n\r\nfor i in range(n):\r\n\r\n if k != 0:\r\n\r\n if ord(s[i]) - 97 > 122 - ord(s[i]):\r\n x = ord(s[i]) - 97\r\n if k >= x:\r\n ans.append(hh[x - hh.find(s[i])])\r\n k -= x\r\n else:\r\n ans.append(hh[hh.find(s[i]) - k])\r\n k = 0\r\n else:\r\n x = 122 - ord(s[i])\r\n if k >= x:\r\n ans.append(hh[x + hh.find(s[i])])\r\n k -= x\r\n else:\r\n ans.append(hh[hh.find(s[i]) + k])\r\n k = 0\r\n else:\r\n ans.append(s[i])\r\nif k == 0:\r\n print(*ans,sep='')\r\nelse:\r\n print(-1)\r\n"
] | {"inputs": ["4 26\nbear", "2 7\naf", "3 1000\nhey", "5 50\nkzsij", "5 500\nvsdxg", "1 0\na", "1 1\ng", "1 25\nr", "1 15\no", "10 100\naddaiyssyp", "50 100\ntewducenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb", "2 1\nzz", "8 8\nabcdefgh", "1 25\nz", "1 24\nz", "1 24\ny", "2 49\nzz", "1 26\na", "1 25\na", "4 17\nrzsq", "69 1701\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzy", "2 9\nbc", "2 48\nab", "1 8\nc", "2 25\nyd", "5 24\nizrqp", "1 13\nn", "5 21\nfmmqh"], "outputs": ["zcar", "hf", "-1", "zaiij", "-1", "a", "f", "-1", "-1", "zzzzcyssyp", "azazecenaqgpilgftjcmzttrgebnyldwfgbtttrygaiqtkgbjb", "yz", "ibcdefgh", "a", "b", "a", "ab", "-1", "z", "azsq", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax", "kc", "zy", "k", "ac", "zsrqp", "a", "zlmqh"]} | UNKNOWN | PYTHON3 | CODEFORCES | 65 | |
2edeeac50e31bc716f0e02afb027d0d3 | Days of Floral Colours | The Floral Clock has been standing by the side of Mirror Lake for years. Though unable to keep time, it reminds people of the passage of time and the good old days.
On the rim of the Floral Clock are 2*n* flowers, numbered from 1 to 2*n* clockwise, each of which has a colour among all *n* possible ones. For each colour, there are exactly two flowers with it, the distance between which either is less than or equal to 2, or equals *n*. Additionally, if flowers *u* and *v* are of the same colour, then flowers opposite to *u* and opposite to *v* should be of the same colour as well — symmetry is beautiful!
Formally, the distance between two flowers is 1 plus the number of flowers on the minor arc (or semicircle) between them. Below is a possible arrangement with *n*<==<=6 that cover all possibilities.
The beauty of an arrangement is defined to be the product of the lengths of flower segments separated by all opposite flowers of the same colour. In other words, in order to compute the beauty, we remove from the circle all flowers that have the same colour as flowers opposite to them. Then, the beauty is the product of lengths of all remaining segments. Note that we include segments of length 0 in this product. If there are no flowers that have the same colour as flower opposite to them, the beauty equals 0. For instance, the beauty of the above arrangement equals 1<=×<=3<=×<=1<=×<=3<==<=9 — the segments are {2}, {4,<=5,<=6}, {8} and {10,<=11,<=12}.
While keeping the constraints satisfied, there may be lots of different arrangements. Find out the sum of beauty over all possible arrangements, modulo 998<=244<=353. Two arrangements are considered different, if a pair (*u*,<=*v*) (1<=≤<=*u*,<=*v*<=≤<=2*n*) exists such that flowers *u* and *v* are of the same colour in one of them, but not in the other.
The first and only line of input contains a lonely positive integer *n* (3<=≤<=*n*<=≤<=50<=000) — the number of colours present on the Floral Clock.
Output one integer — the sum of beauty over all possible arrangements of flowers, modulo 998<=244<=353.
Sample Input
3
4
7
15
Sample Output
24
4
1316
3436404
| [
"f = [0, 4, 8, -1, 16, -10, 4, -12, -48, 26, -44, 15, -16, -4, -4, -1]\r\njly = 998244353\r\nt = 0\r\nx = [0, 0, 0, 24, 4, 240, 204, 1316, 2988, 6720, 26200, 50248, 174280, 436904, 1140888, 3436404]\r\nn = int(input())\r\nfor i in range(16, n + 1):\r\n t = 0\r\n for j in range(0, 16):\r\n t = (t + f[(i - j - 1) & 15] * x[j]) % jly\r\n x[i & 15] = t\r\nprint((x[n & 15] + jly) % jly)"
] | {"inputs": ["3", "4", "7", "15", "10", "99", "1317", "50000", "5", "6", "8", "9", "11", "12", "13", "14", "16", "17", "18", "19", "20", "33", "39", "89", "144", "233", "396", "418", "431", "831", "985", "998", "1000", "2017", "3939", "5000", "8081", "10000", "10001", "10492", "20178", "23333", "25252", "30000", "35000", "39393", "40404", "45000", "49997", "49999"], "outputs": ["24", "4", "1316", "3436404", "26200", "620067986", "414025", "475800099", "240", "204", "2988", "6720", "50248", "174280", "436904", "1140888", "8348748", "24631232", "64575924", "174658944", "488230244", "823529776", "302870971", "530141864", "395837543", "422271260", "994574954", "57956054", "767293469", "418821250", "574051668", "452930999", "945359814", "222633425", "582943734", "148029988", "473740780", "938538566", "552705744", "914991759", "207394683", "259575428", "306102706", "583465411", "520751787", "929692433", "618777849", "672059275", "645043850", "791828238"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
2f2d711ae79c779f5d447f7d9a907eb7 | Kefa and First Steps | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.
Help Kefa cope with this task!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
Sample Input
6
2 2 1 3 4 1
3
2 2 9
Sample Output
33 | [
"n=int(input())\r\nr=input()\r\ns=r.split(\" \")\r\na=[]\r\nfor i in s:\r\n a.append(int(i))\r\ni=0;maxi=1;num=1\r\nwhile i<n-1:\r\n if a[i]<=a[i+1]:\r\n num+=1\r\n if num>maxi:\r\n maxi=num\r\n else:\r\n num=1\r\n i+=1\r\nprint(maxi)",
"n=int(input())\r\na1=list(map(int,input().split()))\r\nk=1\r\nc=1\r\nfor i in range(1,n):\r\n if a1[i]>=a1[i-1]:\r\n k+=1\r\n else:\r\n c=max(k,c)\r\n k=1\r\nc=max(k,c)\r\nprint(c)",
"n = int(input())\r\nm = 1\r\ncount = 1\r\nseq = list(map(int, input().split()))\r\nfor i in range(n - 1):\r\n if seq[i] <= seq[i + 1]:\r\n count += 1\r\n else:\r\n m = max(m, count)\r\n count = 1\r\nm = max(m, count)\r\nprint(m)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na=[0]\r\nc=0\r\nfor i in range(n-1):\r\n if l[i]>l[i+1]:\r\n a.append(i+1)\r\na.append(n)\r\nfor i in range(len(a)-1): \r\n if -a[i]+a[i+1]>c:\r\n c=a[i+1]-a[i]\r\nprint(c)\r\n\r\n",
"n = int(input())\r\nmoney = list(map(int, input().split()))\r\n\r\nmax_len, curr_len = 1, 1\r\nfor i in range(1, n):\r\n if money[i] >= money[i-1]:\r\n curr_len += 1\r\n else:\r\n max_len = max(max_len, curr_len)\r\n curr_len = 1\r\n\r\nmax_len = max(max_len, curr_len)\r\nprint(max_len)",
"n = int(input()) # Read the number of elements in the list\r\na = list(map(int, input().split())) # Read the list of integers\r\n\r\nmax_length = 1 # Initialize the maximum length of increasing subarray\r\ncurrent_length = 1 # Initialize the length of the current increasing subarray\r\n\r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n current_length += 1 # Increase the length of the current increasing subarray\r\n else:\r\n max_length = max(max_length, current_length) # Update the maximum length\r\n current_length = 1 # Reset the length for the new increasing subarray\r\n\r\n# After the loop ends, check if the current subarray is longer than the recorded maximum\r\nmax_length = max(max_length, current_length)\r\n\r\nprint(max_length) # Print the length of the longest increasing subarray\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nc = 1\r\nm = 0\r\nfor i in range(1,n):\r\n if a[i]>=a[i-1]:\r\n c += 1\r\n else:\r\n m = max(m,c)\r\n c = 1\r\nm = max(m,c)\r\nprint(m)\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\npre=cnt=m=0\r\nfor i in a:\r\n cnt=cnt+1 if i>=pre else 1\r\n m=max(m,cnt)\r\n pre=i\r\nprint(m)",
"n = int(input())\r\n\r\narr = list(map(int, input().split()))\r\nans, br, cur = 0, 0, 0\r\nfor x in range(0, n):\r\n val = arr[x]\r\n if val < br:\r\n ans = max(ans, cur)\r\n cur = 1\r\n else:\r\n cur += 1\r\n br = val\r\nans = max(ans, cur)\r\nprint(ans)\r\n",
"testcases = int(input())\r\nsequence = list(map(int, input().split()))\r\nmax_len = 1\r\ncurrent_len = 1\r\n\r\nfor i in range(1, testcases):\r\n if sequence[i] >= sequence[i-1]:\r\n current_len += 1\r\n else:\r\n max_len = max(max_len, current_len)\r\n current_len = 1\r\n\r\nmax_len = max(max_len, current_len)\r\nprint(max_len)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nmax_len = 1\r\ncurrent_len = 1\r\nfor i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n current_len += 1\r\n max_len = max(max_len, current_len)\r\n else:\r\n current_len = 1\r\nprint(max_len)",
"import math\n\nn = int(input())\n\ncc=0\nln=0\nans=-1\n\npos=1\nfor i in input().split():\n if (ln<=int(i)):\n cc+=1\n else:\n ans=max(ans,cc)\n cc=1\n ln=int(i)\n pos+=1\n\nprint(max(ans,cc))\n\n \t\t\t\t \t\t\t \t\t\t\t \t\t \t\t\t\t\t \t",
"n = int(input())\r\nresult = 1\r\ncount = 1 \r\nbil = list(map(int, input().split()))\r\n\r\nfor i in range(1, n):\r\n if bil[i] >= bil[i - 1]:\r\n count += 1\r\n result = max(result, count)\r\n else:\r\n count = 1\r\n\r\nprint(result)\r\n",
"n = int(input())\r\ns = [int(x) for x in input().split()]\r\nans = 0\r\nmx = 1\r\nfor i in range(n - 1):\r\n if s[i] <= s[i + 1]:\r\n mx += 1\r\n else:\r\n if ans < mx:\r\n ans = mx\r\n mx = 1\r\nif mx > ans:\r\n ans = mx\r\nprint(ans)",
"import sys\r\ninput = sys.stdin.buffer.readline \r\n \r\ndef process(A):\r\n n = len(A)\r\n answer = 1 \r\n curr = 1\r\n for i in range(1, n):\r\n if A[i] >= A[i-1]:\r\n curr+=1 \r\n else:\r\n curr =1 \r\n answer = max(answer, curr)\r\n print(answer)\r\n\r\nn = int(input())\r\nA = [int(x) for x in input().split()]\r\nprocess(A)",
"n = int(input())\r\nl1 = [int(i) for i in input().split()]\r\nl = []\r\nc = 0\r\nfor i in range(n-1):\r\n if l1[i] <= l1[i+1]:\r\n c+=1\r\n l.append(c+1)\r\n else:\r\n c=0\r\nl.append(c+1) \r\n\r\nprint(max(l)) ",
"n = int(input())\r\na = list(map(int, input().split()))\r\nk = 1\r\nt = 0\r\nfor i in range(n-1):\r\n if (a[i]<=a[i+1]):\r\n k += 1\r\n else:\r\n t = max(t, k)\r\n k = 1\r\nt = max(t, k)\r\nprint(t)",
"import sys\r\n\r\nn = int(sys.stdin.readline().strip())\r\n\r\nb = list(map(int,sys.stdin.readline().strip().split()))\r\n\r\ncurrent_length = 1\r\n\r\nmax_length = 1\r\n\r\nfor i in range(1, n):\r\n if b[i] >= b[i-1]:\r\n current_length += 1\r\n else:\r\n max_length = max(max_length, current_length)\r\n current_length = 1\r\nmax_length = max(max_length, current_length)\r\nprint(max_length)",
"n= int(input())\r\nlisty=list(map(int, input().split()))\r\n\r\nseq=1\r\nmaxseq=1\r\nfor i in range(1,n):\r\n if(listy[i]>=listy[i-1]):\r\n seq+=1\r\n else:\r\n seq=1\r\n if(seq>maxseq):\r\n maxseq=seq\r\n\r\nprint(maxseq)\r\n\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\narr.append(0)\r\nlength = 0\r\nnew_lenght = 1\r\narr_old = arr[0]\r\nfor i in range(n):\r\n if arr[i+1] >= arr_old: new_lenght += 1 \r\n else:\r\n if new_lenght > length: \r\n length = new_lenght\r\n new_lenght = 1\r\n else: new_lenght = 1\r\n arr_old = arr[i+1]\r\nprint(length)",
"n=int(input())\r\n\r\nsub=[]\r\nseq=list (map (int , input().split()))\r\n\r\ns=1\r\nif len(seq)>1:\r\n for i in range(1,len(seq)):\r\n if seq[i]>=seq[i-1]:\r\n s=s+1\r\n else:\r\n sub.append(s)\r\n s=1\r\n sub.append(s)\r\n print(max(sub))\r\n\r\nif len(seq)==1:\r\n print(1)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))[:n]\r\nmax=0\r\ncount=1\r\nfor i in range(1,n):\r\n if l[i]>=l[i-1]:\r\n count+=1\r\n else:\r\n if(count>max):\r\n max=count\r\n count=1\r\nif count>max:\r\n max=count\r\nprint(max)",
"# @name: A. Kefa and First Steps\r\n# @author: AbrarShakhi\r\n# @link: https://codeforces.com/problemset/problem/580/A\r\n\r\n\r\nn = int(input())\r\na = [*map(int, input().split())]\r\n\r\nmax_len = 1\r\ncurr_len = 1\r\nfor i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n curr_len += 1\r\n else:\r\n curr_len = 1\r\n max_len = max(max_len, curr_len)\r\n\r\nprint(max_len)",
"n=int(input())\nl=[int(x) for x in input().split()]\nnl=[]\nk=1\ns=0\nfor i in range(len(l)-1):\n if l[i+1]>=l[i]:\n k+=1\n else:\n nl.append(k)\n k=1\nnl.append(k)\nprint(max(nl))\n \t \t\t \t\t\t\t\t\t \t\t\t \t \t\t\t",
"n = int(input())\r\nA = list(map(int, input().split()))\r\n\r\nprev_no = A[0]\r\nmax_len = 1\r\ntemp_max = 1\r\nfor i in range(1, n):\r\n if prev_no <= A[i]:\r\n temp_max += 1\r\n prev_no = A[i]\r\n else:\r\n max_len = max(max_len, temp_max)\r\n prev_no = A[i]\r\n temp_max = 1\r\nmax_len = max(max_len, temp_max)\r\n\r\nprint(max_len)",
"n = int(input())\r\nsequence = list(map(int, input().split()))\r\n\r\nmax_length = 1 # length of the maximum non-decreasing subsegment\r\ncurrent_length = 1 # length of the current non-decreasing subsegment\r\n\r\nfor i in range(1, n):\r\n if sequence[i] >= sequence[i-1]:\r\n current_length += 1\r\n max_length = max(max_length, current_length)\r\n else:\r\n current_length = 1\r\n\r\nprint(max_length)\r\n",
"a=int(input())\r\nb=list(map(int,input().split()))\r\no=1\r\nl=1\r\nfor x in range(1,len(b)):\r\n if b[x]>=b[x-1]:\r\n l+=1\r\n o=max(o,l)\r\n else:\r\n l=1\r\nprint(o)",
"\r\ndef Kefa_First_Steps(list_a):\r\n max_length = 1\r\n current_length = 1\r\n for i in range(1 , len(list_a)):\r\n if list_a[i] >= list_a[i-1]:\r\n current_length += 1\r\n else :\r\n current_length = 1\r\n max_length = max(max_length , current_length)\r\n return max_length\r\n\r\nif __name__ == \"__main__\" :\r\n n = int(input())\r\n list_a = list(map(int , input().split()[:n]))\r\n print(Kefa_First_Steps(list_a))",
"n = int(input())\nprofits = list(map(int, input().split()))\n\nl = 1\nml = 1\n\nfor i in range(1, n):\n if profits[i] >= profits[i - 1]:\n l += 1\n ml = max(ml, l)\n else:\n l = 1\n\nprint(ml)\n\n \t \t\t\t\t\t\t \t\t \t \t\t\t\t \t",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nml = 1\r\nres = [1]\r\nfor i in range(1,len(l)):\r\n if l[i-1] <= l[i] and i == len(l)-1:\r\n res.append(ml + 1)\r\n ml += 1\r\n elif l[i-1] <= l[i]:\r\n ml += 1\r\n else:\r\n res.append(ml)\r\n ml = 1\r\nprint(max(res))",
"num = int(input())\r\nchars = input().split(\" \")\r\nnumbers = []\r\ntotal_len = 0\r\n\r\nfor i in chars:\r\n numbers.append(int(i))\r\n\r\nlength = 1\r\nlenghts = []\r\n\r\nfor i in range(len(numbers) - 1):\r\n one = numbers[i] \r\n sec = numbers[i + 1] \r\n if one <= sec:\r\n length += 1\r\n else:\r\n lenghts.append(length)\r\n length = 1\r\nlenghts.append(length)\r\n\r\nprint(max(lenghts))\r\n \r\n\r\n\r\n",
"length = int(input())\r\nnums = list(map(int,input().split()))\r\ncount = 1\r\nmaxCount = 0\r\nfor index in range(1 , length) :\r\n if nums[index] >= nums[index - 1] : count += 1 \r\n else : \r\n if count > maxCount : maxCount = count\r\n count = 1\r\nprint(maxCount if maxCount > count else count)",
"n=int(input())\r\ndp=[1]+[0]*(n-1)\r\nsequence=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n if sequence[i]>=sequence[i-1]:\r\n dp[i]=dp[i-1]+1\r\n else:\r\n dp[i]=1\r\nprint(max(dp))",
"n = int(input())\r\narray = list(map(int, input().split()))\r\n\r\nhigh = 1\r\nhighest = 1\r\n\r\nfor j in range(1, n):\r\n if array[j] >= array[j - 1]:\r\n high += 1\r\n if high > highest:\r\n highest = high\r\n else:\r\n high = 1\r\n\r\nprint(highest)\r\n",
"import math\r\n# Shortcut for input\r\ndef I(): return int(input())\r\ndef MI(): return map(int, input().split())\r\ndef LI(): return list(map(int, input().split()))\r\ndef S(): return input()\r\n# Constants\r\nmod = 10**9 + 7\r\nn = I()\r\na = LI()\r\ndef main(a):\r\n l = 0 \r\n r= 1 \r\n ans = 0\r\n if len(a)==1:\r\n return 1\r\n while r <len(a):\r\n if a[r-1] <= a[r]:\r\n r+=1\r\n else:\r\n ans = max(ans,r-l)\r\n l = r \r\n r+=1\r\n if r > l:\r\n ans = max(ans,r-l)\r\n return ans\r\nprint(main(a)) ",
"n = int(input())\r\nlst = input().split()\r\nlst = [int(ele) for ele in lst]\r\nmax_count = 0\r\ncount = 0\r\n\r\nfor i in range(0,n-1):\r\n if lst[i] <= lst[i+1]:\r\n count+=1\r\n else:\r\n max_count = max(max_count,count)\r\n count = 0\r\n\r\nmax_count = max(max_count,count)\r\nprint(max_count+1)",
"n = int(input())\r\narr = [int(x) for x in input().split()]\r\nres = 1\r\ncurr = 1\r\nfor i in range(1,n):\r\n if(arr[i-1]>arr[i]):\r\n res = max(res, curr)\r\n curr = 1\r\n else:\r\n curr+=1\r\nprint(max(res,curr))",
"# Read the number of days\r\nn = int(input())\r\n\r\n# Read the sequence of money made on each day\r\na = list(map(int, input().split()))\r\n\r\n# Initialize variables to keep track of the current subsegment length and the maximum subsegment length\r\ncurrent_length = 1\r\nmax_length = 1\r\n\r\n# Iterate through the sequence starting from the second element\r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n # If the current day's earnings are greater or equal to the previous day's earnings,\r\n # increment the current subsegment length\r\n current_length += 1\r\n else:\r\n # If the current day's earnings are less than the previous day's earnings,\r\n # reset the current subsegment length to 1\r\n current_length = 1\r\n \r\n # Update the maximum subsegment length if needed\r\n max_length = max(max_length, current_length)\r\n\r\n# Print the maximum non-decreasing subsegment length\r\nprint(max_length)\r\n",
"n = int(input())\nnumbers = list(map(int, input().split()))\n\nmax_length = 1\ncurrent_length = 1\n\nfor i in range(1, n):\n if numbers[i] >= numbers[i-1]:\n current_length += 1\n max_length = max(max_length, current_length)\n else:\n current_length = 1\n\nprint(max_length)\n\n\t \t \t \t \t\t\t \t \t \t \t\t",
"n=int(input());arr=list(map(int,input().split()));c=1;m=1\r\nfor i in range(1,n):\r\n if arr[i] >= arr[i-1]:c+=1\r\n else:c=1\r\n m=max(c,m)\r\nprint(m)",
"testes = int(input())\n\ncom_max = 1 \ncom_atual = 1\nlista = []\n\nn=input().strip().split()\n\n\nfor i in range(0,testes):\n n[i] = int(n[i])\n lista.append(n[i])#[2 , 2 , 1 , 3 , 4 ,1]\n\nfor i in range(1 , len(lista)):\n #verificar se o elemento atual lista[i] e maior ou igual ao\n #elemento anterior lista[i-1]\n if lista[i] >= lista[i-1]:\n com_atual= com_atual+1\n #se for maior logo a lista nao esta diminuindo\n else:\n #caso nao a sequencia foi quebrada logo reiniciamos\n #o comprimento atual com 1\n com_atual = 1\n\n com_max = max(com_max,com_atual) \nprint(com_max)\n\n \t\t\t\t\t \t\t\t\t\t\t\t\t\t \t\t\t\t \t \t",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ni = 0\r\nj = 1\r\nsum_1 = 1\r\nsum_0 = 1\r\n\r\nwhile i < n > j:\r\n if arr[j] < arr[j - 1]:\r\n i = j\r\n j += 1\r\n if sum_0 >= sum_1:\r\n sum_1 = sum_0\r\n sum_0 = 1\r\n\r\n elif arr[j] > arr[j - 1] or arr[j] == arr[j - 1]:\r\n sum_0 += 1\r\n j += 1\r\n\r\nif sum_0 > sum_1:\r\n print(sum_0)\r\nelse:\r\n print(sum_1)\r\n\r\n\r\n",
"n = int(input())\r\ns = input().split()\r\nc, m = 0, 0\r\nfor j in range(n-1):\r\n if int(s[j])<=int(s[j+1]):\r\n c+=1\r\n else:\r\n if c>m:\r\n m = c\r\n c = 0\r\nelse:\r\n if c>m:\r\n m = c\r\nprint (m+1) \r\n",
"n=int(input())\r\nls=list(map(int,input().split()))\r\ncount=1\r\ncount2=1\r\nfor i in range(1,len(ls)):\r\n if ls[i-1]<=ls[i]:\r\n count+=1\r\n else:\r\n count=1\r\n if count>count2:\r\n count2=count\r\nprint(count2)",
"def main():\r\n n = int(input())\r\n inputs = input().split() # Split the input into individual integers\r\n last = int(inputs[0])\r\n curLen = 1\r\n result = 1\r\n \r\n for i in range(1, n):\r\n in_val = int(inputs[i])\r\n if in_val >= last:\r\n curLen += 1\r\n else:\r\n curLen = 1\r\n result = max(result, curLen)\r\n last = in_val\r\n \r\n print(result)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"count = 1\r\nans = 0\r\nn=int(input())\r\nrow = list(map(int,input().split()))\r\nfor i in range(n-1):\r\n if row[i]<= row[i+1]:\r\n count += 1\r\n else:\r\n ans = max(ans,count)\r\n count = 1\r\nprint(max(ans,count))",
"# cook your dish here\r\nn=int(input())\r\nli=[int(x) for x in input().split()]\r\nc=0\r\nans=0\r\nflag=0\r\nfor i in range(0,n-1):\r\n \r\n ans=max(c,ans)\r\n # print(ans)\r\n if(li[i]<=li[i+1]):\r\n c=c+1\r\n #print(c)\r\n else:\r\n c=0\r\nprint(max(ans,c)+1) ",
"x=int(input())\r\nlist1=[int(i) for i in input().split(\" \")]\r\n\r\nstreak=1\r\ntotal=1\r\ncurr=list1[0]\r\nfor i in range(1,x):\r\n if list1[i]>=curr:\r\n curr=list1[i]\r\n total+=1\r\n elif list1[i]<curr:\r\n curr=list1[i]\r\n if total>=streak:\r\n streak=total\r\n total=1\r\n else:\r\n total=1\r\n\r\nif total>=streak:\r\n streak=total\r\nprint(streak)\r\n\r\n",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\na.append(0)\r\n\r\ncount = [a[0]]\r\nmaxcount = 0\r\nfor number in a[1:]:\r\n if number < count[-1]:\r\n if len(count) > maxcount:\r\n maxcount = len(count)\r\n count = [number]\r\n else:\r\n count.append(number)\r\nprint(maxcount)",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nans, j = 1, 1\r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n j += 1\r\n else:\r\n ans = max(ans, j)\r\n j = 1\r\nprint(max(ans, j))",
"n=int(input())\r\np=list(map(int,input().split()))\r\nm=1\r\nv=1\r\nvv=1\r\np.append(-10000)\r\nfor i in p[:-1]:\r\n if i<=p[m]:\r\n v+=1\r\n m+=1\r\n if v>vv:\r\n vv=v\r\n else:\r\n m+=1\r\n v=1\r\nprint(vv)",
"n = int(input())\r\ndays = list(map(int, input().split()))\r\ncounter = 0\r\n\r\nresult = [0]\r\n\r\nfor i in range(1, len(days)):\r\n if(days[i] >= days[i-1]):\r\n counter += 1\r\n result.append(counter)\r\n else:\r\n counter = 0\r\n result.append(counter) \r\n \r\nprint(max(result)+1)",
"n=int(input())\r\nl1=list(map(int,input().split()))\r\nx=1\r\nans=1\r\nfor i in range(n-1):\r\n if l1[i]<=l1[i+1]:\r\n x+=1\r\n ans=max(ans,x)\r\n else:\r\n x=1\r\n ans=max(ans,x)\r\nprint(ans)",
"def kefa_and_first_steps(arr):\r\n max_length = 1\r\n current_length = 1\r\n\r\n for i in range(1, len(arr)):\r\n if arr[i] >= arr[i - 1]:\r\n current_length += 1\r\n else:\r\n current_length = 1\r\n\r\n max_length = max(max_length, current_length)\r\n\r\n return max_length\r\n\r\ndef main():\r\n n = int(input()) \r\n arr = list(map(int, input().split()))\r\n\r\n result = kefa_and_first_steps(arr)\r\n print(result)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"a=int(input())\r\nq=list(map(int,input().split()))\r\nmax=1\r\nu=1\r\nfor i in range(1,len(q)):\r\n if q[i-1]<=q[i]:\r\n u+=1\r\n if max<u:max=u\r\n else:u=1\r\nprint(max)",
"n = int(input())\na = list(map(int, input().split()))\n\n# Almacenamos las longitudes del\n# subsegmento maximo (no creciente)\nsubMax = [1] * n\n\nfor i in range(1, n):\n if a[i] >= a[i-1]:\n # Si valor actual es mayor al valor\n # siguiente \n subMax[i] = subMax[i-1] + 1\n\nmax_length = max(subMax)\nprint(max_length)\n\n \t \t\t \t \t\t \t \t\t\t \t\t \t \t",
"# input\r\n\r\ndays = int(input())\r\narray = input().split(\" \")\r\narray = [int(num) for num in array]\r\n\r\nm = 0\r\nlength = [0]\r\n\r\nfor n in array:\r\n if n >= m:\r\n length[-1] += 1\r\n else:\r\n length.append(1)\r\n\r\n m = n\r\n\r\n\r\n\r\nprint(max(length))\r\n",
"n = int(input())\r\nsubsegment = list(map(int,input().split()))\r\nif n == len(subsegment):\r\n lst = []\r\n for i in range(len(subsegment)-1):\r\n if subsegment[i] <= subsegment[i+1]:\r\n lst.append(1)\r\n else:\r\n lst.append(0)\r\n word = \"\".join(list(map(str,lst)))\r\n word_lst = word.split(\"0\")\r\n num = max([len(letter) for letter in word_lst])\r\n print(num+1)",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nans = 1\r\ntemp = 1\r\nfor i in range(n-1):\r\n if l[i] <= l[i+1]:\r\n temp += 1\r\n else:\r\n if temp >= ans:\r\n ans = temp\r\n temp = 1\r\nif temp > ans:\r\n ans = temp\r\nprint(ans)\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nans=[0]\r\nc=1\r\nfor i in range(n-1):\r\n if a[i+1]>=a[i]:\r\n c+=1\r\n else:\r\n ans.append(c)\r\n c=1\r\n i+=1\r\nprint(max(max(ans),c))\r\n ",
"n = int(input())\r\norder = [int(i) for i in input().split()]\r\ncount = 0\r\nmax_value = 0\r\n\r\nfor i in range(1, n):\r\n if order[i] >= order[i-1]:\r\n count += 1\r\n else:\r\n count = 0\r\n if count > max_value:\r\n max_value = count\r\nmax_value += 1\r\nprint(max_value)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nl = []\r\nans = 1\r\nfor i in range(len(a)):\r\n if i+1== len(a):\r\n l.append(ans)\r\n break\r\n else:\r\n if a[i+1] >= a[i]:\r\n ans+=1\r\n else:\r\n l.append(ans)\r\n ans = 1\r\nprint(max(l, default = 0))",
"n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\nans = 1\r\ncurrent = 1\r\nfor i in range(1, n):\r\n\tif a[i] < a[i-1]:\r\n\t\tcurrent = 1\r\n\telse:\r\n\t\tcurrent+=1\r\n\t\tans = max(ans, current)\r\n\r\nprint(ans)",
"n = int(input())\na = list(map(int,input().split()))\nc = 1 \nm = 0 \nfor i in range(1,n):\n if a[i-1]<=a[i]:\n c+=1 \n else:\n m = max(c,m) \n c = 1\nm = max(m,c)\nprint(m)",
"num = int(input())\r\nnumbers = [int(i) for i in input().split(\" \")]\r\ntotal_len = 0\r\nlength = 1\r\nlenghts = []\r\nfor i in range(len(numbers) - 1):\r\n one = numbers[i] \r\n sec = numbers[i + 1] \r\n if one <= sec:\r\n length += 1\r\n else:\r\n lenghts.append(length)\r\n length = 1\r\nlenghts.append(length)\r\nprint(max(lenghts))",
"# To solve this problem, we can iterate through the sequence and keep track of the current non-decreasing\n# subsegment's length and the maximum length encountered so far. Here's the algorithm:\n#\n# Read the value of n, the number of elements in the sequence. Read the sequence of n integers. Initialize two\n# variables: maxLength = 1 (minimum length is always 1) and currentLength = 1 (initialize with the first element).\n# Iterate from i = 1 to n-1:\n# a. If ai is greater than or equal to ai-1, increment currentLength by 1.\n# b. Otherwise, reset currentLength to 1.\n# c. Update maxLength if currentLength is greater than maxLength. Print the value of maxLength.\n\nn = int(input())\nsequence = list(map(int, input().split()))\n\nmaxLength = 1\ncurrentLength = 1\n\nfor i in range(1, n):\n if sequence[i] >= sequence[i - 1]:\n currentLength += 1\n else:\n currentLength = 1\n maxLength = max(maxLength, currentLength)\n\nprint(maxLength)\n",
"import math\r\ndef readint():\r\n return int(input())\r\n \r\ndef readarray(typ):\r\n return list(map(typ, input().split()))\r\n\r\n\r\nn = readint()\r\nprofit = readarray(int)\r\n\r\nmaxStreak = -float(\"inf\")\r\ncurrStreak = 1\r\n\r\nfor i in range(1, n):\r\n if profit[i] >= profit[i-1]: currStreak += 1\r\n else: \r\n maxStreak = max(maxStreak, currStreak)\r\n currStreak = 1\r\n\r\nprint(max(maxStreak, currStreak))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nlen=1\r\nans=1\r\nfor i in range(n-1):\r\n if(a[i+1]>=a[i]):\r\n len=len+1\r\n else:\r\n ans=max(ans,len)\r\n len=1\r\nprint(max(len,ans))",
"\r\nn = int(input())\r\nnums = [int(x) for x in input().split()]\r\nbest = 1\r\ncurrent = 1\r\nfor i in range(1, n, 1):\r\n if nums[i] < nums[i - 1]:\r\n current = 1\r\n else:\r\n current += 1\r\n best = max(current, best)\r\nprint(best)\r\n",
"n=int(input())\r\nm=list(map(int,input().split()))\r\nc1=1\r\nc2=1\r\nfor i in range(0,n-1):\r\n if m[i]<=m[i+1]:\r\n #print(m[i],m[i+1])\r\n c2 +=1\r\n elif m[i]>m[i+1]:\r\n if c2>c1:\r\n c1=c2\r\n c2=1\r\nif c2 > c1:\r\n c1 = c2\r\nprint(c1)",
"def main():\n n = int(input())\n a = [int(x) for x in input().split()]\n print(solve(n, a))\n\ndef solve(n, a):\n dp = [0] * n\n ans = 0\n for index in range(n):\n if index >= 0 and a[index] >= a[index - 1]:\n dp[index] = dp[index - 1] + 1\n else:\n dp[index] = 1\n ans = max(ans, dp[index])\n return ans\n \n\nmain()",
"def solution(n, a):\n if a == sorted(a):\n return len(a)\n\n curr_count = 1\n lengths_of_subsegments = []\n i = 0 # Initialize 'i' outside of the while loop\n\n while i < n - 1:\n if a[i] <= a[i + 1]:\n curr_count += 1\n i += 1\n else:\n lengths_of_subsegments.append(curr_count)\n curr_count = 1 # Reset 'curr_count'\n i += 1\n lengths_of_subsegments.append(curr_count) # Add the last subsegment\n\n return max(lengths_of_subsegments)\n\nn = int(input())\na = list(map(int, input().split()))\nprint(solution(n, a))",
"n=int(input())\r\nsp=[int(i) for i in input().split()]\r\ncnt=1\r\nmx=1\r\nfor i in range(len(sp)-1):\r\n if sp[i+1]>=sp[i]:\r\n cnt+=1\r\n if cnt>mx:\r\n mx=cnt\r\n else:\r\n cnt=1\r\nprint(mx)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nk, m = 1, 0\r\nfor i in range(n - 1):\r\n if a[i] <= a[i+1]:\r\n k += 1\r\n else:\r\n m = max(m, k)\r\n k = 1\r\nm = max(m, k)\r\nprint(m)\r\n",
"x = int(input())\r\na = [int(i) for i in input().split()]\r\nans, cur, last = -1, 0, 0\r\nfor i in a:\r\n if i >= last:\r\n cur += 1\r\n else:\r\n ans = max(cur, ans)\r\n cur = 1\r\n last = i\r\nprint(max(cur, ans))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ncounta=countb=0\r\ni=1\r\nwhile i<n:\r\n if a[i]>=a[i-1]:\r\n countb+=1\r\n else:\r\n if counta<countb:\r\n counta=countb\r\n countb=0\r\n i+=1\r\nif counta<countb:\r\n\r\n print(countb+1)\r\nelse:\r\n print(counta+1)",
"import sys\r\nfrom os import path\r\nif (path.exists('input.txt')):\r\n\tsys.stdin = open('input.txt', 'r')\r\n\tsys.stdout = open('output.txt','w')\r\n\r\nn = int(input())\r\narr = [int(x) for x in input().split()]\r\ntemp = best = 0\r\nfor i in range (n-1):\r\n\tif arr[i]<=arr[i+1]:\r\n\t\ttemp += 1\r\n\telse:\r\n\t\ttemp = 0\r\n\tbest = max(temp, best)\r\nprint(best + 1)",
"def max_non_decreasing_subsegment(n, arr):\r\n max_length = 1\r\n current_length = 1\r\n\r\n for i in range(1, n):\r\n if arr[i] >= arr[i-1]:\r\n current_length += 1\r\n else:\r\n max_length = max(max_length, current_length)\r\n current_length = 1\r\n\r\n return max(max_length, current_length)\r\n\r\n# Read input\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\n# Calculate the length of the maximum non-decreasing subsegment\r\nresult = max_non_decreasing_subsegment(n, arr)\r\n\r\n# Print the result\r\nprint(result)\r\n",
"n = int(input())\narr = [int(x) for x in input().split(' ')]\n\ncount = 1\nmax = 1\n\nfor i in range(n-1):\n if (arr[i] > arr[i+1]):\n if (count > max):\n max = count\n count = 1\n else:\n count+=1\n\nif ( count > max):\n max = count\nprint(max)\n\n\n \t\t \t \t\t\t\t \t\t \t\t\t \t\t\t \t \t",
"n = int(input())\nar = list(map(int, input().split()))#\nmax_count = 1\ncount = 1\n\nfor i in range(1, n):\n if ar[i-1] <= ar[i]:\n count += 1\n if count > max_count:\n max_count = count\n else:\n count = 1\nprint(max_count)\n\t \t \t\t \t \t \t \t\t\t \t \t \t\t \t\t\n\t \t \t \t\t \t\t\t\t \t\t \t \t\n\t \t \t\t \t \t\t\t \t\t \t\t \t\t\t\t\t \t\t",
"n = int(input()) # Number of days\r\na = list(map(int, input().split())) # Number of candies each day\r\n\r\nmax_sequence = 1 # Maximum consecutive non-decreasing sequence length\r\ncurrent_sequence = 1 # Current consecutive non-decreasing sequence length\r\n\r\n# Iterate through the candies starting from the second day\r\nfor i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n # Current candy is greater than or equal to the previous one\r\n current_sequence += 1\r\n else:\r\n # Current candy is smaller than the previous one\r\n current_sequence = 1\r\n\r\n # Update the maximum sequence length if necessary\r\n max_sequence = max(max_sequence, current_sequence)\r\n\r\nprint(max_sequence)\r\n",
"n = int(input())\na = list(map(int, input().split(' ')))\nb = [0]*n\nb[0] = 1\nfor i in range(1, n):\n if(a[i-1] <= a[i]):\n b[i] = b[i-1]+1\n else:\n b[i] = 1\nprint(max(b))",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nx=ans=1\r\nfor i in range(n-1):\r\n if a[i]<=a[i+1]:\r\n x += 1\r\n else:\r\n if x > ans:\r\n ans = x\r\n x = 1\r\nif x > ans:\r\n ans = x\r\nprint(ans)",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\ndp = [1]\r\n\r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n dp.append(dp[i - 1] + 1)\r\n else:\r\n dp.append(1) \r\n\r\nprint(max(dp))",
"n = int(input())\narr = list(map(int, input().split()))\nmax = 1\ncount = 1\nfor i in range(1, len(arr)):\n if arr[i-1] <= arr[i]:\n count += 1\n if count > max:\n max = count\n else:\n count = 1\nprint(max)\n\n \t\t\t\t\t \t \t\t \t\t\t \t\t\t\t \t \t\t",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndef length(n, a):\r\n maxlen = 1\r\n cnt = 1\r\n for i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n cnt += 1\r\n else:\r\n cnt = 1\r\n maxlen = max(maxlen, cnt)\r\n return maxlen\r\n\r\nprint(length(n, a))",
"days = int(input())\r\nmoney = list(map(int, input().split()))\r\n\r\nseq = 1\r\ncurrent_seq = 1\r\n\r\nfor i in range(1, len(money)):\r\n if money[i] >= money[i - 1]:\r\n current_seq += 1\r\n else:\r\n current_seq = 1\r\n seq = max(seq, current_seq)\r\n\r\nprint(seq)",
"def solve():\r\n n = int(input())\r\n seq = list(map(int,input().split()))\r\n c = 1\r\n count = []\r\n for i in range(len(seq)-1):\r\n if seq[i] <= seq[i+1]:\r\n c += 1\r\n elif seq[i] > seq[i+1]:\r\n count.append(c)\r\n c = 1\r\n count.append(c)\r\n \r\n print(max(count))\r\nsolve()\r\n ",
"n = int(input()) # Число дней\r\nearnings = list(map(int, input().split())) # Заработки в каждый день\r\n\r\nmax_length = 1 # Максимальная длина подотрезка\r\ncurrent_length = 1 # Текущая длина подотрезка\r\n\r\n# Проходим по заработкам, начиная со второго дня\r\nfor i in range(1, n):\r\n if earnings[i] >= earnings[i - 1]:\r\n current_length += 1\r\n max_length = max(max_length, current_length)\r\n else:\r\n current_length = 1\r\n\r\n# Выводим максимальную длину подотрезка\r\nprint(max_length)",
"b=int(input())\r\nk=1\r\nq=1\r\na=list(map(int,input().split()))\r\nfor i in range(b-1):\r\n if a[i+1]>=a[i]:\r\n k+=1\r\n else:\r\n k=1\r\n q=max(q,k)\r\nprint(q)\r\n",
"n = int(input())\n\narr = list(map(int,input().split()))\n\ndef calcSubSegment(arr):\n mx = 0\n pindex = arr[0]\n subSegmentLen = 0\n\n for elem in arr:\n \n if elem < pindex:\n subSegmentLen = 1\n \n else:\n subSegmentLen +=1\n mx = subSegmentLen if subSegmentLen > mx else mx\n \n pindex = elem\n \n return mx\n\nprint(calcSubSegment(arr))\n\t\t\t\t\t \t \t\t\t\t \t \t\t\t\t\t\t\t \t\t",
"n = int(input())\r\nb = [int(x) for x in input().split()]\r\ncnt = 1\r\nans = 1\r\nfor i in range(1, len(b)):\r\n if b[i] >= b[i - 1]:\r\n cnt += 1\r\n else:\r\n cnt = 1\r\n if cnt > ans:\r\n ans = cnt\r\nprint(ans)",
"x = int(input())\r\nlist_1 = list(map(int, input().split()))\r\nlist_2 = []\r\ncnt = 1\r\n\r\nfor i in range(1, len(list_1)):\r\n if list_1[i] >= list_1[i-1]:\r\n cnt+=1\r\n else:\r\n list_2.append(cnt)\r\n cnt = 1\r\nlist_2.append(cnt)\r\nprint(max(list_2))",
"n = int(input())\r\nx = [int(x) for x in input().split(\" \")]\r\nx.append(0)\r\nmax_cnt = 1\r\ncnt = 1\r\n\r\nfor i in range(1, len(x)):\r\n if x[i] >= x[i - 1]:\r\n cnt += 1\r\n else:\r\n if cnt > max_cnt:\r\n max_cnt = cnt\r\n cnt = 1\r\nprint(max_cnt)",
"def kefa(n, lst):\n l = 1\n mx = 1\n for i in range(n-1):\n if lst[i] <= lst[i+1]:\n l += 1\n else:\n l = 1\n mx = max(mx, l)\n\n return mx\n\n\nn = int(input())\nlst = list(map(int, input().split()))\nprint(kefa(n, lst))\n\t \t \t \t \t \t \t \t\t\t \t\t\t\t",
"def min_non_decreasing():\r\n num = int(input())\r\n numbers = list(map(int, input().split(' ')))\r\n lenght = 1\r\n max_lenght = 1\r\n for i in range(1, num):\r\n if numbers[i] >= numbers[i - 1]:\r\n lenght += 1\r\n else:\r\n max_lenght = max(max_lenght, lenght)\r\n lenght = 1\r\n\r\n max_lenght = max(max_lenght, lenght)\r\n print(max_lenght)\r\n\r\n\r\nmin_non_decreasing()\r\n",
"numbers_days = int(input())\r\nmoney_days = list(map(int,input().split(' ')))\r\ni = 0\r\ncounts = []\r\ncount = 0\r\nwhile i < numbers_days:\r\n if i==0:\r\n count=1\r\n else:\r\n if money_days[i]>=money_days[i-1]:\r\n count+=1\r\n else:\r\n counts.append(count)\r\n count=1\r\n i+=1\r\nif len(counts)==0 or count!=counts[-1] :\r\n counts.append(count)\r\nprint(max(counts))",
"input()\r\na = [int(i) for i in input().split()]\r\nc, k = 1, 1\r\nfor i in range(1, len(a)):\r\n\tif(a[i] >= a[i - 1]):\r\n\t\tc += 1\r\n\telse:\r\n\t\tk = max(k, c)\r\n\t\tc = 1\r\nprint(max(k, c))",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nh = 1;\r\nH = 1;\r\nfor i in range(1,n):\r\n if(l[i]>=l[i-1]):\r\n h+=1\r\n if(h>H):\r\n H = h \r\n else:\r\n continue\r\n\r\n else:\r\n h = 1\r\nprint(H)",
"n = int(input())\r\na = list(map(int, input().split(' ')))\r\nc, mc = 0, 0\r\nfor i in range(1, n):\r\n if a[i-1] <= a[i]:\r\n c += 1\r\n else:\r\n if c > mc:\r\n mc = c\r\n c = 0\r\n if c > mc:\r\n mc = c\r\nprint(mc+1)",
"n = int(input())\r\n\r\ndayList = [int(x) for x in input().split()]\r\n\r\nmaxSeq = 0\r\npreSeq = 0\r\n\r\nfor i in range(n-1):\r\n if dayList[i+1] >= dayList[i]:\r\n preSeq += 1\r\n else:\r\n if preSeq > maxSeq:\r\n maxSeq = preSeq\r\n preSeq = 0\r\nif preSeq > maxSeq:\r\n maxSeq = preSeq \r\nprint(maxSeq+1)\r\n ",
"n = int(input())\nx = list(map(int, input().split()))\n\nmax_length = 1\ncurrent_length = 1\n\nfor i in range(1, n):\n if x[i] >= x[i-1]:\n current_length += 1\n else:\n current_length = 1\n\n max_length = max(max_length, current_length)\nprint(max_length)\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nc = 1\r\nmc = 1 # mc = 0 is an error for 5 4 3 2 1\r\np = a[0]\r\nfor v in a[1:]:\r\n if p <= v:\r\n c += 1\r\n mc = max(mc, c)\r\n else:\r\n c = 1\r\n p = v\r\nprint(mc)\r\n\r\n",
"def kefa():\r\n l = int(input())\r\n array = list(map(int,input().split()))\r\n points=[];count=1\r\n for i in range(1,l):\r\n if array[i]<array[i-1]:\r\n points.append(count)\r\n count=1\r\n else:\r\n count+=1\r\n points.append(count)\r\n return max(points)\r\nprint(kefa())",
"n=int(input())\r\na=list(map(int,input().split()))\r\nmaxim=1\r\ncurr=1\r\nfor i in range(1,n):\r\n if a[i]>=a[i-1]:\r\n curr+=1\r\n maxim=max(maxim,curr)\r\n else:\r\n curr=1\r\nprint(maxim)",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nma,c=0,1\r\nfor i in range(1,n):\r\n if a[i-1]<=a[i]:\r\n c+=1\r\n else:\r\n ma=max(c,ma)\r\n c=1\r\nma=max(c,ma)\r\nprint (ma)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nans=0\r\nmaxi=0\r\nfor i in range(n-1):\r\n if(l[i]<=l[i+1]):\r\n ans+=1\r\n maxi=max(maxi,ans)\r\n else:\r\n ans=0\r\nprint(maxi+1)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ncnt=1\r\nmx=-1\r\npr=l[0]\r\nfor i in range (1,n):\r\n if cnt>mx:\r\n mx=cnt\r\n if l[i]<pr:\r\n cnt=1\r\n else:\r\n cnt+=1\r\n pr=l[i]\r\nif cnt>=mx:\r\n mx=cnt\r\nprint(mx)",
"\r\n\r\n\r\n\r\ndef solution(T):\r\n\tn=int(input())\r\n\tl=list(map(int,input().split()))\r\n\r\n\tmx,c,p=0,0,0\r\n\tfor i in l:\r\n\t\tif i>=p:\r\n\t\t\tc+=1\r\n\t\t\tmx=max(c,mx)\r\n\t\telse:\r\n\t\t\tc=1\r\n\t\t\tp=i\r\n\t\tp=i\r\n\tprint(mx)\r\n\r\n\r\nTT=1\r\n# TT=int(input())\r\nfor T in range(1,TT+1):\r\n\tsolution(T)",
"# Read input\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nmax_length = 1 # Initialize the maximum subsegment length as 1 (minimum length)\r\n\r\ncurrent_length = 1 # Initialize the current subsegment length as 1\r\n\r\n# Iterate through the list starting from the second element\r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n current_length += 1\r\n else:\r\n current_length = 1 # Reset the current length if the sequence is not non-decreasing\r\n \r\n max_length = max(max_length, current_length) # Update the maximum length\r\n\r\n# Output the result\r\nprint(max_length)\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nmx = 1\r\nc = 1\r\npr = a[0]\r\nfor i in range(1,n):\r\n if a[i] >= pr:\r\n c += 1\r\n else:\r\n mx = max(c,mx)\r\n c = 1\r\n pr = a[i]\r\nmx = max(mx,c)\r\nprint(mx)",
"n = int(input())\r\nmoney = list(map(int, input().split()))\r\nmax_count = 1\r\n\r\ncount = 1\r\nfor i in range(1, n):\r\n if money[i] < money[i - 1]:\r\n if max_count < count:\r\n max_count = count\r\n count = 1\r\n else:\r\n count += 1\r\n\r\nif max_count < count:\r\n max_count = count\r\n \r\nprint(max_count)# 1689949431.6428213",
"T = int(input())\r\na = list(map(int, input().split()))\r\nn = []\r\nc = 1\r\nfor i in range(0, T):\r\n for j in range(i+1, T):\r\n if a[i] <= a[j]:\r\n c += 1\r\n break\r\n else:\r\n n.append(c)\r\n c = 1\r\n break\r\nn.append(c)\r\nprint(max(n))",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nm = 1\r\nc = 1\r\n\r\nfor i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n c += 1\r\n else:\r\n c = 1\r\n m = max(m, c)\r\n\r\nprint(m)\r\n",
"n = int(input())\r\n\r\n\r\nresults = list(map(int, input().split()))\r\n\r\n# Using a stack\r\n\r\nstack = []\r\nmax_count = 0\r\nfor result in results:\r\n if stack and result >= stack[-1]:\r\n stack.append(result)\r\n else:\r\n if len(stack) > max_count:\r\n max_count = len(stack)\r\n while stack:\r\n stack.pop()\r\n stack.append(result)\r\n\r\nprint(max(max_count, len(stack)))\r\n\r\n\r\n\r\n",
"from typing import List, Union\r\nfrom collections import namedtuple\r\nimport sys\r\nimport traceback\r\nfrom datetime import datetime\r\nfrom time import perf_counter\r\n\r\n\r\n# Two Pointers Solution\r\nclass Solution:\r\n def kefa_steps(self, nums):\r\n result = 0\r\n if len(nums) == 1:\r\n result = 1\r\n left, right = 0, 1\r\n while left < len(nums):\r\n count = 1\r\n while right < len(nums) and nums[right] >= nums[right - 1]:\r\n right += 1\r\n count += 1\r\n result = max(result, count)\r\n left, right = right, right + 1\r\n print(result)\r\n return result\r\n\r\n\r\nTestCase = namedtuple('TestCase', 'nums correct')\r\n\r\n\r\ndef read_test_cases(input_file, output_file):\r\n test_cases: List[TestCase] = []\r\n try:\r\n with open(input_file) as in_f:\r\n with open(output_file) as out_f:\r\n while True:\r\n line = in_f.readline().strip()\r\n if not line or len(line) == 0:\r\n break\r\n line = line.strip()\r\n arr_len = int(line)\r\n nums = in_f.readline().strip().split()\r\n nums = [int(n) for n in nums]\r\n correct = int(out_f.readline().strip())\r\n test_cases.append(TestCase(nums, correct))\r\n # raise Exception('My Test Exception')\r\n except Exception as exc:\r\n exc_name = exc.__class__.__name__\r\n exc_msg = str(exc)\r\n exc_info = sys.exc_info()\r\n print('EXCEPTION:', exc_name, exc_msg)\r\n traceback.print_exception(*exc_info)\r\n return test_cases\r\n\r\n\r\ndef run_test_cases(test_cases: List[TestCase]):\r\n for t in test_cases:\r\n result = Solution().kefa_steps(t.nums)\r\n print('NUMS:', t.nums, 'CORRECT:', t.correct, 'RESULT:', result, 'CHECK:', result == t.correct)\r\n\r\n\r\nif __name__ == '__main__':\r\n if len(sys.argv) > 1 and '--debug' in sys.argv:\r\n date_str = datetime.utcnow().strftime('%Y.%m.%d %H:%M:%S')\r\n print('STARTING:', date_str)\r\n test_cases = read_test_cases('data/input.txt', 'data/output.txt')\r\n start_counter = perf_counter()\r\n run_test_cases(test_cases)\r\n stop_counter = perf_counter()\r\n print('COUNTER:', stop_counter - start_counter)\r\n else:\r\n arr_len = int(input())\r\n nums = []\r\n for _ in range(arr_len):\r\n items = []\r\n while True:\r\n ch = sys.stdin.read(1)\r\n if ch == ' ' or ch == '\\n':\r\n break\r\n items.append(ch)\r\n n = int(''.join(items))\r\n nums.append(n)\r\n # print(nums)\r\n Solution().kefa_steps(nums)\r\n",
"n = int(input())\r\nd = list(map(int,input().split()))\r\ncount=1\r\ncl=[]\r\nfor i in range(n-1):\r\n if d[i]<=d[i+1]:\r\n count+=1\r\n else:\r\n cl+=[count]\r\n count=1\r\ncl+=[count]\r\nprint(max(cl))",
"#B\nn = int(input())\ntmp = int(0)\ncount = int(0)\na = [int(x) for x in input().split()]\nfor i in range(1, n):\n if (a[i-1]<=a[i]):\n count+=1\n if (count>tmp):\n tmp = count\n else :\n count = 0\nprint(tmp+1)\n\t \t\t\t \t \t \t \t\t\t \t\t \t",
"num = int(input())\r\nmoney = [int(i) for i in input().split()]\r\nmaxCount = 0\r\ns_count = 0\r\nfor i in range(0,len(money)-1):\r\n if money[i+1]>=money[i]:\r\n s_count +=1\r\n else:\r\n s_count = 0\r\n maxCount = max(maxCount,s_count)\r\nprint(maxCount+1)",
"n = int(input())\r\na = list(map(int,input().split()))\r\nm = 1\r\nc = 1\r\nfor i in range(len(a)-1):\r\n if a[i] > a[i+1]:\r\n c = 1\r\n else:\r\n c += 1\r\n if m<c:\r\n m = c\r\nprint(m)",
"n=int(input())\r\nnumbers=[*map(int,input().split())]\r\ndp=[1]*n\r\nfor i in range(1,n):\r\n if numbers[i-1]<=numbers[i]:\r\n dp[i]+=dp[i-1]\r\nprint(max(dp))",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nhigh_score = 1\r\nscore = 1\r\nfor i in range(1, len(a)):\r\n if not a[i] < a[i-1]:\r\n score += 1\r\n high_score = max(high_score, score)\r\n else:\r\n score = 1\r\n\r\nprint(high_score)",
"a=int(input())\r\ns=list(map(int,input().split()))\r\nd=[0,1]\r\nfor i in range(2,a+1):\r\n if s[i-1]>=s[i-2]:\r\n d.append(d[i-1]+1)\r\n else:\r\n d.append(1)\r\nprint(max(d))",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nans=0\r\nm=1\r\nfor i in range(1,n):\r\n if arr[i-1]<=arr[i]:\r\n m+=1\r\n else:\r\n if m>ans:\r\n ans=m\r\n m=1\r\nif m>ans:\r\n ans=m\r\nprint(ans)",
"n=int(input())\r\na=list(map(int,input().split(' ')))\r\nres=[]\r\ncount=1\r\nfor i in range (1,len(a)):\r\n if a[i-1]>a[i]:\r\n res.append(count)\r\n count=1\r\n else:\r\n count+=1\r\nres.append(count)\r\nprint(max(res))",
"n = int(input())\nl1 = list(map(int,input().split()))\nans = 0\nfinal = 0\nfor i in range(n-1):\n if l1[i] <= l1[i+1]:\n ans += 1 \n else:\n final = max(ans,final)\n ans = 0\n final = max(ans,final)\nprint(final + 1)\n ",
"a=int(input())\r\nn=list(map(int, input().split()))\r\ns=0\r\nmaxi=0\r\nfor i in range(1, len(n)):\r\n if n[i]>=n[i-1]:\r\n s+=1\r\n else:\r\n s+=1\r\n if s>maxi:\r\n maxi=s\r\n s=0\r\ns+=1\r\nif s>maxi:\r\n maxi=s\r\ns=0\r\nprint(maxi)",
"n = int(input())\r\n\r\n# Read the sequence of numbers\r\nnumbers = list(map(int, input().split()))\r\n\r\n# Initialize variables\r\nmax_length = 1 # Initialize with 1 as a single number is always non-decreasing\r\ncurrent_length = 1\r\n\r\n# Iterate through the sequence\r\nfor i in range(1, n):\r\n if numbers[i] >= numbers[i - 1]:\r\n current_length += 1\r\n else:\r\n current_length = 1 # Reset the length for a new non-decreasing subsegment\r\n max_length = max(max_length, current_length)\r\n\r\n# Print the maximum length of a non-decreasing subsegment\r\nprint(max_length)",
"n = int(input())\r\nsequence = list(map(int, input().split()))\r\nmaxLen = 1\r\ncurrentLen = 1\r\nfor i in range(1, n):\r\n if sequence[i] >= sequence[i-1]:\r\n currentLen += 1\r\n else:\r\n maxLen = max(maxLen, currentLen)\r\n currentLen = 1\r\nmaxLen = max(maxLen, currentLen)\r\nprint(maxLen)\r\n",
"\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\ncount=0\r\nres=0\r\nfor i in range(n-1):\r\n if l[i]<=l[i+1]:\r\n count+=1\r\n else:\r\n count=0\r\n res=max(res,count)\r\nprint(res+1)\r\n ",
"n = map(int,input().split())\r\na = list(map(int,input().split()))\r\n\r\nlast_a = 0\r\nfirst_flag = 1\r\nmax_length = 0\r\ntotal_length = 0\r\n\r\nfor ai in a:\r\n if ai >= last_a or first_flag:\r\n if first_flag:\r\n first_flag = 0\r\n total_length += 1\r\n max_length = max(max_length, total_length)\r\n else:\r\n total_length = 1\r\n last_a = ai\r\n\r\nmax_length = max(max_length, total_length)\r\n\r\nprint(max_length)",
"n = int(input())\na = list(map(int, input().split()))\n\ncurr= 1\nres = 1\nfor i in range(1, n):\n if a[i] >= a[i - 1]:\n curr += 1\n else:\n res = max(curr, res)\n curr = 1\nres = max(curr, res)\nprint(res)",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nans=1\r\np=1\r\nfor x in range(1,len(b)):\r\n if b[x]>=b[x-1]:\r\n p+=1\r\n ans=max(ans,p)\r\n else:\r\n p=1\r\nprint(ans)",
"n = int(input())\r\na = list(int(num) for num in input().split())\r\n\r\nmax_subsec = 1\r\ncurrent_max_subsec = 1\r\nprevious_profit = a[0]\r\nfor current_profit in a[1:]:\r\n if current_profit >= previous_profit:\r\n current_max_subsec += 1\r\n else:\r\n if max_subsec < current_max_subsec:\r\n max_subsec = current_max_subsec\r\n current_max_subsec = 1\r\n previous_profit = current_profit\r\n\r\nif max_subsec < current_max_subsec:\r\n max_subsec = current_max_subsec\r\n\r\nprint(max_subsec)",
"n = int(input())\r\n\r\n\r\nnums = list(map(int, input().split()))\r\n\r\n\r\nprev = 0 \r\n\r\nmaxi = 1 \r\n\r\ncurr = 0 \r\n\r\nfor num in nums :\r\n if num >= prev :\r\n curr += 1 \r\n else :\r\n curr = 1\r\n \r\n prev = num \r\n maxi = max(maxi, curr)\r\n\r\nprint(maxi)",
"x = int(input())\r\ny = [int(i) for i in input().split()]\r\nm = 1\r\nt = 1\r\nfor i in range(x-1):\r\n if y[i+1] >= y[i]:\r\n t += 1\r\n else:\r\n if t > m:\r\n m = t\r\n t = 1\r\nif t > m:\r\n m = t\r\nprint(m)",
"dias = int(input())\r\ndinero = list(map(int,input().split()))\r\n\r\nlong_max = 1\r\nlong_actual = 1\r\n\r\nfor i in range(1, dias):\r\n if dinero[i] >= dinero[i - 1]:\r\n long_actual += 1\r\n else:\r\n long_max = max(long_max, long_actual)\r\n long_actual = 1\r\n\r\nprint(max(long_max, long_actual ))",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nmax_len = 1\r\ncur_len = 1\r\n\r\nfor i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n cur_len += 1\r\n max_len = max(max_len, cur_len)\r\n else:\r\n cur_len = 1\r\n\r\nprint(max_len)\r\n\r\n",
"n = int(input())\na = list(map(int, input().split()))\ntam_max = 1\ntam_atual = 1\nif n > 1:\n for i in range(1, n):\n if a[i] >= a[i - 1]:\n tam_atual += 1\n else:\n tam_atual = 1\n tam_max = max(tam_atual, tam_max)\nelse:\n tam_max = 1\nprint(tam_max)\n \t \t \t \t\t \t \t\t\t\t\t\t\t\t \t\t \t \t",
"input()\r\nx = list(map(int, input().split(\" \")))\r\nc = m = 1\r\nfor i in range(1, len(x)):\r\n if x[i] >= x[i-1]:\r\n c += 1\r\n else:\r\n if c > m:\r\n m = c\r\n c = 1\r\nprint(max(m,c))\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nseq = 1\r\nans = 1\r\na.append(-1)\r\nfor i in range(n):\r\n if a[i] > a[i+1]:\r\n if seq > ans:\r\n ans = seq\r\n seq = 1\r\n else:\r\n seq += 1\r\n\r\nprint(ans)",
"#https://codeforces.com/problemset/problem/580/A\r\n\r\nnumber_of_integers = int(input())\r\nlist_of_integers = [int(x) for x in input().split(\" \")]\r\nlist_of_increasing_segment = []\r\ncount = 1\r\n\r\nfor x in range(number_of_integers):\r\n try:\r\n if(list_of_integers[x] <= list_of_integers[x + 1]):\r\n count +=1\r\n else:\r\n list_of_increasing_segment.append(count)\r\n count = 1\r\n except:\r\n list_of_increasing_segment.append(count)\r\n\r\nprint(max(list_of_increasing_segment))",
"# Read input\r\nn = int(input()) # Number of days\r\na = list(map(int, input().split())) # List of money earned each day\r\n\r\n# Initialize variables\r\ncurrent_length = 1 # Current non-decreasing subsegment length\r\nmax_length = 1 # Maximum non-decreasing subsegment length\r\n\r\n# Iterate over the sequence starting from the second element\r\nfor i in range(1, n):\r\n # Check if the current element is greater than or equal to the previous element\r\n if a[i] >= a[i - 1]:\r\n # Increment the current subsegment length\r\n current_length += 1\r\n else:\r\n # Reset the current subsegment length\r\n current_length = 1\r\n # Update the maximum subsegment length if needed\r\n max_length = max(max_length, current_length)\r\n\r\n# Print the maximum non-decreasing subsegment length\r\nprint(max_length)\r\n",
"n = int(input())\na = list(map(int, input().split()))\n\ntemp = 1\nmax1 = 1\n\nfor j in range(1, n):\n if a[j] >= a[j - 1]:\n temp += 1\n else:\n temp = 1\n\n if temp > max1:\n max1 = temp\n\nprint(max1)\n\n\t\t \t \t\t \t \t \t \t\t\t\t \t\t\t\t",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\nr=-1\r\nk=0\r\nka=0\r\nfor x in a:\r\n \r\n if ka<=x :\r\n #print(ka,x)\r\n k+=1\r\n ka=x\r\n else :\r\n #print('*',ka,x)\r\n k=1\r\n ka=x \r\n if r<=k: r=k\r\n #print(r,k)\r\n #print()\r\nprint(r)\r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nmaxx = 0\r\ncount = 0\r\nfor i in range(n-1):\r\n if l[i+1] >= l[i]:\r\n count += 1\r\n else:\r\n count = 0\r\n if maxx < count :\r\n maxx = count\r\nprint(maxx+1)\r\n",
"# URL: https://codeforces.com/problemset/problem/580/A\n\nimport io\nimport os\nimport sys\n\ninput_buffer = io.BytesIO(os.read(0, os.fstat(0).st_size))\ninp = lambda: input_buffer.readline().rstrip(b\"\\n\").rstrip(b\"\\r\")\nout = sys.stdout.write\n\nn = int(inp())\na = list(map(int, inp().split()))\nd = [0] * n\nd[0] = 1\nfor i in range(1, n):\n if a[i] >= a[i - 1]:\n d[i] = d[i - 1] + 1\n else:\n d[i] = 1\nprint(max(d))\n",
"def main():\r\n n=int(input())\r\n line=input()\r\n line=line.split()\r\n z=[]\r\n y=-1\r\n x=[]\r\n x2=0\r\n for c in line:\r\n z.append(int(c))\r\n for i in z:\r\n if i>=y:\r\n x2+=1\r\n y=i\r\n else:\r\n x.append(x2)\r\n y=i\r\n x2=1\r\n x.append(x2)\r\n x.sort(reverse=True)\r\n print(x[0])\r\nmain()",
"testcases=1\n\nfor t in range (testcases):\n\tn=int(input())\n\tstring=input()\n\tarrs=string.split()\n\tarr=[]\n\tfor num in arrs:arr.append(int(num))\n\t\n\tmaxi=1\n\tcount=1\n\tfor i in range(n-1):\n\t\tif arr[i]<= arr[i+1]:\n\t\t\tcount+=1\n\t\t\tif maxi< count:\n\t\t\t\tmaxi=count\n\t\telse:\n\t\t\tcount=1\n\tprint(maxi)\n\n\t\n",
"from collections import deque\nfrom heapq import *\nimport sys\nsys.setrecursionlimit(5005)\nmod = 1000000007\ntime = 0\n\ndef solve():\n\tn = int(input())\n\tarr = list(map(int,input().split()))\n\tma = cn = 1\n\tfor i in range(1,n):\n\t\tif arr[i]>=arr[i-1]:\n\t\t\tcn+=1\n\t\telse:\n\t\t\tma = max(ma,cn)\n\t\t\tcn = 1\n\tma = max(ma,cn)\n\tprint(ma)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nt = 1\n#t = int(input())\n\nfor i in range(t):\n\tsolve()",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ni=0\r\nm=0\r\nwhile i<n:\r\n x=0\r\n while i<n-1 and l[i]<=l[i+1]:\r\n x+=1\r\n i+=1\r\n i+=1\r\n m=max(x+1,m)\r\nprint(m)",
"n = int(input())\r\na = [int(i) for i in input().split(\" \")]\r\n\r\nmx = 1\r\ncx = 1\r\n\r\nfor i in range(1, n):\r\n if a[i - 1] <= a[i]:\r\n cx += 1\r\n else:\r\n cx = 1\r\n\r\n if cx > mx:\r\n mx = cx\r\n\r\nprint(mx)",
"numbers=int(input())\r\nsequence=list(map(int,input().split()))\r\ncount=1\r\nfinal_count=1\r\nturn_off=False\r\nfor i in range(len(sequence)-1):\r\n if(sequence[i]<=sequence[i+1]):\r\n count+=1\r\n turn_off=False\r\n else:\r\n if(count>final_count):\r\n final_count=count\r\n count=1\r\n \r\n if(count>final_count):\r\n final_count=count\r\n \r\nprint(final_count)",
"n = int(input())\r\nmoney = list(map(int, input().split()))\r\n\r\ndp = [1] * n\r\nfor i in range(1, n):\r\n if money[i] >= money[i - 1]:\r\n dp[i] = dp[i - 1] + 1\r\n\r\nmax_len = max(dp)\r\nprint(max_len)",
"input()\r\nl = list(map(int,input().split()))\r\nc, mx= 0, 0\r\nfor i in range(1,len(l)):\r\n if (l[i] < l[i - 1]):\r\n mx = max(mx,i-c)\r\n c = i\r\n\r\nmx = max(mx , len(l) - c)\r\n\r\n\r\nprint(mx)",
"n=int(input())\r\narr=[int(i) for i in input().split()]\r\ndp=[0]*(n)\r\ndp[0]=1\r\nfor i in range(1,n):\r\n if arr[i]>=arr[i-1]:\r\n dp[i]=1+dp[i-1]\r\n else:\r\n dp[i]=1\r\nprint(max(dp))\r\n ",
"def long(arr,n):\r\n dp = [1] * n\r\n max1 = 1\r\n for i in range(1,n):\r\n if arr[i]>=arr[i-1]:\r\n dp[i]=dp[i-1]+1\r\n max1 = max(max1,dp[i])\r\n else:\r\n dp[i]=1\r\n return max1\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n arr = list(map(int,input().split()))\r\n print(long(arr,n))",
"n = int(input())\r\nlistX = list(map(int,input().split(\" \")))\r\nnum = listX[0]\r\ncount = 0\r\ncountList = []\r\nfor x in listX:\r\n if num<=x:\r\n count +=1\r\n countList.append(count)\r\n num = x\r\n else:\r\n count = 1\r\n num = x\r\nprint(max(countList))\r\n \r\n ",
"n=int(input())\r\nlis=list(map(int,input().split()))\r\nc=0\r\nm=0\r\nfor i in range(n-1):\r\n if lis[i]<=lis[i+1]:\r\n c+=1\r\n if c>m:\r\n m=c\r\n else:\r\n c=0\r\nprint(m+1)\r\n ",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nq=1\r\ns=[]\r\nif n == 1:\r\n print(1)\r\nelse:\r\n for i in range(n-1):\r\n if l[i]<=l[i+1]:\r\n q+=1\r\n s.append(q)\r\n else:\r\n q=1\r\n s.append(q)\r\n print(max(s))",
"last_earned = 0\r\ncur_sequence = 0\r\nmax_sequence = 0\r\n\r\n_ = input()\r\n\r\ndays = list(map(int, input().split()))\r\n\r\nfor earned_in_day in days:\r\n\tif earned_in_day >= last_earned:\r\n\t\tcur_sequence += 1\r\n\t\t\r\n\t\tif cur_sequence > max_sequence:\r\n\t\t\tmax_sequence = cur_sequence\r\n\telse:\r\n\t\t# cur_sequence is now equal to this sequence\r\n\t\tcur_sequence = 1\r\n\tlast_earned = earned_in_day\r\n\t\r\nprint(max_sequence)\r\n\t\t",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ncount = 0\r\ncount2 = 0\r\nnums = []\r\nfor i in range(n - 1):\r\n if arr[i] <= arr[i + 1]:\r\n count += 1\r\n if count2 < count:\r\n count2 = count\r\n else:\r\n count = 0\r\n\r\nprint(count2 + 1)",
"# d[i]: 2 2 1 3 4 1\r\n# dp[i]: 1 2 1 2 3 1 \r\nn = int(input())\r\nd = list(map(int, input().split()))\r\ndp = [0] * n\r\ndp[0] = 1\r\nfor i in range(1, n):\r\n if d[i] < d[i - 1]:\r\n dp[i] = 1\r\n else:\r\n dp[i] = dp[i - 1] + 1\r\nprint(max(dp))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ncount=1\r\nans=1\r\nfor i in range(0,n-1):\r\n if(a[i+1]>=a[i]):\r\n count+=1\r\n if(ans<count):\r\n ans=count\r\n else:\r\n count=1\r\nprint(ans)\r\n",
"n = input()\r\nj = input().split(\" \")\r\nnum = 0\r\npv = 0\r\npr = 0\r\nfor i in j:\r\n if int(i) >= num:\r\n pr += 1\r\n num = int(i)\r\n else:\r\n if pv < pr:\r\n pv = pr\r\n pr = 1\r\n num = int(i)\r\nprint(max(pv, pr))\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nk, o = 1, float('-inf')\r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n k += 1\r\n else:\r\n o = max(o, k)\r\n k = 1\r\nprint(max(o, k))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nlen = 1\r\nmax_len = 1\r\nfor i in range(n - 1):\r\n if a[i] <= a[i + 1]:\r\n len += 1\r\n else: len = 1\r\n if len > max_len: max_len = len\r\n\r\nprint(max_len)",
"n = int(input())\r\narr = list(map(int, input().split(' ')))\r\nans = float('-inf')\r\nl = 0\r\nfor i in range(1, n):\r\n if arr[i] < arr[i - 1]:\r\n ans = max(ans, i - l)\r\n l = i\r\nprint(max(ans, n - l))\r\n ",
"first = input()\r\nsecond = input().split(\" \")\r\nnewlist = []\r\nbest = 0\r\ncount = 0\r\nlog = [0]\r\nfor l in second:\r\n newlist.append(int(l))\r\n\r\nfor x in newlist:\r\n if x >= best:\r\n best = x\r\n count +=1\r\n log.append(count)\r\n else:\r\n best = x\r\n count = 1\r\n\r\nprint(max(log))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nif(n==1):\r\n print(1)\r\nelse: \r\n cnt,maxi=1,-999999999\r\n for i in range(n-1):\r\n if(l[i]>l[i+1]):\r\n maxi=max(maxi,cnt)\r\n cnt=1\r\n elif(i==n-2):\r\n maxi=max(maxi,cnt+1)\r\n else: \r\n cnt+=1\r\n print(maxi) ",
"n = int(input())\na = list(map(int, input().split()))\n\nmax_length = 1 # Initialize the maximum subsegment length to 1\ncurrent_length = 1 # Initialize the current subsegment length to 1\n\nfor i in range(1, n):\n if a[i] >= a[i - 1]:\n current_length += 1\n else:\n current_length = 1\n\n max_length = max(max_length, current_length)\n\nprint(max_length)\n\n \t\t\t\t\t \t \t\t\t\t \t \t \t \t \t\t",
"n=int (input())\r\nc,c1 = 1,1\r\narr = list(map(int,input().split()))\r\nfor i in range(n-1):\r\n if arr[i]<=arr[i+1]:\r\n c1+=1\r\n if c<c1:\r\n c=c1\r\n else:\r\n c1=1\r\nprint(c)",
"last_earned = 0\ncur_sequence = 0\nmax_sequence = 0\n\n_ = input()\n\ndays = list(map(int, input().split()))\n\nfor earned_in_day in days:\n if earned_in_day >= last_earned:\n cur_sequence += 1\n\n if cur_sequence > max_sequence:\n max_sequence = cur_sequence\n else:\n # cur_sequence is now equal to this sequence\n cur_sequence = 1\n last_earned = earned_in_day\n\nprint(max_sequence)",
"n = int(input())\r\nnumber = list(map(int, input().split()))\r\nmax_len =1\r\nlength = 1\r\nfor i in range(1 , n) :\r\n \r\n if number[i] >= number[i-1]:\r\n length+=1\r\n \r\n else :\r\n max_len = max(length , max_len)\r\n length =1\r\n\r\nmax_len = max(length , max_len)\r\nprint(max_len)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Sep 7 10:40:18 2023\r\n\r\n@author: mac\r\n\"\"\"\r\n\r\nn = int(input())\r\nnums = list(map(int,input().split()))\r\nlength = 1 #动态记录单调列长度\r\nmaxlen = 1 #动态记录最大单调列长度\r\nfor i in range(n - 1):\r\n if nums[i+1] >= nums[i]:\r\n length += 1\r\n else:\r\n length = 1\r\n maxlen = max(maxlen, length)\r\nprint(maxlen)",
"n = int(input())\na = [int(x) for x in input().split()]\nlongestStreak = 0\ncurrentStreak = 1\nfor i in range(1, n):\n if a[i] < a[i - 1]:\n if currentStreak > longestStreak:\n longestStreak = currentStreak\n currentStreak = 1\n # print(\"Oh no Streak is Broken\")\n else:\n currentStreak += 1\n # print(\"Still a non decreasing\")\n\n\nprint(max(longestStreak, currentStreak))\n\n \t\t \t \t \t\t \t\t\t \t\t\t\t\t\t\t \t",
"from sys import stdin, stdout\r\n\r\nn = int(stdin.readline())\r\nl = [*map(int, stdin.readline().split())]\r\n\r\ninitial = l[0]\r\nans = 0\r\npartial = 1\r\n\r\nfor i in l[1:]:\r\n if i>= initial:\r\n partial += 1\r\n else:\r\n ans = max(ans, partial)\r\n partial = 1\r\n initial = i\r\nelse:\r\n ans = max(ans, partial)\r\n\r\nstdout.write(str(ans))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans = 1\r\nc = 1\r\nfor i in range(1, n):\r\n if a[i] < a[i-1]:\r\n ans = max(ans, c)\r\n c = 1\r\n else:\r\n c += 1\r\nans = max(ans, c)\r\nprint(ans)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndp = [1] * n\r\n\r\nfor i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n dp[i] = dp[i-1] + 1\r\n\r\nmax_length = max(dp)\r\nprint(max_length)\r\n",
"n = int(input())\r\n\r\na =list(map(int,input().split()))\r\n\r\ncurrent_length= 1\r\nmax_length =1\r\n\r\nfor i in range(1,n):\r\n if a[i] >= a[i-1]:\r\n current_length += 1\r\n max_length=max(max_length,current_length)\r\n else:\r\n current_length = 1\r\n \r\n \r\nprint(max_length)\r\n",
"\n\nn = int(input())\nl = list(map(int, input().split(' ')))\n\nmx = 1\ncur = 1\na = l[0]\nfor i in range(1, n):\n b = l[i]\n if b >= a:\n cur += 1\n else:\n if mx < cur:\n mx = cur\n cur = 1\n a = b\nif mx < cur:\n mx = cur\nprint(mx)\n",
"input()\r\nrow = list(map(int, input().split(' ')))\r\ncounter,maxval=1,1\r\nfor i in range(1,len(row)):\r\n if row[i] >= row[i-1]:\r\n \r\n counter+=1\r\n if counter > maxval:\r\n\r\n maxval = counter\r\n \r\n else:\r\n counter = 1\r\n\r\nprint(maxval)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nmaxi=1\r\nk=[1]\r\ncount=0\r\nfor i in range(0,len(l)-1):\r\n if l[i]<=l[i+1]:\r\n maxi=maxi+1\r\n if count<maxi:\r\n count=maxi\r\n k.append(count)\r\n else:\r\n if count<maxi:\r\n count=maxi\r\n k.append(count)\r\n maxi=1\r\nb=max(k)\r\nprint(b)",
"n = int(input())\r\nmas = list(map(int,input().split()))\r\n\r\n\r\ndp = [0]*n\r\n\r\ndp[0] = 1\r\n\r\nfor i in range(1,n):\r\n if mas[i]>= mas[i-1]:\r\n dp[i] = dp[i-1] + 1\r\n else:\r\n dp[i] = 1\r\n \r\nprint(max(dp))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans = 1\r\ncur_length = 1\r\nfor i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n cur_length += 1\r\n else:\r\n cur_length = 1\r\n ans = max(ans, cur_length)\r\nprint(ans) ",
"b=int(input())\nc=m=s=0\nfor z in input().split():\n a=int(z)\n if a>=m:\n s+=1\n else:\n s=1\n if c<s:\n c=s\n m=a\nprint(c)\n\t \t \t\t \t \t\t \t\t\t\t\t\t\t \t\t\t \t \t \t",
"n=int(input())\r\na=list(map(int,input().split()))\r\nmaxL=1\r\ncurrentL=1\r\nfor i in range(1,n):\r\n if a[i]>=a[i-1]:\r\n currentL+=1\r\n maxL=max(maxL,currentL)\r\n else:\r\n currentL=1\r\nprint(maxL)",
"n=int(input())\r\nmoneys=list(map(int,input().split()))\r\nmax_len,current=1,1\r\nfor i in range(1,n):\r\n if moneys[i]>=moneys[i-1]:\r\n current+=1\r\n else:\r\n if max_len<current:\r\n max_len=current\r\n current=1\r\nif current>max_len:\r\n max_len=current\r\nprint(max_len)",
"n = int(input())\r\ns = list(map(int, input().split()))\r\ndef subsegment(s):\r\n count = 1\r\n max_count = 1\r\n for i in range(n - 1):\r\n if s[i] <= s[i + 1]:\r\n count += 1\r\n else:\r\n count = 1\r\n max_count = max(max_count, count)\r\n return max_count\r\nresult = subsegment(s)\r\nprint(result)\r\n",
"n, p = int(input()), input().split()\r\np = [int(item) for item in p]\r\nmax = 0\r\nc = 1\r\nif n == 1:\r\n print('1')\r\nelse:\r\n for i in range(1, n):\r\n if p[i] >= p[i - 1]:\r\n c += 1\r\n else:\r\n c = 1\r\n if c > max:\r\n max = c\r\n print(max) ",
"input();c=m=s=0\r\nfor i in map(int,input().split()):c=[c+1,1][i<s];m=max(m,c);s=i\r\nprint(m)",
"n = int(input())\r\nnums = [int(i) for i in input().split()]\r\n\r\n\r\nmax_length = 0\r\ncur_length = 1\r\n\r\nfor i in range(1,n):\r\n if nums[i] >= nums[i-1]:\r\n cur_length += 1\r\n else:\r\n if cur_length > max_length:\r\n max_length = cur_length\r\n cur_length = 1\r\n\r\nif cur_length > max_length:\r\n max_length = cur_length\r\nprint(max_length)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nmx=-1\r\nincreasing=1\r\ni=1\r\nwhile i<n:\r\n if a[i]>=a[i-1]: increasing+=1\r\n else:\r\n mx=max(mx, increasing)\r\n increasing=1\r\n i+=1\r\nmx=max(mx, increasing)\r\nprint(mx)",
"# Wadea #\r\n\r\nm = int(input())\r\ns = list(map(int,input().split()))\r\nr = 0\r\narr = [0]\r\nfor i in range(m-1):\r\n if s[i] <= s[i+1]:\r\n r += 1\r\n arr.append(r)\r\n else:\r\n arr.append(r)\r\n r = 0\r\nprint(max(arr)+1)\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\ncount = 1\r\nanswer = 1\r\ni = 1\r\nwhile i < len(a):\r\n if a[i]>=a[i-1]:\r\n count += 1\r\n else:\r\n if answer < count:\r\n answer = count\r\n count = 1\r\n i += 1\r\nif answer < count:\r\n answer = count\r\n\r\nprint(answer)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nt=0\r\nr=0\r\nfor i in range(n):\r\n if l[i] >= t:\r\n c+=1\r\n t=l[i]\r\n r=max(r,c)\r\n else:\r\n c=1\r\n t=l[i]\r\nprint(r)",
"n=int(input())\r\nn1=input().split(\" \")\r\nl=[]\r\nfor i in n1:\r\n l.append(int(i))\r\ntc=0\r\nc=0\r\nfor k in range(0,len(l)-1,1):\r\n if k==len(l)-2:\r\n if l[k+1]>=l[k]:\r\n tc=tc+1\r\n if tc>c:\r\n c=tc\r\n else:\r\n if tc>c:\r\n c=tc\r\n elif l[k]<=l[k+1]:\r\n tc=tc+1\r\n else:\r\n if tc>c:\r\n c=tc\r\n tc=0\r\nprint(c+1)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nd = []\r\ncou = 1\r\nfor i in range(0, n):\r\n for j in range(i+1, n):\r\n if a[i] <= a[j]:\r\n cou += 1\r\n break\r\n else:\r\n d.append(cou)\r\n cou = 1\r\n break\r\nd.append(cou)\r\nprint(max(d))",
"n = int(input())\r\na = list(map(int,input().split()))\r\nmx = 0\r\nl = 0\r\nfor i in range(n - 1):\r\n if a[i] <= a[i + 1]:\r\n l += 1\r\n else:\r\n mx = max(l,mx)\r\n l = 0\r\nmx = max(l,mx)\r\nprint(mx + 1)\r\n",
"a=int (input())\r\nb=[int (i) for i in input().split()]\r\nl=0\r\nf=0\r\nfor o in range (len(b)-1) :\r\n if b[o]<=b[o+1] :\r\n l+=1\r\n if l>f : \r\n f=l\r\n if b[o]>b[o+1] :\r\n l=0\r\nprint(f+1)",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\np=1\r\no = 0\r\nif n == 1:\r\n print(1)\r\nelse:\r\n for i in range(1,len(a)):\r\n if a[i] >= a[i-1]:\r\n p += 1\r\n else:\r\n o = max(o,p)\r\n p = 1\r\n print(max(o,p))\r\n#print(z)\r\n",
"n=int(input())\r\nmaxi=0\r\na=[int(i) for i in input().split()]\r\ncur=0\r\nfor i in range(n-1):\r\n if a[i]<=a[i+1]:\r\n cur+=1\r\n else:\r\n maxi=max(cur+1,maxi)\r\n cur=0\r\nprint(max(maxi,cur+1))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nsum = 1\r\nk = 1\r\nfor i in range(1, len(a)):\r\n if a[i] >= a[i - 1]:\r\n k += 1\r\n else:\r\n if k > sum:\r\n sum = k\r\n k = 1\r\nif k > 1 and sum < k:\r\n sum = k\r\nprint(sum)\r\n",
"n = int(input())\r\ndata = list(map(int, input().split()))\r\nans = 1\r\nta = 1\r\nfor i in range(1, n):\r\n if data[i] >= data[i-1]:\r\n ta += 1\r\n else:\r\n ans = max(ans, ta)\r\n ta = 1\r\n \r\nprint(max(ta, ans))",
"n=int(input())\r\nb=list(map(int,input().split()))\r\nv=[]\r\nc=0\r\nfor i in range(n-1):\r\n if b[i]<=b[i+1]:\r\n c+=1\r\n else:\r\n c+=1\r\n v.append(c)\r\n c=0\r\nelse:\r\n c+=1\r\n v.append(c)\r\nprint(max(v))",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\n# Initialize variables for maximum length and current length of non-decreasing subsegment\r\nmax_length = 1\r\ncur_length = 1\r\n\r\n# Loop through the array and update the current length of the non-decreasing subsegment\r\nfor i in range(1, n):\r\n if a[i] >= a[i-1]:\r\n cur_length += 1\r\n else:\r\n # Update the maximum length and reset the current length to 1\r\n max_length = max(max_length, cur_length)\r\n cur_length = 1\r\n\r\n# Update the maximum length after the loop ends\r\nmax_length = max(max_length, cur_length)\r\n\r\nprint(max_length)",
"x=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nmax_l=0\r\nfor i in range(x-1):\r\n if l[i]<=l[i+1]:\r\n c+=1\r\n if c>max_l:\r\n max_l=c\r\n else:\r\n c=0\r\nprint(max_l+1)",
"n=int(input())\r\n \r\na = list(map(int,input().strip().split()))[:n]\r\n\r\nans=0\r\ntemp=1\r\nfor i in range(n-1):\r\n if(a[i]>a[i+1]):\r\n ans=max(ans,temp)\r\n temp=1\r\n i-=1\r\n else:\r\n temp+=1\r\n\r\nans=max(ans,temp)\r\n\r\nprint(ans)\r\n \r\n ",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = h = x = 0\r\nfor i in a: \r\n if i >= h: \r\n s += 1\r\n else: \r\n x = max(s, x)\r\n s = 1\r\n h = i\r\nprint(max(s,x))",
"n = int(input())\r\ns = list(map(int, input().split()))\r\nc = 1\r\nc_last = 1\r\n\r\nfor i in range(1, len(s)):\r\n\r\n if s[i] >= s[i-1]:\r\n c += 1\r\n if c > c_last:\r\n c_last = c\r\n\r\n else:\r\n c = 1\r\n\r\n\r\nprint(c_last)\r\n",
"n = int(input(\"\"))\r\ninput_string = input(\"\")\r\na = [int(x) for x in input_string.split()]\r\n\r\ndp = [1] * n # Initialize an array dp with all elements set to 1\r\n\r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n dp[i] = dp[i - 1] + 1\r\n\r\n# The length of the longest non-decreasing subsequence is the maximum value in the dp array\r\nlongest_non_decreasing_length = max(dp)\r\n\r\nprint(longest_non_decreasing_length)",
"n = int(input()) \r\na = list(map(int, input().split())) \r\n\r\nmax1 = 1 \r\nc = 1 \r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n c += 1 \r\n else:\r\n max1= max(max1, c)\r\n c = 1 \r\nmax1 = max(max1, c)\r\n\r\nprint(max1)\r\n",
"n = int(input())\r\na = [int(e) for e in input().split(' ')]\r\nl, i = 1, 0\r\na += [0]\r\nwhile i < n:\r\n c = 1\r\n while a[i+1] >= a[i]:\r\n c += 1\r\n i += 1\r\n l = max(l, c) \r\n i += 1\r\nprint(l)\r\n",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nc = [1]*len(a)\r\nfor i in range(1, len(a)):\r\n if a[i] >= a[i-1]:\r\n c[i] = c[i-1] + 1\r\nprint(max(c))\r\n",
"t = int(input())\r\n\r\narr = list(map(int, input().split()))\r\ncount = 1\r\nans = 1\r\n\r\nfor i in range(len(arr) - 1):\r\n if arr[i] <= arr[i+1]:\r\n count+=1\r\n else:\r\n ans = max(count,ans)\r\n count = 1\r\n\r\nans = max(count,ans)\r\nprint(ans)",
"n=int(input(''))\r\nx=list(map(int,input().split()))\r\nc=1\r\nm=1\r\nfor i in range(n):\r\n if i == n-1:\r\n break\r\n if x[i]<=x[i+1]:\r\n c+=1\r\n else:\r\n if m<=c :\r\n m=c\r\n c=1\r\n\r\nif m > c :\r\n print(m)\r\nelse:\r\n print(c)",
"def find_max_non_decreasing_subsegment_length(n, numbers):\n max_length = 1 # Minimum length is 1 (for a single element)\n\n current_length = 1\n for i in range(1, n):\n if numbers[i] >= numbers[i - 1]:\n # Current number is greater than or equal to the previous number\n current_length += 1\n else:\n # Current number is smaller than the previous number\n max_length = max(max_length, current_length) # Update the maximum length\n current_length = 1 # Reset the current length\n\n # Check if the last subsegment is the longest\n max_length = max(max_length, current_length)\n\n return max_length\n\n\n# Read input values\nn = int(input())\nnumbers = list(map(int, input().split()))\n\n# Find the length of the maximum non-decreasing subsegment\nresult = find_max_non_decreasing_subsegment_length(n, numbers)\n\n# Output the result\nprint(result)\n\n\t \t\t \t \t\t\t \t \t \t \t\t \t \t\t\t",
"from sys import stdin\r\n\r\nn = int(stdin.readline())\r\nb = list(map(int,stdin.readline().split()))\r\naCum = 1\r\nz = 0\r\nfor i in range(1,n):\r\n if b[i-1]<= b[i]:aCum += 1 \r\n elif z < aCum: z = aCum;aCum = 1\r\n else:aCum = 1\r\nif aCum>z:\r\n print(aCum)\r\nelse:\r\n print(z)",
"n = int(input())\n\nniz = [int(x) for x in input().split()]\n\ndef najduzi(niz):\n najveci = 0\n ukupno = 0\n prvi = niz[0]\n for i in range(1, len(niz)):\n if prvi<=niz[i]:\n najveci+=1\n \n else:\n najveci=0\n \n ukupno=max(ukupno,najveci)\n prvi= niz[i]\n return ukupno+1\n\nprint(najduzi(niz))\n\n",
"# 580A - Kefa and First Steps\r\nn = int(input())\r\nli = list(map(int, input().split()))\r\nc = 0\r\ntmp = 0\r\nres = 0\r\nfor i in range(n):\r\n if li[i] >= tmp:\r\n c += 1\r\n tmp = li[i]\r\n res = max(res, c)\r\n else:\r\n c = 1\r\n tmp = li[i]\r\nprint(res)\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nans, tmp = 0, 1\r\nfor i in range(1, n):\r\n if (tmp > ans): ans = tmp\r\n if (arr[i] >= arr[i-1]): tmp = tmp + 1\r\n else: tmp = 1\r\nif (tmp > ans): ans = tmp\r\nprint(ans)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n \r\ndp = [0] * n\r\ndp[0] = 1\r\nfor i in range(1, n):\r\n if a[i] >= a[i - 1]:\r\n dp[i] = dp[ i -1] + 1\r\n else:\r\n dp[i] = 1\r\n \r\nprint(max(dp))",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nml = 0\r\ncl = 1\r\nfor i in range(1, len(a)):\r\n if a[i] >= a[i-1]:\r\n cl += 1\r\n else:\r\n ml = max(ml, cl)\r\n cl = 1\r\nml = max(ml, cl)\r\nprint(ml)\r\n",
"n = int(input())\r\nm = list(map(int, input().split()))\r\n\r\nlength = 1 \r\nmax_length = 1 \r\n\r\nfor i in range(1, n):\r\n if m[i] >= m[i-1]:\r\n length += 1\r\n else:\r\n length = 1\r\n max_length = max(max_length, length)\r\n\r\nprint(max_length)",
"n = int(input())\r\narr = [int(x) for x in input().split()]\r\nmaxim = 1\r\ncount = 1\r\nfor a in range(n - 1):\r\n if arr[a] <= arr[a + 1]:\r\n count += 1\r\n\r\n else:\r\n if count > maxim:\r\n maxim = count\r\n count = 1\r\n\r\n if a == n - 2:\r\n if count > maxim:\r\n maxim = count\r\nprint(maxim)\r\n",
"n=int(input())\narr=list(map(int,input().strip().split()))\nans,count=1,1\nfor i in range(n-1):\n if arr[i]<=arr[i+1]:\n count+=1\n ans=max(ans,count)\n else:\n count=1\n\nprint(ans)\n\n\n\n\n\n\n\n\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Oct 8 21:09:02 2023\r\n\r\n@author: 25419\r\n\"\"\"\r\n\r\nn=int(input())\r\nlist1=input().split()\r\nanswers=[]\r\nsum=0\r\nfor i in range(n):\r\n if i!=n-1 and int(list1[i])<=int(list1[i+1]):\r\n sum=sum+1\r\n else:\r\n answers.append(sum)\r\n sum=0\r\nprint(max(answers)+1)",
"def main() -> None :\r\n print(max_Length_Of_None_Decreasing_Segment(user_Inputs()))\r\n\r\n\r\ndef max_Length_Of_None_Decreasing_Segment(array: list[int]) -> int :\r\n return max_Length_Of_Success_Values(is_Next_Number_None_Decreasings(array), True) + 1\r\n\r\ndef is_Next_Number_None_Decreasings(array: list[int]) -> list[bool] :\r\n return [array[index] <= array[index+1] for index in range(len(array)-1)]\r\n\r\ndef max_Length_Of_Success_Values(array: list[int], success_value: int) -> int :\r\n result:int = 0\r\n success_length:int = 0\r\n \r\n for e in array :\r\n if e != success_value :\r\n success_length = 0 \r\n continue\r\n\r\n success_length += 1 \r\n result = max(result, success_length)\r\n \r\n return result\r\n\r\n\r\ndef user_Inputs() -> list[int] :\r\n ignore_Line()\r\n return input_Array()\r\n\r\ndef input_Array() -> list[int] :\r\n return list(map(int, input().split()))\r\n\r\ndef ignore_Line() -> None :\r\n input()\r\n\r\n\r\nmain()",
"n=int(input())\r\nx=list(map(int,input().split()))\r\nc=1\r\na=[]\r\nfor i in range(n-1):\r\n if x[i]<=x[i+1]:\r\n c=c+1\r\n else:\r\n a.append(c)\r\n c=1\r\na.append(c)\r\nb=sorted(a)\r\nprint(b[len(b)-1])",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nl = [1]*n\r\nfor i in range(1,n):\r\n if a[i]>=a[i-1]:\r\n l[i]=l[i-1]+1\r\n\r\nprint(max(l))",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\nc,d=0,1\r\nfor i in range(n-1):\r\n if a[i]>a[i+1]:\r\n c=max(c,d)\r\n d=1\r\n else:\r\n d+=1\r\nc=max(c,d)\r\nprint(c)\r\n",
"def stdInput(type): # assists in getting inputs in different ways and returns the data needed\r\n if type == \"TC\": # test case count\r\n return int(input())\r\n if type == \"SI\": # spaced integers\r\n return [int(i) for i in input().split()]\r\n if type == \"SS\": # spaced strings\r\n return [i for i in input().split()]\r\n if type == \"TCSI\": # needs test case count, spaced integers\r\n fin = []\r\n for _ in range(stdInput(\"TC\")):\r\n x = [int(i) for i in input().split()]\r\n fin.append(x)\r\n return fin\r\n if type == \"TCSS\": # needs test case count, spaced strings, gives string of each line\r\n fin = []\r\n for _ in range(stdInput(\"TC\")):\r\n x = [i for i in input().split()]\r\n fin.append(x)\r\n return fin\r\n if type == \"S\": # single string\r\n return input()\r\n if type == \"I\": # single integer\r\n return int(input())\r\n\r\nstdInput(\"I\")\r\nints = stdInput(\"SI\")\r\n\r\nlast = 0\r\nsub = []\r\ntemp = []\r\nfor i in ints:\r\n if i >= last:\r\n temp.append(i)\r\n else:\r\n sub.append(temp)\r\n temp = [i]\r\n last = int(i)\r\nsub.append(temp)\r\n\r\nlengths = []\r\nfor i in sub:\r\n lengths.append(len(i))\r\nprint(max(lengths))",
"n = int(input())\r\na = list(map(int, input().split()))\r\ncount1 = 1\r\ncount2 = 1\r\nfor i in range(1, n):\r\n if a[i-1] <= a[i]:\r\n count1 += 1\r\n else:\r\n count1 = 1\r\n if count1 > count2:\r\n count2 = count1\r\n\r\nprint(count2)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=0\r\nc=0\r\nfor i in range(1,n):\r\n #rint(\"c=\",c)\r\n #print(\"l[i]=\",l[i])\r\n #print(\"l[i-1]=\",l[i-1])\r\n if l[i]>=l[i-1]:\r\n #print(\"if\")\r\n c=c+1\r\n else:\r\n #print(\"else\")\r\n m=max(c,m)\r\n c=0\r\n #print(\"c'=\",c)\r\n m=max(c,m)\r\nprint(m+1)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ndp = [0] * n\r\ndp[0] = 1\r\nfor i in range(1, n):\r\n if arr[i] >= arr[i - 1]:\r\n dp[i] = 1 + dp[i - 1]\r\n else:\r\n dp[i] = 1\r\nprint(max(dp))\r\n",
"n = int(input())\r\nnums = input().split(' ')\r\nnums = [int(x) for x in nums]\r\nm = 1\r\nc = 1\r\nfor i in range(len(nums)-1):\r\n if nums[i] <= nums[i+1]:\r\n c+=1\r\n else:\r\n if m < c:\r\n m = c\r\n c = 1\r\n if m < c:\r\n m = c\r\nprint(m)\r\n ",
"n = int(input()) \narr = list(map(int, input().split())) \n\nmax_len = 1\ncurr_len = 1\n\nfor i in range(1, n):\n if arr[i] >= arr[i-1]:\n curr_len += 1\n else:\n max_len = max(max_len, curr_len)\n curr_len = 1\n\nmax_len = max(max_len, curr_len) \nprint(max_len)\n\t\t\t \t \t \t\t\t \t\t\t \t \t\t \t \t\t\t",
"d=int(input())\r\na=list(map(int,input().split()))\r\ne=j=0\r\nfor i in range(d-1):\r\n if a[i]<=a[i+1]:\r\n \te+=1\r\n \tif j<e:\r\n \t j=e \r\n else:e=0 \r\nprint(j+1) ",
"n = int(input())\r\nsequence = list(map(int,input().split()))\r\ncurrent_length =1\r\nmax_length = 1\r\nfor i in range(1,n):\r\n if sequence[i]>=sequence[i-1]:\r\n current_length+=1\r\n else:\r\n current_length =1\r\n max_length = max(max_length,current_length)\r\nprint(max_length)",
"def solve():\r\n x = int(input())\r\n l = [int(i) for i in input().split()]\r\n cur, mx = 0, 0\r\n last = 0\r\n for i in l:\r\n if i >= last:\r\n cur += 1\r\n else:\r\n mx = max(mx, cur)\r\n cur = 1\r\n last = i\r\n print(max(mx, cur))\r\n\r\n\r\n# t = int(input())\r\nt = 1\r\nwhile t:\r\n solve()\r\n t -= 1\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nres = 0\r\ncnt = 1 if a else 0\r\nfor i in range(n - 1):\r\n if a[i] > a[i + 1]:\r\n i = i + 1\r\n res = max(res, cnt)\r\n cnt = 1\r\n else:\r\n cnt += 1\r\nres = max(res, cnt)\r\nprint(res)\r\n",
"n = int(input())\r\nmax = 0\r\nx = [int(a) for a in input().split()]\r\ncnt = 0\r\nb = x[0]\r\nfor i in x:\r\n if i >= b:\r\n cnt+=1\r\n else:\r\n cnt = 1\r\n if cnt > max:\r\n max = cnt\r\n b = i\r\nprint(max)",
"n = input()\r\na = list(map(int, input().split(' ')))\r\nresult = 0\r\ncurrent = 0\r\nprev = -1\r\nfor i in range(len(a)):\r\n if prev == -1:\r\n current = 1\r\n elif a[i] >= prev:\r\n current += 1\r\n else:\r\n if current > result:\r\n result = current\r\n current = 1\r\n prev = a[i]\r\nif current > result:\r\n result = current\r\nprint(result)",
"n = int(input())\r\nnum = list(map(int, input().split()))\r\nl = 1\r\nans = list()\r\nfor i in range(1, n):\r\n if num[i] >= num[i - 1]:\r\n l += 1\r\n else:\r\n ans.append(l)\r\n l = 1\r\nans.append(l)\r\nprint(max(ans))",
"n = int(input())\r\na = list(map(int,input().split()))\r\ncount = 1\r\nmaxcount = 1\r\nfor i in range(1,n):\r\n if a[i] >= a[i - 1]:\r\n count += 1\r\n else:\r\n count = 1\r\n maxcount = max(maxcount,count)\r\nprint(maxcount)",
"def solve():\r\n (n,) = map(int, input().split())\r\n a = map(int, input().split())\r\n\r\n best_result = None\r\n prev = 0\r\n result = 0\r\n for e in a:\r\n if e >= prev:\r\n result += 1\r\n else:\r\n if best_result is None or best_result < result:\r\n best_result = result\r\n result = 1\r\n prev = e\r\n\r\n if best_result is None or best_result < result:\r\n best_result = result\r\n\r\n print(best_result)\r\n\r\n\r\nt = 1 # int(input())\r\n\r\nfor _ in range(t):\r\n solve()\r\n",
"def main():\r\n n = int(input())\r\n nums = [int(x) for x in input().split()]\r\n\r\n res = 1\r\n temp = 1\r\n for j in range(1, n):\r\n if nums[j] >= nums[j-1]:\r\n temp += 1\r\n else:\r\n temp = 1\r\n res = max(res, temp)\r\n print(res)\r\n return\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"n=int(input())\r\na=list(map(int,input().split()))\r\ncnt=1\r\nres=1\r\nfor i in range(n-1):\r\n if a[i]<=a[i+1]:\r\n cnt+=1\r\n else:\r\n if cnt>res:\r\n res=cnt\r\n cnt=1\r\nif cnt>res:\r\n res=cnt\r\nprint(res)",
"input()\nsequence = input().split(\" \")\nsequence = [int(n) for n in sequence]\ncount = 1\nmax_count = 1\nfor i in range(1, len(sequence)):\n if sequence[i] >= sequence[i - 1]:\n count += 1\n max_count = max(max_count, count)\n else:\n count = 1\nprint(max_count)\n",
"n=int(input())\r\nlist1=list(map(int,input().split()))\r\nlist2=list1.copy()\r\nlist2.sort()\r\nif list1==list2:\r\n print(len(list1))\r\nelse:\r\n mx=0\r\n count1=1\r\n for x in range(len(list1)-1):\r\n if list1[x]<=list1[x+1]:\r\n count1+=1\r\n else:\r\n count1=1\r\n mx=max(mx,count1)\r\n print(mx)"
] | {"inputs": ["6\n2 2 1 3 4 1", "3\n2 2 9", "5\n10 100 111 1 2", "10\n1 2 3 4 1 2 3 4 5 6", "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992", "1\n1", "2\n1 1", "6\n5 4 3 2 1 2", "9\n1 2 3 4 5 6 7 8 9", "7\n99 100 1 2 3 4 5", "5\n3 3 1 2 3", "1\n100", "1\n5"], "outputs": ["3", "3", "3", "6", "50", "42", "1", "2", "2", "9", "5", "3", "1", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 250 | |
2f3f7b94851f56f96e4ed58c3ab91d6f | Greg's Workout | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise.
Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous.
Sample Input
2
2 8
3
5 1 10
7
3 3 2 7 9 6 8
Sample Output
biceps
back
chest
| [
"n = int(input())\r\n\r\nl_n = list(map(int, input().split()))\r\na_t = [0]*3\r\n\r\nfor i in range(n):\r\n a_t[i % 3] += l_n[i]\r\n\r\nif a_t[0] > a_t[1] and a_t[0] > a_t[2]:\r\n print(\"chest\")\r\nelif a_t[1] > a_t[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"total = [0,0,0]\nn = int(input())\ndays = list(map(int,input().split()))\nfor i in range(n):\n total[i%3] += days[i]\nmaxi = max(total)\nprint('chest' if maxi == total[0] else ('biceps' if maxi == total[1] else 'back'))\n",
"n=int(input())\r\na=list(map(int,input().split(\" \")))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(n):\r\n if(i%3==0):\r\n chest+=a[i]\r\n elif(i%3==1):\r\n biceps+=a[i]\r\n elif(i%3==2):\r\n back+=a[i]\r\nif(chest>biceps and chest>back):\r\n print(\"chest\")\r\nelif(biceps>chest and biceps>back):\r\n print(\"biceps\")\r\nelse:\r\n if(back>chest and back>biceps):\r\n print(\"back\")",
"n = int(input())\r\ns = [\"c\", \"bi\", \"ba\"]\r\nd = {}\r\nans = [0, 0, 0]\r\nfor ind, i in enumerate(map(int, input().split())):\r\n d.setdefault(s[(ind % 3)], [0])[0] += i\r\nfor i in d:\r\n if i == 'c':\r\n ans[0] = d[i][0]\r\n elif i == 'bi':\r\n ans[1] = d[i][0]\r\n else:\r\n ans[2] = d[i][0]\r\n\r\nif ans[0] > ans[1] and ans[0] > ans[2]:\r\n print(\"chest\")\r\nelif ans[1] > ans[0] and ans[1] > ans[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nbrr = [0] * 3\r\nfor i in range(n):\r\n brr[i%3] += arr[i]\r\n\r\nprint(('chest', 'biceps', 'back')[brr.index(max(brr))])",
"from sys import stdin, setrecursionlimit, stdout\r\n\r\n\r\ndef solve():\r\n\r\n n = int(stdin.readline())\r\n mas = [int(s) for s in stdin.readline().split()]\r\n k = 0\r\n ans = [0]*3\r\n\r\n for i in range(n):\r\n ans[k] += mas[i]\r\n k = (k + 1) % 3\r\n\r\n if ans[0] > ans[1] and ans[0] > ans[2]:\r\n print('chest')\r\n elif ans[1] > ans[0] and ans[1] > ans[2]:\r\n print('biceps')\r\n else:\r\n print('back')\r\n\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n",
"n = int(input())\r\na = input().split()\r\na = [int(x) for x in a]\r\nc = 0\r\nbi = 0\r\nba = 0\r\nfor i in range(len(a)) :\r\n if i%3 == 0 :\r\n c += a[i]\r\n if i%3 == 1 :\r\n bi += a[i]\r\n if i%3 == 2 :\r\n ba += a[i]\r\nmaximum = max(c,bi,ba)\r\nif maximum == c :\r\n print(\"chest\")\r\nif maximum == bi :\r\n print(\"biceps\")\r\nif maximum == ba :\r\n print(\"back\")\r\n",
"n = int(input())\r\narr = list(map (int, input().split()))\r\n# n = 7 \r\n# arr = [5,1,0]\r\nbiceps,chest,back = 0,0,0\r\ni = 0\r\nfor itr in range(len(arr)) :\r\n if i == 0 :\r\n chest+=arr[itr]\r\n if i==1 :\r\n biceps +=arr[itr]\r\n \r\n if i == 2 :\r\n back += arr[itr]\r\n i+=1\r\n i = i%3\r\nif biceps > chest and biceps > back : \r\n print(\"biceps\") \r\nelif chest > biceps and chest > back : \r\n print(\"chest\") \r\nelse:\r\n print(\"back\")",
"ch=\"chest\"\nbi=\"biceps\"\nba=\"back\"\nm={ch:0,bi:0,ba:0}\nn=int(input())\na=map(int,input().split())\ns=[ch,bi,ba]*n\nz=zip(s[:n],a)\nfor e,ai in z:\n m[e]+=ai\nprint(max(m,key=m.get))\n\n\n\n",
"n=int(input())\r\nli=list(input().split())\r\nli1=[0,0,0]\r\nli2=['chest','biceps','back']\r\nfor i,j in enumerate(li):\r\n li1[int(i)%3]+=int(j)\r\nprint(li2[li1.index(max(li1))])\r\n\r\n",
"i=int(input())\r\nl=list(map(int,input().split()))\r\nx,y,z=0,0,0\r\nfor n in range(i):\r\n\tif n%3==0:x+=l[n]\r\n\telif n%3==1:y+=l[n]\r\n\telse:z+=l[n]\r\nif x>y and x>z:print(\"chest\")\r\nelif y>x and y>z:print(\"biceps\")\r\nelif z>x and z>y:print(\"back\")",
"n = int(input())\r\nlst = []\r\nlst = list(map(int, input().split()))\r\n\r\nc = 0\r\nb = 0\r\nba = 0\r\nfor i in range(0,n):\r\n if i % 3 == 0:\r\n c += lst[i]\r\n elif i % 3 == 1:\r\n b += lst[i]\r\n else:\r\n ba += lst[i]\r\n\r\n\r\nif c == max(c,b,ba):\r\n print('chest')\r\nelif b == max(c,b,ba):\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nmax_count = 0\r\nmax_muscle = \"\"\r\n\r\nmuscles = [\"chest\", \"biceps\", \"back\"]\r\nfor i in range(3):\r\n\tcount = 0\r\n\tfor j in range(i, len(a), 3):\r\n\t\tcount += a[j]\r\n\tif count > max_count:\r\n\t\tmax_count = count\r\n\t\tmax_muscle = muscles[i]\r\n\r\nprint(max_muscle)",
"n = int(input())\nnum = input()\na = []\n\n\ndef get_the_data(count, num, arr):\n for i in range(0, len(num)):\n if num[i] == ' ':\n arr.append(int(num[count:i]))\n count = i+1\n elif i == len(num)-1:\n arr.append(int(num[count:len(num)]))\n return arr\n\n\narr = get_the_data(0, num, a)\nchest = 0\nbicep = 0\nback = 0\nfor i in range(0,len(arr),3):\n chest += arr[i]\n if i+1 <= len(arr)-1:\n bicep += arr[i+1]\n if i+2 <= len(arr)-1:\n back += arr[i+2]\n\nif chest >back and chest > bicep:\n print('chest')\nelif bicep > chest and bicep > back:\n print('biceps')\nelse:\n print('back')\n\n",
"def main():\r\n m = int(input())\r\n vals = [int(v) for v in input().split()]\r\n biceps = 'biceps'\r\n back = 'back'\r\n chest = 'chest'\r\n freq = {\r\n biceps:0, back:0, chest:0\r\n }\r\n for i,v in enumerate(vals):\r\n if i%3==0:\r\n freq[chest]+=v\r\n elif i%3==1:\r\n freq[biceps]+=v\r\n elif i%3==2:\r\n freq[back]+=v\r\n res = sorted(freq.items(), key=lambda b:b[1], reverse=True)\r\n print(res[0][0])\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n = int(input())\r\nreps = list(map(int,input().split()))\r\nchest = []\r\nbiceps = []\r\nback = []\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest.append(reps[i])\r\n elif i % 3 == 1:\r\n biceps.append(reps[i])\r\n else:\r\n back.append(reps[i])\r\nif sum(chest) > sum(biceps) and sum(chest) > sum(back):\r\n print('chest')\r\nelif sum(biceps) > sum(chest) and sum(biceps) > sum(back):\r\n print('biceps')\r\nelse:\r\n print('back')",
"#F - Greg`s Workout\n#https://vjudge.net/contest/499284#problem/F\n#Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise ai times.\n#Greg now only does three types of exercises: \"chest\" exercises, \"biceps\" exercises and \"back\" exercises. Besides, his training is cyclic, that is, the first exercise he does is a \"chest\" one, the second one is \"biceps\", the third one is \"back\", the fourth one is \"chest\", the fifth one is \"biceps\", and so on to the n-th exercise.\n#Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.\n\n#input\n#The first line contains integer n (1 ≤ n ≤ 20). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 25) — the number of times Greg repeats the exercises.\n#output\n#Print word \"chest\" (without the quotes), if the chest gets the most exercise, \"biceps\" (without the quotes), if the biceps gets the most exercise and print \"back\" (without the quotes) if the back gets the most exercise.\n#It is guaranteed that the input is such that the answer to the problem is unambiguous.\n\n#sample 1\n#input\n#2\n#2 8\n#output\n#biceps\n\n#sample 2\n#input\n#3\n#5 1 10\n#output\n#back\n\n#sample 3\n#input\n#7\n#3 3 2 7 9 6 8\n#output\n#chest\n\n#note\n#In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.\n#In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.\n#In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.\nfrom asyncio.windows_events import NULL\nfrom textwrap import indent\n\n\ninput_list=[]\nn=int(input())\nstring=input()\nstring=string.split(\" \")\nfor item in string:\n input_list.append(int(item))\n#input_list=[3,3,2 , 7,9,6 , 8]\n# 0 1 2 3 4 5 6\n#input_list=[1,2,3 , 1,2,3 , 1]\n\n\noutputlist=[0,0,0]\nfor i in range(0,len(input_list),3): #frint fist \n #i jumps to the first digit of 3 block\n x=i\n count=0\n for j in range(x,x+3):\n if j>(len(input_list)-1):\n break\n #print(input_list[j],end=\" \")\n temp=outputlist[count]+input_list[j]\n outputlist[count]=temp\n count=count+1\n if count>2:\n count=0\n\n #print(input_list[i])\n #print()\n#print()\n#for i in range(0,len(input_list),2): #frint fist \n# print(input_list[i])\n#print(outputlist)\ndef return_max_index(list):\n max=list[0]\n index=NULL\n for i in range(0,len(list)):\n if list[i]>max:\n index=i\n max=list[i]\n return index\n\nx=return_max_index(outputlist)\nif x==0:\n print(\"chest\")\nelif x==1:\n print(\"biceps\")\nelif x==2:\n print(\"back\")\n\n\n\n\n\n\n\t \t\t \t \t\t \t\t\t \t \t \t\t\t\t\t \t\t\t",
"n = int(input())\na = list(map(int, input().split()))\n\nI=0\nii=0\niii=0\n\nfor i in range(n):\n\tif i%3==0: I+=a[i]\n\tif i%3==1: ii+=a[i]\n\tif i%3==2: iii+=a[i]\nif ii<I>iii:print(\"chest\")\nif I<ii>iii:print(\"biceps\")\nif I<iii>ii:print(\"back\")\n",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nk = 0\r\nz = 0\r\nl = 0\r\n'''chest'''\r\nfor i in range(0, len(a), 3):\r\n k += a[i]\r\n'''biceps'''\r\nfor i in range(1, len(a), 3):\r\n z += a[i]\r\n'''back'''\r\nfor i in range(2, len(a), 3):\r\n l += a[i]\r\n\r\nj = max(k, z, l)\r\nif j == k:\r\n print('chest')\r\nif j == z:\r\n print('biceps')\r\nif j == l:\r\n print('back')",
"n = int(input())\narr = list(map(int,input().split()))\nchest, biceps, back = 0,0,0\nfor i in range(0,len(arr),3):\n chest += arr[i]\nfor i in range(1,len(arr),3):\n biceps += arr[i]\nfor i in range(2,len(arr),3):\n back += arr[i]\nmxx = max(chest,biceps,back)\nif mxx == chest:\n print(\"chest\")\nelif mxx == biceps:\n print(\"biceps\")\nelse:\n print(\"back\")\n\n\n \t \t \t\t\t\t \t \t \t\t \t \t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\nx = 0\r\ny = 0\r\nz = 0\r\nfor i in range(0,n,3):\r\n x += a[i]\r\nfor j in range(1,n,3):\r\n y += a[j]\r\nfor k in range(2,n,3):\r\n z += a[k]\r\nif max(x,y,z) == x:\r\n print('chest')\r\nelif max(x,y,z) == y:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\nb = 0 \nc = 0 \nba = 0 \nmas = list(map(int,input().split()))\nfor i in range(n):\n if i%3==0:\n c += mas[i] \n elif i%3==1:\n b += mas[i]\n else:\n ba += mas[i]\nif c>b and c>ba:\n print(\"chest\")\nelif b>c and b>ba:\n print(\"biceps\")\nelse:\n print(\"back\")\n ",
"n=int(input())\r\na=[int(x)for x in input().split()]\r\nexercise=[0,0,0]\r\ni=0\r\nj=0\r\nwhile i<n:\r\n exercise[j]+=a[i]\r\n i+=1\r\n j+=1\r\n if j==3:\r\n j=0\r\nm=max(exercise)\r\nif m==exercise[0]:\r\n print(\"chest\")\r\nelif m==exercise[1]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\narr=[int(i) for i in input().split()]\r\nc,bi,ba=0,0,0\r\nfor i in range(n):\r\n if i%3==0:\r\n c=c+arr[i]\r\n elif (i+2)%3==0:\r\n bi=bi+arr[i]\r\n elif (i+1)%3==0:\r\n ba=ba+arr[i]\r\nif c>bi:\r\n if c>ba:\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\nelse:\r\n if bi>ba:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n ",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nnumberBiceps = 0 # 0,3,6\r\nnumberBack = 0 # 1,4,7\r\nnumberChest = 0 # 2,5,8\r\n\r\nfor i in range(0,n):\r\n if i % 3 == 0:\r\n numberChest += a[i]\r\n elif (i - 1) % 3 == 0:\r\n numberBiceps += a[i]\r\n elif (i - 2) % 3 == 0:\r\n numberBack += a[i] \r\n\r\nif numberBiceps > numberBack and numberBiceps > numberChest:\r\n print('biceps')\r\nelif numberBack > numberBiceps and numberBack > numberChest:\r\n print(\"back\")\r\nelif numberChest > numberBiceps and numberChest > numberBack:\r\n print(\"chest\")\r\nelse:\r\n print(1%3)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc,b,ba=0,0,0\r\nfor i in range(0,n,3):\r\n\tc+=l[i]\r\nfor i in range(1,n,3):\r\n\tb+=l[i]\r\nfor i in range(2,n,3):\r\n\tba+=l[i]\r\nx=max(c,b,ba)\r\nif x==c:\r\n\tprint('chest')\r\nelif x==b:\r\n\tprint('biceps')\r\nelse:\r\n\tprint('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc=0\r\nbi=0\r\nba=0\r\nfor i in range(n):\r\n if i%3==0:\r\n c+=a[i]\r\n elif i%3==1:\r\n bi+=a[i]\r\n else:\r\n ba+=a[i]\r\nx=max(c,bi,ba)\r\nif x==c:\r\n print('chest')\r\nelif x==bi:\r\n print('biceps')\r\nelse:\r\n print('back')",
"import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\ninput=sys.stdin.readline\r\nn=int(input())\r\nl=[int(i) for i in input().split()]\r\ns1,s2,s3=0,0,0\r\nfor i in range(n):\r\n if(i%3==0):\r\n s1+=l[i]\r\n elif(i%3==1):\r\n s2+=l[i]\r\n else:\r\n s3+=l[i]\r\nm=max(s1,s2,s3)\r\nif(m==s1):\r\n print(\"chest\")\r\nelif(m==s2):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = list(map(int,input().split()))\r\nchest = []\r\nbiceps = []\r\nback = []\r\nc = 0\r\nfor i in range(len(a)):\r\n if c%3==0:\r\n chest.append(a[i])\r\n c+=1\r\n elif c%3==1:\r\n biceps.append(a[i])\r\n c+=1\r\n elif c%3==2:\r\n back.append(a[i])\r\n c+=1\r\nq = sum(chest)\r\nw = sum(biceps)\r\ne = sum(back)\r\nif q>w and q>e:\r\n print(\"chest\")\r\nelif w>q and w>e:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"#gregsworkout\nN = input()\nT = [int(x) for x in input().split()]\nexer = {0:0, 1:0, 2:0}\nres = {0:\"chest\", 1:\"biceps\", 2:\"back\"}\nfor i in range(len(T)):\n exer[i%3] += T[i]\nprint(res[max(exer, key=exer.get)])",
"n = int(input())\r\ncount_repeat = [int(i) for i in input().split()]\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor k in range(0, len(count_repeat), 3):\r\n chest += count_repeat[k]\r\nfor j in range(1, len(count_repeat), 3):\r\n biceps += count_repeat[j]\r\nfor l in range(2, len(count_repeat), 3):\r\n back += count_repeat[l]\r\n\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps > chest and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Mar 14 22:04:46 2020\r\n\r\n@author: DELL\r\n\"\"\"\r\nc=0\r\nbi=0\r\nba=0\r\nn=int(input())\r\nm=list(map(int,input().split()))\r\nx=1\r\nfor i in m:\r\n if x==1:\r\n c+=i\r\n elif x==2:\r\n bi+=i\r\n elif x==3:\r\n ba+=i\r\n x=0\r\n x+=1\r\nif c>ba and c>bi:\r\n print('chest')\r\nelif ba>c and ba>bi:\r\n print('back')\r\nelif bi>c and bi>ba:\r\n print('biceps')\r\n ",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest=[]\r\nbiseps=[]\r\nback=[]\r\n\r\nfor i in range(0,len(l),3):\r\n chest.append(l[i])\r\n\r\nfor i in range(1,len(l),3):\r\n biseps.append(l[i])\r\n\r\nfor i in range(2,len(l),3):\r\n back.append(l[i])\r\n\r\nch=sum(chest)\r\nbi=sum(biseps)\r\nba=sum(back)\r\n\r\nnew=[ch,bi,ba]\r\nif max(new)==ch:\r\n print(\"chest\")\r\n \r\nif max(new)==bi:\r\n print(\"biceps\")\r\n \r\nif max(new)==ba:\r\n print(\"back\")\r\n",
"x = input()\r\ninp = input().split(\" \")\r\nchest = 0\r\nback = 2\r\nbiceps = 1\r\ncount = [0, 0, 0]\r\nfor i in range(len(inp)):\r\n if i==chest:\r\n count[0]+=int(inp[chest])\r\n chest+=3\r\n if i==biceps:\r\n count[1]+=int(inp[biceps])\r\n biceps+=3\r\n if i==back:\r\n count[2]+=int(inp[back])\r\n back+=3\r\nmaxVal = max(count)\r\nif count[0]==maxVal:\r\n print(\"chest\")\r\nelif count[1]==maxVal:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"x=int(input())\r\n\r\nchest=0\r\nbiceps=0\r\nback=0\r\n\r\ny=input()\r\nyy=y.split()\r\n\r\nnew=[]\r\n\r\nfor i in yy:\r\n new.append(int(i))\r\n \r\n\r\n\r\ncounter=0\r\nwhile counter<len(new):\r\n \r\n chest=chest+new[counter]\r\n \r\n counter=counter+1\r\n if counter==len(new):\r\n break\r\n\r\n \r\n\r\n biceps=biceps+new[counter]\r\n \r\n counter=counter+1\r\n if counter==len(new):\r\n break\r\n \r\n\r\n back=back+new[counter]\r\n counter=counter+1\r\n if counter==len(new):\r\n break\r\n\r\n\r\n \r\n\r\n\r\n\r\n#print(chest, biceps, back) \r\n\r\n\r\n\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n\r\n",
"l=['chest','biceps','back']\r\nl1=[0,0,0]\r\nn=int(input())\r\nx=[int(i) for i in input().split()]\r\nfor a in range(n):\r\n l1[a%3]+=x[a]\r\nprint(l[l1.index(max(l1))])\r\n",
"def solve():\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n s = {sum(a[0::3]) : \"chest\" , sum(a[1::3]): \"biceps\",sum(a[2::3]): \"back\"}\r\n print(s[max(s)])\r\n#for _ in range(int(input())): \r\nsolve()",
"a = int(input())\r\nk = [0, 0, 0]\r\np = 0\r\nx = list(map(int, input().split()))\r\nfor i in range(a):\r\n if p == 3:\r\n p = 0\r\n k[p] += x[i]\r\n p += 1\r\nv = max(k[0], k[1], k[2])\r\nif k[0] == v:\r\n print('chest')\r\nif k[1] == v:\r\n print('biceps')\r\nif k[2] == v:\r\n print('back')",
"n = int(input())\r\ns = list(map(int, input().split()))\r\n\r\n\r\nmapper = {\r\n 0: 'chest',\r\n 1: 'biceps',\r\n 2: 'back'\r\n}\r\n\r\ncounts = [0,0,0]\r\nmax_index = 0\r\ncurr_max = 0\r\nfor i in range(n):\r\n curr_index = i % 3 \r\n counts[curr_index] += s[i]\r\n if counts[curr_index] > curr_max:\r\n curr_max = counts[curr_index]\r\n max_index = curr_index\r\n \r\nprint(mapper[max_index])\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor i in range (n):\r\n if (i+1) % 3 == 1:\r\n chest += a[i]\r\n elif (i+1) % 3 == 2:\r\n biceps += a[i]\r\n elif (i+1) % 3 == 0:\r\n back += a[i]\r\n\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelif back > chest and back > biceps:\r\n print(\"back\")",
"n = int(input())\r\ns = input().split()\r\np = [int(i) for i in s]\r\nc=0\r\nbi=0\r\nba=0\r\nfor i in range(1,n+1):\r\n if i%3 == 1:\r\n c+=p[i-1]\r\n elif i%3 == 2:\r\n bi+=p[i-1]\r\n else:\r\n ba+=p[i-1]\r\nif c>bi and c>ba:\r\n print(\"chest\")\r\nelif bi>ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"x=int(input())\r\nrepeats=list(map(int, input().split()))\r\n\r\nchests=repeats[::3]\r\nchests=sum(chests)\r\n\r\nbiceps=repeats[1::3]\r\nbiceps=sum(biceps)\r\n \r\nback=repeats[2::3]\r\nback=sum(back)\r\n \r\nif max(chests, biceps, back) == chests:\r\n print('chest')\r\nelif max(chests, biceps, back) == biceps:\r\n print('biceps')\r\nelif max(chests, biceps, back) == back:\r\n print('back')",
"n=int(input())\r\nchest=0\r\n\r\nbiceps=0\r\n\r\nback=0\r\n\r\nlst=list(map(int,input().rstrip().split()))\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=lst[i]\r\n elif i%3==1:\r\n biceps+=lst[i]\r\n else:\r\n back+=lst[i]\r\nif biceps > max(chest,back):\r\n print(\"biceps\")\r\nelif chest > max(biceps,back):\r\n print(\"chest\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nnl=list(map(int,input().split()))\r\nc,bi,ba=0,0,0\r\n#ns=['chest','biceps','back']\r\nfor i in range(n):\r\n j=i%3\r\n if(j==0):\r\n c+=nl[i]\r\n elif(j==1):\r\n bi+=nl[i]\r\n elif(j==2):\r\n ba+=nl[i]\r\nans=max(c,bi,ba)\r\nif(ans==c):\r\n print('chest')\r\nelif(ans==bi):\r\n print('biceps')\r\nelse:\r\n print('back')\r\n ",
"n = int(input())\r\na = list(map(int,input().split()))\r\nb = [0,0,0]\r\nfor i in range(n):\r\n b[i%3] += a[i]\r\nprint([\"chest\",\"biceps\",\"back\"][b.index(max(b))])",
"nstr=input()\r\nn=int(nstr)\r\nlstr=input()\r\nl=lstr.split()\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(0,n):\r\n s=l[i]\r\n num=int(s)\r\n if i%3==0:\r\n chest=chest+num\r\n elif i%3==1:\r\n biceps=biceps+num\r\n else:\r\n back=back+num\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelse:\r\n print('back') \r\n ",
"t = int(input())\r\nx = list(map(int, input().split()))\r\na = 0\r\nb = 0\r\nc = 0\r\nfor i in range(t):\r\n if i%3 == 0:\r\n a += x[i]\r\n elif i%3 == 1:\r\n b += x[i]\r\n else:\r\n c += x[i]\r\nn = max(a,b,c)\r\nif a == n:\r\n print(\"chest\")\r\nelif b == n:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"a=int(input())\r\nb=list(map(int,input().split()))\r\na1=0\r\na2=0\r\na3=0\r\nr=0\r\nfor i in range(a):\r\n r+=1\r\n if r==1:\r\n a1+=b[i]\r\n elif r==2:\r\n a2+=b[i]\r\n elif r==3:\r\n a3+=b[i]\r\n if r==3:\r\n r=0\r\na4=[a1,a2,a3]\r\nif max(a4)==a1:\r\n print(\"chest\")\r\nelif max(a4)==a2:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\np = input().split()\r\nsuma, sumb, sumc = 0, 0, 0\r\nfor i1 in range(0,n,3):\r\n suma += int(p[i1])\r\nfor i2 in range(1,n,3):\r\n sumb +=int(p[i2])\r\nfor i3 in range(2,n,3):\r\n sumc += int(p[i3])\r\nmaxsum = max(suma,sumb,sumc)\r\nif suma==maxsum:\r\n print(\"chest\")\r\nif sumb == maxsum:\r\n print(\"biceps\")\r\nif sumc == maxsum:\r\n print(\"back\")",
"x=int(input())\r\narr = list(map(int, input().split()))\r\nchest = sum(arr[::3])\r\nbiceps = sum(arr[1::3])\r\nback = sum(arr[2::3])\r\narr=[chest,biceps,back]\r\nprint((\"chest\", \"biceps\", \"back\")[arr.index(max(arr))])",
"n = int(input())\r\ninput_list = list(map(int,input().split()))\r\n\r\nchest = bicep = back = 0\r\n\r\nfor i in range(n):\r\n if i%3 == 0:\r\n chest += input_list[i]\r\n elif i%3 == 1:\r\n bicep += input_list[i]\r\n else:\r\n back += input_list[i]\r\n\r\nif chest > bicep and chest > back:\r\n print('chest')\r\nelif bicep > chest and bicep > back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"def solution():\n num = int(input())\n li = list(map(int, input().split()))\n chest = 0\n biceps = 0\n back = 0\n checker = []\n for i in range(num):\n if len(checker) == 0:\n chest += li[i]\n checker.append('c')\n elif checker[-1] == 'c':\n biceps += li[i]\n checker.append('b')\n elif checker[-1] == 'b':\n back += li[i]\n checker.append('ba')\n elif checker[-1] == 'ba':\n chest += li[i]\n checker.append('c')\n if chest > biceps and chest > back:\n return print('chest')\n elif biceps > chest and biceps > back:\n return print('biceps')\n else:\n return print('back')\nsolution()\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nx=y=z=0\r\nfor i in range(n):\r\n\tif i%3==0:\r\n\t\tx+=a[i]\r\n\telif (i-1)%3==0:\r\n\t\ty+=a[i]\r\n\telse:\r\n\t\tz+=a[i]\r\nif max(x,y,z)==x:\r\n\tprint('chest')\r\nelif max(x,y,z)==y:\r\n\tprint('biceps')\r\nelse:\r\n\tprint('back')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nsum1=0\r\nsum2=0\r\nsum3=0\r\nfor i in range(0,n,3):\r\n sum1=sum1+l[i]\r\nfor i in range(1,n,3):\r\n sum2=sum2+l[i]\r\nfor i in range(2,n,3):\r\n sum3=sum3+l[i]\r\nif sum1>sum2 and sum1>sum3:\r\n print(\"chest\")\r\nelif sum2>sum3 and sum2>sum3:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"# import sys\r\n# sys.stdout = open('DSA/Stacks/output.txt', 'w')\r\n# sys.stdin = open('DSA/Stacks/input.txt', 'r')\r\n\r\nn = int(input())\r\nll = list(map(int, input().split()))\r\n\r\nchest = 0\r\nbicep = 0\r\nback = 0\r\ncurr = 1\r\nfor i in range(n):\r\n if curr==1:\r\n chest+=ll[i]\r\n curr=2\r\n elif curr==2:\r\n bicep+=ll[i]\r\n curr=3\r\n else:\r\n back+=ll[i]\r\n curr=1\r\n\r\nif chest > back and chest > bicep:\r\n print(\"chest\")\r\nelif back > chest and back > bicep:\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nchest = sum([a[i] for i in range(0, n, 3)])\r\nbicep = sum([a[i] for i in range(1, n, 3)])\r\nback = sum([a[i] for i in range(2, n, 3)])\r\n\r\nif chest > bicep and chest > back:\r\n\tprint(\"chest\")\r\nelif bicep > chest and bicep > back:\r\n\tprint(\"biceps\")\r\nelif back > bicep and back > chest:\r\n\tprint(\"back\")",
"n=int(input())\r\nl=list(map(int,input().strip().split()))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(1,n+1):\r\n if i%3==0:\r\n c +=l[i-1]\r\n elif i%3==1:\r\n a +=l[i-1]\r\n elif i%3==2:\r\n b +=l[i-1]\r\nif max(a,b,c)==a:\r\n print(\"chest\")\r\nelif max(a,b,c)==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nche=0\r\nbic=0\r\nbac=0\r\nc=0\r\nbi=0\r\nba=0\r\nfor i in arr:\r\n if che==bic==bac:\r\n c+=i\r\n che+=1\r\n elif bic==bac and che>bac:\r\n bi+=i\r\n bic+=1\r\n elif bic == che and bac<che:\r\n ba+=i\r\n bac+=1\r\n \r\nif max(c,bi,ba)==c:\r\n print(\"chest\")\r\nelif max(c,bi,ba)==bi:\r\n print(\"biceps\")\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(n):\r\n if(i%3 == 0):\r\n chest += a[i]\r\n elif(i%3 == 1):\r\n biceps += a[i]\r\n else:\r\n back += a[i]\r\nif(chest >= biceps and chest >= back):\r\n print('chest')\r\nelif(biceps >= chest and biceps >= back):\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\nar = list(map(int, input().split()))\r\n\r\ndic = {'chest': 0, 'biceps': 0, 'back': 0}\r\nf = 1\r\nfor i in ar:\r\n if f == 1:\r\n dic['chest'] += i\r\n f+=1\r\n elif f == 2:\r\n dic['biceps']+= i\r\n f += 1\r\n elif f == 3:\r\n dic['back'] += i\r\n f = 1\r\n\r\nmax = 0\r\n# print(dic)\r\nfor i in dic:\r\n if dic[i] > max:\r\n op = i\r\n max = dic[i]\r\nprint(op)\r\n \r\n ",
"int(input())\nlist_1= list(map(int,input().split()))\nc= sum([list_1[i] for i in range(len(list_1)) if i%3==0])\nbi= sum([list_1[i] for i in range(len(list_1)) if i%3==1])\nba= sum([list_1[i] for i in range(len(list_1)) if i%3==2])\n\nx= max(c, bi, ba)\n\nif x==c:\n print(\"chest\")\nelif x== bi:\n print(\"biceps\")\nelse:\n print(\"back\")\n\t\t \t \t\t\t\t\t \t \t\t\t \t\t \t",
"number = int(input())\r\nelements = [int(el) for el in input().split(\" \")]\r\ndict = {'biceps': 0, 'back': 0, 'chest': 0}\r\nfor i in range(len(elements)):\r\n if i % 3 == 1:\r\n dict['biceps'] += elements[i]\r\n if i % 3 == 2:\r\n dict['back'] += elements[i]\r\n if i % 3 == 0:\r\n dict['chest'] += elements[i]\r\nmax_el = 0\r\nans = ''\r\nfor key, value in dict.items():\r\n if value > max_el:\r\n max_el = value\r\n ans = key\r\nprint(ans)",
"# -*- coding: utf-8 -*-\n\"\"\"Untitled75.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1D1x8mgVYBiLay890KzZPAq2TMoXX-k_G\n\"\"\"\n\nn=int(input())\nl1=list(map(int,input().split()))\nx=0\na=0\nb=0\nc=0\nwhile x<len(l1):\n if x<len(l1):\n a=a+l1[x]\n x=x+1\n if x<len(l1):\n b=b+l1[x]\n x=x+1\n if x<len(l1):\n c=c+l1[x]\n x=x+1\nd=max(a,b,c)\nif d==a:\n print(\"chest\")\nelif d==b:\n print(\"biceps\")\nelse:\n print(\"back\")",
"#F - Greg's Workout\n\nn = int(input())\na = list(map(int,input().split())) \nchest = []\nbiceps = []\nback = []\nbig = {}\ncount = 0\nfor i in range(len(a)):\n count = count+1\n \n if count==1:\n x = a[i]\n \n chest.append(x)\n elif count==2:\n y = a[i]\n \n biceps.append(y)\n elif count==3:\n z = a[i]\n \n back.append(z)\n count=0\n \n\nsum_c = sum(chest)\nbig[sum_c]=\"chest\"\nsum_bi = sum(biceps)\nbig[sum_bi]='biceps'\nsum_b = sum(back)\nbig[sum_b]= 'back'\n\n\n\nmx = max(big.keys())\n\nprint(big[mx])\n\n\n \t\t \t \t\t \t \t \t\t\t\t",
"n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(0,n,3):\r\n chest+=a[i]\r\n\r\nfor j in range(1,n,3):\r\n biceps+=a[j]\r\n\r\nfor k in range(2,n,3):\r\n back+=a[k]\r\n\r\n\r\nmaxVal = max(chest,biceps,back)\r\n\r\nif maxVal == chest:\r\n print(\"chest\")\r\nelif maxVal == biceps:\r\n print(\"biceps\")\r\nelif maxVal == back:\r\n print(\"back\")\r\n\r\n \r\n \r\n \r\n",
"input()\r\na=[int(i) for i in input().split()]\r\nchest=a[0::3]\r\nbiceps=a[1::3]\r\nback=a[2::3]\r\nif sum(chest)>sum(biceps) and sum(chest)>sum(back):\r\n print('chest')\r\nelif sum(biceps)>sum(chest) and sum(biceps)>sum(back):\r\n print('biceps')\r\nelse: print('back')",
"n=int(input())\r\nnums=input().split()\r\nchest,biceps,back=0,0,0\r\ntry:\r\n for i in range(0,n,3):\r\n chest += int(nums[i])\r\n biceps += int(nums[i+1])\r\n back += int(nums[i+2])\r\nexcept IndexError:\r\n pass\r\n\r\nif max(chest,biceps,back) == chest:\r\n print('chest')\r\nelif max(biceps, back) == biceps:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ni=0\r\ns1,s2,s3=0,0,0\r\np1=1\r\np2=2\r\np3=3\r\ni1,i2,i3=0,0,0\r\nfor i in range(len(l)):\r\n if((i+1)==p1+3*i1):\r\n s1+=l[i]\r\n i1+=1\r\n elif((i+1)==p2+3*i2):\r\n s2+=l[i]\r\n i2+=1\r\n elif((i+1)==p3+3*i3):\r\n s3+=l[i]\r\n i3+=1\r\n#print(max(s1,s2,s3))\r\nif(s1>=s2 and s1>=s3):\r\n print(\"chest\")\r\nelif(s2>=s1 and s2>=s3):\r\n print(\"biceps\")\r\nelif(s3>=s1 and s3>=s2):\r\n print(\"back\")\r\n\r\n\r\n",
"n = int(input())\r\narr = [int(o) for o in input().split(\" \")]\r\narr1 = [0,0,0]\r\n\r\nfor i in range(len(arr)):\r\n if i%3==0:\r\n arr1[0]+=arr[i]\r\n elif i%3==1:\r\n arr1[1]+=arr[i]\r\n else:\r\n arr1[2]+=arr[i]\r\n\r\n\r\nx = max(arr1)\r\nswitcher = {arr1[0]:\"chest\",arr1[1]:\"biceps\",arr1[2]:\"back\"}\r\nprint(switcher[x])",
"n = int(input())\r\nl = list(map(int,input().split()))\r\ncount_a = 0\r\ncount_b = 0\r\ncount_c = 0\r\nfor i in range(len(l)):\r\n if (i+1)%3 == 1:\r\n count_a+=l[i]\r\n elif (i+1)%3 == 2:\r\n count_b+=l[i]\r\n else:\r\n count_c+=l[i]\r\nif max(count_b,count_a,count_c) == count_a:\r\n print(\"chest\")\r\nelif max(count_b,count_a,count_c) == count_b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = list(map(int, input().split()))\r\nj = 0\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor i in range(n):\r\n\r\n if j == 0:\r\n chest = chest+a[i]\r\n j = 1\r\n elif j == 1:\r\n biceps = biceps+a[i]\r\n j = 2\r\n else:\r\n back = back+a[i]\r\n j = 0\r\n\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif back > biceps and back > chest:\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")",
"n = int(input())\r\nsum1 = 0\r\nsum2 = 0\r\nsum3 = 0\r\nl = list(map(int,input().split()))\r\nfor i in range(0,n,3):\r\n sum1 += l[i]\r\nfor j in range(1,n,3):\r\n sum2 += l[j]\r\nfor k in range(2,n,3):\r\n sum3 += l[k]\r\nif sum1 == max(sum1,sum2,sum3):\r\n print(\"chest\")\r\nelif sum2 == max(sum1,sum2,sum3):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nz = list(map(int,input().split()))\r\na,b,c= 0,0,0\r\nfor i in range(n):\r\n\tif i%3==0:\r\n\t\ta+=z[i]\r\n\telif i%3==1:\r\n\t\tb+=z[i]\r\n\telif i%3==2:\r\n\t\tc+=z[i]\r\nx = max(a,b,c)\r\nif x ==a:\r\n\tprint(\"chest\")\r\nelif x == b:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nbis=0\r\nback=0\r\n\r\na=n%3\r\n\r\nfor i in range(0,len(l)-a,3):\r\n c=c+l[i]\r\n bis=bis+l[i+1]\r\n back=back+l[i+2]\r\n\r\nif(a==1):\r\n c=c+l[-1]\r\nelif(a==2):\r\n c=c+l[-2]\r\n bis=bis+l[-1]\r\n\r\nif(c>bis and c>back):\r\n print(\"chest\")\r\nelif(bis>c and bis>back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"a=[0,0,0]\r\nb=[\"chest\",\"biceps\",\"back\"]\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(n):\r\n a[i%3]+=l[i]\r\nprint(b[a.index(max(a))])",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nd = {}\r\nd[0] = 0\r\nd[1] = 0\r\nd[2] = 0\r\n\r\nfor i in range(n):\r\n\td[i%3] += a[i]\r\n\r\nres = max(d[0], d[1], d[2])\r\n\r\n\r\nif res == d[0]:\r\n\tprint('chest')\r\nelif res == d[1]:\r\n\tprint('biceps')\r\nelse:\r\n\tprint('back')\r\n",
"length = int(input())\r\nlist_ = list(map(int, input().split()))\r\none = 0\r\ntwo = 0\r\nthree = 0\r\n\r\nfor index in range(0,length,3):\r\n one += list_[index]\r\nfor index in range(1,length,3):\r\n two += list_[index]\r\nfor index in range(2,length,3):\r\n three += list_[index]\r\n\r\nmax_ = max(one, two, three)\r\n\r\nif max_ == one:\r\n print(\"chest\")\r\nelif max_ == two:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nk=0\r\nl=0\r\nm=0\r\na = [int(x) for x in input().split()]\r\nfor i in range(len(a)):\r\n if (i+1)%3==1:\r\n k+=a[i]\r\n if (i+1)%3==2:\r\n l+=a[i]\r\n if (i+1)%3==0:\r\n m+=a[i]\r\nif max(k,l,m)==k:\r\n print(\"chest\")\r\nelif max(k,l,m)==l:\r\n print(\"biceps\")\r\nelif max(k,l,m)==m:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc,j=0,0\r\np,k=0,1\r\nb,l=0,2\r\nfor i in range(n):\r\n\tif i==j:\r\n\t\tc+=a[i]\r\n\t\tj+=3\r\n\tif i==k:\r\n\t\tp+=a[i]\r\n\t\tk+=3\r\n\tif i==l:\r\n\t\tb+=a[i]\r\n\t\tl+=3\r\nx=max(c,b,p)\t\t\r\nif c==x:\r\n\tprint(\"chest\")\r\nelif p==x:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")",
"n=int(input())\r\nl = list(map(int,input().split()))\r\nl3=[]\r\nif len(l)==1:\r\n print('chest')\r\nelif len(l)==2:\r\n print('chest' if l[0]>l[1] else 'biceps')\r\nelse:\r\n l1 = l[::3]\r\n l2 = l[1::3]\r\n l3 = sum(l)-(sum(l2)+sum(l1))\r\n if sum(l1)==max(sum(l1),sum(l2),l3):\r\n print('chest')\r\n elif sum(l2)==max(sum(l1),sum(l2),l3):\r\n print('biceps')\r\n else:\r\n print('back')",
"a = int(input())\nb = list(map(int, input().split()))\nchestlist = []\nbicepslist = []\nbacklist = []\nn = 0\ncount = 0\nwhile count<len(b):\n if n>=len(b):\n break\n chestlist.append(b[n])\n n+=3\n\nn=1\nwhile count<len(b):\n if n>=len(b):\n break\n bicepslist.append(b[n])\n n+=3\n\nn=2\nwhile count<len(b):\n if n>=len(b):\n break\n backlist.append(b[n])\n n+=3\n\n\nchest = sum(chestlist)\nbiceps = sum(bicepslist)\nback = sum(backlist)\n\nif chest > biceps and chest > back:\n print(\"chest\")\nelif biceps > chest and biceps > back:\n print(\"biceps\")\nelse:\n print(\"back\")\n \t\t \t \t \t \t \t\t \t\t\t\t \t\t \t\t",
"n = int(input())\r\nli = list(map(int,input().split()))\r\nc,b,d=0,0,0\r\nfor i in range(len(li)):\r\n if(i%3==0):\r\n c+=li[i]\r\n elif(i%3==1):\r\n b+=li[i]\r\n elif(i%3==2):\r\n d+=li[i]\r\n#print(c,b,d)\r\nif(c>b and c>d):\r\n print(\"chest\")\r\nelif(b>c and b>d):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"l1=0\r\nl2=0\r\nl3=0\r\nn=int(input())\r\nx=[int(q) for q in input().split()]\r\nfor i in range(len(x)):\r\n if i%3==0:\r\n l1+=x[i]\r\n if i%3==1:\r\n l2+=x[i]\r\n if i%3==2:\r\n l3+=x[i]\r\nq=max(l1,l2,l3)\r\nif q==l1:\r\n print(\"chest\")\r\nif q==l2:\r\n print(\"biceps\")\r\nif q==l3:\r\n print(\"back\")",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nc = 0\r\nb = 0\r\nba = 0\r\nfor i in range(n):\r\n if i%3 == 0:\r\n c += l[i]\r\n elif i%3 == 1:\r\n b += l[i]\r\n else:\r\n ba += l[i]\r\nm = max(c,b,ba)\r\nif m == c:\r\n print('chest')\r\nif m == b:\r\n print('biceps')\r\nif m == ba:\r\n print('back')",
"n = int(input())\r\ndata = list(map(int,input().split()))\r\nchest = sum(data[i] for i in range(0,len(data),3))\r\nbiceps = sum(data[i] for i in range(1,len(data),3))\r\nback = sum(data[i] for i in range(2,len(data),3))\r\nif max(chest,biceps,back)==chest:\r\n print(\"chest\")\r\nelif max(chest,biceps,back)==biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n= int(input())\r\ns= [int(x) for x in input().split()]\r\nchest =0\r\nbiceps =0 \r\nback =0\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=s[i]\r\n elif i%3==1:\r\n biceps+=s[i]\r\n else:\r\n back+=s[i]\r\nif max(chest,biceps,back)==chest:\r\n print(\"chest\")\r\nelif max(chest,biceps,back)==biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\ncount_1 = 0\ncount_2 = 0\ncount_3 = 0\nline = list(map(int, input().split()))\n\nfor i in range(1, n + 1):\n calculate = i % 3\n if calculate == 0:\n count_3 += line[i - 1]\n if calculate == 1:\n count_1 += line[i - 1]\n if calculate == 2:\n count_2 += line[i - 1]\n\nmax_num = max(count_1, count_2, count_3)\n\nif max_num == count_1:\n print(\"chest\")\nif max_num == count_2:\n print(\"biceps\")\nif max_num == count_3:\n print(\"back\")\n\n\t\t\t\t\t \t\t\t \t\t\t \t \t \t \t \t\t",
"n=int(input())\nl=list(map(int,input().split()))\nif n%3!=0:\n a=((((len(l))//3)+1)*3)-len(l)\nelse:\n a=n\nl+=[0]*a\nb=c=d=0\nfor i in range(0,len(l),3):\n b+=l[i]\n c+=l[i+1]\n d+=l[i+2]\nif b==max(b,c,d):\n print(\"chest\")\nelif c==max(b,c,d):\n print(\"biceps\")\nelse:\n print(\"back\")\n ",
"n = input()\r\nlst = input().split()\r\nlist = [int(itm) for itm in lst]\r\n\r\nchest = 0\r\nback = 0\r\nbiceps = 0\r\ntmp = 1\r\nfor i in range(len(list)):\r\n if tmp == 2:\r\n biceps += int(list[i])\r\n tmp += 1\r\n elif tmp == 3:\r\n back += int(list[i])\r\n tmp = 1\r\n else:\r\n tmp += 1\r\n chest += int(list[i])\r\n\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse: print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nk=[0]*3\r\nfor i in range(n): k[i%3]+=a[i]\r\nif k[0]>k[1] and k[0]>k[2]:\r\n print(\"chest\")\r\nelif k[1]>k[0] and k[1]>k[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\nchest=[]\r\nbiceps=[]\r\nback=[]\r\n\r\nfor i in range(0,n,3):\r\n chest.append(a[i])\r\n\r\nfor i in range(1,n,3):\r\n biceps.append(a[i])\r\n \r\nfor i in range(2,n,3):\r\n back.append(a[i])\r\n\r\n#print(chest, biceps, back, sep='\\n')\r\n\r\nm=max(sum(chest),sum(biceps),sum(back))\r\n\r\nif sum(chest)==m:\r\n print('chest')\r\nelif sum(biceps)==m:\r\n print('biceps')\r\nelse:\r\n print('back')",
"no_of_exercises = int(input())\r\n\r\nrepeat_exer = list(map(int, input().split())) + ([0] * (3 - (no_of_exercises % 3)))\r\nchest = sum([repeat_exer[i] for i in range(0, no_of_exercises + 1, 3 )])\r\nbiceps = sum([repeat_exer[i] for i in range(1, no_of_exercises + 1, 3 )])\r\nback = sum([repeat_exer[i] for i in range(2, no_of_exercises + 1, 3 )])\r\n\r\nif chest > biceps and chest > back :\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back :\r\n print(\"biceps\")\r\nelse :\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nche=0\r\nbi=0\r\nba=0\r\nfor i in range(n):\r\n if i%3==0:\r\n che+=a[i]\r\n if i%3==1:\r\n bi+=a[i]\r\n if i%3==2:\r\n ba+=a[i]\r\n\r\nif che==max(che,ba,bi):\r\n print(\"chest\")\r\nelif ba==max(che,ba,bi):\r\n print(\"back\")\r\nelif bi==max(che,ba,bi):\r\n print(\"biceps\")",
"n = int(input())\r\ne = [int(i) for i in input().split()]\r\n\r\nmuscles = {\"chest\": 0, \"biceps\": 0, \"back\": 0}\r\ncount = 0\r\n\r\nfor i in e:\r\n count += 1\r\n if count == 1:\r\n muscles[\"chest\"] += i\r\n elif count == 2:\r\n muscles[\"biceps\"] += i\r\n else:\r\n muscles[\"back\"] += i\r\n count = 0\r\n\r\nval = max(muscles.values())\r\n\r\nfor item in muscles:\r\n if muscles[item] == val:\r\n print(item)\r\n exit()",
"b=[0,0,0]\r\nc=0\r\nn=int(input())\r\n\r\ne=list(map(int,input().split()))\r\nfor i in e:\r\n if c==3:\r\n c=0\r\n \r\n \r\n b[c]=i+b[c]\r\n c+=1\r\nif max(b)==b[0]:\r\n print('chest')\r\nelif max(b)==b[1]:\r\n print('biceps ')\r\nelse:\r\n print('back')",
"n = input()\nx=list(map(int,input().split()))\nprint([\"chest\",\"biceps\",\"back\"][max(0,1,2,key=lambda i:sum(x[i::3]))])\n\t \t \t \t\t\t \t \t \t \t\t \t \t",
"n=int(input())\r\n\r\nl=list(map(int,input().split()))\r\nc=0\r\nbi=0\r\nba=0\r\nfor i in range(n):\r\n if i%3==0:\r\n c+=l[i]\r\n elif i%3==1:\r\n bi+=l[i]\r\n elif i%3==2:\r\n ba+=l[i]\r\n \r\nif c>bi and c>ba:\r\n print(\"chest\")\r\nelif bi>c and bi>ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n= int(input())\r\nx = list(map(int, input().split()))\r\nch=0\r\nbi=0\r\nb=0\r\n\r\nfor i in range(n):\r\n if i%3==0:\r\n ch+=x[i]\r\n elif i %3 ==1:\r\n bi+=x[i]\r\n else:\r\n b+=x[i]\r\n\r\nif ch>bi and ch>b:\r\n print('chest')\r\nelif bi>ch and bi >b:\r\n print('biceps')\r\nelse:\r\n print('back')",
"t = int(input())\r\nlst = list(map(int, input().split()))\r\nch = 0\r\nbic= 0\r\nback = 0\r\nfor x in range(0, t,3):\r\n ch += lst[x]\r\nfor x in range(1,t,3):\r\n bic += lst[x]\r\nfor x in range(2,t,3):\r\n back += lst[x]\r\nif ch == max(ch,back,bic):\r\n print(\"chest\")\r\nelif bic == max(ch,back,bic):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n\r\n\r\n",
"n = int(input())\n\nc=0\nbi=0\nba=0\n\na = list(map(int, input().split()))\nfor i in range(0,n):\n if i%3 ==0:\n c+=a[i]\n elif i%3==1:\n bi+=a[i]\n else:\n ba+=a[i]\n\nmaxi = max(c,bi,ba)\nif(maxi==c):\n print('chest')\nelif(maxi == bi):\n print('biceps')\nelse:\n print('back')",
"# tc = int(input())\r\ntc = 1\r\nwhile tc:\r\n # inp = [int(x) for x in input().split()]\r\n n = int(input())\r\n # n, k, l, c, d, p, nl, np = inp[0], inp[1], inp[2], inp[3], inp[4], inp[5], inp[6], inp[7]\r\n # a = input()\r\n # q = input()\r\n a = [int(x) for x in input().split()]\r\n chest = 0\r\n biceps = 0\r\n back = 0\r\n i = 0\r\n j = 1\r\n k = 2\r\n while i < n:\r\n chest += a[i]\r\n i += 3\r\n while j < n:\r\n biceps += a[j]\r\n j += 3\r\n while k < n:\r\n back += a[k]\r\n k += 3\r\n if chest > biceps and chest > back:\r\n print(\"chest\")\r\n elif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n tc -= 1\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nb=0\r\nbi=0\r\nfor i in range(0,n,3):\r\n\tc+=l[i]\r\nfor i in range(1,n,3):\r\n\tbi+=l[i]\r\nfor i in range(2,n,3):\r\n\tb+=l[i]\r\nif c>bi and c>b:\r\n\tprint('chest')\r\nelif bi>c and bi>b:\r\n\tprint('biceps')\r\nelse:\r\n\tprint('back')",
"#A. Greg's Workout\r\nn = int(input())\r\nexs = [int(x) for x in input().split()]\r\ntots = [0,0,0]\r\nfor i in range(n):\r\n if i % 3 == 0: tots[0] += exs[i]\r\n if i % 3 == 1: tots[1] += exs[i]\r\n if i % 3 == 2: tots[2] += exs[i]\r\n\r\nif tots[0] > tots[1] and tots[0] > tots[2]: print(\"chest\")\r\nif tots[1] > tots[0] and tots[1] > tots[2]: print(\"biceps\")\r\nif tots[2] > tots[1] and tots[2] > tots[0]: print(\"back\")",
"n=int(input())\r\narr=list(map(int,input().split()))\r\ns1=0\r\ns2=0\r\ns3=0\r\nfor i in range(n):\r\n if i%3==0:\r\n s1=s1+arr[i]\r\n elif (i-1)%3==0:\r\n s2=s2+arr[i]\r\n elif (i-2)%3==0:\r\n s3=s3+arr[i]\r\nif s1==max(s1,s2,s3):\r\n print(\"chest\")\r\nelif s2==max(s1,s2,s3):\r\n print(\"biceps\")\r\nelif s3==max(s1,s2,s3):\r\n print(\"back\")",
"n = int(input())\r\nk = [int(i) for i in input().split()]\r\na = 0\r\nb = 0\r\nc = 0\r\nl = ['back',\"chest\" ,'biceps']\r\ncnt = [0, 0, 0]\r\nfor i in range(1, n+1):\r\n cnt[i%3] += k[i-1]\r\nf = cnt.index(max(cnt))\r\nprint(l[f])",
"n=int(input())\r\ns=list(map(int,input().split()))\r\none=0\r\ntwo=0\r\nthree=0\r\nc=0\r\nfor i in s:\r\n if c==0:\r\n one+=i\r\n c=1\r\n elif c==1:\r\n two+=i\r\n c=2\r\n else:\r\n three+=i\r\n c=0\r\n\r\nif one >two and one >three:\r\n print(\"chest\")\r\nif two >one and two >three:\r\n print(\"biceps\")\r\nif three >one and two <three:\r\n print(\"back\")\r\n",
"n=int(input())\r\n\r\nL1= [int(x) for x in input().split(\" \")]\r\n\r\nchest=0\r\nbicep=0\r\nback=0\r\n\r\nctr=0\r\n\r\nfor i in range(0,n):\r\n ctr=ctr+1\r\n\r\n if ctr==1:\r\n chest=chest+L1[i]\r\n elif ctr==2:\r\n bicep=bicep+L1[i]\r\n\r\n else:\r\n back=back+L1[i]\r\n ctr=0\r\n\r\nif chest>bicep and chest>back:\r\n print(\"chest\")\r\nelif bicep>chest and bicep>back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\ne = list(map(int, input().split()))\r\n\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest = chest + e[i]\r\n elif i % 3 == 1:\r\n biceps = biceps + e[i]\r\n else:\r\n back = back + e[i]\r\nif chest == max(chest, biceps, back):\r\n print(\"chest\")\r\nelif biceps == max(chest, biceps, back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(n):\r\n if i%3 == 0:\r\n chest += arr[i]\r\n elif i%3 == 1:\r\n biceps += arr[i]\r\n elif i %3 == 2:\r\n back += arr[i]\r\ntemp = max(chest,biceps,back)\r\nif temp == chest:\r\n print(\"chest\")\r\nelif temp == biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"\r\n# ||||||||| /\\ | | | /\\ - \r\n#\t | / \\\t | | | / \\ - \r\n# | /----\\ | ||||||| /----\\ - \r\n# | / \\ | | | / \\ - \r\n# | / \\ |_______ | | / \\ -\r\n\t#------------------------------------------------------\r\nj = int(input())\r\narr = list(map(int,input().split()))\r\nch = sum(arr[::3])\r\nbicp = sum(arr[1::3])\r\nback = sum(arr[2::3])\r\nif max(ch,bicp,back) == ch:\r\n\tprint('chest')\r\nelif max(ch,bicp,back) == bicp:\r\n\tprint('biceps')\r\nelse:\r\n\tprint('back')",
"n=int(input())\r\nm=list(map(int,input().split()))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range (n):\r\n\tif i%3==0:\r\n\t\ta=a+m[i]\r\n\tif i%3==1:\r\n\t\tb=b+m[i]\r\n\tif i%3==2:\r\n\t\tc=c+m[i]\r\nif a>b and a>c:\r\n\tprint(\"chest\")\r\nif b>a and b>c:\r\n\tprint(\"biceps\")\r\nif c>b and c>a:\r\n\tprint(\"back\")",
"a=int(input())\r\nlis=list(map(int,input().split()))\r\nc=0\r\nb=0\r\nba=0\r\nfor i in range(a):\r\n if(i%3==0):\r\n c+=lis[i]\r\n elif(i%3==1):\r\n b+=lis[i]\r\n else:\r\n ba+=lis[i]\r\nans=max(c,b,ba)\r\nif(c==ans):\r\n print(\"chest\")\r\nelif(b==ans):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchest, biceps, back, max = 0, 0, 0, 0\r\nfor i in range(len(a)):\r\n if i%3 == 0:\r\n chest += a[i]\r\n if i%3 == 1:\r\n biceps += a[i]\r\n if i%3 == 2:\r\n back += a[i]\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps > chest and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nchest, biceps, back = 0, 0, 0\r\n\r\nfor i in range(0, n, 3):\r\n chest += arr[i]\r\n\r\nfor i in range(1, n, 3):\r\n biceps += arr[i]\r\n\r\nfor i in range(2, n, 3):\r\n back += arr[i]\r\n\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelif back > chest and back > biceps:\r\n print(\"back\")\r\n",
"class Solution:\r\n\tdef __init__(self):\r\n\t\tpass\r\n\r\n\tdef solve(self):\r\n\t\tt = int(input())\r\n\t\texercises = list(map(int, input().split()))\r\n\t\tchest, biceps, back = 0, 0, 0\r\n\r\n\t\tfor count, ex in enumerate(exercises):\r\n\t\t\tif count % 3 == 0:\r\n\t\t\t\tchest += ex\r\n\t\t\telif count % 3 == 1:\r\n\t\t\t\tbiceps += ex\r\n\t\t\telse:\r\n\t\t\t\tback += ex\r\n\r\n\t\tmax_val = max(chest, biceps, back)\r\n\r\n\t\tif max_val == chest:\r\n\t\t\tprint(\"chest\")\r\n\t\telif max_val == biceps:\r\n\t\t\tprint(\"biceps\")\r\n\t\telse:\r\n\t\t\tprint(\"back\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tsol = Solution()\r\n\tsol.solve()\r\n",
"n=input()\r\nl=list(map(int,input().split()))\r\nval=[0,0,0]\r\nj=0\r\nans=['chest','biceps','back']\r\nfor i in l:\r\n val[j%3]+=i\r\n j+=1\r\nprint(ans[val.index(max(val))])",
"n=int(input())\r\narr=[int(x) for x in input().split()]\r\nchest=0\r\nbiceps=0\r\nback=0\r\n\r\nfor i in range(0,n,3):\r\n chest+=arr[i]\r\nfor i in range(1,n,3):\r\n biceps+=arr[i]\r\nfor i in range(2,n,3):\r\n back+=arr[i]\r\nmaxx=[chest,biceps,back]\r\nmaxx.sort()\r\nif(maxx[2]==chest):\r\n print(\"chest\")\r\nelif(maxx[2]==biceps):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input().strip())\narr=list(map(int,input().strip().split(' ')))\nsum_chest,sum_bicep,sum_back=0,0,0\nfor i in range(n):\n if i%3==0:\n sum_chest+=arr[i]\n elif i%3==1:\n sum_bicep+=arr[i]\n elif i%3==2:\n sum_back+=arr[i]\nlist1=[sum_chest,sum_bicep,sum_back]\nif max(list1)==sum_chest:\n print(\"chest\")\nelif max(list1)==sum_bicep:\n print(\"biceps\")\nelse:\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split(\" \")))\r\n\r\nres=[0,0,0]\r\nfor i in range(n):\r\n\tres[i%3]+=l[i]\r\n\r\na,b,c=res[0],res[1],res[2]\r\nif a>b and a>c:print(\"chest\")\r\nelif b>a and b>c:print(\"biceps\")\r\nelse:print(\"back\")",
"from sys import stdin\r\ninput=lambda:stdin.readline().strip()\r\nn=int(input())\r\nlst=[int(i) for i in input().split()]\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(0,n):\r\n if i%3==0:\r\n a+=lst[i]\r\n elif i%3==1:\r\n b+=lst[i]\r\n elif i%3==2:\r\n c+=lst[i]\r\nif a>b and a>c:\r\n print(\"chest\")\r\nelif b>c:\r\n print('biceps')\r\nelse:\r\n print('back')",
"import sys, collections, math, itertools, random\r\nINF = sys.maxsize\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef input(): return sys.stdin.readline().strip()\r\nmod = 1000000007\r\n\r\nn = int(input())\r\narr = get_array()\r\nif n == 1:\r\n print('chest')\r\nelif n == 2:\r\n idx = arr.index(max(arr))\r\n if idx == 1:\r\n print('biceps')\r\n else:\r\n print('chest')\r\nelse:\r\n s = [0,0,0]\r\n for i in range(0, n, 3):\r\n s[0] += arr[i]\r\n for i in range(1,n,3):\r\n s[1] += arr[i]\r\n for i in range(2,n,3):\r\n s[2] += arr[i]\r\n idx = s.index(max(s))\r\n if idx == 1:\r\n print('biceps')\r\n elif idx == 2:\r\n print('back')\r\n else:\r\n print('chest')",
"n = int(input())\r\nl = list(map(int, input().split()))\r\n\r\nchest, biceps, back = 0, 0, 0\r\nfor i in range(0, len(l), 3):\r\n chest = chest + l[i]\r\n \r\nfor i in range(1, len(l), 3):\r\n biceps = biceps + l[i]\r\n\r\nfor i in range(2, len(l), 3):\r\n back = back + l[i]\r\n\r\nif (chest > biceps and chest > back):\r\n print(\"chest\")\r\n \r\nif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\n \r\nif back > biceps and back > chest:\r\n print(\"back\")\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nind,ch,bi,ba=0,0,0,0\r\nfor i in range(n):\r\n\tif l[i]==max(l):\r\n\t\tind=i\r\nif n==1:\r\n\tprint(\"chest\")\r\nelse:\r\n\tfor i in range(0,n,3):\r\n\t\tch+=l[i]\r\n\tfor i in range(1,n,3):\r\n\t\tbi+=l[i]\t\r\n\tfor i in range(2,n,3):\r\n\t\tba+=l[i]\t\r\n\tif ch>bi and ch>ba:\r\n\t\tprint(\"chest\")\r\n\telif bi>ba:\r\n\t\tprint(\"biceps\")\r\n\telse:\r\n\t\tprint(\"back\")",
"n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor i in range(0, n, 3):\r\n chest += a[i]\r\n\r\nfor i in range(1, n, 3):\r\n biceps += a[i]\r\n\r\nfor i in range(2, n, 3):\r\n back += a[i]\r\n\r\nmaxi = max(chest, biceps, back)\r\n\r\nif chest == maxi:\r\n print('chest')\r\nelif biceps == maxi:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(0,len(l),3):\r\n chest+=l[i]\r\nfor i in range(1,len(l),3):\r\n biceps+=l[i]\r\nfor i in range(2,len(l),3):\r\n back+=l[i]\r\nif(chest>biceps and chest>back):\r\n print(\"chest\")\r\nelif(biceps>chest and biceps>back):\r\n print(\"biceps\")\r\nelif(back>biceps and back>chest):\r\n print(\"back\")",
"chest,bi,back = 0,0,0\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nfor i in range(1, n + 1):\r\n if i%3 == 1:\r\n chest += l[i-1]\r\n elif i%3 == 2:\r\n bi += l[i-1]\r\n elif i%3 == 0:\r\n back += l[i-1]\r\n\r\nif chest > bi and chest > back:\r\n print(\"chest\")\r\nelif bi > chest and bi > back:\r\n print(\"biceps\")\r\nelse:\r\n print('back') \r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in l[::3]:\r\n chest+=i\r\nfor j in l[1::3]:\r\n biceps+=j\r\nfor z in l[2::3]:\r\n back+=z\r\nif chest > biceps and chest> back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nseq = list(map(int,input().split()))\r\n\r\nrs = [0,0,0]\r\nfor i in range(n):\r\n rs[i%3] += seq[i]\r\n\r\nindex = rs.index(max(rs))\r\n\r\nif index == 0:\r\n print(\"chest\")\r\nelif index == 1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = input().split(' ')\r\nch,bi,ba = 0,0,0\r\nfor i in range(n):\r\n a[i] = int(a[i])\r\nif n >= 3:\r\n for j in range(0,n,3):\r\n ch += a[j]\r\n for k in range(1,n,3):\r\n bi += a[k]\r\n for l in range(2,n,3):\r\n ba += a[l]\r\n x = max(ch,bi,ba)\r\n if ch == x:\r\n print('chest')\r\n elif bi == x:\r\n print('biceps')\r\n else:\r\n print('back')\r\nelif n == 2:\r\n if a[0] >= a[1]:\r\n print('chest')\r\n else:\r\n print('biceps')\r\nelse:\r\n print('chest')",
"from audioop import reverse \nimport math, os, sys, string \nif(os.path.exists('input.txt')):\n sys.stdin = open(\"input.txt\",\"r\")\n sys.stdout = open(\"output.txt\",\"w\")\n \nimport sys\ninput = sys.stdin.readline \n\n#Main code here:\nn = int(input())\narr = list(map(int, input().split()))\n\nres = [0,0,0]\n\ni,j = 0,0\nwhile(i < n):\n num = arr[i]\n res[j] += num\n \n j += 1\n if j == 3: \n j = 0\n i += 1\n\nmax_value = max(res)\nmax_ind = res.index(max_value)\n\nif max_ind == 0: print(\"chest\")\nelif max_ind == 1: print(\"biceps\")\nelse: print(\"back\")\n \nsys.stdout.close() \nsys.stdin.close() \n\t\t\t\t\t\t\t\t\t \t \t \t \t \t \t",
"n = int(input())\r\n*l, = map(int, input().split(' '))\r\nchest = 0;biceps = 0;back = 0\r\n\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest += l[i]\r\n elif i % 3 == 1:\r\n biceps += l[i]\r\n else:\r\n back += l[i]\r\n\r\nif max(chest, biceps, back) == chest:\r\n print('chest')\r\nelif max(chest, biceps, back) == biceps:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\n\r\na = [sum(l[i::3]) for i in [0,1,2]]\r\n\r\nprint([\"chest\", \"biceps\", \"back\"][a.index(max(a))])",
"n = int(input())\nchest,biceps,back = 0,0,0\nfreq = list(map(int,input().split()))\n\nfor i in range(n):\n if i%3 == 0:\n chest += freq[i]\n elif i%3 == 1:\n biceps += freq[i]\n else:\n back += freq[i]\n\n\nif chest > biceps and chest > back:\n print(\"chest\")\nelif biceps > chest and biceps > back: \n print(\"biceps\")\nelse:\n print(\"back\") \n \n",
"# https://codeforces.com/contest/255/problem/A\r\n\r\nN = int(input())\r\nl = [int(i) for i in input().split()]\r\n\r\nchest, biceps, back = 0, 0, 0\r\n\r\nindex = 1\r\nfor i in range(0, N):\r\n if index == 1:\r\n chest += l[i]\r\n elif index == 2:\r\n biceps += l[i]\r\n elif index == 3:\r\n back += l[i]\r\n index += 1\r\n if index == 4:\r\n index = 1\r\n\r\nh = [chest, biceps, back].index(max([chest, biceps, back]))\r\nprint([\"chest\", \"biceps\", \"back\"][h])",
"import sys\r\nfrom math import *\r\nfrom collections import Counter, defaultdict, deque\r\ninput = sys.stdin.readline\r\nmod = 10**9+7\r\nn = int(input())\r\narr = [int(i) for i in input().split()]\r\nfreq = [0]*3\r\n\r\nfor id, i in enumerate(arr):\r\n if (id % 3 == 0):\r\n freq[0] += i\r\n elif (id % 3 == 1):\r\n freq[1] += i\r\n else:\r\n freq[2] += i\r\n\r\nid_fin = 0\r\nin_val = freq[0]\r\nfor id, i in enumerate(freq):\r\n if (i > in_val):\r\n in_val = i\r\n id_fin = id\r\n\r\nif (id_fin == 0):\r\n print(\"chest\")\r\nif (id_fin == 1):\r\n print(\"biceps\")\r\nif (id_fin == 2):\r\n print(\"back\")\r\n\r\n# chest = 0\r\n# bicep = 0\r\n# back = 0\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nch = sum(a[0::3])\r\nbi = sum(a[1::3])\r\nba = sum(a[2::3])\r\n\r\nif max(ch,bi,ba) == ch:\r\n print('chest')\r\nelif max(ch,bi,ba) == bi:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\na = list(map(int,input().split()))\n\nchest,biceps,back = 0,0,0\n\nfor i in range(n):\n\tif(i%3==0):\n\t\tchest+=a[i]\n\telif(i%3==1):\n\t\tbiceps+=a[i]\n\telif(i%3==2):\n\t\tback+=a[i]\n\nif chest == max([chest,biceps,back]):\n\tprint(\"chest\")\nelif back == max([chest,biceps,back]):\n\tprint(\"back\")\nelif biceps == max([chest,biceps,back]):\n\tprint(\"biceps\")",
"import operator \r\nn=int(input())\r\na=list(map(int,input().split()))\r\nc=[]\r\nx=[\"chest\",\"biceps\",\"back\"]\r\nfor i in range(3):\r\n c.append(sum(a[i::3]))\r\nmapped=zip(x,c)\r\nprint(sorted(list((mapped)), key = operator.itemgetter(1))[-1][0])\r\n\r\n",
"n = int(input())\r\ns = list(map(int, input().split(\" \")))\r\n\r\nbi = 0\r\nch = 0\r\nba = 0\r\n\r\nac = 0\r\nfor i in range(n):\r\n if(ac == 0):\r\n ch += s[i]\r\n elif(ac == 1):\r\n bi += s[i]\r\n elif(ac == 2):\r\n ba += s[i]\r\n ac += 1\r\n if(ac == 3):\r\n ac = 0\r\n\r\nif(bi >= ch and bi >= ba):\r\n print(\"biceps\")\r\nelif(ba>=ch and ba>= bi):\r\n print(\"back\")\r\nelse:\r\n print(\"chest\")\r\n",
"n = int(input())\r\ninputlists = list(map(int, input().strip().split()))\r\nlists = [0, 0, 0]\r\nfor i in range(n):\r\n lists[i % 3] += inputlists[i]\r\nmax_ex = max(lists)\r\nif max_ex == lists[0]:\r\n print(\"chest\", end=\"\")\r\nelif max_ex == lists[1]:\r\n print(\"biceps\", end=\"\")\r\nelif max_ex == lists[2]:\r\n print(\"back\", end=\"\")\r\n",
"num=int(input())\r\na=list(map(int, input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range (num):\r\n if i%3==0:\r\n chest+=a[i]\r\n elif i%3==1:\r\n biceps+=a[i]\r\n else:\r\n back+=a[i]\r\nif chest>biceps and chest>back:\r\n print (\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print (\"biceps\")\r\nelse:\r\n print (\"back\")",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\n\r\nch, bi, ba = sum(lst[0::3]), sum(lst[1::3]), sum(lst[2::3])\r\nma = max([ch,bi,ba])\r\nif ma == ch: print(\"chest\")\r\nelif ma == bi: print(\"biceps\")\r\nelse: print(\"back\")",
"def solve(lst):\r\n chest = 0\r\n biceps = 0 \r\n back = 0 \r\n\r\n for i in range(1, len(lst)+1):\r\n if i == 1:\r\n chest += lst[i-1]\r\n elif i == 2:\r\n biceps += lst[i-1]\r\n elif i == 3:\r\n back += lst[i-1]\r\n elif i % 3 == 1:\r\n chest += lst[i-1] \r\n elif i % 3 == 2: \r\n biceps += lst[i-1]\r\n elif i % 3 == 0:\r\n back += lst[i-1]\r\n\r\n aug_lst = [chest, biceps, back]\r\n\r\n indx = aug_lst.index(max(aug_lst))\r\n\r\n if indx == 0: \r\n print(\"chest\")\r\n elif indx == 1: \r\n print(\"biceps\")\r\n else: \r\n print(\"back\")\r\n\r\nnum = int(input())\r\nlst = list(map(int, input().split()))\r\nsolve(lst)",
"x = int(input())\r\ndictt = {'chest': 0 ,'biceps':0,'back': 0}\r\nday1 , day2, day3 , =\"chest\" ,'biceps','back' \r\nfor value in (list(map(int,input().split()))) : \r\n dictt[day1]+=value \r\n day1 , day2 , day3 = day2 , day3 ,day1\r\nfor k , v in dictt.items(): \r\n if v == max(dictt.values()) :\r\n print(k)\r\n break ",
"n = int(input())\nlst = list(map(int, input().split()))\ncount = [0,0,0]\na = [\"chest\", \"biceps\", \"back\"]\nfor i in range(n):\n count[i%3] += lst[i]\nprint(a[count.index(max(count))])\n\t\t \t \t \t \t \t \t\t\t\t\t \t\t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nexc = [0,0,0]\r\n\r\nfor i in range(0,n,3):\r\n exc[0] += a[i]\r\nfor i in range(1,n,3):\r\n exc[1] += a[i]\r\nfor i in range(2,n,3):\r\n exc[2] += a[i]\r\n \r\nind = exc.index(max(exc))\r\nif ind == 0:\r\n print('chest')\r\nelif ind == 1:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n\r\n",
"T = int (input()) \r\narr = list (map(int, input().split(' '))) \r\ncnt = [0,0,0] \r\nfor i in range (T):\r\n cnt[i%3]+= arr[i]\r\nmx = max (cnt) \r\nif cnt[0] == mx:\r\n print (\"chest\")\r\nif cnt[1] == mx : \r\n print(\"biceps\")\r\nif cnt[2] == mx : \r\n print (\"back\")",
"n = int(input())\r\nc, bi, b = 0, 0, 0 \r\nli = list(map(int,input().split()))\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n c += li[i]\r\n elif i % 3 == 1:\r\n bi += li[i]\r\n else:\r\n b += li[i]\r\n \r\nif c > b and c > bi:\r\n print(\"chest\")\r\nelif bi > c and bi > b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\na = list(map(int, input().split()))\ns1 = s2 = s3 = 0\nfor i in range(0, len(a), 3):\n s1 = s1 + a[i]\nfor j in range(1, len(a), 3):\n s2 = s2 + a[j]\nfor k in range(2, len(a), 3):\n s3 = s3 + a[k]\nif max(s1, s2, s3) == s1:\n print(\"chest\")\nelif max(s1, s2, s3) == s2:\n print(\"biceps\")\nelse:\n print(\"back\")\n",
"x = int(input())\r\nz = []\r\nz[0:] = map(int,input().split())\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nadd = 0\r\nfor i in range(x):\r\n if i == 0 + add:\r\n chest += z[i]\r\n elif i == 1 + add:\r\n biceps += z[i]\r\n elif i == 2 + add:\r\n back += z[i]\r\n add += 3\r\nw = {chest : \"chest\", biceps: \"biceps\",back: \"back\"}\r\nprint(w[max(w)])\r\n\r\n\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nx,y,z=0,0,0\r\nfor i in range(n):\r\n f=i%3\r\n if(f==0):\r\n x=x+l[i]\r\n elif(f==1):\r\n y=y+l[i]\r\n else:\r\n z=z+l[i]\r\nm=max(x,y,z)\r\nif(m==x):\r\n print('chest')\r\nelif(m==y):\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\na = input().split()\r\na = [int(i) for i in a]\r\nch = sum(a[0::3])\r\nbi = sum(a[1::3])\r\nba = sum(a[2::3])\r\nif max(ch,bi,ba) == ch:\r\n print(\"chest\")\r\nelif max(ch,bi,ba) == bi:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc=0\r\nbi=0\r\nb=0\r\nfor i in range(n):\r\n if i%3==0:\r\n c+=a[i]\r\n elif i%3==1:\r\n bi+=a[i]\r\n else:\r\n b+=a[i]\r\n\r\nif c>bi and c>b:\r\n print('chest')\r\nelif bi>c and bi>b:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nc=[0,3,6,9,12,15,18]\r\nb=[1,4,7,10,13,16,19]\r\nba=[2,5,8,11,14,17,20]\r\nfor i in range(n):\r\n if i in c:\r\n chest+=l[i]\r\n elif i in b:\r\n biceps+=l[i]\r\n else:\r\n back+=l[i]\r\ns=max(chest,biceps,back)\r\nif s==chest:\r\n print(\"chest\")\r\nelif s==biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchest = 0\r\nback = 0\r\nbiceps = 0\r\nlchest = a[::3]\r\nchest = sum(lchest)\r\nif n > 1:\r\n lbiceps = a[1::3]\r\n biceps = sum(lbiceps)\r\nif n > 2:\r\n lback = a[2::3]\r\n back = sum(lback)\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nexcercises = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor x in range(0, n, 3):\r\n chest += excercises[x]\r\n\r\nfor y in range(1, n, 3):\r\n biceps += excercises[y]\r\n\r\nfor z in range(2, n, 3):\r\n back += excercises[z]\r\n\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > back and biceps > chest:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = map(int, input().split())\r\nx = list(a)\r\nb = 0\r\nchest = x[::3]\r\nbiceps = x[1::3]\r\nback = x[2::3]\r\nch = sum(chest)\r\nbi = sum(biceps)\r\nba = sum(back)\r\nif ch >= bi:\r\n if ch >= ba:\r\n print('chest')\r\n else:\r\n print('back')\r\nelif bi >= ch:\r\n if bi >= ba:\r\n print('biceps')\r\n else:\r\n print('back')\r\n",
"n = int(input())\ntraining = [int(i) for i in input().split(' ')]\nchest = sum(training[::3])\nbiceps = sum(training[1::3])\nback = sum(training[2::3])\n\ntrain = {\"biceps\":biceps, \"chest\":chest, \"back\":back}\nmax_v = 0\nmax_k = 0\nfor k, v in train.items():\n if(v > max_v):\n max_k = k\n max_v = v\nprint(max_k)\n \t\t\t \t \t \t\t\t\t\t\t\t \t\t\t",
"n = int(input())\r\narr = [int(i) for i in input().split()]\r\nchest, biceps, back = 0, 0, 0\r\nfor i in range(n):\r\n if i%3 == 0:\r\n chest += arr[i]\r\n elif i%3 == 1:\r\n biceps += arr[i]\r\n else:\r\n back += arr[i]\r\nmaxi = max(chest, biceps, back)\r\nif maxi == chest:\r\n print(\"chest\")\r\nelif maxi == biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nA = list(map(int, input().split(\" \")))\r\ncount = [0,0,0]\r\nfor index, i in enumerate(A):\r\n count[index%3] += i \r\nres = count.index(max(count))\r\nif res == 0:\r\n print(\"chest\")\r\nelif res == 2:\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nif n<3:\r\n b=max(a)\r\n if a.index(b)==0:\r\n print(\"chest\")\r\n elif a.index(b)==1:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\nelse:\r\n p=a[0::3]\r\n q=a[1::3]\r\n r=a[2::3]\r\n l=[sum(p),sum(q),sum(r)]\r\n if sum(p)==max(l):\r\n print(\"chest\")\r\n if sum(q)==max(l):\r\n print(\"biceps\")\r\n if sum(r)==max(l):\r\n print(\"back\")",
"n = int(input())\nchest = 0\nbiceps = 0\nback = 0\n\nlst = input().split()\nfor i in range(n):\n lst[i] = int(lst[i])\n\nfor i in range(n):\n if i % 3 == 0:\n chest += lst[i]\n elif i % 3 == 1:\n biceps += lst[i]\n else:\n back += lst[i]\n\nif chest >= back and chest >= biceps:\n print(\"chest\")\n\nelif biceps >= back and biceps >= chest:\n print(\"biceps\")\n\nelse:\n print(\"back\")\n\n \t \t \t \t\t \t \t \t \t\t",
"# Greg's Workout\nn = int(input())\na = list(map(int,input().split()))\nchest = 0\nbiceps = 0\nback = 0\nfor i in range(n):\n if i%3 == 0:\n chest += a[i]\n elif i%3 == 1:\n biceps += a[i]\n else:\n back += a[i]\nif max(chest,biceps,back) == chest:\n print(\"chest\")\nelif max(chest,biceps,back) == biceps:\n print(\"biceps\")\nelse:\n print(\"back\")\n",
"trains=int(input())\r\ntimes=[int(t) for t in input().split()]\r\nc,b,bc,timer=0,0,0,0\r\nfor i in times:\r\n timer+=1\r\n if timer%3==1:c+=i\r\n elif timer%3==2:b+=i\r\n else: timer,bc=0,bc+i\r\nif c>b and c>bc: print('chest')\r\nelse: print('biceps' if b>bc else 'back')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nb=0\r\nbi=0\r\nwhile len(l)>0:\r\n if len(l)>=3:\r\n c+=l[0]\r\n bi+=l[1]\r\n b+=l[2]\r\n l.pop(2)\r\n l.pop(1)\r\n l.pop(0)\r\n elif len(l)==1:\r\n c+=l[0]\r\n l.pop()\r\n elif len(l)==2:\r\n c+=l[0]\r\n bi+=l[1]\r\n l.pop(1)\r\n l.pop(0)\r\n \r\nif max(c,b,bi)==bi:\r\n print(\"biceps\")\r\nelif max(c,b,bi)==c:\r\n print(\"chest\")\r\nelse:\r\n print(\"back\")",
"N=int(input())\r\nexercise=list(map(int,input().split()))\r\ntimes=[0]*3\r\nfor ind in range(N):\r\n\ttimes[ind%3]+=exercise[ind]\r\nmaxExercise=times.index(max(times))\r\ntypes=['chest','biceps','back']\r\nprint(types[maxExercise])\r\n",
"n=int(input())\r\nlis=list(map(int,input().split()))\r\nl1=[0]\r\nl2=[0]\r\nl3=[0]\r\nfor i in range(0,n,3):\r\n l1.append(lis[i])\r\nfor i in range(1,n,3):\r\n l2.append(lis[i])\r\nfor i in range(2,n,3):\r\n l3.append(lis[i])\r\ns1=sum(l1)\r\ns2=sum(l2)\r\ns3=sum(l3)\r\nif s1>s2 and s1>s3:\r\n print(\"chest\")\r\nelif s2>s1 and s2>s3:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"a=int(input())\r\nl=list(map(int,input().split()))\r\nx=0\r\ny=0\r\nz=0\r\nfor i in range(a):\r\n d=i%3\r\n if(d==0):\r\n x=x+l[i]\r\n elif(d==1):\r\n y=y+l[i]\r\n else:\r\n z=z+l[i]\r\nif(x>y and x>z):\r\n print(\"chest\")\r\nelif(y>x and y>z):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"t=int(input())\r\nl=[int(x) for x in input().split()]\r\ncount=0\r\nch=0\r\nbc=0\r\nb=0\r\nfor i in l:\r\n if count==0:\r\n ch+=i\r\n count+=1\r\n elif count==1:\r\n bc+=i\r\n count+=1\r\n\r\n elif count==2:\r\n b+=i\r\n count=0\r\nif ch>bc and ch>b:\r\n print(\"chest\")\r\nelif bc>ch and bc>b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split(\" \")))\r\nc=0\r\nb=0\r\nk=0\r\nfor i in range(1,n+1):\r\n if i%3==0:\r\n k+=a[i-1]\r\n elif i%3==1:\r\n c+=a[i-1]\r\n else:\r\n b+=a[i-1]\r\nd=max(b,c,k)\r\nif d==b:\r\n print(\"biceps\")\r\nelif d==c:\r\n print(\"chest\")\r\nelse:\r\n print(\"back\")\r\n",
"def greg_workout(a):\r\n sum_1=0\r\n sum_2=0\r\n sum_3=0\r\n for i in range(0,len(a),3):\r\n sum_1=sum_1+a[i]\r\n \r\n for i in range(1,len(a),3):\r\n sum_2=sum_2+a[i]\r\n\r\n for i in range(2,len(a),3):\r\n sum_3=sum_3+a[i]\r\n\r\n maxi=max(sum_1,sum_2,sum_3)\r\n if maxi==sum_1:\r\n print('chest')\r\n elif maxi==sum_2:\r\n print('biceps')\r\n else:\r\n print('back')\r\n \r\n \r\n\r\n\r\n\r\n\r\nn=int(input(''))\r\na=list(map(int,input('').split()))\r\ngreg_workout(a)\r\n# for i in range(0,10,3):\r\n# print(i)",
"muscles = [0]*3\r\nchest, biceps, back = 0, 0, 0\r\nnum = int(input())\r\ntraining = list(map(int, input() .split()))\r\nfor i in range(num):\r\n if i % 3 == 0:\r\n chest += training[i]\r\n elif i % 3 == 1:\r\n biceps += training[i]\r\n elif i % 3 == 2:\r\n back += training[i]\r\nif biceps > back and biceps > chest:\r\n print(\"biceps\")\r\nelif chest > back and chest > biceps:\r\n print(\"chest\")\r\nelif back > chest and back > biceps:\r\n print(\"back\")",
"given = [\"chest\", \"biceps\", \"back\"]\r\nn = int(input())\r\ntake = list(map(int, input().split()))\r\nif n <= 3:\r\n j = take.index(max(take))\r\n print(given[j])\r\nelse:\r\n new = [0]*3\r\n for j in range(n):\r\n new[j % 3] += take[j]\r\n j = new.index(max(new))\r\n print(given[j])\r\n",
"a=int(input())\r\nl=list(map(int, input().split()))\r\nx=0\r\ny=0\r\nz=0\r\nfor i in range(a):\r\n d=i%3\r\n if (d==0):\r\n x+=l[i]\r\n elif (d==1):\r\n y+=l[i]\r\n else:\r\n z+=l[i]\r\n\r\nif max(x,y,z)==x:\r\n print('chest')\r\nelif max(x,y,z)==y:\r\n print('biceps')\r\nelse:\r\n print('back')",
"a = int(input())\r\nb = list(map(int, input().split()))\r\n\r\nchest_1 = sum(b[0::3])\r\nbiceps_1 = sum(b[1::3])\r\nback_1 = sum(b[2::3])\r\n\r\n\r\nmax_ = max(chest_1, biceps_1, back_1)\r\n\r\nif max_ == chest_1:\r\n print(\"chest\")\r\nelif max_ == biceps_1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nworkout_plan = list(map(int, input().split()))\r\nrepeat_chest, repeat_biceps, repeat_back = 0, 0, 0\r\n\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n repeat_chest += workout_plan[i]\r\n elif i % 3 == 1:\r\n repeat_biceps += workout_plan[i]\r\n else:\r\n repeat_back += workout_plan[i]\r\n\r\nif repeat_chest > repeat_biceps and repeat_chest > repeat_back:\r\n print('chest')\r\nelif repeat_biceps > repeat_chest and repeat_biceps > repeat_back:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\na = [int(i)for i in input().split()]\r\nC = 0\r\nBI = 0\r\nB = 0\r\nfor l in range(len(a)):\r\n if l % 3 == 0:\r\n C += a[l]\r\n elif l % 3 == 1:\r\n BI += a[l]\r\n else:\r\n B += a[l]\r\nans = max(B, C, BI)\r\nif ans == B:\r\n print(\"back\")\r\nelif ans == BI:\r\n print(\"biceps\")\r\nelse:\r\n print(\"chest\")",
"a= int(input())\r\nb = list(map(int,input().split()))\r\nc= [0,0,0]\r\nfor i in range(len(b)):\r\n c[i%3]+= b[i]\r\nd = c.index(max(c))\r\nif d == 0:\r\n print('chest')\r\nelif d== 1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na=[]\r\nfor i in range(0,len(l),3):\r\n a.append(l[i:i+3])\r\n#print(a)\r\nc=0\r\nbi=0\r\nba=0\r\nfor x in range(len(a)):\r\n for y in range(len(a[x])):\r\n if y==0:\r\n c=c+a[x][y]\r\n elif y==1:\r\n bi=bi+a[x][y]\r\n elif y==2:\r\n ba=ba+a[x][y]\r\nif c>bi and c>ba:\r\n print(\"chest\")\r\nelif bi>c and bi>ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\ny1,y2,y3=0,0,0\r\nfor i in range(len(a)):\r\n if i%3==0:\r\n y1+=a[i]\r\n elif i%3==1:\r\n y2+=a[i]\r\n else:\r\n y3+=a[i]\r\nif y1>y2 and y1>y3:\r\n print('chest')\r\nelif y2>y1 and y2>y3:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\nnl = [int(i) for i in input().split()]\r\nif(n == 2):\r\n if(nl[0] > nl[1]):\r\n print(\"chest\")\r\n else:\r\n print(\"biceps\")\r\nelse:\r\n c, b, ba = 0, 0, 0\r\n for i in range(0, len(nl), 3):\r\n c += nl[i]\r\n for j in range(1, len(nl), 3):\r\n b += nl[j]\r\n for k in range(2, len(nl), 3):\r\n ba += nl[k]\r\n if(max(c, b, ba) == c):\r\n print(\"chest\")\r\n elif(max(c, b, ba) == b):\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")",
"n = int(input())\r\ngr = 0\r\nbtc = 0\r\nspn = 0\r\nb = 0\r\nm = list(map(int, input().split()))\r\nfor i in range(len(m)):\r\n b += 1\r\n if b == 1:\r\n gr += m[i]\r\n elif b == 2:\r\n btc += m[i]\r\n elif b == 3:\r\n spn += m[i]\r\n b = 0\r\nl = [gr, btc, spn]\r\nif max(l) == gr:\r\n print('chest')\r\nelif max(l) == spn:\r\n print('back')\r\nelse:\r\n print('biceps') \r\n",
"import sys\r\n\r\nn = int(sys.stdin.readline())\r\n\r\ne = list(map(int,sys.stdin.readline().strip().split()))\r\n\r\nc = 0 \r\na = 0 \r\nb = 0\r\n\r\nfor i in range(len(e)):\r\n if i%3 == 0 :\r\n c = c + e[i]\r\n elif i%3 == 1 :\r\n a = a + e[i]\r\n else:\r\n b = b + e[i]\r\n\r\nif c > a:\r\n if c > b :\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\nelse:\r\n if a > b:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")",
"n = int(input())\r\n\r\nexercises = list(map(int, input().split()))\r\n\r\ni = 0\r\nturn = 0\r\n\r\nbi = 0\r\nch = 0\r\nba = 0\r\nwhile i < n:\r\n if (turn > 2):\r\n turn = 0\r\n\r\n if (turn == 0):\r\n ch += exercises[i]\r\n\r\n elif (turn == 1):\r\n bi += exercises[i]\r\n\r\n else:\r\n ba += exercises[i]\r\n \r\n turn += 1\r\n i += 1\r\n\r\nif (max(bi, ch, ba) == ch):\r\n print(\"chest\")\r\n\r\nelif (max(bi, ch, ba) == ba):\r\n print(\"back\")\r\n\r\nelse:\r\n print(\"biceps\")",
"if __name__ == '__main__':\n n = int(input())\n arr = list(map(int, input().split()))\n biceps = 0\n chest = 0\n back = 0\n k = 0\n for i in range(len(arr)):\n if k == 0:\n chest += arr[i]\n k += 1\n elif k == 1:\n biceps += arr[i]\n k += 1\n elif k == 2:\n back += arr[i]\n k = 0\n\n val = max(biceps, chest, back)\n if val == biceps:\n print('biceps')\n elif val == chest:\n print('chest')\n else:\n print('back')",
"import sys\r\nfrom math import sqrt, floor, factorial\r\nfrom collections import deque\r\ninp = sys.stdin.readline\r\nread = lambda: list(map(int, inp().strip().split()))\r\n\r\ndef solve():\r\n\tn = int(inp()); arr = [0,0,0]; arr1 = read(); arr2 = [\"chest\", \"biceps\", \"back\"]\r\n\tfor i, elem in enumerate(arr1):arr[i%3] += elem\r\n\tprint(arr2[arr.index(max(arr))])\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tsolve()",
"n = int(input())\na = list(map(int, input().split()))\nprint([\"chest\", \"biceps\", \"back\"][max(range(3), key=lambda i: sum(a[i::3]))])\n",
"l=int(input())\r\na = list(map(int,input().split()))\r\nchest=sum(a[0:l:3])\r\nbiceps=sum(a[1:l:3])\r\nback=sum(a[2:l:3])\r\nif chest>biceps and chest>back:\r\n print ('chest')\r\nelif biceps>chest and biceps>back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nl=list(map(int,input().strip().split()))\r\nce=0\r\nbe=0\r\nbae=0\r\nfor i in range(0,len(l)):\r\n if i%3==0:\r\n ce=ce+l[i]\r\n elif i%3==1:\r\n be=be+l[i]\r\n else:\r\n bae=bae+l[i]\r\nif bae>be and bae>ce:\r\n print('back')\r\nelif ce>be and ce>bae:\r\n print('chest')\r\nelse:\r\n print('biceps')\r\n",
"input()\r\nk=list(map(int,input().split()))\r\nc={sum(k[::3]):\"chest\",sum(k[1::3]):\"biceps\",sum(k[2::3]):\"back\" }\r\nprint(c.get(max(c)))",
"n = int(input())\r\nk = list(map(int, input().split()))\r\ntask = 1\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in k:\r\n if task%3 == 1:\r\n chest += i\r\n elif task%3 == 2:\r\n biceps += i\r\n else:\r\n back += i\r\n task += 1\r\nif back< chest > biceps:\r\n print('chest')\r\nelif back<biceps>chest:\r\n print('biceps')\r\nelse:\r\n print('back')",
"x = int(input())\r\ny = list(map(int, input().split(' ')))\r\nc = 0\r\nbi = 0\r\nbk = 0\r\nfor z in y:\r\n c = y[0::3]\r\n bi = y[1::3]\r\n bk = y[2::3]\r\nc = sum(c)\r\nbi = sum(bi)\r\nbk = sum(bk)\r\nif max(c, bi, bk) == c:\r\n print(\"chest\")\r\nelif max(c, bi, bk) == bi:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\nresult = [0,0,0]\r\n\r\nnames = [\"chest\", \"biceps\" , \"back\"]\r\nindex = 0 \r\nfor l in a:\r\n \r\n result[index] += l\r\n \r\n index += 1\r\n index %= 3\r\n \r\n \r\nmaxIndex = 0\r\nfor i, r in enumerate(result):\r\n if max(result) == r:\r\n maxIndex = i\r\n\r\nprint(names[maxIndex])",
"x = int(input())\r\nl = list(map(int , input().split()))\r\n\r\nc = 0\r\nbi = 0\r\nba = 0\r\n\r\ni =0 \r\nwhile i < x:\r\n c+=l[i]\r\n if i ==x-1:\r\n break\r\n i+=1\r\n bi +=l[i]\r\n if i ==x-1:\r\n break\r\n i+=1\r\n ba +=l[i]\r\n i+=1\r\n\r\n\r\nif c > bi and c > ba:\r\n print('chest')\r\nelif bi > c and bi > ba:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nlistt=[]\r\na=list(map(int,input().split()))\r\nchest=sum(a[0::3])\r\nbiceps=sum(a[1::3])\r\nback=sum(a[2::3])\r\nmaxx=\"chest\"\r\nif biceps>chest and biceps>back:\r\n\tmaxx=\"biceps\"\r\nelif back>biceps and back>chest:\r\n\tmaxx=\"back\"\r\nprint(maxx)\r\n",
"n = int(input())\r\n\r\nl = [int(x) for x in input().split(\" \")]\r\n\r\nchest = 0 \r\nbiceps = 0\r\nback = 0\r\n\r\nfor i in range(0,n,3):\r\n try:\r\n chest += l[i]\r\n biceps += l[i+1]\r\n back += l[i+2]\r\n except IndexError:\r\n if n==2:\r\n chest += l[i]\r\n biceps += l[i+1]\r\n elif n==1:\r\n chest += l[i]\r\n \r\nmaxexe = max(chest,biceps,back)\r\n\r\nif maxexe == chest:\r\n print(\"chest\")\r\n \r\nelif maxexe == biceps:\r\n print(\"biceps\")\r\n \r\nelse:\r\n print(\"back\")\r\n \r\n",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nchest=0\r\nbicep=0\r\nback=0\r\nj=0\r\nfor i in range(len(b)):\r\n\tif j==0:\r\n\t\tchest+=b[i]\r\n\t\tj=1\r\n\telif j==1:\r\n\t\tbicep+=b[i]\r\n\t\tj=2\r\n\telif j==2:\r\n\t\tback+=b[i]\r\n\t\tj=0\r\nif bicep>chest and bicep>back:\r\n\tprint(\"biceps\")\r\nelif bicep<chest and chest>back:\r\n\tprint(\"chest\")\r\nelse :\r\n\tprint(\"back\")\r\n\t\t\r\n\t\t",
"a = int(input())\nchest =0\nbiceps = 0\nback = 0\nb = input().split()\nfor i in range(len(b)):\n if(i%3==0):\n chest +=int(b[i])\n if(i%3==1):\n biceps += int(b[i])\n if(i%3==2):\n back += int(b[i])\nl2 = [chest,biceps,back]\nl3 = ['chest','biceps','back']\nmax_value = max(l2) \nmax_index = l2. index(max_value) \nprint(l3[max_index])\n \t \t\t\t \t\t \t\t\t \t\t \t\t \t\t\t",
"input()\r\nnums=list(map(int,input().split()))\r\nc=1\r\nchest=0\r\nbisecps=0\r\nback=0\r\nfor i in range(len(nums)):\r\n if c==1:\r\n chest+=nums[i]\r\n c=2\r\n elif c==2:\r\n bisecps+=nums[i]\r\n c=3\r\n else:\r\n back+=nums[i]\r\n c=1\r\nif chest>bisecps and chest >back:\r\n print(\"chest\")\r\nelif bisecps>chest and bisecps>back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n ",
"n=int(input())\r\nx=list(map(int,input().split()))\r\na,b,c=0,0,0\r\nfor i in range(0,n,3):\r\n z=x[i:i+3]\r\n if len(z)<3:\r\n z+=[0 for i in range(abs(3-len(z)))]\r\n a+=z[0];b+=z[1];c+=z[2]\r\nif max(a,b,c)==a:\r\n print(\"chest\")\r\nelif max(a,b,c)==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\ng=0\r\nb=0\r\ns=0\r\ncount=0\r\nfor i in a:\r\n count+=1\r\n if count>3:\r\n count=1\r\n if count==1:\r\n g=g+i\r\n if count==2:\r\n b=b+i\r\n if count==3:\r\n s=s+i\r\nif g>b and g>s:\r\n print('chest')\r\nelse:\r\n if b>s:\r\n print('biceps')\r\n else:\r\n print('back')\r\n \r\n \r\n \r\n\r\n \r\n",
"n=int(input())\r\na=map(int, input().split())\r\na=list(a)\r\nc=[] # chest\r\nb=[] #biceps\r\nz=[] #back\r\nfor i in range(n):\r\n if i%3==0:\r\n c.append(a[i])\r\n elif i%3==2:\r\n z.append(a[i])\r\n else:\r\n b.append(a[i])\r\nif (sum(c))>(sum(b)) and (sum(c))>(sum(z)):\r\n print('chest')\r\nelif (sum(b))>(sum(c)) and (sum(b))>(sum(z)):\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"chest, biceps, back = 0, 0, 0\r\nn = int(input())\r\nlst = [int(i) for i in input().split()]\r\nfor i in range(0, n, 3):\r\n chest += lst[i]\r\nfor i in range(1, n, 3):\r\n biceps += lst[i]\r\nfor i in range(2, n, 3):\r\n back += lst[i]\r\nif chest > back and chest > biceps:\r\n print('chest')\r\nelif back > chest and back > biceps:\r\n print('back')\r\nelse:\r\n print('biceps')\r\n",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nback=sum(b[2::3])\r\nchest=sum(b[::3])\r\nbic=sum(b[1::3])\r\nc=max(back,chest,bic)\r\nif back==c:print('back')\r\nelif chest==c:print('chest')\r\nelse:print('biceps')\r\n",
"import sys,math\n#sys.setrecursionlimit(100000000)\ninput = sys.stdin.readline\n \n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inara():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\ndef invr():\n return(map(int,input().split()))\n################################################################\n############ ---- THE ACTUAL CODE STARTS BELOW ---- ############\n\nn=inp()\n\nara=inara()\n\none=0\ntwo=0\nthree=0\n\nfor i in range(0,n,3):\n\tone+=ara[i]\n\nfor i in range(1,n,3):\n\ttwo+=ara[i]\n\nfor i in range(2,n,3):\n\tthree+=ara[i]\n\t\n\nans=max(one,two,three)\n\nif ans==one:\n\tprint(\"chest\")\nelif ans==two:\n\tprint(\"biceps\")\nelse:\n\tprint(\"back\")\n\n \t\t\t\t\t\t \t\t \t\t\t \t\t\t \t\t\t \t\t\t\t\t",
"a = int(input())\r\nl = list(map(int, input().split()))\r\nx, y, z = 0, 0, 0\r\n\r\nfor i in range(1,a+1):\r\n if i % 3 == 1:\r\n x += l[i-1]\r\n elif i % 3 == 2:\r\n y += l[i-1]\r\n else:\r\n z += l[i-1]\r\n\r\np = max(x, y, z)\r\n\r\nif p == x:\r\n print(\"chest\")\r\nelif p == y:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\") ",
"input()\r\nch,bi,bck,count=0,0,0,1\r\nfor i in map(int,(input().split())):\r\n if count%3==0:\r\n bck=bck+i\r\n count=1\r\n elif count%2==0:\r\n count=count+1\r\n bi=bi+i\r\n else:\r\n ch=ch+i\r\n count=count+1\r\nif ch>bi and ch>bck:\r\n print('chest')\r\nelif bi>ch and bi>bck:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\n\r\nif n == 1:\r\n ch = l[0]\r\n print(\"chest\")\r\nelif n == 2:\r\n ch = l[0]\r\n bi = l[1]\r\n if ch > bi:\r\n print(\"chest\")\r\n else:\r\n print(\"biceps\")\r\nelse:\r\n ch = 0\r\n bi = 0\r\n ba = 0\r\n count = 0\r\n for i in l:\r\n count += 1\r\n if count == 1:\r\n ch += i\r\n if count == 2:\r\n bi += i\r\n if count == 3:\r\n ba += i\r\n count = 0\r\n\r\n if ch>bi and ch > ba:\r\n print(\"chest\")\r\n elif bi>ch and bi>ba:\r\n print(\"biceps\")\r\n elif ba>ch and ba>bi:\r\n print(\"back\")",
"def get_list_count_complete_training(arr: list):\r\n list_count_complete_training = list()\r\n list_count_complete_training.append(sum(arr[0::3]))\r\n list_count_complete_training.append(sum(arr[1::3]))\r\n list_count_complete_training.append(sum(arr[2::3]))\r\n\r\n return list_count_complete_training\r\n\r\ndef get_result(index):\r\n if index == 0:\r\n return \"chest\"\r\n elif index == 1:\r\n return \"biceps\"\r\n else:\r\n return \"back\"\r\n\r\ndef test():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n list_count_complete_training = get_list_count_complete_training(arr)\r\n max_element = max(list_count_complete_training)\r\n index_max_element = list_count_complete_training.index(max_element)\r\n \r\n result = get_result(index_max_element)\r\n print(result)\r\n \r\n\r\nif __name__ == \"__main__\":\r\n # count_tests = int(input())\r\n count_tests = 1\r\n for number_test in range(count_tests):\r\n test()",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nchest_cnt = 0\r\nbicep_cnt = 0\r\nback_cnt = 0\r\n\r\nflag = 1\r\nfor i in range(len(a)):\r\n if flag == 1:\r\n chest_cnt += a[i]\r\n elif flag == 2:\r\n bicep_cnt += a[i]\r\n else:\r\n back_cnt += a[i]\r\n\r\n flag += 1\r\n if flag == 4:\r\n flag = 1\r\n\r\nif chest_cnt > bicep_cnt and chest_cnt > back_cnt:\r\n print(\"chest\")\r\nelif bicep_cnt > chest_cnt and bicep_cnt > back_cnt:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nflag=0\r\nfor i in range(n):\r\n if flag==0:\r\n chest+=arr[i]\r\n flag=1\r\n continue\r\n elif flag==1:\r\n biceps+=arr[i]\r\n flag=2\r\n continue\r\n elif flag==2:\r\n back+=arr[i]\r\n flag=0\r\n continue\r\nif chest == max(chest,biceps,back):\r\n print('chest')\r\nelif biceps== max(chest,biceps,back):\r\n print('biceps')\r\nelse:\r\n print('back')",
"def most_exercised_muscle(n, repetitions):\r\n chest_count = 0\r\n biceps_count = 0\r\n back_count = 0\r\n for i in range(n):\r\n if i % 3 == 0:\r\n chest_count += repetitions[i]\r\n elif i % 3 == 1:\r\n biceps_count += repetitions[i]\r\n else:\r\n back_count += repetitions[i]\r\n if chest_count >= biceps_count and chest_count >= back_count:\r\n return \"chest\"\r\n elif biceps_count >= chest_count and biceps_count >= back_count:\r\n return \"biceps\"\r\n else:\r\n return \"back\"\r\n\r\nn = int(input())\r\nrepetitions = list(map(int, input().split()))\r\nresult = most_exercised_muscle(n, repetitions)\r\nprint(result)\r\n",
"n=int(input())\nlist1=input().split(' ')\nfor i in range(len(list1)):\n list1[i]=int(list1[i])\nchest=0\nbiceps=0\nback=0\nfor i in range(0,len(list1),3):\n chest+=list1[i]\nfor i in range(1,len(list1),3):\n biceps+=list1[i]\nfor i in range(2,len(list1),3):\n back+=list1[i]\nif chest>=biceps and chest >= back:\n max='chest'\nelif biceps >= chest and biceps >= back:\n max='biceps'\nelse:\n max='back'\nprint(max)\n\t\t\t\t\t \t\t \t \t \t\t\t \t \t\t \t \t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(len(l)):\r\n if i>2:\r\n l[i%3]=l[i%3]+l[i]\r\nc=l.index(max(l))\r\nif c==0:\r\n print(\"chest\")\r\nelif c==1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=[0,0,0]\r\nfor i in range(0,len(l)):\r\n if i%3==0:\r\n m[0]=m[0]+l[i]\r\n elif i%3==1:\r\n m[1]=m[1]+l[i]\r\n else:\r\n m[2]=m[2]+l[i]\r\nmaxi=m.index(max(m))\r\nif maxi==0:\r\n print('chest')\r\nelif maxi==1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\n##v=0\r\n##chest=0 #Грудь\r\n##biceps=0 #Бицепс\r\n##back=0 #Спина\r\n##\r\n##for i in range(n):\r\n## if a[i] in a[::3]:\r\n## chest+=a[i]\r\n## elif a[i] in a[1::3]:\r\n## biceps+=a[i]\r\n## elif a[i] in a[2::3]:\r\n## back+=a[i]\r\n## print(i)\r\n##\r\n##if chest>biceps and chest>back:\r\n## print('chest')\r\n##elif biceps>chest and biceps>back:\r\n## print('biceps')\r\n##else:\r\n## print('back')\r\nchest=a[::3]\r\nbiceps=a[1::3]\r\nback=a[2::3]\r\n\r\nch=sum(chest)\r\nbic=sum(biceps)\r\nback=sum(back)\r\n\r\nif ch>bic and ch>back:\r\n print('chest')\r\nelif bic>ch and bic>back:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\nif n == 1:\n ex = [int(input())]\nelse:\n ex = list(map(int, input().split()))\nchest = biceps = back = 0\nfor i in range(0,n,3):\n chest += ex[i]\nfor i in range(1,n,3):\n biceps += ex[i]\nfor i in range(2,n,3):\n back += ex[i]\nif max(biceps, back, chest)==chest:\n print(\"chest\")\nelif max(biceps, back, chest)==biceps:\n print(\"biceps\")\nelse:\n print(\"back\")\n",
"number = input()\r\nlessons = input()\r\n \r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n \r\nfor i in range(0, int(number)):\r\n if int(number)-(i*3+1) >= 0:\r\n chest += int(lessons.split(' ')[i*3])\r\n if int(number)-(i*3+2) >= 0:\r\n biceps += int(lessons.split(' ')[i*3+1])\r\n if int(number)-(i*3+3) >= 0:\r\n back += int(lessons.split(' ')[i*3+2])\r\n \r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif back > biceps and back > chest:\r\n print('back')\r\nelse:\r\n print('biceps')\r\n",
"n = int(input())\r\nlst = [int(elem) for elem in input().split(\" \")]\r\nchest, biceps, back = 0, 0, 0\r\nfor i in range(len(lst)):\r\n if i % 3 == 0:\r\n chest += lst[i]\r\n elif i % 3 == 1:\r\n biceps += lst[i]\r\n else:\r\n back += lst[i]\r\nif chest > back and chest > biceps:\r\n print('chest')\r\nelif back > biceps and back > chest:\r\n print('back')\r\nelse:\r\n print(\"biceps\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest,biceps,back=0,0,0\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=l[i]\r\n elif i%3==1:\r\n biceps+=l[i]\r\n else:\r\n back+=l[i]\r\nif max(chest,biceps,back)==chest:\r\n print(\"chest\")\r\nelif max(chest,biceps,back)==biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"exercises = int(input())\r\nrepeats = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in repeats[::3]:\r\n chest += i\r\nfor i in repeats[1::3]:\r\n biceps += i\r\nfor i in repeats[2::3]:\r\n back += i\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps > chest and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\ne=[int(_) for _ in input().split()]\r\nch=bi=ba=0\r\nlic=0\r\nfor ele in e:\r\n\tlic+=1\r\n\tif lic==1: ch+=ele\r\n\tif lic==2: bi+=ele\r\n\tif lic==3:\r\n\t\tba+=ele\r\n\t\tlic=0\r\nprint(\"chest\" if max(ch,bi,ba)==ch else \"biceps\" if max(ch,bi,ba)==bi else \"back\")",
"i = int(input())\nlst = input().split()\nch = 0\nbi = 1\nbk = 2\n\nchest = 0\nbiceps = 0\nback = 0\n\nfor i in range(len(lst)):\n if i == ch:\n chest += int(lst[i])\n ch += 3\n elif i == bi:\n biceps += int(lst[i])\n bi += 3\n else:\n back += int(lst[i])\n bk += 3\n \nmx = max(chest, biceps, back)\nif chest == mx:\n print('chest')\nelif biceps == mx:\n print('biceps')\nelse:\n print('back')\n \t \t \t\t \t \t \t\t\t\t \t \t \t \t",
"le = int(input())\r\nlis = list(map(int, input().split()))\r\ns = 0\r\na = 0\r\nb = 0\r\nc = 0\r\nfor i in range(0,le,3):\r\n a += lis[i]\r\nfor i in range(1, le, 3):\r\n b += lis[i]\r\nfor i in range(2, le, 3):\r\n c += lis[i]\r\nx = max(a, b, c)\r\nif x == a:\r\n print('chest')\r\nif x == b:\r\n print('biceps')\r\nif x == c:\r\n print('back')\r\n\r\n",
"n = int(input())\r\nA = list(map(int, input().split()))\r\nc, bi, b = 0, 0, 0\r\nfor i in range(n):\r\n if i%3 == 0:\r\n c += A[i]\r\n elif i%3 == 1:\r\n bi += A[i]\r\n else:\r\n b += A[i]\r\nif max(c, bi, b) == c:\r\n print(\"chest\")\r\nelif max(c, bi, b) == bi:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\nl=list(map(int,input().split()))\nc=0\nbi=0\nba=0\nfor i in range(n):\n if(i%3==0):\n c=c+l[i]\n elif(i%3==1):\n bi=bi+l[i]\n else:\n ba=ba+l[i]\n#print(c,bi,ba)\nif(c>bi and c>ba):\n print(\"chest\")\nelif(bi>ba and bi>c):\n print(\"biceps\")\nelse:\n print(\"back\")",
"def solve(n, arr):\r\n c = bi = bk = 0\r\n for i in range(0, len(arr), 3):\r\n if i < n:\r\n c += arr[i]\r\n \r\n if i + 1 < n:\r\n bi += arr[i+1]\r\n\r\n if i + 2 < n:\r\n bk += arr[i+2]\r\n\r\n if c > bi and c > bk:\r\n return \"chest\"\r\n elif bi > c and bi > bk:\r\n return \"biceps\"\r\n else:\r\n return \"back\"\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nprint(solve(n, arr))",
"strength={}\r\nstrength['chest']=0\r\nstrength['biceps']=0\r\nstrength['back']=0\r\nn=int(input())\r\nnumber_list=list(map(int,input().split()))\r\nfor i in range(0,n,3):\r\n strength['chest']=strength['chest']+number_list[i]\r\nfor i in range(1,n,3):\r\n strength['biceps']=strength['biceps']+number_list[i]\r\nfor i in range(2,n,3):\r\n strength['back']=strength['back']+number_list[i]\r\n'''\r\nfor key,value in strength.items():\r\n print(key+':'+str(value))\r\n'''\r\nmax=strength['chest']\r\nto_print='chest'\r\nfor key,value in strength.items():\r\n if(value>max):\r\n max=value\r\n to_print=key\r\nprint(to_print)\r\n ",
"n = int(input())\r\nl = list(map(int,input().split()))\r\ni = 0\r\nchest , bicep, back = 0,0,0\r\nwhile(i<n):\r\n if i <n :\r\n chest+= l[i]\r\n i+=1\r\n if i <n :\r\n bicep+= l[i]\r\n i+=1\r\n if i <n :\r\n back+= l[i]\r\n i+=1\r\n\r\nif chest>bicep and chest >back:\r\n print('chest')\r\nelif bicep>back and bicep>chest:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"chest=0\r\nbiceps=0\r\nback=0\r\nt=int(input())\r\nc=0\r\nb=1\r\nb2=2\r\ny=list(map(int,input().split()))\r\nfor i in range(0,len(y)):\r\n if i==c:\r\n chest+=y[i]\r\n c+=3\r\n elif i==b:\r\n biceps+=y[i]\r\n b += 3\r\n elif i==b2:\r\n back+=y[i]\r\n b2 += 3\r\nif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest=back=biceps=0\r\nfor i in range(0,n,3):\r\n\tchest+=l[i]\r\nfor i in range(1,n,3):\r\n\tbiceps+=l[i]\r\nfor i in range(2,n,3):\r\n\tback+=l[i]\r\nif chest>biceps and chest>back:\r\n\tprint(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")",
"t=int(input())\r\na=input().split()\r\nb=[int(i) for i in a]\r\ns1=sum([b[i] for i in range(0,len(b),3)])\r\ns2=sum([b[i] for i in range(1,len(b),3)])\r\ns3=sum([b[i] for i in range(2,len(b),3)])\r\nif max(s1,s2,s3)==s1:\r\n print(\"chest\")\r\nelif max(s1,s2,s3)==s2:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc,b,bic=0,0,0\r\nfor i in range(n):\r\n if i%3==0:\r\n c+=a[i]\r\n elif i%3==1:\r\n bic+=a[i]\r\n else:\r\n b+=a[i]\r\nif max(c,b,bic)==c:\r\n print(\"chest\")\r\nelif max(c,b,bic)==b:\r\n print(\"back\") \r\nelse:\r\n print(\"biceps\")",
"n = int(input())\nexercises = list(map(int, input().split()))\n\nchest_sum = 0\nbiceps_sum = 0\nback_sum = 0\n\nfor i in range(n):\n if (i % 3) == 0:\n chest_sum += exercises[i]\n elif (i % 3) == 1:\n biceps_sum += exercises[i]\n else:\n back_sum += exercises[i]\n\nif chest_sum > biceps_sum and chest_sum > back_sum:\n print(\"chest\")\nelif biceps_sum > chest_sum and biceps_sum > back_sum:\n print(\"biceps\")\nelse:\n print(\"back\")\n\n\t \t\t\t\t \t \t\t\t\t\t\t\t \t\t \t \t",
"n=int(input())\r\na=input().split()\r\nchest=[]\r\nbiceps=[]\r\nback=[]\r\nwhile n>0:\r\n if n==1:\r\n chest.append(int(a[0]))\r\n del a[0]\r\n n-=1\r\n elif n==2:\r\n chest.append(int(a[0]))\r\n biceps.append(int(a[1]))\r\n del a[0]\r\n del a[0]\r\n n-=2\r\n elif n>2:\r\n chest.append(int(a[0]))\r\n biceps.append(int(a[1]))\r\n back.append(int(a[2]))\r\n del a[0]\r\n del a[0]\r\n del a[0]\r\n n-=3\r\ni=sum(chest)\r\no=sum(biceps)\r\np=sum(back)\r\nm=max(i,o,p)\r\nif m==i:\r\n print('chest')\r\nif m==o:\r\n print('biceps')\r\nif m==p:\r\n print('back')\r\n\r\n",
"'''\r\nJust group evens and odds\r\n'''\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nans=[\"chest\",\"biceps\",\"back\"]\r\narr=[0,0,0]\r\n\r\nt=int(input())\r\na=list(map(int,input().split()))\r\nfor i in range(t):\r\n arr[i%3] += a[i]\r\nmx = max(arr)\r\nfor i in range(3):\r\n if arr[i] == mx:\r\n print(ans[i])\r\n break",
"num=int(input())\r\nz=[int(i) for i in input().split()]\r\nz.insert(0,0)\r\nch=[]\r\nbi=[]\r\nba=[]\r\nfor i in range(1,len(z)):\r\n if i%3==0:\r\n ba.append(z[i])\r\n elif i%3==2:\r\n bi.append(z[i])\r\n else:\r\n ch.append(z[i])\r\nf=[sum(ch),sum(bi),sum(ba)]\r\nif f.index(max(f))==0:\r\n print('chest')\r\nelif f.index(max(f))==1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nb=0\r\nba=0\r\ni=0\r\nwhile(i!=n):\r\n c=c+l[i]\r\n i=i+1\r\n if(i!=n):\r\n b=b+l[i]\r\n i=i+1\r\n if(i!=n):\r\n ba=ba+l[i]\r\n i=i+1\r\nif(c==max(c,b,ba)):\r\n print(\"chest\")\r\nelif(b==max(c,b,ba)):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n\r\n \r\n",
"if __name__ == '__main__':\r\n\tn = int(input())\r\n\texeList = [int(i) for i in input().split()]\r\n\tches, bice, back, i = 0, 0, 0, 0\r\n\twhile i < n:\r\n\t\tif i < n: ches, i = (ches + exeList[i]), i + 1\r\n\t\tif i < n: bice, i = (bice + exeList[i]), i + 1\r\n\t\tif i < n: back, i = (back + exeList[i]), i + 1\r\n\t\t\r\n\tprint('chest' if ches == max(ches, bice, back) else ('biceps' if bice == max(bice, back) else 'back'))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc=0\r\nbi=0\r\nba=0\r\nfor i in range(len(a)):\r\n if i%3==0:\r\n c+=a[i]\r\n elif i%3==1:\r\n bi+=a[i]\r\n else:\r\n ba+=a[i]\r\nk=max(c,ba,bi)\r\nif k==c:\r\n print(\"chest\")\r\nelif k==bi:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchest= bicep = back = 0\r\nfor i in range(0, len(a), 3):\r\n chest += a[i]\r\nfor j in range(1, len(a), 3):\r\n bicep += a[j]\r\nfor k in range(2, len(a), 3):\r\n back += a[k]\r\n\r\nif(max(chest, bicep, back) == bicep):\r\n print('biceps')\r\nelif(max(chest, bicep, back) == back):\r\n print('back')\r\nelse:\r\n print('chest')",
"n=int(input())\r\ns=list(map(int,input().split()))\r\na=sum(s[0::3])\r\nb=sum(s[1::3])\r\nc=sum(s[2::3])\r\nif max(a,b,c)==a:\r\n print('chest')\r\nif max(a,b,c)==b:\r\n print('biceps')\r\nif max(a,b,c)==c:\r\n print('back')",
"a = int(input())\r\nb = list(map(int,input().split()))\r\nc = len(b)\r\no = 3\r\nf = 0\r\nx = 0\r\ny = 0\r\nz = 0\r\nfor i in b:\r\n k = b[f:o]\r\n if len(k) == 3:\r\n x = x + k[0]\r\n y = y + k[1]\r\n z = z + k[2]\r\n elif len(k) == 2:\r\n x = x + k[0]\r\n y = y + k[1]\r\n elif len(k) == 1:\r\n x = x + k[0]\r\n o = o + 3\r\n f = f + 3\r\nif x > y and x > z:\r\n print(\"chest\")\r\nelif y > x and y > z:\r\n print(\"biceps\")\r\nelif z > x and z > y:\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nx=sum(a[::3])\r\ny=sum(a[1::3])\r\nz=sum(a[2::3])\r\nif(x>y and (x>z)):\r\n print(\"chest\")\r\nelif(y>x and y>z):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\nc=0\nb=0\nba=0\nuser=input().split()\nd=[]\nf=[1,4,7,10,13,16,19]\nfor i in range(len(user)):\n d.append(int(user[i]))\nfor i in range(n):\n if i==0 or i%3==0:\n c+=d[i]\n elif i in f:\n b+=d[i]\n else:\n ba+=d[i]\nif c>b and c>ba:\n print('chest')\nelif b>c and b>ba:\n print('biceps')\nelse:\n print('back')\n\t \t \t \t \t\t \t \t\t \t\t \t\t",
"n = int(input())\r\nsp = list(map(int, input().split(\" \")))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(0, len(sp), 3):\r\n chest += sp[i]\r\nfor i in range(1, len(sp), 3):\r\n biceps += sp[i]\r\nfor i in range(2, len(sp), 3):\r\n back += sp[i]\r\nif (max(chest, biceps, back) == chest):\r\n print(\"chest\")\r\nelif(max(chest, biceps, back) == biceps):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"from sys import stdin\r\nfrom collections import defaultdict as dd\r\nn=int(stdin.readline().rstrip())\r\nl=list(map(int,stdin.readline().split()))\r\nd=dd(int)\r\nfor i in range(n):\r\n d[i%3]+=l[i]\r\nm=max(d[0],d[1],d[2])\r\nif m==d[0]:\r\n print(\"chest\")\r\nelif m==d[1]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"##a=str(input())\r\n##b=\"\"\r\n##for i in range(len(a)):\r\n## if i%3!=0:\r\n## print(a[i], end=\"\")\r\n\r\n\r\n##n=int(input()) #кол-во соревнований\r\n##list_= [int(value) for value in input().split()] #кол-во баллов во всех соревнованиях\r\n##list2=[list_.pop(0)] #удаляем баллы за первое соревнование и помещаем в новый список\r\n##maxim=0\r\n##minim=0\r\n##for i in list_: #проверяем каждое его соревнование на баллы\r\n## if i>max(list2): #провеяем если он набрал за новое соревнования больше баллов чем в\r\n## maxim+=1 #предыдщуих всех соревнованиях наращиваем удивительное соревнование\r\n## elif i<min(list2): #если он набрал за новое соревнования меньше баллов чем в\r\n## minim+=1#предыдщуих всех соревнованиях наращиваем удивительное соревнование\r\n## list2.append(i)#добавляем баллы за его соревнование во второй список\r\n##print(maxim+minim)#выводим общее кол-во удивительных соревнований\r\n\r\n\r\n###минимальное кол-во денег надо потратить, чтобы уровнять всех\r\n##n=int(input()) #кол-во граждан\r\n##a=list(map(int,input().split())) #бюджет каждого отдельного человека\r\n##z=max(a) #самый большой капитал человека к которому мы будем уравнивать\r\n##q=0 #общее кол-во денег всех граждан\r\n##for i in a:\r\n## q+=i\r\n##print(z*n-q)\r\n\r\n\r\n#что егор накачает больше всего\r\nn=int(input()) #сколько упражнений он выполнит 1-грудь 2-бицепс 3-спина 4 грудь и т д\r\na=list(map(int,input().split()))#повторы упражнений\r\nchest=0 #наращиваем сколько он сделал упражнений на грудь\r\nbiceps=0 #наращиваем сколько он сделал упражнений на бицепс\r\nback=0 #наращиваем сколько он сделал упражнений на спину\r\nfor i in range(len(a)):\r\n if i%3==0:\r\n chest+=a[i]\r\n if i%3==1:\r\n biceps+=a[i]\r\n if i%3==2:\r\n back+=a[i]\r\nif chest>biceps:\r\n if chest>back:\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\nelif biceps>chest:\r\n if biceps>back:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\nelif back>chest:\r\n if back>biceps:\r\n print(\"back\")\r\n else:\r\n print(\"biceps\")\r\n",
"if __name__ == \"__main__\":\r\n _ = int(input())\r\n exercises = list(map(int, input().split()))\r\n \r\n types_of_exercises = [0, 0, 0]\r\n\r\n i = 0\r\n while len(exercises):\r\n if i == 3:\r\n i = 0\r\n exercises = exercises[3:]\r\n\r\n if i < len(exercises):\r\n types_of_exercises[i] += exercises[i]\r\n\r\n i += 1\r\n \r\n type = types_of_exercises.index(max(types_of_exercises))\r\n \r\n if type == 0:\r\n print(\"chest\")\r\n elif type == 1:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n",
"num = int(input())\r\narr = list(map(int, input().split()))\r\nch = [i for i in range(0, num, 3)]\r\nbi = [i for i in range(1, num, 3)]\r\nba = [i for i in range(2, num, 3)]\r\n\r\nc = 0\r\nbii = 0\r\nbaa = 0\r\n\r\nfor i in ch:\r\n c += arr[i]\r\nfor i in bi:\r\n bii += arr[i]\r\nfor i in ba:\r\n baa += arr[i]\r\n\r\nmaxx = max(c, bii, baa)\r\n\r\nif maxx ==c:\r\n print(\"chest\")\r\nelif maxx == bii:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n\r\n\r\n\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\na = 0\r\nb = 0\r\nc = 0\r\nfor i in range(0,len(arr),3):\r\n a += arr[i]\r\nfor i in range(1,len(arr),3):\r\n b += arr[i]\r\nfor i in range(2,len(arr),3):\r\n c += arr[i]\r\nif (max(a,b,c) == a):\r\n print(\"chest\")\r\nelif (max(a,b,c) == b):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\ntn = list(map(int, input().split()))\r\nt = [0,0,0]\r\nfor i in range(0,n):\r\n t[i % 3] += tn[i]\r\nif t[0] > t[1] and t[0] > t[2]:\r\n print('chest')\r\nelif t[1]> t[0] and t[1] > t[2]:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"# first, lets prepare the vars.\r\n\r\n# create a list to carry the accumlative sums for each exercise\r\nexercisesDone=[0,0,0]\r\n# create a dict that carries the name of the exercise\r\ntypes={0:\"chest\", 1:\"biceps\", 2:\"back\"}\r\n# input the number exercises to be done\r\nn = int(input())\r\n\r\n# input the list that contains the reps of each exercise \r\nreptitions = str(input()).split(\" \")\r\n\r\n# as said in the problem we always start with chest\r\n# also we will use this var to index the exercise that should be increased\r\ncurrentType=0\r\n\r\n# loop over the number of exercises to be done\r\nfor exercise in reptitions:\r\n # now, use the var to index the sum that should be increased\r\n exercisesDone[currentType]+=int(exercise)\r\n # add one to the var to index the next exercise\r\n currentType+=1\r\n # check if the var 3 (meaning we finished a cycle of training (chest->biceps->back))\r\n if(currentType==3):\r\n currentType=0\r\n\r\n# get the index of the max sum\r\nindexOfMax=exercisesDone.index(max(exercisesDone))\r\n\r\n# now, use the dict we created eariler to print the muscle that did the most work.\r\nprint(types[indexOfMax])",
"if __name__ == \"__main__\":\r\n n = int(input())\r\n exercises = list(map(int, input().split()))\r\n\r\n types_of_exercises = [0, 0, 0]\r\n\r\n i = 0\r\n type = 0\r\n while i < n:\r\n if type == 3:\r\n type = 0\r\n\r\n types_of_exercises[type] += exercises[i]\r\n\r\n i += 1\r\n type += 1\r\n\r\n type = types_of_exercises.index(max(types_of_exercises))\r\n \r\n if type == 0:\r\n print(\"chest\")\r\n elif type == 1:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n",
"n=int(input())\r\ns=list(map(int,input().split(' ')))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(1,n,3):\r\n\tb+=s[i]\r\nfor i in range(0,n,3):\r\n\ta+=s[i]\r\nfor i in range(2,n,3):\r\n\tc+=s[i]\r\nif max(a,b,c)==a:\r\n\tprint('chest')\r\nif max(a,b,c)==b:\r\n\tprint('biceps')\r\nif max(a,b,c)==c:\r\n\tprint('back')",
"a = int(input())\r\nb = list(map(int,input().split()))\r\nf = []\r\ng = []\r\np = []\r\nfor i in b[0::3]:\r\n f.append(i)\r\ntry:\r\n for i in b[1::3]:\r\n g.append(i)\r\nexcept:\r\n g = []\r\ntry:\r\n for i in b[2::3]:\r\n p.append(i)\r\nexcept:\r\n p = []\r\nf = sum(f)\r\ng = sum(g)\r\np = sum(p)\r\nk = [f,g,p]\r\nif max(k) == f:\r\n print('chest')\r\nelif max(k) == g:\r\n print('biceps')\r\nelse:\r\n print('back')",
"# # №1.1 Буква в слове\r\n# a = input()\r\n# s = list(input().split())\r\n# l = len(s)\r\n# for i in range(l):\r\n# if a in s[i]:\r\n# print(s[i])\r\n\r\n# # №1.2 Максимальное кол-во букв в слове\r\n# a = input().lower()\r\n# max_c = 0\r\n# for i in a:\r\n# if a.count(i) >= max_c:\r\n# max_c = a.count(i)\r\n# print(max_c)\r\n\r\n# # №1.3 Удалить каждый третий символ\r\n# a = input()\r\n# l = len(a)\r\n# b = ''\r\n# for i in range(l):\r\n# if i != 0 and i % 3 != 0:\r\n# b = b + a[i]\r\n# print(b)\r\n\r\n# # №1.4 Полицейские-рекруты\r\n# c = int(input())\r\n# h = list(map(int, input().split()))\r\n# p_count = 0\r\n# out = 0\r\n# for i in h:\r\n# if i == -1:\r\n# if p_count == 0:\r\n# out += 1\r\n# else:\r\n# p_count -= 1\r\n# if 1 <= i <= 10:\r\n# p_count += i\r\n# print(out)\r\n# https://codeforces.com/problemset/problem/427/A\r\n\r\n# # №1.5 A. I_love_%username%\r\n# c = int(input())\r\n# h = list(map(int, input().split()))\r\n# count = 0\r\n# min = h[0]\r\n# max = h[0]\r\n# for i in range(c):\r\n# if h[i] > max:\r\n# max = h[i]\r\n# count += 1\r\n# elif h[i] < min:\r\n# min = h[i]\r\n# count += 1\r\n# print(count)\r\n# https://codeforces.com/problemset/problem/155/A\r\n\r\n# # №1.5 A. Следующий раунд\r\n# n, k = map(int, input().split())\r\n# h = list(map(int, input().split()))\r\n# count = 0\r\n# for i in range(n):\r\n# if h[i] >= h[k-1] and h[i] > 0:\r\n# count += 1\r\n# print(count)\r\n# https://codeforces.com/problemset/problem/158/A\r\n\r\n# # №1.5.1 A. Праздник равенства\r\n# n = int(input())\r\n# h = list(map(int, input().split()))\r\n# max_h = max(h)\r\n# count = 0\r\n# for i in range(n):\r\n# if h[i] < max_h:\r\n# r = max_h - h[i]\r\n# count += r\r\n# print(count)\r\n# https://codeforces.com/problemset/problem/758/A\r\n\r\n# # №1.6 Тренировки Егора\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ncount_chest = 0\r\ncount_biceps = 0\r\ncount_back = 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n count_chest += a[i]\r\n elif i % 3 == 1:\r\n count_biceps += a[i]\r\n elif i % 3 == 2:\r\n count_back += a[i]\r\n else:\r\n print('что то не так')\r\nif count_chest > count_biceps and count_chest > count_back:\r\n print('chest')\r\nelif count_biceps > count_chest and count_biceps > count_back:\r\n print('biceps')\r\nelif count_back > count_chest and count_back > count_biceps:\r\n print('back')\r\nelse:\r\n print('сбой снова')\r\n# https://codeforces.com/problemset/problem/255/A",
"n=int(input())\r\nI=[int(x) for x in input().split()]\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(n):\r\n if (i%3==0):\r\n chest = chest+I[i]\r\n if (i%3==1):\r\n biceps = biceps+I[i]\r\n if (i%3==2):\r\n back = back +I[i]\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif chest<biceps and biceps>back:\r\n print(\"biceps\")\r\nelse :\r\n print(\"back\")",
"n = int(input())\r\nexercises = list(map(int, input().split(\" \")))\r\nlast_exercise = \"back\"\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor x in exercises:\r\n if last_exercise == \"back\":\r\n chest += x\r\n last_exercise = \"chest\"\r\n elif last_exercise == \"chest\":\r\n biceps += x\r\n last_exercise = \"biceps\"\r\n else:\r\n back += x\r\n last_exercise = \"back\"\r\nif max(chest, biceps, back) == chest:\r\n print(\"chest\")\r\nelif max(chest, biceps, back) == biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"t=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nbi=0\r\nb=0\r\nfor i in range(0,t,3):\r\n c=c+l[i]\r\n if i+1<t :\r\n bi=bi+l[i+1]\r\n if i+2 <t:\r\n b=b+l[i+2]\r\nif c>bi and c>b:\r\n print(\"chest\")\r\nif bi>c and bi>b:\r\n print(\"biceps\")\r\nif b>bi and b>c:\r\n print(\"back\")",
"n=int(input())\r\na=[]\r\na=input().split()\r\nb,c,d=0,0,0\r\nfor x in range(0,n):\r\n if x%3==0:\r\n b+=int(a[x])\r\n elif x%3==1:\r\n c+=int(a[x])\r\n else:\r\n d+=int(a[x])\r\nif b>=c:\r\n if b>=d:\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\nelse:\r\n if c>=d:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")",
"n=int(input())\r\nlist=list(map(int,input().split()))\r\nindex=1\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(n):\r\n if index%3==1:\r\n chest+=list[i]\r\n elif index%3==2:\r\n biceps+=list[i]\r\n else:\r\n back+=list[i]\r\n index+=1\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelif back>chest and back>biceps:\r\n print(\"back\")",
"tasks = {'chest':0, 'biceps':0, 'back':0}\r\nn = int(input())\r\na = [int(elem) for elem in input().split()]\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n tasks['chest'] +=a[i]\r\n if i % 3 == 1:\r\n tasks['biceps'] +=a[i]\r\n if i % 3 == 2:\r\n tasks['back'] +=a[i]\r\nfor name, counts in tasks.items():\r\n if counts == max(tasks.values()):\r\n print(name)",
"import sys\r\nt = int(sys.stdin.readline())\r\narr = list(map(int, sys.stdin.readline().split()))\r\nchest = biceps = back = 0\r\nfor i in range(len(arr)):\r\n if i % 3 == 0:\r\n chest += arr[i]\r\n elif i % 3 == 1:\r\n biceps += arr[i]\r\n else:\r\n back += arr[i]\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\np=0\r\nq=0\r\nr=0\r\nfor i in range(0,n,3):\r\n p=p+a[i]\r\nfor i in range(1,n,3):\r\n q=q+a[i]\r\nfor j in range(2,n,3):\r\n r=r+a[j]\r\nif p>q and p>r:\r\n print('chest')\r\nelif q>p and q>r: \r\n print('biceps')\r\nelif r>q and r>p:\r\n print('back')\r\n ",
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\nb=[0]*3\r\n# print(b)\r\n\r\nfor i in range(n):\r\n\tb[i%3]+=a[i]\r\n\r\n\r\nm=max(b)\r\nif b[0]==m:\r\n\tprint(\"chest\")\r\nelif b[1]==m:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nif n == 1:\r\n print(\"chest\")\r\nelif n == 2:\r\n chest = arr[0]\r\n biceps = arr[1]\r\n print([\"chest\", \"biceps\"][chest < biceps])\r\n\r\nelif n == 3:\r\n dictionary = {arr[0]: \"chest\", arr[1]: \"biceps\", arr[2]: \"back\"}\r\n m = max(dictionary.keys())\r\n print(dictionary[m])\r\n\r\nelse:\r\n chest = 0\r\n biceps = 0\r\n back = 0\r\n for i in range(0, n, 3):\r\n chest += arr[i]\r\n\r\n for i in range(1, n, 3):\r\n biceps += arr[i]\r\n\r\n for i in range(2, n, 3):\r\n back += arr[i]\r\n\r\n dictionary = {chest: \"chest\", biceps: \"biceps\", back: \"back\"}\r\n m = max(dictionary.keys())\r\n print(dictionary[m])",
"l=[0]*3\r\nn=int(input())\r\na=[ int(x) for x in input().split()]\r\nfor i in range(0,n):\r\n l[i%3]+=a[i]\r\n\r\nmx=0\r\n\r\nfor i in range(1,3):\r\n if l[i]>l[mx]:\r\n mx=i\r\n\r\nif mx==0:\r\n print('chest')\r\nelif mx==1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"x = int(input())\r\n\r\ny = list(map(int, input().strip().split()))\r\n\r\nl = [0, 0, 0]\r\n\r\nfor i in range(x):\r\n l[i % 3] += y[i]\r\n\r\na = l.index(max(l))\r\n\r\nif a == 0:\r\n print(\"chest\")\r\nelif a == 1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\nk = list(map(int, input().split()))\r\nd = {\"chest\": 0, \"biceps\": 0, \"back\": 0}\r\na = [i for i in range(0, 26, 3)]\r\nb = [i for i in range(1, 26, 3)]\r\nc = [i for i in range(2, 26, 3)]\r\nfor i in range(len(k)):\r\n if i in a:\r\n d[\"chest\"] += k[i]\r\n elif i in b:\r\n d[\"biceps\"] += k[i]\r\n else:\r\n d[\"back\"] += k[i]\r\n\r\nprint(max(d, key=d.get))",
"n = int(input())\r\na = list(map(int, input().split()))\r\ng, b, s = 0, 0, 0\r\nfor i in range(n):\r\n g = sum(a[::3])\r\n b = sum(a[1::3])\r\n s = sum(a[2::3])\r\nif g > b and g > s:\r\n print('chest')\r\nelif b > g and b > s:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\nex = list(map(int, input().split()))\r\nmusc = ['chest', 'biceps', 'back']\r\nnum_total = [\r\n\tsum([ex[i] for i in range(n) if i%3==0]),\r\n\tsum([ex[i] for i in range(n) if i%3==1]),\r\n\tsum([ex[i] for i in range(n) if i%3==2])]\r\nprint(musc[num_total.index(max(num_total))])",
"exercises = int(input())\r\nrepeats = list(map(int, input().split()))\r\nlength = len(repeats)\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor exercise in range(length):\r\n if exercise % 3 == 0:\r\n chest += repeats[exercise]\r\n elif exercise % 3 == 1:\r\n biceps += repeats[exercise]\r\n elif exercise % 3 == 2:\r\n back += repeats[exercise]\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\na=[]\r\nb=[]\r\nc=[]\r\nl=list(map(int,input().split()))\r\nfor i in range(0,len(l)):\r\n if i%3==0:\r\n a.append(l[i])\r\n elif i%3==1:\r\n b.append(l[i])\r\n else:\r\n c.append(l[i])\r\nif sum(a)>sum(b) and sum(a)>sum(c):\r\n print(\"chest\")\r\nelif sum(b)>sum(a) and sum(b)>sum(c):\r\n print(\"biceps\")\r\nelif sum(c)>sum(a) and sum(c)>sum(b):\r\n print(\"back\")\r\n",
"n= int(input())\r\narr=[int(x) for x in input().split()]\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(0,len(arr),3) :\r\n chest+=arr[i]\r\n if i+1 < len(arr):\r\n biceps+=arr[i+1]\r\n if i + 2 < len(arr):\r\n back+=arr[i+2]\r\n\r\nmaxi=max(chest,biceps,back)\r\nprint(\"chest\" if maxi==chest else \"biceps\" if maxi==biceps else \"back\")",
"n = int(input())\r\nexercises = list(map(int, input().split(\" \")))\r\nsum = [0, 0, 0]\r\nfor idx in range(0, n):\r\n sum[idx % 3] += exercises[idx]\r\nif sum[0] > sum[1] and sum[0] > sum[2]:\r\n print(\"chest\")\r\nelif sum[1] > sum[0] and sum[1] > sum[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\np=[\"chest\",\"biceps\",\"back\"]\r\nk=[sum(l[::3]),sum(l[1::3]),sum(l[2::3])]\r\nq=list(zip(*sorted(zip(k,p))))\r\nprint(q[1][2])",
"n=int(input())\r\na=list(map(int , input().split()))\r\nc=1\r\nch=0\r\nbi=0\r\nba=0\r\nfor i in range(n):\r\n if(c==1):\r\n ch+=a[i]\r\n c+=1\r\n elif(c==2):\r\n bi+=a[i]\r\n c+=1\r\n elif(c==3):\r\n ba+=a[i]\r\n c=1\r\nd=max(ch,bi,ba)\r\nif(d==ch):\r\n print(\"chest\")\r\nelif(d==bi):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\n\r\na=list(map(int, input().split()))\r\ns=0\r\nb=0\r\nc=0\r\nfor i in range(n):\r\n if i%3==0:\r\n s+=a[i]\r\n elif (i-1)%3==0:\r\n b+=a[i]\r\n elif (i-2)%3==0:\r\n c+=a[i]\r\nif s>b:\r\n if s>c:\r\n print('chest')\r\n else:\r\n print('back')\r\nelse:\r\n if b>c:\r\n print('biceps')\r\n else:\r\n print('back')",
"a = int(input())\r\nb = list(map(int, input().split()))\r\nchestlist = []\r\nbicepslist = []\r\nbacklist = []\r\nn = 0\r\ncount = 0\r\nwhile count<len(b):\r\n if n>=len(b):\r\n break\r\n chestlist.append(b[n])\r\n n+=3\r\n\r\nn=1\r\nwhile count<len(b):\r\n if n>=len(b):\r\n break\r\n bicepslist.append(b[n])\r\n n+=3\r\n\r\nn=2\r\nwhile count<len(b):\r\n if n>=len(b):\r\n break\r\n backlist.append(b[n])\r\n n+=3\r\n\r\n\r\nchest = sum(chestlist)\r\nbiceps = sum(bicepslist)\r\nback = sum(backlist)\r\n\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nb = [sum(l[i::3]) for i in range(3)]\r\nx=(b.index(max(b)))\r\nif(x==0):\r\n print(\"chest\")\r\nif(x==1):\r\n print(\"biceps\")\r\nif(x==2):\r\n print(\"back\")",
"n = int(input())\na = list(map(int, input().split()))\n\nchest = 0\nbiceps = 0\nback = 0\n\nfor i, ai in enumerate(a):\n if i % 3 == 0:\n chest += ai\n elif i % 3 == 1:\n biceps += ai\n else:\n back += ai\n\nif chest > biceps and chest > back:\n print(\"chest\")\nelif biceps > chest and biceps > back:\n print(\"biceps\")\nelse:\n print(\"back\")\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nresult = [0, 0, 0]\r\nstring = ['chest', 'biceps', 'back']\r\nj = 0\r\nfor i in range(n):\r\n result[j % 3] += a[i]\r\n j += 1\r\n\r\nprint(string[result.index(max(result))])\r\n",
"n = input()\r\ninp = list(map(int,input().split()))\r\n# print(inp)\r\n# print(sum(inp[2::3]),sum(inp[1::3]),sum(inp[::3]))\r\nprint([\"chest\",\"biceps\",\"back\"][max(0,1,2,key=lambda i: sum(inp[i::3]))])",
"n = int(input())\nk = list(map(int,input().split()))\nx = sum(k[0::3])\n\ny = sum(k[1::3])\n\nz =sum(k[2::3])\n\nif max(x,y,z) == x:\n\tprint(\"chest\")\nelif max(x,y,z) == y:\n\tprint(\"biceps\")\nelse:\n\tprint(\"back\")",
"n = int(input())\ns = list(map(int,input().split()))\nx=0\ny=0\nz=0\n \nfor i in range(0,n,3):\n x = x+s[i]\nfor i in range(1,n,3):\n y = y+s[i] \nfor i in range(2,n,3):\n z = z+s[i] \nif x > y and x>z:\n print('chest')\nelif y > x and y > z:\n print('biceps')\nelse:\n print('back')\n\n \n \n \n \n \n\n\n \n\n",
"dic={'chest':0,'biceps':0,'back':0}\nn=int(input())\nl=list(map(int,input().split()))\nfor i in range(len(l)):\n if i%3==0:\n dic['chest']+=l[i]\n elif i%3==1:\n dic['biceps']+=l[i]\n elif i%3==2:\n dic['back']+=l[i]\nmaxx=-1\nans=''\nfor k,v in dic.items():\n if dic[k]>maxx:\n maxx=dic[k]\n ans=k\nprint(ans)\n\t \t \t \t \t\t \t\t\t \t\t",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=['chest', 'biceps', 'back']*(n//3)\r\nif n%3==1:\r\n b.append('chest')\r\nelif n%3==2:\r\n b.extend(['chest', 'biceps'])\r\nch=0\r\nbi=0\r\nba=0\r\nfor i in range(n):\r\n if b[i]=='chest':\r\n ch+=a[i]\r\n elif b[i]=='biceps':\r\n bi+=a[i]\r\n else:\r\n ba+=a[i]\r\nif max(ch, bi, ba)==ch:\r\n print('chest')\r\nelif max(ch, bi, ba)==bi:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\nexc = [int(x) for x in input().split()][:n]\nchest, biceps, back = 0, 0, 0\nfor i in range(n):\n\tif i % 3 == 0:\n\t\tchest += exc[i]\n\telif i % 3 == 1:\n\t\tbiceps += exc[i]\n\telse:\n\t\tback += exc[i]\nif chest >= biceps and chest >= back:\n\tprint('chest')\nelif biceps >= chest and biceps >= back:\n\tprint('biceps')\nelse:\n\tprint('back')\n\n# 0 1 2 -- 3 4 5 -- 6 7 8\n\t \t\t\t \t\t \t \t \t \t\t \t \t",
"n = int(input())\r\nL = [int(a) for a in input().split(\" \",n-1)]\r\ns=0\r\ns1=0\r\ns2=0\r\nif n<3:\r\n if n==1:\r\n print(\"chest\")\r\n else:\r\n if L[0]>L[1]:\r\n print(\"chest\")\r\n else:\r\n print(\"biceps\")\r\nelse:\r\n if n%3==0:\r\n for i in range(3,n+1,3):\r\n s=s+L[i-3]\r\n s1=s1+L[i-2]\r\n s2=s2+L[i-1]\r\n else:\r\n for i in range(3,n+1,3):\r\n s=s+L[i-3]\r\n s1=s1+L[i-2]\r\n s2=s2+L[i-1]\r\n if (n%3)==1:\r\n s=s+L[(3*(n//3))]\r\n else:\r\n s=s+L[(3*(n//3))]\r\n s1=s1+L[(3*(n//3))+1]\r\n if(s>s1 and s>s2):\r\n print(\"chest\")\r\n elif(s1>s and s1>s2):\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n ",
"n = int(input())\r\na = list(map(int,input().split()))\r\nch = sum(a[0::3])\r\nbi = sum(a[1::3])\r\nba = sum(a[2::3])\r\n\r\nif ch>bi and ch>ba:\r\n print(\"chest\")\r\nelif bi>ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nchest=back=biceps=0\r\ni=0\r\n\r\nwhile n:\r\n if n==1:\r\n chest=chest+a[i]\r\n n=n-1\r\n i=i+1\r\n elif n==2:\r\n chest=chest+a[i]\r\n biceps=biceps+a[i+1]\r\n n=n-2\r\n i=i+2\r\n else:\r\n chest=chest+a[i]\r\n biceps=biceps+a[i+1]\r\n back=back+a[i+2]\r\n n=n-3\r\n i=i+3\r\n \r\nif chest>=biceps and chest>=back:\r\n print(\"chest\")\r\nelif biceps>=chest and biceps>=back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n ",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(0,n,3):\r\n\ta=a+l[i]\r\nfor i in range(1,n,3):\r\n\tb=b+l[i]\r\nfor i in range(2,n,3):\r\n\tc=c+l[i]\r\nif max(a,b,c)==a:\r\n\tprint(\"chest\")\r\nelif max(a,b,c)==b:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")\r\n",
"n = int(input())\r\nx = 1\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\ncounts = list(map(int, input().split()[:n]))\r\nfor count in counts:\r\n if x == 1:\r\n chest += count\r\n elif x == 2:\r\n biceps += count\r\n elif x == 3:\r\n back += count\r\n x += 1\r\n if x == 4:\r\n x = 1\r\nif chest >= biceps and chest >= back:\r\n print('chest')\r\nelif biceps >= chest and biceps >= back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc1=c2=c3=0\r\nfor i in range(0,n,3):\r\n c1+=a[i]\r\nfor i in range(1,n,3):\r\n c2+=a[i]\r\nfor i in range(2,n,3):\r\n c3+=a[i]\r\n\r\nif(c1==max(c1,c2,c3)):\r\n print('chest')\r\nelif(c2==max(c1,c2,c3)):\r\n print('biceps')\r\nelif(c3==max(c1,c2,c3)):\r\n print('back')",
"n = int(input())\nrepetitions = list(map(int, input().split()))\n\nchest = 0\nbiceps = 0\nback = 0\n\nfor i in range(n):\n if i % 3 == 0:\n chest += repetitions[i]\n elif i % 3 == 1:\n biceps += repetitions[i]\n else:\n back += repetitions[i]\n\nif chest > biceps and chest > back:\n print(\"chest\")\nelif biceps > chest and biceps > back:\n print(\"biceps\")\nelse:\n print(\"back\")\n",
"holds = int(input())\r\narr = list(map(int,input().strip().split()))\r\nchest,biceps,back = 0,0,0\r\nx = 1\r\nfor i in arr:\r\n if x ==1:\r\n chest+=i\r\n x+=1\r\n elif x==2:\r\n biceps+=i\r\n x+=1\r\n else:\r\n back+=i\r\n x = 1\r\nif chest == max([chest,biceps,back]):\r\n print('chest')\r\nelif biceps == max([chest,biceps,back]):\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\narr=input().split()\r\narr=[int(i) for i in arr]\r\nchest=0\r\nback=0\r\nbiceps=0\r\nfor i in range(n):\r\n if(i==0 or i%3==0):\r\n chest+=arr[i]\r\n elif(i==1 or i%3==1):\r\n biceps+=arr[i]\r\n else:\r\n back+=arr[i]\r\n\r\nif(chest>biceps):\r\n if(chest>back):\r\n print('chest')\r\n else:\r\n print('back')\r\nelse:\r\n if(biceps>back):\r\n print('biceps')\r\n else:\r\n print('back')\r\n",
"#%% 255a Nag's workout \r\nn = int(input())\r\narr = [*map(int,input().split())]\r\nw = []\r\nfor i in range(3):\r\n w.append(sum(arr[i::3]))\r\nprint(['chest','biceps','back'][w.index(max(w))])\r\n\r\n",
"n=int(input())\r\nl=[int(x) for x in input().split()]\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(n):\r\n\tif i % 3 == 0:\r\n\t\tchest+=l[i]\r\n\telif i%3 == 1:\r\n\t\tbiceps+=l[i]\r\n\telif i % 3 == 2:\r\n\t\tback+=l[i]\r\nif chest > biceps and chest > back:\r\n\tprint(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")",
"n=int(input())\r\nL=list(map(int,input().split()))\r\nc1=0\r\nc2=0\r\nc3=0\r\nfor i in range(len(L)):\r\n if i%3==0:\r\n c1+=L[i]\r\n elif i%3==1:\r\n c2=c2+L[i]\r\n else:\r\n c3+=L[i]\r\nif max(c1,c2,c3)==c1:\r\n print(\"chest\")\r\nelif max(c1,c2,c3)==c2:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\nli=input().split()\r\nl=list(map(int,li))\r\ns1,s2,s3=0,0,0\r\nfor i in range(0,len(l),3):\r\n s1+=l[i]\r\nfor i in range(1,len(l),3):\r\n s2+=l[i]\r\nfor i in range(2,len(l),3):\r\n s3+=l[i]\r\nif(s1>s2 and s1>s3):\r\n print(\"chest\")\r\nelif(s2>s1 and s2>s3):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"if __name__ == \"__main__\":\r\n n = int(input())\r\n exercises = list(map(int,input().split()))\r\n chest = 0\r\n biceps = 0\r\n back = 0\r\n for i in range(n):\r\n if i%3 == 0:\r\n chest += exercises[i]\r\n elif i%3 == 1:\r\n biceps += exercises[i]\r\n else:\r\n back += exercises[i]\r\n mx = max([chest,biceps,back])\r\n if chest == mx:\r\n print(\"chest\")\r\n elif biceps == mx:\r\n print('biceps')\r\n else:\r\n print('back')",
"n=int(input())\narr=list(map(int,input().split()))\nm={1:0,2:0,3:0}\nfor i in range(n):\n m[(i%3)+1]+=arr[i]\n\n\n# for i in arr:\n# if i==1:\n# m[1]+=1\n# if i==2:\n# m[1]+=1\n# m[2]+=1\nk=[1,2,3]\nv=list(m.values())\n# print(m,v,max(v),v.index(max(v)),k[v.index(max(v))])\n# print(v,max(v))\nif k[v.index(max(v))]==1:\n print(\"chest\")\nelif k[v.index(max(v))]==2:\n print(\"biceps\")\nelse:\n print(\"back\")\n\n# n=int(input())\n# arr=list(map(int,input().split()))\n# for i in range(n):\n# arr[i]=arr[i]%3\n# m={1:0,2:0,3:0}\n# for i in arr:\n# if i==0:\n# m[i]+=1\n# if i==1:\n# m[i]+=1\n# m[0]+=1\n# # if\n# v=list(m.values())\n# # print(m)\n# if v.index(max(v))==0:\n# print(\"chest\")\n# elif v.index(max(v))==2:\n# print(\"biceps\")\n# else:\n# print(\"back\")\n\n\n# n=int(input())\n# arr=list(map(int,input().split()))\n# for i in range(n):\n# arr[i]=arr[i]%3\n# m={1:0,2:0,3:0}\n# for i in arr:\n# if i==1:\n# m[1]+=1\n# if i==2:\n# m[1]+=1\n# m[2]+=1\n# k=[1,2,3]\n# v=list(m.values())\n# print(m,v,max(v),v.index(max(v)),k[v.index(max(v))])\n# print(v,max(v))\n# if k[v.index(max(v))]==1:\n# print(\"chest\")\n# elif k[v.index(max(v))]==2:\n# print(\"biceps\")\n# else:\n# print(\"back\")\n\n# # n=int(input())\n# # arr=list(map(int,input().split()))\n# # for i in range(n):\n# # arr[i]=arr[i]%3\n# # m={1:0,2:0,3:0}\n# # for i in arr:\n# # if i==0:\n# # m[i]+=1\n# # if i==1:\n# # m[i]+=1\n# # m[0]+=1\n# # # if\n# # v=list(m.values())\n# # # print(m)\n# # if v.index(max(v))==0:\n# # print(\"chest\")\n# # elif v.index(max(v))==2:\n# # print(\"biceps\")\n# # else:\n# # print(\"back\")",
"times = int(input())\r\ninputArr = input().split(\" \")\r\ncount = 1\r\ntotalBiceps = 0\r\ntotalChest = 0\r\ntotalBack = 0\r\n\r\nfor i in inputArr:\r\n i = int(i)\r\n if count == 1:\r\n totalChest += i\r\n count += 1\r\n elif count == 2:\r\n totalBiceps += i\r\n count += 1\r\n elif count == 3:\r\n totalBack += i\r\n count = 1\r\n \r\nmaximum = max(totalBiceps,totalChest,totalBack)\r\n\r\nif (maximum == totalChest):\r\n print(\"chest\")\r\nelif (maximum == totalBiceps):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"import sys\r\nsys.setrecursionlimit(100000000)\r\ninput=lambda:sys.stdin.readline().strip()\r\nwrite=lambda x:sys.stdout.write(str(x)+'\\n')\r\n\r\n# from random import randint\r\n# from copy import deepcopy\r\nfrom collections import deque,Counter\r\n# from heapq import heapify,heappush,heappop\r\n# from bisect import bisect_left,bisect,insort\r\nfrom math import inf,sqrt,gcd,ceil,floor,log,log2,log10,pi\r\n# from functools import cmp_to_key\r\n\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nans=[0]*3\r\nfor i in range(3):\r\n j=i\r\n while j<n:\r\n ans[i]+=a[j]\r\n j+=3\r\nif max(ans)==ans[0]:\r\n print('chest')\r\nelif max(ans)==ans[1]:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=[]\r\ns.append(sum(a[0::3]))\r\ns.append(sum(a[1::3]))\r\ns.append(sum(a[2::3]))\r\nif s.index(max(s))==0:\r\n print('chest')\r\nif s.index(max(s))==1:\r\n print('biceps')\r\nif s.index(max(s))==2:\r\n print('back')",
"pairs = {'chest': 0 , 'biceps': 0 , 'back': 0}\r\nn = int(input())\r\narr=list(map(int, input().split(' ')[:n]))\r\nfor i in range(n):\r\n if(i%3==0):\r\n pairs['chest'] = int(pairs['chest'])+arr[i]\r\n continue\r\n if(i%3==1):\r\n pairs['biceps'] = int(pairs['biceps'])+arr[i]\r\n continue\r\n else:\r\n pairs['back'] = int(pairs['back'])+arr[i]\r\n continue\r\nif(pairs['chest']>pairs['biceps'] and pairs['chest']>pairs['back']):\r\n print(\"chest\")\r\n exit()\r\nif(pairs['biceps']>pairs['chest'] and pairs['biceps']>pairs['back']):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n\r\n",
"n=int(input())\r\nx=list(map(int,input().split()))\r\nn=len(x)\r\nfor i in range(n):\r\n a=sum(x[::3])\r\n b = sum(x[1::3])\r\n c = sum(x[2::3])\r\nif a>b and a>c:\r\n print('chest')\r\nelif b>a and b>c:\r\n print('biceps')\r\nelif c>a and c>b:\r\n print('back')",
"N=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(0,len(l)):\r\n if(i%3==0):\r\n chest+=l[i]\r\n elif(i%3==1):\r\n biceps+=l[i]\r\n elif(i%3==2):\r\n back+=l[i]\r\n\r\nif(chest>biceps and chest>back):\r\n print(\"chest\")\r\nelif(biceps>chest and biceps>back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n\r\n \r\n",
"s = input()\r\narr = [int(i) for i in input().split()]\r\na = sum(arr[::3])\r\nb = sum(arr[1::3])\r\nc = sum(arr[2::3])\r\nd={a:'chest',b:'biceps',c:'back'}\r\nprint(d[max(a,b,c)])",
"n = int(input())\r\nk = list(map(int,input().split()))\r\ng = 0\r\nb = 0\r\nc = 0\r\nfor i in range(len(k)):\r\n if i%3==0:\r\n g+=k[i]\r\n if i%3==1:\r\n b+=k[i]\r\n if i%3==2:\r\n c+=k[i]\r\nif g>b and g>c:\r\n print('chest')\r\nelif b>c and b>g:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\ns=list(map(int,input().split()))\r\nc=sum(s[0::3])\r\nbi=sum(s[1::3])\r\nba=sum(s[2::3])\r\nif c > bi and c > ba:\r\n print(\"chest\")\r\nelif bi > ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))[:n]\r\nsum1=sum2=sum3=0\r\nfor i in range(len(l)):\r\n rem=i%3\r\n if(rem==0):\r\n sum1+=l[i]\r\n elif(rem==1):\r\n sum2+=l[i]\r\n else:\r\n sum3+=l[i]\r\nif(sum1>sum2):\r\n if(sum1>sum3):\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\nelse:\r\n if(sum2>sum3):\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n ",
"# Greg's Workout\r\n# https://codeforces.com/problemset/problem/255/A\r\n\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n#for i in range(n):\r\n# print(a[i], end=\", \")\r\n\r\nfor i in range(n):\r\n if i%3==0: # when i is 0, 3, 6, ...\r\n chest += a[i]\r\n elif i%3==1: # when i is 1, 4, 7, ...\r\n biceps += a[i]\r\n else:\r\n back += a[i]\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n ",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na,b,c=0,0,0\r\nfor i in range(n):\r\n if i%3==0:\r\n a+=l[i]\r\n elif i%3==1:\r\n b+=l[i]\r\n else:\r\n c+=l[i]\r\nif a>=b and a>=c:\r\n print(\"chest\")\r\nelif b>=a and b>=c:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nlist1=list(map(int,input().split(\" \")))\r\nch,ba,bi=0,0,0\r\nfor j in range(n):\r\n if j%3==0:\r\n ch+=list1[j]\r\n elif j%3==1:\r\n ba+=list1[j]\r\n else:\r\n bi+=list1[j]\r\nif ch>ba and ch>bi:\r\n print('chest')\r\nelif ba>ch and ba>bi:\r\n print('biceps')\r\nelse:\r\n print('back')",
"x=input()\ndel x\nb=[int(i) for i in input().split()]\n\ns1,s2,s3= sum(b[::3]) , sum(b[1::3]) , sum(b[2::3] )\n\nif s1 >s2 and s1 > s3:\n print(\"chest\")\n\nif s2 >s1 and s2 > s3:\n print(\"biceps\")\n\nif s3 >s1 and s3 > s2:\n print(\"back\")\n",
"n = int(input())\r\n\r\nrepeat_exercise = [int(i) for i in input().split()]\r\nattempt = [0] * 3\r\n\r\nfor i in range(n):\r\n attempt[i % 3] += repeat_exercise[i]\r\n\r\nif attempt[0] > attempt[1] and attempt[0] > attempt[2]:\r\n print(\"chest\")\r\nelif attempt[1] > attempt[2] and attempt[1] > attempt[0]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input()) \nx = list(map(int, input().split(' ')[:n]))\n\nif n>=1 and n<=20:\n a=x[0::3]\n b=x[1::3]\n c=x[2::3]\n\nd=0\ne=0\nf=0\n\nfor i in a:\n if i>=1 and i<=25:\n d=d+i\nfor i in b:\n if i>=1 and i<=25:\n e=e+i\nfor i in c:\n if i>=1 and i<=25:\n f=f+i\n\nz=max(d,e,f)\n\nif d==z:\n print('chest')\nif e==z:\n print('biceps')\nif f==z:\n print('back')\n \t \t\t \t\t \t \t \t\t \t\t \t\t \t",
"import os, sys, math, cmath, time, collections\nfrom collections import deque, Counter, OrderedDict, defaultdict\nfrom heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace\nfrom math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi\nfrom bisect import bisect_left, bisect_right\nfrom functools import reduce\n\n\n# SOME GENERAL HELPER\ndef input_as_array(): return list(map(int, input().split()))\n\n\ndef debug():\n if os.path.exists('data.in'):\n print(\"**********************\")\n\n\ndef debug2(value):\n if os.path.exists('data.in'):\n print(value)\n\n\nstart_time = time.time()\n\n\ndef solve(A, n):\n ctr = {0:0, 1:0, 2:0}\n for i in range(n):\n ctr[i%3] += A[i]\n ctr = {k:v for k, v in sorted(ctr.items(), key=lambda x:x[1], reverse=True)}\n keys = list(ctr.keys())\n if keys[0] == 0:\n print(\"chest\")\n elif keys[0] == 1:\n print(\"biceps\")\n else:\n print(\"back\")\n\ndef main():\n n = int(input())\n A = input_as_array()\n solve(A, n)\n debug()\n\n\nif __name__ == \"__main__\":\n if os.path.exists('data.in'):\n sys.stdin = open(\"data.in\", \"r\")\n sys.stdout = open(\"data.out\", \"w\")\n\n testcases = 1\n for i in range(testcases):\n main()\n\n # If it's local - Print this O/P\n if os.path.exists('data.in'):\n print(f\"Time Elapsed: {time.time() - start_time} seconds\")\n sys.stdout.close()\n",
"'''\r\nhttps://codeforces.com/problemset/problem/255/A\r\n'''\r\n\r\nn = int(input(\"\"))\r\n\r\nnums = [int(i) for i in input(\"\").split()]\r\n\r\nchest = 0\r\nbicep = 0\r\nback = 0\r\n\r\n\r\nfor i, workout in enumerate(nums):\r\n if i%3==0:\r\n chest += workout\r\n elif i%3==1:\r\n bicep +=workout\r\n else:\r\n back+=workout\r\n\r\nif chest>bicep:\r\n if chest>back:\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\nelse:\r\n if bicep>back:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")",
"n = int(input())\r\nexs = list(map(int, input().split()))\r\n\r\nrips = {\"chest\": 0, \"biceps\": 0, \"back\": 0}\r\nfor i in range(len(exs)):\r\n if i%3 == 0:\r\n rips[\"chest\"]+=exs[i]\r\n elif i%3 == 1:\r\n rips[\"biceps\"]+=exs[i]\r\n else:\r\n rips[\"back\"]+=exs[i]\r\n \r\nprint(max(*rips.items(), key=lambda x: x[1])[0])\r\n",
"import sys\r\ninput = sys.stdin.readline\r\nn= int(input())\r\nlt= list(map(int,input().split()))\r\nchest=[lt[i] for i in range(0,n,3)]\r\nbiceps=[lt[i] for i in range(1,n,3)]\r\nback=[lt[i] for i in range(2,n,3)]\r\ntotal=list()\r\ntotal.append(sum(chest))\r\ntotal.append(sum(biceps))\r\ntotal.append(sum(back))\r\nif total.index(max(total)) == 0:\r\n print('chest')\r\nelif total.index(max(total)) == 1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"def int_lst_input():\n return [int(val) for val in input().split(' ')]\n\ndef int_input():\n return int(input())\n\ndef solve():\n n = int_input()\n a = int_lst_input()\n\n ch, bi, ba = 0, 0, 0\n\n for i in range(0, n):\n if i % 3 == 0:\n ch += a[i]\n elif i % 3 == 1:\n bi += a[i]\n elif i % 3 == 2:\n ba += a[i]\n\n if ch > bi and ch > ba:\n print('chest')\n elif bi > ch and bi > ba:\n print('biceps')\n elif ba > ch and ba > bi:\n print('back')\n\nif __name__ == '__main__':\n solve()\n",
"n=int(input())\r\nmat=list(map(int,input().split()))\r\nchest=0\r\nbicep=0\r\nback=0\r\nfor i in range(n):\r\n if i%3==0:\r\n chest=chest+mat[i]\r\n elif i%3==1:\r\n bicep=bicep+mat[i]\r\n else:\r\n back=back+mat[i]\r\nif(chest>bicep and chest>back):\r\n print(\"chest\")\r\nelif(bicep>chest and bicep>back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"def f():\r\n n=int(input())\r\n a=list(map(int,input().strip().split(' ')))\r\n ch=0\r\n bi=0\r\n ba=0\r\n for i in range(0,n,3):\r\n ch+=a[i]\r\n if i+1<n:\r\n bi+=a[i+1]\r\n if i+2<n:\r\n ba+=a[i+2]\r\n\r\n m=max(ch,bi,ba)\r\n if m==ch:\r\n print('chest')\r\n elif m==bi:\r\n print('biceps')\r\n else:\r\n print('back')\r\n return\r\n\r\nt=1\r\nwhile t:\r\n f()\r\n t-=1\r\n \r\n",
"n = int(input())\r\nl = [int(x) for x in input().split()]\r\nch = sum([l[i] for i in range(0,n,3)])\r\nbi = sum([l[i] for i in range(1,n,3)])\r\nba = sum([l[i] for i in range(2,n,3)])\r\nm = [ch,bi,ba]\r\nmaxx = max(m)\r\nif ch == maxx:\r\n print(\"chest\")\r\nelif bi == maxx:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n# c b back\r\nbir=0\r\niki=0\r\nuc=0\r\nfor i in range(0,len(l),3):\r\n try:\r\n bir+=l[i]\r\n iki+=l[i+1]\r\n uc+=l[i+2]\r\n except:\r\n break\r\ncv=max(bir,iki,uc)\r\nif cv==bir:\r\n aa=\"chest\"\r\nelif cv==iki:\r\n aa=\"biceps\"\r\nelif cv==uc:\r\n aa=\"back\"\r\nprint(aa)\r\n",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\nresult = {0:0, 1:0, 2:0}\r\nj = 0\r\n\r\nfor i in nums:\r\n result[j] += i\r\n\r\n if j == 2:\r\n j = -1\r\n j += 1\r\n\r\nresult = max(result, key=result.get)\r\n\r\nif result == 0:\r\n print(\"chest\")\r\nelif result == 1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nres=[0]*3\r\nfor i in range(n):\r\n res[i%3]+=l[i]\r\nre=res.index(max(res))\r\nif re==0:\r\n print('chest')\r\nelif re==1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\nv = list(map(int, input().split()))\na = ['chest', 'biceps', 'back']\nb= [0,0,0]\nfor i in range(n):\n b[i%3] += v[i]\nprint(a[b.index(max(b))])\n \t\t\t \t \t\t \t \t\t \t\t \t\t\t \t \t",
"n = int(input())\nw = input()\nw = w.split(\" \")\nl = []\nfor i in w:\n i = int(i)\n l.append(i)\ni_c = []\ni_b = []\ni_back = []\ns_1 = 0\ns_2 = 1\ns_3 = 2\nf = []\ns_c = 0\ns_b = 0\ns_ba = 0\nwhile s_1 <= len(l)-1:\n i_c.append(s_1)\n s_1 += 3\nwhile s_2 <= len(l)-1:\n i_b.append(s_2)\n s_2 += 3\nwhile s_3 <= len(l)-1:\n i_back.append(s_3)\n s_3 += 3\nfor m in i_c:\n s_c += l[m]\nf.append(s_c)\nfor n in i_b:\n s_b += l[n]\nf.append(s_b)\nfor o in i_back:\n s_ba += l[o]\nf.append(s_ba)\nmaxy = max(f)\nif maxy == s_c:\n print(\"chest\")\nelif maxy == s_b:\n print(\"biceps\")\nelif maxy == s_ba:\n print(\"back\")\n \t \t\t \t \t \t\t \t\t\t\t \t\t \t",
"# import sys\n# sys.stdin=open('input.in','r')\n# sys.stdout=open('output.out','w')\ns=int(input())\nl=list(map(int,input().strip().split()[:s]))\nbicep=chest=back=0\n\nif len(l)%3!=0:\n\tfor x in range(3-(len(l)%3)):\n\t\tl.append(0)\nx=0\nwhile x<len(l):\n\tchest+=l[x]\n\tbicep+=l[x+1]\n\tback+=l[x+2]\n\tx+=3\t\nif max(chest,bicep,back)==chest:\n\tprint('chest')\nelif max(chest,bicep,back)==bicep:\n\tprint('biceps')\nelse:\n\tprint('back')",
"from sys import stdin,stdout\r\n\r\nst=lambda:list(stdin.readline().strip())\r\nli=lambda:list(map(int,stdin.readline().split()))\r\nmp=lambda:map(int,stdin.readline().split())\r\ninp=lambda:int(stdin.readline())\r\npr=lambda n: stdout.write(str(n)+\"\\n\")\r\n\r\nmod=1000000007\r\n\r\nn=inp()\r\nl=li()\r\nc,b,bi=0,0,0\r\nfor i in range(n):\r\n if i%3==0:\r\n c+=l[i]\r\n elif i%3==1:\r\n bi+=l[i]\r\n else:\r\n b+=l[i]\r\nx=max(c,b,bi)\r\nif x==c:\r\n print('chest')\r\nelif x==b:\r\n pr('back')\r\nelse:\r\n print('biceps')\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nres = []\r\n\r\nfor i in range(3):\r\n temp = 0\r\n j = i\r\n \r\n while(j < n):\r\n temp += arr[j]\r\n j += 3\r\n\r\n res.append(temp)\r\n\r\nif(res[0] > res[1] and res[0] > res[2]):\r\n print(\"chest\")\r\nelse:\r\n if(res[1] > res[2]):\r\n print(\"biceps\")\r\n else:\r\n print(\"back\") ",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = [0] * 3\r\nfor i in range(3):\r\n b[i] = sum(map(lambda j: a[j], range(i, n, 3)))\r\nans = b.index(max(b))\r\ns = ['chest', 'biceps', 'back']\r\nprint(s[ans])\r\n",
"n = int(input())\na = list(map(int, input().split()))\ngr = 0\nbi = 0\nsp = 0\nif n == 1:\n print('chest')\nelif n == 2:\n for i in range(0, len(a), 2):\n gr += a[i]\n bi += a[i + 1]\nelif n >= 3:\n for i in range(0, len(a), 3):\n if abs(n - i) > 2:\n gr += a[i]\n bi += a[i + 1]\n sp += a[i + 2]\n elif abs(n - i) == 2:\n gr += a[i]\n bi += a[i + 1]\n elif abs(n - i) == 1:\n gr += a[i]\n \nif bi > gr and bi > sp:\n print('biceps')\nelif gr > bi and gr > sp:\n print('chest')\nelif sp > bi and sp > gr:\n print('back')\n\n\n\n\n",
"number = int(input())\r\narr_ex = list(map(int , input().split()))\r\narr_co = [\r\n {'counter' : 0 , \"name\" : \"chest\"} ,\r\n {'counter' : 0 , \"name\" : \"biceps\"} ,\r\n {'counter' : 0 , \"name\" : \"back\"}\r\n]\r\nfor i in range(0 , number):\r\n arr_co[i%3]['counter'] += arr_ex[i]\r\ndef re(key):\r\n return key['counter']\r\narr_co.sort(key=re , reverse=True)\r\nprint(arr_co[0]['name'])",
"n=int(input())\r\nlst = [int(i) for i in input().split()]\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(0,n,3):\r\n chest = chest+lst[i]\r\nfor i in range(1,n,3):\r\n biceps = biceps+lst[i]\r\nfor i in range(2,n,3):\r\n back = back+lst[i]\r\nif chest>back and chest>biceps:\r\n print(\"chest\")\r\nif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nif back>chest and back>biceps:\r\n print(\"back\")",
"n=int(input())\r\nchest=0\r\nbiceps=0\r\nback=0\r\nx=list(map(int,input().split()))\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=x[i]\r\n elif i%3==1:\r\n biceps+=x[i]\r\n elif i%3==2:\r\n back+=x[i]\r\nxx=max(chest,max(biceps, back))\r\nprint(\"chest\" if xx==chest else \"biceps\" if xx==biceps else \"back\")",
"n=int(input())\r\na=input()\r\na1=a.split()\r\nfor i in range(n):\r\n a1[i]=int(a1[i])\r\nc=0 #chest\r\nd=0 #biceps \r\nb=0 #back\r\nfor i in range(n):\r\n if i%3==0: c=c+a1[i]\r\n elif i%3==1: d=d+a1[i]\r\n else: b=b+a1[i]\r\nif max(c,d,b)==c: print(\"chest\")\r\nelif max(c,d,b)==d: print(\"biceps\")\r\nelse: print(\"back\")\r\n",
"# cf 255 A 800\nn = int(input())\nA = [*map(int, input().split())]\nc, bi, ba = 0, 0, 0\n\nfor i in range(len(A)):\n if i % 3 == 0:\n c += A[i % n]\n elif i % 3 == 1:\n bi += A[i % n]\n elif i % 3 == 2:\n ba += A[i % n]\n\nif c > bi and c > ba:\n print(\"chest\")\nelif bi > c and bi > ba:\n print(\"biceps\")\nelif ba > c and ba > bi:\n print(\"back\")\n",
"if __name__ == '__main__':\r\n input()\r\n aa = list(map(int, input().split()))\r\n counts = [(val, sum(aa[key::3])) for key, val in enumerate(['chest', 'biceps', 'back'])]\r\n print(max(counts, key=lambda x: x[1])[0])\r\n",
"n = int(input())\r\nx = [int(x) for x in input().split()]\r\ny = []\r\n\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor i in range(0,len(x),3):\r\n chest+= x[i]\r\n if i + 1 < len(x):\r\n biceps+= x[i+1]\r\n if i + 2 < len(x):\r\n back += x[i+2]\r\n\r\nmaxx = max(chest, biceps, back)\r\nif maxx == chest:\r\n print(\"chest\")\r\nelif maxx == biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\nlist1 = list(map(int,input().split()))\nch, bi, ba = [0]*3\nfor i in range(0,len(list1),3):\n ch+=list1[i]\nfor i in range(1,len(list1),3):\n bi+=list1[i]\nfor i in range(2,len(list1),3):\n ba+=list1[i]\nif ch > bi and ch > ba:\n print(\"chest\")\nelif bi > ch and bi > ba:\n print(\"biceps\")\nelse:\n print(\"back\")\n \t\t\t\t\t \t \t\t \t \t\t \t\t",
"# Online Python compiler (interpreter) to run Python online.\r\n# Write Python 3 code in this online editor and run it.\r\nn= int(input())\r\nl=list(map(int,input().split()))\r\ns=[0,0,0]\r\nfor i in range(n):\r\n s[i%3]+=l[i]\r\n \r\nm=max(s)\r\nif s[0]==m:\r\n print('chest')\r\nelif s[1]==m:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"a=0;b=0;c=0\r\nn=int(input())\r\nlst=list(map(int,input().split()))\r\nfor i in range(n):\r\n\tif (i-3)%3==0:\r\n\t\ta+=lst[i]\r\n\tif (i-1)%3==0:\r\n\t\tb+=lst[i]\r\n\tif (i+1)%3==0:\r\n\t\tc+=lst[i]\r\nif max(a,b,c)==a:\r\n\tprint('chest')\r\nelif max(a,b,c)==b:\r\n\tprint('biceps')\r\nelse:\r\n\tprint('back')",
"t=int(input())\r\nl=[int(i) for i in input().split()]\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(t):\r\n if i%3==0:\r\n a+=l[i]\r\n elif i%3==1:\r\n b+=l[i]\r\n else:\r\n c+=l[i]\r\nm=max(a,b,c)\r\nif m==a:\r\n print(\"chest\")\r\nelif m==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"import math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nimport functools\r\nfrom operator import itemgetter, attrgetter\r\nfrom collections import Counter\r\n\r\nif __name__ == '__main__':\r\n Y = lambda: list(map(int, input().split()))\r\n P = lambda: map(int, input().split())\r\n N = lambda: int(input())\r\n\r\n n = N()\r\n a = Y()\r\n p, v, t = 0, 0, 0\r\n\r\n for i in range(n):\r\n if i % 3 == 0:\r\n p += a[i]\r\n elif i % 3 == 1:\r\n v += a[i]\r\n else:\r\n t += a[i]\r\n if p > v and p > t:\r\n print(\"chest\")\r\n elif v > p and v > t:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")",
"x=int(input())\r\ny=list(map(int,input().split()))\r\nd={\"chest\":0,\"biceps\":0 ,\"back\":0}\r\nfor i,j in enumerate(y):\r\n if(i%3==0):\r\n d['chest']+=j\r\n elif(i%3==1):\r\n d['biceps']+=j\r\n else:\r\n d[\"back\"]+=j\r\nc=list(d.values())\r\nd=list(k for k,j in d.items() if j==max(c))\r\nprint(*d,sep='')",
"n = int(input())\r\nA = list(map(int, input().split(' ')))\r\nbiceps = 0\r\nback = 0\r\nchest = 0\r\n\r\nfor i in range(0,n,3):\r\n chest += A[i]\r\n\r\nfor j in range(1,n,3):\r\n biceps += A[j]\r\n\r\nfor k in range(2,n,3):\r\n back += A[k]\r\n\r\nif max(chest, biceps, back)==chest:\r\n print('chest')\r\n \r\nelif max(chest, biceps, back)==biceps:\r\n print('biceps')\r\n \r\nelse :\r\n print('back')\r\n",
"n = int(input())\r\nls = list(map(int,input().split()))\r\nchest =0\r\nbiceps =0\r\nback =0\r\nfor i in range(0,n,3):\r\n chest+=ls[i]\r\nfor j in range(1,n,3):\r\n biceps+=ls[j]\r\nfor k in range(2,n,3):\r\n back+=ls[k]\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"a = int(input())\r\nlist2=[]\r\nlist2=map(int,input().split())\r\nch=0\r\nbi=0\r\nba=0\r\nlist1=[]\r\nif 1 <= a <= 20 :\r\n\tfor i in list2 :\r\n\t\tlist1.append(i)\r\n\twhile True :\r\n\t\tif len(list1) == 0:\r\n\t\t\tbreak\r\n\t\telse:\r\n\t\t\tch += int(list1[0])\r\n\t\t\tlist1.pop(0)\r\n\t\t\tif len(list1) == 0 :\r\n\t\t\t\tbreak\r\n\t\t\telse:\r\n\t\t\t\tbi += int(list1[0])\r\n\t\t\t\tlist1.pop(0)\r\n\t\t\t\tif len(list1) == 0 :\r\n\t\t\t\t\tbreak\r\n\t\t\t\telse:\r\n\t\t\t\t\tba += int(list1[0])\r\n\t\t\t\t\tlist1.pop(0)\r\n\tif bi >= ba and bi >= ch :\r\n\t\tprint(\"biceps\")\r\n\telif ba >= bi and ba >= ch :\r\n\t\tprint(\"back\")\r\n\telif ch >= ba and ch > bi :\r\n\t\tprint(\"chest\")",
"n=int(input())\r\na=list(map(int, input().split()))\r\ni=0\r\nch=0\r\nbi=0\r\nb=0\r\nif int(n%3)==1:\r\n a.append(0)\r\n a.append(0)\r\n n=len(a)\r\nif int(n%3)==2:\r\n a.append(0)\r\n n=len(a)\r\nwhile i<n and n>=3:\r\n ch+=a[i]\r\n bi+=a[i+1]\r\n b+=a[i+2]\r\n i+=3\r\nm = max(ch, bi, b)\r\nif m == ch:\r\n print('chest')\r\nelif m == bi:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nv=n\r\nl=[]\r\nch=bk=pc=0\r\nl.extend(map(int,input().split()))\r\nfor i in range(1,n+1):\r\n if i%3 ==1:\r\n ch+=l[i-1]\r\n elif i%3 ==2:\r\n pc+=l[i-1]\r\n elif i%3==0:\r\n bk+=l[i-1]\r\nif max(ch,pc,bk) == ch:\r\n print(\"chest\")\r\nelif max(ch,pc,bk) == pc:\r\n print(\"biceps\")\r\nelse :\r\n print(\"back\")",
"n = int(input())\nworkout_num = input().split()\nchest = biceps = back = 0\nfor i in range(n):\n if i%3 == 0:\n chest += int(workout_num[i])\n elif i%3 == 1: \n biceps += int(workout_num[i])\n else:\n back += int(workout_num[i])\n\nif chest >= biceps and chest >= back:\n print(\"chest\")\nelif biceps >= back and biceps >= chest:\n print(\"biceps\")\nelse:\n print(\"back\")\n\n\n\t \t \t\t\t\t \t \t \t\t\t \t \t",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nback=sum(b[2::3])\r\nchest=sum(b[::3])\r\nbic=sum(b[1::3])\r\nc=max(back,chest,bic)\r\nif back==c:\r\n print('back')\r\nelif chest==c:\r\n print('chest')\r\nelse:\r\n print('biceps')\r\n",
"n = int(input())\narray = list(map(int, input().split()))\n\nc, bi, ba = 0, 0, 0\n\ni = 0\npos = 0\nwhile len(array) > 0:\n if pos == 0:\n c += array[i]\n del array[i]\n pos = 1\n elif pos == 1:\n bi += array[i]\n del array[i]\n pos = 2\n elif pos == 2:\n ba += array[i]\n del array[i]\n pos = 0\n\nmaxi = max(c, bi, ba)\nif c == maxi:\n print('chest')\nelif bi == maxi:\n print('biceps')\nelse:\n print('back')\n",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nb = 0\r\nfor i in range(0, n, 3):\r\n b += a[i]\r\nc = 0\r\nfor i in range(1, n, 3):\r\n c += a[i]\r\nd = 0\r\nfor i in range(2, n, 3):\r\n d += a[i]\r\nx = max(b, c, d)\r\nif x == b:\r\n print('chest')\r\nelif x == c:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"def main():\r\n n = int(input().strip())\r\n es = list(map(int, input().split()))\r\n\r\n biceps = 0\r\n chest = 0\r\n back = 0\r\n for i in range(len(es)):\r\n if i % 3 == 0:\r\n chest += es[i]\r\n elif i % 3 == 1:\r\n biceps += es[i]\r\n elif i % 3 == 2:\r\n back += es[i]\r\n\r\n if biceps >= chest and biceps >= back:\r\n print(\"biceps\")\r\n elif chest >= biceps and chest >= back:\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"a = int(input())\r\nq = list(map(int, input().split(' ')))\r\ns = 1\r\nw = 0\r\nd = 0\r\ne = 0\r\nfor i in q:\r\n if s == 1:\r\n w += i\r\n elif s == 2:\r\n d += i\r\n else:\r\n e += i\r\n s += 1\r\n if s == 4:\r\n s = 1\r\nif w == max(w, d, e):\r\n print(\"chest\")\r\nelif d == max(w, e, d):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nk=1\r\ns1=s2=s3=0\r\nfor el in a:\r\n if k==1:\r\n s1+=el\r\n k+=1\r\n elif k==2:\r\n s2+=el\r\n k+=1\r\n else:\r\n s3+=el\r\n k=1\r\nif s1>s2 and s1>s3:\r\n print('chest')\r\nelif s2>s1 and s2>s3:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nexc=list(map(int,input().split()))\r\ncount_chest=0\r\ncount_biceps=0\r\ncount_back=0\r\nfor i in range(1,n+1):\r\n if (i)%3==0:\r\n count_back+=exc[i-1]\r\n if (i)%3==1:\r\n count_chest+=exc[i-1]\r\n if (i)%3==2:\r\n count_biceps+=exc[i-1]\r\nmax_count=max(count_chest,count_back,count_biceps,)\r\nif count_chest==max_count:\r\n print('chest')\r\nelif count_biceps==max_count:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n\r\n",
"input()\na = list(map(int, input().split()))\nx = {\"chest\": sum(a[::3]), \"biceps\": sum(a[1::3]), \"back\": sum(a[2::3])}\nprint(max(x, key=x.get))\n",
"input()\na=[*map(int,input().split())]\nprint(['chest','biceps','back'][max(0,1,2,key=lambda i: sum(a[i::3]))])",
"t=int(input())\r\nx=list(map(int,input().split()))\r\nch=0\r\nbi=0\r\nba=0\r\nfor i in range(0,len(x),3):\r\n ch+=x[i]\r\nfor i in range(1,len(x),3):\r\n bi+=x[i]\r\nfor i in range(2,len(x),3):\r\n ba+=x[i]\r\nm=max(ch,bi,ba)\r\nif m==ch:\r\n print(\"chest\")\r\nelif m==bi:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\nli=list(map(int,input().split()))\r\nans=[0]*3\r\nfor i in range(n):\r\n if i%3==0:\r\n ans[0]+=li[i]\r\n elif i%3==1:\r\n ans[1]+=li[i]\r\n elif i%3==2:\r\n ans[2]+=li[i]\r\nmx=max(ans)\r\nind=ans.index(mx)\r\nif ind==0:\r\n print(\"chest\")\r\nelif ind==1:\r\n print(\"biceps\")\r\nelif ind==2:\r\n print(\"back\")",
"n = int(input())\r\na = list(map(int , input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(0 , len(a) , 3):\r\n chest += a[i]\r\n \r\nfor i in range(1 , len(a) , 3):\r\n biceps += a[i]\r\n \r\nfor i in range(2 , len(a) , 3):\r\n back += a[i]\r\n\r\nif chest > biceps and chest > back : \r\n print('chest')\r\nelif back > biceps and back > chest:\r\n print('back')\r\nelse:\r\n print('biceps')\r\n ",
"n=int(input())\r\na=list(map(int,input().split()))\r\nost=n%3\r\nif ost==1 or ost==2: x=a[(n-ost)-1+1]\r\nelse:x=0\r\nif ost==2: y=a[(n-ost)-1+2]\r\nelse:y=0\r\nz=0\r\nfor i in range((n-ost)//3):\r\n x+=a[3*i]\r\n y+=a[1+3*i]\r\n z+=a[2+3*i]\r\nif x==max(x,y,z): print('chest')\r\nelif y==max(x,y,z): print('biceps')\r\nelif z==max(x,y,z): print('back')",
"import sys, math\ninput = sys.stdin.readline\n\nn = int(input())\na = [int(x) for x in input().split()]\nd = {0: \"chest\", 1: \"biceps\", 2: \"back\"}\nres = [sum(a[0:n:3]), sum(a[1:n:3]), sum(a[2:n:3])]\nprint(d[res.index(max(res))])\n\t \t \t \t \t \t \t\t\t \t\t \t",
"podhodi = int(input())\r\nuprazhnenia = list(map(int, input().split()))\r\n\r\nturn = biceps = back = chest = 0\r\n\r\nfor i in range(podhodi):\r\n turn += 1\r\n if turn == 1:\r\n chest += uprazhnenia[i]\r\n elif turn == 2:\r\n biceps += uprazhnenia[i]\r\n else:\r\n back += uprazhnenia[i]\r\n turn = 0\r\n\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps > chest and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"def ii(): return int(input())\r\ndef mi(): return map(int, input().split())\r\ndef li(): return list(mi())\r\n\r\nn = ii()\r\na = li()\r\nc = b = ba = 0\r\nfor i in range(n):\r\n if i%3 == 0:\r\n c+=a[i]\r\n elif i%3 == 1:\r\n b+=a[i]\r\n else:\r\n ba+=a[i]\r\nif c > b and c > ba:\r\n print(\"chest\")\r\nelif b > c and b > ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nw = [int(i) for i in input().split()]\r\na, b, c = 0, 0, 0\r\nfor i in range(1, n+1):\r\n if i % 3 == 1:\r\n a += w[i-1]\r\n elif i % 3 == 2:\r\n b += w[i-1]\r\n else:\r\n c += w[i-1]\r\nif a == max(a, b, c):\r\n print(\"chest\")\r\nelif b == max(a, b, c):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"#!/usr/bin/env python\r\n\r\nimport math\r\nimport sys\r\nimport itertools\r\nimport fractions\r\n\r\nif __name__ == '__main__':\r\n wtf = sys.stdin.read()\r\n wtf = wtf.strip().split('\\n')\r\n n = int(wtf[0])\r\n A = list(map(int, wtf[1].split()))\r\n M = [0, 0, 0]\r\n i = 0\r\n for a in A:\r\n if i == 3:\r\n i = 0\r\n M[i] += a\r\n i += 1\r\n Mds = {0:'chest', 1:'biceps', 2:'back'}\r\n print(Mds[M.index(max(M))])\r\n",
"n = int(input())\r\narr =list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(n+2//3):\r\n j = 3*i\r\n k = 3*i+1\r\n l = 3*i+2\r\n if j<n:\r\n chest+=arr[j]\r\n if k<n:\r\n biceps+=arr[k]\r\n if l<n:\r\n back+=arr[l]\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nx = [int(x) for x in input().split()]\r\nm1 = 0\r\nm2 = 0\r\nm3 = 0\r\nfor i in range(len(x)):\r\n if(i%3==0):\r\n m1+=x[i]\r\n elif(i%3==1):\r\n m2+=x[i]\r\n else:\r\n m3+=x[i]\r\nif(max(m1,m2,m3)==m1):\r\n print('chest')\r\nelif(max(m1,m2,m3)==m2):\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\narr=list(map(int,input().split()))\r\na=b=c=0\r\nfor i in range(n):\r\n if i%3==0:\r\n a+=arr[i]\r\n elif i%3==1:\r\n b+=arr[i]\r\n else:\r\n c+=arr[i]\r\nif max(a,b,c)==a:\r\n print(\"chest\")\r\nelif max(a,b,c)==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=[]\r\na[0:n]=map(int,input().split())\r\nc=0\r\nbi=0\r\nbk=0\r\nfor i in range(1,n+1):\r\n if i%3==1:\r\n c+=a[i-1]\r\n elif i%3==2:\r\n bi+=a[i-1]\r\n else:\r\n bk+=a[i-1]\r\nif c>bi and c>bk:\r\n print(\"chest\")\r\nelif bi>c and bi>bk:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n=int(input())\r\na=list(map(int, input().split()))\r\nchest=0\r\nback=0\r\nbiceps=0\r\nfor i in range(n):\r\n if (i)%3==0:\r\n chest=chest+a[i]\r\n elif (i)%3==1:\r\n biceps=biceps+a[i]\r\n elif (i)%3==2:\r\n back=back+a[i]\r\nif max(chest, biceps, back)==chest:\r\n print(\"chest\")\r\nelif max(chest, biceps, back)==biceps:\r\n print(\"biceps\")\r\nelif max(chest, biceps, back)==back:\r\n print(\"back\")",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nchest = bicep = back = 0\r\nfor i in range(len(l)):\r\n if i%3 == 0:\r\n chest += l[i]\r\n if i%3 == 1:\r\n bicep += l[i]\r\n if i%3 == 2:\r\n back += l[i]\r\n\r\nm = max(chest,bicep,back)\r\nif chest == m:\r\n print('chest')\r\nelif bicep == m:\r\n print('biceps')\r\nelse:\r\n print('back')",
"from sys import stdin\r\n_input = stdin.readline\r\n_int, _max = int, max\r\ndef solution():\r\n n = _int(_input())\r\n arr = [_int(i) for i in _input().split()]\r\n ans = [0]*3\r\n index = 0\r\n for i in arr:\r\n ans[index%3] += i\r\n index += 1\r\n ans_word = [\"chest\",\"biceps\",\"back\"]\r\n print(ans_word[ans.index(_max(ans))])\r\n\r\nsolution()",
"n=input()\r\ns=list(map(int,input().split()))\r\nch=sum(s[::3])\r\nbi=sum(s[1::3])\r\nba=sum(s[2::3])\r\nif max([ch,bi,ba])==ch:\r\n print(\"chest\")\r\nelif max([ch,bi,ba])==ba:\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")",
"input()\r\na = list(map(int, input().split()))\r\nch = 0\r\nbi = 0\r\nba = 0\r\nfor i in range(0, len(a), 3):\r\n ch += a[i]\r\nfor j in range(1, len(a), 3):\r\n bi += a[j]\r\nfor k in range(2, len(a), 3):\r\n ba += a[k]\r\nif max(ch,bi,ba) == ch:print(\"chest\")\r\nelif max(ch,bi,ba) == bi:print(\"biceps\")\r\nelse:print(\"back\")",
"n = int(input())\r\nx = list(map(int, input() .split()))\r\ni = 0\r\nc,bi,ba = 0,0,0\r\nwhile True:\r\n if i < n:\r\n c = c +x[i]\r\n else:\r\n break\r\n if i + 1 < n:\r\n bi = bi + x[i+1]\r\n else:\r\n break\r\n if i + 2 < n :\r\n ba = ba + x[i+2]\r\n else:\r\n break\r\n i+=3\r\nt = max(c,bi,ba)\r\nif t == c:\r\n print('chest')\r\nelif t == bi:\r\n print('biceps')\r\nelse:\r\n print('back')",
"list1=[0,0,0]\n\nn=int(input())\nt=input().split(' ')\n\ncount=0\nx=0\nwhile x<n:\n if count==3:\n count=0\n list1[count]+=int(t[x])\n count+=1\n x+=1\nif list1.index(max(list1))==0:\n print('chest')\n \nelif list1.index(max(list1))==1:\n print('biceps')\nelif list1.index(max(list1))==2:\n print('back')\n\t\t \t\t\t \t \t\t \t \t\t\t\t\t\t\t\t\t \t\t",
"n = int(input())\r\na = input().split()\r\n\r\nch = int(0)\r\nbi = int(0)\r\nba = int(0)\r\n\r\ncount = int(1)\r\nfor i in range(n):\r\n if count == 1:\r\n ch+=int(a[i])\r\n if count == 2:\r\n bi+=int(a[i])\r\n if count == 3:\r\n ba+=int(a[i])\r\n count+=1\r\n if(count==4):\r\n count = 1\r\nif ch>bi and ch>ba:\r\n print(\"chest\")\r\nelif bi>ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n \r\n",
"def solve(l):\n chest = 0\n biceps = 0\n back = 0\n i = 0\n while i < len(l):\n chest += l[i]\n i += 3\n i=1\n while i < len(l):\n biceps += l[i]\n i += 3\n i=2\n while i < len(l):\n back += l[i]\n i += 3\n q = [(chest,\"chest\"), (biceps, \"biceps\"), (back,\"back\") ]\n q.sort()\n return q[2][1]\n\ninput()\nl=list(map(int, input().split(\" \")))\nprint (solve(l))\n",
"x = int(input())\r\ntrains = list(map(int,input().split()))\r\nwork = \"chest\"\r\nchest = 0\r\nbiceb = 0\r\nback = 0\r\nfor i in trains:\r\n if work == \"chest\":\r\n chest+=i\r\n work=\"biceb\"\r\n elif work==\"biceb\":\r\n biceb+=i\r\n work=\"back\"\r\n elif work==\"back\":\r\n back+=i\r\n work=\"chest\"\r\nif chest>biceb and chest>back:\r\n print(\"chest\")\r\nif biceb>chest and biceb>back:\r\n print(\"biceps\")\r\nif back>chest and back>biceb:\r\n print(\"back\")",
"input()\r\na, out, s = {0: 0, 1: 0, 2: 0}, ['chest', 'biceps', 'back'], list(map(int, input().split()))\r\nfor i in range(len(s)):\r\n a[i % 3] += s[i]\r\nprint(out[max(a, key= a.get)])",
"#l = list(map(int, input().strip().split()))[:n]\r\nc, bi, b = 0, 0, 0\r\nn = input()\r\nn = int(n)\r\nl = list(map(int, input().strip().split()))[:n]\r\ni, j, k = 0, 1, 2\r\nwhile i < n:\r\n c += l[i]\r\n i += 3\r\nwhile j < n:\r\n bi += l[j]\r\n j += 3\r\nwhile k < n:\r\n b += l[k]\r\n k += 3\r\n\r\nmx = max(c, bi, b)\r\nif mx == c:\r\n print(\"chest\\n\")\r\nelif mx == bi:\r\n print(\"biceps\\n\")\r\nelif mx == b:\r\n print(\"back\\n\")\r\n",
"t=int(input())\ne=list(map(int,input().split()))\nsets=[0,0,0]\nadd=len(e)%3\nadd=3-add\nfor i in range(add):\n e.append(0)\n\ni=0\nwhile i<len(e):\n sets[0]+=e[i]\n sets[1]+=e[i+1]\n sets[2]+=e[i+2]\n\n i+=3\n\nmax=max(sets)\nif max==sets[0]:\n print('chest')\nelif max==sets[1]:\n print('biceps')\nelse:\n print('back')\n\t \t \t\t\t \t \t \t \t \t \t",
"n = int(input())\r\npodhod = list(map(int, input('').split()))\r\nchest, biceps, back = 0, 0, 0\r\nfor i in range(len(podhod)):\r\n wrewer = (i + 1) % 3\r\n if (i + 1) % 3 == 1:\r\n chest += podhod[i]\r\n elif (i + 1) % 3 == 2:\r\n biceps += podhod[i]\r\n elif (i + 1) % 3 == 0:\r\n back += podhod[i]\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps> chest and biceps > back:\r\n print('biceps')\r\nelif back > chest and back > biceps:\r\n print('back')",
"n = input()\r\nl = list(map(int,input().split()))\r\nll = [0,0,0]\r\nfor i in range(len(l)):\r\n ll[i%3]+=(l[i])\r\nprint('cbbhiaeccsektp s'[ll.index(max(ll))::3])",
"n=int(input())\r\nl=list(map(int,input().strip().split()))\r\nk=[]\r\ni=0\r\nwhile(i<len(l)):\r\n if(i+3<len(l)):\r\n k.append(list(l[i:i+3]))\r\n else:\r\n k.append(list(l[i:]))\r\n d=3-len(k[-1])\r\n for j in range(d):\r\n k[-1].append(0)\r\n i=i+3\r\nstrong=[0,0,0]\r\nfor i in k:\r\n for j in range(3):\r\n strong[j]+=i[j]\r\nma=max(strong)\r\nif(strong.index(ma)==0):\r\n print(\"chest\")\r\nelif(strong.index(ma)==1):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na,b,c=0,0,0\r\nfor i in range(n):\r\n if(i%3==0):\r\n a=a+l[i]\r\n if(i%3==1):\r\n b=b+l[i]\r\n if(i%3==2):\r\n c=c+l[i]\r\np=max(a,b,c) \r\nif(p==a):\r\n print(\"chest\")\r\nelif(p==b):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n ",
"n=int(input())\r\nl=list(map(int, input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\n\r\nfor i in range(n):\r\n if i==0 or i==3 or i==6 or i==9 or i==12 or i==15 or i==18:\r\n chest+=l[i]\r\n elif i==1 or i==4 or i==7 or i==10 or i==13 or i==16 or i==19:\r\n biceps+=l[i]\r\n elif i==2 or i==5 or i==8 or i==11 or i==14 or i==17 or i==20:\r\n back+=l[i]\r\nif chest> biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>back and biceps>chest:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nexercise = [0, 0, 0]\r\n\r\ni = 0\r\nj = 0\r\nwhile i < n:\r\n exercise[j] += a[i]\r\n i += 1\r\n j += 1\r\n if j == 3:\r\n j = 0\r\n\r\nm = max(exercise)\r\n\r\nif m == exercise[0]:\r\n print(\"chest\")\r\nelif m == exercise[1]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"a = int(input()) #7\r\nb = input()\r\nb = b.split()\r\nb = b[:a] # 5 1 10 1 4 12 3\r\n\r\ntotal = [0, 0, 0]\r\n\r\nx = 0\r\nfor i in b:\r\n i = int(i)\r\n b[x] = i\r\n x+=1\r\n\r\n#9 5 22\r\nq = 0\r\nfor j in range(len(b)):\r\n if(q < len(b)):\r\n total[0] = total[0] + b[q]\r\n q += 3\r\n else:\r\n break\r\nw = 1\r\nfor j in range(len(b)):\r\n if(w < len(b)):\r\n total[1] = total[1] + b[w]\r\n w += 3\r\n else:\r\n break \r\n\r\ne = 2\r\nfor j in range(len(b)):\r\n if(e < len(b)):\r\n total[2] = total[2] + b[e]\r\n e += 3 \r\n else:\r\n break \r\n\r\n# print(total)\r\nif(total[0] == max(total)):\r\n print(\"chest\")\r\nelif(total[1] == max(total)):\r\n print(\"biceps\")\r\nelif(total[2] == max(total)):\r\n print(\"back\")\r\n",
"input()\r\na=[int(i)for i in input().split()]\r\nb=[sum(a[::3]),sum(a[1::3]),sum(a[2::3])]\r\nc=['chest','biceps','back']\r\nprint(c[b.index(max(b))])",
"import sys\n\ndef max2(a, b):\n return max(a, b)\n\ndef max3(a, b, c):\n return max2(max2(a, b), c)\n\ndef min2(a, b):\n return min(a, b)\n\ndef min3(a, b, c):\n return min2(min2(a, b), c)\n\ndef main():\n chest = 0\n bicep = 0\n bck = 0\n\n n = int(input())\n a = list(map(int, input().split()))\n\n for i in range(0, n, 3):\n chest += a[i]\n\n for i in range(1, n, 3):\n bicep += a[i]\n\n for i in range(2, n, 3):\n bck += a[i]\n\n if max3(chest, bicep, bck) == chest:\n print(\"chest\")\n elif max3(chest, bicep, bck) == bicep:\n print(\"biceps\")\n else:\n print(\"back\")\n\nif __name__ == \"__main__\":\n main()\n",
"n = int(input())\r\nl = list(map(int,input().split()))[:n]\r\nstart = 0\r\nmax_chest = 0\r\nmax_biceps = 0\r\nmax_back = 0 \r\nfor i in range(len(l)):\r\n if start == 0:\r\n max_chest += l[i]\r\n elif start == 1:\r\n max_biceps+=l[i]\r\n elif start == 2:\r\n max_back+=l[i]\r\n start += 1\r\n if start == 3:\r\n start = 0\r\n\r\nif max_chest >= max_biceps and max_chest >= max_back :\r\n print(\"chest\")\r\nelif max_biceps >= max_chest and max_biceps >= max_back :\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\nl = list(map(int, input().split(' ')))\r\ngr, bic, spina = 0, 0, 0\r\nfor i in range(0, len(l)):\r\n if i % 3 == 0:\r\n gr += l[i]\r\n if i % 3 == 1:\r\n bic += l[i]\r\n if i % 3 == 2:\r\n spina += l[i]\r\nif spina == max(gr, bic, spina):\r\n print(\"back\")\r\nif gr == max(gr, bic, spina):\r\n print(\"chest\")\r\nif bic == max(gr, bic, spina):\r\n print(\"biceps\")",
"n=int(input())\r\ns1=0\r\ns2=0\r\ns3=0\r\nlst=list(map(int,input().split()))\r\nfor i in range(n):\r\n if (i+1)%3==1:\r\n s1+=lst[i]\r\n elif (i+1)%3==2:\r\n s2+=lst[i]\r\n else:\r\n s3+=lst[i]\r\nm=max(s1,s2,s3)\r\nif m==s1:\r\n print(\"chest\")\r\nelif m==s2:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"while True:\r\n try:\r\n n = eval(input())\r\n a = list(map(int, input().split()))\r\n x, y, z = 0, 0, 0\r\n for i in range(n):\r\n if i % 3 == 0:\r\n x += a[i]\r\n elif i % 3 == 1:\r\n y += a[i]\r\n else:\r\n z += a[i]\r\n if x == max(x, y, z):\r\n print('chest')\r\n elif y == max(x, y, z):\r\n print('biceps')\r\n else:\r\n print('back')\r\n except:\r\n break",
"def solve(n,arr):\n\t\n\tc,bs,bk=0,0,0\n\n\tfor i in range(n):\n\t\tif i%3==0 :\n\t\t\tc+=arr[i]\n\t\telif i%3==1:\n\t\t\tbs+=arr[i]\n\t\telse:\n\t\t\tbk+=arr[i]\n\t\n\n\tif c>bs and c>bk :\n\t\treturn 'chest'\n\telif bs>c and bs > bk :\n\t\treturn 'biceps'\n\telse :\n\t\treturn 'back'\n\t\n\n\n\t\t\n\t\n\n\nl1=int(input())\nl2=input()\n\nl2=[int(x) for x in l2.split()]\n\n\nprint(solve(l1, l2) )",
"\r\nn = int(input())\r\narr = list(map(int,input().split()))\r\nif n <= 3:\r\n value = max(arr)\r\n if arr.index(value) == 0:\r\n print('chest')\r\n elif arr.index(value) == 1:\r\n print('biceps')\r\n else:\r\n print('back')\r\nelse:\r\n ans = []\r\n for t in range(3):\r\n sum1 = arr[t]\r\n i = t+3\r\n while i<len(arr):\r\n sum1 += arr[i]\r\n i+=3\r\n ans.append(sum1)\r\n value = max(ans)\r\n if ans.index(value) == 0:\r\n print('chest')\r\n elif ans.index(value) == 1:\r\n print('biceps')\r\n else:\r\n print('back')\r\n\r\n",
"# chest = 1 ; biecps = 2 ; back = 3\r\n\r\nloop = int(input())\r\nworkout = input().split()\r\n\r\nx = 0\r\ny = 1\r\nz = 2\r\na = []\r\nb = []\r\nc = []\r\n\r\n\r\nfor i in range(loop):\r\n try:\r\n a.append(workout[x])\r\n b.append(workout[y])\r\n c.append(workout[z])\r\n x += 3\r\n y += 3\r\n z += 3\r\n except IndexError:\r\n break\r\n \r\nintListA = list(map(int, a))\r\nintListB = list(map(int, b))\r\nintListC = list(map(int, c))\r\n\r\n\r\nif sum(intListA) > sum(intListB) and sum(intListA) > sum(intListC):\r\n print(\"chest\")\r\n\r\nelif sum(intListB) > sum(intListC) and sum(intListB) > sum(intListA):\r\n print(\"biceps\")\r\n\r\nelse:\r\n print(\"back\")",
"'''It comprises of 4 functions :-\r\n\r\n1) inp — For taking integer inputs.\r\n\r\n2) inlt — For taking List inputs.\r\n\r\n3) insr — For taking string inputs. Actually it returns a List of Characters,\r\ninstead of a string,which is easier to use in Python, because in Python, Strings are Immutable.\r\n\r\n4) invr — For taking space seperated integer variable inputs.\r\n\r\nThe input = sys.stdin.readline is actually for Faster Inputs,\r\n because line reading through System STDIN (Standard Input) is faster in Python.\r\n'''\r\n\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n\r\n\r\nn = inp()\r\ninlt = inlt()\r\ninsr = insr()\r\n\r\n\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i, value in enumerate(inlt):\r\n if(i%3 == 0):\r\n chest += value\r\n elif(i%3==1):\r\n biceps += value\r\n else:\r\n back += value\r\n\r\nif(chest > biceps and chest > back):\r\n print('chest')\r\nelif(biceps > chest and biceps > back):\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n=int(input())\r\nl=[0,0,0]\r\nl1=['chest','biceps','back']\r\nfor a,b in enumerate(map(int,input().split(\" \"))):\r\n l[a%3]+=b\r\nif(l[0]>l[1] and l[0]>l[2]):\r\n print(\"chest\")\r\nelif(l[1]>l[0] and l[1]>l[2]):\r\n print('biceps')\r\nelif(l[2]>l[0] and l[2]>l[1]):\r\n print('back')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest,biceps,back=0,0,0\r\nfor i in range(0,n,3):\r\n chest+=l[i]\r\nfor i in range(1,n,3):\r\n biceps+=l[i]\r\nfor i in range(2,n,3):\r\n back+=l[i]\r\nvar = {chest:\"chest\",biceps:\"biceps\",back:\"back\"}\r\nprint(var.get(max(var)))\r\n\r\n\r\n",
"user=int(input())\nchest=0\nbiceps=0\nback=0\n\nnew=[]\nneww=input().split(' ')\nfor j in neww:\n new.append(int(j))\n \nfor i in range(len(new)):\n temp=i%3\n if temp==0:\n chest+=new[i]\n if temp==1:\n biceps+=new[i]\n if temp==2:\n back+=new[i]\n \nif chest>back and chest>biceps:\n print('chest')\nelif back>chest and back>biceps:\n print('back')\nelse:\n print('biceps')\n\t\t \t\t\t\t\t\t \t\t\t \t\t\t\t \t \t",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nba=bi=c=x=int(0)\r\nfor x in range(a):\r\n\tif x%3==0:\r\n\t\tc=c+b[x]\r\n\telif x%3==1:\r\n\t\tbi=bi+b[x]\r\n\telse:\r\n\t\tba=ba+b[x]\r\nif ba>bi and ba>c:\r\n\tprint(\"back\")\r\nelif bi>ba and bi>c:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"chest\")",
"f = int(input())\nl1 = list(map(int,input().split()))\nchest = 0\nbiceps = 0 \nback = 0 \n\nfor x in range(f):\n if x%3==0:\n chest=chest+l1[x]\n elif x%3==1:\n biceps=biceps+l1[x]\n elif x%3==2:\n back = back+l1[x]\n\n\n\n\nmaxx = max(chest,biceps,back)\nif maxx==chest:\n print(\"chest\")\nelif maxx==biceps:\n print(\"biceps\")\nelse:\n print(\"back\")\n\n\n",
"n=int(input())\r\nar=input().split()\r\nch=[0,'chest']\r\nbi=[0,'biceps'] \r\nba=[0,'back']\r\nfor x in range(len(ar)) : \r\n if (x+1)%3==1:\r\n ch[0]+=int(ar[x])\r\n elif (x+1)%3==2:\r\n bi[0]+=int(ar[x])\r\n else:\r\n ba[0]+=int(ar[x])\r\nM=ch\r\nfor x in ch,bi,ba:\r\n if x[0]>M[0] : M=x\r\nprint(M[1])",
"n = int(input())\r\na = list(map(int,input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(len(a)):\r\n if i % 3 == 0:\r\n chest += a[i]\r\n elif i % 3 == 1:\r\n biceps += a[i]\r\n else:\r\n back += a[i]\r\nif max(chest,biceps,back) == chest:\r\n print('chest')\r\nelif max(chest,biceps,back) == biceps:\r\n print('biceps')\r\nelse:\r\n print('back')",
"x = int(input())\r\nl = input().split()\r\na = [0,0,0]\r\nfor i,y in enumerate(l):\r\n y = int(y)\r\n if (i%3==0):\r\n a[0]+=y\r\n elif (i%3==1):\r\n a[1]+=y\r\n elif (i%3==2):\r\n a[2]+=y\r\nx = max(a)\r\nif (a[0]==x):\r\n print(\"chest\")\r\nelif(a[1]==x):\r\n print(\"biceps\")\r\nelif(a[2]==x):\r\n print(\"back\")\r\n \r\n\r\n ",
"n = int(input())\na = list(map(int, input().split()))\ns = [0] * 3\nfor i in range(n):\n s[i % 3] += a[i]\nsmx = max(s)\nif smx == s[0]:\n print(\"chest\")\nelif smx == s[1]:\n print(\"biceps\")\nelse:\n print(\"back\")\n\n",
"n = int(input())\nls = [0, 0, 0]\nfor i, x in enumerate(input().split()):\n ls[i % 3] += int(x)\nt = ls.index(max(ls))\nif t == 0:\n print('chest')\nelif t == 1:\n print('biceps')\nelse:\n print('back')",
"n,chest,biceps,back,count=int(input()),0,0,0,0\r\nl=[int(ele) for ele in input().split()]\r\nfor e in l:\r\n if count%3==0:\r\n chest,count=chest+e,count+1\r\n elif (count-1)%3==0:\r\n biceps,count=biceps+e,count+1\r\n elif (count-2)%3==0:\r\n back,count=back+e,count+1\r\nif chest==max(chest,biceps,back):print('chest')\r\nelif biceps==max(chest,biceps,back):print('biceps')\r\nelif back==max(chest,biceps,back):print('back')",
"n = int(input())\na = [int(x) for x in input().split()]\nchest , biceps , back = 0, 0, 0\nfor i in range(n):\n if i%3==0:\n chest += a[i]\n elif i%3==1:\n biceps += a[i]\n else:\n back += a[i]\n\nif chest>biceps:\n if chest > back:\n print(\"chest\")\n else:\n print(\"back\")\nelse:\n if biceps > back:\n print(\"biceps\")\n else:\n print(\"back\")\n",
"n=int(input())\r\ns=list(map(int,input().split()))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(n):\r\n if(i%3==0):\r\n a+=s[i]\r\n elif(i%3==1):\r\n b+=s[i]\r\n else:\r\n c+=s[i]\r\nma=max(a,max(b,c))\r\nif(ma==a):\r\n print('chest')\r\nif(ma==b):\r\n print('biceps')\r\nif(ma==c):\r\n print('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc,bi,b=0,0,0\r\nif len(a)==2:\r\n c+=a[0]\r\n bi+=a[1]\r\nelif len(a)==1:\r\n c+=a[0]\r\nelif len(a)>=3:\r\n for i in range(0,n,3):\r\n c+=a[i]\r\n for j in range(1,n,3):\r\n bi+=a[j]\r\n for k in range(2,n,3):\r\n b+=a[k]\r\nif c>bi and c>b:\r\n print('chest')\r\nelif bi>c and bi>b:\r\n print('biceps')\r\nelif b>c and b>bi:\r\n print('back')\r\n \r\n \r\n",
"n = int(input())\r\ns = input().split()\r\ns = [int(i) for i in s]\r\nc,b,ba = (0,0,0)\r\nfor i in range(n):\r\n\tif(i%3 == 0):\r\n\t\tc += s[i]\r\n\telif(i%3 == 1):\r\n\t\tb += s[i]\r\n\telse:\r\n\t\tba += s[i]\r\nif(c>b):\r\n\tif(c>ba):\r\n\t\tprint('chest')\r\n\telse:\r\n\t\tprint('back')\r\nelse:\r\n\tif(b>ba):\r\n\t\tprint('biceps')\r\n\telse:\r\n\t\tprint('back')",
"#██████████ █ █ /█\\ █ █ ███ /█\\ ██████████████\r\n\"█ █ █ /███\\ █ █ █ ██ /███\\ /██/ \"\r\n#█ █ █ /█████\\ █ █ █ ██ /█████\\ /██/ \r\n\"█ █ █ █!:) █ █ █ █ ██ █ █ /██/ \"\r\n#██████████ █████████ █(:| █ ████████ ████ █ █ /██/ \"\r\n\" █ █ █ █!:) █ █ █ █ ██ █ █ /██/ \"\r\n# █ █ █ ███████ █ █ █ ██ ███████ /██/\r\n\" █ █ █ █ █ █ █ █ ██ █ █ ██/ \"\r\n#██████████ █ █ █ █ █ █ ███ █ █ ██████████████\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nchest_arr=sum(arr[0::3])\r\nbice_arr=sum(arr[1::3])\r\nback_arr=sum(arr[2::3])\r\nif max(bice_arr,chest_arr,back_arr)==bice_arr:\r\n print('biceps')\r\nelif max(bice_arr,chest_arr,back_arr)==chest_arr:\r\n print('chest')\r\nelse:\r\n print('back')\r\n ",
"t=int(input())\r\nl=[int(x) for x in input().split()]\r\nm=[]\r\nn=[]\r\no=[]\r\nfor i in range(0,t,3):\r\n m.append(l[i])\r\nif t>1: \r\n for i in range(1,t,3):\r\n n.append(l[i])\r\nelse:\r\n b=0 \r\nif t>2: \r\n for i in range(2,t,3):\r\n o.append(l[i])\r\nelse:\r\n c=0 \r\na=sum(m)\r\nb=sum(n)\r\nc=sum(o)\r\nj=[a,b,c] \r\nif max(j)==a:\r\n print('chest')\r\nelif max(j)==b:\r\n print('biceps')\r\nelse:\r\n print('back') \r\n\r\n ",
"n=int(input())\r\narr=list(map(int, input().split()))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(n):\r\n a+=sum(arr[0::3])\r\n b+=sum(arr[1::3])\r\n c+=sum(arr[2::3])\r\nif max(a,b,c)==a:\r\n print(\"chest\")\r\nelif max(a,b,c)==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n ",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\np1=l[0:n:3]\r\np2=l[1:n:3]\r\np3=l[2:n:3]\r\n\r\na=sum(p1)\r\nb=sum(p2)\r\nc=sum(p3)\r\n\r\nd=max(a,b,c)\r\n\r\nif(a==d):\r\n print(\"chest\")\r\nelif(b==d):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\nA = input().split()\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nk = 0\r\nfor i in A:\r\n i = int(i)\r\n if (k == 0):\r\n chest += i\r\n elif (k == 1):\r\n biceps += i\r\n else:\r\n back += i\r\n k += 1\r\n k = k % 3\r\nif (chest > biceps and chest > back):\r\n print(\"chest\")\r\nelif (biceps > chest and biceps > back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=0\r\nc=0\r\nd=0\r\nfor i in range(0,n,3):\r\n b+=a[i]\r\nfor i in range(1,n,3):\r\n c+=a[i]\r\nfor i in range(2,n,3):\r\n d+=a[i]\r\ne=max(b,c,d)\r\nif(e==b):\r\n print(\"chest\")\r\nelif(e==c):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"t=int(input())\r\ns=input()\r\nk=s.split()\r\nchest=0\r\nbicep=0\r\nback=0\r\nfor i in range(0,t,3):\r\n chest+=int(k[i])\r\nfor i in range(1,t,3):\r\n bicep+=int(k[i])\r\nfor i in range(2,t,3):\r\n back+=int(k[i])\r\n \r\nif chest>back and chest>bicep:\r\n print(\"chest\")\r\nelif back>bicep and back>chest:\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")",
"n = int(input())\r\nlist1 = input().split()\r\nback = 0\r\nchest = 0\r\nbiceps = 0\r\nfor i in range(0,n,3):\r\n chest+= int(list1[i])\r\nif n>1:\r\n for i in range(1,n,3):\r\n biceps += int(list1[i])\r\nif n>2:\r\n for i in range(2,n,3):\r\n back += int(list1[i])\r\nif back > biceps and back > chest:\r\n print(\"back\")\r\nelif chest > biceps and back < chest:\r\n print(\"chest\")\r\nelif back < biceps and biceps > chest:\r\n print(\"biceps\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nl1=[]\r\nl2=[]\r\nl3=[]\r\ni=0\r\nwhile i<=len(a):\r\n if i==len(a):break\r\n else:\r\n l1.append(a[i])\r\n if i == len(a): break\r\n else:\r\n i+=1\r\n if i == len(a): break\r\n else:\r\n l2.append(a[i])\r\n i+=1\r\n if i == len(a): break\r\n else:\r\n l3.append(a[i])\r\n i+=1\r\na1=sum(l1)\r\na2=sum(l2)\r\na3=sum(l3)\r\nk=max(sum(l1),sum(l2),sum(l3))\r\nif a1==k:print('chest')\r\nelif a2==k:print('biceps')\r\nelse:print('back')\r\n\r\n",
"chest=0\r\nbiceps=0\r\nback=0\r\nchest_index=0\r\nbiceps_index=1\r\nback_index=2\r\nnumber_of_exercises=int(input())\r\nif 1<=number_of_exercises<=20:\r\n exercise_repeating = [int(exercise_repeating) for exercise_repeating in input().split()]\r\nwhile chest_index<len(exercise_repeating):\r\n chest+=exercise_repeating[chest_index]\r\n chest_index+=3\r\nwhile biceps_index<len(exercise_repeating):\r\n biceps+=exercise_repeating[biceps_index]\r\n biceps_index+=3\r\nwhile back_index<len(exercise_repeating):\r\n back+=exercise_repeating[back_index]\r\n back_index+=3\r\nif 1<=number_of_exercises<=20:\r\n if chest>biceps and chest>back:\r\n print(\"chest\")\r\n elif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")",
"_ = input()\r\nvls = list(map(int, input().split()))\r\n\r\nres = [0, 0, 0]\r\nfor i, v in enumerate(vls):\r\n res[i % 3] += v\r\n\r\nx = res.index(max(res))\r\nprint('chest' if x == 0 else 'biceps' if x == 1 else 'back')\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nchest,biceps,back = 0,0,0\r\ncounter = 0\r\nfor i in a:\r\n if counter > 2:\r\n counter = 0\r\n if counter == 0:\r\n chest+=i \r\n counter+=1\r\n elif counter == 1:\r\n biceps+=i\r\n counter+=1\r\n elif counter == 2:\r\n back+=i\r\n counter+=1\r\nif chest > biceps and chest> back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nch,bi,ba = 0,0,0\r\nfor i in range(0,n):\r\n if i%3 == 0: ch +=a[i]\r\n if i%3 == 1: bi +=a[i]\r\n if i%3 == 2: ba +=a[i]\r\nif ch>bi and ch>ba: print(\"chest\")\r\nif ch<bi and bi>ba: print(\"biceps\")\r\nif ch<ba and bi<ba: print(\"back\")\r\n",
"n=int(input());b=[0,0,0];i=-1\r\na=list(map(int,input().split()));p=0\r\nwhile n>0:\r\n n-=1;i+=1;p+=1\r\n if p==1:\r\n b[0]+=a[i]\r\n elif p==2:\r\n b[1]+=a[i]\r\n else:\r\n b[2]+=a[i]\r\n if p==3:\r\n p=0\r\np=b.index(max(b))\r\nif p==0:\r\n print('chest')\r\nelif p==1:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Feb 13 18:19:37 2020\r\n\r\n@author: Lenovo\r\n\"\"\"\r\n\r\n\r\n##https://codeforces.com/problemset/problem/255/A\r\n\r\ndef bodybuilder():\r\n \r\n exercises = int(input())\r\n \r\n routine = input().split()\r\n \r\n dic = {\"Chest\":0,\"Biceps\":0,\"Back\":0}\r\n \r\n while len(routine) != 0:\r\n for i in dic:\r\n if len(routine) == 0:\r\n break\r\n dic[i] += int(routine[0])\r\n routine.pop(0)\r\n \r\n if dic[\"Chest\"] > dic[\"Biceps\"] and dic[\"Chest\"] > dic[\"Back\"]:\r\n print(\"chest\")\r\n return\r\n elif dic[\"Biceps\"] > dic[\"Chest\"] and dic[\"Biceps\"] > dic[\"Back\"]:\r\n print(\"biceps\")\r\n return\r\n else:\r\n print(\"back\")\r\n return\r\n \r\nbodybuilder()\r\n ",
"a=[[0,'chest'],[0,'biceps'],[0,'back']]\r\ninput()\r\n#print(a)\r\nx=[int(i) for i in input().split()]\r\nfor i in range(len(x)):\r\n a[(i)%3][0]+=x[i]\r\na.sort(key=lambda x:x[0])\r\n#print(a)\r\nprint(a[-1][1])\r\n",
"#Keshika Patwari\r\n#Indian Institute Of Technology, Jodhpur\r\n# 2022\r\nimport sys\r\ninput=sys.stdin.readline\r\ndef exe():\r\n chest=0\r\n biseps=0\r\n back=0\r\n for i in range(n):\r\n if(i%3==0):\r\n chest+=l[i]\r\n elif(i%3==1):\r\n biseps+=l[i]\r\n else:\r\n back+=l[i]\r\n #print(chest,biseps,back)\r\n if(chest>biseps and chest>back):\r\n return 'chest'\r\n elif(chest<biseps and biseps>back):\r\n return 'biceps'\r\n elif(back>biseps and chest<back):\r\n return 'back'\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nprint(exe())",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns1=0\r\ns2=0\r\ns3=0\r\nfor i in range(0,n):\r\n if(((i+3)/3).is_integer()):\r\n s1=s1+a[i]\r\n elif(((i+2)/3).is_integer()): \r\n s2=s2+a[i]\r\n elif(((i+1)/3).is_integer()):\r\n s3=s3+a[i]\r\nmaximum=max(s1,s2,s3)\r\nif(s1==maximum):\r\n print(\"chest\")\r\nelif(s2==maximum):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\") ",
"a=int(input())\r\ny=[int(i) for i in input().split()]\r\ns=[0]*3\r\nk=1\r\nfor i in y:\r\n if k>3:\r\n k=1\r\n s[k-1]+=i\r\n k+=1\r\nq=s.index(max(s))\r\nif q==0:\r\n print(\"chest\")\r\nelif q==1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nc = []\r\nbi = []\r\nb = []\r\nfor i in range(0,n):\r\n if(i%3 == 0):\r\n c.append(l[i])\r\n elif(i%3==1):\r\n bi.append(l[i])\r\n else:\r\n b.append(l[i])\r\nif(max(sum(c),sum(b),sum(bi)) == sum(c)):\r\n print(\"chest\")\r\nelif(max(sum(c),sum(b),sum(bi)) == sum(bi)):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\ns = input()\r\ns = s.split()\r\nc = 0\r\nb = 0\r\np = 0\r\nfor i in range(0,n,3):\r\n c = c + int(s[i])\r\nfor i in range(1,n,3):\r\n p = p + int(s[i])\r\nfor i in range(2,n,3):\r\n b = b + int(s[i])\r\nif c > p and c > b:\r\n print(\"chest\")\r\nelif p > c and p > b:\r\n print(\"biceps\")\r\nelif b > c and b > p:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))[:n]\r\nc=bi=b=0 \r\nfor i in range(len(l)):\r\n if i%3==0:\r\n c+=l[i]\r\n elif i%3==1:\r\n bi+=l[i]\r\n elif i%3==2:\r\n b+=l[i]\r\nk=max(c,bi,b)\r\nif k==c:\r\n print('chest')\r\nelif k==bi:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nl=list(map(int, input().split(\" \")))\r\nchest=int(0)\r\nbiceps=int(0)\r\nback=int(0)\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=l[i]\r\n elif i%3==1:\r\n biceps+=l[i]\r\n else:\r\n back+=l[i]\r\ns=max(chest,biceps,back)\r\nif s==chest:\r\n print(\"chest\")\r\nelif s==biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = list(map(int,input().split()))\r\nl = [0]*3\r\nfor i in range(len(a)):\r\n if i%3==0:\r\n l[0]+=a[i]\r\n elif i%3==1:\r\n l[1]+=a[i]\r\n else:\r\n l[2]+=a[i]\r\nmx = max(l)\r\nif mx==l[0]:\r\n print('chest')\r\nelif mx==l[1]:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\na,b,c = 0,0,0\r\n\r\nfor i in range(n):\r\n if i%3==0:\r\n a += lst[i]\r\n elif i%3==1:\r\n b += lst[i]\r\n elif i%3==2:\r\n c += lst[i]\r\n \r\nif a>b and a>c:\r\n print('chest')\r\nelif b>a and b>c:\r\n print('biceps')\r\nelif c>a and c>b:\r\n print('back')",
"x=int(input(\"\"))\r\nar=list(map(int,input(\"\").split()))\r\nch=bi=ba=0\r\nfor i in range(len(ar)):\r\n j=i%3\r\n if(j==0):\r\n ch=ch+ar[i]\r\n elif(j==1):\r\n bi=bi+ar[i]\r\n else:\r\n ba=ba+ar[i]\r\n \r\nj=max(ch,bi,ba)\r\nif(j==ch):\r\n print(\"chest\")\r\nelif(j==ba):\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")",
"n=int(input())\r\narr=[int(x) for x in input().split()] \r\nsum1=0 \r\nsum2=0 \r\nsum3=0 \r\nfor i in range(0,n,3):\r\n sum1=sum1+arr[i]\r\nfor i in range(1,n,3):\r\n sum2=sum2+arr[i]\r\nfor i in range(2,n,3):\r\n sum3=sum3+arr[i]\r\na=max(sum1,sum2,sum3)\r\nif a==sum1:\r\n print(\"chest\") \r\nelif a==sum2:\r\n print(\"biceps\")\r\nelif a==sum3:\r\n print(\"back\")",
"\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nchest=0\r\nbic=0\r\nback=0\r\nfor i in range(n):\r\n if (i+1)%3==1:\r\n chest+=a[i]\r\n elif (i+1)%3==2:\r\n bic+=a[i]\r\n else:\r\n back+=a[i]\r\nif chest>bic and chest>back:\r\n print('chest')\r\nelif bic>chest and bic>back:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n, lst, dem = int(input()), list(map(int, input().split())), [0] * 3\r\nfor x in range(n): dem[x % 3] += lst[x]\r\nif max(dem[0], dem[1], dem[2]) == dem[0]: print(\"chest\")\r\nelif max(dem[0], dem[1], dem[2]) == dem[1]: print(\"biceps\")\r\nelse: print(\"back\")",
"n = int(input())\r\na = list(map(int, input().split()))\r\nt = [0] * 3\r\nfor i in range(n):\r\n t[i % 3] += a[i]\r\nn = t.index(max(t))\r\nprint(\"chest\" if n == 0 else \"biceps\" if n == 1 else \"back\")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=[]\r\nfor i in range(3):\r\n s=sum(a[i::3])\r\n b.append(s)\r\nif b[0]>b[1] and b[0]> b[2]:\r\n print('chest')\r\nelif b[1]>b[0] and b[1]>b[2]:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\nx1=1\r\na1=0\r\nb1=0\r\nc1=0\r\nfor x in range(n):\r\n if x1==1:\r\n a1+=a[x]\r\n x1+=1\r\n elif x1==2:\r\n b1+=a[x]\r\n x1+=1\r\n else:\r\n c1+=a[x]\r\n x1=1\r\nif max(a1,c1,b1)==a1:\r\n print('chest')\r\nelif max(a1,c1,b1)==b1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nl=[int(i) for i in input().split()]\r\nc,bi,b=0,0,0\r\nfor i in range(0,len(l),3):\r\n c+=l[i]\r\nfor i in range(1,len(l),3):\r\n bi+=l[i]\r\nfor i in range(2,len(l),3):\r\n b+=l[i]\r\nz=max(c,bi,b)\r\nif z==c:\r\n print('chest')\r\nelif z==bi:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nA=list(map(int,input().split()))\r\nsum,sum1,sum2,m=0,0,0,[]\r\nif n>=4:\r\n for i in range(0,len(A),3):\r\n sum+=A[i]\r\n for i in range(1,len(A),3):\r\n sum1+=A[i]\r\n for i in range(2,len(A),3):\r\n sum2+=A[i]\r\n m.append(sum)\r\n m.append(sum1)\r\n m.append(sum2)\r\n if m[0] > max(m[1],m[2]):\r\n print(\"chest\")\r\n elif m[1] > max(m[0],m[2]):\r\n print(\"biceps\")\r\n elif m[2] > max(m[0],m[1]):\r\n print(\"back\")\r\nelif n==3:\r\n if A[0]>(A[1] and A[2]):\r\n print(\"chest\")\r\n elif A[1]>(A[0] and A[2]):\r\n print(\"biceps\")\r\n elif A[2] > (A[0] and A[1]):\r\n print(\"back\")\r\nelif n==2:\r\n if A[0]<A[1]:\r\n print('biceps')\r\n else:\r\n print(\"chest\")\r\nelif n==1:\r\n print(\"chest\")\r\n",
"\r\ndef check(l):\r\n chest = 0\r\n biceps = 0\r\n back = 0\r\n for i in range(0,2):\r\n if len(l) % 3 == 0:\r\n break\r\n l.append(0)\r\n\r\n for i in range(0,len(l),3):\r\n chest += l[i]\r\n biceps += l[i+1]\r\n back +=l[i+2] \r\n\r\n if chest > biceps and chest > back:\r\n return 'chest'\r\n elif biceps > chest and biceps > back:\r\n return 'biceps'\r\n else:\r\n return 'back'\r\n\r\n\r\nt = int(input())\r\na = input().split()\r\nb = map(int, a)\r\ni_list = list(b)\r\nprint(check(i_list))\r\n\r\n\r\n\r\n",
"n = int(input())\r\nx = list(map(int, input().split()))\r\n\r\nchest = sum(x[0::3])\r\nbiceps = sum(x[1::3])\r\nback = sum(x[2::3])\r\n\r\na = max(chest, biceps, back)\r\n\r\nif a == chest:\r\n print(\"chest\")\r\nelif a == biceps:\r\n print(\"biceps\")\r\nelif a == back:\r\n print(\"back\")\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(3):\r\n for j in range(i,n,3):\r\n if i==0:\r\n chest+=l[j]\r\n if i==1:\r\n biceps+=l[j]\r\n if i==2:\r\n back+=l[j]\r\ns=max(chest,back,biceps)\r\nif s==chest:\r\n print('chest')\r\nif s==back:\r\n print('back')\r\nif s==biceps:\r\n print('biceps')\r\n",
"input()\r\na = [0,0,0]\r\ns = 0\r\nfor i in input().split():\r\n a[s % 3] += int(i)\r\n s += 1\r\ni = a.index(max(a))\r\nif i == 0:\r\n print(\"chest\")\r\nelif i == 1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"inp1 = int(input())\r\ninp2 = list(map(int,input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(0,inp1,3):\r\n chest+=inp2[i]\r\nfor j in range(1,inp1,3):\r\n biceps += inp2[j]\r\nfor k in range(2,inp1,3):\r\n back += inp2[k]\r\nmax1 = max(chest,biceps,back)\r\nif max1 == chest:\r\n print(\"chest\")\r\nelif max1 == biceps:\r\n print(\"biceps\")\r\nelif max1 == back:\r\n print(\"back\")",
"n = int(input())\na = list(map(int, input().split()))\nm = len(a)\nk = []\nchest = []\nbiceps = []\nback = []\nfor i in range(m):\n back = a[2::3]\n biceps = a[1::3]\n chest = a[::3]\nif sum(back) >= sum(chest) and sum(back) >= sum(biceps):\n print('back')\nif sum(chest) >= sum(back) and sum(chest) >= sum(biceps):\n print('chest')\nif sum(biceps) >= sum(chest) and sum(biceps) >= sum(back):\n print('biceps')\n",
"n = int(input())\r\na = {0: 0, 1: 0, 2: 0}\r\nmas = list(map(int, input().split()))\r\nfor i in range(n):\r\n a[i%3] += mas[i]\r\nc = max(a.values())\r\na = {v:k for k,v in a.items()}\r\nc = a[c]\r\nprint('chest' if c==0 else ('biceps' if c==1 else 'back'))",
"n = int(input())\r\n\r\nlst = list(map(int,input().split()))\r\nnew_lst=[0,0,0]\r\n\r\nfor i in range(0,len(lst)+2,3):\r\n if i +3 <= n:\r\n \r\n new_lst[0] += lst[i]\r\n new_lst[1] += lst[i+1]\r\n new_lst[2] += lst[i+2]\r\n else:\r\n if len(lst[i:]) ==2:\r\n \r\n new_lst[0] += lst[i]\r\n new_lst[1] += lst[i+1]\r\n if len(lst[i:]) == 1:\r\n \r\n new_lst[0] += lst[i]\r\n \r\n\r\nidx = new_lst.index(max(new_lst))\r\nif idx==0:\r\n print('chest')\r\nelif idx ==1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"# coding: utf-8\r\n\r\nexercises = [0 for i in range(3)]\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nfor i in range(n):\r\n exercises[i % 3] += a[i]\r\n \r\nprint(['chest', 'biceps', 'back'][exercises.index(max(exercises))])",
"n = int(input())\r\na = list(map(int, input().split()))\r\ncount = 0\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor i in a:\r\n if count == 3:\r\n count = 0\r\n count += 1\r\n if count == 1:\r\n chest = chest + i\r\n if count == 2:\r\n biceps = biceps + i\r\n if count == 3:\r\n back = back + i\r\n\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nif biceps > chest and biceps > back:\r\n print('biceps')\r\nif back > chest and back > biceps:\r\n print('back')",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nb = [0] * 3\r\nfor i in range(n):\r\n b[i % 3] += a[i]\r\n\r\nchest, biceps, back = b\r\nif chest > back and chest > biceps:\r\n print('chest')\r\nif biceps > back and biceps > chest:\r\n print('biceps')\r\nif back > biceps and back > chest:\r\n print('back')\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nprsnt_max=0\r\nc=0\r\npresnt_c=None\r\nchest,biceps,back=0,0,0\r\nfor i in a:\r\n if c<3:\r\n c+=1\r\n elif c==3:\r\n c=1\r\n presnt_c=c\r\n # print(presnt_c)\r\n \r\n if presnt_c==1:chest+=i\r\n elif presnt_c==2:biceps+=i\r\n elif presnt_c==3:back+=i\r\n \r\n# print(chest,biceps,back) \r\nmmax=max(chest,max(biceps,back))\r\n# print(mmax) \r\nif mmax==chest:\r\n print(\"chest\")\r\n\r\nelif mmax==biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nc=sum(arr[::3])\r\nb=sum(arr[1::3])\r\nba=sum(arr[2::3])\r\nres=max(c,b,ba)\r\nif res==c:\r\n print(\"chest\")\r\nelif res==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nls = list(map(int,input().strip().split()))[:n]\r\nch = 0\r\nbi = 0 \r\nba = 0\r\nfor i in range(len(ls)):\r\n if i % 3 == 0:\r\n ch = ch+ls[i]\r\n elif i % 3 == 1:\r\n bi = bi+ls[i]\r\n else:\r\n ba = ba+ls[i]\r\nif ch == max(ch, bi, ba):\r\n print(\"chest\")\r\nelif bi == max(ch, bi, ba):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"# JAI SHREE RAM\r\n\r\nimport math; from collections import *\r\nimport sys; from functools import reduce\r\n\r\n# sys.setrecursionlimit(10**6)\r\ndef get_ints(): return map(int, input().strip().split())\r\ndef get_list(): return list(get_ints())\r\ndef get_string(): return list(input().strip().split())\r\ndef printxsp(*args): return print(*args, end=\"\")\r\ndef printsp(*args): return print(*args, end=\" \")\r\n\r\nUGLYMOD = int(1e9)+7; SEXYMOD = 998244353; MAXN = int(1e5)\r\n\r\n# sys.stdin=open(\"input.txt\",\"r\");sys.stdout=open(\"output.txt\",\"w\")\r\n\r\n# for _testcases_ in range(int(input())):\r\nn = int(input())\r\nli = get_list()\r\nd = defaultdict(lambda : 0)\r\nname = ['chest', 'biceps', 'back']\r\nfor i in range(n):\r\n d[name[i%3]] += li[i]\r\nprint(max(d.items(), key=lambda x: x[1])[0])\r\n\r\n\r\n\r\n\r\n\r\n'''\r\n>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!\r\nTHE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )\r\nLink may be copy-pasted here if it's taken from other source.\r\nDO NOT PLAGIARISE.\r\n>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!\r\n'''",
"n = int(input())\na = [int(i) for i in input().split()]\nbiceps = 0 \nchest = 0\nback = 0\nfor i in range(0,n) :\n d = (i+1) % 3\n if d == 2 : \n biceps += a[i]\n elif d == 0 :\n back += a[i]\n else : \n chest += a[i]\nma = [back,chest,biceps]\nif max(ma) == chest :\n print('chest')\nelif max(ma) == back : \n print('back')\nelse :\n print('biceps')",
"n=int(input())\r\nm=list(map(int,input().split()))\r\nbiceps=0\r\nchest=0\r\nback=0\r\nfor i in range(n):\r\n if i in list(range(1,n+1,3)):#m[1::3]\r\n biceps+=m[i]\r\n elif i in list(range(2,n+1,3)):\r\n back+=m[i]\r\n else:\r\n chest+=m[i]\r\nif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na,b,c=0,0,0\r\nl=list(map(int,input().split()))\r\nfor i in range(n):\r\n if i==0 or i%3==0:\r\n a+=l[i]\r\n elif i==1 or i%3==1:\r\n b+=l[i]\r\n else:\r\n c+=l[i]\r\nmaxi=max(a,b,c)\r\nif maxi==a:\r\n print(\"chest\")\r\nelif maxi==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nx=[int(i) for i in input().split()]\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(n):\r\n if i%3==0:\r\n a=a+x[i]\r\n elif i%3==1:\r\n b=b+x[i]\r\n else:\r\n c=c+x[i]\r\nif a>b and a>c:\r\n print(\"chest\")\r\nelif b>a and b>c:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\ncount=1\r\nc=[] #chest\r\nf=[] #biceps\r\nh=[] #back\r\nfor i in range(len(a)):\r\n if i%3==0:\r\n c.append(a[i])\r\n elif i%3==1:\r\n f.append(a[i])\r\n elif i%3==2:\r\n h.append(a[i])\r\n \r\n \r\n \r\n \r\n## print('i',i,'i+1',i+1,'ai',a[i],'c',c,'f',f,'h',h)\r\n\r\nif sum(h)<sum(c)>sum(f):\r\n print('chest')\r\nelif sum(h)<sum(f)>sum(c):\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\nstep = 0\r\nm = [[]]\r\ndic = {\"chest\":0,\"back\":0,'biceps':0}\r\n\r\n\r\nl = list(map(int,input().split()))\r\nfor i in l:\r\n if step == 3:\r\n step = 0\r\n if step == 0:\r\n dic[\"chest\"] += i\r\n elif step == 1:\r\n dic['biceps']+=i\r\n elif step == 2:\r\n dic[\"back\"] += i\r\n step += 1\r\nmax_key = max(dic, key=dic.get)\r\nprint(max_key)\r\n",
"x=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(len(l)):\r\n if i>2:\r\n l[i%3]=l[i%3]+l[i]\r\nl=l[:3]\r\nd={0:'chest',1:'biceps',2:'back'}\r\nprint(d[l.index(max(l))])\r\n",
"A = input()\r\nB = input().split()\r\nB = list(map(int, B))\r\n\r\nchest = B[::3]\r\nbiceps = B[1::3]\r\nback = B[2::3]\r\n \r\nchest = sum(chest)\r\nbiceps = sum(biceps)\r\nback = sum(back)\r\n\r\nmax = max(chest, biceps, back)\r\n\r\nif chest == max:\r\n print('chest')\r\nelif biceps == max:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n=int(input())\r\nm=list(map(int,input().split()))\r\n\r\nchest=0\r\nbiceps=0\r\nback=0\r\n\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=m[i]\r\n \r\n elif i%3==1:\r\n biceps+=m[i]\r\n \r\n else:\r\n back+=m[i]\r\n \r\n\r\nn=max(back,biceps,chest)\r\nif n==biceps:\r\n print('biceps')\r\n\r\nelif n==back:\r\n print('back')\r\n\r\nelse:\r\n print('chest')\r\n\r\n",
"n=int(input())\r\n\r\nl=list(map(int,input().split()))\r\n\r\nc=0\r\nb=0\r\nv=0\r\nfor i in range(0,n,3):\r\n c+=l[i]\r\n \r\n \r\nfor i in range(1,n,3):\r\n b+=l[i] \r\nfor i in range(2,n,3):\r\n v+=l[i]\r\nif max(c,b,v)==c:\r\n print(\"chest\")\r\nelif max(c,b,v)==b:\r\n print( \"biceps\")\r\nelse:\r\n print(\"back\")",
"# URL: https://codeforces.com/problemset/problem/255/A\n\nimport io\nimport os\nimport sys\n\ninput_buffer = io.BytesIO(os.read(0, os.fstat(0).st_size))\ninp = lambda: input_buffer.readline().rstrip(b\"\\n\").rstrip(b\"\\r\")\nout = sys.stdout.write\n\nn = int(inp())\na = list(map(int, inp().split()))\nx = sum(a[::3])\ny = sum(a[1::3])\nz = sum(a[2::3])\nif x > y and x > z:\n out(\"chest\\n\")\nelif y > z and y > z:\n out(\"biceps\\n\")\nelse:\n out(\"back\\n\")\n",
"n = int(input())\r\na = input().split(\" \")\r\na = [int(i) for i in a]\r\ns_ba = 0\r\ns_bi = 0\r\ns_c = 0\r\nfor i in range(n):\r\n if (i+1) % 3 == 0:\r\n ba = a[i]\r\n s_ba = s_ba + ba\r\n if (i+1) %3 == 2:\r\n bi = a[i]\r\n s_bi = s_bi + bi \r\n if (i+1) % 3 == 1:\r\n c = a[i]\r\n s_c = s_c + c\r\nans = max(s_c, s_bi, s_ba)\r\nif ans == s_c:\r\n print(\"chest\")\r\nelif ans == s_ba:\r\n print(\"back\")\r\nelif ans == s_bi:\r\n print(\"biceps\")",
"n = int(input())\narray = list(map(int, input().split()))\n\nchest = sum(array[0::3])\nbiceps = sum(array[1::3])\nback = sum(array[2::3])\n\nif chest == max([chest, biceps, back]):\n print(\"chest\")\nelif biceps == max([chest, biceps, back]):\n print(\"biceps\")\nelse:\n print(\"back\")\n \t\t\t \t\t\t\t \t\t \t \t\t\t \t \t",
"n = int(input())\r\ns = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(1, len(s)+1):\r\n if i % 3 == 1:\r\n chest += s[i-1]\r\n elif i % 3 == 2:\r\n biceps += s[i-1]\r\n elif i % 3 == 0:\r\n back += s[i-1]\r\nif back > chest and back > biceps:\r\n print('back')\r\nelif chest > back and chest > biceps:\r\n print('chest')\r\nelse:\r\n print('biceps')\r\n",
"l = [0, 0, 0]\r\nans = [\"chest\", \"biceps\", \"back\"]\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nfor i, v in enumerate(arr):\r\n l[i%3] += v\r\n\r\nprint(ans[l.index(max(l))])",
"n = int(input())\r\n\r\nl = [int(i) for i in input().split()]\r\nc=[]\r\nfor i in range(len(l)):\r\n c.append(l[i])\r\n\r\nchest=0\r\nbiceps=0\r\nback=0\r\n\r\nfor i in range(len(c)):\r\n if(i%3 == 0):\r\n chest = chest + int(c[i])\r\n elif(i%3 ==1):\r\n biceps = biceps + int(c[i])\r\n else:\r\n back = back + int(c[i])\r\n\r\n#print(max(chest,biceps,back))\r\n\r\n\r\nif(max(chest,biceps,back) == chest):\r\n print(\"chest\")\r\nelif(max(chest,biceps,back) == biceps):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\nlist = [int(x) for x in input().split()]\nchest, biceps, back = 0, 0, 0\nfor i in range(n):\n if i % 3 == 0:\n chest += list[i]\n elif i % 3 == 1:\n biceps += list[i]\n else:\n back += list[i]\nif chest >= biceps and chest >= back:\n print(\"chest\")\nelif biceps >= chest and biceps >= back:\n print(\"biceps\")\nelse:\n print(\"back\")\n \t\t\t\t \t\t \t\t\t \t\t \t \t\t\t \t\t\t\t \t",
"n = int(input())\n\narr = list(map(int, input().split()))\n\n\nans = [0, 0, 0]\n\ni = 0\nflag = 0\nwhile i < n:\n if flag > 2:\n flag = 0\n\n ans[flag] += arr[i]\n\n i += 1\n flag += 1\n\nif ans[0] == max(ans):\n print(\"chest\")\nif ans[1] == max(ans):\n print(\"biceps\")\nif ans[2] == max(ans):\n print(\"back\")\n",
"n = int(input())\r\narr = input().split()\r\n\r\na = 0\r\nb = 0\r\nc = 0\r\n\r\nfor i in range(0, n):\r\n if (i % 3 == 0):\r\n arr[i] = int(arr[i])\r\n a += arr[i]\r\n if (i % 3 == 1):\r\n arr[i] = int(arr[i])\r\n b += arr[i]\r\n if (i % 3 == 2):\r\n arr[i] = int(arr[i])\r\n c += arr[i]\r\n\r\nif (a > b and a > c):\r\n print(\"chest\")\r\nelif (b > a and b > c):\r\n print(\"biceps\")\r\nelif (c > b and c > a):\r\n print(\"back\")\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchest = sum(a[0::3])\r\nbiceps = sum(a[1::3])\r\nback = sum(a[2::3])\r\nif chest == max(chest, biceps, back):\r\n\ti = 0\r\nelif biceps == max(chest, biceps, back):\r\n\ti = 1\r\nelse:\r\n\ti = 2\r\nprint(['chest','biceps','back'][i])",
"input()\r\nnums = list(map(int,input().split()))\r\np = sum(nums[::3])\r\nq = sum(nums[1::3])\r\nr = sum(nums[2::3])\r\nif max(p,q,r) == p:\r\n print('chest')\r\nelif max(p,q,r) == q:\r\n print('biceps')\r\nelse:\r\n print('back')",
"t=int(input())\ndata=list(map(int,input().split(' ')))\nif len(data)<=3:\n if max(data)==data[0]:\n print('chest')\n elif max(data)==data[1]:\n print('biceps')\n else:\n print('back')\nelse:\n a, b, c = 0, 0, 0\n d = []\n for x in range(0, len(data), 3):\n a += data[x]\n d.append(a)\n for y in range(1, len(data), 3):\n b += data[y]\n d.append(b)\n for z in range(2, len(data), 3):\n c += data[z]\n d.append(c)\n if max(d) == a:\n print('chest')\n elif max(d) == b:\n print('biceps')\n else:\n print('back')\n\n\n\n\n\n\n\n\n\t\t\t \t \t \t \t\t\t\t \t\t\t \t \t \t",
"n = int(input())\r\nl = list(map(int,input().split()))\r\na = []\r\nb = []\r\nc = []\r\n\r\nif len(l) == 2 :\r\n if max(l) == l[0]:\r\n print('chest')\r\n exit()\r\n else:\r\n print('biceps')\r\n exit()\r\n\r\nelif len(l) == 3 :\r\n if max(l) == l[0] :\r\n print('chest')\r\n exit()\r\n elif max(l) == l[1] :\r\n print('biceps')\r\n exit()\r\n else:\r\n print('back')\r\n exit()\r\n\r\nelse:\r\n a= l[::3]\r\n b = l[1::3]\r\n c = l[2::3]\r\n\r\nif sum(a) > sum(b) and sum(a) > sum(c):\r\n print('chest')\r\n exit()\r\nelif sum(b) > sum(a) and sum(b) > sum(c):\r\n print('biceps')\r\n exit()\r\nelse:\r\n print('back')\r\n",
"q=lambda:map(int,input().split())\r\nqi=lambda:int(input())\r\nqs=lambda:input().split()\r\nn=qi()\r\na=list(q())\r\n\r\nx=[sum((a[i] for i in range(0,n,3))),sum((a[i] for i in range(1,n,3))),sum((a[i] for i in range(2,n,3)))]\r\nprint(['chest','biceps','back'][x.index(max(x))])",
"n = int(input())\r\na = input().split(' ')\r\nb = [int(i) for i in a]\r\nch = 0\r\nbi = 0\r\nba = 0\r\ns = []\r\ni = 0\r\nfor i in range(0,n,3):\r\n ch = ch+ b[i]\r\nfor i in range(1,n,3):\r\n bi = bi+ b[i]\r\nfor i in range(2,n,3):\r\n ba = ba+b[i]\r\ns.append(ch)\r\ns.append(bi)\r\ns.append(ba)\r\nif max(s) == s[0]:\r\n print('chest')\r\nelif max(s) == s[1]:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\na,b,c=0,0,0\r\nx=list(map(int,input().split()))\r\nfor i in range(n):\r\n if i%3==0:\r\n a+=x[i]\r\n elif i%3==1:\r\n b+=x[i]\r\n else:\r\n c+=x[i]\r\nif a==max(a,b,c):\r\n print(\"chest\")\r\nelif b==max(a,b,c):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n#c,bi,bk=0,0,0\r\na=[0]*3\r\nfor i in range(n):\r\n a[i%3]+=l[i]\r\nif a[0]>a[1] and a[0]>a[2]:\r\n print(\"chest\")\r\nelif a[1]>a[0] and a[1]>a[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"a = int(input())\r\nb = list(map(int, input().split()))\r\n\r\nchest = 0\r\nbiceps = 0 \r\nback = 0\r\nfor c in range(a):\r\n c += 1\r\n if(c%3 == 1): chest += b[c-1]\r\n if(c%3 == 2): biceps += b[c-1]\r\n if(c%3 == 0): back += b[c-1]\r\n\r\nh = max(chest, biceps, back)\r\nif h == chest: \r\n print(\"chest\")\r\nelif h == biceps:\r\n print(\"biceps\")\r\nelse: \r\n print(\"back\")",
"n = int(input())\r\na = list(map(int,input().split()))\r\nch = 0\r\nbic = 0\r\nbk = 0\r\nq = 1\r\nq1 = 2\r\nfor x in range(n):\r\n if x == 0 or x%3 == 0:\r\n ch+=a[x]\r\n elif x == q:\r\n bic+=a[x]\r\n q+=3\r\n elif x == q1:\r\n bk+=a[x]\r\n q1+=3\r\nq = max(ch,bic,bk)\r\nif q == ch:\r\n print('chest')\r\nelif q == bic:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\narr = list(map(int, input().split()))\n\nchest = sum(arr[::3])\n\nbiceps = sum(arr[1::3])\n\nback = sum(arr[2::3])\n\nif chest > biceps and chest > back:\n print('chest')\nelif biceps > chest and biceps > back:\n print('biceps')\nelse:\n print('back')",
"while True:\r\n n=int(input(\"\"))\r\n if 1<=n<=20:\r\n break\r\nL=[]\r\ntest=False\r\nwhile (test==False):\r\n ch=input(\"\")\r\n L=ch.split(' ')\r\n test=True\r\n if len (L)==n:\r\n for i in range(n):\r\n if int(L[i])<1 or int(L[i])>25:\r\n test=False\r\n else:\r\n test=False\r\nfor i in range(n):\r\n L[i]=int(L[i])\r\nfor i in range(20-n):\r\n L.append(0)\r\nbiceps,back,chest=0,0,0\r\nfor i in range(3):\r\n for j in range(i,20,3):\r\n if i==0:\r\n chest+=L[j]\r\n elif i==1:\r\n biceps+=L[j]\r\n else:\r\n back+=L[j]\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelif back>biceps and back>chest:\r\n print(\"back\")\r\n \r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(len(a)):\r\n if i%3 == 0:\r\n chest += a[i]\r\n elif i%3 == 1:\r\n biceps += a[i]\r\n elif i%3 == 2:\r\n back += a[i]\r\na = max(chest,biceps,back)\r\nif a == chest:\r\n print(\"chest\")\r\nelif a == biceps:\r\n print(\"biceps\")\r\nelif a == back:\r\n print(\"back\")",
"input ()\r\na = list ( map ( int, input ().split () ) )\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range ( 0, len ( a ), 3 ) :\r\n\tchest += a[i]\r\nfor i in range ( 1, len ( a ), 3 ) :\r\n\tbiceps += a[i]\r\nfor i in range ( 2, len ( a ), 3 ) :\r\n\tback += a[i]\t\r\nif biceps < chest > back :\r\n\tprint ( 'chest' )\r\nelif chest < biceps > back :\r\n\tprint ( 'biceps' )\t\r\nelif chest < back > biceps :\r\n\tprint ( 'back' )",
"n=int(input())\r\na=list(map(int,input().split()))\r\nv=0\r\nchest=0 #Грудь\r\nbiceps=0 #Бицепс\r\nback=0 #Спина\r\n\r\nfor i in range(n):\r\n if v==0:\r\n chest+=a[i]\r\n v=1\r\n elif v==1:\r\n biceps+=a[i]\r\n v=2\r\n elif v==2:\r\n back+=a[i]\r\n v=0\r\n\r\nif chest>biceps and chest>back:\r\n print('chest')\r\nelif biceps>chest and biceps>back:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n\r\n\r\n\r\n\r\n##for i in range(n):\r\n## if a[i] in a[::3]:\r\n## chest+=a[i]\r\n## elif a[i] in a[1::3]:\r\n## biceps+=a[i]\r\n## elif a[i] in a[2::3]:\r\n## back+=a[i]\r\n## print(i)\r\n##\r\n##if chest>biceps and chest>back:\r\n## print('chest')\r\n##elif biceps>chest and biceps>back:\r\n## print('biceps')\r\n##else:\r\n## print('back')\r\n\r\n\r\n\r\n\r\n##chest=a[::3]\r\n##biceps=a[1::3]\r\n##back=a[2::3]\r\n##\r\n##ch=sum(chest)\r\n##bic=sum(biceps)\r\n##back=sum(back)\r\n##\r\n##if ch>bic and ch>back:\r\n## print('chest')\r\n##elif bic>ch and bic>back:\r\n## print('biceps')\r\n##else:\r\n## print('back')\r\n",
"n=int(input())\r\nchest=0\r\nbiceps=0\r\nback=0\r\nex=list(map(int,input().split(' ',n-1)))\r\nm=0\r\nwhile len(ex)>0:\r\n if m>=3:\r\n m-=3\r\n if m==0:\r\n chest+=ex[0]\r\n elif m==1:\r\n biceps+=ex[0]\r\n elif m==2:\r\n back+=ex[0]\r\n del ex[0]\r\n m+=1\r\nmaxx=max(chest,biceps,back)\r\nif chest==maxx:\r\n print('chest')\r\nelif biceps==maxx:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n\r\n\r\n\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc=0\r\nb=0\r\nbb=0\r\nfor i in range(n):\r\n if i%3==0:\r\n c+=a[i]\r\n if i%3==1:\r\n b+=a[i]\r\n if i%3==2:\r\n bb+=a[i]\r\nif c>b and c>bb:\r\n print(\"chest\")\r\nif b>c and b>bb:\r\n print(\"biceps\")\r\nif bb>b and bb>c:\r\n print(\"back\")\r\n ",
"n=int(input())\r\ni=0\r\nh=0\r\nj=0\r\ng=list(map(int,input().split()))\r\nif n>3:\r\n for x in range(0,len(g),3):\r\n i+=g[x]\r\n for y in range(1,len(g),3):\r\n h+=g[y]\r\n for z in range(2,len(g),3):\r\n j+=g[z]\r\nelif n==2:\r\n for x in range(0,len(g),3):\r\n i+=g[x]\r\n for y in range(1,len(g),3):\r\n h+=g[y]\r\nelif n==3:\r\n for x in range(0,len(g),3):\r\n i+=g[x]\r\n for y in range(1,len(g),3):\r\n h+=g[y]\r\n for z in range(2,len(g),3):\r\n j+=g[z]\r\nelse:\r\n for x in range(len(g)):\r\n i+=g[x]\r\nif i>h and i>j:\r\n print('chest')\r\nelif h>i and h>j:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\na = list(map(int,input().split(\" \")))\r\nl = [0]*3\r\nfor i in range(n):\r\n l[i%3] += a[i]\r\nmx = max(l)\r\nif(l[0] == mx):\r\n print(\"chest\")\r\nelif(l[1] == mx):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n \r\n",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\na1=0\r\na2=0\r\na3=0\r\nfor j in range(n):\r\n if j%3==0:\r\n a1+=a[j]\r\n elif j%3==1:\r\n a2+=a[j]\r\n else:\r\n a3+=a[j]\r\nif a1>a2 and a1>a3:\r\n print(\"chest\")\r\nelif a2>a1 and a2>a3:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\ns=list(map(int,input().split()))\r\nco=[0,0,0]\r\nfor i in range(n):\r\n i+=1\r\n if i%3==1:\r\n co[0]+=s[i-1]\r\n if i%3==2:\r\n co[1]+=s[i-1]\r\n if i%3==0:\r\n co[2]+=s[i-1]\r\nif co[0]==max(co):\r\n print(\"chest\")\r\nif co[1]==max(co):\r\n print(\"biceps\")\r\nif co[2]==max(co):\r\n print(\"back\")\r\n\r\n \r\n",
"n=int(input())\r\ndo=list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(n):\r\n if i%3==0:\r\n chest=chest+do[i]\r\n elif i%3==1:\r\n biceps=biceps+do[i]\r\n elif i%3==2:\r\n back=back+do[i]\r\n \r\nif chest>biceps and chest>back:\r\n print('chest')\r\nelif biceps>chest and biceps>back:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = input(); chest = 0; biceps = 0; back = 0\r\na = list(map(int, input().split()))\r\nfor i in range(len(a)):\r\n if i % 3 == 0:\r\n chest += a[i]\r\n elif i % 3 == 1:\r\n biceps += a[i]\r\n else:\r\n back += a[i]\r\n\r\nMax = max(chest, biceps, back)\r\nif Max == chest:\r\n print('chest')\r\nelif Max == biceps:\r\n print('biceps')\r\nelse:\r\n print('back')",
"def calculate(n, arr):\r\n s1, s2, s3 = 0, 0, 0\r\n i = 0\r\n while True:\r\n s1 = s1 + arr[i]\r\n i += 3\r\n if i > n - 1:\r\n break\r\n j = 1\r\n while True and n >= 2:\r\n s2 = s2 + arr[j]\r\n j += 3\r\n if j > n - 1:\r\n break\r\n k = 2\r\n while True and n >= 3:\r\n s3 = s3 + arr[k]\r\n k += 3\r\n if k > n - 1:\r\n break\r\n # print(s1, s2, s3)\r\n if s1 > s2 and s1 > s3:\r\n return \"chest\"\r\n if s2 > s3 and s2 > s1:\r\n return \"biceps\"\r\n if s3 > s1 and s3 > s2:\r\n return \"back\"\r\n\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n r = calculate(n, a)\r\n print(r)\r\n",
"n = int(input())\n\nls = [int(i) for i in input().split()]\n\nchest = 0\nbiceps = 0\nback = 0\nfor i in range(0,len(ls)):\n if i%3==0:\n chest+=ls[i]\n elif i%3==1:\n biceps+= ls[i]\n else:\n back+=ls[i]\n\n\nmaxval = max(chest,biceps,back)\n\nif maxval==chest:\n print(\"chest\")\nelif maxval==biceps:\n print(\"biceps\")\nelse:\n print(\"back\")",
"n = int(input())\r\ncycle = [int(x) for x in input().split()]\r\nchest = biceps = back = 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest += cycle[i]\r\n elif (i-1) % 3 == 0:\r\n biceps += cycle[i]\r\n else:\r\n back += cycle[i]\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif chest < biceps and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\na = input().split(\" \")\ncount = 0\nchest = 0\nbiceps = 0\nback = 0\n\nfor i in range(len(a)):\n count += 1\n if (count == 1):\n chest += int(a[i])\n elif (count == 2):\n biceps += int(a[i])\n elif (count == 3):\n back += int(a[i])\n if (count == 3):\n count = 0\nif (chest > biceps and chest > back ): \n print(\"chest\")\nelif (biceps > chest and biceps > back):\n print(\"biceps\")\nelif(back > chest and back > biceps):\n print(\"back\")\n \n \t \t \t \t \t \t\t \t\t\t\t \t \t\t \t",
"a=int(input())\n\nb=list(map(int,input().split()))\nchest=0\nbic=0\nesp1=0\notros=[]\n\n\ni=1\nfor num in b:\n if i %3 ==0:\n esp1=esp1+num\n else:\n otros.append(num)\n i+=1\nj=1\nfor num2 in otros:\n\n if j%2 ==0:\n bic=bic+num2\n else:\n chest=chest+num2\n j+=1\n \nif chest > bic and chest > esp1:\n print(\"chest\")\nelif bic > chest and bic > esp1:\n print(\"biceps\")\nelse:\n print(\"back\")\n\n \t\t \t\t\t \t\t \t\t\t \t \t\t\t\t\t \t\t\t",
"n = int(input())\r\nexcercises_list = list(map(int, input().split()))\r\n\r\nchest_excercises = sum(excercises_list[::3])\r\nbiceps_excercises = sum(excercises_list[1::3])\r\nback_excercises = sum(excercises_list[2::3])\r\n\r\nmax_excercises = max([chest_excercises, biceps_excercises, back_excercises])\r\n\r\nif max_excercises == chest_excercises:\r\n print('chest')\r\n\r\nelif max_excercises == biceps_excercises:\r\n print('biceps')\r\n\r\nelse:\r\n print('back')\r\n\r\n",
"n=int(input())\r\nk=list(map(int,input().split()))\r\nc,b,ba=0,1,2\r\ns,bi,bc=0,0,0\r\nfor i in range(n):\r\n if c>=n:\r\n break\r\n else:\r\n s+=k[c]\r\n c+=3\r\nfor i in range(n):\r\n if b>=n:\r\n break\r\n else:\r\n bi+=k[b]\r\n b+=3\r\nfor i in range(n):\r\n if ba>=n:\r\n break\r\n else:\r\n bc+=k[ba]\r\n ba+=3\r\nif s>bi and s>bc:\r\n print('chest')\r\nelif bi>s and bi>bc:\r\n print('biceps')\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\ncounta=0\r\ncountb=0\r\ncountc=0\r\nfor i in range(0,n,3):\r\n counta+=a[i]\r\nfor i in range(1,n,3):\r\n countb+=a[i] \r\nfor i in range(2,n,3):\r\n countc+=a[i] \r\nans = max(counta,countb,countc)\r\nif ans==counta:\r\n print(\"chest\")\r\nelif ans==countb:\r\n print(\"biceps\")\r\nelif ans==countc:\r\n print(\"back\") ",
"n = int(input())\r\ns = list(map(int,input().split()))\r\na=b=c=0\r\nfor i in range(n):\r\n\tif i%3==0:\r\n\t\ta+=s[i]\r\n\telif (i-1)%3==0 and i>=1:\r\n\t\tb+=s[i]\r\n\telif (i-2)%3==0 and i>=2:\r\n\t\tc+=s[i]\r\nif a==max(a,b,c):\r\n\tprint('chest')\r\nelif b==max(a,b,c):\r\n\tprint('biceps')\r\nelse:\r\n\tprint('back')",
"class CodeforcesTask255ASolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.tasks = []\n\n def read_input(self):\n self.n = int(input())\n self.tasks = [int(x) for x in input().split(\" \")]\n\n def process_task(self):\n res = [0] * 3\n for x in range(self.n):\n res[x % 3] += self.tasks[x]\n self.result = [\"chest\", \"biceps\", \"back\"][res.index(max(res))]\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask255ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nch = sum(l[::3])\r\nbi = sum(l[1::3])\r\nba = sum(l[2::3])\r\nif ch>bi and ch>ba:\r\n print(\"chest\")\r\nelif bi>ba and bi>ch:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"count1=0\r\ncount2=0\r\ncount3=0\r\nv1=0\r\nv2=1\r\n\r\nz=int(input()) \r\nx=list(map(int,input().split())) \r\nfor c in range(z):\r\n \r\n \r\n if c==v1:\r\n count1+=x[c]\r\n v1+=3\r\n elif c==v2:\r\n count2+=x[c]\r\n v2+=3\r\n else: \r\n count3+=x[c] \r\n#print('count1',count1) \r\n#print('count2',count2) \r\n#print('count3',count3) \r\n \r\nif count1>count2 and count1>count3:\r\n print(\"chest\")\r\nelif count2>count1 and count2>count3: \r\n print( \"biceps\") \r\nelse:\r\n print(\"back\") \r\n ",
"n=int(input())\r\ns=input()\r\nl=s.split()\r\nl=[int(i) for i in l]\r\nc=[]\r\nb=[]\r\nba=[]\r\nfor i in l[::3]:\r\n c.append(i)\r\nfor i in l[1::3]:\r\n b.append(i)\r\nfor i in l[2::3]:\r\n ba.append(i)\r\nif sum(c)>sum(b) and sum(c)>sum(ba):\r\n print(\"chest\")\r\nelif sum(b)>sum(c) and sum(b)>sum(ba):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\ntypes = [0, 0, 0]\r\n\r\nfor i in range(n):\r\n types[i % 3] += a[i]\r\n\r\nmx = max(types)\r\nif mx == types[0]:\r\n print(\"chest\")\r\nelif mx == types[1]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\np = []\r\ncount1 = 0\r\ncount2 = 0\r\ncount3 = 0\r\nfor i in range(0,n,3):\r\n\tcount1 += l[i]\r\np.append(count1)\r\nfor j in range(1,n,3):\r\n\tcount2 += l[j]\r\np.append(count2)\r\nfor k in range(2,n,3):\r\n\tcount3 += l[k]\r\np.append(count3)\t\r\nmax_ = max(p)\r\nif max_==p[0]:\r\n\tprint(\"chest\")\t\r\nelif max_==p[1]:\r\n\tprint(\"biceps\")\r\nelif max_==p[2]:\r\n\tprint(\"back\")\t",
"n = int(input())\nexercise = list(map(int, input().split()))\nchest = 0\nbiceps = 0 \nback = 0\nfor x in range(0,n,3):\n chest += exercise[x]\nfor y in range(1,n,3):\n biceps += exercise[y]\nfor l in range(2,n,3):\n back += exercise[l]\nif chest == max(chest,biceps,back):\n print(\"chest\")\nif biceps == max(chest,biceps,back):\n print(\"biceps\")\nif back == max(chest,biceps,back):\n print(\"back\")\n\n\n\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ni=0\r\nj=1 \r\nk=2\r\nc=bcp=b=0\r\nwhile i<n or j<n or k<n:\r\n if i<n:\r\n c+=a[i]\r\n i+=3\r\n if j<n:\r\n bcp+=a[j]\r\n j+=3\r\n if k<n:\r\n b+=a[k]\r\n k+=3\r\n \r\nif c>bcp and c>b:\r\n print(\"chest\")\r\nelif bcp>c and bcp>b:\r\n print(\"biceps\")\r\nelif b>c and b>bcp:\r\n print(\"back\")",
"n=int(input())\r\narr=list(map(int,input().split()))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(1,n+1):\r\n if i%3==1:\r\n a=a+arr[i-1]\r\n elif i%3==2:\r\n b=b+arr[i-1]\r\n else:\r\n c=c+arr[i-1]\r\nif a>b and a>c:\r\n print('chest')\r\nelif b>a and b>c:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(0, n, 3):\r\n chest += arr[i]\r\nif n >= 2:\r\n for i in range(1, n, 3):\r\n biceps += arr[i]\r\nif n >= 3:\r\n for i in range(2, n, 3):\r\n back += arr[i]\r\nif max(chest, biceps, back) == chest:\r\n print('chest')\r\nif max(chest, biceps, back) == biceps:\r\n print('biceps')\r\nif max(chest, biceps, back) == back:\r\n print('back')",
"n=int(input())\nchest=0\nbiceps=0\nback=0\nline=input().split()\nif 1<=n<=20:\n for i in range(0, n, 3):\n if i<n:\n chest+=int(line[i])\n if i+1<n:\n biceps+=int(line[i+1])\n if i+2<n:\n back+=int(line[i+2])\nif chest>biceps and chest>back:\n print('chest')\nelif biceps>chest and biceps>back:\n print('biceps')\nelse:\n print('back')\n\t\t\t\t \t \t \t \t \t\t \t \t\t",
"def strongest_muscle(repeats):\r\n muscles = {}\r\n muscles['chest'] = 0\r\n muscles['biceps'] = 0\r\n muscles['back'] = 0\r\n \r\n for i in range(len(repeats)):\r\n if i % 3 == 0:\r\n muscles['chest'] += repeats[i]\r\n elif i % 3 == 1:\r\n muscles['biceps'] += repeats[i]\r\n else:\r\n muscles['back'] += repeats[i]\r\n return max(muscles, key=lambda k: muscles[k])\r\n \r\nn = int(input())\r\nprint(strongest_muscle(list(map(int, input().split()))))",
"n=int(input())\r\nx=[int(i) for i in input().split()]\r\nlength=len(x)\r\n\r\nchest=biceps=back=0\r\n\r\nfor i in range(0,length,3) :\r\n chest+=x[i]\r\n\r\nfor i in range(1,length,3) :\r\n biceps+=x[i]\r\n\r\nfor i in range(2,length,3) :\r\n back+=x[i]\r\n\r\n\r\nif chest > biceps and chest>back:\r\n print(\"chest\")\r\nif biceps>chest and biceps >back:\r\n print(\"biceps\")\r\nif back>chest and back> biceps:\r\n print(\"back\")\r\n",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nchest,biceps,back=0,0,0\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=lst[i]\r\n elif i%3==1:\r\n biceps+=lst[i]\r\n elif i%3==2:\r\n back+=lst[i]\r\nx=max(chest,biceps,back)\r\nif x==chest:\r\n print(\"chest\")\r\nelif x==biceps:\r\n print(\"biceps\")\r\nelif x==back:\r\n print(\"back\")",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int,input().split()))\r\n\r\none = 0\r\ntwo = 0\r\nthree = 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n one += a[i]\r\n if i % 3 == 1:\r\n two += a[i]\r\n if i % 3 == 2:\r\n three += a[i]\r\n\r\nif one == max(one,two,three):\r\n print('chest')\r\nif two == max(one,two,three):\r\n print('biceps')\r\nif three == max(one,two,three):\r\n print('back')",
"set = int(input())\ndata = list(map(int, input().split()))\nc = 0\nb = 0\nba = 0\nfor i in range(set):\n if i % 3 == 0:\n c += data[i]\n elif i % 3 == 1:\n b += data[i]\n else:\n ba += data[i]\nif c > b and c > ba:\n print(\"chest\")\nelif b > c and b > ba:\n print(\"biceps\")\nelse:\n print(\"back\")\n \t\t\t\t\t \t \t\t\t\t \t\t \t\t \t \t",
"n=int(input())\r\n*x,=map(int,input().split())\r\na=sum(x[::3]);b=sum(x[1::3]);c=sum(x[2::3])\r\ny=[a,b,c]\r\nif max(y)==a: print('chest')\r\nelif max(y)==b: print('biceps')\r\nelif max(y)==c: print('back')",
"n = int(input())\r\narray=list(map(int, input(). strip(). split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(n):\r\n if i % 3 == 1:\r\n biceps += array[i]\r\n if i % 3 == 2:\r\n back += array[i]\r\n if i % 3 == 0:\r\n chest += array[i]\r\nreps = [chest, biceps, back]\r\n#print(reps)\r\nindx = reps.index(max(reps))\r\n#print(indx)\r\nprint(['chest', 'biceps', 'back'][indx])\r\n\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n#Array for the muscles \r\nl1 = [0,0,0] #chest, biceps, back respectively \r\ni, j = 0, 0 \r\nwhile (i < n):\r\n l1[j] += arr[i]\r\n j += 1\r\n if j == 3:\r\n j = 0\r\n i += 1\r\n#Print for max \r\nnum = l1.index(max(l1))\r\nif num == 0:\r\n print(\"chest\")\r\nelif num == 1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"t = int(input())\r\na = list(map(int, input().split(' ')))\r\nchest = 0\r\nback = 0\r\nbiceps = 0\r\nfor i in range(t):\r\n if (i + 1) % 3 == 1:chest += a[i]\r\n elif (i + 1) % 3 == 2:biceps += a[i]\r\n else:back += a[i]\r\n\r\nl = max(chest, biceps, back)\r\n\r\nif l == chest:print('chest')\r\nelif l == back:print('back')\r\nelse:print('biceps')\r\n",
"n=int(input())\nl=list(map(int,input().split()))\nch=bi=ba=0\ni=0\nwhile i<(n//3)*3:\n\tch+=l[i]\n\tbi+=l[i+1]\n\tba+=l[i+2]\n\ti+=3\nif i+2<n:\n\tch+=l[i]\n\tbi+=l[i+1]\n\tba+=l[i+1]\nelif i+1<n:\n\tch+=l[i]\n\tbi+=l[i+1]\nelif i<n:\n\tch+=l[i]\n\t\nd={ch:\"chest\",bi:\"biceps\",ba:\"back\"}\nprint(d[max(ch,bi,ba)])",
"#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-07 23:23:10\nLastEditTime: 2021-11-07 23:41:16\nDescription: \nFilePath: CF255A.py\n'''\n\n\ndef func():\n n = int(input())\n exercises = list(map(int, input().strip().split()))\n count = {\"chest\": 0, \"biceps\": 0, \"back\": 0}\n for i in range(n):\n if i % 3 == 0:\n count[\"chest\"] += exercises[i]\n elif i % 3 == 1:\n count[\"biceps\"] += exercises[i]\n else:\n count[\"back\"] += exercises[i]\n\n maximum = -1\n for k, v in count.items():\n if v > maximum:\n name, maximum = k, v\n print(name)\n\n\nif __name__ == '__main__':\n func()\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nzero=one=two=0\r\nfor i in range(n):\r\n if i%3==0:zero+=l[i]\r\n elif i%3==1:one+=l[i]\r\n else :two+=l[i]\r\nif zero>one and zero>two:print('chest')\r\nelif one>zero and one>two:print('biceps')\r\nelif two>zero and two>one:print('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\nx,y,z=0,0,0\r\nfor i in range(0,n):\r\n\tif i%3==0:\r\n\t\tx+=a[i]\r\n\telif i%3==1:\r\n\t\ty+=a[i]\r\n\telse:\r\n\t\tz+=a[i]\r\nk=max(x,y,z)\r\nif k==x:\r\n\tprint(\"chest\")\r\nelif k==y:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")",
"n = int(input())\r\n\r\nr = input()\r\n\r\nr = [int(x) for x in r.split()]\r\n\r\nch = sum(r[::3])\r\nbi = sum(r[1::3])\r\nba = sum(r[2::3])\r\n\r\nif ch > bi and ch > ba :\r\n print (\"chest\")\r\nelif bi > ch and bi> ba:\r\n print (\"biceps\")\r\nelse:\r\n print (\"back\")\r\n\r\n \r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n \r\n\r\n\r\n \r\n\r\n \r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n \r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n",
"a={}\r\ns=['chest','biceps','back']\r\nidx=0\r\na[s[0]],a[s[1]],a[s[2]]=0,0,0\r\nk=int(input())\r\nn=list(map(int,input().split()))\r\nfor i in range(k) :\r\n a[s[idx]]+=n[i]\r\n if idx==2 :\r\n idx=-1\r\n idx+=1\r\nl=[s[0],0]\r\nfor i in s :\r\n if a[i]>l[1] :\r\n l[1]=a[i]\r\n l[0]=i\r\nprint(l[0])",
"n = int(input())\r\narr = [int(i) for i in input().split()]\r\nans = [0, 0, 0]\r\nan = ['chest', 'biceps', 'back']\r\nfor i in range(n):ans[i%3] += arr[i]\r\nprint(an[ans.index(max(ans))])",
"n = int(input())\r\nl = [int(i) for i in input().split()]\r\nc=0\r\nbi = 0\r\nba = 0\r\nfor i in range(n):\r\n if i%3 == 0:\r\n c+=l[i]\r\n elif i%3 == 1:\r\n bi+=l[i] \r\n elif i%3 == 2:\r\n ba+=l[i] \r\nif max(c,bi,ba) == c:\r\n print(\"chest\")\r\nelif max(c,bi,ba) == bi:\r\n print(\"biceps\")\r\nelif max(c,bi,ba) == ba:\r\n print(\"back\")",
"n=int(input())\nlstx=[i for i in input().split()]\nlst=[int(i) for i in lstx]\ncst=0\nbk=0\nby=0\nfor i in range(len(lst)):\n if i%3==0 or i==0:\n cst+=lst[i]\n elif (i-1)%3==0:\n by+=lst[i]\n else:\n bk+=lst[i]\nif (cst > by ) and (cst > bk):\n print(\"chest\")\nelif (by > cst) and (by > bk):\n print(\"biceps\")\nelse:\n print(\"back\")\n\n\t \t\t\t\t \t \t\t\t\t\t \t\t\t\t\t \t \t \t",
"n = int(input())\na = input().split()\n\nfor i in range(len(a)):\n a[i] = int(a[i])\n\nchest = 0\nbiceps = 0\nback = 0\n\nfor i in range(len(a)):\n if i % 3 == 0:\n chest += a[i]\n elif i % 3 == 1:\n biceps += a[i]\n elif i % 3 == 2:\n back += a[i]\n\nstrongest_muscle = max(chest, biceps, back)\n\nif strongest_muscle == chest:\n print('chest')\nelif strongest_muscle == biceps:\n print('biceps')\nelse:\n print('back')",
"n = int(input())\r\na = list(map(int, input().split()))\r\nc = [sum(a[i::3]) for i in range(3)]\r\nif c[0] > c[1] and c[0] > c[2]:\r\n print(\"chest\")\r\nelif c[1] > c[0] and c[1] > c[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))[:n]\r\nchest=0\r\nbiceps=0\r\nback=0\r\na=0\r\nb=1\r\nc=2\r\nfor i in range(len(l)):\r\n if a<len(l):\r\n chest=chest+l[a]\r\n else:\r\n break\r\n if b<len(l):\r\n biceps=biceps+l[b]\r\n else:\r\n break\r\n if c<len(l):\r\n back=back+l[c]\r\n else:\r\n break\r\n a=a+3\r\n b=b+3\r\n c=c+3\r\nf=max(chest,biceps)\r\nd=max(f,back)\r\nif d==chest:\r\n print(\"chest\")\r\nelif d==biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = input()\r\ns = list(map(int, input().split()))\r\n\r\nchest = sum(s[0::3])\r\nbiceps = sum(s[1::3])\r\nback = sum(s[2::3])\r\n\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps > chest and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"x = int(input())\ny = input()\ny = y.split(' ')\nch = 0\nbi = 0\nba = 0\nfor i in range(x):\n if i in [0,3,6,9,12,15,18]:\n ch+=int(y[i])\n elif i in [1,4,7,10,13,16,19]:\n bi +=int(y[i])\n elif i in [2,5,8,11,14,17]:\n ba +=int(y[i])\nif ch > bi and ch > ba:\n print('chest')\nelif bi > ch and bi > ba:\n print('biceps')\nelif ba > bi and ba > ch:\n print('back')\n\n\t\t\t \t \t\t\t \t \t \t \t\t \t\t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\nmoo = 0\r\npor = 0\r\nblu = 0\r\nfor i in range(len(a)):\r\n if i % 3 == 0:\r\n moo += a[i]\r\n elif i % 3 == 1:\r\n por += a[i]\r\n else:\r\n blu += a[i]\r\nif moo > por and moo > blu:\r\n print(\"chest\")\r\nelif por > moo and por > blu:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ncounts = {\"chest\": 0, \"biceps\": 0, \"back\": 0}\r\nmuscle = \"chest\"\r\n\r\nfor reps in a:\r\n if muscle == \"chest\":\r\n counts[\"chest\"] += reps\r\n muscle = \"biceps\"\r\n\r\n elif muscle == \"biceps\":\r\n counts[\"biceps\"] += reps\r\n muscle = \"back\"\r\n\r\n elif muscle == \"back\":\r\n counts[\"back\"] += reps\r\n muscle = \"chest\"\r\n\r\nprint(max(counts, key=counts.get))",
"n=int(input())\r\nalist=list(map(int,input().split()))\r\nsumc=0\r\nsumb=0\r\nsumbk=0\r\nfor i in range(0,n,3):\r\n sumc+=alist[i]\r\nif(n>1):\r\n for j in range(1,n,3):\r\n sumb+=alist[j]\r\n if(n>2):\r\n for i in range(2,n,3):\r\n sumbk+=alist[i] \r\nsumf=(max(sumc,sumb,sumbk))\r\nif(sumf==sumc):\r\n print(\"chest\")\r\nelif(sumf==sumb):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"import sys\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nx, y, z = 0, 0, 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n x += a[i]\r\n elif i % 3 == 1:\r\n y += a[i]\r\n else:\r\n z += a[i]\r\n \r\nif x > y and x > z:\r\n print(\"chest\")\r\nelif y > x and y > z:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n'''6\r\n2 1 4 3 6 5\r\n''' \r\n\r\n\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nchest = []\r\nbiceps = []\r\nback = []\r\ncnt = 1\r\nfor i in range(len(l)):\r\n if cnt % 3 == 1:\r\n chest.append(l[i])\r\n cnt += 1\r\n elif cnt % 3 == 2:\r\n biceps.append(l[i])\r\n cnt += 1\r\n else:\r\n back.append(l[i])\r\n cnt += 1\r\nif sum(chest) > sum(biceps) and sum(chest) > sum(back):\r\n print(\"chest\")\r\nelif sum(biceps) > sum(chest) and sum(biceps) > sum(back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\narr=[int(x) for x in input().split()]\r\nsum1=0\r\nsum2=0\r\nsum3=0\r\nfor i in range(0,len(arr),3):\r\n sum1+=arr[i]\r\nfor j in range(1,len(arr),3):\r\n sum2+=arr[j]\r\nfor k in range(2,len(arr),3):\r\n sum3+=arr[k]\r\nif sum1 > sum2 and sum1>sum3:\r\n print(\"chest\")\r\nelif sum2>sum1 and sum2 >sum3:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"if __name__==\"__main__\":\r\n a = [0, 0, 0]\r\n b = [\"chest\", \"biceps\", \"back\"]\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n for i in range(n):\r\n a[i % 3] += l[i]\r\n print(b[a.index(max(a))])",
"\"\"\"\r\n@auther:Abdallah_Gaber \r\n\"\"\"\r\nn = int(input())\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nlst = [int(x) for x in input().split()]\r\nchest += sum(lst[0::3])\r\nbiceps += sum(lst[1::3])\r\nback += sum(lst[2::3])\r\nk = max(chest,biceps,back)\r\n\r\nif k == chest:\r\n print(\"chest\")\r\nelif k == biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=[int(i) for i in input().split()]\r\na=[0,0,0]\r\nfor i in range(n):\r\n if i%3==0:\r\n a[0]+=l[i]\r\n if i%3==1:\r\n a[1]+=l[i]\r\n if i%3==2:\r\n a[2]+=l[i]\r\nif a.index(max(a))==0:\r\n print(\"chest\")\r\nif a.index(max(a))==1:\r\n print(\"biceps\")\r\nif a.index(max(a))==2:\r\n print(\"back\") \r\n ",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=0\r\nt=0\r\np=0\r\nm=[]\r\nfor i in l[0:n:3]:\r\n s=s+i\r\nm.append(s)\r\nfor i in l[1:n:3]:\r\n t=t+i\r\nm.append(t)\r\nfor i in l[2:n:3]:\r\n p=p+i\r\nm.append(p)\r\nx=m.index(max(m))\r\nif x==0:\r\n print(\"chest\")\r\nelif x==1:\r\n print(\"biceps\")\r\nelif x==2:\r\n print(\"back\")",
"n = int(input())\r\nl = list(map(int,input().split()))\r\ni = 0\r\nc = bi = b = 0\r\nfor i in range(0,n,3):\r\n c += l[i]\r\nfor i in range(1,n,3):\r\n bi += l[i]\r\nfor i in range(2,n,3):\r\n b += l[i]\r\n\r\nif c == max(c,bi,b):\r\n print('chest')\r\nelif bi == max(c,bi,b):\r\n print('biceps')\r\nelse:\r\n print('back')\r\n ",
"n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nturn = [\"chest\",\"biceps\",\"back\"]*20\r\nfor i in range(n):\r\n s = turn[i]\r\n if s == \"chest\":\r\n chest+=a[i]\r\n elif s == \"biceps\":\r\n biceps+=a[i]\r\n elif s == \"back\":\r\n back += a[i]\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif back>biceps and back>chest:\r\n print(\"back\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\n",
"import sys\r\n\r\ndef main():\r\n l = list(map(int, sys.stdin.read().strip().split('\\n')[1].split()))\r\n d = {'chest': sum(l[::3]), 'biceps': sum(l[1::3]), 'back': sum(l[2::3])}\r\n return max(d, key=d.get)\r\n \r\nprint(main())",
"import decimal\r\nimport random\r\n\r\nx=int(input())\r\nworkout=[]\r\nworkout = list(map(int, input().split()))\r\nfor i in range(x,20,1):\r\n workout.append(0)\r\n\r\n\r\nchest=0\r\nbiceps=0\r\nback=0\r\n\r\nfor a in range(0,20,3):\r\n chest=chest+workout[a]\r\n\r\nfor b in range(1,20,3):\r\n biceps=biceps+workout[b]\r\n\r\n\r\nfor c in range(2,20,3):\r\n back=back+workout[c]\r\n\r\nlist=[chest,biceps,back]\r\nind=list.index(max(list))\r\nif ind==0: print(\"chest\")\r\nelif ind==1: print(\"biceps\")\r\nelse: print(\"back\")\r\n\r\n\r\n\r\n",
"n = int(input())\r\ne = list(map(int, input().split()))\r\nch = sum(e[::3])\r\nbi = sum(e[1::3])\r\nba = sum(e[2::3])\r\n\r\nm = max(ch, bi, ba)\r\n\r\nif m == ch: print(\"chest\")\r\nelif m == bi: print(\"biceps\")\r\nelse: print(\"back\")\r\n",
"input()\r\nl=list(map(int,input().split()))\r\nc=0\r\nb=0\r\nback=0\r\nturn=1\r\nfor i in l:\r\n if(turn==1):\r\n turn=2\r\n c+=i\r\n elif(turn==2):\r\n turn = 3\r\n b += i\r\n elif (turn == 3):\r\n turn = 1\r\n back += i\r\nif(c>b and c>back):\r\n print(\"chest\")\r\nelif(b>c and b>back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\ns = list(map(int, input().split(\" \")))\r\nche = 0\r\nbi = 0\r\nbac = 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n che += s[i]\r\n elif i % 3 == 1:\r\n bi += s[i]\r\n else:\r\n bac += s[i]\r\nif che >= bac and che >= bi:\r\n print(\"chest\")\r\nelif bac >= che and bac >= bi:\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")\r\n",
"input()\r\nx = 0\r\ny = 0\r\nz = 0\r\ni = 0\r\nfor e in map(int,input().split()):\r\n if i%3 == 0:\r\n x+=e\r\n elif i%3 == 1:\r\n y+=e\r\n else:\r\n z+=e\r\n i+=1\r\nm = max(x,y,z)\r\nif x == m:\r\n print(\"chest\")\r\nelif y == m:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\narr = [int(i) for i in input().split()]\r\nc_count = 0\r\nb_count = 0\r\nba_count = 0\r\nchest = True\r\nbiceps = False\r\nback = False\r\n\r\nfor i in range(n):\r\n if chest:\r\n c_count += arr[i]\r\n chest = False\r\n biceps = True\r\n back = False\r\n continue\r\n if biceps:\r\n b_count += arr[i]\r\n biceps = False\r\n chest = False\r\n back = True\r\n continue\r\n if back:\r\n ba_count += arr[i]\r\n chest = True\r\n back = False\r\n biceps = False\r\n continue\r\nans = max(c_count,b_count,ba_count)\r\nif ans == c_count:\r\n print(\"chest\")\r\nelif ans == b_count:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"def solve(n, t):\r\n\r\n chest = sum(t[0::3])\r\n biceps = sum(t[1::3])\r\n back = sum(t[2::3])\r\n\r\n maxExercise = \"chest\"\r\n\r\n if biceps > chest and biceps > back:\r\n maxExercise = \"biceps\"\r\n elif back > chest and back > biceps:\r\n maxExercise = \"back\"\r\n\r\n return maxExercise\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n t = list(map(int, input().split()))\r\n print(solve(n, t))\r\n",
"from collections import defaultdict\r\ndef solution():\r\n n = int(input())\r\n arr = [int(x) for x in input().split(' ')]\r\n t = ['chest', 'biceps', 'back']\r\n i = 0\r\n d = defaultdict(int)\r\n for x in arr:\r\n if i == 3:\r\n i = 0\r\n d[t[i]] += x\r\n i += 1\r\n print(max(d, key=lambda x: d[x]))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n solution()\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns_g=[]\r\ns_b=[]\r\ns_s=[]\r\nfor i in range(1,n+1):\r\n #print(i) 1-7\r\n if i%3==1:\r\n s_g.append(a[i-1])\r\n elif i%3==2:\r\n s_b.append(a[i-1])\r\n elif i%3==0:\r\n s_s.append(a[i-1])\r\n\r\nif sum(s_g)>sum(s_b) and sum(s_g)>sum(s_s):\r\n print('chest')\r\nelif sum(s_b)>sum(s_g) and sum(s_b)>sum(s_s):\r\n print('biceps')\r\nelse:\r\n print('back')",
"input()\nl1 = [int(i) for i in input().split()]\nchest = sum(l1[::3])\nbiceps = sum(l1[1::3])\nback = sum(l1[2::3])\nif chest >= biceps and chest >= back:\n\tprint('chest')\nelif biceps >= chest and biceps >= back:\n\tprint('biceps')\nelse:\n\tprint('back')\n\n\t \t \t \t\t \t \t \t\t\t\t\t \t",
"a = int(input())\nb =[ int(x) for x in input().split()]\n\nche = bic = bac = 0\n\n#==============================================\n\nfor i in range(0, len(b), 3):\n che += b[i]\nfor i in range(1, len(b), 3):\n bic += b[i]\nfor i in range(2, len(b), 3):\n bac += b[i]\n\n#==============================================\n\nx = max(che, bic, bac)\n\nif x == che:\n print(\"chest\")\nelif x == bic:\n print(\"biceps\")\nelif x == bac:\n print(\"back\")\n \t \t\t \t\t\t\t\t \t\t \t \t\t\t\t\t \t\t \t\t",
"n = int(input())\r\narr = list(map(int, input().split()[:n]))\r\nchest = arr[::3]\r\nbiceps = arr[1::3]\r\nback = arr[2::3]\r\nif sum(chest) > sum(biceps) and sum(chest)>sum(back):\r\n print(\"chest\")\r\nelif sum(biceps) > sum(chest) and sum(biceps)> sum(back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n, a = int(input()), (int(i) for i in input().split())\nres = [0, 0, 0]\nfor i, e in enumerate(a):\n res[i % 3] += e\nres = \"chest\" if res[0] == max(res) else \"biceps\" if res[1] == max(res) else \"back\"\nprint(res)\n",
"n=int(input())\na=list(map(int,input().split()))\nx=y=z=0\nfor i in range(n):\n\tif i%3==0:\n\t\tx+=a[i]\n\telif i%3==1:\n\t\ty+=a[i]\n\telif i%3==2:\n\t\tz+=a[i]\nt=max(x,y,z)\nif x==t:\n\tprint(\"chest\")\nelif y==t:\n\tprint(\"biceps\")\nelif z==t:\n\tprint(\"back\")\n",
"chest = 0\r\nbiceps = 0\r\nback = 0\r\nt = int(input())\r\nk = [int(a) for a in input().split()]\r\nc = 'c'\r\nfor i in k:\r\n if c == 'c':\r\n chest += i\r\n c = 'bi'\r\n continue\r\n if c == 'bi':\r\n biceps += i\r\n c = 'ba'\r\n continue\r\n back += i\r\n c = 'c'\r\nif chest > max(biceps, back):\r\n print('chest')\r\n exit()\r\nif biceps > max(chest, back):\r\n print('biceps')\r\n exit()\r\nprint('back')",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nchest=0\r\nbicep=0\r\nback=0\r\nfor i in range(len(a)):\r\n if i%3==0:\r\n chest+=a[i]\r\n if i%3==1:\r\n bicep+=a[i]\r\n if i%3==2:\r\n back+=a[i]\r\np=max(chest,bicep,back)\r\nif chest==p:\r\n print('chest')\r\nelif bicep==p:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n\r\n",
"import math\nn = int(input())\n\nchoco = [int(x) for x in input().split()]\n\nchest = 0\nbiceps = 0\nback = 0\nfor i in range(0,len(choco),3):\n chest = chest+choco[i]\n\nfor i in range(1,len(choco),3):\n biceps = biceps+choco[i]\n\nfor i in range(2,len(choco),3):\n back = back+choco[i]\n\n\nif chest>biceps and chest>back:\n print(\"chest\")\nelif biceps>chest and biceps>back:\n print(\"biceps\")\nelse:\n print(\"back\")\n\n \t \t\t\t\t \t \t \t\t \t \t\t",
"n = int(input())\r\ng = []\r\nx = 0\r\ny = 1\r\nz = 2\r\nc = 0\r\nb = 0\r\nba = 0\r\nfor i in range(n):\r\n a = map(int, input().split())\r\n g += a\r\n break\r\nfor u in range(len(g)):\r\n if u == x:\r\n c += g[x]\r\n x += 3\r\n elif u == y:\r\n b += g[y]\r\n y += 3\r\n elif u == z:\r\n ba += g[z]\r\n z += 3\r\nif c > b and c > ba:\r\n print('chest')\r\nelif b > c and b > ba:\r\n print('biceps')\r\nelif ba > c and ba > b:\r\n print('back')\r\n\r\n",
"\r\nn = int(input())\r\n\r\nx = [int(x) for x in input().split()]\r\n\r\nbi = ba = ch = 0\r\n\r\nfor i in range(n):\r\n if (i + 1) % 3 == 1:\r\n ch = ch + x[i]\r\n elif (i + 1) % 3 == 2:\r\n bi = bi + x[i]\r\n else:\r\n ba = ba + x[i]\r\n \r\nif max(bi , ba , ch) == bi:\r\n print('biceps')\r\nelif max(bi , ba , ch) == ba:\r\n print('back')\r\nelse:\r\n print('chest')",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ncnt = [0] * 3\r\nfor i in range(n):\r\n cnt[i % 3] += a[i]\r\n\r\nprint(['chest', 'biceps', 'back'][cnt.index(max(cnt))])\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc=a[0:n:3]\r\nbi=a[1:n:3]\r\nba=a[2:n:3]\r\nif(max(sum(c),sum(bi),sum(ba))==sum(c)):\r\n print(\"chest\")\r\nelif(max(sum(c),sum(bi),sum(ba))==sum(bi)):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\") ",
"def task(): \n n = int(input())\n list1 = list(map(int, input().split()))\n chest, biceps, back = 0, 0, 0\n \n ind, j = 0, 0 \n while(ind < n):\n if(j == 0):\n chest += list1[ind]\n elif(j == 1):\n biceps += list1[ind]\n else:\n back += list1[ind]\n \n j += 1\n if(j > 2):\n j = 0\n ind += 1\n \n if(chest >= biceps and chest >= back):\n print(\"chest\")\n elif(biceps >= chest and biceps >= back):\n print(\"biceps\")\n else:\n print(\"back\")\n \ntask() \n\t\t \t \t \t \t \t \t \t \t",
"# import sys\n# sys.stdin = open('input.txt', 'r') \n# sys.stdout = open('output.txt', 'w')\n\ndef solve(arr, n):\n\n\tr = [0]*3\n\tfor i in range(n):\n\t\tr[i%3] += arr[i] \n\t\n\tif r[0] > r[1] and r[0] > r[2]:\n\t\treturn 'chest'\n\telif r[1] > r[2] and r[1] > r[0]:\n\t\treturn 'biceps'\n\telse:\n\t\treturn 'back'\n\nn = int(input())\narr = list(map(int, input().strip().split()))\nresult = solve(arr, n)\nprint(result)",
"if __name__ == '__main__':\r\n n = int(input())\r\n s = input().split()\r\n a = [int(s[i]) for i in range(n) if i % 3 == 0]\r\n b = [int(s[i]) for i in range(n) if i % 3 == 1]\r\n c = [int(s[i]) for i in range(n) if i % 3 == 2]\r\n q = sum(a)\r\n w = sum(b)\r\n e = sum(c)\r\n m = max(q, w, e)\r\n if m == q:\r\n print(\"chest\")\r\n elif m == w:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n",
"num = int(input())\r\nlist = [int(x) for x in input().split(\" \")]\r\ndic = {\"chest\": 0, \"biceps\":0, \"back\":0}\r\nfor i in range(num):\r\n if i%3 == 0:\r\n dic[\"chest\"]+=list[i]\r\n elif i%3 == 1:\r\n dic[\"biceps\"]+=list[i]\r\n else:\r\n dic[\"back\"]+=list[i]\r\n\r\nprint(max(dic, key=dic.get))",
"n = int(input())\r\nlst = [int(x) for x in input().split()]\r\nchest, biceps, back = 0, 0, 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest += lst[i]\r\n elif i % 3 == 1:\r\n biceps += lst[i]\r\n else:\r\n back += lst[i]\r\nmx = max(chest, biceps, back)\r\nif mx == chest:\r\n print(\"chest\")\r\nelif mx == biceps:\r\n print(\"biceps\")\r\nelse:\r\n print('back')\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nbi=0\r\nba=0\r\nfor i in range(0,n,3):\r\n c=c+l[i]\r\n if(i+1 < n):\r\n bi=bi+l[i+1]\r\n if(i+2 <n):\r\n ba=ba+l[i+2]\r\nif(c>bi and c>ba):\r\n print(\"chest\")\r\nelif(bi>c and bi>ba):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\na = list(map(int, input().split()))\r\nbiceps = back = chest = 0\r\nfor i in range(n):\r\n\tif i%3==0:\r\n\t\tchest+=a[i]\r\n\telif i%3==1:\r\n\t\tbiceps+=a[i]\r\n\telse:\r\n\t\tback+=a[i]\r\nif max(max(chest, biceps), back) == chest:\r\n\tprint(\"chest\")\r\nelif max(max(chest, biceps), back) == biceps:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nq=[1,4,7,10,13,16,19,22,25]\r\nw=[2,5,8,11,14,17,20,23]\r\ne=[3,6,9,12,15,18,21,24]\r\nk=1\r\ng=0\r\nb=0\r\ns=0\r\nfor i in a:\r\n if k in q:\r\n g+=i\r\n elif k in w:\r\n b+=i\r\n elif k in e:\r\n s+=i\r\n k+=1\r\nif g==max(g,b,s):\r\n print('chest')\r\nelif b==max(g,b,s):\r\n print('biceps')\r\nelif s==max(g,b,s):\r\n print('back')",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nchest=sum(arr[::3])\r\nbisecp=sum(arr[1::3])\r\nloda=sum(arr[2::3])\r\nif max(chest,bisecp,loda)==chest:\r\n print(\"chest\")\r\nelif max(chest,bisecp,loda)==loda:\r\n print(\"back\")\r\nelse :\r\n print(\"biceps\")\r\n ",
"# 0 + a3 = p,a = i%3==0\n# 1 + a3 = p,(i-1)%3==0\n# 2 +a3 = p,(i-2)%3==0\nn = int(input())\na = list(map(int, input().split()))\nchest = 0\nbicep = 0\nback = 0\nfor i in range(n):\n if i % 3 == 0:\n chest += a[i]\n elif (i - 1) % 3 == 0:\n bicep+=a[i]\n elif (i - 2) % 3 == 0:\n back += a[i]\nif bicep > chest and bicep > back:\n print(\"biceps\")\nelif chest > bicep and chest > back:\n print(\"chest\")\nelse:\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nif(sum(a[0:len(a):3])>sum(a[2:len(a):3])):\r\n\tif(sum(a[0:len(a):3])>sum(a[1:len(a):3])):\r\n\t\tprint(\"chest\")\r\n\telse:\r\n\t\tprint(\"biceps\")\r\nelse:\r\n\tif(sum(a[2:len(a):3])>sum(a[1:len(a):3])):\r\n\t\tprint(\"back\")\r\n\telse:\r\n\t\tprint(\"biceps\")",
"n=int(input(\"\"))\r\na=list(map(int,input(\"\").split()))\r\nt1=0\r\nt2=0\r\nt3=0\r\nfor i in range (len(a)):\r\n if i%3==0:\r\n t1+=a[i]\r\n elif i%3==1:\r\n t2+=a[i]\r\n else:\r\n t3+=a[i]\r\nif t1==max(t2,t3,t1):\r\n print(\"chest\")\r\nelif t2==max(t3,t1,t2):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\na = [int(i) for i in input().split()]\r\nb=0\r\nc=0\r\nd=0\r\nfor i in range(0,n,3):\r\n b+=a[i]\r\nfor i in range(1,n,3):\r\n c+=a[i]\r\nfor i in range(2,n,3):\r\n d+=a[i]\r\nma=max(b, max(c,d))\r\nif ma==b:\r\n print('chest')\r\nelif ma==c:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input()) \r\nx = list(map(int, input().split(' ')[:n]))\r\n\r\nif n>=1 and n<=20:\r\n a=x[0::3]\r\n b=x[1::3]\r\n c=x[2::3]\r\n\r\nd=0\r\ne=0\r\nf=0\r\n\r\nfor i in a:\r\n if i>=1 and i<=25:\r\n d=d+i\r\nfor i in b:\r\n if i>=1 and i<=25:\r\n e=e+i\r\nfor i in c:\r\n if i>=1 and i<=25:\r\n f=f+i\r\n\r\nz=max(d,e,f)\r\n\r\nif d==z:\r\n print('chest')\r\nif e==z:\r\n print('biceps')\r\nif f==z:\r\n print('back')",
"n = int(input())\r\nnumbers= list(map(int,input().split(\" \")))\r\ni=0\r\nc1=0\r\nc2=0\r\nc3=0\r\nwhile i<len(numbers):\r\n c1+=numbers[i]\r\n i+=3\r\n\r\n\r\nj=1\r\nwhile j<len(numbers):\r\n c2+=numbers[j]\r\n j+=3\r\n\r\n\r\ng=2\r\nwhile g<len(numbers):\r\n c3+=numbers[g]\r\n g+=3\r\n\r\n\r\nmaximum = max(c1,c2,c3)\r\nif maximum == c1:\r\n print(\"chest\")\r\nelif maximum == c2:\r\n print(\"biceps\")\r\nelif maximum == c3:\r\n print(\"back\")",
"n = int(input())\r\n\r\narr = [int(i) for i in input().split(' ')]\r\n\r\ndef chunkify(lst,n):\r\n return [lst[i::n] for i in range(n)]\r\n\r\nnew_arr = chunkify(arr, 3)\r\nc = []\r\nfor i in new_arr:\r\n c.append(sum(i))\r\n\r\nif max(c) == c[0]:\r\n print('chest')\r\nelif max(c) == c[1]:\r\n print('biceps')\r\nelif max(c) == c[2]:\r\n print('back')\r\n\r\n",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\nresult = {0:0, 1:0, 2:0}\r\nj = 0\r\n\r\nfor i in nums:\r\n result[j] += i\r\n\r\n if j == 2:\r\n j = -1\r\n j += 1\r\n\r\nmaxi = -1\r\nkey = 0\r\nfor i in result:\r\n if result[i] > maxi:\r\n maxi = result[i]\r\n key = i\r\nresult = key\r\nif result == 0:\r\n print(\"chest\")\r\nelif result == 1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl1=[int(i) for i in input().split()]\r\nchest=biceps=back=0\r\nfor j in range(n):\r\n if j%3==0:\r\n chest=chest+l1[j]\r\n elif j%3==1:\r\n biceps=biceps+l1[j]\r\n else :\r\n back=back+l1[j]\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelse :\r\n print(\"back\")",
"ans = [0,0,0]\r\n#chest, biceps, back\r\n\r\nn = input()\r\narr = list(map(int, input().split()))\r\n\r\nk = 0\r\nfor i in arr:\r\n ans[k] += i\r\n if(k == 2):\r\n k = 0\r\n else:\r\n k += 1\r\n\r\nm = max(ans)\r\n\r\nif(ans[0] == m):\r\n print(\"chest\")\r\nelif(ans[1] == m):\r\n print(\"biceps\")\r\nelif(ans[2] == m):\r\n print(\"back\")\r\n",
"\r\nn=int(input())\r\ns=list(map(int,(input().rstrip().split())))\r\nc=0\r\nb=0\r\nm=0\r\nr=0\r\nq=0\r\nt=0\r\nfor i in range(n):\r\n if r==0:\r\n c=c+s[i]\r\n r=r+1\r\n elif q==0:\r\n b=b+s[i]\r\n q=q+1\r\n elif t==0:\r\n m=m+s[i]\r\n t=t+1\r\n if r==1 and q==1 and t==1 :\r\n r=0\r\n q=0\r\n t=0\r\nf=max(c,b,m)\r\nif f==c:\r\n print(\"chest\")\r\nelif f==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nchest, biceps, back = 0, 0, 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest += l[i]\r\n if i % 3 == 1:\r\n biceps += l[i]\r\n if i % 3 == 2:\r\n back += l[i]\r\nif chest > max(biceps, back):\r\n print(\"chest\")\r\nif biceps > max(chest, back):\r\n print(\"biceps\")\r\nif back > max(biceps, chest):\r\n print(\"back\")",
"# 코드포스 255A Greg's Workout\r\nimport sys\r\nput = sys.stdin.readline\r\n\r\nn = int(put())\r\na = list(map(int, put().split()))\r\ncnt = {\"chest\": 0, \"biceps\": 0, \"back\": 0}\r\nexercise = list(cnt.keys())\r\n\r\nfor i in range(n):\r\n cnt[exercise[i % 3]] += a[i]\r\n\r\nprint(max(cnt, key=cnt.get))",
"\r\nn = int(input())\r\nx = []\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\ny = list(map(int, input().split()))\r\ni = 0\r\nk = 0\r\nfor j in range(0, 3):\r\n k = j\r\n if j == 0:\r\n while k < n:\r\n chest += y[k]\r\n k += 3\r\n elif j == 1:\r\n while k < n:\r\n biceps += y[k]\r\n k += 3\r\n elif j == 2:\r\n while k < n:\r\n back += y[k]\r\n k += 3\r\n\r\nif chest < back and biceps < back:\r\n print(\"back\")\r\nelif back < chest and biceps < chest:\r\n print(\"chest\")\r\nelse:\r\n print(\"biceps\")\r\n",
"t = int(input())\r\nexer = list(map(int, input().split()))\r\nb = 0\r\nc = 0\r\nback = 0\r\nfor i in range(len(exer)):\r\n if i == 0 or i == 3 or i == 6 or i == 9 or i == 12 or i == 15 or i == 18:\r\n c += exer[i]\r\n elif i == 1 or i == 4 or i == 7 or i == 10 or i == 13 or i == 16 or i == 19:\r\n b += exer[i]\r\n elif i == 2 or i == 5 or i == 8 or i == 11 or i == 14 or i == 17 or i == 20:\r\n back += exer[i]\r\nif b > c and b > back:\r\n print('biceps')\r\nelif c > b and c > back:\r\n print('chest')\r\nelif back > b and back > c:\r\n print('back')",
"n = int(input())\r\n\r\nx = list(map(int, input().split()))\r\ny = [0]*3\r\n\r\nfor i in range(n):\r\n y[i % 3] += x[i]\r\n\r\nif y[0] > y[1] and y[0] > y[2]:\r\n print(\"chest\")\r\nelif y[1] > y[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"x=int(input())\r\nz=list(map(int,input().split()))\r\nz.append(0)\r\nz.append(0)\r\na=sum(z[::3])\r\nb=sum(z[1::3])\r\nc=sum(z[2::3])\r\nif b<a>c:\r\n print(\"chest\")\r\nelif a<b>c:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n1 = int(input())\r\nn2 = input().split()\r\nlist1 = []\r\nfor i in n2:\r\n list1.append(int(i))\r\n\r\n\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(len(list1)):\r\n if i % 3 == 0:\r\n chest += list1[i]\r\n elif (i-1) % 3 == 0:\r\n biceps += list1[i]\r\n elif (i-2) % 3 ==0:\r\n back += list1[i]\r\n\r\nmax1 = max(chest,biceps,back)\r\n\r\nif chest == max1:\r\n print(\"chest\")\r\nelif biceps == max1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"import math\ndef ys():\n print(\"YES\")\ndef no():\n print(\"NO\")\nn=int(input())\nls=list(map(int,input().split()))\na=0\nfor i in range(0,n,3):\n a+=ls[i]\nb=0\nfor i in range(1,n,3):\n b+=ls[i]\nc=sum(ls)-(a+b)\nif max(a,b,c)==a:\n print(\"chest\")\nelif max(a,b,c)==b:\n print(\"biceps\")\nelse:\n print(\"back\")",
"n = int(input())\r\nexercise = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(0,len(exercise),3):\r\n # print(\"i=\",i)\r\n chest+=exercise[i]\r\nfor j in range(1, len(exercise), 3):\r\n #print(\"j=\",j)\r\n biceps+=exercise[j]\r\nfor k in range(2, len(exercise),3):\r\n #print(\"k=\", k)\r\n back+=exercise[k]\r\n\r\n#print(chest,biceps,back)\r\n\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n",
"if __name__ == '__main__':\r\n n = int(input())\r\n lst = list(map(int,input().split()))\r\n a = lst[::3]\r\n b = lst[1::3]\r\n c = lst[2::3]\r\n m = max(sum(a),sum(b),sum(c))\r\n if m == sum(a):\r\n print('chest')\r\n elif m == sum(b):\r\n print('biceps')\r\n elif m == sum(c):\r\n print('back')",
"h = {'chest':0,'biceps':0, 'back':0}\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\ni = 0\r\nwhile i < len(l):\r\n h[list(h)[i%3]] += l[i]\r\n i=i+1\r\nprint(max(zip(h.values(), h.keys()))[1])\r\n",
"input()\r\na=list(map(int, input().split()))\r\nn1,n2,n3=sum(a[0::3]),sum(a[1::3]),sum(a[2::3])\r\nc=max(n1,n2,n3)\r\nif c==n1:print('chest')\r\nelif c==n2:print('biceps')\r\nelse:print('back')",
"a = int(input())\r\nb = input().split()\r\nci = [0,3,6,9,12,15,18]\r\nbici =(1,4,7,10,13,16,19)\r\nbaci = (2,5,8,11,14,17,20)\r\nc = 0\r\nbic = 0\r\nbac = 0\r\nfor i in range(a):\r\n if i in ci:\r\n c+=int(b[i])\r\n elif i in bici:\r\n bic+=int(b[i])\r\n elif i in baci:\r\n bac+=int(b[i])\r\nz = [c,bic,bac]\r\nx = 0\r\ny = 0\r\nfor i in z:\r\n if i>x:\r\n x=i\r\nfor i in range(len(z)):\r\n if z[i] == x:\r\n y = i\r\nif y == 0:\r\n print(\"chest\")\r\nelif y == 1:\r\n print(\"biceps\")\r\nelif y == 2:\r\n print(\"back\")\r\n ",
"n = int(input())\r\narr = list(map(int,input().split()))\r\ndic = {'chest':0,'biceps':0,'back':0}\r\nfor i in range(n):\r\n if i%3==0:\r\n dic['chest'] += arr[i]\r\n elif i%3==1:\r\n dic['biceps'] += arr[i]\r\n else:\r\n dic['back'] += arr[i]\r\nmaxi = dic['chest']\r\nans = 'chest'\r\nfor i in dic:\r\n if dic[i]>maxi:\r\n maxi = dic[i]\r\n ans = i\r\nprint(ans)",
"n=int(input())\r\nx=[int(w) for w in input().split()]\r\na=sum(x[0::3])\r\nb=sum(x[1::3])\r\nc=sum(x[2::3])\r\nif max(a,b,c)==a:\r\n print('chest')\r\nelif max(a,b,c)==b:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nd=[0,0,0]\r\nk=[\"chest\",\"biceps\",\"back\"]\r\nfor i in range(len(l)):\r\n d[i%3]+=l[i]\r\n\r\nm=0\r\nfor i in range(len(d)):\r\n if d[i]>=m:\r\n m=d[i]\r\n max_index=i\r\nprint(k[max_index])",
"n=int(input())\r\nli=list(int(num) for num in input().strip().split())[:n]\r\nch=bi=ba=0\r\nfor i in range(0,n,3):\r\n ch+=li[i]\r\nfor i in range(1,n,3):\r\n bi+=li[i]\r\nfor i in range(2, n, 3):\r\n ba+=li[i]\r\ndi={ch:'chest',bi:'biceps',ba:'back'}\r\nprint(di[max(di.keys())])",
"from math import ceil, log, floor, sqrt\nimport math\t\n\t\n\t\nk = 1\t\ndef mod_expo(n, p, m):\n\t\"\"\"find (n^p)%m\"\"\"\n\tresult = 1\n\twhile p != 0:\n\t\tif p%2 == 1:\n\t\t\tresult = (result * n)%m\n\t\tp //= 2\n\t\tn = (n * n)%m\n\treturn result\n\t\ndef is_prime(n):\n\tm = 2\n\twhile m*m <= n:\n\t\tif n%m == 0:\n\t\t\treturn False\n\t\tm += 1\n\treturn True\n\t\ndef find_sum(n, a):\n\ta.insert(0, 0)\n\tfor i in range(1, n+1):\n\t\tprev = a[i] & a[i-1]\n\t\tcur = a[i] | a[i-1]\n\t\ta[i-1] = prev\n\t\ta[i] = cur\n\treturn sum(m*m for m in a)\n\ndef prin_abc(x, y, z):\n\tl = [x, y, z]\n\tl.sort()\n\tif l[1] < l[2]:\n\t\tprint(\"NO\")\n\t\treturn \n\ta = b = l[0]\n\tc = l[2]\n\tprint(\"YES\")\n\tprint(a, b, c)\n\t\ndef get_scores(n, vals):\n\tl = 0\n\tr = n-1\n\tturn = 0\n\tsereja = 0\n\tdima = 0\n\twhile l <= r:\n\t\tif vals[l] > vals[r]:\n\t\t\tcur = vals[l]\n\t\t\tl += 1\n\t\telse:\n\t\t\tcur = vals[r]\n\t\t\tr -= 1\n\t\tif turn == 0:\n\t\t\tsereja += cur\n\t\telse:\n\t\t\tdima += cur\n\t\tturn = not turn\n\tprint(sereja, dima)\n\t\t\ndef count_lamps(n, m):\n\treturn (n*m + 1)//2\n\t\ndef find_holidays(n):\n\tcnt = 2*(n//7)\n\trem = n%7\n\t#if n < 7:\n\t#\tprint(0, cnt)\n\tmx = mn = cnt\n\tif rem == 1:\n\t\tmx += 1\n\telif rem > 1:\n\t\tmx += 2\n\tif rem == 6:\n\t\tmn += 1\n\t\n\tprint(mn, mx)\n\t\ndef count_eggs(n, s, t):\n\treturn max(1, max(n-s+1, n-t+1))\n\t\t\ndef find_best(n, a):\n\tchest = 0\n\tbiceps = 0\n\tback = 0\n\tfor i in range(n):\n\t\tif i%3 == 0:\n\t\t\tchest += a[i]\n\t\telif i%3 == 1:\n\t\t\tbiceps += a[i]\t\n\t\telse:\n\t\t\tback += a[i]\n\tif chest > max(biceps, back):\n\t\tprint(\"chest\")\n\telif biceps > max(chest, back):\n\t\tprint(\"biceps\")\n\telse:\n\t\tprint(\"back\")\n\nt = 1\n#t = int(input())\nwhile t:\n\tt = t - 1\n\tk, g = 0, 0\n\tpoints = []\n\tn = int(input()) \n\t#a = input()\n\t#b = input()\n\t#s, v1, v2, t1, t2 = map(int, input().split()) \n\t#n, s, l = map(int, input().split()) \n\t#print(discover())\n\t# = map(int, input().split())\n\ta = list(map(int, input().strip().split()))[:n]\n\t#w = list(map(int, input().strip().split()))[:k]\n\t#for i in range(3):\n\t#\tx, y = map(int, input().split()) \n\t#\tpoints.append((x, y))\n\t#s = input()\n\t#if happy_trio(x, y, z, a, b, c):\n\t#\tprint(\"YES\")\n\t#else:\n\t#\tprint(\"NO\")\n\tfind_best(n, a)\n\t#print(count_eggs(n, s, l))\n",
"n = int(input())\r\nexercises = [int(i) for i in input().split()]\r\nchest = biceps = back = 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest += exercises[i]\r\n elif (i - 1) % 3 == 0:\r\n biceps += exercises[i]\r\n else:\r\n back += exercises[i]\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps > chest and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Apr 24 17:04:45 2021\r\n\r\n@author: nagan\r\n\"\"\"\r\n\r\nn = int(input())\r\ns = input().split()\r\nl = [int(i) for i in s]\r\nc = 0\r\nbi = 0\r\nba = 0\r\ncount = 0\r\nfor i in range(n):\r\n if count == 0:\r\n c += l[i]\r\n count += 1\r\n elif count == 1:\r\n bi += l[i]\r\n count += 1\r\n elif count == 2:\r\n ba += l[i]\r\n count = 0\r\nd = {c: \"chest\", bi: \"biceps\", ba: \"back\"}\r\ndi = list(d.keys())\r\ndi.sort(reverse = True)\r\nans = di[0]\r\nprint(d[ans])",
"count = int(input())\r\nmuscles = ['chest', 'biceps', 'back']\r\ntraining = [int(i) for i in input().split(' ')]\r\nsums = [0, 0, 0]\r\nfor i in range(len(training)):\r\n sums[i%3] += training[i]\r\nmaxIndex = sums.index(max(sums))\r\nprint(muscles[maxIndex])",
"n = int(input())\nA = list(map(int, input().split()))\n\ndef set_group(group):\n if group == 'chest':\n return 'biceps'\n elif group == 'biceps':\n return 'back'\n else:\n return 'chest'\ndata = {\n 'chest': 0,\n 'biceps': 0,\n 'back': 0,\n}\n\ngroup = 'chest'\nfor a in A:\n data[group] += a\n group = set_group(group)\n\nc = 0 \nresult = None\nfor key in data.keys():\n if data[key] > c:\n result = key \n c = data[key]\n\nprint(result)\n",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\na1,a2,a3=0,0,0\r\nfor i in range(0,len(a),3):\r\n a1+=a[i]\r\nfor i in range(1,len(a),3):\r\n a2+=a[i]\r\na3=sum(a)-a1-a2\r\nif max(a1,a2,a3)==a1:\r\n print('chest')\r\nelif max(a1,a2,a3)==a2:\r\n print('biceps')\r\nelse:\r\n print('back')",
"# LUOGU_RID: 101473345\nn,*a=map(int,open(0).read().split())\r\nprint(['chest','biceps','back'][max(0,1,2,key=lambda i:sum(a[i::3]))])",
"n = int(input())\r\nnum = [int(i) for i in input().split()]\r\nd = {'chest':0, 'biceps':0, 'back':0}\r\nptr,m = -1,0\r\nwhile m<n:\r\n if ptr==-1:\r\n d['chest'] += num[m]\r\n ptr+=1\r\n elif ptr==0:\r\n d['biceps'] += num[m]\r\n ptr+=1\r\n elif ptr==1:\r\n d['back'] += num[m]\r\n ptr=-1\r\n m+=1\r\nprint(sorted(d.items(), key=lambda item: item[1])[-1][0])",
"n= int(input())\na = list(map(int, input().split()))\ncount=1\nchest,biceps,back=0,0,0\nfor i in range(len(a)):\n if count==1:\n chest+=a[i]\n count+=1\n elif count==2:\n biceps+=a[i]\n count += 1\n elif count==3:\n back+=a[i]\n count =1\nif chest > biceps and chest > back:\n print('chest')\nif biceps > chest and biceps > back:\n print('biceps')\nif back > chest and back > biceps:\n print('back')\n",
"t = int(input())\r\n\r\nexe = [int(i) for i in input().split()]\r\n\r\nlis = [0,0,0]\r\n\r\nfor i,item in enumerate(exe):\r\n lis[i%3] += item\r\n\r\nprint([\"chest\",\"biceps\",\"back\"][lis.index(max(lis))])\r\n \r\n",
"a=int(input())\r\nc=0\r\nbi=0\r\nba=0\r\nq=1\r\nw=0\r\ne=0\r\ns=list(map(int,input().split()))\r\nfor i in s:\r\n if q==1:\r\n c+=i\r\n q=0\r\n w=1\r\n continue\r\n if w==1:\r\n bi+=i\r\n w=0\r\n e=1\r\n continue\r\n if e==1:\r\n ba+=i\r\n e=0\r\n q=1\r\n continue\r\nif bi>ba and bi>c:\r\n print('biceps')\r\nelif ba>bi and ba>c:\r\n print('back')\r\nelse:\r\n print('chest')\r\n",
"a=int(input())\r\nl=list(map(int,input().split()))\r\nch=0\r\nbic=0\r\nbac=0\r\ncount=1\r\nfor i in range(a):\r\n if count%3==0:\r\n bac+=l[i]\r\n elif count%2==0:\r\n bic+=l[i]\r\n else:\r\n ch+=l[i]\r\n count+=1\r\n if count==4:\r\n count=1\r\ne=max([bac,bic,ch])\r\nif e==bac:\r\n print('back')\r\nelif e==bic:\r\n print('biceps')\r\nelse:\r\n print('chest')\r\n\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nexercices = [0,0,0]\r\nfor i in range(len(l)):\r\n exercices[i%3] += l[i]\r\nex_n = [\"chest\", 'biceps', 'back']\r\nmax_i = exercices.index(max(exercices))\r\nprint(ex_n[max_i])",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchest = sum(a[::3])\r\nbiceps = sum(a[1::3])\r\nback = sum(a[2::3])\r\nif max(chest, biceps, back) == chest:\r\n print('chest')\r\nelif max(chest, biceps, back) == biceps:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\na = list(map(int, input().split()))\r\nl = [sum(a[i::3]) for i in [0,1,2] ]\r\nprint([\"chest\", \"biceps\", \"back\"][l.index(max(l))])",
"n=int(input())\r\na=input()\r\na=a.split()\r\nfor i in range(n):\r\n a[i]=int(a[i])\r\nbiceps=0\r\nback=0\r\nchest=0\r\nfor i in range(n):\r\n if(i%3==1):\r\n biceps+=a[i]\r\n elif(i%3==2):\r\n back+=a[i]\r\n else:\r\n chest+=a[i]\r\nif(biceps>back and biceps>chest):\r\n print(\"biceps\")\r\nelif(biceps<back and chest<back):\r\n print(\"back\")\r\nelse:\r\n print(\"chest\")",
"v=int(input())\na = [int(x) for x in input().split()]\nb = [sum(a[::3]), sum(a[1::3]), sum(a[2::3])]\nc = ['chest', 'biceps', 'back']\nprint(c[b.index(max(b))])\n\t \t\t \t \t\t \t\t \t \t \t \t \t\t\t\t",
"n=int(input())\r\nl=input().split()\r\nback,chest,biceps=0,0,0\r\nfor i in range (len(l)):\r\n if (i+1)%3==0:\r\n back+=int(l[i])\r\n elif (i+1)%3==1:\r\n chest+=int(l[i])\r\n else:\r\n biceps+=int(l[i])\r\nc=max(back,chest,biceps)\r\nif(c==back):\r\n print(\"back\")\r\nelif(c==chest):\r\n print(\"chest\")\r\nelse:\r\n print(\"biceps\")\r\n",
"n = int(input())\r\nseries = input().split()\r\nexercices = {\"chest\": 0, \"biceps\": 0, \"back\": 0}\r\nc = 0\r\nfor serie in series:\r\n if c == 0:\r\n exercices[\"chest\"] += int(serie)\r\n c += 1\r\n elif c == 1:\r\n exercices[\"biceps\"] += int(serie)\r\n c += 1\r\n elif c == 2:\r\n exercices[\"back\"] += int(serie)\r\n c = 0\r\nprint(max(exercices, key=exercices.get))\r\n",
"import sys\r\nrln=sys.stdin.buffer.readline\r\nrl=lambda:rln().rstrip(b'\\r\\n').rstrip(b'\\n')\r\nri=lambda:int(rln())\r\nrif=lambda:[*map(int,rln().split())]\r\nrt=lambda:rl().decode()\r\nrtf=lambda:rln().decode().split()\r\ninf=float('inf')\r\ndir4=[(-1,0),(0,1),(1,0),(0,-1)]\r\ndir8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]\r\nYES,NO,Yes,No,yes,no='YES','NO','Yes','No','yes','no'\r\n\r\nn=ri()\r\na=rif()\r\ncnt=[0,0,0]\r\nfor i in range(n):\r\n cnt[i%3]+=a[i]\r\nprint('chest biceps back'.split()[\r\n cnt.index(max(cnt))\r\n])\r\n",
"def li():\r\n return list(map(int,input().split()))\r\ndef gi(n):\r\n return [list(map(int,input().split())) for _ in range(n)]\r\n\r\n# File input\r\n\r\n# import sys\r\n# sys.stdin = open('user.txt','r')\r\n\r\nx = y = z = 0\r\nn = int(input())\r\nl = li()\r\n\r\nfor i in range(0,n,3):\r\n x += l[i]\r\nfor i in range(1,n,3):\r\n y += l[i]\r\nfor i in range(2,n,3):\r\n z += l[i]\r\n\r\nif max(x,y,z) == x:\r\n print('chest')\r\nelif max(x,y,z) == y:\r\n print('biceps')\r\nelse:\r\n print('back')",
"k=int(input())\r\nl1=[int(i) for i in input().split()]\r\n# p={\"chest\":0,\"biceps\":0,\"back\":0}\r\n# for i in l1:\r\n# if i//3==1:\r\n# p[\"chest\"]+=i\r\n# elif i//3==:\r\n# p[\"biceps\"]+=i\r\n# else:\r\n# p[\"back\"]+=i\r\np,q,r=0,0,0\r\nfor i in range(0,k):\r\n if i%3==0:\r\n p=p+l1[i]\r\n elif i%3==1:\r\n q=q+l1[i]\r\n else:\r\n r=r+l1[i]\r\nif max(p,q,r)==p:\r\n print(\"chest\")\r\nelif max(p,q,r)==q:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"a=int(input())\r\nn=input().split()\r\nchest=0; biceps=0; back=0\r\nfor i in range(a):\r\n if i%3==0: chest+=int(n[i])\r\n elif i%3==1: biceps+=int(n[i])\r\n else: back+=int(n[i])\r\nif(chest>=biceps and chest>=back): print('chest')\r\nelif(biceps>=chest and biceps>=back): print('biceps')\r\nelse: print('back')",
"a,b,c = 0,0,0\r\ninput()\r\nx = list(map(int,input().split()))\r\nfor i in range(0,len(x),3):\r\n a+=x[i]\r\nfor i in range(1,len(x),3):\r\n b+=x[i]\r\nfor i in range(2,len(x),3):\r\n c+=x[i]\r\nif a > b and a > c:\r\n print('chest')\r\nif b > a and b > c:\r\n print('biceps')\r\nif c > a and c > b:\r\n print('back')",
"import sys\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inps():\r\n return(input())\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n\r\nn = inp()\r\nnums = inlt()\r\n\r\nexercise = [0,0,0]\r\n\r\ni = 0\r\nfor num in nums:\r\n exercise[i] += num\r\n i = (i+1) % 3\r\n\r\nmaxEx = 0\r\nidx = -1\r\nfor i, val in enumerate(exercise):\r\n if val > maxEx:\r\n idx = i\r\n maxEx = val\r\n\r\nif idx == 0:\r\n print(\"chest\")\r\nelif idx == 1:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=[int(k) for k in input().split()]\r\nb={sum(a[0::3]):\"chest\",sum(a[1::3]):\"biceps\",sum(a[2::3]):\"back\"}\r\nprint(b[max(b)])\r\n",
"amountofexersizes = list(map(int, input().split()))\r\nexersizes = list(map(int, input().split()))\r\nh = 0\r\nbig = 0\r\nexersizes2 = [0, 0, 0]\r\ng = [2, 0, 1]\r\nfor i in exersizes:\r\n h += 1 \r\n exersizes2[g[h % 3 ]] = exersizes2[g[h % 3] ] + i\r\na = 0\r\nfor i in exersizes2:\r\n a = a+1\r\n if i > big:\r\n big = i\r\n b = a\r\nif b == 1:\r\n print(\"chest\")\r\nelif b == 2:\r\n print(\"biceps\")\r\nelif b == 3:\r\n print(\"back\")",
"n = int(input())\na = list(input().split())\nfor j in range(len(a)):\n a[j] = int(a[j])\nnum = 0\nchest = 0\nbiceps=0\nback = 0\nfor i in range(len(a)):\n num+=1\n if num == 1:\n chest +=a[i]\n if num == 2:\n biceps +=a[i]\n if num == 3:\n back+=a[i]\n num=0\nif chest > biceps and chest > back:\n print(\"chest\")\nelif biceps >chest and biceps >back:\n print(\"biceps\")\nelse:\n print(\"back\")\n\t\t\t \t \t\t\t \t \t\t \t\t \t \t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = [0] * 3\r\nfor i in range(n):\r\n b[i % 3] += a[i]\r\nif b[0] > b[1] and b[0] > b[2]:\r\n print(\"chest\")\r\nelif b[1] > b[0] and b[1] > b[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nans = [sum(l[i::3], 0) for i in range(3)]\r\nmx = ans.index(max(ans))\r\nprint('chest' if mx ==0 else 'biceps' if mx == 1 else 'back' if mx == 2 else '0')\r\n# chest = 0; ch = 0; biceps = 1; bi = 0; back = 2; ba = 0\r\n# if len(l)==1:\r\n# ch+=l[0]\r\n# elif len(l)==2:\r\n# ch+=l[0]\r\n# bi += l[1]\r\n# else:\r\n# while back< len(l):\r\n# ch += l[chest]; bi += l[biceps]; ba += l[back]; chest += 3; biceps += 3; back += 3\r\n# if chest == len(l)-1:\r\n# ch +=l[chest]\r\n# break\r\n# elif biceps == len(l)-1:\r\n# bi+=l[biceps]\r\n# break\r\n# elif back == len(l)-1:\r\n# ba+=l[back]\r\n# break\r\n#\r\n# mx = max(ch, bi, ba)\r\n# print(\"chest\" if mx ==ch else 'biceps' if mx ==bi else 'back' if mx ==ba else '0' )\r\n\r\n\r\n\r\n",
"n=int(input())\r\na=0\r\nb=0\r\nc=0\r\ns=1\r\nlist1=list(map(int,input().split()))\r\nfor i in range(n):\r\n if(s==1):\r\n a+=list1[i]\r\n elif(s==2):\r\n b+=list1[i]\r\n else:\r\n c+=list1[i]\r\n s+=1\r\n if(s>3):\r\n s=1\r\nif(a>b and a>c):\r\n print(\"chest\")\r\nelif(b>a and b>c):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"# 255A - Greg's Workout\r\nn, l, c, bi, ba = int(input()), list(map(int, input().split())), 0, 0, 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n c += l[i]\r\n elif i % 3 == 1:\r\n bi += l[i]\r\n else:\r\n ba += l[i]\r\nm = max(c, bi, ba)\r\nif c == m:\r\n print(\"chest\")\r\nelif bi == m:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(0, n, 3):\r\n chest += a[i]\r\nfor i in range(1, n, 3):\r\n biceps += a[i]\r\nfor i in range(2, n, 3):\r\n back += a[i]\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps > chest and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"int(input())\r\nlist_1= list(map(int,input().split()))\r\nc= sum([list_1[i] for i in range(len(list_1)) if i%3==0])\r\nbi= sum([list_1[i] for i in range(len(list_1)) if i%3==1])\r\nba= sum([list_1[i] for i in range(len(list_1)) if i%3==2])\r\n\r\nx= max(c, bi, ba)\r\n\r\nif x==c:\r\n print(\"chest\")\r\nelif x== bi:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"import sys\r\nimport math\r\nfrom sys import stdin, stdout\r\n# TAKE INPUT\r\ndef get_ints_in_variables():\r\n return map(int, sys.stdin.readline().strip().split())\r\ndef get_int(): return int(input())\r\ndef get_ints_in_list(): return list(\r\n map(int, sys.stdin.readline().strip().split()))\r\ndef get_list_of_list(n): return [list(\r\n map(int, sys.stdin.readline().strip().split())) for _ in range(n)]\r\ndef get_string(): return sys.stdin.readline().strip()\r\ndef main():\r\n # //Write Your Code Here\r\n n = int(input())\r\n arr = get_ints_in_list()\r\n chest = 0\r\n biceps = 0\r\n back = 0\r\n for i in range(0, n):\r\n if (i+1)%3 == 1:\r\n chest += arr[i]\r\n elif (i+1)%3 == 2:\r\n biceps += arr[i]\r\n else: # (i+1)%3 == 0\r\n back += arr[i]\r\n\r\n if chest > biceps and chest > back:\r\n print(\"chest\")\r\n elif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\n elif back > chest and back > biceps:\r\n print(\"back\")\r\n# for printing format\r\n# print(\"Case #{}: {}\".format(t+1, ans))\r\n# calling main Function\r\nif __name__ == \"__main__\":\r\n main()",
"n=input()\r\nc=[0,0,0]\r\nans=[\"chest\",\"biceps\",\"back\"]\r\nl=list(map(int,input().split()))\r\nfor i in range(int(n)):\r\n c[i%3]+=l[i]\r\nprint(ans[c.index(max(c))])\r\n ",
"import sys\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\ndef iinput(): return int(input())\r\ndef rinput(): return map(int, sys.stdin.readline().strip().split()) \r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split())) \r\n\r\n\r\nn=iinput()\r\na=list(map(int,input().split()))\r\nc=0\r\nc1=0\r\nc2=0\r\nfor i in range(n):\r\n if(i==0 or i%3==0):\r\n c+=a[i]\r\n elif(i==1 or (i-1)%3==0):\r\n c1+=a[i]\r\n elif(i==2 or (i-2)%3==0):\r\n c2+=a[i]\r\n\r\nm=max(c,c1,c2)\r\n\r\nif(m==c1):\r\n print(\"biceps\")\r\nelif(m==c):\r\n print(\"chest\")\r\nelif(m==c2):\r\n print(\"back\")",
"a = int(input())\r\nb = input().split()\r\ncount1 = 0\r\ncount2 = 0\r\ncount3 = 0\r\nfor i in range(0,a,3):\r\n count1 += int(b[i])\r\nfor i in range(1,a,3):\r\n count2 += int(b[i])\r\nfor i in range(2,a,3):\r\n count3 += int(b[i])\r\nif max(count1,count2,count3) == count1:\r\n print('chest')\r\nelif max(count1,count2,count3) == count2:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\nexe = input()\r\nexe = exe.split()\r\nexe = [int(x) for x in exe]\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nif n>=3:\r\n chest = sum(exe[0::3])\r\n biceps = sum(exe[1::3])\r\n back = sum(exe[2::3])\r\nif n==2:\r\n chest = exe[0]\r\n biceps = exe[1]\r\nif n==1:\r\n chest = exe[0]\r\nif chest>=biceps and chest>back:\r\n print('chest')\r\nif biceps>=chest and biceps>=back:\r\n print('biceps')\r\nif back>=chest and back>=biceps:\r\n print('back')",
"n=int(input())\r\nl=list(map(int,input().split(' ')))\r\na=sum(l[::3])\r\nb=sum(l[1::3])\r\nc=sum(l[2::3])\r\nif(a>b and a>c):\r\n print('chest')\r\nelif(b>a and b>c):\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc=0\r\nbi=0\r\nb=0\r\nfor i in range(1,n+1):\r\n if(i%3==1):\r\n c+=a[i-1]\r\n elif(i%3==2):\r\n bi+=a[i-1]\r\n else:\r\n b+=a[i-1]\r\nm=max(c,bi,b)\r\nif(c==m):\r\n print(\"chest\")\r\nelif(bi==m):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\na = 0\r\nb = 3\r\nwhile b < len(l) + 1:\r\n x = l[a:b]\r\n chest += x[0]\r\n biceps += x[1]\r\n back += x[2]\r\n a += 3\r\n b += 3\r\n\r\nif len(l) % 3 == 1:\r\n chest += l[-1]\r\nelif len(l) % 3 == 2:\r\n chest += l[-2]\r\n biceps += l[-1]\r\nif chest > biceps and chest > back:\r\n print('chest')\r\nelif biceps > chest and biceps > back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n=int(input())\r\na=list(map(int,input().split()))\r\nback,chest,biceps=0,0,0\r\nfor j in range(0,len(a)):\r\n if((j+1)%3==0):\r\n back=back+a[j]\r\n elif((j+1)%3==1):\r\n chest=chest+a[j]\r\n elif((j+1)%3==2):\r\n biceps=biceps+a[j]\r\nif(chest>back and chest>biceps):\r\n print(\"chest\")\r\nelif(back>chest and back>biceps):\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")\r\n \r\n ",
"length=int(input())\r\ncase=input()\r\ncaseLst=list(map(int,case.split()))\r\nchest=0\r\nback=0\r\nbiceps=0\r\nindex=0\r\nwhile(True):\r\n\tif length>index:\r\n\t\tchest+=caseLst[index]\r\n\t\tindex+=1\r\n\telse:\r\n\t\tbreak\r\n\tif length>index:\r\n\t\tbiceps+=caseLst[index]\r\n\t\tindex+=1\r\n\telse:\r\n\t\tbreak\r\n\tif length>index:\r\n\t\tback+=caseLst[index]\r\n\t\tindex+=1\r\n\telse:\r\n\t\tbreak\r\nif chest>=back and chest>=biceps:\r\n\tprint(\"chest\")\r\nelif biceps>=chest and biceps>=back:\r\n\tprint(\"biceps\")\r\nelse:\r\n\tprint(\"back\")",
"'''\r\na = int(input())\r\nfor i in range(a):\r\n n = input()\r\n if len(n)>10:\r\n print(n[0]+str(len(n)-2)+n[-1])\r\n else:\r\n print(n)\r\n\r\na = int(input())\r\ncount = 0\r\nfor i in range(a):\r\n b = input().split()\r\n count1 = 0\r\n count0 = 0\r\n for i in range(len(b)):\r\n if b[i] == \"1\":\r\n count1 += 1\r\n elif b[i] == \"0\":\r\n count0 += 1\r\n if count1 > count0:\r\n count += 1\r\nprint(count)\r\n\r\n#if a number is binary print it if not write ways to make it binary\r\na = int(input())\r\nm = 0\r\nfor i in range(a):\r\n n = input()\r\n if n.count(\"1\")+n.count(\"0\")==len(n):\r\n print(1)\r\n else:\r\n for i in n:\r\n if int(i)>m:\r\n m=int(i)\r\n print(m)\r\n\r\nn = input()\r\nc = \"\"\r\nfor i in n:\r\n if i not in c:\r\n c+=i\r\nif len(c)%2 == 0:\r\n print(\"CHAT WITH HER!\")\r\nelif len(c)%2 != 0:\r\n print(\"IGNORE HIM!\")\r\n\r\nn = input().split()\r\ncount=0\r\nb1 = int(n[0])\r\nb2 = int(n[1])\r\nwhile True:\r\n if b2>=b1:\r\n b1=b1*3\r\n b2=b2*2\r\n count+=1\r\n elif b1>b2:\r\n break\r\nprint(count)\r\n\r\nn = input().split()\r\nn1 = n[0]\r\nn2 = n[1]\r\nfor i in range(int(n2)):\r\n if n1[-1] == \"0\":\r\n n1 = int(n1)//10\r\n n1 = str(n1)\r\n elif n1[-1] != \"0\":\r\n n1 = int(n1)-1\r\n n1 = str(n1)\r\nprint(n1)\r\n\r\ns = input()\r\na = \"abcdefghijklmnopqrstuvwxyz\"\r\nA = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\r\ncl = \"\"\r\nsl = \"\"\r\nfor i in s:\r\n if i in a:\r\n sl+=i\r\n elif i in A:\r\n cl+=i\r\nif len(cl)>len(sl):\r\n print(s.upper())\r\nelif len(sl)>=len(cl):\r\n print(s.lower())\r\n\r\n#lucky number\r\na = input()\r\nb = \"\"\r\nfor i in a:\r\n if i == \"4\":\r\n b+=i\r\n elif i == \"7\":\r\n b+=i\r\nprint(len(b))\r\nif len(b) == 0:\r\n print(\"NO\")\r\nelif len(b) == 1:\r\n print(\"NO\")\r\nelif len(b) == 2:\r\n print(\"NO\")\r\nelif len(b) == 3:\r\n print(\"NO\")\r\nelif len(b) == 4:\r\n print(\"YES\")\r\nelif len(b) == 5:\r\n print(\"NO\")\r\nelif len(b) == 6:\r\n print(\"NO\")\r\nelif len(b) == 7:\r\n print(\"YES\")\r\nelif len(b) >= 8:\r\n print(\"NO\")\r\n\r\nn = input()\r\ns = input()\r\nif (n[::-1]) == s:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\nN = input()\r\nn = input()\r\nA = \"\"\r\nD = \"\"\r\nfor i in n:\r\n if i == \"A\":\r\n A+=i\r\n elif i == \"D\":\r\n D+=i\r\nif len(A)>len(D):\r\n print(\"Anton\")\r\nelif len(D)>len(A):\r\n print(\"Danik\")\r\nelif len(A) == len(D):\r\n print(\"Friendship\")\r\n\r\nn = input().split()\r\ns = input().split()\r\na = 0\r\nns = n[0]\r\nfh = int(n[1])\r\nfor i in s:\r\n if int(i)>fh:\r\n a+=2\r\n elif int(i)<=fh:\r\n a+=1\r\nprint(a)\r\n\r\nn = int(input())\r\ncount = 0\r\nfor i in range(n):\r\n s = input().split()\r\n a = s[0]\r\n b = s[1]\r\n if int(b)-int(a) == 0:\r\n count+=0\r\n elif int(b)-int(a) == 1:\r\n count+=0\r\n elif int(b)-int(a) != 0 or int(b)-int(a) != 1 :\r\n count+=1\r\nprint(count)\r\n\r\na = int(input())\r\nn = input().split()\r\ncount = 0\r\nfor i in n:\r\n if i == \"1\":\r\n count+=1\r\nif count >0:\r\n print(\"Hard\")\r\nelif count == 0:\r\n print(\"Easy\")\r\n\r\n\r\nn = int(input())\r\na = \"I hate that \"\r\nb = \"I love that \"\r\nc = \"\"\r\nfor i in range(1,n+1):\r\n if i == n and i%2 == 0:\r\n c+=\"I love it\"\r\n elif i == n and i%2 != 0:\r\n c+=\"I hate it\"\r\n elif i == 1:\r\n c+=a\r\n elif i ==2:\r\n c+=b\r\n elif i%2!=0:\r\n c+=a\r\n elif i%2==0:\r\n c+=b\r\nprint(c)\r\n\r\nn = input().split()\r\na = []\r\nfor i in n:\r\n if i not in a:\r\n a.append(i)\r\nprint(4-len(a))\r\n#i will do it later in the prep\r\n\r\nn = int(input())\r\na = input()\r\nb = input()\r\nc = \"\"\r\nfor i in a:\r\n if i not in c:\r\n c+=i+\" \"\r\nfor i in b:\r\n if i not in c:\r\n c+=i+\" \"\r\nc = c.split()\r\nc.sort()\r\nprint(c)\r\nif int(c[-1]) == n and len(c) == n:\r\n print(\"I become the guy.\")\r\nelif int(c[-1]) != n and len(c) != n:\r\n print(\"Oh, my keyboard!\")\r\n\r\n\r\n# AnTON and letters\r\nn = input()\r\nalp = \"abcdefghijklmnopqrstuvwxyz\"\r\ns = \"\"\r\nfor i in n:\r\n if i in alp:\r\n s+=i\r\na = \"\"\r\nfor i in s:\r\n if i not in a:\r\n a+=i\r\nprint(len(a))\r\n# pangram\r\ns = input()\r\nn = input()\r\nalp = \"abcdefghijklmnopqrstuvwxyz\"\r\ncount = 0\r\nfor i in alp:\r\n if i in n:\r\n count+=1\r\nif count == 26:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\nn = input().lower()\r\ns = input().lower()\r\nj = input().lower()\r\na = \"\"\r\nfor i in n:\r\n if i in j:\r\n a+=i\r\n j = j.replace(i,\"\")\r\nfor i in s:\r\n if i in j:\r\n a+=i\r\n j = j.replace(i,\"\")\r\nprint(a,len(a),len(j))\r\nif len(a)==len(j):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n#1328580341\r\n\r\ndef magnets():\r\n a=int(input())\r\n count=0\r\n if a==1:\r\n b=int(input())\r\n print(1)\r\n else:\r\n for i in range(a):\r\n b = list(map(str,input()))\r\n for j in range(len(b)-1):\r\n if b[j]!=b[j+1]:\r\n count+=1\r\n print(count//2)\r\nmagnets()\r\n \r\ndef drinks():\r\n a=int(input())\r\n n=list(map(int,input().split()))\r\n summ = sum(n)\r\n av=summ/a\r\n print(av)\r\ndrinks()\r\n\r\ndef ultra_fast():\r\n a=input()\r\n b=input()\r\n c=''\r\n for i in range(0,len(a)):\r\n if a[i]!=b[i]:\r\n c+='1'\r\n else:\r\n c+='0'\r\n print(c)\r\nultra_fast()\r\n\r\ndef divisibility_problem():\r\n a=int(input())\r\n for i in range(a):\r\n b,c=input().split()\r\n if b%c==0:\r\n print(0)\r\n else:\r\n per = int(b)%int(c)\r\n print(int(c)-per)\r\ndivisibility_problem()\r\n\r\ndef park_lightning():\r\n a=int(input())\r\n for i in range(a):\r\n b,c=input().split()\r\n B=int(b)\r\n C=int(c)\r\n if (B*C)%2==0:\r\n print((B*C)//2)\r\n else:\r\n deci = (B*C)/2\r\n print(int(deci+0.5))\r\npark_lightning()\r\n \r\n\r\na = int(input())\r\nb = input().split()\r\nx = 0\r\ny = 0\r\nfor i in range(a):\r\n if b[1]>b[-1]:\r\n x+=int(b[1])\r\n b = b[1].replace(\"\")\r\n elif b[-1]>b[1]:\r\n x+=int(b[-1])\r\n b = b[-1].replace(\"\")\r\n elif b[1]>b[-1]:\r\n y+=int(b[1])\r\n b = b.replace(b[1],\"\")\r\n elif b[-1]>b[1]:\r\n y+=int(b[-1])\r\n b = b.replace(b[-1],\"\")\r\n \r\nprint(x,y)\r\n\r\n\r\nz = input().split()\r\na = int(z[0])\r\nb = int(z[1])\r\nc = int(z[2])\r\nd = int(z[3])\r\ne = int(z[4])\r\nf = int(z[5])\r\ng = int(z[6])\r\nh = int(z[7])\r\np = b*c\r\nq = p//g\r\nr = d*e\r\ns = f//h\r\nans = min(q,r,s)//a\r\nprint(ans)\r\n\r\n#do later\r\nx = []\r\ny = []\r\nn = int(input())\r\nfor i in range(n*2):\r\n a = int(input())\r\n b = input().split()\r\n for i in range(a-1):\r\n if b[i]!=b[i+1]:\r\n x.append(b[i])\r\n y.append(b[i+1])\r\n \r\nprint(x,y)\r\n\r\n\r\nx = 0\r\ny = 0\r\na = int(input())\r\nif a%2 != 0:\r\n x+=1\r\nb = list(map(int,input().split()))\r\nfor i in range((a//2)):\r\n if len(b) == 0:\r\n break\r\n x+=max(b[0],b[-1])\r\n b.remove(max(b[0],b[-1]))\r\n y+=max(b[0],b[-1])\r\n b.remove(max(b[0],b[-1]))\r\nprint(x,y) \r\n\r\na = int(input())\r\nfor i in range(a):\r\n b = int(input())\r\n c = input().split()\r\n d = c\r\n c = list(c)\r\n c1 = c\r\n c1.sort()\r\n for j in c1:\r\n if c1[0] != c1[1]:\r\n x = c1[1]\r\n elif c1[0] == c1[1]:\r\n x = c[-1]\r\nz = 0\r\nfor k in range(b):\r\n if d[k] == str(x):\r\n z = k\r\nprint(z+1)\r\n#now code\r\np = int(input())\r\nfor i in range(p):\r\n q = int(input())\r\n a = list(map(int,input().split())) \r\n b = a[0]\r\n x = []\r\n y = []\r\n z = 0\r\n for i in range(len(a)):\r\n if b == a[i]:\r\n x.append(a[i])\r\n elif b != a[i]:\r\n y.append(a[i])\r\n z+=i\r\n print(z)\r\n\r\na = [3,3,3,3,2,3,3,3,3] \r\nb = a[0]\r\nx = []\r\ny = []\r\nz = 0\r\nfor i in range(len(a)):\r\n if b == a[i]:\r\n x.append(a[i])\r\n z = 1\r\n break\r\n elif b != a[i]:\r\n y.append(a[i])\r\n z+=i\r\nprint(z)\r\n\r\na = int(input())\r\nMishka = 0\r\nChris = 0\r\nties = 0\r\nfor i in range(a):\r\n b = input().split()\r\n m = b[0]\r\n c = b[1]\r\n if m>c:\r\n Mishka += 1\r\n elif c>m:\r\n Chris += 1\r\n elif c == m:\r\n ties += 1\r\nif Mishka>Chris:\r\n print(\"Mishka\")\r\nelif Chris>Mishka:\r\n print(\"Chris\")\r\nelif Chris == Mishka:\r\n print(\"Friendship is magic!^^\")\r\n'''\r\na = int(input())\r\nb = input().split()\r\nci = [0,3,6,9,12,15,18]\r\nbici =(1,4,7,10,13,16,19)\r\nbaci = (2,5,8,11,14,17,20)\r\nc = 0\r\nbic = 0\r\nbac = 0\r\nfor i in range(a):\r\n if i in ci:\r\n c+=int(b[i])\r\n elif i in bici:\r\n bic+=int(b[i])\r\n elif i in baci:\r\n bac+=int(b[i])\r\nz = [c,bic,bac]\r\nx = 0\r\ny = 0\r\nfor i in z:\r\n if i>x:\r\n x=i\r\nfor i in range(len(z)):\r\n if z[i] == x:\r\n y = i\r\nif y == 0:\r\n print(\"chest\")\r\nelif y == 1:\r\n print(\"biceps\")\r\nelif y == 2:\r\n print(\"back\")\r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n=int(input())\r\nlst=list(map(int, input().split()))\r\na,b,c=0,0,0\r\nfor i in range(0,n,3):\r\n a+=lst[i]\r\nfor i in range(1,n,3):\r\n b+=lst[i]\r\nfor i in range(2,n,3):\r\n c+=lst[i]\r\nif a>b and a>c:\r\n print(\"chest\")\r\nelif b>a and b>c:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"u=int(input())\r\ni=map(int,input().split())\r\nlst=list(i)\r\nn=0\r\nm=0\r\nb=0\r\nfor x in range(u):\r\n if x==0 or x%3==0:\r\n m += lst[x]\r\n elif x==1 or (x-1)%3==0:\r\n n += lst[x]\r\n else:\r\n b += lst[x]\r\nif max(m,n,b)==b:\r\n print(\"back\")\r\nelif max(m,n,b)==m:\r\n print(\"chest\")\r\nelse:\r\n print(\"biceps\")",
"n = int(input())\r\nex = list(map(int, input().split()))\r\nch = sum(ex[0::3])\r\nbi = sum(ex[1::3])\r\nba = sum(ex[2::3])\r\nif max(ch, bi, ba) == ch:print(\"chest\")\r\nelif max(ch, bi, ba) == bi:print(\"biceps\")\r\nelse:print(\"back\")\r\n",
"n = int(input())\r\n\r\nlis = [int(i) for i in input().split()]\r\n\r\nopts = [0,0,0]\r\n\r\nfor i, item in enumerate(lis):\r\n\topts[i%3]+=item\r\n\r\nprint(['chest','biceps','back'][opts.index(max(opts))])\r\n\t\r\n",
"# A. Greg's Workout\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nc=sum(l[0::3])\r\nbi=sum(l[1::3])\r\nba=sum(l[2::3]) \r\nm=max(c,bi,ba)\r\nif m==c:\r\n print(\"chest\")\r\nelif m==bi:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"l = [0,0,0]\r\nn = int(input())\r\nt = list(map(int,input().split()))\r\nfor i,val in enumerate(t):\r\n l[i%3]+=val\r\nif l[0] > l[1] and l[0] >l[2]:\r\n print(\"chest\")\r\nelif l[1]>l[0] and l[1]>l[2]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"x=int(input())\r\nl=list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(x):\r\n if i%3==0:\r\n chest+=l[i]\r\n elif i%3==1:\r\n biceps+=l[i]\r\n else:\r\n back+=l[i]\r\na=max(chest,biceps,back)\r\nif a==chest:\r\n print(\"chest\")\r\nelif a==biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"y = int(input())\r\np = list(map(int, input().split()))\r\n\r\nchest = []\r\nbiceps = []\r\nback = []\r\n\r\nfor k in range(len(p)):\r\n ex = p[k]\r\n m = k % 3\r\n if m == 0:\r\n chest.append(ex)\r\n elif m == 1:\r\n biceps.append(ex)\r\n elif m == 2:\r\n back.append(ex)\r\n\r\nchest_sum = sum(chest)\r\nbiceps_sum = sum(biceps)\r\nback_sum = sum(back)\r\n\r\nres = [chest_sum, biceps_sum, back_sum]\r\nres.sort(reverse=True)\r\n\r\nif res[0] == chest_sum:\r\n print('chest')\r\nelif res[0] == biceps_sum:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n\r\n",
"import math\r\nA = int(input())\r\na = ()\r\na = list(map(int,input().split()))\r\nbiceps = 0\r\nback = 0\r\nchest = 0\r\nfor i in range(A):\r\n if math.fmod(i,3) == 1:\r\n biceps = biceps + a[i]\r\n elif math.fmod(i,3) == 2:\r\n back = back + a[i]\r\n elif math.fmod(i,3) == 0:\r\n chest = chest + a[i]\r\nif max(biceps, back, chest) == biceps: print('biceps')\r\nelif max(biceps, back, chest) == back: print('back')\r\nelif max(biceps, back, chest) == chest: print('chest')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest=0\r\nbiceps=0\r\nback=0\r\nif len(l)==1:\r\n print(\"chest\")\r\nelif len(l)==2: \r\n chest+=l[0]\r\n biceps+=l[1]\r\n if chest>biceps:\r\n print(\"chest\")\r\n else:\r\n print(\"biceps\")\r\nelse:\r\n \r\n for i in range(len(l)):\r\n if i%3==0:\r\n chest+=l[i]\r\n elif i%3==1:\r\n biceps+=l[i]\r\n elif i%3==2:\r\n back+=l[i]\r\n if back>biceps and back>chest:\r\n print(\"back\")\r\n elif biceps>back and biceps>chest:\r\n print(\"biceps\")\r\n elif chest>biceps and chest>back:\r\n print(\"chest\")",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nd = {\r\n 'chest':[[i for i in range(0, n, 3)], 0],\r\n 'biceps':[[i for i in range(1, n, 3)], 0],\r\n 'back':[[i for i in range(2, n, 3)], 0],\r\n}\r\n\r\nfor i, val in enumerate(arr):\r\n if i in d.get('chest')[0]:\r\n d['chest'][1] += val\r\n elif i in d.get('biceps')[0]:\r\n d['biceps'][1] += val \r\n else:\r\n d['back'][1] += val \r\n\r\nprint(sorted(d.items(), key= lambda x: x[1][1])[-1][0])",
"# https://codeforces.com/problemset/problem/255/A\r\n\r\ninput()\r\nseq = tuple(map(int, input().split()))\r\nch, bi, ba = 0, 0, 0\r\nfor i in range(len(seq)):\r\n if i % 3 == 0:\r\n ch += seq[i]\r\n if i % 3 == 1:\r\n bi += seq[i]\r\n if i % 3 == 2:\r\n ba += seq[i]\r\n\r\nt = max([ch, bi, ba]) \r\nif t == ch:\r\n print(\"chest\")\r\nelif t == bi:\r\n print(\"biceps\") \r\nelse:\r\n print(\"back\")",
"chest = 0\r\nbiceps = 0\r\nback = 0\r\nnum = 1\r\ny = input()\r\nz = list(map(int, input().split()))\r\nfor i in z:\r\n if num == 1:\r\n chest += i\r\n num = 2\r\n elif num == 2:\r\n biceps += i\r\n num = 3\r\n elif num == 3:\r\n back += i\r\n num = 1\r\nif chest == max(chest,biceps,back):\r\n print('chest')\r\nelif biceps == max(chest,biceps,back):\r\n print('biceps')\r\nelif back == max(chest,biceps,back):\r\n print('back')",
"x=int(input())\r\na=[int(x) for x in input().split()]\r\nl1=[]\r\nl2=[]\r\nl3=[]\r\nwhile len(a)%3!=0:\r\n a.append(0)\r\nfor i in range(0,len(a),3):\r\n l1.append(a[i])\r\n l2.append(a[i+1])\r\n l3.append(a[i+2])\r\ns=max(sum(l1),sum(l2),sum(l3))\r\nif s==sum(l1):\r\n print(\"chest\")\r\nelif s==sum(l2):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"if __name__ == \"__main__\":\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n chest=0\r\n biceps=0\r\n back=0\r\n for i in range(n):\r\n if i%3==0:\r\n chest+=a[i]\r\n elif i%3==1:\r\n biceps+=a[i]\r\n elif i%3==2:\r\n back+=a[i]\r\n if chest>biceps and chest>back:\r\n print('chest')\r\n elif biceps>chest and biceps>back:\r\n print('biceps')\r\n elif back>chest and back>biceps:\r\n print('back')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na,b,c=0,0,0\r\nfor i in range(n):\r\n if (i+1)%3==1:\r\n a=a+l[i]\r\n elif (i+1)%3==2:\r\n b=b+l[i]\r\n else:\r\n c=c+l[i]\r\nm=max(a,b,c)\r\nif m==a:\r\n print(\"chest\")\r\nelif m==b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nu = list(map(int, input().split()))\r\nc = 0\r\nbi = 0\r\nb = 0\r\n# c - 0 3 6 9\r\n# bi - 1 4 7 10\r\n# b - 2 5 8 11\r\nfor i in range(len(u)):\r\n j = u[i]\r\n if i % 3 == 0:\r\n c += j\r\n elif i % 3 == 1:\r\n bi += j\r\n elif i % 3 == 2:\r\n b += j\r\nif c > bi and c > b:\r\n print('chest')\r\nelif bi > c and bi > b:\r\n print('biceps')\r\nelse:\r\n print('back')",
"count1=0\r\ncount2=0\r\ncount=0\r\nn=int(input())\r\nl=list(map(int,input().strip().split()))[:n]\r\nfor i in range(0,n):\r\n if(i==0 or i==3 or i==6 or i==9 or i==12 or i==15 or i==18):\r\n count=count+l[i]\r\n elif(i==1 or i==4 or i==7 or i==10 or i==13 or i==16 or i==19):\r\n count1=count1+l[i]\r\n else:\r\n count2=count2+l[i]\r\nif(count>count1 and count>count2):\r\n print(\"chest\")\r\nelif(count1>count and count1>count2):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"workoutamount = [[\"chest\", 0], ['biceps', 0], ['back', 0]]\r\nworkoutnum = int(input())\r\nworkout = [int(x) for x in input().split()]\r\n\r\nfor i in range(workoutnum):\r\n workoutamount[i%3][-1] += workout[i]\r\n\r\nprint(sorted(workoutamount, key=lambda x:x[1])[-1][0])",
"# cook your dish here\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(n):\r\n if(i%3==0):\r\n chest+=a[i]\r\n elif(i%3==1):\r\n biceps+=a[i]\r\n else:\r\n back+=a[i]\r\n#print(chest, back, biceps)\r\nif(max(back, biceps, chest)==chest):\r\n print('chest')\r\nif(max(back, biceps, chest)==back):\r\n print('back')\r\nif(max(back, biceps, chest)==biceps):\r\n print('biceps')\r\n ",
"while True:\r\n try:\r\n s = input()\r\n s = list(map(int, input().split(' ')))\r\n a, b, c = True, False, False\r\n l1, l2, l3 = 0, 0, 0\r\n for i in s:\r\n if a:\r\n l1 += i\r\n a, b, c = False, True, False\r\n elif b:\r\n l2 += i\r\n a, b, c = False, False, True\r\n else:\r\n l3 += i\r\n a, b, c = True, False, False\r\n if max(l1, l2, l3) == l1:\r\n print(\"chest\")\r\n elif max(l1, l2, l3) == l2:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n except:\r\n break",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na=0\r\nb=0\r\nc=0\r\ni=0\r\nwhile(i<n):\r\n # print(i)\r\n a=a+l[i]\r\n if(i+1>=n):\r\n break\r\n b=b+l[i+1]\r\n if(i+2>=n):\r\n break\r\n c=c+l[i+2]\r\n i=i+3\r\nif(max(a,b,c)==a):\r\n print(\"chest\")\r\nelif(max(a,b,c)==b):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n# print(a,b,c)",
"n=int(input())\r\nv=[]\r\nu=[]\r\nt=[]\r\nl=list(map(int,input().split()))\r\nfor i in range(0,n,3):\r\n\tv.append(l[i])\r\nfor i in range(1,n,3):\r\n\tu.append(l[i])\r\nfor i in range(2,n,3):\r\n\tt.append(l[i])\r\n\r\nvs=sum(v)\r\nts=sum(t)\r\nus=sum(u)\r\nh=max(vs,us,ts)\r\n# print(h)\r\nif h==vs:\r\n\tprint('chest')\r\nelif h==us:\r\n\tprint('biceps')\r\nelse:\r\n\tprint('back')",
"def show(n,r1):\r\n w1=0\r\n w2=0\r\n w3=0\r\n for i in range(0,n,3):\r\n w1=w1+r1[i]\r\n for j in range(1,n,3):\r\n w2=w2+r1[j]\r\n for k in range(2,n,3):\r\n w3=w3+r1[k]\r\n\r\n if w1>w2 and w1>w3:\r\n max=\"w1\"\r\n if w2>w1 and w2>w3:\r\n max=\"w2\"\r\n if w3>w2 and w3>w1:\r\n max=\"w3\"\r\n\r\n if max==\"w1\":\r\n return \"chest\"\r\n if max==\"w2\":\r\n return \"biceps\"\r\n if max==\"w3\":\r\n return \"back\"\r\n\r\nn=int(input())\r\nr1 = list(map(int, input().split(\" \")))\r\nprint(show(n,r1))\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nc = sum(l[0:n:3])\r\nbs = sum(l[1:n:3])\r\nb = sum(l[2:n:3])\r\n\r\nif c>bs and c>b:\r\n print(\"chest\")\r\nelif bs>c and bs>b:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"import sys, math\ninput = sys.stdin.readline\n\nn = int(input())\na = [int(x) for x in input().split()]\n\nexcercise = ['chest', 'biceps', 'back']\n\narr = [0, 0, 0]\n\nfor i in range(n):\n arr[(i % 3)] += a[i]\n\nprint(excercise[arr.index(max(arr))])\n \t \t \t \t\t\t\t \t \t\t\t\t \t",
"l = int(input())\r\nnums = [int(inp) for inp in input().split()]\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(len(nums)):\r\n if i % 3 == 0:\r\n chest += nums[i]\r\n elif i % 3 == 1:\r\n biceps += nums[i]\r\n else:\r\n back += nums[i]\r\nif max(chest, biceps, back) == chest:\r\n print(\"chest\")\r\nelif max(chest, biceps, back) == biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\n\r\nsumc=sum(lst[0:n:3])\r\nsumb=sum(lst[1:n:3])\r\nsumbk=sum(lst[2:n:3])\r\nmaxx=max(sumc,sumb,sumbk)\r\nif sumc==maxx:\r\n print(\"chest\")\r\nelif sumb== maxx:\r\n print(\"biceps\")\r\nelif sumbk== maxx:\r\n print(\"back\")",
"n = int(input())\r\nm = list(map(int, input().split(' ')))\r\na, b, c, i = 0, 0, 0, 0\r\nwhile(i < n):\r\n if not i % 3:\r\n b += m[i]\r\n elif i % 3 == 1:\r\n c += m[i]\r\n else:\r\n a += m[i]\r\n i += 1\r\nif a == max(a, b, c):\r\n print('back')\r\nelif b == max(a, b, c):\r\n print('chest')\r\nelse:\r\n print('biceps')",
"n = input()\r\nlist1 = list(map(int,input().split()))\r\nk = 0\r\ni1=i2=i3=0\r\nwhile len(list1)%3!=0:\r\n list1.append(0)\r\nllen=len(list1)\r\nwhile llen > 0:\r\n i1 += list1[k]\r\n i2 += list1[k+1]\r\n i3 += list1[k+2]\r\n k+=3\r\n llen-=3\r\nk1,k2,k3 = i1,i2,i3\r\nif k1 > k2 and k1 > k3:\r\n print('chest')\r\nelif k2 > k1 and k2 > k3:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\nlst = list(map(int,input().strip().split()))[:n]\r\nf = int(n%3)\r\nG = 3-f\r\nfor i in range(G):\r\n lst.append(0)\r\nH = int(len(lst)//3)\r\nk = 0\r\nl = 1\r\nm = 2\r\nlst2 = []\r\nlst1 = []\r\nlst3 = []\r\nfor j in range(H):\r\n lst1.append(lst[k])\r\n lst2.append(lst[l])\r\n lst3.append(lst[m])\r\n k = k + 3\r\n l = l + 3\r\n m = m + 3\r\nB = sum(lst1)\r\nP = sum(lst2)\r\nQ = sum(lst3)\r\ncst = [B,P,Q]\r\nX = max(cst)\r\nU = cst.index(X)\r\nif U==0:\r\n print(\"chest\")\r\nelif U==1:\r\n print(\"biceps\")\r\nelif U==2:\r\n print(\"back\")",
"'''\r\n# Submitted By M7moud Ala3rj\r\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\r\n'''\r\n# Problem Name = \"Greg's Workout\"\r\n# Class: A\r\n\r\nimport sys\r\n#sys.setrecursionlimit(2147483647)\r\ninput = sys.stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n sys.stdout.write(sep.join(map(str, args)) + end)\r\n\r\ndef Solve():\r\n n = int(input())\r\n c, bi, ba = 0, 0, 0\r\n trainings = list(map(int, input().split()))\r\n c = sum(trainings[::3])\r\n bi = sum(trainings[1::3])\r\n ba = sum(trainings[2::3])\r\n\r\n if c > bi and c > ba:\r\n print(\"chest\")\r\n elif bi > ba:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n\r\nif __name__ == \"__main__\":\r\n Solve()",
"n = int(input())\r\na = list(map(int, input().split()))\r\nmuscles = [0, 0, 0]\r\nanswer = [\"chest\", \"biceps\", \"back\"]\r\n\r\nfor i in range(len(a)):\r\n if i % 3 == 0:\r\n muscles[0] += a[i]\r\n elif i % 3 == 1:\r\n muscles[1] += a[i]\r\n else:\r\n muscles[2] += a[i]\r\n\r\nstrongest = muscles.index(max(muscles))\r\nprint(answer[strongest])\r\n",
"input()\r\na = [int(i) for i in input().split()]\r\n\r\nif len(a) == 1:\r\n print('chest')\r\nelif len(a) == 2:\r\n print('chest' if a[0] > a[1] else 'biceps')\r\nelse:\r\n chest = sum(a[::3]) # Грудь\r\n biceps = sum(a[1::3])\r\n back = sum(a[2::3]) # Спина\r\n if chest > biceps and chest > back:\r\n print('chest')\r\n elif biceps > chest and biceps > back:\r\n print('biceps')\r\n else:\r\n print('back')\r\n",
"from math import *\r\nfrom collections import *\r\nfrom itertools import *\r\nfrom sys import *\r\n\r\n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(n):\r\n if i%3==0:\r\n a+=l[i]\r\n elif i%3==1:\r\n b+=l[i]\r\n elif i%3==2:\r\n c+=l[i]\r\nm=max(a,b,c)\r\nif m==a:\r\n print(\"chest\")\r\nelif m==b:\r\n print(\"biceps\")\r\nelif m==c:\r\n print(\"back\")",
"if __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n s = [0, 0, 0]\r\n for i in range(n):\r\n if (i + 1) % 3 == 1:\r\n s[0] += a[i]\r\n elif (i + 1) % 3 == 2:\r\n s[1] += a[i]\r\n else:\r\n s[2] += a[i]\r\n res = max(s)\r\n if res == s[0]:\r\n print('chest')\r\n elif res == s[1]:\r\n print('biceps')\r\n else:\r\n print('back')\r\n",
"n = int(input())\r\nj = 0\r\na = [0] * 3\r\ndata = input().split()\r\nfor el in data:\r\n a[j] += int(el)\r\n j += 1\r\n if j == 3:\r\n j = 0\r\nif a.index(max(a)) == 0:\r\n print('chest')\r\nelif a.index(max(a)) == 1:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\nc = [0, 0, 0]\r\nfor i in range(n):\r\n c[(i+1)%3-1] += a[i]\r\nif c[0] > c[1] and c[0] > c[2]: print(\"chest\")\r\nelif c[1] > c[0] and c[1] > c[2]: print(\"biceps\")\r\nelse: print(\"back\")",
"n = int(input())\r\nexercise_counts = list(map(int, input().split()))\r\n\r\nchest_count = 0\r\nbiceps_count = 0\r\nback_count = 0\r\n\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest_count += exercise_counts[i]\r\n elif i % 3 == 1:\r\n biceps_count += exercise_counts[i]\r\n else:\r\n back_count += exercise_counts[i]\r\n\r\nmax_count = max(chest_count, biceps_count, back_count)\r\n\r\nif max_count == chest_count:\r\n print(\"chest\")\r\nelif max_count == biceps_count:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"u = int(input())\nu2 = input()\nu2 = u2.split(\" \")\nch = 0\nba = 0\nbi = 0\nfor i in range(0,u,3):\n ch += int(u2[i])\nfor i in range(1,u,3):\n bi += int(u2[i])\nfor i in range(2,u,3):\n ba += int(u2[i])\nif (ch >= ba and ch > bi) or (ch >= bi and ch > ba) :\n print('chest')\nelif (ba >= ch and ba > bi) or (ba >= bi and ba > ch):\n print('back')\nelse:\n print('biceps')\n \t\t \t\t \t\t \t\t \t \t \t\t\t\t \t\t \t",
"t=int(input())\r\na=list(map(int,input().split()))\r\nx=y=z=0\r\nfor i in range(t):\r\n if(i%3==0):\r\n x+=a[i] \r\n elif(i%3==1):\r\n y+=a[i]\r\n else:\r\n z+=a[i]\r\nd=max(x,y,z)\r\nif(d==x):\r\n print(\"chest\")\r\nelif(d==y):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"def f(n,l):\r\n\tx=[\"chest\",\"biceps\",\"back\"]\r\n\tif n==1:\r\n\t\treturn x[n-1]\r\n\tif n==2:\r\n\t\treturn x[l.index(max(l))]\r\n\tl2=[0,0,0]\r\n\tfor i in range(0,n,3):\r\n\t\tl2[0]+=l[i]\r\n\tfor i in range(0,n-1,3):\r\n\t\tl2[1]+=l[i+1]\r\n\tfor i in range(0,n-2,3):\r\n\t\tl2[2]+=l[i+2]\r\n\r\n\treturn x[l2.index(max(l2))]\r\n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nprint(f(n,l))",
"a=input()\nb=input()\nb=b.split()\nbi=0\nba=0\nch=0\nfor x in range(0,len(b),3):\n ch+=int(b[x])\nfor y in range(1,len(b),3):\n bi+=int(b[y])\nfor z in range(2,len(b),3):\n ba+=int(b[z])\nif ch>bi and ch>ba:\n print('chest')\nelif bi>ch and bi>ba:\n print('biceps')\nelse:\n print('back')\n \t \t \t \t \t\t\t \t\t\t\t\t\t\t\t \t",
"n = int(input())\r\nchest = 0\r\nbicep = 0\r\nback = 0\r\nline = input()\r\nline = line.split()\r\nfor i in range(0,n):\r\n line[i] = int(line[i])\r\n if(i % 3 == 0):\r\n chest = chest + line[i]\r\n elif(i % 3 == 1):\r\n bicep = bicep + line[i]\r\n else:\r\n back = back + line[i]\r\nif(chest > bicep and chest > back):\r\n print(\"chest\")\r\nelif(bicep > chest and bicep > back):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input(''))\r\nl=list(map(int,input().split()))\r\nc,bc,bk=[],[],[]\r\nfor i in range(0,n,3):\r\n c.append(l[i])\r\nfor j in range(1,n,3):\r\n bc.append(l[j])\r\nfor k in range(2,n,3):\r\n bk.append(l[k])\r\nt=[sum(c),sum(bc),sum(bk)]\r\nm=t.index(max(t))\r\nif m==0:\r\n print('chest')\r\nelif m==1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"# Дано n упражнений\r\n# Каждое упраженине это A1.. A2.. A3......\r\n\r\n# 1. Грудь\r\n# 2. Бицепс\r\n# 3. Спина\r\n\r\nn = int(input()) # Кол-во упражнений\r\ntren = list(map(int,input().split()))\r\n\r\ngrud = 0\r\nbic = 0\r\nspin = 0\r\n\r\nupr = 1\r\n\r\nfor i in tren:\r\n if upr == 1:\r\n grud += i\r\n elif upr == 2:\r\n bic += i\r\n elif upr == 3:\r\n spin += i\r\n \r\n upr += 1\r\n if upr > 3:\r\n upr = 1\r\n\r\nif bic < grud > spin:\r\n print('chest')\r\nelif grud < bic > spin:\r\n print('biceps')\r\nelif bic < spin > grud:\r\n print('back')\r\n\r\n\r\n",
"a = int(input(\"\"))\r\nb = input(\"\").split()\r\nc = 0\r\nd = 0\r\ne = 0\r\nfor i in range(0, a):\r\n if i % 3 == 0:\r\n c += int(b[i])\r\n elif i % 3 == 1:\r\n d += int(b[i])\r\n else:\r\n e += int(b[i])\r\nif e < c > d:\r\n print(\"chest\")\r\nelif e < d > c:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc,bi,b=0,0,0\r\nfor i in range(0,len(a),3):\r\n c=c+a[i]\r\nfor i in range(1,len(a),3):\r\n bi=bi+a[i]\r\nfor i in range(2,len(a),3):\r\n b=b+a[i]\r\nif(c==max(c,bi,b)):\r\n print(\"chest\")\r\nif(bi==max(c,bi,b)):\r\n print(\"biceps\")\r\nif(b==max(c,bi,b)):\r\n print(\"back\")",
"c = 0\nb = 0\nba = 0\n\nnope = input()\nuser = [int(i) for i in input().split(\" \")]\nfor num in range(len(user)) :\n if num % 3 == 0 :\n c = c + user[num]\n elif num % 3 == 1 :\n b = b + user[num]\n else :\n ba = ba + user[num]\n\nif c > b and c > ba :\n print(\"chest\")\nelif b > c and b > ba :\n print(\"biceps\")\nelse :\n print(\"back\")\n\t\t\t\t \t \t\t \t \t \t\t\t \t \t \t\t\t",
"n = int(input())\r\na = list(map(int, input().split()))\r\neil = [sum(a[i::3]) for i in [0, 1, 2]]\r\nif eil[0] == max(eil):\r\n print(\"chest\")\r\nelif eil[1] == max(eil):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"import sys\r\ninput = sys.stdin.readline\r\n \r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))#might need to remove the -1\r\ndef invr():\r\n return(map(int,input().split()))\r\n\r\nn = inp()\r\ns = inlt()\r\ni = 1\r\nchest, biceps, back = 0, 0, 0\r\nfor j in range(n):\r\n if i == 1:\r\n chest += s[j]\r\n i += 1\r\n elif i == 2:\r\n biceps += s[j]\r\n i += 1\r\n else:\r\n back += s[j]\r\n i = 1\r\nw = max(chest, biceps, back)\r\nif w == chest:\r\n print('chest')\r\nelif w == biceps:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\nx,y,z = 0,0,0\r\n\r\nl = list(map(int, input().split()))\r\nx = sum(l[0:len(l):3])\r\ny = sum(l[1:len(l):3])\r\nz = sum(l[2:len(l):3])\r\n\r\nif x == max(x,y,z):\r\n print(\"chest\")\r\nelif y == max(x,y,z):\r\n print(\"biceps\")\r\nelif z == max(x,y,z):\r\n print(\"back\")\r\n\r\n ",
"\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nn = int(input())\r\nb = list(map(int,input().split()))\r\nfor i in range(n):\r\n if i % 3 == 2:\r\n back += b[i]\r\n elif i % 3 == 0:\r\n chest += b[i]\r\n else:\r\n biceps += b[i]\r\n\r\nmax_ = max(chest,biceps,back)\r\nif max_ == chest:\r\n print(\"chest\")\r\nelif max_ == biceps:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nr1=sum(a[::3])\r\nr2=sum(a[1::3])\r\nr3=sum(a[2::3])\r\nr=max(r1,r2,r3)\r\nif r==r1:\r\n print('chest')\r\nelif r==r2:\r\n print('biceps')\r\nelse :\r\n print('back')",
"n=int(input())\r\nl=[]\r\nc=0\r\nbi=0\r\nba=0\r\nl=list(map(int,input().split(' ')))\r\nfor i in range(0,n,3):\r\n c=c+l[i]\r\nfor i in range(1,n,3):\r\n bi=bi+l[i]\r\nfor i in range(2,n,3):\r\n ba=ba+l[i]\r\nif c>bi and c>ba:\r\n print(\"chest\")\r\nelif bi>c and bi>ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nx=0\r\ny=0\r\nz=0\r\na=list(map(int,input().split()))\r\nfor i in range(n):\r\n\tif i%3==0:\r\n\t\tx+=a[i]\r\n\telif i%3==1:\r\n\t\ty+=a[i]\r\n\telif i%3==2:\r\n\t\tz+=a[i]\r\nif x>y and x>z:\r\n\tprint(\"chest\")\r\nelif y>x and y>z:\r\n\tprint(\"biceps\")\r\nelif z>x and z>y:\r\n\tprint(\"back\")",
"n = int(input())\r\n\r\nrepetitions = list(map(int, input().split()))\r\n\r\nchest_total = 0\r\nbiceps_total = 0\r\nback_total = 0\r\n\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest_total += repetitions[i]\r\n elif i % 3 == 1:\r\n biceps_total += repetitions[i]\r\n else:\r\n back_total += repetitions[i]\r\n\r\nif chest_total > biceps_total and chest_total > back_total:\r\n print(\"chest\")\r\nelif biceps_total > chest_total and biceps_total > back_total:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nb=0\r\nc=0\r\nbc=0\r\nj=0\r\nfor i in range(0,len(l),3):\r\n c+=l[i]\r\nfor i in range(1,len(l),3):\r\n b+=l[i]\r\nfor i in range(2,len(l),3):\r\n bc+=l[i]\r\nif c>b and c>bc:\r\n print('chest')\r\nif b>c and b>bc:\r\n print('biceps')\r\nif bc>b and bc>c:\r\n print('back')\r\n ",
"n=int(input())\na=list(map(int, input().split()))\nc=[a[i] for i in range(0,n,3)]\nb=[a[i] for i in range(1,n,3)]\nk=[a[i] for i in range(2,n,3)]\nsc=sum(c)\nsb=sum(b)\nsk=sum(k)\nif sc>sb and sc>sk:\n print(\"chest\")\nelif sb>sk and sb>sc:\n print(\"biceps\")\nelse:\n print(\"back\")\n",
"# testCaseNum = int(input())\n# for testCase in range(testCaseNum):\n# p ,a ,b ,c = map(int ,input().split())\n# print(min(dis(p ,a) ,dis(p ,b) ,dis(p ,c)))\nn = int(input())\nexercise = list(map(int ,input().split()))\ncnt = [0 ,0 ,0]\nfor i in range(n):\n cnt[i%3] += exercise[i]\nif max(cnt) == cnt[0]:\n print(\"chest\")\nelif max(cnt) == cnt[1]:\n print(\"biceps\")\nelse:\n print(\"back\")\n",
"n = int(input())\r\nL = [int(x) for x in input().split()]\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(n):\r\n if i%3 == 0: chest += L[i]\r\n elif i%3 == 1: biceps += L[i]\r\n else: back += L[i]\r\nprint('chest' if max(chest, biceps, back) == chest else 'biceps' if max(chest, biceps, back) == biceps else 'back')\r\n",
"chest=0\nbiceps=0\nback=0\nt=int(input())\nc=0\nb=1\nb2=2\ny=list(map(int,input().split()))\nfor i in range(0,len(y)):\n if i==c:\n chest+=y[i]\n c+=3\n elif i==b:\n biceps+=y[i]\n b += 3\n elif i==b2:\n back+=y[i]\n b2 += 3\nif biceps>chest and biceps>back:\n print(\"biceps\")\nelif chest>biceps and chest>back:\n print(\"chest\")\nelse:\n print(\"back\")\n \t\t \t \t \t\t \t\t\t\t\t\t\t \t \t \t\t",
"n=int(input())\r\nt=list(map(int,input().split()))\r\nti=len(t)\r\nchest=0\r\nbiceps=0\r\nback=0\r\nfor i in range(ti):\r\n if i %3 == 0:\r\n chest = chest + t[i]\r\n elif i %3 == 1:\r\n biceps = biceps + t[i]\r\n elif i %3 == 2:\r\n back = back + t[i]\r\nif max(chest, biceps, back) == chest:\r\n print('chest')\r\nelif max(chest, biceps, back) == biceps:\r\n print('biceps')\r\nelif max(chest, biceps, back) == back:\r\n print('back')\r\n",
"import sys\ninput = sys.stdin.readline\n\nN = int(input())\nA = list(map(int, input().split()))\nED = [\"chest\", \"biceps\", \"back\"]\nec = [0, 0, 0]\nfor i in range(N) :\n\tec[i%3] += A[i]\nprint(ED[ec.index(max(ec))])",
"n = int(input())\r\nex = list(map(int, input().split()))\r\ndone = [0] * 3\r\n\r\nfor i in range(n):\r\n done[i % 3] += ex[i]\r\n\r\nans = [\"chest\", \"biceps\", \"back\"]\r\nprint(ans[done.index(max(done))])\r\n",
"n = int(input())\n\nch = 0\nbi = 0\nba = 0\n\nif n >=1 and n <= 20:\n a = input()\n a = a.split()\n if len(a) == n:\n for i in range(n):\n if i%3 == 0:\n ch += int(a[i])\n elif i%3 == 1:\n bi += int(a[i])\n elif i%3 == 2:\n ba += int(a[i])\nif ch > bi and ch > ba:\n print(\"chest\")\nelif bi > ch and bi > ba:\n print(\"biceps\")\nelse:\n print(\"back\")\n \n\n \t\t\t \t\t\t\t\t\t\t\t\t\t \t \t\t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nchest,bicep,back=0,0,0\r\nfor i in range(n):\r\n if(i%3==0):\r\n chest+=l[i]\r\n elif(i%3==1):\r\n bicep+=l[i]\r\n else:\r\n back+=l[i]\r\nif(chest>bicep and chest>back):\r\n print('chest')\r\nelif(bicep>chest and bicep>back):\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"i=int(input())\r\nl=list(map(int,input().split()))\r\na,b,c=0,0,0\r\nfor x in range(i):\r\n\tif x%3==0:a+=l[x]\r\n\telif x%3==1:b+=l[x]\r\n\telse:c+=l[x]\r\nif a>b and a>c:print(\"chest\")\r\nelif b>a and b>c:print(\"biceps\")\r\nelif c>a and c>b:print(\"back\")",
"n = int(input())\r\na = list(map(int,input().split()))\r\nif len(a)%3 != 0:\r\n for i in range(3 - len(a)%3):\r\n a.append(0)\r\nch = 0\r\nbi = 0\r\nba = 0\r\nfor i in range(0,len(a)-2,3):\r\n ch+=a[i]\r\n bi+=a[i+1]\r\n ba+=a[i+2]\r\nif ch > bi:\r\n if ch > ba:\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\nelse:\r\n if bi > ba:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")",
"a = int(input())\nrepeats = list(map(int, input().split()))\n\n\nchests = repeats[::3]\nchests = sum(chests)\n\nbiceps = repeats[1::3]\nbiceps = sum(biceps)\n\nback = repeats[2::3]\nback = sum(back)\n\nif max(chests, biceps, back) == chests:\n print('chest')\nelif max(chests, biceps, back) == biceps:\n print('biceps')\nelif max(chests, biceps, back) == back:\n print('back')\n\n\n",
"reapets = int(input())\r\ninputs = input().split(\" \")\r\nexercises = [int(x) for x in inputs]\r\nchist = 0\r\nbiceps = 0\r\nback = 0\r\ncount = 0\r\nwhile count < reapets:\r\n chist += exercises[count]\r\n try:\r\n biceps += exercises[count + 1]\r\n except:\r\n biceps += 0\r\n try:\r\n back += exercises[count + 2]\r\n except:\r\n back += 0\r\n count += 3\r\n\r\nexer = [chist, back, biceps]\r\nif max(exer) == chist:\r\n print(\"chest\")\r\nelif max(exer) == back:\r\n print(\"back\")\r\nelse:\r\n print(\"biceps\")\r\n",
"import io,os,sys\r\nimport math\r\nimport random\r\nfrom queue import PriorityQueue as PQ\r\nfrom bisect import bisect_left as BSL\r\nfrom bisect import bisect_right as BSR\r\nfrom collections import OrderedDict as OD\r\nfrom collections import Counter\r\nfrom itertools import permutations\r\nfrom decimal import Decimal as BIGFLOAT\r\n\r\n# mod = 998244353\r\nmod = 1000000007\r\n# mod = 998244353 \r\nsys.setrecursionlimit(1000000)\r\n\r\n\r\ntry:\r\n f = os.open(\"actext.txt\",os.O_RDONLY)\r\n input = io.BytesIO(os.read(f,os.fstat(f).st_size)).readline\r\n \r\nexcept:\r\n input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n \r\n \r\n\r\n \r\ndef get_ints():\r\n return map(int,input().decode().split())\r\n \r\ndef palindrome(s):\r\n mid = len(s)//2\r\n for i in range(mid):\r\n if(s[i]!=s[len(s)-i-1]):\r\n return False\r\n return True\r\ndef check(i,n):\r\n if(0<=i<n):\r\n return True\r\n else:\r\n return False\r\n \r\n# --------------------------------------------------------------------------\r\n\r\n \r\nt = int(input().decode())\r\narr = list(get_ints())\r\nchest = sum(arr[::3])\r\nbiceps = sum(arr[1::3])\r\nback = sum(arr[2::3])\r\nif(chest>biceps and chest>back):\r\n print(\"chest\")\r\nelif(biceps>chest and biceps>back ):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"chest = 0\r\nbicep=0\r\nback =0\r\nc_i,bi_i,ba_i =0,1,2\r\ninput()\r\nn = input().split()\r\nfor i in range(0,len(n),3):\r\n chest+= int(n[i])\r\nfor j in range(1,len(n),3):\r\n bicep+= int(n[j])\r\nfor k in range(2,len(n),3):\r\n back+= int(n[k])\r\nif chest >bicep and chest >back:\r\n print(\"chest\")\r\nelif bicep >chest and bicep >back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n = int(input())\r\nmimd = [int(j) for j in input().split()]\r\ntraining = {\r\n \"chest\" : 0 ,\r\n 'biceps' : 0,\r\n 'back' : 0\r\n}\r\ni = 0\r\nwhile i < len(mimd) :\r\n if i%3 == 0 :\r\n training['chest'] += mimd[i]\r\n elif i%3 == 1 :\r\n training['biceps'] += mimd[i]\r\n else:\r\n training['back'] += mimd[i]\r\n i+=1\r\n\r\n\r\n\r\nprint(max(training, key=training.get))",
"q = int(input())\r\ns1, s2, s3 = 0, 0, 0\r\na = input().split()\r\nfor j in range(len(a)):\r\n a[j] = int(a[j])\r\nfor j in range(0, len(a), 3):\r\n s1 = s1 + a[j]\r\nfor j in range(1, len(a), 3):\r\n s2 = s2 + a[j]\r\nfor j in range(2, len(a), 3):\r\n s3 = s3 + a[j]\r\nm = max(s1, s2, s3)\r\nif m == s1:\r\n print(\"chest\")\r\nelif m == s2:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n= int(input())\r\nl=[]\r\nchest=biceps=back=0\r\n\r\nl.extend(map(int,input().split()))\r\nfor i in range(1,n+1):\r\n if i%3==0:\r\n back += l[i-1]\r\n elif i % 3 == 2:\r\n biceps +=l[i-1]\r\n elif i %3 ==1 :\r\n chest +=l[i-1]\r\nif max(chest,biceps,back) == chest:\r\n print(\"chest\")\r\nelif max(chest,biceps,back) == biceps:\r\n print(\"biceps\")\r\nelse :\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nd={'chest':0,'biceps':0,'back':0}\r\nfor i in range(n):\r\n if i%3==0:\r\n d['chest']+=a[i]\r\n elif i%3==1:\r\n d['biceps']+=a[i]\r\n else:\r\n d[\"back\"]+=a[i]\r\nprint(max(d,key=d.get))",
"from math import ceil\r\nn = int(input())\r\nwo = list(map(int, input().split()))\r\n\r\nch, bi, ba = 0, 0, 0\r\nchest, bicep, back = True, False, False\r\nfor i in range(n):\r\n if chest:\r\n ch += wo[i]\r\n bicep, chest = True, False\r\n elif bicep:\r\n bi += wo[i]\r\n back, bicep = True, False\r\n elif back:\r\n ba += wo[i]\r\n chest, back = True, False\r\n\r\nif ch > bi and ch > ba:\r\n print(\"chest\")\r\nelif bi > ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n ",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nb=0\r\nba=0\r\nfor i in range(0,n,3):\r\n try:\r\n c+=l[i]\r\n b+=l[i+1]\r\n ba+=l[i+2]\r\n except:\r\n pass\r\nif c==max(c,b,ba):\r\n print(\"chest\")\r\nelif b==max(c,b,ba):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n",
"n = int(input())\n\nlst = input()\n\nlst = list(map(int,lst.split(\" \")))\n\nchest = 0\nbiceps = 0\nback = 0\n\nfor i in range(0,len(lst),3):\n chest+=lst[i]\n\nfor i in range(1,len(lst),3):\n biceps+=lst[i]\n\nfor i in range(2,len(lst),3):\n back+=lst[i]\n\nif chest>=biceps and chest>=back:\n print(\"chest\")\n\nelif biceps>=chest and biceps>=back:\n print(\"biceps\")\n\nelse:\n print(\"back\")\n \t \t \t\t \t \t\t\t \t \t",
"n = int(input()) \r\nl = list(map(int,input().split())) \r\nl1 = ['chest','biceps','back'] \r\nans=[0,0,0]\r\nfor i in range(n):\r\n ans[i%3]+=l[i]\r\nprint(l1[ans.index(max(ans))]) ",
"n = int(input())\narr = [int(_) for _ in input().split()]\n\nch = 0\nbi = 0\nba = 0\n\nfor i in range(n):\n if (i+1) % 3 == 2:\n bi += arr[i]\n\n elif (i+1) % 3 == 1:\n ch += arr[i]\n\n elif (i+1) % 3 == 0:\n ba += arr[i]\n\nif ch > bi and ch > ba:\n print('chest')\n\nelif bi > ch and bi > ba:\n print('biceps')\n\nelse:\n print('back')",
"n=int(input())\r\n\r\ni=input().split()\r\nl=list(map(int,i))\r\ndef q(l,n):\r\n c=0\r\n bi=0\r\n ba=0\r\n for i in range(n):\r\n v=i+1\r\n x=l[i]\r\n if v%3==1:\r\n c+=x\r\n elif v%3==2:\r\n bi+=x\r\n else:\r\n ba+=x\r\n m=max(c,bi,ba)\r\n if m==c:\r\n return \"chest\"\r\n elif m==bi:\r\n return \"biceps\"\r\n else:\r\n return \"back\" \r\nprint(q(l,n)) ",
"n = int(input())\r\nex = list(map(int, input().split()))\r\nchest, bi, back = 0, 0, 0\r\nfor i in range(0, len(ex), 3):\r\n chest += ex[i]\r\nfor j in range(1, len(ex), 3):\r\n bi += ex[j]\r\nfor k in range(2, len(ex), 3):\r\n back += ex[k]\r\n\r\nif max(chest, bi, back) == chest:\r\n print(\"chest\")\r\nelif max(chest, bi, back) == bi:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"# lesson 27\r\n# A. Тренировки Егора\r\n# https://codeforces.com/problemset/problem/255/A\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest += a[i]\r\n elif i % 3 == 1:\r\n biceps += a[i]\r\n elif i % 3 == 2:\r\n back += a[i]\r\n\r\nm = max(chest, biceps, back)\r\n\r\nif m == chest:\r\n print('chest')\r\nelif m == biceps:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n\r\n\r\n\r\n",
"a=int(input())\r\nc=0\r\nd=0\r\ne=0\r\nb=[int(i) for i in input().split()]\r\nfor i in range(0,a,3):\r\n c=c+b[i]\r\nfor i in range(1,a,3):\r\n d=d+b[i]\r\nfor i in range(2,a,3):\r\n e=e+b[i]\r\nif max(c,d,e)==c:\r\n print('chest')\r\nif max(c,d,e)==d:\r\n print('biceps')\r\nif max(c,d,e)==e:\r\n print('back')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ni=0\r\nsc=0\r\nsb=0\r\nsa=0\r\nwhile(i<n):\r\n sc+=l[i]\r\n i+=3\r\ni=1\r\nwhile(i<n):\r\n sb+=l[i]\r\n i+=3\r\ni=2\r\nwhile(i<n):\r\n sa+=l[i]\r\n i+=3\r\nif sc>sb and sc>sa:\r\n print(\"chest\")\r\nelif sb>sc and sb>sa:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"muscles = [0 ,0 ,0]\r\nn = int(input())\r\nins = input().split(\" \")\r\n\r\nfor i in range(n):\r\n muscles[i%3] += int(ins[i])\r\n\r\nprint(\"chest,biceps,back\".split(\",\")[muscles.index(max(muscles))])",
"n = int(input())\na = list(map(int, input().rstrip().split()))\nchest = 0\nbiceps = 0\nback = 0\nfor i in range(n):\n x = a[i]\n if i % 3 == 0:\n chest += x\n elif i % 3 == 1:\n biceps += x\n else:\n back += x\n\n# print(chest)\n# print(biceps)\n# print\nif chest > back and chest > biceps:\n print(\"chest\")\nelif biceps > chest and biceps > back:\n print(\"biceps\")\nelse:\n print(\"back\")",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ncnt = [0] * 3\r\nfor i in range(n):\r\n cnt[i % 3] += arr[i]\r\nif cnt[0] == max(cnt):\r\n print('chest')\r\nelif cnt[1] == max(cnt):\r\n print('biceps')\r\nelse:\r\n print('back')\r\n\r\n",
"t=int(input())\nuser=input()\nuser=user.split()\nfor i in range(t):\n user[i]=int(user[i])\nj=0\nchest=0\nbicep=0\nback=0\nfor i in range(t):\n if j>2:\n j=0\n if j==0:\n chest+=user[i]\n if j==1:\n bicep+=user[i]\n if j==2:\n back+=user[i]\n j+=1\nif chest>bicep and chest>back:\n print(\"chest\")\nelif bicep>chest and bicep>back:\n print(\"biceps\")\nelse:\n print('back')\n\t\t \t \t\t\t\t\t \t\t \t \t\t \t\t",
"\"\"\"\r\nq = int(input())\r\nfor z in range(q):\r\n\tn = int(input())\r\n\"\"\"\r\nn = int(input())\r\nv = list(map(int, input().split()))\r\nc = [0]*3\r\nr = [\"chest\", \"biceps\", \"back\"]\r\nfor i in range(n):\r\n\tc[i%3] += v[i]\r\nprint(r[c.index(max(c))])\t",
"num=int(input())\r\nlist1=list(map(int,input().split()))\r\nsum1=sum(list1[0::3])\r\nsum2=sum(list1[1::3])\r\nsum3=sum(list1[2::3])\r\nmax_=max(sum1,sum2,sum3)\r\nif max_==sum1:\r\n print(\"chest\")\r\nelif max_==sum2:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n ",
"n = int(input())\r\na = [int(s) for s in input().split(' ')]\r\nc = sum([a[i] for i in range(0, n, 3)])\r\nbi = sum([a[i] for i in range(1, n, 3)])\r\nba = sum([a[i] for i in range(2, n, 3)])\r\nif max([c, bi, ba]) == c:\r\n print('chest')\r\nelif max([c, bi, ba]) == bi:\r\n print('biceps')\r\nelse:\r\n print('back')\r\n",
"n = int(input())\r\nt = list(map(int,input().split()))\r\nchest = sum(t[::3])\r\nbiceps = sum(t[1::3])\r\nback = sum(t[2::3])\r\nif biceps < chest > back:\r\n print(\"chest\")\r\nelif chest < biceps > back:\r\n print(\"biceps\")\r\nelif chest < back > biceps:\r\n print(\"back\")\r\n ",
"n,l=int(input()),[0]*3\r\na=list(map(int,input().split()))\r\nfor i in range(n):l[i%3]+=a[i]\r\nprint(\"cbbhiaeccsektp s \"[l.index(max(l))::3])",
"n = int(input())\r\ne = list(map(int, input().split()))\r\nchest_total = 0\r\nbiceps_total = 0\r\nback_total = 0\r\n\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n chest_total += e[i]\r\n elif i % 3 == 1:\r\n biceps_total += e[i]\r\n else:\r\n back_total += e[i]\r\nmax_total = max(chest_total, biceps_total, back_total)\r\nif max_total == chest_total:\r\n print(\"chest\")\r\nelif max_total == biceps_total:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"int(input())\r\nk = list(map(int,input().split()))\r\nchest = sum(k[0::3])\r\nbiceps = sum(k[1::3])\r\nback = sum(k[2::3])\r\nmax = max(chest,biceps,back)\r\nif chest == max:\r\n print(\"chest\")\r\nelif biceps == max:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"n=int(input())\r\na=list(map(int,input().split()))\r\nchest=[]\r\nbiceps=[]\r\nback=[]\r\nfor i in range(n):\r\n if i%3==0:\r\n chest.append(a[i])\r\n if i%3==1:\r\n biceps.append(a[i])\r\n if i%3==2:\r\n back.append(a[i])\r\nif sum(back)>sum(chest) and sum(back)>sum(biceps):\r\n print(\"back\")\r\nelif sum(chest)>sum(back) and sum(chest)>sum(biceps):\r\n print(\"chest\")\r\nelif sum(biceps)>sum(chest) and sum(biceps)>sum(back):\r\n print(\"biceps\")\r\n",
"\r\nfrom collections import defaultdict, deque\r\nimport collections, math\r\nfrom concurrent.futures import thread\r\nimport heapq\r\nfrom operator import indexOf\r\nimport sys, threading\r\nmod = 1000000007\r\nimport math\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\ndef get_int(): return int(sys.stdin.readline().strip())\r\ndef get_list_strings(): return list(map(str, sys.stdin.readline().strip().split())) \r\n\r\ndef run():\r\n n = get_int()\r\n li = get_list()\r\n \r\n biceps = 0\r\n chest = 0\r\n back = 0\r\n \r\n for i in range(len(li)):\r\n j = i % 3\r\n if j == 0:\r\n chest += li[i]\r\n elif j == 1:\r\n biceps += li[i]\r\n else:\r\n back += li[i]\r\n \r\n if biceps > chest and biceps > back:\r\n print(\"biceps\")\r\n elif chest > back and chest > biceps:\r\n print(\"chest\")\r\n else:\r\n print(\"back\")\r\n \r\nif __name__ == '__main__':\r\n threading.stack_size(1 << 27)\r\n sys.setrecursionlimit(1 << 30)\r\n main_thread = threading.Thread(target=run)\r\n main_thread.start()\r\n main_thread.join()",
"import sys,math\r\n\r\n\r\ndef solve():\r\n n = inp()\r\n a = inlt()\r\n chest = 0\r\n bicep = 0\r\n back = 0\r\n count = 0\r\n for i in range(n):\r\n if count == 0:\r\n chest += a[i]\r\n count += 1\r\n elif count == 1:\r\n bicep += a[i]\r\n count += 1\r\n elif count == 2:\r\n back += a[i]\r\n count = 0\r\n \r\n if chest > bicep and chest > back:\r\n print(\"chest\")\r\n elif bicep > chest and bicep > back:\r\n print(\"biceps\")\r\n else:\r\n print(\"back\")\r\n\r\n\r\ndef main():\r\n global tt\r\n t = 1\r\n # t = inp()\r\n for tt in range(t):\r\n solve()\r\n \r\n#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n#------------------ GLOBAL VARIABLES ------------------#\r\n\r\n# sys.setrecursionlimit(10**9)\r\n# inf = 10**19\r\n\r\n#------------------ USEFUL FUNCTIONS ------------------#\r\n'''\r\ndef counter(a):\r\n # returns the number of each element in array -> returns list\r\n q = [0] * max(a)\r\n for i in range(len(a)):\r\n q[a[i] - 1] = q[a[i] - 1] + 1\r\n return(q)\r\n \r\ndef counter_elements(a):\r\n # returns dict of element and their count\r\n q = dict()\r\n for i in range(len(a)):\r\n if a[i] not in q:\r\n q[a[i]] = 0\r\n q[a[i]] = q[a[i]] + 1\r\n return(q)\r\n \r\ndef string_counter(a):\r\n # returns count of alphabets \r\n # alphabets should be lower case\r\n q = [0] * 26\r\n for i in range(len(a)):\r\n q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1\r\n return(q)\r\n \r\ndef factorial(n,m = 1000000007):\r\n # returns factorial of number\r\n q = 1\r\n for i in range(n):\r\n q = (q * (i + 1)) % m\r\n return(q)\r\n \r\ndef factors(n):\r\n # returns list of number that can divide the given value\r\n q = []\r\n for i in range(1,int(n ** 0.5) + 1):\r\n if n % i == 0: q.append(i); q.append(n // i)\r\n return(list(sorted(list(set(q)))))\r\n \r\ndef prime_factors(n):\r\n # returns only prime factors of the number\r\n q = []\r\n while n % 2 == 0: q.append(2); n = n // 2\r\n for i in range(3,int(n ** 0.5) + 1,2):\r\n while n % i == 0: q.append(i); n = n // i\r\n if n > 2: q.append(n)\r\n return(list(sorted(q)))\r\n \r\ndef transpose(a):\r\n # returns transpose no brainer.\r\n n,m = len(a),len(a[0])\r\n b = [[0] * n for i in range(m)]\r\n for i in range(m): \r\n for j in range(n): \r\n b[i][j] = a[j][i]\r\n return(b)\r\n \r\ndef power_two(x):\r\n # return if x is power of 2 or not - boolean \r\n return (x and (not(x & (x - 1))))\r\n \r\ndef ceil(a,b = 2):\r\n # 2.4 - 3\r\n return -(-a // b)\r\n \r\ndef seive(n):\r\n # seive algo\r\n a = [1]\r\n prime = [True for i in range(n + 1)] \r\n p = 2\r\n while (p * p <= n): \r\n if (prime[p] == True): \r\n for i in range(p ** 2,n + 1,p): \r\n prime[i] = False\r\n p = p + 1\r\n for p in range(2,n + 1): \r\n if prime[p]: \r\n a.append(p)\r\n return(a)\r\n \r\ndef ncr(n,r):\r\n # selection of things without considering their order of arrangement.\r\n # combination formula\r\n\r\n if r > n:\r\n return(0)\r\n else:\r\n return(math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))\r\n \r\ndef npr(n,r):\r\n # no of ways of selecting and arranging 'r' things from given 'n' things\r\n # permutation formula\r\n if r > n:\r\n return(0)\r\n else:\r\n return(math.factorial(n) // math.factorial(n - r))\r\n \r\ndef gcd(x,y):\r\n # Euclidean Algorithm\r\n # return greatest common divisor of x and y\r\n while y:\r\n x, y = y, x%y\r\n return x\r\n\r\n'''\r\n\r\n \r\n#-----------------------------------------------------------------------#\r\nif __name__ == \"__main__\":\r\n input = sys.stdin.readline\r\n main()",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na=0\r\nb=0\r\nc=0\r\nfor i in range(n):\r\n if(i%3==0):\r\n a=a+l[i]\r\n elif(i%3==1):\r\n b=b+l[i]\r\n else:\r\n c=c+l[i]\r\nif(a>b and a>c):\r\n print(\"chest\")\r\nelif(b>a and b>c):\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n \r\n ",
"n=int(input())\r\na=input()\r\na=a.split()\r\ni=0\r\nch=0\r\nbi=1\r\nba=2\r\nc=0\r\nb=0\r\nback=0\r\nwhile n>0:\r\n if i==ch:\r\n c+=int(a[i])\r\n if i==bi:\r\n b+=int(a[i])\r\n if i==ba:\r\n back+=int(a[i])\r\n ch+=3\r\n bi+=3\r\n ba+=3\r\n n-=1\r\n i+=1\r\nif c>b and c>back:\r\n print('chest')\r\nelif b>back:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\nm = [0, 0, 0]\r\na = list(map(int, input().split()))\r\n\r\nfor i in range(n):\r\n m[i % 3] += a[i]\r\n \r\nif max(m) == m[0]:\r\n print('chest')\r\nelif max(m) == m[1]:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n= int(input())\r\nchest=0\r\nbicep=0\r\nback=0\r\nl= list(map(int, input().split()))\r\n\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=l[i]\r\n elif i%3==1:\r\n bicep+=l[i]\r\n elif i%3==2:\r\n back+=l[i]\r\n\r\nif chest>bicep and chest>back:\r\n print('chest')\r\nelif bicep>chest and bicep>back:\r\n print('biceps')\r\nelif back>chest and back>bicep:\r\n print('back')\r\n",
"import sys\r\nfrom os import path\r\nfrom math import gcd,floor,sqrt,log,ceil\r\nfrom bisect import bisect_left, bisect_right\r\nimport heapq\r\n\r\n############ ---- Input Functions ---- ####################\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\ndef inmatrix(n,m):\r\n arr=[]\r\n for i in range(n):\r\n temp=inlt()\r\n arr.append(temp)\r\n return arr\r\n############################################################\r\ndef cuberoot(x):\r\n if 0<=x: return x**(1./2.)\r\n return -(-x)**(1./2.)\r\ndef is_anagram(str1, str2):\r\n return sorted(str1) == sorted(str2)\r\n############################################################\r\nmod=1000000007\r\n############################################################\r\nif(path.exists('input.txt')):\r\n sys.stdin = open(\"input.txt\",\"r\")\r\n sys.stdout = open(\"output.txt\",\"w\")\r\n sys.stderr = open(\"error.txt\", \"w\")\r\nelse:\r\n input = sys.stdin.readline\r\n############################################################\r\ndef solve():\r\n n=inp()\r\n a=inlt()\r\n chest,biceps,back=0,0,0\r\n c_=True\r\n bi_=False\r\n ba_=False\r\n for i in range(n):\r\n if c_==True:\r\n chest+=a[i]\r\n c_=False\r\n bi_=True\r\n elif bi_==True:\r\n biceps+=a[i]\r\n bi_=False\r\n ba_=True\r\n elif ba_==True:\r\n back+=a[i]\r\n ba_=False\r\n c_=True\r\n if max(chest,biceps,back)==back:\r\n print(\"back\")\r\n elif max(chest,biceps,back)==biceps:\r\n print(\"biceps\")\r\n else:\r\n print(\"chest\")\r\n\r\n\r\n\r\n\r\n\r\ndef main():\r\n # T=inp()\r\n T=1\r\n for i in range(1,T+1):\r\n #print(\"Case #{}:\".format(i),end=\" \")\r\n solve()\r\n\r\nmain() ",
"n = int(input())\r\n\r\nli = list(map(int,input().split()))\r\nchest = 0\r\nbiceps = 0\r\nback = 0\r\n\r\nfor i in range(n):\r\n if i%3==0:\r\n chest+=li[i]\r\n elif i%3==1:\r\n biceps+=li[i]\r\n else:\r\n back+=li[i\r\n ]\r\n\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n=int(input())\r\nworkout=list(map(int,input().split()))\r\ncounter=0\r\nbiceps=0\r\nback=0\r\nchest=0\r\nfor i in range(len(workout)):\r\n if counter==0:\r\n chest+=workout[i]\r\n elif counter==1:\r\n biceps+=workout[i]\r\n elif counter==2:\r\n back+=workout[i]\r\n counter+=1\r\n counter=counter%3\r\nif chest>biceps and chest>back:\r\n print(\"chest\")\r\nelif biceps>chest and biceps>back:\r\n print(\"biceps\")\r\nelif back>biceps and back>chest:\r\n print(\"back\")",
"n=int(input())\r\n\r\nl=list(map(int,input().split()))\r\n\r\nx=[0]*3\r\n\r\nfor i in range(len(l)):\r\n x[i%3]+=l[i]\r\n \r\nm=x.index(max(x))\r\n\r\nif m==0:\r\n print('chest')\r\nelif m==1:\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\na = input().split()\r\na = [int(i) for i in a]\r\nchest = biceps = back = 0\r\nfor i in range(0, len(a), 3):\r\n chest += a[i]\r\nfor i in range(1, len(a), 3):\r\n biceps += a[i]\r\nfor i in range(2, len(a), 3):\r\n back += a[i]\r\nif chest > back and chest > biceps:\r\n print('chest')\r\nelif back > chest and back > biceps:\r\n print('back')\r\nelse:\r\n print('biceps')",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=be=ba=0\r\nfor i in range(1,n+1):\r\n if(i%3==1):\r\n c+=l[i-1]\r\n elif(i%3==2):\r\n be+=l[i-1]\r\n else:\r\n ba+=l[i-1]\r\nif(c>be and c>ba):\r\n print(\"chest\")\r\nelif(be>c and be>ba):\r\n print(\"biceps\")\r\nelif(ba>c and ba>be):\r\n print(\"back\")",
"t = int(input())\r\na = list(map(int,input().split()))\r\n\r\nc=0\r\nb=0\r\nd=0\r\n\r\nfor i in range(0,len(a),3):\r\n c+=a[i]\r\nfor i in range(1,len(a),3):\r\n b+=a[i]\r\nfor i in range(2,len(a),3):\r\n d+=a[i]\r\nif c>d and c>b:\r\n print(\"chest\")\r\nelif b>c and b>d:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n\r\n\r\n\r\n\r\n",
"n= int(input())\r\na = [int(a)for a in input().split()]\r\nc=0\r\nb=0\r\nd=0\r\ncount = 1\r\nfor i in range(len(a)):\r\n if count==1:\r\n c+=a[i]\r\n count +=1\r\n elif count==2:\r\n b+=a[i]\r\n count+=1\r\n else:\r\n d+=a[i]\r\n count=1\r\nif c>b and c>d:\r\n print((\"chest\"))\r\nelif b>c and b >d:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\" )",
"n=int(input())\narr=[int(x) for x in input().split()]\nchest=0\nbiceps=0\nback=0\n\nfor i in range(0,n,3):\n chest+=arr[i]\nfor i in range(1,n,3):\n biceps+=arr[i]\nfor i in range(2,n,3):\n back+=arr[i]\nmaxx=[chest,biceps,back]\nmaxx.sort()\nif(maxx[2]==chest):\n print(\"chest\")\nelif(maxx[2]==biceps):\n print(\"biceps\")\nelse:\n print(\"back\")\n \t\t \t \t \t \t\t \t\t\t\t\t \t\t\t\t \t",
"input()\r\na = [int(i) for i in input().split()]\r\nd, b, c = sum(a[0::3]), sum(a[1::3]), sum(a[2::3])\r\nr = max(d, b, c)\r\nprint('chest' * (r == d) + 'biceps' * (r == b) + 'back' * (r == c))",
"n = int(input())\r\ntmp_dict = {'chest':0, 'biceps':0, 'back':0}\r\na = [int(m) for m in input().split()]\r\nfor i in range(n):\r\n if i % 3 == 0:\r\n tmp_dict['chest'] += a[i]\r\n elif i % 3 == 1:\r\n tmp_dict['biceps'] += a[i]\r\n else:\r\n tmp_dict['back'] += a[i]\r\nprint(max(tmp_dict, key=tmp_dict.get))",
"a = int(input())\r\nv = [int(j) for j in input().split()]\r\nch = 0\r\nbi = 0\r\nba = 0\r\nfor f in range(0, a, 3):\r\n ch += v[f]\r\nfor f in range(1, a, 3):\r\n bi += v[f]\r\nfor f in range(2, a, 3):\r\n ba += v[f]\r\nif ch>bi and ch>ba:\r\n print(\"chest\")\r\nelif bi>ch and bi>ba:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"a=b=c=0;i=1;n=int(input())\r\nfor x in list(map(int,input().split())):\r\n if i==1:\r\n a+=x\r\n if i==2:\r\n b+=x\r\n if i==3:\r\n c+=x\r\n i+=1\r\n if i>3:\r\n i=1\r\n\r\nk=max(a,b,c)\r\nif a==k:\r\n print(\"chest\")\r\nelif b==k:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")",
"a = int(input())\r\nx = list(map(int, input().split()))\r\nq = 0\r\nchest=0\r\nbiceps=0\r\nback=0\r\nwhile q < len(x):\r\n chest+=x[q]\r\n q+=1\r\n if q == len(x):\r\n break\r\n biceps+=x[q]\r\n q+=1\r\n if q == len(x):\r\n break\r\n back+=x[q]\r\n q+=1\r\nif chest > biceps and chest > back :\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back :\r\n print(\"biceps\")\r\nelif back > chest and back > biceps :\r\n print(\"back\")",
"n = int(input())\r\n\r\nk = list(map(int, input().strip().split()))\r\nc = 0\r\nl = 0 \r\nf = 0\r\nfor i in range(0, len(k), 3):\r\n c+=k[i]\r\nfor i in range(1, len(k), 3):\r\n l+=k[i]\r\nfor i in range(2, len(k), 3):\r\n f+=k[i]\r\n\r\nif c > l and c > f:\r\n print(\"chest\")\r\nif l > c and l > f:\r\n print(\"biceps\")\r\nif f > c and f > l:\r\n print(\"back\")",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ncheck=1\r\nbiceps,back,chest=0,0,0\r\nfor i in l:\r\n if check==1:\r\n chest += i\r\n check=2\r\n elif check==2:\r\n biceps += i\r\n check=3\r\n elif check==3:\r\n back += i\r\n check=1\r\n\r\nk=[chest,biceps,back]\r\nif max(k)==k[0]:\r\n print(\"chest\")\r\nelif max(k)==k[1]:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n ",
"\r\nn = int(input())\r\n\r\nlist1 = [int(x) for x in input().split()]\r\nchest, biceps,back = 0,0,0\r\n\r\n\r\nfor i in range(0,n,3):\r\n chest += int(list1[i])\r\nfor i in range(1,n,3):\r\n biceps += int(list1[i])\r\nfor i in range(2,n,3):\r\n back += int(list1[i])\r\n\r\nif chest > biceps and chest > back:\r\n print(\"chest\")\r\nelif biceps > chest and biceps > back:\r\n print(\"biceps\")\r\nelse:\r\n print(\"back\")\r\n",
"n = int(input())\r\nreps = list(map(int,input().split()))\r\nchest = []\r\nbiceps = []\r\nback = []\r\nfor i in range(n):\r\n if i == 0 or i == 3 or i == 6 or i == 9 or i == 12 or i == 15 or i == 18 or i == 21 or i == 24:\r\n chest.append(reps[i])\r\n elif i == 1 or i == 4 or i == 7 or i == 10 or i == 13 or i == 16 or i == 19 or i == 22 or i == 25:\r\n biceps.append(reps[i])\r\n else:\r\n back.append(reps[i])\r\nif sum(chest) > sum(biceps) and sum(chest) > sum(back):\r\n print('chest')\r\nelif sum(biceps) > sum(chest) and sum(biceps) > sum(back):\r\n print('biceps')\r\nelse:\r\n print('back')",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nres = [0]*3\r\nx = 0\r\nfor i in range(n):\r\n res[x] += arr[i]\r\n x += 1\r\n if x == 3: x = 0\r\nmx = res.index(max(res))\r\nif mx == 0: print(\"chest\")\r\nelif mx == 1: print(\"biceps\")\r\nelif mx == 2: print(\"back\")",
"MAP_TYPES = {\r\n 0: \"chest\",\r\n 1: \"biceps\",\r\n 2: \"back\"\r\n}\r\n\r\ndef maxTypeExcersice(a):\r\n total= len(MAP_TYPES.keys())\r\n table = [0] * total\r\n for i, value in enumerate(a):\r\n table[i % total] += value\r\n return MAP_TYPES[table.index(max(table))]\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n a = [int(i) for i in input().split()]\r\n print(maxTypeExcersice(a))",
"n = int(input())\r\nar = list(map(int,input().split()))\r\nc,bi,b=0,0,0\r\nfor i in range(n):\r\n if i%3==0:\r\n c += ar[i]\r\n elif i%3==1:\r\n bi += ar[i]\r\n else:\r\n b += ar[i]\r\nif c>bi and c>b:\r\n print(\"chest\")\r\nelif bi>c and bi>b:\r\n print(\"biceps\")\r\nelif b>c and b>bi:\r\n print(\"back\")",
"int(input())\r\narr = list(map(int,input().split()))\r\ns = [0]*3\r\nfor i in range(len(arr)):s[i%3] += arr[i]\r\nif s[0] == max(s):print(\"chest\")\r\nelif s[1] == max(s):print(\"biceps\")\r\nelse:print(\"back\")",
"def answer():\r\n a = int(input())\r\n c = [int(x) for x in input().split()]\r\n i=0\r\n d=[0,0,0]\r\n e=[\"chest\",\"biceps\",\"back\"]\r\n while i<len(c):\r\n d[i%3]+=c[i]\r\n i+=1\r\n print(e[d.index(max(d))])\r\nanswer()\r\n"
] | {"inputs": ["2\n2 8", "3\n5 1 10", "7\n3 3 2 7 9 6 8", "4\n5 6 6 2", "5\n8 2 2 6 3", "6\n8 7 2 5 3 4", "8\n7 2 9 10 3 8 10 6", "9\n5 4 2 3 4 4 5 2 2", "10\n4 9 8 5 3 8 8 10 4 2", "11\n10 9 7 6 1 3 9 7 1 3 5", "12\n24 22 6 16 5 21 1 7 2 19 24 5", "13\n24 10 5 7 16 17 2 7 9 20 15 2 24", "14\n13 14 19 8 5 17 9 16 15 9 5 6 3 7", "15\n24 12 22 21 25 23 21 5 3 24 23 13 12 16 12", "16\n12 6 18 6 25 7 3 1 1 17 25 17 6 8 17 8", "17\n13 8 13 4 9 21 10 10 9 22 14 23 22 7 6 14 19", "18\n1 17 13 6 11 10 25 13 24 9 21 17 3 1 17 12 25 21", "19\n22 22 24 25 19 10 7 10 4 25 19 14 1 14 3 18 4 19 24", "20\n9 8 22 11 18 14 15 10 17 11 2 1 25 20 7 24 4 25 9 20", "1\n10", "2\n15 3", "3\n21 11 19", "4\n19 24 13 15", "5\n4 24 1 9 19", "6\n6 22 24 7 15 24", "7\n10 8 23 23 14 18 14", "8\n5 16 8 9 17 16 14 7", "9\n12 3 10 23 6 4 22 13 12", "10\n1 9 20 18 20 17 7 24 23 2", "11\n22 25 8 2 18 15 1 13 1 11 4", "12\n20 12 14 2 15 6 24 3 11 8 11 14", "13\n2 18 8 8 8 20 5 22 15 2 5 19 18", "14\n1 6 10 25 17 13 21 11 19 4 15 24 5 22", "15\n13 5 25 13 17 25 19 21 23 17 12 6 14 8 6", "16\n10 15 2 17 22 12 14 14 6 11 4 13 9 8 21 14", "17\n7 22 9 22 8 7 20 22 23 5 12 11 1 24 17 20 10", "18\n18 15 4 25 5 11 21 25 12 14 25 23 19 19 13 6 9 17", "19\n3 1 3 15 15 25 10 25 23 10 9 21 13 23 19 3 24 21 14", "20\n19 18 11 3 6 14 3 3 25 3 1 19 25 24 23 12 7 4 8 6", "1\n19", "2\n1 7", "3\n18 18 23", "4\n12 15 1 13", "5\n11 14 25 21 21", "6\n11 9 12 11 22 18", "7\n11 1 16 20 21 25 20", "8\n1 2 20 9 3 22 17 4", "9\n19 2 10 19 15 20 3 1 13", "10\n11 2 11 8 21 16 2 3 19 9", "20\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 24", "12\n4 24 21 3 13 24 22 13 12 21 1 15", "13\n14 14 16 2 13 5 1 14 9 4 16 8 3", "14\n1 9 15 4 11 8 25 3 9 14 13 2 1 11", "15\n4 19 10 6 16 12 5 11 7 23 1 24 11 7 17", "16\n2 8 2 8 13 22 20 12 22 23 18 13 18 22 11 17", "17\n24 5 5 16 10 8 22 6 4 13 10 10 5 23 8 20 8", "18\n14 8 9 12 11 18 24 1 14 24 18 5 12 17 1 10 1 22", "19\n21 2 10 6 9 1 24 5 2 19 10 13 10 7 19 2 6 13 24", "20\n7 1 14 17 6 6 18 13 12 3 25 4 3 19 22 24 16 14 1 23", "1\n19", "20\n2 1 2 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1 22"], "outputs": ["biceps", "back", "chest", "chest", "chest", "chest", "chest", "chest", "biceps", "chest", "chest", "chest", "back", "chest", "biceps", "chest", "back", "chest", "chest", "chest", "chest", "chest", "chest", "biceps", "back", "chest", "biceps", "chest", "back", "biceps", "chest", "back", "biceps", "back", "chest", "biceps", "chest", "back", "back", "chest", "biceps", "back", "chest", "biceps", "biceps", "chest", "back", "back", "back", "chest", "back", "biceps", "biceps", "back", "chest", "chest", "chest", "chest", "biceps", "chest", "biceps"]} | UNKNOWN | PYTHON3 | CODEFORCES | 802 | |
2f7db9cb6c84ba4b95dc8cedb622e240 | Fox and Number Game | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output a single integer — the required minimal sum.
Sample Input
2
1 2
3
2 4 6
2
12 18
5
45 12 27 30 18
Sample Output
2
6
12
15
| [
"import fractions\n\n\nN = int(input())\nX = list(map(int, input().split()))\nnow = fractions.gcd(X[0], X[1])\nfor i in range(2, N):\n now = fractions.gcd(now, X[i])\n\nans = now * N\nprint(ans)\n",
"import math\r\n\r\nn = int(input())\r\narr = list(map(int, input().strip().split()))\r\nans = arr[0]\r\nfor i in range(1, n) :\r\n ans = math.gcd(ans, arr[i])\r\nans *= n\r\nprint(ans)",
"import sys\r\nimport math\r\n\r\ndef gcd(a, b):\r\n if(b == 0):\r\n return a\r\n r = a % b\r\n return gcd(b, r)\r\n\r\nn = int(sys.stdin.readline())\r\nan = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nvmin = min(an)\r\nkmin = 101\r\nfor i in range(n):\r\n t = gcd(vmin, an[i])\r\n if(t < vmin):\r\n vmin = t\r\n \r\nprint(n * t)",
"n = int(input())\r\na = list(map(int,input().split()))\r\na.sort()\r\nwhile True:\r\n\tk = 0\r\n\tfor i in range(n-1,0,-1):\r\n\t\tif a[i] > a[i-1]:\r\n\t\t\ta[i]=a[i]-a[i-1]\r\n\t\t\tk = k + 1\r\n\ta.sort()\r\n\tif k == 0:\r\n\t\tbreak\r\nprint(sum(a))",
"N = int(input())\r\nX = sorted(list(map(int, input().split())))\r\nwhile X.count(X[0]) != N:\r\n X[-1] -= X[0]\r\n X= sorted(X)\r\nprint(N*X[0])\r\n\r\n# UB_CodeForces\r\n# Advice: Be on your own\r\n# Location: Based on popular demand \"\" \"\" \"\" \"\"\r\n# Caption: Last breath\r\n# CodeNumber: 570\r\n",
"n = int(input())\nnum = input().split()\nnum = [int(x) for x in num]\n\nwhile(max(num)!= min(num)):\n maior = num.index(max(num))\n num[maior] -= min(num)\n\nsoma = 0\nfor n in num:\n soma += n\n\nprint(soma)\n \n",
"import fractions\r\nn=int(input())\r\na=0\r\nfor x in input().split():\r\n\ta=fractions.gcd(a,int(x))\r\nprint(a*n) ",
"input().split()\r\nxs = list(map(int, input().split()))\r\ndef gdc(a,b):\r\n while b > 0:\r\n a, b = b, a%b\r\n return a\r\n \r\nret = 0\r\nfor x in xs:\r\n ret = gdc(x,ret)\r\n\r\nprint(ret*len(xs))",
"import math\n\nn = int(input())\narray = input().split(\" \")\n\nfor i in range(n):\n array[i] = int(array[i])\n\nanswer = array[0]\n\nfor i in range (1, n):\n answer = math.gcd(answer, array[i])\n\nprint(answer * n)\n\n#9 3 0 3 0\n \t \t \t\t \t \t\t \t\t\t\t \t\t \t",
"n = int(input())\r\nr = lambda : list(map(int, input().split()))\r\narr = r()\r\n\r\nwhile arr.count(arr[0]) != n:\r\n x = min(arr)\r\n for i,j in enumerate(arr):\r\n if j%x==0: arr[i] = x\r\n else: arr[i] = arr[i]%x\r\n\r\nprint(sum(arr))\r\n\r\n ",
"n=int(input())\r\na=list(map(int, input().split()))\r\ndef fn(a,b):\r\n a,b=max(a,b),min(a,b)\r\n if a%b==0:return b\r\n else:return fn(a%b,b)\r\nwhile min(a)!=max(a):\r\n t1,t2=max(a),min(a)\r\n i1=a.index(t1)\r\n i2=a.index(t2)\r\n t1=t2=fn(t1,t2)\r\n a[i1]=a[i2]=t1\r\nprint(sum(a))\r\n",
"n=int(input())\r\na=list(map(int,input().split(' ')))\r\na.sort()\r\nwhile(n):\r\n x=max(a)\r\n y=min(a)\r\n xi=a.index(x)\r\n if x>y:\r\n a[xi]=x-y\r\n else:\r\n break\r\nprint(sum(a))",
"# Problem Link: https://codeforces.com/problemset/problem/389/A\r\n# Author: Raunak Sett\r\nimport sys\r\nreader = (s.rstrip() for s in sys.stdin)\r\ninput = reader.__next__\r\n\r\n# do magic here\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\ndone = False\r\n\r\nwhile not done:\r\n arr.sort(reverse=True)\r\n changed = False\r\n for i in range(1, n):\r\n if (arr[i-1] > arr[i]):\r\n arr[i-1] = arr[i-1] - arr[i]\r\n changed = True\r\n if not changed:\r\n done = True\r\n\r\nprint(sum(arr)) ",
"import sys\n\nn = int(input())\nx = list(map(int, sys.stdin.readline().split()))\n\ndef pgcd(a,b):\n while b:\n a,b = b,a%b\n return a\n\nans = x[0]\nfor i in range(1,n):\n ans = pgcd(ans,x[i])\nprint(n*ans)\n",
"input()\na = list(map(int, input().split()))\n\nwhile 1:\n\tchange = 0\n\tfor ind, i in enumerate(a):\n\t\tm = min(a)\n\t\tif i > m:\n\t\t\ta[ind] = i - m\n\t\t\tchange += 1\n\tif change == 0:\n\t\tbreak\nprint(sum(a))\n \t \t \t \t\t \t\t \t \t\t\t\t\t",
"import math\r\nn = int(input())\r\nli = list(map(int, input().split()))\r\ng = li[0]\r\nfor i in li[1:]:\r\n g = math.gcd(g, i)\r\nprint(g*n)",
"from math import gcd\r\nn=int(input())\r\nA=input().split()\r\nhcf=int(A[0])\r\nfor i in A:\r\n hcf=gcd(int(i),hcf)\r\nprint(n*hcf)",
"from math import gcd\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nfoo = a[0]\r\nfor i in range(1, n):\r\n foo = gcd(foo, a[i])\r\nprint(foo*n)\r\n \r\n \r\n",
"import math\r\nn = int(input())\r\nans = 0\r\nfor i in map(int, input().split()) : \r\n ans = math.gcd(ans, i)\r\n\r\nprint(ans * n)",
"n = int(input())\r\nnumber = [int(i) for i in input().split()]\r\nm = 1\r\n\r\nfor i in range(2,min(number) + 1):\r\n for j in number:\r\n if j % i != 0:\r\n break\r\n if j == number[-1]:\r\n m = i\r\nprint(n * m)\r\n",
"from math import *\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\ng=l[0]\r\nfor i in range(1,n):\r\n g=gcd(g,l[i])\r\nprint(g*n)",
"from math import gcd\r\nfrom functools import reduce\r\n\r\nn=int(input())\r\nprint(n*reduce(gcd,map(int,input().split())))",
"import math as m\r\nx=int(input())\r\ny=input().split()\r\np=y[0]\r\nfor i in range(len(y)):\r\n y[i]=int(y[i])\r\n p=m.gcd(int(p),int(y[i]))\r\nq=x*p\r\nprint(q)\r\n\r\n\r\n",
"from math import inf\n\nn, x = int(input()), [int(i) for i in input().split()]\nnxt_mi, mi = min(x), inf\nwhile nxt_mi < mi:\n mi = nxt_mi\n for i in range(n):\n while x[i] > mi:\n x[i] -= mi\n nxt_mi = min(nxt_mi, x[i])\nres = sum(x)\nprint(res)\n",
"import copy\r\nn = int(input())\r\nx = list(map(int, input().split()))\r\nx = sorted(x)\r\ny = []\r\n\r\nwhile x[0] != x[-1]:\r\n\tfor i in range(n-1):\r\n\t\tif x[-i-1] > x[-i-2]:\r\n\t\t\ty.append(x[-i-1]-x[-i-2])\r\n\t\telse:\r\n\t\t\ty.append(x[-i-1])\r\n\ty.append(x[0])\r\n\tx = copy.copy(y)\r\n\tx = sorted(x)\r\n\ty = []\r\n\r\nprint(x[0]*n)\r\n",
"def nod(x, y):\r\n while (x > 0) and (y > 0):\r\n if x > y:\r\n x %= y\r\n else:\r\n y %= x\r\n return (x + y)\r\n\r\n\r\ns = int(input())\r\na = [int(x) for x in input().split()]\r\nc = a[0]\r\nfor i in range(1, s):\r\n c = nod(c, a[i])\r\nprint(c * s)\r\n",
"import math\r\nn=int(input()) \r\ny=list(map(int,input().split()))\r\nh=y[0]\r\nfor i in range(1,n):\r\n h=math.gcd(h,y[i])\r\nprint(h*n)",
"\r\nfrom math import gcd\r\n\r\n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nprint(n*gcd(*l))\r\n\r\n\r\n",
"import math\r\nn = int(input())\r\nl = list(map(int , input().split()))\r\nans = l[0]\r\ni=1\r\nwhile i<len(l):\r\n ans = math.gcd(ans , l[i])\r\n i = i +1\r\nprint(ans*n)\r\n",
"'''input\n5\n45 12 27 30 18\n'''\n# I am Mr.Inconsistent \nfrom sys import stdin\nimport math\n\n\ndef equal(arr):\n\tc = arr[0]\n\tfor i in range(len(arr)):\n\t\tif arr[i] != c:\n\t\t\treturn False\n\n\telse:\n\t\treturn True\n\n# main starts\nn = int(stdin.readline().strip())\narr = list(map(int, stdin.readline().split()))\n\nwhile True:\n\tif equal(arr):\n\t\tbreak\n\n\tm = min(arr)\n\tfor i in range(len(arr)):\n\t\tif arr[i] % m == 0:\n\t\t\tarr[i] = m\n\t\telse:\n\t\t\tarr[i] %= m\nprint(sum(arr))\t\t",
"from math import gcd\r\nn = int(input())\r\nlst = list(map(int,input().split()))\r\nans = lst[0]\r\nfor i in range(1,n):\r\n ans = gcd(ans,lst[i])\r\nprint(ans * n)",
"n = int(input())\r\nstro = list(map(int, input().split()))\r\n\r\nwhile min(stro)!=max(stro):\r\n for i in range(n):\r\n for j in range(n):\r\n if stro[i]>stro[j]:\r\n stro[i]=stro[i]-stro[j]\r\nprint(sum(stro))\r\n",
"n=int(input())\r\nx=list(map(int,input().split()))\r\nx.sort()\r\nwhile x[n-1]>x[0]:\r\n for i in range(n):\r\n if x[i]>x[0] and x[i]%x[0]!=0:\r\n x[i]= x[i] % x[0]\r\n elif x[i]>x[0] and x[i]%x[0]==0:\r\n x[i]=x[0]\r\n x.sort()\r\njam=0\r\nfor i in range(n):\r\n jam+=x[i]\r\nprint(jam)",
"from math import *\nn = int(input())\ng = 0\nlst = input(\"\").split(' ')\n\n\nfor i in range(n):\n g = gcd(g,int(lst[i]))\n\nprint(g*n)\n \t \t\t \t\t\t \t \t \t\t\t\t \t \t\t\t\t",
"from math import *\r\nn=int(input())\r\na=[int(x) for x in input().split()]\r\nres=gcd(a[0],a[1])\r\nfor i in range(2,n):\r\n res=gcd(res,a[i])\r\nprint(res*n)",
"n=int(input())\r\narr=[int(i) for i in input().split()]\r\narr.sort()\r\ni=arr[0]\r\ndef gcd(arr,n):\r\n i=arr[0]\r\n while(i>1):\r\n c=0\r\n for z in arr:\r\n if z%i==0:\r\n c=c+1\r\n if c==n:\r\n return i\r\n i=i-1\r\n return 1\r\nprint(n*gcd(arr,n))",
"num = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nmn = min(arr)\r\nmx = max(arr)\r\n\r\nwhile mn != mx:\r\n\r\n arr = [i-mn if i != mn else mn for i in arr]\r\n mn = min(arr)\r\n mx = max(arr)\r\n# print(arr)\r\nprint(sum(arr))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nflag=0\r\nfor i in range(100):\r\n\ta.sort()\r\n\tfor i in range(len(a)-1,0,-1):\r\n\t\tif((a[i]-a[i-1])>0):\r\n\t\t\ta[i]=a[i]-a[i-1]\r\nprint(sum(a))",
"from math import gcd\r\n\r\n\r\ndef play_numbers(lst):\r\n g = lst[0]\r\n for i in range(1, len(lst)):\r\n g = gcd(g, lst[i])\r\n return g * len(lst)\r\n\r\n\r\nn = int(input())\r\na = [int(j) for j in input().split()]\r\nprint(play_numbers(a))",
"n=int(input())\r\nx=[int(q) for q in input().split()]\r\n\r\ndef gcd(a,b):\r\n while(b):\r\n a,b=b,a%b\r\n return a\r\ng=x[0]\r\nfor i in range(1,len(x)):\r\n g=gcd(g,x[i])\r\nprint(len(x)*g)",
"from fractions import gcd\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nk = 0\r\nfor el in a:\r\n k = gcd(k, el)\r\nk *= len(a)\r\nprint(k)",
"def gcd(a,b):\r\n if b == 0 :\r\n return a\r\n else:\r\n return gcd(b, a % b)\r\n\r\n\r\nn = int(input())\r\nnumbers = list(map(int,input().split(' ')))\r\n\r\n# print(numbers)\r\nans = 0\r\n\r\nfor i in numbers:\r\n ans = gcd(ans,i)\r\n\r\nprint(n*ans)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ndef gcd(a,b):\r\n if b==0:\r\n return a\r\n else:\r\n return gcd(b,a%b)\r\nfor i in range(len(l)):\r\n for j in range(i+1,n):\r\n l[i]=l[j]=gcd(l[i],l[j])\r\nprint(sum(l))\r\n ",
"n = int(input())\r\narr = list(map(int,input().split()))\r\n \r\nwhile len(set(arr)) > 1 :\r\n x = max(arr)\r\n y = min(arr)\r\n arr.append(x - y)\r\n arr.remove(x)\r\n \r\nprint(sum(arr))\r\n ",
"import math\r\n\r\ndef minimal_sum_of_numbers(numbers):\r\n # Calculate the GCD of all numbers in the list\r\n gcd = numbers[0]\r\n for i in range(1, len(numbers)):\r\n gcd = math.gcd(gcd, numbers[i])\r\n \r\n # Calculate the minimal sum\r\n minimal_sum = gcd * len(numbers)\r\n \r\n return minimal_sum\r\n\r\n# Example usage:\r\nn = int(input())\r\nnumbers = list(map(int, input().split()))\r\nresult = minimal_sum_of_numbers(numbers)\r\nprint(result)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nwhile len(set(l))!=1:\r\n m=min(l)\r\n for i in range(n):\r\n if l[i]!=m:\r\n if l[i]%m!=0:\r\n l[i]=l[i]-m*(l[i]//m)\r\n else:\r\n l[i]=m\r\nprint(sum(l))",
"def gcd(X,Y):\r\n X,Y = min(X,Y),max(X,Y)\r\n if(X == 0):return Y;\r\n return gcd(Y % X,X)\r\ndef F(l):\r\n A = l[0]\r\n for E in l:\r\n A = gcd(A,E)\r\n return A * len(l)\r\nn = int(input())\r\na = list(map(int , input().split()))\r\nprint(F(a))\r\n",
"from functools import reduce\n\nn = int(input())\n\nk = list(map(int,input().split()))\n\n\ntemp = 0\nans = 0\n\nwhile True:\n if len(set(k)) == 1:\n break\n\n k.sort()\n\n k.reverse()\n\n for i in range(len(k)):\n\n\n for j in range(len(k[i:])):\n\n if k[i] > k[j]:\n k[i] = k[i] - k[j]\n\n break\n\n\n\n\n\n\n\n\nprint(reduce(lambda x,y:x+y,k))\n\n\n",
"n = int(input())\r\nlst = list(map(int,input().split()))\r\n\r\nwhile(len(set(lst)) != 1):\r\n maxi = max(lst)\r\n mini = min(lst)\r\n diff = maxi - mini\r\n lst[lst.index(maxi)] = diff\r\n \r\n \r\nprint(sum(lst))",
"import math\nn = int(input())\nl = list(map(int,input().split()))\n\nk = l[0]\n\nfor i in range(1,n):\n k = math.gcd(k, l[i])\n\nprint(k*n)\n \n \n \n",
"n=int(input())\r\nl=[]\r\nl=list(map(int, input().split()))\r\nl.sort()\r\nwhile True:\r\n arr=[]\r\n for x in range(n-1):\r\n arr.append(0)\r\n for i in range(1,n):\r\n if l[i]%l[0]!=0:\r\n l[i]=l[i]%l[0]\r\n l.sort()\r\n elif l[i]%l[0]==0:\r\n l[i]=l[0]\r\n l.sort()\r\n for y in range(n-1):\r\n if l[y]==l[y+1]:\r\n arr[y]=1\r\n else:\r\n break\r\n if 0 in arr:\r\n continue\r\n else:\r\n break\r\nprint(n*l[0])\r\n",
"import math\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\n\r\n\r\nc = l[0]\r\n\r\nfor i in range(1,n):\r\n c = math.gcd(c,l[i])\r\nprint(n*c)\r\n\r\n",
"n = int(input())\r\nt = [int(i) for i in input().split()]\r\nwhile min(t) != max(t):\r\n k = min(t)\r\n for i in range(n):\r\n if t[i] > k :\r\n t[i] = t[i] % k\r\n if t[i] == 0:\r\n t[i] = k\r\ns = n * t[0]\r\nprint(s)\r\n",
"def gcd(a,b):\n if(b==0):\n return a\n else:\n return gcd(b,a%b)\nn = int(input())\nx = list(map(int,input().split()))\ni = 0\nfor i in range(n):\n x[0] = gcd(x[0],x[i])\nprint(n*x[0]) \n\n\t\t \t\t\t\t \t \t\t\t \t \t\t \t\t\t\t \t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ni=n-1\r\nwhile True:\r\n\tl.sort()\r\n\tif l[i]>l[0]:\r\n\t\tl[i]-=l[0]\r\n\t\ti-=1\r\n\telse:\r\n\t\tif l[0]==l[n-1]:\r\n\t\t\tbreak\r\n\t\ti=n-1\r\n\t\tcontinue\r\nprint(sum(l))",
"def gcd(a,b):\r\n if(b==0):\r\n return a\r\n else:\r\n return gcd(b,a%b)\r\nn=int(input())\r\nx=list(map(int,input().split()))\r\nx.sort()\r\ng=gcd(x[0],x[1])\r\nfor i in range(2,n):\r\n g=gcd(g,x[i])\r\nprint(g*n)",
"def gcd(a, b):\r\n while b != 0:\r\n a, b = b, a % b\r\n return a\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nm = a[0]\r\n\r\nfor i in range(1, n):\r\n m = (gcd(a[i], m))\r\nprint(n * m)\r\n \r\n",
"import math\r\nn = int(input())\r\narr = [int(x) for x in input().split()]\r\nhc = arr[0]\r\nfor i in range(n):\r\n hc = math.gcd(hc,arr[i])\r\n if hc == 1:\r\n break\r\nprint(hc*n) ",
"n = int(input())\r\ndata = [int(x) for x in input().split()]\r\ndata.sort()\r\nwhile data[0] != data [-1]:\r\n for i in range(n-1,0,-1):\r\n if data[i] > data[i-1]:\r\n data[i] -= data[i-1]\r\n data.sort()\r\nprint(sum(data))",
"a=int(input())\nb=[int(b) for b in input().split()]\nb.sort()\nc=0\nfor i in range(a):\n for j in range(a):\n while(b[i]<b[j]):\n b[j]=b[j]-b[i]\n while(b[i]>b[j]):\n b[i]=b[i]-b[j]\nfor i in range(a):\n for j in range(a):\n while(b[i]<b[j]):\n b[j]=b[j]-b[i]\n while(b[i]>b[j]):\n b[i]=b[i]-b[j]\nfor i in range(a):\n c=c+b[i]\nprint(c)\n \n",
"def arr_inp():\r\n return [int(x) for x in stdin.readline().split()]\r\n\r\n\r\nfrom sys import *\r\n\r\nn, a = int(input()), arr_inp()\r\n\r\nfor i in range(min(a), 0, -1):\r\n c = 0\r\n for j in a:\r\n if j % i:\r\n break\r\n else:\r\n c += 1\r\n if c == n:\r\n exit(print(i*n))\r\n",
"import fractions\nn=int(input())\na=0\nfor x in input().split():\n\ta=fractions.gcd(a,int(x))\nprint(a*n)\n",
"def gcd(a, b):\r\n if(a%b==0):\r\n return b\r\n else:\r\n return gcd(b, a%b)\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nres = arr[0]\r\nfor ele in arr:\r\n res = gcd(res, ele)\r\nprint(n*res)",
"def findDiff(values):\n one = values[0]\n for val in values:\n if(val != one):\n return True\n return False\n\nn = int(input())\nvalues = input()\nvalues = list(map(int, values.split(\" \")))\n\nwhile(findDiff(values)):\n curr = min(values)\n maximo = max(values)\n pos = 0\n for i in range(len(values)):\n if(values[i] != curr and values[i] <= maximo):\n maximo = values[i]\n pos = i\n values[pos] = values[pos] - curr\nprint(sum(values))\n\n \t \t \t \t \t\t\t\t \t\t \t \t\t \t\t",
"import math\r\nfrom functools import reduce\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n line = map(int, input().split())\r\n print(n * reduce(math.gcd, line))\r\n",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\ndef check(nums):\r\n for i in nums:\r\n if i != nums[0]:\r\n return True\r\n return False\r\n\r\nwhile(check(nums)):\r\n nums.sort()\r\n nums.reverse()\r\n for i in range(n - 1):\r\n if nums[i] > nums[i + 1]:\r\n nums[i] = nums[i] - nums[i + 1]\r\n\r\nprint(sum(nums))\r\n",
"n = int(input())\r\nnumber = [int(i) for i in input().split()]\r\n\r\nwhile True:\r\n \r\n tem_min = number[0]\r\n for i in range(n):\r\n if number[i] < tem_min:\r\n tem_min = number[i]\r\n\r\n for i in range(n):\r\n if number[i] % tem_min == 0:\r\n number[i] = tem_min\r\n else:\r\n number[i] = number[i]%tem_min\r\n\r\n if sum(number) == n*tem_min:\r\n\r\n break\r\n\r\nprint(sum(number))\r\n",
"import math\r\nfrom collections import defaultdict\r\n\r\ndef input_ints():\r\n return list(map(int, input().split()))\r\n\r\ndef solve():\r\n n = int(input())\r\n a = input_ints()\r\n x = a[0]\r\n for y in a:\r\n x = math.gcd(x, y)\r\n print(n * x)\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat May 7 14:33:56 2016\r\n\r\n@author: Alex\r\n\"\"\"\r\n\r\nn = int(input())\r\nheap = list(map(int,input().split()))\r\ns = 0\r\ndif = 1\r\ni = 0\r\nwhile dif>0:\r\n heap.sort(reverse=True)\r\n i = 1\r\n while i<n:\r\n if heap[0]==heap[i]:\r\n i+=1\r\n else:\r\n break\r\n if i == n:\r\n break\r\n dif = heap[i]\r\n heap[0] -= dif\r\nprint(sum(heap))\r\n \r\n\r\n",
"__author__ = 'Utena'\r\nn=int(input())\r\ns=list(map(int,input().split()))\r\na=s[0]\r\nfor i in range(n-1):\r\n a,b=max(a,s[i+1]),min(a,s[i+1])\r\n while True:\r\n if a%b==0:\r\n a=b\r\n break\r\n else:\r\n c=a%b\r\n a=b\r\n b=c\r\nprint(a*n)",
"import fractions\nn = int(input())\na = 0\nfor x in input().split():\n\ta = fractions.gcd(a, int(x))\nprint(a * n)\n",
"import math\r\nn = int(input())\r\nx = list(map(int,input().split()))\r\ng=x[0]\r\nfor i in range(1,n):\r\n g=math.gcd(g,x[i])\r\nprint(g*n)",
"import math\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\ncommon_gcd = math.gcd(a[0], a[1])\r\nfor i in range(2, n):\r\n common_gcd = math.gcd(common_gcd, a[i])\r\n\r\nprint(common_gcd * n)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nf=1\r\nwhile(f==1):\r\n m=0\r\n a.sort()\r\n for i in range(n-1,0,-1):\r\n if(a[i]>a[i-1]):\r\n a[i]=a[i]-a[i-1]\r\n else:\r\n m+=1\r\n if(m==n-1):\r\n print(sum(a))\r\n f=0",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\ng = lst[0]\r\n\r\ndef gcd(x, y):\r\n if x<y:\r\n return gcd(y, x)\r\n \r\n if y==0:\r\n return x\r\n \r\n return gcd(y, x%y)\r\n \r\n\r\nfor i in range(1, n):\r\n g = gcd(g, lst[i])\r\n \r\nprint(g*n)\r\n ",
"from math import *\r\nn=int(input())\r\na=input().split()\r\nb=int(a[0])\r\nfor i in range(n):\r\n b=gcd(b,int(a[i]))\r\nprint(n*b)",
"import math\nn = int(input())\nx = list(map(int, input().split()))\n\ny = x[0]\nfor i in x[1:]:\n y = math.gcd(y, i)\n \nprint(y * n)",
"n = int(input())\nx = [int(i) for i in input().split()]\n\nhcf = 1\n\nfor i in range(min(x), 0, -1):\n\tfor j in x:\n\t\tif j % i != 0:\n\t\t\tbreak\n\telse:\n\t\thcf = i\n\t\tbreak\n\nprint(i*n)\n",
"n = int(input())\r\nx = list(map(int, input().split()))\r\n\r\nwhile True:\r\n x.sort(reverse=True)\r\n if x[0] == x[-1]:\r\n break\r\n x[0] -= x[-1]\r\n\r\nprint(sum(x))\r\n",
"######################################################################\r\n# Write your code here\r\nimport sys\r\nfrom math import *\r\ninput = sys.stdin.readline\r\n#import resource\r\n#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])\r\n#sys.setrecursionlimit(0x100000)\r\n# Write your code here\r\nRI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]\r\nrw = lambda : input().strip().split()\r\nls = lambda : list(input().strip()) # for strings to list of char\r\nfrom collections import defaultdict as df\r\nimport heapq \r\n#heapq.heapify(li) heappush(li,4) heappop(li)\r\n#import random\r\n#random.shuffle(list)\r\ninfinite = float('inf')\r\n#######################################################################\r\n\r\ndef gcd(a,b):\r\n if(a<b):\r\n t=b\r\n b=a\r\n a=t\r\n while(b!=0):\r\n t=b\r\n b=a%b\r\n a=t\r\n return(a)\r\nn=int(input())\r\nl=RI()\r\ntemp=l[0]\r\n\r\nfor i in range(1,n):\r\n temp=gcd(temp,l[i])\r\n\r\nprint(temp*n)\r\n",
"from math import gcd\nfrom functools import reduce\n\n\ndef find_gcd(l):\n x = reduce(gcd, l)\n return x\n\n\n\nclass CodeforcesTask389ASolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.nums = []\n\n def read_input(self):\n self.n = int(input())\n self.nums = [int(x) for x in input().split(\" \")]\n\n def process_task(self):\n self.result = str(self.n * find_gcd(self.nums))\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask389ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n",
"from fractions import gcd\r\nfrom functools import reduce\r\nn = int(input())\r\nl = map(int,input().split())\r\nans = n * (reduce(gcd,l))\r\nprint(ans)\r\n",
"n = int(input())\r\nl = sorted(list(map(int,input().split())))\r\nchanged = True\r\nwhile changed:\r\n changed = False\r\n m = l[0]\r\n for i in range(1,n):\r\n if l[i]>m:\r\n mod = l[i]%m\r\n l[i] = mod if mod else m\r\n changed = True\r\n l = sorted(l)\r\nprint (sum(l))\r\n",
"n=int(input())\r\na=sorted(list(map(int,input().split())))\r\nflag=True\r\ni=1\r\nwhile i<n:\r\n if a[i]>a[i-1]:\r\n flag=False\r\n a[i]-=a[i-1]\r\n i+=1\r\n if not flag and i==n:\r\n a.sort()\r\n i=1\r\n flag=True\r\nprint(sum(a))",
"n = int(input())\r\nx = list(sorted(map(int, input().split())))\r\n\r\n\r\ndef gcd(a, b):\r\n while b > 0:\r\n a, b = b, a % b\r\n return a\r\n\r\ntgcd = x.pop(0)\r\nfor i in x:\r\n tgcd = gcd(tgcd, i)\r\n\r\nprint(tgcd * n)\r\n",
"import sys\r\ninp = sys.stdin.readlines()\r\n\r\nn = int(inp[0])\r\ndata = list(map(int, inp[1].split()))\r\n\r\ndef secondLargest(x):\r\n\tlist.sort(x)\r\n\ti = -2\r\n\twhile x[-1] == x[i]:\r\n\t\ti -= 1\r\n\treturn x[i]\r\n\r\nwhile True:\r\n\tif (max(data) - min(data) == 0):\r\n\t\tprint(data[0] * n)\r\n\t\tbreak\r\n\telse:\r\n\t\tdata[data.index(max(data))] = max(data) - secondLargest(data)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nwhile min(l)<max(l):l[l.index(max(l))]=max(l)-min(l)\r\nprint(sum(l))",
"n = int(input())\r\n\r\na = input().split()\r\nfor i in range(n):\r\n a[i] = int(a[i])\r\n\r\nwhile True:\r\n a.sort()\r\n k = 0\r\n for i in range(n-1):\r\n if a[i] < a[i+1]:\r\n a[i+1] -= a[i]\r\n k+=1\r\n if k == 0:\r\n break\r\n\r\ns = 0\r\nfor i in range(n):\r\n s += a[i]\r\n\r\nprint(s)",
"def find_gcd(x, y):\r\n while(y):\r\n x, y = y, x % y\r\n return x\r\n\r\nn=int(input())\r\nl = list(map(int,input().split()))\r\n \r\nnum1=l[0]\r\nnum2=l[1]\r\ngcd=find_gcd(num1,num2)\r\n \r\nfor i in range(2,len(l)):\r\n gcd=find_gcd(gcd,l[i])\r\n \r\nprint(gcd*n)",
"n=int(input())\r\nx=[int(i) for i in input().split()]\r\nwhile 1:\r\n x.sort(reverse=True)\r\n num=0\r\n i=0;\r\n while i < len(x):\r\n for j in range(i+1,len(x)):\r\n if x[j]!=x[i]:\r\n num=1\r\n for k in range(i,j):\r\n x[k]=x[k]-x[j]\r\n i=j\r\n break;\r\n if j==len(x)-1:\r\n break\r\n if num==0:\r\n break\r\nsum=0\r\nfor i in x:\r\n sum+=i\r\nprint(sum)",
"# bsdk idhar kya dekhne ko aaya hai, khud kr!!!\r\n# import math\r\n# from itertools import *\r\n# import random\r\n# import calendar\r\n# import datetime\r\n# import webbrowser\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nwhile max(arr) > min(arr):\r\n index = arr.index(max(arr))\r\n arr[index] -= min(arr)\r\nprint(sum(arr))\r\n",
"def gcd(a,b):\r\n x=max(a,b)\r\n y=min(a,b)\r\n if(x%y==0):\r\n return y\r\n else:\r\n return gcd(b,a%b)\r\n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\na=l[0]\r\nb=l[1]\r\nk=gcd(a,b)\r\nfor i in range(2,n):\r\n k=gcd(k,l[i])\r\nprint(k*n)\r\n",
"from math import gcd\ndef gcd_arr(arr):\n\tg = arr[0]\n\tfor i in range(1, len(arr)):\n\t\tg = gcd(g, arr[i])\n\treturn g\nn = int(input().strip())\narr = list(map(int, input().strip().split()))\nprint(gcd_arr(arr)*n)",
"def gcd(a,b):\n\twhile b != 0:\n\t\ta,b = b,a%b\n\treturn a\n\nn = int(input())\na = list(map(int,input().split()))\n\ns = gcd(a[0],a[1])\nfor i in range(2,n):\n\ts=gcd(s,a[i])\n\nprint(s*n)",
"x = int(input())\r\nz = []\r\nz[0:] = map(int,input().split())\r\nz.sort()\r\nw = list(z)\r\n#print(z)\r\nq = 0\r\nwhile(1):\r\n for i in range(len(z)-1):\r\n if z[i+1] != w[i]:\r\n z[i + 1] = w[i + 1] - w[i]\r\n\r\n z.sort()\r\n w = list(z)\r\n\r\n #print(z)\r\n if min(z) == max(z):# or (z[0] == 0 and z[z.index(max(z))-1] == 0 ):\r\n break\r\n\r\nprint(sum(z))\r\n",
"from math import gcd\nn=int(input())\nans=0\na=input().split()\nfor i in a:\n ans=gcd(ans,int(i))\nprint(ans*n)",
"\r\nn = int(input())\r\nx = []\r\nm = map(int,input().split())\r\nfor k in m:\r\n x.append(k)\r\n\r\nwhile True:\r\n mine = x[0]\r\n for i in range(1,n):\r\n mine = min(mine,x[i])\r\n changed = False\r\n for i in range(n):\r\n if x[i]>mine:\r\n x[i]-=mine\r\n changed = True\r\n if not changed:\r\n break\r\n\r\n\r\nsum = 0\r\nfor i in range(n):\r\n sum += x[i]\r\nprint(sum)",
"from math import gcd\nn,x=int(input()),0\nfor i in map(int,input().split()):\n x=gcd(i,x)\nprint(n*x)\n\t\t\t \t \t \t \t\t\t \t \t\t\t \t\t \t\t\t \t",
"import math\r\nn = int(input())\r\narr = [int(i) for i in input().split()]\r\ng = 0\r\nfor c in arr:\r\n g = math.gcd(g,c)\r\nprint(g*n)",
"\r\nn=int(input())\r\nt=list(map(int,input().split()))\r\nl=sorted(t,reverse=True)\r\nwhile len(set(l))!=1:\r\n l=sorted(l,reverse=True)\r\n y1=l.pop(0)\r\n y2=l.pop(0)\r\n if y1==y2:\r\n t=[y2]\r\n h=l.pop(0)\r\n while h==y1:\r\n t.append(h)\r\n h=l.pop(0)\r\n for i in t:\r\n l.append(i)\r\n l.append(y1-h)\r\n l.append(h)\r\n else:\r\n l.append(y1-y2)\r\n l.append(y2)\r\n #print(l)\r\nprint(l[0]*len(l))",
"def find_gcd(x, y):\r\n while(y):\r\n x, y = y, x % y\r\n return x\r\nn=int(input())\r\nlst=list(map(int, input().split()))\r\nnum1=lst[0]\r\nnum2=lst[1]\r\ngcd=find_gcd(num1,num2)\r\n \r\nfor i in range(2,len(lst)):\r\n gcd=find_gcd(gcd,lst[i])\r\n \r\nprint(gcd*n)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nres = sum(arr)\r\nwhile True:\r\n m = min(arr)\r\n for i in range(n):\r\n if arr[i] > m:\r\n arr[i] -= m\r\n\r\n if res > sum(arr):\r\n res = sum(arr)\r\n else:\r\n break\r\nprint(res)\r\n",
"def gcd(a,b):\r\n\tc=max(a,b)\r\n\tb=min(a,b)\r\n\ta=c\r\n\tif a%b==0:\r\n\t\treturn b\r\n\telse:\r\n\t\treturn gcd(b,a%b)\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\ng=l[0]\r\nfor i in range(1,n):\r\n\tg=gcd(g,l[i])\r\nprint(n*g)",
"'''\nCreated on 2016-4-28\n\n@author: chronocorax\n'''\ndef line(): return [int(c) for c in input().split()]\n\nn = int(input())\nx = line()\n\ndef gcd(a, b):\n if b > a: a, b = b, a\n if a % b == 0: return b\n else: return gcd(b, a % b)\n\nfrom functools import reduce\nprint(reduce(gcd, x) * n)",
"def gcd(x,y):\r\n if(x%y == 0):\r\n return y\r\n else:\r\n return gcd(y,x%y)\r\nif __name__=='__main__':\r\n n = (int)(input())\r\n x = list(map(int, input().split()))\r\n g = x[0]\r\n for i in range(len(x)):\r\n g = gcd(g,x[i])\r\n print(g*len(x))\r\n",
"from fractions import gcd\r\nn=int(input())\r\nk=0\r\nl=list(map(int,input().split()))\r\nfor i in l:\r\n k=gcd(k,i)\r\nprint(k*n)\r\n\r\n \r\n ",
"import math\n\nn = int(input())\n\narr = [int(x) for x in input().split()]\n\ngcd = math.gcd(arr[0], arr[1])\n\nfor i in range(2, n):\n gcd = math.gcd(gcd, arr[i])\n\nres = n * gcd\n\nprint(res)\n \t \t\t\t\t \t\t\t \t \t\t \t\t \t \t\t\t \t",
"n = int(input())\r\nline = list(map(int,input().split()))\r\nline.sort()\r\nflag = 0\r\nwhile flag == 0:\r\n flag = 1\r\n for i in range(n-1,0,-1):\r\n if line[i] - line[i - 1] > 0:\r\n line[i] = line[i] - line[i-1]\r\n flag = 0\r\n if(flag == 0):\r\n line.sort()\r\nprint(sum(line))",
"'''input\n2\n1 2\n'''\n\n\n\n\n\nn = int(input())\n\nl = list(map(int, input().split()))\n \nglobal minE\nminE = min(l)\n\n\ndef minimize(minE):\n\to = False\n\tcurrMin = minE\n\tfor i in range(n):\n\t\tif l[i] > minE:\n\t\t\tif l[i]%minE == 0:\n\t\t\t\tk = l[i] - (l[i]/minE - 1)*minE\n\t\t\t\tl[i] = k\n\t\t\t\tif currMin > k:\n\t\t\t\t\tcurrMin = k\n\t\t\telse:\n\t\t\t\tk = l[i] - (l[i]//minE)*minE\n\t\t\t\tl[i] = k\n\t\t\t\tif currMin > k:\n\t\t\t\t\tcurrMin = k\n\n\t\t\to = True\n\n\n\tif(o):\n\t\tminimize(currMin)\n\telse:\n\t\treturn\n\n\nx = minimize(minE)\n\n\nprint(int(sum(l)))\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
"# import sys \r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"out.out\",'w')\r\nfrom math import gcd\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ng=0\r\nfor i in range(n):\r\n\tg=gcd(a[i],g)\r\nprint(g*n)\t ",
"# BOOGEYMAN >>> Version 11.0\nimport os, sys, math, itertools, bisect\nfrom string import ascii_lowercase, ascii_uppercase\nfrom collections import deque, defaultdict, OrderedDict, Counter\nii,si = lambda : int(input()), lambda : input() \nmi, msi = lambda : map(int,input().strip().split(\" \")), lambda : map(str,input().strip().split(\" \")) \nli, lsi = lambda : list(mi()), lambda : list(msi())\n\ndef BoogeyMan() -> None:\n '''\n Query\n '''\n from math import gcd\n n,q=int(input()),0\n for i in map(int,input().split()):q=gcd(q,i)\n print(q*n)\n \n \nif __name__ == \"__main__\":\n try:\n from baba_yaga import cmdIO, _generator_\n def _BoogeyMan_() -> None : yield cmdIO(); yield BoogeyMan(); yield _generator_()\n master = _BoogeyMan_()\n try:\n while True: assert not next(master)\n except StopIteration: pass\n except (FileNotFoundError,ModuleNotFoundError): BoogeyMan()\n \t\t\t \t \t\t \t \t \t \t\t\t\t\t\t \t",
"def gcd1(x, y): \r\n while(y): \r\n x, y = y, x % y \r\n return x \r\ndef gcdn(l):\r\n gcd=gcd1(l[0],l[1])\r\n for i in range(2,len(l)): \r\n gcd=gcd1(gcd,l[i])\r\n return gcd\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\nk = gcdn(l)\r\nprint(n*k)",
"import math\r\nk=int(input())\r\nl=list(map(int,input().split()))\r\ng=max(l)\r\nfor i in l:\r\n g=math.gcd(g,i)\r\nprint(g*k)",
"n=int(input())\ns=[int(x) for x in input().split()]\nr=s[0]\ndef gcd(t,p):\n while p:\n t,p = p, t%p \n return t\nfor i in s[1:]:\n r=gcd(max(r,i), min(r,i))\nprint(r*len(s))\n",
"from math import gcd\r\nn = int(input())\r\nx = list(map(int, input().split(\" \")))\r\ngcdt = gcd(x[0],x[1])\r\nfor i in range(n):\r\n gcdt = gcd(gcdt,x[i])\r\nprint(gcdt*n)",
"import math\r\nn=int(input())\r\ng=0\r\na=list(map(int,input().split()))\r\nfor i in range(n):\r\n\tg=math.gcd(g,a[i])\r\nprint(g*n)",
"n = int(input())\r\narr = map(int,input().split())\r\narr = sorted(arr)\r\nwhile(arr[n-1]>arr[0]):\r\n for j in range(n):\r\n if arr[j]>arr[0]:\r\n arr[j]=arr[j]-arr[0]\r\n arr=sorted(arr)\r\nprint(sum(arr))",
"n = int(input())\r\ns = input().split()\r\ns = [int(i) for i in s]\r\nm = max(s)\r\nflag = 1\r\nres = 0\r\nfor i in range(2,m+1):\r\n\tc = 0\r\n\tfor j in range(n):\r\n\t\tif(s[j]%i == 0):\r\n\t\t\tc += 1\r\n\tif(c == n):\r\n\t\tres = max(res,i*n)\r\n\t\tflag = 0\r\n\r\nif(flag == 1):\r\n\tprint(n)\r\nelse:\r\n\tprint(res)\r\n\r\n",
"n = int(input())\nl = list(map(int, input().split()))\n\ni = (n-1)\n\nwhile(True):\n\tl.sort()\n\tif( l[i] > l[0]):\n\t\tl[i] -= l[0]\n\t\ti -= 1\n\telse:\n\t\tif(l[0] == l[n-1]):\n\t\t\tbreak\n\t\ti = (n-1)\n\t\tcontinue\n\n\nprint(sum(l))",
"import math\nn = int(input())\nlst = map(int, input().split())\n\na = 0\n\nfor x in lst:\n a = math.gcd(a,x)\n\nprint(a*n)\n",
"from functools import reduce\r\n\r\ngcd = lambda a, b: gcd(b, a % b) if b else a\r\n\r\nprint(int(input()) * reduce(gcd, map(int, input().split())))",
"from math import gcd\r\nn=int(input())\r\nL=list(map(int,input().split()))\r\ng=L[0]\r\nfor i in range(0,len(L)):\r\n\tg=gcd(g,L[i])\r\nprint(g*n)",
"import functools\r\nfrom math import gcd\r\nt=int(input())\r\nlst=list(map(int,input().split()))\r\nprint(functools.reduce(gcd,lst)*t)",
"n=int(input())\r\nll=input().split()\r\nl=list(map(int,ll))\r\nl.sort()\r\nfor i in range(1,n):\r\n while l[i]!=l[0]:\r\n a=max(l[i]-l[0],l[0])\r\n b=min(l[i]-l[0],l[0])\r\n l.pop(0)\r\n l.insert(0,b)\r\n l.pop(i)\r\n l.insert(i,a)\r\n l.sort()\r\nprint(l[0]*n)",
"from math import gcd\r\nn = int(input())\r\n*a, = sorted(map(int, input().split()))\r\ng = a[0]\r\nfor i in range(1, n):\r\n g = gcd(g, a[i])\r\nprint(g * n)\r\n",
"n = int(input())\r\nx = list(map(int, input().split()))\r\nwhile max(x) != min(x):\r\n x.sort(reverse=True)\r\n for i in range(n-1):\r\n if x[i] > x[i+1]:\r\n x[i] -= x[i+1]\r\n break\r\nprint(sum(x))",
"from math import *\r\nn=int(input())\r\nl=list(map(int,input().strip().split()))\r\nl.sort()\r\ngcd_value=l[0]\r\nfor i in range(1,len(l)):\r\n gcd_value=gcd(gcd_value,l[i])\r\nprint(gcd_value*n)",
"def gcd(a,b):\r\n if b==0:\r\n return a\r\n else:\r\n return gcd(b,a%b)\r\n\r\nn=int(input())\r\nx=list(map(int,input().split()))\r\nd=max(x)\r\ni=0\r\nwhile i<n:\r\n d=gcd(d,x[i])\r\n i=i+1\r\nprint(d*n)\r\n",
"from math import gcd\r\n\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n arr = list(map(int,input().split()))\r\n\r\n first = arr[0]\r\n for i in range(1,n):\r\n first=gcd(first,arr[i])\r\n print(first*n)\r\n\r\nsolve()\r\n\r\n",
"def gcd(a, b):\r\n while b != 0:\r\n a, b = b, a % b\r\n return a\r\n\r\ndef solution(x):\r\n g = gcd(x[0], x[1])\r\n for k in range(2, len(x)):\r\n g = gcd(g, x[k])\r\n return g * len(x)\r\n\r\nN = int(input())\r\nx = list(map(int, input().split()))\r\nprint(solution(x))",
"m=int(input())\r\nl=list(map(int,input().split()))\r\nl=list(set(l))\r\nl.sort(reverse=True)\r\nn=len(l)\r\nwhile n>1:\r\n l[0]-=l[1]\r\n for i in range(n-1):\r\n if l[i]<l[i+1]:\r\n l[i],l[i+1]=l[i+1],l[i]\r\n else:\r\n break\r\n if l[i]==l[i+1]:\r\n del l[i]\r\n n-=1\r\nprint(m*l[0])",
"#For fast I/O\r\nimport sys\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\n#gets gcd of 2 positive integers\r\ndef gcd(a,b):\r\n\tif a < b:\r\n\t\ta,b = b,a\r\n\twhile b != 0:\r\n\t\ta,b = b,a%b\r\n\treturn a\r\n\r\nn = int(input())\r\nl = [int(i) for i in input().split()]\r\n\r\ngcd_l = l[0]\r\nfor i in range(1,n):\r\n\tgcd_l = gcd(gcd_l, l[i])\r\n\r\nprint(gcd_l*n)\r\n",
"from functools import reduce\n\nn = int(input())\n\nm = [*map(int, input().split())]\n\nm = sorted(m, reverse=True)\n\ndef g_d_c(n1, n2):\n\n if n2 == 0:\n return n1\n else:\n return g_d_c(n2, n1 % n2)\n \n \ngcd = reduce(lambda x,y: g_d_c(x,y),m)\n\nprint (gcd*n)",
"from math import gcd\r\nn=int(input())\r\nl=[int(i) for i in input().split()]\r\nd=gcd(l[0],l[1])\r\nfor i in range(2,n):\r\n\td=gcd(d,l[i])\r\nprint(d*n)",
"import sys, os\r\nimport math\r\nfrom itertools import combinations, permutations\r\n\r\nTC = False\r\n\r\ndef find_gcd(x, y):\r\n while(y):\r\n x, y = y, x % y\r\n return x\r\n\r\ndef solve():\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n num1 = l[0]\r\n num2 = l[1]\r\n gcd = find_gcd(num1, num2)\r\n\r\n for i in range(2, len(l)):\r\n gcd = find_gcd(gcd, l[i])\r\n \r\n print(gcd*n)\r\n\r\nif os.path.exists('input.txt'):\r\n debug = True\r\n sys.stdin = open(\"input.txt\",\"r\")\r\n #sys.stdout = open(\"output.txt\",\"w\")\r\n\r\nif TC:\r\n for _ in range(int(input())):\r\n solve()\r\nelse:\r\n solve()",
"import sys\r\ninp = sys.stdin.readlines()\r\na = int(inp[0])\r\nb = list(map(int, inp[1].split()))\r\n\r\ndef secondLargest(x):\r\n\t\r\n\ti = 0 \r\n\twhile (x[0] == x[i] and i < len(x)-1): i += 1\r\n\treturn i\r\n\r\nwhile True:\r\n\tb = sorted(b, reverse = True)\r\n\tif(b[0]-b[secondLargest(b)] == 0): break\r\n\tb[0]=b[0]-b[secondLargest(b)]\r\n\r\nprint(b[0]*a)",
"import math\r\n\r\ndef minimal_sum_of_numbers(numbers):\r\n \r\n gcd = numbers[0]\r\n for i in range(1, len(numbers)):\r\n gcd = math.gcd(gcd, numbers[i])\r\n \r\n \r\n minimal_sum = gcd * len(numbers)\r\n \r\n return minimal_sum\r\n\r\n\r\nn = int(input())\r\nnumbers = list(map(int, input().split()))\r\nresult = minimal_sum_of_numbers(numbers)\r\nprint(result)\r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\n\r\nwhile True :\r\n o = min(l)\r\n \r\n if all([i == o for i in l]):\r\n break\r\n\r\n for j in range(len(l)) :\r\n if l[j] != o :\r\n l[j] -= o\r\n \r\n\r\nprint(sum(l))",
"n = int(input())\r\narr = map(int, input().split())\r\nfor i in range(n*2):\r\n arr = sorted(arr, reverse=True)\r\n for j in range(1, n):\r\n while arr[j] and arr[0] > arr[j]:\r\n arr[0] -= arr[j]\r\nprint(sum(arr))\r\n",
"input()\r\na = list(map(int, input().split()))\r\n \r\n \r\na = sorted(a, reverse=True)\r\nm = min(a)\r\n\r\ncs = sum(a)\r\n\r\nfirst=True\r\nwhile cs != sum(a) or first:\r\n cs = sum(a)\r\n first = False\r\n #print(a)\r\n m = min(a)\r\n for i in range(len(a)):\r\n if a[i] > m and a[i]%m != 0:\r\n a[i] = a[i]%m\r\n else:\r\n a[i] = m\r\n \r\n\r\nprint(sum(a))",
"def g(x):\r\n if len(x)==1:return x[0]\r\n if x[0]==0:return g(x[1:])\r\n return g([x[-1]%x[0]]+x[:-1])\r\ninput()\r\na=list(map(int,input().split()))\r\nprint(g(a)*len(a))\r\n",
"Num = int(input())\r\n\r\nArr = list(map(int,input().split()))\r\n\r\n\r\nwhile(len(set(Arr)) != 1):\r\n Minn = min(Arr)\r\n for i in range(Num):\r\n if(Arr[i] != Minn):\r\n if(Arr[i] % Minn == 0):\r\n Arr[i] = (Arr[i] - (Arr[i] // Minn - 1) * Minn)\r\n else:\r\n Arr[i] = Arr[i] % Minn\r\n\r\nprint(sum(Arr))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nwhile(len(set(a))!=1):\r\n\tw=min(a)\r\n\tfor j in range(n):\r\n\t\tif a[j]!=w and w!=0:\r\n\t\t\tif a[j]%w==0:\r\n\t\t\t\ta[j]=w\r\n\t\t\telse:\r\n\t\t\t\ta[j]=a[j]%w\r\nprint(n*a[0])",
"from math import gcd\r\nxx = input()\r\nls = map(int,input().split())\r\n \r\ng =0\r\nfor i in ls:\r\n g = gcd(g,i)\r\nprint(g*int(xx))",
"n=int(input())\r\nA=list(map(int,input().split()))\r\nconf=0\r\nwhile(conf!=1):\r\n x=min(A)\r\n conf=1\r\n for y in A:\r\n if(y%x!=0):\r\n conf=0\r\n break\r\n if(conf==0):\r\n z=A.index(x)\r\n for i in range(n):\r\n if(i==z or A[i]%x==0):\r\n continue\r\n A[i]-=x\r\nprint(x*n)\r\n",
"from functools import reduce\r\nfrom math import gcd\r\nimport math\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\n\r\ndef find_gcd(list):\r\n x = reduce(gcd, list)\r\n return x\r\n\r\n\r\ntemp = find_gcd(arr)\r\nprint(temp*n)\r\n",
"def find_minimum_sum():\r\n\tcount = int(input())\r\n\tnumbers = [int(num) for num in input().split()]\r\n\r\n\twhile True:\r\n\t\tnumbers.sort()\r\n\t\tfound = False\r\n\t\tfor index in range(count-1, 0, -1):\r\n\t\t\tif numbers[index] > numbers[index-1]:\r\n\t\t\t\tnumbers[index] -= numbers[index-1]\r\n\t\t\t\tfound = True\r\n\t\t\r\n\t\tif not found:\r\n\t\t\tprint(sum(numbers))\r\n\t\t\tbreak\r\n\r\nfind_minimum_sum()",
"def gcd (a,b):\r\n if (b == 0):\r\n return a\r\n else:\r\n return gcd (b, a % b)\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\n\r\nres = a[0]\r\nfor c in a[1::]:\r\n res = gcd(res , c)\r\n\r\nif(1 in a or res==1):\r\n print(n)\r\nelse:\r\n print(n*res)",
"n = int(input())\r\nnums = set(map(int, input().split()))\r\nwhile len(nums) > 1:\r\n max1 = max(nums)\r\n nums.discard(max1)\r\n nums.add(max1 - max(nums))\r\nprint(int(''.join(list(map(str, nums)))) * n)",
"from math import gcd\r\nprint(int(input())*gcd(*(int(e) for e in input().split())))",
"\r\nimport math\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nq=l[0]\r\nfor i in range(1,len(l)):\r\n q=math.gcd(q,l[i])\r\n if(q==1):\r\n break\r\nprint(n*q)\r\n ",
"from fractions import gcd\r\nn, val = int(input()), 0\r\nfor a in (int(x) for x in input().split()):\r\n val = a if val == 0 else gcd(val, a)\r\nprint(val * n)",
"from math import gcd\r\nfrom functools import reduce\r\nif __name__ == '__main__':\r\n #input n\r\n n = int(input())\r\n #input list of n number\r\n arr = map(int, input().split())\r\n #find greatest common divisor of all numbers in list\r\n x = reduce(gcd, arr)\r\n #print gcd\r\n print(x * n)\r\n\r\n \r\n ",
"def gcd(a, b):\r\n while b != 0:\r\n a, b = b, a % b\r\n return a\r\n\r\nn = int(input())\r\n\r\nins = input().split(\" \")\r\n\r\nmin = int(ins[0])\r\nfor i in range(1, n):\r\n min = gcd(min, int(ins[i]))\r\n\r\nprint(str(n * min))\r\n\r\n\r\n",
"n = int(input())\r\ndata = list(map(int,input().split()))\r\ndata.sort()\r\nwhile data[n-1]>data[0]:\r\n data[n-1]-=data[0]\r\n data.sort()\r\nprint(sum(data))",
"n = int(input())\nnumber = [int(i) for i in input().split()]\nodd = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,53,59,61, 67, 71, 73, 79, 83, 89, 97]\nlenth = len(odd)\n\nresult = [100] * lenth\n\nfor i in range(n):\n\tcur = number[i]\n\ttem = [0] * lenth\n\tfor j in range(lenth):\n\t\twhile cur % odd[j] == 0:\n\t\t\tcur = cur/odd[j]\n\t\t\ttem[j] += 1\n\t\tif cur % odd[j] != 0:\n\t\t\tif tem[j] < result[j]:\n\t\t\t\tresult[j] = tem[j]\n\nsumpre = 1\nfor i in range(lenth):\n\tif result[i] != 0 and result[i] != 100:\n\t\ttemp = result[i]\n\t\twhile temp > 0:\n\t\t\tsumpre *= odd[i] \n\t\t\ttemp -= 1\n\nsumnum = n * sumpre\nprint(sumnum)",
"n = int(input())\r\nv = list(map(int, input().split()))\r\n\r\ndef gcd(x, y):\r\n if y == 0:\r\n return x\r\n else:\r\n return gcd(y, x % y)\r\n\r\ng = v[0]\r\nfor each_v in v:\r\n g = gcd(g, each_v)\r\n\r\nprint(g * n)\r\n",
"from math import gcd\r\nfrom functools import reduce\r\nprint(int(input())*reduce(gcd,map(int,input().split())))",
"def gcd (x,y):\r\n if(x%y==0):\r\n return y\r\n elif(y%x==0):\r\n return x\r\n elif(x>y):\r\n return gcd(x%y,y)\r\n elif(y>x):\r\n return gcd(y%x,x)\r\nn=int(input())\r\ninp = list(map(int,input().split()))\r\nk=inp[0]\r\nfor i in range(0,len(inp)-1):\r\n k=gcd(k,inp[i+1])\r\nprint (len(inp)*k)",
"def find_gcd(x, y): \r\n \r\n while(y): \r\n x, y = y, x % y \r\n \r\n return x\r\n\r\nn=int(input())\r\narr=list(map(int , input().split()))\r\n\r\nans=arr[0]\r\n\r\nfor i in range(1,n):\r\n ans=find_gcd(ans,arr[i])\r\nprint(ans*n)\r\n",
"def gdb(a, b) :\n while b != 0 :\n tem = a%b \n a = b \n b = tem \n return a \n\nt = int(input())\nline = input()\nar = line.split()\nx = int(ar[0])\ny = int(ar[1])\nans = gdb(max(x, y), min(x, y))\nfor i in range(2, t) :\n n = int(ar[i])\n ans = gdb(max(ans, n), min(ans, n))\nprint(ans*t)\n \t\t\t \t\t\t\t \t\t \t \t\t\t \t\t \t\t \t",
"x = input()\r\nnums = input().split(\" \")\r\nfor i in range(len(nums)):\r\n nums[i] = int(nums[i])\r\ndec = False\r\nwhile True:\r\n nums.sort()\r\n count = 1\r\n for i in reversed(range(1, len(nums))):\r\n if nums[i]>nums[i-1]:\r\n nums[i]-=nums[i-1]\r\n else:\r\n count+=1\r\n if count==len(nums):\r\n break\r\nprint(sum(nums))",
"n = int(input())\r\nl = sorted(list(map(int,input().split())))\r\nfor i in range(n):\r\n for j in range(i+1,n):\r\n while l[j]-l[i]>0:\r\n l[j] = l[j]-l[i]\r\n l.sort()\r\nprint(sum(l))\r\n",
"n=int(input())\r\nl=list(map(int, input().split()))\r\nfrom math import gcd\r\nfrom functools import reduce\r\nx = reduce(gcd, l)\r\nr=x\r\nprint(r*n)",
"import math\nn = int(input())\nmylist = list(map(int, input().split(None,n)[:n]))\nfor i in range(n):\n\tif i == 0:\n\t\tmin_sum = mylist[i]\n\telse:\n\t\tmin_sum = math.gcd(min_sum,mylist[i])\nprint(n*min_sum)\n\t\t\t\t \t \t\t\t \t \t\t\t\t\t \t\t \t \t\t",
"from fractions import gcd\r\nn,a=int(input()),0\r\nfor i in map(int,input().split()):a=gcd(i,a)\r\nprint(n*a)",
"from collections import deque\r\nn=int(input())\r\nli = deque(sorted(list(map(int, input().split()))))\r\ng = li.popleft()\r\ndef gcd(a,b):\r\n if a == b or a*b==0:return min(abs(a),abs(b))\r\n else:\r\n smaller = min(abs(a),abs(b));larger=max(abs(a),abs(b))\r\n return gcd(larger-smaller,smaller)\r\nwhile li and g!=1:\r\n g=gcd(g,li.popleft())\r\nprint(g*n)",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nx=1\r\nwhile x:\r\n a=sorted(a)\r\n x=0\r\n for i in range(1,n):\r\n if(a[i]!=a[i-1]):\r\n x=1\r\n a[i]=a[i]-a[i-1]\r\nprint(sum(a))",
"a=int(input())\r\n\r\n\r\np=0\r\nt=list(map(int,input().split()))\r\n\r\nt.sort()\r\n\r\n\r\nu=t[0]\r\n\r\n\r\nwhile len(set(t))!=1:\r\n for k in range(a):\r\n if t[k]%u==0:\r\n t[k]=u\r\n else:\r\n while u!=t[k]:\r\n if u>t[k]:\r\n u-=t[k]\r\n elif t[k]>u:\r\n t[k]-=u\r\n \r\n \r\n \r\n\r\n\r\nprint(sum(t))\r\n",
"n = int(input())\nA = list(map(int, input().split()))\nfrom math import gcd\ng = 0\nfor a in A:\n g = gcd(g, a)\nprint(n * g)\n\n",
"def pairGCD(a, b):\n\twhile a:\n\t\ta, b = b % a, a\n\treturn b\n\ndef gcd(l):\n\tres = l[0]\n\tfor x in l[1:]:\n\t\tres = pairGCD(res, x)\n\treturn res\n\nn = int(input())\nl = [int(x) for x in input().split()]\nprint(gcd(l) * n)\n",
"import math\r\n\r\nn = int(input())\r\nnoList = list(map(int, input().split()))\r\n\r\nresult = math.gcd(noList[0],noList[1])\r\nfor i in range(2, n):\r\n\tresult = math.gcd(result, noList[i])\r\n\r\nprint(result*n)",
"# python 3\n\"\"\"\n\"\"\"\n\n\ndef fox_and_number_game(n_int: int, numbers_list: list) -> int:\n numbers_list.sort(reverse=True)\n while numbers_list[0] > numbers_list[-1]:\n largest_2nd_idx = 1\n while numbers_list[0] == numbers_list[largest_2nd_idx]:\n largest_2nd_idx += 1\n numbers_list[0] = numbers_list[0] - numbers_list[largest_2nd_idx]\n numbers_list.sort(reverse=True)\n return sum(numbers_list)\n\n\nif __name__ == \"__main__\":\n \"\"\"\n Inside of this is the test. \n Outside is the API\n \"\"\"\n n = int(input())\n numbers = list(map(int, input().split()))\n print(fox_and_number_game(n, numbers))\n",
"def gcd(a, b):\r\n c = a % b\r\n return gcd(b, c) if c else b\r\nn, t = int(input()), list(map(int, input().split()))\r\nj = t[0]\r\nfor i in t[1: ]: j = gcd(i, j)\r\nprint(n * j)",
"def make_remlist(lst):\r\n temp_lst = list()\r\n for i in range(len(lst)-1):\r\n for j in range(i + 1, len(lst)):\r\n if(lst[j]%lst[i] == 0):\r\n temp_lst.append(lst[i])\r\n else:\r\n temp_lst.append(lst[j]%lst[i])\r\n \r\n if(lst[i]%lst[j] == 0):\r\n temp_lst.append(lst[j])\r\n else:\r\n temp_lst.append(lst[i]%lst[j])\r\n return temp_lst\r\n\r\n\r\ndef find_rem(arr, miN):\r\n for i in range(len(arr)):\r\n if(arr[i]%miN == 0):\r\n arr[i] = miN\r\n else:\r\n arr[i] = arr[i]%miN\r\n \r\n\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\nlst2 = make_remlist(lst)\r\nwhile(len(set(lst2)) != 1):\r\n min_val = min(lst2)\r\n find_rem(lst2, min_val)\r\nprint(lst2[0]*n)",
"from math import gcd\r\nn = int(input())\r\nx = list(map(int,input().split()))\r\na = gcd(x[0],x[1])\r\nfor i in range(2,n):\r\n\ta = gcd(a,x[i])\r\nprint(n*a)",
"n=int(input())\r\nx=input().split()\r\nfor i in range(n):\r\n x[i]=int(x[i])\r\nflag=0 \r\nm2=0\r\nm1=0 \r\nwhile True:\r\n for i in range(n):\r\n if x[i]>m1:\r\n m1=x[i]\r\n index1=i\r\n if m1==100:\r\n break\r\n x[index1]=0\r\n for i in range(n):\r\n if x[i]>m2 and x[i]!=m1:\r\n m2=x[i]\r\n if m2==m1-1:\r\n break\r\n x[index1]=m1-m2\r\n for i in range(1,n):\r\n if x[0]!=x[i]:\r\n break\r\n else:\r\n flag+=1\r\n if flag==n-1:\r\n print(sum(x)) \r\n break\r\n m1=0\r\n m2=0 \r\n flag=0 \r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nflag = True\r\nwhile flag:\r\n arr.sort()\r\n arr = arr[::-1]\r\n flag = False\r\n for i in range(n-1):\r\n if arr[i]>arr[i+1]:\r\n arr[i] = arr[i]-arr[i+1]\r\n flag = True\r\n\r\nprint(sum(arr))",
"from fractions import gcd\nn = int(input())\narr = list(map(int, input().split()))\nans = arr[0]\nfor i in range(1,len(arr)):\n\tans = gcd(ans, arr[i])\nprint(ans * len(arr))",
"n = eval(input())\r\nno = list(map(eval,input().split()))\r\nwhile True:\r\n flag = False\r\n for i in no:\r\n if i<=0:\r\n continue\r\n for j in range(n):\r\n if no[j]>i:\r\n flag = True\r\n if no[j]%i == 0:\r\n no[j] = i\r\n else:\r\n no[j] = no[j]%i\r\n if flag == False:\r\n break\r\n# print(no)\r\nsum = 0\r\nfor i in no:\r\n sum += i\r\nprint(int(sum))",
"def hcfnaive(a,b): \r\n if(b==0): \r\n return a \r\n else: \r\n return hcfnaive(b,a%b) \r\n \r\nn = int(input())\r\nli = [int(x) for x in input().split()]\r\na = li[0]\r\nfor _ in range(n-1):\r\n a = hcfnaive(a , li[_+1])\r\nprint(a*n)",
"n=int(input())\r\nx=[int(i) for i in input().split()]\r\nx.sort()\r\ndef f(x,y):\r\n for i in range(1,x+1):\r\n if x%i==0 and y%i==0:\r\n m=i\r\n return m\r\n\r\na=f(x[0],x[1])\r\nfor i in range(2,len(x)):\r\n a=f(a,x[i])\r\n\r\nprint(n*a)\r\n",
"n,q=int(input()),0\r\nimport math \r\nfor i in map(int,input().split()):q=math.gcd(q,i)\r\nprint(q*n)",
"from fractions import gcd\r\nfrom functools import reduce\r\nprint(int(input()) * reduce(gcd, [int(x) for x in input().split()]))",
"from functools import *\r\nfrom fractions import *\r\nprint(int(input()) * reduce(gcd,map(int,input().split())))",
"def reduce(arr):\n\tarr.sort(reverse=True)\n\tif len(set(arr)) == 1:\n\t\treturn sum(arr)\n\tfound = False\n\tfor i in range(1, len(arr)):\n\t\tif arr[i] and arr[i] < arr[0]:\n\t\t\tarr[0] -= arr[i]\n\t\t\tfound = True\n\t\t\tbreak\n\tif not found:\n\t\treturn sum(arr)\n\treturn reduce(arr)\n\nn = int(input().strip())\narr = list(map(int, input().strip().split()))\nprint(reduce(arr))\n",
"n = int(input())\r\nlis = list(map(int,input().split()))\r\n\r\nlis.sort()\r\n\r\n\r\nwhile len(set(lis))!=1:\r\n i = 0\r\n for i in range(0,n-1):\r\n if lis[n-1-i]>lis[n-2-i]:\r\n lis[n-1-i] = lis[n-1-i] - lis[n-2-i]\r\n lis.sort()\r\n \r\nans = lis[0]*n\r\nprint(ans)",
"from collections import defaultdict, deque\nfrom functools import lru_cache\nfrom heapq import heappush, heappop\nfrom bisect import bisect_right, bisect_left\n\nimport math\nhpop = heappop\nhpush = heappush\nMOD = 10**9 + 7\ndef solution():\n n = int(input())\n arr = list(map(int, input().split()))\n while min(arr) < max(arr):\n mn = min(arr)\n for i in range(n):\n if arr[i] > mn:\n arr[i] -= mn\n print(sum(arr))\ndef main():\n t = 1\n #t = int(input())\n for _ in range(t):\n solution() \n \n#import sys\n#import threading\n#sys.setrecursionlimit(1 << 30)\n#threading.stack_size(1 << 27)\n#thread = threading.Thread(target=main)\n#thread.start(); thread.join()\nmain()\n \n \n \n \n\"\"\"\n\"\"\"\n",
"from math import gcd\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nprint(n*(gcd(*a)))",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nwhile(len(set(a))!=1):\r\n a.sort(reverse=True)\r\n for i in range(len(a)-1):\r\n if(a[i]-a[i+1]!=0):\r\n a[i]= a[i] - a[i+1]\r\nprint(sum(a))\r\n",
"n = int(input())\r\ns = input().split()\r\nfor i in range(n):\r\n s[i] = int(s[i])\r\ns = sorted(s)\r\nm = s[0]\r\nwhile m>1:\r\n jud = 0\r\n for i in s:\r\n if i%m != 0:jud = 1\r\n if jud == 0:\r\n break\r\n m -= 1\r\nprint (m*n)\r\n",
"\"\"\"\nHandle: shashank-sharma\nCreated at: 12-03-2021T17:16:49\n\"\"\"\n\nimport sys\ninput = sys.stdin.readline\n\n############ ---- Input Functions ---- ############\ndef inp():\n return(int(input()))\ndef inlt():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\ndef invr():\n return(map(int,input().split()))\n\n\n\"\"\"\n45 12 27 30 18\n\n12 18 27 30 45\n12 6 9 3 15\n3 6 9 12 15\n3 3 3 3\n\"\"\"\n\nn = inp()\nx = list(invr())\ntemp = 0\nwhile temp != n - 1:\n temp = 0\n x.sort(reverse=True)\n for i in range(1, n):\n diff = x[i-1] - x[i]\n if diff != 0:\n x[i-1] = diff\n else:\n temp += 1\nprint(sum(x))\n\n\n",
"def GCD(x,y):\r\n while (x!=y):\r\n if x<y: x,y = y,x\r\n x-=y\r\n return x\r\n\r\nn = int(input())\r\nar = list(map(int,input().split(' ')))\r\nr = ar[0]\r\nfor i in range(n-1):\r\n r = GCD(r, ar[i+1])\r\nprint(r*n)\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nimport math\r\ng = a[0]\r\n\r\nfor i in a:\r\n g = math.gcd(g, i)\r\n \r\nprint(g*n)",
"n,q=int(input()),0\nimport math \nfor i in map(int,input().split()):q=math.gcd(q,i)\nprint(q*n)\n\t\t \t\t \t\t \t \t\t\t\t\t \t \t \t \t",
"from math import gcd\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nresult = a[0]\r\nfor i in range(1, n):\r\n result = gcd(result, a[i])\r\nprint(result * n)\r\n",
"import math\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nfor i in range(n - 1):\r\n t = math.gcd(a[i], a[i + 1])\r\n a[i], a[i + 1] = t, t\r\nprint(n * min(a))\r\n",
"def nod(x,y):\r\n while x*y:\r\n if x>y:\r\n x%=y\r\n else:\r\n y%=x\r\n return x+y\r\n\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nm=a[0]\r\nfor i in range(1,n):\r\n m=nod(m,a[i])\r\nprint(n*m)",
"n=int(input())\r\nmat=list(map(int,input().split()))\r\ndef gcd(a,b):\r\n if b==0:\r\n return a\r\n else:\r\n return gcd(b,a%b)\r\nk=gcd(mat[0],mat[1])\r\nfor i in range(2,len(mat)):\r\n k=gcd(k,mat[i])\r\nprint(k*n)",
"def nod(a,b):\r\n while max(a,b) % min(a,b) != 0:\r\n if a>= b:\r\n a=a %b\r\n else:\r\n b=b%a\r\n return min(a,b)\r\n\r\nn = int(input())\r\narr = list(map(int,input().split()))\r\nx = arr[0]\r\nfor i in range(1,n):\r\n x = nod(arr[i],x)\r\nprint(x*n)",
"n=int(input())\r\nimport math\r\na=list(map(int,input().split()))\r\nx=a[0]\r\nfor i in range(1,n):\r\n x=math.gcd(x,a[i])\r\nprint(x*n)\r\n",
"input()\na = list(map(int, input().split()))\n\ndef minimal(arr, minval):\n\tif len(set(arr)) == 1:\n\t\tprint(sum(arr))\n\t\treturn\n\tfor index, i in enumerate(arr):\n\t\tif i > minval:\n\t\t\tarr[index] = i-minval\n\t\telif i < minval:\n\t\t\tminval = i\n\tminimal(arr, minval)\nminimal(a, a[0])\n\t\t\t \t\t\t\t \t\t \t \t\t \t\t\t\t \t \t\t\t \t",
"n=int(input());\nx=[int(i) for i in input().split()];\nm=min(x);\nfor i in range(m,0,-1):\n isok=True;\n for j in x:\n if(j % i): \n isok=False;\n break;\n if(isok):\n print(i*n);\n exit(0);\n",
"n = int(input())\nl = list(map(int, input().split()))\nm = min(l)\nwhile max(l) != m:\n for i in range(n):\n if l[i] > m:\n l[i] -= m\n m = min(l)\nprint(m*n)",
"import math\r\na=int(input())\r\nz=list(map(int,input().split()))\r\nz.sort()\r\nflag=0\r\nfor i in range(1,len(z)):\r\n if(math.gcd(z[i],z[0])==1):\r\n flag=1\r\n break;\r\n else:\r\n z[0]=math.gcd(z[i],z[0])\r\n \r\n \r\nif(flag==0):\r\n print(z[0]*len(z))\r\nelse:\r\n print(len(z))\r\n \r\n",
"from functools import reduce\r\nn=int(input())\r\nnumbers=list(map(int,input().split()))\r\nnumbers.sort()\r\ndef gcd(a,b):\r\n while b%a!=0:\r\n a,b=b%a,a\r\n return a\r\nprint(n*reduce(gcd,numbers))",
"n = int(input())\r\n\r\nnumbers = list(map(int, input().split()))\r\n\r\na = numbers[0]\r\nb = numbers[1]\r\n\r\nfor i in range(1, n):\r\n b = numbers[i]\r\n while a != b:\r\n if a > b:\r\n a -= b\r\n else:\r\n b -= a\r\nprint(n*a)\r\n",
"n = int(input())\r\na = list(map(int , input().split()))\r\na = sorted(a)\r\nwhile a[0] != a[n-1]:\r\n if(a[0] < a[n-1]):\r\n a[n-1] = a[n-1] - a[0]\r\n \r\n a = sorted(a)\r\n\r\nprint(sum(a))",
"# coding: utf-8\nn = int(input())\nx = [int(i) for i in input().split()]\nwhile True:\n tmp = min(x)\n for i in range(n):\n if x[i]%tmp == 0:\n x[i] = tmp\n else:\n x[i] %= tmp\n if sum(x) == tmp*n:\n break\nprint(sum(x))\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndef gcd(a,b):\r\n while (b):\r\n a,b = b, a%b\r\n return a\r\n\r\nx = gcd(a[0], a[1])\r\n\r\nfor i in range(2, n):\r\n x = gcd(x, a[i])\r\n\r\nprint(x*n)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nwhile l[0]!=l[n-1]:\r\n j=int(n-1)\r\n while j>0:\r\n if l[j]>l[j-1]:\r\n l[j]=l[j]-l[j-1]\r\n j-=1\r\n l.sort()\r\nprint(sum(l))\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\ndef hcf(x,y):\r\n while(y):\r\n x,y = y,x%y\r\n return x\r\ngcd = hcf(l[0],l[1])\r\nfor i in range(2,len(l)):\r\n gcd = hcf(gcd,l[i])\r\nprint(gcd*n)",
"from fractions import gcd\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nno=a[0]\r\nfor i in range(1,n):\r\n no=gcd(no,a[i])\r\nprint(no*n)",
"from functools import reduce\r\nn = int(input())\r\n\r\nm = [int(x) for x in input().split()]\r\n\r\nm = sorted(m, reverse=True)\r\n\r\n\r\n\r\ndef GCD(a, b):\r\n\r\n\r\n\r\n if b == 0:\r\n\r\n return a\r\n\r\n else:\r\n\r\n return GCD(b, a % b)\r\n\r\n \r\n\r\ngcd = reduce(lambda x,y:GCD(x,y),m)\r\n\r\n\r\n\r\nprint (gcd*n)\r\n \r\n\r\n \r\n\r\n\r\n \r\n\r\n \r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n",
"cnt = int(input())\r\narr = [int(i) for i in input().split()]\r\n\r\narr.sort()\r\nwhile True:\r\n for i in range(1, cnt):\r\n if(arr[i] > arr[0]):\r\n arr[i] = arr[i] % arr[0]\r\n if arr[i] == 0:\r\n arr[i] = arr[0]\r\n arr.sort()\r\n if arr[0] == arr[cnt - 1]:\r\n break\r\n\r\nsum = 0\r\nfor i in arr:\r\n sum += i\r\n\r\nprint(sum)\r\n",
"from fractions import gcd\r\nfrom functools import reduce\r\nn = int(input())\r\na = map(int, input().split())\r\nprint (n * reduce(gcd, a))\r\n",
"from math import gcd\r\nn=eval(input())\r\ns=list(map(int,input().split()))\r\nk=gcd(s[0],s[1])\r\nfor i in range(1,n-1):\r\n\tk=gcd(k,s[i+1])\r\nprint(k*n)",
"import sys\r\n\r\nflag = True\r\nn = int(input())\r\ninp = [int(x) for x in input().split()]\r\nwhile flag == True:\r\n c = 0\r\n inp.sort(reverse=True)\r\n if len(inp) == 2 and inp[0] > inp[1]:\r\n inp[0] = inp[0]-inp[1]\r\n c += 1\r\n else:\r\n for i in range(n-1):\r\n if inp[i] > inp[i+1]:\r\n c += 1\r\n inp[i] = inp[i] - inp[i+1]\r\n if c == 0:\r\n flag = False\r\n\r\nprint(sum(inp))\r\n# if len(inp) == 2 and inp[0]-inp[1] > 0:\r\n# min = inp[0]-inp[1]\r\n# else:\r\n# for i in range(n-1):\r\n# if inp[i]-inp[i+1] < min and inp[i]-inp[i+1] > 0:\r\n# min = inp[i]-inp[i+1]\r\n# if min == sys.maxsize:\r\n# print(inp[0]*n)\r\n# elif min < inp[-1]:\r\n# print(min*n)\r\n# else:\r\n# print(inp[-1]*n)\r\n",
"from sys import stdin\r\nimport math\r\nn = int(stdin.readline())\r\na = list(map(int, stdin.readline().split()))\r\nans = 0\r\nfor i in a:\r\n ans = math.gcd(ans, i)\r\n\r\nprint(ans*n)",
"n = int(input())\nx = list(map(int, input().split()))\n##greatest common divisor\ndef gcd(a , b):\n while b > 0:\n (a, b) = (b, a % b)\n return a\n\nres = x[0]\nfor i in x[1:]:\n res = gcd(res, i)\n\nprint(res*len(x))\n\n\t \t\t\t\t \t\t\t \t \t\t \t \t\t \t",
"import math \r\nn=int(input())\r\na=[int(x) for x in input().split()]\r\na.sort()\r\ng=math.gcd(a[0],a[1])\r\nfor i in range(1,len(a)):\r\n k=math.gcd(g,a[i])\r\nprint(n*k)",
"import sys\r\nfrom math import *\r\n\r\ndef minp():\r\n\treturn sys.stdin.readline().strip()\r\n\r\ndef mint():\r\n\treturn int(minp())\r\n\r\ndef mints():\r\n\treturn map(int, minp().split())\r\n\r\ndef gcd(a,b):\r\n\twhile b > 0:\r\n\t\tc = a%b\r\n\t\ta = b\r\n\t\tb = c\r\n\treturn a\r\n\r\nn = mint()\r\nz = None\r\nfor i in mints():\r\n\tif z == None:\r\n\t\tz = i\r\n\telse:\r\n\t\tz = gcd(z,i)\r\nprint(n*z)",
"import math\r\nfrom functools import reduce\r\nn = int(input())\r\ndata = [int(x) for x in input().split()]\r\nprint(reduce(lambda x,y:math.gcd(x,y),data) * n)\r\n",
"n = int(input())\r\nk = list(map(int, input().split()))\r\nk = sorted(k)\r\nr=[]\r\nfor i in k:\r\n if i not in r:\r\n r.append(i)\r\nr=sorted(r)\r\nif len(r)==1:print(len(k)*k[0])\r\nelif len(r)==2:\r\n while r[0]!=r[1]:\r\n r.append(r[1]-r[0])\r\n r=sorted(r)\r\n r.remove(r[-1])\r\n print(len(k)*r[0])\r\nelif len(k)==3:\r\n s=[]\r\n for h in range(1,len(k)):\r\n\r\n if k[h] % k[0] != 0:\r\n s.append(len(k))\r\n else:\r\n t = []\r\n for w in range(1, len(r)):\r\n t.append(r[w] - r[w - 1])\r\n s.append(min(t) * len(k))\r\n print(min(s))\r\nelif len(r)>3:\r\n t=[]\r\n for w in range(1,len(r)):\r\n t.append(r[w]-r[w-1])\r\n print(min(t)*len(k))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n = int(input())\r\nnum = [int(i) for i in input().split()]\r\nnum.sort()\r\nJ = True\r\nwhile J:\r\n J = False\r\n for i in range(1,n):\r\n temp = num[i] % num[0]\r\n if temp == 0:\r\n num[i] = num[0]\r\n else:\r\n num[i] = temp\r\n J = True\r\n num.sort()\r\n\r\nprint(sum(num))\r\n\r\n",
"def findMaxSubarraySum(arr, n, sum):\r\n\tcurr_sum = arr[0]\r\n\tmax_sum = 0\r\n\tstart = 0\r\n\tfor i in range(1, n):\r\n\t\tif (curr_sum <= sum):\r\n\t\t\tmax_sum = max(max_sum, curr_sum)\r\n\t\twhile (curr_sum + arr[i] > sum and start < i):\r\n\t\t\tcurr_sum -= arr[start]\r\n\t\t\tstart += 1\r\n\t\tcurr_sum += arr[i]\r\n\tif (curr_sum <= sum):\r\n\t\tmax_sum = max(max_sum, curr_sum)\r\n\treturn max_sum\r\n\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nl = sorted(l)\r\nl = l[::-1]\r\nwhile l.count(l[0]) != n:\r\n for i in range(n):\r\n l[i] -= findMaxSubarraySum(l, n, l[i]-1)\r\nprint(sum(l))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nwhile(len(set(a))!=1):\r\n\ta.sort(reverse=True)\r\n\tfor j in range(1,n):\r\n\t\tif a[j-1]>a[j]:\r\n\t\t\ta[j-1]-=a[j]\r\nprint(sum(a))",
"from sys import stdin\n\n\ndef main():\n n = int(stdin.readline())\n l = list(map(int, stdin.readline().split()))\n while True:\n l.sort()\n i = max(range(1, n), key=lambda _: l[_] - l[_ - 1])\n if l[i] == l[i - 1]:\n return sum(l)\n l[i] -= l[i - 1]\n\n\nprint(main())\n\n",
"import math\r\n\r\nn = int(input())\r\nlst = [int(i) for i in input().split()]\r\ngcd = lst[0]\r\n\r\nfor i in range(1, n):\r\n gcd = math.gcd(gcd, lst[i])\r\n\r\nprint(gcd*n)\r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nwhile len(set(l))>1:\r\n l = [(x%min(l))*bool(x%min(l)) + bool(not x%min(l))*min(l) for x in l]\r\nprint(sum(l))",
"from fractions import gcd\r\nn = int(input())\r\na = [int(x)for x in input().split()]\r\nx = a[0]\r\nfor i in range(1,n):\r\n\tx = gcd(x,a[i])\r\nprint(x*len(a))",
"from math import gcd\n\nn = int(input())\ng = 0\nfor i in map(int, input().split()): g = gcd(g,i)\nprint(g*n)\n\t\t\t \t\t\t\t \t \t \t\t \t \t",
"# LUOGU_RID: 101541623\nfrom math import gcd\r\nn, *a = map(int, open(0).read().split())\r\ng = a[0]\r\nfor x in a:\r\n g = gcd(g, x)\r\nprint(g * n)",
"def minimal(l):\r\n x = min(l)\r\n for i in range(x,1,-1):\r\n for j in l:\r\n if j%i != 0:\r\n break\r\n else:\r\n return(i)\r\n return(1)\r\n\r\nn = int(input())\r\nl = [int(i) for i in input().split()]\r\nprint(n*minimal(l))\r\n",
"import math\r\nn = int(input())\r\nx = list(map(int, input().split()))\r\nq = 0\r\nfor i in x:\r\n q = math.gcd(q, i)\r\nprint(q*n)\r\n",
"def gcd(a,b):\r\n if b==0:\r\n return a\r\n return gcd(b,a%b)\r\n\r\ndef gcd_arr(arr):\r\n arr.sort(reverse=True)\r\n g=gcd(l[0],l[1])\r\n for i in range(2,len(l)):\r\n g=gcd(g,l[i])\r\n return g\r\n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nprint((gcd_arr(l))*len(l))\r\n\r\n#explanation\r\n#eg: 12 18\r\n#calculating gcd\r\n#1)18-->18-12=6\r\n#2)12-->12-6=6\r\n#3)6-->6-6=0\r\n#4)gcd=6\r\n#but in this problem we only subtract if i is strictly greater than j\r\n#hence they both stop at step 2 as 6 is not greater than 6\r\n# hence both these numbers are 6 and 6 and the sum is 12. (ie 2*gcd(18,12))",
"n = int(input())\n\narr = list(map(int, input().split()))\n\narr.sort()\n\nx = arr[0]\n\nisMorePossible = True\n\ni = 1\n\nwhile True:\n if isMorePossible == False:\n break\n\n for num in range(n):\n if x == arr[num]:\n isMorePossible = False\n else:\n while x < arr[num]:\n arr[num] -= x\n isMorePossible = True\n arr.sort()\n x = arr[0]\n\nprint(sum(arr))\n",
"n=input()\r\nn1=int(n)\r\nc=list(map(int,input().split()[:n1]))\r\nc.sort(reverse=True)\r\nl=len(c)\r\ni=-1\r\nwhile i<l-2:\r\n i=i+1\r\n if i==l-1:\r\n break\r\n if c[i]>c[i+1]:\r\n c[i]=c[i]-c[i+1]\r\n c.sort(reverse=True)\r\n i=-1\r\nprint(sum(c))",
"import math\r\nn=int(input())\r\nl=map(int,input().split())\r\na=0\r\nfor i in l:\r\n a=math.gcd(a,i)\r\nprint(a*n)",
"def gcd(a, b):\n while b > 0:\n a, b = b, a % b\n return a\n\nn = int(input())\nnS = [int(x) for x in input().split()]\nanswer = nS[0]\nfor i in nS[1::]:\n answer = gcd(answer, i)\nprint(answer*n)\n\t\t \t\t\t \t \t \t \t\t \t \t \t \t",
"n=int(input())\r\na=list(map(int,input().split()))\r\nfrom math import gcd\r\nx=gcd(a[1],a[0])\r\nfor j in range(2,n):\r\n\tx=gcd(x,a[j])\r\nprint(x*n)\r\n\t",
"import math\r\nn=int(input())\r\nl=[int(i) for i in input().split()]\r\ng=l[0]\r\nfor i in range(1,n):\r\n g=math.gcd(g,l[i])\r\nprint(g*n)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\ndef sub(a,b):\r\n if a==b:\r\n return a\r\n elif a>b:\r\n return sub(a-b,b)\r\n elif a<b:\r\n return sub(a,b-a)\r\n\r\nfor i in range(n):\r\n for j in range(n-1):\r\n if (i!=j):\r\n l[i]=sub(l[i],l[j])\r\n l[j]=l[i]\r\n\r\nprint(sum(l))\r\n \r\n",
"import math\r\n\r\nn = int(input())\r\ndata = list(map(int, input().split()))\r\ntmp = data[0]\r\nfor i in data[1:]:\r\n tmp = math.gcd(tmp, i)\r\n\r\nprint(tmp * n)",
"#import math\n#n, m = input().split()\n#n = int (n)\n#m = int (m)\n#k = int (k)\nn = int(input())\n#m = int(input())\n#s = input()\n#t = input()\n#h = list(map(int, input().split()))\nb = list(map(int, input().split()))\n#c = list(map(int, input().split()))\n\n#x1, y1, x2, y2 =map(int,input().split())\n#n = int(input())\n#f = []\n#f = [0]*n\n#t = [0]*n\n#f = [(int(s1[0]),s1[1]), (int(s2[0]),s2[1]), (int(s3[0]), s3[1])]\n#f = sorted (f, key = lambda tup: tup[0] )\n\n#h = [\"\"] * n\n#f1 = sorted(f, key = lambda tup: tup[0])\n\n\n#f1 = sorted(t, key = lambda tup: tup[0])\n\nc = 0\nwhile (c < n):\n m = min(b)\n c = 0\n for i in range(n):\n if (m == b[i]):\n c += 1\n else:\n b[i] = b[i] % m\n if (b[i] == 0):\n b[i] = m\n \nprint (sum(b))\n",
"n = int(input())\nx = [int(a) for a in input().split()]\n\nx.sort()\nwhile x[0] != x[-1]:\n i = -2\n while x[-1] == x[i]:\n i -= 1\n\n x[-1] -= x[i]\n x.sort()\n\nprint(sum(x))",
"def gcd(a,b):\r\n if a%b==0:\r\n return b\r\n else:\r\n a,b = b,a%b\r\n return gcd(a,b)\r\nn = int(input())\r\narr = [int(x) for x in input().split()]\r\nhcf = arr[0]\r\nfor i in arr:\r\n hcf = gcd(i,hcf)\r\nprint(hcf*n)",
"from fractions import gcd\r\n\r\n\r\nn = int(input())\r\narr = map(int, input().split())\r\nj = next(arr)\r\nfor i in arr:\r\n j = gcd(i, j)\r\nprint(n * j)\r\n",
"from math import gcd\r\nn,q=int(input()),0\r\nfor i in map(int,input().split()):q=gcd(q,i)\r\nprint(q*n)",
"\r\nnum_inp=lambda: int(input())\r\narr_inp=lambda: list(map(int,input().split()))\r\nsp_inp=lambda: map(int,input().split())\r\nstr_inp=lambda:input()\r\nn,q=int(input()),0\r\nimport math \r\nfor i in map(int,input().split()):q=math.gcd(q,i)\r\nprint(q*n)",
"def solve():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n a.sort()\r\n while a[n-1] > a[0]:\r\n for i in range(n):\r\n if not a[i]%a[0] == 0:\r\n a[i] = a[i]%a[0]\r\n else:\r\n a[i] = a[0]\r\n a.sort()\r\n print(sum(a))\r\ntry:\r\n solve()\r\nexcept:\r\n pass",
"n = int(input())\r\na = list(map(int,input().split()))\r\ndef euclid(x,y):\r\n p = max(x,y)\r\n q = min(x,y)\r\n r = p%q\r\n while r > 0:\r\n p = q\r\n q = r\r\n r = p%q\r\n return q\r\nr = a[0]\r\nfor i in range(1,n):\r\n r = euclid(r,a[i])\r\nprint(r*n)",
"from fractions import gcd\nfrom functools import reduce\n\ndef main():\n n = int(input())\n a = sorted(list(map(int, input().split(' '))), key=lambda x: -x)\n return reduce(gcd, a) * n\n\nprint(main())\n",
"def find_gcd(x, y): \r\n \r\n while(y): \r\n x, y = y, x % y \r\n \r\n return x \r\n \r\n# Driver Code \r\nn=int(input())\r\nl = list(map(int,input().split()))\r\n \r\nnum1 = l[0] \r\nnum2 = l[1] \r\ngcd = find_gcd(num1, num2) \r\n \r\nfor i in range(2, len(l)): \r\n gcd = find_gcd(gcd, l[i]) \r\n \r\nprint(gcd*len(l))",
"n=int(input())\r\nlist=[int(i) for i in input().split()]\r\nwhile(min(list)!=max(list)):\r\n list.sort()\r\n for i in range(1,n):\r\n if(list[i]>list[0]):\r\n list[i]-=list[0]\r\nprint(sum(list)) ",
"n=int(input())\r\nx=[]\r\nx=input().split()\r\nfor i in range(0,n):\r\n x[i]=int(x[i])\r\n\r\nm1=max(x)\r\nm2=0\r\nfor i in range(0,n):\r\n if x[i]>m2 and x[i]!=m1:\r\n m2=x[i]\r\nwhile(m1!=m2)and m2!=0:\r\n i=x.index(m1)\r\n j=x.index(m2)\r\n x[i]=x[i]-x[j]\r\n m1=max(x)\r\n m2=0\r\n for i in range(0,n):\r\n if x[i]>m2 and x[i]!=m1:\r\n m2=x[i]\r\n \r\n \r\nprint(sum(x))\r\n",
"#Keshika Patwari\r\n#Indian Institute Of Technology, Jodhpur\r\n# 2022\r\nimport sys\r\ninput=sys.stdin.readline\r\ndef find_gcd(x, y):\r\n\twhile(y):\r\n\t\tx, y = y, x % y\r\n\treturn x\r\n\r\ndef exe():\r\n l.sort()\r\n #print(l)\r\n num1=l[0]\r\n num2=l[1]\r\n gcd=find_gcd(num1,num2)\r\n for i in range(2,len(l)):\r\n gcd=find_gcd(gcd,l[i])\r\n return gcd*n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nprint(exe())",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nt=[]\r\nfor i in range(1,min(l)+1):\r\n\tk=0\r\n\tfor j in range(n):\r\n\t\tif l[j]%i==0:\r\n\t\t\tk+=1\r\n\tif k==n:\r\n\t\tt.append(i)\r\nprint(n*max(t))",
"from fractions import gcd\r\nn=int(input())\r\nl=list(map(int,list(input().split())))\r\ngc=0\r\nfor i in l:\r\n gc=gcd(gc,i)\r\nprint(gc*n)\r\n",
"import math\n\nn = int(input())\n\narr = input().split()\narr = [int(i) for i in arr]\nx=arr[0]\nfor i in range(n-1):\n x = math.gcd(x,arr[i+1])\n\nprint(x*n)\n\t \t\t \t \t \t\t\t \t \t \t \t",
"N = int(input())\r\n\r\nfrom math import *\r\nA = list(map(int, input().split()))\r\nif N == 1:\r\n print(A[0])\r\nelse:\r\n g = gcd(A[0], A[1])\r\n for i in range(2, N):\r\n g = gcd(g, gcd(A[i], A[i-1]))\r\n print(g * N)",
"n = int(input())\narr = [int(x) for x in input().split()]\narr.sort()\nmdc = arr[0]\nfor i in arr[1:]:\n if mdc < i:\n aux = mdc\n mdc = i\n i = aux\n while i != 0:\n aux = i\n i = mdc % i\n mdc = aux\nprint (mdc*n)\n\t\t \t \t \t \t\t\t\t\t \t\t\t \t \t\t",
"import fractions\r\nn = int(input())\r\na = 0\r\nfor x in input().split():\r\n\ta = fractions.gcd(a, int(x))\r\nprint(a * n)",
"def GCD(x,y):\r\n while(y):\r\n x,y=y,x%y\r\n \r\n return x\r\n\r\nn=int(input())\r\n\r\nx= list(map(int, input().split()))\r\n\r\nnum1= x[0]\r\nnum2= x[1]\r\n\r\ngcd = GCD(num1, num2)\r\n\r\nfor i in range(2,len(x)):\r\n gcd = GCD(gcd, x[i])\r\nprint(gcd*n)\r\n \r\n \r\n",
"import math\r\nn=int(input())\r\nlistt=list(map(int,input().split(' ',n-1)))\r\n\r\nlistt=sorted(listt)\r\ngcd=listt[n-1]\r\nfor i in range(0,n-1):\r\n gcd=math.gcd(gcd,listt[i])\r\n\r\nprint(len(listt)*gcd)",
"# Description of the problem can be found at http://codeforces.com/problemset/problem/389/A\r\n\r\ndef gcd(a, b):\r\n if a == 0:\r\n return b\r\n elif b == 0:\r\n return a\r\n else:\r\n return gcd(b % a, a)\r\n \r\nn = int(input())\r\nl_n = list(map(int, input().split()))\r\n\r\ng = gcd(l_n[0], l_n[1])\r\nfor i in range(2, n):\r\n g = gcd(g, l_n[i])\r\n \r\nprint(g * n)",
"import sys\r\ninput = sys.stdin.readline\r\nimport math\r\n\r\nn = int(input())\r\nw = sorted(map(int, input().split()))\r\ns = w[0]\r\nfor i in range(1, n):\r\n s = math.gcd(s, w[i])\r\n if s == 1:\r\n break\r\nprint(s*n)",
"from fractions import gcd\r\na = int(input())\r\nnums = list(map(int, input().split(' ')))\r\ngcdx = nums[0]\r\nfor i in range(len(nums)):\r\n gcdx = gcd(gcdx, nums[i])\r\nprint(gcdx*a)\r\n\r\n",
"n = int(input())\nnumbers = [int(x) for x in input().split()]\n\n\nwhile True:\n x = numbers.index(ma := max(numbers))\n y = numbers.index(mi := min(numbers))\n if x != y:\n numbers[x] = ma - mi\n else:\n break\nprint(sum(numbers))\n",
"n = int(input())\nm = list(map(int, input().split()))\n\n\n\ndef bmm(a, b):\n a, b = max(a, b), min(a, b)\n while a % b != 0:\n a, b = b, a % b\n return b\n\n\nnow = m[0]\nfor i in range(n):\n now = bmm(now, m[i])\nprint(now * n)\n",
"\r\ndef log(*args): \r\n #print(*args)\r\n pass\r\n\r\nN = int(input())\r\nL = [int(n) for n in input().split()]\r\nassert N == len(L)\r\nL.sort()\r\n\r\nchanged = True\r\n\r\nwhile changed:\r\n log('begin, L=', L)\r\n blah = L[:]\r\n changed = False\r\n for i in range(N):\r\n for j in range(i):\r\n num = L[i] + L[j]\r\n if num not in blah:\r\n blah.append(num)\r\n\r\n log('blah', blah)\r\n\r\n for i in range(N):\r\n num = L[i]\r\n for n in range(num-1, -1, -1):\r\n if n in blah:\r\n log('pos', i, 'subtracting', n, 'from', L[i])\r\n L[i] = num - n\r\n changed = True\r\n break\r\n \r\n log(sum(L))\r\n\r\nlog('fin')\r\nprint(sum(L))\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nwhile(1):\r\n t=0\r\n l.sort()\r\n for i in range(n-1,0,-1):\r\n if(l[i]>l[i-1]):\r\n l[i]-=l[i-1]\r\n t=1\r\n break\r\n if(t==0):\r\n break\r\nprint(sum(l))",
"n = int(input())\r\ns = [int(i) for i in input().split()]\r\n\r\nwhile s.count(s[0])!=n:\r\n\ta = min(s)\r\n\tfor i in range(n):\r\n\t\tif s[i]>a:\r\n\t\t\ts[i]-=a\r\n\r\nprint(sum(s)) ",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\narr = sorted(arr, reverse=True)\r\nfound = True\r\nwhile found is True:\r\n found = False\r\n\r\n for i in range(n):\r\n max_j = None\r\n\r\n for j in range(n):\r\n if i != j \\\r\n and arr[i] > arr[j] \\\r\n and (max_j is None or arr[j] > arr[max_j]):\r\n max_j = j\r\n\r\n if max_j is not None:\r\n found = True\r\n arr[i] -= arr[max_j]\r\n\r\n\r\nprint(sum(arr))\r\n\r\n\r\n",
"\r\nimport math\r\nn = int(input())\r\narr = [int(x) for x in input().split()]\r\n\r\ncurr= arr[0]\r\n\r\nfor i in range(1,n):\r\n\tcurr = math.gcd(curr,arr[i])\r\n\r\nprint(n*curr)",
"import math\nn = int(input())\nl = list(map(int,input().split()))\ns = 0\nfor i in l:\n s = math.gcd(s,i)\nprint(n*s)\n\n \t \t \t \t \t \t \t \t\t\t",
"import math\r\nn, a, g = int(input()), list(map(int, input().split())), 0\r\nfor x in a: g = math.gcd(g, x)\r\nprint(g * n)",
"from math import gcd\n\nn = int(input())\narr = list(map(int, input().split()))\nal = arr[0]\nfor m in arr[1:]:\n al = gcd(m, al)\nprint(al*n)\n \t \t\t \t \t \t \t\t \t\t \t \t",
"\r\nfrom fractions import gcd\r\n\r\nn = int(input())\r\nx = []\r\nm = map(int,input().split())\r\nfor k in m:\r\n x.append(k)\r\ng = x[0]\r\nfor i in range(1,n):\r\n g = gcd(g,x[i])\r\n\r\nprint(g*n)",
"from math import *\r\nfrom collections import *\r\nfrom sys import *\r\nt=stdin.readline\r\np=stdout.write\r\ndef GI(): return map(int, t().strip().split())\r\ndef GS(): return map(str, t().strip().split())\r\ndef GL(): return list(map(int, t().strip().split()))\r\ndef SL(): return list(map(str, t().strip().split()))\r\n\r\nn=int(t())\r\na=GL()\r\ns=10**6\r\nwhile(s>sum(a)):\r\n a.sort()\r\n s=sum(a)\r\n for i in range(n-1,0,-1):\r\n if a[i]>a[i-1]:\r\n a[i]-=a[i-1]\r\n \r\np(str(sum(a)))",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nwhile min(lst)!=max(lst):\r\n a=lst.index(max(lst))\r\n b=lst.index(min(lst))\r\n lst[a]=lst[a]-lst[b]\r\nprint(sum(lst))\r\n ",
"n = int(input())\r\nk = [int(x) for x in input().split()]\r\n\r\nfor i in range(max(k), 0, -1):\r\n a = True\r\n for x in k:\r\n if x%i != 0:\r\n a = False\r\n break\r\n if a:\r\n print(i*n)\r\n break",
"n = int(input())\r\na = [int(x) for x in input().split()] \r\nwhile any(x != a[0] for x in a):\r\n a.sort()\r\n a = [a[i] - a[0] if a[i] > a[0] else a[i] for i in range(0, n)]\r\nprint(sum(a))\r\n",
"def f(x,y):\r\n while True:\r\n t=x%y\r\n x=y\r\n y=t\r\n if t==0:\r\n return x\r\nn=int(input())\r\nx=list(map(int,input().split()))\r\nj=x[0]\r\nfor i in x:\r\n j=f(j,i)\r\n #print(j)\r\nprint(j*n)\r\n",
"from math import gcd\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\nlst.sort()\r\nr = lst[0]\r\nfor x in lst[1:]:\r\n r = gcd(r, x)\r\nprint(n * r)",
"n = int(input())\r\nm = [int(k) for k in input().split()]\r\ndef g(a,b):\r\n c = a%b\r\n if c != 0:\r\n return c\r\n else:\r\n return b\r\ndef f(a,b):\r\n h = []\r\n for k in a:\r\n h.append(g(k,b))\r\n return h\r\nm.sort()\r\nwhile True:\r\n if sum(m) != n*m[0]:\r\n m = f(m,m[0])\r\n m.sort()\r\n else:\r\n break\r\nprint(m[0]*n)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nwhile(1):\r\n T = True\r\n for i in range(n):\r\n for j in range(n):\r\n if a[i] > a[j]:\r\n a[i] = a[i] - a[j]\r\n T = False\r\n elif a[i] < a[j]:\r\n a[j] = a[j] - a[i]\r\n T = False\r\n if T:\r\n break\r\nprint(sum(a))",
"from math import gcd\r\n\r\nn = int(input())\r\ng = 0\r\nfor i in map(int, input().split()): g = gcd(g,i)\r\nprint(g*n)",
"from math import gcd\r\nn = int(input()); res = 0\r\nfor i in input().split():\r\n res = gcd(res, int(i))\r\nprint(res * n)\r\n",
"n=int(input())\r\nl1=list(map(int,input().split()))\r\nimport math\r\nfor i in range(n):\r\n if i==0:\r\n x=l1[i]\r\n else :\r\n x=math.gcd(x,l1[i])\r\nprint(x*n)",
"def GCD(a, b):\r\n if b == 0:\r\n return a\r\n else:\r\n return GCD(b, a % b)\r\n\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\nrs = lst[0]\r\nfor i in range(1, n):\r\n rs = GCD(rs, lst[i])\r\nprint(rs * n)",
"n=int(input())\r\nl=sorted(list(map(int,input().split())))\r\nwhile len(set(l))!=1:\r\n l[-1]-=l[0]\r\n l.sort()\r\nprint(sum(l))",
"import sys\r\nsys.setrecursionlimit(1500)\r\ndef fun(list):\r\n list=sorted(list)\r\n c,d,i=list[0],len(list),1\r\n if list.count(c)==d:return list\r\n else:\r\n list=sorted(list)\r\n while i<d:\r\n if list[i]==c:\r\n i=i+1\r\n continue\r\n else:\r\n list[i]=list[i]-c\r\n i=i+1\r\n return(fun(list))\r\na,list=int(input()),[int(x) for x in input().split()]\r\nprint(sum(fun(list)))\r\n",
"import math \r\nn=int(input())\r\nar=input().split()\r\nb=ar[0]\r\nfor i in range (n):\r\n ar[i]=int(ar[i])\r\n b=math.gcd(int(b),int(ar[i]))\r\na=n*b\r\nprint(a)\r\n\r\n\r\n",
"N = int(input())\n\nfox_numbers = list(map(int, input().split()))\n\nif list(set(fox_numbers)) == 1:\n print(sum(fox_numbers))\nelse:\n answer = []\n times = 0\n while True:\n if len(answer) > 1 and all(e == answer[0] for e in answer):\n break\n elif times == 1:\n times = 0\n fox_numbers = answer.copy()\n answer = []\n for i in range(N):\n idx = -1\n for j in range(N):\n if i == j:\n continue\n if fox_numbers[i] > fox_numbers[j]:\n idx = j\n if idx > -1:\n answer.append(fox_numbers[i] - fox_numbers[idx])\n else:\n answer.append(fox_numbers[i])\n times += 1\n\n print(sum(answer))\n",
"n= int(input())\r\nl= list(map(int, input().split()))\r\nm= 100000\r\nt=0\r\ns=[]\r\nl.sort()\r\nwhile t<100:\r\n l.sort()\r\n for i in range(n):\r\n for j in range(i+1,n):\r\n if l[j]>l[i]:\r\n l[j]=l[j]-l[i]\r\n s.append(sum(l)) \r\n t+=1\r\n \r\nprint(min(s))",
"#!/usr/bin/env python3\n\ndef gcd(x, y):\n if y == 0 or x == 0:\n return max(x, y)\n t = x % y\n while t != 0:\n x = y\n y = t;\n t = x % y\n return y\n\ndef main():\n readData = lambda : map(int, input().split())\n n = int(input())\n X = list(readData())\n d = 0\n for x in X:\n d = gcd(d, x)\n print(d * len(X))\n\nif __name__ == \"__main__\":\n main()\n",
"n = int(input())\r\nx = list(map(int, input().split()))\r\n\r\ndone = False\r\nwhile not done:\r\n x.sort()\r\n k = n - 2\r\n while k >= 0 and x[n - 1] == x[k]:\r\n k -= 1\r\n\r\n if k < 0:\r\n done = True\r\n break\r\n\r\n x[n - 1] -= x[k]\r\n\r\nprint(sum(x))",
"from math import gcd\r\nn,x=int(input()),0\r\nfor i in map(int,input().split()):\r\n x=gcd(i,x)\r\nprint(n*x)",
"from cmath import inf\r\nfrom heapq import heapify, heappop, heappush\r\n\r\n\r\nn = int(input())\r\nnums = [int(ch) for ch in input().split(' ')]\r\nheapify(nums)\r\n\r\nwhile nums:\r\n\r\n x = heappop(nums)\r\n\r\n if len(nums) == 0:\r\n print(x * n)\r\n break\r\n if x == 1:\r\n print(n)\r\n break\r\n\r\n y = heappop(nums)\r\n\r\n if x == y or y - x == x:\r\n heappush(nums, x)\r\n else:\r\n heappush(nums, x)\r\n heappush(nums, y - x)\r\n",
"from math import gcd\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\ngcd1 = 0\r\nfor i in l:\r\n\tgcd1 = gcd(i,gcd1)\r\nprint(n*gcd1)\t",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nwhile len(set(a))!=1:\r\n for i in range(n):\r\n x=min(a)\r\n if a[i]>x:\r\n a[i]-=x\r\nprint(sum(a))\r\n\r\n",
"import math\r\nn = int(input())\r\nins = [int(x) for x in input().split()]\r\n\r\nmn = min(ins)\r\n\r\nprimeNumbers = [2 , 3]\r\n\r\nfor i in range(5 , math.ceil(math.sqrt(mn)) , 2):\r\n isPrime = True\r\n for j in primeNumbers:\r\n if i % j == 0 :\r\n isPrime = False\r\n break\r\n if isPrime:\r\n primeNumbers.append(i)\r\nprimeNumbers.insert(0 , 1)\r\n\r\nHCMs = []\r\nfor index in range(len(primeNumbers)):\r\n HCMs.insert(index , primeNumbers[index])\r\n HCMs.insert(-1-index , mn // primeNumbers[index])\r\n\r\nfor hcm in HCMs:\r\n isRight = True\r\n for num in ins:\r\n if num % hcm != 0:\r\n isRight = False\r\n if isRight:\r\n break\r\n\r\nprint(hcm * n)",
"from fractions import gcd\r\nfrom functools import reduce\r\nprint(int(input()) * reduce(gcd, map(int, input().split())))",
"n = int(input())\nele = input().split()\nele = list(map(int, ele))\n\nele.sort()\n\nwhile(ele[0]!=ele[-1]):\n for i in range(len(ele)-1, 0, -1):\n if ele[i]%ele[0]==0:\n ele[i] = ele[0]\n else:\n ele[i] = ele[i]%ele[0]\n ele.sort()\n\nprint(len(ele)*ele[0])\n\n",
"from functools import reduce\r\nfrom fractions import gcd\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ns = reduce(gcd, a)\r\nprint(s*n)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl=sorted(l)\r\nwhile len(set(l))>1 :\r\n ma=max(l)\r\n for i in range(n-2,-1,-1) :\r\n if l[i]!=ma :\r\n mi=l[i]\r\n l[n-1]=ma-mi\r\n \r\n \r\n l=sorted(l)\r\nprint(sum(l))\r\n\r\n",
"import sys, os\r\nfrom collections import defaultdict\r\nfrom math import gcd\r\ninput = sys.stdin.readline\r\nread = lambda: list(map(int, input().strip().split()))\r\n\r\n\r\n\r\ndef main():\r\n n = int(input()); arr = read()\r\n gcd_ = 0\r\n for i in arr:\r\n gcd_ = gcd(i, gcd_)\r\n print(gcd_*n)\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n\r\n\r\n\r\n\"\"\"\r\n3 2\r\n1 1\r\n2 2\r\n\r\n\r\n\r\n\"\"\"",
"n = int(input().strip())\r\nlst = list(map(int, input().split()))\r\nnum = min(lst)\r\nwhile True:\r\n for i in range(n):\r\n if lst[i] % num == 0:\r\n lst[i] = num\r\n else:\r\n lst[i] = lst[i] % num\r\n if min(lst) == max(lst):\r\n break\r\n num = min(lst)\r\nprint(sum(lst))\r\n",
"n = int(input())\nnumbers = sorted(int(x) for x in input().split())\n\nwhile True:\n element = next((first for first, second in zip(numbers, numbers[1:]) if second > first), None)\n\n if element is None:\n break\n\n numbers = sorted(number - element if number > element else number for number in numbers)\n\nprint(sum(numbers))\n\t\t\t\t\t \t \t \t\t\t\t\t\t\t\t \t \t \t\t \t\t \t",
"import math\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\ns = 0\r\nfor i in l:\r\n s = math.gcd(s,i)\r\nprint(n*s)\r\n",
"n=int(input())\r\narr=list(map(int, input().split()))\r\narr.sort()\r\nwhile(True):\r\n if(arr[0]==arr[n-1]):\r\n break;\r\n for i in range(n-1,0,-1):\r\n if(arr[i]>arr[i-1]): \r\n arr[i]=arr[i]-arr[i-1]\r\n arr.sort()\r\nprint(sum(arr))",
"from fractions import gcd\r\nfrom functools import reduce\r\n\r\nn = int(input())\r\nnums = map(int, input().split())\r\nprint(reduce(lambda x, y: gcd(x, y), nums) * n)",
"def hcf(x,y):\r\n while(y):\r\n x,y = y,x%y\r\n return x\r\n\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\nh = hcf(l[0],l[1])\r\nfor i in range(2,n):\r\n h = hcf(h,l[i])\r\nprint(h*n)",
"# Python 3.5 supports math.gcd function\r\n# fractions.gcd is now deprecated\r\n# However most linux OS only support\r\n# Python 3.4.2. Therefore I will write\r\n# the code for Euclidean algorithm\r\n\r\ndef gcd(a,b):\r\n while b:\r\n a,b = b, a%b\r\n return a\r\n\r\nn = int(input())\r\nx = [int(x) for x in input().split()]\r\n\r\ns = x[0]\r\nfor i in x[1:]:\r\n s = gcd(s, i)\r\nprint(n * s)"
] | {"inputs": ["2\n1 2", "3\n2 4 6", "2\n12 18", "5\n45 12 27 30 18", "2\n1 1", "2\n100 100", "2\n87 58", "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52", "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96", "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98", "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42", "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70", "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22", "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63", "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91", "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36", "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71", "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33", "10\n60 12 96 48 60 24 60 36 60 60", "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51", "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58", "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90", "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82", "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70", "2\n100 1", "2\n18 30", "2\n3 5", "2\n1 10", "2\n8 5", "5\n2 3 5 8 18", "5\n2 4 1 6 8", "3\n12 10 5", "3\n6 10 15"], "outputs": ["2", "6", "12", "15", "2", "200", "58", "2028", "5664", "10000", "700", "819", "4130", "1914", "945", "273", "324", "3266", "770", "120", "1020", "2900", "980", "8200", "100", "2", "12", "2", "2", "2", "5", "5", "3", "3"]} | UNKNOWN | PYTHON3 | CODEFORCES | 315 | |
2f824162334d023d3a67d940eb317f6c | Anton and Classes | Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has *n* variants when he will attend chess classes, *i*-th variant is given by a period of time (*l*1,<=*i*,<=*r*1,<=*i*). Also he has *m* variants when he will attend programming classes, *i*-th variant is given by a period of time (*l*2,<=*i*,<=*r*2,<=*i*).
Anton needs to choose exactly one of *n* possible periods of time when he will attend chess classes and exactly one of *m* possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal.
The distance between periods (*l*1,<=*r*1) and (*l*2,<=*r*2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |*i*<=-<=*j*|, where *l*1<=≤<=*i*<=≤<=*r*1 and *l*2<=≤<=*j*<=≤<=*r*2. In particular, when the periods intersect, the distance between them is 0.
Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number!
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of time periods when Anton can attend chess classes.
Each of the following *n* lines of the input contains two integers *l*1,<=*i* and *r*1,<=*i* (1<=≤<=*l*1,<=*i*<=≤<=*r*1,<=*i*<=≤<=109) — the *i*-th variant of a period of time when Anton can attend chess classes.
The following line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) — the number of time periods when Anton can attend programming classes.
Each of the following *m* lines of the input contains two integers *l*2,<=*i* and *r*2,<=*i* (1<=≤<=*l*2,<=*i*<=≤<=*r*2,<=*i*<=≤<=109) — the *i*-th variant of a period of time when Anton can attend programming classes.
Output one integer — the maximal possible distance between time periods.
Sample Input
3
1 5
2 6
2 3
2
2 4
6 8
3
1 5
2 6
3 7
2
2 4
1 4
Sample Output
3
0
| [
"# full logic before coding\r\n\r\n# test_cases = int(input())\r\n\r\n# for test_case in range(test_cases):\r\nn = int(input())\r\nmax_l1 = 0\r\nmin_r1 = 10**9 + 1\r\nfor i in range(n):\r\n l1, r1 = map(int, input().split())\r\n if l1 > max_l1:\r\n max_l1 = l1\r\n if r1 < min_r1:\r\n min_r1 = r1\r\n\r\nm = int(input())\r\nmax_l2 = 0\r\nmin_r2 = 10**9 + 1\r\nfor i in range(m):\r\n l2, r2 = map(int, input().split())\r\n if l2 > max_l2:\r\n max_l2 = l2\r\n if r2 < min_r2:\r\n min_r2 = r2\r\n\r\nans = max(max_l2 - min_r1, max_l1 - min_r2)\r\nif ans > 0:\r\n print(ans)\r\nelse:\r\n print(0)",
"\r\ndef solve():\r\n n=int(input());r=1e11;l=-1\r\n for i in range(n):\r\n x,y=map(int,input().split())\r\n r=min(r,y)\r\n l=max(l,x)\r\n ans=0\r\n for j in range(int(input())):\r\n x,y=map(int,input().split())\r\n ans=max(ans,x-r,l-y)\r\n print(ans)\r\nsolve()",
"def f():\r\n\ta, b = 1000000001, -1\r\n\tfor i in range(int(input())):\r\n\t\ts = input().split()\r\n\t\ta = min(a, int(s[1]))\r\n\t\tb = max(b, int(s[0]))\r\n\treturn a,b\r\n\r\na , b =f()\r\na1, b1=f()\r\nprint(max(0, b1-a, b-a1))",
"def func():\r\n n = int(input())\r\n mnr = 10**9+1\r\n mxl = 0\r\n for i in range(n):\r\n l, r = [int(x) for x in input().split()]\r\n mnr = min(mnr, r)\r\n mxl = max(mxl, l)\r\n return mxl, mnr\r\n\r\nl1, r1 = func()\r\nl2, r2 = func()\r\nprint(max(l1-r2, l2-r1, 0))",
"n = int(input())\r\nminr = 10**9 + 7\r\nmaxl = 0\r\n\r\nfor _ in range(n):\r\n l, r = map(int, input().split())\r\n minr = min(minr, r)\r\n maxl = max(maxl, l)\r\n\r\nm = int(input())\r\nans = 0\r\n\r\nfor _ in range(m):\r\n l, r = map(int, input().split())\r\n ans = max(ans, l - minr)\r\n ans = max(ans, maxl - r)\r\n\r\nprint(ans)\r\n",
"maxx = float(\"inf\")\r\nminR1 = minR2 = maxx\r\nmaxL1 = maxL2 = -maxx\r\n\r\nn = int(input())\r\nfor i in range(0, n):\r\n\t(l, r) = map(int, input().split())\r\n\tmaxL1 = max(maxL1, l)\r\n\tminR1 = min(minR1, r)\r\n\t\r\nm = int(input())\r\nfor i in range(0, m):\r\n\t(l, r) = map(int, input().split())\r\n\tmaxL2 = max(maxL2, l)\r\n\tminR2 = min(minR2, r)\r\nres = max(maxL2 - minR1, maxL1 - minR2)\r\nprint(max(res, 0))",
"n = int(input())\r\nmnr = 1e9+17\r\nmnl = 1e9+17\r\nmxl = -1\r\nmxr = -1\r\nfor i in range(n):\r\n c1, c2 = [int(e) for e in input().split()]\r\n if c1 > mxl:\r\n mxl = c1\r\n if c2 < mnr:\r\n mnr = c2\r\n if c1 < mnl:\r\n mnl = c1\r\n if c2 > mxr:\r\n mxr = c2\r\n\r\nm = int(input())\r\nres = 0\r\nfor i in range(m):\r\n l2, r2 = [int(e) for e in input().split()]\r\n # there is only one chess\r\n # edge case: prgm is outside the bound\r\n if l2 > mnr and l2-mnr > res:\r\n res = l2-mnr\r\n if r2 < mxl and mxl-r2 > res:\r\n res = mxl-r2\r\n if r2 < mnl and mnl-r2 > res:\r\n res = mnl-r2\r\n if l2 > mxr and l2-mxr > res:\r\n res = l2-mxr\r\n\r\nprint(res)\r\n",
"if __name__ == \"__main__\":\r\n n = int(input())\r\n min_r1 = 2 * 10 ** 9\r\n max_l1 = 0\r\n\r\n while n > 0:\r\n l1, r1 = [int(x) for x in input().split()]\r\n if r1 < min_r1:\r\n min_r1 = r1\r\n if l1 > max_l1:\r\n max_l1 = l1\r\n n -= 1\r\n\r\n m = int(input())\r\n min_r2 = 2 * 10 ** 9\r\n max_l2 = 0\r\n\r\n while m > 0:\r\n l2, r2 = [int(x) for x in input().split()]\r\n if r2 < min_r2:\r\n min_r2 = r2\r\n if l2 > max_l2:\r\n max_l2 = l2\r\n m -= 1\r\n\r\n if max_l2 - min_r1 >= 0 and max_l1 - min_r2 >= 0:\r\n print(max(max_l2 - min_r1, max_l1 - min_r2))\r\n elif max_l2 - min_r1 >= 0:\r\n print(max_l2 - min_r1)\r\n elif max_l1 - min_r2 >= 0:\r\n print(max_l1 - min_r2)\r\n else:\r\n print(0)",
"n = int(input())\r\np = []\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n p.append((a,b))\r\nm = int(input())\r\nc = []\r\nfor i in range(m):\r\n a,b = map(int,input().split())\r\n c.append((a,b))\r\ns1 = max(p ,key= lambda x:x[0])[0]\r\nt1 = min(p,key= lambda x:x[1])[1]\r\ns2 = max(c,key= lambda x:x[0])[0]\r\nt2 = min(c,key= lambda x:x[1])[1]\r\n\r\nans = 0\r\nfor i in range(m):\r\n ans = max(c[i][0]-t1,ans)\r\n ans = max(s1-c[i][1],ans)\r\nfor i in range(n):\r\n ans = max(p[i][0]-t2,ans)\r\n ans = max(s2-p[i][1],ans)\r\nprint(ans)"
] | {"inputs": ["3\n1 5\n2 6\n2 3\n2\n2 4\n6 8", "3\n1 5\n2 6\n3 7\n2\n2 4\n1 4", "20\n13 141\n57 144\n82 124\n16 23\n18 44\n64 65\n117 133\n84 117\n77 142\n40 119\n105 120\n71 92\n5 142\n48 132\n106 121\n5 80\n45 92\n66 81\n7 93\n27 71\n3\n75 96\n127 140\n54 74", "10\n16 16\n20 20\n13 13\n31 31\n42 42\n70 70\n64 64\n63 63\n53 53\n94 94\n8\n3 3\n63 63\n9 9\n25 25\n11 11\n93 93\n47 47\n3 3", "1\n45888636 261444238\n1\n244581813 591222338", "1\n166903016 182235583\n1\n254223764 902875046", "1\n1 1\n1\n1000000000 1000000000", "1\n1000000000 1000000000\n1\n1 1", "1\n1000000000 1000000000\n1\n1000000000 1000000000", "6\n2 96\n47 81\n3 17\n52 52\n50 105\n1 44\n4\n40 44\n59 104\n37 52\n2 28", "4\n528617953 528617953\n102289603 102289603\n123305570 123305570\n481177982 597599007\n1\n239413975 695033059", "7\n617905528 617905554\n617905546 617905557\n617905562 617905564\n617905918 617906372\n617905539 617905561\n617905516 617905581\n617905538 617905546\n9\n617905517 617905586\n617905524 617905579\n617905555 617905580\n617905537 617905584\n617905556 617905557\n617905514 617905526\n617905544 617905579\n617905258 617905514\n617905569 617905573", "5\n999612104 999858319\n68705639 989393889\n297814302 732073321\n577979321 991069087\n601930055 838139173\n14\n109756300 291701768\n2296272 497162877\n3869085 255543683\n662920943 820993688\n54005870 912134860\n1052 70512\n477043210 648640912\n233115268 920170255\n575163323 756904529\n183450026 469145373\n359987405 795448062\n287873006 872825189\n360460166 737511078\n76784767 806771748", "1\n1 100000000\n1\n200000000 200000010", "1\n999999995 999999996\n1\n999999998 999999999", "1\n10 100\n1\n2 5", "1\n999999992 999999993\n1\n999999996 999999997", "1\n999999997 999999997\n1\n999999999 999999999", "1\n999999999 999999999\n1\n1000000000 1000000000", "1\n1 1000000000\n1\n1000000000 1000000000", "1\n1000000000 1000000000\n1\n999999999 999999999", "1\n100000000 100000001\n1\n100000009 100000011", "1\n5 5\n1\n6 6", "1\n1000000000 1000000000\n1\n1000000000 1000000000", "1\n200000000 200000001\n1\n200000000 200000001", "1\n2 6\n1\n4 8"], "outputs": ["3", "0", "104", "91", "0", "71988181", "999999999", "999999999", "0", "42", "137124372", "404", "999541592", "100000000", "2", "5", "3", "2", "1", "0", "1", "8", "1", "0", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
2fcaec95ca0fe52784f2e76a62c1e938 | Soldier and Bananas | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Sample Input
3 17 4
Sample Output
13 | [
"k,n,w=map(int,input().split())\r\ntotal = k*(w*(w+1) // 2)\r\nborrow=max(0,total - n)\r\nprint(borrow)",
"k, n, w = (int(i) for i in input().split())\r\nsum = 0\r\nfor i in range(w):sum += (i+1)*k\r\nprint(sum - n if sum >= n else 0)",
"\r\nk,n,w = map(int, input().split())\r\n\r\ncost = 0\r\nfor i in range(1, w+1):\r\n cost += i*k\r\n\r\nif cost <= n:\r\n print(0)\r\nelse:\r\n print(cost - n)\r\n\r\n",
"while True:\r\n try:\r\n a, b, c = map(int, input().split())\r\n t = sum(i * a for i in range(1, c + 1))\r\n res = max(0, t - b)\r\n \r\n print(res)\r\n except EOFError:\r\n break\r\n",
"number = input()\r\nlist = number.split()\r\n\r\ncost = int(list[0])\r\nmoney = int(list[1])\r\nwant = int(list[2])\r\n\r\nfor i in range(want):\r\n current_cost = cost*(i + 1)\r\n money -= current_cost\r\n \r\nif money < 0:\r\n money *= -1\r\n print(money)\r\nelse:\r\n print(0)\r\n \r\n ",
"a,b,n=map(int,input().split())\r\nborrow=0\r\ntcost=(n*(n+1))//2 *a\r\nborrow=tcost-b\r\nif borrow<=0:\r\n print(0)\r\nelse:\r\n print(borrow)",
"k,n,w=map(int,input().split())\r\ncost=0\r\nfor i in range(1,w+1):\r\n cost=cost+i*k\r\nif cost>n:\r\n b=cost-n \r\nelse:\r\n b=0\r\nprint(b)\r\n",
"x,y,z=map(int,input().split())\r\ntotal=0\r\nfor i in range(1,z+1):\r\n total+=x*i;\r\nif y> total:\r\n print(0)\r\nelse:\r\n print(total-y)",
"a, n, m = map(int, input().split())\r\ns = a*((m*(m+1))//2)\r\nif s-n <= 0:\r\n print(0)\r\nelse:\r\n print(s-n)\r\n",
"k,n,w=map(int,input().split())\r\ncost=0\r\nfor i in range(0,w+1):\r\n cost= cost+k*i\r\n\r\noutput=abs(cost-n)\r\nif cost<=n:\r\n print(0)\r\nelse:\r\n print(output)",
"p,e,w=map(int,input().split())\r\ns=((2*p+p*(w-1))/2)*w\r\nif e>=s:\r\n print(0)\r\nelse:\r\n a=s-e\r\n print(int(a))",
"x,y,z=map(int,input().split())\r\na=0\r\nfor i in range(1,z+1):\r\n a+=i*x\r\nif a>y:\r\n print(a-y) \r\nelse:\r\n print(0) ",
"a, b, c = map(int, input().split())\r\ns = 0\r\nfor i in range(1, c + 1):\r\n s += i * a\r\nif s - b < 0:\r\n print(0)\r\nelse:\r\n print(s - b)",
"k,n,w=map(int,input().split())\r\nprint(max(k*w*(1+w)//2-n,0))",
"k,n,w = map(int,input().split())\r\ns = 0\r\nfor i in range(1,w+1):\r\n s += i*k\r\nif s <= n:\r\n print(0)\r\nelse:\r\n print(s-n)",
"k,n,w = map(int, input().split())\nprint(int(((k*w*(w+1))/2) - n)) if int(((k*w*(w+1))/2)) > n else print(0)\n",
"k,n,w = map(int,input().split())\r\ns = (k+w*k)*w//2\r\nif s<=n:\r\n print(0)\r\nelse:\r\n print(s-n)",
"k,n,w=map(int,input().split())\r\nt=(w*(w+1)//2)*k \r\nprint(max(0,t-n))",
"k , n, w= map(int,input().split()) \r\nfor i in range(1,w+1):\r\n n-=(k*i) \r\nif n<0 :\r\n print(abs(n))\r\nelse:\r\n print(0) ",
"k, n, w = input().split()\r\nk = int(k)\r\nn = int(n)\r\nw = int(w)\r\n\r\nw = w*(w+1)/2\r\nw = w*k\r\n\r\nif n < w:\r\n print(int(w-n))\r\nelse:\r\n print(0)\r\n",
"#import re\r\na, b, c = list(map(int, input().split()))\r\ni = c*(c+1)//2\r\nif a*i>b:\r\n print(a*i-b)\r\nelse:\r\n print(0)",
"k, n, w = list(map(int, input().split()))\r\nsu = 0\r\nfor i in range(1,w+1):\r\n su += i * k\r\nprint(max(su - n,0))\r\n",
"def totalPrice(k,w):\r\n sum= 0\r\n for i in range(1,w+1):\r\n sum+= (k*i)\r\n return sum\r\nk,n,w = list(map(int, input().split()))\r\n\r\ntoborrow = totalPrice(k,w)-n\r\nif(toborrow<=0):\r\n print(0)\r\nelse:\r\n print(toborrow)",
"k, n, w = input().split(\" \")\ncost = 0\n\nfor i in range(1, int(w)+1):\n cost += int(k)*i\nif int(n) >= cost:\n print(0)\nelse:\n print(cost - int(n))",
"k, n, w = map(int,input().split())\r\na = 0\r\nfor i in range(1,w+1):\r\n a += i * k \r\nif n >= a:\r\n print('0')\r\nelse:\r\n print(a - n)",
"k, n, w = map(int, input().split())\r\np = k * ((w*(w+1))//2)\r\nif p > n:\r\n print(p - n)\r\nelse:\r\n print(0)",
"k,n,w = map(int,input().split())\r\ntot = 0\r\nfor i in range(1,w + 1,1):\r\n tot = tot + i * k\r\nif tot <= n:\r\n print(0)\r\nelse:\r\n print(tot - n)",
"k,n,w=map(int,input().split())\r\nif (w*(w+1)/2)*k >n:\r\n print(int((w*(w+1)/2)*k-n))\r\nelse:\r\n print(0)",
"import sys\r\n\r\nnumbers = [int(i) for i in sys.stdin.readline().split()]\r\n\r\nk = numbers[0]\r\nn = numbers[1]\r\nw = numbers[2]\r\n\r\ntotal_price = 0\r\n\r\ni = 1\r\n\r\nwhile i <= w:\r\n total_price += i * k\r\n i += 1\r\n\r\nif n >= total_price:\r\n print('0')\r\nelse:\r\n print(total_price - n)",
"num=input().split()\r\nk=int(num[0])\r\nn=int(num[1])\r\nw=int(num[2])\r\nmoney=int(k*w*(w+1)/2)\r\nif money>n:\r\n x=money-n\r\nelse:\r\n x=0\r\nprint(x)",
"cost_1st,in_money,no_banana=map(int,input().split())\r\nrequired_money=cost_1st*(no_banana)*(no_banana+1)//2\r\nif(required_money>in_money):\r\n print(required_money-in_money)\r\nelse:\r\n print(0)",
"# Input the cost of the first banana, initial amount of money, and number of bananas wanted\r\nk, n, w = map(int, input().split())\r\n\r\n# Calculate the total cost to buy w bananas using the arithmetic series formula\r\ntotal_cost = k * w * (w + 1) // 2\r\n\r\n# Calculate the amount the soldier needs to borrow\r\nborrow_amount = max(0, total_cost - n) # If the soldier has enough money, borrow_amount = 0\r\n\r\nprint(borrow_amount) # Output the amount the soldier needs to borrow\r\n\r\n",
"c=list(map(int,input().split(' ')))\r\nsu=0\r\nk=c[0]\r\nn=c[1]\r\nw=c[2]\r\nfor i in range (1,w+1):\r\n su=su+i\r\nsu=su*k\r\nif n>=su:\r\n print(0)\r\nelse:\r\n print(su-n)",
"k,n,w=map(int,input().split())\r\ncost=0\r\nfor i in range(w):\r\n cost=cost+(i+1)*k\r\nif cost>=n:\r\n print(cost-n)\r\nelse:\r\n print(0)",
"k,n,w = map(int,input().split())\r\ncost = 0\r\nfor i in range(w):\r\n cost = cost + (i+1)*k\r\n\r\nif n > cost:\r\n print(0)\r\nelse:\r\n print(cost-n)\r\n\r\n",
"k, n, w = map(int, input().split())\r\ne = w * (w + 1) // 2\r\nt = k * e\r\nvlt = max(0, t - n)\r\nprint(vlt)",
"\r\na=list(map(int,input().split()))\r\nk=a[0]\r\nw=a[1]\r\nn=a[2]\r\nif n*(n+1)*k/2>w:\r\n print(int(k*n*(n+1)/2-w))\r\nelse:\r\n print(0)\r\n ",
"a,b,c=map(int,input().split(\" \"))\r\nsum=0\r\nfor i in range (1,c+1):\r\n\tval=a\r\n\tval*=i\r\n\tsum+=val\r\nif (sum<=b):\r\n\tprint('0')\r\nelse:\r\n\tprint(sum-b)",
"K, N, W = map(int, input().split())\r\nsum1 = 0\r\nfor i in range(1, W+1):\r\n sum1 += i*(K)\r\nif sum1>N:\r\n print(sum1-N)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\n\r\nneeded = int(k*(w+1)/2*w)\r\nif n >= needed:\r\n print(0)\r\nelse:\r\n print(needed - n)\r\n",
"str1=input().split()\r\nk=int(str1[0])\r\nw=int(str1[1])\r\nn=int(str1[2])\r\nif w>=k*(1+n)/2*n:\r\n print(\"0\")\r\nelse:\r\n print(int(k*(1+n)/2*n-w))",
"def dollars_to_borrow(k,n,w):\r\n cost=0\r\n for i in range(1,w+1):\r\n cost+=i*k\r\n borrow=max(0,cost-n)\r\n return borrow\r\nk,n,w=map(int,input().split())\r\nresult=dollars_to_borrow(k,n,w)\r\nprint(result)",
"k,n,w = map(int, input().split())\r\ns = w * (w + 1) // 2 * k\r\nprint(s - n if s > n else 0)",
"k, n, w = map(int,input().split())\r\nprint(((w * (w + 1 ) // 2) * k - n) if ((w * (w + 1 ) // 2) * k - n) > 0 else 0)",
"def totalCost(k, n, w):\r\n total = (w * (w + 1) // 2) * k\r\n borrow = total - n\r\n if borrow < 0:\r\n return 0\r\n else:\r\n return borrow\r\n\r\nk, n, w = map(int, input().split())\r\nresult = totalCost(k, n, w)\r\nprint(result)",
"#!/usr/bin/env python\n# coding: utf-8\n\n# In[6]:\n\n\nk,n,w = map(int,input().split())\ncost,finalcost=0,0\nfor i in range(w+1):\n cost = i*k\n finalcost+=cost\nif n>=finalcost:\n print('0')\n \nelse:\n print(finalcost-n)\n\n\n# In[ ]:\n\n\n\n\n",
"b,m,n = [int(b) for b in input().split()]\r\nz = n\r\nfor i in range(z):\r\n m = m-(b*(i+1))\r\n\r\nif m > 0:\r\n print(0)\r\nelse:\r\n x = -m\r\n print(x)\r\n",
"k, n, w = map(int, input().split())\r\ns=0\r\nfor i in range(1, w+1):\r\n s+=i*k\r\nif s>=n:\r\n print(s-n)\r\n \r\nelse:\r\n print(0)",
"# CF_Problem:\r\n\r\ndef needToBorrow(k, n, w):\r\n totalCost = 0\r\n for i in range(1, w+1):\r\n totalCost += k*i\r\n\r\n return totalCost-n if totalCost > n else 0\r\n\r\n\r\nk, n, w = [int(i) for i in input().split(\" \")]\r\nprint(needToBorrow(k, n, w))\r\n",
"k,n,w=input().split()\nk=int(k)\nn=int(n)\nw=int(w)\n\ntotal=0\n\nfor i in range(1,w+1):\n total=total+ (i*k)\n\nif n<total:\n print(total-n)\nelse:\n print(0)\n \t\t\t\t\t\t\t\t \t \t \t \t \t \t",
"k,n,w=map(int, input().split())\r\ns = k * w* (w+1)//2\r\nif s - n <= 0:\r\n\ts = n\r\nprint(s-n)",
"k,n,w=map(int,input().split())\r\nprint(max(0,w*(w+1)*k//2-n))",
"k , n ,w = input().split()\nn = int(n)\nk = int(k)\nw = int(w)\n\ntotal = 0\n\nfor i in range(1, w+1):\n total = total + i\n\ntotal = total*k\n\nif n < total:\n print(total - n )\nelse:\n print(0)\n \t\t\t\t \t\t\t\t \t\t \t\t\t\t \t\t\t \t \t\t",
"k, n, w = map(int, input().split())\r\n\r\ns = int(n - k*((w*(w+1))/2))\r\nif s>0:\r\n print(0)\r\nelse:\r\n print(abs(s))",
"single,total,num=map(int,input().split())\r\ntotal_cost=(1+num)*num*single/2\r\nif total_cost>total:\r\n borrow=total_cost-total\r\nelse:\r\n borrow=0\r\nprint(int(borrow))",
"a=input().split()\r\nk=int(a[0])\r\nn=int(a[1])\r\nw=int(a[2])\r\nmoney=int((k*(w+1)*w)/2)\r\nif n>=money:\r\n print(0)\r\nelse:\r\n print(money-n)",
"p,q,r = map(int, input().split())\r\nx = 0\r\nfor i in range(1,r+1):\r\n x += p*i\r\nif q > x:\r\n print(0)\r\nelse:\r\n print(x - q)",
"k, n, w = map(int, input().split())\r\n\r\ntotal_cost = 0\r\n\r\nfor i in range(1,w+1):\r\n new_cost = k*i\r\n total_cost += new_cost\r\n\r\nborrowed = total_cost - n\r\nif borrowed < 0:\r\n borrowed = 0\r\nprint(borrowed)",
"p,c,w = map(int,input().split())\nm = 0\nfor i in range(1,w+1):\n m += i * p\nif m >= c:\n print(m-c)\nelse:\n print(0)",
"k, n, w = map(int, input().split())\r\nq = 0\r\nfor i in range(1, w+1):\r\n q += i*k\r\nif q <= n:\r\n print(0)\r\nelse:\r\n print(q - n)",
"k, n, w = input().split()\r\nk = int(k)\r\nn = int(n)\r\nw = int(w)\r\n\r\ncena = 0\r\nfor i in range(1,w+1):\r\n cena+= k*i\r\nif (n > cena):\r\n print(0)\r\nelse:\r\n print(cena - n)",
"b=input()\r\nk,n,w=map(int,b.split())\r\na=((w+1)*w//2)*k\r\nif a-n<=0:\r\n print(0)\r\nelse:\r\n print(a-n)",
"a,b,c=map(int,input().split())\r\nk=0\r\nfor i in range(a,a*c+1,a):\r\n k+=i\r\nif k-b<0:\r\n print(0)\r\nelse:\r\n print(k-b)",
"n,m,d=map(int,input().split())\r\ns=[]\r\nfor i in range(1,d+1):\r\n s.append(i*n)\r\nsu=sum(s)\r\nif su>=m:\r\n print(su-m)\r\nelse:\r\n print(\"0\")",
"k, n, w = map(int, input().split())\r\ntotal = 0\r\nfor i in range(1, w+1):\r\n total += i*k\r\nif total > n:\r\n print(total-n)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\nj = 0\r\nfor i in range(1, w+1):\r\n j += k*i\r\nprint(0 if j <= n else j-n)",
"c = list(map(int, input().split()))\r\nk = c[0]\r\nn = c[1]\r\nw = c[2]\r\nprice = 0\r\nfor i in range(1, w + 1):\r\n price = price+i*k\r\nb = price - n\r\nif b <= 0:\r\n print(0)\r\nelse:\r\n print(b)\r\n",
"k, n, w = map(int, input().split())\r\nt = k * (w * (w + 1) // 2)\r\nm = max(t - n, 0)\r\nprint(m)\r\n",
"def solve(k, n, w):\r\n total = 0\r\n borrow = 0\r\n for i in range(1, w+1):\r\n total += i * k\r\n\r\n if total > n:\r\n return total - n\r\n else:\r\n return 0\r\n \r\n\r\n\r\n\r\ndef main():\r\n\r\n k, n, w = map(int, input().split())\r\n print(solve(k, n, w))\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"\"\"\"A. Soldier and Bananas\"\"\"\r\nk,n,w=map(int, input().split())\r\n#w num of bannana \r\n#k the cost for first bannana\r\n#n money he has\r\n#how much need to borrow money from his friend\r\ni=1\r\nc=0\r\nv=0\r\nwhile i <=w:\r\n s=i*k\r\n v+=s\r\n i+=1\r\n \r\nc+=v\r\n\r\nif n>=c:\r\n print(0)\r\nelse:\r\n l=n-c\r\n print(-l)\r\n ",
"x = list(map(int, input().split(\" \")))\ntotal = 0\nfor i in range(1,x[2]+1):\n total += i * x[0]\n\nif total - x[1] > 0:\n print(total - x[1])\nelse:\n print(0)\n\n\n \n",
"k,n,w=list(map(int,input().strip().split()))\nans=k*(w*(w+1)//2) - n\nprint(max(0,ans))\n\n\n",
"a,b,c=map(int,input().split())\r\nq=0\r\ns=0\r\nwhile c>0:\r\n s=s+c*a\r\n c=c-1\r\nif s-b>0:\r\n print(s-b)\r\nelse:\r\n print(0)",
"k,n,w=[int(x) for x in input().split()]\r\nsum=0\r\nfor i in range(1,w+1,1):\r\n sum=sum+i*k\r\nz=sum-n\r\nif z<0:\r\n z=0\r\nprint(z)",
"line = input().split(\" \")\n\nk = int(line[0])\nn = int(line[1])\nw = int(line[2])\n\n\nfor i in range(1, w+1):\n n -= i * k\n \nif n < 0:\n print(abs(n))\nelse:\n print(0)\n",
"k,n,w=map(int,input().split())\r\ny=0\r\nfor j in range(1,w+1):\r\n y+=j*k\r\nif y>n:\r\n print(y-n)\r\nelse :\r\n print(0)\r\n ",
"k,n,w = map(int, input().split())\r\nsu = 0\r\nfor i in range(1,w+1):\r\n f = i * k\r\n su += f\r\nif su > n:\r\n print(su-n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\na=k*((w+1)*w/2)\r\nif n>=a:\r\n print(0)\r\nelif n<a:\r\n print(int(a-n))",
"k,n,w=map(int,input().split())\r\na=w*k\r\nsum=(w/2*((2*k)+(w-1)*k))-n\r\nif sum>0:\r\n print(int(sum))\r\nelse:\r\n print(0)",
"k,n,w = map(int, input().split())\ndollars = 0\nfor i in range(1,w+1):\n dollars += i * k \nif dollars < n :\n print(0)\nelse:\n print(dollars-n)",
"k, n, w = list(map(int, input().split()))\r\nprint(max(0,k*w*-~w//2-n))",
"k,n,w=input().split()\r\nk,n,w=[int(k), int(n), int(w)]\r\nsumma=[]\r\nfor i in range(1,w+1):\r\n q=i*k\r\n summa.append(q)\r\nx=sum(summa)\r\nif x>n:\r\n print(x-n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\nsum=0\r\nfor i in range(1,w+1):\r\n sum=sum+i*k\r\nif(sum-n<=0):\r\n print(0)\r\nelse:\r\n print(sum-n)",
"k, n, w = map(int, input().split())\r\n\r\ns = 0\r\n\r\nfor i in range(1, w+1):\r\n s += k*i\r\n\r\nif n-s < 0:\r\n print(abs(n-s))\r\nelse:\r\n print(0)",
"k,n,w = map(int,input().split())\r\ncost = 0\r\nfor i in range(1,w+1):\r\n cost += k*i\r\nif n > cost:\r\n print(0)\r\nelse:\r\n print(cost-n)",
"k, n, w = map(int, input().split())\n\ncosto_total = (w * (w + 1) // 2) * k\n\ncantidad_prestada = max(0, costo_total - n)\n\nprint(cantidad_prestada)\n\n \t\t \t\t \t\t\t\t\t \t\t\t \t\t",
"k,n,w=list(map(int,input().split()))\r\ncount=0\r\nfor i in range(1,w+1):\r\n count+=k*i\r\nif (count<n):\r\n print(0)\r\nelse:\r\n print(count-n)\r\n",
"k, n, w = map(int, input().split())\r\ntotal_cost = k * (w * (w + 1) // 2)\r\nborrow_amount = max(0, total_cost - n)\r\nprint(borrow_amount)",
"k, n, w = map(int, input().split())\r\n\r\nprint(max(k * w * (w+1) // 2 - n, 0))\r\n",
"k,n,w = (int(x) for x in input().split())\ncost = int(w*((k+w*k)/2))\nprint(0 if (res:=cost-n) <= 0 else res)\n",
"k,n,w=map(int,input().split())\r\ntotal_c=k*(w*(w+1))//2\r\nb_a=max(0,total_c-n)\r\nprint(b_a)",
"k, n, w = map(int, input().split())\r\n\r\nsumma = 0\r\n\r\nfor i in range(1, w + 1):\r\n summa += i * k\r\n\r\nif summa - n < 1:\r\n print(0)\r\nelse:\r\n print(summa - n)\n# Tue Oct 10 2023 10:19:29 GMT+0300 (Moscow Standard Time)\n",
"S,D,n=map(int,input().split())\r\nSum=S\r\nfor i in range(2,n+1):\r\n Sum=Sum+i*S\r\n \r\nif Sum-D>=0:\r\n print(Sum-D)\r\nelse:\r\n print(0)\r\n \r\n",
"k,n,w=map(int,input().split())\r\ns=0\r\nfor i in range(w):\r\n\ts+=(i+1)*k\r\nprint(max(0,s-n))",
"k,n,w = input().split(\" \")\r\n\r\nk = int(k)\r\nw = int(w)\r\nn = int(n)\r\n\r\n\r\ntotal = (w/2)*((2*k)+(w-1)*k)\r\n\r\nif int(total)>n:\r\n print(int(total-n))\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\ntotal_cost = (w * (w + 1) // 2) * k # Total cost of w bananas using arithmetic sum formula\r\nborrow = max(0, total_cost - n) # Calculate the amount to borrow, ensuring it's non-negative\r\nprint(borrow)",
"def bananas(k, n, w):\r\n total = k * ((w*(w+1))//2)\r\n if total > n:\r\n return total - n\r\n else:\r\n return 0\r\n\r\n\r\nif __name__ == '__main__':\r\n k, n, w = list(map(int, input().split()))\r\n print(bananas(k, n, w))",
"k,n,w=map(int,input().split())\r\n\r\n\r\ntotal=0\r\nfor x in range(1,w+1):\r\n total=total+x*k\r\n\r\nif total>n:\r\n friend=total-n\r\n print(friend)\r\nif total<=n:\r\n print(0)",
"k , n , w = map(int , input().split())\r\ncost = int((w*(w+1)/2)*k)\r\nprint(cost-n) if cost-n>=0 else print(0)\r\n",
"a = 1\ninfo = input(). split()\ncost = int(info[0])\ncash = int(info[1])\nneed_banans = int(info[2])\nhave_bananas = 0\n\nwhile have_bananas != need_banans:\n cash -= cost*a\n a += 1\n have_bananas +=1\nif cash < 0:\n print(abs(cash))\nelse:\n print(0)",
"info=input().split()\r\nk=int(info[0])\r\nn=int(info[1])\r\nw=int(info[-1])\r\np=0\r\nfor i in range(w):\r\n p+=(i+1)*k\r\nif p>=n:\r\n print(p-n)\r\nelse:\r\n print(0)",
"price, dollars, amount = map(int, input().split())\r\n\r\n\r\nans = (amount) * (amount + 1) // 2 * price - dollars\r\n\r\nprint(ans if ans > 0 else 0)",
"data_list = input().split()\r\n\r\ndata_list = list(map(int, data_list))\r\n\r\n# for i in range(len(list)):\r\n# list[i] = int(list[i])\r\n\r\nk, n, w = data_list\r\n# k стоимость первого банана\r\n# n изначальное количество долларов у солдата\r\n# w количество бананов, которые он хочет купить.\r\n\r\nprice = 0\r\nfor i in range(1, w + 1):\r\n price += k * i\r\n\r\nif price > n:\r\n print(price - n)\r\nelse:\r\n print(0)",
"b,i,o=map(int, input().split(' '))\r\nk=int((((1+o)*o)/2)*b-i)\r\nif k>0:\r\n\tprint(k)\r\nelse:\r\n\tprint(0)",
"k,n,w=map(int,input().split())\r\nprint(max(0,k*w*-~w//2-n))\r\n",
"k,n,w=map(int,input().split())\r\nfor i in range(w):\r\n n-=(i+1)*k\r\nif n<0:\r\n print(abs(n))\r\nelse:\r\n print(0)\r\n \r\n",
"k, n, w = map(int, input().split())\r\nresult = (k * ((w * (w + 1)) / 2)) - n\r\nif result < 0:\r\n print(\"0\")\r\nelse:\r\n print(int(result))",
"k, n, w = map(int, input().split())\r\nt_cost = (w * (w + 1) // 2) * k \r\nb = max(0, t_cost - n)\r\nprint(b)\r\n",
"k,n,w=map(int,input().split())\r\nc=0\r\nfor i in range(1,w+1):c+=i*k\r\nif c>n:\r\n\tprint(c-n)\r\nelse:\r\n\tprint('0')",
"k,n,w=map(int,input().split())\r\ns=0\r\nfor i in range(w):\r\n s+=k*(i+1)\r\na=s-n\r\nif a<0:\r\n print(\"0\")\r\nelse:\r\n print(a)",
"a,b,c=map(int,input().split())\r\ns=0\r\nfor i in range(1,c+1):\r\n s=s+(i*a)\r\nr=s-b\r\nif r>0:print(r)\r\nelse:print(0)\r\n",
"k,n,w=map(int,input().split())\r\ntotal_cost = k * w * (w + 1) // 2 \r\nborrowed_amount = max(0, total_cost - n)\r\nprint(borrowed_amount)",
"k,n,w=map(int,input().split())\nproduct = k\nb=1\nsum = 0\nwhile b<=w:\n product = k*b\n sum = sum + product\n b=b+1\namount=sum-n\nif amount<=0:\n print(0)\nelse:\n print(amount)\n",
"(k,n,w)=map(int,input().split())\r\nneed = k*(w+1)*w/2\r\nif need >= n:\r\n print(int(need-n))\r\nelse:\r\n print(0)",
"k, n, w = input().split()\nn = int(n)\nk = int(k)\nw = int(w)\n\ntotal = 0\n\nfor i in range(1, w+1):\n total = total + (i*k)\n\nif n < total:\n print(total - n)\nelse:\n print(0)\n\t\t\t\t\t\t \t \t\t \t\t\t\t\t\t \t",
"k,n,w = map(int,input().split())\r\nreq = (w*(w+1))//2\r\nif k*req<=n:\r\n print(0)\r\nelse:\r\n print(k*req - n)\r\n",
"k, n, w = list(map(int, input().split()))\r\nprice = ((w + 1) * w // 2) * k\r\nprint(max(price - n, 0))",
"k,n,w = map(int,input().split())\r\nsum = 0\r\nfor i in range(0,w+1):\r\n sum += i*k\r\nif n>sum:\r\n print(0)\r\nelse:\r\n print(sum-n)",
"startPrice, money, bananas = map(int, input().split())\r\nbananaPrice = startPrice\r\nfor i in range(2, bananas + 1):\r\n bananaPrice += i * startPrice\r\n\r\ncost = bananaPrice - money\r\nprint(cost if cost >= 0 else 0)",
"raw=input()\r\nrawed=raw.split()\r\nk=int(rawed[0])\r\nn=int(rawed[-1])\r\nw=int(rawed[1])\r\ni=1\r\np=0\r\nwhile i<=n:\r\n p+=i*k\r\n i+=1\r\nif p<=w:\r\n print(0)\r\nelse:\r\n print(p-w)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Sep 8 15:54:37 2023\r\n\r\n@author: Zinc\r\n\"\"\"\r\ns=0\r\nk,n,w=[int(x) for x in input().split()]\r\nfor i in range(1,w+1): \r\n y=i*k\r\n s+=y\r\nif s<=n: \r\n print(0)\r\nelse: \r\n print(s-n)",
"# Read input values\r\nk, n, w = map(int, input().split())\r\n\r\n# Calculate the total cost using the formula\r\ntotal_cost = w * (k + k * w) // 2 # Using integer division to get an integer result\r\n\r\n# Calculate the amount of money to borrow, if needed\r\nborrow_amount = max(0, total_cost - n)\r\n\r\n# Output the result\r\nprint(borrow_amount)\r\n",
"\r\n\r\ncost,dollars,bananas=map(int,input().split())\r\n\r\ntotal=0\r\n\r\nfor i in range(bananas):\r\n total=total+(i+1)*cost\r\n\r\nif total>dollars:\r\n print(total-dollars)\r\nelse:\r\n print(0)",
"inp = input().split()\nk, n, w = int(inp[0]), int(inp[1]), int(inp[2])\nsum = 0\nfor i in range(1,w+1):\n sum += i*k\n\nif n - sum >= 0:\n print(0)\nelse:\n print (abs(n-sum))\n",
"num = input().split()\r\nnum1 = [int(a) for a in num]\r\nk = num1[0]\r\nn = num1[1]\r\nw = num1[2]\r\n\r\nmoney = k * (1 + w) * w // 2\r\n\r\nif money > n:\r\n\tprint(money - n)\r\nelse:\r\n\tprint(\"0\")\r\n",
"k, n, w = [int(x) for x in input().split()]\n\ncost = 0\nfor x in range (1, w+1):\n cost += (x * k)\n\nif (cost-n) < 0:\n print(0)\nelse:\n print(cost-n)\n",
"ievade = input()\r\nk,n,w = ievade.split(\" \")\r\nk = int(k)\r\nn = int(n)\r\nw = int(w)\r\ncena = 0\r\nfor i in range(1, w+1):\r\n banans = i * k\r\n cena = cena + banans\r\nif cena <= n:\r\n print(0)\r\nelse:\r\n print(cena - n)",
"k, n, w = map(int,input().split())\r\na = int((w * (w + 1) / 2) * k)\r\nif a - n > 0:\r\n print(a - n)\r\nelse:\r\n print(0)",
"ievads=str(input(\"\"))\r\nmaksa_1=int(ievads.split(\" \")[0])\r\ncik=int(ievads.split(\" \")[2])\r\nnauda=int(ievads.split(\" \")[1])\r\nkopejais=0\r\n\r\nk=1\r\nwhile k<=cik:\r\n kopejais=kopejais+(k*maksa_1)\r\n k=k+1\r\nif kopejais<=nauda:\r\n print(\"0\")\r\nelse:\r\n print(kopejais-nauda)",
"# O(1)\r\n\r\nk, n, w = map(int, input().split())\r\nprecio = (w * (w + 1) // 2) * k\r\nprestado = max(0, precio - n)\r\n\r\nprint(prestado)",
"k, n, w = map(int,input().split())\r\nsummary = 0\r\nfor i in range(w+1):\r\n summary += i*k\r\nif n < summary:\r\n debt = abs(n-summary)\r\n print(debt)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\n\r\ndollars = 0\r\nfor i in range(1,w + 1):\r\n dollars += i * k\r\nx = dollars - n\r\nif x < 0:\r\n print(0)\r\nelse:\r\n print(x)",
"ip,m,nb=map(int,input().split())\r\nsum=0\r\nfor i in range(1,nb+1):\r\n sum=sum+ip*i\r\n# print(sum)\r\nif m-sum>=0:\r\n print(0)\r\nelse:\r\n print(sum-m)",
"k, n, w = map(int, input().split())\r\nneed = 0\r\n\r\nfor i in range(1, w + 1):\r\n need += i * k\r\n\r\nif need <= n:\r\n print(0)\r\nelse:\r\n print(need - n)\r\n",
"k,n,w=map(int,input().split())\r\ntotal=k*((w*(w+1))//2)\r\nif total<=n or total==0:\r\n print(0)\r\nelse:\r\n print(total-n)\r\n",
"k, n, w = map(int, input().split())\r\n\r\n# Calculate the total cost of buying w bananas\r\ntotal_cost = k * w * (w + 1) // 2\r\n\r\n# Calculate how much money the soldier needs to borrow\r\nborrowed_money = max(0, total_cost - n)\r\n\r\nprint(borrowed_money)\r\n",
"'''\r\n#wrong subtraction\r\nN=list(map(int,input().split()))\r\na=N[0]\r\nb=N[1]\r\nfor i in range(b):\r\n if a%10==0:\r\n a=a//10\r\n else:\r\n a=a-1\r\nprint(a)\r\n \r\n'''\r\nN=list(map(int,input().split()))\r\na=N[0]\r\nb=N[1]\r\nc=N[2]\r\nif b>= int((a*c*(c+1))/2):\r\n print(0)\r\nelse:\r\n print(int((a*c*(c+1))/2)-b)\r\n",
"knw = input()\r\nk_n_w = knw.split()\r\nk = int(k_n_w[0])\r\nn = int(k_n_w[1])\r\nw = int(k_n_w[2])\r\ncost = 0\r\n\r\nfor i in range(1,w+1):\r\n cost += i*k\r\n\r\nborrow = cost - n\r\nif borrow > 0:\r\n print(borrow)\r\nelse:\r\n print(0)\r\n",
"k,n,w=map(int,input().split())\r\nsum=0\r\nj=1\r\nfor i in range(w):\r\n t=j*k\r\n sum+=t\r\n j+=1\r\nif sum<=n:\r\n print(0)\r\nelse:\r\n print(sum-n)",
"# Leer los valores de k, n y w\nk, n, w = map(int, input().split())\n\n# Calcular la suma total de los plátanos\ntotal_cost = (w * (w + 1) // 2) * k\n\n# Calcular la cantidad de dinero que el soldado debe pedir prestado\ndinero_prestado = max(0, total_cost - n)\n\n# Imprimir la cantidad de dinero prestado\nprint(dinero_prestado)\n\n\t\t \t\t \t \t \t\t\t \t \t\t\t\t\t\t\t \t",
"a, b, c = map(int, input().split())\r\nd = 0\r\nfor i in range(1, c + 1):\r\n d += i * a\r\nif d > b:\r\n print(d - b)\r\nelse:\r\n print(0)\r\n",
"k,n,w = map(int,input().split(\" \"))\r\ntotal_amount = 0\r\nfor i in range(1,w+1):\r\n total_amount += k * i\r\nif total_amount <= n:\r\n print(\"0\")\r\nelse:\r\n print(total_amount - n)",
"k, n, w = map(int, input().split())\r\n\r\ni=1\r\ntotal=0\r\n\r\nwhile i <= w : \r\n\ttotal =total + (k*i)\r\n\ti=i+1\r\nif total>=n :\r\n\tborrow=total-n\r\nelse :\r\n\tborrow = 0\r\nprint(borrow)",
"a, b, c = input('').split(' ')\r\nk, n, w = int(a), int(b), int(c)\r\nh = 0\r\nfor i in range(1,w+1):\r\n h += i*k\r\nif h-n<=0:\r\n print(0)\r\nelse:\r\n print(h-n)",
"k,n,w=map(int,input().split())\r\ntn=0\r\nfor i in range(1,w+1):\r\n tn=tn+i*k\r\nif tn>n:\r\n print(tn-n)\r\nelse:\r\n print(0)\r\n",
"a, b, c = map(int, input().split())\r\nsum = a\r\nfor i in range(2, c + 1):\r\n sum += a * i\r\nif b < sum:\r\n print(sum - b)\r\nelse:\r\n print(0)\r\n",
"tmp = input()\r\ntmp = tmp.split()\r\nk = int(tmp[0])\r\nn = int(tmp[1])\r\nw = int(tmp[2])\r\nsum = 0\r\nfor i in range(w):\r\n sum += (i+1) * k\r\nif sum > n:\r\n print(sum - n)\r\nelse:\r\n print(0)",
"k,n,t= map(int, input().split())\r\ntot_cost=k*t*(t+1)//2\r\nbor=max(0,tot_cost-n)\r\nprint(bor)\r\n",
"# Read the input values\r\nk, n, w = map(int, input().split())\r\n\r\n# Calculate the total cost of w bananas\r\ntotal_cost = (k * w * (w + 1)) // 2\r\n\r\n# Calculate the borrowed money (if any)\r\nborrowed_money = max(0, total_cost - n)\r\n\r\n# Print the borrowed money\r\nprint(borrowed_money)\r\n",
"k, n, w = map(int, input().split())\r\nsumma = k * w * (w + 1) // 2 \r\naiznemums = max(0, summa - n)\r\n \r\nprint(aiznemums)\r\n",
"k, n, w = [int(i) for i in input().split()]\r\nc = k\r\nfor i in range(2, w+1):\r\n c += k*i\r\nif c-n >= 0:\r\n print(c-n)\r\nelse:\r\n print(0)\r\n",
"k,n,w=map(int,input().split())\r\nm=k*w*(w+1)/2\r\nif m>n:\r\n print(int(m-n))\r\nelse:\r\n print(0)\r\n",
"a=input()\r\nb=list(map(int,a.split()))\r\nif b[0]*b[2]*(b[2]+1)/2>b[1]:\r\n print(int(b[0]*b[2]*(b[2]+1)/2-b[1]))\r\nelse:\r\n print(0)",
"count=0\r\nw=list(map(int,input().split()))\r\nprice=w[0]\r\ntotal_price=w[1]\r\nnum_b=w[2]\r\nfor i in range(1,num_b+1):\r\n\ta=price*i\r\n\tcount+=a\r\nif count<total_price:\r\n\tprint(0)\r\nelse:\r\n\tprint((count)-(total_price))\r\n",
"\r\nk, n, w = map(int, input().split())\r\n\r\nans = 0\r\nfor i in range(1,w + 1):\r\n ans += (i * k)\r\n\r\nif n >= ans:\r\n print(0)\r\nelse:\r\n print(ans - n)",
"k,n,w = map(int,input().split())\r\nneed = (k*w + k*w**2)//2 - n\r\nif need <= 0:\r\n print(0)\r\nelse:\r\n print(need)",
"a=input().split()\r\n\r\nk=int(a[0])\r\nn=int(a[1])\r\nw=int(a[2])\r\ntotal=0\r\n\r\nfor i in range(0,w+1):\r\n total=total+(i*k)\r\n\r\nif total>n:\r\n borrow=total-n\r\nelse:\r\n borrow=0\r\n\r\nprint(borrow)\r\n \r\n",
"c,b,n=[int(i) for i in input().split()]\r\ns=0\r\nfor i in range(n):\r\n s+=(i+1)*c\r\na=s-b\r\nif a>=0:\r\n print(a)\r\nelse:\r\n print(0)",
"k,n,w=list(map(int, input().split()))\r\ns=0\r\nfor i in range(1,w+1):\r\n s=s+i*k\r\n\r\nif n>=s:\r\n print(0)\r\nelse:\r\n print(s-n)",
"k, n, w = [int(x) for x in input().split(' ')]\r\nfor i in range(1, w+1):\r\n n -= k*i\r\nprint(n*(-1)) if n < 0 else print(0)\r\n",
"k, n, w = map(int, input().split())\r\nt=sum((i+1)*k for i in range(w))\r\ne=t-n if t>n else 0\r\nprint(e)\r\n",
"k, n , w = map(int, input().split())\r\ndollars = [i*k for i in range(1,w+1)]\r\nans = sum(dollars) - n\r\nif ans > 0:\r\n print(ans)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\ncost = 0\r\nfor i in range(1, w+1):\r\n cost = cost + k * i\r\nif cost > n:\r\n ans = cost - n\r\n print(ans)\r\nelse:\r\n print(0)",
"k,n,w = map(int,input().split())\r\ntotal = k * ((w + 1) * w//2)\r\nprint(total-n if total > n else 0)\r\n",
"st=input()\r\nL=st.split(\" \")\r\nneed=0\r\nk,n,w=map(int,L)\r\nfor i in range(1,w+1):\r\n need+=(k*i)\r\n\r\nif (need -n)>0:\r\n print(need-n)\r\nelse:\r\n print(0)",
"k, n , w = [int(x) for x in input().split()] \n\nsum = 0\n\nfor i in range(1,w+1):\n\n sum += i * k\n\nb = sum - n\n\nif b > 0:\n\n print(b)\n\nelse:\n \n print(0)\n",
"a,b,c = map(int, input().split())\r\n \r\nsum = 0\r\n\r\nfor i in range(1, c+1):\r\n sum+= (i*a)\r\n \r\nif(sum>b):\r\n print(sum-b)\r\nelse:\r\n print(0)\r\n ",
"a,b,c=map(int,input().split())\r\nc=(c*(c+1))//2\r\nif a*c<=b:\r\n\tprint(0)\r\nelse:\r\n\tprint(a*c-b)",
"k,n,w=map(int,input().split())\r\nx=k*(w*(w+1)//2)\r\nif(x>=n):\r\n print(x-n)\r\nelse:\r\n print(\"0\")",
"k,n,w=map(int,input().split())\r\ntotal_cost=(w*(w+1)*k)//2\r\nborrowed=max(0,total_cost-n)\r\nprint(borrowed)",
"k, n, w = map(int,input().split())\r\ncost = 0\r\nfor i in range(w+1):\r\n cost += k*i\r\nif cost <= n:\r\n print('0')\r\nelse:\r\n print(cost-n)",
"k, n, w = map(int, input().split())\r\n\r\ntc = w * (w + 1) // 2 * k\r\n\r\nbt = max(0, tc - n)\r\n\r\nprint(bt)\r\n",
"k, n, w = map(int, input().split(\" \"))\r\nj = 0\r\nfor i in range(w):\r\n\tj += k*(i+1)\r\nif(n >= j):\r\n\tprint(0)\r\nelse:\r\n\tprint(j-n)",
"d,money,n = input().split()\r\nd,money,n = int(d), int(money),int(n)\r\n \r\ntotal_money = n/2*(2*d + (n-1)*d)\r\nif total_money >= money:\r\n print(int(abs(total_money - money)))\r\nelse:\r\n print(0)",
"k,n,w=(int(i) for i in input().split())\r\nsum=0\r\nfor i in range (w):\r\n i+=1\r\n sum +=i*k\r\nif sum>n:\r\n print(sum-n)\r\nelse:\r\n print(0)\r\n\r\n",
"k,n,w=map(int,input().split())\r\nc=0\r\nfor i in range(w):\r\n c+=k*(i+1)\r\nif n>=c:\r\n print(0)\r\nelse:\r\n print(c-n)\r\n",
"data = [int(x) for x in input().split(' ')]\r\n\r\nk = data[0]\r\nn = data[1]\r\nw = data[2]\r\n\r\noutput = k * ((w * (w + 1)) // 2) - n\r\n\r\nif output <= 0:\r\n output = 0\r\n\r\nprint(output)\r\n",
"k,n,w = map(int, input().split())\r\nsumm = 0\r\n\r\nfor i in range(w+1):\r\n summ += k * i \r\n\r\nif summ > n:\r\n print(summ - n)\r\nelse:\r\n print(0)",
"def find(n,h,w):\r\n cost=0\r\n i=1\r\n while i<=w:\r\n cost+=n*i\r\n i+=1\r\n if(cost>h):\r\n\t return cost-h\r\n else:\r\n\t return 0\r\n\r\nn,h,w=map(int,input().split())\r\nval=find(n,h,w)\r\nprint(val)\r\n\r\n\t\r\n",
"k,n,w=input().split()\r\nk=int(k)\r\nn=int(n)\r\nw=int(w)\r\nf=0\r\nfor i in range(1,w+1):\r\n f+=k*i\r\nif f<=n:\r\n print(0)\r\nelse:\r\n print(f-n)",
"k,d,n=map(int,input().split())\r\nans=0\r\nj=1\r\nwhile n>0:\r\n ans=ans+(j*k)\r\n j+=1\r\n n-=1\r\nif(ans>=d):\r\n print(abs(ans-d))\r\nelse:\r\n print(\"0\")",
"k,n,w=map(int,input().split())\r\ndebt=int((1+w)*w/2*k-n)\r\nif debt>0:\r\n print(debt)\r\nelse:\r\n print(0)",
"s = [int(i) for i in input().split()]\nk = s[0]\nn = s[1]\nw = s[2]\ntotal = 0\nfor i in range(w + 1):\n total += k * i\nif total - n <= 0:\n print(0)\nelse:\n print(total - n)",
"k,n,w=map(int,input().split())\r\nprice=k*(w*(w+1))//2\r\nif n>=price:\r\n print(0)\r\nelse:\r\n print(price-n)",
"cost, dollars, target = map(int, input().split())\r\ntotal = 0\r\nfor _ in range(1, target + 1):\r\n total += cost * _\r\nprint(total - dollars if total - dollars > 0 else 0)",
"k, n, w = map(int, input().split())\r\nt = k * w * (w + 1) // 2\r\na = max(0, t - n)\r\nprint(a)\r\n",
"shopping = input()\r\n\r\nfirst_banan_price , budget , wanted_amount = map(int , shopping.split())\r\n\r\ni = 1\r\nz = 0\r\n\r\nwhile i <= wanted_amount :\r\n first_banan_price_temp = first_banan_price*i\r\n z += first_banan_price_temp\r\n i += 1\r\n\r\n\r\nif z <= budget : print(0)\r\nelse : print( z - budget )\r\n",
"price, have, amount = map(int, input().split())\r\ntotal = 0\r\nfor i in range(1, amount + 1):\r\n total += i * price\r\nif have >= total:\r\n print(0)\r\nelse:\r\n print(total - have)",
"k,n,w=input().split(\" \")\r\nk=int(k)\r\nn=int(n)\r\nw=int(w)\r\n\r\n\r\n# w=4, k+2K+3K+4K= k*(1+2+3+4)=k*sum(1->w)\r\n# k*Sum(1->w)\r\ncost=0\r\nfor i in range(1,w+1):\r\n cost=cost+i\r\n \r\ncost=cost*k \r\nif(cost>n):\r\n print(cost-n)\r\nelse:\r\n print(0)\r\n",
"k, n, w = map(int, input().split())\r\nif k * w * (w+1) // 2 - n > 0:\r\n print(k * w * (w+1) // 2 - n)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\ntotal_cost = 0\r\n\r\nfor i in range(w):\r\n total_cost += (i + 1) * k\r\n \r\namount = total_cost - n\r\n\r\nprint(amount if total_cost > n else 0)",
"def main():\r\n\r\n inp = input().split(\" \")\r\n BC = int(inp[0])\r\n D = int(inp[1])\r\n A = int(inp[2])\r\n\r\n\r\n TC = 0\r\n for j in range(1, A+1):\r\n TC = TC + BC * j\r\n\r\n borrow = 0\r\n\r\n if TC <= D:\r\n borrow == 0\r\n\r\n else:\r\n\r\n borrow = TC - D\r\n \r\n print(borrow)\r\n\r\nmain()",
"k, n, w=map(int,input().split())\r\nx=w*(k+w*k)/2\r\n\r\nif x<=n:\r\n print(\"0\")\r\nelse:\r\n y=x-n\r\n t=int(y)\r\n print(t)",
"def soldierAndBananas():\r\n k, n, w = map(int, input().split())\r\n requiredDollers = (w*k)*(w+1)*0.5\r\n if n < requiredDollers:\r\n print(int(requiredDollers-n))\r\n else:\r\n print(int(0))\r\n \r\nsoldierAndBananas()",
"a,s,r=map(int,input().split())\r\nans=0\r\nj=1\r\nwhile r>0:\r\n ans=ans+(j*a)\r\n j+=1\r\n r-=1\r\nif ans>=s:\r\n print(abs(ans-s))\r\nelse:\r\n print(\"0\")",
"k,n,w=map(int,input().split())\r\na = sum(i*k for i in range(1,w+1))\r\nif a>n:\r\n print(a-n)\r\nelse:\r\n print('0')",
"k,n,w=map(int,input().split())\r\ncost=k*w*(w+1)//2\r\namount_borrowed=max(0,cost-n)\r\nprint(amount_borrowed)",
"i,k,j = map(int, input().split(' '))\r\ncount =1 \r\ntotalprice = 0\r\nfor _ in range(j):\r\n totalprice += count * i \r\n count+=1\r\nborrow = max(0, totalprice - k) \r\nprint(borrow)",
"# Read input values\r\nk, n, w = map(int, input().split())\r\n\r\n# Calculate the total cost of w bananas using the formula\r\ntotal_cost = k * w * (w + 1) // 2 # Sum of the first w natural numbers\r\n\r\n# Calculate the amount to borrow, or 0 if not needed\r\nborrow_amount = max(0, total_cost - n)\r\n\r\n# Print the amount to borrow\r\nprint(borrow_amount)\r\n",
"x,y,z= map(int, input().split()) \r\nt= x*(z*(z+1) // 2)\r\nb=max(0,t- y)\r\nprint(b)\r\n",
"k,n,w=input().split()\r\nk=int(k)\r\nn=int(n)\r\nw=int(w)\r\nsum=0\r\nfor i in range(1,w+1):\r\n sum+=i*k\r\nif sum-n < 0:\r\n print(0)\r\nelse:\r\n print(sum-n)\r\n",
"a,b,c=map(int,input().split())\r\nsum=0\r\nfor i in range(1,c+1):\r\n sum+=a*i\r\nif sum>=b:\r\n print(sum-b)\r\nelse:\r\n print(0) ",
"k,n,w = map(int,input().split(' '))\r\nans=(1+w)*w//2*k-n\r\nif ans<0:\r\n print(0)\r\nelse:\r\n print(ans)",
"k, n, w = map(int, input().split())\r\ntotalCost = 0\r\nfor i in range(1,w+1):\r\n totalCost += k*i\r\nif n > totalCost:\r\n print(0)\r\nelse:\r\n print(totalCost - n)",
"k,n,w=input().split()\nk=int(k)\nn=int(n)\nw=int(w)\nsum=0\nfor i in range(1 , w+1):\n sum+=i*k\nif sum>n:\n print(sum-n)\nelse:\n print(0)\n \t\t\t\t \t \t\t\t\t \t \t \t\t\t\t\t \t\t\t",
"k, n, w = map(int, input().split())\r\ns = k * w * (w + 1) // 2\r\nif n < s:\r\n z = s - n\r\n print(z)\r\nelse:\r\n print(0)\r\n",
"k,n,w=list(map(int,input().split()))\r\nif n>=w*(w+1)*k/2:\r\n print(0)\r\nelse:\r\n print(int(w*(w+1)*k/2-n))\r\n",
"c,w,n=map(int,input().split())\r\nt=c*n*(n+1)//2\r\nif(t>w):\r\n print(t-w)\r\nelse:\r\n print(\"0\")",
"k, n, w = map(int, input().split())\r\n\r\np = 0\r\n\r\ni = 1\r\n\r\nwhile i <= w:\r\n\r\n p += k * i\r\n\r\n i += 1\r\n\r\ns = n - p\r\n\r\nif s > 0: print(0)\r\nelse: print(abs(s))",
"import sys\r\ndef I(): return int(sys.stdin.readline().rstrip())\r\ndef LI(): return list(map(int, sys.stdin.readline().rstrip().split()))\r\ndef MI(): return map(int, sys.stdin.readline().rstrip().split())\r\ndef SI(): return sys.stdin.readline().rstrip()\r\n\r\n\r\ndef main():\r\n k,n,w = MI()\r\n cost = 0\r\n for i in range(1,w+1):\r\n cost += i*k\r\n if cost > n: \r\n print(cost - n) \r\n else: \r\n print(0)\r\n \r\n\r\nif __name__ == \"__main__\":\r\n main()",
"k , n, w = input ().split ()\nk = int (k)\nn = int (n)\nw = int (w)\n\ntotal_cost = k * w * (w + 1) // 2\n\nborrowed = max (total_cost - n, 0)\n\nprint (borrowed)\n \t\t \t \t\t \t\t \t \t \t \t \t\t\t \t",
"k,n,w=list(map(int,input().split()))\r\na=((w*(w+1))//2)*k\r\nif(a<n):\r\n print(0)\r\nelse:\r\n num=a-n\r\n print(num)\r\n",
"k, n, w=map(int,input().split())\r\nsum=0\r\nfor i in range(1,w+1):\r\n sum = sum + (k*i)\r\nif sum>=n:\r\n borrow=sum-n\r\n print(borrow)\r\nelse:\r\n print(0)",
"d, h_d, w = map(int, input().split())\r\nans = 0\r\ncnt = 0\r\nwhile cnt < w:\r\n cnt += 1\r\n ans = ans + d * cnt\r\nif ans - h_d > 0:\r\n print(ans - h_d)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\nborrow = int(((1 + w) * w * k / 2) - n)\r\nif borrow <= 0:\r\n print(\"0\")\r\nelse:\r\n print(borrow)",
"k,n,w=map(int,input().split())\r\nl=0\r\nfor i in range(1,w+1):\r\n l+=i*k\r\nif(n>l):\r\n print(0)\r\nelse:\r\n print(l-n)\r\n",
"# for _ in range(int(input())):\r\nk,n,w=map(int,input().split())\r\n\r\n\r\npri=0\r\nfor i in range(1,w+1):\r\n pri+=i*k\r\nif n>=pri:print(0)\r\nelse:print(pri-n)",
"a,b,c=map(int,input().split())\r\nn=(a+a*c)/2*c\r\nif b>=n:\r\n print(0)\r\nelse:\r\n \r\n print(int(n-b))",
"k, n,w = list(map(int, input().split()))\r\nt = 0\r\nfor i in range(1, w+1):\r\n t = t+i*k\r\n\r\nif n>=t:\r\n print(0)\r\nelse:\r\n print(t-n)\r\n",
"k,n,w=map(int,input().split())\r\nif (k*(w*(w+1)//2))-n > 0:\r\n print((k*(w*(w+1)//2))-n)\r\nelse:\r\n print(0)",
"from sys import stdin\n\n# stdin = open(\"input.txt\")\ndef get_solution():\n # stdin = open(\"input.txt\")\n k, n, w = map(int, stdin.readline().rstrip().split())\n \n return max(0, (1 + w) * w * k // 2 - n)\n \n \nt = 1#int(stdin.readline().rstrip())\nfor _ in range(t):\n print(get_solution())\n",
"x, y, z = map(int, input().split())\r\nm=0\r\nfor i in range(1, z+1): \r\n i*=x\r\n m+=i\r\nif y >= m:\r\n print(0)\r\nelse:\r\n \r\n print(m-y)",
"x, y, z = map(int, input().split())\r\nmoney = ((1 + z) * z / 2) * x\r\nif y < money:\r\n print(int(money - y))\r\nelse:\r\n print('0')",
"'''\r\nProblem Statement:\r\na soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, \r\n2k dollars for the second one and so on (in other words, he has to pay i*k dollars for the i-th banana).\r\nHe has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?\r\nInput Format :\r\nThe first line contains Three positive integers k, n, w (1<=k, w<=1000,0<=n<=10**9),\r\nthe cost of the first banana, inital number of dollars the soldier has and number of bananas he wants.\r\n\r\nOutput Format:\r\nOutput one integer -- the amount of dollars that the soldier must borrow from his friend. \r\nif he doesn't have to borrow money, output 0.\r\n\r\ngiven variables:\r\nw = no-of bananas 3\r\nk = cost of bananas 17 \r\nn = initial balance 4\r\n'''\r\n\r\ndef banana_shop(w, k, n):\r\n total_cost = 0\r\n for i in range(1, w + 1):\r\n total_cost += i * k\r\n \r\n borrowed_money = max(0, total_cost - n)\r\n return borrowed_money\r\ndef main():\r\n k, n, w = map(int, input().split())\r\n result = banana_shop(w, k, n)\r\n print(result)\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"a=input().split()\r\nprice=int(a[0])\r\nmoney=int(a[1])\r\nbanana=int(a[2])\r\n\r\nans=(1+banana)*banana//2*price-money\r\n\r\nif ans>=0:\r\n print(ans)\r\n\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\np = 0\na = 0\nfor i in range(1, w + 1):\n p += k * i\n a = p - n\nif a > 0:\n print(a)\nelse:\n print(0)\n",
"str1=input(\"\")\r\nl=str1.split()\r\ncost=int(l[0])\r\ndol=int(l[1])\r\nban=int(l[2])\r\ntot=0\r\nbrw=0\r\nwhile(ban):\r\n tot+=ban*cost\r\n ban-=1\r\nif tot>dol:\r\n brw=tot-dol\r\nprint(brw)",
"nums=map(int, input().split())\r\nnum=list(nums)\r\nstore=0\r\nfor i in range(1, num[2]+1):\r\n store+=(i*num[0])\r\nif store-num[1]<=0:\r\n print(0)\r\nelse:\r\n print(store-num[1])",
"k,n,w = input().split()\n\nc = 0\nfor i in range(int(w)):\n c += int(k)*(i+1)\n\nif int(n)>c:\n print(0)\nelse:\n print(c-int(n))\n",
"a = str.split(input(), \" \")\r\nk = int(a[0])\r\nn = int(a[1])\r\nw = int(a[2])\r\nm = 0\r\nfor x in range(1, w+1):\r\n m += k*x\r\n\r\nif m <= n:\r\n print(0)\r\nelse:\r\n print(m - n)",
"k,n,w = map(float,input().split())\r\nans = w*(w+1)/2*k - n\r\nans = int(ans)\r\nif ans > 0:\r\n print(ans)\r\nelse:\r\n print(0)\r\n",
"k, n, w = input().split()\r\nk, n, w = int(k), int(n), int(w)\r\nc = 0\r\nfor i in range(int(w)):\r\n c += k*(i+1)\r\n\r\nrez = c-n\r\nif rez < 0:\r\n print(0)\r\nelse:\r\n print(rez)",
"k,n,w=map(int,input().split())\r\nprice=0\r\nborrow=0\r\nfor i in range(1,w+1):\r\n price+=i*k\r\nif price<=n:\r\n print(borrow)\r\nelse:\r\n borrow=price-n\r\n print(borrow)\r\n",
"import sys\r\ns=[int (i) for i in sys.stdin.readline().split()]\r\nk=s[0]\r\nn=s[1]\r\nw=s[2]\r\ntotal=0\r\ni=1 \r\nwhile i <= w:\r\n total+=i*k\r\n i+=1\r\nif n>=total: \r\n print(\"0\")\r\nelse:\r\n print(total-n)\r\n ",
"k,n,w=map(int,input().split())\r\na=int(w/2*(1+w))*k-n\r\nprint(0 if a<0 else a)",
"import sys\n\ninput = sys.stdin.readline\n\nk, n, w = map(int, input().split())\n\namount_required = k * w * (w + 1) // 2\n\nif amount_required <= n:\n sys.stdout.write(f\"0\")\n\nelse:\n borrow = amount_required - n\n sys.stdout.write(f\"{borrow}\")\n",
"k, n, w = map(int, input().split())\r\nc = 0\r\nfor i in range(w):\r\n l = (i+1)*k\r\n c = c+l\r\nif(c>n):\r\n print(c-n)\r\nelse:\r\n print(0)\r\n ",
"inputs = input().split(\" \")\r\ninitialBananaCost = int(inputs[0])\r\npocketMoney = int(inputs[1])\r\nnumberOfDesiredBananas = int(inputs[2])\r\n\r\ntotalCost = 0\r\nfor i in range(numberOfDesiredBananas):\r\n totalCost += (i+1) * initialBananaCost\r\n \r\nif pocketMoney - totalCost > 0:\r\n print(\"0\")\r\nelse:\r\n print(totalCost - pocketMoney)",
"k, n, w = map(int,input().split())\r\nmoney = (w**2+w)/2*k\r\nif n >= money:\r\n print(0)\r\nelse:\r\n print(int(money-n))",
"x, y, z = input().split(\" \")\r\nx = int(x); y = int(y); z = int(z)\r\ntotal = 0.5 * z * (2 * 1 + (z - 1) * 1) * x\r\nif (total - y < 0):\r\n print(0)\r\nelse:\r\n print(int(total - y))",
"def amount_to_borrow(k, n, w):\r\n a = k\r\n d = k\r\n total_cost = (w * (2 * a + (w - 1) * d)) // 2\r\n return max(0, total_cost - n)\r\n\r\n\r\nk, n, w = map(int, input().split())\r\n\r\nresult = amount_to_borrow(k, n, w)\r\nprint(result)\r\n",
"k_n_w = input().split()\r\nk_n_w = list(map(int, k_n_w))\r\nmoney = sum(k_n_w[0]*i for i in range(1, k_n_w[2]+1))\r\nif money >= k_n_w[1]:\r\n print(money - k_n_w[1])\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\nboza=(k*w*(w+1))//2\r\nif boza-n >=0:\r\n print(boza-n)\r\nelse:\r\n print(0)\r\n",
"k, a, w = map(int, input().split())\r\nct = k * (w * (w + 1) // 2)\r\nb = max(0, ct - a)\r\nprint(b)\r\n",
"k, n, w = map(int, input().split()) # Input: k, n, w\r\n\r\n# Calculate the total cost for buying w bananas\r\ntotal_cost = k * w * (w + 1) // 2\r\n\r\n# Calculate the amount the soldier needs to borrow\r\nborrowed_money = max(0, total_cost - n)\r\n\r\nprint(borrowed_money) # Output: The amount of dollars the soldier must borrow\r\n",
"k,n,w=input().split()\r\nk,n,w=int(k), int(n), int(w)\r\ncost=0\r\nfor i in range(1,w+1):\r\n cost+=(i*k)\r\nif cost>n:\r\n print(cost-n)\r\nelse:\r\n print(0)\r\n",
"k,n,w=map(int,input().split())\r\np=0\r\nfor i in range(w):\r\n p += k*(i+1)\r\n\r\nif p>n:\r\n print(p-n)\r\nelse:\r\n print(0)\r\n \r\n",
"a, b, c = map(int, input().split())\r\nsum = 0\r\nfor i in range(1, c + 1):\r\n sum = sum + (i * a)\r\nif b < sum:\r\n print(sum - b)\r\nelse:\r\n print(0)\r\n",
"k, n, w = map(int, input().split())\nr = ((1 + w) * w // 2) * k\nif r <= n:\n print(0)\nelse:\n print(r - n)\n \t\t \t\t\t\t \t\t\t\t\t\t\t \t\t \t\t\t \t \t",
"k,n,w = map(int,input().split())\r\ntotalsum = k * (w) * (w+1) /2 \r\nif totalsum > n:\r\n\tprint(int(totalsum - n))\r\nelse:\r\n\tprint(0)",
"k,n,w = map(int,input().split())\r\n\r\ni = 0\r\n\r\nsum = ((1 + w) * w / 2) * k\r\n\r\n \r\nif sum <= n:\r\n print('0')\r\nelse:\r\n print(int(sum - n))",
"k, n, w = map(int, input().split())\r\n\r\ns = 0\r\nfor i in range(w + 1):\r\n s += i * k\r\n\r\nif s > n:\r\n print(s - n)\r\nelse:\r\n print(0)",
"k,n,w = map(int, input().split())\ntotal = 0\n\nfor i in range (w):\n r = k * (i + 1)\n total = total + r\n\ntotal_r = max(0, total - n)\n\nprint (total_r)\n \t \t \t\t \t \t\t\t\t\t \t \t\t \t",
"k, n, w = map(int, input().split())\r\n\r\ns = 0\r\n\r\nfor i in range(1, w + 1):\r\n s += k * i\r\n\r\nm = max(0, s - n) # Calculate the amount the soldier has to borrow\r\n\r\nif m == 0:\r\n print(\"0\") # The soldier doesn't have to borrow money\r\nelse:\r\n print(m) # Output the amount the soldier has to borrow\r\n",
"k,n,w=map(int,input().split())\r\nnew=[]\r\nfor i in range(1,w+1):\r\n new.append(i*k)\r\ns=sum(new)\r\nif s<n:\r\n print(0)\r\nelse:\r\n print(s-n)",
"if __name__ == \"__main__\":\r\n k,dollars,bananas=[int(x) for x in input().split(\" \")]\r\n\r\n answer = int((k*bananas*(bananas+1))/2 - dollars)\r\n\r\n if(answer <= 0):\r\n print(0)\r\n else:\r\n print(answer)",
"a, b, c = (input().split(\" \"))\r\nk = int(a)\r\nn = int(b)\r\nw = int(c)\r\np = int(0)\r\nwhile w > 0:\r\n m = int(w*k)\r\n w = w-1\r\n p = int(p + m)\r\nr = int(p - n)\r\nif r <= 0:\r\n print(\"0\")\r\nelse:\r\n print(r)\r\n",
"k,n,w=map(int,input().split())\r\ncosts=0\r\nfor i in range(1,w+1):\r\n costs=costs+i*k\r\nborrowed=costs-n\r\nif borrowed<0:\r\n borrowed=0\r\nprint(borrowed)",
"k, n, w = [int(i) for i in input().split()]\r\n\r\nfor i in range(1, w + 1):\r\n\tn = n - i*k\r\n\r\nif n < 0:\r\n\tprint(abs(n))\r\nelse:\r\n\tprint(0)\r\n",
"k, n, w = map(int, input().split())\n\np = k*(sum([i for i in range(1, w+1)]))\nif p > n:\n\tprint(p-n)\nelse:\n\tprint(0)\n",
"import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef in2i():\r\n '''\r\n input to int\r\n '''\r\n return int(input())\r\n\r\ndef in2il():\r\n '''\r\n intput to int list\r\n '''\r\n return (list(map(int, input().split())))\r\n\r\ndef s2cs():\r\n '''\r\n string to chars\r\n '''\r\n s = input()\r\n return (list(s[:len(s)]))\r\n\r\nk, n, w = in2il()\r\ns = 0\r\nfor i in range(1, w + 1):\r\n s += i * k\r\nif n > s:\r\n print(0)\r\nelse:\r\n print(s - n)",
"import sys\r\n\r\ninput = [int(x) for x in sys.stdin.readline().split(\" \")]\r\nk = int(input[0])\r\nn = int(input[1])\r\nw = int(input[2])\r\n\r\nif w % 2 == 0:\r\n total = (1 + w)*(w/2)*k\r\nelse:\r\n total = ((1 + w)*((w - 1)/2) + (w + 1)/2)*k\r\n\r\nborrow = n - total\r\nif borrow > 0:\r\n borrow = 0\r\n\r\nsys.stdout.write(str(int(abs(borrow))))",
"k,n,w=map(int,input().split())\r\nans=0\r\nfor i in range(1,w+1):\r\n ans+=k*i\r\nif ans-n<=0:\r\n print(0)\r\nelse:\r\n print(ans-n)",
"L= input().split(\" \")\r\nmon_argent = int(L[1])\r\nprix_initiale = int(L[0])\r\nnombre_de_bannane = int(L[2])\r\nmontantT = int(prix_initiale * nombre_de_bannane*(nombre_de_bannane + 1)/2)\r\nif mon_argent >= montantT :\r\n print(0)\r\nelse :\r\n print(montantT-mon_argent)",
"\r\na,b,c=map(int,(input().split()))\r\nk,i=0,1\r\nwhile(c>0):\r\n i=c*a\r\n k=k+i\r\n c-=1\r\nif(k>b):\r\n print(k-b)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\ntotal_cost=k*w*(w+1)//2\r\nborrow_amount=max(0,total_cost-n)\r\nprint(borrow_amount)",
"k,n,w = map(int, input().split())\r\n\r\ntotal = (w*(w+1)//2)*k\r\n\r\nto_borrow = total - n\r\n\r\nprint(max(0, to_borrow)) # Incase he doesn't have to borrow anything",
"virkne = input()\r\nk,n,w = map(int, virkne.split())\r\ncena = k*w*(w+1)//2\r\nnodoklis = max(0,cena - n)\r\nprint(nodoklis)",
"x = input()\r\nc = x.split()\r\nk = int(c[0])\r\nn = int(c[1])\r\nw = int(c[2])\r\n\r\nfor i in range(w):\r\n n -= (i+1)*k\r\nif n >= 0:\r\n print(0)\r\nelse:\r\n print(abs(n))\r\n",
"k, n, w = map(int,input().split())\r\nprint(max(0, ((w*(w+3-2)//2)*k)-n))",
"nums = input()\r\n\r\nnums_list = nums.split()\r\n\r\nsum = 0\r\nfor i in range(1,int(nums_list[2])+1):\r\n sum += i*int(nums_list[0])\r\n\r\nif sum>int(nums_list[1]):\r\n print(sum-int(nums_list[1]))\r\nelse:\r\n print(0)",
"inp=input()\r\nk,have,w=[int(i) for i in inp.split()]\r\nneed=k*((w*(w+1))/2)\r\nborrow=need-have\r\nif borrow<=0:\r\n borrow=0\r\nprint(int(borrow))",
"x,y,z=map(int,input().split())\r\na=0\r\nfor i in range(1,z+1):\r\n a+=x*i\r\nif a-y>0:\r\n print(a-y)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\nprice = 0\r\nfor i in range(1, w + 1):\r\n price += i * k\r\nif price>n:\r\n print(price - n)\r\nelse:\r\n print('0')\r\n",
"k, n, w = map(int, input().split())\r\nsum = 0\r\nfor i in range(w):\r\n sum += (i+1)*k\r\nprint(sum-n) if sum-n > 0 else print(0)\r\n",
"k,n,w = map(int,input().split())\r\ntotal=0\r\nfor x in range(1,w+1):\r\n total = total+k*x\r\nif total >= n:\r\n print(total-n)\r\nelse:\r\n print(0)",
"n = [int(x)for x in input().split(\" \")]\r\nL =[]\r\nfor i in range(0,n[2]):\r\n L.append(n[0]*(i+1))\r\nif sum(L) > n[1]:\r\n print(sum(L)-n[1])\r\nelse:\r\n print(0)",
"chir,abc,bcac = map(int,input().split())\r\nxml = chir*(bcac*(bcac+1))/2\r\nif (xml-abc)>0:\r\n\tprint (int(xml-abc))\r\nelse:\r\n\tprint (0)",
"k,n,w=list(map(int,input().strip().split()))\nans=k*(w*(w+1)//2) - n\nif ans<0:\n ans=0\nprint(ans)\n\n\n",
"a,b,c=map(int,input().split())\r\nk=0\r\nfor i in range(c+1):\r\n k=k+i*a\r\nif k-b<0:\r\n print(0)\r\nelse:\r\n print(k-b)\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 19 15:55:50 2023\r\n\r\n@author: lenovo\r\n\"\"\"\r\n\r\nk,n,w=map(int,input().split())\r\nprint(int(max(0,w*(w+1)/2*k-n)))",
"def main():\n k,n,w = map(int,input().split(' '))\n total_cost = k*(w*(w+1)//2)\n if(n-total_cost>0):\n print(0)\n else:\n print(abs(n-total_cost))\n\nif __name__ == '__main__':\n main()\n \n",
"a, b, c = map(int, input().split())\r\nx = c*(c+1)//2\r\ncost = x * a\r\nif cost > b:\r\n print(cost - b)\r\nelse:\r\n print(0)\r\n",
"k, n, w =map(int, input().split())\r\n\r\nprice_all_bananas = 0\r\nfor i in range(1, w+1):\r\n price_all_bananas = i * k + price_all_bananas\r\nif n >= price_all_bananas:\r\n print(0)\r\nelse:\r\n print(price_all_bananas-n)",
"k,n,w = map(int, input().split())\r\ncost = 0\r\nfor i in range (1, w+1):\r\n cost += i * k\r\n\r\nborrow = cost - n\r\nif borrow < 0:\r\n borrow = 0\r\n\r\nprint(borrow)\r\n",
"a,b,c=map(int, input().split())\r\nn,m = 0,0\r\nfor i in range(1,c+1):\r\n n = n+(a*i)\r\nif n>b:\r\n m = n-b\r\nprint(m)",
"a,b,c=input().split()\na=int(a)\nb=int(b)\nc=int(c)\nsum=0\n\nfor i in range(c):\n sum+=a*(i+1)\n\n\nif(sum>b):\n print(sum-b)\nelse:\n print(0)\n\n \t \t \t \t\t \t\t \t \t \t\t \t \t",
"k,n,w=list(map(int,input().split()))\r\ncost=0\r\nfor i in range(1,w+1):\r\n cost+=i*k\r\nif cost>n:\r\n print(cost-n)\r\nelse:\r\n print(\"0\")",
"k,n,w = map(int, input().split())\r\nc = 0\r\nfor i in range(w+1):\r\n c += k * i\r\nif (c-n) > 0:\r\n print(c-n)\r\nelse:\r\n print(0)",
"if __name__=='__main__':\r\n\tinputs = input().split(' ')\r\n\tk, n, w = int(inputs[0]), int(inputs[1]), int(inputs[2])\r\n\tout = k*w*(w+1)/2 - n\r\n\tif out > 0:\r\n\t\tprint(int(out))\r\n\telse:\r\n\t\tprint('0')",
"sum = 0\r\n\r\nk,n,w = map(int,input().split())\r\n\r\nfor x in range(w+1):\r\n sum += x*k \r\n\r\nborrowed = sum - n\r\n\r\nif borrowed <= 0:\r\n print(0)\r\nelse:\r\n print(borrowed)",
"k,n,w = map(int, input().split())\r\ncost = 0\r\nfor i in range(1,w+1):\r\n cost += i*k\r\nif cost > n:\r\n print(cost-n)\r\nelse:\r\n print(0)\r\n ",
"cost_of_banana, dollars_got, numbers_banana_wanted = map(int,input().split())\r\ncost = 0\r\nfor banana in range(1,numbers_banana_wanted + 1):\r\n cost += cost_of_banana * banana\r\nborrowed = cost - dollars_got\r\nif borrowed < 0:\r\n borrowed = 0\r\nprint(borrowed) \r\n",
"k,n,w = map(int,input().split())\r\n\r\namount = (w/2)*(2*k + (w -1)*k)\r\nif amount > n:\r\n print(int(amount - n))\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\nsum=0\r\nfor x in range(1,w+1):\r\n sum+=x*k\r\nif sum>=n:\r\n print(sum-n)\r\nelse:\r\n print(0)",
"x,y,z=map(int,input().split())\r\nprint(max(0,x*z*(z+1)//2-y))",
"a,b,c=map(int,input().split())\r\nprint(max(int(a*c*(c+1)/2-b),0))",
"x , y ,z = map(int,input().split())\r\nsum = 0\r\nfor i in range(1,z+1):\r\n sum += i * x\r\nif sum >= y:\r\n print(sum - y)\r\nelse:\r\n print(0)",
"a,b,d=map(int,input().split())\r\nc=0\r\nfor i in range(1,d+1):\r\n c=c+a*i\r\nif(b>c):\r\n print(0)\r\nelse:\r\n print(c-b)",
"def main():\r\n k, n, w = map(int, input().split())\r\n\r\n borrowed_money = 0\r\n\r\n for i in range(1, w+1):\r\n banana_cost = k * i\r\n\r\n if n - banana_cost >= 0:\r\n n -= banana_cost\r\n else:\r\n borrowed_money += banana_cost - n\r\n n += banana_cost - n\r\n n -= banana_cost\r\n \r\n print(borrowed_money)\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"k, n, w = map(int, input().split())\r\n\r\ntotal = 0\r\n\r\nfor i in range(w):\r\n total += k*(i+1)\r\n\r\nif (n-total)>0:\r\n print(\"0\")\r\nelse:\r\n print(abs(n-total))",
"x,y,z=map(int,str(input()).split())\r\nc=0\r\nfor i in range(1,z+1):\r\n c=c+x*i\r\nif(y<c):\r\n print(abs(y-c))\r\nelse:\r\n print(0)\r\n\r\n\r\n",
"k,n,w=map(int,input().split())\r\nc=0\r\nfor i in range(1,w+1):\r\n c+=k*i\r\nif c>n:\r\n print(abs(c-n))\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\n\r\ntotal = 0\r\nfor i in range(w + 1):\r\n total = total + (i * k)\r\n\r\nif total - n <= 0:\r\n print(0)\r\nelse:\r\n print(total - n)",
"cenaBananna, iloscPieniedzy, liczbaBananow = map(int, input().split())\r\n\r\nkwota = 0\r\nfor i in range(liczbaBananow):\r\n kwota = kwota + (i+1)*cenaBananna\r\n\r\n\r\npozyczka = kwota-iloscPieniedzy\r\n\r\nif pozyczka < 0:\r\n print(0)\r\nelse:\r\n print(pozyczka)",
"k,n,w = map(int,input().split())\r\ntotHarga = 0\r\ncount = 0\r\nwhile (count < w):\r\n count += 1\r\n hargaSatuan = k * count\r\n totHarga += hargaSatuan\r\nif(totHarga > n):\r\n hasil = totHarga - n\r\n print(hasil)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\nw=((w*(w+1))//2)*k\r\nif w-n>0:\r\n print(w-n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\nsum=0\ntc=0\nfor i in range(w+1):\n sum=sum+i\ntc=sum*k\nif(n<tc):\n print(tc-n) \nelse:\n print(0)",
"# Leer los valores de k, n y w\nk, n, w = map(int, input().split())\n\n# Calcular la cantidad total necesaria para comprar w bananas\ntotal_cost = k * w * (w + 1) // 2\n\n# Calcular la cantidad que el soldado debe pedir prestado\nborrowed_money = max(0, total_cost - n)\n\n# Imprimir la cantidad de dinero prestado que el soldado necesita\nprint(borrowed_money)\n\n \t\t \t \t\t \t\t \t \t \t\t \t\t\t \t\t \t",
"k,n,w=map(int, input().split())\r\nprice=0\r\nfor i in range(1,w+1):\r\n price+=i*k\r\nif n>=price:\r\n print(0)\r\nelse:\r\n print(price-n)",
"price, money, col = map(int, input().split())\r\ntotal = 0\r\nfor i in range(1, col + 1):\r\n total += price * i\r\nif money - total >= 0:\r\n print(0)\r\nelse:\r\n print(total - money)",
"k,n,w = map(int, input().split(' '))\r\nsum1=0\r\ni=1\r\nresult=0\r\n\r\nwhile i<=w:\r\n a= k * i\r\n sum1 += a\r\n i += 1\r\n\r\nif sum1>n:\r\n result=sum1-n\r\n\r\nelif sum1<=n:\r\n result =0\r\n \r\nprint(result)\r\n\r\n",
"k, n, w = map(int, input().split(\" \"))\r\nw_cost = 0\r\nfor i in range(1,1+w):\r\n w_cost += k*i\r\nif n>= w_cost:\r\n print(0)\r\nelse:\r\n debt = w_cost - n\r\n print(debt)\r\n",
"k,n,w = map(int,input().split(\" \"))\r\ns = 0;\r\nfor i in range(0,w+1):\r\n s+=i\r\nif (s*k-n)>=0:\r\n print(s*k-n) \r\nelse:\r\n print(0)\r\n",
"k, n, w = map(int, input().split(\" \")) \r\ndollars = 0\r\nfor i in range(1,w+1):\r\n dollars += i * k\r\n\r\nrequired_dollars = dollars - n\r\nif required_dollars < 0:\r\n print(0)\r\nelse:\r\n print(required_dollars)",
"price,hehave,wanted=map(int,input().split())\r\ntotal_cost=0\r\n\r\nfor i in range(1,wanted+1):\r\n total_cost=total_cost+i*price\r\n \r\nif(total_cost<= hehave):\r\n print(0)\r\nelse:\r\n print(abs(total_cost-hehave))",
"k, n, w = map(int, input().split())\r\n\r\n# Calculate the sum of the first w positive integers\r\ntotal_sum = w * (w + 1) // 2\r\n\r\n# Calculate the total cost\r\ntotal_cost = k * total_sum\r\n\r\n# Calculate the amount to borrow\r\nborrow = max(0, total_cost - n)\r\n\r\nprint(borrow)\r\n",
"if __name__ == '__main__':\n k, n, w = map(int, input().split())\n res, to_pay = 0, k\n for b in range(w):\n if to_pay >= n: \n res += to_pay - n\n n = 0\n else: n -= to_pay\n to_pay += k\n\n print(res)\n",
"p=0\r\na=list(map(int,input().split()))\r\nk=a[0]\r\nn=a[1]\r\nw=a[2]\r\nfor i in range(1,w+1):\r\n p+=i*k\r\nif p>n:\r\n print(p-n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\ncnt=0\r\nfor i in range(1,w+1):\r\n cnt+=k*i\r\nif n>cnt:\r\n print(0)\r\nelse:\r\n print(cnt-n)",
"l = list(map(int, input().split()))\nsum=0\nfor i in range(1,l[2]+1):\n sum += i\nans = sum*l[0]-l[1]\nif ans>0:\n print(ans)\nelse:\n print(0)",
"x,y,z=(input().split())\r\nk=int(x)\r\nn=int(y)\r\nw=int(z)\r\n\r\nm=0\r\nfor i in range (1,w+1):\r\n m=m+i*k\r\nif m>n:\r\n print(m-n)\r\nelse:\r\n print(\"0\")\r\n",
"k,n,w = map(int,input().split())\r\nsum=0\r\nfor i in range (0,w):\r\n sum = sum + k*(i+1)\r\n\r\nb = n-sum\r\nif(b<0):\r\n print(sum-n)\r\nelse:\r\n print(\"0\")",
"k,n,w=map(int,input().split())\r\ntotal=k*w*(w+1)//2\r\nborrow=max(0,total-n)\r\nprint(borrow)",
"a = list(map(int, input().split()))\r\ns = 0\r\nk, n, w = a[0], a[1], a[2]\r\nfor i in range(1, w+1):\r\n s += k*i\r\nif s <= n:\r\n print(0)\r\nelse:\r\n print(s - n)\r\n",
"k,n,w=input().split()\r\nk=(int)(k);n=(int)(n);w=(int)(w)\r\nborrow=(k*(w*(w+1)//2))-n\r\nif(borrow<0):\r\n borrow=0\r\nprint(borrow)",
"k,n,w = map(int,input().split())\r\ntotal = 0\r\nfor x in range(w):\r\n total += (x+1)*k\r\nborrowed = total - n\r\nprint(borrowed) if borrowed>0 else print(0)",
"def draw_st(k, n, w):\r\n total = 0\r\n for i in range(1, w + 1):\r\n total += k * i\r\n\r\n s = max(0, total - n)\r\n return s\r\n\r\n\r\n\r\n\r\nk, n, w = map(int, input().split())\r\nprint(draw_st(k, n, w))",
"k,n,w =[int(x) for x in input().split()]\r\nprint(k*(1+w)*w//2-n if k*(1+w)*w/2>n else 0)",
"k,n,w = map(int,input().split())\r\nres = (k*w*(w+1))//2\r\nif res<n:\r\n print(0)\r\nelse:\r\n print(res-n)",
"(k,n,w)=map(int,input().split())\r\nprint(max(0,(w*(w+1)*k) // 2 - n))",
"k,n,w=map(int,input().split())\r\nc=0\r\nfor i in range(w):\r\n c = c + k*(i + 1)\r\nc = c - n\r\nif c < 0:\r\n print(0)\r\nelse:\r\n print(c)",
"k, n, w=map(int, input().split())\r\ns=0\r\nfor i in range(1, w+1):\r\n s+=i*k\r\nif s-n>0:\r\n print(abs(s-n))\r\nelse:\r\n print(0)",
"ss = input()\r\ns = ss.split()\r\nk = int(s[0])\r\nn = int(s[1])\r\nw = int(s[2])\r\nm = 0\r\nfor i in range(w):\r\n m = m+(i+1)*k\r\nif m <= n:\r\n print(0)\r\nelse:\r\n print(m-n)",
"variables=input().split()\r\nk=int(variables[0])\r\nn=int(variables[1])\r\nw=int(variables[2])\r\ncost=(k+w*k)*w/2\r\nprint(0 if(n>=cost)else int(cost-n))",
"k , n , w = map(int , input().split())\nz = w*(w+1)*k//2\nif z > n :\n print(z-n)\nelse :\n print(\"0\")\n \t \t \t\t\t \t \t\t\t\t\t \t\t \t\t\t \t",
"k,n,w=map(int,input().split())\r\np=0\r\nfor i in range(1,w+1):\r\n p+=i*k\r\nif n>p:\r\n print(\"0\")\r\nelse:\r\n print(abs(n-p))",
"x, y, z = map(int, input().split())\r\ntotal_cost = x * z * (z + 1) // 2\r\nborrowed_money = max(0, total_cost - y)\r\nprint(borrowed_money)\r\n",
"s = input()\r\nnum = s.split()\r\nk = int(num[0])\r\nn = int(num[1])\r\nw = int(num[2])\r\n\r\nsumd = (1 + w) * k * w // 2\r\n\r\nif sumd < n:\r\n\tprint(0)\r\n\r\nelse:\r\n\tprint(sumd - n)",
"k,n,w = map(int,input().split());a=[k*i for i in range(1,w+1)];print(abs(n-sum(a) if n-sum(a)<0 else 0 ))",
"k,n,w=map(int,input().strip().split())\r\ncost=k*((w*(w+1))//2)\r\nif cost>=n:\r\n print(cost-n)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split()) # Cost of the first banana, initial amount, and number of bananas\r\n\r\n# Calculate the total cost of 'w' bananas\r\ntotal_cost = k * w * (w + 1) // 2\r\n\r\n# Calculate how much money the soldier needs to borrow\r\nborrowed = max(0, total_cost - n)\r\n\r\nprint(borrowed)\r\n",
"k, n, w = map(int,input().split())\n\nres = 0\ni = 0\n\nres = (k * w * (w + 1)) // 2\n\nif n >= res:\n print(0)\nelse:\n print(res - n)\n# Sat Oct 21 2023 19:18:27 GMT+0300 (Moscow Standard Time)\n",
"k, n, w = [int(x) for x in input().split()]\r\n\r\nsum_money = int((w * (w + 1) / 2) * k)\r\nborrow = sum_money - n\r\nprint(max(borrow, 0))\r\n",
"k,n,w=map(int, input().split(' '))\r\nt=int((((1+w)*w)/2)*k-n)\r\nif t>0:\r\n\tprint(t)\r\nelse:\r\n\tprint(0)",
"k,n,w=map(int,input().split())\r\nS = (w/2)*(2*k + (w-1)*k)\r\nif n>=S:\r\n print(0)\r\nelse:\r\n print(round(S-n))\r\n",
"k, n, w = map(int, input().split())\r\ncost = w * (w + 1) * k // 2\r\nprint(0 if n >= cost else cost - n)",
"k,n,w=[int(x) for x in input().split()]\r\nm=k*w*(w+1)/2\r\nif m<=n:\r\n print(0)\r\nelse:\r\n print(int(m-n))#上面有/2不加int的化会出现浮点数形式,如果你想要的话,可以在上面用//2解决",
"k,n,w=map(int,input().split())\nm=k*((w*(w+1))//2)\nif m <=n:\n print(0)\nelse:\n print(m-n)",
"k, n, w = map(int, input().split())\r\nS = k * w * (w + 1) // 2\r\nif n < S:\r\n z = S - n\r\n print(z)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\nsum = 0\r\n\r\nfor i in range(1, w + 1):\r\n sum += i * k\r\n\r\nif sum <= n:\r\n print(0)\r\nelse:\r\n print(sum - n)",
"k,n,w=map(int,input().split())\r\ntotal_cost=k*(w*(w+1))//2\r\nborrow_amount=max(0,total_cost-n)\r\nprint(borrow_amount)\r\n",
"k,n,w = map(int,input().split())\nans = 0\nfor x in range(1,w+1):\n ans += x * k\nif n >= ans:\n print(0)\nelse:\n print(ans-n)",
"L = [int(x) for x in input().split()]\r\nk = L[0]\r\nn = L[1]\r\nw = L[2]\r\nx = (w*(w+1))//2\r\nz = n-(x*k)\r\nif z >= 0:\r\n print(0)\r\nelse:\r\n print(abs(z))",
"k, n, w = map(int, input().split())\r\nres = ((w * (w+1)) / 2) * k - n\r\nprint(int(res) if res > 0 else 0)\n# Mon Oct 16 2023 18:41:25 GMT+0300 (Moscow Standard Time)\n",
"k,w,n = map(int,input().split())\r\na =k*n*(n+1)//2-w\r\nif a > 0:\r\n print(a)\r\nelse:\r\n print(0)",
"k,n,m =map(int,input().split())\r\ntotal_cost=k*(m*(m+1)//2)\r\nborrow_am=max(0,total_cost-n)\r\nprint(borrow_am)",
"k,n,w=input().split()\r\na=int(w)*(int(w)+1)/2\r\nif int(int(a)*int(k)-int(n))>0:\r\n print(int(a)*int(k)-int(n))\r\nelse:\r\n print('0')",
"k,n,w=map(int,input().split())\r\ns=0\r\nfor i in range(1,w+1):\r\n s+=i*k\r\nif n>=s:\r\n print(0)\r\nelse:\r\n print(s-n)",
"b1,b2,b3 = map(int,input().split())\r\nb = (b3*(b3+1)//2)*b1\r\nbb = b-b2\r\nif bb > 0:\r\n print(bb)\r\n \r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\ns = 0\r\nfor i in range(1, w+1):\r\n s = s + k*i\r\nif s > n:\r\n s = s - n\r\nelse:\r\n s = 0\r\nprint(s)",
"cost, dollars, target = map(int, input().split())\r\ntotal = cost * sum(range(1, target + 1))\r\nprint(max(total - dollars, 0))",
"k, n, w = map(int, input().split())\r\n\r\ncost = 0\r\n\r\nfor i in range(w+1):\r\n cost += (k*i)\r\n\r\nif cost-n < 0:\r\n print(0)\r\nelse:\r\n print(cost-n)\r\n",
"first, dollars, wantcount = list(map(int, input().split()))\r\n\r\nsum = 0\r\n\r\nfor i in range(1, wantcount+1):\r\n sum += first * i\r\n\r\nfinal = sum - dollars\r\n\r\nif final <= 0:\r\n print(0)\r\n exit()\r\nelse:\r\n print(sum - dollars)",
"k,n,w = map(int,input().split())\nt = 0\nfor i in range(1,w+1):\n t += i*k \nprint(t-n) if t>n else print(0)\n# Thu Nov 09 2023 21:07:43 GMT+0300 (Moscow Standard Time)\n",
"k, n, w = list(map(int, input().split(\" \")))\r\nprint(max(0, int((k * ((w * (w + 1)) / 2)) - n)))",
"case = [int(num) for num in input().split()]\r\n\r\ncost = case[2] * case[0] * (case[2] + 1) / 2\r\n\r\nif cost > case[1]:\r\n print(int(cost - case[1]))\r\nelse:\r\n print(0)",
"def calculate_borrow_amount(k, n, w):\r\n total_cost = (w * (w + 1) // 2) * k # Calculate the total cost using the sum of an arithmetic series formula\r\n borrow_amount = max(0, total_cost - n) # Calculate the amount to borrow, ensuring it's non-negative\r\n return borrow_amount\r\n\r\n# Read input values\r\nk, n, w = map(int, input().split())\r\n\r\n# Calculate and print the result\r\nresult = calculate_borrow_amount(k, n, w)\r\nprint(result)\r\n",
"# A. Soldier and Bananas\r\n\r\ninputUser = input().split()\r\nk, n, w = int(inputUser[0]), int(inputUser[1]), int(inputUser[-1]) \r\nresult = 0\r\n# the cost of the first banana,\r\n# initial number of dollars the soldier has and number of bananas he wants.\r\n\r\nfor i in range(1, w+1):\r\n if ((i * k) <= n):\r\n n -= (i * k)\r\n elif ((i * k) > n):\r\n result += (i * k) - n\r\n n = 0\r\n\r\nprint(result)",
"a,b,d=map(int,input().split())\r\nf=0\r\nq=a\r\nfor i in range(d):\r\n f+=q\r\n q+=a\r\nif b>f:\r\n print(0)\r\nelse:\r\n print(f-b)\r\n",
"k,n,w=map(int,input().split())\r\nx=(k*w*(w+1))//2\r\nif x<=n:\r\n print(0)\r\nelse:\r\n print(x-n)",
"a,b,c=map(int,input().split())\r\nresult=0\r\nfor i in range(1,c+1):\r\n result+=i*a\r\nif result>b:\r\n print(result-b)\r\nelse:\r\n print(\"0\")",
"k,n,w=map(int,input().split())\r\nsm=((w*(w+1))/2)*k\r\nif sm>n:\r\n print(int(sm-n))\r\nelse:\r\n print(0)",
"x=input().split(\" \")\r\nsum=0\r\nfor i in range(int(x[-1])):\r\n sum+=int(x[0])*(i+1)\r\nif sum-int(x[1])>0:print(sum-int(x[1]))\r\nelse:print(0)",
"kl,num,w=map(int,input().split())\r\ncst=0\r\nfor i in range(1,w+1):\r\n cst=cst+i*kl\r\nborrowed=cst-num\r\nif borrowed<0:\r\n borrowed=0\r\nprint(borrowed)",
"from sys import stdin, stdout\r\nimport math\r\n\r\nMOD = 1000000007\r\nINF = float('inf')\r\n\r\ndef read_int():\r\n return int(stdin.readline().rstrip())\r\n\r\ndef read_map():\r\n return map(int, stdin.readline().rstrip().split())\r\n\r\ndef read_lst():\r\n return list(map(int, stdin.readline().rstrip().split()))\r\n\r\ndef read_str():\r\n return stdin.readline().rstrip()\r\n\r\ndef write(*args, **kwargs):\r\n sep = kwargs.get('sep', ' ')\r\n end = kwargs.get('end', '\\n')\r\n stdout.write(sep.join(map(str, args)) + end)\r\n\r\ndef ok(val):\r\n write(\"YES\" if val else \"NO\")\r\n\r\n# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n\r\ndef solve():\r\n k, n, w = read_map()\r\n\r\n c = 0\r\n for i in range(w):\r\n c += (i + 1) * k\r\n\r\n print(c - n if c > n else 0)\r\n\r\n# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\r\n\r\ndef main():\r\n for _ in range(1):\r\n solve()\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"k,n,w=map(int,input().split())\r\ntot_cs=((w*(w+1))//2)*k\r\nrm=tot_cs-n\r\nif rm<=0:\r\n print(0)\r\nelse:\r\n print(rm)\r\n",
"k,n,w=list(map(int,input().split()))\r\n\r\nm = 0\r\nfor i in range(1,w+1):\r\n m += i*k\r\nif m > n:\r\n print(m-n)\r\nelse: print(0)",
"k,n,w=[int(v)for v in input().split()]\r\ntong=0\r\nfor i in range(1,w+1):\r\n tong+=i\r\nif tong*k>n:\r\n print((tong*k)-n)\r\nelse:\r\n print(0)",
"#546A: soldiers and bananas\r\na=input().split()\r\nk=int(a[0])\r\nn=int(a[1])\r\nw=int(a[2])\r\ntotal=int(k*w*(w+1)/2)\r\nif n>=total:\r\n print(0)\r\nelse:\r\n print(total-n)",
"k,n,w=map(int,input().split())\r\na=w*(2*k+(w-1)*k)//2\r\nd=a-n\r\nif d<0:\r\n print(0)\r\nelse:\r\n print(d)",
"# Input\nk, n, w = map(int, input().split())\n\n# Calculate the total cost of w bananas\ntotal_cost = (w * (w + 1) // 2) * k\n\n# Calculate the amount to borrow (if needed)\nborrow_amount = max(0, total_cost - n)\n\n# Output the result\nprint(borrow_amount)\n\n \t\t \t \t\t \t\t \t \t\t\t \t\t\t",
"banaaaaa = list(map(int, input().split()))\r\ncost =0\r\nfor i in range(1,banaaaaa[2]+1):\r\n cost += banaaaaa[0]*i\r\n\r\nif cost < banaaaaa[1]:\r\n print(0)\r\nelse:\r\n print(cost-banaaaaa[1])",
"k,n,w=map(int,input().split())\r\nsum=k\r\nfor i in range(2,w+1):\r\n x = i*k\r\n sum= sum + x\r\nif(n>=sum):\r\n print(0)\r\nelse:\r\n print( abs(n-sum))\r\n",
"k, n, w = input().split()\r\nk, n, w = int(k), int(n), int(w)\r\ns = 0\r\nfor i in range(0, w):\r\n s = s+(i+1)*k\r\nif s <= n:\r\n print(0)\r\nelse:\r\n print(s-n)",
"k,n,w = map(int,input().split())\r\nc = k *((1+w)*w/2)\r\ny = n - c\r\nif y >= 0 :\r\n print(0)\r\nelse:\r\n print(\"{:.0f}\".format(abs(y)))\r\n",
"k,n,w = map(int,input().split())\r\nsum1 = 0\r\nfor i in range(1,w+1):\r\n sum1 = sum1 + i*k\r\nd= sum1-n\r\nif d<=0:\r\n print(0)\r\nelse:\r\n print(d)\r\n",
"k, n, w = map(int, input().split())\r\n\r\ntotal_cost = 0\r\ni = 1\r\n\r\nwhile i <= w:\r\n total_cost += i * k\r\n i += 1\r\n\r\nborrow_amount = max(0, total_cost - n)\r\n\r\nprint(borrow_amount)",
"k, n, w = map(int, input().split())\r\ncost = 0\r\n\r\nfor i in range(1, w + 1):\r\n cost += i * k\r\n\r\nborrow = max(0, cost - n)\r\nprint(borrow)\r\n",
"s = input().split(\" \")\r\nk = int(s[0])\r\nn = int(s[1])\r\nw = int(s[2])\r\nsum = (2 * k + k *(w - 1)) * w / 2\r\n\r\nif n >= sum:\r\n print(0)\r\nelse:\r\n print(int(sum - n))",
"k, n, w = input().split()\r\nk = int(k)\r\nn = int(n)\r\nw = int(w)\r\ncost = 0\r\nfor i in range(1,w+1):\r\n cost = cost + i * k\r\nif cost > n:\r\n print(cost - n)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\n\r\ndollars_needed = 0\r\n\r\nfor banana in range(1, w+1):\r\n dollars_needed += banana * k\r\n\r\nif dollars_needed > n:\r\n print(dollars_needed - n)\r\nelse:\r\n print(\"0\")",
"k,n,w=map(int,input().split())\r\ncost=k*w*(w+1)//2\r\nborrow=max(0,cost-n)\r\nprint(borrow)",
"k, n, w = map(int, input().split()) # Input the cost of the first banana, initial money, and the number of bananas\r\n\r\n# Calculate the total cost of buying w bananas\r\ntotal_cost = k * w * (w + 1) // 2\r\n\r\n# Calculate the amount the soldier needs to borrow (if any)\r\nborrowed_money = max(0, total_cost - n)\r\n\r\nprint(borrowed_money) # Output the amount of dollars to borrow\r\n",
"k, n, w = map(int, input().split())\n\ntotal_cost = 0\n\nfor i in range(1, w + 1):\n total_cost += i * k\nborrow_amount = max(0, total_cost - n)\n\nprint(borrow_amount)\n\t \t\t \t\t\t \t\t \t\t\t \t\t\t\t\t\t \t\t\t\t",
"def solve():\r\n k, n, w = map(int, input().split())\r\n print(max(w*(w+1)//2*k-n, 0))\r\n\r\n\r\n# t = int(input())\r\nt = 1\r\nwhile t:\r\n solve()\r\n t -= 1\r\n",
"def dollars(k,n,w):\r\n wsum = (w*(w+1)//2)*k\r\n return wsum - n if wsum-n >=0 else 0\r\n \r\nk,n,w = map(int,input().split())\r\nprint(dollars(k,n,w))",
"l=list(map(int,input().split()))\r\nif ((l[0]*(1+l[2])*l[2]//2)-l[1])>0:\r\n m=((l[0]*(1+l[2])*l[2]//2)-l[1])\r\nelse:\r\n m=0\r\nprint(m)",
"k,n,w = map(int, input().split())\r\ns = w * (w + 1) // 2 * k\r\nprint(max(0, s - n))",
"s = input().split(' ')\r\ndollars = int(s[0])\r\nsolider_dollars = int(s[1])\r\nbananas = int(s[2])\r\nbananas_price = 0\r\nfor i in range(bananas + 1):\r\n bananas_price += i * dollars\r\nif solider_dollars >= bananas_price:\r\n print(0)\r\nelse:\r\n print(bananas_price - solider_dollars)\r\n",
"a = list(map(int, input().split()))\r\nk = a[0]\r\nn = a[1]\r\nw = a[-1]\r\nsumm = 0\r\nfor i in range(1, w+1):\r\n summ += i*k\r\nif n < summ:\r\n print(summ - n)\r\nelse:\r\n print(0)",
"k,n,w = map(int, input().split())\r\ncost = (k*(w)*(w+1))/2\r\nif cost >n:\r\n print(int(cost - n))\r\nelse:\r\n print(0)",
"#https://codeforces.com/problemset/problem/546/A\r\nk,n,w=map(int,input().split())\r\ndif=(int(n-((w/2)*((2*k)+(w-1)*k))))\r\nif dif>=0:\r\n print(0)\r\nelse:\r\n print(abs(dif))",
"arr = input()\r\narr = arr.split()\r\nk = int(arr[0])\r\nn = int(arr[1])\r\nw = int(arr[2])\r\nfull_price = 0\r\nfor i in range(1,w+1):\r\n full_price += i*k\r\nif(full_price-n>=0):\r\n print(full_price - n)\r\nelse:\r\n print(0)",
"k_n_w = list(input().split())\r\nk = int(k_n_w[0])\r\nn = int(k_n_w[1])\r\nw = int(k_n_w[2])\r\ncounter = 1\r\ncost = 0\r\n\r\nwhile counter <= w:\r\n cost += counter * k\r\n counter += 1\r\n\r\nif n > cost:\r\n print(0)\r\nelse:\r\n print(cost - n)",
"from sys import stdin\ndef input(): return stdin.readline()\n\ns=list(map(int, input().split()))\ni=1\nsum=0\nwhile i<=s[2]:\n sum=sum+(i*s[0])\n i=i+1\nif(sum>s[1]):\n print(sum-s[1])\nelse:\n print(\"0\")",
"k, n, w = map(int, input().split())\r\n\r\nprint(max(0, k*w*-~w//2 - n))",
"k,n,w=map(int,input().split())\r\ncost=0\r\nfor i in range(1,w+1):\r\n cost+=(i*k)\r\nif(cost>n):\r\n print(cost-n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\ns=int((k+k*w)/2*w)-n\r\nif s<=0: print(0)\r\nelse: print(s)",
"k,n,w = [int(x) for x in input().split()]\r\ntotal_cost = (w*(w+1)/2)*k\r\n\r\nif total_cost>n:\r\n c = total_cost-n\r\nelse:\r\n c = 0\r\n\r\nprint(int(c))\r\n",
"k, w, n = map(int, input().split())\r\nc = 0\r\nfor i in range(n):\r\n c += (i+1) * k\r\n\r\nprint(abs(w-c) if w-c < 0 else 0)\r\n",
"k,n,w = map(int, input().split())\r\nborrow = 0\r\n\r\nfor i in range(1,w+1):\r\n n -= k*i\r\nif n<0:\r\n borrow += abs(n) \r\n\r\nprint(borrow)",
"k,n,w = list(map(int, input().split()))\r\nsum = 0\r\nfor i in range(w+1):\r\n sum += i*k\r\nif n > sum :\r\n print(0)\r\nelse:\r\n print(abs(sum-n))\r\n",
"valorPlatano, dineroSoldado, cantidadPlatanos = map(int, input().split())\ntotal,totalTemp,i=0,0,1\nwhile i<= cantidadPlatanos:\n totalTemp=valorPlatano*i\n total=total+totalTemp\n i += 1\nif dineroSoldado < total:\n print(total-dineroSoldado)\nelse:\n print(\"0\")\n\n\t\t\t\t \t\t\t\t\t \t\t \t \t\t\t\t\t\t \t\t \t\t",
"a=list(map(int,input().split()))\r\nif a[2]*a[0]*(a[2]+1)/2 > a[1]:\r\n print( int(a[2]*a[0]*(a[2]+1)/2 - a[1]))\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\nd=((w*(w+1))//2)*k\r\nif(d-n>=0):\r\n print(d-n)\r\nelse:\r\n print(0)",
"value = list(map(int, input().split(' ')))\r\nprice = value[0]\r\nsummary = value[1]\r\ntotal = value[2]\r\n\r\ni_total = 0\r\nfor i in range(total):\r\n i_total += (i+1)\r\nif i_total * price > summary:\r\n print(i_total * price - summary)\r\nelse:\r\n print(0)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Oct 9 22:05:35 2023\r\n\r\n@author: 刘婉婷 2300012258\r\n\"\"\"\r\n\r\nk,n,w=map(int,input().split())\r\nt=0\r\nfor i in range(w):\r\n t=k*(i+1)+t\r\nif t<=n:\r\n a=0\r\nelse:\r\n a=t-n\r\nprint(a)",
"k, n, w = map(int, input().split())\ncost = (w * (w + 1)) // 2 * k\nmoney_needed = cost - n\nif money_needed < 0:\n money_needed = 0\nprint(money_needed)\n#\n\t \t\t\t\t\t\t \t \t \t\t\t \t\t \t \t",
"k,n,w=map(int,input().split())\r\ns=(sum([k*i for i in range(1,w+1)])-n)\r\nif s>=0:\r\n print(s)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\nm=(((k*w*(w+1)//2))-n)\r\nif (m>0):\r\n print(m)\r\nelse:\r\n print(0)",
"k,n,w = map(int,input().split())\r\nprint(int(max((1+w)*w/2*k-n,0)))\r\n",
"def prob(k,n,w):\r\n sum=0\r\n for i in range(1,w+1):\r\n sum+=k*i\r\n if (sum-n)<0:\r\n return 0\r\n return sum-n\r\nk,n,w=map(int,input().split())\r\nprint(prob(k,n,w))\r\n\r\n",
"k, n, w = map(int, input().split())\n\n# Calculate the total cost of buying w bananas\ntotal_cost = k * w * (w + 1) // 2\n\n# Calculate the amount the soldier needs to borrow\nborrow_amount = max(0, total_cost - n)\n\nprint(borrow_amount)\n",
"k,n,w=map(int,input().split())\r\nans=0\r\nfor i in range(1,w+1):\r\n ans += i*k\r\nif ans>=n:\r\n print(ans-n)\r\nelse:\r\n print(0)",
"def banana(k,n,w):\r\n count = 0\r\n first = k\r\n while(count < w):\r\n n = n - k\r\n k += first\r\n count += 1\r\n \r\n if n >= 0:\r\n return 0\r\n else: \r\n return -n\r\n \r\nk,n,w = str(input()).split()\r\n\r\nprint(banana(int(k),int(n),int(w)))",
"x, y, z=map(int, input().split())\ncurrentprice=0\nfor i in range(1,z+1):\n currentprice+=i*x\nif y>=currentprice:\n print(0)\nelse:\n print(currentprice-y)\n\n",
"# Input the cost of the first banana, initial dollars, and the number of bananas\r\nk, n, w = map(int, input().split())\r\n\r\n# Calculate the total cost of w bananas\r\ntotal_cost = k * (w * (w + 1) // 2)\r\n\r\n# Calculate the amount the soldier needs to borrow\r\nborrow_amount = max(0, total_cost - n)\r\n\r\n# Output the amount to borrow\r\nprint(borrow_amount)\r\n",
"k,n,w=map(int,input(\"\").split())\r\nprice=0\r\nfor x in range(1,w+1):\r\n price=price+k*x\r\nif price>n:\r\n print(price-n)\r\nelse:\r\n print((0))",
"inputs = input().split(' ')\r\n\r\nk = int(inputs[0])\r\nn = int(inputs[1])\r\nw = int(inputs[2])\r\n\r\ntotal_cost = 0\r\n\r\nfor i in range(0, w + 1):\r\n total_cost += i * k\r\n\r\nif total_cost < n:\r\n print(0)\r\nelse:\r\n print(total_cost - n)\r\n",
"a,b,c = map(int,input().split())\r\ng = 0\r\nr = 0\r\nwhile g != c:\r\n g += 1\r\n r += g * a\r\nif r > b:\r\n h = r - b\r\n print(h)\r\nelse:\r\n print(0)",
"k,n,w = map(int,input().split())\r\nsum = 0\r\nfor i in range(1,w+1):\r\n sum+=i*k\r\nif sum>=n:\r\n print(sum-n)\r\nelse:\r\n print(0)",
"cost,dollars,num_bananas=map(int ,input().split())\r\npay=0\r\nfor n in range(1,num_bananas+1):\r\n pay+=n*cost\r\n\r\nres=pay-dollars\r\nif res >=0:\r\n print(res)\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split(\" \"))\ni_sum = (w + 1) * w / 2\ntotal_cost = int(k * i_sum)\nborrow = max(total_cost - n, 0)\nprint(borrow)\n",
"knw=list(map(int, input().split()))\r\ns=0\r\nfor i in range(1,knw[2]+1):\r\n s+=knw[0]*i\r\nif s>knw[1]:\r\n print(s-knw[1])\r\nelse: print(0)",
"a,b,c = map(int,input().split())\r\ns = 0\r\nfor i in range(1,c+1):\r\n s = s+(i*a)\r\nt = s - b\r\nif t > 0:\r\n print(t)\r\nelse:\r\n print(0)",
"# k = harga banana; n = how much money he has\n# w = jml. bananas\nk,n,w = (int(x) for x in input().split())\ntotalPrice = 0\nm = 1\n\nfor rep in range(0,w):\n totalPrice += m*k\n m += 1\n\nif n < totalPrice:\n print(totalPrice - n)\nelse:\n print(\"0\")\n \t\t\t\t \t\t \t\t\t \t \t\t\t\t\t \t \t",
"initial, money, number=map(int,input().split())\r\nprice=0\r\nfor x in range(number):\r\n additional=initial*(x+1)\r\n price=price+additional\r\nif price>money:\r\n print(price-money)\r\nelse:\r\n print('0')",
"k, n, w = map(int, input().split())\nif k*((w*(w+1))/2)-n > 0:\n print(int(k*((w*(w+1))/2)-n))\nelse:\n print(0)\n",
"k,n,w=map(int,input().split())\r\nc=0\r\nfor i in range(1,w+1):\r\n c+=k*i\r\nif n>c:\r\n print(0)\r\nelse:\r\n print(c-n)",
"first_banana, initial_money, num_banana = [int(x) for x in input().split()]\r\nlast_banana = first_banana * num_banana\r\ncost = int(num_banana / 2 * (first_banana + last_banana))\r\nborrowed_amount = cost - initial_money\r\n\r\nif borrowed_amount <= 0:\r\n print(0)\r\nelse:\r\n print(borrowed_amount)",
"k,n,w =map(int,input().split())\r\nall_in=0\r\nfor i in range(1,w+1):\r\n all_in += k*i\r\nif all_in > n:\r\n print(all_in-n)\r\nelse:\r\n print(0)",
"arr = [int(x) for x in input().split()]\r\nk = arr[0] \r\nsuma = 0\r\nfor i in range (1,arr[2]+1):\r\n suma+=k*i\r\nif arr[1]>suma:\r\n print (0)\r\nelse:\r\n print (suma-arr[1])\r\n\r\n \r\n",
"k, n, w = map(int, input().split())\r\ncost = (k + w * k) * w // 2\r\nprint(max(cost - n, 0))",
"k, n, w = map(int, input().split())\r\n\r\ntotal_cost = 0 \r\n\r\nfor i in range(1, w+1):\r\n total_cost += i * k \r\n\r\nborrowed_money = total_cost - n\r\n\r\nif borrowed_money <= 0:\r\n print(0)\r\nelse:\r\n print(borrowed_money)\r\n",
"inp = [int(x) for x in input().split(\" \")]\r\nbananaCost = inp[0]\r\ndollars = inp[1]\r\nn = inp[2]\r\n\r\ncost = int(((n * (n + 1)) / 2) * bananaCost)\r\nborrow = 0 if (dollars >= cost) else abs(dollars - cost)\r\nprint(borrow)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Sep 10 12:10:12 2023\r\n\r\n@author: He'Bing'Ru\r\n\"\"\"\r\n\r\nls = input().split()\r\nk = int(ls[0])\r\nn = int(ls[1])\r\nw = int(ls[2])\r\ntot = 0\r\nbor = 0\r\nfor i in range(1,w+1) :\r\n tot += i*k\r\nif tot <= n :\r\n print(0)\r\nelse:\r\n print(tot - n)",
"k,n,w =map(int,input().split())\r\ns=k*(w+1)*w/2\r\na=s-n\r\nif a>0:\r\n print(int(a))\r\nelse :\r\n print(0) ",
"k,n,w = map(int,input().split())\r\nval = int(k*(w*(w+1)/2)-n)\r\nval = val if val>=0 else 0\r\nprint(val)",
"x,a,w=map(int,input().split());print(max(0,w*(w+1)*x//2-a))\r\n",
"k,n,w=map(int,input().split())\nsum = 0\nfor i in range(0,w):\n sum += (i+1)*k\nprint(max(0, sum -n)) \n\n\n",
"z=list(map(int, input().split()))\nk=z[0] \nn=z[1]\nw=z[2]\nfor i in range(2,w+1):\n k+=i*z[0]\nif k-n>0:\n print(k-n)\nelse:\n print(0)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Sep 6 16:12:31 2023\r\n\r\n@author: mac\r\n\"\"\"\r\n\r\nk, n, w = list(map(int,input().split(\" \")))\r\ncost = 0 #总共花费的钱\r\nfor i in range(1, w+1):\r\n cost += i * k\r\nprint(max(cost - n, 0))",
"data = input().split()\r\n\r\ninitial_cost, dollars, total_bananas = int(data[0]), int(data[1]), int(data[2])\r\n\r\nsum = (total_bananas*(total_bananas + 1))/2\r\nfinal_cost = sum*initial_cost\r\n\r\nif final_cost <= dollars:\r\n print(0)\r\n\r\nelse: print(int(final_cost - dollars))",
"k,n,w=map(int,input().split())\r\ncost=0\r\nfor i in range(1,w+1):\r\n cost=cost+(k*i)\r\nif cost>n:\r\n amt=cost-n\r\n print(amt)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\na=0\r\nfor i in range(1,w+1):\r\n a=a+i*k\r\nif a>n:\r\n print(a-n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\ns=0\r\nfor i in range(1,w+1):\r\n s=s+(i*k)\r\nif n>=s:\r\n print(0)\r\nelse:\r\n c=s-n\r\n print(c)\r\n ",
"a,b,c= map(int, input().split())\r\ncost= (c* (c + 1) // 2) * a\r\nans= max(0,cost-b)\r\nprint(ans)\r\n",
"k, n, w = [int(x) for x in (input().split())]\r\ntotal_cost = 0\r\ntotal_borrow = 0\r\nfor i in range(1, w + 1):\r\n total_cost += k * i\r\ntotal_borrow = total_cost - n\r\nif total_borrow > 0:\r\n print(abs(total_borrow))\r\nelse:\r\n print('0')",
"k,n,w=(input()).split(\" \")\r\nk=int(k)\r\nn=int(n)\r\nw=int(w)\r\ntotalAmount=[]\r\nbarrowAmout=0\r\nfor i in range(1,w+1):\r\n totalAmount.append(i*k)\r\nbarrowAmout=sum(totalAmount)-n\r\nif barrowAmout<=0:\r\n barrowAmout=0\r\nprint(barrowAmout)",
"k, n, w = map(int, input().split())\r\nt = int(k*((w*(w+1))/2) - n)\r\nprint(0 if t < 0 else t)",
"k,n,w = map(int, input().split())\r\nprint(max(0, k*w*(w+1)//2-n))",
"k,n,w = map(int, input().split())\r\nsumma = 0\r\nfor i in range(1,w+1):\r\n summa+=i*k\r\nif n>summa:\r\n print(0)\r\nelse:\r\n print(summa-n)",
"k, n, w = map(int, input().split())\r\nplata = 0\r\nfor koef in range(1, w + 1):\r\n plata += koef * k\r\nif plata > n:\r\n print(plata - n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\nm=0\r\n\r\nfor i in range(int(w)+1):\r\n a=i*k\r\n m=m+a\r\n\r\nif n>=m:\r\n print(\"0\")\r\nelse:\r\n print(int(m)-int(n))\r\n",
"x,n,y=map(int,input().split())\r\nprint(max(0,x*y*-~y//2-n))",
"k,n,w = map(int, input().split())\r\n\r\nt = 0\r\n\r\nfor i in range(w+1):\r\n t += k*i\r\n\r\nif t - n <= 0:\r\n print(0)\r\nelse:\r\n print(t-n)",
"mony = list(map(int,input().split())) # k , n , w \r\n\r\nk = mony[0]\r\nn = mony[1]\r\nw = mony[2]\r\nCost = 0\r\n\r\nfor i in range(w):\r\n Cost += k * (i+1)\r\n \r\nif Cost > n :\r\n Cost = Cost - n\r\n print(Cost)\r\nelse :\r\n print(0)\r\n",
"k,n,w = map(int, input().split())\r\n\r\ntotal_cost = 0\r\n\r\nfor i in range(1, w+1):\r\n money_for_ith = i*k\r\n total_cost += money_for_ith\r\n\r\nif total_cost > n:\r\n diff = total_cost - n\r\n print(diff)\r\nelse: \r\n print(\"0\")",
"k,n,w = input() .split()\nk = int(k)\nn = int(n)\nw = int(w)\nsum = 0\nfor i in range(1,w+1):\n sum += i*k\nif sum > n:\n print(sum - n)\nelse:\n print(0)\n \t \t\t\t\t \t \t \t\t\t\t \t \t \t\t \t\t\t",
"a,b,d=map(int,input().split())\r\nc=0\r\nfor i in range(1,d+1):\r\n x=a*i\r\n c=c+x\r\nif(b>=c):\r\n print(0)\r\nelse:\r\n \r\n print(c-b)",
"k,n,w = map(int,input().split())\r\nc = 0\r\nfor i in range(1,w+1):\r\n c+=(k*i)\r\nif c<n:\r\n print(0)\r\nelse:\r\n print(c-n)",
"k, n, m=map(int, input().split())\r\nsum=0\r\nfor i in range(1, m+1):\r\n sum+=i*k\r\nif n-sum>=0:\r\n print(0)\r\nelse:\r\n print(abs(n-sum))\r\n \r\n",
"k , n , w = map(int, input().split())\r\nbought = 1\r\nn -= k\r\n\r\nif w == 0:\r\n print(0)\r\n exit()\r\n\r\nwhile bought != w:\r\n bought += 1\r\n n -= bought*k\r\n \r\nif n > 0:\r\n print(0)\r\nelse:\r\n print(abs(n))\r\n\r\n ",
"cost = 0\r\nk, n, w = map(int, input().split())\r\nfor i in range(1 , w+1):\r\n cost += i*k\r\nprint(cost-n) if cost > n else print(0)",
"def solve():\r\n k,n,w = map(int,input().split())\r\n res = ((k+w*k)/2)*w\r\n dolg = int(res-n)\r\n if dolg<=0:\r\n print(0)\r\n return\r\n print(int(res-n))\r\n\r\nsolve()\r\n\r\n",
"k, n, w = map(int, input().split())\r\ntotal = sum((i+1)*k for i in range(w))\r\nto_borrow = total - n if total > n else 0\r\nprint(to_borrow)",
"k, n, w = map(int, input().split())\nanswer = k * w * (w + 1) // 2\nprint(max(0, answer - n))\n\n# Thu Oct 12 2023 16:27:15 GMT+0300 (Moscow Standard Time)\n",
"k,n,w=input(\"\").split()\r\ns=int(k)*(int(w)*(int(w)+1)/2)\r\nif s>int(n):\r\n print(int(s-int(n)))\r\nelse:\r\n print(0)",
"class solution:\r\n def __init__(self):\r\n self.list1 = []\r\n self.r = 0\r\n self.w = 0\r\n self.k = 0\r\n self.n = 0\r\n \r\n def compute(self):\r\n sum1 = (self.w*(self.w+1))/2\r\n amount = self.k*sum1\r\n self.r = amount - self.n\r\n \r\n def change(self):\r\n self.k = int(self.list1[0])\r\n self.n = int(self.list1[1])\r\n self.w = int(self.list1[2])\r\n \r\n def get_input(self):\r\n str1 = input()\r\n temp = str1.split()\r\n self.list1 = temp\r\n del temp\r\n \r\n def check(self):\r\n if self.r <= 0:\r\n self.r = 0\r\n \r\n def show(self):\r\n print(int(self.r))\r\n \r\n def execute(self):\r\n self.get_input()\r\n self.change()\r\n self.compute()\r\n self.check()\r\n self.show()\r\n \r\ndef main():\r\n s1 = solution()\r\n s1.execute()\r\n \r\nif __name__ == '__main__':\r\n main() ",
"n=[int(x) for x in input().split()]\r\nmoney=0\r\ni=1\r\n\r\nwhile(n[2]>0):\r\n money+=i*n[0]\r\n n[2]-=1\r\n i+=1\r\nif(money<=n[1]):\r\n print(0)\r\nelse:\r\n print(money-n[1])",
"k,n,w=map(int,input().split())\r\nprix_bananes=0\r\nfor i in range(1,w+1) : \r\n prix_bananes+= k*i \r\nif prix_bananes > n : \r\n print(prix_bananes-n)\r\nelse : \r\n print('0')",
"def Solution(k, n, w):\r\n res = ((w*(w+1))//2)*k - n\r\n return res if res > 0 else 0\r\n\r\nif __name__ == \"__main__\":\r\n k, n, w = map(int, input().split())\r\n print(Solution(k, n, w))\r\n",
"k,n,w=map(int,input().split())\r\nr=(w*(w+1)*k)/2\r\nif(r<=n):\r\n print(\"0\")\r\nelse:\r\n d=int(r-n)\r\n print(d)\r\n ",
"k,n,w=map(int,input().split())\r\ns=0\r\nfor i in range(1,w+1):\r\n s+=i\r\nif k*s<=n:\r\n print(0)\r\nelse:\r\n print((k*s)-n)",
"[k, n, w] = list(map(int, input().split()))\r\n\r\nct=0\r\n\r\nfor i in range(1,w+1):\r\n \r\n ct=ct+(k*i)\r\n \r\ny=ct-n\r\na=0\r\nif(n>=ct):\r\n print(a)\r\nelse:\r\n print(y)\r\n \r\n",
"k, n, w = [int(i) for i in input().split()]\r\nc = 0\r\nfor i in range(1, w+1):\r\n c += k*i\r\nif c <= n:\r\n print(0)\r\nelse:\r\n print(c-n)\r\n",
"k,n,w=map(int,input().split())\r\ntotal=0\r\nfor i in range(1,w+1):\r\n total+=k*i\r\n\r\nif total<=n or total==0:\r\n print(0)\r\nelse:\r\n print(total-n)",
"k, n, m = map(int, input().split())\r\n\r\ncost = 0\r\nfor i in range(1, m + 1):\r\n cost += k * i\r\n\r\nprint(max(0, cost - n))",
"k, n, w = map(int, input().split())\r\n\r\n# Calculate the total cost of buying w bananas\r\ntotal_cost = sum(i * k for i in range(1, w + 1))\r\n\r\n# Calculate the amount of dollars the soldier must borrow\r\nborrow_amount = max(0, total_cost - n)\r\n\r\nprint(borrow_amount)",
"k,n,w = map(int,input().split())\r\ncount=0\r\n\r\nfor i in range(1,w+1):\r\n count += i*k\r\nif n > count:\r\n print(0)\r\nelse:\r\n print(count-n)",
"k, n, w = map(int, input().split())\r\n\r\ndef sum_arithmetic_progression_formula(a, b):\r\n return int((a + a * b) * b / 2)\r\n\r\nresult = n - sum_arithmetic_progression_formula(k, w)\r\nresult = min(result, 0)\r\nresult = abs(result)\r\nprint(result)\r\n",
"mon,curmon,ban = input().split(\" \")\r\npay = 0\r\nfor i in range(1,int(ban)+1):\r\n pay = pay + (int(mon)*i)\r\n \r\nif pay - int(curmon) < 0:\r\n print(0)\r\nelse:\r\n print(pay - int(curmon) )",
"c,h,b=map(int,input().split())\r\na=0\r\nfor i in range(1,b+1):\r\n a+= (i*c)\r\nif h==0 or h<=a :\r\n print(abs(a-h))\r\nelse:\r\n print(0) \r\n\r\n",
"k,n,w=map(int,input().split())\r\ni=1\r\nx=0\r\nfor j in range(w):\r\n x+=i*k\r\n i+=1\r\nif x<=n:\r\n print(0)\r\nelse:\r\n print(x-n)",
"c,m,n=map(int,input().split())\r\na=0\r\nfor i in range(1,n+1):\r\n a+= c*i \r\nans=a-m\r\nif ans>=0:\r\n print(ans)\r\nelse:\r\n print(0)",
"def borrow_amount(k, n, w):\r\n total_cost = k * (1 + w) * w // 2\r\n borrow = max(0, total_cost - n)\r\n return borrow\r\n\r\n# Read input\r\nk, n, w = map(int, input().split())\r\n\r\n# Calculate and print the amount of dollars to borrow\r\nresult = borrow_amount(k, n, w)\r\nprint(result)",
"k,n,w=map(int,input().split())\r\ns=0\r\nfor i in range(1,w+1):\r\n s=s+i*k\r\nif (s>n):\r\n print(s-n)\r\nelse :\r\n print(0)",
"n = input().split(\" \")\nx = sum([x for x in range(int(n[2])+1)])\nif int(n[0])*x-int(n[1])>=0:\n print(int(n[0])*x-int(n[1]))\nelse:\n print(0)\n\n",
"k,n,w = map(int, input().split())\r\n\r\nans = ((w*(w+1)) // 2) * k - n\r\n\r\nprint( ans if ans > 0 else 0)",
"cost, dollar, wanted = list(map(int, input().split()))\r\ntotal = 0\r\n\r\nfor i in range(1, wanted + 1):\r\n total += i * cost\r\n\r\nif total > dollar:\r\n print(total - dollar)\r\n\r\nelse:\r\n print(0)",
"k, n, w = [int(x) for x in input().split()]\r\nb = (k * w * (w + 1)) // 2 - n\r\nif b <= 0:\r\n print(0)\r\nelse:\r\n print(b)\r\n",
"k, n, w = map(int, input().split())\r\ntotal_cost = k * w * (w + 1) // 2 # Sum of the first 'w' natural numbers\r\nresult = max(total_cost - n, 0)\r\nprint(result)\r\n",
"k,n,w=map(int,input().split())\r\ncosts=0\r\nfor i in range(1,w+1):\r\n costs=costs+i*k\r\nbr=costs-n\r\nif br<0:\r\n br=0\r\nprint(br)",
"k,n,w = map(int, input().split())\ncost = 0\nfor i in range(1, w+1):\n cost += i*k\n\nif cost <= n:\n print(0)\nelse:\n print(cost - n)\n\t\t \t\t\t \t \t \t \t\t \t \t \t \t",
"a,b,c=map(int,input().split())\r\nd=0\r\nfor i in range(c+1):\r\n d+=a*i\r\nif d<=b:\r\n print(0)\r\nelse:\r\n print(d-b)\r\n",
"nm=input()\r\nls=list(map(int,nm.split()))\r\n\r\nk=ls[0]\r\nn=ls[1]\r\nw=ls[2]\r\ni=1\r\nsum=0\r\nwhile(w>0):\r\n sum+=i*k\r\n i+=1\r\n w-=1\r\nif(sum<=n):\r\n print(0)\r\nelse:\r\n print(sum-n) ",
"k,n,w = map(int, input().split())\r\nprice = 0\r\ni = 1\r\nwhile i <= w:\r\n price = price + k*i\r\n i = i + 1\r\nborrow_price = price - n\r\nif borrow_price < 1:\r\n print(0)\r\nelse:\r\n print(borrow_price)",
"k, n, w = list(map(int, input().split()))\r\n\r\n\r\ncount = 0\r\n\r\nidx = 1\r\n\r\nwhile idx <= w:\r\n count += k*idx\r\n idx += 1\r\n\r\nif count <= n:\r\n print(0)\r\nelse:\r\n print(count-n)",
"a,b,c = map(int, input().split())\r\ncount = 0\r\nfor i in range(1, c+1):\r\n count += a*i\r\nif count > b:\r\n print(count - b)\r\nelse:\r\n print(0)",
"k,n,w=input().split(\" \")\r\nk=int(k)\r\nn=int(n)\r\nw=int(w)\r\n\r\n\r\n# w=4, k+2K+3K+4K= k*(1+2+3+4)=k*sum(1->w)\r\n# k*Sum(1->w)\r\ncost=0\r\nfor i in range(1,w+1):\r\n cost=cost+i\r\n \r\ncost=cost*k\r\n# cost>n , cost-n>0\r\nnet=cost-n\r\nprint(max(0,net))\r\n\r\n\r\n\r\n",
"price,money,banana = map(int, input().split())\r\ntotal = 0\r\nfor i in (range(1,banana+1)):\r\n total += i*price\r\nborrow = total - money\r\nif borrow <= 0:\r\n borrow = 0\r\nprint(borrow)",
"k,n,w=map(int,input().split())\r\ntot=k*(w*(w+1)//2)\r\nb=max(0,tot-n)\r\nprint(b)\r\n",
"\r\nk,n,w = map(int,input().split())\r\nsum = 0\r\nfor i in range(1,w+1):\r\n sum = sum + (k*i)\r\n\r\nif(sum>=n):\r\n print(sum - n)\r\nelse:\r\n print(0)\r\n\r\n",
"v=0\r\nr=0\r\nc=0\r\ns=0\r\nz = []\r\nk,n,w =map(int, input().split())\r\nm = int(k)\r\nk=0\r\nfor i in range(w):\r\n k = k ++ m\r\n c = z.append(k)\r\nfor i in z:\r\n s = s + i\r\n\r\nif s > n :\r\n r = s - n\r\nelse:\r\n v = 0\r\nprint(r)",
"k, n, w = input().split()\r\nk, n, w = int(k), int(n), int(w)\r\nif w*(w+1)*k/2 - n > 0:\r\n print(int(w*(w+1)*k/2 - n))\r\nelse:\r\n print(0)",
"def main():\r\n k, n, w = map(int, input().split())\r\n\r\n cost = 0\r\n\r\n for i in range(1, w+1):\r\n cost += k * i\r\n\r\n print(0 if cost <= n else cost - n)\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"m,n,k = map(int,input().split())\r\nmoney = 0\r\nfor i in range(k):\r\n money += m*(i+1)\r\nif money > n:\r\n brow = money - n\r\n print(brow)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\np=[]\r\nfor i in range(1,w+1):\r\n u=i*k\r\n p.append(u)\r\nf=sum(p)\r\nif f<=n:\r\n print(0)\r\nelse:\r\n print(f-n)",
"# Read the input values\r\nk, n, w = map(int, input().split())\r\n\r\n# Calculate the total cost\r\ntotal_cost = k * w * (w + 1) // 2\r\n\r\n# Calculate how much the soldier needs to borrow\r\nborrowed_money = max(0, total_cost - n)\r\n\r\n# Print the result\r\nprint(borrowed_money)\r\n",
"k, n, w = map(int, input().split())\ns = (k+w*k)*w/2\nprint(max(0, int(s-n)))",
"k, n, w = map(int, input().split())\r\nadd = (w * ( w + 1)) // 2\r\nprint(k * add - n if k * add > n else 0)",
"k,n,w = map(int,input().split())\r\n\r\ni = 1\r\n\r\nprice = 0\r\n\r\nfor i in range(w+1):\r\n price += i*k\r\n\r\nif price > n:\r\n debt = price - n\r\nelse:\r\n debt = 0\r\n\r\nprint (debt)\r\n\r\n",
"k,n,w=map(int,input().split())\r\na=0\r\nfor i in range(w+1):\r\n a=a+k*i\r\nif n>a:\r\n print(0)\r\nelse:\r\n print(a-n)",
"k,n,w=map(int,input().split())\r\ncost=0\r\nfor i in range(0,w+1):\r\n cost=cost+i*k\r\nn=max(0,cost-n)\r\nprint(n)",
"a,b,c=map(int,input().split())\nz=(c*(c+1)//2)*a\nx=max(0,z-b) \nprint(x) \n\t\t\t\t\t \t\t \t \t\t\t\t\t \t \t \t\t",
"k,m,b=map(int,input().split())\r\nsum=0\r\nfor i in range(b):\r\n sum+=(i+1)*k \r\nif sum<=m:\r\n print(0)\r\nelse:\r\n print(sum-m)",
"k,n,w=map(int,input().split())\r\ns=0\r\nfor i in range(1,w+1):\r\n s=s+(k*i)\r\nif(s>n):\r\n print(s-n)\r\nelse:\r\n print(0)\r\n",
"k, n, w = map(int, input().split())\r\ncost = int(w*(w+1)/2*k)\r\n\r\nif cost <= n:\r\n print(0)\r\nelse:\r\n print(cost-n)",
"a, b, c = input().split()\n\nresult = 0\nfor i in range(1 , int(c)+1):\n result += (i*int(a))\n \nif(result - int(b)) >= 0:\n print(result - int(b))\nelse:\n print(0)\n\t \t\t \t \t\t\t\t \t \t \t \t\t\t\t\t \t",
"def solve(k, n, w):\r\n\r\n total_cost = k * w * (w + 1) // 2\r\n borrowed_money = max(0, total_cost - n)\r\n return borrowed_money\r\n \r\n\r\n\r\ndef main():\r\n\r\n k, n, w = map(int, input().split())\r\n print(solve(k, n, w))\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"k, n, w =map(int, input().split())\r\n\r\nsum = k*(w*(w+1))//2\r\n\r\nif(n>=sum):\r\n print('0')\r\nelse:\r\n ans = sum - n\r\n print(ans)",
"dollars = input()\r\ndollars = dollars.strip()\r\nnumbers = dollars.split()\r\nnumbers = [int(number) for number in numbers]\r\ntotal_cost = 0\r\n\r\nfor i in range(numbers[2]):\r\n total_cost += (i + 1) * numbers[0]\r\n\r\nif total_cost > numbers[1]:\r\n print(total_cost - numbers[1])\r\nelse:\r\n print(0)\r\n",
"k,n,w=input().split(\" \")\r\nk=int(k)\r\nn=int(n)\r\nw=int(w)\r\n\r\n\r\n# w=4, k+2K+3K+4K= k*(1+2+3+4)=k*sum(1->w)\r\n# k*Sum(1->w)\r\ncost=w*(w+1)//2 \r\ncost=cost*k\r\n\r\n# cost>n , cost-n>0\r\nnet=cost-n\r\nprint(max(0,net))\r\n\r\n\r\n\r\n",
"a, b, c = map(int, input().split())\r\nc = int(a * (c * (c+1) / 2) - b)\r\nprint(c) if c > 0 else print(0)\r\n",
"a=str(input())\r\nb=a.split()\r\nc=int(b[0])\r\nd=int(b[1])\r\ne=int(b[2])\r\nf=0\r\nfor i in range(0,e+1):\r\n f=i*c+f\r\nif f<=d:\r\n print(0)\r\nelse:\r\n print(int(f-d))\r\n\r\n",
"k,n,w = input().split()\r\nk = int(k) # the cost of the first banana, \r\nn = int(n) # initial number of dollars the soldier has \r\nw = int(w) # and number of bananas he wants.\r\nquntity = 0\r\nfor i in range(w+1):\r\n quntity = i + quntity \r\ncost = quntity * k\r\n\r\nborrow = n - cost\r\nif borrow < 0:\r\n print((n-cost) * -1)\r\nelse:\r\n print(0)\r\n",
"k, n, w = map(int, input().split())\r\n \r\n \r\nfor i in range(1, w+1):\r\n n -= i*k\r\n \r\nprint(abs(n) if n < 0 else 0)",
"k,n,w=map(int,input().split())\r\ncost=(w*(w+1)//2)*k\r\namt=max(0,cost-n)\r\nprint(amt)",
"def banane(k,n,w):\r\n prix=0\r\n for i in range(w+1):\r\n prix=prix+i*k\r\n if (n>=prix):\r\n return(0)\r\n else:\r\n return(prix-n)\r\n\r\nx=input()\r\nx=x.split()\r\nk=int(x[0])\r\nn=int(x[1])\r\nw=int(x[2])\r\nprint(banane(k,n,w))",
"n1,n2,n3=map(int,input().split())\r\ntotal=0\r\nfor i in range(1,n3+1):\r\n total+=i\r\ntotal=n1*total\r\nresult=total-n2\r\nif result>0:\r\n print(result)\r\nelse:\r\n print(0)\r\n ",
"k, n, w = list(int(num) for num in input().split())\r\nsum = int(k * w * (1 + w) / 2)\r\n\r\nif sum < n:\r\n print(0)\r\nelse:\r\n print(sum - n)",
"k,n,w=map(int,input().split())\r\nnm=int((1+w)*w/2*k)\r\nif nm<=n:\r\n print(0)\r\nelse:\r\n print(nm-n)",
"line = input()\nline = line.split(' ')\nk = int(line[0])\nn = int(line[1])\nw = int(line[2])\ntotal_cost = int((w*(w+1))/2) * k\nif total_cost - n > 0:\n print(total_cost-n)\nelse:\n print(0)",
"k, n, w = [int(i) for i in input().split(\" \")]\r\ntotal = w*(w+1)//2*k - n\r\ntotal = total if total>=0 else 0\r\nprint(total)",
"k,n,w=map(int,input().split())\r\nr=((w*(w+1))//2)*k\r\nif(r-n>=0):\r\n print(r-n)\r\nelse:\r\n print(0)",
"k,n,w=[int(i)for i in input().split()]\r\ncnt=0\r\nfor i in range(1,w+1):cnt+=i\r\nif int(k*cnt-n)<=0:print(0)\r\nelse:print(int(k*cnt-n))",
"arr = [int(a) for a in input().split(\" \")] # k n w, ���������, ����������� ���, �������\r\nsum = 0\r\nfor i in range(arr[2]):\r\n sum += (i+1) * arr[0]\r\n\r\nif arr[1] >= sum:\r\n print(0)\r\nelse:\r\n print(sum-arr[1])",
"# la complejidad es O(w), ya que todo depende de la cantidad de platanos que quiere\nk, n, w = map(int, input().split())\nvt = 0 # Valor total\n\nfor x in range(1, w + 1):\n vt += k * x\n\nr = max(0, vt - n)#respuesta\n\nprint(r)\n\t\t \t\t\t \t\t\t\t \t \t\t \t\t\t\t \t\t \t \t",
"k,n,w=map(int,input().split())\r\na=0\r\nfor i in range(1,w+1):\r\n a+=(k*i)\r\nif a>n:\r\n print(a-n)\r\nelse:\r\n print(\"0\")",
"k, n, b = map(int, input().split()) \r\nx = k*b*(b+1)//2\r\nprint(0 if x <= n else x-n)",
"k,n,w = map(int, input().split(\" \",))\r\ns = 0\r\n\r\nfor i in range(w):\r\n s = s + ((i+1)*k)\r\n\r\n \r\nif s < n:\r\n print('0')\r\nelse:\r\n print(s-n)",
"import sys\r\n\r\n\r\ndef iinp():\r\n return int(sys.stdin.readline().strip())\r\n\r\n\r\ndef linp():\r\n return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\n\r\ndef lsinp():\r\n return sys.stdin.readline().strip().split()\r\n\r\n\r\ndef digit():\r\n return [int(i) for i in (list(sys.stdin.readline().strip()))]\r\n\r\n\r\ndef char():\r\n return list(sys.stdin.readline().strip())\r\n\r\n\r\nfrom bisect import bisect_left, bisect_right\r\nfrom collections import defaultdict\r\n\r\n\r\ndef summ(n):\r\n return sum(int(i) for i in list(str(n)))\r\n\r\n\r\nfrom math import ceil\r\n\r\n\r\ndef solve():\r\n k, n, w = linp()\r\n ans = k * (w * (w + 1) // 2) - n\r\n if ans > 0:\r\n print(ans)\r\n else:\r\n print(0)\r\n\r\n\r\nq = 1\r\nfor _ in range(q):\r\n solve()\r\n",
"first_b, soldiers_money, how_many = map(int, input().split()) \r\ncost = 0\r\nfor i in range(1, how_many+1):\r\n banana_cost = i * first_b\r\n cost += banana_cost\r\nif soldiers_money >= cost:\r\n print(0)\r\nelse:\r\n print(cost - soldiers_money)\r\n ",
"k, n, w = map(int, input().split())\nvalor = k * w * (w + 1) // 2\nprestamo = valor-n\nif prestamo <= 0:\n print(0)\nelse:\n print(prestamo)\n\t \t \t\t\t \t \t \t\t\t\t\t \t \t \t\t",
"k,n,w=map(int,input().split())\r\nt=sum([i*k for i in range(w+1)])\r\nif n>=t:\r\n print(0)\r\nelse:\r\n print(t-n)",
"k,n,w=map(int,input().split())\r\nx=0\r\nfor i in range(1,w+1,1):\r\n x+=k*i\r\nif n>=x:\r\n print(0)\r\nelse:\r\n print(x-n)\r\n",
"k,n,w=map(int,input().split())\r\nres=k*w*(w+1)//2\r\nif res<=n:\r\n print(0)\r\nelse:\r\n print(res-n)",
"a=input().split()\r\nif int(a[1])>=int(a[0])*(1+int(a[2]))*int(a[2])/2:\r\n print(\"0\")\r\nelse:\r\n print(int(int(a[0])*(1+int(a[2]))*int(a[2])/2-int(a[1])))",
"k, n, w = map(int, input().split())\r\nF=k*(w*(w+1)/2)\r\nb=int(F-n)\r\nif b<0:\r\n print(0)\r\nelse:\r\n print(b)",
"a,b,c = list(map(int,input().split()))\r\n\r\nif 1<=a<=1000 and 1<=c<=1000 and 0<=b<=pow(10,9):\r\n sum = 0\r\n for i in range(1, c + 1):\r\n sum += i\r\n\r\n tk = sum * a\r\n print(tk - b) if b < tk else print(0)\r\n",
"arr = list(map(int,input().split()))\r\n\r\nk,n,w = arr[0],arr[1],arr[2]\r\n\r\nprice = sum(list(range(1,w+1))*k)\r\n\r\nprint(\"0\") if price<n else print(price-n)",
"k, n, w = map(int, input().split())\r\ntotal = (w * (w + 1)) // 2\r\ntotal *= k\r\nif total - n > 0:\r\n print(total - n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\ns=0\r\nfor i in range(1,w+1):\r\n s+=i*k\r\nprint(s-n if s-n>-1 else 0)",
"k,n,w = map(int,input().split())\r\nc = k*(w*(w+1)//2)\r\nif c <=n:\r\n print(0)\r\nelse:\r\n print(abs(n-c))",
"p,h,w=map(int,input().split())\r\nt=0\r\nfor i in range(1,w+1):\r\n t=t+i*p\r\nif(t<= h):\r\n print(0)\r\nelse:\r\n print(abs(t-h))",
"k,n,w = map(int,input().split())\r\nprint(max(0,k*w*(w+1)//2-n))\r\n",
"k,n,w=map(lambda x: int(x), input().split())\r\ntemp=k*(1+w)*w//2-n\r\nprint(temp if temp>0 else 0)\r\n",
"k,n,w = map(int,input().split())\r\ncost = k*((w*(w+1))/2)\r\nif n>=cost: print(0)\r\nelse: print(int(cost-n))",
"k, n, w= map(int, input().split())\r\n\r\n#count all price\r\nprice = 0\r\nfor i in range(1, w +1):\r\n price += i * k\r\n\r\n\r\n#borrow\r\nborrow = max(0, price - n )\r\nprint(borrow)",
"k, n, w = map(int, input().split())\r\n\r\ntotal = k*(w*(w+1)/2)\r\n\r\nif total>n:\r\n print(int(total-n))\r\nelse:\r\n print(0)",
"k, n, w = map(int, input().split())\r\nc = 0\r\nfor i in range (1, w+1):\r\n c = c + i*k\r\nif n > c:\r\n print(0)\r\nelse:\r\n print(c-n)",
"k,n,w=input().split()\r\nc=0\r\nfor i in range(1,int(w)+1):\r\n c=c+i*int(k)\r\nif c<int(n):\r\n print(0)\r\nelse:\r\n print(c-int(n))",
"k, n, w = map(int, input().split())\ntot = (w * (w + 1)) // 2\nreq = tot * k\nprint(max(req - n, 0))\n \t\t \t\t\t \t\t\t \t \t \t \t \t\t\t\t\t \t",
"k,n,w=list(map(int,input().split()))\r\nc=0\r\nfor i in range(1,w+1):\r\n c+=i*k\r\n a=c-n\r\nif a>0:\r\n print(a)\r\nelse:\r\n print(\"0\")",
"L = [int(i) for i in input().split()]\r\ns = 0\r\nfor i in range(1,L[2]+1):\r\n s+= i * L[0]\r\n\r\nif L[1] - s >= 0:\r\n print(0)\r\nelse:\r\n print(s-L[1])\r\n\r\n",
"k,n,w = map(int,input().split())\r\nif (w*(w+1)//2)*k - n < 0:\r\n print(0)\r\nelse:\r\n print((w*(w+1)//2)*k - n)",
"price,hehave,wanted=map(int,input().split())\r\ntotal_cost=0\r\nfor i in range(1,wanted+1):\r\n total_cost=total_cost+i*price\r\nif(total_cost<= hehave):\r\n print(0)\r\nelse:\r\n print(abs(total_cost-hehave))",
"k, n, w = map(int, input().split())\r\nc=0\r\nfor i in range(w+1):\r\n c+= k*i\r\nif n>c:\r\n print(0)\r\nelse:\r\n print(c-n)",
"\r\na, b, c = map(int, input().split())\r\nsumma = a * (c * (c + 1) // 2)\r\naizdot = max(0, summa - b)\r\nprint(aizdot)\r\n",
"k,n,w=map(int,input().split())\nx=int((2*k+(w-1)*k)*w/2-n)\nprint(max(0,x))",
"m, l, s = map(int, input().split())\r\ntc = 0\r\nfor i in range(1,s+1):\r\n tc += m*i\r\nif l > tc:\r\n print(0)\r\nelse:\r\n print(tc - l)",
"k,n,w=map(int,input().split())\r\nc=0\r\nfor i in range(1,w+1):\r\n c+=i*k\r\nbor=c-n\r\nif bor<0:\r\n bor=0\r\nprint(bor)",
"k, n, w = map(int, input().split())\r\ntotal = 0\r\nfor i in range(1, w+1):\r\n total += i * k\r\nprint(total - n) if total > n else print('0')",
"k,n,w=map(int,input().split())\r\nm=int(k*(w+1)*w/2)\r\nif m>=n:\r\n f=m-n\r\nelse:\r\n f=0\r\nprint(str(f))",
"s = input().split()\r\n\r\nk, n, w = int(s[0]), int(s[1]), int(s[2])\r\n\r\nsum = k * w * (w + 1) / 2\r\nprint(int(max(0, sum - n)))",
"first = input().split(\" \")\r\ncost = int(first[0])\r\nsavings = int(first[1])\r\nwanted = int(first[2])\r\nmoneyneeded = 0\r\nfor x in range(1,wanted+1):\r\n moneyneeded += cost*x\r\nneeded = savings-moneyneeded\r\nif needed >=0:\r\n print(0)\r\nelse:\r\n print(abs(needed))",
"k, n, w = map(int, input().split())\r\n\r\ntotal_cost = 0\r\n\r\nfor i in range(1, w + 1):\r\n total_cost += i * k\r\n\r\nborrowed = max(0, total_cost - n)\r\nprint(borrowed)\r\n",
"banana_price , dollars_he_has , number_of_bananas = map(int , input().split())\r\ninstead_0f_num_of_bananas = number_of_bananas\r\nfor x in range(1 , number_of_bananas+1):\r\n if instead_0f_num_of_bananas > 0 :\r\n price = x*banana_price\r\n dollars_he_has = dollars_he_has - price\r\n instead_0f_num_of_bananas -= 1\r\n else :\r\n break\r\nif dollars_he_has >= 0 :\r\n output = 0 \r\nelse :\r\n output = abs(dollars_he_has)\r\nprint(output)\r\n",
"k,n,w = map(int,input().split())\r\nc = 0\r\nfor i in range(1,w+1):\r\n c+=k*i\r\nif c-n<0:\r\n print(0)\r\nelse:\r\n print(c-n)",
"k, n, w = map(int, input().split())\r\nsumm = 0\r\nfor i in range(1, w + 1):\r\n summ += i * k\r\nif n < summ:\r\n print(summ - n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split()) #k-стоимость первого банана,n-количество денег у солдат\r\nsum=0\r\nfor x in range(1,w+1):\r\n sum+=k*x\r\nif sum>n:\r\n print(sum-n)\r\nelse:\r\n print(0)\r\n ",
"# Soldier and Bananas Difficulty:800\r\nk, n, w = map(int, input().split())\r\nif (w*(w+1)/2)*k-n > 0:\r\n borrow = int((w*(w+1)/2)*k-n)\r\nelse:\r\n borrow = 0\r\nprint(borrow)\r\n",
"m,n,w=map(int,input().split())\r\nprint(max(0,m*w*-~w//2-n))",
"k,n,w=map(int,input().split())\r\nborrow=(((w*(w+1))//2)*k)-n\r\nif borrow<0:\r\n borrow=0\r\nprint(borrow)",
"k,n,w=map(int, input().split())\r\ntotal=0\r\nfor i in range(1,w+1):\r\n total+=i*k\r\nif total>=n:\r\n print(total-n)\r\nelse:\r\n print(0)",
"k, n, w= map(int, input().split(\" \"))\r\ntotal = 0\r\nfor i in range(1, w + 1):\r\n total += i * k\r\nto_borrow = total - n\r\nif to_borrow < 0:\r\n to_borrow = 0 \r\nprint(to_borrow)",
"a,b,c=map(int,input().split())\r\nprint(max(0,a*c*-~c//2-b))",
"k, n , w = map(int, input().split())\r\n# print(k)\r\n# print(n)\r\n# print(w)\r\ntotal_cost = 0\r\nfor i in range(1, w+1):\r\n total_cost += (i * k)\r\nborrow = total_cost - n\r\nif borrow > 0:\r\n print(borrow)\r\nelse:\r\n print(0) ",
"a=list(map(int,input().split(\" \")))\r\ndebt=int(a[0]*a[2]*(a[2]+1)/2-a[1])\r\nif debt<0:\r\n print(\"0\")\r\nelse:\r\n print(debt)",
"def borrowed_money(k, n, w):\r\n total_cost = 0\r\n for i in range(1, w+1):\r\n total_cost += i*k\r\n \r\n borrowed = max(0, total_cost - n)\r\n return borrowed\r\n\r\nk, n, w = map(int, input().split())\r\n\r\n\r\nresult = borrowed_money(k, n, w)\r\n\r\n\r\nprint(result)\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 12 16:14:24 2023\r\n\r\n@author: ljy\r\n\"\"\"\r\n\r\nk,n,w=map(int,input().split())\r\nprice=0\r\nfor i in range(w):\r\n price+=k*(i+1)\r\nif n>=price:\r\n print(0)\r\nelse:\r\n print(price-n)",
"k,n,w = map(int, input().split())\r\nt= k*w*(w+1)//2\r\na=max(0,t-n)\r\nprint(a)",
"k, n, w = input().split()\nk = int(k)\nw = int(w)\nn = int(n)\ncost = 0\nfor i in range(1, w+1):\n cost += k*i\n\nif cost > n:\n print(cost - n)\nelse:\n print(0)\n\n#k\n#2k\n#3k\n \t\t\t\t \t\t \t \t \t\t \t\t",
"k, n, w = map(int, input().split())\r\n\r\ns=0\r\nq=1\r\n\r\nfor i in range(w):\r\n s=s+k*q\r\n q+=1 \r\n \r\nx=s-n\r\n\r\nif x>0:\r\n print(x)\r\nelse:\r\n print('0')",
"k,n,b = map(int,input().split())\r\nneed = k * b * (b + 1) // 2 - n\r\nif need > 0:\r\n print(need)\r\nelse:\r\n print(0)\r\n",
"k,n,w = input().split()\nk = int(k)\nn = int(n)\nw = int(w)\n\n\ntotal_cost = k * w * (w + 1) // 2\nborrow = max(0, total_cost - n)\nprint(borrow)\n\n\n\n\n \t \t\t\t \t\t \t \t \t \t \t\t\t\t\t\t\t",
"k,n,s=map(int,input().split())\r\nprint(max(0,k*s*-~s//2-n))",
"k, n, w = map(int, input().split())\r\nsumka = 0\r\nfor i in range(1, w + 1):\r\n sumka += i * k\r\nprint(sumka - n if sumka > n else 0)",
"k,n,w=map(int,input().split())\r\n\r\ns=0\r\nfor i in range(1,w+1):\r\n \r\n p=k*i\r\n s=s+p\r\nif s>=n:\r\n print(s-n)\r\nelse:\r\n print(\"0\")\r\n \r\n\r\n ",
"k,n,w = map(int, input().split())\r\ntotal = k*(w*(w+1))/2\r\nif total > n:\r\n print(int(total-n))\r\nelse:\r\n print(0)",
"k, n, w = map(int,input().split())\r\nd = 0\r\nfor i in range(1,w+1):\r\n d += k*i\r\nprint(0 if n >= d else d-n)\r\n ",
"k,n,w=map(int,input().split())\r\nx=w*(w+1)//2\r\nxx=k*x\r\nif k*x>n:\r\n print(xx-n)\r\nelse:\r\n print(0)\r\n",
"k,n,w=map(int,input().split())\r\ncost=k*(w*(w+1))//2\r\nif(cost-n)>0:\r\n print(cost-n)\r\nelse:\r\n print(0)",
"a,b,c= map(int,input().split())\r\n\r\n\r\na1 = 0\r\nfor x in range(c):\r\n a1+= a*(x+1)\r\nif (a1 - b) < 0:\r\n print(0)\r\nelse:\r\n print(a1- b)",
"k,n,w=map(int,input().split())\r\ns=w*(w+1)//2*k\r\nif s<=n:\r\n print(0)\r\nelse:\r\n print(s-n)",
"s,e,n=map(int,input().split())\r\nprint(max(0,s*(n+1)*n//2-e))",
"k, n, w = map(int, input().split())\r\n\r\nprice = 0\r\nfor i in range(1,w+1):\r\n price += k*i\r\n\r\nif price > n:\r\n print(price-n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\ncost=0\r\nfor i in range(1,w+1):\r\n cost+=i*k\r\nif cost>=n:\r\n print(cost-n)\r\nelse:\r\n print(0)",
"k,n,w=map(int,input().split())\r\nTC=0\r\nfor i in range(1,w+1):\r\n TC=TC+i*k\r\nif(TC-n>0):\r\n print(TC-n)\r\nelse:\r\n print(0)"
] | {"inputs": ["3 17 4", "1 2 1", "1 1 1", "1 5 6", "1 1000000000 1", "1000 0 1000", "859 453892 543", "1000 1000000000 1000", "1000 500500000 1000", "1000 500500001 1000", "1000 500499999 1000", "634 87973 214", "432 10000 241", "111 111111111 111", "20 43 3"], "outputs": ["13", "0", "0", "16", "0", "500500000", "126416972", "0", "0", "0", "1", "14497197", "12587552", "0", "77"]} | UNKNOWN | PYTHON3 | CODEFORCES | 620 | |
2ff5a19d85e28f8e54918a2087001c0c | Space mines | Once upon a time in the galaxy of far, far away...
Darth Wader found out the location of a rebels' base. Now he is going to destroy the base (and the whole planet that the base is located at), using the Death Star.
When the rebels learnt that the Death Star was coming, they decided to use their new secret weapon — space mines. Let's describe a space mine's build.
Each space mine is shaped like a ball (we'll call it the mine body) of a certain radius *r* with the center in the point *O*. Several spikes protrude from the center. Each spike can be represented as a segment, connecting the center of the mine with some point *P*, such that (transporting long-spiked mines is problematic), where |*OP*| is the length of the segment connecting *O* and *P*. It is convenient to describe the point *P* by a vector *p* such that *P*<==<=*O*<=+<=*p*.
The Death Star is shaped like a ball with the radius of *R* (*R* exceeds any mine's radius). It moves at a constant speed along the *v* vector at the speed equal to |*v*|. At the moment the rebels noticed the Star of Death, it was located in the point *A*.
The rebels located *n* space mines along the Death Star's way. You may regard the mines as being idle. The Death Star does not know about the mines' existence and cannot notice them, which is why it doesn't change the direction of its movement. As soon as the Star of Death touched the mine (its body or one of the spikes), the mine bursts and destroys the Star of Death. A touching is the situation when there is a point in space which belongs both to the mine and to the Death Star. It is considered that Death Star will not be destroyed if it can move infinitely long time without touching the mines.
Help the rebels determine whether they will succeed in destroying the Death Star using space mines or not. If they will succeed, determine the moment of time when it will happen (starting from the moment the Death Star was noticed).
The first input data line contains 7 integers *A**x*,<=*A**y*,<=*A**z*,<=*v**x*,<=*v**y*,<=*v**z*,<=*R*. They are the Death Star's initial position, the direction of its movement, and its radius (<=-<=10<=≤<=*v**x*,<=*v**y*,<=*v**z*<=≤<=10, |*v*|<=><=0, 0<=<<=*R*<=≤<=100).
The second line contains an integer *n*, which is the number of mines (1<=≤<=*n*<=≤<=100). Then follow *n* data blocks, the *i*-th of them describes the *i*-th mine.
The first line of each block contains 5 integers *O**ix*,<=*O**iy*,<=*O**iz*,<=*r**i*,<=*m**i*, which are the coordinates of the mine centre, the radius of its body and the number of spikes (0<=<<=*r**i*<=<<=100,<=0<=≤<=*m**i*<=≤<=10). Then follow *m**i* lines, describing the spikes of the *i*-th mine, where the *j*-th of them describes the *i*-th spike and contains 3 integers *p**ijx*,<=*p**ijy*,<=*p**ijz* — the coordinates of the vector where the given spike is directed ().
The coordinates of the mines' centers and the center of the Death Star are integers, their absolute value does not exceed 10000. It is guaranteed that *R*<=><=*r**i* for any 1<=≤<=*i*<=≤<=*n*. For any mines *i*<=≠<=*j* the following inequality if fulfilled: . Initially the Death Star and the mines do not have common points.
If the rebels will succeed in stopping the Death Star using space mines, print the time from the moment the Death Star was noticed to the blast.
If the Death Star will not touch a mine, print "-1" (without quotes).
For the answer the absolute or relative error of 10<=-<=6 is acceptable.
Sample Input
0 0 0 1 0 0 5
2
10 8 0 2 2
0 -3 0
2 2 0
20 0 0 4 3
2 4 0
-4 3 0
1 -5 0
8 8 4 4 4 2 6
1
-2 -2 -1 3 0
30 30 2 1 2 1 20
3
0 0 40 5 1
1 4 4
-10 -40 -5 7 0
100 200 95 8 1
-10 0 0
Sample Output
10.0000000000-174.6757620881 | [
"import sys, math\r\ndef dist(a,b):\r\n return pow((a[0] - b[0])**2 + (a[1] - b[1])**2 + (a[2] - b[2])**2,0.5)\r\n\r\ndef vxv(v1,v2):\r\n x = -v1[2] * v2[1] + v1[1] * v2[2]\r\n y = -v1[0] * v2[2] + v1[2] * v2[0]\r\n z = -v1[1] * v2[0] + v1[0] * v2[1]\r\n return (x,y,z)\r\nreadline = sys.stdin.readline\r\ns1,s2,s3,v1,v2,v3,R = map(int,readline().split())\r\nn = int(readline())\r\npm = []\r\np = []\r\n\r\nfor _ in range(n):\r\n o1,o2,o3,r,m = map(int,readline().split())\r\n p.append((o1,o2,o3,r))\r\n for _ in range(m):\r\n pm1,pm2,pm3 = map(int,readline().split())\r\n pm.append((pm1 + o1, pm2 + o2, pm3 + o3))\r\n\r\nnv = (v1,v2,v3)\r\nm = (s1,s2,s3)\r\ndistance = []\r\nfor x in pm:\r\n tp = (x[0] - m[0], x[1] - m[1], x[2] - m[2])\r\n tp1 = vxv(tp,nv)\r\n d = dist(tp1,(0,0,0))/dist(nv,(0,0,0))\r\n if d <= R:\r\n dd = pow(dist(x,m)**2-d**2,0.5)\r\n dnv = dist(nv, (0, 0, 0))\r\n nnv = (dd * nv[0] / dnv + m[0], dd * nv[1] / dnv + m[1], dd * nv[2] / dnv + m[2])\r\n if dist(nnv, x) < dist(x, m):\r\n distance.append(dd - pow(R**2 - d**2,0.5))\r\nfor i in range(len(p)):\r\n pi =(p[i][0],p[i][1],p[i][2])\r\n tp = (pi[0] - m[0], pi[1] - m[1], pi[2] - m[2])\r\n tp1 = vxv(tp,nv)\r\n d = dist(tp1,(0,0,0))/dist(nv,(0,0,0))\r\n if d - p[i][3] <= R:\r\n dd = pow(dist(pi,m)**2-d**2,0.5)\r\n dnv = dist(nv,(0,0,0))\r\n nnv = (dd * nv[0]/dnv + m[0], dd * nv[1]/dnv + m[1],dd * nv[2]/dnv + m[2])\r\n if dist(nnv,p[i]) < dist(p[i],m):\r\n dr = pow((R + p[i][3])**2 - d**2,0.5)\r\n distance.append(dd - dr)\r\n\r\nif len(distance):\r\n distance.sort()\r\n print(distance[0]/dist(nv,(0,0,0)))\r\nelse:\r\n print(-1)# 1692608648.734028"
] | {"inputs": ["0 0 0 1 0 0 5\n2\n10 8 0 2 2\n0 -3 0\n2 2 0\n20 0 0 4 3\n2 4 0\n-4 3 0\n1 -5 0", "8 8 4 4 4 2 6\n1\n-2 -2 -1 3 0", "30 30 2 1 2 1 20\n3\n0 0 40 5 1\n1 4 4\n-10 -40 -5 7 0\n100 200 95 8 1\n-10 0 0", "100 99 30 -1 -5 -3 100\n1\n100 -90 -50 5 4\n0 6 0\n7 0 0\n6 1 1\n0 -6 -1", "0 0 0 5 5 5 20\n1\n-20 0 -30 10 2\n0 11 2\n-5 -8 -6", "-4 5 8 6 1 5 10\n5\n10 -3 -3 3 1\n0 -4 -2\n5 9 -8 1 1\n-1 0 -1\n-9 8 -6 1 2\n-1 0 1\n0 -1 1\n0 4 -7 3 2\n2 -1 -3\n4 -2 0\n0 -9 -9 3 1\n0 -3 -1", "-47 -7 -43 5 -8 -10 13\n13\n-10 -40 -34 5 3\n6 -2 3\n-4 -1 -4\n-6 -1 2\n-36 45 33 10 2\n-4 -6 8\n0 -14 -5\n14 -15 6 1 3\n-1 -1 0\n1 0 -1\n0 -1 1\n9 -32 6 6 2\n-1 6 -1\n-4 -2 -5\n45 -31 2 11 2\n0 14 8\n-12 -11 0\n-5 35 -3 7 2\n-9 1 1\n-3 -9 1\n-17 -13 -6 2 1\n2 0 1\n-45 -41 16 10 1\n10 -6 -4\n-46 30 4 4 3\n0 5 -1\n1 4 0\n0 -5 3\n23 10 -31 9 1\n-10 -3 -2\n26 10 0 9 2\n9 -3 2\n-1 4 -10\n-45 12 23 1 1\n-1 1 0\n22 -1 45 5 3\n6 0 4\n0 1 -5\n-4 -1 -3", "-10000 0 0 1 0 0 2\n1\n10000 3 0 1 0", "-10000 0 0 1 0 0 3\n1\n10000 6 0 2 1\n-3 0 0", "-10000 0 0 10 1 0 100\n1\n9995 2110 0 10 0", "-10000 0 0 10 1 0 100\n1\n9994 2110 0 10 0"], "outputs": ["10.0000000000", "-1", "74.6757620881", "17.6693584143", "-1", "-1", "-1", "20000.0000000000", "-1", "2000.2694337364", "-1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
301e737070363b274b194f0490596d1d | Shopping | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains *k* items. *n* customers have already used the above service. Each user paid for *m* items. Let *a**ij* denote the *j*-th item in the *i*-th person's order.
Due to the space limitations all the items are arranged in one single row. When Ayush receives the *i*-th order he will find one by one all the items *a**ij* (1<=≤<=*j*<=≤<=*m*) in the row. Let *pos*(*x*) denote the position of the item *x* in the row at the moment of its collection. Then Ayush takes time equal to *pos*(*a**i*1)<=+<=*pos*(*a**i*2)<=+<=...<=+<=*pos*(*a**im*) for the *i*-th customer.
When Ayush accesses the *x*-th element he keeps a new stock in the front of the row and takes away the *x*-th element. Thus the values are updating.
Your task is to calculate the total time it takes for Ayush to process all the orders.
You can assume that the market has endless stock.
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*k*<=≤<=100,<=1<=≤<=*m*<=≤<=*k*) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains *k* distinct integers *p**l* (1<=≤<=*p**l*<=≤<=*k*) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to *k*.
Each of the next *n* lines contains *m* distinct integers *a**ij* (1<=≤<=*a**ij*<=≤<=*k*) — the order of the *i*-th person.
Print the only integer *t* — the total time needed for Ayush to process all the orders.
Sample Input
2 2 5
3 4 1 2 5
1 5
3 1
Sample Output
14
| [
"number = int(input().split()[0])\r\n#orders = int(input())\r\narray = input().split()\r\n\r\nsum = 0\r\n\r\nfor i in range(0,number):\r\n items = input().split()\r\n for j in items:\r\n buffer = []\r\n sum = sum + int(array.index(j)) +1\r\n buffer.append(j) \r\n array.remove(j)\r\n array = buffer + array\r\n \r\n \r\nprint(sum) \r\n \r\n",
"import sys\nimport math\n\ndata = sys.stdin.read().split()\ndata_ptr = 0\n\ndef data_next():\n global data_ptr, data\n data_ptr += 1\n return data[data_ptr - 1]\n\nN = int(data_next())\nM = int(data_next())\nK = int(data_next())\narr = []\nfor i in range(K):\n arr.append(int(data_next()))\n\nans = 0\nfor i in range(N):\n for j in range(M):\n item = int(data_next())\n idx = arr.index(item)\n arr = [item] + arr[0:idx] + arr[idx + 1:]\n ans += idx + 1\nprint(ans)\n\n",
"n,m,k=map(int,input().split())\r\np=list(map(int,input().split()))\r\nt=0\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n for x in a:\r\n ind=p.index(x)\r\n t+=(ind+1)\r\n p.pop(ind)\r\n p.insert(0,x)\r\nprint(t)\r\n\r\n\r\n \r\n",
"n, m, k = map(int, input().split())\r\np = list(map(int, input().split()))\r\nt = 0\r\nfor _ in range(n):\r\n a = list(map(int, input().split()))\r\n for i in a:\r\n pos = p.index(i)\r\n t += pos + 1\r\n p = [i] + p[:pos] + p[pos + 1:]\r\nprint(t)\r\n",
"f = lambda: map(int, input().split())\r\nn, m, k = f()\r\na = list(f())\r\ns = m * n\r\nfor i in range(n):\r\n for b in f():\r\n i = a.index(b)\r\n s += i\r\n a = [a.pop(i)] + a\r\nprint(s)",
"def main():\n n, m, k = map(int, input().split())\n aa, t = list(map(int, input().split())), n * m * k\n aa.reverse()\n for _ in range(n):\n for a in map(int, input().split()):\n i = aa.index(a)\n t -= i\n del aa[i]\n aa.append(a)\n print(t)\n\n\nif __name__ == '__main__':\n main()\n",
"n, m, k = map(int, input().split())\r\na = list(map(int,input().split()))\r\n\r\nans = m*n\r\n\r\nfor i in range(n):\r\n b = list(map(int,input().split()))\r\n for j in range(m):\r\n pos = a.index(b[j])\r\n ans += pos\r\n del a[pos]\r\n a.insert(0,b[j])\r\n \r\nprint(ans)",
"n, m, k = list(map(lambda q: int(q), input().split()))\nk_lst = list(map(lambda q: int(q), input().split()))\norder_lst = []\nfor i in range(n):\n\tlst = list(map(lambda q: int(q), input().split()))\n\torder_lst += lst\n\n# def calctime(a, ta, b, tb, h, m):\n# \tstart_queue = list(range(300, 1439))[::b]\n# \tstart_m = 60 * h + m\n# \tarrive_m = min(start_m + ta, END_M)\n# \ttotal = 0\n# \tfor index, num in enumerate(start_queue):\n# \t\tif num > start_m - tb and num < arrive_m:\n# \t\t\ttotal += 1\n# \treturn total\n\n\ndef calcCost(n,m,k,k_lst):\n\ttotal_min = 0\n\t_index = 0\n\tfor i in range(n*m):\n\t\t_item = order_lst[_index]\n\t\tfor index, item in enumerate(k_lst):\n\t\t\tif item == _item:\n\t\t\t\ttotal_min += index + 1\n\t\t\t\tbreak\n\t\tk_lst = [k_lst[index]] + k_lst[0:index] + k_lst[index+1:]\n\t\t_index += 1\n\treturn total_min\n\nprint(calcCost(n, m, k, k_lst))\n\n\n\n\n\n",
"ln=input().split(\" \")\r\nn=int(ln[0])\r\nm=int(ln[1])\r\nk=int(ln[2])\r\nx=0\r\npila=input().split(\" \")\r\nfor i in range(n):\r\n cus=input().split(\" \")\r\n for j in range(m):\r\n ind=pila.index(cus[j])\r\n x=x+ind+1\r\n pila.insert(0,pila.pop(ind)) \r\nprint(x)\r\n",
"n, m, k = map(int, input().split())\r\ns = list(map(int, input().split()))\r\nd = 0\r\nfor i in range(n):\r\n for a in list(map(int, input().split())):\r\n for j in range(k):\r\n if s[j] == a:\r\n del(s[j])\r\n s = [a] + s\r\n d += j + 1\r\nprint(d)",
"from sys import stdin, stdout\r\nfrom collections import deque\r\nnumbers, everyq, allq = map(int, stdin.readline().split())\r\nitems = deque(list(map(int, stdin.readline().split())))\r\ncnt = 0\r\nfor i in range(numbers):\r\n current = map(int, stdin.readline().split())\r\n for n in current:\r\n ind = 0\r\n while items[ind] != n:\r\n ind += 1\r\n cnt += ind + 1\r\n value = items[ind]\r\n for j in range(ind, 0, -1):\r\n items[j] = items[j - 1]\r\n items[0] = value\r\n \r\nstdout.write(str(cnt))",
"n, m, k = map(int, input().split())\r\np = list(map (int, input().split()))\r\nmoves = 0\r\nfor i in range(n):\r\n c = list(map(int, input().split()))\r\n for item in c:\r\n pos = 0\r\n while (item != p[pos]):\r\n pos = pos+1\r\n moves += pos + 1\r\n p = [p.pop(pos)] + p\r\nprint(moves)",
"n, m, k = map(int, input().split())\nl = list(map(int, input().split()))\nans = 0\n\nfor i in range(n):\n\tt = list(map(int, input().split()))\n\tfor j in range(m):\n\t\tans += l.index(t[j]) + 1\n\t\tl.remove(t[j])\n\t\tl.insert(0, t[j])\n\t\t\nprint (ans)\n",
"n,m,k = map(int,input().split())\r\npos = list(map(int,input().split()))\r\na = [list(map(int,input().split())) for i in range(n)]\r\nans = 0\r\nfor i in a:\r\n for j in i:\r\n ind = pos.index(j)\r\n ans+=ind+1\r\n pos.pop(ind)\r\n pos = [j]+pos\r\nprint(ans)\r\n ",
"n, m, k = map(int,input().split())\r\np = list(map(int,input().split()))\r\nans = 0\r\nfor _ in range(n):\r\n a = list(map(int,input().split()))\r\n for i in a:\r\n pos = p.index(i)\r\n ans += pos + 1\r\n mas = p + []\r\n for j in range(pos):\r\n p[j+1] = mas[j]\r\n p[0] = i\r\nprint(ans)\r\n\r\n\r\n\r\n",
"a= list(map(int, input().split()))\r\nn=a[0]\r\nm=a[1]\r\nk=a[2]\r\nb= list(map(int, input().split()))\r\nt=0\r\nfor i in range(n):\r\n arr=list(map(int, input().split()))\r\n for j in range(m):\r\n l=b.index(arr[j])\r\n t+=(1+l)\r\n for h in range(l,0,-1):\r\n b[h]=b[h-1]\r\n b[0]=arr[j]\r\nprint(t)",
"def get_index(el, lst):\r\n for idx, element in enumerate(lst):\r\n if element == el:\r\n return idx\r\n\r\n return -1\r\n\r\nif __name__ == '__main__':\r\n n, m, k = (int(cur_num) for cur_num in input().split())\r\n\r\n things = [int(cur_num) for cur_num in input().split()]\r\n\r\n ans = 0\r\n\r\n for _ in range(n):\r\n\r\n bought = [int(cur_num) for cur_num in input().split()]\r\n\r\n for purchase in bought:\r\n\r\n idx = get_index(purchase, things)\r\n\r\n ans += idx+1\r\n\r\n del things[idx]\r\n\r\n things = [purchase] + things\r\n\r\n print(ans)",
"import sys, math\r\ninput=sys.stdin.readline\r\nINF=int(1e9)+7\r\n\r\ndef solve(): \r\n n,m,k=map(int,input().split())\r\n data=list(map(int,input().split()))\r\n ans=0\r\n for _ in range(n):\r\n now=list(map(int,input().split()))\r\n for i in now:\r\n idx=data.index(i)\r\n ans+=idx+1\r\n data=[data[idx]]+data[:idx]+data[idx+1:]\r\n print(ans)\r\n \r\n \r\nt=1\r\nwhile t:\r\n t-=1\r\n solve()\r\n",
"n, m, k = map(int, input().split())\na = list(map(int, input().split()))\nans = 0\nfor i in range(n):\n\torders = map(int, input().split())\n\tfor order in orders:\n\t\tans += a.index(order) + 1\n\t\ta.remove(order)\n\t\ta.insert(0, order)\nprint(ans)",
"def main():\n n, m, k = map(int, input().split())\n aa, t = list(map(int, input().split())), n * m * k\n aa.reverse()\n u, v, w = aa.index, aa.remove, aa.append\n for _ in range(n):\n for a in map(int, input().split()):\n t -= u(a)\n v(a)\n w(a)\n print(t)\n\n\nif __name__ == '__main__':\n main()\n",
"tmp = input().split(' ')\r\nn = int(tmp[0])\r\nm = int(tmp[1])\r\nk = int(tmp[2])\r\ntmp = input().split(' ')\r\npos = []\r\nneed = []\r\nfor i in range(k):\r\n\tpos.append(int(tmp[i]))\r\ntime = 0\r\nfor i in range(n):\r\n\ttmp = input().split(' ')\r\n\tneed.clear()\r\n\tfor j in range(m):\r\n\t\tneed.append(int(tmp[j]))\r\n\tfor j in range(m):\r\n\t\tcurpos = pos.index(need[j])\r\n\t\ttime = time + curpos + 1\r\n\t\tdel pos[curpos]\r\n\t\tpos.insert(0,need[j])\r\n\r\nprint(time)\r\n\t\t",
"n,m,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nsums=0\r\nfor i in range(n):\r\n p = list(map(int,input().split()))\r\n for j in range(m):\r\n sums+=(a.index(p[j])+1)\r\n a.remove(p[j])\r\n a.insert(0,p[j])\r\nprint(sums)\r\n \r\n ",
"n , m , k = map ( int , input () . split () )\r\np = list ( map ( int , input () . split () ) ) \r\nans = 0\r\nfor _ in range ( n ) :\r\n arr = list ( map ( int , input () . split () ) ) \r\n for i in arr :\r\n pos = p . index ( i ) \r\n ans += pos + 1\r\n p = [p [pos]] + p[:pos] + p[pos + 1:]\r\n \r\nprint (ans)",
"n,m,k = map(int,input().split())\n\nl = list(map(int,input().split()))\n\ncusOrders = []\n\nfor i in range(n):\n\tcusOrders = cusOrders + list(map(int,input().split()))\n\ntotTime = 0\nsizeOfList = len(l)\n\nfor x in cusOrders:\n\tpos = l.index(x)\n\ttotTime = totTime + pos + 1\n\tn = [x]+l[:pos]\n\tif(pos != (sizeOfList-1)):\n\t\tn = n+l[pos+1:]\n\tl = n\n\nprint(totTime)\n \n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m, k = map(int, input().split())\r\nd = list(map(int, input().split()))\r\n\r\nx = [0]*(k+1)\r\nfor i in range(k):\r\n x[d[i]] = i+1\r\nc = 0\r\nfor _ in range(n):\r\n q = list(map(int, input().split()))\r\n for i in q:\r\n a = x[i] - 1\r\n c += a+1\r\n d = [d[a]] + d[:a] + d[a+1:]\r\n for j in range(a+1):\r\n x[d[j]] = j+1\r\n\r\nprint(c)",
"n,m,k=[int(x) for x in input().split()]\r\na=[None]*k\r\ninitial = [int(x) for x in input().split()]\r\n\r\ntime=0\r\nfor c in range(n):\r\n for obj in input().split():\r\n obj = int(obj)\r\n pos = initial.index(obj)\r\n time+=pos+1\r\n del initial[pos]\r\n initial.insert(0,obj)\r\nprint(time) \r\n",
"n,m,k=map(int,input().split()) \r\na=list(map(int,input().split())) \r\nans=0 \r\nfor _ in range(n):\r\n for i in map(int,input().split()):\r\n \r\n for j in range(k):\r\n if a[j]==i:\r\n ans+=j \r\n c=j-1 \r\n while c>=0:\r\n a[c],a[c+1]=a[c+1],a[c]\r\n c-=1 \r\n break \r\nprint(ans+n*m)",
"I=lambda:map(int,input().split())\r\nn,m,k=I()\r\na=list(I())\r\nl,s=[0]*(k+1),0\r\nfor i in range(k):l[a[i]]=i\r\nfor i in range(n):\r\n b=list(I())\r\n for j in b:\r\n v=l[j]\r\n s+=v+1\r\n for g in range(1,k+1):l[g]+=l[g]<v\r\n l[j]=0\r\nprint(s)",
"[n,m,k]=[int(i) for i in input().split()]\r\na=[0]*(k+1)\r\ntemp=[int(i) for i in input().split()]\r\nfor i in range(0,k):\r\n a[temp[i]]=i+1\r\nanswer=0\r\nfor z in range(0,n):\r\n temp=[int(i) for i in input().split()]\r\n for i in temp:\r\n answer+=a[i]\r\n for l in range(1,k+1):\r\n if a[l]<a[i]: a[l]+=1\r\n a[i]=1\r\n \r\nprint(answer)",
"n,m,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nans=0\r\nfor i in range(n) :\r\n for j in map(int,input().split()) :\r\n x=arr.index(j);\r\n ans+=(x+1)\r\n arr.pop(x)\r\n arr=[j]+arr[:]\r\n\r\nprint(ans)",
"n,m,k = map(int,input().split())\r\nkk = [int(i) for i in input().split()]\r\nss = 0\r\nfor _ in range(0,n):\r\n lst = [int(i) for i in input().split()]\r\n for i in range(0,m):\r\n k = kk.index(lst[i])\r\n ss += k+1\r\n kk = [lst[i]]+kk[:k]+kk[k+1:]\r\nprint(ss)",
"n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=[]\r\ncnt=0\r\nfor i in range(n):\r\n b=list(map(int,input().split()))\r\n for j in range(len(b)):\r\n c=a.index(b[j])+1\r\n cnt+=c\r\n a.insert(0,b[j])\r\n del a[c]\r\nprint(cnt)",
"n,m,k=map(int,input().split())\r\np=list(map(int,input().split()))\r\nlen_a=n*m\r\na=[None]*len_a\r\nfor i in range(n):\r\n\tcur_line=list(map(int,input().split()))\r\n\tfor j in range(m):\r\n\t\ta[i*m+j]=cur_line[j]\r\n\r\nsum=0\r\nfor i in range(len_a-1):\r\n\tindex_cur=p.index(a[i])\r\n\tsum+=index_cur+1\r\n\tfor j in range(index_cur):\r\n\t\tp[index_cur-j],p[index_cur-j-1]=p[index_cur-j-1],p[index_cur-j]\r\nsum+=p.index(a[-1])+1\r\nprint(sum)",
"n,m,k = list(map(int, input().strip().split()))\r\na = list(map(int, input().strip().split()))\r\n\r\nd = dict()\r\n\r\nfor i in range(k):\r\n d[a[i]] = i+1\r\n\r\nc = 0\r\nfor i in range(n):\r\n b = list(map(int, input().strip().split()))\r\n for el in b:\r\n e = d[el]\r\n for elk in d.keys():\r\n if d[elk] > e:\r\n pass\r\n elif d[elk] == e:\r\n d[elk] = 1\r\n else:\r\n d[elk] += 1\r\n c += e\r\nprint(c)",
"s = input().split()\r\nn = int(s[0])\r\nm = int(s[1])\r\nk = int(s[2])\r\npos = 0\r\ngoods = [int (x) for x in input().split()]\r\nfor i in range(n):\r\n\tbuy = input().split()\r\n\tfor u in buy:\r\n\t\tx = int(u)\r\n\t\tpos = pos + goods.index(x) + 1\r\n\t\tgoods.remove(x)\r\n\t\tgoods.insert(0, x)\r\nprint (pos)",
"n, m, k = map(int, input().split())\r\nrow = list(map(int, input().split()))\r\na = []\r\nfor _ in range(n):\r\n a += list(map(int, input().split()))\r\n\r\ntime = 0\r\nfor e in a:\r\n tmp = row.index(e)\r\n time += tmp + 1\r\n row.insert(0, row.pop(tmp))\r\n\r\nprint(time)\r\n \r\n",
"[n,m,k]=[int(a) for a in input(\"\").split(\" \")]\npos=[int(a) for a in input(\"\").split(\" \")]\ntime=0\nfor i in range(n):\n orders=[]\n orders+=[int(a) for a in input(\"\").split(\" \")]\n for o in orders:\n ind=pos.index(o)\n time+=(ind+1)\n pos=[pos.pop(ind)]+pos\nprint(time)",
"n,m,k=map(int,input().split())\r\n\r\nsum=0\r\na=list(map(int,input().split()))\r\nfor p in range(n):\r\n x=list(map(int,input().split()))\r\n for i in range(m):\r\n for j in range(k):\r\n if x[i]==a[j]:\r\n sum+=j+1\r\n for u in range(j,0,-1):\r\n a[u]=a[u-1]\r\n a[0]=x[i] \r\n \r\n #print(a) \r\n #print(sum)\r\n break\r\n \r\n \r\n\r\nprint(sum) \r\n \r\n ",
"from sys import stdin as fin\n# fin = open(\"ecr12b.in\", \"r\")\n\nclass node:\n def __init__(self, val=None):\n self.prev = self.next = None\n self.val = val\n\n @staticmethod\n def link(node1, node2):\n node1.next = node2\n node2.prev = node1\n return node2\n\n @staticmethod\n def move(node1, node2, inode1, inode2):\n if inode1.prev is not None:\n inode1.prev.next = inode2.next\n if inode2.next is not None:\n inode2.next.prev = inode1.prev\n node1 = node.link(node1, inode1)\n node2 = node.link(inode2, node2)\n return node1, node2\n\n\nn, m, k = map(int, fin.readline().split())\narr = list(map(int, fin.readline().split()))\n\n# p = [None] * k\n# for i in range(k):\n# p[arr[i] - 1] = i\n\ncur = line = node()\nfor num in arr:\n cur = node.link(cur, node(num))\nres = 0\nfor i in range(n):\n buy = list(map(int, fin.readline().split()))\n for num in buy:\n cur = line\n cnt = 0\n while cur.val != num:\n cur = cur.next\n cnt += 1\n res += cnt\n if line.next != cur:\n line = node.move(line, line.next, cur, cur)[0].prev\n\nprint(res)",
"s = input().split(\" \")\r\ngoods_count = int(s[0])\r\ngoods = input().split(\" \")\r\nt = 0\r\nfor i in range(goods_count):\r\n s = input().split(\" \")\r\n for item in s:\r\n t += goods.index(item) + 1\r\n del goods[goods.index(item)]\r\n goods.insert(0, item)\r\nprint(t)",
"n, m, k = map(int, input().split())\r\np, v = input().split(), 0\r\nfor i in range(n):\r\n for x in input().split():\r\n c = p.index(x)\r\n v += c + 1\r\n p.pop(c)\r\n p.insert(0, x)\r\nprint(v)",
"n, m, k = map(int, input().split())\r\npos = list(map(int, input().split()))\r\nd = 0\r\nfor i in range(n):\r\n for a in list(map(int, input().split())):\r\n for j in range(k):\r\n if pos[j] == a:\r\n del(pos[j])\r\n pos = [a] + pos\r\n d += j + 1\r\nprint(d)\r\n \r\n",
"n, m, k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\ntime = 0\r\nfor a in range(n):\r\n B = list(map(int, input().split()))\r\n for i in B:\r\n K = [i]\r\n time += (A.index(i) + 1)\r\n for a in A:\r\n if a != i:\r\n K.append(a)\r\n A = K\r\nprint(time)",
"n,m,k=map(int,input().split())\r\np=list(map(int,input().split()))\r\na=[list(map(int,input().split())) for i in range(n)]\r\nst=0\r\nfor i in range(n):\r\n\tfor j in range(m):\r\n\t\tfor g in range(k):\r\n\t\t\tif a[i][j]==p[g]:\r\n\t\t\t\tp.insert(0,p[g])\r\n\t\t\t\tdel(p[g+1])\r\n\t\t\t\tst+=g+1\r\n\t\t\t\tg-=1\t\t\r\nprint(st)\r\n",
"import sys\r\nreadline=sys.stdin.readline\r\n\r\nN,M,K=map(int,readline().split())\r\nP=list(map(int,readline().split()))\r\nans=0\r\nfor n in range(N):\r\n A=list(map(int,readline().split()))\r\n for a in A:\r\n i=P.index(a)\r\n ans+=i+1\r\n P=[a]+P[:i]+P[i+1:]\r\nprint(ans)",
"n,m,k=map(int,input().split())\r\np=list(map(int,input().split()))\r\np.reverse()\r\nans=0\r\nfor i in range(n):\r\n z=list(map(int,input().split()))\r\n for j in z:\r\n v=0\r\n for k in range(len(p)-1,-1,-1):\r\n v+=1\r\n if p[k]==j:\r\n ans+=v\r\n p.pop(k)\r\n p.append(j)\r\n break\r\nprint(ans)\r\n",
"n,m,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nans=0\r\nwhile n:\r\n n-=1\r\n temp=list(map(int,input().split()))\r\n pos=-1\r\n for i in range(m):\r\n for j in range(k):\r\n if(l[j]==temp[i]):\r\n pos=j+1\r\n ans+=pos\r\n # print(pos)\r\n break\r\n f=l[pos-1]\r\n l.remove(l[pos-1])\r\n l.insert(0,f)\r\nprint(ans) \r\n\r\n",
"import sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nn,m,k = map(int, input().split())\r\nP = list(map(int, input().split()))\r\nans = 0\r\nfor i in range(n):\r\n A = list(map(int, input().split()))\r\n for a in A:\r\n for j, p in enumerate(P):\r\n if p == a:\r\n break\r\n P = [a]+P[0:j]+P[j+1:]\r\n ans += j+1\r\nprint(ans)\r\n",
"user,item,total=map(int,input().split())\r\nitems=list(map(int,input().split()))\r\nto=0\r\nfor i in range(user):\r\n a=list(map(int,input().split()))\r\n for j in a:\r\n to+=items.index(j)+1\r\n items.pop(items.index(j))\r\n items=[j]+items\r\nprint(to)\r\n",
"l1 = list(map(int, input().split()))\r\nn = l1[0]\r\nm = l1[1]\r\nk = l1[2]\r\na = list(map(int, input().split()))\r\ntot = 0\r\nfor i in range(n):\r\n\torders = list(map(int, input().split()))\r\n\tfor i in range(m):\r\n\t\tb = []\r\n\t\tval = orders[i]\r\n\t\tpos = a.index(val)\r\n\t\ttot = tot + pos + 1\r\n\t\ta.pop(pos)\r\n\t\tb.append(val)\r\n\t\tb = b + a\r\n\t\ta = b\r\nprint(tot)",
"n, m, k = map(int, input().split())\r\nc = list(map(int, input().split()))\r\nr = 0\r\nfor _ in range(n):\r\n for x in map(int, input().split()):\r\n i = c.index(x)\r\n r += i + 1\r\n c.pop(i)\r\n c.insert(0, x)\r\nprint(r)\r\n",
"n, m, k = map(int, input().split())\r\nps = list(map(int, input().split()))\r\nxs = []\r\nfor _ in range(n):\r\n xs.append(list(map(int, input().split())))\r\n\r\ndef get(x):\r\n i = ps.index(x)\r\n ps[1:i + 1] = ps[0:i]\r\n ps[0] = x\r\n return i + 1\r\n\r\nprint(sum(map(lambda ys: sum(map(get, ys)), xs)))\r\n",
"import sys\r\n\r\nn, m, k = map(int, input().split())\r\nitems = list(map(int, input().split()))\r\nans = 0\r\n\r\nfor _ in range(n):\r\n for x in map(int, input().split()):\r\n i = items.index(x)\r\n ans += i + 1\r\n items.insert(0, items.pop(i))\r\n\r\nprint(ans)\r\n",
"import sys\ninput=sys.stdin.readline\nn,m,k = map(int,input().split())\na = list(map(int,input().split()))\nres = 0\nfor i in range(n):\n for j in input().split():\n yy = int(j)\n res+=a.index(yy) + 1\n a.remove(yy)\n a = [yy]+a\nprint(res)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m, k = map(int, input().split())\r\np = list(map(int, input().split()))\r\nans = 0\r\nfor _ in range(n):\r\n a = list(map(int, input().split()))\r\n for i in a:\r\n x = p.index(i)\r\n ans += x + 1\r\n for j in range(x, 0, -1):\r\n p[j - 1], p[j] = p[j], p[j - 1]\r\nprint(ans)",
"#!/usr/bin/python\nimport sys\ninput = lambda: sys.stdin.readline().strip()\nn, m, k = [int(x) for x in input().split()]\npos = [int(x) for x in input().split()]\nans = 0\nfor i in range(n):\n a = [int(x) for x in input().split()]\n for x in a:\n j = pos.index(x)\n ans += j + 1\n pos.pop(j)\n pos.insert(0, x)\nprint(ans)\n",
"n,m,k=map(int,input().split())\r\nk1=[int(x) for x in input().split()]\r\na=[]\r\nfor j in range(n):\r\n m1=[int(q) for q in input().split()]\r\n a.extend(m1)\r\ns=0\r\nfor l in range(len(a)):\r\n w=0\r\n e=[]\r\n for i in range(len(k1)):\r\n if a[l]==k1[i]:\r\n s+=k1.index(k1[i])+1\r\n w=k1[i]\r\n e.append(w)\r\n del k1[i]\r\n e.extend(k1)\r\n k1=[]\r\n k1.extend(e)\r\n break\r\nprint(s)\r\n \r\n",
"n,m,k=map(int,input().split())\r\nq=list(map(int,input().split()))\r\nans=0\r\nfor i in range(n):\r\n lst=list(map(int,input().split()))\r\n for j in lst:\r\n #for x in input().split():\r\n ind=q.index(j)\r\n ans+=(ind+1)\r\n q.pop(ind)\r\n q.insert(0,j)\r\nprint(ans)\r\n\r\n",
"n, m, k = map(int, input().split())\r\np = list(map(int, input().split()))\r\n\r\nr = 0\r\n\r\n#p = {key: p.index(key) + 1 for key in p}\r\n\r\nfor i in range(0, n):\r\n a = list(map(int, input().split()))\r\n for j in range(0, len(a)):\r\n index = p.index(a[j])\r\n r += index + 1\r\n p.insert(0, p.pop(index))\r\n\r\nprint(r)",
"#!/usr/bin/env python\nn, m, k = map(int, input().split())\nl = list(map(int, input().split()))\nt = 0\n\nfor i in range(n):\n for item in map(int, input().split()):\n t += l.index(item) + 1\n l.remove(item)\n l.insert(0, item)\nprint(t)\n",
"#import sys\r\n#sys.stdin = open('in', 'r')\r\n#n = int(input())\r\n#a = [int(x) for x in input().split()]\r\nn,m,k = map(int, input().split())\r\np = [int(x) for x in input().split()]\r\ninds = [-1 for i in range(k + 1)]\r\nfor i in range(k):\r\n inds[p[i]] = i\r\n\r\nres = 0\r\nfor i in range(n):\r\n a = [int(x) for x in input().split()]\r\n for aij in a:\r\n pos = inds[aij]\r\n res += pos + 1\r\n while pos > 0:\r\n inds[p[pos-1]] += 1\r\n p[pos] = p[pos-1]\r\n pos -= 1\r\n p[0] = aij\r\n inds[aij]=0\r\n\r\nprint(res)\r\n",
"from collections import *\r\n\r\nn,m,k = map(int,input().split())\r\np = list(map(int,input().split()))\r\n\r\nsn = 0 \r\nfor _ in range(n):\r\n r = list(map(int,input().split()))\r\n for j in r:\r\n i = p.index(j)\r\n sn += i+1\r\n p.pop(i)\r\n p = [j]+p\r\n\r\n\r\nprint(sn)\r\n",
"n, m, k = map(int, input().split(' '))\r\np = input().split(' ')\r\n\r\nans = 0\r\nfor _ in range(0, n):\r\n il = input().split(' ')\r\n for i in il:\r\n idx = p.index(i)\r\n ans += idx + 1\r\n del p[idx]\r\n p = [i] + p\r\n \r\nprint(ans)",
"n, m, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\n\r\ntime = 0\r\n\r\n\r\nfor i in range(n):\r\n c = list(map(int, input().split()))\r\n for j in c:\r\n for k in range(len(a)):\r\n if a[k] == j:\r\n p = k\r\n break\r\n time += p + 1\r\n a = [j] + a[:k] + a[k + 1:]\r\n\r\nprint(time)\r\n",
"n, m, k = map(int, input().split())\r\nv = list(map(int, input().split()))\r\nplace = 0\r\ns = 0\r\nfor l in range(n):\r\n a = list(map(int, input().split()))\r\n for i in a:\r\n for j in range(k):\r\n if v[j] == i:\r\n place = j\r\n break\r\n s += place+1\r\n while place > 0:\r\n v[place] = v[place-1]\r\n place -= 1\r\n v[0] = i\r\nprint(s)\r\n"
] | {"inputs": ["2 2 5\n3 4 1 2 5\n1 5\n3 1", "4 4 4\n1 2 3 4\n3 4 2 1\n4 3 2 1\n4 1 2 3\n4 1 2 3", "1 1 1\n1\n1", "10 1 100\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99 65 20 52 35 85 16 12 94 100 59 56 18 33 47 46 71 8 38 57 2 92 3 95 6 4 87 22 48 80 15 29 11 45 72 76 44 60 91 90 39 74 41 36 13 27 53 83 32 5 30 63 89 64 49 17 9 97 69 14 50 77 37 96 10 42 28 34 61 19 73 7 62 43 58 25\n33\n69\n51\n7\n68\n70\n1\n35\n24\n7", "100 1 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "3 2 3\n3 1 2\n1 2\n2 1\n2 3", "10 10 10\n3 4 1 2 8 9 5 10 6 7\n9 10 7 8 6 1 2 3 4 5\n2 5 3 6 1 4 9 7 8 10\n2 9 1 8 4 7 5 10 6 3\n10 9 7 1 3 6 2 8 5 4\n2 5 1 3 7 10 4 9 8 6\n6 1 8 7 9 2 3 5 4 10\n1 3 2 8 6 9 4 10 5 7\n5 2 4 8 6 1 10 9 3 7\n5 1 7 10 4 6 2 8 9 3\n2 1 3 9 7 10 6 4 8 5"], "outputs": ["14", "59", "1", "335", "100", "13", "771"]} | UNKNOWN | PYTHON3 | CODEFORCES | 65 | |
30494f7ac1c5ba89c23a40068f7d26fe | Exams | Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.
According to the schedule, a student can take the exam for the *i*-th subject on the day number *a**i*. However, Valera has made an arrangement with each teacher and the teacher of the *i*-th subject allowed him to take an exam before the schedule time on day *b**i* (*b**i*<=<<=*a**i*). Thus, Valera can take an exam for the *i*-th subject either on day *a**i*, or on day *b**i*. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number *a**i*.
Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.
The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take.
Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=<<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i*-th exam, correspondingly.
Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.
Sample Input
3
5 2
3 1
4 2
3
6 1
5 2
4 3
Sample Output
2
6
| [
"n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n a, b= map(int, input().split())\r\n l.append([a,b])\r\nl.sort()\r\nprev=0\r\nfor a, b in l:\r\n if b>= prev:\r\n prev=b\r\n else:\r\n prev=a\r\nprint(prev)",
"d = {}\r\nfor i in range(int(input())):\r\n t = [int(i) for i in input().split()]\r\n if t[0] in d:\r\n d[t[0]].append(t[1])\r\n else:\r\n d[t[0]] = [t[1]]\r\nday = 0\r\nfor i in sorted(d.keys()):\r\n if day<=min(d[i]):\r\n day = max(d[i])\r\n else:\r\n day = i\r\nprint(day)",
"def main():\r\n n = int(input())\r\n lis = []\r\n for _ in range(n):\r\n lis.append([int(i) for i in input().split(' ')])\r\n lis = sorted(lis)\r\n ans = 0\r\n for j in range(n):\r\n sublis = lis[j]\r\n if ans <= sublis[1]:\r\n ans = sublis[1]\r\n else:\r\n ans = sublis[0]\r\n print(ans)\r\n\r\n\r\nmain()",
"k = 0\r\nfor a, b in sorted(tuple(map(int, input().split())) for _ in range(int(input()))):\r\n k = b if k <= b else a\r\nprint(k)\r\n",
"n,d=int(input()),0\r\ne=[tuple(map(int,input().split())) for i in range(n)]\r\nfor a,b in sorted(e): d = b if b >=d else a\r\nprint(d)\r\n",
"t = int(input())\r\nz = []\r\nfor i in range(t):\r\n z.append(list(map(int,input().split())))\r\nz2 = sorted(z,key=lambda x:t*x[0]+x[1])\r\nq = 0\r\nfor x in z2:\r\n if q <= x[1]:\r\n q = x[1]\r\n else:\r\n q = x[0]\r\nprint(q)\r\n ",
"t = [list(map(int, input().split())) for i in range(int(input()))]\r\nt.sort()\r\ns = 0\r\nfor a, b in t: s = a if b < s else b\r\nprint(s)",
"def find_minimum_day(n, a):\r\n # Sort the array of pairs\r\n a.sort()\r\n\r\n best = -1\r\n for i in range(n):\r\n if best <= a[i][1]:\r\n best = a[i][1]\r\n else:\r\n best = a[i][0]\r\n\r\n # Print the result\r\n return best\r\n\r\n# Read the number of exams\r\nn = int(input())\r\n\r\n# Read the exam details\r\nexams = []\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n exams.append((a, b))\r\n\r\n# Find the minimum possible day\r\nminimum_day = find_minimum_day(n, exams)\r\n\r\n# Print the result\r\nprint(minimum_day)",
"def solve():\r\n n = int(input().strip())\r\n\r\n data = []\r\n for i in range(n):\r\n a_i, b_i = map(int, input().strip().split())\r\n\r\n data.append((a_i, b_i))\r\n\r\n data.sort()\r\n\r\n min_day = data[0][1]\r\n for i in range(1, n):\r\n if min_day <= data[i][1]:\r\n min_day = data[i][1]\r\n else:\r\n min_day = data[i][0]\r\n\r\n print(min_day)\r\n\r\n\r\nsolve()\r\n",
"n = int(input())\r\na = sorted([list(map(int, input().split())) for _ in range(n)])\r\np = 0\r\nfor i in a:\r\n p = i[1] if i[1] >= p else i[0]\r\n\r\nprint(p)",
"a = sorted([list(map(int,input().split())) for i in range(int(input()))])\r\nb = a[0][1]\r\nfor i,j in a[1:]:\r\n b = i if j < b else j\r\nprint(b)\r\n#The heck this took me so long, i just needed to be greedy",
"n = int(input())\r\narr = []\r\nfor _ in range(n):\r\n\ta,b = map(int,input().split())\r\n\tarr.append((a,b))\r\n\r\narr.sort()\r\n\r\nbest = -1\r\n\r\nfor i in range(n):\r\n\tif(best <= arr[i][1]):\r\n\t\tbest = arr[i][1]\r\n\telse:\r\n\t\tbest = arr[i][0]\r\n\r\nprint(best)",
"s=[list(map(int, input().split())) for i in range(int(input()))]\r\ns.sort()\r\nd=0\r\nfor a,b in s:\r\n d=a if b<d else b\r\nprint(d)",
"n = int(input())\r\nlst = []\r\nfor _ in range(n):\r\n lst.append(list(map(int,input().split())))\r\nlst.sort()\r\ndate = lst[0][1]\r\nfor j in range(n):\r\n if date <= min(lst[j][1],lst[j][0]):\r\n date = min(lst[j][1],lst[j][0])\r\n else:\r\n date = max(lst[j][0],lst[j][1])\r\nprint(date)",
"def main():\r\n n = int(input())\r\n p = list()\r\n for i in range(n):\r\n a, b = list(map(int, input().split()))\r\n p.append([a, b])\r\n p.sort()\r\n curr_time = 0\r\n for i in range(n):\r\n if p[i][1] >= curr_time:\r\n curr_time = p[i][1]\r\n else:\r\n curr_time = p[i][0]\r\n\r\n print(curr_time)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"t = int(input())\r\narr = []\r\nfor _ in range(t):\r\n n,k = map(int,input().split())\r\n arr.append([n,k])\r\narr.sort()\r\nres = -1\r\nfor i in range(len(arr)):\r\n if res <= arr[i][1]:\r\n res = arr[i][1]\r\n else:\r\n res = arr[i][0]\r\nprint(res)\r\n \r\n ",
"n=int(input())\r\nlis=[]\r\nfor i in range(n):\r\n a,b=(map(int,input().split()))\r\n lis.append((a,b))\r\nlis.sort()\r\nans=0\r\nfor i in range(1,n):\r\n if max(ans,min(lis[i-1]))>min(lis[i]):\r\n ans=lis[i][0]\r\nif ans==0:\r\n print(min(lis[-1]))\r\nelse:\r\n print(max(ans,min(lis[-1])))",
"\r\n#from math import ceil, sqrt\r\n\r\nimport io, os, sys\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #input().decode().rstrip('\\r\\n')\r\nprint = lambda x: sys.stdout.write(str(x) + \"\\n\")\r\n \r\nII = lambda: int(input())\r\nMII = lambda: map(int, input().split())\r\nLMII = lambda: list(MII())\r\n#SLMII = lambda: sorted(LMII())\r\n\r\nn = II()\r\ndays = []\r\n\r\nfor i in range(n):\r\n days.append(tuple(MII()))\r\ndays.sort()\r\n\r\nday = 0\r\nfor i in range(n):\r\n day = min(days[i]) if min(days[i]) >= day else days[i][0]\r\n \r\nprint(day)\r\n \r\n \r\n",
"from collections import deque\r\nimport io,os\r\n#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\nt = 1#int(input())\r\nfor _ in range(t):\r\n va,vb,v = [],[],[]\r\n n = int(input())\r\n vis = [0] * (n + 1)\r\n for i in range(n):\r\n a, b = map(int,input().split())\r\n v += [[a,b]]\r\n va += [[a,-i]]\r\n vb += [[b,i]]\r\nva.sort()\r\nv.sort()\r\nbest = -1\r\nfor i in range(n):\r\n if best <= v[i][1]:\r\n best = v[i][1]\r\n else:best = v[i][0]\r\nprint(best)\r\nexit()\r\nix,ix1 =[],[]\r\nls = -1\r\nls1 = -1\r\nfor i in range(n):\r\n # print(v[i])\r\n ix1 += [v[-va[i][1]][1]]\r\n#print(ix1)\r\nif ix1 == sorted(ix1):\r\n print(vb[-1][0])\r\nelse:print(va[-1][0])",
"n = int(input())\r\na = []\r\nfor i in range(n):\r\n a.append(list(map(int, input().split())))\r\na.sort()\r\nans = a[0][1]\r\nfor i in range(n):\r\n if ans > a[i][1]:\r\n ans = a[i][0]\r\n else:\r\n ans = a[i][1]\r\nprint(ans)\r\n",
"n=int(input())\r\ndi={}\r\nfor i in range(n):\r\n\ta,b=[int(i) for i in input().split()]\r\n\tdi[i]=[a,b]\r\nz=sorted(di,key=lambda i:di[i][0]*100000+di[i][1])\r\nans=0\r\nfor i in z:\r\n\tif ans>di[i][1]:\r\n\t\tans=max(di[i][0],ans)\r\n\telse:\r\n\t\tans=di[i][1]\r\nprint(ans)",
"y = sorted([list(map(int, input().split())) for _ in range(int(input()))], key=lambda k: [k[0], k[1]])\r\nans = -1\r\nfor i in y:\r\n ans = i[1] if ans <= i[1] else i[0]\r\nprint(ans)\r\n",
"n = int(input())\r\n\r\nab = []\r\nfor _ in range(n):\r\n x, y = input().split()\r\n ab.append((int(x), int(y)))\r\nab.sort()\r\ncur = 1\r\nfor i, j in ab:\r\n if j >= cur:\r\n cur = j\r\n else:\r\n cur = i\r\n\r\nprint(cur)",
"n = int(input())\r\nexams = []\r\n\r\nfor _ in range(n):\r\n ai, bi = map(int, input().split())\r\n exams.append((ai, bi))\r\n\r\nexams.sort()\r\n\r\nearliest_possible_day = exams[0][1]\r\nfor i in range(1, n):\r\n if exams[i][1] < earliest_possible_day:\r\n earliest_possible_day = exams[i][0]\r\n else:\r\n earliest_possible_day = exams[i][1]\r\n\r\nprint(earliest_possible_day)\r\n",
"n = int(input())\r\nexams = []\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n exams.append((a, b))\r\n\r\n# Sort the exams by scheduled day in ascending order, and in case of a tie, by early day in descending order.\r\nexams.sort()\r\n\r\nday = exams[0][1]\r\nfor i in range(1, n):\r\n # Always take the exam at the earliest possible day that doesn't violate the condition.\r\n # If taking an exam early would make the days go in decreasing order, take the exam at the scheduled day.\r\n if exams[i][1] < day:\r\n day = exams[i][0]\r\n else:\r\n day = exams[i][1]\r\n\r\nprint(day)",
"import sys\r\ninput = sys.stdin.readline\r\nls = []\r\nt = int(input())\r\nwhile t :\r\n t -= 1\r\n ls.append(list(map(int,input().split())))\r\nls.sort()\r\nlast = 0\r\nfor i in range(len(ls)) :\r\n if ls[i][1] >= last and ls[i][0] >= last :\r\n last = min(ls[i][0],ls[i][1])\r\n else :\r\n last = max(ls[i][0],ls[i][1])\r\nprint(last)",
"t = int(input())\r\nl = []\r\nfor _ in range(t):\r\n a, b = map(int, input().split())\r\n l.append((a, b))\r\nl.sort()\r\nd = 0\r\nfor a, b in l:\r\n d = b if d <= b else a\r\nprint(d)\r\n",
"n = int(input())\r\nz = []\r\nfor i in range(n):\r\n z.append(list(map(int, input().split())))\r\nz.sort()\r\nc = 0\r\nfor a, b in z:\r\n if b >= c:\r\n c = b\r\n else:\r\n c = a\r\nprint(c)",
"def clc(): \r\n n = int(input())\r\n arr = []\r\n for _ in range(n):\r\n x,y = map(int,input().split())\r\n arr.append((x,y))\r\n best = -1\r\n arr = sorted(arr)\r\n for i in range(len(arr)):\r\n if best<=arr[i][1]:\r\n best = arr[i][1]\r\n else:\r\n best = arr[i][0]\r\n print(best)\r\n\r\n return True\r\n\r\nv1 = clc()\r\n\r\nif not v1:\r\n print(0)",
"n = int(input())\r\narr = []\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n arr.append((a, b))\r\narr.sort()\r\nres = -1\r\nfor i in arr:\r\n if i[1] >= res: res = i[1]\r\n else: res = i[0]\r\nprint(res)\r\n",
"d={}\r\nans=0\r\nfor _ in range(int(input())):\r\n a,b=map(int,input().split())\r\n d.setdefault(a,[])\r\n d[a].append(b)\r\nnum = sorted(d.keys())\r\ndays= 0\r\nn=len(num)\r\nfor i in range(n):\r\n x=num[i]\r\n d[x].sort()\r\n if days<=d[x][0]:\r\n days= d[x][-1]\r\n else:\r\n days=x\r\nprint(days)\r\n ",
"\"\"\"\r\nCodeforces Contest 274 Div 1 Problem A\r\n\r\nAuthor : chaotic_iak\r\nLanguage: Python 3.3.4\r\n\"\"\"\r\n\r\ndef main():\r\n n, = read()\r\n a = []\r\n for i in range(n):\r\n a.append(tuple(read()))\r\n a.sort()\r\n day = 0\r\n for i in range(n):\r\n if day <= a[i][1]:\r\n day = a[i][1]\r\n else:\r\n day = a[i][0]\r\n print(day)\r\n\r\n################################### NON-SOLUTION STUFF BELOW\r\n\r\ndef read(mode=2):\r\n # 0: String\r\n # 1: List of strings\r\n # 2: List of integers\r\n inputs = input().strip()\r\n if mode == 0: return inputs\r\n if mode == 1: return inputs.split()\r\n if mode == 2: return list(map(int, inputs.split()))\r\n\r\ndef write(s=\"\\n\"):\r\n if s is None: s = \"\"\r\n if isinstance(s, list): s = \" \".join(map(str, s))\r\n s = str(s)\r\n print(s, end=\"\")\r\n\r\nwrite(main())",
"n = int(input())\r\nl = []\r\nfor i in range(n):\r\n x = list(map(int, input().split()))\r\n l.append(x)\r\nl.sort()\r\nday = l[0][1]\r\nfor i in range(1,len(l)):\r\n if day>l[i][1]:\r\n day = l[i][0]\r\n else:\r\n day = l[i][1]\r\n\r\n\r\nprint(day)",
"import sys\n# sys.stdin = open(\".in\", \"r\")\n# sys.stdout = open(\".out\", \"w\")\ninput = sys.stdin.readline\ndef print(*args, end='\\n', sep=' ') -> None:\n sys.stdout.write(sep.join(map(str, args)) + end)\ndef map_int():\n return map(int, input().split())\ndef list_int():\n return list(map(int, input().split()))\n\n\n\nn = int(input())\narr = sorted(tuple(map_int()) for i in range(n))\nlast = 0\nfor i in range(n):\n a, b = arr[i]\n if b >= last:\n last = b\n else:\n last = a\n\nprint(last)\n\n",
"import sys\r\n\r\n\r\ndef iinp():\r\n return int(sys.stdin.readline().strip())\r\n\r\n\r\ndef linp():\r\n return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\n\r\ndef lsinp():\r\n return sys.stdin.readline().strip().split()\r\n\r\n\r\ndef digit():\r\n return [int(i) for i in (list(sys.stdin.readline().strip()))]\r\n\r\n\r\ndef char():\r\n return list(sys.stdin.readline().strip())\r\n\r\n\r\ndef solve():\r\n n = iinp()\r\n temp = []\r\n for i in range(n):\r\n temp.append(linp())\r\n temp.sort()\r\n _, ans = temp[0]\r\n for i, j in temp[1:]:\r\n if j < ans:\r\n ans = i\r\n else:\r\n ans = max(j, ans)\r\n print(ans)\r\n\r\n\r\nq = 1\r\nfor _ in range(q):\r\n solve()\r\n",
"from functools import cmp_to_key as ctk\r\ndef f(a,b):\r\n if a[0]>b[0]:\r\n return 1\r\n if a[0]<b[0]:\r\n return -1\r\n if a[1]>b[1]:\r\n return 1\r\n if a[1]<b[1]:\r\n return -1\r\n return 0\r\n\r\nn=int(input())\r\nm1,m2=0,0\r\narr=[]\r\nfor _ in range(n):\r\n a,b=map(int,input().split())\r\n arr.append([a,b])\r\narr.sort(key=ctk(f))\r\nprev=0\r\nfor a,b in arr:\r\n if b>=prev:\r\n prev=b\r\n continue\r\n prev=a\r\nprint(prev)",
"n = int(input())\r\na = []\r\nfor _ in range(n):\r\n k, l = map(int, input().split())\r\n a.append([k, l])\r\na.sort()\r\nb = -1000\r\nfor i in range(n):\r\n if b <= a[i][1]:\r\n b = a[i][1]\r\n else:\r\n b = a[i][0]\r\nprint(b)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n############ ---- Input Functions ---- ############\r\n\r\ndef Exams():\r\n n = inp()\r\n\r\n a = []\r\n b = []\r\n for i in range(n):\r\n ai,bi = invr()\r\n a.append(ai)\r\n b.append(bi)\r\n \r\n a_sorted = [x for x,y in sorted(zip(a,b))]\r\n b_acc = [y for x,y in sorted(zip(a,b))]\r\n\r\n current_day = -1 \r\n\r\n for a,b in zip(a_sorted,b_acc):\r\n least_day_at_which_exam_can_be_taken = min(a,b)\r\n\r\n if least_day_at_which_exam_can_be_taken >= current_day:\r\n current_day = least_day_at_which_exam_can_be_taken\r\n else:\r\n if least_day_at_which_exam_can_be_taken == a:\r\n current_day = b \r\n else:\r\n current_day = a \r\n \r\n print(current_day)\r\n return \r\n\r\nExams()",
"n = int(input())\r\n\r\nexams = []\r\n\r\nfor i in range(n):\r\n exams.append(list(map(int, input().split())))\r\n# print(exams)\r\n\r\nexams.sort() \r\nstart = exams[0][1]\r\n\r\n# print(exams)\r\nfor s,e in exams:\r\n # print(vals)\r\n if e >= start:\r\n start = e\r\n else:\r\n start = s\r\n\r\n# print(vals)\r\n\r\nprint(start)\r\n",
"#https://codeforces.com/problemset/problem/479/C\r\n\r\nn = int(input())\r\na_b = []\r\nfor x in range(n):\r\n a,b = (int(x) for x in input().split())\r\n a_b.append([a,b])\r\na_b.sort()\r\nmin_days = min(a_b[0])\r\nfor x in range(1, n):\r\n temp_days = min(a_b[x])\r\n if(temp_days >= min_days):\r\n min_days = temp_days\r\n else:\r\n min_days = max(a_b[x])\r\nprint(min_days)",
"c=0\r\nfor x,y in sorted((list(map(int,input().split()))for _ in range(int(input())))):c=x if y<c else y\r\nprint(c)",
"from functools import cmp_to_key as cmp\r\ndef compare(a,b):\r\n if a[0]<b[0]:\r\n return -1\r\n if a[0]>b[0]:\r\n return 1\r\n if a[1]<b[1]:\r\n return -1\r\n return 1\r\n\r\nn=int(input())\r\nl=[]\r\nfor _ in range(n):\r\n l.append(list(map(int,input().split())))\r\nl=sorted(l,key=cmp(compare))\r\nans=l[0][1]\r\n# print(l)\r\nfor i in l:\r\n if i[1]<ans:\r\n ans=i[0]\r\n else:\r\n ans=i[1]\r\nprint(ans)",
"n = int(input())\r\na = [0] * n\r\nb = [0] * n\r\nfor i in range(n):\r\n a[i], b[i] = map(int, input().split())\r\nexams = []\r\nfor i in range(n):\r\n exams.append((a[i], b[i], i))\r\nexams.sort()\r\ndp = [0] * n\r\ndp[0] = exams[0][1]\r\nfor i in range(1, n):\r\n last = dp[i - 1]\r\n if exams[i][1] >= last:\r\n dp[i] = exams[i][1]\r\n else:\r\n dp[i] = exams[i][0]\r\nprint(dp[-1])",
"def exams(lst):\r\n result = - 1\r\n for elem in lst:\r\n if elem[1] >= result:\r\n result = elem[1]\r\n else:\r\n result = elem[0]\r\n return result\r\n\r\n\r\nn = int(input())\r\na = list()\r\nfor i in range(n):\r\n x, y = [int(j) for j in input().split()]\r\n a.append([x, y])\r\nprint(exams(sorted(a)))\r\n",
"'''\r\n* author: Adham0 \r\n* created: 24.08.2023 02:32:03\r\n \r\n* █████ ██████ ██ ██ █████ ███ ███ \r\n* ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ \r\n* ███████ ██ ██ ███████ ███████ ██ ████ ██ \r\n* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ \r\n* ██ ██ ██████ ██ ██ ██ ██ ██ ██ \r\n'''\r\n\r\nn = int(input())\r\n\r\nlst = []\r\nfor i in range(n):\r\n a, b = [int(i) for i in input().split()]\r\n lst.append((a, b))\r\n\r\nlst.sort()\r\n\r\nres = 0\r\nfor a, b in lst:\r\n res = a if b < res else b\r\n\r\nprint(res)",
"arr = [list(map(int, input().split())) for _ in range(int(input()))]\r\n\r\narr.sort()\r\nans = -1\r\nfor a, b in arr:\r\n if ans <= b:\r\n ans = b\r\n else:\r\n ans = a\r\nprint(ans)\r\n"
] | {"inputs": ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3", "1\n1000000000 999999999", "1\n2 1", "2\n3 2\n3 2", "5\n4 3\n4 2\n4 1\n4 1\n4 1", "6\n12 11\n10 9\n8 7\n6 5\n4 3\n2 1", "2\n3 1\n3 2", "2\n4 2\n4 1", "2\n5 2\n5 1", "6\n3 1\n3 2\n4 1\n4 2\n5 4\n5 4", "3\n3 2\n4 1\n100 10", "3\n4 3\n5 2\n10 8", "5\n6 5\n6 4\n6 3\n6 2\n6 1", "3\n5 4\n6 3\n8 7", "4\n7 1\n7 3\n8 2\n9 8", "3\n3 2\n4 1\n10 5", "3\n5 4\n6 3\n11 10", "4\n2 1\n3 2\n4 1\n6 5"], "outputs": ["2", "6", "999999999", "1", "2", "3", "11", "2", "2", "2", "4", "10", "8", "5", "7", "8", "5", "10", "5"]} | UNKNOWN | PYTHON3 | CODEFORCES | 46 | |
308f31764bb3b87376289f22975af96f | Amr and Pins | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.
Help Amr to achieve his goal in minimum number of steps.
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
Sample Input
2 0 0 0 4
1 1 1 4 4
4 5 6 5 6
Sample Output
1
3
0
| [
"from math import *\r\nr,x,y,a,b=map(int,input().split())\r\nprint(ceil((((x-a)**2+(y-b)**2)**0.5)/(r*2)))\r\n",
"import math\r\nr, x, y, x1, y1 = map(int, input().split())\r\nprint(math.ceil(math.sqrt((x-x1)**2 + (y-y1)**2)/(2*r)))\r\n",
"import math\r\nr, x, y, nx, ny = map(int,input().split())\r\nstep = 2*r\r\nd = math.sqrt((nx-x)**2 + (ny-y)**2)\r\nl, r = 0, 10**10\r\nans = 10**10\r\nwhile l <= r :\r\n mid = (l+r)//2\r\n cur = step*mid\r\n if(cur + 10**(-9) > d) :\r\n ans = mid\r\n r = mid - 1\r\n else :\r\n l = mid + 1\r\nprint(ans)",
"import math\r\nr,x,y,x1,y1 = [int(x) for x in input().split()]\r\ndist = math.sqrt(((x1-x)**2)+((y1-y)**2))\r\nprint(math.ceil(dist/(r*2)))",
"import math\r\n\r\nr, x, y, x_, y_ = map(int, input().split())\r\n\r\nD = 2*r\r\n\r\nd = math.sqrt((x-x_)**2 + (y-y_)**2)\r\n\r\nprint(math.ceil(d/D))",
"import math as m\r\nr,x,y,x_,y_ = [int(i) for i in input().split()]\r\nd = m.sqrt((x_-x)**2 +(y_-y)**2)\r\nprint(m.ceil(d/(2*r)))",
"import math\n\ndef main():\n\tr, x, y, a, b = [int(x) for x in input().split()]\n\n\td = ((a - x) ** 2 + (b - y) ** 2)**0.5\n\tt = r << 1\n\n\tans = math.floor(d) // t\n\td = d - ans * t\n\n\tif d > 0:\n\t\tans += 1\n\n\tprint(ans)\n\nif __name__ == '__main__':\n\tmain()",
"from math import ceil\r\nr,x1,y1,x2,y2 = map(int, input().split())\r\ndist = ((x2-x1)**2 + (y2-y1)**2)**(0.5)\r\nans = int(ceil(dist/(2*r)))\r\nprint(ans)\r\n",
"# ⣿⣷⡶⠚⠉⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠠⣴⣿⣿⣿⣿⣶⣤⣤⣤\r\n# ⠿⠥⢶⡏⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣴⣷⣌⢿⣿⣿⣿⣿⣿⣿⣿\r\n# ⣍⡛⢷⣠⣿⣿⣿⣿⣿⣟⠻⣯⠽⣿⣿⠟⠁⣠⠿⠿⣿⣿⣎⠻⣿⣿⣿⡿⠟⣿\r\n# ⣿⣿⣦⠙⣿⣿⣿⣿⣿⣿⣷⣏⡧⠙⠁⣀⢾⣧ ⠈⣿⡟ ⠙⣫⣵⣶⠇⣋\r\n# ⣿⣿⣿⢀⣿⣿⣿⣿⣿⣿⣿⠟⠃⢀⣀⢻⣎⢻⣷⣤⣴⠟ ⣠⣾⣿⢟⣵⡆⢿\r\n# ⣿⣯⣄⢘⢻⣿⣿⣿⣿⡟⠁⢀⣤⡙⢿⣴⣿⣷⡉⠉⢀ ⣴⣿⡿⣡⣿⣿⡿⢆\r\n# ⠿⣿⣧⣤⡘⢿⣿⣿⠏ ⡔⠉⠉⢻⣦⠻⣿⣿⣶⣾⡟⣼⣿⣿⣱⣿⡿⢫⣾⣿\r\n# ⣷⣮⣝⣛⣃⡉⣿⡏ ⣾⣧⡀ ⣿⡇⢘⣿⠋ ⠻⣿⣿⣿⢟⣵⣿⣿⣿\r\n# ⣿⣿⣿⣿⣿⣿⣌⢧⣴⣘⢿⣿⣶⣾⡿⠁⢠⠿⠁⠜ ⣿⣿⣿⣿⡿⣿⣿⣿\r\n# ⣿⣿⣿⣿⣿⣿⣿⣦⡙⣿⣷⣉⡛⠋ ⣰⣾⣦⣤⣤⣤⣿⢿⠟⢋⣴⣿⣿⣿\r\n# ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣌⢿⣿⣿⣿⣿⢰⡿⣻⣿⣿⣿⣿⣿⢃⣰⣫⣾⣿⣿⣿\r\n# ⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⠿⠿⠿⠛⢰⣾⡿⢟⣭⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\r\n\r\nfrom math import hypot,ceil\r\n\r\nr,x,y,x1,y1 = map(int,input().strip().split())\r\n\r\n# print(r,x,y,x1,y1)\r\nd = hypot(x1-x,y1-y)\r\n# print(d)\r\n\r\n\r\n\r\nprint( 0 if d == 0 else ceil(d/(2*r)) )",
"import math\r\nr, x, y, xx, yy = list(map(int, input().split()))\r\n\r\ndist = ((x - xx)**2 + (y - yy )**2) ** 0.5\r\n\r\nprint(math.ceil(dist / (r*2)))",
"values = list(map(int,(input()).split()))\r\ndistance = (((values[1]-values[3])**2)+((values[2]-values[4])**2))**0.5\r\nif distance%(2*values[0])==0:\r\n print(int(distance/(2*values[0])))\r\nelse:\r\n print(int(distance/(2*values[0]))+1)",
"import math\r\n\r\n\r\nr, x, y, a, b = map(int, input().split())\r\n\r\n\r\nd = math.sqrt((a - x)**2 + (b - y)**2)\r\ns = math.ceil(d / (2 * r))\r\nprint(s)",
"from math import *\r\n\r\nr,x,y,x1,y1=map(int,input().split())\r\n\r\ndist=sqrt(pow(abs(x1-x),2)+pow(abs(y1-y),2))\r\n\r\nprint(ceil(dist/(2*r)))",
"import math\r\nst=[int(i) for i in input().split(\" \")]\r\nr=st[0]\r\nx=st[1]\r\ny=st[2]\r\nx1=st[3]\r\ny1=st[4]\r\nd=math.sqrt((x1-x)**2+(y1-y)**2)\r\nprint(math.ceil(d/(2*r)))\r\n",
"import math\r\nr,x,y,x1,y1 = map(int,input().split())\r\nn = math.sqrt((x1-x)**2 + (y1-y)**2)\r\ns = math.ceil(n/(2*r))\r\nprint(int(s))",
"[r, x1, y1, x2, y2] = list(map(int, input().split(\" \")))\ndx = max(x2-x1, x1-x2)\ndy = max(y2-y1, y1-y2)\nd = (dx*dx + dy*dy)**(0.5)\nd = int(d) + (1 if int(d)*int(d) < (dx*dx + dy*dy) else 0)\nresult = d//(2*r) + (1 if d % (2*r) > 0 else 0)\nprint(result)\n",
"from math import *;r,x,y,x1,y1=map(int,input().split());print(ceil((pow(x-x1,2)+pow(y-y1,2))**(0.5)/(2*r)))\r\n",
"inp = list(map(int,input().split()))\r\nr=inp[0]\r\nx1=inp[1]\r\ny1=inp[2]\r\nx2=inp[3]\r\ny2=inp[4]\r\nd=pow((x1-x2)**2+(y1-y2)**2,0.5)\r\nd_in=int(d)\r\nflag=1\r\nif x1==x2 and y1==y2:\r\n print (0)\r\n flag=0\r\nif d<=2*r and flag==1:\r\n print (1)\r\n flag=0\r\nif d==d_in and flag==1:\r\n if d_in%(2*r)==0:\r\n print (int((d_in-2*r)//(2*r))+1)\r\n flag=0\r\nif flag==1:\r\n print (int((d-2*r)//(2*r))+2)",
"from math import ceil\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nd = ((x2-x1)**2 + (y2-y1)**2)**(0.5)\r\nprint(ceil(d/(2*r)))\r\n",
"import math\nr, x1, y1, x2, y2 = map(int, input().split())\n\nd = 2 * r\ndist = math.sqrt((x2-x1)**2 + (y2-y1)**2)\n\nif dist % d == 0:\n print(int(dist / d))\nelse:\n print(int(dist / d) + 1)",
"import math\nr, x1, y1, x2, y2 = map(int, input().split())\ndx = abs(x2 - x1)\ndy = abs(y2 - y1)\nprint(int(math.ceil(math.sqrt(math.pow(dx / (2 * r), 2) + math.pow(dy / (2 * r), 2)))))\n",
"r, x, y, x1, y1 = [int(i) for i in input().split()]\r\nt = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5\r\nd = 2 * r\r\ns = t // d\r\ns = s if t % d == 0 else s + 1\r\nprint(int(s))",
"import math as m\r\nr,x,y,x1,y1=map(int,input().split())\r\na=m.sqrt((x-x1)**2+(y-y1)**2)\r\na/=(2*r)\r\nprint(m.ceil(a))\r\n\r\n",
"from math import sqrt\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\n\r\nd = sqrt((x2 - x1)**2 + (y2 - y1) ** 2)\r\nd = int(d) + 1 if d > int(d) else int(d)\r\n\r\nprint(d // (2 * r) + (1 if d % (2 * r) != 0 else 0))",
"import sys\r\nimport math\r\ninput = sys.stdin.readline\r\n\r\nR, X1, Y1, X2, Y2 = map(int, input().split())\r\nTD = math.sqrt((X2-X1)**2 + (Y2-Y1)**2)\r\nprint(math.ceil(TD/(R*2)))",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nprint(math.ceil(math.sqrt((x-x1)**2+(y-y1)**2)/(2*r)))",
"import math\r\n\r\nlst=input().split()\r\nr=int(lst[0])\r\nx=int(lst[1])\r\ny=int(lst[2])\r\nnewx=int(lst[3])\r\nnewy=int(lst[4])\r\nans=math.ceil(math.sqrt(pow(newx-x,2)+pow(newy-y,2))/(2*r))\r\nprint(ans)",
"r, x0, y0, x, y = map(int, input().split())\r\n\r\nx -= x0\r\ny -= y0\r\n\r\ndist = (x * x + y * y) ** 0.5\r\n\r\nans = int(dist / (2 * r))\r\n\r\nif dist - 2 * r * ans > 0:\r\n ans += 1\r\n\r\nprint(ans)",
"\r\nimport math \r\n\r\n\r\nu,H1,M1,H2,M2=map(int,input().split())\r\n\r\ne=abs(H2-H1)\r\nr=abs(M2-M1)\r\nz=((e*e)+(r*r))**0.5\r\nk=math.ceil(z/(2*u))\r\nprint(k)",
"r,a,b,c,d= map(int,input().split())\r\nfrom math import sqrt\r\nq = sqrt((abs(c-a))**2 + (abs(d-b))**2)\r\nans = q//(2*r)\r\nif q%(2*r):\r\n\tans+=1\r\nprint(int(ans))",
"from math import ceil, hypot\r\nr,x,y,x1,y1=map(float, input().split())\r\nprint(ceil(hypot(x1-x, y1-y)/2/r))",
"import math\r\n\r\nr, x, y, xx, yy = map(int, input().split())\r\n# print(r, x, y, xx, yy)\r\nres = (xx - x) ** 2 + (yy - y) ** 2\r\nres = math.sqrt(res)\r\nres = math.ceil(res / r / 2)\r\nprint(res)",
"import math\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nprint(math.ceil(((x1-x2)**2+(y1-y2)**2)**0.5/(2*r)))",
"import math\r\nr,x,y,a,b=map(int,input().split())\r\nans=math.sqrt(((x-a)*(x-a))+((y-b)*(y-b)))\r\nprint(-int(-ans//(2*r)))",
"import math\r\ndef distance(x1, y1, x2, y2):\r\n return math.sqrt(pow(x1-x2, 2)+pow(y1-y2, 2))\r\n\r\nr, x, y, xd, yd = map(int, input().split())\r\nd = 2*r\r\ndist = distance(x, y, xd, yd)\r\nprint(math.ceil(dist/d))\r\n",
"import math\r\nr, x, y, a, b=[int(k) for k in input().split()]\r\nprint(math.ceil(math.sqrt((a-x)**2+(b-y)**2)/(2*r)))",
"from cmath import sqrt\r\nfrom math import ceil\r\n\r\n\r\nfor _ in range(1):\r\n r, x, y, x1, y1 = map(int, input().split())\r\n x-=x1\r\n y-=y1\r\n m = sqrt(x*x + y*y).real\r\n \r\n print(ceil(m/(2*r)))",
"# /**\r\n# * author: brownfox2k6\r\n# * created: Wed 12 Apr 2023 at 09:47:21 UTC+7, Hanoi, Vietnam\r\n# **/\r\n\r\nfrom math import ceil, sqrt\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\n\r\nd = sqrt((x1-x2)**2 + (y1-y2)**2)\r\nprint(ceil(d / (r*2)))",
"r,x,y,a,b=map(int,input().split())\r\ndis = ((x-a)**2+(y-b)**2)**(0.5)\r\nprint(-int(-dis//(2*r)))",
"from math import *\r\nr,x,y,x1,y1=map(int,input().split())\r\nprint(ceil(hypot((x1-x),(y1-y))/(2*r)))",
"import math\r\nc = []\r\nc = input().split()\r\nr = int(c[0])\r\nx = int(c[1])\r\ny = int(c[2])\r\na = int(c[3])\r\nb = int(c[4])\r\nprint(math.ceil(math.sqrt((x-a)*(x-a)+(y-b)*(y-b))/(2*r)))",
"from collections import *\r\nfrom bisect import *\r\nfrom math import *\r\nfrom heapq import *\r\nfrom fractions import *\r\nimport sys\r\ninput=sys.stdin.readline\r\nt=1\r\ndef r(a):\r\n return ((a*(a-1))//2)\r\nwhile(t):\r\n t-=1\r\n r,x,y,x1,y1=map(int,input().split())\r\n d=pow(abs(x-x1),2)+pow(abs(y-y1),2)\r\n d=pow(d,0.5)\r\n print(ceil(d/(2*r)))\r\n",
"import math\r\nl=list(map(int, input().split()))\r\n \r\ndist = math.sqrt(math.pow(l[4] - l[2], 2) + math.pow(l[3] - l[1], 2))\r\nans = math.ceil(dist / l[0]/ 2)\r\nprint(ans)\r\n",
"import math\nr, x, y, x_, y_ = map(int, input().split())\nprint(math.ceil((math.sqrt((x-x_)**2+(y-y_)**2)-2*r)/(2*r))+1)\n",
"import math\r\nr,x,y,x1,y1 = map(int, input().split())\r\nprint(math.ceil((math.sqrt(((x1-x)**2)+((y1-y)**2)))/(2*r)))",
"import math\r\nr,x,y,a,b=map(int,input().split())\r\nprint(math.ceil((((x-a)**2+(y-b)**2)**0.5)/(2*r)))",
"import math\r\n\r\ndef min_steps(r, x, y, x_dash, y_dash):\r\n distance = math.sqrt((x_dash - x)**2 + (y_dash - y)**2)\r\n steps = math.ceil(distance / (2 * r))\r\n return steps\r\n\r\nr, x, y, x_dash, y_dash = map(int, input().split())\r\n\r\n\r\nprint(min_steps(r, x, y, x_dash, y_dash))\r\n",
"r,x,y,x1,y1=map(int,input().split())\r\n\r\nres=0\r\n\r\ndist2=(x-x1)**2+(y-y1)**2\r\n\r\ndist=0\r\n\r\nwhile dist**2<dist2:\r\n res+=1\r\n dist+=2*r\r\n\r\nprint(res)",
"r,x1,y1,x2,y2=map(int,input().split())\r\nd=((x2-x1)**2+(y2-y1)**2)**0.5\r\nimport math\r\nx=math.ceil(d/(2*r))\r\nprint(x)",
"import math\r\nr,x,y,a,b = map(int,input().split())\r\na = math.sqrt((x-a)**2+(y-b)**2)\r\nprint(math.ceil(a/(2*r)))",
"r,a,b,c,d=list(map(int,input().split()))\r\nx=((c-a)**2 + (d-b)**2)**0.5\r\nr*=2\r\ny=x//r\r\nif x%r!=0:\r\n y+=1\r\nprint(int(y))",
"import sys\r\nfrom math import ceil\r\ninput = sys.stdin.readline\r\nr, x1,y1,x2,y2 = map(int, input().split())\r\nd = ((x1-x2)**2 + (y1-y2)**2)**0.5\r\nans = d\r\nans/=(2*r)\r\nprint(ceil(ans))",
"\r\nfrom math import ceil ; rad,x1,y1,x2,y2=map(int,input().split()) ; x=((x2-x1)**2+(y2-y1)**2)**.5 ; print(ceil(x/(2*rad)))",
"import math\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nd = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5\r\nprint(math.ceil(d / 2 / r))",
"from math import ceil, sqrt\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nd = (lambda x1, y1, x2, y2: sqrt(((x2 - x1) ** 2) + ((y2 - y1) ** 2)))\r\nprint(ceil(d(x1, y1,x2, y2) / (2 * r)))",
"#!/usr/bin/python3\r\nimport math\r\n\r\ndef d(x, y, xx, yy):\r\n return math.sqrt((x - xx) * (x - xx) + (y - yy) * (y - yy))\r\n\r\nr, x, y, xx, yy = map(int, input().split())\r\nprint(math.ceil(d(x, y, xx, yy) / (2 * r)))\r\n",
"from math import sqrt\r\nn,x,y,xi,yi=map(int,input().split())\r\nr=sqrt((xi-x)**2+(y-yi)**2)\r\nr=r/(2*n)\r\nif r==int(r): print(int(r))\r\nelse:print(int(r+1))",
"import math\n\nls = input().split(\" \")\nr = int(ls[0])\nx1 = int(ls[1])\ny1 = int(ls[2])\nx2 = int(ls[3])\ny2 = int(ls[4])\n\nx_abs = abs(x1 - x2)\ny_abs = abs(y1 - y2)\nm = math.sqrt((x_abs * x_abs) + (y_abs * y_abs))\n\nif m == 0:\n print(0)\nelif m <= (2 * r):\n print(1)\nelse:\n print(math.ceil(m / (2 * r)))\n",
"l=lambda:map(int,input().split())\r\nr,x,y,x1,y1=l()\r\nd=((x-x1)**2+(y-y1)**2)**0.5\r\nfrom math import ceil\r\nprint(int(ceil(d/(2*r))))\r\n",
" ###### ### ####### ####### ## # ##### ### ##### \r\n # # # # # # # # # # # # # ### \r\n # # # # # # # # # # # # # ### \r\n ###### ######### # # # # # # ######### # \r\n ###### ######### # # # # # # ######### # \r\n # # # # # # # # # # #### # # # \r\n # # # # # # # ## # # # # # \r\n ###### # # ####### ####### # # ##### # # # # \r\n \r\nfrom __future__ import print_function # for PyPy2\r\nfrom collections import Counter, OrderedDict\r\nfrom itertools import permutations as perm\r\nfrom fractions import Fraction\r\nfrom collections import deque\r\nfrom sys import stdin\r\nfrom bisect import *\r\nfrom heapq import *\r\nimport math\r\n \r\ng = lambda : stdin.readline().strip()\r\ngl = lambda : g().split()\r\ngil = lambda : [int(var) for var in gl()]\r\ngfl = lambda : [float(var) for var in gl()]\r\ngcl = lambda : list(g())\r\ngbs = lambda : [int(var) for var in g()]\r\nmod = int(1e9)+7\r\ninf = float(\"inf\")\r\n \r\nr, x, y, p, q = gil()\r\nr *= 2\r\nd = (p-x)**2 + (q-y)**2\r\nd = math.sqrt(d)\r\n# print(d)\r\nprint(math.ceil(d/r))",
"import math\nr, x, y, x1, y1 = [int(i) for i in input().split()]\nd = ((x1-x)**2 + (y1-y)**2)**0.5\nd = math.ceil(d/(2*r))\nprint(d)\n",
"import math\n\nr, x,y, x_p, y_p = map(int, input().split())\n\nlength = math.sqrt((x_p-x)**2+(y_p-y)**2)\n\nprint(math.ceil(length / (r*2)))",
"import math\r\nr, x, y,x1, y1=map(int,input().split())\r\nz=(math.sqrt(pow(x-x1,2)+pow(y-y1,2)))\r\nprint(int(math.ceil(z/(2*r))))",
"import math\r\nr,x,y,x_,y_=map(int,input().split())\r\nstep=0\r\ndist=math.sqrt((x-x_)**2 + (y-y_)**2)\r\nwhile(dist>=2*r):\r\n dist=dist-2*r\r\n step=step+1\r\nif dist>0 and dist<2*r:\r\n step=step+1\r\nprint(step)",
"import math\r\nx,a,b,c,d=map(int,input().split())\r\ne=math.sqrt((d-b)**2+(c-a)**2)\r\nprint(math.ceil(e/(2*x)))",
"from math import sqrt\r\nl=list(map(int,input().split()))\r\nr,x,y,xn,yn=l[0],l[1],l[2],l[3],l[4]\r\nd=sqrt((x-xn)**2 + (y-yn)**2)\r\n\r\nif d%(2*r)==0:\r\n print(int(d/(2*r)))\r\nelse:\r\n print(int((d//(2*r))+1))\r\n\r\n",
"from math import sqrt, ceil\n\nr, x, y, xx, yy = map(int, input().split())\n\nd = sqrt((x-xx)**2 + (y-yy)**2)\n\nres = ceil(d/(2*r))\n\nprint(res)\n",
"from math import floor,ceil,sqrt\n\ndef distance(p1, p2):\n return sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)\n\nr,x,y,a,b = list(map(int,input().split()))\n\nr *= 2\n\nprint(ceil(distance((x,y),(a,b)) / r))\n",
"import math\ndef main(args):\n\tt = input()\n\tvals = t.split(' ')\n\tfor i in range(5):\n\t\tvals[i] = int(vals[i])\n\tr = vals[0]\n\tx = vals[1]\n\ty = vals[2]\n\tx1 = vals[3]\n\ty1 = vals[4]\n\tdist = math.sqrt((x-x1)**2+(y-y1)**2)\n\tif(dist%(2*r)==0):\n\t\tprint(int(dist//(2*r)))\n\telse:\n\t\tprint(int(dist//(2*r)) + 1)\nif __name__ == '__main__':\n import sys\n sys.exit(main(sys.argv))",
"import math\r\nr, x, y, nx, ny = map(int,input().split())\r\nstep = 2*r\r\nd = math.sqrt((nx-x)**2 + (ny-y)**2)\r\nif (d//step)*step < d :\r\n print(int(d//step)+1)\r\nelse :\r\n print(int(d//step))",
"from math import *\r\nr,x,y,a,b,=map(int,input().split())\r\nd=sqrt(pow(x-a,2)+pow(y-b,2))\r\nans=(d/(2*r))\r\nif ans!=int(ans):\r\n ans=ceil(ans)\r\nprint(int(ans))",
"from math import *\r\nl=[int(x) for x in input().split()]\r\nr,x,y,x1,y1=l[0],l[1],l[2],l[3],l[4]\r\nz=sqrt(((x-x1)**2)+((y-y1)**2))\r\na=2*r\r\nif z%a==0:\r\n print(int(z//a))\r\nelse:\r\n print(1+int(z//a))\r\n",
"r,x,y,x1,y1=map(int,input().split())\r\nimport math\r\nd=math.sqrt(((x1-x)**2)+((y1-y)**2))\r\nresult=math.ceil(d/(2*r))\r\nprint(result)",
"import math\r\n\r\ninp=list(map(int,input().split()))\r\nr=inp[0]\r\nx=inp[1]\r\ny=inp[2]\r\nxt=inp[3]\r\nyt=inp[4]\r\n\r\nsteps=math.ceil(math.sqrt((x-xt)*(x-xt)+(y-yt)*(y-yt))/(2*r))\r\n\r\nprint(steps)",
"r,x,y,x1,y1=map(int,input().split())\r\nr*=2\r\ndr=((x-x1)**2+(y-y1)**2)**0.5\r\n\r\nif dr%1>0:\r\n dr=int(dr)+1\r\nelse:\r\n dr=int(dr)\r\nif dr%r==0:\r\n ans=dr//r\r\nelse:\r\n ans=dr//r+1\r\nprint(ans)\r\n",
"import math\nr,x,y,X,Y=map(int,input().split())\nsize=((X-x)**2+(Y-y)**2)**.5\nprint(math.ceil(size/(2*r)))\n \t\t\t \t \t\t\t\t \t \t\t\t \t\t\t\t \t\t \t\t",
"import random\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n\r\ndef gcd(a, b):\r\n if a == 0:\r\n return b\r\n return gcd(b % a, a)\r\n\r\n\r\ndef lcm(a, b):\r\n return (a * b) / gcd(a, b)\r\n\r\nr,x,y,x1,y1=map(int, input().split())\r\nd=((x1-x)**2+(y1-y)**2)**(0.5)\r\nif d%(2*r)==0:\r\n print(int(d//(2*r)))\r\nelse:\r\n print(int(d//(2*r)+1))\r\n",
"import math\n\nr, x, y, xp, yp = map(int, input().split())\ndis2 = (x-xp)*(x-xp) + (y-yp)*(y-yp)\ndis = math.sqrt(dis2)\nnb = int(dis/(2*r))\nif (dis - (nb*2*r)) > 0:\n nb += 1\nprint(nb)\n\t \t\t\t \t\t \t \t\t \t\t \t\t \t \t",
"import sys\r\n\r\n###########\r\n\r\n\r\ndef solve():\r\n input = sys.stdin.readline\r\n r, x, y, x1, y1 = map(int, input().split())\r\n d = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5\r\n print(int(d / (2 * r) + 1 if d % (2 * r) else d / (2 * r)))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n########################################################################################################################\r\ndef main():\r\n t = 1#int(input())\r\n for _ in range(t):\r\n solve()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"r,x,y,fx,fy = [int(x) for x in input().split()]\r\ndist = ((x-fx)**2 + (y-fy)**2)**0.5\r\nimport math\r\nprint(math.ceil(dist/(2*r)))\r\n",
"import sys\n\ndef ceil(x, y):\n if x % y == 0:\n return x // y\n else:\n return x // y + 1\n\nr, x1, y1, x2, y2 = [int(i) for i in input().split()]\nd = ((x1 - x2) ** 2 + abs(y1 - y2) ** 2) ** 0.5\nprint(int(ceil(d, (2 * r))))\n",
"import math\r\nx = [int(x) for x in input().split()]\r\n\r\na = math.ceil(math.sqrt((x[1] - x[3]) * (x[1] - x[3]) + (x[2] - x[4]) * (x[2] - x[4])) / (x[0] + x[0]))\r\n\r\nprint(a)",
"import math\nr, x, y , x2, y2 = input().split()\nr = int(r)\nx = float(x)\ny = float(y)\nx2 = float(x2)\ny2 = float(y2)\n\ndist = math.sqrt(pow((x - x2), 2) + pow((y - y2), 2));\n\nresp = int(dist / (2 * r));\ncomp = resp * r * 2\nif comp != dist:\n resp +=1\n \n\nprint(resp)\n\t\t\t\t \t\t \t\t\t \t\t\t \t \t\t\t\t\t\t",
"from math import sqrt, ceil\nparams = list(map(int,list(input().split())))\nr, x1, y1, x2, y2 = params[0], params[1], params[2], params[3], params[4]\n\ndelta = sqrt((abs(x1 - x2)**2 + abs(y1-y2)**2))\n\nprint(ceil(delta / (2*r)))\n\t \t \t \t\t\t\t \t \t \t \t \t\t \t \t\t\t\t",
"from sys import stdin; inp = stdin.readline\r\ndef IA(): return list(map(int, inp().split()))\r\ndef FA(): return list(map(float, inp().split()))\r\ndef SA(): return inp().split()\r\ndef I(): return int(inp())\r\ndef F(): return float(inp())\r\ndef S(): return inp()\r\nfrom math import dist, ceil\r\n\r\ndef main():\r\n r, x, y, dx, dy = IA() \r\n d = dist((x,y), (dx, dy))\r\n return ceil(d / (r*2))\r\n # return int(d // (r*2))\r\n\r\nif __name__ == '__main__':\r\n print(main())",
"from math import ceil,sqrt\r\nr,x1,y1,x2,y2 = [int(i) for i in input().split()]\r\nd = sqrt((x1-x2)**2+(y1-y2)**2)\r\nprint(ceil(d/2/r))",
"import math\r\nimport copy\r\nimport itertools\r\nimport bisect\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef ilst():\r\n return list(map(int,input().split()))\r\n\r\ndef inum():\r\n return map(int,input().split())\r\n \r\n\r\nr,x,y,xd,yd = inum()\r\n\r\ndist = math.sqrt((yd-y)**2+(xd-x)**2)\r\n\r\nans = dist//(2*r)\r\n\r\nif dist%(2*r) != 0:\r\n ans += 1\r\nprint(int(ans))",
"from math import sqrt\r\n\r\nr,x,y,nx,ny=[int(element) for element in input().split(\" \")]\r\n\r\ndistance=sqrt((x-nx)**2+(y-ny)**2)\r\n\r\nanswer=distance//(2*r)\r\n\r\nif distance%(2*r)!=0:\r\n answer+=1\r\n\r\nprint(int(answer))",
"import math\r\nr, x, y, x1, y1 = map(int, input().split())\r\nd = ((x-x1 )**2 + (y-y1 )**2) ** (1/2)\r\nprint(math.ceil(d/(2*r)))",
"import sys\r\nimport math\r\nfrom collections import Counter\r\nfrom collections import OrderedDict\r\nfrom collections import defaultdict\r\nfrom functools import reduce\r\nsys.setrecursionlimit(10**6)\r\ndef inputt():\r\n return sys.stdin.readline().strip()\r\ndef printt(n):\r\n sys.stdout.write(str(n)+'\\n')\r\ndef listt():\r\n return [int(i) for i in inputt().split()]\r\n \r\ndef gcd(a,b): \r\n return math.gcd(a,b) \r\n \r\ndef lcm(a,b): \r\n return (a*b) // gcd(a,b) \r\n\r\ndef factors(n):\r\n step = 2 if n%2 else 1\r\n return set(reduce(list.__add__,([i, n//i] for i in range(1, int(math.sqrt(n))+1, step) if n % i == 0)))\r\n\r\ndef comb(n,k):\r\n factn=math.factorial(n)\r\n factk=math.factorial(k)\r\n fact=math.factorial(n-k)\r\n ans=factn//(factk*fact)\r\n return ans\r\n\r\ndef is_prime(n): \r\n if n <= 1: \r\n return False\r\n if n == 2: \r\n return True\r\n if n > 2 and n % 2 == 0: \r\n return False\r\n\r\n max_div = math.floor(math.sqrt(n)) \r\n for i in range(3, 1 + max_div, 2): \r\n if n % i == 0: \r\n return False\r\n return True\r\ndef maxpower(n,x):\r\n B_max = int(math.log(n, x)) + 1#tells upto what power of x n is less than it like 1024->5^4\r\n return B_max\r\n\r\nr,x1,y1,x2,y2=map(int,inputt().split())\r\nd=0\r\nd=(x2-x1)**2+(y2-y1)**2\r\nd=d**(0.5)\r\nprint(math.ceil(d/(2*r)))",
"import math\r\ndef distance(x1,y1,x2,y2):\r\n d=math.sqrt((x2-x1)**2 + (y2-y1)**2)\r\n return d\r\n\r\n\r\nr,x1,y1,x2,y2=map(int,input().split())\r\ns=math.ceil(distance(x1,y1,x2,y2)/(2*r))\r\nprint(s)",
"import math \r\nr , x,y ,a ,b = map (int, input().split(' ')) \r\nd = math.sqrt(pow(abs(x-a) , 2) + pow(abs(y-b),2) )\r\nprint (math.ceil (d/(r*2)))\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nd=2*r\r\ndistance=((x1-x)**2)+((y1-y)**2)\r\ndistance=math.ceil(math.sqrt(distance))\r\nans=math.ceil(distance/d)\r\nprint(ans)",
"from math import sqrt, ceil\n\ns = input().split(\" \")\ns = map(int, s)\ns = list(s)\n\nr = s[0]\nx = s[1]\ny = s[2]\nx1 = s[3]\ny1 = s[4]\n\ndel s\n\ndist = sqrt((x-x1)**2 + (y-y1)**2)\nd = 2*r\n\nresp = ceil(dist/d)\nprint(resp)\n",
"from math import *\r\na,b,c,d,e=map(int,input().split())\r\nprint(ceil(sqrt(pow(d-b,2)+pow(e-c,2))/(2*a)))",
"import math\r\n\r\na, b, c,d,e = ([int(x) for x in input().split()])\r\nx=b-d\r\ny=c-e\r\nk=x*x+y*y\r\nq=math.sqrt(k)\r\nprint(math.ceil(q/(2*a)))\r\n",
"import math\r\nr, x, y, x1, y1 = map(int,input().split())\r\nd = math.ceil(math.hypot(x-x1, y-y1))\r\nprint (int(math.ceil(d/(2*r))))\r\n",
"from math import *\r\nr,x,y,a,b,=map(int,input().split())\r\nd=sqrt(pow(x-a,2)+pow(y-b,2))\r\nans=ceil(d/(2*r))\r\nprint(int(ans))",
"import math\r\nr, a, b, c, d = map(int, input().split())\r\nz = math.sqrt((a - c)**2 + (b - d)**2)\r\nr2 = 2 * r\r\nx = math.ceil(z / r2)\r\ny = 0 if (z - x * r2) <= 1e-6 else 1\r\nprint(x + y)\r\n",
"import math\r\nr,x1,y1,x2,y2=map(int,input().split())\r\ndis=((x1-x2)**2+(y1-y2)**2)\r\nd=math.sqrt(dis)\r\nres=d/(r*2)\r\nprint(math.ceil(res))",
"from math import *\nr,x,y,xt,yt = [int(i) for i in input().split(' ')]\nans = ((x-xt)**2+(y-yt)**2)**0.5/(2*r)\nprint(ceil(ans))",
"r,x,y,x1,y1 = map(int,input().split())\r\nr*=2\r\nd = (x-x1)*(x-x1) + (y-y1)*(y-y1)\r\nd = (d)**(1/2)\r\nprint(int(d//r)+(1 if d%r else 0))",
"import math\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\n\r\nlength = math.ceil(math.sqrt( (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1) ))\r\n\r\nprint(math.ceil(length / (r*2)))",
"\r\ndef fun(ls):\r\n radius, x1, y1, x2, y2 = ls\r\n dsq = (((x1 - x2)**2) + ((y1 - y2)**2))\r\n if x1 == x2 and y2 == y1:\r\n print(0)\r\n return\r\n \r\n # starting from first time it can shift its center to 2r distance in one move\r\n rd = 2 * radius\r\n for i in range(1, 1000000):\r\n val = rd\r\n if val*val >=dsq:\r\n print(i)\r\n break\r\n rd += ( 2* radius )\r\n\r\n\r\n\r\n\r\nT = 1\r\nfor i in range(T):\r\n ls= list(map(int, input().split()))\r\n fun(ls)",
"import math\r\ndef pins(r,a,b,c,d):\r\n dist= ((c-a)**2 + (d-b)**2)**0.5\r\n return math.ceil(dist/2/r)\r\n \r\n \r\n \r\n(r,a,b,c,d)=map(int, input().split())\r\n \r\nresult= pins(r,a,b,c,d)\r\nprint(result)",
"import math\r\nr,x,y,x1,y1 = map(int, input().split())\r\nd = pow(pow(x-x1,2)+pow(y-y1,2), 1/2)\r\nmoves = math.ceil(d/(2*r))\r\nprint(moves)\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nd=((x-x1)**2+(y-y1)**2)**0.5\r\nprint(math.ceil(d/(2*r)))",
"from math import sqrt, ceil\r\n\r\n\r\ndef euclidean(x1, x2, y1, y2):\r\n return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\r\n\r\n\r\nr, x, y, x1, y1 = map(int, input().split())\r\nd = euclidean(x, x1, y, y1)\r\nprint(ceil(d / (2 * r)))\r\n",
"n=list(map(int,input().split(\" \")))\r\nrad=n[0]\r\nsqdis=(n[1]-n[3])**2+(n[2]-n[4])**2\r\ntr=(sqdis**0.5)\r\nk=tr/rad\r\nv=int(k//2)\r\nif k%2==0:\r\n print(v)\r\nelse:\r\n print(v+1)\r\n",
"r, x, y, x_, y_ = map(int, input().split())\r\nfrom math import ceil\r\ndistance = ((x - x_) ** 2 + (y - y_) ** 2) ** 0.5\r\ndistance = distance / (2 * r)\r\nprint(ceil(distance))",
"import sys\r\nimport math\r\ndef cd(x1,y1,x2,y2):\r\n d = math.sqrt((x1-x2)**2 +(y1-y2)**2)\r\n return d\r\n \r\ndef fn(r,x1,y1,x2,y2):\r\n d = 2*r\r\n if (x1==x2) and (y1==y2):\r\n return 0\r\n a = cd(x1,y1,x2,y2)\r\n b = int(a)\r\n if b%d == 0 and a==b:\r\n return int(a/d)\r\n return int(a/d)+1 \r\n \r\nif __name__ == '__main__': \r\n input = sys.stdin.read()\r\n data = list(map(int, input.split()))\r\n r = data[0]\r\n x1 = data[1]\r\n y1 = data[2]\r\n x2 = data[3]\r\n y2 = data[4]\r\n print(fn(r,x1,y1,x2,y2))",
"from sys import stdin, stdout\r\ndef rdl(x): return map(x, stdin.readline().strip().split())\r\ndef wtl(x): stdout.write(str(x) + '\\n')\r\nimport math\r\n\r\nr, x, y, xx, yy = rdl(int)\r\nwtl(math.ceil(math.sqrt((((x - xx) ** 2 + (y - yy) ** 2))) / (2.0 * r)))",
"import math as mt \nimport sys,string,bisect\ninput=sys.stdin.readline\nfrom collections import deque,defaultdict\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : map(int,input().split())\nI=lambda :int(input())\ndef dist(x,y,c,d):\n return mt.sqrt((x-c)**2+(y-d)**2)\ndef circle(x1, y1, x2,y2, r1, r2): \n \n distSq = (((x1 - x2)* (x1 - x2))+ ((y1 - y2)* (y1 - y2)))**(.5) \n \n if (distSq + r2 <= r1): \n return True\n else: \n return False\nr,a,b,x,y=M()\nprint(mt.ceil(dist(a,b,x,y)/(2*r)))\n",
"r,a,b,x,y=map(int, input().split())\r\nd= (((a-x)**2)+((b-y)**2))**0.5\r\nans=d/(2*r)\r\nif ans%1==0:\r\n print(int(ans))\r\nelse:\r\n print(int(ans)+1)",
"\r\nfrom math import ceil, inf, sqrt\r\nimport sys\r\n\r\ndef pro(x,y,p,q,r):\r\n if((x,y)==(p,q)):\r\n print(0)\r\n return\r\n dist=(x-p)**2 + (y-q)**2\r\n dist=sqrt(dist)\r\n # each step cirle moves by 2r ---r**2\r\n\r\n ans= ceil( dist/(2*r))\r\n print(ans)\r\n\r\n\r\nt=1\r\nfor i in range(t):\r\n r,x,y,p,q=list(map(int,input().split()))\r\n \r\n pro(x,y,p,q,r)",
"l=input().split()\r\n\r\nd=( (abs(int(l[1])-int(l[3])) )**2+(abs(int(l[2])-int(l[4])))**2)**(1/2)\r\n\r\nimport math\r\nn=math.ceil(d/(2*int(l[0])))\r\nprint(n)\r\n\r\n",
"import math\r\n\r\nr, x0, y0, x1, y1 = [int(i) for i in input().split()]\r\nrast = math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2)\r\nprint(math.ceil(rast / (2 * r)))",
"r,x1,y1,x2,y2=map(int,input().split())\r\n\r\nimport math as m\r\n\r\nras=m.sqrt((abs(x1-x2)**2)+(abs(y2-y1)**2))\r\n\r\n\r\n\r\nk=ras/(r*2)\r\n\r\nprint(m.ceil(k))",
"import math\r\n\r\nr, x1, y1, x2, y2 = [int(x) for x in input().split(\" \")]\r\n\r\ndx = x2 - x1\r\ndy = y2 - y1\r\ndis = math.sqrt(dx*dx + dy*dy)\r\n\r\nif dis == 0:\r\n print(0)\r\nelif dis < 1:\r\n print(2)\r\nelse:\r\n print(math.ceil(dis/(2*r)))",
"import math\nr, x, y, x1, y1 = list(map(int, input().rstrip().split()))\ndist = math.sqrt(math.pow(x1 - x, 2) + math.pow(y1 - y, 2))\nq = dist // (2 * r)\nrem = dist % (2 * r)\ncount = q\nif rem > 0:\n count += 1\nprint(int(count))",
"import math\r\nr, x1, y1, x2, y2= list(map(int,input().split()))\r\nd= ((x2 - x1) ** 2)+((y2 - y1)** 2)\r\nd= math.sqrt(d)\r\nprint(math.ceil(d /(2 * r)))",
"import math\nr, x1, y1, x2, y2 = map(int, input().split())\nd = math.sqrt(((x2-x1)**2)+((y2-y1)**2))\nx = (d/r)\ny = math.ceil(x/2)\nprint(y)",
"r,x1,y1,x2,y2=map(int,input().split())\r\nd=2*r\r\nr1=(((x2-x1)**2)+((y2-y1)**2))**0.5\r\nif(r1%d==0):\r\n print(int(r1//d))\r\nelse:\r\n print(int(r1//d)+1)",
"import math\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n#for _ in range (int(input())):\r\nr,x,y,x1,y1 = [int(i) for i in input().split()]\r\ndis = math.sqrt(((x1-x)**2)+((y1-y)**2))\r\nprint(math.ceil(dis/(2*r)))",
"r,x,y,s,t = map(int,input().split())\n\ndist = ((x-s)**2 + (y-t)**2)**.5\n\nres = 0\nwhile dist > 0:\n res += 1\n dist -= 2*r\n\nprint(res)\n\n",
"from math import ceil, sqrt\nr, x0, y0, x1, y1 = list(map(int, input().split()))\nd = sqrt((x1-x0)**2 + (y1-y0)**2)\n\nres = ceil(d/(2*r))\nprint(res)\n",
"\r\ndef fun(ls):\r\n radius, x1, y1, x2, y2 = ls\r\n dsq = (((x1 - x2)**2) + ((y1 - y2)**2))\r\n if x1 == x2 and y2 == y1:\r\n print(0)\r\n return\r\n \r\n # linear approach ( working )\r\n # rd = 2 * radius\r\n # for i in range(1, 1000000):\r\n # val = rd\r\n # if val*val >=dsq:\r\n # print(i)\r\n # break\r\n # rd += ( 2* radius )\r\n \r\n # binary seach approach ( working )\r\n start = 1\r\n end = 1000000\r\n ans = -1\r\n while(start <= end):\r\n mid = (start + end ) //2\r\n mid_val = ((mid*2*radius)**2)\r\n\r\n if mid_val >= dsq:\r\n end = mid - 1\r\n ans = mid\r\n else:\r\n start = mid + 1\r\n print(ans)\r\n\r\n\r\nT = 1\r\nfor i in range(T):\r\n ls= list(map(int, input().split()))\r\n fun(ls)",
"import math\r\n\r\nr, x0, y0, x1, y1 = map(int, input().split())\r\nprint(int(math.ceil(math.sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2) / (2 * r))))",
"from math import *\r\na = input()\r\na = a.split(\" \")\r\n\r\nfor i in range(len(a)):\r\n a[i] = int(a[i])\r\n\r\nb = abs(a[3] - a[1])\r\nc = abs(a[4] - a[2])\r\nd = 2*a[0]\r\ne = 0\r\nif b == 0 and c == 0:\r\n print(0)\r\nelse:\r\n e = b**2 + c**2\r\n e = sqrt(e)\r\n print(ceil(e/d))",
"from math import *\r\nr,x,y,nx,ny=list(map(int,input().split(\" \")))\r\n\r\nr*=2\r\ndiff=(x-nx)*(x-nx)+(y-ny)*(y-ny)\r\ndiff=sqrt(diff)\r\nprint(ceil(diff/r))",
"from math import hypot, ceil\r\n\r\nif __name__ == '__main__':\r\n r, x, y, x1, y1 = map(int, input().split(\" \"))\r\n c_x, c_y = abs(x-x1), abs(y-y1)\r\n c = ceil(hypot(c_x, c_y) / (2*r))\r\n print(c)\r\n",
"import math\n#n, m = input().split()\n#n = int (n)\n#m = int (m)\n#k = int (k)\n#s = input()\n#n = int(input())\n\na = list(map(int, input().split()))\n#b = list(map(int, input().split()))\n\n#x1, y1, x2, y2 =map(int,input().split())\n#n = int(input())\n#f = []\n#f = [0]*n\n#t = [0]*n\n#f = []\n \n#h = [\"\"] * n\n#f1 = sorted(f, key = lambda tup: tup[0])\n\n#f1 = sorted(t, key = lambda tup: tup[0])\nif (a[1] == a[3] and a[2] == a[4]):\n print(0)\nelse:\n if (math.sqrt((a[1]-a[3])*(a[1]-a[3])+ (a[2]-a[4])*(a[2]-a[4]))% (2*a[0]) == 0):\n s = math.sqrt(((a[1]-a[3])*(a[1]-a[3])+ (a[2]-a[4])*(a[2]-a[4]))) / (2*a[0])\n else:\n s =math.sqrt((a[1]-a[3])*(a[1]-a[3])+ (a[2]-a[4])*(a[2]-a[4]))/ (2*a[0])+1\n \n \n print(int(s))\n\n",
"import math\r\n\r\ndef minimum_steps(r, x, y, x_, y_):\r\n distance = math.sqrt((x - x_)**2 + (y - y_)**2) # distance between current and destination positions\r\n steps = math.ceil(distance / (2 * r)) # minimum number of steps required\r\n return steps\r\n\r\n# read input from the user\r\nr, x, y, x_, y_ = map(int, input().split())\r\n\r\n# print the minimum number of steps required\r\nprint(minimum_steps(r, x, y, x_, y_))\r\n",
"from math import ceil, sqrt\r\n\r\nr, x1, y1, x2, y2 = [int(i) for i in input().split()]\r\n\r\ndis = sqrt(x1*x1 + x2*x2 +y1*y1 + y2*y2 - 2*x1*x2 - 2*y1*y2)\r\n# print(dis)\r\nprint(int(ceil(dis/(2*r))))",
"import math\r\n\r\n\r\n\r\ntxt = input()\r\nr,x1,y1,x2,y2 = list(map(int,txt.split(\" \")))\r\ndistance = math.ceil(math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)))\r\nturn = math.ceil(distance/(2*r))\r\nprint(turn)\r\n\r\n",
"a,x,y,p,q=map(int,input().split())\r\nd=((x-p)**2+(y-q)**2)**0.5\r\nans=d//(2*a)\r\nif(d%(2*a)!=0): ans+=1\r\nprint(int(ans))\r\n ",
"import math\r\n\r\ndef solve(r, x0, y0, x1, y1):\r\n d = math.sqrt((x0-x1) ** 2 + (y0-y1) ** 2)\r\n\r\n return math.ceil(d/(2*r))\r\n\r\n\r\n\r\nr, x0,y0,x1,y1 = list(map(int, input().split(\" \")))\r\n\r\nprint(solve(r, x0, y0, x1,y1))\r\n",
"import math\r\nr,x,y,xx,yy=map(int,input().split(\" \"))\r\nf=math.sqrt((xx-x)**2+(yy-y)**2)\r\n\r\nif (x==xx and y==yy):\r\n print(0)\r\n\r\nelse:\r\n c=(f)/(r*2)\r\n print(math.ceil(c))",
"import math\r\nr, x1, y1, x2, y2 = [int(x) for x in input().split()]\r\n\r\ndistance = math.sqrt((y2-y1)**2 + (x2-x1)**2)\r\nprint(math.ceil(distance/(2*r)))\r\n",
"from math import sqrt\r\ndef dist(a,b,c,d):\r\n return sqrt(pow((a-b),2) + pow((c-d),2))\r\nr,x,y,x1,y1 = list(map(int,input().split()))\r\n\r\na = dist(x,x1,y,y1)\r\nd = 2*r\r\nif a%d == 0:\r\n print(int(a//d))\r\nelse:\r\n print(int(a//d + 1))",
"import math\n\ndef cordis(a1,b1,a2,b2,r):\n asq = (a2 - a1)**2\n bsq = (b2 -b1)**2\n return (math.sqrt(asq + bsq) - 2*r)\n \ninplt = list(map(int , input().split()))\nr , x1 , y1 , x2 , y2 = [i for i in inplt]\n\nif (x1 == x2) and (y1 == y2):\n print(0)\nelse:\n dip = cordis(x1,y1,x2,y2,r)\n if dip <= 0:\n print(1)\n else:\n stp = math.ceil(dip/(2*r))\n print(stp+1)",
"import math\r\ndef dist(x1,y1,x2,y2):\r\n a = (x1-x2)**2\r\n b = (y1-y2)**2\r\n c = math.sqrt(a+b)\r\n return(c)\r\n\r\nr,x,y,x2,y2 = map(int,input().split())\r\ndistance = dist(x,y,x2,y2)\r\nprint(math.ceil(distance/(2*r)))",
"import math\r\nr,x,y,x1,y1= map(int, input().split())\r\n\r\nif x==x1 and y==y1:\r\n print(0)\r\n quit()\r\n\r\ndistance= math.sqrt((x-x1)**2+ (y-y1)**2)\r\n\r\nprint(math.ceil(distance/(2*r)))",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nd=math.sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1))\r\ns=math.ceil(d/(2*r))\r\nprint(s)",
"import math\r\ndef distance(x1,y1,x2,y2):\r\n return math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))\r\narray=list(map(int, input().rstrip().split()))\r\ndiameter=array[0]*2\r\nx1=array[1]\r\ny1=array[2]\r\nx2=array[3]\r\ny2=array[4]\r\ndist=distance(x1,y1,x2,y2)\r\nif dist%diameter==0:\r\n print(int((dist//diameter)))\r\nelse:\r\n print(int((dist//diameter)+1))",
"import math\r\nr, x, y, x1, y1 = map(int, input().split(' '))\r\n\r\nd = math.sqrt((x1 - x)*(x1-x) + (y1 - y)*(y1-y))\r\n#print(d)\r\nif d%(2*r) == 0: print(int(d/(2*r)))\r\nelse: print(int(d/(2*r)) + 1)",
"import math\r\ns=input().split()\r\ns=[int(x) for x in s]\r\ndistance=math.sqrt(((s[1]-s[3])**2)+((s[2]-s[4])**2))\r\nx=distance/(2*s[0])\r\nif int(x)==x:\r\n\tprint(int(x))\r\nelse:\r\n\tprint(int(x)+1)",
"# cook your dish here\r\nimport math\r\n\r\nr,x1,y1,x2,y2=map(int,input().split())\r\n\r\nd=((x1-x2)**2+(y1-y2)**2)**0.5\r\n\r\nd=math.ceil((d)/(2*r))\r\n\r\nprint(int(d))\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\na = math.sqrt((x1-x)**2+(y1-y)**2)\r\nb = math.ceil(a/(r*2))\r\nprint(b)",
"import math\r\nr,x,y,x1,y1 = map(int,input().split())\r\nst = math.sqrt((x-x1)**2 + (y-y1)**2)\r\nprint(math.ceil(st/(2*r)))\r\n",
"import math\r\nr,x1,y1,x2,y2 = list(map(int,input().split()))\r\n\r\nz = math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))\r\nd = math.ceil(z/(2*r))\r\nprint(d)",
"import math\r\nr,x1,y1,x2,y2=map(int,input().rstrip().split())\r\nr*=2\r\nxx=(x1,y1);yy=(x2,y2)\r\neuc=math.dist(xx,yy)\r\nif euc==0:print(0)\r\nelse:\r\n print(math.ceil(euc/r))\r\n",
"import math\n\nr, x1, y1, x2, y2 = map(int, input().split(' '))\n\nd = ((x2-x1)**2 + (y2-y1)**2)**(1/2)\n\nans = math.ceil(d/(r*2))\n\nprint(int(ans))\n",
"import math\r\nr,x,y,xr,yr=list(map(int,input().split()))\r\nd=math.sqrt((xr-x)**2 + (y-yr)**2)\r\nn=math.ceil(d/(2*r))\r\nprint(int(n))",
"r,x,y,x1,y1=map(int,input().split())\r\nd=((y1-y)**2+(x1-x)**2)**0.5\r\nif d%(2*r)==0:\r\n print(int(d//(2*r)))\r\nelse: \r\n print(int(d//(2*r))+1)",
"r, x1, y1, x2, y2 = map(int, input().split())\r\n\r\nr *= 2\r\nd = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5\r\n\r\nprint(int(d // r) if d % r == 0 else int(d // r + 1))\r\n",
"r,a,b,x,y=map(int,input().split())\r\ndist=(x-a)**2+(y-b)**2\r\nr=4*r**2\r\ndist=(dist+r-1)//r\r\ni=0\r\nwhile i**2<dist:\r\n i+=1\r\nprint(i)",
"import math\r\nr,a,b,c,d=map(int,input().split())\r\nx=math.sqrt((a-c)**2 + (b-d)**2)\r\nprint(math.ceil(x/(2*r)))",
"from math import ceil\r\ndef dist(a,b,c,d):\r\n return ((a-c)**2 + (b-d)**2 )**0.5\r\nr,x1,y1,x2,y2 = map(int, input().split())\r\nprint(ceil(dist(x1,y1,x2,y2)/(2*r)))",
"import math\nr,x,y,x1,y1=map(int,input().split())\nprint(math.ceil(math.sqrt((x-x1)**2+(y-y1)**2)/(2*r)))\n \t \t \t \t\t \t \t\t \t \t \t \t \t",
"import sys\r\nimport math\r\nimport bisect\r\n\r\ndef main():\r\n r, x1, y1, x2, y2 = map(int, input().split())\r\n dist = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\r\n print(math.ceil(dist / (2*r)))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"import math\r\nimport bisect\r\n\r\ndef main():\r\n r, x1, y1, x2, y2 = (map(int, input().split()))\r\n\r\n get_distance = lambda x1,y1,x2,y2: math.sqrt((x1-x2)**2 + (y1-y2)**2)\r\n d = get_distance(x1, y1, x2, y2)\r\n\r\n print(math.ceil(d/(2*r)))\r\n \r\n return\r\n\r\nmain()",
"import math \r\nr,a,b,c,d=map(int,input().split())\r\nprint(math.ceil(((a-c)**2 +(b-d)**2)**(0.5)/(2*r)))",
"r, x, y, x2, y2 = [int(x) for x in input().split(' ')]\ndist = ((x2-x)**2 + (y2-y)**2)**0.5\n\nif dist==0:\n\tprint(0)\nelif dist<=2*r:\n\tprint(1)\nelse:\n\td_steps = int(dist/(2*r))\n\tsteps = d_steps if dist%(2*r)==0 else d_steps+1\n\tprint(steps)",
"from math import ceil\nr, x, y, x1, y1 = map(int, input().split())\nprint(ceil((((x - x1) ** 2 + (y - y1) ** 2) ** 0.5) / (2 * r)))",
"import math\r\n\r\nr, x, y, _x, _y = map(int, input().split())\r\n\r\ndef dist(x, y, _x, _y):\r\n\treturn math.sqrt((x - _x) ** 2 + (y - _y) ** 2)\r\n\r\nans = dist(x, y, _x, _y) // (2 * r)\r\n\r\nans += (1 if dist(x, y, _x, _y) % (2 * r) != 0 else 0)\r\n\r\nprint(int(ans))",
"import atexit\r\nimport io\r\nimport sys\r\nimport math as m\r\n\r\n# _INPUT_LINES = sys.stdin.read().splitlines()\r\n# input = iter(_INPUT_LINES).__next__\r\n# _OUTPUT_BUFFER = io.StringIO()\r\n# sys.stdout = _OUTPUT_BUFFER\r\n#\r\n#\r\n# @atexit.register\r\n# def write():\r\n# sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())\r\n\r\nR = lambda : map(int,input().split())\r\nr,x,y,x1,y1 = R()\r\n\r\nans = m.ceil((m.sqrt((x-x1)**2+(y-y1)**2))/(2*r))\r\nprint(ans)\r\n",
"from math import *\r\n\r\nr, x, y, x2, y2 = map(int, input().split())\r\nd = 2 * r\r\n\r\ns = sqrt((x - x2)**2 + (y - y2)**2)\r\n\r\nprint(int(s / d) + (s - int(s / d) * d > 0))",
"import math\n\nr, x1, y1, x2, y2 = map(int, input().split())\nprint((math.ceil(math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))) + 2*r - 1) // (2 * r))\n\t \t\t \t\t\t\t \t \t\t \t \t\t \t",
"r,x,y,x1,y1=map(int,input().split())\r\ndis=((x-x1)**2 + (y-y1)**2)**0.5\r\nif dis//(2*r) == dis/(2*r):\r\n print(int(dis//(2*r)))\r\nelse:\r\n print(int(dis//(2*r))+1)",
"from sys import stdin,stdout\r\nstdin.readline\r\ndef mp(): return list(map(int, stdin.readline().strip().split()))\r\ndef it():return int(stdin.readline().strip())\r\nfrom collections import defaultdict as dd,Counter as C\r\nfrom math import ceil,sqrt\r\nr,x,y,x1,y1 = mp()\r\nans = ceil(sqrt(abs(x1-x)**2 + abs(y1-y)**2)/(2*r))\r\nprint(ans)\r\n\r\n",
"import math\na=list(map(int,input().split()))\nd=math.ceil(math.sqrt((a[1]-a[3])**2+(a[2]-a[4])**2))\nprint(math.ceil(d/(2*a[0])))\n \t \t\t \t\t\t\t\t \t \t \t \t\t\t\t \t\t\t",
"\r\n\r\n\r\nr,x,y,x1,y1 = map(int,input().split())\r\n\r\n\r\nimport math\r\n\r\n\r\na = math.sqrt((abs(x-x1)**2)+(abs(y-y1)**2))\r\n\r\n\r\nb= math.ceil(a/r)\r\n\r\n\r\nprint(math.ceil(b/2))\r\n",
"import math\r\n\r\ndef distance(a, b):\r\n m = len(a)\r\n c = 0\r\n for i in range(m):\r\n c += (a[i] - b[i]) ** 2\r\n return c ** 0.5\r\n\r\n\r\ndef solve(a, b, r):\r\n return math.ceil(distance(a, b) / (2 * r))\r\n\r\n\r\nr, x0, y0, x1, y1 = [int(s) for s in input().split(' ')]\r\n\r\n\r\nprint(solve((x0, y0), (x1, y1), r))\r\n\r\n\r\n",
"import math\r\nr,x,y,x1,y1=(int(i) for i in input().split())\r\nd=math.sqrt(((x1-x)*(x1-x))+((y1-y)*(y1-y)))\r\nprint(math.ceil(d/(2*r)))",
"import sys\r\nfrom math import *\r\nfrom collections import Counter, defaultdict, deque\r\ninput = sys.stdin.readline\r\nmod = 10**9+7\r\n\r\nr, x, y, x_dash, y_dash = [int(i) for i in input().split()]\r\ncent_dist = sqrt((x-x_dash)**2+(y-y_dash)**2)\r\n# print(cent_dist)\r\nprint(ceil(cent_dist/(2*r)))\r\n",
"r,x,y,x1,y1 = list(map(int,input().split()))\r\n\r\nd = ((x-x1)**2+(y-y1)**2)**(1/2)\r\n\r\nsteps = d//(2*r)\r\nif d%(2*r)!=0:\r\n steps+=1\r\nprint(int(steps))\r\n\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nd=math.sqrt((x1-x)**2+(y1-y)**2)\r\nstep=2*r\r\ncount=0\r\nif int(d/step)==d/step: count=int(d/step)\r\nelse: count=1+int(d/step)\r\nprint(count)\r\n",
"r,x,y,xx,yy=map(int,input().split())\r\nfrom math import hypot,ceil\r\nd=hypot(x-xx,y-yy)\r\nprint(ceil(d/r/2))",
"w=list(map(int,input().split()))\r\ne=((w[1]-w[3])**2+(w[2]-w[4])**2)**(1/2)\r\nr=e//w[0]\r\nif e%(2*w[0])==0:\r\n print(int(r//2))\r\nelse:\r\n print(int(r//2+1))",
"import math \r\nr,x,y,x1,y1=map(int,input().split())\r\ndist= math.hypot(x1-x,y1-y)/r\r\nprint(math.ceil(dist/2))\r\n\r\n",
"import math\r\nr,x,y,a,b=map(int,input().split())\r\nhd=abs(a-x)\r\nvd=abs(b-y)\r\nd=math.sqrt((hd*hd)+(vd*vd))\r\ncount=int(d//(2*r))\r\nif d%(r*2)!=0:\r\n count+=1\r\nprint(count)\r\n ",
"import math\r\nr,x,y,xx,yy = map(int , input().split())\r\n\r\ndis = math.sqrt(math.pow(xx-x , 2) + math.pow(yy-y , 2))\r\ndis = math.ceil(dis / (2*r))\r\nif x == xx and y == yy:\r\n dis = 0\r\nprint(dis)",
"r,x1,y1,x2,y2=list(map(int,input().split()))\r\n\r\nimport math\r\n\r\nres=math.ceil(math.sqrt(abs(x2-x1)**2+abs(y2-y1)**2)/(2*r))\r\nprint(res)\r\n",
"#imgur.com/Pkt7iIf.png\r\n\r\n#n, m = map(int, input().split())\r\n#n = int(input())\r\n#d = list(map(int, input().split()))\r\n\r\nimport math \r\n\r\nr, x, y, i, j = map(int, input().split())\r\n\r\nx = abs(x - i)\r\ny = abs(y - j)\r\n\r\nprint(math.ceil((x**2 + y**2)**0.5/(2*r)))\r\n",
"import math\r\n\r\nl =list(map(int,input().split()))\r\nd =((l[1]-l[3])**2+(l[2]-l[4])**2)**(1/2)\r\nprint(math.ceil((d)/(2*l[0])))",
"r,a,b,x,y=map(int,input().split())\r\nd=(((x-a)**2)+((y-b)**2))**0.5\r\nr+=r\r\nsteps=int(d//r)\r\nif d%r!=0:\r\n\tsteps+=1\r\nprint(steps)",
"import math\narr = [int(x) for x in input().split()]\nr = arr[0]\nx1 = arr[1]\ny1 = arr[2]\nx2 = arr[3]\ny2 = arr[4]\nresp = math.sqrt(math.pow(y2 - y1, 2) + pow(x2 - x1, 2))\nresp = math.ceil((resp / r) / 2)\nprint (resp)\n \t\t\t \t \t\t \t\t\t \t \t\t \t\t\t\t",
"import math\r\nr,x,y,x2,y2=map(int,input().split())\r\ndis=pow((pow(x-x2,2) + pow(y-y2,2)),0.5)\r\nprint(math.ceil(dis/(2*r)))",
"import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nr, x, y, xx, yy = map(int, input().split())\r\n\r\ndist = ((x-xx)**2 + (y-yy)**2)**0.5\r\n\r\nans = dist / (2*r)\r\n\r\nif ans % 1 == 0:\r\n print(int(ans))\r\nelse:\r\n print(int(ans) + 1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nz=math.sqrt((x1-x)**2+(y1-y)**2)\r\nprint(math.ceil(z/(r*2)))",
"from math import ceil\r\nr,x,y,x1,y1=map(int, input().split())\r\nprint(ceil(((x-x1)**2 + (y-y1)**2)**0.5 / (2*r)))",
"import math\r\ndef distance(x1, y1, x2, y2):\r\n\r\n return math.sqrt(math.pow(x2 - x1, 2) +\r\n math.pow(y2 - y1, 2) * 1.0)\r\n\r\nr,x,y,x1,y1=map(int,input().split())\r\ndis = distance(x, y, x1, y1)\r\nprint(math.ceil(dis/(2*r)))",
"mod = 1000000007\r\nii = lambda : int(input())\r\nsi = lambda : input()\r\ndgl = lambda : list(map(int, input()))\r\nf = lambda : map(int, input().split())\r\nil = lambda : list(map(int, input().split()))\r\nls = lambda : list(input())\r\nfrom math import *\r\nr,x,y,p,q=f()\r\nprint(ceil(((abs(p-x)**2+abs(q-y)**2)**0.5)/(2*r)))",
"import math\r\nn, x,y,x1,y1 = list(map(int,input().split()))\r\nd=math.sqrt(((x1-x)**2)+((y1-y)**2))\r\nprint(math.ceil(d/(2*n)))",
"import math\r\nr,x,y,x1,y1 = map(int,input().split())\r\ndx = abs(x1-x)\r\ndy = abs(y1-y)\r\nd = ((x1-x)**2 + (y1-y)**2)**0.5\r\nif(x==x1 and y==y1):\r\n print(0)\r\nelse:\r\n print(math.ceil(d/(2*r)))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n",
"import math as m\r\nw=[int(i) for i in input().split()]\r\nr=w[0]\r\nx=w[1]\r\ny=w[2]\r\nx1=w[3]\r\ny1=w[4]\r\nd=m.sqrt(((x-x1)**2)+((y-y1)**2))\r\nl=d/(2*r)\r\nprint(m.ceil(l))\r\n\r\n",
"import math\n\nr, x1, y1, x2, y2 = [int(x) for x in input().split()]\nc1 = (x1, y1)\nc2 = (x2, y2)\n\ndef distance(a, b):\n xa, ya = a\n xb, yb = b\n\n return math.sqrt((xa - xb) ** 2 + (ya - yb) ** 2)\n\nd = distance(c1, c2)\n# print(f\"Distance: {d}\")\nfull_length_steps = int(d // (2*r))\nif d - (2 * r * full_length_steps) == 0:\n print(full_length_steps)\nelse:\n print(full_length_steps + 1) # We need 1 steps to adjust to any point in between.\n\n\t \t\t\t \t\t\t\t \t \t \t \t\t\t\t \t",
"# cook your dish here\r\n#n=int(input())\r\nimport math\r\nnn=list(map(int,input().rstrip().split()))\r\n\r\ndia=2*nn[0]\r\nx=nn[1]\r\ny=nn[2]\r\nxx=nn[3]\r\nyy=nn[4]\r\n\r\ndist=math.sqrt((yy-y)*(yy-y)+((xx-x)*(xx-x)))\r\nnumm=dist/dia\r\nprint(math.ceil(numm))\r\n ",
"import math\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\n\r\ndef distance(x1, x2, y1, y2):\r\n\r\n b1 = (y2 - y1)**2\r\n b2 = (x2 - x1)**2\r\n\r\n return (math.sqrt(b1 + b2))\r\n\r\nd = distance(x1, x2, y1, y2)\r\n\r\none_move = 2*r\r\n\r\nprint(math.ceil(d / one_move))\r\n\r\n",
"from math import ceil\r\nline = input().split()\r\n\r\nr = int(line[0])\r\nx = int(line[1])\r\ny = int(line[2])\r\nnx = int(line[3])\r\nny = int(line[4])\r\n\r\ndist = ((nx - x)**2 + (ny - y)**2)**0.5\r\n\r\nprint(ceil(dist / (r*2)))\r\n",
"import math\r\n\r\nA= list(map(int,input().split()))\r\nr= A[0]\r\nx= A[1]\r\ny= A[2]\r\nx_dash= A[3]\r\ny_dash= A[4]\r\nif x == x_dash and y == y_dash:\r\n print(0)\r\n \r\nelse:\r\n d = math.sqrt(pow((x-x_dash),2)+pow((y-y_dash),2))\r\n \r\n t = d/(2*r)\r\n \r\n print(math.ceil(t))\r\n",
"r,x,y,x1,y1 = map(int,input().split())\r\nfrom math import sqrt,ceil\r\nd = (float)(sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y))) \r\nprint(int(ceil(d/(2*r))))\r\n",
"from math import *\r\nr,x,y,x1,y1=map(int,input().split())\r\ni=((x1-x)**2+(y1-y)**2)**0.5\r\nprint(ceil(i/(2*r)))",
"n=list(map(int,input().split(\" \")))\r\nrad=n[0]\r\nsqdis=(n[1]-n[3])**2+(n[2]-n[4])**2\r\n#print(sqdis)\r\ntr=(sqdis**0.5)\r\nk=tr/rad\r\nif k==0:\r\n print(0)\r\nelif k%2==0:\r\n print(int(k//2))\r\nelse:\r\n print(int(k//2+1))\r\n",
"#codeforces507B\r\ngi = lambda : list(map(int,input().strip().split()))\r\nr, x, y, a, b = gi()\r\nd = ((x-a)**2 + (y-b)**2)**.5\r\nans = int(d/(2*r))\r\nif d/(2*r) - int(d/(2*r)) > 0:\r\n\tans += 1\r\nprint(ans)",
"from math import ceil\r\nr, x, y, xa, ya = map(int, input().split())\r\nd = ((x - xa) ** 2 + (y - ya) ** 2) ** (1/2)\r\nprint(ceil(d / (r * 2)))",
"ar = []\r\nfor i in input().split(' '):\r\n ar.append(int(i))\r\nr = ar[0] * 2\r\nx1 = ar[1]\r\ny1 = ar[2]\r\nx2 = ar[3]\r\ny2 = ar[4]\r\ndiff = pow((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2), 0.5)\r\ncount = diff // r\r\nif diff % r != 0:\r\n count = count + 1\r\nprint(int(count))",
"r, x1, y1, x2, y2 = list(map(int, input().split()))\r\ndx = abs(x2 - x1)\r\ndy = abs(y2 - y1)\r\ndz = ((abs(x2 - x1))**2 + (abs(y2 - y1))**2)**0.5\r\n\r\nd = 2*r\r\n# considering the case when only X coordinate has changed\r\nif y1 == y2:\r\n ans = dx // d\r\n if dx % d != 0:\r\n ans += 1\r\nelif x1 == x2:\r\n ans = dy // d\r\n if dy % d != 0:\r\n ans += 1\r\nelse:\r\n ans = dz // d\r\n if dz % d != 0:\r\n ans += 1\r\n\r\n\r\nprint(int(ans))",
"import math\r\ndef minSteps(r,x,y,newX,newY):\r\n distance = math.sqrt(pow(x-newX,2)+pow(y-newY,2))\r\n return math.ceil((distance)/(2*r))\r\n\r\nr,x,y,newX,newY = [int(x) for x in input().split()] \r\nprint(minSteps(r,x,y,newX,newY))",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nd=math.sqrt((x1-x)**2+(y1-y)**2)\r\nc=math.ceil(d/(2*r))\r\nif(c==1):\r\n print(int(1))\r\nelse:\r\n print(int(c))",
"import math\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\n\r\ndistance = math.pow(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2), 0.5)\r\n\r\nprint(math.ceil(distance / (r * 2)))\r\n",
"import math\r\nx,y,z,a,b=map(int,input().split())\r\nans=math.sqrt((b-z)*(b-z)+(a-y)*(a-y))\r\nprint(math.ceil(ans/2.0/x))",
"import math\r\nr,x,y,c,d = [int(x) for x in input().split()]\r\ndist = math.sqrt((c-x)**2+(d-y)**2)\r\n\r\nsteps = dist/(r+r)\r\nprint(math.ceil(steps))",
"import math\r\ndef steps(r,x,y,x1,y1):\r\n distance=math.sqrt((x-x1)**2+(y-y1)**2)\r\n if distance%(2*r)==0:\r\n return int(distance//(2*r))\r\n else:\r\n return int((distance//(2*r))+1)\r\nl=list(map(int,list(input().split())))\r\nprint(steps(l[0],l[1],l[2],l[3],l[4]))",
"import math\narr=list(map(int,input().split()))\nr,x,y,x1,y1=arr[0],arr[1],arr[2],arr[3],arr[4]\nd=math.sqrt((x-x1)**2+(y-y1)**2)\nif d%(r*2)==0:\n\tprint(int(d//(2*r)))\nelif d<2*r:\n\tprint(1)\nelif d<4*r:\n\tprint(2)\nelse:\n\tstep=0\n\twhile d>4*r:\n\t\td=d-2*r\n\t\tstep+=1\n\tprint(step+2)",
"import math\r\nr,x0,y0,x1,y1=map(int,input().split())\r\nd = math.sqrt((x1-x0)**2+(y1-y0)**2)\r\ns = d/(r<<1)\r\nprint(math.ceil(s))\r\n",
"from math import ceil\r\nr,a,b,c,d=map(int,input().split())\r\ns=pow((pow(abs(c-a),2)+pow(abs(d-b),2)),0.5)\r\nprint(ceil(s/(2*r)))",
"import math\r\ndef disb2p(x1,y1,x2,y2):\r\n return (math.sqrt((x2-x1)**2+(y2-y1)**2))\r\n\r\na,x1,y1,x2,y2=map(int,input().split())\r\nprint(math.ceil(disb2p(x1,y1,x2,y2)/(2*a)))\r\n# CodeBy: RAHUL MAHAJAN\r\n# A2OJ: rahulmahajan\r\n# CC: anonymous0201\r\n# CF: rahulmahajan\r\n# CSES: rahulmahajan",
"import math\r\ns=input().split(' ')\r\nr=int(s[0])\r\nx=int(s[1])\r\ny=int(s[2])\r\nx1=int(s[3])\r\ny1=int(s[4])\r\ndist=math.sqrt((x1-x)**2+(y1-y)**2)\r\nnum=math.ceil(dist/r/2)\r\nprint(int(num))",
"r,x,y,x1,y1 = map(int,input().split())\r\nd = ((x1-x)**2 + (y1-y)**2)**0.5\r\nprint(int((d//(2*r) + int(1 if d%(2*r)!= 0.0 else 0))))\r\n",
"r, x1, y1, x2, y2 = [int(i)for i in input().split()]\r\nans = 0\r\nlen = ((x1-x2)**2+(y1-y2)**2)**0.5\r\nif len == 0:\r\n print(0)\r\nelif len//(r*2) == len/(r*2):\r\n print(int(len//(r*2)))\r\nelse:\r\n print(int(len//(r*2))+1)",
"import math\r\nr, x, y, xt, yt = map(int, input().split())\r\nd = 2*r\r\ndt = math.sqrt((x-xt)**2+(y-yt)**2)\r\nprint(math.ceil(dt/d))\r\n",
"from math import *\r\n\r\nr, x, y, x1, y1 = map(int, input().split())\r\nd = r * 2\r\n\r\ns = sqrt((x - x1)**2 + (y - y1)**2)\r\nprint(int(s / d) + (s - int(s / d) * d > 0))",
"import math\r\n\r\n\r\ng = 0\r\n\r\na,b,c,d,e = [int(x) for x in input().split()]\r\n\r\ndist = math.sqrt((d - b)**2 + (e - c)**2)\r\n\r\ng = dist /(2*a)\r\n\r\n\r\nprint( math.ceil(g))",
"import sys\r\ninput = sys.stdin.readline\r\nfrom math import ceil\r\n\r\nr, x, y, x1, y1 = map(int, input().split())\r\n\r\nprint(ceil(((x1-x)**2 + (y1-y)**2)**0.5 / (r*2)))",
"r,x,y,x1,y1 = map(int,input().split())\r\nd = pow((x-x1)**2+(y-y1)**2,0.5)\r\ni = int(d)\r\nif i==d:\r\n if i%(2*r)==0:\r\n print(i//(2*r))\r\n else:\r\n print(i//(2*r)+1)\r\nelse:\r\n print(i//(2*r)+1)",
"from fractions import Fraction\nfrom math import ceil\ndef get(f): return f(input().strip())\ndef gets(f): return [*map(f, input().split())]\n\n\nr, x, y, u, v = gets(int)\nf = Fraction((x - u) ** 2 + (y - v) ** 2, r ** 2 << 2)\nprint(ceil(f ** .5))\n",
"'''input\n1 1 1 4 4\n'''\n\nfrom math import sqrt, ceil\n\ndef dis(x1, y1, x2, y2):\n return sqrt((x1-x2)**2 + (y1-y2)**2)\n\n\n\ndef main():\n\n r, x1, y1, x2, y2 = map(int, input().split())\n\n dist = dis(x1, y1, x2, y2)\n\n # print(dist)\n # print(dist//(2*r), dist%(2*r))\n print(ceil(dist/(2*r)))\n\n\n\n\n\n\n\nif __name__ == '__main__':\n main()\n",
"import math\r\nr,x,y,x1,y1 = list(map(int, input().split()))\r\n\r\nans = math.ceil(math.sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1))/(2*r))\r\nprint(ans)\r\n",
"import math\r\nx,y,z,a,b=map(int,input().split())\r\nsol=math.sqrt((b-z)*(b-z)+(a-y)*(a-y))\r\nprint(math.ceil(sol/2.0/x))",
"import math\r\n\r\n[r,x,y,xp,yp] = [int(i) for i in input().split(' ')]\r\nprint(math.ceil(math.sqrt((x-xp)**2 + (y-yp)**2)/(2*r)))",
"import math\r\nx = input().split()\r\nr = int(x[0])\r\nx1 = int(x[1])\r\ny1 = int(x[2])\r\nx2 = int(x[3])\r\ny2 = int(x[4])\r\nprint(math.ceil(((x1-x2)**2+(y1-y2)**2)**0.5 / (2*r)))",
"import math\r\nr, x, y, X, Y= map(int, input().split())\r\nsize=((X-x)**2+(Y-y)**2)**.5\r\nprint(math.ceil(size/(2*r)))",
"from math import ceil\r\n\r\n\r\ndef main():\r\n r, x0, y0, x1, y1 = map(int, input().split())\r\n\r\n d = ((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1)) ** 0.5\r\n ans = ceil(d / 2 / r)\r\n print(ans)\r\n\r\n\r\nmain()\r\n",
"import math\r\n\r\nr, x, y, x2, y2 = tuple(map(int, input().split(\" \")))\r\nd = math.sqrt((x-x2)**2 + (y-y2)**2)\r\nres = math.ceil(d/r)\r\nres = math.ceil(res/2)\r\nprint(res)\r\n",
"import math\nr, x, y, u, v = map(int, input().split())\nd = math.sqrt((u-x)**2 + (v-y)**2) / (2*r)\nif d != int(d):\n d += 1 \nprint(int(d))\n",
"import math \r\ndef distance(x1 , y1 , x2 , y2): \r\n return math.sqrt(math.pow(x2 - x1, 2) +math.pow(y2 - y1, 2) ) \r\n \r\nr,x,y,x1,y1=map(int,input().split())\r\nif(x1==x and y1==y):\r\n print(0)\r\nelse:\r\n d=distance(x,y,x1,y1)\r\n print(math.ceil(d/(2*r)))\r\n ",
"import math as m\r\na,b,c,d,e = map(int,input().split())\r\ndistance = m.sqrt((d-b)**2+ (e-c)**2)\r\nprint(m.ceil(distance/a/2))",
"import math\r\nr,x,y,x1,y1=map(int,input().split(\" \"))\r\nd = (x-x1)**2 + (y-y1)**2\r\nd = math.sqrt(d)\r\nd = math.ceil(d/(2*r))\r\nprint(d)",
"import math\n\n# Capture input\nA = list(map(int, input().split()))\nr = A[0]\nx = A[1]\ny = A[2]\nx_prime = A[3]\ny_prime = A[4]\n\n# If both are same 0 since no moves are needed\nif x == x_prime and y == y_prime:\n print(0)\n\nelse:\n # Calculate the distance between the two points\n distance = math.sqrt(pow((x - x_prime),2)+pow((y - y_prime),2))\n\n # Get the number of turns\n turns = distance/(2*r)\n\n print(math.ceil(turns))\n \t \t \t\t \t\t\t \t\t\t\t\t \t\t \t\t\t",
"from math import ceil\r\nr,x_1,y_1,x_2,y_2 = map(int, input().split(\" \"))\r\n\r\ndistance = ((x_1-x_2)**2 + (y_1-y_2)**2)**0.5\r\nres : int\r\n\r\nif distance == 0:\r\n\tres = 0\r\nelse:\r\n\tres = ceil(distance/(r*2))\r\n\r\nif (res*r*2)+r*2 <= distance:\r\n\tres+=1\r\n\r\nprint(int(res))",
"import sys\r\nfrom collections import *\r\nfrom heapq import *\r\nimport math\r\nimport bisect\r\n#def input():\r\n #return sys.stdin.readline()\r\n\r\nr,x,y,x1,y1=map(int,input().split())\r\ndis=math.sqrt((x1-x)**2+(y1-y)**2)\r\nprint(math.ceil(dis/(2*r)))\r\n",
"import math\r\na,b,c,d,e=map(int,input().split())\r\nprint(math.ceil((math.sqrt((b-d)*(b-d)+(c-e)*(c-e)))/(2*a)))",
"import math\nvalues = list(map(int,input().split()))\n\ndistance = ((values[1] - values[3])**2 + (values[2] - values[4])**2)**0.5\n\nmoves = math.ceil(distance/(2*values[0]))\n\nprint(moves)",
"from math import ceil\r\n\r\nr, x1, y1, x2, y2 = list(map(int, input().split()))\r\ndistance = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5\r\nre = ceil(distance / (2 * r))\r\nprint(re)",
"from math import sqrt, ceil\r\n\r\n\r\ndef distance(r, x1, y1, x2, y2):\r\n return ceil(sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) / (2 * r))\r\n\r\n\r\nR, X1, Y1, X2, Y2 = [int(i) for i in input().split()]\r\nprint(distance(R, X1, Y1, X2, Y2))\r\n",
"import math\nr, x,y, x1,y1 = map(int, input().split())\ndist = ((x1-x)**2 + (y1-y)**2)**(1/2)\nans = math.ceil(dist/(2*r))\nprint(ans)\n \n\t\t\t \t\t \t\t\t\t\t \t \t\t \t\t \t\t\t",
"import math\r\nr, a, b, c, d = map(int, input().split())\r\nz = math.sqrt((a - c)**2 + (b - d)**2)\r\nprint(math.ceil(z / (2 * r)))\r\n",
"def isin(r,x,y,x1,y1):\r\n if(x>x1):\r\n if(y>y1 and x-r<=x1+r and y-r<=y1+r):\r\n return True\r\n elif(y<y1 and x-r<=x1+r and y+r>=y1-r):\r\n return True\r\n elif(x<x1):\r\n if (y > y1 and x + r >= x1 - r and y - r <= y1 + r):\r\n return True\r\n elif (y < y1 and x + r >= x1 - r and y + r >= y1 - r):\r\n return True\r\n\r\n\r\nr,x,y,x1,y1=map(int,input().split())\r\nans=0;c=0\r\nif(x==x1 and y==y1):\r\n print(0)\r\nelse:\r\n dis=((x-x1)**2+(y-y1)**2)**(1/2)\r\n while(dis>2*r):\r\n c+=1\r\n dis-=(2*r)\r\n print(c+1)",
"from sys import stdin, stdout\r\n\r\ninput = stdin.readline\r\ndef print(val):\r\n stdout.write(f'{val}\\n')\r\n\r\ndef distance(x1, y1, x2, y2):\r\n return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\n\r\ndistance = distance(x1, y1, x2, y2)\r\nif distance == 0:\r\n print(0)\r\nelse:\r\n print(int(distance / (2 * r)) + 1 if distance % (2 * r) else int(distance / (2 * r)))",
"import math\r\na= list(map(int,input().split()))\r\nd=(a[3]-a[1])**2 + (a[4]-a[2])**2\r\nd=d**(0.5)\r\nx=a[0]\r\nprint(math.ceil(d/(2*x)))",
"from sys import stdin,stdout\r\nfrom collections import Counter\r\ndef ai(): return list(map(int, stdin.readline().split()))\r\ndef ei(): return map(int, stdin.readline().split())\r\ndef ip(): return int(stdin.readline().strip())\r\ndef op(ans): return stdout.write(str(ans) + '\\n')\r\nfrom math import ceil\r\nimport math\r\n\r\nr,x,y,a,b=ei()\r\nd = math.sqrt((a-x)**2+(b-y)**2)\r\nprint(ceil(d/(2*r)))",
"from functools import reduce\r\nimport os\r\nimport sys\r\nfrom collections import *\r\n#from fractions import *\r\nfrom math import *\r\nfrom bisect import *\r\nfrom heapq import *\r\nfrom io import BytesIO, IOBase\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\ndef value(): return tuple(map(int, input().split())) # multiple values\r\ndef arr(): return [int(i) for i in input().split()] # array input\r\ndef sarr(): return [int(i) for i in input()] #array from string\r\ndef starr(): return [str(x) for x in input().split()] #string array\r\ndef inn(): return int(input()) # integer input\r\ndef svalue(): return tuple(map(str, input().split())) #multiple string values\r\ndef parr(): return [(value()) for i in range(n)] # array of pairs\r\nmo = 1000000007\r\ninf=1e18\r\ndiv=998244353\r\n#print(\"Case #{}:\".format(_+1),end=\" \")\r\n# ----------------------------CODE------------------------------#\r\nr,x,y,x1,y1=value()\r\nres=sqrt((x-x1)**2+(y-y1)**2)\r\nprint(ceil(res/(2*r)))\r\n\r\n\r\n\r\n\r\n\r\n",
"r, x, y, z, w = [int(r) for r in input().split()]\r\n\r\ndef steps(r,x,y,z,w):\r\n diameter=2*r\r\n d=pow(((x-z)**2+(y-w)**2),0.5)\r\n if d%diameter==0:\r\n stepreq=d//diameter\r\n else:\r\n stepreq=1+d//diameter\r\n print(int(stepreq))\r\n \r\nsteps(r,x,y,z,w)",
"lst1 = list(map(int,input().split()))\r\nd = ((lst1[1] - lst1[3])**2 + (lst1[2] - lst1[4])**2)**0.5\r\nans = 0\r\nans += int(d//(2*lst1[0]))\r\nif d%(2*lst1[0]) != 0:\r\n ans+=1\r\nprint(ans)",
"import math\r\ndef solve():\r\n r, x0, y0, x1, y1 = [int(x) for x in input().split(\" \")]\r\n return (math.ceil(math.sqrt((x1-x0)**2 + (y1-y0)**2)/(2*r)))\r\n\r\nif __name__==\"__main__\":\r\n print(solve())",
"import sys, math\r\ninput = sys.stdin.readline\r\n\r\nr, x1, y1, x2, y2 = [int(c) for c in input().split()]\r\n\r\ndX = abs(x2-x1)\r\ndY = abs(y2-y1)\r\nd = (dX**2+dY**2)**(1/2)\r\nmove = math.ceil(d/(2*r))\r\n\r\nprint(move)\r\n\r\n\r\n\t\r\n",
"r,x,y,xx,yy=map(int,input().split())\nfrom math import hypot,ceil\nd=hypot(x-xx,y-yy)\nprint(ceil(d/r/2))",
"from sys import stdin, setrecursionlimit\r\nfrom collections import deque\r\nimport math \r\ninput = stdin.readline\r\nsetrecursionlimit(int(2e5))\r\ndef getstr(): return input()[:-1]\r\ndef getint(): return int(input())\r\ndef getints(): return list(map(int, input().split()))\r\ndef getint1(): return list(map(lambda x : int(x) - 1, input().split()))\r\njn = lambda x,l: x.join(map(str,l))\r\n \r\nMOD = 10 ** 9 + 7\r\ny, n = \"YES\", \"NO\"\r\n# inputs=open('input.txt','r')\r\n \r\n# n=inputs.readlines()\r\n \r\ndef solve():\r\n r,x1,y1,x2,y2 = getints()\r\n d = 2*r\r\n dis = math.sqrt((x1 -x2)*(x1 - x2) +\r\n (y1 - y2)*(y1 - y2)) \r\n print(-int(-dis//(d)))\r\n \r\n \r\nif __name__ == \"__main__\":\r\n # solve()\r\n # for t in range(getint()):\r\n # print(\"Case #{}: \".format(t + 1), end=\"\")\r\n # solve()\r\n #for _ in range(int(inputs.readline())):\r\n solve()",
"from math import sqrt, ceil\r\nr, x, y, x2, y2 = map(int, input().split())\r\n\r\nd = sqrt(pow(x - x2, 2) + pow(y - y2, 2))\r\n\r\ns = int(ceil(d / (2 * r)))\r\n\r\nprint(s)",
"import math\r\n\r\n\r\nr,x,y,x1,y1=[int(i) for i in input().split()]\r\nd=(((x-x1)**2)+((y-y1)**2))**0.5\r\nd1=2*r\r\nif d%d1==0:\r\n print(int(d/d1))\r\nelse :\r\n print(math.floor(d/d1)+1)",
"import math #.sqrt\r\ndef ceil (a, b):\r\n return -(-a // b)\r\ndef answer(r, x, y, xp, yp):\r\n d = math.sqrt((xp-x)**2 + (yp-y)**2)\r\n num_rs = ceil(d, 2*r)\r\n\r\n return int(num_rs)\r\n\r\ndef main():\r\n r, x, y, xp, yp = [int(i) for i in input().split()]\r\n print(answer(r, x, y, xp, yp))\r\n\r\n\r\n return\r\nmain()",
"from math import ceil,sqrt\r\nr,x1,y1,x2,y2 = map(int,input().split())\r\nd = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))\r\nprint(ceil(d/(2*r)))",
"import math\r\nr,x1,y1,x2,y2=[int(x) for x in input().split()]\r\nans=(math.sqrt((x2-x1)**2+(y2-y1)**2))/(2*r)\r\nans=int(math.ceil(ans))\r\nprint(ans)\r\n\r\n\r\n",
"from math import ceil\r\n\r\nr, x, y, xx, yy = map(float, input().split())\r\n\r\ndist = ((xx-x)**2 + (yy-y)**2) ** 0.5\r\nprint(ceil(dist/(2*r)))\r\n",
"import math\r\nr,x,y,x2,y2=list(map(int, input().split()))\r\nprint(math.ceil(math.sqrt((x-x2)**2+(y-y2)**2)/(r*2)))",
"import math\nr ,x1,y1,x2,y2 = list(map(int,input().split()))\n\ndist = math.sqrt((x1-x2)**2 + (y1-y2)**2)\n\nans = 0\nans+=(dist/(r*2))\nprint(math.ceil(ans))\n",
"from math import sqrt\r\nfrom math import ceil\r\n\r\nr, x, y, x2, y2 = map(int, input().split(' '))\r\nprint(ceil(sqrt((x2-x)**2+(y2-y)**2)/(r+r)))",
"import math\r\n\r\n# Capture input\r\nA = list(map(int, input().split()))\r\nr = A[0]\r\nx = A[1]\r\ny = A[2]\r\nx_prime = A[3]\r\ny_prime = A[4]\r\n\r\n# If both are same 0 since no moves are needed\r\nif x == x_prime and y == y_prime:\r\n print(0)\r\n\r\nelse:\r\n # Calculate the distance between the two points\r\n distance = math.sqrt(pow((x - x_prime),2)+pow((y - y_prime),2))\r\n\r\n # Get the number of turns\r\n turns = distance/(2*r)\r\n\r\n print(math.ceil(turns))",
"r,x1,y1,x2,y2=map(int,input().split())\r\ndistance=(((x1-x2)**2) + ((y1-y2)**2))**(1/2)\r\nif(distance!=0):\r\n for i in range(1,10**6 ):\r\n if(distance/i > 2*r):\r\n pass\r\n if(distance/i <= 2*r):\r\n print(i)\r\n break\r\nelse:\r\n print(0)\r\n",
"from math import ceil, sqrt\nr, x1, y1, x2, y2 = map(int, input().split())\nprint(ceil(sqrt((x1-x2)**2 + (y1-y2)**2) / (r*2)))\n",
"from math import *\r\nr,x,y,xi,yi=map(int,input().split())\r\nc=sqrt(((xi-x)**2)+(yi-y)**2)\r\nprint(ceil(c/(r*2)))",
"r,x,y,a,b = map(int,input().split())\r\ndis = ((x-a)**2+(y-b)**2)**(0.5)\r\neq = dis/(r*2)\r\nif eq!=int(eq):\r\n eq+=1\r\nprint(int(eq))",
"import math\r\ndef solve():\r\n r, x, y, n_x, n_y = map(int, input().split())\r\n if(x == n_x and y == n_y):\r\n print(0)\r\n else:\r\n dist = ((n_x - x)**2 + (n_y - y)**2)**0.5\r\n print(math.ceil(dist/(2*r)))\r\n\r\nsolve()",
"import math\r\nr, x, y, xn, yn = map(int,input().split(' '))\r\ndis = pow(((x-xn)*(x-xn)+(y-yn)*(y-yn)),0.5)\r\nif(dis==0.0):\r\n print(0)\r\nelse:\r\n print(math.ceil(dis/(2*r)))",
"from math import *\r\nr,x,y,a,b,=map(int,input().split())\r\nd=sqrt(pow(x-a,2)+pow(y-b,2))\r\nans=(d//(2*r))\r\nif d%(2*r)!=0:\r\n ans+=1\r\nprint(int(ans))",
"from math import ceil, sqrt\r\nr, x, y, x_, y_ = map(int, input().split())\r\ndx, dy = x_ - x, y_ - y\r\nprint(ceil(sqrt(dx ** 2 + dy ** 2) / (2 * r)))\r\n",
"import math\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nm = math.sqrt((abs(x1-x2)**2)+(abs(y1-y2)**2))\r\nd = r*2\r\nans = m//d\r\nif m%d > 0:\r\n ans += 1\r\nans = int(ans)\r\nprint(ans)",
"import math\n\nr, x, y, a ,b = map(int, input().split())\n\nd = ((x - a) ** 2 + (y - b) ** 2) ** (1 / 2)\n\nprint(math.ceil(d / (2 * r)))",
"r,x,y,x2,y2=map(int,input().split())\r\nl=((x-x2)**2+(y-y2)**2)**0.5\r\nprint(-int(-l//(2*r)))\r\n",
"from math import sqrt, ceil\r\n\r\nr,x,y,newx,newy = map(int, input().split())\r\n\r\ndist = sqrt((x-newx)**2 + (y-newy)**2)\r\n\r\nturns = ceil(dist / (2*r))\r\nprint(turns)",
"import math\r\n\r\nprint(\r\n (\r\n lambda r, x1, y1, x2, y2: math.ceil(\r\n math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) / (2 * r)\r\n )\r\n )(*map(int, input().split()))\r\n)\r\n",
"import math\r\nw=input().split(\" \")\r\nr=int(w[0])\r\nx,y,x1,y1=int(w[1]),int(w[2]),int(w[3]),int(w[4])\r\ndis=math.sqrt((x-x1)**2+(y-y1)**2)\r\nif dis//(2*r)==dis/(2*r):\r\n\tprint(int((dis//(2*r))) )\r\nelse:\r\n\tprint(int((dis//(2*r)+1)))\r\n",
"r,x1,y1,x2,y2=map(int,input().split())\r\nd=(((x1-x2)**2)+((y1-y2)**2))**0.5\r\ncount=d//(2*r)+ (d%(2*r)>0)\r\n# print(d//(2*r),d%(2*r))\r\nprint(int(count))",
"import math\r\nr,x,y,x1,y1 = map(int, input().split())\r\nprint(math.ceil((((x1-x)**2 + (y1-y)**2)**0.5)/(2*r)))",
"from math import sqrt,ceil\r\nr,x,y,x_,y_=map(int,input().split())\r\n\r\nll=x_-x\r\nrr=y_-y\r\n\r\nre=sqrt((ll**2+rr**2))\r\nma=2*r\r\nprint(ceil(re/ma))\r\n",
"import math\r\nr,x,y,xx,yy = map(int,input().split())\r\nd = math.sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y))\r\nprint(math.ceil(d/(2*r)))",
"from math import ceil\r\nr, x, y, x_n, y_n = map(int, input().split())\r\nd = ((x - x_n) ** 2 + (y - y_n) ** 2) ** 0.5\r\nprint(ceil(d / (2 * r)))",
"from math import dist, ceil\r\n\r\ndef main():\r\n\tr, x1, y1, x2, y2 = map(int, input().split())\r\n\t# can move up to 2 * r\r\n\tto_go = dist((x1, y1), (x2, y2))\r\n\tprint(ceil(to_go / (2 * r)))\r\n\t\t\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()",
"import math\r\nr, x, y, x1, y1 = map(int, input().split(' '))\r\n\r\ndx = abs(x1-x)\r\ndy = abs(y1-y)\r\n\r\nd = math.sqrt(dx**2 + dy**2)\r\ntemp = 0\r\nwhile d>2*r*temp:\r\n temp+=1\r\nprint(temp)\r\n\r\n\r\n",
"from math import sqrt\r\nfrom math import ceil \r\n\r\ndef main():\r\n r, x, y, a, b = map(int, input().split())\r\n if x==a and y==b:\r\n return 0 \r\n distance = sqrt((x-a)**2 + (y-b)**2)\r\n ans = ceil(distance/(2*r))\r\n \r\n return ans\r\n \r\nprint(main())",
"import math\r\nr,x,y,x1,y1 = map(int, input().split())\r\nd = ((x1-x)**2 + (y1-y)**2) ** (0.5)\r\nprint(math.ceil(d / (2 * r)))\r\n\r\n",
"from math import ceil\nr, x, y, xx, yy = map(int, input().split())\nprint(ceil(((xx - x) ** 2 + (yy - y) ** 2) ** 0.5 / r / 2))\n",
"import math\r\nr,x1,x2,y1,y2=map(int,input().split())\r\nz=(((x1-y1)**2)+((x2-y2)**2))\r\nz=math.sqrt(z)\r\nprint(math.ceil(z/(2*r)))\r\n",
"import sys\r\ninput = sys.stdin.readline\r\n \r\nr, x, y, x1, y1 = map(int, input().split())\r\n\r\ndist = ((x-x1)**2 + (y-y1)**2)**0.5\r\n\r\nres = int(dist / (2*r))\r\nif dist % (2*r) > 0:\r\n res += 1\r\nprint(res)\r\n",
"from math import *\r\ns1=input()\r\ns2=s1.split()\r\nfor i in range(5):\r\n s2[i]=int(s2[i])\r\nr,x,y,x1,y1=s2[0],s2[1],s2[2],s2[3],s2[4]\r\n\r\ndis=hypot((x-x1),(y-y1))\r\n\r\nans=ceil(dis/(2*r))\r\n\r\nprint(ans)\r\n\r\n\r\n \r\n",
"r, x, y, nx, ny = map(int, input().split())\r\n\r\ndist = ((nx-x)**2+(ny-y)**2)**0.5\r\nadd = 0\r\nif dist % (2*r) != 0:\r\n add = 1\r\nprint(int(dist//(2*r)) + add)\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\ndist = math.sqrt((x-x1)**2 + (y-y1)**2)\r\nprint(math.ceil(dist/(2*r)))",
"#n,t=map\r\n\r\nfrom cmath import sqrt\r\nfrom math import ceil\r\n\r\n\r\na = list(map(int,input().strip().split()))[:5]\r\nr=a[0]\r\nx=a[1]\r\ny=a[2]\r\nx2=a[3]\r\ny2=a[4]\r\nif x==x2 and y==y2:\r\n print(0)\r\n exit()\r\nd=sqrt((abs(x-x2)**2)+(abs(y-y2)**2))\r\na=d.real\r\nb=d.imag\r\nval=a+b\r\nval=ceil(val)\r\nres=ceil(val/(2*r))\r\nprint(res)",
"import math\n\nr,x,y,x1,y1=[int(x) for x in input().split(' ')]\n\n# print(r,x,y,x1,y1)\na=((x1-x)*(x1-x))+((y1-y)*(y1-y))\n# print(a)\nm=math.sqrt(abs(a))/(2*r)\nprint(math.ceil(m))",
"\"\"\"\r\nCreated on Sun Aug 23 09:45:23 2020\r\n\r\n@author: roastedcoder\r\n\r\nThis is for Codeforces\r\n\"\"\"\r\n\r\nmod = 1000000007\r\nssi = lambda : map(int,input().split())\r\n\r\n# RoastedCoder\r\n\r\nfrom math import ceil\r\n\r\nr, x, y, x1, y1 = ssi()\r\na = pow(abs(x-x1), 2) + pow(abs(y-y1), 2)\r\ndist = pow(a,0.5)\r\nres = ceil(dist/(2*r))\r\nprint(res)",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\ndis=math.sqrt((x1-x)**2+(y1-y)**2)\r\n#print(dis)\r\nprint(math.ceil(dis/(2*r)))\r\n#print(2*r)",
"r,a,b,x,y = map(int, input().split())\r\nd = 2*r\r\nl = ((x-a)**2)+((y-b)**2)\r\nk = l**(0.5)\r\nif k%d == 0:\r\n print(int(k/d))\r\nelse:\r\n print(int(k//d)+1)",
"import math\r\n\r\nr,x,y,x1,y1 = list(map(int,input().split()))\r\ndist = math.sqrt((x1-x)**2+(y1-y)**2)\r\nprint(math.ceil(dist/(2*r)))",
"import math\r\ndef solve():\r\n\tr,x1,y1,x2,y2 = map(int, input().split())\r\n\tdist = math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))\r\n\tR = r*2\r\n\treturn math.ceil(dist/R)\r\n\r\nprint(solve())",
"import math\r\nr,x,y,x1,y1=input().split()\r\nr=int(r)\r\nx=int(x)\r\ny=int(y)\r\nx1=int(x1)\r\ny1=int(y1)\r\ndis=math.sqrt(((x1-x)**2)+((y1-y)**2))\r\nprint(math.ceil(dis/(2*r)))\r\n",
"import math\r\nr,x1,y1,x2,y2=map(int,input().split())\r\nd=math.sqrt((x1-x2)**2+(y1-y2)**2)\r\nprint(math.ceil(d/(2*r)))",
"import math\r\nr, x, y, xn, yn = [int(x) for x in input().split()]\r\nd = math.sqrt((x-xn)**2 + (y-yn)**2)\r\nprint(math.ceil(d/(2*r)))",
"import math\r\nimport sys\r\ninput = sys.stdin.readline\r\nr,a,b,x,y = map(int, input().split())\r\nd = ((a-x)**2 + (b-y)**2)**0.5\r\nr*=2\r\nif d%r==0:\r\n print(int(d//r))\r\nelse:\r\n print(int(d//r) +1)\r\n ",
"import math\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\n\r\na = math.pow((x1-x2),2)\r\nb = math.pow((y1-y2),2)\r\n\r\ndistance = math.sqrt(a+b)\r\n\r\nanswer = math.ceil(distance / (r*2))\r\nprint(answer)",
"import math\r\nr, x, y, xx, yy = map(int, input().split())\r\nhyp = math.sqrt((xx-x)**2+(yy-y)**2)\r\nprint(math.ceil(hyp/(2*r)))\r\n",
"r, x, y, x1, y1 = map(int, input().split())\r\nd = ((x-x1)**2 + (y-y1)**2)**0.5\r\nres = int(d//(r*2))\r\nif d % (r * 2):\r\n res += 1\r\nprint(res)",
"r,x,y,x1,y1=list(map(int,input().split(\" \")))\r\n\r\n\r\n\r\ndef amir(r,x,y,x1,y1): \r\n d=((x1-x)**(2)+(y1-y)**(2))**(1/2)\r\n if d%(2*r)==0:\r\n print(int(d/(2*r)))\r\n return\r\n else:\r\n if d<2*r:\r\n print(1)\r\n return\r\n print(int(d//(2*r))+1)\r\n return\r\n \r\namir(r,x,y,x1,y1)",
"import math\r\nL=list(map(int,input().split()))\r\nd=((L[1]-L[3])**2+(L[2]-L[4])**2)**0.5\r\nprint(math.ceil(d/(2*L[0])))\r\n\r\n",
"from math import ceil, sqrt, fabs\r\n\r\nr, x, y, x1, y1 = map(int, input().split(' '))\r\nprint(ceil(ceil(sqrt((x1 - x) ** 2 + (y1 - y) ** 2)) / (2 * r)))\r\n",
"# Amr and Pins\r\nimport math\r\n\r\n# function to calculate the distance between two points\r\ndef distance(x, y, x1, y1):\r\n return math.sqrt(((x1-x)**2+(y1-y)**2))\r\n\r\n# taking the input\r\nr, x, y, x1, y1 = input().split()\r\nr = int(r)\r\nx = int(x)\r\ny = int(y)\r\nx1 = int(x1)\r\ny1 = int(y1)\r\n\r\n# the answer is basically ceil(distance/(2*radius))\r\nprint(math.ceil(distance(x, y, x1, y1)/(2*r)))\r\n",
"from math import ceil\ndef dist(a,b):\n return (a*a + b*b)**.5\n\ndef how_many(r, sx,sy, tx,ty):\n l = dist(sx-tx,sy-ty)\n #print(l)\n res = (l )/(2*r)\n return ceil(res)\n\nr,sx,sy,tx,ty = map(int, input().split())\n\nprint(how_many(r,sx,sy,tx,ty))\n",
"r,x,y,x1,y1=map(int,input().split(' '))\r\ndist=pow(((x-x1)*(x-x1)+(y-y1)*(y-y1)),0.5)\r\nif(dist==0.0):\r\n print(0)\r\nelse:\r\n z=(dist/(2*r))\r\n if((z-int(z)==0.0)):\r\n print(int(z))\r\n else:\r\n print(int(z+1)) \r\n",
"from math import ceil\r\nr,x1,y1,x2,y2=map(int,input().split())\r\nd=((x1-x2)**2+(y1-y2)**2)**(1/2)\r\nprint(ceil(d/(2*r)))",
"import math\r\nx=list(map(int,input().split()))\r\nr=x[0]\r\ndistance=math.sqrt((x[4]-x[2])**2 + (x[3]-x[1])**2)\r\nif distance%(2*r)==0:\r\n\tprint(int(distance//(2*r)))\r\nelse:\r\n\tprint(int(distance//(2*r))+1)",
"import math\nr,x,y,x1,y1 = map(int,input().split())\n\na = abs(x1-x)\nb = abs(y1-y)\n\nk = (a**2 + b**2)**0.5\n\n\nk = math.ceil(k/(2*r))\nprint(k)",
"r,x1,y1,x2,y2=[int(x) for x in input().split()]\r\nd = ((x2-x1)**2 + (y2-y1)**2)**0.5\r\ncounter=0\r\nwhile counter * 2*r < d:\r\n\tcounter+=1\r\nprint(counter)",
"import sys\r\ninput=sys.stdin.readline\r\nr,x1,y1,x2,y2=map(int,input().split())\r\nd=((x2-x1)**2+(y2-y1)**2)**0.5\r\nif int(d)**2==int(((x2-x1)**2+(y2-y1)**2)):\r\n d=int(d)\r\n if d%(2*r)==0:print(d//(2*r))\r\n else:print(d//(2*r)+1)\r\nelse:\r\n print(int(1+d//(2*r)))",
"import math as mt\r\nr,x,y,xx,yy=[int(x) for x in input().split()]\r\n# print(r,x,y,xx,yy)\r\ntempx=abs(xx-x)\r\ntempy=abs(yy-y)\r\ndist=mt.sqrt(tempx*tempx+tempy*tempy)\r\n# print(dist)\r\ntemp=int(dist/(2*r))\r\n# print(dist,temp,r)\r\nif temp*2*r==dist:\r\n # print(\"up\")\r\n print(int(temp))\r\nelse: \r\n print(int(temp)+1)",
"from math import sqrt\r\nr, x, y, xx, yy = map(int, input().split()) \r\ndistance = sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y))\r\ndiameter = 2*r\r\nans = distance//diameter\r\nif distance%diameter!=0:\r\n ans+=1\r\nprint(round(ans)) ",
"from math import hypot, fabs, ceil\r\n\r\nd, xx, yy, x, y = map(int, input().split())\r\n\r\nd *= 2;\r\n\r\ndist = hypot(fabs(xx-x), (fabs(yy-y)))\r\n\r\nprint(ceil(dist/d))\r\n",
"import math\r\n\r\ndef main():\r\n r, x1, y1, x2, y2 = input().split()\r\n r = int(r)\r\n x1 = int(x1)\r\n x2 = int(x2)\r\n y1 = int(y1)\r\n y2 = int(y2)\r\n distance = math.sqrt(math.pow(abs(x1-x2), 2) + math.pow(abs(y1-y2), 2))\r\n print(math.ceil(distance/(2*r)))\r\n\r\nmain()",
"import math\r\nr,x1,y1,x2,y2=map(int,input().split(' '))\r\np=math.sqrt(((x2-x1)**2)+((y2-y1)**2))\r\nprint(math.ceil(p/(2*r)))",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Jun 5 12:39:16 2020\r\n\r\n@author: Anmol Singla\r\n\"\"\"\r\n\r\nfrom math import sqrt\r\nr,x,y,x1,y1=map(int,input().split())\r\nif(x==x1 and y==y1):\r\n print(0)\r\nelse:\r\n a=(x-x1)**2\r\n b=(y-y1)**2\r\n c=sqrt(a+b)\r\n if(c<=2*r):\r\n print(1)\r\n else:\r\n d=(c-r)\r\n s=d/(2*r)\r\n if((d-(int(s)*2*r))<=r):\r\n print(int(s)+1)\r\n else:\r\n print(int(s)+2)\r\n \r\n \r\n ",
"import math\r\nr, x, y, x1, y1 = map(int, input().split())\r\nresult = ((x1-x)**2+(y1-y)**2)**0.5\r\nprint(abs(math.ceil(result/(2*r))))\r\n\r\n",
"import math\na,b,c,d,e = map(int,input().split())\n\ndistance = math.hypot(b-d,c-e)\n\nprint(math.ceil(distance/(2*a)))\n",
"# 507B\r\nfrom math import ceil,sqrt\r\nt = input().split()\r\nt = list(map(int, t))\r\nr = t[0]\r\nx = t[1]\r\ny = t[2]\r\na = t[3]\r\nb = t[4]\r\nd = sqrt((x-a)**2+(y-b)**2)\r\nif d == 0:\r\n res = 0\r\nelse: \r\n if r>d:\r\n res = 1\r\n else:\r\n res = ceil(d/(2*r))\r\nprint(res)",
"import math\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nans3 = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)\r\nprint(int(-(-ans3 // (r+r))))",
"from math import ceil\r\n\r\nr, x, y, x1, y1 = map(int, input().split())\r\n\r\ns = ((x-x1)**2 + (y-y1)**2)**0.5\r\n\r\nprint(ceil(s/(2*r)))\r\n",
"def amr(r,x1,y1,x2,y2):\r\n\tx = x1-x2\r\n\ty = y1-y2\r\n\tdist = (x**2 + y**2)**(.5)\r\n\ti = 0 \r\n\twhile dist > 0:\r\n\t\tdist -= 2*r\r\n\t\ti += 1\r\n\treturn i\r\na = list(map(int, input().split()))\t\r\nprint(amr(a[0],a[1],a[2],a[3],a[4]))",
"from math import sqrt,ceil\r\n\r\n\r\nr, x, y, x1, y1 = [int(x) for x in input().split()]\r\n\r\nprint(ceil(sqrt((x - x1) ** 2 + (y - y1) ** 2) / (r * 2)))",
"import math\r\nr,x,y,X,Y=map(int,input().split())\r\nd=math.sqrt(math.pow(X-x,2)+math.pow(Y-y,2))\r\nprint(int(math.ceil(d/(2*r))))\r\n",
"import math\r\narr = list(map(int,input().split()))\r\nprint(math.ceil((math.sqrt((arr[3]-arr[1])*(arr[3]-arr[1])+(arr[4]-arr[2])*(arr[4]-arr[2])))/(2*arr[0])))",
"from bisect import bisect_right, bisect_left\r\nfrom math import inf, gcd, sqrt, ceil\r\nfrom collections import defaultdict, Counter\r\nfrom functools import cache, lru_cache\r\nrvar = lambda: map(int, input().split())\r\nrarr = lambda: list(map(int, input().split()))\r\nrstr = lambda: input().split()\r\nrint = lambda: int(input())\r\n\r\n'''Speed up'''\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nr, x, y, xx, yy = rvar()\r\n\r\ndist = sqrt((x - xx)**2 + (y - yy)**2)\r\n\r\nprint(ceil(dist/(2*r)))\r\n\r\n\r\n",
"import math\r\nr, x, y, x1,y1 = map(int, input().split())\r\nr =r *2\r\n\r\nk = math.sqrt(((x1 -x) *(x1 -x)) + ((y1 -y) *(y1 -y))) \r\n\r\nif(k == k//1 and (k//1) % r ==0):\r\n print(int(k//r))\r\nelse:\r\n print(int(k//r +1)) ",
"def solve(r, x, y, x1, y1):\n\tfrom math import ceil\n\t\n\tdis = ((x-x1)**2 + (y-y1)**2)**0.5\n\ti=0\n\tdcov =0\n\twhile dis > dcov:\n\t \ti+=1\n\t \tdcov += 2*r\n\treturn i\n\n\n \n\t\n \n\t\n\t\n \n \n \n \nfrom sys import stdin\ninput = stdin.readline\n \n\nr, x, y, x1, y1 =[int(x) for x in input().split()]\n \n \nprint(solve(r, x, y, x1, y1))",
"\r\nimport sys\r\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\r\nimport math\r\narr = get_ints()\r\n\r\nr = arr[0]\r\nx1 = arr[1]\r\ny1 = arr[2]\r\nx2 = arr[3]\r\ny2 = arr[4]\r\ndiff = math.sqrt((y2 - y1)*(y2 - y1) + (x2 - x1) * (x2 - x1))\r\nprint(math.ceil(diff/(2*r)))\r\n\r\n\r\n",
"from math import ceil\r\n\r\ndef solve():\r\n r, x1, y1, x2, y2 = map(int, input().split())\r\n print( ceil(((x2-x1)**2+(y2-y1)**2)**0.5/r/2) )\r\n\r\nif __name__ == \"__main__\":\r\n solve()",
"import math\r\nr, x, y, x1, y1 = map(int, input().split())\r\nprint(math.ceil(math.hypot(x1-x,y1-y)/(2*r)))\r\n",
"import math\r\nfrom math import sqrt\r\n\r\ndef check(distance,radius):\r\n\tx=(distance/(2*radius))\r\n\ty=math.ceil(x)\r\n\treturn y\r\n\r\n(r,x,y,x_1,y_1)=map(int,input().split(\" \"))\r\ndistance= sqrt((x-x_1)**2+(y-y_1)**2)\r\nprint(check(distance,r))\r\n",
"import math\n\nr, x, y, x1, y1 = map(int, input().split())\n\nprint(math.ceil(math.sqrt((x1 - x) ** 2 + (y1 - y) ** 2) / (2 * r)))",
"'''\r\nimport sys\r\ntry:\r\n sys.stdin = open('in.txt', 'r')\r\nexcept:\r\n pass\r\n'''\r\nimport math\r\n\r\ntemp = input().split(); r, x, y, a, b = [int(x) for x in temp]\r\nprint(int(math.ceil((math.sqrt((a - x) ** 2 + (b - y) ** 2) / (2 * r)))))",
"import math\r\n\r\nr, x, y, x1, y1 = map(int, input().split())\r\ndistance = math.sqrt((x - x1) ** 2 + (y - y1) ** 2)\r\nans = math.ceil(distance / (2 * r))\r\nprint(ans)",
"import math\r\n[r,x,y,x1,y1]= list(map(int,input().split()))\r\nd = ((x-x1)**2 + (y-y1)**2)**0.5\r\nif d==0:\r\n\tprint(0)\r\nelse:\r\n\te = d/(2*r)\r\n\tprint(math.ceil(e))",
"import math\r\nli = [int(x) for x in input().split()]\r\nr = li[0]\r\nx1= li[1]\r\ny1=li[2]\r\nxf = li[3]\r\nyf = li[4]\r\nu = math.sqrt((yf-y1)**2 + (xf-x1)**2)\r\nd = int(u//(2*r))\r\nif u%(2*r) !=0:\r\n d=d+1\r\nprint(d)",
"from math import ceil\nr, x1, y1, x2, y2 = map(int, input().strip().split())\ndist = ((y2-y1)**2 + (x2-x1)**2)**.5\nprint(ceil(dist/(2*r)))",
"import math\r\n(r, x1, y1, x2, y2) = tuple(map(int, input().split()))\r\nd = math.sqrt((x1-x2)**2+(y1-y2)**2)\r\ndiv = r*2\r\nif d % div == 0:\r\n print(int(d / div))\r\nelse:\r\n print(int(d // div + 1))",
"import math\nr,x,y,x_1,y_1 = map(int,input().split())\n\nmax = ((x_1-x)**2 + (y_1-y)**2)**0.5\nprint(int(math.ceil(max/(2*r))))\n",
"from math import ceil\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\ndist = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5\r\nprint(ceil(dist / (2 * r)))",
"from math import sqrt, pow, ceil\nfrom decimal import *\n\n#getcontext().prec = 10\n\n#l1 = int(input())\nl1 = input().split()\n#l2 = input()\n#l2 = input().split()\n\nl1 = [int(i) for i in l1]\n#l2 = [int(i) for i in l2]\n\n#cin >> r >> x1 >> y1 >> x2 >> y2;\nd = sqrt(pow(l1[3] - l1[1], 2) + pow(l1[4] - l1[2], 2));\nprint(ceil(d / l1[0] / 2));\n \t\t \t\t \t\t \t\t\t \t \t\t \t\t \t",
"import math\r\n\r\nr, x, y, x2, y2 = list(map(int, input().split()))\r\n\r\nd = math.dist((x, y), (x2, y2))\r\n\r\nprint(math.ceil(d / (2*r)))",
"from math import *\r\nr,x,y,x1,y1=map(int,input().split())\r\ndef dist(a,b,c,d):\r\n h = sqrt(pow(abs(c-a),2)+pow(abs(d-b),2))\r\n return h\r\n#print(dist(x,y,x1,y1))\r\nprint(ceil(dist(x,y,x1,y1)/(2*r)))",
"from math import ceil\r\nr,x1,y1,x2,y2 = map(int,input().split())\r\ndist = (((x2-x1)**2) + ((y2-y1)**2))**0.5\r\nans = ceil(dist/(2*r))\r\nprint(ans)",
"from math import ceil\r\nr,x,y,x1,y1 = map(int,input().split())\r\nd = (x1-x)**2 + (y1-y)**2\r\nd = ceil(d**0.5)\r\nprint(ceil(d/(2*r)))\r\n",
"import math\r\nr,x,y,x1,y1=list(map(int,input().split()))\r\ndistance=math.sqrt((x-x1)**2 +(y-y1)**2)\r\nprint(math.ceil(distance/(2*r)))",
"import math \r\nr,x,y,x1,y1=(map(int,input().split()))\r\nd=math.sqrt((x-x1)**2+(y-y1)**2)\r\ncount=math.ceil(d/(2*r))\r\nprint(count)",
"from math import ceil\r\nr, x, y, x1, y1 = map(int, input().split())\r\nprint(ceil(((x1 - x) ** 2 + (y1 - y) ** 2) ** .5 / (2 * r)))\r\n",
"import math\r\n\r\nr, x0, y0, x1, y1 = map(int, input().split(' '))\r\nh = (x0 - x1)**2 + (y0 - y1)**2\r\nh = math.sqrt(h)\r\nprint(math.ceil(h / (2*r)))\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\ndist=(abs(x1-x)**2+abs(y1-y)**2)**0.5\r\nprint( math.ceil(dist/(2*r)))",
"import math\r\n\r\narr=[int(x) for x in input().split()]\r\nr,x1,y1,x2,y2=arr[0],arr[1],arr[2],arr[3],arr[4]\r\nd=(((x2-x1)**2+(y2-y1)**2)**0.5)/r\r\nans=math.ceil(d/2)\r\nprint(ans)",
"from math import ceil;r,x,y,x1,y1=map(int,input().split());print(ceil(((x-x1)**2+(y-y1)**2)**0.5/(2*r)))",
"#print(\"codeforces Amr and pins B 1400\")\r\nimport math\r\nr,x1,y1,x2,y2 = map(int,input().split())\r\nd = math.sqrt((x2-x1)**2+(y2-y1)**2)\r\nres = math.ceil(d/(2*r))\r\nprint(res)",
"from sys import stdin, stdout\ndef read():\n\treturn stdin.readline().rstrip()\n\ndef read_int():\n\treturn int(read())\n \ndef read_ints():\n\treturn list(map(int, read().split()))\n \ndef solve():\n\tr,x,y,x1,y1=read_ints()\n\td2=(x-x1)**2+(y-y1)**2\n\tr2=4*r*r\n\t# sqrt(d2) <= k*sqrt(r2)\n\t# d2/r2 <= k*2\n\tl = (d2+r2-1)//r2\n\tk=0\n\twhile k*k<l:\n\t\tk+=1\n\tprint(k)\n\nsolve()\n",
"s=input()\r\na=s.split(' ')\r\nr=int(a[0])\r\nx=int(a[1])\r\ny=int(a[2])\r\nx1=int(a[3])\r\ny1=int(a[4])\r\ndist=pow(((x-x1)*(x-x1)+(y-y1)*(y-y1)),0.5)\r\nif(dist==0.0):\r\n print(0)\r\nelse:\r\n z=(dist/(2*r))\r\n if((z-int(z)==0.0)):\r\n print(int(z))\r\n else:\r\n print(int(z+1)) \r\n",
"import math\r\na = list(map(int,input().split()))\r\n\r\nb = a[3]-a[1]\r\nc = a[4]-a[2]\r\n\r\nd = (b**2 + c**2)**(1/2)\r\n\r\ne = math.ceil(d/(a[0]*2))\r\n\r\nprint(e)",
"import math\r\nr,a,b,c,d=map(int, input().split())\r\nx=abs((a-c)**2+(b-d)**2)**0.5\r\nr*=2\r\nprint(math.ceil(x/r))",
"from math import sqrt,log,ceil\r\nimport sys\r\n# sys.stdin=open('input.txt','r')\r\n# sys.stdout=open('output.txt','w')\r\nfrom random import randint as r\r\n\r\nr,x1,y1,x2,y2=map(int,input().split())\r\nt=(x1-x2)**2+(y1-y2)**2\r\nden=2*r\r\nprint(ceil(sqrt(t)/den))",
"from sys import stdin\r\nstdin.readline\r\ndef mp(): return list(map(int, stdin.readline().strip().split()))\r\ndef it():return int(stdin.readline().strip())\r\n\r\nfrom math import sqrt,ceil\r\nr,x,y,x1,y2=mp()\r\nd=sqrt((x1-x)**2+(y2-y)**2)\r\nprint(ceil(d/(2*r)))\r\n\r\n",
"import math\r\nr,a,b,c,d=map(int, input().split())\r\ndis=((c-a)**2+(d-b)**2)**0.5\r\nans=math.ceil(dis/(2*r))\r\n\r\nprint(int(ans))",
"from math import ceil\r\n\r\nclass Solution:\r\n def __init__(self):\r\n self.r, self.x, self.y, self.x_, self.y_ = [int(x) for x in input().split()]\r\n\r\n def solve_and_print(self):\r\n print(ceil(((abs(self.x_-self.x)**2 + abs(self.y_-self.y)**2)**0.5)/(self.r<<1)))\r\n\r\nif __name__ == \"__main__\":\r\n Solution().solve_and_print()",
"import math\r\nr,x1,y1,x2,y2=map(int,input().rstrip().split());r*=2\r\neuc=math.dist((x1,y1),(x2,y2))\r\nprint(math.ceil(euc/r))",
"from sys import stdin\r\n\r\nr, x1, y1, x2, y2 = map(int, stdin.readline().rstrip().split(\" \"))\r\nr = 2*r\r\n\r\ndistance = ((x2-x1)**2 + (y2-y1)**2)**0.5\r\n\r\nres = distance//r\r\nif distance%r:\r\n print(int(res+1))\r\nelse:\r\n print(int(res))",
"import math \r\ndef calculateDistance(x1,y1,x2,y2): \r\n dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2) \r\n return dist \r\ndef solve(r,x1,y1,x2,y2):\r\n x=calculateDistance(x1,y1,x2,y2)\r\n y=math.ceil(x/(2*r))\r\n print(y)\r\n\r\nR,X1,Y1,X2,Y2=[int(x) for x in input().split()]\r\nsolve(R,X1,Y1,X2,Y2);\r\n",
"import math\r\n\r\nr,x,y,x1,y1 = map(int,input().split())\r\n\r\ndist =math.sqrt((x-x1)**2 + (y-y1)**2)\r\n\r\nif dist != int (dist):\r\n dist = int (dist)+1 \r\nres = dist//(2*r)\r\nif (dist) % (2*r) != 0 :\r\n res = res +1\r\nprint ( int(res)) \r\n",
"from math import ceil\nr, x1, y1, x2, y2 = map(int, input().split())\nd = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5\nprint(ceil(d / (2 * r)))",
"r,n,m,x,y=[int(x) for x in input().split()]\r\nd=((n-x)**2+(y-m)**2)**0.5\r\n#print(d)\r\nif d%(2*r):\r\n print(int(d//(2*r)+1))\r\nelse:\r\n print(int(d//(2*r)))",
"import math\nvalues = input()\nvalues = values.split()\nr = int(values[0])\nx1 = int(values[1])\ny1 = int(values[2])\nx2 = int(values[3])\ny2 = int(values[4])\nform = math.sqrt(pow(y2 - y1, 2) + pow(x2 - x1, 2))\nprint(int(math.ceil(form / r / 2)))\n \n\n\t\t\t\t\t \t \t\t\t\t \t\t \t\t\t\t\t\t\t \t",
"import math\r\n\r\nr, x, y, x_d, y_d = map(int, input().split(\" \"))\r\n\r\ndist = (x_d - x) * (x_d - x) + (y_d - y) * (y_d - y)\r\n\r\ndist = math.sqrt(dist)\r\n\r\nans = math.ceil(dist / (2 * r))\r\n\r\nprint(ans)\r\n",
"import math\r\n\r\nr,x,y,nx,ny = map(int,input().split())\r\nprint(math.ceil(((nx-x)**2 + (ny-y)**2)**0.5 / (r*2)))",
"import math\r\nr, x, y, p, q = list(map(int, input().strip().split(' ')))\r\nprint(math.ceil((((p - x) ** 2 + (q - y) ** 2) ** 0.5) / (2 * r)))",
"\r\nfrom math import ceil,sqrt\r\nr,x,y,a,b=map(int,input().split())\r\np=sqrt((a-x)**2+(b-y)**2)\r\nprint(ceil(p/(2*r)))",
"from math import *\r\na,b,c,d,e=map(int,input().split())\r\nprint(ceil(hypot(b-d,c-e)/(2*a)))",
"import math\n\nq, x1, y1, x2, y2 = list(map(int,input().split()))\n\ndef distance(args):\n x1, x2, y1, y2 = args\n return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n\nd = distance([x1, x2, y1, y2])\n\nif d == 0:\n print(0)\nelse:\n print(math.ceil(d / (2 * q)))\n\n \t \t \t\t \t\t\t \t\t\t\t \t\t \t\t\t\t \t",
"from math import ceil\r\nr, x, y, x1, y1 = map(int, input().split())\r\nprint(ceil(((x1-x)**2+(y1-y)**2)**0.5/(2*r)))\r\n",
"from math import ceil as c\r\nr, x, y, x2, y2 = map(int, input().split())\r\n\r\nd = (((x2-x)**2) + ((y2-y)**2))**0.5\r\n\r\nprint(c(d/(2*r)))\r\n",
"import math\n\n[r, a, b, x, y] = [int(item) for item in input().split(' ')]\na -= x\na *= a\nb -= y\nb *= b\nsteps = int(math.ceil((math.sqrt(a + b)) / (2 * r)))\n\nprint(steps)\n",
"import math\r\nr,x1,y1,x2,y2=map(int,input().split())\r\nk=math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))\r\nprint(math.ceil(k/(2*r)))\r\n\r\n",
"l=list(map(int,input().split()))\r\nr=l[0]\r\n\r\nx1=l[1]\r\ny1=l[2]\r\nx2=l[3]\r\ny2=l[4]\r\nres=(((x2-x1)**2)+((y2-y1)**2))**0.5\r\nif res!=0 and res%int(res)!=0:\r\n res=int(res)+1\r\nc=res//(r*2)\r\nif res%(r*2)!=0:\r\n c+=1\r\nprint(int(c))",
"import math\r\nr,x,y,a,b = [int(x) for x in input().split(\" \")]\r\nd = ((a-x)**2+(b-y)**2)**.5\r\nif d==0: print(0)\r\nelse: print(math.ceil(d/(2*r)))",
"import math\r\nr, x, y, x1, y1 = map(int, input().split())\r\nans = 0\r\nt = math.sqrt(abs(x-x1)**2+abs(y-y1)**2)\r\nprint(math.ceil(t/(2*r)))\r\n",
"n,x,y,X,Y=map(int,input().split())\r\n'''\r\ndiff_x=abs(X-x)\r\ndiff_y=abs(Y-y)\r\ndiff=max(diff_x,diff_y)\r\nvalue=[]\r\nfor c in range(diff+1):\r\n\ta=(diff_x-c)/(2*n)\r\n\tb=(diff_y-c)/(2*n)\r\n\tv=abs(a)+abs(b)+abs(c)\r\n\tvalue.append(v)\r\nprint(int(min(value)))\r\n'''\r\ndistance=((X-x)**2+(Y-y)**2)**(0.5)\r\n\r\n#distance=4\r\n#n=1\r\n#print(distance)\r\nif distance==0:\r\n\tprint(0)\r\nif 0<distance<=n:\r\n\tprint(1)\r\nx=(distance-n)//(2*n)\r\ny=(distance-n)%(2*n)\r\n\r\nif 0<=y<=n and distance>n:\r\n\tprint(int(1+x))\r\nif y>n and distance>n:\r\n\tprint(int(2+x))",
"a,b,c,d,e=map(int,input().split()) \r\ndis=(e-c)**2 + (d-b)**2\r\ndis=dis**(0.5)\r\nprint (int(dis//(2*a)) if dis%(2*a)==0 else int(dis//(2*a)) +1)",
"import math\r\n\r\nr,x,y,x1,y1 = map(int, input().split())\r\nd = pow((x-x1)*(x-x1)+(y-y1)*(y-y1), 0.5)\r\n\r\nprint(math.ceil(d/(2*r)))\r\n",
"import math\r\nr, x, y, x1, y1 = map(int, input().split())\r\nr *= 2\r\nline = math.sqrt(abs(x-x1)**2+abs(y-y1)**2)\r\nprint(int(math.ceil(line/r)))",
"from math import ceil,sqrt \r\nr,x,y,x1,y1 = map(int,input().split())\r\nd = sqrt((x1-x)**2 + (y1-y)**2)\r\nprint(ceil(d/(2*r)))",
"import math\r\n\r\nr, x, y, xp, yp = map(int, input().split())\r\nprint((math.ceil(math.sqrt((xp-x)*(xp-x) + (yp-y)*(yp-y))) + 2*r - 1) // (2 * r))",
"import math\ndef dist(x,y,x1,y1):\n return ( (x-x1)**2 + (y-y1)**2 )**(0.5)\n\nr,x,y,xz,yz = [int(i) for i in input().split()]\n\nq = dist(x,y,xz,yz)\n\nprint(math.ceil(q/(2*r)))\n\n \t \t\t \t\t \t \t \t\t \t",
"from math import ceil, sqrt\r\nr,x,y,a,b = list(map(int, input().split()))\r\nd = sqrt((a-x)**2 + (b-y)**2)\r\nprint(ceil(d/(2*r)))",
"eps = 1e-10\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nk = ((x1-x2) ** 2 + (y1-y2) ** 2) ** .5\r\nr *= 2\r\nprint(int((k+r-eps) // r))\r\n",
"import math\n\naux = input().split(\" \")\nr = int(aux[0])\nx1 = int(aux[1])\ny1 = int(aux[2])\nx2 = int(aux[3])\ny2 = int(aux[4])\n\ndist = math.sqrt(math.pow(y2 - y1, 2) + math.pow(x2 - x1, 2))\nans = math.ceil(dist / r / 2)\nprint(ans)\n \t \t \t \t \t\t\t\t\t\t\t\t\t \t",
"import math\r\nr, x1,y1,x2,y2 = (int(x) for x in input().split())\r\n\r\nk = math.ceil(math.dist((x1,y1),(x2,y2))/(2*r))\r\nprint(k)",
"from math import sqrt,ceil\r\na = list(map(int, input().rstrip().split()))\r\nxd = abs(a[1]-a[3])\r\nyd = abs(a[2]-a[4])\r\ndist = sqrt(xd**2+yd**2)\r\nprint(ceil(dist/a[0]/2))\r\n",
"import math \r\ndef calculateDistance(x1,y1,x2,y2): \r\n dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2) \r\n return dist \r\n\r\nr,x,y,x1,y1=map(int,input().split())\r\n\r\nif x==x1 and y==y1:\r\n print(0)\r\nelse:\r\n print(math.ceil(calculateDistance(x,y,x1,y1)/(2*r)))\r\n",
"from math import sqrt,ceil\r\nr,x,y,a,b=map(int,input().split())\r\nd=sqrt((x-a)**2+(y-b)**2)\r\nprint(ceil(d/(2*r)))",
"import math\r\nr, x, y, a, b = tuple(map(int, input().split()))\r\ndis = math.sqrt(((x-a)*(x-a)) + ((y-b)*(y-b)))\r\nprint(math.ceil(dis/(2*r)))",
"import math\r\nfrom sys import stdin, stdout\r\ninput, print = stdin.readline, stdout.write\r\n\r\n\r\ndef main():\r\n r, x1, y1, x2, y2 = map(int, input().split())\r\n dist = math.sqrt(abs(x2-x1)**2+abs(y2-y1)**2)\r\n ans = math.ceil(dist/(2*r))\r\n print(str(ans) + \"\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"from math import *\r\nr,x,y,xd,yd=map(int,input().split())\r\nd=sqrt((x-xd)**2+(y-yd)**2)\r\nprint(ceil(d/(2*r)))",
"import sys\r\n#import bisect\r\nimport math\r\nimport itertools\r\ndef get_line(): return list(map(int,sys.stdin.readline().strip().split()))\r\ndef in1(): return int(input())\r\n\r\nr,x1,y1,x2,y2=get_line()\r\nt1=math.sqrt((x2-x1)**2+(y2-y1)**2)\r\nt2=t1//(2*r)\r\nif t1%(2*r)==0:\r\n print(int(t2))\r\nelse:\r\n print(int(t2)+1)\r\n",
"import sys\r\nimport math\r\nfrom sys import stdin, stdout\r\n \r\n# TAKE INPUT\r\ndef get_ints_in_variables():\r\n return map(int, sys.stdin.readline().strip().split())\r\ndef get_int(): return int(input())\r\ndef get_ints_in_list(): return list(\r\n map(int, sys.stdin.readline().strip().split()))\r\ndef get_list_of_list(n): return [list(\r\n map(int, sys.stdin.readline().strip().split())) for _ in range(n)]\r\ndef get_string(): return sys.stdin.readline().strip()\r\n \r\ndef main():\r\n # Write Your Code Here\r\n r, x1, y1, x2, y2 = get_ints_in_variables()\r\n # Acc. to distance formula geometry\r\n dist = math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))\r\n # divided by 2 bcoz every time we drew 2*r circumference circle\r\n res = math.ceil((dist)/(2*r))\r\n print(res)\r\n\r\n# calling main Function\r\nif __name__ == \"__main__\":\r\n main()",
"import math\r\ng=input()\r\nr,x,y,X,Y=[int(x) for x in g.split()]\r\nd=math.sqrt((X-x)**2+(Y-y)**2)\r\nl=1\r\nif d==0:\r\n\tprint(\"0\")\r\nelif (2*r)>=d:\r\n\tprint(\"1\")\r\nelse:\r\n\twhile (2*r)<d:\r\n\t\tl+=1\r\n\t\td=d-2*r\t\t\r\n\tprint(l)\t",
"# Amr and Pins\r\nr,x,y,a,b = map(int,input().split(\" \"))\r\nd = ((x-a)**2 + (y-b)**2)**0.5\r\nsteps = (d/(r*2))\r\nif steps != int(steps):\r\n steps = int(steps) + 1\r\nprint(int(steps))",
"import math\r\nr, x, y, x1, y1 = map(int, input().split())\r\n\r\nprint(int(-(math.sqrt((x1-x)**2 + (y1-y)**2) // (-2*r))))\r\n",
"r,x,y,a,b=map(int,input().split())\r\nn=(((x-a)**2+(y-b)**2)**0.5)/(2*r)\r\nif n==int(n):\r\n print(int(n))\r\nelse:\r\n print(int(n+1))",
"\r\nfrom math import ceil\r\n\r\n\r\nr,x1,y1,x2,y2 = map(int,input().split())\r\n\r\nd = (abs(x1-x2)**2 + abs(y1-y2)**2)**0.5\r\n\r\nprint(ceil(d/(2*r)))\r\n\r\n\r\n",
"r,x1,y1,x2,y2=map(int,input().split())\r\ndist=((x1-x2)**2+(y1-y2)**2)**.5\r\nfrom math import ceil\r\nprint(ceil(dist/(2*r)))",
"import math\r\nr, x, y, tX, tY = map(int, input().split(' '))\r\nr *= 2\r\ndistance = math.sqrt((x - tX) * (x - tX) + (y - tY) * (y - tY))\r\nprint(math.ceil(distance / r))\r\n",
"from math import ceil,sqrt\r\nr,x,y,a,b = map(int,input().split())\r\nprint(ceil(sqrt((x-a)**2+(y-b)**2)/(2*r)))",
"from math import sqrt, ceil\r\ncin = [*open(0)][0].split()\r\nr, x, y, xp, yp = map(int, cin)\r\nd = sqrt((xp-x)**2 + (yp-y)**2)\r\nprint(int(ceil(d/r/2.)))",
"from math import sqrt, ceil\r\n(r1, x1, y1, x11, y11) = input().split()\r\nr = int(r1)\r\nx = int(x1)\r\ny = int(y1)\r\ns = int(x11)\r\nf = int(y11)\r\nh = sqrt ( (x - s) ** 2 + (y -f) ** 2)\r\ni = (h // (2 * r)) \r\nq = h % r\r\nb = int(i)\r\nif q != 0 or h % 2*r != 0:\r\n print(b + 1)\r\nelse:\r\n \r\n print(b)\r\n",
"import math\r\n\r\nr,x,y,a,b = list(map(float, str(input()).split(\" \")))\r\ndist = math.sqrt((a-x)*(a-x) + (b-y)*(b-y))\r\nans = math.ceil(dist/(2*r))\r\nprint(ans)\r\n",
"from math import *\r\nr,x,y,x2,y2 = [int(a) for a in input().split() ]\r\n\r\nd = sqrt((x2-x)**2 + (y2-y)**2 ) \r\nres = ceil(d / (2*r) ) \r\nprint(res)\r\n# print(ceil(3),ceil(3.2),floor(3),floor(3.2) )\r\n\r\n\r\n",
"import math\r\na = [int(i) for i in input().split()]\r\nb = math.sqrt((a[1] - a[3]) ** 2 + (a[2] - a[4]) ** 2)\r\nprint(math.ceil(b / (2 * a[0])))",
"#*****************************************************************************\n#* __ ________ __________ __________ __ __ *\n#* | | | | ||_________| ||________| || || *\n#* | | | | || || || || *\n#* | | |________| || || || || *\n#* | | |________| || ______ || ______ || || *\n#* ___| | | | ||____| | | | ||_____| | | | ||______|| *\n#*|______| | | ||______| |_| ||_______| |_| ||______|| *\n#* *\n#******************************************************************************\n\n\nfrom collections import defaultdict as D\nfrom math import *\nfrom sys import stdin, stdout\n\nMOD = 10**9+7\nMAX = 10**18+1\nMIN = -MAX\n\ndef reshape(count, val=0): return [ val for i in range(count) ]\n\ndef vec_read(): return list(map(int,stdin.readline().split()))\n\ndef read(): return map(int,stdin.readline().split())\n\ndef get_string(): return stdin.readline().strip()\n\n\n##################################################\n\ndef solve():\n # Logic Starts Here\n r,x1,y1,x2,y2=read()\n d = ( (x1-x2)**2 + (y1-y2)**2 )**0.5\n print(ceil(d/(2*r)))\n\ndef test_cases():\n t = int(input())\n while t:\n solve()\n t-=1\n\n## Driver Code\nif __name__ == '__main__':\n # test_cases()\n solve()",
"from math import sqrt\r\n\r\n\r\ndef main():\r\n r, x, y, x1, y1 = map(int, input().split())\r\n\r\n if x == x1 and y == y1:\r\n print(0)\r\n return\r\n\r\n distance = sqrt((x1 - x) ** 2 + (y1 - y) ** 2)\r\n steps = int(distance / (2 * r))\r\n if abs(distance - steps * 2 * r) < 10 ** -8:\r\n print(steps)\r\n else:\r\n print(steps + 1)\r\n\r\n\r\nmain()\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nprint(math.ceil(((x-x1)**2+(y-y1)**2)**.5/(2*r)))",
"r,x,y,X,Y=[int(e) for e in input().split()]\r\nif x==X and y==Y:\r\n print(0)\r\nelse:\r\n dx=X-x\r\n dy=Y-y\r\n d=dx*dx+dy*dy\r\n L=1\r\n R=d\r\n while R>L+1:\r\n M=(L+R)//2\r\n if (2*r*M)**2>=d:\r\n R=M\r\n else:\r\n L=M\r\n if (2*r*L)**2>=d:\r\n print(L)\r\n else:\r\n print(R)",
"import math\r\n\r\ndef no_of_steps(r,xi,yi,xf,yf):\r\n distance = math.sqrt((xf-xi)**2+(yf-yi)**2)\r\n if distance%(2*r) == 0:\r\n return int(distance)//(2*r)\r\n else:\r\n return (int(distance)//(2*r)) + 1\r\n\r\ndata = list(map(int, input().split()))\r\nr = data[0]\r\n(xi,yi) = (data[1],data[2])\r\n(xf,yf) = (data[3],data[4])\r\nprint(no_of_steps(r,xi,yi,xf,yf))",
"import math\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nprint(math.ceil(math.dist((x1, y1), (x2, y2)) / (2 * r)))\r\n",
"r,x,y,xp,yp = list(map(int,input().split()))\r\n\r\nans = ((x-xp)**2+(y-yp)**2)**.5\r\nimport math\r\nprint(math.ceil(ans/r/2))\r\n\r\n",
"import math\n\nentrada = input().split()\n\nr = int(entrada[0])\nx1 = int(entrada[1])\ny1 = int(entrada[2])\nx2 = int(entrada[3])\ny2 = int(entrada[4])\n\nd = math.sqrt(pow(y2 - y1, 2) + pow(x2 - x1, 2))\n\nprint(math.ceil(d / r / 2))\n\t \t\t \t\t\t\t\t \t \t\t\t\t\t \t \t\t \t\t \t",
"import math\r\nr, x, y, x1, y1 = [int(var) for var in input().split()]\r\nd=math.sqrt((x1-x)**2+(y1-y)**2)\r\nval=d/(r*2)\r\nif val==round(val):\r\n print(int(val))\r\nelse:\r\n print(int(val)+1)\r\n",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\nd=math.sqrt((x1-x)**2 + (y1-y)**2)\r\nprint(math.ceil(d/(2*r)))",
"from math import ceil, hypot\n\nr, x0, y0, x1, y1 = map(int, input().split())\nprint(ceil(hypot(x0 - x1, y0 - y1) / (2 * r)))\n",
"import math\nr, x, y, xNew, yNew = (int(x) for x in input().split())\nprint(math.ceil(math.hypot(xNew - x, yNew - y)/(2 * r)))\n\n\t \t \t \t \t \t\t\t\t\t\t\t \t\t",
"import math\r\nl = list(map(int, input().split()))\r\nr = l[0]\r\nx = l[1]\r\ny = l[2]\r\na = l[3]\r\nb = l[4]\r\nd = math.sqrt(((x-a)**2)+((y-b)**2))\r\nif d == 0:\r\n print(0)\r\nelif d > 0:\r\n if d % (2*r) == 0:\r\n print(int((d)/(2*r)))\r\n else:\r\n z = ((d)//(2*r)) + 1\r\n print(int(z))\r\n",
"import math\r\nr,x,y,a,b=[int(i) for i in input().split(\" \")]\r\ndist=((a-x)**2+(b-y)**2)**.5\r\nr*=2\r\nif dist==0:\r\n print(0)\r\nelse:\r\n print(math.ceil(dist/(r)))",
"import math\r\ndef sqr(x):\r\n return x*x;\r\nr,x1,y1,x2,y2 = input().split()\r\nd = math.sqrt(sqr(int(x1)-int(x2))+sqr(int(y1)-int(y2)))\r\nprint(math.ceil(d/(2*int(r))))",
"import math\r\nl=list(map(int,input().split()))\r\nd=((l[4]-l[2])**2 +(l[3]-l[1])**2)**0.5\r\n#print(d)\r\n#print(d)\r\nm=(d/l[0]/2)\r\n#print(m)\r\nm=math.ceil(m)\r\n#m=int(m)\r\nprint(int(m))\r\n",
"import sys,math\r\nfrom itertools import groupby\r\nsys.setrecursionlimit(1000000000)\r\nlines = []\r\nfor Line in sys.stdin:\r\n lines.append(Line.rstrip('\\n'))\r\n\r\n\r\n# lines=[\"4 5 6 5 6\"]\r\n\r\n\r\nr,x,y,x1,y1=list(map(int,lines[0].split()))\r\ndel(lines[0])\r\n\r\nd=math.sqrt(((x1-x)**2)+((y1-y)**2))\r\n#print(d,2)\r\nm=d/(r*2)\r\nif (m>round(m)):\r\n\tprint(round(m+1))\r\nelse:\r\n\tprint(round(m))",
"import math\r\ndef distance(x1 , y1 , x2 , y2): \r\n \r\n # Calculating distance \r\n return math.sqrt(math.pow(x2 - x1, 2) +\r\n math.pow(y2 - y1, 2) * 1.0)\r\n \r\ninp = list(map(int,input().split()))\r\nr,x1,y1,x2,y2 = inp[0],inp[1],inp[2],inp[3],inp[4]\r\n\r\ndist = distance(x1,y1,x2,y2)\r\nfinal = math.ceil(dist/(2*r))\r\nprint(final)\r\n",
"import math\r\nt = list(map(float,input().split()))\r\nprint(int(math.ceil((abs(t[3]-t[1])**2+abs(t[4]-t[2])**2)**(1/2)/t[0]/2)))\r\n",
"r, x, y, x1,y1=map(int,input().split())\r\nd=((x-x1)**2+(y-y1)**2)**0.5\r\nif d%(2*r)==0:print(int(d//(2*r)))\r\nelse:print(int((d//(2*r)+1)))\r\n",
"import math\r\nr, a, b, c, d = map(int, input().split())\r\ndist = math.sqrt((a - c) * (a - c) + (b - d) * (b - d))\r\nprint(math.ceil(dist / r / 2))",
"r,x,y,x1,y1=map(int,input().split())\r\nd=2*r\r\nif x==x1 and y==y1:\r\n print(0)\r\nelse:\r\n a=(x-x1)*(x-x1)+(y-y1)*(y-y1)\r\n a=a**0.5\r\n if a==int(a):\r\n if int(a)%d==0:\r\n print(int(a//d))\r\n else:\r\n print(int(a//d)+1)\r\n else:\r\n print(int(a//d)+1)\r\n",
"import math\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nprint(math.ceil(math.sqrt((x2-x1)**2+(y2-y1)**2)/(2*r)))\r\n",
"from collections import defaultdict, deque, Counter, OrderedDict\r\n# import threading,sys\r\nimport math\r\n\r\n\r\ndef main():\r\n r, a, b, x, y = [int(i) for i in input().split()]\r\n dist = (float(x - a)**2 + float(y - b)**2) ** 0.5\r\n ans = math.ceil(dist / (2 * r))\r\n print(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n \"\"\"sys.setrecursionlimit(400000)\r\n threading.stack_size(40960000)\r\n thread = threading.Thread(target=main)\r\n thread.start()\"\"\"\r\n main()\r\n",
"k = input()\r\na1 = int(k.split(\" \")[0])\r\na2 = int(k.split(\" \")[1])\r\na3 = int(k.split(\" \")[2])\r\na4 = int(k.split(\" \")[3])\r\na5 = int(k.split(\" \")[4])\r\ndist = ((a5-a3)**2 + (a4-a2)**2)**0.5\r\nif dist % (2*a1) == 0:\r\n print (int(dist//(2*a1)))\r\nelse:\r\n print(int((dist//(2*a1))+1))",
"from math import *\r\nr,x,y,x1,y1 = map(int,input().split())\r\nd = sqrt(((x-x1)**2) + ((y-y1)**2))\r\nn = 2 * r\r\np = ceil(d/n)\r\nprint(p)",
"from math import ceil\r\n\r\nr, a, b, c, d = map(float, input().split())\r\n\r\ndistance = ((d-b)**2 + (c-a)**2)**0.5\r\ntimes = distance / (2*r)\r\n\r\nprint(int(ceil(times)))",
"import math\r\n\r\nr, x1, y1, x2, y2 = map(int, input().split())\r\nprint(math.ceil(math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/(2*r)))\r\n",
"#I = lambda: [int(i) for i in input().split()]\r\n#import io, os, sys\r\n#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\n\r\n#sys.stdin = open(\"input.txt\", \"r\")\r\n#sys.stdout = open(\"output.txt\", \"w\")\r\n# n = int(input())\r\n# l = list(map(int,input().split()))\r\n# n,x = map(int,input().split())\r\n# mod = 1000000007\r\nimport math\r\nr,x1,y1,x2,y2 = map(int,input().split())\r\nd = math.sqrt((x1-x2)**2+(y1-y2)**2)\r\n\r\nif d.is_integer() and int(d)%(2*r)==0:\r\n print(int(d//(2*r)))\r\nelse:\r\n\r\n print(int(d//(2*r))+1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"import math\nr,x0,y0,x1,y1=map(int,input().split())\ndist=math.sqrt((x1-x0)**2+(y1-y0)**2)\nprint(math.ceil(dist/(2*r)))",
"import math\nr, x, y, x1, y1= map(float, input().split())\nprint(math.ceil(math.hypot(x1-x, y1-y)/(2*r)))\n\t \t \t\t\t\t\t\t \t \t \t",
"import math \r\nfrom collections import defaultdict,deque\r\nfrom bisect import bisect_left,bisect_right\r\nr,x,y,x1,y1=map(int,input().split())\r\nd=math.sqrt((x-x1)**2 + (y-y1)**2)\r\nprint( math.ceil(d/(r+r)))\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Dec 2 18:52:00 2019\r\n\r\n@author: lfy\r\n\"\"\"\r\n\r\nimport math\r\n\r\ndef pin(r,x,y,x_,y_):\r\n l=math.sqrt((x_-x)**2+(y_-y)**2)\r\n a=(l-2*r)/(2*r)\r\n if a==int(a):\r\n return int(a+1)\r\n else:\r\n return int(a+2)\r\ndef main():\r\n il=input().split()\r\n print(pin(float(il[0]),float(il[1]),float(il[2]),float(il[3]),float(il[4])))\r\nif __name__==\"__main__\":\r\n main()",
"import math\r\n\r\ns = input()\r\nr, x, y, x1, y1 = s.split(\" \")\r\nr = int(r)\r\nx = int(x)\r\ny = int(y)\r\nx1 = int(x1)\r\ny1 = int(y1)\r\n\r\nd = math.sqrt((x1 - x) ** 2 + (y1 - y) ** 2)\r\nres = math.ceil(d / (2 * r))\r\nprint(res)\r\n",
"import math\r\nr,x,y,a,b = map(int,input().split())\r\ntemp = math.sqrt((x-a)**2 + (y-b)**2) \r\nprint(math.ceil(temp/(2*r))) ",
"import math \r\nr,x1,y1,x2,y2=map(int,input().split())\r\na=abs(x2-x1)\r\nb=abs(y2-y1)\r\nz=((a*a)+(b*b))**0.5\r\nk=math.ceil(z/(2*r))\r\nprint(k)",
"import math\r\n\r\nr, x, y, p, q = map(int, input().split())\r\n\r\n\r\ndist = math.sqrt((x-p)**2 + (y-q)**2)\r\n\r\nprint(math.ceil(dist/(2*r)))\r\n",
"import math\r\n\r\n\r\ndef find_min_steps(r, x0, y0, x1, y1):\r\n distance = math.sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2)\r\n return math.ceil(distance / (r * 2))\r\n\r\n\r\nif __name__ == '__main__':\r\n r, x0, y0, x1, y1 = map(int, input().strip().split(' '))\r\n print(find_min_steps(r, x0, y0, x1, y1))",
"import math as m\r\n\r\nr, x, y, x1, y1 = [int(i) for i in input().split()]\r\nprint(m.ceil(m.sqrt(((x - x1) ** 2) + ((y - y1) ** 2)) / (2 * r)))",
"import math\r\nr,x,y,x1,y1=map(int,input().split())\r\ndis=math.sqrt((x-x1)**2 +(y-y1)**2)\r\nfd=dis\r\nans1=int(fd/(2*r))\r\nans2=fd%(2*r)\r\nif ans2>0:\r\n print(ans1+1)\r\nelse:\r\n print(ans1)",
"import math\r\nr,sx,sy,gx,gy=[int(x) for x in input().split()]\r\ndistsq=(sx-gx)**2 + (sy-gy)**2\r\noperations=math.ceil(math.sqrt(distsq/(4*r*r)))\r\n# if operations*operations*4*r*r==distsq:\r\n# print(operations)\r\nprint(operations)"
] | {"inputs": ["2 0 0 0 4", "1 1 1 4 4", "4 5 6 5 6", "10 20 0 40 0", "9 20 0 40 0", "5 -1 -6 -5 1", "99125 26876 -21414 14176 17443", "8066 7339 19155 -90534 -60666", "100000 -100000 -100000 100000 100000", "10 20 0 41 0", "25 -64 -6 -56 64", "125 455 450 439 721", "5 6 3 7 2", "24 130 14786 3147 2140", "125 -363 176 93 330", "1 14 30 30 14", "25 96 13 7 2", "4 100000 -100000 100000 -100000", "1 3 4 2 5", "1 -3 3 2 6", "2 7 20 13 -5", "1 1 1 1 4", "249 -54242 -30537 -45023 -89682", "4 100000 -100000 100000 -99999", "97741 23818 78751 97583 26933", "56767 -29030 51625 79823 -56297", "98260 13729 74998 23701 9253", "67377 -80131 -90254 -57320 14102", "1 100000 100000 100000 -100000", "19312 19470 82059 58064 62231", "67398 -68747 -79056 -34193 29400", "91099 37184 -71137 75650 -3655", "46456 -2621 -23623 -98302 -99305", "100 100000 -100000 100000 -99999", "1 100000 -100000 100000 -100000", "8 0 0 0 32", "100000 100000 1 -100000 0"], "outputs": ["1", "3", "0", "1", "2", "1", "1", "8", "2", "2", "2", "2", "1", "271", "2", "12", "2", "0", "1", "3", "7", "2", "121", "1", "1", "2", "1", "1", "100000", "2", "1", "1", "2", "1", "0", "2", "2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 469 | |
309df1bdd3f15ef54a7d1d973fe42330 | Fence | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible.
Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
Sample Input
7 3
1 2 6 1 1 7 1
Sample Output
3
| [
"from sys import stdin, stdout\n\n\ndef input():\n return stdin.readline().strip()\n\n\ndef print(string):\n return stdout.write(str(string) + \"\\n\")\n\n\ndef main():\n n, k = map(int, input().split())\n h = [int(x) for x in input().split()]\n dp = [None] * n\n dp[0] = sum(h[:k])\n smallest_i = 0\n for i in range(n-k):\n dp[i+1] = dp[i] - h[i] + h[i+k]\n if dp[i+1] < dp[smallest_i]:\n smallest_i = i+1\n print(smallest_i+1)\n\n\nif __name__ == \"__main__\":\n main()\n",
"def fence(data, k):\r\n prev=sum(data[:k])\r\n index=1\r\n total=prev\r\n for i in range(k,len(data)):\r\n total-=data[i-k]\r\n total+=data[i]\r\n if total<prev:\r\n prev=total\r\n index=i-k+2\r\n return index\r\ndef main():\r\n n, k = list(map(int, input().split()))\r\n data = list(map(int, input().split()))\r\n print(fence(data,k))\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n,k = list(map(int,input().split()))\r\narr = list(map(int,input().split()))\r\n\r\nlst = []\r\nlst.append(sum(arr[:k]))\r\nfor i in range(k,n):\r\n lst.append(lst[-1]+arr[i]-arr[i-k])\r\nmn = min(lst)\r\nprint(lst.index(mn)+1)\r\n\r\n",
"\r\nn, k = map(int, input().split())\r\nz = list(map(int, input().split()))\r\ndp = [10**8 for _ in range(n)]\r\ndp[k-1] = sum(z[:k])\r\n\r\nfor i in range(k, n):\r\n dp[i] = min(dp[i], dp[i-1] + z[i] - z[i-k])\r\n\r\ninx = dp.index(min(dp))\r\nprint(inx-k+2)",
"n,piano =map(int,input().split())\r\npiano-=1\r\ndef prefix_sum(array):\r\n for i in range(1,n+1):\r\n array[i]+=array[i-1]\r\narray = [0]+list(map(int,input().split()))\r\ndef get_sum(l,r):\r\n return array[r] - array[l-1]\r\nprefix_sum(array)\r\nminimum_index = 0\r\nminimum_value_ever = float('inf')\r\nfor m in range(1,n+1-piano):\r\n temp =get_sum(m,m+piano)\r\n if temp<minimum_value_ever:\r\n minimum_value_ever =temp\r\n minimum_index = m\r\nprint(minimum_index)",
"n,k=list(map(int,input().split()))\r\nheights=list(map(int,input().split()))\r\ni=0\r\nr=k-1\r\nmx=float('inf')\r\nj=-1\r\nsm=sum(heights[i:r+1])\r\nwhile r<n:\r\n if mx>sm:\r\n mx=sm\r\n j=i\r\n sm-=heights[i] \r\n i+=1\r\n \r\n r+=1\r\n if r<n:\r\n sm+=heights[r]\r\nprint(j+1) ",
"w,dis=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nbrefix=[0]*(w)\r\nfor i in range(w):\r\n brefix[i]=brefix[i-1]+x[i]\r\nthesum=999999999999999999999999\r\nind=1\r\nfor i in range(w-dis+1):\r\n \r\n if i==0:\r\n val=brefix[dis-1]\r\n else:\r\n val=brefix[dis-1]-brefix[i-1]\r\n\r\n if val<thesum:\r\n thesum=val\r\n ind=i+1\r\n dis+=1\r\nprint(ind)",
"n , k = map(int , input().split())\r\narr = list(map(int , input().split()))\r\ntotal = 0\r\nlast = 0\r\nind = 0\r\nfor i in range(k):\r\n last += arr[i]\r\ntotal = last\r\nfor i in range(n - k):\r\n last = last - arr[i] + arr[i + k]\r\n if last < total:\r\n total = last\r\n ind = i + 1\r\nprint(ind + 1)",
"n, k = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\n\r\ndp = [0] * (n + 1)\r\n\r\nfor i in range(1, n + 1):\r\n dp[i] = dp[i - 1] + a[i - 1]\r\n\r\nm = 10 ** 9\r\nidx = 0\r\nfor i in range(k, n + 1):\r\n if (dp[i] - dp[i - k]) < m:\r\n m = dp[i] - dp[i - k]\r\n idx = i - k + 1\r\n\r\nprint(idx)",
"n,k=map(int,input().split())\r\nL=list(map(int,input().split()))\r\na=sum(L[:k])\r\nf=sum(L[:k])\r\ni=0\r\nfor j in range(1,n-k+1):\r\n if L[j-1]<=L[j+k-1]:\r\n f=f-L[j-1]+L[j+k-1]\r\n else:\r\n f=f-L[j-1]+L[j+k-1]\r\n if a<=f:\r\n pass\r\n else:\r\n a=f\r\n i=j\r\nprint(i+1)",
"import math\r\n\r\ntestInput = input().split(\" \")\r\nn = int(testInput[0])\r\nk = int(testInput[1])\r\nminHeight = math.inf\r\nheightInput = input().split(\" \")\r\nheight = 0\r\nheightArray = []\r\nfor i in range(k):\r\n height += int(heightInput[i])\r\nheightArray.append(height)\r\n\r\nfor i in range(1, n-k+1):\r\n heightArray.append(heightArray[i-1])\r\n heightArray[i] -= int(heightInput[i-1])\r\n heightArray[i] += int(heightInput[i+k-1])\r\n\r\n\r\nminHeight = math.inf\r\nminIndex = 0\r\nfor i in range(len(heightArray)):\r\n if heightArray[i] < minHeight:\r\n minHeight = heightArray[i]\r\n minIndex = i\r\n\r\nprint(minIndex+1)\r\n ",
"def sufixsum (arr , start , end):\r\n return arr[end] - arr[start-1]\r\nn , k = map(int , input().split())\r\nl = list(map(int , input().split()))\r\narr_sum = [0] + [l[0]] \r\nfor i in range(1,n) : \r\n arr_sum.append(l[i] +arr_sum[-1]) \r\ni = 1\r\nx =[] \r\nwhile i + k - 1 <= len(l) :\r\n x.append(sufixsum(arr_sum , i , i + k -1 ))\r\n i+=1 \r\nprint(x.index(min(x)) + 1 )",
"n, k = map(int, input().split())\r\narr = list(map(int, input().split(' ')))\r\nl, r = 0, k - 1\r\npref = sum(arr[l:k])\r\nans = float('inf')\r\nstart = 0\r\nwhile r < n:\r\n if pref < ans:\r\n ans = pref\r\n start = l\r\n pref -= arr[l]\r\n l += 1 \r\n r += 1\r\n if r < n:\r\n pref += arr[r]\r\n\r\nprint(start + 1)",
"n, k = map(int, input().split())\n\nl_h = list(map(int, input().split()))\n\ns = [l_h[0]] + [0] * (n - 1)\nfor i in range(1, len(l_h)):\n s[i] = s[i - 1] + l_h[i]\n\nm_h = None\nm_i = 0\nfor i in range(n - k + 1):\n if not m_h:\n m_h = s[i + k - 1] - s[i] + l_h[i]\n m_i = i\n else:\n if m_h > s[i + k - 1] - s[i] + l_h[i]:\n m_h = s[i + k - 1] - s[i] + l_h[i]\n m_i = i\n\nprint(m_i + 1)\n",
"n,k = map(int,input().split())\ns = list(map(int,input().split()))\na = sum(s[:k])\nb = 0\nc = a\nfor i in range(n-k):\n\td = a-s[i]+s[i+k]\n\tif d<c:\n\t\tb=i+1\n\t\tc = d\n\ta = d\nprint(b+1)\n \t \t\t\t \t \t\t\t \t\t\t\t \t \t\t \t \t",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\nmin = 2148000\r\nans = 0\r\nfor i in range(1, n):\r\n h[i] += h[i-1]\r\nfor i in range(n-k+1):\r\n if h[i+k-1] - h[i-1] < min and i > 0:\r\n min = h[i+k-1] - h[i-1]\r\n ans = i+1\r\n elif i == 0:\r\n min = h[i+k-1]\r\n ans = i+1\r\nprint(ans)\r\n",
"n, k = map(int, input().split())\r\nplanks = [int(i) for i in input().split()]\r\nprefix = [0]\r\nsum = 0\r\nfor i in planks:\r\n sum += i\r\n prefix.append(sum)\r\n\r\nidx = []\r\nfor i in range(n-k+1):\r\n idx.append((prefix[i+k] - prefix[i], i))\r\n\r\nidx.sort(key=lambda x: x[0])\r\nprint(idx[0][1]+1)\r\n",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nmini = temp = sum(a[:k])\r\n\r\nj = 0\r\nans = 0\r\nfor i in range(k, n):\r\n temp = temp + a[i] - a[j]\r\n if mini > temp:\r\n mini = temp\r\n ans = j + 1\r\n j += 1\r\n\r\nprint(ans + 1)\r\n",
"n, k = [int(x) for x in input().split()]\nl = [int(x) for x in input().split()]\n \ns = sum(l[0:k])\nt = s\nind=1\nfor i in range(k, n):\n\tt -=l[i-k]\n\tt +=l[i]\n\tif t<s:\n\t\ts = t\n\t\tind = i-k+2\nprint(ind)\n \t \t \t \t\t\t \t \t \t \t\t\t \t\t",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\n\r\nmin_sum = sum(h[:k])\r\ncurrent_sum = min_sum\r\nmin_index = 0\r\n\r\nfor i in range(k, n):\r\n current_sum = current_sum - h[i-k] + h[i]\r\n if current_sum < min_sum:\r\n min_sum = current_sum\r\n min_index = i-k+1\r\n\r\nprint(min_index+1)",
"n,k = map(int,input().split())\r\nh = list(map(int,input().split()))\r\ns = sum(h[:k])\r\ni = 1\r\na=s\r\nfor j in range(n-k):\r\n s = s+h[j+k]-h[j]\r\n if s < a:\r\n i=j+2\r\n a=s\r\nprint(i)",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = 1\r\nmn = s = sum(a[:k])\r\nfor i in range(k, n):\r\n s = s + a[i] - a[i - k]\r\n \r\n if s < mn:\r\n mn = s\r\n ans = i - k + 2\r\nprint(ans)\r\n\r\n\r\n",
"n,k = input().split()\r\nn = int(n)\r\nk = int(k)\r\nnumbers =list(map(int,input().split()))\r\nleft = 0\r\nwindowSum = 0\r\nans = 0\r\nresult = []\r\nminVal = float('inf')\r\nfor right in range(n):\r\n windowSum += numbers[right]\r\n if (right+1) - left == k:\r\n if windowSum < minVal:\r\n minVal = windowSum\r\n ans = left + 1\r\n windowSum -= numbers[left]\r\n left += 1\r\nprint(ans)",
"n, k = [int(x) for x in input().split()]\r\nfence = [int(x) for x in input().split()]\r\nans = [0] * (n-k+1)\r\nans[0] = sum(fence[:k])\r\nfor i in range(1, n-k+1):\r\n su = ans[i-1] + fence[i+k-1] - fence[i-1]\r\n ans[i] = su\r\nmini = min(ans)\r\nprint(ans.index(mini)+1)",
"x = [int(x) for x in input().split()]\r\nn = x[0]\r\nk = x[1]\r\nh = [int(x) for x in input().split()]\r\nf = [0 for i in range(n)]\r\n\r\nfor i in range(k):\r\n f[i] = h[i]\r\n\r\nif n == k:\r\n print(\"1\")\r\nelse:\r\n f[k-1] = sum(f)\r\n total = f[k-1]\r\n ans = k-1\r\n for i in range(k,n):\r\n f[i] = f[i-1] + h[i] - h[i-k]\r\n if f[i] < total:\r\n total = f[i]\r\n ans = i\r\n\r\n print(ans + 2 - k)\r\n\r\n\r\n",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\nm = t = sum(h[:k])\r\na = 1\r\nfor i in range(k, n):\r\n t += h[i] - h[i - k]\r\n if t < m: a = i - k + 2;m = t\r\nprint(a)\r\n",
"n,k = map(int,input().split())\r\nhMin = 0\r\nhSum = 0\r\nans = 1\r\nhList = list(map(int,input().split()))\r\nfor i in range(n):\r\n if i<k:\r\n hSum += hList[i]\r\n if i==k-1:\r\n hMin = hSum\r\n else:\r\n hSum += hList[i]-hList[i-k]\r\n if hSum<hMin:\r\n hMin = hSum\r\n ans = i-k+2\r\nprint(ans)",
"def solution():\r\n n, k = map(int, input().split())\r\n a = list(map(int, input().split()))\r\n prefix = [0] + a\r\n for i in range(1, n + 1):\r\n prefix[i] += prefix[i - 1]\r\n ans = []\r\n for i in range(n - k + 1):\r\n cur = prefix[i + k] - prefix[i]\r\n ans.append([cur, i])\r\n min_ans = min(ans)\r\n res = min_ans[1] + 1\r\n print(res)\r\n \r\n \r\nsolution()",
"n,k = map(int,input().split())\nlist=[int(x) for x in input().split()]\nwindow=sum(list[:k])\nres=[]\nres.append(window)\nfor i in range(n-k):\n window+=(-list[i]+list[i+k])\n res.append(window)\nprint(res.index(min(res))+1)\n \t\t \t \t\t\t \t\t\t \t \t \t \t\t",
"n, k = [int(_) for _ in input().split()]\r\n\r\narr = [int(_) for _ in input().split()]\r\n\r\ns = sum(arr[:k])\r\nm = s\r\nindex = 0\r\n\r\nfor i in range(k,n):\r\n s += arr[i] - arr[i-k]\r\n\r\n if s < m:\r\n m = s\r\n index = i-k+1\r\n\r\nprint(index+1)",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\n\r\ncurrent_sum = sum(h[:k]) # Initial sum of the first window\r\nmin_sum = current_sum\r\nindex = 1\r\n\r\nfor i in range(1, n - k + 1):\r\n current_sum += h[i + k - 1] - h[i - 1] # Update the sum by removing the first element and adding the new element\r\n if current_sum < min_sum:\r\n min_sum = current_sum\r\n index = i + 1\r\n\r\nprint(index)",
"def read_numbers():\r\n return [int(n) for n in input().split()]\r\n\r\n\r\nn, k = read_numbers()\r\nj = read_numbers()\r\n\r\nmin_sum = prev_sum = sum(j[0:k])\r\nmin_index = 0\r\n\r\nfor i in range(1, n - k + 1):\r\n new_sum = prev_sum + j[i + k - 1] - j[i - 1]\r\n prev_sum = new_sum\r\n if new_sum < min_sum:\r\n min_sum = new_sum\r\n min_index = i\r\nprint(min_index + 1)",
"n ,k = map(int, input().split())\r\narr=list(map(int, input().split()))\r\n\r\nsarr=[]\r\nsarr.append(0)\r\nsumm=0\r\nfor i in arr:\r\n summ+=i\r\n sarr.append(summ)\r\n#print(sarr, \"sarr\")\r\n\r\n\r\n\r\nnarr=[]\r\n#print(n+1-k)\r\nfor i in range(n+1-k):\r\n narr.append(sarr[i+k]-sarr[i])\r\n#print(narr, \"narr\")\r\n\r\nminn= min(narr)\r\n#print(minn, \"minn\")\r\nprint(narr.index(minn)+1)\r\n\r\n",
"n,k = map(int,input().split())\r\nl= [int(x) for x in input().split()]\r\ndp = [0]*(n-k+1)\r\ndp[0] = sum(l[:k])\r\nans = dp[0]\r\ni = 1\r\nfor i in range(n-k):\r\n dp[i+1] = dp[i]+l[i+k]-l[i]\r\n ans = min(ans,dp[i+1])\r\n \r\nprint(dp.index(ans)+1)",
"n, k = map(int, input().split())\r\nnums = [int(x) for x in input().split()]\r\n\r\ni = 0\r\nj = k - 1\r\n\r\nbest = 0\r\ncurrent = 0\r\nbest_index = 0\r\nfor a in range(j + 1):\r\n current += nums[a]\r\nbest = current\r\n\r\nwhile j + 1 < n:\r\n current -= nums[i]\r\n i += 1\r\n j += 1\r\n current += nums[j]\r\n if current < best:\r\n best = current\r\n best_index = i\r\n\r\n\r\nprint(best_index + 1)\r\n",
"N, K = map(int,input().split()); H = list(map(int,input().split())); S1, S2, ind = sum(H), sum(H), K-1\r\nfor i in range(K, N):\r\n S2 += H[i] - H[i-K]\r\n if S1 > S2: S2 = S1; ind = i\r\nprint(ind-K+2)",
"l = list(map(int,input().split()))\r\nn = l[0]\r\nk = l[1]\r\n\r\nli = list(map(int,input().split()))\r\n\r\ndef sum(li,k,i):\r\n result = 0 \r\n for j in range(k):\r\n result = result + li[i+j]\r\n return result\r\nadd = sum(li,k,0)\r\nmin = 0\r\ny = add\r\nfor i in range(0,n-k):\r\n \r\n x = li[i+k]-li[i]\r\n # print(x)\r\n # print(y)\r\n # print(add)\r\n # print(\"hi\")\r\n y = y+x\r\n if y<=add:\r\n min = i+1\r\n add = y\r\nprint(min+1)",
"n,k=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\nc=sum(a[:k])\r\nx=[c]\r\nfor i in range(n-k):\r\n c-=a[i]\r\n c+=a[i+k]\r\n x.append(c)\r\npos=x.index(min(x))\r\nprint(pos+1)",
"n, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\n\r\nprefix = [0 for i in range(n+1)]\r\nfor i in range(len(arr)):\r\n prefix[i+1] = prefix[i] + arr[i]\r\n\r\nans = float('inf')\r\nindex = -1\r\nfor t in range(k, n+1):\r\n if prefix[t] - prefix[t-k] < ans:\r\n ans = prefix[t] - prefix[t-k]\r\n index = t - k + 1\r\n\r\nprint(index)",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nh = sum(a[:k])\r\ns = h\r\nj = k\r\nfor i in range(k, n):\r\n s += (a[i] - a[i - k])\r\n if s < h:\r\n h = s\r\n j = (i + 1)\r\nprint(j - (k - 1))",
"total_fences, no_of_fence_to_removed = map(int, input().split())\r\nplanks_height_list = list(map(int, input().split()))\r\n\r\n#STORE THE TOTAL HEIGHT OF FIRST `no_of_fence_to_removed` PLANKS\r\nmin_sum = sum(planks_height_list[:no_of_fence_to_removed])\r\nmin_index = 0\r\ncurr_sum = min_sum\r\n\r\nfor i in range(1, total_fences-no_of_fence_to_removed+1):\r\n curr_sum = curr_sum - planks_height_list[i-1] + planks_height_list[i + no_of_fence_to_removed-1]\r\n if curr_sum < min_sum:\r\n min_sum = curr_sum\r\n min_index = i\r\n\r\nprint(min_index + 1)\r\n",
"a,n=map(int, input().split())\r\narr=[int(arr) for arr in input().split()]\r\ns=0\r\ns=sum(arr[:n])\r\nmn=s\r\nimn=0\r\nfor i in range(1,a-n+1):\r\n s +=arr[i+n-1]-arr[i-1]\r\n if s<mn:\r\n mn=s\r\n imn=i\r\nprint(imn+1)",
"n,k= list(map(int,input().split()))\r\narr = list(map(int, input().split()))\r\ntotal = 0\r\nmini = float('inf')\r\nleft = 0\r\nright = 0\r\nres = 1\r\nwhile right < len(arr):\r\n total+=arr[right]\r\n if (right - left) + 1 == k:\r\n if mini > total:\r\n mini = total\r\n res = left+1\r\n total-=arr[left]\r\n left+=1\r\n right+=1\r\n \r\nprint(res)\r\n",
"n, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\nsums = sum(arr[:k])\r\nmins = sums \r\nans = 1\r\nfor i in range(k, n):\r\n sums -= arr[i - k]\r\n sums += arr[i]\r\n if sums < mins:\r\n mins = sums\r\n ans = i - k + 2\r\n #print(ans, mins)\r\nprint(ans)",
"from collections import deque\nfrom heapq import *\nimport sys\nsys.setrecursionlimit(5005)\nmod = 1000000007\ntime = 0\n\ndef solve():\n\tn,k = map(int,input().split())\n\tarr = list(map(int,input().split()))\n\tcursum = 0\n\tfor i in range(k):\n\t\tcursum+=arr[i]\n\tminsum = cursum\n\tminind = 0\n\tfor i in range(k,n):\n\t\tcursum+=arr[i]\n\t\tcursum-=arr[i-k]\n\t\tif cursum<minsum:\n\t\t\tminsum=cursum\n\t\t\tminind = i-k+1\n\tprint(minind+1)\n\n\n\n\n\n\n\nt = 1\n#t = int(input())\n\nfor i in range(t):\n\tsolve()",
"n,k=[int(x) for x in input().split()]\r\narr=[int(x) for x in input().split()]\r\n\r\nmini=float(\"inf\")\r\nans=-1\r\nprefix=[0]\r\nfor i in arr:\r\n prefix.append(prefix[-1]+i)\r\nfor i in range(k,len(prefix)):\r\n if mini>prefix[i]-prefix[i-k]:\r\n mini=prefix[i]-prefix[i-k]\r\n ans=i-k\r\n \r\nprint(ans+1)",
"n,k = map(int,input().split())\r\nh = list(map(int,input().split()))\r\ntotal = sum(h[:k])\r\ntabledtotal = [total]\r\nindexs = 0\r\n\r\nfor _ in range(k,n):\r\n\ttotal += h[_]\r\n\ttotal -= h[indexs]\r\n\ttabledtotal.append(total)\r\n\tindexs += 1\r\n\t\r\nprint(tabledtotal.index(min(tabledtotal))+1)",
"n, k = map(int,input().split())\r\nh = list(map(int,input().split()))\r\n \r\nsum_ = sum(h[:k])\r\nmin_sum = sum_\r\nstart = 0\r\n\r\nfor i in range(k, n):\r\n sum_ = sum_ + h[i] - h[i-k]\r\n\r\n if sum_ < min_sum:\r\n min_sum = sum_\r\n start = i - k + 1\r\n\r\nprint(start + 1)",
"n, k = map(int, input().split())\r\nL = list(map(int, input().split()))\r\n\r\n\r\nm_s = sum(L[:k])\r\nr = 0\r\n\r\nsumm = m_s\r\n\r\nfor i in range(1, n - k + 1):\r\n summ = summ - L[i - 1] + L[i + k - 1]\r\n \r\n if summ < m_s:\r\n m_s = summ\r\n r = i\r\nprint(r + 1)",
"import sys\ninput = sys.stdin.readline\n\n############ ---- Input Functions ---- ############\ndef inp(): # int\n return(int(input()))\ndef inlt(): # list\n return(list(map(int,input().split())))\ndef insr(): # string as char list\n s = input()\n return(list(s[:len(s) - 1]))\ndef instr(): # string\n return input()\ndef invr(): # spaced ints\n return(map(int,input().split()))\n\nn, k = list(invr())\nheights = list(invr())\ncurr_price = 0\nr = 0\nwhile r < k:\n curr_price += heights[r]\n r += 1\n# print(curr_price)\nmin_l = 0\nmin_price = curr_price\nfor l in range(1, n - k + 1):\n curr_price += heights[r] - heights[l-1]\n # print(l, curr_price)\n if curr_price < min_price:\n min_price = curr_price\n min_l = l\n r += 1\nprint(min_l + 1)",
"n, k = map(int, input().split())\r\nh = [0] + list(map(int, input().split()))\r\npfx = [0] * (n + 1)\r\nfor i in range(1, n + 1):\r\n pfx[i] = pfx[i - 1] + h[i]\r\nans = 1\r\nmn = float('inf')\r\nfor i in range(1, n - k + 2):\r\n if pfx[i + k - 1] - pfx[i - 1] < mn:\r\n mn = pfx[i + k - 1] - pfx[i - 1]\r\n ans = i\r\nprint(ans)",
"'''\r\na = input().split(\" \")\r\nn = int(a[0])\r\nh = list(map(int,input().split(\" \")))\r\nk = int(a[1])\r\noutput = []\r\nif n == 1:\r\n print(1)\r\nelse:\r\n for i in range(0,n-k):\r\n b = 0\r\n for j in range(k):\r\n b += h[i+j]\r\n output.append(b)\r\n print(output.index(min(output))+1)\r\n'''\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nd=sum(a[0:k])\r\nj=[d]\r\nfor i in range(n-k):\r\n d=d-a[i]+a[i+k]\r\n j.append(d)\r\nprint(j.index(min(j))+1)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Sep 9 14:12:00 2023\r\n\r\n@author: mac\r\n\"\"\"\r\n\r\nn, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\nmPoint = 1\r\nmValue = s = sum(h[:k])\r\nfor i in range(1, n - k + 1):\r\n s += h[i+k-1] - h[i-1]\r\n if s < mValue:\r\n mValue = s\r\n mPoint = i + 1\r\nprint(mPoint)",
"#a = input().split()\r\n#b = list(map(int, input().split()))\r\n#b.sort()\r\n#print(sum(b[i] for i in range(int(a[1]))))\r\n\r\n#a, b = map(int,input().split())\r\n#l = list(map(int,input().split()))\r\n#if b not in l:\r\n# print(b)\r\n#else:\r\n# print(1)\r\n\r\n#b,d = map(int,input().split());l = list(map(int,input().split()));w, s = 0,sum(l[:d-1])\r\n#n = s + 1\r\n#for i in range(b - d):\r\n# if n > s: w=i; n=s\r\n# s -= l[i];s += l[i+d]\r\n#print(w + 1)\r\n\r\n#x, k = map(int,input().split())\r\n#y = list(map(int,input().split()))\r\n#z = [sum(y[i:i + k]) for i in range(x - k + 1)]\r\n#print(z.index(min(z)) + 1)\r\n\r\n#n ,k = map(int,input().split())\r\n#h = list(map(int,input().split()))\r\n#a = sum(h[:k])\r\n#d = 0\r\n#for x in range(n - k):\r\n# if h[x] > h[x + k]:\r\n# d = x + 1\r\n#print(d + 1)\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nps = [0] * n\r\nps[0] = a[0]\r\nfor i in range(1, n):\r\n\tps[i] = ps[i - 1] + a[i]\r\n\r\n\r\nmn = 1000000000\r\nmni = -1\r\nfor i in range(0, n - k + 1):\r\n\ts = ps[i + k - 1] - (ps[i - 1] if i - 1 >= 0 else 0)\r\n\tif s < mn:\r\n\t\tmn = s\r\n\t\tmni = i\r\n\r\nassert(mni != -1)\r\nprint(mni + 1)\r\n",
"n, k = list(map(int, input().split()))\r\narr = list(map(int, input().split()))\r\n\r\ntotal = 0\r\nfor i in range(k):\r\n total += arr[i]\r\n\r\nl = 0\r\nr = k\r\nmin_total = total\r\nindex = 0\r\nwhile r < len(arr):\r\n total -= arr[l]\r\n total += arr[r]\r\n l += 1\r\n r += 1\r\n if total < min_total:\r\n min_total = total\r\n index = l\r\n\r\nprint(index+1)",
"# #include <bits/stdc++.h>\r\n# // #include <iostream> // cin, cout\r\n# // #include<stdio> // scanf, printf\r\n# // #include<stdlib.h> // atoi, atoll, malloc, rand\r\n# // #include<iomanip> // set, setprecision\r\n# // #include<math> // sqrt, log2, pow, __gcd\r\n# // #include <string> // strlen, strcpy, size, to_string\r\n# // #include <numeric>\r\n# // #include <vector>\r\n# // #include <stack>\r\n# // #include <queue>\r\n# // #include <map>\r\n# // #include <unordered_map>\r\n# // #include <set>\r\n# // #include <unordered_set>\r\n# // #include <algorithm>\r\n# // #include <cstdio>\r\n# // #include <cmath>\r\n# // #include <limits.end>\r\n# // #include <bitset>\r\n# // #include <ctime>\r\n# // #include <typeinfo>\r\n# #pragma GCC optimize (\"O3\")\r\n# #pragma GCC target (\"sse4\")\r\n# using namespace std;\r\n\r\n# //* BOOST BEG //\r\n# #pragma GCC optimize(\"Ofast\")\r\n# #pragma GCC target(\"avx,avx2,fma\")\r\n# #pragma GCC optimization (\"unroll-loops\")\r\n# #pragma GCC target(\"avx,avx2,sse,sse2,sse3,sse4,popcnt\")\r\n# // BOOST END */\r\n\r\n# #define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\r\n\r\n# #define endl \"\\n\"\r\n# typedef long long int ll;\r\n# typedef vector<ll> vll;\r\n# #define mininfi -1000000007 // 10^9 + 7\r\n# #define plusinfi 1000000007 // 10^9 + 7\r\n# #define all(x) x.begin(),x.end()\r\n# #define pb push_back\r\n# #define ff first\r\n# #define ss second\r\n\r\n# template <typename T>\r\n# void inpA (T arr[], int n)\r\n# {\r\n# for (int i = 0; i < n; i++)\r\n# {\r\n# cin >> arr[i];\r\n# }\r\n# }\r\n\r\n# template <typename T>\r\n# void inpV (vector<T> &vec, int n)\r\n# {\r\n# vec.resize(n);\r\n# for (int i = 0; i < n; i++)\r\n# {\r\n# cin >> vec[i] ;\r\n# }\r\n# }\r\n\r\n# template <typename T, size_t SIZE>\r\n# void outA (const T (&array)[SIZE])\r\n# {\r\n# for (size_t i = 0; i < SIZE; i++)\r\n# std::cout << array[i] << \" \";\r\n# }\r\n\r\n# template <typename T>\r\n# void outV (const vector<T> &vec)\r\n# {\r\n# for (int i = 0; i < vec.size(); i++)\r\n# {\r\n# cout << vec[i] << \" \" ;\r\n# }\r\n# cout << endl ;\r\n# }\r\n\r\n# template <typename T>\r\n# void outAptr(const T array[], size_t SIZE)\r\n# {\r\n# /* SIZE = sizeof(array_name) / sizeof(int) */\r\n# /* SIZE = sizeof(array) / sizeof(array[0]) */\r\n# for (size_t i = 0; i < SIZE; i++)\r\n# {\r\n# cout << array[i] << \" \";\r\n# }\r\n# }\r\n\r\n# ll zer = 0, one = 1; // use instead of \"0\" and \"1\" in code\r\n# string yes = \"YES\", no = \"NO\"; // use this with cout\r\n# // #define ls p<<1\r\n# // #define rs p<<1|1\r\n# #define Ma 1000005\r\n# // #define mod 1000000007\r\n# // #define PLL pair<ll,ll>\r\n# // #define PDD pair<double,double>\r\n# // #define fi first\r\n# // #define se second\r\n# // #define N 61\r\n# // #define pb push_back\r\n# // #define ld long double\r\n# // #define all(x) x.begin(),x.end()\r\n\r\n# void solve()\r\n# {\r\n# // \tcin>>s;\r\n# // \ts=\"@\"+s;\r\n# // \tn=s.size()-1;\r\n# // \tfor (ll i=1;i<=n;i++)\r\n# // \t\tl[i]=l[i-1]+(s[i]=='1')*p;\r\n# // \tr[n+1]=0;\r\n# // \tfor (ll i=n;i>=1;i--)\r\n# // \t\tr[i]=r[i+1]+(s[i]=='0')*p;\r\n# // \tll ans=inf;\r\n# // \tfor (ll i=1;i<=n+1;i++)\r\n# // \t\tans=min(ans,l[i-1]+r[i]);\r\n# // \tfor (ll i=1;i<=n-1;i++)\r\n# // \t\tans=min(ans,l[i-1]+r[i+2]+q);\r\n# // \tprintf(\"%lld\\n\",ans);\r\n# // \treturn;\r\n# int n;\r\n# cin>>n;\r\n \r\n# map<string,int> mp ;\r\n \r\n# string res = \"a\" ; \r\n# mp[res] = 0 ;\r\n \r\n# while(n--)\r\n# {\r\n# string str ; \r\n# cin>>str ; \r\n# mp[str]++ ;\r\n# }\r\n \r\n# for(auto p : mp)\r\n# {\r\n# if(p.ss>mp[res])\r\n# res = p.ff ;\r\n# }\r\n \r\n# cout<<res<<endl ;\r\n# }\r\n\r\n# /*fuck you motherfucker\r\nx=lambda:map(int,input().split())\r\nn,k=x()\r\n*a,=x()\r\nm=s=sum(a[:k]) #now is this dp you motherfucker...whoever is seeing\r\n #my solution right at this moment\r\nr=1 #if you cant even tell if this is dp or bf\r\nfor i in range(k,n): #then you have no right to see my soln...go to hell\r\n s+=a[i]-a[i-k]\r\n if s<m:m=s;r=i-k+2\r\nprint(r)\r\n# */\r\n\r\n# int main()\r\n# {\r\n# FAST_IO;\r\n# \tint tt=1;\r\n# \twhile (tt--){\r\n# \t\tsolve();\r\n# \t}\r\n# \treturn 0;\r\n# }\r\n",
"n, k = [int(x) for x in input().split()]\nq = [int(x) for x in input().split()]\ndp = [0]*(n-k+1)\ndp[0] = sum([q[x] for x in range(k)])\ntemp = dp[0]\nans = 1\nfor i in range(1, n-k+1):\n\tdp[i] = dp[i-1] - q[i-1] + q[i+k-1]\n\tif temp > dp[i]:\n\t\ttemp = dp[i]\n\t\tans = i+1\n# print(dp)\nprint(ans)\n\t\t \t \t \t \t \t\t \t \t\t\t\t",
"n, k = [int(thing) for thing in input().split()]\r\nfences = [int(fence) for fence in input().split()]\r\nmincost = sum(fences[0:k])\r\nsumcost = sum(fences[0:k])\r\ncurrentindex = 1\r\nfor i in range(len(fences)-k):\r\n sumcost += (fences[k+i]-fences[i])\r\n if mincost > sumcost:\r\n mincost = sumcost\r\n currentindex = i + 2\r\nprint(currentindex)",
"n,k = [int(x) for x in input().split()]\r\nh = [int(x) for x in input().split()]\r\n\r\nminSum = curSum = sum(h[0:k])\r\nminSumPos = 0\r\nfor i in range(1, n-k+1):\r\n curSum = curSum - h[i-1] + h[i+k-1]\r\n if curSum < minSum:\r\n minSum = curSum\r\n minSumPos = i\r\nprint(minSumPos+1)\r\n",
"n,k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\n#take window of k size\r\n#store its sum\r\n#move by one space\r\ns = sum(h[:k])\r\nans = s\r\nres = 0\r\nl = 0\r\nfor i in range(k,n):\r\n val = s + h[i] - h[l]\r\n l += 1\r\n if val < ans:\r\n ans = val\r\n res = l\r\n s = val\r\n\r\nprint(res+1)",
"import sys\r\ninput=sys.stdin.readline\r\nln,k=map(int,input().split())\r\narr = list(map(int,input().split()))\r\npre = [0]*(ln+1)\r\nfor i in range(ln):\r\n pre[i] = pre[i-1]+arr[i]\r\nmn = 999999999999999999\r\nr=k\r\nans = 1\r\nfor b in range(ln-k):\r\n if r==ln:\r\n break\r\n if pre[k-1]<mn:\r\n mn = pre[k-1]\r\n ans = 1\r\n if pre[r]-pre[b]<mn:\r\n mn = pre[r]-pre[b]\r\n ans = b+2\r\n r+=1\r\nprint(ans)",
"n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nd=sum(a[0:k])\r\nr=[d]\r\nfor i in range(n-k):\r\n d=d-a[i]+a[i+k]\r\n r.append(d)\r\nprint(r.index(min(r))+1)\r\n",
"n,k = input().split()\r\nn = int(n)\r\nk = int(k)\r\nh = input().split()\r\nfor i in range(0,n):\r\n h[i] = int(h[i])\r\n\r\n\r\npref = [0]*n\r\npref[0] = h[0]\r\nfor i in range(1,n):\r\n pref[i] = h[i] + pref[i-1]\r\n\r\ndic = {}\r\n\r\nans = pref[k-1]\r\ndic[ans] = 1\r\nfor i in range(k,n):\r\n curr = pref[i]-pref[i-k]\r\n ans = min(curr,ans)\r\n dic[curr] = i-k+2\r\n\r\n\r\nprint(dic[ans])\r\n \r\n \r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Feb 1 20:41:14 2023\r\n\r\n@author: rohan\r\n\"\"\"\r\n\r\nn, k = map(int, input().split())\r\nnums = list(map(int, input().split()))\r\nminsumm = float('inf')\r\nidx = 0\r\ni = 0\r\nsumm = 0\r\nfor j in range(n):\r\n summ += nums[j]\r\n \r\n if j - i + 1 == k:\r\n if summ < minsumm:\r\n minsumm = summ\r\n idx = i\r\n \r\n summ -= nums[i]\r\n i += 1\r\nprint(idx + 1)\r\n ",
"import math\r\nimport bisect\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nindex=0\r\ns=sum(a[:k])\r\nans=s\r\nfor i in range(k,n):\r\n s-=a[i-k]\r\n s+=a[i]\r\n # print(s,i)\r\n if s<ans:\r\n ans=s\r\n index=i-k+1\r\nprint(index+1)",
"from sys import stdin\r\nfrom bisect import bisect_right as br\r\n\r\n# https://codeforces.com/problemset/problem/363/B\r\n\r\ndef inp():\r\n\treturn stdin.readline().rstrip()\r\n\r\ndef iinp():\r\n\treturn int(inp())\r\n\r\ndef mp():\r\n\treturn map(int, inp().split())\r\n\r\ndef liinp():\r\n\treturn list(mp())\r\n\r\ndef solve(n, k, h_planks):\r\n pref_sum = [0]\r\n\r\n for i in range(n):\r\n if i==0:\r\n pref_sum.append(h_planks[i])\r\n continue\r\n pref_sum.append(pref_sum[-1]+h_planks[i])\r\n \r\n sol = [float('inf'), -1]\r\n for i in range(n-k+1):\r\n l = i; r = l+k\r\n desired_sum = pref_sum[r]-pref_sum[l]\r\n if desired_sum<sol[0]:\r\n sol = [desired_sum, i+1]\r\n \r\n return sol[1]\r\n\r\nif __name__==\"__main__\":\r\n n, k = liinp()\r\n h_planks = liinp()\r\n print(solve(n, k, h_planks))\r\n ",
"n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nsuml=[]\r\nsum=int(0)\r\nfor i in range(k):\r\n sum+=l[i]\r\nsuml.append(sum)\r\nfor i in range(n-k):\r\n sum=sum-l[i]+l[k+i]\r\n suml.append(sum)\r\nprint(suml.index(min(suml))+1)",
"from sys import stdin\r\ndef input(): return stdin.readline()[:-1]\r\ndef solve():\r\n\tn,k=map(int,input().split())\r\n\ta=list(map(int,input().split()))\r\n\ttemp=sum(a[0:k])\r\n\tmn=temp\r\n\tidx=1\r\n\tfor i in range(n-k):\r\n\t\ttemp-=a[i]\r\n\t\ttemp+=a[k+i]\r\n\t\tif mn>temp:\r\n\t\t\tmn=temp\r\n\t\t\tidx=i+2\r\n\tprint(idx)\r\nsolve()",
"n, k = map(int, input().split())\narr = list(map(int, input().split()))\n\nst = 0\nen = k \ncurrent = sum(arr[st:en])\nmin_sum = current\nindex = st + 1\n\nwhile en < n:\n current += arr[en]\n current -= arr[st]\n \n en += 1\n st += 1\n \n if current < min_sum:\n min_sum = current\n index = st + 1\n \n \n \nprint(index)",
"n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nc = sum(a[:k])\r\nb=[]\r\nb.append(c)\r\nfor i in range(n-k):\r\n c -= a[i]\r\n c += a[i+k]\r\n b.append(c)\r\nprint(b.index(min(b))+1)\r\n",
"def prec_sum(l):\r\n n = len(l)\r\n for i in range(1,n):\r\n l[i]+=l[i-1]\r\n return l\r\n\r\n\r\nn,k = map(int, input().split())\r\nArr = list(map(int, input().split()))\r\npre_cal_sum = [0]+prec_sum(Arr)\r\n#print(pre_cal_sum)\r\n\r\nlow = pre_cal_sum[k]-pre_cal_sum[0]\r\n#print(low)\r\nmin_index = 1\r\n\r\nfor i in range(1,n-k+1):\r\n temp = pre_cal_sum[i+k]-pre_cal_sum[i]\r\n #print(temp)\r\n if temp<low:\r\n low = temp\r\n min_index = i+1\r\nprint(min_index)\r\n",
"n, k = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nr, s = 1, sum(lst[0:k])\r\ntmp = s\r\nfor i, (x, y) in enumerate(zip(lst, lst[k:])):\r\n tmp += y - x\r\n if tmp < s:\r\n s = tmp\r\n r = i + 2\r\nprint(r)",
"# DO NOT EDIT THIS\r\nimport math\r\nimport sys\r\ninput = sys.stdin.readline\r\nfrom collections import deque, defaultdict\r\nimport heapq\r\ndef counter(a):\r\n c = defaultdict(lambda : 0) # way faster than Counter\r\n for el in a:\r\n c[el] += 1\r\n return c\r\n\r\ndef inp(): return [int(k) for k in input().split()]\r\ndef si(): return int(input())\r\ndef st(): return input()\r\n\r\n# DO NOT EDIT ABOVE THIS\r\nn, k = inp()\r\narr = inp()\r\n\r\nm, idx = sum(arr[:k]), 0\r\n\r\ni = 0\r\ncur = m\r\nfor j in range(k, len(arr)):\r\n cur += arr[j]\r\n cur -= arr[i]\r\n i += 1\r\n\r\n if cur < m:\r\n m = cur\r\n idx = i\r\n\r\nprint(idx + 1)\r\n",
"#1^2 + 2^2 + 3^3 + ... + n^2 = n*(n + 1)*(2*n + 1) // 6\r\n#1*(1 + 1) + 2*(2 + 1) + 3*(3 + 1) + ... + n*(n + 1) = n*(n + 1)*(n + 2) // 3\r\nfrom bisect import bisect_right, bisect_left\r\nfrom math import inf, gcd, sqrt, ceil, log2\r\nfrom heapq import heappush, heappop\r\nfrom collections import defaultdict, Counter, deque\r\nfrom itertools import accumulate\r\nfrom functools import lru_cache\r\nfrom string import ascii_lowercase\r\nrvar = lambda: map(int, input().split())\r\nrarr = lambda: list(map(int, input().split()))\r\nrstr = lambda: input().strip().decode()\r\nrint = lambda: int(input())\r\nfrom random import getrandbits\r\nRANDOM = getrandbits(32)\r\n\r\nclass Wrapper(int):\r\n def __init__(self, x):\r\n int.__init__(x)\r\n def __hash__(self):\r\n return super(Wrapper, self).__hash__() ^ RANDOM\r\nfrom types import GeneratorType\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n if type(to) is GeneratorType:\r\n stack.append(to)\r\n to = next(to)\r\n else:\r\n stack.pop()\r\n if not stack:\r\n break\r\n to = stack[-1].send(to)\r\n return to\r\n return wrappedfunc\r\n\r\n'''Speed up input'''\r\nimport io, os\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, k = rvar()\r\n\r\narr = rarr()\r\n\r\nps = 0\r\nfor i in range(k):\r\n ps += arr[i]\r\n\r\nans = 1\r\nbest = ps\r\nfor i in range(k, n):\r\n ps -= arr[i - k]\r\n ps += arr[i]\r\n if ps < best:\r\n best = ps\r\n ans = i - k + 2\r\n\r\nprint(ans)",
"n, k = map(int, input().split())\r\nl = list(map(int, input().split()))\r\npr = [0] * (n + 1)\r\nans = 0\r\nfor x in range(1, n + 1):\r\n pr[x] = pr[x - 1] + l[x - 1]\r\n \r\nm = 10 ** 10\r\nfor x in range(n - k + 1):\r\n if m > pr[x + k] - pr[x]:\r\n m = pr[x + k] - pr[x]\r\n ans = x + 1\r\nprint(ans)",
"def min_subarrays_of_length_k(arr, k):\r\n min_sum = 0\r\n current_sum = 0\r\n start = 0\r\n end = k - 1 # Ãndice del último elemento del primer subarray de longitud k\r\n\r\n # Calcula la suma del primer subarray de longitud k\r\n for i in range(k):\r\n current_sum += arr[i]\r\n\r\n min_sum = current_sum\r\n\r\n for i in range(k, len(arr)):\r\n current_sum = current_sum - arr[i - k] + arr[i]\r\n\r\n if current_sum < min_sum:\r\n min_sum = current_sum\r\n start = i - k + 1\r\n end = i\r\n\r\n return min_sum, start, end\r\n\r\n\r\nn, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\n\r\n_, j, _ = min_subarrays_of_length_k(arr, k)\r\n\r\nprint(j + 1)",
"n,k = map(int,input().split(' '))\r\nh = list(map(int,input().split(' ')))\r\nsum = 0\r\nfor i in range (0,k):\r\n sum += h[i]\r\nmin_sum = sum\r\nindex = 0\r\nfor i in range (1,n-k+1):\r\n sum = sum - h[i-1] + h[i + (k-1)]\r\n if min_sum > sum:\r\n min_sum = sum\r\n index = i\r\nprint(index + 1)",
"n,k=map(int,input().split(' '))\r\na=list(map(int,input().split(' ')))\r\ns=sum(a[:k])\r\ni=0\r\nans=i\r\ntotal=s\r\nfor j in range(k,n):\r\n t=s+a[j]-a[i]\r\n i+=1\r\n if t<total:\r\n #print(i)\r\n total=t\r\n ans=i\r\n #print(i,j,t)\r\n s=t\r\n \r\nprint(ans+1)",
"import math, bisect, sys\r\n\r\nn, k = map(int, input().split())\r\nplanks = list(map(int, input().split()))\r\nfor i in range(1, n):\r\n planks[i] += planks[i-1]\r\n# print(planks)\r\n\r\nsum = planks[k-1]\r\npos = 0\r\n# print(sum, k)\r\nfor i in range(k, n):\r\n diff = planks[i] - planks[i-k]\r\n # print(planks[i], planks[i-k])\r\n\r\n if diff < sum:\r\n sum = diff\r\n pos = i - k + 1\r\n # print(diff, i+1)\r\n\r\nprint(pos + 1)",
"n,k = map(int, input().split())\r\ny = [int(x) for x in input().split()]\r\ns = sum(y[0:k])\r\ntemp = s\r\nans = 1\r\nfor i in range(k,n):\r\n s = s - y[i-k] + y[i]\r\n if s <= temp:\r\n temp = s\r\n ans = i-k+2\r\nprint(ans)",
"n, k = [int(i) for i in input().split()]\r\nh = [int(i) for i in input().split()]\r\nj = 0\r\ncurr_sum = sum(h[:k])\r\nsum_min = curr_sum\r\nfor curr_j in range(1, n - k + 1):\r\n curr_sum -= h[curr_j - 1]\r\n curr_sum += h[curr_j + k - 1]\r\n if curr_sum < sum_min:\r\n sum_min = curr_sum\r\n j = curr_j\r\nprint(j+1)",
"nk = list(map(int, input().split()))\r\nn = nk[0]\r\nk = nk[1]\r\n\r\nheights = list(map(int, input().split()))\r\nprefixes = []\r\ntemp_p = 0\r\n\r\nfor i in range(n):\r\n temp_p += heights[i]\r\n \r\n if len(prefixes) == 0:\r\n if (i + 1) % k == 0:\r\n prefixes.append(temp_p)\r\n else:\r\n temp_p -= heights[i - k]\r\n prefixes.append(temp_p)\r\n\r\nminn = 0\r\n\r\nfor i in range(len(prefixes)):\r\n if prefixes[minn] > prefixes[i]:\r\n minn = i\r\n\r\nprint(minn + 1)",
"def solution():\r\n n,k = list(map(int,input().split()))\r\n fence = list(map(int,input().split()))\r\n l = 0\r\n r = k\r\n temp = sum(fence[l:r])\r\n minm,res = float(\"inf\"),0\r\n while l <= n - k:\r\n if l == 0:\r\n minm = temp\r\n res = l\r\n else:\r\n temp = temp - fence[l-1] + fence[r-1]\r\n if temp < minm:\r\n res = l\r\n minm = temp\r\n r+=1\r\n l = r-k\r\n print(res+1)\r\nsolution()",
"I=lambda:list(map(int,input().split()))\r\nn,k=I()\r\nh=I()\r\ns=tmp=sum(h[:k])\r\nres=1\r\nfor i in range(k,n):\r\n s+=h[i]-h[i-k]\r\n if s<tmp:res=i-k+2;tmp=s\r\nprint(res)",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nbeg = 0\r\nend = 0\r\nx = []\r\nsumma = 0\r\nfor i in range(0, k):\r\n summa += a[i]\r\nx.append(summa)\r\nfor i in range(1, n-k+1):\r\n summa = x[i-1] - a[i-1] + a[i+k-1]\r\n x.append(summa)\r\nprint(x.index(min(x))+1)",
"#N\r\nn, k = [int(x) for x in input().split()]\r\nh = [int(x) for x in input().split()]\r\nt = sum(h[:k])\r\nc = t\r\np = 0\r\nfor i in range(1, n-k+1):\r\n t -= h[i-1]\r\n t += h[i+k-1]\r\n if (t<c):\r\n c = t\r\n p = i\r\nprint(p+1)",
"n, k = (int(i) for i in input().split())\nh = [int(i) for i in input().split()]\nmi, s, res = float(\"inf\"), 0, 0\nfor i, e in enumerate(h):\n s += e\n if i >= k:\n s -= h[i - k]\n if i >= k - 1 and s < mi:\n res, mi = i - k + 2, s\nprint(res)\n",
"def find_minimal_height_planks(n, k, heights):\n total_heights = sum(heights[:k]) # sum of first k planks\n min_height = total_heights\n min_index = 0\n \n # iterate through the rest of the planks\n for i in range(k, n):\n # update the total height by adding the current plank and subtracting the plank k steps back\n total_heights += heights[i] - heights[i-k]\n \n # check if the current total height is less than the current min height\n if total_heights < min_height:\n min_height = total_heights\n min_index = i - k + 1 # update the min index\n \n return min_index\n\n# Example usage:\nn, k = map(int, input().split())\nheights = list(map(int, input().split()))\nmin_index = find_minimal_height_planks(n, k, heights)\nprint(min_index+1)\n",
"#****************************************************\r\n#***************Shariar Hasan************************\r\n#**************CSE CU Batch 18***********************\r\n#****************************************************\r\nimport math\r\nimport re\r\nimport random\r\ndef solve():\r\n #for _ in range(int(input())):\r\n for _ in range(1):\r\n n,k = [int(x) for x in input().split()]\r\n h = [int(x) for x in input().split()]\r\n sum = 0\r\n for i in range(k):\r\n sum += h[i]\r\n min = sum\r\n min_index = 1\r\n for i in range(n-k):\r\n sum = sum + h[i+k] - h[i]\r\n if(sum < min): min = sum; min_index = i+2\r\n \r\n print(min_index)\r\n\r\n\r\n\r\n\r\n\r\nsolve()",
"\n\nentrada = input()\n\nseq = int(entrada.split(\" \")[1])\n\nvalores = list(map(int,input().split(\" \")))\n\n\nsoma= 0\nfor j in range(seq):\n soma+=valores[j]\nmelhor = soma\nindice = 1\nfor i in range(seq,len(valores)):\n\n soma = soma+valores[i]-valores[i-seq]\n if(soma<melhor):\n melhor = soma\n indice=i-seq+2\n \nprint(indice)\n \t\t\t\t \t\t \t \t\t \t \t\t\t",
"info = input().split()\r\ninfo = [int(x) for x in info]\r\n\r\n\r\nzoznam = input().split()\r\nzoznam = [int(x) for x in zoznam]\r\nbest=sum(zoznam[:info[1]])\r\nzum=sum(zoznam[:info[1]])\r\n\r\nind=1\r\nif info[0]>info[1]:\r\n for a in range(info[1],info[0]):\r\n zum = zum -zoznam[a-info[1]]+ zoznam[a]\r\n\r\n if zum<best:\r\n best=zum\r\n ind=a-info[1]+2\r\nelse:\r\n ind=1\r\nprint(str(ind))",
"n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\ns=m=sum(a[:k])\r\nx=1\r\nfor i in range(k,n):\r\n s+=a[i]-a[i-k]\r\n if s<m:\r\n m=s\r\n x=i-k+2\r\nprint(x)",
"n, k = list(map(int, input().split()))\r\nh = list(map(int, input().split()))\r\nsumm = 0\r\nfor i in range(k):\r\n summ += h[i]\r\nmin_sum = summ\r\nind = 0\r\nfor i in range(1, n - k + 1):\r\n summ = summ - h[i-1] + h[i + k - 1]\r\n if summ < min_sum:\r\n min_sum = summ\r\n ind = i\r\nprint(ind + 1)\r\n",
"n, k = map(int, input().split())\r\n\r\narr = [0] + list(map(int, input().split()))\r\nfor i in range(n):\r\n arr[i+1] += arr[i]\r\n\r\n#print(arr)\r\nmini = 1000000000000\r\nf = 0\r\nfor i in range(k, n+1):\r\n #print(i, i -k)\r\n if arr[i] - arr[i-k] < mini:\r\n mini = min(mini, arr[i] - arr[i-k])\r\n f = i-k+1\r\n\r\nprint(f)\r\n",
"n, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\n\r\ntemp = sum(a[:k])\r\nminimum = temp\r\nans = 1\r\n\r\nfor i in range(n-k):\r\n temp = temp - a[i] + a[i + k]\r\n if temp < minimum:\r\n minimum = temp\r\n ans = i + 2\r\n\r\nprint(ans)",
"n, k = [int(x) for x in input().split()]\r\nheights = [0] + [int(y) for y in input().split()]\r\n\r\nminimum_sum, position, cumulative_sum = float(\"inf\"), -1, [0] * (n+1)\r\n\r\nfor i in range(1, n+1):\r\n cumulative_sum[i] = cumulative_sum[i-1] + heights[i]\r\n\r\nfor j in range(1, n+2-k):\r\n heights_sum = cumulative_sum[j + k-1] - cumulative_sum[j - 1]\r\n if heights_sum < minimum_sum:\r\n minimum_sum = heights_sum\r\n position = j\r\n\r\nprint(position)\r\n",
"n, k = map(int, input().split())\r\n*a, = map(int, input().split())\r\ns = sum(a[:k])\r\nres = 1\r\nmin_ = s\r\nfor i in range(k, n):\r\n s = s + a[i] - a[i - k]\r\n if s < min_:\r\n min_ = s\r\n res = i - k + 2\r\n\r\nprint(res)",
"n, k = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\n\r\nmin_sum = float('inf')\r\nindex = 0\r\n\r\n# Calculate the initial sum of the first k elements\r\nconsecutive_sum = sum(lst[:k])\r\n\r\nfor i in range(n - k + 1):\r\n if consecutive_sum < min_sum:\r\n min_sum = consecutive_sum\r\n index = i + 1\r\n\r\n # Update the consecutive sum for the next iteration\r\n if i < n - k:\r\n consecutive_sum = consecutive_sum - lst[i] + lst[i + k]\r\n\r\nprint(index)",
"n, k = map(int, input().split(' '))\r\narr = [int(a) for a in input().split(' ')]\r\n\r\nwindow_sum = sum(arr[:k])\r\nmin_sum = window_sum\r\nstart = 0\r\nfor i in range(k, len(arr)):\r\n window_sum = window_sum - arr[i - k] + arr[i]\r\n if window_sum < min_sum:\r\n min_sum = window_sum\r\n start = i - k + 1\r\n\r\nprint(start + 1)",
"#N\nn, k = [int(x) for x in input().split()]\nh = [int(x) for x in input().split()]\nt = sum(h[:k])\nc = t\np = 0\nfor i in range(1, n-k+1):\n t -= h[i-1]\n t += h[i+k-1]\n if (t<c):\n c = t\n p = i\nprint(p+1)\n \t\t \t\t \t \t \t \t\t \t\t\t \t \t\t\t \t",
"x = lambda: map(int, input().split())\r\nn, k = x()\r\n*a, = x()\r\nm = s = sum(a[:k])\r\nr = 1\r\nfor i in range(k, n):\r\n s += a[i] - a[i - k]\r\n if s < m:\r\n m = s\r\n r = i + 1 - (k - 1)\r\nprint(r)\r\n",
"n,k = map(int,input().split())\nfence = list(map(int,input().split()))\nstart = 0 \nend = start+k\nwindow = sum(fence[start:end])\nmini = window\nans = 1\nwhile end < n :\n window +=fence[end]\n window -= fence[start]\n if window < mini :\n mini = window\n ans = start +2\n start +=1\n end +=1\nprint(ans)",
"import sys\r\n\r\n# Read the first line containing n and k\r\nn, k = map(int, sys.stdin.readline().split())\r\n\r\n# Read the second line containing the list of integers\r\nl = list(map(int, sys.stdin.readline().split()))\r\n\r\ndp = [0] * (n - k + 1)\r\ndp[0] = sum(l[:k])\r\n\r\nfor i in range(1, n - k + 1):\r\n dp[i] = dp[i - 1] - l[i - 1] + l[i + k - 1]\r\n\r\nmin_index = dp.index(min(dp)) + 1\r\nprint(min_index)\r\n",
"n, k = map(int, input().split())\na = [0]*n\na = list(map(int, input().split()))\nsig = 0\nind = 1\nfor i in range(k):\n sig = sig + a[i]\nind = k - 1 - k + 2\nleast = sig\nfor i in range(k, n):\n sig = sig + a[i] - a[i - k]\n if sig < least:\n least = sig\n ind = i - k + 2\nprint(ind)\n",
"n,k = input().split()\r\nn = int(n)\r\nk = int(k)\r\nh = input().split()\r\ndict = {}\r\nsum = 0\r\ni = 0\r\nfor j in range(0,len(h)):\r\n h[j] = int(h[j])\r\nwhile i < k:\r\n sum += h[i]\r\n i += 1\r\ndict[sum] = 1\r\nfor i in range(k,n):\r\n sum += h[i]-h[i-k]\r\n dict[sum] = (i-k+2)\r\nprint(dict[min(dict)])",
"I=lambda:list(map(int,input().split()))\nn,k=I()\nh=I()\nm=t=sum(h[:k])\na=1\nfor i in range(k,n):\n t+=h[i]-h[i-k]\n if t<m:a=i-k+2;m=t\nprint(a)\n\t \t\t \t \t\t\t \t\t\t \t\t\t\t\t\t",
"n, k = map(int, input().split())\r\nl = list(map(int, input().split()))\r\n\r\ncurrent_sum = sum(l[:k])\r\nmin_sum = current_sum\r\nmin_index = 0\r\n\r\nfor i in range(k, n):\r\n current_sum += l[i] - l[i-k]\r\n if current_sum < min_sum:\r\n min_sum = current_sum\r\n min_index = i - k + 1\r\n\r\nprint(min_index + 1)",
"def main():\r\n n, k = map(int, input().split())\r\n h = list(map(int, input().split()))\r\n\r\n current_sum = sum(h[:k])\r\n min_sum = current_sum\r\n min_index = 0\r\n\r\n for i in range(k, n):\r\n current_sum += h[i] - h[i - k]\r\n if current_sum < min_sum:\r\n min_sum = current_sum\r\n min_index = i - k + 1\r\n\r\n print(min_index + 1) # Adding 1 because indices are 1-based\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"#Coder_1_neel\r\nn, k = map(int, input().split())\r\nheights = list(map(int, input().split()))\r\n\r\nmin_sum = sum(heights[:k]) \r\nmin_index = 0\r\n\r\ncurrent_sum = min_sum\r\n\r\nfor i in range(1, n - k + 1):\r\n current_sum = current_sum - heights[i - 1] + heights[i + k - 1]\r\n if current_sum < min_sum:\r\n min_sum = current_sum\r\n min_index = i\r\n\r\nmin_index += 1\r\n\r\nprint(min_index)\r\n",
"n,k = map(int,input().split())\r\ns = list(map(int,input().split()))\r\na = sum(s[:k])\r\nb = 0\r\nc = a\r\nfor i in range(n-k):\r\n\td = a-s[i]+s[i+k]\r\n\tif d<c:\r\n\t\tb=i+1\r\n\t\tc = d\r\n\ta = d\r\nprint(b+1)",
"nk=input().split()\r\nn=int(nk[0])\r\nk=int(nk[1])\r\nheights=list(map(int,input().split()))\r\nmin_sum=sum(heights[:k])\r\nsums=sum(heights[:k])\r\nmin_ind=1\r\nfor i in range(1,len(heights)-k+1):\r\n sums+=heights[i+k-1]-heights[i-1]\r\n if sums<min_sum:\r\n min_sum=sums\r\n min_ind=i+1\r\nprint(min_ind)",
"def prefixSum(l: list,n: int):\r\n result = []\r\n result.append(sum(l[0:n]))\r\n for i in range(n,len(l)):\r\n result.append(result[-1] + l[i] - l[(i - n)] )\r\n mini = min(result)\r\n index = result.index(mini)\r\n return index + 1\r\n\r\nn,k = map(int,input().split())\r\nhi = [int(x) for x in input().split()]\r\npre = prefixSum(hi,k)\r\nprint(pre)",
"import math\ndef error(*n):\n print(\"[Err]\",end=\" \")\n for i in n:\n print(i,end=\" \")\n print()\n\nn,k = [int(i) for i in input().split()]\nif type(n) == list:\n n = n[0]\n\nfence = [int(i) for i in input().split()]\npf=[0 for i in range(n+1)]\nfor i in range(n):\n pf[i+1]=fence[i]+pf[i]\n\nsma=1e9+7\nans=0\nfor i in range(1,n+1-(k-1)):\n ps = pf[i+k-1]-pf[i-1]\n if ps<sma:\n ans=i\n sma=ps\n\nprint(ans)\n\n\t \t\t \t \t \t\t\t \t\t\t \t\t\t\t \t\t",
"# Dread it, run from it, destiny arrives all the same.\r\ndef solve():\r\n n, k = map(int, input().split())\r\n h = list(map(int, input().split()))\r\n\r\n min_ind,min_height = 0, 0\r\n for i in range(k): \r\n min_height += h[i]\r\n \r\n total = min_height\r\n for i in range(k,n):\r\n total += h[i] - h[i-k]\r\n if total < min_height: \r\n min_height = total \r\n min_ind = i - (k-1)\r\n\r\n print(min_ind+1)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n # for _ in range(int(input())):\r\n # solve()\r\n solve()\r\n",
"n,k = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\ncurr,beg = sum(a[:k]),1\r\nw = curr\r\nfor i in range(1, n - k + 1):\r\n curr += a[i+k-1]-a[i-1]\r\n if curr < w:\r\n w = curr\r\n beg = i + 1\r\nprint(beg)",
"n,k = map(int,input().split())\r\nlis=list(map(int,input().split()))\r\nmn = sum(lis)\r\ni=0\r\nj=0\r\ns=0\r\nmnn=0\r\nwhile j<n:\r\n s+=lis[j]\r\n while j-i+1>k:\r\n s-=lis[i]\r\n i+=1\r\n if j-i+1==k:\r\n if mn>=s:\r\n mn=s\r\n mnn=i\r\n j+=1\r\nprint(mnn+1)",
"h,k=(map(int,input().split()))\r\nn=list(map(int,input().split()))\r\nsum1=sum(n[:k])\r\nm=sum1;a=1\r\nfor i in range(k,h):\r\n sum1+=(-n[i-k]+n[i])\r\n if sum1<m:m=sum1;a=i-k+2\r\n \r\nprint(a) \r\n",
"n, k = list(map(int, input().split()))\r\nH = list(map(int, input().split()))\r\nans = 1\r\ncur = sum(H[:k])\r\nlowest = cur\r\nfor i in range(len(H)-k):\r\n cur += H[i+k] - H[i]\r\n if cur < lowest: \r\n ans = i+2\r\n lowest = cur\r\nprint(ans)",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\ns = sum(h[0:k])\r\ns1 = s\r\nans = 0\r\nfor i in range(k, n):\r\n s = s - h[i - k] + h[i]\r\n if s < s1:\r\n s1 = s\r\n ans = i - k + 1\r\nprint(ans + 1)\r\n",
"l=[int(i) for i in input().split()]\r\nl1=[int(i) for i in input().split()]\r\nk=l[1]\r\nj=1\r\ns=sum(l1[:k])\r\nm=s\r\nfor i in range(len(l1)-k):\r\n s+=l1[i+k]-l1[i]\r\n if s<m:\r\n m=s\r\n j=i+2\r\nprint(j)",
"# Read input values\r\nn, k = map(int, input().split())\r\nheights = list(map(int, input().split()))\r\n\r\n# Initialize variables to keep track of the minimum sum and its starting index\r\nmin_sum = sum(heights[:k])\r\nmin_index = 0\r\ncurrent_sum = min_sum\r\n\r\n# Iterate through the planks starting from index k\r\nfor i in range(k, n):\r\n current_sum = current_sum - heights[i - k] + heights[i]\r\n \r\n # Check if the current sum is smaller than the minimum sum found so far\r\n if current_sum < min_sum:\r\n min_sum = current_sum\r\n min_index = i - k + 1\r\n\r\n# Print the starting index of the k consecutive planks with the minimum sum\r\nprint(min_index + 1) # Adding 1 because the problem uses 1-based indexing\r\n\r\n\r\n\r\n \r\n ",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\n\r\ncurrent_sum = sum(h[:k])\r\nmin_sum = current_sum\r\nmin_index = 0\r\n\r\nfor i in range(1, n - k + 1):\r\n current_sum = current_sum - h[i - 1] + h[i + k - 1]\r\n if current_sum < min_sum:\r\n min_sum = current_sum\r\n min_index = i\r\n\r\nprint(min_index + 1)",
"n, k = map(int, input().split())\r\nz = [int(c) for c in input().split()]\r\nx = sum(z[i] for i in range(k))\r\nj = 1\r\nans = x\r\nfor i in range(k, n):\r\n x += z[i] - z[i-k]\r\n if x < ans:\r\n ans = x\r\n j = i-k+2\r\nprint(j)",
"n, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\npref = [0]\r\n\r\nfor i in range(n):\r\n pref.append(pref[-1] + arr[i])\r\n\r\n# print(pref)\r\nres = -1\r\nmx = float('inf')\r\n\r\nfor i in range(n - k + 1):\r\n cur = pref[i + k] - pref[i]\r\n # print(cur)\r\n if cur < mx:\r\n mx = cur\r\n res = i + 1\r\n\r\nprint(res)",
"n,k = map(int,input().split())\r\nnums = list(map(int,input().split()))\r\nl,r = 0, k-1\r\nres = sum(nums[l:r+1])\r\nans = 0\r\ncur = res\r\nfor i in range(n-k):\r\n res-=nums[l]\r\n res+=nums[r+1]\r\n if res < cur:\r\n ans = l+1\r\n cur = res \r\n l+=1\r\n r+=1\r\nprint(ans+1)",
"n, k = map(int, input().split())\r\n\r\nh = [int(i) for i in input().split()]\r\ns = [0]*(n + 1)\r\nfor i in range(1, n + 1):\r\n s[i] = s[i - 1] + h[i - 1]\r\n\r\nms = 101*k\r\nj = -1\r\nfor i in range(n - k + 1):\r\n si = s[i + k] - s[i]\r\n if ms > si:\r\n ms, j = si, i\r\n\r\nprint(j + 1)\r\n",
"n, k = map(int, input().split())\r\nmas = list(map(int, input().split()))\r\n \r\n \r\nl = 0\r\nr = 0\r\nans = 0\r\nfor i in range(k):\r\n\tans += mas[r]\r\n\tr += 1\r\n \r\nla = 0\r\n\r\ns = ans\r\nwhile r < n:\r\n\ts -= mas[l]\r\n\ts += mas[r]\r\n\tr += 1\r\n\tl += 1\r\n \r\n\tif s < ans:\r\n\t\tans = s\r\n\t\tla = l\r\n\r\n \r\nprint(la + 1)\r\n",
"p=list(map(int,input().split()))\nn=p[0]\nk=p[1]\nlist_rest=[]\nm=list(map(int,input().split()))\nf=[0 for i in range(n)]\nf[0]=m[0]\nfor u in range(1,n):\n f[u]=f[u-1]+m[u]\nmin=f[k-1]\nlist_rest.append(min)\nfor i in range(k,n):\n list_rest.append(f[i]-f[i-k])\n if min> f[i]-f[i-k]:\n min= f[i]-f[i-k]\nprint(list_rest.index(min)+1)\n \t \t \t\t\t\t\t\t\t\t \t \t \t\t \t",
"from sys import stdin, stdout \r\nfrom functools import cache \r\nfrom math import gcd, lcm, log2, log10, log, ceil, floor, sqrt\r\n\r\ndef rs(): return stdin.readline().strip()\r\ndef ri(): return int(rs())\r\ndef rn(): return map(int, rs().split())\r\ndef rl(): return list(rn())\r\ndef rf(): return map(float, rs().split())\r\n\r\nflag = 0 \r\n\r\ndef solve():\r\n n, k = rn()\r\n a = rl()\r\n pr_sum = [0]\r\n for i in range(n):\r\n pr_sum.append(pr_sum[-1] + a[i])\r\n m = 99999999999999999\r\n ans = -1 \r\n for i in range(n - k + 1):\r\n ok = pr_sum[i + k] - pr_sum[i] \r\n if ok < m:\r\n ans = i + 1 \r\n m = ok\r\n \r\n print(ans)\r\n return None\r\n\r\ndef main():\r\n for _ in range(ri()):\r\n solve()\r\n\r\nif flag:\r\n main()\r\nelse:\r\n solve()\r\n",
"n, k = map(int, input().split())\r\nheights = list(map(int, input().split()))\r\n\r\n# Calculate the total height of the first window of size k\r\ntotal_height = sum(heights[:k])\r\nmin_height = total_height\r\nmin_index = 0\r\n\r\n# Iterate through the remaining windows of size k\r\nfor i in range(1, n - k + 1):\r\n # Update the total height by subtracting the height of the leftmost plank\r\n # and adding the height of the rightmost plank in the current window\r\n total_height = total_height - heights[i - 1] + heights[i + k - 1]\r\n \r\n # Check if the current window has a smaller total height\r\n if total_height < min_height:\r\n min_height = total_height\r\n min_index = i\r\n\r\n# Print the starting index of the sequence with the minimal total height\r\nprint(min_index + 1) # Adding 1 because the input is 1-based index\r\n",
"a,b=[int(x) for x in input().split()]\r\nA=list(map(int, input().split()))\r\nk=A[0]\r\nK=[A[0]]\r\nfor i in range(a-b):\r\n k+=A[i+b]-A[i]\r\n K.append(k)\r\nprint(K.index(min(K))+1)",
"n,k = [int(i) for i in input().split(' ')]\r\nh = [int(i) for i in input().split(' ')]\r\nx = 0\r\ns = sum(h[0:k])\r\nm = s\r\nfor i in range(1, n - k + 1):\r\n s += h[k + i - 1]\r\n s -= h[i - 1]\r\n if(s <= m):\r\n m = s\r\n x = i\r\nprint(x+1)",
"n, k = map(int, input().split())\nplank_heights = list(map(int, input().split()))\n\nmin_sum = sum(plank_heights[:k])\nstart_index = 1\n\ncurrent_sum = min_sum\nfor i in range(k, n):\n current_sum += plank_heights[i] - plank_heights[i - k]\n if current_sum < min_sum:\n min_sum = current_sum\n start_index = i - k + 2\n\nprint(start_index)\n\n\t\t \t \t\t\t\t\t\t\t\t\t\t \t\t\t\t\t \t \t",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\ns = sum(h[:k])\r\nms = s\r\ni = 0\r\nfor j in range(k, n):\r\n s = s + h[j] - h[j-k]\r\n if ms >= s:\r\n ms = s\r\n i = j - k + 1\r\nprint(i + 1)\r\n",
"n,k=map(int,input().split())\r\nlis=list(map(int,input().split()))\r\ns=sum(lis[:k])\r\nans=s\r\nindex=0\r\nfor i in range(k,n):\r\n s-=lis[i-k]\r\n s+=lis[i]\r\n if ans>s:\r\n ans=s\r\n index=1+i-k\r\nprint(index+1)\r\n",
"n,k=map(int,input().split())\r\nar=list(map(int,input().split()))\r\ns=sum(ar[:k])\r\nm=s \r\nb=1 \r\nfor x in range(k,n):\r\n s+=ar[x]-ar[x-k]\r\n if s<m:\r\n b=x-k+2\r\n m=s \r\nprint(b)",
"n,k=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\nt=s=sum(a[:k])\r\nan=1\r\nfor i in range(k,n):\r\n t+=a[i]-a[i-k]\r\n if t<s: s=t; an=i-k+2\r\nprint(an)",
"n,k=map(int,input().split())\r\nh=list(map(int,input().split()))\r\ns=0\r\ni=0\r\nwhile i<k:\r\n s+=h[i]\r\n i+=1\r\nans=s\r\nj=0\r\nk=0\r\nwhile i<n:\r\n s-=h[j]\r\n s+=h[i]\r\n i += 1\r\n j += 1\r\n if ans>s:\r\n\r\n ans=s\r\n k=j\r\n\r\nprint(k+1)\r\n\r\n",
"import sys\r\nn, k = map(int, sys.stdin.readline().strip().split())\r\na = list(map(int, sys.stdin.readline().strip().split()))\r\ns = n * [0]\r\nfor i in range(n-1, n-k-1, -1) :\r\n s[i] = a[i] if i == n-1 else a[i] + s[i+1]\r\n\r\nfor i in range(n-k-1, 0-1,-1) :\r\n s[i] = s[i+1] + a[i] - a[i + k]\r\n\r\nbest_index = 0\r\nfor i in range(n-k+1):\r\n if s[i] < s[best_index] : \r\n best_index = i\r\nprint(best_index+1)",
"n, k = map(int, input().split())\r\ns = list(map(int, input().split()))\r\nans = (0, 100000000)\r\ncur = 0\r\nfor i in range(n):\r\n if i < k:\r\n cur += s[i]\r\n else:\r\n if ans[1] > cur:\r\n ans = (i - k + 1, cur)\r\n cur -= s[i - k]\r\n cur += s[i]\r\nif ans[1] > cur:\r\n ans = (n - k + 1, cur)\r\n\r\nprint(ans[0])",
"n, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\n\r\nprefix_sums = [0] * (n + 1)\r\nfor i in range(n):\r\n prefix_sums[i + 1] = prefix_sums[i] + arr[i]\r\n\r\nminimum_sum = float('inf')\r\nresult = 0\r\n\r\nfor i in range(n - k + 1):\r\n current_sum = prefix_sums[i + k] - prefix_sums[i]\r\n if current_sum < minimum_sum:\r\n minimum_sum = current_sum\r\n result = i\r\n\r\nprint(result + 1)\r\n",
"l = [int(i) for i in input().split(' ')]\r\narr = [int(i) for i in input().split(' ')]\r\nn,k=l[0],l[1]\r\nout=sum(arr[:k:])\r\nind = 0\r\ni = 0\r\ns = out\r\nwhile i+k<n:\r\n s-=arr[i]\r\n s+=arr[i+k]\r\n if out>s:\r\n out=s\r\n ind=i+1\r\n i+=1\r\nprint(ind+1)",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\ncur = sum(a[0:k])\r\nmn = cur\r\ni_mn = 0\r\nfor i in range(k, n):\r\n cur += a[i]\r\n cur -= a[i - k]\r\n if cur < mn:\r\n mn = cur\r\n i_mn = i - k + 1\r\nprint(i_mn + 1)\r\n",
"n, k = map(int, input().split())\r\nelements = list(map(int, input().split()))\r\nmin_index, total, current_sum = -1, float(\"Inf\"), 0\r\nk -= 1\r\nfor i in range(n):\r\n current_sum += elements[i]\r\n if(i >= k):\r\n if(current_sum < total):\r\n total = current_sum\r\n min_index = i - k\r\n current_sum -= elements[i - k]\r\nprint(min_index + 1)",
"n, k = map(int, input().split())\r\narr =list(map(int, input().split()))\r\nprefix = [0]\r\nfor i in range(n):\r\n prefix.append(prefix[-1] + arr[i])\r\nminimal = prefix[k]\r\npost = 1\r\nfor i in range(n-k+1):\r\n if prefix[i+k] - prefix[i] < minimal:\r\n minimal = prefix[i+k] - prefix[i]\r\n post = i + 1\r\nprint(post)\r\n",
"planks, width = [int(x) for x in input().split()]\r\nfence = [int(x) for x in input().split()]\r\nfence_heights_sums = []\r\n\r\nstart_sum = sum(fence[0:width])\r\nfence_heights_sums.append(start_sum)\r\n\r\nfor i in range(planks - width):\r\n start_sum += - fence[i] + fence[width + i]\r\n fence_heights_sums.append(start_sum)\r\n\r\nprint(fence_heights_sums.index(min(fence_heights_sums)) + 1)",
"def main():\n n, k = (int(_) for _ in input().split())\n heights = [int(_) for _ in input().split()]\n acc = [0 for _ in range(len(heights) + 1)]\n\n for i in range(len(heights)):\n acc[i + 1] = acc[i] + heights[i]\n\n min_sum = 1e9\n min_index = -1\n\n for i in range(k, len(acc)):\n if acc[i] - acc[i - k] < min_sum:\n min_sum = acc[i] - acc[i - k]\n min_index = i\n\n print(min_index - k + 1)\n\n\nif __name__ == \"__main__\":\n main()\n",
"n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\ns=sum(l[:k])\r\nx=0\r\nm=s\r\nfor i in range(k,n):\r\n s=s-l[i-k]+l[i]\r\n if m>s:\r\n m=s\r\n x=i-k+1\r\nprint(x+1)",
"y=lambda:map(int,input().split())\nn,k=y()\n*b,=y()\nm=s=sum(b[:k])\nr=1\nfor i in range(k,n):\n s+=b[i]-b[i-k]\n if s<m:\n m=s\n r=i-k+2\nprint(r)\n\t \t \t \t \t \t \t\t\t \t \t\t\t\t\t \t",
"n, k = map(int, input().split())\nvals = list(map(int, input().split()))\nsums = [0 for _ in range(n - k + 1)]\nsums[0] = sum(vals[:k])\nfor i in range(1, len(sums)):\n sums[i] = sums[i - 1] - vals[i - 1] + vals[i + k-1]\nprint(sums.index(min(sums)) + 1)\n",
"n,k=map(int,input().split())\r\nlist1=list(map(int,input().split()))\r\nmin1=sum(list1[0:k])\r\nsum1=sum(list1[0:k])\r\nindex=0\r\nfor i in range (k,n):\r\n sum1-=list1[i-k]\r\n sum1+=list1[i]\r\n if sum1<min1:\r\n min1=sum1\r\n index=i-k+1\r\nprint(index+1)",
"n, k = map(int, input().split())\r\nheights = list(map(int, input().split()))\r\n\r\n# Initialize variables\r\ntotal_height = sum(heights[:k])\r\nmin_height = total_height\r\nstart_index = 0\r\n\r\n# Slide the window and update the minimum height\r\nfor i in range(k, n):\r\n total_height += heights[i] - heights[i - k]\r\n if total_height < min_height:\r\n min_height = total_height\r\n start_index = i - k + 1\r\n\r\n# Print the starting index of the planks with minimum total height\r\nprint(start_index + 1)\r\n",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\nres = 1\r\nmin_height = height = sum(h[:k])\r\nfor i in range(1, n - k + 1):\r\n height += h[i + k - 1] - h[i - 1]\r\n if height < min_height:\r\n min_height = height\r\n res = i + 1\r\nprint(res)\r\n",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\ns = [sum(h[0:k])]\r\nfor i in range(n-k):\r\n s.append(s[i]+h[k+i]-h[i])\r\nprint(s.index(min(s))+1)",
"n, k = map(int, input().split())\r\nx = list(map(int, input().split()))\r\nsums = [0]*(n+1)\r\nfor i in range(n):\r\n sums[i+1]=sums[i]+x[i]\r\nminnum = 101*k\r\nmini = 0\r\nfor i in range(n-k+1):\r\n if sums[i+k]-sums[i] < minnum:\r\n mini = i\r\n minnum = sums[i+k]-sums[i]\r\nprint(mini+1)\r\n",
"n,k=map(int,input().split())\r\nhen=list(map(int,input().split()))\r\ns=sum(hen[:k])\r\nmi=s\r\nnum=1\r\nfor i in range(n-k):\r\n s+=hen[k+i]-hen[i]\r\n if s<mi:\r\n mi=s\r\n num=i+2\r\nprint(num)\r\n",
"n, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nsum = [0] * (n + 1)\r\nminn = 1e9 + 7\r\nans = 0\r\nfor i in range(1, n + 1):\r\n sum[i] = sum[i - 1] + a[i - 1]\r\n# print(sum)\r\nfor i in range(1, n - k + 2):\r\n if sum[i + k - 1] - sum[i - 1] < minn:\r\n minn = sum[i + k - 1] - sum[i - 1]\r\n ans = i\r\nprint(ans)",
"def yzd_solution(n , k, fence):\r\n \r\n arr = [0]\r\n\r\n mini = float(\"inf\")\r\n index = 0\r\n\r\n\r\n for i, v in enumerate(fence):\r\n arr.append(arr[i] + v)\r\n\r\n for i in range(0, n - k + 1):\r\n ans = arr[i+k] - arr[i]\r\n if ans < mini:\r\n mini = ans\r\n index = i\r\n \r\n print(index + 1)\r\n\r\nn, k = map(int, input().split())\r\nfence = list(map(int, input().split()))\r\n \r\nyzd_solution(n, k , fence)",
"import sys,random,bisect\r\nfrom collections import deque,defaultdict\r\nfrom heapq import heapify,heappop,heappush\r\nfrom itertools import permutations\r\nfrom math import gcd,log\r\nmod = int(1e9 + 7)\r\ninf = int(1e20)\r\ninput = lambda :sys.stdin.readline().rstrip()\r\nmi = lambda :map(int,input().split())\r\nli = lambda :list(mi())\r\n\r\n\r\n\r\nn,k=li()\r\narr=li()\r\n\r\nres=1\r\n\r\nans=total=sum(arr[0:k])\r\n\r\n\r\nfor i in range(n):\r\n if i+k>=n:\r\n break\r\n total=total-arr[i]+arr[i+k]\r\n if total<ans:\r\n ans=total\r\n res=i+2\r\nprint(res)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n",
"def prefixSum (list):\r\n\tprefixSumArray = []\r\n\ttotal = 0\r\n\tfor i in range(len(list)):\r\n\t\ttotal += list[i]\r\n\t\tprefixSumArray.append(total)\r\n\treturn prefixSumArray\r\n\r\nn, k = [int(i) for i in input().split()]\r\nlog = prefixSum([int(i) for i in input().split()])\r\nsmallest = log[k-1]\r\nanswer = 1\r\nfor i in range(k, n):\r\n\tif log[i] - log[i-k] <= smallest:\r\n\t\tsmallest = log[i] - log[i-k]\r\n\t\tanswer = i-k+2\t\t\r\nprint(answer)",
"n, k = map(int, input().split())\n\nh = list(map(int, input().split()))\n\nmin_sum = sum(h[:k])\nmin_index = 0\n\ncurrent_sum = min_sum\n\nfor i in range(k, n):\n current_sum = current_sum - h[i-k] + h[i]\n if current_sum < min_sum:\n min_sum = current_sum\n min_index = i - k + 1\n\nprint(min_index + 1) # Adding 1 to convert 0-based indexing to 1-based indexing\n\n \t\t\t \t \t \t\t\t \t \t\t \t\t \t\t \t\t",
"n, k = list(int(num) for num in input().split())\r\nh = list(int(num) for num in input().split())\r\n\r\ntotal_height_of_k_boards = [0] * (n - k + 1)\r\nfor i in range(k):\r\n total_height_of_k_boards[0] += h[i]\r\nfor i in range(1, n - k + 1):\r\n total_height_of_k_boards[i] = total_height_of_k_boards[i - 1] - h[i - 1] + h[i + k - 1]\r\n\r\nj = 1\r\nfor i in range(1, n - k + 1):\r\n if total_height_of_k_boards[i] < total_height_of_k_boards[j-1]:\r\n j = i + 1\r\n\r\nprint(j)",
"n,k=map(int,input().split())\r\nh=list(map(int,input().split()))\r\nj_min=sum(h[0:k])\r\nj=0\r\npp = sum(h[0:k])\r\nfor i in range(1,n-k+1):\r\n pt=pp-h[i-1]+h[i+k-1]\r\n if pt<j_min:\r\n j_min=pt\r\n j=i\r\n pp=pt\r\nprint(j+1)\r\n",
"n, k = map(int, input().split())\nh = list(map(int, input().split()))\nlast = summ = sum(h[:k])\nj = 0\nfor i in range(n-k):\n summ+=h[i+k]-h[i]\n if summ<last:\n last = summ\n j = i+1\nprint(j+1)",
"\ndef seq(feild :list, size :int) -> list:\n S:list = [sum(feild[0:size])]\n minn:int = S[0]\n pos = 1\n\n\n for i in range(0,len(feild) - size + 1):\n if i == 0: continue\n S.append( S[-1] - feild[i - 1] + feild[i + size - 1] )\n if S[-1] < minn:\n minn = S[-1]\n pos = i + 1\n return pos\n\n\n\n\n\n\n\n\nlineone = input().split()\nfence_length :int = int(lineone[0])\npiano_width :int = int(lineone[1])\n\n\nplanks = list(map(int, input().split()))\n\nif fence_length == piano_width:\n print(\"1\")\nelse:\n print(seq(planks,piano_width))\n\n\n",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\n\r\nanswer = 0\r\nmin_sum = sum(h[:k])\r\n\r\nsumma = min_sum \r\nfor i in range(1, n - k + 1):\r\n summa = summa - h[i - 1] + h[i + k - 1]\r\n if summa < min_sum:\r\n min_sum = summa\r\n answer = i\r\n\r\nprint(answer + 1)\r\n",
"from functools import lru_cache\r\nfrom collections import defaultdict, deque, Counter\r\nimport sys\r\ninput = sys.stdin.readline\r\n \r\nclass Solution:\r\n def VasyaAndString(self, n, k, array):\r\n # TODO write an algorithm here\r\n window = k\r\n firstsum = 0\r\n for i in range(window):\r\n firstsum += array[i]\r\n minsum = firstsum\r\n answer = 1\r\n left, right = 0, window-1\r\n while right < n-1:\r\n firstsum -= array[left]\r\n left += 1\r\n right += 1\r\n firstsum += array[right]\r\n if firstsum < minsum:\r\n answer = left + 1\r\n minsum = min(minsum, firstsum)\r\n return answer\r\n \r\n \r\nif __name__ == \"__main__\":\r\n solution = Solution()\r\n n, k = list(map(int, input().split()))\r\n array = list(map(int, input().split()))\r\n print(solution.VasyaAndString(n, k, array))",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\n\r\nmin_sum = sum(h[:k])\r\nmin_index = 0\r\ncurr_sum = min_sum\r\n\r\nfor i in range(1, n - k + 1):\r\n curr_sum = curr_sum - h[i - 1] + h[i + k - 1]\r\n if curr_sum < min_sum:\r\n min_sum = curr_sum\r\n min_index = i\r\n\r\nprint(min_index + 1)\r\n",
"n, k = map(int, input().split())\r\n\r\na = list(map(int, input().split()))\r\n\r\nx = y = sum(a[:k])\r\n\r\nans = 1\r\nfor i in range(k, n):\r\n x = x - a[i - k] + a[i]\r\n if x < y:\r\n y = x\r\n ans = i - k + 2\r\n\r\nprint(ans)\r\n",
"x=lambda:map(int, input().split())\r\nn,k= x()\r\n*a,= x()\r\nm=s=sum(a[:k])\r\nr=1\r\nfor i in range(k, n):\r\n s+=a[i]-a[i-k]\r\n if s<m:\r\n m=s\r\n r=i-k+2\r\nprint(r)",
"n, k = map(int, input().split())\r\na = [int(x) for x in input().split()]\r\n\r\nb = [0]\r\nfor x in a :\r\n b.append(b[-1] + x)\r\nj = 0\r\nfor i in range(n - k + 1) :\r\n if b[i + k] - b[i] < b[j + k] - b[j] :\r\n j = i\r\nprint(j + 1)\r\n",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nn,m=map(int,input().split())\r\nlisty=list(map(int,input().split()))\r\nprefix=[sum(listy[:m])]\r\nfs=0\r\nfor i in range(m,n):\r\n fs=prefix[len(prefix)-1]+listy[i]-listy[i-m]\r\n prefix.append(fs)\r\n# print(prefix)\r\nprint(prefix.index(min(prefix))+1)\r\n",
"n, k = map(int, input().split())\r\nheights = list(map(int, input().split()))\r\n\r\nprefixes = [0]\r\nfor i in range(1, len(heights) + 1):\r\n prefixes.append(prefixes[i - 1] + heights[i - 1])\r\n\r\nmin_sum = 10**9\r\ncurrent_sum_index = 1\r\nfor i in range(k, n + 1):\r\n current_sum = prefixes[i] - prefixes[i - k]\r\n if (current_sum < min_sum):\r\n min_sum = current_sum\r\n current_sum_index = i - k + 1 \r\n\r\nprint(current_sum_index)",
"n,k = list(map(int,input().split()))\r\na = [int(x) for x in input().split()]\r\nc,b = sum(a[:k]),1\r\nd = c\r\nfor i in range(1, n - k + 1):\r\n c += a[i+k-1]-a[i-1]\r\n if c < d:\r\n d = c\r\n b = i + 1\r\nprint(b)",
"\r\nn,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\ns=0\r\nfor i in range(k):\r\n s+=arr[i]\r\n ind=1\r\nns=s\r\nfor i in range(k,len(arr)):\r\n ns+=arr[i]-arr[i-k]\r\n if ns<s:\r\n s=ns\r\n ind=i-k+2\r\nprint(ind)\r\n",
"(n, k), ar = map(int, input().split()), [0]+[int(el) for el in input().split()]\r\nfor i in range(1, len(ar)): ar[i] += ar[i-1]\r\nprint(min([[ar[l+k] - ar[l], l] for l in range(len(ar)-k)])[1]+1)",
"I=lambda:list(map(int,input().split()))\r\nn,k=I()\r\nh=I()\r\nm=t=sum(h[:k])\r\na=1\r\nfor i in range(k,n):\r\n t+=h[i]-h[i-k]\r\n if t<m:a=i-k+2;m=t\r\nprint(a)",
"n,k=map(int,input().split())\r\nh=list(map(int,input().split()))\r\nsumm=0\r\nhigh=[]\r\nfor i in range(k):\r\n summ+=h[i]\r\nhigh.append(summ)\r\nfor i in range(1,n-k+1):\r\n summ=high[i-1]-h[i-1]+h[i+k-1]\r\n high.append(summ)\r\nminn=high.index(min(high))\r\nprint(minn+1)",
"n,k = list(map(int,input().split()))\r\nh = list(map(int,input().split()))\r\ndp = sum(h[:k])\r\nlast = dp\r\nans = 0\r\n\r\nfor i in range(n-k):\r\n dp = dp-h[i]+h[i+k]\r\n if dp<last:\r\n ans = i+1\r\n last = dp\r\nprint(ans+1)\r\n",
"n, k = map(int, input().split())\n\nheights = list(map(int, input().split()))\n\nprefix_sum = [0]*(n+1)\n\nfor i in range(n):\n\tprefix_sum[i+1] = prefix_sum[i] + heights[i]\n\nres = [prefix_sum[i+k]-prefix_sum[i] for i in range(n-k+1)]\nprint(res.index(min(res)) + 1)\n",
"import sys\r\ninput = sys.stdin.readline\r\noutput = sys.stdout.write\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\n\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\n\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\n\r\n############ ---- Output Functions ---- ############\r\ndef outp(num):\r\n output(str(num) + '\\n')\r\n\r\ndef outlt(lst):\r\n output(' '.join(lst) + '\\n')\r\n\r\ndef outsr(st):\r\n output(''.join(st) + '\\n')\r\n\r\n\r\n############ ---- Solution Functions ---- ############\r\ndef solution():\r\n n, k = inlt()\r\n planks = inlt()\r\n\r\n curr_sum = sum(planks[0:k])\r\n best_index = 0\r\n best_sum = curr_sum\r\n for i in range(1,len(planks) - k + 1):\r\n curr_sum = curr_sum - planks[i-1] + planks[i+(k-1)]\r\n if curr_sum <= best_sum:\r\n best_index = i\r\n best_sum = curr_sum\r\n \r\n outp(best_index + 1)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n solution()",
"n,k=map(int, input().split())\r\na=list(map(int, input().split()))\r\nb=[]\r\nb.append(0)\r\ni=0\r\nwhile i<n:\r\n b.append(b[i]+a[i])\r\n i+=1\r\n# print(a)\r\n# print(b)\r\ns=sum(a)+1\r\n# print(s)\r\nind=1\r\ni=k\r\nwhile i<n+1:\r\n if b[i]-b[i-k]<s:\r\n ind=i-k+1\r\n s=b[i]-b[i-k]\r\n i+=1\r\nprint(ind)",
"\"\"\"THIS TEMPLATE belongs to anuj_negi\"\"\"\n\n#Try to use bisect in case of binary search, bisect_left, bisect_right\n#Try to use sortedcontainers when available\n#Try to use Multiset when available\nfrom bisect import *\nfrom heapq import *\n#from functools import cache, lru_cache\nfrom math import *\nfrom collections import defaultdict as ddc\nfrom collections import Counter\nfrom functools import *\nfrom itertools import *\nfrom sys import setrecursionlimit\n\ndef intin(): return int(input())\ndef mapin(): return map(int, input().split())\ndef strin(): return input().split()\n\n#----------------------------------------------\n\n\"\"\"\nSOME FACTS THAT CAN BE USED LATER - \n\n-> if n is prime, then -> (a**(n-1)) % n = 1\n\n-> When cases like DEFICIENT CITY to SURPLUS CITY, work on BFS using SURPLUS city and check for DEFICIENT city\n\n-> PALINDROMEs and str-len FACTORS have some relations. if P = XQ where P, X, Q are palindromes, then X have the possible length in Factors of 'n'\n\n\"\"\"\n\n#----------------------------------------------\n\"\"\"\n-> THIS IS A Interval Based Segmented Trees\n-> Can be modified or used later for similar\n\"\"\"\n\nclass IntervalSeg:\n def __init__(self):\n self.Seg = ddc(int)\n self.otherAdded = ddc(int)\n \n def update(self, s, e, l = 0, r = 10**9, index = 1):\n if r<=s or e<=l: return\n if s<=l<r<=e:\n self.Seg[index]+=1\n self.otherAdded[index]+=1\n \n else:\n m = (l+r)//2\n self.update(s, e, l, m, 2*index)\n self.update(s, e, m, r, 2*index + 1)\n self.Seg[index] = self.otherAdded[index] + max(self.Seg[2*index], self.Seg[2*index + 1])\n \n def use(self, start, end):\n self.update(start, end)\n return self.Seg[1]\n\n#----------------------------------------------\n\nINF = 10**20\nmod = 1000000007\n\n#----------------------------------------------\n\ndef hashit(arr, size, mod = (10**9 + 7)):\n #Subarray size - Rolling Hash - Custom\n \"\"\"\n mul -> must be greater than max(arr)\n rest can be modified\n \"\"\"\n if not size: return \n mul, hashh, div = 256, 0, (1<<(8*size-8))%mod\n \n C = ddc(list)\n for i in range(size):\n hashh = (mul * hashh + arr[i])%mod\n \n C[hashh].append(0)\n \n for i in range(len(arr)-size):\n #update the hashh\n hashh = (mul*(hashh-arr[i]*div) + arr[i+size])%mod\n C[hashh].append(i+1)\n \n return C\n\n#----------------------------------------------\n\ndef LIS(arr, n):\n dp = [10**9]*(n+1)\n \n for ele in arr:\n dp[bisect_left(dp, ele)] = ele\n #print(dp)\n return bisect_left(dp, 10**9)\n\n#----------------------------------------------\n\ndef exponentiation(bas, exp, mod = (10**9 + 7)):\n t = 1\n while(exp > 0): \n \n if (exp % 2 != 0):\n t = (t * bas) % mod\n \n bas = (bas * bas) % mod \n exp //= 2\n return t % mod\n\n#----------------------------------------------\n\ndef MOD(p, q=1, mod = 1000000007):\n expo = 0\n expo = mod - 2\n \n while (expo):\n if (expo & 1):\n p = (p * q) % mod\n q = (q * q) % mod\n expo >>= 1\n return p\n\n#----------------------------------------------\n\nyes = \"YES\"\nno = \"NO\"\neven = \"EVEN\"\nodd = \"ODD\"\nalice = \"ALICE\"\nbob = \"BOB\"\n\n#------------------------\n\ndef graphin(n):\n zz = ddc(set)\n for i in range(n-1):\n a, b = mapin()\n zz[a].add(b)\n zz[b].add(a)\n \n return zz\n\n\ndef process(arr, n, k):\n ans = [1e9, 0]\n curr = 0\n for i in range(k):\n curr += arr[i]\n \n ans[0] = curr\n for i in range(n-k):\n curr = curr-arr[i]+arr[i+k]\n if curr<ans[0]:\n ans = [curr, i+1]\n \n return ans[1]+1\n \n \ndef main():\n #T-testcases\n #graph = graphin(n)\n n, k = mapin()\n arr = list(mapin())\n ans = process(arr, n, k)\n print(ans)\n #print(\"Case {0}: {1}\".format(ans, _+1))\n\n#--------------------------\nif __name__ == \"__main__\":\n main()",
"#author: sushmanth\r\n\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n\r\ninp = lambda : list(map(int,input().split()))\r\n\r\ndef answer():\r\n\r\n s = 0\r\n for i in range(k):\r\n s += a[i]\r\n\r\n ans , index = s , 1\r\n for i in range(k , n):\r\n s -= a[i - k]\r\n s += a[i]\r\n\r\n if(ans > s):\r\n ans = s\r\n index = i - k + 2\r\n\r\n\r\n return index\r\n\r\n\r\n\r\nfor T in range(1):\r\n\r\n n , k = inp()\r\n a = inp()\r\n\r\n print(answer())\r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n",
"n, k = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\nans = tek = sum(a[:k])\r\nj_ans = 1\r\nfor i in range(k, n):\r\n tek -= a[i - k]\r\n tek += a[i]\r\n if ans > tek:\r\n j_ans = i - k + 2\r\n ans = tek\r\nprint(j_ans)\r\n",
"n, k = list(map(int, input().split()))\r\narr = list(map(int, input().split()))\r\nfrom math import *\r\nsumm = 0\r\nmin_sum = inf\r\n\r\n\r\n\r\nfor right in range(k):\r\n summ += arr[right]\r\nmin_sum = min(min_sum, summ)\r\nidx = 0\r\nfor i in range(k, n):\r\n summ = summ - arr[i - k] + arr[i]\r\n if summ < min_sum:\r\n min_sum = summ\r\n idx = i - k + 1\r\n \r\n\r\nprint(idx + 1)\r\n",
"R = lambda: map(int, input().split())\r\nn, k = R()\r\na = list(R())\r\nsum_actual = sum(a[:k])\r\nmin_sum = sum_actual\r\nmin_indice = 0\r\nfor i in range(1, n-k+1):\r\n sum_actual += a[i+k-1] - a[i-1]\r\n if sum_actual < min_sum:\r\n min_sum = sum_actual\r\n min_indice = i\r\nprint(min_indice + 1)",
"ar=lambda:list(map(int,input().split()))\r\nI=lambda:map(int,input().split())\r\nn,k=I()\r\n \r\nh=ar()\r\n \r\nm=t=sum(h[:k])\r\na=1\r\n#1 2 6 1 1 7 1\r\n#t=9+(1-(0))\r\nfor i in range(k,n):\r\n #print(i-k)\r\n t+=h[i]-h[i-k]\r\n if t<m:\r\n a=i-k+2;m=t\r\nprint(a)",
"a,b = map(int,input().split())\r\nlest = list(map(int,input().split()))\r\nnum = sum(lest[0:b])\r\nans = [num]\r\nfor x in range(1,a-b+1) :\r\n num-=lest[x-1]\r\n num+=lest[x+b-1]\r\n ans.append(num)\r\nprint(ans.index(min(ans))+1)\r\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ndef main() -> None :\r\n HOLE_WIDTH:int = inputArray()[1]\r\n FENCE_HEIGHTS:list[int] = inputArray()\r\n\r\n\r\n minFenceRangeIndex:int = -1\r\n \r\n fenceRangeSums:list[int] = []\r\n fenceRangeSums.append(sum(FENCE_HEIGHTS[:HOLE_WIDTH]))\r\n for fenseIndex in range(1, len(FENCE_HEIGHTS)-HOLE_WIDTH+1) :\r\n fenceRangeSums.append(fenceRangeSums[-1]-FENCE_HEIGHTS[fenseIndex-1]+FENCE_HEIGHTS[fenseIndex+HOLE_WIDTH-1]) \r\n minFenceRangeIndex = sorted(enumerate(fenceRangeSums), key=lambda e:e[1])[0][0]+1\r\n\r\n\r\n print(minFenceRangeIndex)\r\n\r\ndef inputArray() -> list[int] :\r\n return list(map(int, input().split()))\r\n\r\nmain()",
"n, k = map(int, input().split())\r\nh = list(map(int, input().split()))\r\n\r\nj = 0\r\ns = 0\r\nfor i in range(k):\r\n s += h[i]\r\n \r\nm = s\r\n\r\n \r\nfor i in range(1, n-k+1):\r\n s = s - h[i-1] + h[i+k-1]\r\n if s < m:\r\n m = s\r\n j = i\r\n \r\nprint(j+1)\r\n ",
"n,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nsu = 0\r\nfor i in range(k):\r\n su+=a[i]\r\nmn = su\r\nibest = 1\r\nfor i in range(k,n):\r\n su-=a[i-k]\r\n su+=a[i]\r\n if su<mn:\r\n mn = su\r\n ibest = i-k+2\r\nprint(ibest)\r\n",
"n_and_k = input()\r\nn, k = n_and_k.split() #n - кол-во целых чисел, k - кол-во элем. заданной посл-ти меньше либо равны x(результат программы)\r\nn = int(n)\r\nk = int(k)\r\n\r\ninput_string = input()\r\nvalues = input_string.split()\r\na = [int(value) for value in values] #последовательность целых чисел длины n\r\n\r\n\r\nm=s=sum(a[:k])\r\n\r\nr=1\r\nfor i in range(k,n):\r\n s+=a[i]-a[i-k]\r\n if s<m:\r\n m=s\r\n r=i-k+2\r\nprint(r)",
"n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nmin_height=sum(a[:k])\r\nnew_min_height=min_height\r\ni=0\r\nindex1=0\r\nwhile i+k<n:\r\n new_min_height=new_min_height-a[i]+a[i+k]\r\n if new_min_height<min_height:\r\n min_height=new_min_height\r\n index1=i+1\r\n i+=1\r\nprint(index1+1)\r\n",
"n, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nr = 0\r\nfor i in range(k):\r\n r += a[i]\r\ne = r\r\nr1 = 0\r\nfor i in range(k,n):\r\n e = e + a[i] - a[i-k]\r\n if e < r:\r\n r = e\r\n r1 = i-k+1\r\nprint(r1+1)\r\n",
"n, k = map(int, input().split())\r\nfence = list(map(int, input().split()))\r\n\r\nif all(x == fence[0] for x in fence):\r\n print(1)\r\nelse:\r\n window_sum = sum(fence[:k])\r\n min_sum = window_sum\r\n pos = 1\r\n for i in range(1, n-k+1):\r\n window_sum = window_sum - fence[i-1] + fence[i+k-1]\r\n if window_sum < min_sum:\r\n min_sum = window_sum\r\n pos = i+1\r\n\r\n print(pos)",
"len1,k=map(int,input().split())\r\nlist1=list(map(int,input().split()))\r\n\r\nsum1=0\r\nfor i in range(k-1):\r\n sum1+=list1[i]\r\nstart,end=0,k-1\r\nmin1=float('inf')\r\nind=0\r\nwhile(end<len1):\r\n sum1+=list1[end]\r\n if(sum1<min1):\r\n ind=start\r\n min1=sum1\r\n sum1-=list1[start]\r\n start+=1\r\n end+=1\r\n \r\nprint(ind+1)",
"n,k=map(int,input().split())\r\ns=[int(i) for i in input().split()]\r\n\r\nf1=f2=sum(s[:k])\r\na=0\r\n\r\nfor i in range(1,n-k+1):\r\n f1-=s[i-1]\r\n f1+=s[i+k-1]\r\n if f1<f2:\r\n f2=f1\r\n a=i\r\n\r\nprint(a+1)",
"n, k = map(int, input().split())\nheights = list(map(int, input().split()))\n\nmin_sum = sum(heights[:k])\nmin_index = 0\n\ncurr_sum = min_sum\nfor i in range(1, n - k + 1):\n curr_sum = curr_sum - heights[i - 1] + heights[i + k - 1]\n if curr_sum < min_sum:\n min_sum = curr_sum\n min_index = i\n\nprint(min_index + 1)\n\n\t\t\t\t \t\t\t \t \t\t\t \t \t \t \t\t",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nwindow = sum(a[:k])\r\nmini = window\r\nmini_idx = 0\r\nfor i in range(len(a)-k):\r\n window = window - a[i] + a[k+i]\r\n if mini > window:\r\n mini = window\r\n mini_idx = i+1\r\nprint(mini_idx+1)",
"import sys\r\ninput=sys.stdin.readline\r\nw,dis=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nprefix=[0]*(w)\r\nfor i in range(w):\r\n prefix[i]=prefix[i-1]+x[i]\r\nthesum=999999999999999999999999\r\nind=1\r\nfor i in range(w-dis+1):\r\n if i==0: val=prefix[dis-1]\r\n else: val=prefix[dis-1]-prefix[i-1]\r\n if val<thesum:\r\n thesum=val\r\n ind=i+1\r\n dis+=1\r\nprint(ind)",
"n, k = map(int, input().split())\r\ns = list(map(int, input().split()))\r\ni = 0\r\nj, mini = 0, 1.5*10**7+1\r\nsu = sum(s[:k])\r\nwhile i+k-1 < n:\r\n if i - 1 >= 0:\r\n su += s[i+k-1]-s[i - 1]\r\n if su < mini:\r\n mini = su\r\n j = i\r\n i+=1\r\nprint(j+1)",
"import sys\r\nn,k=map(int,sys.stdin.readline().split())\r\na=tuple(map(int,sys.stdin.readline().split()))\r\nb=[0]\r\nfor x in a:\r\n b.append(b[-1]+x)\r\nj=0\r\nfor i in range(n-k+1):\r\n if b[i+k]-b[i]<b[j+k]-b[j]:\r\n j=i\r\nprint(j+1)\r\n",
"y=lambda:map(int,input().split())\nn,k=y()\n*b,=y()\nm=s=sum(b[:k])\nq=1\nfor i in range(k,n):\n s+=b[i]-b[i-k]\n if s<m:\n m=s\n q=i-k+2\nprint(q)\n\t\t\t\t \t\t \t \t\t \t\t \t\t \t \t",
"num_fences, fences_to_paint = map(int, input().split())\nheight = list(map(int, input().split()))\n\nsum_height_fences = [0] * (num_fences + 1)\nfor i in range(1, num_fences + 1):\n sum_height_fences[i] = sum_height_fences[i - 1] + height[i - 1]\n\nmin_total_height = float('inf')\nstart_position = 1\n\nfor i in range(fences_to_paint, num_fences + 1):\n total_height = sum_height_fences[i] - sum_height_fences[i - fences_to_paint]\n if total_height < min_total_height:\n min_total_height = total_height\n start_position = i - fences_to_paint + 1\n\nprint(start_position)\n\n \t \t \t\t \t \t\t \t \t\t\t \t",
"n,k=list(map(int,input().split(' ')))\r\nheights=list(map(int,input().split(' ')))\r\nSum=sum(heights[:k])\r\nrSum=Sum\r\nres=1\r\nfor i in range(k,len(heights)):\r\n Sum=Sum-heights[i-k]+heights[i]\r\n if rSum>Sum:\r\n rSum=Sum\r\n res=i-k+2\r\nprint(res)",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\np = [0]*(n+1)\r\nfor i in range(1, n+1):\r\n p[i] = p[i-1] + a[i-1]\r\nj = k\r\nfor i in range(k, n+1):\r\n if p[i]-p[i-k] < p[j]-p[j-k]:\r\n j = i\r\nprint(j-k+1)",
"n, k = map(int, input().split())\nh = list(map(int, input().split()))\n\nif n == k:\n print(1)\nelif k == 1:\n print(h.index(min(h)) + 1)\nelse:\n current_sum = sum(h[:k])\n min_sum = current_sum\n min_index = 0\n\n for j in range(1, n - k + 1):\n current_sum = current_sum - h[j - 1] + h[j + k - 1]\n if current_sum < min_sum:\n min_sum = current_sum\n min_index = j\n\n print(min_index + 1)\n",
"x,y=map(int,input().split())\r\nz=list(map(int,input().split()));k=[z[0]]\r\nfor i in z[1:]:k.append(k[-1]+i)\r\nl=[k[y-1]]\r\nfor i in range(x-y):l.append(k[i+y]-k[i])\r\nm=min(l)\r\nfor i in range(len(l)):\r\n if l[i]==m:print(i+1);break"
] | {"inputs": ["7 3\n1 2 6 1 1 7 1", "1 1\n100", "2 1\n10 20", "10 5\n1 2 3 1 2 2 3 1 4 5", "10 2\n3 1 4 1 4 6 2 1 4 6", "2 2\n20 10", "2 1\n20 1", "3 1\n1 2 3", "3 1\n2 1 3", "3 1\n3 2 1", "3 2\n1 2 3", "3 2\n3 2 1", "3 3\n1 2 3", "4 2\n9 8 11 7", "4 2\n10 1 2 3", "6 3\n56 56 56 2 1 2", "8 3\n1 1 1 1 2 60 90 1", "4 1\n1 5 2 2", "4 2\n4 6 7 4", "10 4\n1 1 1 4 4 4 4 4 4 3", "6 3\n1 2 1 3 1 1", "5 2\n100 100 100 1 1"], "outputs": ["3", "1", "1", "1", "7", "1", "2", "1", "2", "3", "1", "2", "1", "1", "2", "4", "1", "1", "1", "1", "1", "4"]} | UNKNOWN | PYTHON3 | CODEFORCES | 209 | |
30a248252fde97fb2547f74417918dcc | The Big Race | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to *w* meters, and Bolt can perform only steps of length equal to *b* meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance *L*.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to *t* (both are included). What is the probability that Willman and Bolt tie again today?
The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*.
Sample Input
10 3 2
7 1 2
Sample Output
3/10
3/7
| [
"def gcd(a, b):\r\n if (b == 0):\r\n return a\r\n return gcd(b, a % b)\r\n\r\n\r\ns = input()\r\ns = s.split()\r\nt = int(s[0])\r\nw = int(s[1])\r\nb = int(s[2])\r\ng = gcd(w, b)\r\nw = w // g\r\nr = w * b\r\nw = w * g\r\nk = (t // r) + 1\r\nans = (k - 1) + (min(w, b) - 1) * (k - 1) + min(t % r, min(w, b) - 1)\r\nng = gcd(ans, t)\r\nprint(ans // ng, t // ng, sep = '/')\r\n",
"from fractions import gcd\r\ni = input\r\nt,w,b=map(int,i().split())\r\ng = gcd(w,b)\r\na = (w//g)*b\r\ncnt = t//a\r\ncnt = cnt*(min(w,b))+ min(min(w,b)-1,t-a*cnt)\r\ng = gcd(cnt,t)\r\nprint('%d/%d'%(cnt//g,t//g))\r\n",
"from fractions import gcd, Fraction\r\nt, w, b = map(int, input().split())\r\nif w > b:\r\n w, b = b, w\r\nnok = w * b // gcd(w, b)\r\ncnt = t // nok\r\nans = Fraction(cnt * w - 1 + min([t-cnt*nok+1, w]), t)\r\nprint(\"{0}/{1}\".format(ans.numerator, ans.denominator))\r\n",
"import sys\r\nimport math\r\nfrom fractions import Fraction\r\n\r\n#sys.stdin = open('input.txt')\r\n\r\nt, w, b = map(int, input().split())\r\n\r\nlcm = (w*b)//math.gcd(w, b)\r\nm = min(w, b)\r\nc = t//lcm\r\nans = min(m - 1, t) + c*m\r\nif m > t%lcm + 1 and c != 0:\r\n ans -= m - t%lcm - 1\r\n\r\nans_frac = Fraction(ans, t)\r\nprint('{}/{}'.format(ans_frac.numerator, ans_frac.denominator))",
"\r\ndef gcd(a, b):\r\n if b == 0:\r\n return a\r\n return gcd(b, a % b)\r\n\r\n\r\ndef lcm(a, b):\r\n return a * b // gcd(a, b)\r\n\r\n\r\nt, w, b = [int(x) for x in input().split()]\r\nlc = lcm(w, b)\r\nlen = (t // lc)\r\ncnt = (len * min(w, b))\r\ncnt += min(t % lc + 1, min(w, b))\r\ncnt = cnt - 1\r\ng = gcd(cnt, t)\r\nif cnt <= t:\r\n print('{0}/{1}\\n'.format(cnt // g, t // g))\r\nelse:\r\n print('1/1')\r\n",
"import math\n\nt, w, b = list(map(int, input().split()))\n\nu = w * b // math.gcd(w, b)\nminval = min(w, b)\nans = t // u * minval+min(minval-1, (t % u))\n\nbuf = math.gcd(ans, t)\n\nprint(str(ans // buf)+\"/\"+str(t // buf))\n\n \t\t \t\t\t \t\t \t \t \t\t\t\t \t \t\t\t",
"import sys\r\nimport math\r\nfrom fractions import Fraction\r\n\r\n#sys.stdin = open('input.txt')\r\n\r\nt, w, b = map(int, input().split())\r\n\r\nlcm = (w*b)//math.gcd(w, b)\r\nans = (t//lcm + 1)*min(w, b) - max(0, min(w, b) - t%lcm - 1) - 1\r\n\r\nans_frac = Fraction(ans, t)\r\nprint('{}/{}'.format(ans_frac.numerator, ans_frac.denominator))",
"#! /usr/bin/python3\r\n\r\n\r\ndef gcd(a, b) :\r\n\treturn a if b == 0 else gcd(b, a % b)\r\n\r\ndef lcm(a, b):\r\n\treturn a * b // gcd(a, b)\r\n\r\nL, w, b = input().split()\r\nL = int(L)\r\nw = int(w)\r\nb = int(b)\r\n\r\nif w > b:\r\n\tw, b = b, w\r\n\r\n\r\n#print(gcd(w, b))\r\n_lcm = lcm(w, b)\r\n\r\ntimes = L // _lcm\r\n\r\n\r\nmargen = 0\r\nif w >= 2:\r\n\tmargen = w-1\r\n\r\nres = times\r\nres += margen*times;\r\nres += min(margen, L % _lcm)\r\n\r\n\r\n\r\n\r\nprint(str(res//gcd(res, L))+'/'+str(L//gcd(res, L)))",
"from math import gcd\r\ndef lcm(x, y):return x // gcd(x, y) * y\r\nn, m, k = map(int, input().split())\r\nlc = lcm(m, k)\r\ncnt = n // lc\r\nlast = min(m, k) - 1\r\nres = min(n - (cnt * lc), last) + cnt + (cnt * last)\r\ngc = gcd(res, n)\r\nprint(str(res // gc) + '/' + str(n // gc))",
"from fractions import gcd\r\n\r\ndef lcm(a, b):\r\n return (a * b) // gcd(a, b)\r\n\r\nt, w, b = map(int, input().split())\r\nif w > b:\r\n w, b = b, w\r\n\r\nlc = lcm(w, b)\r\nk = t // lc\r\n\r\nres = 0\r\nres += k * w - 1\r\nres += min(t - lc * k + 1, w)\r\n\r\ng = gcd(res, t)\r\nres //= g\r\nt //= g\r\nprint('{}/{}'.format(res, t))\r\n",
"import fractions\r\n\r\nstra = input();\r\nlista = stra.split();\r\nn = int(lista[0]);\r\na = int(lista[1]);\r\nb = int(lista[2]);\r\n\r\n\r\ngab = fractions.gcd(a, b);\r\n\r\nl = a//gab*b;\r\n\r\n# print(l);\r\n\r\n\r\nans = n // l * min(a, b);\r\n# print(ans);\r\n\r\nans += min(n % l, min(a, b) - 1);\r\n# print(ans);\r\n\r\ng = fractions.gcd(ans, n);\r\n\r\n# print(g)\r\n\r\nans //= g;\r\nn //= g;\r\n\r\nprint(str(ans)+'/'+str(n));",
"import math\n\ndef euclid_algorithm(a, b):\n t1, t2 = abs(a), abs(b)\n #saving equalities:\n #t1 == x1 * a + y1 * b,\n #t2 == x2 * a + y2 * b. \n x1, y1, x2, y2 = int(math.copysign(1, a)), 0, 0, int(math.copysign(1, b))\n if t1 < t2:\n t1, t2 = t2, t1\n x1, y1, x2, y2 = x2, y2, x1, y1\n\n while t2 > 0:\n if x1 * a + y1 * b != t1:\n print('inshalla')\n k = int(t1 // t2)\n t1, t2 = t2, t1 % t2\n #t1 - k * t2 == (x1 - k * x2) * a + (y1 - k * y2) * b\n x1, y1, x2, y2 = x2, y2, x1 - k * x2, y1 - k * y2\n\n return t1, x1, y1\n\ndef opposite_element(x, p):\n gcd, k, l = euclid_algorithm(x, p)\n if gcd != 1:\n return -1\n return k % p\n\nt, w, b = [int(x) for x in input().split()]\ngcd = euclid_algorithm(w,b)[0]\nlcm = w * b // gcd\nans = ((t+1) // lcm) * min(w,b) + min((t+1)%lcm, w, b) - 1\nnew_gcd = euclid_algorithm(ans, t)[0]\nprint('{0}/{1}'.format(ans//new_gcd, t//new_gcd))\n\n",
"def gcd(a, b):\r\n if (b == 0):\r\n return a\r\n else:\r\n return gcd(b, a % b)\r\n\r\ndef lcm(a, b):\r\n return a*b//gcd(a, b)\r\n\r\nt, w, b = (int(i) for i in input().split())\r\nx = min(w, b)\r\ny = t//lcm(w, b)\r\nans = x - 1 + x*(y - 1) + min(((t % lcm(w, b)) + 1), x);\r\nif t < max(w, b):\r\n if t < min(w, b):\r\n ans = t;\r\n else:\r\n ans = min(w, b) - 1;\r\nprint(ans//gcd(ans, t), \"/\", t//gcd(ans, t), sep = '')\r\n",
"from math import gcd\n\nt,w,b=tuple(map(int,input().split()))\n\ngd=gcd(w,b)\ngw=(w*b)//gd\nof=min(w,b)-1\n\nret=0\ni=(t//gw) \n\n\nret+=(i+1)*(of+1) -1\n\ne=i*gw\n\nret-=max((e+of-t),0)\n\nprint( str(ret//gcd(ret,t)) +'/'+ str(t//gcd(ret,t)) )\n",
"import math as m\nt,w,b=map(int,input().split())\ngc=m.gcd(w,b)\nmini=min(w,b)\nlc=(w*b)//gc\nbot=t\nnum=t//lc + 1\ncnt=0\ncnt+=(num-1)*mini\ntemp=(num-1)*lc\ncnt+=min(t,temp+mini-1)-temp\ngc2=m.gcd(cnt,bot)\ncnt=cnt//gc2\nbot=bot//gc2\nprint(cnt,'/',bot,sep='')",
"import math\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef lcm(a, b):\r\n return a * b // math.gcd(a, b)\r\n\r\nt, w, b = map(int, input().split())\r\nl = lcm(w, b)\r\np, q = t // l * min(w, b) + min(t % l + 1, w, b) - 1, t\r\ng = math.gcd(p, q)\r\np //= g\r\nq //= g\r\nans = \"/\".join(map(str, (p, q)))\r\nprint(ans)",
"import sys\r\ninput=sys.stdin.readline\r\nfrom math import gcd\r\ndef lcm(a,b):\r\n return a*b//gcd(a,b)\r\nt,w,b=map(int,input().split())\r\nl=lcm(w,b)\r\nr=t%l\r\ncnt=(t//l)*min(w,b)-1+min(min(w,b)-1,r)+1\r\ng=gcd(cnt,t)\r\ncnt//=g;t//=g\r\nprint(str(cnt)+\"/\"+str(t))",
"import math\r\n\r\ndef solve(d, a, b):\r\n tmp=d\r\n c=math.gcd(a,b)\r\n ans=-1\r\n while d//b >= a//c:\r\n lc=a//c*b\r\n ans+=tmp//lc*min(a,b)\r\n d%=lc\r\n ans+=min(a,b,d+1)\r\n c=math.gcd(ans,tmp)\r\n ans//=c\r\n tmp//=c\r\n return str(ans)+\"/\"+str(tmp)\r\n\r\ndef robot(lst):\r\n fn=[]\r\n for i in lst:\r\n d,a,b=i[0],i[1],i[2]\r\n if min(a,b)<0:\r\n fn.append(-1)\r\n if d<1:\r\n fn.append(-1)\r\n else:\r\n fn.append(d,a,b)\r\n\r\nd,a,b=map(int,input().split())\r\nprint(solve(d,a,b))\r\n \r\n",
"def gcd(a, b):\r\n if b == 0:\r\n return a\r\n return gcd(b, a % b)\r\ndef lcm(a, b):\r\n return a * b // gcd(a, b)\r\nt, w, b = map(int, input().split())\r\nif w > b:\r\n w, b = b, w\r\nl = lcm(w, b)\r\nans = w - 1\r\nans += w * ((t // l) - 1)\r\nans += min(w, t + 1 - l * (t // l))\r\ng = gcd(ans, t)\r\nans //= g\r\nt //= g\r\nprint(str(ans) + \"/\" + str(t))\r\n",
"import math\r\nimport sys\r\n\r\ndef Cmmdc(a, b):\r\n\tr = 0\r\n\twhile b > 0:\r\n\t\tr = a % b\r\n\t\ta = b\r\n\t\tb = r\r\n\treturn a\r\n\r\nlst = list(map(int, input().split()))\r\n\r\nt = auxT = lst[0]\r\nn = lst[1]\r\nm = lst[2]\r\n\r\nif n > m:\r\n\taux = n\r\n\tn = m\r\n\tm = aux\r\n\r\ncmmdc = Cmmdc(n, m)\r\ncmmmc = n * m // cmmdc\r\n\r\nfav = (t // cmmmc) * n\r\nt = t % cmmmc\r\nfav += min(n - 1, t)\r\n\r\nt = auxT\r\nc = Cmmdc(fav, t)\r\nfav //= c\r\nt //= c\r\n\r\nprint(str(fav) + \"/\" + str(t) + \"\\n\")\r\n",
"\r\ndef GCD(a,b):\r\n if (b == 0): \r\n return a \r\n return GCD(b, a % b) \r\n \r\n \r\nt,w,b=map(int,input().split())\r\n\r\nvar = (w * b)\r\ngc = GCD(w,b)\r\nX =(var//(gc))\r\nlim = min({t+1,w,b})-1\r\nx = (t-lim)//X +1\r\nsum = (lim+1)*x -1\r\nleft = x*X\r\nsum+= max(0,(t-left+1))\r\ndiv = GCD(sum,t)\r\nprint(\"{p}/{q}\".format(p=sum//div , q=t//div))\r\n\r\n",
"def gcd(a, b):\r\n if a % b == 0:\r\n return b\r\n else:\r\n return gcd(b, a % b)\r\ndef lcm(a, b):\r\n return a * b // gcd(a, b)\r\n \r\nt, w, b = input().split( ' ' )\r\nb = int(b)\r\nw = int(w)\r\nt = int(t)\r\n\r\n\r\ntmp = lcm(w, b)\r\ncnt = t//tmp\r\nans = 0;\r\nif cnt*tmp + min(w, b) > t:\r\n ans = ans + t - cnt * tmp + 1\r\n cnt = cnt - 1\r\nans = ans + (cnt + 1)*min(w, b) - 1\r\nk = gcd(ans, t)\r\nans = ans // k\r\nt = t // k\r\nprint (\"%d/%d\" % (ans, t))",
"def gcd(a, b):\r\n return a if b == 0 else gcd(b, a % b)\r\n\r\ndef main():\r\n t, a, b = map(int, input().split())\r\n if b < a:\r\n a, b = b, a\r\n\r\n lcm = b // gcd(a, b) * a\r\n acc = (t // lcm) + (t // lcm + 1) * (a - 1)\r\n acc -= 0 if a < 1 + t % lcm else (a - t % lcm - 1)\r\n\r\n g = gcd(acc, t)\r\n print('{}/{}'.format(acc // g, t // g))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"from fractions import gcd\r\ndef lcm (a, b):\r\n return a // gcd(a, b) * b\r\nt, w, b = map(int, input().split())\r\npreans = t // lcm(w,b) * min(w, b) + min(min(w,b) - 1, t % lcm(w, b))\r\nansh = preans // gcd(preans, t)\r\nansl = t // gcd(preans, t)\r\nprint(ansh, '/', ansl, sep = \"\")",
"def gcd(a, b):\r\n\tif b == 0:\r\n\t\treturn a\r\n\telse:\r\n\t\treturn gcd(b, a%b)\r\n\r\ndef lcm(a, b):\r\n\treturn a*b//gcd(a, b)\r\n\r\nt, a, b = map(int, input().split(\" \"))\r\n\r\np = 0\r\nq = t\r\n\r\nl = lcm(a, b)\r\np += t//l*min(a, b)-1\r\np += min(t,t//l*l+min(a, b)-1)-t//l*l+1\r\n\r\ng = gcd(p, q)\r\np //= g\r\nq //= g\r\nprint(str(p)+\"/\"+str(q))\r\n",
"import sys\n\ndata = sys.stdin.readline()\ndata = map(int, data.split())\n\ndef gcd(u, v):\n while v!=0:\n r = u%v\n u=v\n v=r\n return u\n\nt, w, b = tuple(data)\nppcm = w*b // gcd(w, b)\np = (t//ppcm + 1)*min([w,b])-1\np-=max([(t//ppcm)*ppcm+min([w,b])-t-1,0])\nd = gcd(p,t)\nprint(str(p//d)+'/'+str(t//d))\n",
"import fileinput\nimport sys\nfrom fractions import gcd\n\n\nfor line in fileinput.input():\n data = line.split()\n break\n\nt = int(data[0])\nw = int(data[1])\nb = int(data[2])\n\nif w == b:\n print('%d/%d' % (1, 1))\n sys.exit()\n\nif w > b:\n w, b = b, w\n\ng = gcd(b, w)\ny = b // g\n\nA = t // (w * y)\nanswer = A * w\n\nadd = t % (w * y)\nadd = min(add, w - 1)\n\nanswer += add\n\ng = gcd(answer, t);\nprint('%d/%d' % (answer // g, t // g)) \n\n",
"def g(a,b):\r\n if(0==b):return a\r\n return g(b,a%b)\r\ni=input\r\nt,w,b=map(int,i().split())\r\nl=(w*b)//g(w,b)\r\nm=min(w,b)\r\nr=t//l*m + min(m-1,t%l)\r\ne=g(t,r)\r\nprint('%d/%d'%(r//e,t//e))",
"from math import gcd\r\nt,a,b=map(int,input().split())\r\nl=(a*b)//gcd(a,b)\r\na,b=min(a,b),max(a,b)\r\nx=t//l\r\nans=(x)*a+min(t-l*(x),a-1)\r\nx=gcd(ans,t)\r\nprint(ans//x,end=\"/\")\r\nprint(t//x)",
"from math import gcd\r\nt, a, b = list(map(int, input().split()))\r\n\r\nif a > b:\r\n a, b = b, a\r\nlcmab = a * b // gcd(a, b)\r\nres = (t // lcmab + 1) * a - 1\r\nlmax = t // lcmab * lcmab + a - 1\r\nif lmax > t:\r\n res -= lmax - t\r\ngcdrt = gcd(res, t)\r\nprint(\"{}/{}\".format(res // gcdrt, t // gcdrt))",
"import math\r\ndef ggcd(x, y):\r\n while(y):\r\n x, y = y, x % y\r\n return x\r\nt, w, b = map(int, input().split())\r\n\r\ntot = t\r\ndraw = 0\r\n\r\nlcm = w * b // ggcd(int(w), int(b))\r\n\r\ncadd = min(w, b) - 1\r\n\r\ncur = tot // lcm\r\n\r\nif(cur * lcm + cadd > t):\r\n draw = draw + 1 + cadd - ((int(cur) * int(lcm) + int(cadd)) - t);\r\n cur = int(cur) - 1;\r\n\r\ndraw = draw + (1 + int(cadd)) * (int(cur) + 1)\r\n\r\ndraw = draw - 1\r\n\r\ngg = ggcd(int(tot), int(draw))\r\n\r\nprint(int(draw) // int(gg), end = '/')\r\nprint(int(tot) // int(gg))\r\n",
"#cin>>n>>x>>y>>z;\r\ndef gcd(a,b): \r\n if(b==0): \r\n return a \r\n else: \r\n return gcd(b,a%b)\r\n \r\nt,w,z=map(int,input().split(' '))\r\nn=min(w,z)\r\nif(n==1):\r\n p=max(w,z)\r\n y=t//p\r\n z=gcd(t,y)\r\n print(\"%d/%d\"%(y//z,t//z))\r\nelse:\r\n \r\n y=(w*z)//(gcd(w,z))\r\n r=(t//y)\r\n pp =( min((r*y) + n-1 , t))\r\n pp =( pp - (r*y))\r\n q1=(r+(r*(n-1))+pp)\r\n z=(gcd(q1,t))\r\n# print(\"%d/%d\"%(y/z,t/z))\r\n print(\"%d/%d\"%((q1//z),(t//z)))",
"s=input().split(' ')\r\nt=int(s[0]); a=int(s[1]); b=int(s[2]);\r\n\r\ndef gcd(a,b):\r\n if b==0:\r\n return a\r\n return gcd(b,a%b)\r\n\r\nif a==b:\r\n print(\"1/1\")\r\n exit()\r\n\r\nif a==1 | b==1:\r\n nb=max(a,b)\r\n p=gcd(t,nb)\r\n print(nb//p,end='')\r\n print(\"/\",end='')\r\n print(t//p)\r\n\r\nelse :\r\n lcm=a//gcd(a,b)*b\r\n nb=t//lcm\r\n fz=nb*min(a,b)\r\n if t>=lcm*nb+min(a,b):\r\n fz=fz+min(a,b)-1\r\n else :\r\n fz=fz+(t-lcm*nb)\r\n p=gcd(t,fz)\r\n print(fz//p,end='')\r\n print(\"/\",end='')\r\n print(t//p)\r\n\r\n",
"from fractions import gcd\n\ndef lcm(a, b):\n return (a * b) // gcd(a, b)\n\n\nif __name__ == '__main__':\n t, w, b = map(int, input().split())\n\n l = lcm(w, b)\n m = min(w, b)\n\n count = t // l\n result = count * m\n result += (m - 1) # 1 to m-1\n\n diff = max(count*l + m - t - 1, 0)\n result -= diff\n\n g = gcd(result, t)\n\n print('{}/{}'.format(result//g, t//g))\n\n\n",
"from fractions import gcd\r\na,b,c = map(int,input().split())\r\nlcm1 = b*c//gcd(b,c)\r\nans1 = (a//lcm1)*min(b,c)-1\r\nans1 += min(a%lcm1+1, min(b,c))\r\nans1 = int(ans1)\r\nprint(str(ans1//gcd(ans1,a))+\"/\"+str(a//gcd(ans1,a)))",
"from fractions import gcd\r\n\r\nt,w,b = map(int,input().split())\r\nif w>b: w,b=b,w\r\nlcm = w//gcd(w,b)*b\r\nans = (t//lcm+1)*w-1\r\nif t%lcm+1 < w:\r\n\tans -= w - (t%lcm+1)\r\ng = gcd(ans,t)\r\nprint(\"%d/%d\"%(ans//g,t//g))",
"import math\r\n\r\ndef lcm(a, b): return (a*b)//(math.gcd(a,b))\r\n\r\nt, a, b = [int(x) for x in input().split()]\r\nmcm = lcm(a, b)\r\nmn = min(a,b)-1\r\ncycles = t//mcm\r\nans = ((cycles*mn)) + min(mn, t%mcm) + cycles\r\ng = math.gcd(ans, t)\r\nprint(ans//g, \"/\", t//g, sep=\"\")\r\n",
"import math\r\nt , w , b = map(int,input().split(' '))\r\nl = t // (w*b //math.gcd(w,b))\r\nnumerator = l*min(w,b) + min(t - l*(w*b //math.gcd(w,b))+1,min(w,b)) - 1\r\nprint(numerator//math.gcd(numerator,t),'/',t//math.gcd(numerator,t),sep='')",
"def gcd(a,b):\r\n\tif b == 0:\r\n\t\treturn a\r\n\telse:\r\n\t\treturn gcd(b, a%b)\r\n\r\nn, a, b = map(int, input().split())\r\n\r\ng = gcd(a,b)\r\nlcm = a*b//gcd(a,b)\r\n\r\nmul = n//lcm\r\n\r\nextra = mul * (min(a,b) - 1)\r\n\r\nlast = mul*lcm\r\nleft = n-last\r\ntotal = mul + extra + min(min(a,b)-1, left)\r\ntotal = min(total, n)\r\n\r\n\r\ng = gcd(total, n)\r\ntotal = total//g\r\nn = n//g\r\nprint(str(total) + '/' + str(n))\r\n",
"from fractions import gcd\n\nt, a, b = map(int, input().split())\n\nif a > b:\n a, b = b, a\n\nlcm = a * b // gcd(a, b)\ncnt = t // lcm\nlst = lcm * cnt\n\nans = cnt * a + a - 1 \n\nif lst + a > t + 1:\n ans -= lst + a - t - 1\n\nnum = ans\nden = t\n\ng = gcd(num, den)\nnum //= g\nden //= g\n\nprint(num, den, sep='/')\n\n",
"from fractions import gcd\n\nt, w, b = map(int, input().split())\nmn = min(w, b)\nnk = w // gcd(w, b) * b\nfirst = (t + 1) // nk * mn - 1\ne = first + min(mn, (t + 1) % nk)\nnd = gcd(e, t)\nprint(e // nd, \"/\", t // nd, sep = \"\")\n",
"\r\nfrom fractions import gcd\r\na, b, c = map(int, input().split(' '))\r\nl = b * c // gcd(b, c)\r\nb, c = min(b, c), max(b, c)\r\n\r\n## 0...b-1 ##\r\nmults = a // l\r\nrem = a - l * mults + 1\r\n\r\nnum = mults * (b)\r\nrem = min(b, rem)\r\nx = num + rem - 1\r\n\r\ng = gcd(x, a)\r\nprint(str(x//g) + '/' + str(a//g))\r\n",
"def evklid(a, b):\r\n while b > 0:\r\n a, b = b, a % b\r\n return a\r\n\r\nt, w, b = tuple(map(int, input().split()))\r\ny = min(w, b)\r\nNOD = evklid(w, b)\r\nNOK = w * b // NOD\r\nnumd = t // NOK + 1\r\n\r\n\r\nm = y * (numd - 1) - 1\r\nm = m + t % NOK + 1 if y > t % NOK else m + y\r\nprint(str(m // evklid(m, t)) + '/' + str(t // evklid(m, t))) ",
"def gcd(a,b):\r\n if a==0:\r\n return b\r\n return gcd(b%a,a)\r\nl=list(map(int,input().split()))\r\nt=l[0]\r\nw=l[1]\r\nb=l[2]\r\nans = 0\r\nlcm = (w*b)//gcd(w,b)\r\nmul = t//lcm\r\nif w > b:\r\n temp = w\r\n w = b\r\n b = temp\r\nif t < lcm*mul + w -1 :\r\n ans = t - lcm*mul + 1\r\nelse:\r\n ans = w\r\n\r\nans += mul*w - 1\r\ng2 = gcd(ans,t)\r\nprint(ans//(g2),\"/\",t//(g2),sep=\"\")\r\n\r\n",
"import math\r\nt,w,b = map(int,input().split())\r\nl = t//(w*b//math.gcd(w,b))\r\nn = l*min(w,b) + min(t-l*(w*b//math.gcd(w,b))+1,min(w,b)) - 1\r\nprint(n//math.gcd(n,t),'/',t//math.gcd(n,t),sep='')",
"#!/usr/bin/env python3\r\n\r\nimport sys\r\nfrom fractions import Fraction, gcd\r\n\r\n\r\ndef lcm(x, y): return x // gcd(x, y) * y\r\n\r\n\r\ndef f(t, w, b):\r\n l = lcm(w, b)\r\n t += 1\r\n t0 = t - t % l\r\n ans = t0 // l * min(w, b)\r\n ans += min(t % l, min(w, b))\r\n ans -= 1\r\n return Fraction(ans, t - 1)\r\n\r\nt, w, b = list(map(int, sys.stdin.readline().split()))\r\nans = f(t, w, b)\r\nprint(\"{}/{}\\n\".format(ans.numerator, ans.denominator))\r\n",
"t, v1, v2 = map(int, input().split())\r\n\r\n\r\ndef gcd(a, b):\r\n c = 0\r\n while b > 0:\r\n c = a % b\r\n a = b\r\n b = c\r\n return a\r\n\r\n\r\nif v1 < v2:\r\n te = v1\r\n v1 = v2\r\n v2 = te\r\n\r\n\r\nk = v1 * v2 // gcd(v1, v2)\r\nr = v2 - 1\r\nr += (t // k) * v2\r\nh = (t // k) * k\r\nad = (t // k) * k + v2 - 1 - t\r\nif ad > 0:\r\n r -= ad\r\nprint(str(r // gcd(t, r)) + str(\"/\") + str(t // gcd(t, r)))",
"def gcd(a,b):\r\n if b == 0:\r\n return a\r\n return gcd(b,a%b)\r\ndef lcm(a,b):\r\n return (a*b)//gcd(a,b)\r\nt,w,b = map(int,input().split())\r\nlc = lcm(w,b)\r\nmn = 0\r\nif w > b:\r\n mn = b\r\nelse:\r\n mn = w\r\nans = mn*(t//lc+1)-1\r\nval = (t//lc)*lc + mn - 1\r\nif t - val < 0:\r\n ans += t-val\r\ng = gcd(ans,t)\r\nans //= g\r\nt //= g\r\nprint(ans,end=\"\")\r\nprint(\"/\",end=\"\")\r\nprint(t) ",
"def gcd(a,b):\r\n if a<b:\r\n a,b=b,a\r\n while b!=0:\r\n tmp=a%b\r\n a=b\r\n b=tmp\r\n return a\r\n\r\ndata = input().split()\r\nl = int(data[0])\r\nw = int(data[1])\r\nb = int(data[2])\r\nm = min(w,b)\r\nt = w*b//gcd(w,b)\r\nres = l//t*m + min(l%t,m-1)\r\npp = gcd(res,l)\r\na1 = res//pp\r\na2 = l//pp\r\nprint(\"%u/%u\"%(a1,a2))\r\n",
"#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n#Suka. Eto prosto pizdets\r\n#Menya davno tak ne bombilo\r\n#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\ndef gcd (a, b):\r\n while (a != 0 and b != 0):\r\n if (a > b): a %= b\r\n else: b %= a\r\n return a + b\r\n\r\nn, a, b = list (map (int, input().split()))\r\nk = a // gcd (a, b) * b\r\nif (a > b): a, b = b, a\r\nans = (n // k + 1) * a - 1\r\nif (n % k < a): ans -= a - n % k - 1\r\nk = gcd (n, ans)\r\nprint (str (ans // k) + \"/\" + str (n // k))",
"t, w, b = map(int, input().split())\r\n\r\ndef gcd(a, b):\r\n if b == 0: return a\r\n return gcd(b, a % b)\r\n\r\ndef lcm(a, b):\r\n return a // gcd(a, b) * b\r\n\r\nadd = min(w, b) - 1\r\nl = lcm(w, b)\r\n\r\ncnt = t // l\r\n\r\nans = add + cnt + cnt * add\r\nans -= max(0, l * cnt + add - t)\r\n\r\ng = gcd(ans, t)\r\nif g != 0:\r\n ans //= g\r\n t //= g\r\n\r\nprint(ans, end='')\r\nprint('/', end='')\r\nprint(t)\r\n",
"def gcd(a, b):\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n\ndef lcm(a, b):\n return (a*b) // gcd(a, b)\n\nl = list(map(int, input().split()))\nt = l[0]\nw = l[1]\nb = l[2]\nans = t // lcm(w, b) + 1\nans = (ans - 1) * min(w, b) - 1\nans += 1\nans += min(min(w, b) - 1, t % lcm(w, b))\ng = gcd(ans, t)\nt = t // g\nans = ans // g\ns = str(ans) + \"/\" + str(t)\nprint(s)\n\n\t \t\t \t \t\t \t \t \t\t \t \t\t\t\t\t",
"t, a, b = map(int, input().split())\r\n\r\ndef gcd(a, b):\r\n if (b == 0):\r\n return a\r\n return gcd(b, a % b)\r\n\r\ndef lcm(a, b):\r\n return a // gcd(a, b) * b\r\n\r\nl = lcm(a, b)\r\nlast = t // l * l\r\nans = t // l * min(a, b)\r\nans += min(a, b, t - last + 1)\r\nans -= 1\r\ng = gcd(ans, t)\r\nans //= g\r\nt //= g\r\nans = str(ans) + '/' + str(t)\r\nprint(ans)\r\n\r\n",
"\ndef gcd(a,b):\n if a<b:\n t=b;\n b=a;\n a=t;\n if b==0:\n return a;\n return gcd(b,a%b)\n\n\nt,w,b = [int(x) for x in input().split()]\n\ng=gcd(w,b)\nnsn=w*b//g;\n\nk=t//nsn\n\nr=t%nsn\n\nres=k*min(w,b)+min(r+1,min(w,b))-1\nif t<nsn:\n res=min(t,min(w-1,b-1))\n \n\ng2=gcd(res,t)\ns=str(res//g2)+\"/\"+str(t//g2)\n\nprint(s)\n\n\n",
"from fractions import gcd, Fraction\r\nt, w, b = map(int, input().split())\r\nif w > b:\r\n w, b = b, w\r\ng = gcd(w,b)\r\nx = w*b//g\r\ndivision, remainder = t//x, t%x\r\na = division*w+min(remainder, w-1)\r\ng = gcd(t, a)\r\nprint(a//g, \"/\", t//g, sep=\"\")",
"def gcd(a, b):\r\n return a if b == 0 else gcd(b, a % b)\r\n\r\n\r\nt, w, b = map(int, input().split())\r\nlcm = w // gcd(w, b) * b\r\ngap = min(w, b)\r\nans = t // lcm * gap + min(t % lcm, gap - 1)\r\n\r\nd = gcd(ans, t)\r\nprint(ans // d, '/', t // d, sep='')\r\n",
"from fractions import gcd\r\nt,w,b=map(int,input().split())\r\nlcm=(w*b)//gcd(w,b)\r\nres=(t//lcm)*min(w,b)\r\nres+=min((min(w,b)-1),t%lcm)\r\nf=gcd(res,t)\r\nprint (\"{0}/{1}\".format(res//f,t//f))\r\n",
"import math\r\n\r\n\r\nT, W, B = map(int, input().split())\r\n\r\nspace = min(W, B)\r\narong = W // math.gcd(W, B) * B\r\nadd = 0\r\nadd += (T // arong) * space;\r\nadd += min(space, T % arong + 1)\r\nadd -= 1\r\n\r\nif add == 0:\r\n print(\"0/1\")\r\nelse:\r\n v = math.gcd(T, add);\r\n T //= v;\r\n add //= v;\r\n print(add,\"/\",T, sep='')\r\n",
"'''input\r\n10 3 2\r\n'''\r\nimport fractions\r\nt,a,b=map(int,input().split())\r\nlcm=(a*b)//fractions.gcd(a,b)\r\nmi=min(a,b)\r\nans=mi*(t//lcm+1)-1\r\numax=(t//lcm)*lcm +mi-1\r\nif umax>t: #cant be greater than total\r\n ans+=(t-umax);\r\nhcf=fractions.gcd(ans,t)\r\nans//=hcf\r\nt//=hcf\r\nprint(str(ans)+'/'+str(t))",
"s=input()\nL=s.split()\nt=int(L[0])\nw=int(L[1])\nb=int(L[2])\n\ndef gcd(a,b):\n\twhile b:\n\t\ta%=b\n\t\ta,b=b,a\n\t\t\n\treturn a\n\ndef lcm(a,b):\n\treturn a//gcd(a,b)*b\n\nif w==b:\n\tprint(\"1/1\")\nelse:\n\tminspeed=min(w,b)\n\tmaxspeed=max(w,b)\n\t\n\tif t>=lcm(w,b):\n\t\tden=t\n\t\tnum=(t//lcm(w,b))*(minspeed)+min(minspeed-1,t%lcm(w,b))\n\t\ttemp=gcd(num,den)\n\t\tnum=num//temp\n\t\tden=den//temp\n\t\tprint(str(num)+\"/\"+str(den))\n\t\t\n\telse:\n\t\tnum=min(minspeed-1,t)\n\t\tden=t\n\t\ttemp=gcd(num,den)\n\t\tnum=num//temp\n\t\tden=den//temp\n\t\tprint(str(num)+\"/\"+str(den))\n",
"from fractions import gcd\r\n\r\nt, w, v = map(int, input().split())\r\nlcm=(w * v) // gcd(w, v)\r\ntie = (t // lcm ) * min(w, v)\r\ntie += min((min(w,v)-1), t%lcm)\r\nprint (tie // gcd(tie, t), t // gcd(tie, t), sep = '/')\r\n",
"def NOD(a, b):\r\n\twhile a != 0 and b != 0:\r\n\t\tif a > b:\r\n\t\t\ta = a % b\r\n\t\telse:\r\n\t\t\tb = b % a\r\n\treturn a + b\r\n\r\nt, w, b = map(int, input().split(' '))\r\n\r\nl = w * b // NOD(w, b)\r\nans = 0\r\nans += max(0, (t // l)) * min(w, b)\r\nans += max(0, min((t % l) + 1, min(w, b)))\r\nres = ans - 1\r\nd = NOD(res, t)\r\nprint(str(res // d) + '/' + str(t // d))",
"def bmm(a, b):\n\twhile a % b != 0:\n\t\ta, b = b, a % b\n\treturn b\n\ndef kmm(a, b):\n\treturn a * b // bmm(a, b)\n\nt, w, b = [int(_) for _ in input().split()]\nk = kmm(w, b)\nm = min(w, b)\n\np = 0\np += (t // k) * m + (m - 1)\nif t % k < m:\n\tp -= m - (t % k) - 1\n\nq = t\n\nb = bmm(p, q)\np, q = p//b, q//b\nprint(str(p) + '/' + str(q))\n\n",
"import sys\r\nfrom math import *\r\nsys.setrecursionlimit(100000000)\r\n\r\ndef pgcd(a,b):\r\n while b!=0:\r\n a,b=b,a%b\r\n return a\r\n\r\ndef ppcm(a,b):\r\n if (a==0) or (b==0):\r\n return 0\r\n else:\r\n return (a*b)//pgcd(a,b)\r\n\r\nt,w,b=map(int,input().split())\r\na=ppcm(w,b)\r\nx=min(w,b)\r\ny=t//a\r\nv=x*y+min(x,t%a+1)-1\r\n\r\nw=pgcd(v,t)\r\nif v==0:print(\"0/1\")\r\nelse:\r\n\tprint(v//w,end=\"\")\r\n\tprint(\"/\",end=\"\")\r\n\tprint(t//w)",
"def gcd(a, b):\r\n while a > 0:\r\n b %= a\r\n (a, b) = (b, a)\r\n return b\r\n#\r\n(t, a , b) = map(int, input().split())\r\nn = a * b // gcd(a, b)\r\nm = min(a, b)\r\nans = 0\r\nif (m > 1):\r\n ans += m - 1\r\n ans += t // n * m\r\n if (t % n + 1 < m):\r\n ans += (t % n) + 1 - m\r\nelse:\r\n ans = t // n\r\nprint(ans // gcd(ans, t), '/', t // gcd(ans, t), sep = '') \r\n",
"#!/usr/bin/python3\nimport fractions\nt,w,b=map(int,input().split())\nl=w*b//fractions.gcd(w,b)\nmn=min(w,b)\nans = (t//l+1)*mn-max(mn-t%l-1,0)-1\ngat=fractions.gcd(t,ans)\nprint(\"%d/%d\" % ((ans//gat),(t//gat)))\n",
"\r\n\r\n\r\n\r\nl,a,b = (map(int,input().split()))\r\n\r\ndef mdc(a,b):\r\n\tif b == 0:\r\n\t\treturn a\r\n\telse:\r\n\t\treturn mdc(b,a%b)\r\n\r\ndef mmc(a,b):\r\n\treturn (a*b)//mdc(a,b)\r\n\r\n\r\nmm = mmc(a,b)\r\npeso_ped = min(a,b)-1\r\nqtd_ped = l//mm\r\n\r\nres = 0\r\nres += qtd_ped\r\nres += qtd_ped*peso_ped\r\nrestante = l%mm\r\nres += min(restante,peso_ped)\r\n\r\nmd = mdc(res,l)\r\nprint(f'{res//md}/{l//md}')\r\n\r\n\r\n\r\n",
"def gcd(a,b):\r\n if(b!=0):\r\n return gcd(b,a%b)\r\n else :\r\n return a\r\n \r\ndef lcm(a,b):\r\n return a//gcd(a,b)*b\r\n \r\nt,a,b = map(int,input().split())\r\n\r\naub = lcm(a,b)\r\nd=min(a,b)\r\nres=(t//aub+1)*d-1-max(0,d-1-t%aub)\r\nd=gcd(res,t);\r\np=res//d\r\nq=t//d\r\nprint(p,end=\"\")\r\nprint(\"/\",end=\"\")\r\nprint(q)",
"def gcd (a, b) :\r\n\twhile (b) :\r\n\t\ta %= b\r\n\t\ta, b = b, a\r\n\treturn a;\r\n\r\n\r\nt, w, b = map(int, input().split())\r\ng = w * b // gcd(w, b)\r\nres = 0\r\nminh = min(w, b)\r\nres += (t // g + 1) * minh - 1\r\ncorrect = (t // g) * g + minh - 1\r\nif (correct > t) :\r\n\tres -= correct - t\r\ny = gcd(res, t)\r\nprint(res // y, \"/\", t // y, sep = \"\")",
"def gcd(a,b): \r\n if(b==0): \r\n return a \r\n else: \r\n return gcd(b,a%b)\r\n \r\nt,w,z=map(int,input().split(' '))\r\nn=min(w,z)\r\n\r\ny=(w*z)//(gcd(w,z))\r\nr=(t//y)\r\npp =( min((r*y) + n-1 , t))\r\npp =( pp - (r*y))\r\nq1=(r+(r*(n-1))+pp)\r\nz=(gcd(q1,t))\r\nprint(\"%d/%d\"%((q1//z),(t//z)))",
"def nod(a, b):\r\n if a > b:\r\n a, b = b, a\r\n while (a > 0):\r\n a, b = b % a, a\r\n return b\r\n\r\nt, w, b = [int(i) for i in input().split()]\r\nnok = w * b // nod(w, b)\r\ncnt = t // nok\r\nif cnt >= 2:\r\n ans = (cnt - 1) * min(w, b) + (min(w, b) - 1) + min(t % nok + 1, min(w, b))\r\nelif cnt == 1:\r\n ans = (min(w, b) - 1) + min(t % nok + 1, min(w, b))\r\nelif cnt == 0:\r\n ans = min(t, min(w, b) - 1)\r\nif (ans == 0):\r\n print('0/1')\r\nelse:\r\n d = nod(ans, t)\r\n print(str(ans // d) + '/' + str(t // d))",
"def gcd(a,b):\r\n\twhile (b > 0):\r\n\t\tt = b\r\n\t\tb = a%b\r\n\t\ta = t\r\n\treturn a\r\nt,a,b = map(int,input().split(' '))\r\nhcf = (a*b)//gcd(a,b)\r\nnum = (t//hcf)*min(a,b) + min(t%hcf,min(a,b)-1)\r\nden = t\r\ncgcd = gcd(num,den)\r\nprint(str(num//cgcd)+'/'+str(den//cgcd))",
"import math\n\ndef gcd(a, b):\n if (b == 0):\n return a\n return gcd(b, a%b)\n \ndef lcm(a, b):\n a = a // gcd(a, b)\n a = a*b\n return a\n\nt, w, b = map(int, input().split())\nl = lcm(w,b)\nm = min(w,b)\n\nn = t // l\nn = n * m\nn = n + min(m-1, t%l)\n\ng = gcd(n,t)\nn = n // g\nt = t // g\n\nprint(str(math.floor(n)) + '/' + str(t))\n \t\t \t \t \t \t \t \t \t\t \t",
"from sys import stdin\r\ninp = stdin.readline\r\n\r\n# -----------------------\r\n\r\n\r\ndef gcd(x, y):\r\n while y:\r\n x, y = y, x % y\r\n return x\r\n\r\n\r\ndef lcm(x, y):\r\n return x * y // gcd(x, y)\r\n\r\n\r\n# -------------------\r\n\r\nt, a, b = map(int, inp().split())\r\n\r\nmod = lcm(a, b)\r\nans = 0\r\na, b = min(a, b), max(a, b)\r\n\r\nans += a*(t//mod)\r\nans += min(a-1, t % mod)\r\ndiv = gcd(ans, t)\r\n\r\nprint(f\"{ans//div}/{t//div}\")\r\n\r\n\r\n",
"t,w,b = map(int, input().split(' '))\r\ndef gcd(a,b):\r\n if (b == 0) :\r\n return a\r\n else :\r\n return gcd(b, a%b)\r\n\r\nlcm = (w*b)//gcd(w,b)\r\ndivide = 0\r\nif min(w,b) <= t :\r\n divide = t//lcm\r\n \r\ntotal = min(w-1,b-1) + divide * min(w-1,b-1) + divide\r\n\r\nclose = (t//lcm)*lcm\r\nif t - close < min(w,b) and w!=1 and b!=1 :\r\n total -= min(w-1,b-1) - (t - close)\r\ng = gcd(total, t)\r\ns = str(total//g) + '/' + str(t//g)\r\nprint(s)\r\n\r\n",
"def gcd(x, y):\r\n return gcd(y % x, x) if x else y\r\nt, w, b = (int(x) for x in input().split())\r\nlcm = w * b // gcd(w, b)\r\ntmp = t // lcm\r\nans = tmp * min(w, b)\r\nans -= max(0, tmp * lcm + min(w - 1, b - 1) - t)\r\nans += min(w - 1, b - 1)\r\ng = gcd(ans, t)\r\nif g:\r\n ans //= g\r\n t //= g\r\nprint(\"%d/%d\" % (ans, t))\r\n",
"import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\nT,W,B = map(int,input().split())\n\nans = (T//lcm(W,B))*min(W,B)\nans+=min(min(W,B)-1,T%lcm(W,B))\ng = gcd(ans,T)\n\nprint(str(ans//g)+\"/\"+str(T//g))\n",
"def gcd(a, b):\r\n if b==0: return a\r\n return gcd(b, a%b)\r\n\r\ndef lcm(a, b):\r\n return a*b//gcd(a,b)\r\n\r\nt, w, b = map(int, input().split())\r\n\r\nl = lcm(w, b)\r\nm = min(w, b)\r\n\r\nq = t\r\np = t // l * m\r\nif t % l != 0:\r\n p += min(t%l, m-1)\r\ng = gcd(p, q)\r\np//=g\r\nq//=g\r\nprint(\"{0}/{1}\".format(p, q))\r\n",
"t, w, b = map(int, input().split())\r\ngcd = lambda a, b: a if b == 0 else gcd(b, a % b)\r\nnok = w * b // gcd(w, b)\r\nk = min(w, b)\r\ncnt = (t // nok) * k - 1 + min(k, t % nok + 1)\r\nd = gcd(cnt, t)\r\np, q = cnt // d, t // d\r\nans = str(p) + '/' + str(q)\r\nprint(ans)\r\n",
"def gcd(a, b):\r\n return b if a == 0 else gcd(b % a, a)\r\n\r\n\r\nt, a, b = list(map(int, input().split()))\r\nnod = gcd(a, b)\r\nnok = a * b // nod\r\nc = (t // nok + 1) * min(a, b) - 1\r\ns = t % nok\r\nif s < min(a, b):\r\n c -= min(a, b) - s - 1\r\nnod = gcd(t, c)\r\nc //= nod\r\nt //= nod\r\nprint(str(c) + '/' + str(t))",
"import math\n\nt , w , b = map(int,input().split())\n# print(t,w,b)\n\nans1 = min(w,b) - 1\ngc = math.gcd(w,b)\n\nlcm = max(w,b)//gc\nlcm = lcm * min(b,w)\n\nans2 = t//lcm\nans3 = ans1 * (ans2-1)\n\nlast_com = ans2*lcm\n\nans = ans1 + ans2 + ans3\nif last_com + ans1 <= t:\n ans = ans + ans1\nelse:\n ans = ans + t-last_com\n\n\nif w == b:\n ans = t\n\ngcd = math.gcd(ans,t)\n\nans = ans // gcd\nt = t//gcd\n\nprint(ans,end=\"\")\nprint('/',end=\"\")\nprint(t)\n# fans = ans+'/'+t\n# print(fans)",
"t,w,b = map(int,input().split())\r\nfrom math import gcd\r\n\r\ncycle = (w * b) // gcd(w,b)\r\n\r\nans = (t // cycle) * min(w,b)\r\n\r\nans += min(t % cycle + 1,w,b)\r\n\r\nans -= 1\r\n\r\nnewAns = ans // gcd(ans,t)\r\nnewT = t // gcd(ans,t)\r\nprint(str(newAns) + \"/\" + str(newT))",
"from fractions import gcd\r\n\r\nt,w,b = map(int,input().split())\r\nper = w*b//gcd(w,b)\r\ncan = (t//per+1)*min(w,b)-1\r\nif t%per<min(w,b):\r\n can-=min(w,b)\r\n can+=t%per+1\r\ng = gcd(can,t)\r\ncan//=g\r\nt//=g\r\nprint(str(can)+\"/\"+str(t))",
"def gcd(a,b):\n if a==0:\n return b\n return gcd(b%a,a)\nt,w,b=map(int,input().split())\nx=(w*b)//gcd(w,b)\nans=(t//x)*min(w,b)+min(w,b)-1\nif (t//x)*x+min(w,b)-1>t:\n ans-=((t//x)*x+min(w,b)-1-t)\ny=gcd(ans,t)\nans=ans//y\nt=t//y\nprint(str(ans)+'/'+str(t))\n",
"from fractions import gcd\nt,w,b=map(int,input().split())\nlcm=w*b//gcd(w,b);\ncnt=t//lcm;\na=min(w,b)*cnt+min(t%lcm,min(w,b)-1)\nzi, mu = a//gcd(a,t), t//gcd(a, t)\nprint(str(zi)+'/'+str(mu));\n",
"# Hello World program in Python\r\n\r\ndef R():\r\n return map(int, input().split())\r\n\r\ndef NOD(a, b):\r\n if (a > b):\r\n tmp = a\r\n a = b\r\n b = tmp\r\n while((a != 0) and (b != 0)):\r\n b = b % a\r\n tmp = a\r\n a = b\r\n b = tmp\r\n return a + b\r\n \r\n\r\nt, w, b = R()\r\nnd = NOD(w, b)\r\nnk = b * w // nd\r\n\r\nnkAmount = (t // nk) + 1\r\n\r\nchisl = 0\r\nif nkAmount > 1:\r\n chisl = (nkAmount-1)*min(b, w)\r\n\r\nlastNk = (nkAmount-1)*nk\r\nchisl += min(min(w, b), t - lastNk + 1) - 1\r\n\r\nprint (str(chisl // NOD(chisl, t)) + '/' + str(t // NOD(chisl, t)));\r\n",
"import math as m\r\n\r\ns = input()\r\nlis = s.split()\r\n\r\nt = int(lis[0])\r\nw = int(lis[1])\r\nb = int(lis[2])\r\n\r\nif w > b:\r\n w, b = b, w\r\n\r\nnum = (w * b) // m.gcd(w, b)\r\nc = t // num\r\n\r\nans = c * w\r\n\r\nif ans > num * c + w - 1 - t and t < num * c + w - 1:\r\n ans -= num * c + w - 1 - t\r\n\r\nans += min(t, w - 1)\r\n\r\nprint(ans // m.gcd(ans, t), end=\"\")\r\nprint(\"/\", end=\"\")\r\nprint(t // m.gcd(t, ans))\r\n",
"from math import *\ndef gcd(a,b):\n if b==0:return a\n else:\n return gcd(b,a%b)\nt,w,b=map(int,input().split())\nnow=w*b//gcd(w,b)\nres=0\nif t//now:\n res=t//now*min(w,b)+min(min(w,b)-1,t%now)\nelse:\n res=min(min(w,b)-1,t)\nans=gcd(res,t)\nprint(res//ans,end='')\nprint('/',end = '')\nprint(t // ans)\n\t \t\t \t \t\t \t \t\t\t\t \t \t\t\t \t\t",
"import math\n\n\nt, a, b = map(int, input().split())\n\nlcm = a * b // math.gcd(a, b)\n\nk = t // lcm\n\nans = max(0, k - 1) * min(a, b)\n\nif k > 0:\n tmp = t % lcm\n ans = ans + min(tmp + 1, min(a, b))\n\nans = ans + min(t, min(a, b) - 1)\n\ng = math.gcd(ans, t)\n\nans = ans // g\n\nt = t // g;\n\nprint(ans, '/', t, sep = '')\n\t\t\t\t \t\t\t \t \t \t\t \t\t",
"from math import *\r\na,b,c=tuple(map(int,input().split(' ')))\r\nd=a//lcm(b,c)*min(b,c)+(min(b,c)-1 if a%lcm(b,c)>min(b,c)-1 else a%lcm(b,c))\r\nprint(f\"{int(d//gcd(d,a))}/{int(a//gcd(d,a))}\")",
"def nod(a, b):\r\n while b != 0:\r\n a, b = b, a % b\r\n return a\r\nt, w, b = map(int, input().split())\r\nq = nod(w, b)\r\nq = w * b // q\r\nw, b = min(w, b), max(w, b)\r\ncol = t // q\r\ne = 0\r\nif t % q < w:\r\n e = w - t % q - 1\r\ng = (col + 1) * w - 1 - e\r\nv = nod(g, t)\r\nt = t // v\r\ng = g // v\r\nprint(g, '/', t, sep = '')\r\n\r\n",
"def gcd(a, b):\r\n while (b > 0):\r\n a, b = b, a % b\r\n return a\r\n\r\ninp = [int(i) for i in input().split(' ')]\r\nt = inp[0]\r\nw = inp[1]\r\nb = inp[2]\r\nnok = w * b // gcd(w, b)\r\nans = t // nok * min(w, b) - 1\r\ntmp = t % nok\r\nans += min(tmp + 1, min(w, b))\r\ng = gcd(ans, t)\r\nprint(ans // g, t // g, sep='/')\r\n",
"def gcd(a,b):\n if b == 0: return a\n return gcd(b, a%b)\n\ndef lcm(a,b):\n return a//gcd(a,b)*b\n\nt,w,b = map(int,input().split())\np = min(w,b)\nlc = lcm(w,b)\nkol = t//lc\nret = kol*p\nzv = t%lc\nret += min(zv, p-1)\ng = gcd(ret, t)\nret//=g\nt//=g\nprint(ret,'/',t,sep=\"\")\n",
"#!/usr/bin/python3\nfrom fractions import gcd\n\nt,w,b = [int(x) for x in input().strip().split()]\n\nBadLen = w*b//gcd(w,b)\nvar = min(w,b)\n\ntimes = (t//BadLen)*(var)\ntimes -= 1\n\n\ntimes += min(var,t-(t//BadLen)*BadLen+1)\nprint(times//gcd(t,times),t//gcd(t,times),sep='/')\n",
"from fractions import gcd\n\nt, w, b = map(int, input().split())\nlcm = w * b // gcd(w, b)\nm = min(w, b)\ns = t // lcm * m + min(t % lcm, m - 1)\ng = gcd(s, t)\ns //= g\nt //= g\nprint(\"{}/{}\".format(s, t))\n",
"def gcd(a,b):\r\n while b > 0:\r\n a, b = b, a % b\r\n return a\r\n \r\ndef lcm(a, b):\r\n return a * b // gcd(a, b)\r\n\r\nT, W, B = map(int, input().split())\r\nLCM = lcm(W, B)\r\n\r\nANS = T//LCM\r\nREQ = ANS * min(W, B)\r\nREQ = REQ+min(W, B)-1\r\nC = ANS * LCM\r\nC += min(W, B)-1\r\nANS = REQ - max(0, C-T)\r\n\r\nGCD = gcd(int(ANS), int(T))\r\nNUM, DENOM = (ANS//GCD), (T//GCD)\r\n\r\nprint(int(NUM), end = \"\")\r\nprint(\"/\", end = \"\")\r\nprint(int(DENOM))\r\n",
"def gcd(a,b):\r\n while(a!=0 and b!=0):\r\n if(a>b):a=a%b\r\n else:b=b%a\r\n return a+b\r\nn,m,k=map(int,input().split());gmk=(m*k)//gcd(m,k);a=min(m,k)*(n//gmk-1)+(min(m,k)-1);a+=min(n,n//gmk*gmk+min(m,k)-1)-(n//gmk*gmk)+1;b=n;c=gcd(a,b);a=a//c;b=b//c\r\nif(m==k):print('1/1')\r\nelse:print(str(a)+'/'+str(b))",
"import sys\r\nimport fractions\r\nfor line in sys.stdin:\r\n li = line.split()\r\n t = int(li[0])\r\n w = int(li[1])\r\n b = int(li[2])\r\n mi = min(w, b)\r\n Gcd = fractions.gcd(w, b)\r\n Lcm = w * b // Gcd\r\n if Lcm > t:\r\n ans = min(t, w - 1, b - 1)\r\n else:\r\n cnt = t // Lcm\r\n res = t - cnt * Lcm\r\n ans = cnt * min(w, b) + min(res, w - 1, b - 1)\r\n Gcd = fractions.gcd(ans, t)\r\n print(\"%s/%s\" % (ans // Gcd, t // Gcd))\r\n\r\n",
"from sys import stdin, stdout\r\n\r\nimport sys\r\nimport random\r\nimport datetime\r\n\r\nendl = '\\n'\r\n\r\nclass Scan():\r\n def __init__(self):\r\n self.read = stdin.read\r\n self.input = stdin.readline\r\n\r\n def integer(self, count=1):\r\n if count == 1:\r\n return self._integer()\r\n return [self._integer() for _ in range(count)]\r\n\r\n def _integer(self):\r\n sym: str = self.read(1)\r\n while sym != '-' and not sym.isdigit():\r\n sym = self.read(1)\r\n \r\n number, sign = (0, -1) if sym == '-' else (int(sym), 1)\r\n sym: str = self.read(1)\r\n while sym.isdigit():\r\n number = number * 10 + int(sym)\r\n sym = self.read(1)\r\n \r\n return number * sign\r\n \r\n def array(self, func=int, sep=' '):\r\n if func == str:\r\n return input().split(sep)\r\n return list(map(func, input().split(sep)))\r\n\r\n def string(self, count=1):\r\n if count == 1:\r\n return self._string()\r\n return [self._string() for _ in range(count)]\r\n\r\n def _string(self):\r\n sym = self.read(1)\r\n while sym in ('\\n', '\\r', ' '):\r\n sym = self.read(1)\r\n \r\n s = str()\r\n while sym not in ('\\n', '\\r', ' '):\r\n s += sym\r\n sym = self.read(1)\r\n\r\n return s\r\n\r\nclass Write():\r\n def __lshift__(self, other):\r\n stdout.write(str(other))\r\n return self\r\n\r\nclass Number():\r\n def gcd(a, b):\r\n while b > 0:\r\n a, b = b, a % b\r\n return a\r\n \r\n def lcm(a, b):\r\n return a * b // Number.gcd(a, b)\r\n\r\n def sqrt(n):\r\n sqrt_n = int(n ** 0.5)\r\n while sqrt_n * sqrt_n < n:\r\n sqrt_n += 1\r\n\r\n while sqrt_n * sqrt_n > n:\r\n sqrt_n -= 1\r\n\r\n return sqrt_n\r\n \r\n def sum_n(n):\r\n return n * (n + 1) // 2\r\n\r\nclass Constants():\r\n EPS = 10 ** -9\r\n INF = 10 ** 18\r\n MOD = 10 ** 9 + 7\r\n\r\ndef solution(scan: Scan, write: Write):\r\n n, a, b = scan.integer(3)\r\n if a > b: a, b = b, a\r\n lcm = Number.lcm(a, b)\r\n ans = a - 1\r\n k = (n - a + 1) // lcm\r\n ans += k * a\r\n ans += max(0, n - (k + 1) * lcm + 1)\r\n gcd = Number.gcd(ans, n)\r\n print(ans // gcd, '/', n // gcd, sep='')\r\n\r\ndef main():\r\n queries: int = 1\r\n scan, write = Scan(), Write()\r\n #queries = scan.integer()\r\n for _ in range(queries):\r\n solution(scan, write)\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"from fractions import gcd\r\ns = list(map(int, input().split()))\r\nt = s[0]\r\na = s[1]\r\nb = s[2]\r\nnod = gcd(a, b)\r\nnok = a * b // nod\r\nans = t // nok * min(a, b) + min(a, b) - 1\r\nans -= max(0, ((t // nok) * nok) + min(a, b) - 1 - t)\r\ngc = gcd(ans, t)\r\nans //= gc\r\nt //= gc\r\nprint(str(int(ans)) + '/' + str(int(t)))",
"def gcd(a, b):\n\twhile b > 0:\n\t\ta, b = b, a % b\n\treturn a\n\ndef lcm(a, b):\n\treturn a * b // gcd(a, b)\n\nt, w, b = map(int, input().split())\n\nl = lcm(w, b)\ncntB = t // l\nans = min(w, b) * cntB + min(w, b, t - cntB * l + 1) - 1\ng = gcd(ans, t)\nans //= g\nt //= g\nprint(str(ans) + \"/\" + str(t))",
"from math import gcd\r\n\r\n\r\ndef lcm(a, b):\r\n return (a * b) // gcd(a, b)\r\n\r\n\r\nans = 0\r\nt, w, b = map(int, input().split())\r\nif lcm(w, b) > t:\r\n ans = min(w - 1, b - 1, t)\r\nelse:\r\n lcmm = lcm(w, b)\r\n count = t // lcmm\r\n still = t - count * lcmm\r\n ans = min(still, w - 1, b - 1) + count * min(w, b)\r\nprint(ans // gcd(ans, t), t // gcd(ans, t), sep='/')\r\n",
"def gcd(a,b):\r\n return (a if b==0 else gcd(b, a%b))\r\nt, w, b = [int(x) for x in input().split()]\r\nlcd = w * b // gcd(w, b)\r\nk, d = min(w, b), t % lcd\r\nans = (t // lcd + 1) * k - 1;\r\nif d < k:\r\n ans -= k - d - 1\r\nprint(ans // gcd(ans, t), \"/\", t // gcd(ans, t), sep=\"\")",
"import math\r\nt, a, b = map(int,input().split())\r\nl = a * b // math.gcd(a,b) # lcm\r\np = (t // l) * min(a,b) + min(t % l, min(a,b) - 1)\r\nq = t\r\nr = math.gcd(p, q)\r\nprint('{}/{}'.format(p//r, q//r))",
"import math\nbuff=input();\nbuff=list(map(int,buff.split(' ')))\n#print(type(buff[2]))\nt=int(buff[0])\na=int(buff[1])\nb=int(buff[2])\n#t=(buff[0]), a=(buff[1]), b=(buff[2])\nans=int(-1)\nx=a//math.gcd(a,b)*b\nr=min(a,b)\nlast=t//x*x\nlg=t//x+1\nwhile True:\n\tdx=min(t-last+1,r)\n\tr=r-dx;\n\tans=ans+dx*lg\n\tlg=lg-1\n\tlast=last+dx-x\n\tif(r==0):\n\t\tbreak\ngg=math.gcd(ans,t)\nprint('{}/{}'.format(ans//gg,t//gg))\n",
"def gcd(x, y) :\r\n\tif (y) : return gcd(y, x % y)\r\n\treturn x\r\n\r\nt, w, b = map(int, input().split())\r\n\r\nkpk = w * b // gcd(w, b)\r\n\r\nans = (t // kpk + 1) * min(w, b) - 1\r\nans -= max(0, min(w, b) - t % kpk - 1)\r\n\r\nfpb = gcd(ans, t)\r\n\r\nprint(ans // fpb, \"/\", t // fpb, sep = \"\")",
"import math\nimport fractions\n\nt, w, b = [int(x) for x in input().split()]\n\nlcm = (w * b) // fractions.gcd(w, b)\ntimes = t // lcm\nn, dn = times * min(w, b) + min(w, b, t-lcm*times+1) - 1, t\n\ngcd = fractions.gcd(n, dn)\nn //= gcd\ndn //= gcd\nprint(str.format(\"{0}/{1}\", n, dn))\n",
"import math\r\n\r\ninp = input().split(' ')\r\nt = int(inp[0])\r\na = int(inp[1])\r\nb = int(inp[2])\r\n\r\nif(a == b):\r\n print(\"1/1\")\r\n exit(0)\r\n\r\nif(a > b):\r\n a += b\r\n b = a - b\r\n a -= b\r\n\r\nn = a // math.gcd(a, b) * b\r\n\r\nmxk = t // n\r\n\r\nans = min(a, t - mxk * n + 1)\r\n\r\nans += mxk * a - 1\r\n\r\ng = math.gcd(ans, t)\r\n\r\nprint(ans // g, \"/\", t // g, sep = \"\")\r\n",
"import math\n\ndef gcd(a, b):\n while b > 0:\n a %= b\n a, b = b, a\n return a\n\ndef lcm(a, b):\n return a // gcd(a, b) * b\n\nt, w, b = map(int, input().split())\nres = min(t, min(b, w) - 1)\nl = lcm(b, w)\nk = t // l\nif k > 0:\n res += (k-1) * min(b, w)\n res += min(t - k * l + 1, min(b, w))\ng = gcd(res, t)\nif res > 0:\n print(\"{}/{}\".format(res//g, t//g))\nelse:\n print(\"0/1\")\n",
"t,w,b = map(int, input().split())\n\nfrom fractions import gcd\nlcm = lambda x,y : x*y//gcd(x,y)\nl = lcm(w,b)\nm,d = divmod(t,l)\ns = min(w,b)\n\nif m > 0:\n p = m*s-1+min(s-1,d)+1\nelse:\n p = min(s-1,t) \n\ng = gcd(p,t)\nprint(str(p//g)+\"/\"+str(t//g))\n",
"def gcd(a, b):\r\n\treturn a if (b == 0) else (gcd(b, a % b))\r\n\r\ndef lcm(a, b):\r\n\treturn a * (b // gcd(a, b))\r\n\r\n#ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}\r\n#ll lcm(ll a, ll b) {return a * (b / gcd(a, b));}\r\n\r\nt, w, b = input().split()\r\nt = int(t)\r\nw = int(w)\r\nb = int(b)\r\nv = lcm(w, b)\r\nv2 = t//v + 1\r\nz = min(w, b)\r\nk = v2*z - 1\r\nif((v2-1)*v + z > t):\r\n\tk -= ((v2-1)*v + z - t - 1)\r\nk2 = t;\r\nk3 = gcd(k, k2);\r\nprint(k//k3, \"/\", k2//k3, sep='')",
"def gcd(a, b):\r\n while (b > 0):\r\n a, b = b, a % b\r\n return a\r\n\r\nt, a, b = map(int, input().split())\r\nx = gcd(a, b)\r\nd = min(a, b)\r\nnok = a * b // x\r\np = t // nok * d + min(d, t % nok + 1) - 1\r\nq = t\r\ny = gcd(p, q)\r\nprint(p // y, '/', q // y, sep='')",
"from fractions import gcd\nt,w,b=map(int,input().split())\ng=gcd(w,b)\na=(w//g)*b\ncnt=t//a\ncnt = cnt*(min(w,b))+ min(min(w,b)-1,t-a*cnt)\ng = gcd(cnt,t)\nprint('%d/%d'%(cnt//g,t//g))",
"def gcd(a,b):\r\n if(b==0):\r\n return a\r\n else:\r\n return gcd(b,a%b)\r\nls=list(map(int,input().split()))\r\nt=ls[0]\r\nw=ls[1]\r\nb=ls[2]\r\ntmp=0\r\nif(w<b):\r\n tmp=w\r\n w=b\r\n b=tmp\r\nx=int(w*b//gcd(w,b))\r\ncnt=int(t//x)\r\nr=int(t-(cnt*x))\r\nres=int(cnt*b+min(r,b-1))\r\nprint(\"{:d}/{:d}\".format(int(res//gcd(res,t)),int(t//gcd(t,res))))\r\n",
"from fractions import gcd\r\n\r\nn, p, q = map(int, input().split())\r\nlcm = p // gcd(p, q) * q\r\nif p > q:\r\n\tp, q = q, p\r\nfull = n % lcm\r\nif p <= full + 1:\r\n\tgood = (n // lcm + 1) * p\r\nelse:\r\n\tgood = n // lcm * p + full + 1\r\n\r\ngood -= 1\r\ng = gcd(good, n)\r\nprint('{}/{}'.format(good // g, n // g))\r\n",
"l, n, m = map(int, input().split())\nfrom fractions import gcd\nlcm = lambda x, y: x // gcd(x,y) * y\nu = lcm(n,m)\nv = min(n,m)\na = (l//u) * v + min(v, l%u+1) - 1 \nprint(a//gcd(a,l),'/',l//gcd(a,l),sep='')\n\n",
"n, w, b = map(int, input().split())\n\nfrom math import gcd\n\nL = w*b//gcd(w, b)\nm = min(b, w)\n\nans = (n-m+1) // L + 1\nans *= m\n\nif n // L == (n-m+1) // L:\n pass\nelse:\n cn = n // L * L\n ans += n - cn + 1\n\nans -= 1\ng = gcd(ans, n)\nprint(ans//g,'/',n//g,sep='')\n",
"from fractions import gcd\r\n\r\ndef lcm(a, b):\r\n return a // gcd(a, b) * b\r\n\r\nt, a, b = map(int, input().split(\" \"))\r\np = lcm(a, b)\r\ncnt = t // p\r\n\r\nans = min(a - 1, b - 1, t)\r\nans += max(0, cnt - 1) * min(a, b)\r\n\r\npos = cnt * p\r\n\r\nif pos >= min(a, b):\r\n if t >= pos:\r\n l = pos\r\n r = pos + min(a, b) - 1\r\n r = min(r, t)\r\n ans += r - l + 1\r\n\r\ng = gcd(ans, t)\r\nprint(\"{0}/{1}\".format(ans // g, t // g))",
"def gcd(a, b):\r\n if b == 0:\r\n return a\r\n return gcd(b, a % b)\r\ndef lcd(a, b):\r\n return (a // gcd(a, b)) * b\r\ndef main():\r\n t, a, b = map(int, input().split())\r\n if a > b:\r\n a, b = b, a\r\n ld = lcd(a, b)\r\n res = t // ld\r\n dep = t % ld\r\n dep += 1\r\n res *= a\r\n res += a - 1\r\n if (dep < a):\r\n res -= a - dep\r\n divi = gcd(res, t)\r\n print(res // divi, t // divi, sep = \"/\")\r\nmain()",
"#!/usr/bin/python3\n\ndef gcd(a, b):\n\tif b == 0:\n\t\treturn a\n\treturn gcd(b, a%b)\n\nx = input()\nx = [int(_) for _ in x.split()]\n# print(x)\n\nt = x[0]\nw = x[1]\nb = x[2]\n\nx = gcd(w, b)\nk = min(w,b)\n\nlcm = (w*b)//x\n\nalpha = t//lcm\n\nans = alpha*(k)\n\nl = alpha*lcm + k- 1\n\nif l <= t :\n\tans += k\nelse:\n\tans += t - (alpha*lcm) + 1\n\nans -= 1\n\ngg = gcd(ans, t)\nans = ans//gg\nt = t//gg\n\nprint(str(ans)+\"/\"+str(t))",
"s=input()\narr=s.split()\nt=int(arr[0])\nw=int(arr[1])\nb=int(arr[2])\n\ndef mysum(a,L):\n to=a//L\n return L*(to*(to - 1))//2 + (a - to*L + 1)*to\n\ndef gcd(a,b):\n if a==0: return b\n else: return gcd(b%a, a)\n\nL=w*b//gcd(w,b)\nres=0\nm=min(w-1,b-1,t)\nres+=m\nres+=mysum(t-1,L) - mysum(t-m-1,L)\nres+=t//L\ndenom=t\ng=gcd(res,denom)\nprint(\"%d/%d\" % (res//g, denom//g))\n\n",
"def mygcd(a,b):\r\n if a%b==0:\r\n return b\r\n else :\r\n return mygcd(b,a%b)\r\n\r\nt,w,b=input().split(\" \");\r\n\r\nt=int(t)\r\nw=int(w)\r\nb=int(b)\r\n\r\n\r\n\r\nx=w\r\ny=b\r\nw=min(x,y)\r\nb=max(x,y)\r\n\r\nlcm=w*b\r\nlcm=lcm//mygcd(w,b)\r\n\r\nu=(t//lcm)*w+min(w-1,t%lcm);\r\n\r\nxx=mygcd(u,t)\r\nu//=xx\r\nt//=xx\r\nprint(u,\"/\",t,sep=\"\")",
"#sourav verma IPG_2013108 ABV IIITM\r\n # Task @ codeforces */\r\n# cook your dish here\r\n\r\ndef gcd(a,b):\r\n if (b==0):\r\n return a\r\n else:\r\n return gcd(b,a%b)\r\n \r\n[t,w,b]=[int(i)for i in input().split()]\r\np=w*b//gcd(w, b)\r\nmn=min(w, b)\r\nl= t//p\r\ncnt=mn*l\r\ncnt+=mn-1\r\np=l*p+mn-1\r\nif(p>t):\r\n cnt-=(p-t)\r\ngcc=gcd(t,cnt)\r\nt=t//gcc\r\ncnt=cnt//gcc\r\nprint(cnt, '/', t, sep='')\r\n\r\n",
"from math import gcd\r\n\r\nt, mn, mx = map(int, input().split())\r\nif mn > mx:\r\n mn, mx = mx, mn\r\nlcm = (mn * mx) // gcd(mn, mx)\r\ncnt = t // lcm\r\nret = mn - 1 + cnt * mn\r\nlast = t - (t % lcm)\r\nif last + mn > t:\r\n ret -= last + mn - t - 1\r\ng = gcd(ret, t)\r\nprint('%d/%d' % (ret // g, t // g))",
" \r\ndef gcd( a, b):\r\n if a == 0 :\r\n return b;\r\n return gcd(b % a,a)\r\n\r\n\r\n\r\nx,t,b=map(int,input().split())\r\ngc = gcd(t, b);\r\nif t == b :\r\n print(\"1/1\")\r\n exit(0)\r\n\t\t\r\niter = t * b // gc;\r\nans = (x // iter)*(min(t,b));\r\nz = x % iter;\r\nans += min(z, min(t, b) - 1);\r\ngc = gcd(ans, x);\r\n\r\nprint(str(ans//gc)+\"/\"+str(x//gc));",
"import math;\r\ndef gcd(a, b):\r\n while b:\r\n a, b = b, a % b\r\n return a\r\n\r\n\r\nt, a, b = map(int, input().split());\r\nans = 0\r\nq1 = gcd(a, b)\r\nnok = a * b // q1\r\nq1 = t // nok\r\nq1 = t // nok\r\nans += q1 - 1;\r\nans += q1 * (min(a, b) - 1);\r\nans += min(t - q1 * nok + 1, min(a, b));\r\nk = gcd(ans, t)\r\nprint(str(ans // k) + '/' + str(t // k))\r\n",
"def gcd(a, b):\r\n if b != 0:\r\n return gcd(b, a%b)\r\n else:\r\n return a\r\n\r\ndef lcm(a, b):\r\n return a // gcd(a, b) * b\r\n\r\nt, a, b = map(int, input().split())\r\nm = lcm(a, b)\r\nd = min(a, b)\r\nres = (t // m + 1) * d - 1 - max(0, d - 1 - t % m)\r\nprint(res // gcd(res, t), '/', t // gcd(res, t), sep='')\r\n",
"#!/usr/bin/env python3\nimport math\nt, a, b = map(int,input().split())\nl= a * b // math.gcd(a,b)\np = (t // l) * min(a,b) + min(t % l, min(a,b) - 1)\nq = t\nr = math.gcd(p, q)\nprint('{}/{}'.format(p//r, q//r))\n",
"from fractions import Fraction,gcd\n\nt,w,b=map(int,input().split())\ng=gcd(w,b)\nn=min(w,b)\nz=(w*b)//g\nf=Fraction(n*((t+1)//z)+min((t+1)%z,n)-1,t)\nprint('%d/%d'%(f.numerator,f.denominator))\n",
"import math as mt \nimport sys,string\ninput=sys.stdin.readline\n#print=sys.stdout.write\n#import random\nimport collections\nfrom heapq import heappush,heapify,heappop\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : map(int,input().split())\nI=lambda :int(input())\ndef lcm(a,b):\n return a*b//mt.gcd(a,b)\nt,w,b=M()\nx=t\ns=lcm(w,b)\nans=t//s\nans=ans*(min(w,b))\nt%=s\nans+=min(w-1,b-1,t)\nprint(str(ans//(mt.gcd(ans,x)))+\"/\"+str(x//(mt.gcd(ans,x))))\n",
"import bisect\r\nimport collections\r\nimport copy\r\nimport enum\r\nimport functools\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport queue\r\nimport random\r\nimport re\r\nimport sys\r\nimport time\r\nimport string\r\nimport datetime\r\nfrom typing import List\r\n\r\nt, w, b = map(int, input().split())\r\nif w > b:\r\n w, b = b, w\r\ng = math.gcd(w, b)\r\nbs = w*b//g\r\nc1, c2 = divmod(t, bs)\r\nans = c1*w\r\nif c2 > 0:\r\n ans += min(c2, w-1)\r\ng = math.gcd(ans, t)\r\nans = ans//g\r\nt = t//g\r\nprint(f'{ans}/{t}')\r\n",
"'''\n Python3(PyPy3) Template for Programming-Contest.\n'''\n\nimport math\nimport sys\n\n\ndef input():\n return sys.stdin.readline().rstrip()\n\n\nDXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # LDRU\nmod = 998244353\ninf = 1 << 64\n\n\ndef main():\n L, n1, n2 = map(int, input().split())\n LCM = n1 * n2 // math.gcd(n1, n2)\n MIN = min(n1, n2)\n q, r = divmod(L, LCM)\n # x == t(modulo LCM) 0 <= t < MIN\n num = q * (MIN) + min(r + 1, MIN) - 1\n den = L\n g = math.gcd(num,den)\n num,den = num // g,den // g\n print(f\"{num}/{den}\")\n return 0\n\n\nif __name__ == \"__main__\":\n main()\n",
"def gcd (a, b): \n while b:\n a %= b\n c = a\n a = b\n b = c\n return a\n\ndef lcm (a, b):\n return a // gcd (a, b) * b\n\nv = input().split(' ')\nt = int(v[0])\na = int(v[1])\nb = int(v[2])\nif a>b:\n c = a\n a = b\n b = c\n\nl = lcm(a, b)\nall = t;\ngood = (t//l)*(a);\n\nif t>=l: \n good-=a;\n good+=(min(t%l+1,a));\n\ngood+=(min(t, a-1));\n\ng=gcd(good, all);\ngood//=g\nall//=g\n\nprint(str(int(good))+'/'+str(int(all)))\n\n",
"# LUOGU_RID: 132281464\ndef gcd(a, b):\r\n if b != 0: return gcd(b, a % b)\r\n return a\r\nq, w, b = map(int, input().split())\r\nlcm = (w // gcd(w, b)) * b\r\np = (q // lcm) * min(w, b) - 1 + min((q % lcm) + 1, min(w, b))\r\nprint(p // gcd(p, q), end = '')\r\nprint('/', end = '')\r\nprint(q // gcd(p, q))",
"def gcd(a, b):\n return gcd(b, a % b) if b > 0 else a\n\nt, w, b = map(int, input().split())\nlcm = w * b // gcd(w, b)\nbase = ((t // lcm) + 1) * min(w, b) - 1\nless = t - ((t // lcm) * lcm) + 1\nif less > 0 and less < min(w, b):\n base -= min(w, b) - less\ng = gcd(base, t)\nprint(\"{0}/{1}\".format(base // g, t // g))\n",
"def gcd(a, b):\r\n if(b == 0):\r\n return int(a)\r\n else:\r\n return int(gcd(b, a % b))\r\n\r\ndef lcm(a, b):\r\n return int(a * b // gcd(a, b))\r\n\r\nif __name__ == \"__main__\":\r\n t, w, b = map(int, input().split())\r\n ans = t // lcm(w, b) * min(w, b)\r\n ans += min(t % lcm(w, b), w - 1, b - 1)\r\n print(ans // gcd(ans, t), end = \"\")\r\n print(\"/\", end = \"\")\r\n print(t // gcd(ans, t))",
"import math\n\nt, w, b = map(int, input().split())\n\ncs = min(w, b) - 1\nlcm = (w*b)//math.gcd(w, b)\nfldiv = t//lcm * lcm\nnum = (cs + (t//lcm - 1)*(cs + 1))\nif fldiv + cs < t:\n\tnum += (cs + 1)\nelse:\n\tnum += (t - fldiv + 1)\ng = math.gcd(num, t)\nnum //= g\nt //= g\nprint(num, end=\"/\")\nprint(t)",
"def gcd(a, b):\r\n if b == 0:\r\n return a\r\n else:\r\n return gcd(b, a % b)\r\n\r\ndef lcm(a, b):\r\n return (a*b) // gcd(a, b)\r\n\r\nl = list(map(int, input().split()))\r\nt = l[0]\r\nw = l[1]\r\nb = l[2]\r\nans = t // lcm(w, b) + 1\r\nans = (ans - 1) * min(w, b) - 1\r\nans += 1\r\nans += min(min(w, b) - 1, t % lcm(w, b))\r\ng = gcd(ans, t)\r\nt = t // g\r\nans = ans // g\r\ns = str(ans) + \"/\" + str(t)\r\nprint(s)\r\n",
"from fractions import gcd\nt, w, b = map(int, input().split())\nif w > b:\n w, b = b, w\nl = w * b // gcd(w, b)\nc = t // l\nans = c * w + (min((t + 1) - l * c, w)) - 1\ng = gcd(ans, t)\nprint('{}/{}'.format(ans // g, t // g))\n",
"from math import gcd\r\nt, w, b = map(int, input().split())\r\ng = gcd(w, b)\r\nlcm = w * b // g\r\nmn = min(w, b)\r\nans = mn * (t // lcm) - 1 + min(mn, t % lcm + 1)\r\ng = gcd(ans, t)\r\nprint(str(ans // g) + \"/\" + str(t // g))",
"from math import *\n\ndef gcd(a, b):\n if b:\n return gcd(b, a % b)\n else:\n return a\n\ndef lcm(a, b):\n return (a * b) // gcd(a, b)\n\nt, w, b = [int(x) for x in input().split()]\n\nans = (t // lcm(w, b)) * min(w, b) + min(w, b, t % lcm(w, b) + 1) - 1\nprint('{0}/{1}'.format(ans // gcd(ans, t), t // gcd(ans, t)))\n",
"def gcd(x, y):\r\n return x if y == 0 else gcd(y, x%y)\r\nt, w, b = map(int, input().split(\" \"))\r\nlcm = w*b // gcd(w, b)\r\nif w > b:\r\n w, b = b , w\r\nres = t // lcm * w + min(t % lcm, w-1)\r\ntmp = gcd(res, t)\r\nprint(str(res//tmp) + \"/\" + str(t//tmp))\r\n",
"from fractions import gcd\r\n\r\nt, w, b = map(int,input().split())\r\n\r\ng=gcd(w,b)\r\na=(w//g)*b\r\ncnt=t//a\r\ncnt = cnt*(min(w,b))+ min(min(w,b)-1,t-a*cnt)\r\ng = gcd(cnt,t)\r\nprint('%d/%d'%(cnt//g,t//g))",
"def gcd(n,m):\n if n < m:\n tmp = n\n n = m\n m = tmp\n while m>0:\n nn = n%m\n n = m\n m = nn\n return n\n\nt, w, b = input().split()\nt = int(t)\nw = int(w)\nb = int(b)\n\ng = gcd(w,b)\nh = (w//g) * (b//g) * g\ndr = t // h\n \ndnr = min(t - dr*h, min(w, b) - 1) + dr * (min(w, b) - 1)\ndans = dr + dnr\n \ndd = gcd(t, dans)\nans = dans // dd\nansb = t // dd\n\nprint(str(ans)+'/'+str(ansb))\n\n",
"from math import gcd\r\n\r\nl = list(input().split())\r\n\r\nt = int(l[0]);\r\nw = int(l[1]);\r\nb = int(l[2]);\r\n\r\n\r\nif w > b:\r\n w, b = b, w;\r\n\r\nres = 0\r\ninter = (w*b)//gcd(w, b);\r\nif(t < inter):\r\n res = min(t, w-1);\r\nelif(t == inter):\r\n res = w\r\nelse:\r\n t2 = t-(inter-1)\r\n qt = 1+ (t2//inter);\r\n\r\n res = qt*w;\r\n res += (min(w, t2%inter));\r\n\r\n # print(t2%inter)\r\n # print(qt)\r\n #\r\n # print(res)\r\n\r\n res = max(0, res-1);\r\ng = gcd(res, t);\r\nres //= g; t //= g;\r\nprint(\"{}/{}\".format(res, t));\r\n\r\n\r\n# # if (t//inter == 0):\r\n# # res -= 1;\r\n# if res < 0:\r\n# res = 0;\r\n#\r\n",
"#! /usr/bin/python\n\nfrom fractions import gcd\n\nt, w, b = map(int, input().split())\n\nif w == b:\n print('1/1')\nelse:\n wb = w * b // gcd(w, b)\n m = min(w, b)\n n = t // wb * m - 1 + min(t % wb + 1, m)\n g = gcd(n, t)\n print(\"%d/%d\" % (n // g, t // g))\n"
] | {"inputs": ["10 3 2", "7 1 2", "1 1 1", "5814 31 7", "94268 813 766", "262610 5583 4717", "3898439 96326 71937", "257593781689876390 32561717 4411677", "111319886766128339 7862842484895022 3003994959686829", "413850294331656955 570110918058849723 409853735661743839", "3000000000000000000 2999999999999999873 2999999999999999977", "9 6 1", "32 9 2", "976 5 6", "5814 31 7", "94268 714 345", "262610 5583 4717", "3898439 96326 71937", "54682301 778668 253103", "329245015 1173508 8918834", "321076647734423976 7 7", "455227494055672047 92 28", "595779167455745259 6954 8697", "1000000000000000000 1000000000 2000000000", "462643382718281828 462643382718281507 462643382718281701", "4000000000000000000 9999999999999997 99999999999999999", "4003000100004000000 9999999099999999 99999999999999999", "4903000100004000000 58997960959949999 99933992929999999", "257593781689876390 32561717 4411677", "111319886766128339 7862842484895022 3003994959686829", "413850294331656955 570110918058849723 409853735661743839", "232 17 83", "5496272 63 200", "180 174 53", "1954 190 537", "146752429 510 514", "579312860 55 70", "1 9 9", "95 19 19", "404 63 441", "5566 4798 4798", "118289676 570846883 570846883", "763 358 358", "85356138 7223 482120804", "674664088 435395270 5", "762200126044291557 370330636048898430 6", "917148533938841535 47 344459175789842163", "360212127113008697 877228952036215545 5259", "683705963104411677 89876390 116741460012229240", "573003994959686829 275856334120822851 1319886766128339", "409853735661743839 413850294331656955 413850294331656955", "19 1 19", "576 18 32", "9540 10 954", "101997840 6 16999640", "955944 1278 748", "482120804 66748 7223", "370330636048898430 61721772674816405 6", "344459175789842163 7328918633826429 47", "877228952036215545 166805277055755 5259", "116741460012229240 1298911316 89876390", "275856334120822851 209 1319886766128339", "413850294331656955 1 413850294331656955", "54682301 778668 253103", "329245015 3931027 6443236", "321076647734423976 7 8", "455227494055672047 71 60", "595779167455745259 9741 9331", "6470 80 160", "686325 828 1656", "4535304 2129 4258", "40525189 6365 12730", "675297075 25986 51972", "5681598412 75376 226128", "384118571739435733 619773000 1859319000", "391554751752251913 625743359 1877230077", "390728504279201198 625082797 1250165594", "389902265396085075 624421544 1248843088", "734812071040507372 857211800 2571635400", "1 1 2", "3 1 4", "8 2 3", "64 32 16", "1 1 1000000000", "1000000000 1 1", "1000000000 1000000000 1000000000", "1000000000 2 4", "1000000000 123 456", "1000000000 123123 654", "123456 123 456", "123456 1234567 123", "314159265 271 8281", "11071994 4231 1324", "961748927 961748941 982451653", "15485221 1259 90863", "5000000000000000000 4999999999999999837 4999999999999999963", "4000000000000000000 3999999999999999691 3999999999999999887", "999999999999999999 999999999999999709 999999999999999737", "799999999999999999 799999999999999969 799999999999999991", "812312312312312222 812312312312311897 812312312312312029", "500000000000000000 499999999999999927 499999999999999931", "555555555555555555 555555555555555083 555555555555555229", "199419941994199419 199419941994199369 199419941994199391", "145685485411238588 145685485411238483 145685485411238573", "314159265358979323 314159265358979167 314159265358979213", "10 1000000000000000000 1000000000000000001", "5 100000000000000000 99999999999999999", "5 1000000000000 1000000000001", "5 1000000000000000000 1000000000000000001", "2 1000000000000000000 1000000000000000001", "2 10 11", "10 123456789123456789 723456789123456781", "12345678910 123456789101112131 123456789101112132", "5 499999999999999999 499999999999999998"], "outputs": ["3/10", "3/7", "1/1", "94/2907", "765/94268", "2358/131305", "71936/3898439", "7914548537/257593781689876390", "3003994959686828/111319886766128339", "409853735661743838/413850294331656955", "23437499999999999/23437500000000000", "1/9", "3/32", "41/244", "94/2907", "689/94268", "2358/131305", "71936/3898439", "253102/54682301", "1173507/329245015", "1/1", "19792499741550983/455227494055672047", "205511958419723/595779167455745259", "1/2", "33045955908448679/33045955908448702", "2499999999999999/1000000000000000000", "4999999549999999/2001500050002000000", "29498980479974999/2451500050002000000", "7914548537/257593781689876390", "3003994959686828/111319886766128339", "409853735661743838/413850294331656955", "2/29", "13765/2748136", "13/45", "189/1954", "571199/146752429", "10344881/144828215", "1/1", "1/1", "31/202", "1/1", "1/1", "1/1", "3611/42678069", "9/674664088", "17/762200126044291557", "28/183429706787768307", "5258/360212127113008697", "539258339/683705963104411677", "3959660298385016/573003994959686829", "1/1", "1/19", "1/16", "1/477", "1/8499820", "1/639", "1/66748", "1/61721772674816405", "1/7328918633826429", "1/55601759018585", "1/649455658", "1/1319886766128339", "1/413850294331656955", "253102/54682301", "357366/29931365", "1672274206950125/13378193655600999", "6411654845854559/455227494055672047", "61162012885196/595779167455745259", "327/647", "114511/228775", "755973/1511768", "20265394/40525189", "112553659/225099025", "1893897375/5681598412", "128039524053435733/384118571739435733", "130518250652782079/391554751752251913", "195364252413988195/390728504279201198", "64983710976697837/129967421798695025", "61234339274051543/183703017760126843", "0/1", "0/1", "3/8", "1/2", "0/1", "1/1", "1/1", "1/2", "6579023/1000000000", "24851/1000000000", "215/30864", "61/61728", "37939/314159265", "2647/11071994", "1/1", "1258/15485221", "1249999999999999959/1250000000000000000", "399999999999999969/400000000000000000", "333333333333333236/333333333333333333", "799999999999999968/799999999999999999", "406156156156155948/406156156156156111", "249999999999999963/250000000000000000", "50505050505050462/50505050505050505", "66473313998066456/66473313998066473", "72842742705619241/72842742705619294", "314159265358979166/314159265358979323", "1/1", "1/1", "1/1", "1/1", "1/1", "1/1", "1/1", "1/1", "1/1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 146 | |
30b0da6da608e9e1c0bcfb1c6a77658e | Xenia and Tree | Xenia the programmer has a tree consisting of *n* nodes. We will consider the tree nodes indexed from 1 to *n*. We will also consider the first node to be initially painted red, and the other nodes — to be painted blue.
The distance between two tree nodes *v* and *u* is the number of edges in the shortest path between *v* and *u*.
Xenia needs to learn how to quickly execute queries of two types:
1. paint a specified blue node in red; 1. calculate which red node is the closest to the given one and print the shortest distance to the closest red node.
Your task is to write a program which will execute the described queries.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of nodes in the tree and the number of queries. Next *n*<=-<=1 lines contain the tree edges, the *i*-th line contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) — an edge of the tree.
Next *m* lines contain queries. Each query is specified as a pair of integers *t**i*,<=*v**i* (1<=≤<=*t**i*<=≤<=2,<=1<=≤<=*v**i*<=≤<=*n*). If *t**i*<==<=1, then as a reply to the query we need to paint a blue node *v**i* in red. If *t**i*<==<=2, then we should reply to the query by printing the shortest distance from some red node to node *v**i*.
It is guaranteed that the given graph is a tree and that all queries are correct.
For each second type query print the reply in a single line.
Sample Input
5 4
1 2
2 3
2 4
4 5
2 1
2 5
1 2
2 5
Sample Output
0
3
2
| [
"class CentroidDecomposition():\r\n def __init__(self, g):\r\n self.g = g\r\n self.n = len(g)\r\n\r\n self.parent = [-1]*self.n\r\n self.size = [1]*self.n\r\n self.cdparent = [-1]*self.n\r\n self.cddepth = [0]*self.n\r\n self.cdorder = [-1]*self.n\r\n self.cdused = [0]*self.n\r\n\r\n cnt = 0\r\n stack = [0]\r\n while stack:\r\n v = stack.pop()\r\n p = self.cdparent[v]\r\n c = self.get_centroid(v)\r\n self.cdused[c] = True\r\n self.cdparent[c] = p\r\n self.cddepth[c] = self.cddepth[v]\r\n self.cdorder[c] = cnt\r\n cnt += 1\r\n for u in self.g[c]:\r\n if self.cdused[u]:\r\n continue\r\n self.cdparent[u] = c\r\n self.cddepth[u] = self.cddepth[c]+1\r\n stack.append(u)\r\n\r\n def get_centroid(self, root):\r\n self.parent[root] = -1\r\n self.size[root] = 1\r\n stack = [root]\r\n order = []\r\n while stack:\r\n v = stack.pop()\r\n order.append(v)\r\n for u in g[v]:\r\n if self.parent[v] == u or self.cdused[u]:\r\n continue\r\n self.size[u] = 1\r\n self.parent[u] = v\r\n stack.append(u)\r\n if len(order) <= 2:\r\n return root\r\n for v in reversed(order):\r\n if self.parent[v] == -1:\r\n continue\r\n self.size[self.parent[v]] += self.size[v]\r\n total = self.size[root]\r\n v = root\r\n while True:\r\n for u in self.g[v]:\r\n if self.parent[v] == u or self.cdused[u]:\r\n continue\r\n if self.size[u] > total//2:\r\n v = u\r\n break\r\n else:\r\n return v\r\n\r\nclass HLD:\r\n def __init__(self, g):\r\n self.g = g\r\n self.n = len(g)\r\n self.parent = [-1]*self.n\r\n self.size = [1]*self.n\r\n self.head = [0]*self.n\r\n self.preorder = [0]*self.n\r\n self.k = 0\r\n self.depth = [0]*self.n\r\n\r\n for v in range(self.n):\r\n if self.parent[v] == -1:\r\n self.dfs_pre(v)\r\n self.dfs_hld(v)\r\n\r\n def dfs_pre(self, v):\r\n g = self.g\r\n stack = [v]\r\n order = [v]\r\n while stack:\r\n v = stack.pop()\r\n for u in g[v]:\r\n if self.parent[v] == u:\r\n continue\r\n self.parent[u] = v\r\n self.depth[u] = self.depth[v]+1\r\n stack.append(u)\r\n order.append(u)\r\n\r\n # 隣接リストの左端: heavyな頂点への辺\r\n # 隣接リストの右端: 親への辺\r\n while order:\r\n v = order.pop()\r\n child_v = g[v]\r\n if len(child_v) and child_v[0] == self.parent[v]:\r\n child_v[0], child_v[-1] = child_v[-1], child_v[0]\r\n for i, u in enumerate(child_v):\r\n if u == self.parent[v]:\r\n continue\r\n self.size[v] += self.size[u]\r\n if self.size[u] > self.size[child_v[0]]:\r\n child_v[i], child_v[0] = child_v[0], child_v[i]\r\n\r\n def dfs_hld(self, v):\r\n stack = [v]\r\n while stack:\r\n v = stack.pop()\r\n self.preorder[v] = self.k\r\n self.k += 1\r\n top = self.g[v][0]\r\n # 隣接リストを逆順に見ていく(親 > lightな頂点への辺 > heavyな頂点 (top))\r\n # 連結成分が連続するようにならべる\r\n for u in reversed(self.g[v]):\r\n if u == self.parent[v]:\r\n continue\r\n if u == top:\r\n self.head[u] = self.head[v]\r\n else:\r\n self.head[u] = u\r\n stack.append(u)\r\n\r\n def for_each(self, u, v):\r\n # [u, v]上の頂点集合の区間を列挙\r\n while True:\r\n if self.preorder[u] > self.preorder[v]:\r\n u, v = v, u\r\n l = max(self.preorder[self.head[v]], self.preorder[u])\r\n r = self.preorder[v]\r\n yield l, r # [l, r]\r\n if self.head[u] != self.head[v]:\r\n v = self.parent[self.head[v]]\r\n else:\r\n return\r\n\r\n def for_each_edge(self, u, v):\r\n # [u, v]上の辺集合の区間列挙\r\n # 辺の情報は子の頂点に\r\n while True:\r\n if self.preorder[u] > self.preorder[v]:\r\n u, v = v, u\r\n if self.head[u] != self.head[v]:\r\n yield self.preorder[self.head[v]], self.preorder[v]\r\n v = self.parent[self.head[v]]\r\n else:\r\n if u != v:\r\n yield self.preorder[u]+1, self.preorder[v]\r\n break\r\n\r\n def subtree(self, v):\r\n # 頂点vの部分木の頂点集合の区間 [l, r)\r\n l = self.preorder[v]\r\n r = self.preorder[v]+self.size[v]\r\n return l, r\r\n\r\n def lca(self, u, v):\r\n # 頂点u, vのLCA\r\n while True:\r\n if self.preorder[u] > self.preorder[v]:\r\n u, v = v, u\r\n if self.head[u] == self.head[v]:\r\n return u\r\n v = self.parent[self.head[v]]\r\n\r\nimport sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\ng = [[] for i in range(n)]\r\nfor i in range(n-1):\r\n a, b = map(int, input().split())\r\n a, b = a-1, b-1\r\n g[a].append(b)\r\n g[b].append(a)\r\n\r\ncd = CentroidDecomposition(g)\r\nhld = HLD(g)\r\n#print(cd.cdparent)\r\nmin_dist = [0]*n\r\nfor i in range(n):\r\n min_dist[i] = hld.depth[i]\r\n\r\n#print(min_dist)\r\n\r\nfor i in range(m):\r\n t, v = map(int, input().split())\r\n v -= 1\r\n if t == 1:\r\n cur = v\r\n while cur != -1:\r\n l = hld.lca(cur, v)\r\n d = hld.depth[cur]+hld.depth[v]-2*hld.depth[l]\r\n min_dist[cur] = min(min_dist[cur], d)\r\n cur = cd.cdparent[cur]\r\n else:\r\n ans = n\r\n cur = v\r\n while cur != -1:\r\n l = hld.lca(cur, v)\r\n d = hld.depth[cur]+hld.depth[v]-2*hld.depth[l]\r\n ans = min(ans, d+min_dist[cur])\r\n cur = cd.cdparent[cur]\r\n print(ans)\r\n",
"import os, sys\r\nfrom io import BytesIO, IOBase\r\nfrom array import array\r\nfrom itertools import accumulate\r\nimport bisect\r\nimport math\r\nfrom collections import deque\r\n\r\n# from functools import cache\r\n# cache cf需要自己提交 pypy3.9!\r\nfrom copy import deepcopy\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\n\r\ninput = lambda: sys.stdin.readline().strip()\r\nints = lambda: list(map(int, input().split()))\r\nInt = lambda: int(input())\r\n\r\n\r\ndef queryInteractive(a, b, c):\r\n print('? {} {} {}'.format(a, b, c))\r\n sys.stdout.flush()\r\n return int(input())\r\n\r\n\r\ndef answerInteractive(x1, x2):\r\n print('! {} {}'.format(x1, x2))\r\n sys.stdout.flush()\r\n\r\n\r\nINF = 1000000000\r\n\r\n\r\n\r\nfrom types import GeneratorType\r\n\r\n\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n if type(to) is GeneratorType:\r\n stack.append(to)\r\n to = next(to)\r\n else:\r\n stack.pop()\r\n if not stack:\r\n break\r\n to = stack[-1].send(to)\r\n return to\r\n\r\n return wrappedfunc\r\n\r\nclass LCA:\r\n \"\"\"<O(n), O(log(n))>\"\"\"\r\n\r\n def __init__(self, G, root, parents):\r\n from collections import deque\r\n\r\n self.n = len(G)\r\n self.tour = [0] * (2 * self.n - 1)\r\n self.depth_list = [0] * (2 * self.n - 1)\r\n self.id = [-1] * self.n\r\n self.dfs(G, root, parents)\r\n self._rmq_init(self.depth_list)\r\n\r\n def _rmq_init(self, arr):\r\n n = self.mod = len(arr)\r\n self.seg_len = 1 << (n - 1).bit_length()\r\n self.seg = [self.n * n] * (2 * self.seg_len)\r\n seg = self.seg\r\n for i, e in enumerate(arr):\r\n seg[self.seg_len + i] = n * e + i\r\n for i in range(self.seg_len - 1, 0, -1):\r\n seg[i] = min(seg[2 * i], seg[2 * i + 1])\r\n\r\n def _rmq_query(self, l, r):\r\n l += self.seg_len\r\n r += self.seg_len\r\n res = self.n * self.mod\r\n seg = self.seg\r\n while l < r:\r\n if r & 1:\r\n r -= 1\r\n res = min(res, seg[r])\r\n if l & 1:\r\n res = min(res, seg[l])\r\n l += 1\r\n l >>= 1\r\n r >>= 1\r\n return res % self.mod\r\n\r\n def dfs(self, G, root, parents):\r\n id = self.id\r\n tour = self.tour\r\n depth_list = self.depth_list\r\n v = root\r\n it = [0] * self.n\r\n visit_id = 0\r\n depth = 0\r\n while v != -1:\r\n if id[v] == -1:\r\n id[v] = visit_id\r\n tour[visit_id] = v\r\n depth_list[visit_id] = depth\r\n visit_id += 1\r\n g = G[v]\r\n if it[v] == len(g):\r\n v = parents[v]\r\n depth -= 1\r\n continue\r\n if g[it[v]] == parents[v]:\r\n it[v] += 1\r\n if it[v] == len(g):\r\n v = parents[v]\r\n depth -= 1\r\n continue\r\n else:\r\n child = g[it[v]]\r\n it[v] += 1\r\n v = child\r\n depth += 1\r\n else:\r\n child = g[it[v]]\r\n it[v] += 1\r\n v = child\r\n depth += 1\r\n\r\n def lca(self, u: int, v: int) -> int:\r\n l, r = self.id[u], self.id[v]\r\n if r < l:\r\n l, r = r, l\r\n q = self._rmq_query(l, r + 1)\r\n return self.tour[q]\r\n\r\n def dist(self, u: int, v: int) -> int:\r\n lca = self.lca(u, v)\r\n depth_u = self.depth_list[self.id[u]]\r\n depth_v = self.depth_list[self.id[v]]\r\n depth_lca = self.depth_list[self.id[lca]]\r\n return depth_u + depth_v - 2 * depth_lca\r\n\r\nclass Graph:\r\n def __init__(self, n):\r\n self.n = n\r\n self.dis = [INF] * n\r\n self.g = [[] for _ in range(n)]\r\n self.root_dis = [INF] * n\r\n self.lca_nodes = []\r\n self.first_occur = [0] * n\r\n self.MAX_LOG = 18\r\n self.rmq = [array('l',[INF]*(2*n)) for _ in range(self.MAX_LOG)]\r\n def input(self):\r\n for _ in range(self.n-1):\r\n u, v = map(int, input().split())\r\n u -= 1\r\n v -= 1\r\n self.g[u].append(v)\r\n self.g[v].append(u)\r\n self.update_distance([0])\r\n self.root_dis[0] = 0\r\n self.dfs_plus(0)\r\n # print(len(self.lca_nodes), self.lca_nodes)\r\n for j in range(self.MAX_LOG):\r\n step = 2**(j-1)\r\n length = len(self.lca_nodes)\r\n for i in range(length):\r\n u = self.lca_nodes[i]\r\n if j == 0:\r\n self.rmq[j][i] = self.root_dis[u]\r\n else:\r\n self.rmq[j][i] = self.rmq[j-1][i]\r\n if i + step < length:\r\n self.rmq[j][i] = min(self.rmq[j][i], self.rmq[j-1][i+step])\r\n def dfs_plus(self, start):\r\n Q = deque([(start,0,-1)])\r\n while Q:\r\n u, nxt, last = Q.pop()\r\n if nxt == 0:\r\n self.first_occur[u] = len(self.lca_nodes)\r\n self.lca_nodes.append(u)\r\n is_add_back = False\r\n for i in range(nxt, len(self.g[u])):\r\n v = self.g[u][i]\r\n if v != last:\r\n self.root_dis[v] = self.root_dis[u] + 1\r\n Q.append((u, i+1, last))\r\n Q.append((v, 0, u))\r\n is_add_back = True\r\n break\r\n if last != -1 and not is_add_back:\r\n self.lca_nodes.append(last)\r\n def dfs(self, u, last):\r\n self.first_occur[u] = len(self.lca_nodes)\r\n self.lca_nodes.append(u)\r\n for v in self.g[u]:\r\n if v != last:\r\n self.root_dis[v] = self.root_dis[u] + 1\r\n self.dfs(v,u)\r\n self.lca_nodes.append(u)\r\n def update_distance(self, l):\r\n # nodes in l are changed to distance 0, update others\r\n for u in l:\r\n self.dis[u] = 0\r\n Q = deque(l)\r\n while Q:\r\n u = Q.popleft()\r\n for v in self.g[u]:\r\n if self.dis[v] > self.dis[u] + 1:\r\n self.dis[v] = self.dis[u] + 1\r\n Q.append(v)\r\n def get_distance(self, u):\r\n return self.dis[u]\r\n def get_pair_distance(self, u, v):\r\n return self.root_dis[u] + self.root_dis[v] \\\r\n - 2 * self.get_lca_root_distance(u,v)\r\n def get_lca_root_distance(self, u, v):\r\n fu, fv = self.first_occur[u], self.first_occur[v]\r\n if fu > fv:\r\n fu, fv = fv, fu\r\n length = fv - fu + 1\r\n j, step = 0, 1\r\n while step*2 < length:\r\n j += 1\r\n step <<= 1\r\n return min(self.rmq[j][fu], self.rmq[j][fv - step + 1])\r\n\r\n\r\nn,m = ints()\r\ng = Graph(n)\r\ng.input()\r\n\r\n\r\nLIM = int(math.sqrt(m))\r\nbuck = [0]\r\n\r\ndef qry(x):\r\n ans = g.dis[x]\r\n for y in buck:\r\n ans = min(ans,g.get_pair_distance(y,x))\r\n return ans\r\n\r\n\r\n\r\n\r\nfor i in range(m):\r\n t,v = ints()\r\n v -= 1\r\n if t == 1:\r\n buck.append(v)\r\n else:\r\n print(qry(v))\r\n \r\n if len(buck) >= LIM:\r\n g.update_distance(buck)\r\n buck = []\r\n",
"class Tree():\r\n def __init__(self, n):\r\n self.n = n\r\n self.tree = [[] for _ in range(n)]\r\n self.root = None\r\n\r\n def add_edge(self, u, v):\r\n self.tree[u].append(v)\r\n self.tree[v].append(u)\r\n\r\n def set_root(self, r=0):\r\n self.root = r\r\n self.par = [None] * self.n\r\n self.dep = [0] * self.n\r\n self.height = [0] * self.n\r\n self.size = [1] * self.n\r\n self.ord = [r]\r\n stack = [r]\r\n while stack:\r\n v = stack.pop()\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj: continue\r\n self.par[adj] = v\r\n self.dep[adj] = self.dep[v] + 1\r\n self.ord.append(adj)\r\n stack.append(adj)\r\n for v in self.ord[1:][::-1]:\r\n self.size[self.par[v]] += self.size[v]\r\n self.height[self.par[v]] = max(self.height[self.par[v]], self.height[v] + 1)\r\n\r\n def rerooting(self, op, e, merge, id):\r\n if self.root is None: self.set_root()\r\n dp = [e] * self.n\r\n lt = [id] * self.n\r\n rt = [id] * self.n\r\n inv = [id] * self.n\r\n for v in self.ord[::-1]:\r\n tl = tr = e\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj: continue\r\n lt[adj] = tl\r\n tl = op(tl, dp[adj])\r\n for adj in self.tree[v][::-1]:\r\n if self.par[v] == adj: continue\r\n rt[adj] = tr\r\n tr = op(tr, dp[adj])\r\n dp[v] = tr\r\n for v in self.ord:\r\n if v == self.root: continue\r\n p = self.par[v]\r\n inv[v] = op(merge(lt[v], rt[v]), inv[p])\r\n dp[v] = op(dp[v], inv[v])\r\n return dp\r\n\r\n def euler_tour(self):\r\n if self.root is None: self.set_root()\r\n self.tour = []\r\n self.etin = [None for _ in range(self.n)]\r\n self.etout = [None for _ in range(self.n)]\r\n used = [0 for _ in range(self.n)]\r\n used[self.root] = 1\r\n stack = [self.root]\r\n while stack:\r\n v = stack.pop()\r\n if v >= 0:\r\n self.tour.append(v)\r\n stack.append(~v)\r\n if self.etin[v] is None:\r\n self.etin[v] = len(self.tour) - 1\r\n for adj in self.tree[v]:\r\n if used[adj]: continue\r\n used[adj] = 1\r\n stack.append(adj)\r\n else:\r\n self.etout[~v] = len(self.tour)\r\n if ~v != self.root:\r\n self.tour.append(self.par[~v])\r\n\r\n def heavylight_decomposition(self):\r\n if self.root is None: self.set_root()\r\n self.hldid = [None] * self.n\r\n self.hldtop = [None] * self.n\r\n self.hldtop[self.root] = self.root\r\n self.hldnxt = [None] * self.n\r\n self.hldrev = [None] * self.n\r\n stack = [self.root]\r\n cnt = 0\r\n while stack:\r\n v = stack.pop()\r\n self.hldid[v] = cnt\r\n self.hldrev[cnt] = v\r\n cnt += 1\r\n maxs = 0\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj: continue\r\n if maxs < self.size[adj]:\r\n maxs = self.size[adj]\r\n self.hldnxt[v] = adj\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj or self.hldnxt[v] == adj: continue\r\n self.hldtop[adj] = adj\r\n stack.append(adj)\r\n if self.hldnxt[v] is not None:\r\n self.hldtop[self.hldnxt[v]] = self.hldtop[v]\r\n stack.append(self.hldnxt[v])\r\n\r\n def lca(self, u, v):\r\n while True:\r\n if self.hldid[u] > self.hldid[v]: u, v = v, u\r\n if self.hldtop[u] != self.hldtop[v]:\r\n v = self.par[self.hldtop[v]]\r\n else:\r\n return u\r\n\r\n def dist(self, u, v):\r\n lca = self.lca(u, v)\r\n return self.dep[u] + self.dep[v] - 2 * self.dep[lca]\r\n\r\n def range_query(self, u, v, edge_query=False):\r\n while True:\r\n if self.hldid[u] > self.hldid[v]: u, v = v, u\r\n if self.hldtop[u] != self.hldtop[v]:\r\n yield self.hldid[self.hldtop[v]], self.hldid[v] + 1\r\n v = self.par[self.hldtop[v]]\r\n else:\r\n yield self.hldid[u] + edge_query, self.hldid[v] + 1\r\n return\r\n\r\n def subtree_query(self, u):\r\n return self.hldid[u], self.hldid[u] + self.size[u]\r\n\r\n def _get_centroid_(self, r):\r\n self._par_[r] = None\r\n self._size_[r] = 1\r\n ord = [r]\r\n stack = [r]\r\n while stack:\r\n v = stack.pop()\r\n for adj in self.tree[v]:\r\n if self._par_[v] == adj or self.cdused[adj]: continue\r\n self._size_[adj] = 1\r\n self._par_[adj] = v\r\n ord.append(adj)\r\n stack.append(adj)\r\n if len(ord) <= 2: return r\r\n for v in ord[1:][::-1]:\r\n self._size_[self._par_[v]] += self._size_[v]\r\n sr = self._size_[r] // 2\r\n v = r\r\n while True:\r\n for adj in self.tree[v]:\r\n if self._par_[v] == adj or self.cdused[adj]: continue\r\n if self._size_[adj] > sr:\r\n v = adj\r\n break\r\n else:\r\n return v\r\n\r\n def centroid_decomposition(self):\r\n self._par_ = [None] * self.n\r\n self._size_ = [1] * self.n\r\n self.cdpar = [None] * self.n\r\n self.cddep = [0] * self.n\r\n self.cdord = [None] * self.n\r\n self.cdused = [0] * self.n\r\n cnt = 0\r\n stack = [0]\r\n while stack:\r\n v = stack.pop()\r\n p = self.cdpar[v]\r\n c = self._get_centroid_(v)\r\n self.cdused[c] = True\r\n self.cdpar[c] = p\r\n self.cddep[c] = self.cddep[v]\r\n self.cdord[c] = cnt\r\n cnt += 1\r\n for adj in self.tree[c]:\r\n if self.cdused[adj]: continue\r\n self.cdpar[adj] = c\r\n self.cddep[adj] = self.cddep[c] + 1\r\n stack.append(adj)\r\n\r\n def centroid(self):\r\n if self.root is None: self.set_root()\r\n sr = self.size[self.root] // 2\r\n v = self.root\r\n while True:\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj: continue\r\n if self.size[adj] > sr:\r\n v = adj\r\n break\r\n else:\r\n return v\r\n\r\n def diam(self):\r\n if self.root is None: self.set_root()\r\n u = self.dep.index(max(self.dep))\r\n self.set_root(u)\r\n v = self.dep.index(max(self.dep))\r\n return u, v\r\n\r\n def get_path(self, u, v):\r\n if self.root != u: self.set_root(u)\r\n path = []\r\n while v != None:\r\n path.append(v)\r\n v = self.par[v]\r\n return path\r\n\r\n def longest_path_decomposition(self, make_ladder=True):\r\n assert self.root is not None\r\n self.lpdnxt = [None] * self.n\r\n self.lpdtop = [None] * self.n\r\n self.lpdtop[self.root] = self.root\r\n stack = [self.root]\r\n while stack:\r\n v = stack.pop()\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj: continue\r\n if self.height[v] == self.height[adj] + 1:\r\n self.lpdnxt[v] = adj\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj or self.lpdnxt[v] == adj: continue\r\n self.lpdtop[adj] = adj\r\n stack.append(adj)\r\n if self.lpdnxt[v] is not None:\r\n self.lpdtop[self.lpdnxt[v]] = self.lpdtop[v]\r\n stack.append(self.lpdnxt[v])\r\n if make_ladder: self._make_ladder_()\r\n\r\n def _make_ladder_(self):\r\n self.ladder = [[] for _ in range(self.n)]\r\n for v in range(self.n):\r\n if self.lpdtop[v] != v: continue\r\n to = v\r\n path = []\r\n while to is not None:\r\n path.append(to)\r\n to = self.lpdnxt[to]\r\n p = self.par[v]\r\n self.ladder[v] = path[::-1]\r\n for i in range(len(path)):\r\n self.ladder[v].append(p)\r\n if p is None: break\r\n p = self.par[p]\r\n\r\n def level_ancestor(self, v, k):\r\n while v is not None:\r\n id = self.height[v]\r\n h = self.lpdtop[v]\r\n if len(self.ladder[h]) > k + id:\r\n return self.ladder[h][k + id]\r\n v = self.ladder[h][-1]\r\n k -= len(self.ladder[h]) - id - 1\r\n\r\nimport io, os\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nN, Q = map(int, input().split())\r\n\r\nt = Tree(N)\r\n\r\nfor _ in range(N - 1):\r\n u, v = map(int, input().split())\r\n t.add_edge(u - 1, v - 1)\r\n\r\nt.heavylight_decomposition()\r\nt.centroid_decomposition()\r\n\r\nmin_dist = [N] * N\r\nres = []\r\n\r\ndef query_1(v):\r\n cur = v\r\n while cur is not None:\r\n min_dist[cur] = min(min_dist[cur], t.dist(cur, v))\r\n cur = t.cdpar[cur]\r\n\r\ndef query_2(v):\r\n ret = N\r\n cur = v\r\n while cur is not None:\r\n ret = min(ret, t.dist(cur, v) + min_dist[cur])\r\n cur = t.cdpar[cur]\r\n return ret\r\n\r\nquery_1(0)\r\n\r\nfor _ in range(Q):\r\n q, v = map(int, input().split())\r\n if q == 1:\r\n query_1(v - 1)\r\n else:\r\n res.append((query_2(v - 1)))\r\n\r\nprint('\\n'.join(map(str, res)))",
"class Tree():\r\n def __init__(self, n):\r\n self.n = n\r\n self.tree = [[] for _ in range(n)]\r\n self.root = None\r\n\r\n def addEdge(self, u, v):\r\n self.tree[u].append(v)\r\n self.tree[v].append(u)\r\n\r\n def setRoot(self, r=0):\r\n self.root = r\r\n self.par = [None] * self.n\r\n self.dep = [0] * self.n\r\n self.height = [0] * self.n\r\n self.size = [1] * self.n\r\n self.order = [r]\r\n stack = [r]\r\n while stack:\r\n v = stack.pop()\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj: continue\r\n self.par[adj] = v\r\n self.dep[adj] = self.dep[v] + 1\r\n self.order.append(adj)\r\n stack.append(adj)\r\n for v in self.order[1:][::-1]:\r\n self.size[self.par[v]] += self.size[v]\r\n self.height[self.par[v]] = max(self.height[self.par[v]], self.height[v] + 1)\r\n\r\n def rerooting(self, op, e, merge, timer):\r\n if self.root is None: self.setRoot()\r\n dp = [e] * self.n\r\n lt = [timer] * self.n\r\n rt = [timer] * self.n\r\n inv = [timer] * self.n\r\n for v in self.order[::-1]:\r\n tl = tr = e\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj: continue\r\n lt[adj] = tl\r\n tl = op(tl, dp[adj])\r\n for adj in self.tree[v][::-1]:\r\n if self.par[v] == adj: continue\r\n rt[adj] = tr\r\n tr = op(tr, dp[adj])\r\n dp[v] = tr\r\n for v in self.order:\r\n if v == self.root: continue\r\n p = self.par[v]\r\n inv[v] = op(merge(lt[v], rt[v]), inv[p])\r\n dp[v] = op(dp[v], inv[v])\r\n return dp\r\n\r\n def eulerTour(self):\r\n if self.root is None: self.setRoot()\r\n self.tour = []\r\n self.etin = [None for _ in range(self.n)]\r\n self.etout = [None for _ in range(self.n)]\r\n used = [0 for _ in range(self.n)]\r\n used[self.root] = 1\r\n stack = [self.root]\r\n while stack:\r\n v = stack.pop()\r\n if v >= 0:\r\n self.tour.append(v)\r\n stack.append(~v)\r\n if self.etin[v] is None:\r\n self.etin[v] = len(self.tour) - 1\r\n for adj in self.tree[v]:\r\n if used[adj]: continue\r\n used[adj] = 1\r\n stack.append(adj)\r\n else:\r\n self.etout[~v] = len(self.tour)\r\n if ~v != self.root:\r\n self.tour.append(self.par[~v])\r\n\r\n def heavyLightDecompostion(self):\r\n if self.root is None: self.setRoot()\r\n self.hldtimer = [None] * self.n\r\n self.hldtop = [None] * self.n\r\n self.hldtop[self.root] = self.root\r\n self.hldnxt = [None] * self.n\r\n self.hldrev = [None] * self.n\r\n stack = [self.root]\r\n cnt = 0\r\n while stack:\r\n v = stack.pop()\r\n self.hldtimer[v] = cnt\r\n self.hldrev[cnt] = v\r\n cnt += 1\r\n maxs = 0\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj: continue\r\n if maxs < self.size[adj]:\r\n maxs = self.size[adj]\r\n self.hldnxt[v] = adj\r\n for adj in self.tree[v]:\r\n if self.par[v] == adj or self.hldnxt[v] == adj: continue\r\n self.hldtop[adj] = adj\r\n stack.append(adj)\r\n if self.hldnxt[v] is not None:\r\n self.hldtop[self.hldnxt[v]] = self.hldtop[v]\r\n stack.append(self.hldnxt[v])\r\n\r\n def lca(self, u, v):\r\n while True:\r\n if self.hldtimer[u] > self.hldtimer[v]: u, v = v, u\r\n if self.hldtop[u] != self.hldtop[v]:\r\n v = self.par[self.hldtop[v]]\r\n else:\r\n return u\r\n\r\n def dist(self, u, v):\r\n lca = self.lca(u, v)\r\n return self.dep[u] + self.dep[v] - 2 * self.dep[lca]\r\n\r\n\r\n def getCentoridTimer(self, r):\r\n self.parent[r] = None\r\n self.size[r] = 1\r\n order = [r]\r\n stack = [r]\r\n while stack:\r\n v = stack.pop()\r\n for adj in self.tree[v]:\r\n if self.parent[v] == adj or self.cdused[adj]: continue\r\n self.size[adj] = 1\r\n self.parent[adj] = v\r\n order.append(adj)\r\n stack.append(adj)\r\n if len(order) <= 2: return r\r\n for v in order[1:][::-1]:\r\n self.size[self.parent[v]] += self.size[v]\r\n sr = self.size[r] // 2\r\n v = r\r\n while True:\r\n for adj in self.tree[v]:\r\n if self.parent[v] == adj or self.cdused[adj]: continue\r\n if self.size[adj] > sr:\r\n v = adj\r\n break\r\n else:\r\n return v\r\n\r\n def centroidDecomposition(self):\r\n self.parent = [None] * self.n\r\n self.size = [1] * self.n\r\n self.cdpar = [None] * self.n\r\n self.cddep = [0] * self.n\r\n self.cdorder = [None] * self.n\r\n self.cdused = [0] * self.n\r\n cnt = 0\r\n stack = [0]\r\n while stack:\r\n v = stack.pop()\r\n p = self.cdpar[v]\r\n c = self.getCentoridTimer(v)\r\n self.cdused[c] = True\r\n self.cdpar[c] = p\r\n self.cddep[c] = self.cddep[v]\r\n self.cdorder[c] = cnt\r\n cnt += 1\r\n for adj in self.tree[c]:\r\n if self.cdused[adj]: continue\r\n self.cdpar[adj] = c\r\n self.cddep[adj] = self.cddep[c] + 1\r\n stack.append(adj)\r\n\r\n\r\n\r\nimport sys\r\ndef rd(): return sys.stdin.readline().strip()\r\ndef rdl(typ,sep=\" \"): return list(map(typ, rd().split(sep)))\r\ndef wt(x,sep=\"\\n\") : sys.stdout.write(str(x) + sep) # string / num\r\n\r\n\r\n\r\n\r\nN, Q = rdl(int)\r\n\r\ntree = Tree(N)\r\n\r\nfor _ in range(N - 1):\r\n u, v = rdl(int)\r\n tree.addEdge(u - 1, v - 1)\r\n\r\ntree.heavyLightDecompostion()\r\ntree.centroidDecomposition()\r\n\r\nminDist = [N] * N\r\nres = []\r\n\r\ndef centroidUpdate(v):\r\n curr = v\r\n while curr is not None:\r\n minDist[curr] = min(minDist[curr], tree.dist(curr, v))\r\n curr = tree.cdpar[curr]\r\n\r\ndef centroidQuery(v):\r\n ret = N\r\n curr = v\r\n while curr is not None:\r\n ret = min(ret, tree.dist(curr, v) + minDist[curr])\r\n curr = tree.cdpar[curr]\r\n return ret\r\n\r\ncentroidUpdate(0)\r\n\r\nfor _ in range(Q):\r\n q, v = rdl(int)\r\n if q == 1:\r\n centroidUpdate(v - 1)\r\n else:\r\n wt((centroidQuery(v - 1)))\r\n"
] | {"inputs": ["5 4\n1 2\n2 3\n2 4\n4 5\n2 1\n2 5\n1 2\n2 5"], "outputs": ["0\n3\n2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
30cbb8e50f856c890357da22cf574c69 | Cyclic Components | You are given an undirected graph consisting of $n$ vertices and $m$ edges. Your task is to find the number of connected components which are cycles.
Here are some definitions of graph theory.
An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices. All edges are bidirectional (i.e. if a vertex $a$ is connected with a vertex $b$, a vertex $b$ is also connected with a vertex $a$). An edge can't connect vertex with itself, there is at most one edge between a pair of vertices.
Two vertices $u$ and $v$ belong to the same connected component if and only if there is at least one path along edges connecting $u$ and $v$.
A connected component is a cycle if and only if its vertices can be reordered in such a way that:
- the first vertex is connected with the second vertex by an edge, - the second vertex is connected with the third vertex by an edge, - ... - the last vertex is connected with the first vertex by an edge, - all the described edges of a cycle are distinct.
A cycle doesn't contain any other edges except described above. By definition any cycle contains three or more vertices.
The first line contains two integer numbers $n$ and $m$ ($1 \le n \le 2 \cdot 10^5$, $0 \le m \le 2 \cdot 10^5$) — number of vertices and edges.
The following $m$ lines contains edges: edge $i$ is given as a pair of vertices $v_i$, $u_i$ ($1 \le v_i, u_i \le n$, $u_i \ne v_i$). There is no multiple edges in the given graph, i.e. for each pair ($v_i, u_i$) there no other pairs ($v_i, u_i$) and ($u_i, v_i$) in the list of edges.
Print one integer — the number of connected components which are also cycles.
Sample Input
5 4
1 2
3 4
5 4
3 5
17 15
1 8
1 12
5 11
11 9
9 15
15 5
4 13
3 13
4 3
10 16
7 10
16 7
14 3
14 4
17 6
Sample Output
1
2
| [
"n, m = map(int, input().split())\r\ngrafo = [[] for i in range(n + 1)]\r\n\r\nfor i in range(m):\r\n v_i, u_i = map(int, input().split())\r\n grafo[v_i].append(u_i)\r\n grafo[u_i].append(v_i)\r\n\r\nconjunto = set(i for i in range(n + 1) if len(grafo[i]) == 2)\r\n\r\nres = 0\r\nwhile conjunto:\r\n i = conjunto.pop()\r\n v, u = grafo[i]\r\n while u in conjunto:\r\n conjunto.remove(u)\r\n v_i, u_i = grafo[u]\r\n if v_i in conjunto:\r\n u = v_i\r\n elif u_i in conjunto:\r\n u = u_i\r\n else:\r\n break\r\n if v == u:\r\n res += 1\r\n\r\nprint(res)\r\n",
"from collections import defaultdict\n\nn , m = list(map(int, input().split()))\nadj = defaultdict(list)\n\nfor i in range(m):\n x , y = list(map(int, input().split()))\n adj[x].append(y)\n adj[y].append(x)\nresult = 0\n\nvisited =[False for i in range(n + 1)]\n\nfor i in range(1 , n +1):\n if visited[i]:\n continue\n cycle = True\n lista = [i]\n visited[i] = True\n while lista:\n element = lista.pop()\n if len(adj[element]) != 2:\n cycle = False\n for j in adj[element]:\n if not visited[j]:\n visited[j] = True\n lista.append(j)\n\n result = result + int(cycle)\nprint(result)\n\t\t\t\t\t\t\t\t\t\t \t \t \t \t\t\t \t \t",
"n, m = list(map(int, input().split()))\n\nady = [[] for i in range(n)]\nvis = [False for i in range(n)]\n\nfor _ in range(m):\n u, v = list(map(int, input().split()))\n ady[u-1].append(v-1)\n ady[v-1].append(u-1)\n\npar = [len(ady[i]) == 2 for i in range(n)]\n\n\n\n\ndef dfs(x):\n pila = []\n pila.append(x)\n vis[x] = True\n\n r = par[x]\n\n while len(pila) > 0:\n i = pila.pop(0)\n for j in ady[i]:\n if not vis[j]:\n vis[j] = True\n pila.append(j)\n r = r and par[j]\n\n return r\n\nr = 0\n\nfor i in range(n):\n if not vis[i]:\n res = dfs(i)\n if res:\n r += 1\n \nprint(r)\n\t\t \t\t\t\t \t\t \t \t\t \t\t \t \t\t \t",
"from collections import Counter, defaultdict\r\nclass DisjointSetUnion:\r\n def __init__(self, n):\r\n self.parent = list(range(n))\r\n self.size = [1] * n\r\n self.num_sets = n\r\n\r\n def find(self, a):\r\n acopy = a\r\n while a != self.parent[a]:\r\n a = self.parent[a]\r\n while acopy != a:\r\n self.parent[acopy], acopy = a, self.parent[acopy]\r\n return a\r\n\r\n def union(self, a, b):\r\n a, b = self.find(a), self.find(b)\r\n if a != b:\r\n if self.size[a] < self.size[b]:\r\n a, b = b, a\r\n\r\n self.num_sets -= 1\r\n self.parent[b] = a\r\n self.size[a] += self.size[b]\r\n\r\n def set_size(self, a):\r\n return self.size[self.find(a)]\r\n\r\n def __len__(self):\r\n return self.num_sets\r\n \r\n\r\n\r\nm,n = map(int, input().split())\r\n\r\nc = Counter()\r\ndsu = DisjointSetUnion(m)\r\nfor i in range(n):\r\n u,v = map(int, input().split())\r\n u-=1\r\n v-=1\r\n dsu.union(u,v)\r\n c[u]+=1\r\n c[v]+=1\r\n\r\nroots = defaultdict(list)\r\nfor x in range(m):\r\n root = dsu.find(x)\r\n roots[root].append(x)\r\n\r\nans = 0\r\nfor root, llist in roots.items():\r\n if len(llist) < 3:\r\n continue\r\n is_valid = True\r\n for x in llist:\r\n if c[x] != 2:\r\n is_valid = False\r\n break\r\n if is_valid:\r\n ans+=1\r\nprint(ans)",
"inf = float('inf')\n\ndef graph(n, m):\n x, s, G = [0]*(2*m), [0]*(n+3), [0]*(2*m)\n for i in range(0, 2*m, 2):\n u, v = map(int,input().split())\n s[u+2] += 1; s[v+2] += 1\n x[i]=u; x[i+1] = v\n for i in range(3, n+3):\n s[i] += s[i-1]\n for i in range(2*m):\n j = x[i] + 1\n G[s[j]] = x[i^1]\n s[j] += 1\n return G, s\ndef bfs(s):\n q, k = [s], 0\n di[s] = True\n check = True\n while len(q)^k:\n i = q[k]\n if s0[i+1] - s0[i] != 2:\n check = False\n for v in range(s0[i], s0[i+1]):\n j = G[v]\n if not di[j]:\n di[j] = True\n q.append(j)\n k+=1\n return check\n\n\nn, m = map(int,input().split())\nG, s0 = graph(n, m)\ndi = [False]*(n+1)\nans = 0\nfor i in range(1, n+1):\n if not di[i]:\n ans += bfs(i)\nprint(ans)\n \n",
"n,m=map(int,input().split())\r\nb=[[] for i in range(n+1)]\r\nfor i in range(m):\r\n c,d=map(int,input().split())\r\n b[c].append(d)\r\n b[d].append(c)\r\nse = set(i for i in range(n+1) if len(b[i]) == 2)\r\nresult = 0\r\nwhile se:\r\n\tv = se.pop()\r\n\tR, L = b[v]\r\n\twhile L in se:\r\n\t\tse.remove(L)\r\n\t\tV1, V2 = b[L]\r\n\t\tif V1 in se:\r\n\t\t\tL = V1\r\n\t\telif V2 in se:\r\n\t\t\tL = V2\r\n\t\telse:\r\n\t\t\tbreak\r\n\t\tif L == R:\r\n\t\t\tresult += 1\r\nprint(result)",
"import sys\nfrom collections import defaultdict\n\n\n# LOAD DATA IN LIST WITH 2 POINTS\n# IF THERE IS 3rd POINT IN EDGE TURN BOTH POINTS INVALID\n\n# node[a] = [c, b] + d\n# turn a and d invalid\n# keep check of invalid points in bitmap\n\n\n# 0 - 63 => 0\n# 64 - 127 => 1\n\n\n\ndef set_bit(bitmap, index):\n\tbitmap[index >> 6] |= 1 << (index & 63)\n\n\ndef clear_bit(bitmap, index):\n\tbitmap[index >> 6] &= ~(1 << (index & 63))\n\n\ndef get_bit(bitmap, index):\n\treturn bitmap[index >> 6] & (1 << (index & 63))\n\n\ndef bit_scan_forward(bitmap):\n\treturn bin(bitmap)[::-1].index('1')\n\n\ndef choose_edge(graph, last_node, current_node):\n\tif graph[current_node][0] == last_node:\n\t\treturn graph[current_node][1]\n\telse:\n\t\treturn graph[current_node][0]\n\t\n\n\nin_f = sys.stdin.read(-1).replace(\"\\r\\n\", \"\\r\")\nin_f = in_f.split()\n\nn, m = int(in_f[0]), int(in_f[1])\n\n# valid_nodes = [0 for i in range(n)]\nvalid_nodes = [0 for i in range((n + 63) // 64)]\n\nedges = defaultdict(lambda: [-1, -1])\ncycles = 0\n\nfor edge in range(2, 2*m+2, 2):\n\tp1, p2 = int(in_f[edge]) - 1, int(in_f[edge + 1]) - 1\n\tif edges[p1][0] == -1:\n\t\tedges[p1][0] = p2\n\telif edges[p1][1] == -1:\n\t\tedges[p1][1] = p2\n\t\tset_bit(valid_nodes, p1)\n\telse:\n\t\tclear_bit(valid_nodes, p1)\n\tif edges[p2][0] == -1:\n\t\tedges[p2][0] = p1\n\telif edges[p2][1] == -1:\n\t\tedges[p2][1] = p1\n\t\tset_bit(valid_nodes, p2)\n\telse:\n\t\tclear_bit(valid_nodes, p2)\n\n\ni = 0\nwhile i < n:\n\tif valid_nodes[i >> 6] == 0:\n\t\ti += 64 - (i & 63)\n\t\tcontinue\n\ti += bit_scan_forward(valid_nodes[i >> 6] >> (i & 63))\n\tlast_node = -1\n\tcurrent_node = i\n\twhile True:\n\t\tclear_bit(valid_nodes, current_node)\n\t\tnode = choose_edge(edges, last_node, current_node)\n\t\tlast_node = current_node\n\t\tcurrent_node = node\t\t\n\t\tif current_node == -1 or not get_bit(valid_nodes, current_node):\n\t\t\tif current_node == i:\n\t\t\t\tcycles += 1\n\t\t\tbreak\nprint(cycles)\n",
"def merge_comp(u,v):\r\n if comp[v]==comp[u]:size[comp[u]]+=1;return\r\n if size[comp[v]]>size[comp[u]]:\r\n (u,v) = (v,u)\r\n size[comp[u]]+=size[comp[v]]+1\r\n for i in members[comp[v]]:\r\n comp[i]=comp[u] \r\n members[comp[u]] += (i,)\r\n \r\ndef checkcycle(m):\r\n for a in m:\r\n if len(adj[a])!=2:return False \r\n return True\r\n\r\n\r\nn,m = tuple(map(int,input().split()))\r\nadj = [[] for i in range(n)]\r\nsize=[0]*n\r\ncomp = [i for i in range(n)]\r\nmembers=[[i] for i in range(n)]\r\nfor i in range(m):\r\n a,b=list(map(int,input().split()))\r\n a-=1;b-=1\r\n merge_comp(a,b)\r\n adj[a].append(b)\r\n adj[b].append(a) \r\nconcomp = set()\r\nfor i in comp:\r\n concomp.add(i)\r\nans=0\r\nfor j in concomp:\r\n if size[j]==len(members[j]) and checkcycle(members[j]):\r\n ans+=1\r\nprint(ans)"
] | {"inputs": ["5 4\n1 2\n3 4\n5 4\n3 5", "17 15\n1 8\n1 12\n5 11\n11 9\n9 15\n15 5\n4 13\n3 13\n4 3\n10 16\n7 10\n16 7\n14 3\n14 4\n17 6", "4 4\n1 2\n2 3\n1 3\n1 4", "5 5\n1 2\n2 3\n3 4\n4 1\n3 5", "200000 0", "1 0", "5 10\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n2 4\n3 5\n3 1\n2 5", "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5", "6 9\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n6 2\n2 4\n6 4", "4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4"], "outputs": ["1", "2", "0", "0", "0", "0", "0", "0", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
30db901d2974d16a3492d3335b4eb28f | Collective Mindsets (medium) | Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the *N*<=-<=1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109).
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Sample Input
1
3
99
Sample Output
0
1
49
| [
"n = int(input())\r\nif n & 1:\r\n print(n//2)\r\nelse:\r\n k = 1\r\n while k <= n:\r\n k *= 2\r\n print((n - k//2)//2)\r\n",
"import math \r\na = int(input())\r\nif a%2==1:\r\n print(math.ceil((a-1)/2))\r\nelse:\r\n z = 1\r\n while z*2<=a:\r\n z*=2\r\n print((a-z)//2)",
"from math import log2, floor\nN = int(input())\nif N % 2 == 0:\n N //= 2\n ans = N - 2 ** floor(log2(N))\nelse:\n ans = (N+1) // 2 - 1\nprint(ans)\n",
"from math import log2, floor\r\nN = int(input())\r\nif N % 2 == 0:\r\n N //= 2\r\n ans = N - 2 ** floor(log2(N))\r\nelse:\r\n ans = (N+1) // 2 - 1\r\nprint(ans)",
"n = int(input())\r\nif (n % 2 == 1):\r\n print(n // 2)\r\n exit(0)\r\ni = 1\r\nwhile (i <= n):\r\n i *= 2\r\ni //= 2\r\nn -= i\r\nprint(n // 2)"
] | {"inputs": ["1", "3", "2", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "99", "100", "9999", "21736", "873467", "4124980", "536870910", "536870912", "876543210", "987654321", "1000000000"], "outputs": ["0", "1", "0", "0", "2", "1", "3", "0", "4", "1", "5", "2", "6", "3", "7", "0", "8", "1", "9", "2", "49", "18", "4999", "2676", "436733", "1013914", "134217727", "0", "169836149", "493827160", "231564544"]} | UNKNOWN | PYTHON3 | CODEFORCES | 5 | |
30de59f08fe3576a3c3ef0138a341c0f | Gabriel and Caterpillar | The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height *h*1 cm from the ground. On the height *h*2 cm (*h*2<=><=*h*1) on the same tree hung an apple and the caterpillar was crawling to the apple.
Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by *a* cm per hour by day and slips down by *b* cm per hour by night.
In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
The first line contains two integers *h*1,<=*h*2 (1<=≤<=*h*1<=<<=*h*2<=≤<=105) — the heights of the position of the caterpillar and the apple in centimeters.
The second line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.
Print the only integer *k* — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.
If the caterpillar can't get the apple print the only integer <=-<=1.
Sample Input
10 30
2 1
10 13
1 1
10 19
1 2
1 50
5 4
Sample Output
1
0
-1
1
| [
"def solve(h1, h2, a, b):\r\n d = max(h2 - a * 8 - h1, 0)\r\n if d and a <= b:\r\n return -1\r\n x = max(1, (a - b) * 12)\r\n return (d + x - 1) // x\r\n\r\n\r\nh1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\nprint(solve(h1, h2, a, b))\r\n",
"h1, h2 = map(int, input().split())\na, b = map(int, input().split())\n\nh = h1\nans = 0\nwhile True:\n h += 8 * a\n if h2 <= h:\n break\n h -= 12 * b\n h += 4 * a\n if h <= h1:\n ans = -1\n break\n ans += 1\n\nprint(ans)\n",
"h1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\n\r\nh1 -= 4*a\r\nh = h1\r\nfor i in range(1, 24*10**5+50):\r\n q, r = divmod(i-1, 12)\r\n if q%2 == 0:\r\n h += a\r\n else:\r\n h -= b\r\n if h >= h2:\r\n print(q//2)\r\n exit()\r\nprint(-1)\r\n",
"import math\na,b=list(map(int,input().split()))\nc,d=list(map(int,input().split()))\nif a+8*c>=b:\n print('0')\nelif c>d:\n print(math.floor(((b-a-8*c)+(12*(c-d))-1)/(12*(c-d))))\n\nelse:\n print('-1')\n\t\t\t\t\t \t \t\t \t\t\t\t\t\t\t \t\t",
"a,b = map(int,input().split())\nc,d = map(int,input().split())\n\nf = 0\na = a-(c*4)\n\n\nwhile True:\n a += c*12\n if a >= b:\n break\n elif d>=c:\n f = -1\n break\n else:\n a -= d*12\n f += 1\n \nprint(f)",
"h, g = [int(x) for x in input().split(' ')]\r\na, b = [int(x) for x in input().split(' ')]\r\nans = 0\r\nh += 8 * a\r\nuph = h\r\nwhile g > h:\r\n ans += 1\r\n h += 12 * (a - b)\r\n if h <= uph:\r\n ans = -1\r\n break\r\n uph = h\r\nprint(ans)",
"import sys\r\nreadline=sys.stdin.readline\r\n\r\nh1,h2=map(int,readline().split())\r\na,b=map(int,readline().split())\r\nif h1+8*a+1>h2:\r\n ans=0\r\nelif a<=b:\r\n ans=-1\r\nelse:\r\n ans=(h2-h1-8*a-1)//(a-b)//12+1\r\nprint(ans)",
"h1,h2 = map(int,input().split())\r\na,b = map(int,input().split())\r\nif(b>=a):\r\n if(h1+8*a>=h2):print(0)\r\n else:print(-1)\r\nelse:\r\n dist=12*(a-b)\r\n t=dist\r\n ans=1\r\n h1+=8*a\r\n if(h1>=h2):print(0)\r\n else:\r\n while(h1+t<h2):\r\n ans+=1\r\n t+=dist\r\n print(ans)\r\n",
"h1, h2 = map(int, input().split())\na, b = map(int, input().split())\n\nh1 += 8 * a\nif (h1 >= h2):\n print(0)\nelse:\n if a <= b:\n print(-1)\n else:\n h1 -= 12 * b\n i = 1\n while(h1 + 12 * a < h2):\n i += 1\n h1 += 12 * (a - b)\n print(i)\n",
"import math\r\n\r\nn, h = map(int, input().split())\r\nh -= n\r\nn = 0\r\na, b = map(int, input().split())\r\nif(a <= b):\r\n if(h > a*8): print(-1)\r\n else: print(0)\r\nelse:\r\n if(h <= a*8): print(0)\r\n else:\r\n ans = 0\r\n h -= a*8\r\n while(n < h):\r\n n -= 12*b\r\n n += 12*a\r\n ans += 1\r\n print(ans)\r\n",
"import sys\r\n\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\n\r\n\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\n\r\n\r\nMOD = 1000000007\r\n\r\n# for _ in range(int(input())):\r\nh1, h2 = get_ints()\r\na, b = get_ints()\r\ni = 0\r\ncnt = 0\r\nans = h1\r\nstart = 0\r\nend = 0\r\nif h1 + 8 * a < h2 and a <= b:\r\n print(-1)\r\nelse:\r\n while start <= h2:\r\n if i == 0:\r\n start = ans + 8 * a\r\n end = 12 * b\r\n ans = start - end\r\n # print(f'start {start}, end {end}, ans {ans}')\r\n if start >= h2:\r\n break\r\n else:\r\n cnt += 1\r\n else:\r\n start = ans + 12 * a\r\n end = 12 * b\r\n # print(f'start {start}, end {end}, ans {ans}')\r\n ans = start - end\r\n if start >= h2:\r\n break\r\n else:\r\n cnt += 1\r\n i += 1\r\n print(cnt)\r\n",
"H1, H2 = map(int, input().split())\r\nA, B = map(int, input().split())\r\n\r\nnum = H2-H1-8*A\r\nden = 12*(A-B)\r\nif den > 0:\r\n\tans = max(0, (num+den-1) // den)\r\nelse:\r\n\tans = 0 if num <= 0 else -1\r\nprint(ans)\r\n",
"h1, h2 = map(int, input().split())\na, b = map(int, input().split())\n# 0 day starts at 2pm\nday = 0\nh1 += 8 * a\nif h1 >= h2:\n print(day)\n exit()\nh1 -= 12 * b;\n# 1 day\nif h1 + 12 * a < h2 and a <= b:\n print(-1)\nelse:\n while True:\n h1 += 12 * a\n day += 1\n if h1 >= h2:\n print(day)\n exit()\n h1 -= 12 * b\n",
"caterpillar, apple = map(int, input().split())\r\nup, down = map(int, input().split())\r\nfirst_day = caterpillar + up * 8\r\ndays = 0\r\nif first_day >= apple: print(days)\r\nelse:\r\n if up <= down: print(-1)\r\n else:\r\n differ = (up - down) * 12\r\n if (apple - first_day) // differ < (apple - first_day) / differ: print((apple - first_day) // differ + 1)\r\n else: print((apple - first_day) // differ )\r\n\r\n",
"import sys\r\nh1,h2 = map(int ,input().split())\r\na,b = map(int ,input().split())\r\n\r\n\r\nh1 += 8*a;\r\nif h1 >= h2:\r\n print(0)\r\n sys.exit(0)\r\n\r\nif b >= a:\r\n print(-1)\r\n sys.exit(0)\r\n \r\nans = 1\r\nwhile True:\r\n h1 -= 12 * b\r\n h1 += 12 * a\r\n if h1>=h2:\r\n break;\r\n ans+=1;\r\nprint(ans)\r\n",
"h1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\nx = h1 + 8 * a\r\nif x >= h2:\r\n print(0)\r\nelse:\r\n x -= b * 2\r\n flg = 0\r\n for i in range(1, 100000):\r\n x -= b * 10\r\n x += a * 12\r\n if x >= h2:\r\n print(i)\r\n flg = 1\r\n break\r\n x -= b * 2\r\n if flg == 0:\r\n print(-1)",
"arr = list(map(int, input().split()))\r\nh1=arr[0]\r\nh2=arr[1]\r\narr = list(map(int, input().split()))\r\na=arr[0]\r\nb=arr[1]\r\nk=0\r\nif(h1+8*a>=h2):\r\n print(k)\r\nelse:\r\n h1=h1+8*a-12*b\r\n k=1\r\n if(h1+12*a>=h2):\r\n print(k)\r\n elif(b>=a):\r\n print(-1)\r\n else:\r\n k=2\r\n h1=h1+(12*a)-(12*b)\r\n while(h2-h1>12*a):\r\n h1+=12*(a-b)\r\n k+=1\r\n print(k)\r\n ",
"h1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\nif (h1+8*a)>=h2:\r\n print(0)\r\nelif a>b:\r\n need = h2-h1 - 8*a\r\n vv = 12*(a-b)\r\n print(1+(need-1)//vv)\r\nelse:\r\n print(-1)\r\n",
"h1, h2 = map(int, input().split(' '))\na, b = map(int, input().split(' '))\n\nif h1+8*a >= h2:\n print(0)\nelif a <= b:\n print(-1)\nelse:\n cnt = 0\n h1 += 8*a\n while h1 < h2:\n h1 += 12*(a-b)\n cnt += 1\n print(cnt)\n",
"h1,h2=map(int,input().split())\r\na,b=map(int,input().split())\r\nif h2-a*8-h1>0 and a<=b:\r\n print(-1)\r\n exit()\r\nx=max(1,(a-b)*12)\r\nprint((max(0,h2-a*8-h1)+x-1)//x)",
"from math import *\r\n\r\nh1, h2 = [int(i) for i in input().split()]\r\na, b = [int(i) for i in input().split()]\r\na *= 12\r\nb *= 12\r\nif a <= b and h2 - h1 > (a // 12 * 8):\r\n print(-1)\r\n exit()\r\nh1 += (a // 12 * 8)\r\nif h1 >= h2:\r\n print(0)\r\n exit()\r\nday = int(ceil((h2 - h1) / (a - b)))\r\nprint(day)",
"h1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\nh1 += 8*a\r\nans = 0\r\nif h1>=h2: ans = 0\r\nelif a<=b: ans = -1\r\nelse:\r\n while h1<h2:\r\n h1-=12*b\r\n h1+=12*a\r\n ans+=1\r\nprint(ans)",
"h1,h2=map(int,input().split())\r\na,b=map(int,input().split())\r\n\r\nif a<=b and (h2-h1>8*a):\r\n print(-1)\r\nelse:\r\n if h2-h1 <=8*a:\r\n print(0)\r\n else:\r\n ans = (h2-h1-8*a)//(12*(a-b))\r\n if (h2-h1-8*a)%(12*(a-b))==0:\r\n print(ans)\r\n else:\r\n print(ans+1)",
"# LUOGU_RID: 101607479\nx, y, a, b = map(int, open(0).read().split())\r\nt = y - x - 8 * a - 1\r\nprint(0 if t < 0 else t // (12 * (a - b)) + 1 if a > b else -1)",
"import math\r\n\r\n\r\nh1, h2 = map(int, input().split())\r\nday, night = map(int, input().split())\r\n\r\nif h2 - h1 <= day * 8:\r\n print(0)\r\nelif (h2 - h1) - day * 8 + night * 12 - day * 12 <= 0:\r\n print(1)\r\nelif day - night <= 0:\r\n print(-1)\r\nelse:\r\n\r\n # (h2 - h1) <= k * (day - night) * 12 + day * 12 + day * 8 - night * 12\r\n\r\n print(\r\n int(math.ceil(\r\n ((h2 - h1) - day * 20 + night * 12) / ((day - night) * 12)\r\n )) + 1\r\n )\r\n",
"from math import ceil\r\nh1,h2 = map(int, input().split())\r\na,b = map(int, input().split())\r\nh = h2 - h1 - a*8\r\nif(h<=0):\r\n print(0)\r\nelif(a<=b):\r\n print(-1)\r\nelse:\r\n print(ceil(h/(12*(a-b))))",
"h, g = map(int, input().split())\r\na, b = map(int, input().split())\r\nans = 0\r\nh += a << 3\r\nuph = h\r\nwhile g > h:\r\n ans += 1\r\n h += 12 * (a - b)\r\n if h <= uph:\r\n ans = -1\r\n break\r\n uph = h\r\nprint(ans)",
"I = lambda: [int(i) for i in input().split()]\r\nh1, h2 = I()\r\na, b = I()\r\n\r\nif h1 + 8 * a >= h2:\r\n print(0)\r\nelse:\r\n if b >= a:\r\n print(-1)\r\n else:\r\n h1 += (8 * a - 12 * b)\r\n i = 0\r\n while True:\r\n if i % 2 == 0:\r\n h1 += 12 * a\r\n else:\r\n h1 -= 12 * b\r\n if h1 >= h2:\r\n print(i//2 + 1)\r\n break\r\n i += 1\r\n",
"h1,h2 = map(int, input().split(\" \"))\na,b = map(int, input().split(\" \"))\n\ndef caterpillar(a,b,h1,h2):\n if h1 + 8*a >= h2:\n print(0)\n else:\n h = h1 + 8*a\n if 12*(a-b) <= 0:\n print(-1)\n else:\n c = h2-h\n d = 12*(a-b)\n print( (c // d) + (c%d > 0)*1)\n\ncaterpillar(a,b,h1,h2)\n",
"\r\nh1 , h2 = map(int , input().split())\r\ninc , dec = map(int , input().split())\r\ntemp = h1 \r\nj = 1\r\nif inc <= dec and h1 + inc * 8 < h2:\r\n print(-1)\r\n exit(0)\r\nh1 += inc * 8\r\nif h1 >= h2:\r\n print(0)\r\n exit(0)\r\nh1 -= dec * 12\r\nwhile h1 < h2:\r\n h1 += inc * 12\r\n if h1 >= h2:\r\n break\r\n h1 -= dec * 12\r\n j+=1\r\nprint(j) ",
"h1, h2 = map(int, input().split(' '))\na, b = map(int, input().split(' '))\n\nif h1+8*a >= h2:\n print(0)\nelif a <= b:\n print(-1)\nelse:\n dis = h2-h1-8*a\n inc = (a-b)*12\n print((dis+inc-1)//inc)\n",
"def solve():\n h1, h2 = map(int, input().split())\n a, b = map(int, input().split())\n\n h3 = h1 + a * 8\n\n if h3 >= h2:\n print(0)\n return\n\n if b >= a:\n print(-1)\n return\n\n h4 = h2 - h3\n\n c = (a - b) * 12\n\n ans = int((h4 + (c - 1)) / c)\n\n print(ans)\n\n\nif __name__ == '__main__':\n solve()\n",
"h1,h2=map(int,input().split())\na,b= map(int,input().split())\nif (h1+(8*a)) >= h2:\n print(0)\nelif a>b:\n cal = h2 - h1 - 8 * a;\n cal2 = 12 * (a - b);\n ans = (cal + cal2 - 1) // cal2;\n print(ans)\nelse:\n print(-1)\n",
"x=input().split()\r\nh1=int(x[0])\r\nh2=int(x[1])\r\nx=input().split()\r\na=int(x[0])\r\nb=int(x[1])\r\n\r\nh1=h1+a*8 #first day\r\nif h1>=h2:\r\n print(0)\r\nelse:\r\n if a>b:\r\n day=1\r\n while day>0:\r\n h1=h1-12*b #night 1\r\n h1=h1+12*a\r\n if h1>=h2:\r\n print(day) \r\n break\r\n day=day+1\r\n else:\r\n print(-1)",
"h1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\nd, v = h2 - h1 - 8 * a, 12 * (a - b)\r\nif d <= 0:\r\n print(0)\r\nelif b >= a:\r\n print(-1)\r\nelse:\r\n print((d + v - 1) // v)",
"arr = list(map(int, input().split(' ')))\r\nh1 = arr[0]\r\nh2 = arr[1]\r\narr1 = list(map(int, input().split(' ')))\r\na = arr1[0]\r\nb = arr1[1]\r\n\r\nh1 += 8 * a\r\nans = 0\r\n\r\nif h1 >= h2:\r\n print(ans)\r\nelse:\r\n h1 -= 12 * b\r\n\r\n while h1 < h2:\r\n ans += 1\r\n h1 += 12 * a\r\n if h1 >= h2:\r\n print(ans)\r\n break\r\n if b >= a:\r\n print(-1)\r\n break\r\n h1 -= 12 * b\r\n\r\n \r\n",
"import sys\r\n\r\nh1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\nday = 12\r\nnight = 12\r\nfirst_part = 8\r\nif a * 8 + h1 >= h2:\r\n print(0)\r\n sys.exit()\r\nif a <= b:\r\n print(-1)\r\n sys.exit()\r\n\r\ncur = h1 + a * 8\r\nd = h2 - cur\r\ndays = d // (12 * a - 12 * b)\r\nost = d % (12 * a - 12 * b)\r\nif ost == 0:\r\n print(days)\r\nelse:\r\n print(days + 1)\r\n",
"f = lambda: map(int, input().split())\r\nx, y = f()\r\na, b = f()\r\nh = y - x - 8 * a - 1\r\nd = 12 * (a - b)\r\nprint(0 if h < 0 else h // d + 1 if a > b else -1)",
"from math import ceil\n\nh1, h2 = map(int, input().split())\n\na, b = map(int, input().split())\n\nx = h2 - h1\np = 0\n\nfor i in range(8):\n p += a\n if p >= x:\n print(0)\n exit()\n\nfor i in range(100000):\n for j in range(12):\n if i&1:\n p += a\n else:\n p -= b\n if p >= x:\n print(ceil(i/2))\n exit()\n\nprint(-1)\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nh1, h2 = map(int, input().split())\r\na, b = map(int, input().split())\r\nh1 -= 4 * a\r\nans = -1\r\nfor i in range(114514):\r\n h1 += 12 * a\r\n if h1 >= h2:\r\n ans = i\r\n break\r\n h1 -= 12 * b\r\nprint(ans)"
] | {"inputs": ["10 30\n2 1", "10 13\n1 1", "10 19\n1 2", "1 50\n5 4", "1 1000\n2 1", "999 1000\n1 1", "999 1000\n1 1000", "1 1000\n999 1", "1 1000\n100 99", "500 509\n1 1", "500 555\n6 1", "1 100000\n2 1", "99990 100000\n1 1", "90000 100000\n2 1", "10 100000\n1 100000", "1 41\n5 6", "1 100000\n1 100000", "1 9\n1 1", "8 16\n1 12", "14 30\n2 1", "7245 77828\n6224 92468", "43951 66098\n1604 35654", "1 2\n4 3", "90493 94279\n468 49", "1 50\n3 1", "26300 88310\n7130 351", "1 17\n2 2", "10718 75025\n7083 6958", "1 10\n1 100000", "1 190\n10 1", "24951 85591\n3090 8945", "1 25\n3 2", "27043 88418\n7273 7", "35413 75637\n4087 30166", "1 18\n2 3", "1 16\n2 2", "1 18\n2 1", "1 10\n2 2", "1 30\n2 1", "1 100000\n10000 100000", "4444 33425\n2758 44", "1 100000\n10 99910", "12 100\n6 11", "100 100000\n10 11", "28473 80380\n2568 95212", "10 105\n10 1", "4642 39297\n3760 451", "1 90\n10 1", "2 100\n1 100000", "1 100000\n1000 100000", "1 45\n1 100000", "12 1000\n100 1", "64635 76564\n100 34238", "10 90\n10 12", "49238 81395\n3512 251", "6497 62133\n309 50077", "1 100\n1 100000", "1 10000\n1 10000", "55674 93249\n846 1", "10 90\n9 10", "23110 69794\n171 808", "1 100000\n1 10000", "1 9\n1 2", "58750 81357\n2 98022", "82125 89348\n894 91369", "25401 53663\n957 30449", "2 12\n1 2", "1 10000\n1 100000", "1 100000\n1 99999", "1 149\n8 2", "3 100\n1 1", "1 18\n2 2", "1 77\n9 1", "7330 94486\n968 141", "89778 98176\n863 61", "1 70\n6 5"], "outputs": ["1", "0", "-1", "1", "82", "0", "0", "0", "17", "-1", "1", "8332", "-1", "832", "-1", "0", "-1", "0", "0", "0", "-1", "-1", "0", "1", "2", "1", "0", "6", "-1", "2", "-1", "0", "1", "-1", "-1", "0", "1", "0", "2", "-1", "1", "-1", "-1", "-1", "-1", "1", "1", "1", "-1", "-1", "-1", "1", "-1", "0", "1", "-1", "-1", "-1", "4", "-1", "-1", "-1", "0", "-1", "-1", "-1", "-1", "-1", "-1", "2", "-1", "-1", "1", "9", "1", "2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 40 | |
30de7ee740a6e995d73e72689e102fa6 | Four Melodies | Author note: I think some of you might remember the problem "Two Melodies" from Eductational Codeforces Round 22. Now it's time to make it a bit more difficult!
Alice is a composer, and recently she had recorded two tracks that became very popular. Now she has got a lot of fans who are waiting for new tracks.
This time Alice wants to form four melodies for her tracks.
Alice has a sheet with *n* notes written on it. She wants to take four such non-empty non-intersecting subsequences that all of them form a melody and sum of their lengths is maximal.
Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
Subsequence forms a melody when each two adjacent notes either differ by 1 or are congruent modulo 7.
You should write a program which will calculate maximum sum of lengths of such four non-empty non-intersecting subsequences that all of them form a melody.
The first line contains one integer number *n* (4<=≤<=*n*<=≤<=3000).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — notes written on a sheet.
Print maximum sum of lengths of such four non-empty non-intersecting subsequences that all of them form a melody.
Sample Input
5
1 3 5 7 9
5
1 3 5 7 2
Sample Output
4
5
| [
"import heapq\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef add_edge(u, v, cost, f):\r\n G[u].append([v, cost, f, len(R[v])])\r\n R[v].append([u, -cost, 0, len(G[u]) - 1])\r\n\r\ndef dijkstra(s):\r\n inf = pow(10, 9) + 1\r\n dist = [inf] * l\r\n dist[s] = 0\r\n parent = [-1] * l\r\n p = []\r\n heapq.heappush(p, (0, s))\r\n while p:\r\n d, i = heapq.heappop(p)\r\n if dist[i] < d:\r\n continue\r\n di = dist[i] + h[i]\r\n for j, c, f, _ in G[i]:\r\n if not f:\r\n continue\r\n nd = di + c - h[j]\r\n if dist[j] > nd:\r\n parent[j] = i\r\n dist[j] = nd\r\n heapq.heappush(p, (nd, j))\r\n for j, c, f, _ in R[i]:\r\n if not f:\r\n continue\r\n nd = di + c - h[j]\r\n if dist[j] > nd:\r\n parent[j] = i\r\n dist[j] = nd\r\n heapq.heappush(p, (nd, j))\r\n return dist, parent\r\n\r\ndef min_cost_flow(s, t, f):\r\n ans = 0\r\n while f:\r\n dist, parent = dijkstra(s)\r\n for i in range(l):\r\n h[i] += dist[i]\r\n if not parent[t] ^ -1:\r\n return -1\r\n ma = f\r\n u = t\r\n x, y = [], []\r\n while u ^ s:\r\n v = parent[u]\r\n ok = 0\r\n Gv = G[v]\r\n for i in range(len(Gv)):\r\n if not Gv[i][0] ^ u:\r\n ma = min(ma, Gv[i][2])\r\n ok = 1\r\n x.append((v, i))\r\n break\r\n if not ok:\r\n Rv = R[v]\r\n for i in range(len(Rv)):\r\n if not Rv[i][0] ^ u:\r\n ma = min(ma, Rv[i][2])\r\n ok = 1\r\n y.append((v, i))\r\n break\r\n u = v\r\n f -= ma\r\n for i, j in x:\r\n Gi = G[i]\r\n Gi[j][2] -= ma\r\n R[Gi[j][0]][Gi[j][3]][2] += ma\r\n for i, j in y:\r\n Ri = R[i]\r\n Ri[j][2] -= ma\r\n G[Ri[j][0]][Ri[j][3]][2] += ma\r\n ans += h[t] * ma\r\n return ans\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nl = 3 * n + 2\r\nG = [[] for _ in range(l)]\r\nR = [[] for _ in range(l)]\r\nh = [0] * l\r\ns, t = l - 2, l - 1\r\nm = pow(10, 5) + 5\r\nx, y = [-1] * m, [-1] * 7\r\ninf = pow(10, 9) + 1\r\nfor i in range(n):\r\n add_edge(s, i, 0, 1)\r\n add_edge(i, i + n, -1, 1)\r\n add_edge(i, i + 2 * n, 0, inf)\r\n add_edge(i + n, i + 2 * n, 0, 1)\r\n add_edge(i + 2 * n, t, 0, 1)\r\n ai = a[i]\r\n for j in [x[ai - 1], x[ai + 1], y[ai % 7]]:\r\n if j == -1:\r\n continue\r\n add_edge(j + 2 * n, i, 0, inf)\r\n x[ai], y[ai % 7] = i, i\r\nans = -min_cost_flow(s, t, 4)\r\nprint(ans)"
] | {"inputs": ["5\n1 3 5 7 9", "5\n1 3 5 7 2", "4\n1 3 5 7", "4\n1 1 1 1", "4\n1 1 2 1", "4\n3 2 3 1", "4\n3 4 2 2", "4\n5 3 4 3", "4\n5 3 1 4", "4\n3 5 2 4", "4\n8 6 8 1", "4\n6 3 6 4", "5\n8 1 4 8 2", "6\n2 7 8 6 5 7", "7\n9 12 12 1 8 12 12", "8\n16 1 8 13 14 5 4 4", "9\n5 4 10 10 13 17 15 15 12", "10\n19 18 20 1 7 1 3 14 1 11", "11\n6 13 20 20 3 12 8 21 3 19 18", "12\n21 20 4 4 4 15 13 12 17 15 11 13", "13\n4 17 14 24 5 17 22 25 20 3 19 12 25", "14\n8 14 20 7 26 22 7 26 2 16 19 20 5 6", "15\n3 16 14 2 24 6 11 7 9 23 13 10 7 27 27", "16\n19 9 4 4 9 21 10 18 27 9 5 3 6 12 21 18", "17\n16 26 6 8 6 25 4 31 25 23 30 21 5 34 19 8 13", "18\n17 31 24 19 7 36 23 16 28 1 22 3 20 3 12 5 10 25", "19\n8 18 34 1 25 23 22 29 12 36 10 23 21 22 8 35 1 31 29", "20\n26 5 4 29 39 3 5 16 36 18 36 11 16 8 36 4 15 37 25 13"], "outputs": ["4", "5", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "5", "6", "7", "8", "9", "9", "11", "12", "11", "12", "14", "13", "14", "14", "16", "18"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
30f04343d73228a109494c7b3fd6aa52 | Maximum Increase | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print the maximum length of an increasing subarray of the given array.
Sample Input
5
1 7 2 11 15
6
100 100 100 100 100 100
3
1 2 3
Sample Output
3
1
3
| [
"n = int (input())\r\ncurrent = 1\r\nmax = 1\r\n\r\nx = list(map(int,input().split()))\r\nfor i in range(n-1): # 0 1 2 3 4 \r\n if x[i+1] > x[i]: # 1 7 2 11 15\r\n current = current +1\r\n else:\r\n current=1\r\n\r\n if max<current:max=current\r\n\r\n\r\nprint (max)",
"from sys import stdin\r\n\r\nlen_l = int(stdin.readline()[:-1])\r\n\r\nl = list(map(int, list(input().split(\" \"))))\r\n\r\nprev = 0\r\n\r\nbest = 0\r\nres = 0\r\n\r\nfor elem in l:\r\n if prev < elem:\r\n res += 1\r\n prev = elem\r\n else:\r\n best = max(best, res)\r\n prev = elem\r\n res = 1\r\n\r\nprint(max(best, res))",
"n = int(input())\na = list(map(int, input().split()))\nans = []\ncnt = 1\nfor i in range(n - 1):\n if a[i + 1] > a[i]:\n cnt += 1\n else:\n ans.append(cnt)\n cnt = 1\nans.append(cnt)\nprint(max(ans))\n",
"n = int(input())\nnumArray = list(map(int, input().split()))\n\nmaxLenght = 1\ncurrentLenght = 1\n\npreviousNum = numArray[0]\n\nfor i in range(1, n):\n \n currentNum = numArray[i]\n \n if currentNum > previousNum:\n currentLenght += 1\n \n else:\n currentLenght = 1\n \n maxLenght = max(maxLenght, currentLenght)\n \n previousNum = currentNum\n \nprint(maxLenght)\n\n \t \t \t\t \t \t\t\t\t \t \t\t\t \t\t",
"def maxSub(n, arr, dp):\r\n dp [0] = 1\r\n for i in range (1, n):\r\n if arr[i]>arr[i-1]:\r\n dp[i] = dp[i-1]+1\r\n else :\r\n dp[i] = 1\r\n #print(dp)\r\n return max(dp)\r\n \r\ndef main():\r\n n = int(input())\r\n arr = list(map(int, input().split(' ')))\r\n dp = [0] * (n+1)\r\n \r\n print(maxSub(n, arr, dp))\r\n \r\n\r\nif __name__ == \"__main__\":\r\n main()",
"n = int(input())\r\narray = [int(x) for x in input().split()]\r\ndp = [1]*(n+1)\r\ndp[0] = 0\r\nfor i in range(0,n-1):\r\n if array[i+1] > array[i]:\r\n dp[i+2] = dp[i+1] +1\r\nprint(max(dp))\r\n ",
"def main():\r\n solve()\r\n\r\ndef solve():\r\n N = int(input())\r\n numbers = list(map(int,input().split()))\r\n maxx = tmp = 0\r\n for i in range(N - 1):\r\n if numbers[i] < numbers[i + 1]:\r\n tmp += 1\r\n if tmp > maxx: maxx = tmp\r\n elif numbers[i] >= numbers[i + 1]:\r\n tmp = 0\r\n print(maxx + 1)\r\n\r\nmain()",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=1\r\nout=1\r\nfor i in range(n-1):\r\n if l[i+1]>l[i]:\r\n m+=1\r\n else:\r\n if m>out:\r\n m,out=out,m\r\n m=1\r\nif m>out:\r\n m,out=out,m\r\nprint(out)",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\ncurrMax = 1\r\nans = 1\r\nfor i in range(1,n):\r\n if(a[i] > a[i-1]): currMax += 1\r\n else: currMax = 1\r\n ans = max(ans, currMax)\r\nprint(ans)",
"n = int(input())\na = list(map(int, input().split())) + [0]\nans = s = 1\nfor i in range(n):\n if a[i + 1] > a[i]:\n s += 1\n else:\n ans = max(ans, s)\n s = 1\nprint(ans)\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nnums=[]\r\nc=1\r\nfor i in range(0,n):\r\n for j in range(i+1, n):\r\n if a[i]<a[j]:\r\n c+=1\r\n break\r\n else:\r\n nums.append(c)\r\n c=1\r\n break\r\nnums.append(c)\r\nprint(max(nums))\r\n",
"a = int(input())\r\nb = list(map(int, input().split()))\r\nc = 1\r\nmx =1\r\nd =[]\r\nfor i in range(1,a):\r\n if b[i-1]<b[i]:\r\n c+=1\r\n \r\n else:\r\n c= 1\r\n if c>mx:\r\n mx = c \r\nprint(mx)",
"from sys import stdin, stdout\r\n\r\nN = int(stdin.readline())\r\nA = list(map(int, stdin.readline().strip().split()))\r\n\r\nLENGTHS = []\r\n\r\nLEN = 1\r\n\r\nfor j in range(1, len(A)):\r\n if A[j]>A[j-1]:\r\n LEN+=1 \r\n else:\r\n LENGTHS.append(LEN)\r\n LEN = 1 \r\nLENGTHS.append(LEN)\r\n\r\nstdout.write(f\"{max(LENGTHS)}\\n\")",
"n = int(input())\r\na = list(map(int,input().split()))\r\nx = 1\r\ny = 1\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n x+=1\r\n else:\r\n x = 1\r\n y = max(x,y)\r\nprint(y)\r\n",
"input();v=s=r=0\nfor x in map(int,input().split()):s=s+1 if x>v else 1;v=x;r=max(r,s)\nprint(r)\n \t\t \t \t\t\t\t \t\t\t\t \t \t\t \t",
"n = int(input())\r\n\r\nintegers = list(map(int, input().split()))\r\n\r\nanswer = 1\r\nlength = 1\r\n\r\nfor i in range(1, n):\r\n if integers[i - 1] >= integers[i]:\r\n length = 1\r\n else:\r\n length += 1\r\n answer = max(answer, length)\r\n\r\nprint(answer)",
"n = int(input())\r\nnums = list(map(int,input().split()))\r\nl = 0 \r\nans = 0\r\nfor i, n in enumerate(nums):\r\n if i==0 or nums[i-1]<n:\r\n ans = max(i-l+1,ans)\r\n else:\r\n l = i\r\n \r\nprint(ans)",
"n = int(input())\r\nl = 0\r\nr = 0\r\nm = 1\r\ns = list(map(int, input().split()))\r\nfor i in range(1, n):\r\n if s[i]>s[i-1]:\r\n r = i\r\n m = max(m, r-l+1)\r\n else:\r\n l = i\r\nprint(m)\r\n",
"n = int(input())\na = [int(x) for x in input().split()]\nans = 1\ncur = 1\nfor i in range(1,n):\n if a[i] > a[i-1]:\n cur += 1\n ans = max(cur,ans)\n else:\n cur = 1\n\nprint(ans)\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nmax = 0\r\np =0\r\nprev = -1\r\nfor i in l:\r\n if(prev<i):\r\n prev = i\r\n p += 1\r\n else:\r\n if(p>max):\r\n max = p\r\n p = 1\r\n prev = i\r\nif(p>max):\r\n max = p\r\nprint(max)\r\n",
"n = int(input())\r\n\r\nnums = list(map(int, input().split()))\r\n\r\ncount = answer = 1\r\nfor i in range(1, n):\r\n if nums[i] > nums[i - 1]:\r\n count += 1\r\n else:\r\n count = 1\r\n answer = max(count, answer)\r\nprint(answer)",
"\r\n\"\"\"main logic is, in array found it - is it next value greater to prev value? if yes then count+=1\"\"\"\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ncount = 1\r\nmaxi = 1\r\nfor i in range(1, n):\r\n if(a[i] > a[i-1]):\r\n count+=1\r\n else:\r\n if (count > maxi):\r\n maxi = count\r\n\r\n count = 1\r\n\r\n if (count > maxi):\r\n maxi = count\r\n\r\nprint(maxi) \r\n\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\ncount = 1\r\nmaxcount = 1\r\ni = 1\r\nwhile i < n:\r\n if arr[i] > arr[i-1]:\r\n count += 1\r\n else:\r\n maxcount = max(maxcount,count)\r\n count = 1\r\n i += 1\r\nmaxcount = max(maxcount,count)\r\nprint(maxcount)\r\n ",
"n=int(input())\r\nl = list(map(int,input().split(\" \")))\r\ncnt=1\r\nmaxs=1\r\nfor i in range(0,n-1):\r\n if l[i] <l[i+1]:\r\n cnt=cnt+1\r\n if cnt>maxs:\r\n maxs=cnt\r\n else:\r\n if cnt>maxs:\r\n maxs=cnt\r\n cnt=1\r\n\r\nprint(maxs)\r\n",
"a=int(input())\r\nar=list(map(int,input().split()))\r\nans=[]\r\ncount=1\r\nfor i in range(len(ar)-1):\r\n if(ar[i]<ar[i+1]):\r\n count=count+1\r\n else:\r\n ans.append(count)\r\n count=1\r\nans.append(count)\r\nprint(max(ans))",
"n = int(input())\n\nl = list(map(int, input().split()))\n\nmaxx, length = 1, 1\n\nfor i in range(1, n):\n\tif l[i] > l[i-1]:\n\t\tlength += 1\n\telse:\n\t\tif maxx < length:\n\t\t\tmaxx = length\n\t\tlength = 1\n\n\nif maxx<length:\n\tmaxx = length\n\nprint(maxx)\n \t \t\t\t \t \t\t \t\t\t\t \t \t\t",
"a=int(input())-1\r\nb=input()\r\nb=b.split()\r\nwhile a>=0:\r\n b[a]=int(b[a])\r\n a-=1\r\nx=1\r\ny=0\r\nl=[]\r\nwhile y<len(b):\r\n while y<len(b)-1 and b[y]<b[y+1]:\r\n x=x+1\r\n y=y+1\r\n l.append(x)\r\n y=y+1\r\n x=1\r\n\r\nprint(max(l))",
"n = int(input())\na = input().split()\nfor i in range(n):\n a[i]=int(a[i])\ncount = 1\nmaxi = 1 \nfor i in range(1,n,1):\n if a[i]>a[i-1]:\n count+=1\n else:\n if(count>maxi):\n maxi = count\n count = 1 \nif count>maxi :\n maxi= count\n\nprint (maxi)\n \t\t \t \t\t\t\t\t \t\t \t \t \t \t",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\nmx = 1\r\ncur = 1\r\n\r\nfor i in range(n - 1):\r\n if a[i] < a[i + 1]:\r\n cur += 1\r\n if cur > mx:\r\n mx = cur\r\n else:\r\n cur = 1\r\n\r\nprint(mx)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nd = 1\r\nb = 1\r\nfor i in range(1, n):\r\n if a[i] > a[i-1]:\r\n d += 1\r\n else:\r\n d = 1\r\n b = max(b, d)\r\n\r\nprint(b)\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ncur_len = 1\r\nmax_len = 1\r\ni = 1\r\nwhile i < n:\r\n\tif arr[i] > arr[i-1]:\r\n\t\tcur_len += 1\r\n\telse:\r\n\t\tcur_len = 1\r\n\tmax_len = max(cur_len, max_len)\r\n\ti+=1\r\n\r\nprint(max_len)\r\n",
"line_len = int(input())\r\narr = [int(i) for i in input().split()]\r\nmax_increases = 1\r\nincreases = 1\r\nfor i in range(line_len - 1):\r\n if arr[i + 1] > arr[i]:\r\n increases += 1\r\n max_increases = max(max_increases, increases)\r\n else:\r\n increases = 1\r\n\r\nprint(max_increases)\r\n",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nc=1\r\nd=[]\r\nfor i in range(1,a):\r\n if b[i]>b[i-1]:\r\n c+=1\r\n d.append(c)\r\n else:\r\n c=1\r\nd.append(1)\r\nif max(d)>1:\r\n print(max(d))\r\nelse:\r\n print(1)",
"x = int(input())\r\nzoop = list(map(int, input().split()))\r\n\r\ndp = [1]*len(zoop)\r\nfor i in range(1, len(zoop)):\r\n if zoop[i] > zoop[i-1]:\r\n dp[i] = dp[i-1]+1\r\n\r\nprint(max(dp))\r\n",
"def max_increasing_subarray_length(n, arr):\r\n # Edge case: if the array is empty, return 0\r\n if n == 0:\r\n return 0\r\n \r\n # Initialize the length of the current increasing subarray to 1\r\n current_length = 1\r\n # Initialize the maximum length to 1\r\n max_length = 1\r\n \r\n # Iterate through the array, starting from the second element\r\n for i in range(1, n):\r\n # If the current element is greater than the previous element\r\n if arr[i] > arr[i - 1]:\r\n # Increment the length of current increasing subarray\r\n current_length += 1\r\n # Update the maximum length\r\n max_length = max(max_length, current_length)\r\n else:\r\n # Reset the length of current increasing subarray\r\n current_length = 1\r\n \r\n # Return the maximum length of an increasing subarray\r\n return max_length\r\n\r\n# Input reading:\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\n# Function call and output:\r\nprint(max_increasing_subarray_length(n, arr))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ni=0\r\nc=1\r\na=[]\r\nwhile(i<n-1):\r\n if l[i]<l[i+1]:\r\n c+=1\r\n else:\r\n a.append(c)\r\n c=1\r\n i+=1 \r\nelse:\r\n a.append(c)\r\nprint(max(a)) \r\n \r\n",
"length = int(input())\r\narr = list(map(int, input().split()))\r\ncount = 0\r\nres = 0\r\nprev = float(\"-infinity\")\r\nfor i in range(len(arr)):\r\n\tif arr[i] > prev:\r\n\t\tcount += 1\r\n\telse:\r\n\t\tres = max(res, count)\r\n\t\tcount = 1\r\n\tprev = arr[i]\r\nres = max(res, count)\r\nprint(res)",
"n = int(input())\nlist_a = list(map(int, input().split()))\n\nlast_a = list_a[0]\nacc = 1\nmaxx = 1\n\nfor i in range(1, n):\n a = list_a[i]\n\n if a > last_a:\n acc += 1\n last_a = a\n else:\n last_a = a\n maxx = max(maxx, acc)\n acc = 1\n\nmaxx = max(maxx, acc)\nprint(maxx)",
"n=int(input())\r\narr = list(map(int ,input().split()))\r\ndp = [1 for i in range(n)]\r\nfor x in range(1,n):\r\n if arr[x]>arr[x-1]:\r\n dp[x] = max(dp[x-1]+1,dp[x])\r\ndp.sort()\r\nprint(dp[-1])",
"size = int(input())\r\narr = tuple(int(x) for x in input().split())\r\nans,curr = 1,1\r\n\r\nfor i in range(size-1):\r\n\tif arr[i] < arr[i+1]:\r\n\t\tcurr += 1\r\n\t\tif curr > ans:\r\n\t\t\tans = curr\r\n\telse:\r\n\t\tcurr = 1\r\n\r\nprint(ans) ",
"f = int(input())\na = [int(i) for i in input().split()]\ng = []\nt = 0\nfor i in range(1, len(a)):\n if a[i] > a[i - 1]:\n t += 1\n else:\n g.append(t)\n t = 0\nelse:\n g.append(t)\n\nprint(max(g) + 1)",
"n = int(input())\r\n\r\nss = list(map(int,input().split()))\r\n\r\nif len(ss)==1:\r\n print(1)\r\nelse:\r\n cnt = 1\r\n longest = 0\r\n for i in range(1,n):\r\n if ss[i-1] < ss[i]:\r\n cnt += 1\r\n else:\r\n longest = max(longest,cnt)\r\n cnt = 1\r\n if cnt > longest:\r\n longest = cnt\r\n print(longest)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ndp=[1]*n\r\nfor i in range(1,n):\r\n if(a[i]>a[i-1]):\r\n dp[i]=dp[i-1]+1\r\nprint(max(dp))",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nmx = 1\r\ns = 1\r\nfor i in range(1,n):\r\n if(l[i]>l[i-1]):\r\n s = s + 1\r\n else:\r\n if(s>mx):\r\n mx = s\r\n s = 1\r\nprint(max(mx,s))",
"n = int(input())\r\na = list((map(int,input().split())))\r\nmaxi = 0\r\ncurr = 0\r\n\r\nfor i in range(1,n):\r\n if a[i-1] < a[i]:\r\n curr +=1\r\n maxi = max(maxi,curr)\r\n else:\r\n curr = 0\r\n\r\nprint(maxi+1)",
"import math\r\nstack = []\r\nn = int(input())\r\nt = 1\r\na = [int(x) for x in input().split()]\r\nfor i in range(1,len(a)):\r\n if a[i] > a[i-1]:\r\n t += 1\r\n else:\r\n stack.append(t)\r\n t = 1\r\nstack.append(t)\r\nprint(max(stack))",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nmaxcnt=1\r\nc=1\r\nfor i in range(1,len(lst)):\r\n if lst[i]>lst[i-1]:\r\n c=c+1\r\n else:\r\n c=1\r\n if c>maxcnt:\r\n maxcnt=c\r\n\r\nprint(maxcnt) \r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nt = 1\r\nlengths = []\r\nmax = 0\r\nfor x in range(1,n):\r\n if l[x] > l[x-1] :\r\n t +=1\r\n else:\r\n if t > max :\r\n max = t\r\n t = 1\r\nif t > max :\r\n max = t\r\n \r\nprint(max) ",
"n = int(input())\r\nln = list(map(int, input().split()))\r\nres = 0\r\nmaxres = 0\r\nfor i in range(n-1):\r\n if ln[i+1] > ln[i]:\r\n res += 1\r\n else:\r\n res+=1\r\n if maxres < res:\r\n maxres = res\r\n res = 0\r\nres+=1\r\nif maxres < res:\r\n maxres = res\r\n\r\nprint(maxres)\r\n\r\n",
"n=int(input())\r\na=list(map(int, input().split()))\r\nc=1\r\nd=1\r\nfor i in range(n-1):\r\n if a[i]<a[i+1]:\r\n c=c+1\r\n else:\r\n if c>d:\r\n d=c\r\n c=1\r\nif c>d:\r\n d=c\r\nprint(d)",
"n = int(input())\n\npesos = input().split( )\npesos = [int(x) for x in pesos]\n\ns = 1 #sequencia final\nst = 1 #sequencia temporaria\nfor i in range (0, n-1):\n if pesos[i+1] > pesos[i]:\n st+=1\n else:\n st = 1\n \n if st > s:\n s = st\n \nprint(s)\n \t \t \t\t \t\t\t \t\t \t \t\t \t\t\t",
"input()\nv = s = r = 0\nfor x in map(int, input().split()):\n s = s + 1 if x > v else 1\n v = x\n r = max(r, s)\nprint(r)\n\n \t \t\t \t\t\t \t \t \t",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nm= 1\r\nc = 1\r\n\r\nfor i in range(1, n):\r\n if arr[i] > arr[i-1]:\r\n c += 1\r\n else:\r\n m = max(m, c)\r\n c = 1\r\n\r\nm = max(m, c)\r\nprint(m)\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nres = 1\r\ntemp = 1\r\nfor i in range(len(arr)-1):\r\n if arr[i] < arr[i+1]:\r\n temp += 1\r\n else:\r\n if res < temp:\r\n res = temp\r\n temp = 1\r\nif temp > res:\r\n res = temp\r\nprint(res)\r\n",
"n = int(input())\r\n\r\nl = [int(x) for x in input().split(\" \")]\r\n\r\nc = 1\r\nm = 1\r\n\r\nfor i in range(1, len(l)):\r\n if(l[i] > l[i-1]):\r\n c += 1\r\n else:\r\n if c > m:\r\n m = c\r\n c = 1\r\nif c > m:\r\n print(c)\r\nelse:\r\n print(m)",
"n = int(input())\r\nasL = list(map(int, input().split()))\r\nmaxL = [1]\r\nfor i in range(n-1):\r\n if asL[i+1]-asL[i]>0:\r\n maxL[-1]+=1\r\n else:\r\n maxL += [1]\r\n\r\nprint (max(maxL))\r\n ",
"n = int(input())\nl = [int(x) for x in input().strip().split(' ')]\n\nbr = 0\nmaX = 0\nfor i in range(len(l)):\n if i < len(l)-1 and l[i] < l[i+1]:\n br += 1\n else:\n maX = max(br + 1, maX)\n br = 0\n\nprint(maX)\n\n\n",
"array_len = int(input())\r\narray = list((int(x) for x in input().split()));\r\nmax_len = 0;\r\ncurrent_len=0;\r\nlast = 0;\r\nfor i in range(array_len):\r\n if array[i] > last:\r\n current_len+=1;\r\n max_len = max(max_len, current_len)\r\n else:\r\n max_len = max(max_len, current_len)\r\n current_len = 1;\r\n last = array[i]\r\nprint(max_len)\r\n \r\n",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nc, m = 1, 0\r\nfor i in range(1, n):\r\n if a[i] > a[i-1]:\r\n c += 1\r\n else:\r\n m = max(m, c)\r\n c = 1\r\nm = max(m, c)\r\nprint(m)\r\n",
"s = int(input())\nn = list(map(int, input().split()))\n\np = []\nt = 1\nfor i in range(1, len(n)):\n if n[i] > n[i - 1]:\n t += 1\n else:\n p.append(t)\n t = 1\n\n\np.append(t)\nprint(max(p))\n",
"#https://codeforces.com/problemset/problem/702/A\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\ntemp_max, max = 1, 1\r\nfor index in range(1, n):\r\n if(a[index] > a[index-1]):\r\n temp_max += 1\r\n else:\r\n temp_max = 1\r\n if(temp_max > max):\r\n max = temp_max\r\nprint(max)",
"# LUOGU_RID: 101608127\nn, *a = map(int, open(0).read().split())\r\nc = 1\r\nans = []\r\nfor i in range(1, n):\r\n if a[i] <= a[i - 1]:\r\n ans += c,\r\n c = 1\r\n else:\r\n c += 1\r\nans += c,\r\nprint(max(ans))",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Feb 25 12:18:51 2023\r\n\r\n@author: rohan\r\n\"\"\"\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nans = 0\r\nc = 0\r\nprev = 0\r\nfor i in a:\r\n if prev < i:\r\n c += 1\r\n else:\r\n c = 1\r\n \r\n ans = max(ans, c)\r\n prev = i\r\nprint(ans) ",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nres = 0\r\nprev = 0\r\nmaxRes = 0\r\nfor i in a:\r\n if(i > prev):\r\n res += 1\r\n else:\r\n res = 1\r\n maxRes = max(maxRes, res)\r\n prev = i\r\nprint(maxRes)",
"def main():\r\n n = int(input())\r\n lst = list(map(int, input().split()))\r\n result = []\r\n result.append(1)\r\n current_length = result[0]\r\n for i in range(1, n):\r\n if lst[i] > lst[i-1]:\r\n current_length += 1\r\n elif lst[i] <= lst[i-1]:\r\n current_length = 1\r\n result.append(max(result[i-1], current_length))\r\n\r\n print(result[-1])\r\n\r\n\r\nmain()\r\n",
"from collections import deque\nfrom heapq import *\nimport sys\nsys.setrecursionlimit(5005)\nmod = 1000000007\ntime = 0\n\ndef solve():\n\tn = int(input())\n\tarr = list(map(int,input().split()))\n\tdp = [0]*n\n\tdp[0] = 1\n\tfor i in range(1,n):\n\t\tif arr[i]>arr[i-1]:\n\t\t\tdp[i] = dp[i-1]+1\n\t\telse:\n\t\t\tdp[i] = 1\n\tprint(max(dp))\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nt = 1\n#t = int(input())\n\nfor i in range(t):\n\tsolve()",
"n = int(input())\r\n\r\nlst = list(map(int,input().split()))\r\n\r\nans = 1\r\n\r\ncnt = 1\r\nfor i in range(1,n):\r\n if lst[i]>lst[i-1]:\r\n cnt += 1\r\n\r\n else:\r\n ans = max(cnt,ans)\r\n cnt =1\r\n\r\nans = max(ans,cnt)\r\n\r\nprint(ans)",
"a = int(input())\nm = [int(n) for n in input().split()]\ns = 1\nw = 1\nfor j in range(1,a):\n if m[j]>m[j-1]:\n w = w + 1\n else:\n if w>s:\n s = w\n w = 1\nif w>s:\n s = w\nprint(s)\n \t \t\t \t \t \t\t\t \t\t\t \t \t\t",
"n = int(input())\r\na = list(map(int , input().split()))\r\nl = []\r\nc = 0\r\nfor i in range(n-1):\r\n if a[i+1] > a[i]:\r\n c += 1\r\n if i == n-2:\r\n l.append(c)\r\n else:\r\n l.append(c)\r\n c = 0\r\nif n == 1:\r\n l.append(0)\r\nprint(max(l) + 1)",
"# URL: https://codeforces.com/problemset/problem/702/A\n\nimport io\nimport os\nimport sys\n\ninput_buffer = io.BytesIO(os.read(0, os.fstat(0).st_size))\ninp = lambda: input_buffer.readline().rstrip(b\"\\n\").rstrip(b\"\\r\")\nout = sys.stdout.write\n\nn = int(inp())\na = list(map(int, inp().split()))\nf = [1] * n\nfor i in range(1, n):\n if a[i] > a[i - 1]:\n f[i] = f[i - 1] + 1\nans = max(f)\nout(f\"{ans}\\n\")\n",
"n = int(input())\r\ntest = [int(x) for x in input().split()]\r\nmax_length = 0\r\ni = j = 0\r\nwhile j <= n-1:\r\n if test[j] > test[j-1]:\r\n j += 1\r\n else:\r\n max_length = max(max_length, j-i)\r\n i, j = j, j+1\r\nprint(max(max_length, j-i))\r\n \r\n \r\n",
"n=int(input())\r\nl = [int(i) for i in input().split()]\r\nmaxi = 1\r\nc = 1\r\nfor i in range(n-1):\r\n if(l[i]<l[i+1]):\r\n c = c+1\r\n else:\r\n if(maxi<c):\r\n maxi = c \r\n c = 1\r\nif maxi<c:\r\n maxi = c\r\nprint(maxi)",
"j=int(input())\r\nk=[int(i) for i in input().split()]\r\nw=[]\r\ns=1\r\nfor i in range(j):\r\n if i!=j-1:\r\n if k[i+1]>k[i]:\r\n s+=1\r\n else:\r\n w.append(s)\r\n s=1\r\nw.append(s)\r\nprint(max(w))\r\n \r\n \r\n \r\n",
"import math\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nif n == 1:\r\n print(1)\r\nelse:\r\n a += [-math.inf]\r\n ans = 0\r\n left = 0\r\n for right, x in enumerate(a):\r\n if not right:\r\n continue\r\n if x <= a[right - 1]:\r\n ans = max(ans, right - left)\r\n left = right\r\n print(ans)\r\n",
"n = int(input())\na = list(map(int, input().split()))\n\nlast = a[0]\nans = 1\ncount = 1\n\nfor elem in a[1:]:\n if elem > last:\n count += 1\n else:\n count = 1\n last = elem\n ans = max(ans, count)\n\nprint(ans)\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nans=0\r\nk=1\r\nfor r in range(1,n):\r\n if a[r-1]<a[r]:\r\n k+=1\r\n else:\r\n ans=max(ans,k)\r\n k=1\r\nans=max(ans,k)\r\nprint(ans)",
"import sys\r\ninput=sys.stdin.readline\r\n\r\nn=int(input())\r\nlst=[*map(int,input().split())]\r\n\r\ncnt=1\r\nmaxi=0\r\nfor i in range(1,n):\r\n if lst[i]>lst[i-1]:\r\n cnt+=1\r\n else:\r\n if cnt>maxi: maxi=cnt\r\n cnt=1\r\nprint(max(maxi,cnt))",
"input()\ns=m=j=0\nfor i in map(int,input().split()):\n\tif j<i:m+=1\n\telse:\n\t\ts=max(s,m)\n\t\tm=1\n\tj=i\nprint(max(s,m))\n\t\t \t \t\t \t \t\t \t \t \t\t \t",
"c=1\r\nx=int(input())\r\nl=list(map(int,input().split()))\r\nt=1\r\nfor i in range(1,x):\r\n\tif l[i]>l[i-1]:\r\n\t\tt+=1\r\n\telse:\r\n\t\tc=max(c,t)\r\n\t\tt=1\r\nprint(max(t,c))",
"n = int(input())\r\na = list(map(int,input().split()))\r\nans = 1\r\ncurr = 1\r\nfor i in range(n-1):\r\n if a[i+1] > a[i]:\r\n curr += 1\r\n else:\r\n if curr > ans:\r\n ans = curr\r\n curr = 1\r\nif curr > ans:\r\n ans = curr\r\nprint(ans)",
"input()\r\ns=a=m=0\r\nfor x in map(int,input().split()):a=a+1 if x>s else 1;s=x;m=max(m,a)\r\nprint(m)",
"n = int(input())\n\ndp = [1 for _ in range(n)]\n\ndp[0] = 1\nnums = list(map(int, input().split()))\nfor i in range(1, n):\n if nums[i] > nums[i-1]: \n dp[i] = dp[i-1] + 1\n else: \n dp[i] = 1\nprint(max(dp))\n\n",
"\r\n#from math import ceil, sqrt\r\n#from collections import defaultdict\r\n#from heapq import heapify, heappush, heappop\r\n#from collections import deque\r\n#import io, os, sys\r\n#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #input().decode().rstrip('\\r\\n')\r\n#print = lambda x: sys.stdout.write(str(x) + \"\\n\")\r\n#mod = 10**9 + 7\r\n\r\nII = lambda: int(input())\r\nMII = lambda: map(int, input().split())\r\nLMII = lambda: list(MII())\r\n#SLMII = lambda: sorted(LMII())\r\n\r\nn = II()\r\nnums = LMII()\r\n\r\nmax_end = 1\r\nmax_ = 1\r\n\r\nfor i in range(1, n):\r\n if nums[i] > nums[i-1]:\r\n max_end += 1\r\n else:\r\n max_end = 1\r\n max_ = max(max_, max_end)\r\n \r\nprint(max_)\r\n \r\n\r\n",
"n = int(input())\r\narg = list(map(int, input().split()))\r\n\r\ndef longest_len(arg, n):\r\n longest_subarray_len = 1\r\n current_subarray_len = 1\r\n\r\n for i in range(1, n):\r\n if arg[i] > arg[i - 1]:\r\n current_subarray_len += 1\r\n else:\r\n longest_subarray_len = max(longest_subarray_len, current_subarray_len)\r\n current_subarray_len = 1\r\n\r\n longest_subarray_len = max(longest_subarray_len, current_subarray_len)\r\n\r\n return longest_subarray_len\r\n\r\n\r\nprint(longest_len(arg, n))\n# Sat Apr 22 2023 11:21:16 GMT+0300 (Moscow Standard Time)\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=0\r\nmx=0\r\npre=-1\r\nfor i in l:\r\n if i>pre:\r\n c+=1\r\n pre=i\r\n else:\r\n c=1\r\n pre=i\r\n mx=max(mx,c)\r\nprint(mx)",
"n=int(input())\r\narr = list(map(int,input().split()))\r\n\r\nc=1\r\nres=[]\r\nfor i in range(len(arr)-1):\r\n if arr[i]<arr[i+1]:\r\n c+=1\r\n else:\r\n res.append(c)\r\n c=1\r\n\r\nres.append(c)\r\nprint(max(res))\r\n ",
"def f(s):\r\n m=1\r\n t=0\r\n i=0\r\n while i<len(s)-1:\r\n if s[i+1]>s[i]:\r\n i+=1\r\n else:\r\n m = max(m,(i-t)+1)\r\n t=i+1\r\n i+=1\r\n return max(m,(i-t)+1)\r\n\r\n\r\nt = input()\r\na = input().split(\" \")\r\na = [int(x) for x in a]\r\nprint(f(a))",
"n = int(input())\r\nal = list(map(int,input().split()))\r\nmaxl = 1\r\ncounter = 1\r\nfor i in range(1,n):\r\n if al[i-1] < al[i]:\r\n counter += 1\r\n else:\r\n counter = 1\r\n if maxl < counter:\r\n maxl = counter\r\nprint(maxl)",
"n=int(input())\r\na=b=c=0\r\nfor i in map(int,input().split()):\r\n c=c+1 if i>a else 1\r\n b=max(b,c)\r\n a=i\r\nprint(b)",
"n = int (input())\nl = list (map(int, input().split()))\n\nNum = [1]*n\n\nfor i in range (1, n):\n\n if l[ i-1 ] < l[i]:\n\n Num[i] = Num[i-1]+1\n\nprint(max(Num))\n\n\n\t\t \t\t \t \t\t\t\t\t\t \t \t\t \t \t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=1\r\nk=1\r\nfor i in range(n-1):\r\n # print(l[i],l[i+1],sep=' ')\r\n if l[i]<l[i+1]:\r\n k+=1\r\n else:\r\n if k>m:\r\n m=k\r\n k=1\r\nif k>m:\r\n m=k\r\nprint(m)",
"n = int(input())\r\nx = [int(x) for x in input().split()]\r\ns = 0\r\ncnt = 0\r\nfor i in range(1,len(x)):\r\n if x[i-1] < x[i]:\r\n cnt = cnt + 1\r\n else:\r\n s = max(s,cnt+1)\r\n cnt = 0\r\ns=max(cnt+1,s)\r\n \r\nprint(s)",
"n = int(input())\r\nls = list(map(int, input().split()))\r\nt, tt = [], []\r\nprev = -1\r\n\r\nfor i in ls:\r\n if i > prev: t.append(i)\r\n else: \r\n tt.append(len(t))\r\n t = [i]\r\n prev = i\r\n \r\ntt.append(len(t))\r\nprint(max(tt))",
"\r\n\r\n\r\ndef _main__():\r\n a = int(input())\r\n T = [int(T) for T in input().split()]\r\n frst = T[0]\r\n licznik = 1\r\n M = 1\r\n for x in T:\r\n if x > frst:\r\n licznik += 1\r\n M = max(licznik, M)\r\n else:\r\n licznik = 1\r\n frst = x\r\n print(M)\r\n_main__()\r\n",
"a = int(input())\r\nb = list(map(int, input().split()))\r\nc, d = 1, 1\r\nfor i in range(1, a):\r\n if b[i-1] < b[i]:\r\n d += 1\r\n if d > c:\r\n c = d\r\n else:\r\n d = 1\r\nprint(c)",
"# 702A\r\n\r\n# The starting array will always output 1 because we always have\r\n# at least one number.\r\n\r\n# We can count the number of times a number is bigger than the\r\n# previous number. if the number is bigger than our previous\r\n# max, we replace the max.\r\n\r\nnumbers = int(input())\r\nmaxCounter = 1\r\ncounter = 1\r\noutput = 0\r\nnumberlist = [int(i) for i in input().split()]\r\n\r\nfor n in range(1, numbers):\r\n \r\n if numberlist[n] > numberlist[n-1]:\r\n counter += 1\r\n else:\r\n counter = 1\r\n \r\n if counter > maxCounter:\r\n maxCounter = counter\r\n\r\noutput = maxCounter\r\nprint(output)",
"n=int(input())\r\nls=list(map(int,input().split()))\r\nif n==1:\r\n print(1)\r\nelse:\r\n lz=[]\r\n cnt=1\r\n for i in range(1,n):\r\n if ls[i]>ls[i-1]:\r\n cnt+=1\r\n else:\r\n lz.append(cnt)\r\n cnt=1\r\n lz.append(cnt)\r\n print(max(lz))",
"n = int(input())\nmas = list(map(int, input().split()))\nansp = 1\nans = 1\nfor i in range(1, len(mas)):\n if mas[i - 1] < mas[i]:\n ansp += 1\n ans = max(ans, ansp)\n else:\n ansp = 1\nprint(ans)\n",
"input()\r\narr = list(map(int, input().split()))\r\nn = 1\r\nt = 1\r\nfor i in range(len(arr) - 1):\r\n if (arr[i] < arr[i + 1]):\r\n t += 1\r\n else:\r\n t = 1\r\n n = max(n, t)\r\nprint(n)",
"\r\na = int(input())\r\nb = list(map(int,input().split()))\r\ndp = 0\r\nans = 1\r\nb.append(-9)\r\nfor i in range(1,a+1):\r\n if b[i]>b[i-1]:\r\n ans+=1\r\n else:\r\n dp=max(dp,ans) \r\n ans=1\r\nprint(dp) ",
"n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nif n==1:\r\n print(1)\r\n exit()\r\nl = 0\r\nr = 1\r\nres = 1\r\nwhile l<=r and r<n:\r\n if a[r]>a[r-1]:\r\n res = max(r-l+1,res)\r\n else:\r\n l = r\r\n r+=1\r\nprint(res)\r\n ",
"def find_longest_contiguous_subarray(arr,n):\n longest_subarray_length = 1\n\n current_subarray_length = 1\n current_subarray_start = 0\n\n # Initialize variables to track the previous element and the maximum element seen so far\n prev_elem = arr[0]\n max_elem = arr[0]\n\n for i in range(1, n):\n if arr[i] > prev_elem:\n current_subarray_length += 1\n prev_elem = arr[i]\n if arr[i] > max_elem:\n max_elem = arr[i]\n else:\n if current_subarray_length > longest_subarray_length:\n longest_subarray_length = current_subarray_length\n if max_elem <= prev_elem:\n current_subarray_length = 1\n current_subarray_start = i\n prev_elem = arr[i]\n max_elem = arr[i]\n else:\n # Skip over elements that cannot be part of a longer increasing subarray\n j = current_subarray_start\n while arr[j] <= prev_elem:\n j += 1\n current_subarray_length = i - j + 1\n prev_elem = arr[i]\n\n if current_subarray_length > longest_subarray_length:\n longest_subarray_length = current_subarray_length\n\n return longest_subarray_length\n\nn = int(input())\narray = list(map(int, input().split()))\n\nprint(find_longest_contiguous_subarray(array, n))\n\t\t \t\t\t\t\t \t \t\t\t \t \t \t",
"z=int(input())\r\nx=list(map(int,input().split()))\r\nc=[]\r\na=1\r\nfor i in range(z-1):\r\n if x[i]<x[i+1]:\r\n a+=1\r\n else:\r\n c+=[a]\r\n a=1\r\nc+=[a]\r\nprint(max(c))\r\n",
"n = int(input())\r\n\r\narr = [int(_) for _ in input().split()]\r\n\r\ndp = [1]*n\r\n\r\nfor i in range(1,n):\r\n if arr[i-1] < arr[i]:\r\n dp[i] = max(dp[i],dp[i-1]+1)\r\n else:\r\n dp[i] = 1\r\n\r\nprint(max(dp))",
"n=int(input())\r\narr=list(map(int,input().rstrip().split()))\r\no=0;oo=0\r\nfor e in range(0,n-1):\r\n if arr[e]>=arr[e+1]:\r\n oo=max(oo,o+1)\r\n o=0\r\n continue\r\n o+=1 \r\noo= max(oo,o+1) \r\nprint(oo) ",
"# list(map(int,input().split()))\r\nma = 1\r\nn=int(input())\r\narr = list(map(int,input().split()))\r\nj=1\r\nfor i in range(1,n):\r\n if arr[i]<=arr[i-1]:\r\n ma=max(ma,j)\r\n j=0\r\n j+=1\r\nprint(max(ma,j))",
"import sys,random,bisect\r\nfrom collections import deque,defaultdict\r\nfrom heapq import heapify,heappop,heappush\r\nfrom itertools import permutations\r\nfrom math import gcd,log\r\nMOD = int(1e9 + 7)\r\nINF = int(1e20)\r\ninput = lambda :sys.stdin.readline().rstrip()\r\nmi = lambda :map(int,input().split())\r\nli = lambda :list(mi())\r\n\r\nn=int(input())\r\narr=li()\r\nres=ans=0\r\npre=-1\r\n\r\nfor i in arr:\r\n if i>pre:\r\n ans+=1\r\n else:\r\n ans=1\r\n pre=i\r\n res=max(res,ans)\r\nprint(res)\r\n\r\n\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\nx=[]\r\nc=1\r\nif n==1:\r\n print(1)\r\nelse:\r\n for i in range(n-1):\r\n if a[i]<a[i+1]:\r\n c+=1\r\n elif a[i]>=a[i+1]:\r\n x.append(c)\r\n if i!=n-2:\r\n c=1\r\n if i==n-2:\r\n x.append(c)\r\n c=1\r\n print(max(x))\r\n\r\n",
"# Happy_water\r\ndef main():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n i = 0\r\n ans = 0\r\n while i < n:\r\n res = i\r\n i += 1\r\n while i < n and a[i] > a[i - 1]:\r\n i += 1\r\n ans = max(ans, i - res)\r\n print(ans)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"import sys\r\n\r\nk = int(input())\r\narray = [int(i) for i in sys.stdin.readline().split()]\r\narr = []\r\ncount = 1\r\nfor i in range(1, k):\r\n if array[i] > array[i-1]:\r\n count += 1\r\n else:\r\n arr.append(count)\r\n count = 1\r\narr.append(count)\r\nprint(max(arr))\r\n",
"input()\r\nl = [int(x) for x in input().split()]\r\ncounts = []\r\nc = 1\r\nfor i in range(len(l)-1):\r\n if l[i+1] > l[i]:\r\n c+=1\r\n else:\r\n counts.append(c)\r\n c = 1\r\ncounts.append(c)\r\nprint(max(counts))\r\n",
"def solve(lst):\r\n ans=1\r\n start=1\r\n for i in range(1,len(lst)):\r\n if lst[i]>lst[i-1]:\r\n start+=1\r\n if start>ans:\r\n ans=start\r\n else:\r\n start=1\r\n return ans\r\nn=input()\r\nlst=list(map(int,input().split()))\r\nprint(solve(lst))",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nmaxi=1\r\ncnt=1\r\nfor i in range(1,n):\r\n if lst[i-1]<lst[i]:\r\n cnt+=1\r\n else:\r\n maxi=max(cnt,maxi)\r\n cnt=1\r\nprint(max(maxi,cnt))\r\n ",
"n=int(input())\r\nli=[int(i) for i in input().split()]\r\ndp=[1]*n\r\nfor j in range(1,n):\r\n if li[j]>li[j-1]:\r\n dp[j]=dp[j-1]+1\r\nprint(max(dp))",
"import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef inp():\r\n return int(input())\r\n\r\n\r\ndef minp():\r\n return map(int, input().split())\r\n\r\n\r\ndef mlinp():\r\n return list(map(int, input().split()))\r\n\r\n\r\nt = inp()\r\nl = mlinp()\r\n\r\nm = 0\r\nmm = 1\r\nfor i in range(1, t):\r\n if l[i] > l[i - 1]:\r\n mm += 1\r\n else:\r\n m = max(mm, m)\r\n mm = 1\r\n\r\nm = max(mm, m)\r\n\r\n\r\nprint(m)",
"def solve(list_numbers):\n response = 1\n current_length = 1\n\n for i in range(1, len(list_numbers)):\n if list_numbers[i - 1] < list_numbers[i]:\n current_length += 1\n else:\n current_length = 1\n\n if current_length > response:\n response = current_length\n return response\n\n\nn = int(input())\nnumbers = list(map(int, input().split()))\nprint(solve(numbers))\n\n \t\t \t\t \t\t\t \t\t \t \t \t\t",
"from collections import Counter\r\n\r\nn=int(input())\r\nnums=list(map(int,input().split()))\r\nbest = 1\r\nans = 1\r\nfor i in range(1,n):\r\n if nums[i] <= nums[i-1]:\r\n ans = 1\r\n else:\r\n ans += 1\r\n best = max(best,ans)\r\nprint(best)",
"n=int(input())\r\na=[int(val) for val in input().split()]\r\ni,j,mmax=1,0,1\r\nwhile i<n:\r\n mmax=max(mmax,i-j)\r\n if a[i]<=a[i-1]:j=i\r\n i+=1\r\nmmax=max(mmax,i-j)\r\nprint(mmax)\r\n",
"n = int(input())\nl1 = list(map(int,input().split()))\na = 1\naa = 1\nfor i in range(1,len(l1)):\n if l1[i] > l1[i-1]:\n a += 1\n else:\n a = 1\n aa = max(aa,a)\nprint(aa)",
"n=int(input())\r\nl1=[int(i) for i in input().split()]\r\nmax=0\r\ncount=0\r\nfor j in range(n):\r\n if j==0:\r\n count=1\r\n max=1\r\n else :\r\n if l1[j]>l1[j-1]:\r\n count+=1\r\n if count>max:\r\n max=count\r\n else :\r\n count=1\r\nprint(max)",
"import sys\r\na = int(sys.stdin.readline())\r\np = list(map(int,sys.stdin.readline().strip().split(' ')))\r\nprev = -1\r\ns = 0\r\nt = -1\r\nfor index, val in enumerate(p):\r\n if val>prev:\r\n s+=1\r\n prev = val\r\n else:\r\n t = max(s,t)\r\n s = 1\r\n prev = val\r\nt = max(s,t)\r\nprint(t)\r\n",
"# input\r\nn = int(input())\r\nnumbers = input().split()\r\ni = 0\r\nwhile i < n:\r\n numbers[i] = int(numbers[i])\r\n i += 1\r\n\r\n# solve\r\ncurrent_max = 0\r\ncurrent_start = 0\r\nwhile current_start < n:\r\n current_end = current_start\r\n while current_end + 1 < n and numbers[current_end] < numbers[current_end + 1]:\r\n current_end += 1\r\n current_max = max(current_max, current_end - current_start + 1)\r\n current_start = current_end + 1\r\n\r\nprint(current_max)",
"n = int(input())\r\na = input().split()\r\nlen = 1\r\nmxlen = 1\r\nmx = int(a[0])\r\nfor item in a:\r\n if int(item) > int(mx):\r\n len += 1\r\n mx = int(item)\r\n if len > mxlen:\r\n mxlen = len\r\n else:\r\n len = 1\r\n mx = int(item)\r\nprint(mxlen)\r\n",
"n = int(input())\r\nlistA = list(map(int,input().split(\" \")))\r\nnum = 0\r\ncount = 0\r\ncountList = []\r\nfor a in listA:\r\n if a>num:\r\n count+=1\r\n num = a\r\n else:\r\n num = a\r\n countList.append(count)\r\n count = 1\r\ncountList.append(count)\r\nprint(max(countList))",
"a,b,m,n=0,0,0,input()\r\nfor i in map(int,input().split()):\r\n m= m+1 if i>b else 1\r\n a=max(a,m)\r\n b=i\r\nprint(a)",
"n = int(input())\r\ns = int(0)\r\nc = int(0)\r\nmax = int(0)\r\n\r\nar = [int(l) for l in input().split()]\r\nfor i in range(n):\r\n if ar[i] > s:\r\n c+=1\r\n s = ar[i]\r\n if c > max:\r\n max = c\r\n else:\r\n c = 1\r\n s = ar[i]\r\nprint(max)",
"n=int(input())\r\narr=[int(x) for x in input().split()]\r\ncount=0\r\nl=len(arr)\r\nmaxi=0\r\nj=0\r\nfor i in range(l):\r\n if arr[i-1]<arr[i]:\r\n count+=1\r\n # maxi = max(count, maxi)\r\n else:\r\n maxi=max(count,maxi)\r\n count=1\r\n j=i\r\nprint(max(maxi,count))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nc=1\r\nans=1\r\nfor i in range(1,len(a)):\r\n\tif a[i]>a[i-1]:\r\n\t\tc+=1\r\n\telse:\r\n\t\tc=1\r\n\tans=max(ans,c)\r\nprint(ans)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ncnt=0\r\nans=1\r\nfor i in range(n-1):\r\n if l[i+1]>l[i] :\r\n cnt+=1\r\n else :\r\n cnt+=1\r\n ans=max(ans,cnt)\r\n cnt=0\r\nans=max(ans,cnt+1)\r\nprint(ans)\r\n ",
"n=int(input())\r\na=list(map(int,input().split()))\r\ncount=1\r\nres=1\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n count+=1\r\n else:\r\n count=1\r\n res=max(res,count)\r\nprint(res)\r\n \r\n",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\ndp = [0] * n\r\n\r\nfor i in range(1, n):\r\n if nums[i] > nums[i - 1]:\r\n dp[i] = dp[i - 1] + 1\r\n\r\nprint(max(dp) + 1)\r\n",
"n= int(input())\r\na=[0]*n\r\ns=input().split()\r\na=[int(i) for i in s]\r\nk=1\r\nMax=0\r\nfor i in range(n-1):\r\n if a[i]<a[i+1]:k+=1\r\n else:\r\n Max=max(Max,k)\r\n k=1\r\nMax=max(Max,k)\r\nprint(Max)",
"def solve():\n n = int(input())\n inp = input().split()\n inp = [int(i) for i in inp]\n ans = 1\n count = 1\n\n for i in range(1,n):\n if inp[i]>inp[i-1]:\n count += 1\n ans = max(ans, count)\n else:\n count = 1\n print(ans) \n \n \n\n\ndef main():\n # t = int(input())\n t = 1\n for _ in range(t):\n solve()\n\n\n\nif __name__ == \"__main__\":\n main()\n",
"def f():\n _ = input()\n nums = [int(c) for c in input().split()]\n n = len(nums)\n dp = n * [1]\n for i in range(1, n):\n if nums[i] > nums[i-1]:\n dp[i] = dp[i-1] + 1\n print(max(dp))\n\n\nf()\n",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\nmaxSub = 1\r\ncurrSub = 1\r\n\r\nfor i in range(len(lst)):\r\n if i > 0 and lst[i] > lst[i-1]:\r\n currSub += 1\r\n maxSub = max(maxSub, currSub)\r\n else:\r\n currSub = 1\r\n\r\nprint(maxSub)",
"n, a = int(input()), [int(i) for i in input().split()]\nres, s, i = 0, 0, 1\nwhile i < n:\n if a[i] <= a[i - 1]:\n res, s = max(res, i - s), i\n i += 1\nres = max(res, i - s)\nprint(res)",
"n = int(input())\r\nlt = [int(x) for x in input().split()]\r\ndp =[1]*n\r\nif n == 1:\r\n print('1')\r\nelse:\r\n for i in range(1,n):\r\n if lt[i] > lt[i - 1]:\r\n dp[i] += dp[i -1]\r\n print(max(dp))\r\n",
"n=int(input())\r\ns=input()\r\ns=s.split()\r\nfor i in range(len(s)): s[i]=int(s[i])\r\nmaxno=0\r\nmaxlen=0\r\nmaxmaxlen=0\r\nfor i in range(n):\r\n if s[i]>maxno:\r\n maxno=s[i]\r\n maxlen=maxlen+1\r\n if maxmaxlen<maxlen: maxmaxlen=maxlen\r\n else:\r\n maxno=s[i]\r\n maxlen=1\r\nprint(maxmaxlen)\r\n \r\n",
"\r\nn = int(input())\r\nl = [int(i) for i in input().split()]\r\ncount = 0\r\nmx = 0\r\nfor i in range(0, n-1):\r\n if l[i]<l[i+1]:\r\n count += 1\r\n mx = max(count+1, mx)\r\n else:\r\n count = 0\r\nmx = max(count+1, mx)\r\nprint(mx)",
"n = int(input())\r\nm = list(map(int, input().split()))\r\ndp = [0 for i in range(n)]\r\ndp[0] = 1\r\nfor i in range(1, n):\r\n if m[i] > m[i - 1]:\r\n dp[i] = dp[i - 1] + 1\r\n else:\r\n dp[i] = 1\r\n\r\nprint(max(dp))\r\n# print(dp)",
"n = int(input())\nnums = [int(x) for x in input().split(' ')]\n\ncurrlen = 1\nmaxlen = 0\ni = 0\nwhile i < n - 1 :\n if nums[i + 1] > nums[i]:\n currlen += 1\n i += 1\n\n else :\n maxlen = max(currlen, maxlen)\n i += max(currlen - 1, 1)\n currlen = 1\n\nprint(max(maxlen, currlen))\n\n\n \n\t \t \t\t \t \t \t \t\t\t\t",
"\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\nprev = a[0]\r\nans = 1\r\ncnt = 1\r\nfor i in range(1, n):\r\n if a[i] > prev:\r\n cnt += 1\r\n else:\r\n cnt = 1\r\n prev = a[i]\r\n ans = max(ans, cnt)\r\nprint(ans)",
"n= int(input())\r\n\r\na = list(map(int,input().split()))\r\n\r\nk = 1\r\ncur = 1\r\nfor i in range(n-1):\r\n if a[i+1]>a[i]:\r\n \r\n cur +=1\r\n k = max(cur,k)\r\n else:\r\n \r\n cur = 1\r\n \r\nprint(k)\r\n\r\n\r\n \r\n ",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nmaxi = 1 \r\nleng = 1 \r\nfor i in range(n-1): \r\n if arr[i]<arr[i+1]: \r\n leng += 1 \r\n else: \r\n if leng > maxi: \r\n maxi = leng \r\n leng = 1 \r\nif leng > maxi: \r\n maxi = leng \r\nprint(maxi) ",
"v=int(input());v1=list(map(int,input().split()));c=1;c1=1\r\nfor i in range(1,v):\r\n if v1[i-1]<v1[i]:c+=1\r\n else:c=1\r\n c1=max(c1,c)\r\nprint(c1)\r\n",
"import sys\r\nfrom collections import defaultdict\r\n \r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n \r\nn = inp()\r\nnums = inlt()\r\nans = [1]*n\r\n\r\nfor i in range(1, n):\r\n if nums[i] > nums[i-1]:\r\n ans[i] = ans[i-1] + 1\r\n \r\nprint(max(ans))",
"jxtymdfJyjtxbckj= int(input())\r\nw = list(map(int,input().split()))\r\nb = [1]\r\nfor i in range(1,len(w)):\r\n if w[i] > w[i - 1]:\r\n b.append(b[i-1] + 1)\r\n else:\r\n b.append(1)\r\nprint( max(b) )",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Apr 10 22:48:30 2023\r\n\r\n@author: Srusty Sahoo\r\n\"\"\"\r\n\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nl,i=1,0\r\nx=1\r\nwhile i<(n-1):\r\n if arr[i]<arr[i+1]:\r\n x=x+1\r\n else:\r\n l=max(l,x)\r\n x=1\r\n i=i+1\r\n \r\nprint(max(l,x))\r\n \r\n ",
"input()\r\nx=list(map(int,input().split()))\r\ny=0\r\nc=1\r\nfor i in range(len(x)-1):\r\n if x[i+1]<=x[i]:\r\n if c>y:\r\n y=c\r\n c=1\r\n else:\r\n c+=1\r\nif c>y:\r\n print(c)\r\nelse:\r\n print(y)",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\ncnt, mx = 1,1\r\nfor i in range(1,n):\r\n if(a[i-1] >= a[i]):\r\n cnt = 1; continue\r\n cnt = cnt + 1;\r\n mx = max(mx,cnt)\r\nprint(mx)",
"no=int(input())\r\narr=[int(n) for n in input().split()]\r\nlent=1\r\nsublen=1\r\nfor i in range(0,no-1):\r\n if arr[i]<arr[i+1]:\r\n lent+=1\r\n else:\r\n if lent>sublen:\r\n sublen=lent\r\n lent=1\r\n if lent>sublen:\r\n sublen=lent\r\nprint(sublen)",
"length = int(input())\r\narray = list(map(int, input().split()))\r\n\r\nnew_length = 1\r\nis_max = 1\r\n\r\nfor i in range(1, length):\r\n if array[i] > array[i - 1]:\r\n new_length += 1\r\n else:\r\n new_length = 1\r\n is_max = max(new_length, is_max)\r\n \r\nprint(is_max)",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\ncount = 1\r\nq = 1\r\nprev = a[0]\r\nfor i in a[1:]:\r\n\tif i > prev:\r\n\t\tq += 1\r\n\telse:\r\n\t\tcount = max(count, q)\r\n\t\tq = 1\r\n\tprev = i\r\ncount = max(count, q)\r\nprint(count)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nans = 1 \r\ncur = 1\r\nfor i in range(1, n):\r\n if arr[i] > arr[i - 1]:\r\n cur += 1\r\n else:\r\n ans = max(ans, cur)\r\n cur = 1\r\n\r\nif cur > 1:\r\n ans = max(ans, cur)\r\nprint(ans)\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\n\r\nmlen = 1\r\nclen = 1\r\n\r\nfor i in range(1,n):\r\n if arr[i]>arr[i-1]:\r\n clen+=1\r\n continue\r\n mlen = max(mlen,clen)\r\n clen = 1\r\nmlen = max(mlen,clen)\r\n\r\nprint(mlen)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nmax = 1\r\nc = 1\r\n\r\nfor i in range(n-1):\r\n if arr[i+1] > arr[i]:\r\n c += 1\r\n if c > max:\r\n max = c\r\n else:\r\n c = 1\r\n \r\nprint(max)",
"n=int(input())\r\narr=[int(i) for i in input().split()]\r\nm = 1\r\nl = 1\r\nfor i in range(1, n) :\r\n if (arr[i] > arr[i-1]):\r\n l =l + 1\r\n else :\r\n if (m < l):\r\n m = l \r\n l=1\r\nif (m < l) :\r\n m = l\r\nprint(m)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=1;m1=1\r\nfor i in range(1,len(l)):\r\n if l[i]>l[i-1]:\r\n c+=1\r\n else:\r\n if c>m1:\r\n m1=c\r\n c=1\r\n if c>m1:\r\n m1=c\r\nprint(m1)\r\n ",
"input()\r\nl = list(map(int, input().split()))\r\nlater = 0\r\na = []\r\ncurr = 0\r\n\r\nfor i in l:\r\n if i > later: \r\n curr += 1\r\n if i <= later:\r\n a.append(curr)\r\n curr = 1 \r\n \r\n later = i\r\n\r\na.append(curr)\r\nprint(max(a))",
"n = int(input())\r\narr = list(map(int,input().split(\" \")))\r\ndef asd(arr, n) :\r\n\tm = 1\r\n\tl = 1\r\n\tfor i in range(1, n) :\r\n\t\tif (arr[i] > arr[i-1]) :\r\n\t\t\tl =l + 1\r\n\t\telse :\r\n\t\t\tif (m < l) :\r\n\t\t\t\tm = l\r\n\t\t\tl = 1\r\n\tif (m < l) :\r\n\t\tm = l\r\n\treturn m\r\nprint(asd(arr,n))\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans = 1\r\ntemp = 1\r\nfor i in range(1,n):\r\n if a[i-1] < a[i]:\r\n temp += 1\r\n else:\r\n ans = max(ans, temp)\r\n temp = 1\r\nans = max(ans, temp)\r\nprint(ans)",
"n=int(input())\r\na=[int(a)for a in input().split()]\r\na.append(-1)\r\ns=1\r\nw=[]\r\nfor i in range(n):\r\n if a[i]<a[i+1]:\r\n s+=1\r\n else:\r\n w.append(s)\r\n s=1\r\nprint(max(w))\r\n \r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nif n==1:\r\n print(1)\r\nelse:\r\n l=[]\r\n c=0\r\n for i in range(n-1):\r\n if a[i]<a[i+1]:\r\n c+=1\r\n else:\r\n c+=1\r\n l.append(c)\r\n c=0\r\n if a[-1]>a[-2]:\r\n c+=1\r\n l.append(c)\r\n print(max(l))",
"input()\nres, current = 1, 1\nfor i, num in enumerate(arr:=[int(elem) for elem in input().split()]):\n if i != 0:\n if num > arr[i-1]:\n current += 1\n if current > res: res = current\n else:\n current = 1\nprint(res)\n\n\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm,c=0,1 \r\nfor i in range(n-1):\r\n if(l[i]<l[i+1]):\r\n c+=1\r\n else:\r\n m=max(m,c)\r\n c=1\r\nprint(max(m,c)) ",
"n=int(input())\r\nls=list(map(int,input().split()))\r\nc=1\r\nmaxi=-1\r\nfor i in range(1,n):\r\n if ls[i]>ls[i-1]:\r\n c+=1\r\n else:\r\n maxi=max(maxi,c)\r\n c=1\r\nmaxi=max(maxi,c)\r\nprint(maxi)",
"from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nans=1\r\ntmp=1\r\nfor i in range(n-1):\r\n if a[i]<a[i+1]:\r\n tmp+=1\r\n else:\r\n tmp=1\r\n ans=max(ans,tmp)\r\n\r\nprint(ans)",
"n = int(input())\r\na = list(map(int,input().split()))\r\ntemp = 1\r\ncount = 1\r\nfor i in range(n-1):\r\n if(a[i] < a[i+1]):\r\n temp += 1\r\n else:\r\n count = max(count,temp)\r\n temp = 1\r\ncount = max(count,temp)\r\nprint(count)",
"length = int(input())\r\nlst = list(map(int, input().split()))\r\ntotal = 1\r\nprev = lst[0]\r\ncurrent = 1\r\nfor i in range(1,length):\r\n if lst[i] > prev:\r\n current += 1\r\n else:\r\n total = max(current,total)\r\n current = 1\r\n prev = lst[i]\r\ntotal = max(current,total)\r\nprint(total)",
"# for _ in range(int(input())):\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\nm = 1\r\nc = 0\r\nfor i in range(1, n):\r\n if a[i] > a[i-1]:\r\n m += 1\r\n else:\r\n m = 1\r\n c = max(m, c)\r\nc = max(m, c)\r\nprint(c)\r\n",
"t = int(input())\n\nl = list(map(int,input().split()))\n\nmaxx = 1\ncmaxx = 1\nfor i in range(1,len(l)):\n if l[i] > l[i-1]:\n cmaxx += 1\n else:\n cmaxx = 1\n if cmaxx > maxx:\n maxx = cmaxx\n\n \nprint(maxx)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Feb 25 12:18:51 2023\r\n\r\n@author: rohan\r\n\"\"\"\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nans = 0\r\ni = 0\r\nfor j in range(n):\r\n if j > 0 and a[j-1] >= a[j]:\r\n i = j\r\n \r\n ans = max(ans, j - i + 1)\r\n\r\nprint(ans)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ndef main() -> None :\r\n array:list[int] = []\r\n input()\r\n array = list(map(int, input().split()))\r\n\r\n maxIncreaseLength:int = 1\r\n currentIncreaseLength:int = 1\r\n prevElement:int = array[0]\r\n for element in array :\r\n if prevElement < element : currentIncreaseLength += 1\r\n else : currentIncreaseLength = 1\r\n prevElement = element\r\n maxIncreaseLength = max(maxIncreaseLength, currentIncreaseLength)\r\n\r\n print(maxIncreaseLength)\r\n\r\nmain()",
"n = int(input())\na = [int(s) for s in input().split()]\n\nbest = ans = 1\nfor i in range(1, n):\n if a[i] > a[i - 1]:\n ans += 1\n best = max(ans, best)\n else:\n ans = 1\n\nprint(best)",
"n = int(input())\r\nv = list(map(int, input().split()))\r\n\r\nctr_max = ctr = 1\r\nfor i in range(1, n):\r\n\tif v[i] > v[i-1]:\r\n\t\tctr += 1\r\n\t\tif ctr > ctr_max:\r\n\t\t\tctr_max += 1\r\n\telse:\r\n\t\tctr = 1\r\n\t\t\r\nprint(ctr_max)",
"n=int(input())\r\na=[int(s) for s in input().split()]\r\nsan=a[0]\r\nss=1\r\nmk=1\r\nfor k in range(1,n):\r\n if a[k]>san:\r\n ss+=1\r\n san=a[k]\r\n else:\r\n if ss>mk:\r\n mk=ss\r\n ss=1\r\n san=a[k]\r\nelse:\r\n if ss>mk:\r\n mk=ss\r\nprint(mk)\r\n",
"# Read the number of integers\nn = int(input())\n\n# Read the array of integers\narray = list(map(int, input().split()))\n\n# Initialize variables\ncurrent_length = 1\nmax_length = 1\n\n# Iterate over the array\nfor i in range(1, n):\n # Check if the current element is greater than the previous element\n if array[i] > array[i-1]:\n # Increment the current length\n current_length += 1\n else:\n # Update the maximum length if the current length is greater\n max_length = max(max_length, current_length)\n # Reset the current length\n current_length = 1\n\n# Update the maximum length if the last increasing subarray is longer\nmax_length = max(max_length, current_length)\n\n# Print the maximum length of the increasing subarray\nprint(max_length)\n\n \t \t\t \t\t \t \t\t\t \t \t\t\t\t",
"from sys import stdin, stdout\r\n\r\ninput_int = lambda: int(stdin.readline())\r\ninput_ints = lambda: map(int, stdin.readline().split())\r\ninput_list = lambda: list(input_ints())\r\ninput_str = lambda: stdin.readline()[:-1]\r\n\r\nn = input_int()\r\na = input_list()\r\nr = 1\r\ncr = 1\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n cr += 1\r\n else:\r\n r = max(r, cr)\r\n cr = 1\r\nr = max(r, cr)\r\nstdout.write(f'{r}')\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nmaxl = 1\r\ncurrentl = 1\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n currentl += 1\r\n else:\r\n maxl = max(currentl, maxl)\r\n currentl = 1\r\nmaxl = max(maxl, currentl)\r\nprint(maxl)",
"n = int(input())\r\ncnt = 1\r\nl = list(map(int, input().split()))\r\nmax = 0\r\nfor i in range(len(l) - 1):\r\n if l[i] < l[i + 1]:\r\n cnt += 1\r\n else:\r\n if max < cnt:\r\n max = cnt\r\n cnt = 1\r\nif max < cnt:\r\n max = cnt\r\nprint(max)",
"n = int(input())\nniz = [int(x) for x in input().split()]\n\ndef obracun(niz):\n najveci = 1\n trenutni = 1\n\n for i in range(1, len(niz)):\n if niz[i] > niz[i-1]:\n trenutni += 1\n najveci = max(najveci, trenutni)\n else:\n trenutni = 1\n\n return najveci\n\nprint(obracun(niz))",
"n=int(input())\r\nl=list(map(int, input().split()))\r\nc=0\r\nmax=0\r\nfor i in range(len(l)):\r\n if i==n-1:\r\n c+=1\r\n if max<c:\r\n max=c\r\n elif(l[i]<l[i+1]):\r\n c+=1\r\n else:\r\n c+=1\r\n if max<c:\r\n max=c\r\n c=0\r\nprint(max)\r\n",
"c = 1\nans = 1\nn = int(input())\nnum = [int(i) for i in input().split()]\nfor i in range(1,n):\n if num[i]>num[i-1]:\n c += 1\n else:\n c=1\n ans = max(ans,c)\nprint(ans)",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nhlp = []\r\nhlp.append([])\r\nk = 0\r\ni = 0\r\nif len(arr) == 1:\r\n print(1)\r\nelse:\r\n while i < n-1:\r\n hlp[k].append(arr[i])\r\n while i < n - 1 and arr[i] < arr[i+1]:\r\n hlp[k].append(arr[i+1])\r\n i += 1\r\n k += 1\r\n hlp.append([])\r\n i += 1\r\n\r\n mx = 0\r\n for i in range(k):\r\n if len(hlp[i]) > mx:\r\n mx = len(hlp[i])\r\n print(mx)",
"n = int(input())\r\narr = list(map(int,input().split(\" \")))\r\nlength = 0\r\ncurrlength = 0\r\ncurr = 0\r\nfor i in range(n):\r\n if arr[i]>curr:\r\n currlength+=1\r\n else:\r\n length = max(length,currlength)\r\n currlength = 1\r\n curr = arr[i]\r\nlength = max(length,currlength)\r\nprint(length)",
"n = int(input())\r\nl = list(map(int,input().split()))\r\n\r\nmaxcount = 0\r\n\r\ncurrcount = 1\r\nfor i in range(1,n):\r\n if(l[i]>l[i-1]):\r\n currcount += 1\r\n else:\r\n maxcount = max(maxcount,currcount)\r\n currcount = 1\r\nmaxcount = max(maxcount,currcount)\r\n\r\nprint(maxcount)",
"n=int(input())\r\nnumbers=list(map(int,input().split()))\r\ndp=[1]\r\nmax_subarray=1\r\n\r\nfor i in range(1,len(numbers)):\r\n \r\n if numbers[i]>numbers[i-1]:\r\n dp.append(dp[i-1]+1)\r\n if dp[i]>max_subarray:\r\n max_subarray=dp[i]\r\n else:\r\n dp.append(1)\r\nprint(max_subarray)",
"n = int(input())\r\na = list(map(int,input().split()))\r\nprev = a[0]\r\ncount = 1\r\ns = [1]\r\nfor i in range(1,n):\r\n if(a[i])>prev:\r\n count += 1\r\n else:\r\n count = 1\r\n prev = a[i]\r\n s.append(count)\r\nprint(max(s))",
"def main():\r\n n = int(input())\r\n a = [int(i) for i in input().split()]\r\n curr_max = 1\r\n mx = 1\r\n for i in range(1, n):\r\n if a[i] > a[i-1]:\r\n curr_max += 1\r\n else:\r\n mx = max(mx, curr_max)\r\n curr_max = 1\r\n print(max(curr_max, mx))\r\n\r\n\r\nmain()",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=1\r\nans=0\r\nfor x in range(1,n):\r\n if a[x-1]<a[x]:s+=1\r\n else:\r\n ans=max(ans,s)\r\n s=1\r\nprint(max(ans,s))",
"input()\r\nl=list(map(int,input().split()))\r\nc=1\r\nmaxlist=[1]\r\nfor i in range(len(l)-1):\r\n if l[i]<l[i+1]:\r\n c+=1\r\n maxlist.append(c)\r\n else:\r\n c=1\r\nprint(max(maxlist))",
"n = int(input())\r\nls = list(map(int, input().split()))\r\n\r\ncount = 1\r\nmaxTillNow = 1\r\nfor i in range(n - 1):\r\n if ls[i] < ls[i + 1]:\r\n count += 1\r\n maxTillNow = max(count, maxTillNow)\r\n else:\r\n count = 1\r\n\r\nprint(maxTillNow)",
"n = int(input())\nl = list(map(int, input().split()))\n\ni=0\nmax = 1\nwhile(i < n):\n count = 1\n while i<n-1 and l[i] < l[i+1]:\n i += 1\n count += 1\n if count > max:\n max = count\n i += 1\n \nprint(max)\n \n \t \t \t\t \t \t \t\t \t\t \t",
"a = int(input())\r\nb = list(map(int,input().split()))\r\np,c,m=0,0,0\r\nfor x in b:\r\n if x>p:\r\n c+=1\r\n else:\r\n c=1\r\n m=max(c,m)\r\n p=x\r\nprint(m)",
"input()\r\nv = s = r = 0\r\nfor x in map(int, input().split()):\r\n s = s + 1 if x > v else 1\r\n v = x\r\n r = max(r, s)\r\nprint(r)",
"'''f = open('702A.INP')\r\ng = open('702A.OUT','w')\r\n\r\nimport sys\r\nsys.stdin = f\r\nsys.stdout = g\r\n'''\r\nn= int(input())\r\na=[*map(int,input().split())]\r\n\r\nc=[1]*n\r\nfor i in range(n-1,-1,-1):\r\n\tfor j in range(i-1,-1,-1):\r\n\t\tif a[i]>a[j] : \r\n\t\t\tc[j]+=c[i]\r\n\t\t\tbreak;\r\n\t\telse :\r\n\t\t\tbreak\r\n\t#print(c)\r\nprint(max(c))\r\n\r\n#f.close(); g.close()",
"ints = lambda: list(map(int, input().split()))\r\ntw = lambda n: (n&(n-1)==0) and n!=0\r\n\r\ndef solve():\r\n # by Azimjonm2333\r\n n=int(input())\r\n a=ints()\r\n mx=1\r\n s=1\r\n for i in range(n-1):\r\n if a[i]<a[i+1]: s+=1\r\n else:\r\n if mx<s: mx=s\r\n s=1\r\n if mx<s: mx=s\r\n print(mx)\r\n\r\nt=1\r\n# t=int(input())\r\nfor i in range(t): solve()",
"n = int(input())\r\ndata = list(map(int, input().split()))\r\nanswer = 1\r\na = []\r\nfor i in range(1, n):\r\n if data[i - 1] < data[i]:\r\n a.append(data[i])\r\n else:\r\n answer = max(len(a) + 1, answer)\r\n a = []\r\nanswer = max(len(a) + 1, answer)\r\nprint(answer)\r\n",
"n=int(input())\r\nk=1\r\nb=[]\r\na=list(map(int,input().split()))\r\nfor i in range(len(a)-1):\r\n if a[i]<a[i+1]:\r\n k+=1\r\n else:\r\n b.append(k)\r\n k=1\r\nb.append(k)\r\nprint(max(b))",
"n = int(input()) # Read the number of integers\r\narr = list(map(int, input().split())) # Read the array of integers\r\n\r\n# Initialize max_length and current_length\r\nmax_length = 1\r\ncurrent_length = 1\r\n\r\n# Iterate through the array and evaluate the length of increasing subarrays\r\nfor i in range(1, n):\r\n if arr[i] > arr[i-1]:\r\n # Increment current_length if this element is greater than the previous element\r\n current_length += 1\r\n # Update max_length if necessary\r\n max_length = max(max_length, current_length)\r\n else:\r\n # If the subarray is not increasing anymore, reset current_length to 1\r\n current_length = 1\r\n\r\n# Output max_length\r\nprint(max_length)",
"n = int(input())\r\narray = list(map(int,input().split()))\r\n\r\nans = [1]*n\r\nfor i in range(n-1):\r\n if array[i] < array[i+1]:\r\n ans[i+1] = ans[i]+1\r\n\r\nprint(max(ans))",
"n = int(input())\r\nA = [int(p) for p in input().split()]\r\na = []\r\nhub = []\r\nx = 0\r\nfor i in range (n):\r\n if A[i] > x:\r\n a.append(A[i])\r\n x = A[i]\r\n else:\r\n hub.append(len(a))\r\n a = [A[i]]\r\n x = A[i]\r\n if i == n-1:\r\n hub.append(len(a))\r\nprint(max(hub))",
"def main():\r\n n = int(input())\r\n a = [int(i) for i in input().split()]\r\n a.append(-1000000000)\r\n k = 1\r\n maxi = 0\r\n for i in range(1, len(a)):\r\n if a[i] > a[i - 1]:\r\n k += 1\r\n else:\r\n if k > maxi:\r\n maxi = k\r\n k = 1\r\n print(maxi)\r\nif __name__ == '__main__':\r\n main()",
"def maximumIncrease(arr):\r\n count = 1\r\n maxCount = 1 \r\n\r\n for i in range(1, len(arr)):\r\n if arr[i] > arr[i - 1]:\r\n count += 1\r\n else:\r\n count = 1\r\n maxCount = max(maxCount, count)\r\n return maxCount\r\n\r\nn = int(input())\r\ninputString = input()\r\n\r\narr = [int(x) for x in inputString.split()]\r\nprint(maximumIncrease(arr))\r\n",
"n = int(input())\r\narr = [None] * n\r\na = input().split()\r\n\r\nfor i in range(n):\r\n arr[i] = int(a[i])\r\n\r\ncount = 1\r\nmax = 1\r\n\r\nfor i in range(1, n):\r\n if arr[i] > arr[i - 1]:\r\n count += 1\r\n else:\r\n if count > max:\r\n max = count\r\n count = 1\r\nif count > max:\r\n max = count\r\n\r\nprint(max)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=1\r\nb=0\r\nfor j in range(1,len(l)):\r\n if(l[j]>l[j-1]):\r\n c+=1\r\n else:\r\n b=max(b,c)\r\n c=1\r\nb=max(c,b)\r\nprint(b)",
"n = int(input())\nintegers = list(map(int, input().split()))\ncount = 1\nmax = 1\n\nfor i in range(1, n):\n if integers[i] > integers[i - 1]:\n count += 1\n\n else:\n if count > max:\n max = count\n count = 1\n\nif count > max:\n max = count\nprint(max)\n\n \t\t\t \t\t \t \t\t\t \t \t \t\t \t \t \t",
"t = int(input())\r\na = [int(x) for x in input().split()]\r\nn = []\r\nr = 1\r\nfor i in range(t-1):\r\n if a[i+1] > a[i]:\r\n r += 1\r\n else:\r\n n.append(r)\r\n r = 1\r\n continue\r\nn.append(r)\r\nprint(max(n))\r\n\r\n\r\n\r\n",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nans=1\r\ni=1\r\nfor x in range(1,n):\r\n if arr[x]>arr[x-1]:\r\n i+=1\r\n else:\r\n ans=max(ans,i)\r\n i=1\r\nprint(max(ans,i))",
"import sys\r\nif sys.platform =='ios':\r\n\timport clipboard\r\n\ta=clipboard.get()\r\n\ta = a.split('\\n')\r\n\ttext = '\\n'.join(a)\r\n\twith open('input_file.txt','w') as f:\r\n\t\tf.write(text)\r\n\tsys.stdin = open('input_file.txt')\r\nsys.setrecursionlimit(410000000)\r\nstdin = sys.stdin \r\nni = lambda: int(ns())\r\nna = lambda: list(map(int, stdin.readline().split()))\r\nns = lambda: stdin.readline().strip()\r\nnm = lambda: map(int,input().split())\r\nna_1 = lambda: list(map(lambda x:int(x)*(-1), stdin.readline().split()))\r\nna_2 = lambda: list(map(lambda x:int(x)-1, stdin.readline().split()))\r\n\r\nfrom bisect import bisect_left\r\n\r\nN = int(input())\r\nA = list(map(int, input().split()))\r\n\r\nINF = 10 ** 10\r\n\r\ndp = [-INF] * (N+2)\r\n\r\n\r\ndp[0] = 1\r\nfor i in range(1,N):\r\n\tif A[i-1] < A[i]:\r\n\t\tdp[i] = dp[i-1]+1\r\n\telse:\r\n\t\tdp[i] = 1\r\nans = 0\r\nprint(max(dp))",
"n = int(input())\r\nk = [int(i) for i in input().split()]\r\nmx = 0\r\nm = 1\r\nfor i in range(len(k) - 1):\r\n if k[i] < k[i+1]:\r\n m+=1 \r\n else:\r\n if mx < m:\r\n mx = m\r\n m = 1\r\nif mx < m:\r\n mx = m\r\nprint(mx)",
"def solucion(arr):\n maxLength = length = 1\n for i in range(1, len(arr)):\n if arr[i] > arr[i-1]:\n length += 1\n else:\n if length > maxLength:\n maxLength = length\n length = 1\n if length > maxLength:\n maxLength = length\n return maxLength\n\n\nn = int(input())\nbids = list(map(int, input().split()))\nprint(solucion(bids))\n\n\t\t\t \t \t\t\t\t\t\t \t \t \t\t \t\t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\nmx = 1\r\nstart = 0\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n mx = max(mx, i - start + 1)\r\n else:\r\n mx = max(mx, i - start)\r\n start = i\r\nmx = max(mx, n - start)\r\nprint(mx)\r\n",
"n = int(input())\nnums = [int(x) for x in input().split(\" \")]\n\nmaxlen = 1\ncurrlen = 1\n\nfor i in range(1,n):\n if nums[i]>nums[i-1]:\n currlen+=1\n maxlen = max(maxlen,currlen)\n else:\n currlen=1\n\nprint(maxlen)\n",
"length = int(input())\r\nnumbers = [int(x) for x in input().split()]\r\nsum1,sum2 = 0,1\r\n\r\nfor i in range(1,length):\r\n if numbers[i-1] < numbers[i]:\r\n sum2 += 1\r\n elif sum2 > sum1:\r\n sum1 = sum2\r\n sum2 = 1\r\n else:\r\n sum2 = 1\r\n\r\nif sum2 > sum1:\r\n print(sum2)\r\nelse:\r\n print(sum1)\r\n ",
"n = int(input())\r\nl_n = list(map(int, input().split()))\r\n\r\nl = 1\r\nm = 1\r\nfor i in range(1, n):\r\n if l_n[i] > l_n[i - 1]:\r\n l += 1\r\n else:\r\n l = 1\r\n m = max(l, m)\r\nprint(m)\r\n ",
"# list(map(int,input()))\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nj=1\r\nres=1\r\nwhile(j<n):\r\n t=j\r\n while(j<n and a[j]>a[j-1]):\r\n j+=1\r\n j+=1\r\n res=max(res,j-t)\r\nprint(res)",
"n = int(input())\na = list(map(int,input().split()))\nb,c,d=0,0,0\nfor i in a:\n\tif i > b:\n\t\tc+=1\n\telse:\n\t\tc=1\n\td = max(c, d)\n\tb = i\nprint(d)\n\t\t\t\t \t \t\t\t\t \t\t \t\t \t \t\t \t\t\t\t",
"n = int(input())\r\ndata = input().split()\r\na = [int(x) for x in data]\r\nans = 1\r\nleng = 1\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n leng += 1\r\n else:\r\n ans = max(leng, ans)\r\n leng = 1\r\nprint(max(ans, leng))",
"if 1:\n from sys import stdin\n line = iter(stdin.read().split('\\n'))\nelse:\n with open('inputs.txt', 'r') as file: line = iter(file.read().split('\\n'))\n# input = lambda: next(line)\n# ii = lambda: int(input())\n# mi = lambda: map(int, input().split())\n\nmaxincrease = increase = 0\nfor i in range(int(next(line))):\n if i:\n if n[i - 1] < n[i]: increase += 1\n else:\n if maxincrease < increase: maxincrease = increase\n increase = 0\n else: n = tuple(map(int, next(line).split()))\n\n\nprint(max(maxincrease, increase) + 1)",
"n = int(input())\r\nl = list(map(int, input().split()))\r\ndp = [1] * n\r\n\r\nfor i in range(1, len(l)):\r\n if l[i] > l[i - 1]:\r\n dp[i] = dp[i - 1] + 1\r\nprint(max(dp))",
"result = []\r\nlength = int(input())\r\nelements = list(map(int, input().split(\" \")))\r\ncounter = 1 # Initialize counter to 1 since the first element is always part of an increasing sequence\r\nmax_counter = 1 # Initialize max_counter to 1\r\n\r\nfor i in range(1, len(elements)): # Start the loop from index 1\r\n previos = elements[i - 1]\r\n current = elements[i]\r\n\r\n if current > previos:\r\n counter += 1\r\n else:\r\n counter = 1 # Reset the counter when the sequence breaks\r\n\r\n if counter > max_counter:\r\n max_counter = counter\r\n\r\nprint(max_counter)\r\n",
"input()\r\na = list(map(int, input().split()))\r\naa = 1\r\nlast = a[0]\r\nhis = []\r\n\r\nfor i in a[1:]:\r\n if i > last:\r\n aa += 1\r\n else:\r\n his.append(aa)\r\n aa = 1\r\n last = i \r\nhis.append(aa)\r\n\r\nprint(max(his))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nmxlocal=1\r\nmxglobal=1\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n mxlocal+=1\r\n else:\r\n mxlocal=1\r\n mxglobal=max(mxglobal,mxlocal)\r\nprint(mxglobal)\r\n",
"from collections import Counter\r\n\r\ndef solution(arr, n):\r\n if n < 2:\r\n return n\r\n \r\n ans = 0\r\n l, r = 0, 1\r\n\r\n while r < n:\r\n if arr[r] > arr[r-1]:\r\n r += 1\r\n else:\r\n l = r\r\n r += 1\r\n ans = max(ans, r - l + 1)\r\n\r\n return ans-1\r\n\r\ndef driver():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n sol = solution(arr, n)\r\n print(sol)\r\n return\r\n\r\ndriver()",
"n = int(input()) \narr = list(map(int, input().split())) \n\ndef tamanoSubArr(arr, n) :\n\n\tm = 1\n\tl = 1\n\n\tfor i in range(1, n) :\n\n\t\tif (arr[i] > arr[i-1]) :\n\t\t\tl =l + 1\n\t\telse :\n\n\t\t\tif (m < l) :\n\t\t\t\tm = l\n\n\t\t\tl = 1\n\t\t\n\tif (m < l) :\n\t\tm = l\n\n\treturn m\n\nprint(tamanoSubArr(arr, n))\n \t\t \t\t \t\t\t \t \t\t\t \t\t \t",
"def subarray(n):\n arr = []\n input_str = input()\n input_list = input_str.split()\n \n for num_str in input_list:\n e = int(num_str)\n arr.append(e)\n\n max_len = 1\n current_len = 1\n\n for j in range(1, len(arr)):\n if arr[j] > arr[j - 1]:\n current_len += 1\n else:\n current_len = 1\n\n max_len = max(max_len, current_len)\n\n print(max_len)\n\nn = int(input())\nsubarray(n)\n\n \t\t\t\t \t\t\t \t\t \t\t \t \t\t\t\t\t \t \t",
"n=int(input())\r\nmax=0\r\ncounter=0\r\nparsa=list(map(int,input().split()))\r\nfor i in range(0,len(parsa)-1,1):\r\n if parsa[i+1]>parsa[i]:\r\n counter+=1\r\n if max<counter:\r\n max=counter\r\n else:\r\n counter=0\r\nprint(max+1)",
"import sys\r\nn = int(input())\r\narr = [int(i) for i in sys.stdin.readline().split()]\r\nans = 0\r\narr1 = [0]\r\nfor i in range(1, len(arr)):\r\n if arr[i - 1] < arr[i]:\r\n ans += 1\r\n else:\r\n arr1.append(ans)\r\n ans = 0\r\nprint(max(ans, max(arr1)) + 1)",
"n=int(input())\r\nf=list(map(int,input().split()))\r\nc=1\r\nd=[1]\r\nfor i in range(1,n):\r\n if f[i-1]<f[i]:\r\n c+=1\r\n else:\r\n d.append(c)\r\n c=1\r\nd.append(c)\r\nprint(max(d))",
"n = int(input())\r\nl = *(map(int,input().split())),\r\nm = -10**10\r\ncnt = 1\r\nfor i in range(1,n):\r\n if(l[i-1]<l[i]): cnt += 1\r\n else: m = max(m,cnt); cnt = 1\r\nprint(max(m,cnt))",
"n = int(input())\r\ns = list(map(int,input().split(\" \")))\r\nf = [1]*n\r\nfor i in range(n-1):\r\n if s[i+1] > s[i]:\r\n f[i+1] = (f[i] + 1)\r\nprint(max(f))",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nans = 0\r\nc = 0\r\nfor i in range(n-1):\r\n if l[i+1]>l[i]:\r\n c+=1\r\n ans = max(ans,c)\r\n else:\r\n c = 0\r\n\r\nprint(ans+1)",
"l=int(input())\r\na=list(map(int,input().split()))\r\nc=0 \r\nm=1\r\nfor i in range(l):\r\n if i==0:\r\n c=1 \r\n elif a[i-1]<a[i]:\r\n c+=1\r\n if c>m:\r\n m=c \r\n else:\r\n c=1\r\n \r\nprint(m) \r\n ",
"input();v=s=r=0\r\nfor x in map(int,input().split()):s=s+1 if x>v else 1;v=x;r=max(r,s)\r\nprint(r)",
"# Read the number of integers\nn = int(input())\n\n# Read the array of integers\na = list(map(int, input().split()))\n\ndp = [1] * n # Initialize dp array with all elements as 1\n\n# Iterate through the array\nfor i in range(1, n):\n if a[i] > a[i-1]:\n dp[i] = dp[i-1] + 1\n\n# Find the maximum length in dp array\nmax_length = max(dp)\n\n# Print the maximum length of an increasing subarray\nprint(max_length)\n\n\n\n \t\t\t\t\t\t \t\t \t\t\t \t \t \t \t\t\t",
"n=int(input())\r\nx=list(map(int,input().split()))\r\nans=[1]\r\nsum=1\r\nfor i in range(n-1):\r\n if x[i+1]>x[i]:\r\n sum+=1\r\n ans.append(sum)\r\n else:\r\n sum=1\r\nprint(max(ans))",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nM=1\r\nle=1\r\nstartInd=0\r\nEndInd=1\r\nwhile startInd<n-1 and EndInd<n:\r\n if arr[startInd]<arr[EndInd]:\r\n le+=1\r\n else:\r\n M=max(M,le)\r\n le=1\r\n startInd+=1\r\n EndInd+=1\r\nprint(max(M,le))",
"n = int(input())\narr = list(map(int, input().split()))\n\nmax_len = 1 # At least one element is always there\ncurrent_len = 1\n\nfor i in range(1, n):\n if arr[i] > arr[i-1]:\n current_len += 1\n max_len = max(max_len, current_len)\n else:\n current_len = 1\n\nprint(max_len)\n\n\t \t \t\t \t\t\t \t\t\t\t \t\t \t\t\t\t\t\t\t",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nm = c = 1\r\nfor i in range(1,n):\r\n if l[i] > l[i-1]:\r\n c += 1\r\n m = max(m,c)\r\n else:\r\n c = 1\r\n\r\nprint(m)",
"input(\"\")\nnums = list(map(int, input(\"\").split(' ')))\n\nmax_run = 1\ncurr_run = 1\nprevious = nums[0]\nfor num in nums[1:]:\n if num > previous:\n curr_run += 1\n else:\n curr_run = 1\n max_run = max(max_run, curr_run)\n previous = num\nprint(max_run)\n",
"n=int(input())\narr=list(map(int,input().split()))\n#dp=[0 for i in range(n)]\nc=1\nans=0\nfor i in range(n-1):\n if arr[i]<arr[i+1]:\n c+=1 \n else:\n ans=max(ans,c)\n c=1 \nans=max(ans,c)\nprint(ans)\n",
"n = int(input())\r\nmas = list(map(int, input().split()))\r\nmas.append(0)\r\nc = []\r\nk = 0\r\nfor i in range(len(mas) - 1):\r\n if mas[i] < mas[i + 1]:\r\n k += 1\r\n else:\r\n c.append(k)\r\n k = 0\r\n\r\n\r\nprint(max(c) + 1)",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nprev=a[0]\r\nans=0\r\ncount=1\r\nfor i in range(1,n):\r\n\tif a[i]>prev:\r\n\t\tcount+=1\r\n\telse:\r\n\t\tif count>ans:\r\n\t\t\tans=count\r\n\t\tcount=1\r\n\tprev=a[i]\r\nif count>ans:\r\n\tans=count\r\nprint(ans)",
"import sys\r\n# sys.stdin = open(\"input.txt\", \"r\")\r\n# sys.stdout = open(\"output.txt\", \"w\")\r\n# sys.stderr = open(\"error.txt\", \"w\")\r\n# # your remaining code\r\n\r\n\r\nt = int(input())\r\na = list(map(int,input().split()))\r\n\r\n_global = 1\r\n_local = 1\r\n\r\nfor i in range(len(a)-1) :\r\n\r\n\tif a[i] < a[i+1] :\r\n\t\t_local += 1\r\n\telse :\r\n\t\tif _local > _global :\r\n\t\t\t_global = _local\r\n\t\t_local = 1\r\nif _local > _global :\r\n\t_global = _local\r\n\r\nprint(_global)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"from typing import List, Union\r\nfrom collections import namedtuple\r\nimport sys\r\nimport traceback\r\nfrom time import perf_counter\r\n\r\n\r\nclass Solution:\r\n def maximum_increase(self, nums: List[int]):\r\n max_count = 0\r\n count = 0\r\n prev_n = -1\r\n for n in nums:\r\n if n > prev_n:\r\n prev_n = n\r\n count += 1\r\n else:\r\n max_count = max(max_count, count)\r\n count = 1\r\n prev_n = n\r\n max_count = max(max_count, count)\r\n print(max_count)\r\n return max_count\r\n\r\n\r\nTestCase = namedtuple('TestCase', 'nums correct')\r\n\r\n\r\ndef read_test_cases(input_file, output_file):\r\n test_cases = []\r\n try:\r\n with open(input_file) as in_f:\r\n test_num = int(in_f.readline())\r\n with open(output_file) as out_f:\r\n for _ in range(test_num):\r\n arr_len = int(in_f.readline())\r\n nums = in_f.readline().strip().split(' ')\r\n nums = [int(n) for n in nums]\r\n correct = int(out_f.readline())\r\n t = TestCase(nums, correct)\r\n test_cases.append(t)\r\n # raise Exception('My New Exception')\r\n except Exception as exc:\r\n exc_name = exc.__class__.__name__\r\n exc_msg = str(exc)\r\n exc_info = sys.exc_info()\r\n print('EXCEPTION:', exc_name, exc_msg)\r\n traceback.print_exception(*exc_info)\r\n return test_cases\r\n\r\n\r\nif __name__ == '__main__':\r\n if len(sys.argv) > 1 and '--debug' in sys.argv:\r\n test_cases = read_test_cases('data/input.txt', 'data/output.txt')\r\n start_counter = perf_counter()\r\n for t in test_cases:\r\n result = Solution().maximum_increase(t.nums)\r\n print('NUMS:', t.nums, 'CORRECT:', t.correct, 'RESULT:', result, 'CHECK:', result == t.correct)\r\n stop_counter = perf_counter()\r\n print('COUNTER:', stop_counter - start_counter)\r\n else:\r\n arr_len = int(input())\r\n nums = input().strip().split(' ')\r\n nums = [int(n) for n in nums]\r\n Solution().maximum_increase(nums)",
"n = int(input())\r\nx = [int(x) for x in input().split()]\r\nmaxLen = 0\r\nlen = 1\r\nfor i in range(1, n):\r\n if x[i] > x[i - 1]:\r\n len += 1\r\n else:\r\n maxLen = max(maxLen, len)\r\n len = 1\r\nmaxLen = max(maxLen, len)\r\nprint(maxLen)\r\n",
"def solve(l):\r\n max_s = 1\r\n s = 1\r\n for i in range(len(l)-1):\r\n if l[i] < l[i+1]:\r\n s += 1\r\n if s > max_s:\r\n max_s = s\r\n else:\r\n s = 1\r\n return max_s\r\n \r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nprint(solve(l))",
"\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nans= -1e9\r\ni=0\r\nj=1\r\nwhile i<n and j<n:\r\n start=i\r\n while i<n and j<n and arr[i]<arr[j]:\r\n i+=1\r\n j+=1\r\n ans=max(ans,j-start)\r\n i=j\r\n j=i+1\r\nif n==1:\r\n print(1)\r\nelse:\r\n print(ans)\r\n ",
"import math\n\nclass Solution:\n\n\tdef maxLen(self, nums, n) -> None:\n\n\t\tl, h = 0, 0\n\t\tmaxi = 1\n\n\t\twhile h < n - 1:\n\t\t\tif nums[h] < nums[h + 1]:\n\t\t\t\th += 1\n\t\t\t\tmaxi = max(maxi, h - l + 1)\n\t\t\telse:\n\t\t\t\th += 1\n\t\t\t\tl = h\n\t\t\t\n\t\t\n\t\tprint(maxi)\n\t\treturn\n\n\ndef main():\n\tn = int(input())\n\n\tnums = list(map(int, input().strip().split()))\n\n\tsol = Solution()\n\n\tsol.maxLen(nums, n)\n\n\nif __name__ == '__main__':\n\n\tmain()",
"n=int(input())\r\nl=[int(x) for x in input().split(\" \")]\r\ncount=0\r\ntemp=1\r\nfor i in range(len(l)-1):\r\n if l[i+1]>l[i]:\r\n temp+=1\r\n else: \r\n if temp>count:\r\n count=temp\r\n temp=1\r\nif temp>count:\r\n print(temp)\r\nelse:\r\n print(count)",
"N = int(input())\r\nA = list(map(int, input().split()))\r\n\r\ndp = [1]*N\r\n\r\nfor i in range(1, N):\r\n if A[i] > A[i-1]:\r\n dp[i] = dp[i-1]+1\r\n else:\r\n dp[i] = 1\r\n \r\nprint(max(dp))",
"n=int(input())\r\narr=list(map(int,input().split()))\r\ndef max_subarray(arr):\r\n cnt=1\r\n maxi=0\r\n n=len(arr)\r\n for i in range(1,n):\r\n if arr[i-1]<arr[i]:\r\n cnt+=1\r\n else:\r\n maxi=max(maxi,cnt)\r\n cnt=1\r\n return max(maxi,cnt)\r\nprint(max_subarray(arr))",
"n=int(input(''))\r\nl=list(map(int,input().split()))\r\nm,c=[],0\r\nfor i in range(n-1):\r\n if l[i+1]>l[i]:\r\n c+=1\r\n m.append(c)\r\n else:\r\n c=0\r\nif len(m)>0:\r\n print(max(m)+1)\r\nelse:\r\n print(1)",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nk = 1\r\nans = 1\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n k += 1\r\n ans = max(ans, k)\r\n else:\r\n k = 1\r\nprint(ans)",
"n=int(input())\r\nnums=list(map(int,input().split()))\r\nans,count=1,1\r\nfor i in range(n-1):\r\n if nums[i]>=nums[i+1]:\r\n ans=max(ans,count)\r\n count=1\r\n else:\r\n count+=1\r\n ans=max(ans,count)\r\nprint(ans)",
"N = int(input())\r\nli = [*map(int,input().split())]\r\nmx = 1\r\ntemp=1\r\nfor i in range(len(li)-1):\r\n j=i+1\r\n if li[i]<li[j]:\r\n temp+=1\r\n else:\r\n mx = max(temp,mx)\r\n temp=1\r\n mx = max(temp,mx)\r\nprint(mx)",
"n=int(input())\r\nlis=list(map(int,input().split()))\r\ncount=1\r\nmaxm=1\r\nfor i in range(n-1):\r\n if lis[i]<lis[i+1]:\r\n count+=1\r\n else:\r\n count=1\r\n maxm=max(maxm,count)\r\nprint(maxm) ",
"n = int(input())\na = list(map(int, input().split()))\n\ndp = [0] * n\ndp[0] = 1\nmmax = 1\n\nfor i in range(1, n):\n if a[i] > a[i - 1]:\n dp[i] = dp[i - 1] + 1\n if dp[i - 1] == mmax:\n mmax += 1\n else:\n dp[i] = 1\nprint(mmax)\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nmax_len = 1\r\ncurr_len = 1\r\n\r\nfor i in range(1, n):\r\n if a[i] > a[i-1]:\r\n curr_len += 1\r\n else:\r\n max_len = max(max_len, curr_len)\r\n curr_len = 1\r\n\r\nmax_len = max(max_len, curr_len)\r\n\r\nprint(max_len)\r\n",
"length = int(input())\r\nnumbers = list(map(int, input().split()))\r\n\r\nmaxi = 1\r\ncurrent = 1\r\nfor i in range(length - 1):\r\n if numbers[i + 1] > numbers[i]:\r\n current += 1\r\n else:\r\n if current > maxi:\r\n maxi = current\r\n current = 1\r\n\r\nif current > maxi:\r\n maxi = current\r\n\r\nprint(maxi)",
"def ret_max_n(my_arr,n):\r\n maxi = 1\r\n t_m = 1\r\n \r\n for i in range(1, n):\r\n if (my_arr[i] > my_arr[i - 1]):\r\n t_m += 1\r\n \r\n else:\r\n if (t_m > maxi):\r\n maxi = t_m\r\n \r\n t_m = 1\r\n \r\n if (maxi > (n - i)):\r\n break\r\n \r\n \r\n if (t_m > maxi):\r\n return t_m\r\n \r\n return maxi\r\n \r\n \r\nn = int(input())\r\narr = list(map(int, input().strip().split()))\r\n\r\nprint(ret_max_n(arr, n))",
"\nn = int(input())\nsa = input().split()\na = [0] * n\nfor i in range(n):\n a[i] = int(sa[i])\nstates = [1] * n\nfor i in range(1, n):\n if (a[i] > a[i-1]):\n states[i] = states[i-1] + 1\nprint(max(states))\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=1\r\ns=1\r\nfor i in range(1,n):\r\n if l[i]>l[i-1]:\r\n s+=1\r\n m=max(m,s)\r\n else:\r\n s=1\r\nprint(m)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ncs=1\r\nc=1\r\nfor i in range(1,n):\r\n if l[i]>l[i-1]:\r\n c+=1\r\n else:\r\n cs=max(cs,c)\r\n c=1\r\ncs=max(cs,c)\r\nprint(cs)",
"n = int(input()) \r\nt = list(map(int, input().split())) \r\n\r\nm = 1\r\nc = 1 \r\nfor i in range(1, n):\r\n if t[i] > t[i - 1]:\r\n c += 1\r\n else:\r\n if c >m :\r\n m = c\r\n c = 1\r\n\r\nif c > m:\r\n m = c\r\n\r\nprint(m) \r\n",
"import sys\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport itertools\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict, Counter, deque\r\nfrom bisect import bisect_left,bisect_right, insort_left, insort_right\r\n\r\nmod=1000000007\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\ndef get_int(): return int(sys.stdin.readline().strip())\r\ndef get_list_strings(): return list(map(str, sys.stdin.readline().strip().split()))\r\n\r\n\r\n\r\ndef solve():\r\n n =get_int()\r\n nums = get_list()\r\n dp = [1] * n\r\n ans = 1\r\n for i in range(len(nums)-2, -1, -1):\r\n if nums[i] < nums[i + 1]:\r\n dp[i] = dp[i + 1] + 1\r\n ans = max(dp[i], ans)\r\n return ans\r\n \r\n \r\n \r\n#main code\r\nif __name__ == \"__main__\":\r\n print(solve())",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nm, count = 0, 1\r\nfor i in range(n-1):\r\n if l[i] < l[i+1]:\r\n count += 1\r\n else:\r\n if m < count:\r\n m = count\r\n count = 1\r\nif m < count:\r\n m = count\r\nprint(m)",
"\r\n# problem/702/A\r\n\r\nn = int(input());\r\na = input().split(\" \");\r\na = [int(a[i]) for i in range(n)];\r\n\r\n# (maxlength so far, last mismatch except initial 0)\r\nmaxlengthsofar = 1;\r\nc =1;\r\nfor i in range(1,n):\r\n if i==0:\r\n k = a[i]\r\n else:\r\n k = a[i-1]\r\n # if found smaller element or reached end\r\n if (a[i]<=k) :\r\n maxlengthsofar = max(c, maxlengthsofar);\r\n c=1;\r\n continue;\r\n c +=1;\r\n maxlengthsofar = max(c, maxlengthsofar);\r\n \r\n\r\nprint(maxlengthsofar);\r\n",
"import sys\r\n\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\nt = int(input())\r\nl = list(map(int, input().split()))\r\nans = 1\r\nmans = 1\r\nfor i in range(t - 1):\r\n if l[i] < l[i + 1]:\r\n ans += 1\r\n else:\r\n mans = max(mans, ans)\r\n ans = 1\r\nmans = max(mans, ans)\r\nprint(mans)\r\n",
"input();v=s=r=0\r\nfor x in map(int,input().split()):\r\n s=s+1 if x>v else 1\r\n v=x;r=max(r,s)\r\nprint(r)",
"n = int(input())\r\na = [int(t) for t in input().split()]\r\n\r\ncur = 1\r\nans = 1\r\nfor i in range(n-1):\r\n if a[i]<a[i+1]:\r\n cur += 1\r\n else:\r\n cur = 1\r\n ans = max(ans, cur)\r\n\r\n\r\nprint(ans)",
"n = int(input())\r\narr = input().split()\r\nfor i in range(n):\r\n arr[i] = int(arr[i])\r\nmax_len = 1\r\nlens = []\r\nfor i in range(n - 1):\r\n if arr[i] < arr[i + 1]:\r\n max_len += 1\r\n else:\r\n lens.append(max_len)\r\n max_len = 1\r\nlens.append(max_len)\r\nprint(max(lens))",
"a = int(input())\r\nb = [int(i) for i in input().split(\" \")]\r\nk = 1\r\nm = 1\r\nfor i in range(1, a):\r\n if b[i] > b[i - 1]:\r\n k += 1\r\n if k > m:\r\n m = k\r\n else:\r\n k = 1\r\nprint(m)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc,m=1,1\r\nfor i in range(1,n):\r\n if l[i]>l[i-1]:\r\n c+=1\r\n else:\r\n if c>m:\r\n m=c\r\n c=1\r\nif c>m:\r\n m=c\r\nprint(m)",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nans = t =1\r\nfor i in range(1,n):\r\n if l[i] > l[i-1]:\r\n t+=1\r\n ans = max(t,ans)\r\n else:\r\n t = 1\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n",
"from collections import Counter \n\ndef main1(): \n n = int(input()) \n lst = list(map(int, input().split())) \n dp = [1 for i in range(n)] \n for i in range(1, n): \n if lst[i] > lst[i-1]: \n dp[i] = dp[i-1] + 1 \n ans = 0 \n for i in range(n): \n ans = max(ans, dp[i]) \n print(ans) \n\nif __name__ == '__main__': \n t = 1\n for _ in range(t): \n main1() \n\n# 1 2\n# 0 0 true \n# 0 1 false \n# 1 0 false \n# 1 1 false \n# 2 1 true \n# ",
"n=int(input())\r\na=list(map(int,input().split()))\r\nk=1\r\nlengmax=0\r\nleng=0\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n k+=1\r\n leng=k\r\n else:\r\n k=1\r\n if leng>lengmax:\r\n lengmax=leng\r\nif leng > lengmax:\r\n lengmax = leng\r\nif lengmax==0:\r\n lengmax=1\r\nprint(lengmax)\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nmx=1\r\ns=1\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n s+=1\r\n mx=max(mx,s)\r\n else:\r\n s=1\r\nprint(mx)",
"num=int(input())\r\nli=list(map(int,input().strip().split()))\r\nx=0\r\nc=1\r\nf=0\r\nif num==1:\r\n print(1)\r\nelse:\r\n for i in range(1,num):\r\n if li[i]>li[i-1]:\r\n c+=1\r\n if i==num-1:\r\n print(max(x,c))\r\n f=1\r\n else:\r\n x=max(x,c)\r\n c=1\r\n if f==0:\r\n print(x)",
"n = int(input())\narray = map(int,input().split())\n\npre = 0\nmax_len = 1\ncount = 0\n\nfor i in array:\n if i - pre > 0:\n count += 1\n else:\n count = 1\n max_len = max(count,max_len)\n pre = i\n\nprint(max_len)\n\n",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\nc = 1\r\nd = 1\r\nfor i in range(1, len(a)):\r\n if a[i - 1] < a[i]:\r\n d += 1\r\n if d > c:\r\n c = d\r\n else:\r\n d = 1\r\nprint(c)",
"n = int(input())\r\nl = list(map(int, input().strip().split()))\r\ncount = 0\r\nmaxCount = -1\r\nfor i in range(1, n):\r\n if l[i] > l[i-1]:\r\n count += 1\r\n else:\r\n count = 0\r\n maxCount = max(maxCount, count)\r\nif n == 1:\r\n print(1)\r\nelse:\r\n print(maxCount+1)\r\n",
"n=int(input())\r\nls=list(map(int,input().split()))\r\ndp=[0]*n\r\nfor i in range(n-1):\r\n if ls[i]<ls[i+1]:\r\n dp[i]=dp[i-1]+1\r\nprint(max(dp)+1)",
"n=int(input())\r\narr=[int(k) for k in input().split()]\r\noutput=[]\r\nleng=1\r\nmaxlen=1\r\nfor i in range(n-1):\r\n if(arr[i+1]>arr[i]):\r\n leng=leng+1\r\n else:\r\n if(leng>maxlen):\r\n maxlen=leng\r\n leng=1\r\nif leng>maxlen:\r\n maxlen=leng\r\nprint(maxlen)\r\n",
"def longest_subsequence(n,nums):\r\n ans=1\r\n temp=1\r\n for i in range(1,n):\r\n\t if nums[i]>nums[i-1]:\r\n\t\t temp +=1\r\n\t else:\r\n\t\t ans=max(ans,temp)\r\n\t\t temp=1\r\n return max(temp,ans) \r\nn=int(input())\r\nnums=list(map(int,input().split()))\r\nprint(longest_subsequence(n,nums))",
"#P\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\nm = 1\r\nc = 1\r\nfor i in range(1, len(a)):\r\n if (a[i-1]<a[i]):\r\n c+=1\r\n else :\r\n c = 1\r\n m = max(m, c)\r\nprint(m)",
"n = int(input())\r\nl = list(map(int,input().split()))\r\n\r\ndp = [1]*n\r\n\r\ni=1\r\nwhile i < n:\r\n if l[i]>l[i-1]:\r\n dp[i]=dp[i-1]+1\r\n i+=1\r\n\r\nprint(max(dp))",
"n = int(input())\r\narr = input().split()\r\narr = [int(_) for _ in arr]\r\nmax= 1\r\ncurrentmax = 1\r\nfor i in range(n-1):\r\n if arr[i] < arr[i+1]:\r\n currentmax += 1\r\n if currentmax >= max:\r\n max = currentmax\r\n else:\r\n currentmax = 1\r\nprint(max)",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nmaxele=1\r\ncnt=1\r\nfor i in range(1,n):\r\n if lst[i-1]<lst[i]:\r\n cnt+=1\r\n else:\r\n maxele=max(cnt,maxele)\r\n cnt=1\r\nprint(max(maxele,cnt))\r\n ",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\n\r\nm = 1\r\nres = -1\r\nfor i in range(1, n):\r\n if a[i - 1] < a[i]:\r\n m += 1\r\n else:\r\n res = max(res, m)\r\n m = 1\r\nres = max(res, m)\r\nprint(res)",
"\r\nl = int(input())\r\nnums = [int(x) for x in input().split()]\r\n\r\nsize = 1\r\ncount = 1\r\nprev = nums[0]\r\n\r\nfor i in nums:\r\n if i > prev:\r\n count += 1\r\n prev = i\r\n else:\r\n if count > size:\r\n size = count\r\n count = 1\r\n prev = i\r\n\r\nif count > size:\r\n print(count)\r\nelse:\r\n print(size)",
"n = int(input())\r\naa = list(map(int,input().split()))\r\naa.append(0)\r\ni = 0\r\nmax =0\r\ncurrent=0\r\nwhile i<n:\r\n if aa[i]<aa[i+1]:\r\n i+=1\r\n max+=1\r\n else:\r\n i+=1\r\n max =0\r\n if max>current:\r\n current=max\r\nprint(current+1)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nb = []\r\ncount = 1\r\n\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n count += 1\r\n else:\r\n b.append(count)\r\n count = 1\r\nb.append(count)\r\n\r\nprint(max(b))",
"n = int(input())\na = list(map(int,input().split()))\n\nl = 0\nr = 1\nm_len = 0\nwhile(r<n):\n if(a[r]<=a[r-1]):\n m_len = max(m_len,r-l)\n l = r\n r += 1\nm_len = max(m_len,r-l)\nprint(m_len)",
"n = int(input())\na = list(map(int,input().split()))\ndp = [1]*n\nmx = 1\nfor i in range(1,n):\n if a[i]>a[i-1]:\n dp[i] = dp[i-1]+1\n mx = max(mx,dp[i])\nprint(mx)\n",
"n=int(input())\r\ns=list(map(int,input().split()))\r\nm = 1\r\nl = 1\r\nfor i in range(1, n): \r\n if (s[i] > s[i-1]):\r\n l =l + 1\r\n else:\r\n if (m < l):\r\n m = l\r\n l = 1\r\nif (m < l) :\r\n m = l\r\nprint(m)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = []\r\nfor i in range(n):\r\n if i == 0:\r\n b.append(1)\r\n else:\r\n if a[i] > a[i - 1]:\r\n b.append(b[i - 1] + 1)\r\n else:\r\n b.append(1)\r\nprint(max(b))\r\n",
"def solve(n, l):\r\n max_count = 1\r\n count = 1\r\n for i in range(n-1):\r\n if(l[i] < l[i+1]):\r\n count += 1\r\n else:\r\n max_count = max(max_count, count)\r\n count = 1\r\n max_count = max(max_count, count)\r\n return max_count\r\n\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nprint(solve(n, l))",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\n\r\nans = 0\r\ncnt = 1 # Start with cnt=1 since every element is a non-decreasing subarray of length 1\r\n\r\nfor i in range(1, n):\r\n if a[i - 1] < a[i]:\r\n cnt += 1\r\n else:\r\n ans = max(ans, cnt)\r\n cnt = 1\r\n\r\nans = max(ans, cnt) # Update ans with the final count\r\n\r\nprint(ans)\r\n",
"input()\r\nl = list(map(int,input().split()))\r\nx = 1\r\nm = float('-inf')\r\nfor i in range(len(l)-1):\r\n if l[i] < l[i+1]:\r\n x+=1\r\n else:\r\n m = max(x,m)\r\n x=1\r\nm = max(x,m)\r\nprint(m)",
"n = int(input())\r\nnum = list(map(int,input().split()))\r\nMAX = 1\r\nlong = 1\r\nfor i in range(1,n):\r\n\tif num[i] > num[i-1]:\r\n\t\tlong += 1\r\n\t\tif long > MAX:\r\n\t\t\tMAX = long\r\n\telse:\r\n\t\tlong = 1\r\nprint(MAX)",
"arr=list(map(int,[*open(0)][1].split()))\r\ncounts=[]\r\ncount=1\r\nfor k in range(len(arr)-1):\r\n if arr[k+1]>arr[k]: count+=1\r\n else:\r\n counts+=count,\r\n count=1\r\ncounts+=count,\r\nprint(max(counts))\r\n",
"n=int(input())\r\nt=1\r\nwhile t:\r\n li=list(map(int,input().strip().split()))\r\n ans,mans=1,1\r\n for i in range(1,n):\r\n if li[i]>li[i-1]:\r\n ans+=1\r\n if mans<ans:\r\n mans=ans\r\n else:\r\n ans=1\r\n print(mans)\r\n t-=1",
"input()\r\nseq = tuple(map(int, input().split()))\r\ncnt = 1\r\nmx = 0\r\n\r\nfor i in range(1, len(seq)):\r\n if seq[i] > seq[i - 1]:\r\n cnt += 1\r\n else:\r\n mx = max(mx, cnt)\r\n cnt = 1\r\n\r\nmx = max(mx, cnt)\r\nprint(mx)\r\n",
"n = int(input())\nnumbers = tuple(map(int, input().split()))\nstreak = 1 \nstreaks = [streak]\nprevious = None\nfor number in numbers:\n if previous:\n if previous < number:\n streak += 1\n streaks.append(streak)\n else:\n streak = 1\n\n previous = number\n\nprint(max(streaks))\n",
"\r\nl = int(input())\r\narr = [int(x) for x in input().split()]\r\nmx, i = 1, 0\r\n\r\nwhile i < l:\r\n c = 1\r\n while i < l-1 and arr[i] < arr[i+1]:\r\n i += 1\r\n c += 1\r\n i+=1\r\n mx = max(mx, c)\r\n\r\nprint(mx)",
"n = int(input())\r\na = list(map(int,input().split()))\r\na+=[0]\r\nans = []\r\nc = 1\r\nfor i in range(n):\r\n if a[i] < a[i+1]:\r\n c+=1\r\n else:\r\n ans.append(c)\r\n c = 1\r\nprint(max(ans))",
"from sys import stdin\r\ndef input(): return stdin.readline()[:-1]\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nc=1\r\nans=1\r\nfor i in range(n-1):\r\n\tif a[i+1]>a[i]:\r\n\t\tc+=1\r\n\telse:\r\n\t\tans=max(ans,c)\r\n\t\tc=1\r\nprint(max(ans,c))",
"n = int(input())\r\narr = list(map(int, input().split()))\r\nmaxLength = 1\r\nlength=1\r\nfor i in range(1,len(arr)):\r\n if arr[i]>arr[i-1]:\r\n length+=1\r\n maxLength = max(length,maxLength)\r\n else:\r\n length=1\r\nprint(maxLength)",
"a = int(input())\r\nb = list(map(int,input().split()))\r\ns = 1\r\nm = 1\r\nfor i in range(0,a-1):\r\n #print(b[i],b[i+1])\r\n if b[i]>=b[i+1]:\r\n s = 1\r\n else:\r\n s+=1\r\n\r\n if s>m:\r\n m=s\r\nprint(m)\r\n",
"kavyagh = int(input())\r\npremath = list(map(int, input().split()))\r\n\r\nmlen = 1\r\nclen = 1\r\n\r\nfor lazyj in range(1, kavyagh):\r\n if premath[lazyj] > premath[lazyj-1]:\r\n clen += 1\r\n else:\r\n mlen = max(mlen, clen)\r\n clen = 1\r\n\r\nmlen = max(mlen, clen)\r\n\r\nprint(mlen)\r\n",
"n = int(input())\na = list(map(int, input().split()))\nrm = 1\nr = 1\nfor i in range(1, n):\n\tif a[i] > a[i-1]:\n\t\tr += 1\n\telse:\n\t\trm = max([r, rm])\n\t\tr = 1\nrm = max([r, rm])\nprint(rm)\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nmaxln = 1\r\nln = 1\r\nfor i in range(1,n):\r\n if a[i] > a[i-1] : \r\n ln+=1\r\n else :\r\n maxln = max(maxln,ln)\r\n ln = 1\r\nprint(max(maxln,ln))\r\n ",
"n = int(input())\r\na = list(map(int,input().split()))\r\n\r\ndp = [0] * (n + 5)\r\ndp[0] = 1\r\n\r\nfor i in range(1,n):\r\n if a[i] > a[i - 1]:\r\n dp[i] = dp[i - 1] + 1\r\n else:\r\n dp[i] = 1\r\n\r\nprint(max(dp))\r\n",
"# https://codeforces.com/problemset/problem/702/A\r\n\r\ndef check(seq):\r\n m, c = 1, 1\r\n for i in range(1,len(seq)):\r\n if seq[i] > seq[i-1]:\r\n c += 1\r\n else:\r\n m = max(m, c)\r\n c = 1\r\n m = max(m, c)\r\n return m\r\n\r\n\r\ninput()\r\nseq = tuple(map(int, input().split()))\r\nprint(check(seq))",
"n = int(input())\r\nnums = list(map(int,input().split()))\r\ncounter = 1\r\nmax = 1\r\nfor i in range(1,n):\r\n if nums[i] > nums[i-1]:\r\n counter+=1\r\n else:\r\n if counter > max:\r\n max=counter\r\n counter=1\r\nif counter > max:\r\n max=counter \r\nprint(max)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nlen_=1\r\nmax_=1\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n len_+=1\r\n else:\r\n if max_<len_:\r\n max_=len_\r\n len_=1\r\nif max_<len_:\r\n max_=len_\r\n len_=1\r\nprint(max_)\r\n \r\n ",
"n=int(input().strip())\r\na=list(map(int,input().strip().split()))\r\nmx = 1\r\nt = 1\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n t+=1\r\n else:\r\n mx = max(mx, t)\r\n t = 1\r\nmx = max(mx, t)\r\nprint(mx)",
"n=int(input())\r\nlst = [int(a) for a in input().split()]\r\nnw = 0\r\nctn=0\r\nmx=0\r\nfor i in lst :\r\n if i>nw :\r\n ctn+=1\r\n mx = max(mx,ctn)\r\n else:\r\n ctn=1\r\n nw=i\r\nprint(mx)\r\n",
"n=int(input())\r\nstring=input().split()\r\narr=[]\r\nans=[]\r\n\r\nfor x in string:\r\n arr.append(int(x))\r\nmx=1\r\ncnt=1\r\nviolet=False\r\n\r\nfor i in range(1,len(arr),1):\r\n \r\n if arr[i-1]>=arr[i]:\r\n violet=True\r\n \r\n else:\r\n cnt+=1\r\n #print(\"cnt is \",cnt)\r\n violet=False\r\n \r\n\r\n \r\n if violet==True:\r\n if mx<(cnt):\r\n mx=cnt\r\n cnt=1\r\n\r\n \r\nmx=max(mx,cnt)\r\nprint(mx)\r\n",
"n=int(input())\r\narr = list(map(int, input().split()))\r\ns=1\r\nmaxi=1\r\nfor i in range(1,len(arr)):\r\n if arr[i]>arr[i-1]:\r\n s+=1\r\n else:\r\n maxi=max(maxi,s)\r\n s=1\r\nmaxi=max(s,maxi)\r\nprint(maxi)",
"n = int(input())\r\ns = list(map(int, input().split()))\r\nk = 1\r\nans = 1\r\nfor i in range(1, n):\r\n\tif s[i] > s[i - 1]:\r\n\t\tk = k + 1\r\n\telse:\r\n\t\tif k > ans:\r\n\t\t\tans = k\r\n\t\tk = 1\r\nif k > ans:\r\n\tans = k\r\nprint(ans)\r\n\r\n",
"s = int(input())\r\na = list(map(int,(input().split(\" \"))))\r\nmax=1\r\ni = 0\r\ntemp=1\r\nwhile i<s-1:\r\n if a[i] < a[i+1]:\r\n temp =temp+1\r\n else:\r\n if temp >max:\r\n max = temp \r\n temp =1\r\n i = i+1\r\nif temp>max:\r\n max =temp\r\nprint(max)",
"n=int(input())\r\nlst=list(map(int,input().split()))\r\nc=0\r\nm=0\r\nfor i in range(n-1):\r\n if(lst[i]<lst[i+1]):\r\n c=c+1\r\n else:\r\n if(c>m):\r\n m=c\r\n c=0\r\nif(c>m):\r\n m=c\r\nprint(m+1)",
"N=int(input())\r\narr=list(map(int,input().split()))\r\n# print(arr)\r\n# # arr=[9,9,9,9,9,9]\r\n# N=6\r\nl=0\r\nr= N-1\r\nmaxc=1\r\nwhile l<r:\r\n c=1\r\n if arr[l]<arr[l+1]:\r\n while l<r and arr[l]<arr[l+1]:\r\n c+=1\r\n l+=1\r\n else:\r\n l+=1\r\n maxc=max(maxc,c)\r\nprint(maxc)",
"n = int(input())\narr = list(map(int, input().split()))\n\nmax_len = 1 # Initialize maximum length as 1\ncur_len = 1 # Initialize current length as 1\n\nfor i in range(1, n):\n if arr[i] > arr[i - 1]:\n cur_len += 1\n else:\n cur_len = 1\n\n max_len = max(max_len, cur_len)\n\nprint(max_len)\n\n\t\t\t\t\t \t \t \t \t \t \t\t \t \t \t\t",
"n = int(input())\r\na = list(map(int,input().split()))\r\nres = 1\r\nmx = 1\r\nfor i in range(1,n):\r\n\tif a[i]>a[i-1]:\r\n\t\tmx += 1\r\n\telse:\r\n\t\tres = max(res,mx)\r\n\t\tmx = 1\t\r\nprint(max(res,mx))",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nm = c = 0\r\n\r\nfor i in range(1, len(l)):\r\n if l[i] > l[i-1]:\r\n c += 1\r\n else:\r\n c = 0\r\n if c > m:\r\n m = c\r\n\r\nm += 1\r\n\r\nprint(m)\r\n",
"input()\r\nt=b=c=0\r\nfor i in map(int,input().split()):\r\n if t<i:c+=1;t=i\r\n else:b=max(c,b);c=1;t=i\r\nprint(max(b,c)) ",
"n = int(input())\r\na = list(map(int, input().split()))\r\nc = m = 1\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n c += 1\r\n else:\r\n if c > m:\r\n m = c\r\n c = 1\r\nif c > m:\r\n m = c\r\nprint(m)",
"from sys import stdin, stdout\r\ninput, print = stdin.readline, stdout.write\r\n\r\n\r\ndef str_input():\r\n s = input()\r\n return s[:len(s)-1]\r\n\r\n\r\ndef char_list_input():\r\n s = input()\r\n return list(s[:len(s)-1])\r\n\r\n\r\ndef list_input():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef multi_input():\r\n return map(int, input().split())\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n a = list_input()\r\n ans = 0\r\n cnt = 0\r\n last = 0\r\n for i in a:\r\n if i > last:\r\n cnt += 1\r\n else:\r\n cnt = 1\r\n ans = max(ans, cnt)\r\n last = i\r\n print(f\"{ans}\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"# Read the input\r\nn = int(input())\r\narray = list(map(int, input().split()))\r\n\r\n# Initialize variables\r\nmax_length = 1 # The minimum length of an increasing subarray is 1\r\ncurrent_length = 1\r\n\r\n# Iterate through the array starting from the second element\r\nfor i in range(1, n):\r\n if array[i] > array[i - 1]:\r\n # If the current element is greater than the previous one, the subarray is increasing\r\n current_length += 1\r\n else:\r\n # If not, start a new increasing subarray\r\n current_length = 1\r\n \r\n # Update the maximum length\r\n max_length = max(max_length, current_length)\r\n\r\n# Print the result\r\nprint(max_length)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nc=1\r\ni=0\r\nx=[]\r\nwhile(i<n-1):\r\n if(l[i]<l[i+1]):\r\n c+=1\r\n else:\r\n x.append(c)\r\n c=1\r\n i+=1\r\nelse:\r\n x.append(c)\r\nprint(max(x))\r\n",
"def solve(arr):\r\n maxi = 1 \r\n cnt = 0 \r\n currMax = 0 \r\n \r\n for num in arr :\r\n if num > currMax :\r\n cnt += 1 \r\n currMax = num \r\n else :\r\n maxi = max(maxi, cnt)\r\n currMax = num \r\n cnt = 1 \r\n \r\n return max(maxi, cnt)\r\n\r\nn = int(input())\r\narr = [int(i) for i in input().split()]\r\n\r\nprint(solve(arr))",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\nprev = 0\r\nrun = 0\r\nmx = 0\r\nfor i in a:\r\n if i > prev:\r\n run += 1\r\n else:\r\n run = 1\r\n prev = i\r\n mx = max(mx, run)\r\nprint(mx)\r\n",
"n = int(input())\r\nls = list(map(int, input().split()))\r\n\r\ncount, value, i = 1, 1, 1\r\n\r\nwhile i < n:\r\n if ls[i - 1] < ls[i]:\r\n count += 1\r\n value = max(value, count)\r\n else:\r\n count = 1\r\n i += 1\r\n\r\nprint(value)",
"n = int(input())\r\nar = list(map(int, input().split()))\r\nmax_length = 1\r\ncurrent_length = 1\r\nfor i in range(len(ar) - 1):\r\n if ar[i] < ar[i + 1]:\r\n current_length += 1\r\n else:\r\n current_length = 1\r\n max_length = max(max_length, current_length)\r\nprint(max_length)",
"n=int(input())\r\nma=0\r\ntemp=[]\r\nls=list(map(int,input().split()))\r\nif n==1:\r\n print(1)\r\nelse:\r\n for i in range(len(ls)-1):\r\n if ls[i]<ls[i+1]:\r\n ma+=1\r\n temp.append(ma)\r\n if ls[i]>=ls[i+1]:\r\n ma=0\r\n if len(temp)==0:\r\n print(1)\r\n else:\r\n print(max(temp)+1)",
"def countMax(a):\r\n currentMax = a[0]\r\n for i in a:\r\n if currentMax<i:\r\n currentMax=i\r\n return currentMax\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ntemp = 1\r\nb =[]\r\nfor i in range(1,len(a)):\r\n if a[i-1]<a[i]:\r\n temp+=1\r\n else:\r\n b.append(temp)\r\n temp=1\r\nb.append(temp)\r\nprint(countMax(b))",
"# 코드포스 702A Maximum Increase\r\nimport sys\r\nput = sys.stdin.readline\r\n\r\nn = int(put())\r\na = list(map(int, put().split()))\r\ncnt = 0\r\nlength = 1\r\nai = a[0]\r\n\r\nfor i in a[1:]:\r\n if i > ai:\r\n length += 1\r\n ai = i\r\n\r\n else:\r\n cnt = max(cnt, length)\r\n length = 1\r\n ai = i\r\ncnt = max(cnt, length)\r\n\r\nprint(cnt)",
"n = int(input())\r\nL = list(map(int, input().split()))\r\nans = 0\r\nf = 1\r\nfor i in range(1, n):\r\n if L[i - 1] < L[i]:\r\n f += 1\r\n else:\r\n ans = max(ans, f)\r\n f = 1\r\nans = max(ans, f)\r\nprint(ans)\r\n",
"nu=int(input())\r\nls=list(map(int,input().split()))\r\ndp=[0]*nu\r\nfor i in range(nu-1):\r\n if ls[i]<ls[i+1]:\r\n dp[i]=dp[i-1]+1\r\nprint(max(dp)+1)",
"def find_max(arr):\r\n max_val = -1000000000000000000\r\n for i in arr:\r\n if i > max_val:\r\n max_val = i\r\n return max_val\r\n\r\nn = int(input())\r\nar = list(map(int, input().split()))\r\nans = 0\r\nans_ar = []\r\nfor i in range(0,len(ar)-1):\r\n if ar[i] < ar[i+1]:\r\n ans += 1\r\n ans_ar.append(ans)\r\n else:\r\n ans = 0\r\n\r\nif len(ans_ar) == 0:\r\n print(1)\r\nelif len(ans_ar) != 0:\r\n print(int(find_max(ans_ar)) + 1)\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\ngg=1\r\nvv=False;\r\nmmax=1\r\n\r\nfor i in range(n-1):\r\n\tif a[i]<a[i+1]:\r\n\t\tgg+=1;\r\n\telse:\r\n\t\tmmax = max(mmax,gg)\r\n\t\tgg=1\r\nmmax=max(gg,mmax)\r\nprint(mmax)",
"n = int(input())\r\narr = [int(x) for x in input().split()]\r\ntable = [1] * n\r\nfor i in range(1, n):\r\n if arr[i-1] < arr[i]:\r\n table[i] += table[i-1]\r\nprint(max(table))",
"def solve(n, a):\n end = 1\n length = 1\n step_length = 1\n while end < n:\n if a[end - 1] < a[end]:\n step_length += 1\n length = max(length, step_length)\n else:\n step_length = 1\n end += 1\n return length\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n print(solve(n, a))\n\nif __name__ == \"__main__\":\n main()\n\n \t\t \t\t\t\t \t \t \t \t \t \t\t \t",
"def calMaxLength(arr, n) :\n\n\ta = 1\n\tb = 1\n\n\tfor i in range(1, n) :\n\n\t\tif (arr[i] > arr[i-1]) :\n\t\t\tb = b + 1\n\t\telse :\n\n\t\t\tif (a < b) :\n\t\t\t\ta = b\n\n\t\t\tb = 1\n\t\t\n\tif (a < b) :\n\t\ta = b\n\n\treturn a\n\nn = int(input())\n\nnum_list = list(map(int, input().split()))\n\nprint(calMaxLength(num_list, n))\n\t \t\t\t \t\t \t \t \t\t \t\t \t\t\t \t \t",
"class Solution: \r\n def incSubarray(self,n,arr):\r\n i = j = 0\r\n maxLen = 1\r\n while j+1<n:\r\n if arr[j]<arr[j+1]: j += 1\r\n else: \r\n maxLen = max(maxLen,j-i+1)\r\n j += 1\r\n i = j\r\n maxLen = max(maxLen,j-i+1)\r\n return maxLen\r\n \r\nn = int(input())\r\narr = list(map(int,input().split()))\r\nres = Solution().incSubarray(n,arr)\r\nprint(res)",
"\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\n\r\nstreak = 1; maxStreak = 1\r\nprev = a[0]; \r\n\r\nfor i in range(1,n):\r\n curr = a[i]\r\n if curr > prev:\r\n streak +=1\r\n maxStreak = max(streak,maxStreak)\r\n else:\r\n streak = 1\r\n prev = curr\r\nprint(maxStreak)",
"n=int(input())\nnums=[int(i) for i in input().split()]\ni=0\nmaxi=1\nfor j in range(1,n):\n if nums[j]<=nums[j-1]:\n i=j\n maxi=max(maxi,j-i+1)\nprint(maxi)\n",
"n=int(input())\r\nans = 1\r\nj = 1\r\nl=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n if l[i]>l[i-1]:\r\n j+=1\r\n else:\r\n j=1\r\n if j>ans:\r\n ans=j\r\nprint(ans)",
"n = int(input())\nentrada = input()\narreglo = entrada.split()\narreglo_ent = []\nnumero = float('inf')\ncontador = 1\nmaximo = contador\n\nfor i in range(n):\n arreglo_ent.append(int(arreglo[i]))\n \nfor i in range(n):\n if(arreglo_ent[i] > numero):\n numero = arreglo_ent[i]\n contador += 1\n else:\n if(maximo < contador):\n maximo = contador\n numero = arreglo_ent[i]\n contador = 1\nif(maximo < contador):\n maximo = contador\n \nprint(maximo)\n \t \t\t \t\t \t\t\t \t \t\t\t \t",
"length = int(input())\r\nnums = list(map(int,input().split()))\r\ncount = 0\r\nmincreasing = 0\r\nfor index in range(1 , length):\r\n if nums[index - 1] < nums[index] : count += 1\r\n else :\r\n if count > mincreasing : mincreasing = count \r\n count = 0\r\nprint(count + 1 if count > mincreasing else mincreasing + 1)",
"n = int(input())\na = list(map(int, input().split()))\nconteo = 1\nmaximo = 1\n\nfor i in range(1, n):\n if a[i] > a[i - 1]:\n conteo += 1\n else:\n if conteo > maximo:\n maximo = conteo\n conteo = 1\n\nif conteo > maximo:\n maximo = conteo\n\nprint(maximo)\n\n \t\t\t \t \t\t \t\t \t\t \t\t \t\t\t \t \t",
"n = int(input())\r\nl = list(map(int, input().split()))\r\ncount = 1\r\nmax_ = 1\r\nfor i in range(len(l)-1):\r\n if l[i] < l[i+1]:\r\n # print(l[i], l[i+1])\r\n count += 1\r\n # print(max_, count)\r\n else:\r\n if max_ < count:\r\n max_ = count\r\n count = 1\r\nprint(max(max_, count))",
"n=int(input())\na=list(map(int,input().split()))\nx=[]\nc=1\nfor i in range(len(a)-1):\n if a[i]<a[i+1]:\n c+=1\n else:\n x.append(c)\n c=1\nx.append(c)\nprint(max(x))\n",
"n = int(input())\r\na_n = list(map(int, input().split()))\r\n\r\nans = 0\r\ntemp = 1\r\nfor a, b in zip(a_n, a_n[1:]):\r\n if b > a:\r\n temp += 1\r\n else:\r\n if temp > ans:\r\n ans = temp\r\n temp = 1\r\nif temp > ans:\r\n ans = temp\r\n\r\nprint(ans)",
"import math\r\nimport sys\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n stringInput = input()\r\n lst = list(map(int, stringInput.split()))\r\n\r\n count = 1\r\n max_count = 1\r\n\r\n for i in range(1, n):\r\n\r\n if( lst[i] <= lst[i-1] ): count = 1\r\n else: count += 1\r\n\r\n max_count = max(max_count, count)\r\n \r\n print(max_count)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n solve()\r\n\r\n \r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nmax_len = 1\r\ncurr_len = 1\r\nprev = a[0]\r\nfor x in a[1:]:\r\n if x > prev:\r\n curr_len += 1\r\n else:\r\n curr_len = 1\r\n prev = x\r\n max_len = max(curr_len, max_len)\r\nprint(max_len)\r\n",
"n=int(input())\r\na=[int(x) for x in input().split(\" \")]\r\ncnt=1\r\ntemp=1\r\nfor i in range(n-1):\r\n if (a[i]<a[i+1]):\r\n temp+=1\r\n else:\r\n cnt=max(cnt,temp)\r\n temp=1\r\nprint(max(cnt,temp))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans = 1\r\nvr = 1\r\nif n == 1:\r\n ans = 1\r\nelse:\r\n for i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n vr += 1\r\n else:\r\n vr = 1\r\n if vr > ans:\r\n ans = vr\r\nprint(ans)\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nb,c,d=0,0,0\r\nfor i in a:\r\n\tif i > b:\r\n\t\tc+=1\r\n\telse:\r\n\t\tc=1\r\n\td = max(c, d)\r\n\tb = i\r\nprint(d)",
"n = input()\r\nnum = list(map(int, input().split()))\r\ncount = 1\r\nmaxCount = 1\r\ncurr = num[0]\r\n\r\nfor i in num:\r\n if i > curr:\r\n count += 1\r\n curr = i\r\n if count > maxCount:\r\n maxCount = count\r\n\r\n else:\r\n curr = i\r\n count = 1\r\n\r\nprint(maxCount)",
"n = int(input())\r\nlist_n = list(map(int, input().split()))\r\n\r\n\r\nmax_n = 0\r\ntemp = 1\r\n\r\nfor i in range(1, n):\r\n if list_n[i] > list_n[i - 1]:\r\n temp += 1\r\n else:\r\n max_n = max(max_n, temp)\r\n temp = 1\r\n\r\nprint(max(max_n, temp))",
"n=int(input())\r\ns=[int(i) for i in input().split()]\r\nl=0\r\nmaxi=0\r\nliss=[]\r\nll=0\r\nfor r in range(len(s)-1):\r\n\tif s[r]>=s[r+1]:\r\n\t\tmaxi=max(maxi,ll)\r\n\t\tll=0\r\n\telse:\r\n\t\tll+=1\r\nif ll:\r\n\tmaxi=max(maxi,ll)\r\nprint(maxi+1)\r\n",
"n = int(input())\r\ndata = list(map(int, input().split()))\r\nk = 1\r\nmk = 1\r\n\r\nfor i in range(1, n):\r\n if data[i] > data[i - 1]:\r\n k += 1\r\n else:\r\n if k > mk:\r\n mk = k \r\n k = 1\r\nif k > mk:\r\n mk = k \r\n\r\nprint(mk)",
"def max_increase(arr):\r\n n = len(arr)\r\n maxsublen = 0\r\n temp = 1\r\n for i in range(1, n):\r\n if arr[i-1] < arr[i]:\r\n temp += 1\r\n else:\r\n maxsublen = max(maxsublen, temp)\r\n temp = 1\r\n return max(maxsublen, temp)\r\n\r\n \r\n\r\nn = int(input())\r\n\r\narr = list(map(int, input().split()))\r\n\r\nprint(max_increase(arr))",
"n = int(input())\r\n\r\nintegers = list(map(int, input().split()))\r\n\r\nprev = float('-inf')\r\n\r\nanswer = 0\r\nlength = 0\r\n\r\nfor i in range(n):\r\n if prev >= integers[i]:\r\n length = 1\r\n else:\r\n length += 1\r\n answer = max(answer, length)\r\n prev = integers[i]\r\n\r\nprint(answer)",
"# Input: Read the number of integers n and the array of integers arr\nn = int(input())\narr = list(map(int, input().split()))\n\n# Initialize variables to keep track of the maximum length and the current length of increasing subarrays\nmax_length = 1 # The minimum length of any subarray is 1\ncurrent_length = 1 # Start with the first element, so the current length is 1\n\n# Iterate through the array to find increasing subarrays\nfor i in range(1, n):\n if arr[i] > arr[i - 1]:\n current_length += 1 # Extend the current increasing subarray\n max_length = max(max_length, current_length) # Update the maximum length if needed\n else:\n current_length = 1 # Reset the current length\n\n# Output: Print the maximum length of an increasing subarray\nprint(max_length)\n\n \t\t\t \t\t \t \t\t\t \t\t\t\t\t \t",
"n = int(input())\r\nnums = [int(i) for i in input().split()]\r\nmxl = 0\r\nt = 1\r\nfor i in range(n - 1):\r\n if nums[i] < nums[i + 1]:\r\n t += 1\r\n else:\r\n if t > mxl:\r\n mxl = t\r\n t = 1\r\nif t > mxl:\r\n mxl = t\r\nprint(mxl)",
"x = int(input())\r\ncount = 1 # Initialize count to 1 (minimum length is 1)\r\nmax_count = 1 # Initialize max_count to 1\r\ns = list(map(int, input().split()))\r\n\r\nif len(s) == 1:\r\n print(1)\r\n exit()\r\nelif len(set(s)) == 1:\r\n print(1)\r\n exit()\r\nelse:\r\n for i in range(1, len(s)):\r\n if s[i - 1] < s[i]:\r\n count += 1\r\n max_count = max(max_count, count) # Update max_count if count is greater\r\n else:\r\n count = 1 # Reset count to 1 when the sequence is not strictly increasing\r\n\r\nprint(max_count) # Print the length of the longest increasing subsequence\r\n",
"n = int(input())\r\nnums = list(map(int,input().split()))\r\nmaxm = 0\r\nprev = 0\r\ncount= 0\r\nfor i in range(n):\r\n if prev<nums[i]:\r\n prev = nums[i]\r\n count+=1\r\n else:\r\n prev=nums[i]\r\n maxm = max(count,maxm)\r\n count=1\r\nprint(max(maxm,count))\r\n \r\n\r\n",
"def lenOfLongIncSubArr(arr, n) :\r\n m = 1\r\n l = 1\r\n for i in range(1, n) :\r\n if (arr[i] > arr[i-1]) :\r\n l =l + 1\r\n else :\r\n if (m < l) :\r\n m = l\r\n l = 1\r\n if (m < l) :\r\n m = l\r\n return m\r\nn=int(input())\r\narr=[*map(int,input().split())]\r\nprint( lenOfLongIncSubArr(arr, n))",
"length = int(input())\r\narray = [int(i) for i in input().split()] + [0]\r\n\r\n\r\nprev = array[0]\r\nmemory = 1\r\ncounter = 1\r\nfor num in array[1:]:\r\n if num > prev:\r\n counter+=1\r\n else:\r\n if counter > memory:\r\n memory = counter\r\n counter = 1\r\n prev = num\r\nprint(memory)",
"t = int(input());ans = [];s = 1\r\n*l, = map(int, input().split(' '))\r\n\r\nfor i in range(t - 1):\r\n if l[i] < l[i + 1]:\r\n s += 1\r\n else:\r\n ans.append(s)\r\n s = 1\r\nans.append(s)\r\nprint(max(ans))\r\n",
"a=int(input())\r\nl2=[int(x) for x in input().split()]\r\nc=1\r\nm=1\r\nfor i in range(1,len(l2)):\r\n if l2[i]>l2[i-1]:\r\n c=c+1\r\n else:\r\n c=1\r\n m=max(m,c)\r\nprint(m)\r\n",
"import sys\r\ninput = sys.stdin.readline\r\noutput = sys.stdout.write\r\n\r\n\r\ndef main():\r\n input()\r\n list_ = list(map(int, input().rstrip().split()))\r\n seq_ = {1}\r\n counter = 1\r\n last_ = list_[0]\r\n for num in list_[1:]:\r\n if num > last_:\r\n counter += 1\r\n else:\r\n seq_.add(counter)\r\n counter = 1\r\n last_ = num\r\n seq_.add(counter)\r\n ans = max(seq_)\r\n output(str(ans))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n",
"import math\r\n# Shortcut for input\r\ndef I(): return int(input())\r\ndef MI(): return map(int, input().split())\r\ndef LI(): return list(map(int, input().split()))\r\ndef S(): return input()\r\n# Constants\r\nmod = 10**9 + 7\r\n\"\"\"\r\nCONTRAINTS\r\n1-n-10**5\r\n1-ai-10**9\r\n\"\"\"\r\n#maximum strictly increasing subarray\r\nn = I()\r\na = LI()\r\nl = 0 \r\nr = 1\r\nans = 1\r\nwhile r < len(a):\r\n if a[r] > a[r-1]:\r\n r+=1\r\n else:\r\n #[l..r-1]\r\n ans = max(r-l,ans)\r\n l = r \r\n r +=1\r\nans = max(r-l,ans)\r\nprint(ans)",
"n = int(input())\nq = [int(x) for x in input().split()]\nans = 1\nt = 1\nfor i in range(1, n):\n\tans = max(ans, t)\n\tif q[i] > q[i-1]:\n\t\tt += 1\n\telse:\n\t\tt = 1\n\tans = max(ans, t)\nprint(ans)\n\t\t \t \t \t \t\t\t \t\t \t \t\t\t",
"# Input reading\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\n# Initializing variables\r\nmax_length = 1 # The maximum length of an increasing subarray\r\ncurrent_length = 1 # The length of the current increasing subarray\r\n\r\n# Iterating through the array\r\nfor i in range(1, n):\r\n # Comparing the current element with the previous one\r\n if a[i] > a[i-1]:\r\n # If the current element is greater, increment current_length\r\n current_length += 1\r\n else:\r\n # Otherwise, reset current_length\r\n current_length = 1\r\n # Update max_length\r\n max_length = max(max_length, current_length)\r\n\r\n# Output\r\nprint(max_length)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=0\r\nt=1\r\n\r\nfor i in range(1,n):\r\n if l[i]>l[i-1]:\r\n t+=1\r\n else:\r\n m=max(m,t)\r\n t=1\r\nprint(max(m,t))\r\n",
"n = int(input())\r\nans = 1\r\ncur_len = 1\r\nl = -1\r\ns = input()\r\nfor i in s.split(\" \"):\r\n\tif l != -1:\r\n\t\tif int(i) > l:\r\n\t\t\tcur_len += 1\r\n\t\telse:\r\n\t\t\tans = max(cur_len, ans)\r\n\t\t\tcur_len = 1\r\n\tl = int(i)\r\n\r\nprint(max(ans, cur_len))\r\n\t\t\t\t\t",
"n = int(input())\r\na = list(map(int,input().split()))\r\nlength_max = 1\r\nlength_test = 1\r\n\r\nfor i in range(1,n):\r\n if a[i] > a[i-1]:\r\n length_test += 1\r\n if length_test > length_max:\r\n length_max = length_test\r\n else:\r\n length_test = 1\r\n\r\nprint(length_max)",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nc=0\r\ncount=1\r\nch=0\r\nfor i in range(1,n):\r\n if arr[i]>arr[i-1]:\r\n count+=1\r\n else:\r\n c=max(c,count)\r\n count=1\r\nc=max(c,count)\r\nprint(c)\r\n",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\nlst.append(0)\r\nhlp = []\r\nHLP = []\r\nfor i in range(len(lst) - 1):\r\n if lst[i + 1] > lst[i]:\r\n hlp.append(lst[i])\r\n else:\r\n hlp.append(lst[i])\r\n HLP.append(hlp)\r\n hlp = []\r\nHLP.append(hlp)\r\ndp = []\r\nfor i in HLP:\r\n dp.append(len(i))\r\nprint(max(dp))\r\n",
"t = int(input())\r\nlst = list(map(int, input().split()))\r\nlst1 = []\r\nlst2 = []\r\nfor i in range(len(lst) - 1):\r\n if lst[i] < lst[i + 1]:\r\n lst1.append(1)\r\n else:\r\n lst1.append(0)\r\n\r\n\r\ncount = 0 \r\nfor i in lst1:\r\n if i == 1:\r\n count += 1\r\n lst2.append(count)\r\n else:\r\n count = 0\r\n\r\nif len(lst2) == 0:\r\n print(1)\r\nelse:\r\n print(max(lst2) + 1)\r\n",
"n=input()\r\nx = y = z = 0\r\nl1=map(int, input().split())\r\nfor i in l1:\r\n if i > y:\r\n x=x+1 \r\n else:\r\n x=1\r\n y = i\r\n z = max(z, x)\r\nprint(z)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Jan 23 20:50:30 2023\r\n\r\n@author: rohan\r\n\"\"\"\r\n\r\nn = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\ndef solve():\r\n i = 0\r\n ans = 0\r\n for j in range(n):\r\n if i <= j and j-i+1 > 1 and nums[j-1] >= nums[j]:\r\n i = j\r\n \r\n ans = max(ans, j - i + 1)\r\n return ans\r\n\r\nprint(solve())"
] | {"inputs": ["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3", "1\n1000000000", "10\n802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754", "2\n2 1", "5\n1 2 3 3 4", "4\n1 2 2 3", "3\n2 1 1", "3\n1 2 1", "1\n1", "2\n1 2", "3\n1 1 2", "11\n1 2 3 1 2 3 2 1 2 3 4", "9\n1 2 3 4 5 6 7 8 9", "9\n1 1 1 1 1 1 1 1 1", "3\n3 2 1", "7\n1 2 3 4 5 6 7", "1\n1234394"], "outputs": ["3", "1", "3", "1", "3", "1", "3", "2", "1", "2", "1", "2", "2", "4", "9", "1", "1", "7", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 389 | |
310156f005df4f13b9a0d5cafd315f04 | Andryusha and Colored Balloons | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored balloon at each of the squares. The baloons' colors are described by positive integers, starting from 1. In order to make the park varicolored, Andryusha wants to choose the colors in a special way. More precisely, he wants to use such colors that if *a*, *b* and *c* are distinct squares that *a* and *b* have a direct path between them, and *b* and *c* have a direct path between them, then balloon colors on these three squares are distinct.
Andryusha wants to use as little different colors as possible. Help him to choose the colors!
The first line contains single integer *n* (3<=≤<=*n*<=≤<=2·105) — the number of squares in the park.
Each of the next (*n*<=-<=1) lines contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other using the paths.
In the first line print single integer *k* — the minimum number of colors Andryusha has to use.
In the second line print *n* integers, the *i*-th of them should be equal to the balloon color on the *i*-th square. Each of these numbers should be within range from 1 to *k*.
Sample Input
3
2 3
1 3
5
2 3
5 3
4 3
1 3
5
2 1
3 2
4 3
5 4
Sample Output
3
1 3 2 5
1 3 2 5 4 3
1 2 3 1 2 | [
"import sys\r\ninput = sys.stdin.readline\r\ndef dfs():\r\n stack = [(0,0)]\r\n d[0].append(1)\r\n while stack:\r\n i,p = stack.pop()\r\n c = 1\r\n for j in d[i]:\r\n if j != p:\r\n stack.append((j,i))\r\n while c in {color[i],color[p]}:\r\n c = c+1\r\n\r\n color[j] = c\r\n c = c+1\r\n\r\n\r\nn = int(input())\r\nd = {}\r\nd[0] = []\r\nfor _ in range(n-1):\r\n x,y = map(int,input().split())\r\n if x in d:\r\n d[x].append(y)\r\n\r\n else:\r\n d[x] = [y]\r\n\r\n if y in d:\r\n d[y].append(x)\r\n\r\n else:\r\n d[y] = [x]\r\n\r\nm = 0\r\nfor i in d:\r\n if len(d[i]) > m:\r\n m = len(d[i])\r\n\r\nans = m+1\r\ncolor = [-1]*(n+1)\r\ndfs()\r\nprint(ans)\r\nprint(*color[1:])",
"import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\ndef dfs(i):\n global P,N\n l = [i]\n vis = [0]*N\n ans = [-1]*N\n ans[i] = 1\n\n while l:\n x = l.pop()\n if vis[x]==1:continue\n vis[x] = 1\n s = set([ans[x]])\n for j in P[x]:\n if vis[j]==1:s.add(ans[j])\n\n cnt = 1\n for j in P[x]:\n if vis[j]==0:\n while cnt in s:cnt+=1\n ans[j] = cnt\n s.add(cnt)\n\n for y in P[x]:\n if vis[y]==1:continue\n l.append(y)\n\n return max(ans),ans\n\nN = int(input())\nP = [[] for _ in range(N)]\nfor _ in range(N-1):\n a,b = map(int,input().split())\n P[a-1].append(b-1)\n P[b-1].append(a-1)\n\na,b = dfs(0)\nprint(a)\nprint(*b)",
"# region declaration\nfrom collections import *\nfrom functools import *\nfrom math import *\nfrom heapq import *\nfrom itertools import *\nfrom bisect import *\n\n# autopep8: off\ndef floatl(): return (list(map(float, input().split())))\ndef inlt(): return (list(map(int, input().split())))\ndef inp(): return int(input())\ndef ins(): return str(input())\ndef insr(): return list(input())\ndef yesno(predicate): print(\"Yes\" if predicate else \"No\")\n# MOD = 998244353\nMOD = 1_000_000_007 \nINF = int(1e18)\n# autopep8: on\n# endregion\n\n\ndef solve():\n n = inp()\n edges = defaultdict(list)\n colors = 1\n for _ in range(n-1):\n u, v = inlt()\n u -= 1\n v -= 1\n edges[u].append(v)\n edges[v].append(u)\n\n q = list(edges[0])\n seen = [False] * n\n par = [0] * n\n colors = [1] * n\n mincolors = 1\n seen[0] = True\n for u in edges[0]:\n seen[u] = True\n mincolors += 1\n colors[u] = mincolors\n\n while q:\n u = q.pop()\n mincolors = max(mincolors, len(edges[u]) + 1)\n c = 1\n for v in edges[u]:\n if seen[v]:\n continue\n par[v] = u\n seen[v] = True\n q.append(v)\n while c == colors[u] or c == colors[par[u]]:\n c += 1\n colors[v] = c\n c += 1\n\n print(mincolors)\n print(*colors)\n\n\nt = 1\n# t = inp()\nfor _ in range(t):\n solve()\n",
"from sys import stdin\r\nfrom collections import deque\r\n\r\n\r\ndef main():\r\n n = int(input()) + 1\r\n g = [[] for _ in range(n)]\r\n for s in range(n-2):\r\n u, v = map(int, input().split())\r\n g[u].append(v)\r\n g[v].append(u)\r\n cc, palette, q = [0] * n, [True] * n, deque(((1, 0, 1),))\r\n cc[1] = 1\r\n while q:\r\n u, a, b = q.popleft()\r\n \r\n c = 1\r\n for v in g[u]:\r\n if not cc[v]:\r\n while c in [a,b]:\r\n c += 1\r\n cc[v] = c\r\n q.append((v, b, c))\r\n c += 1\r\n \r\n print(max(cc))\r\n print(' '.join(map(str, cc[1:])))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n \r\n",
"n = int(input())\n\nE = [[] for u in range(n)]\nfor i in range(n - 1):\n u, v = map(lambda x: int(x) - 1, input().split())\n E[u].append(v)\n E[v].append(u)\n\nk = max([len(E[u]) for u in range(n)]) + 1\n\nused = [False] * k\ncolor = [0] * n\n\ndef getnext(x):\n while used[x]:\n x += 1\n return x\n\nvis = [False] * n\nstk = [0]\n\nwhile stk:\n u = stk.pop()\n vis[u] = True\n used[color[u]] = True\n for v in E[u]:\n if vis[v]:\n used[color[v]] = True\n x = 0\n for v in E[u]:\n if not vis[v]:\n x = getnext(x)\n color[v] = x\n used[x] = True\n stk.append(v)\n\n used[color[u]] = False\n for v in E[u]:\n used[color[v]] = False\n\nprint(k)\nprint(*[x + 1 for x in color])\n",
"# from math import sqrt\r\n# from queue import Queue\r\n# from math import inf\r\nfrom collections import deque\r\n# from bisect import bisect\r\n# from collections import Counter\r\n# n,k,m=map(int,input().split())\r\n# from copy import copy \r\n# for _ in range(int(input())):\r\nn=int(input())\r\ncol=[0 for ____ in range((n))]\r\nadj=[[] for __ in range(n)]\r\nprev=[0 for _______ in range(n)]\r\nfor ______ in range(n-1):\r\n x,y=map(int,input().split())\r\n adj[x-1].append(y-1)\r\n adj[y-1].append(x-1)\r\nq=deque()\r\nq.append(0)\r\ncol[0]=1\r\nwhile len(q)!=0:\r\n a=q.popleft()\r\n ca=col[a]\r\n can=col[prev[a]]\r\n count=1\r\n for nb in adj[a]:\r\n if nb!=prev[a]:\r\n q.append(nb)\r\n prev[nb]=a\r\n if count!=ca and count!=can:\r\n col[nb]=count\r\n elif abs(ca-can)==1:\r\n count+=2\r\n col[nb]=count\r\n else:\r\n count+=1\r\n col[nb]=count\r\n count+=1\r\n\r\nprint(len(set(col)))\r\nprint(*col)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn = int(input())\r\nd = [[] for i in range(n+1)]\r\nfor i in range(n-1):\r\n a, b = map(int, input().split())\r\n d[a].append(b)\r\n d[b].append(a)\r\nt = max(len(i)+1 for i in d)\r\nx = [0]*(n+1)\r\nx[1] = 1\r\nq = [(1, -1)]\r\nwhile q:\r\n a, b = q.pop()\r\n s = {x[a], x[b] if b != -1 else 0}\r\n c = 1\r\n for i in d[a]:\r\n if i != b:\r\n while c in s:\r\n c += 1\r\n x[i] = c\r\n c += 1\r\n q.append((i, a))\r\nprint(t)\r\nprint(' '.join(map(str, x[1:])))\r\n",
"import collections\ndef doit():\n # rows = [[] for y in range(M)]\n rows = dict()\n\n N = int(input())\n graph = dict()\n for n in range(N) :\n graph[n] = list()\n\n for n in range(N - 1):\n a, b = map(int, input().split())\n graph[a-1].append(b-1)\n graph[b-1].append(a-1)\n\n msize = 0\n for k in graph:\n msize = max(msize, len(graph[k]))\n print(msize+1)\n\n\n root = 0\n colors = [0 for x in range(N)]\n colors[root] = 1\n parents = [0 for x in range(N)]\n parents[root] = root\n\n\n def color(c1, c2):\n colorindex = 0\n while colorindex < msize + 1:\n colorindex += 1\n if colorindex == c1 or colorindex == c2:\n continue\n yield colorindex\n\n\n # visited = set()\n # visited.add(root)\n queue = collections.deque([root])\n while queue:\n vertex = queue.popleft()\n # newcolors = [c for c in range(1, msize+2) if c != colors[vertex] and c != colors[parents[vertex]] ]\n # newcolors = filter(lambda c: c != colors[vertex] and c != colors[parents[vertex]], range(1, msize+2))\n #\n # print(f'newcolors={newcolors}')\n colorgen = color(colors[vertex], colors[parents[vertex]])\n for neighbour in graph[vertex]:\n if neighbour == parents[vertex]:\n continue\n parents[neighbour] = vertex\n colors[neighbour] = next(colorgen)\n # visited.add(neighbour)\n queue.append(neighbour)\n print(\" \".join(map(str, colors)))\n\ndoit()",
"import sys\r\ninput = sys.stdin.readline\r\nfrom collections import deque\r\n\r\ndef bfs():\r\n visited = [False]*n\r\n visited[0] = True\r\n color = [-1]*n\r\n color[0] = 1\r\n q = deque([(0, 1, -1)])\r\n\r\n while q:\r\n v, pre_c1, pre_c2 = q.popleft()\r\n cnt = 1\r\n \r\n for nv in G[v]:\r\n if visited[nv]:\r\n continue\r\n \r\n while cnt==pre_c1 or cnt==pre_c2:\r\n cnt += 1\r\n \r\n color[nv] = cnt\r\n cnt += 1\r\n q.append((nv, color[v], color[nv]))\r\n visited[nv] = True\r\n \r\n return color\r\n\r\nn = int(input())\r\nG = [[] for _ in range(n)]\r\n\r\nfor _ in range(n-1):\r\n x, y = map(int, input().split())\r\n G[x-1].append(y-1)\r\n G[y-1].append(x-1)\r\n\r\ncolor = bfs()\r\n\r\nprint(max(color))\r\nprint(*color)",
"from collections import deque\r\nfrom sys import stdin,stdout\r\nn=int(stdin.readline())\r\nchildren = dict()\r\nfor j in range(n-1):\r\n per1,per2 = map(int,stdin.readline().split())\r\n if per1 in children:\r\n children[per1].append(per2)\r\n else:\r\n children[per1] = [per2]\r\n if per2 in children:\r\n children[per2].append(per1)\r\n else:\r\n children[per2] = [per1]\r\nqueue = deque()\r\nanswer = [0] * n\r\nanswer[0] = 1\r\nqueue.append([1,1,-1,-1])\r\nmaxs = 1\r\nwhile queue:\r\n per = queue.pop()\r\n cou = 1\r\n for j in children[per[0]]:\r\n if j != per[2]:\r\n if cou == per[3] or cou == per[1]:\r\n cou +=1\r\n if cou == per[3] or cou == per[1]:\r\n cou +=1 \r\n answer[j-1] = cou\r\n queue.appendleft([j,cou,per[0],per[1]])\r\n cou+=1\r\n \r\n maxs = max(maxs,cou-1)\r\nstdout.write(str(maxs) + '\\n')\r\nstdout.write(' '.join(map(str,answer)))",
"import sys\nfrom collections import defaultdict\nfrom collections import deque\nfrom types import GeneratorType\ninput = sys.stdin.readline\n\ndef bootstrap(f, stack=[]):\n \n def wrappedfunc(*args, **kwargs):\n if stack:\n return f(*args, **kwargs)\n else:\n to = f(*args, **kwargs)\n while True:\n if type(to) is GeneratorType:\n stack.append(to)\n to = next(to)\n else:\n stack.pop()\n if not stack:\n break\n to = stack[-1].send(to)\n return to\n return wrappedfunc\n\ndef get_adj_mat(src, dst):\n matrix = defaultdict(list)\n for src_i, dst_i in zip(src, dst):\n matrix[src_i].append(dst_i)\n matrix[dst_i].append(src_i)\n return matrix\n\n\n@bootstrap\ndef set_colour(curr_index, parent_index, adj_mat, colours):\n val = 1\n curr_val, parent_val = colours[curr_index], colours[parent_index]\n for child_index in adj_mat[curr_index]:\n if child_index != parent_index:\n while val in [curr_val, parent_val]:\n val += 1\n colours[child_index] = val\n val += 1\n yield set_colour(child_index, curr_index, adj_mat, colours)\n yield None\n \n \ndef solve(src, dst, n):\n adj_mat = get_adj_mat(src, dst)\n colours = [-1] * n\n root = 0\n \n colours[root] = 1\n set_colour(0, 0, adj_mat, colours)\n print(max(colours))\n print(*colours)\n\n \nif __name__ == \"__main__\":\n n = int(input())\n src, dst = [], []\n for _ in range(n-1):\n src_i, dst_i = [int(val) for val in input().split()]\n src.append(src_i-1), dst.append(dst_i-1)\n solve(src, dst, n)\n\n",
"import sys\r\ninput=sys.stdin.readline\r\nfrom collections import defaultdict,deque\r\nn=int(input())\r\ng=defaultdict(list)\r\nind=[0]*(n+1)\r\nfor i in range(n-1):\r\n x,y=map(int,input().split())\r\n g[x].append(y)\r\n g[y].append(x)\r\n ind[x]+=1\r\n ind[y]+=1\r\nmx,idx=0,-1\r\nfor i in range(n+1):\r\n if ind[i]>mx:\r\n mx=ind[i]\r\n idx=i\r\nk=deque([])\r\n#print(idx)\r\nfor i in range(1,mx+2):\r\n k.append(i)\r\nvisited={idx}\r\ncolor={idx:1}\r\nq=deque([idx])\r\npar={idx:idx}\r\n#print(k)\r\nwhile q:\r\n node=q.popleft()\r\n #print(color,node)\r\n c1=color[node]\r\n c2=color[par[node]]\r\n for nbr in g[node]:\r\n if nbr not in visited:\r\n visited.add(nbr)\r\n q.append(nbr)\r\n par[nbr]=node\r\n while k[0]==c1 or k[0]==c2:\r\n c=k.popleft()\r\n k.append(c)\r\n color[nbr]=k[0]\r\n c=k.popleft()\r\n k.append(c)\r\nprint(len(k))\r\nfor i in range(1,n+1):\r\n print(color[i],end=' ')\r\nprint()",
"import sys\nsys.setrecursionlimit(200000)\n\nn = int(input())\narr = [[] for i in range(n)]\nfor i in range(n - 1):\n a, b = map(int, input().split())\n arr[a - 1].append(b - 1)\n arr[b - 1].append(a - 1)\ns = max([len(p) for p in arr]) + 1\nprint(s)\n\ncolored = [0] * n\ndef dfs(v, c, d):\n colored[v] = p = c\n for u in arr[v]:\n if not colored[u]:\n c = c + 1 if c < s else 1\n if c == d:\n c = c + 1 if c < s else 1\n dfs(u, c, p)\nif s > 3:\n dfs(0, 1, 0)\nelse:\n i = 0\n c = 1\n while len(arr[i]) != 1:\n i += 1\n for j in range(n):\n colored[i] = c\n c = c + 1 if c < s else 1\n if j < n - 1:\n i = arr[i][0] if not colored[arr[i][0]] else arr[i][1]\nprint(\" \".join(map(str, colored)))",
"import sys\r\nsys.setrecursionlimit(200000)\r\n\r\nn=int(input())\r\ng=[[] for i in range(n)]\r\nfor i in range(n-1):\r\n a,b=map(int, input().split())\r\n g[a-1].append(b-1)\r\n g[b-1].append(a-1)\r\ns = max([len(p) for p in g]) + 1\r\nprint(s)\r\nr=[0]*n\r\ndef dfs(v,c,d):\r\n r[v]=p=c\r\n for u in g[v]:\r\n if not r[u]:\r\n c=c+1 if c<s else 1\r\n if c==d:\r\n c=c+1 if c<s else 1\r\n dfs(u,c,p)\r\nif s>3:\r\n dfs(0, 1, 0)\r\nelse:\r\n i=0\r\n c=1\r\n while len(g[i])!=1:\r\n i+=1\r\n for j in range(n):\r\n r[i]=c\r\n c=c+1 if c<s else 1\r\n if j<n-1:\r\n i=g[i][0] if not r[g[i][0]] else g[i][1]\r\nprint(\" \".join(map(str, r)))",
"from sys import stdin\n\n\ndef main():\n n = int(input()) + 1\n g = [[] for _ in range(n)]\n for s in stdin.read().splitlines():\n u, v = map(int, s.split())\n g[u].append(v)\n g[v].append(u)\n cc, palette, nxt = [0] * n, [True] * n, [(1, 0, 1)]\n cc[1] = 1\n while nxt:\n cur, nxt = nxt, []\n for u, a, b in cur:\n palette[a] = palette[b] = False\n c = 1\n for v in g[u]:\n if not cc[v]:\n while not palette[c]:\n c += 1\n cc[v] = c\n nxt.append((v, b, c))\n c += 1\n palette[a] = palette[b] = True\n print(max(cc))\n print(' '.join(map(str, cc[1:])))\n\n\nif __name__ == '__main__':\n main()\n",
"from sys import stdin\r\ninput = stdin.readline\r\n\r\ndef put():\r\n return map(int, input().split())\r\n\r\ndef dfs():\r\n s = [(0,0)]\r\n tree[0].append(1)\r\n while s:\r\n i,p = s.pop()\r\n c = 1\r\n for j in tree[i]:\r\n if j!=p:\r\n s.append((j,i))\r\n while c in [color[i], color[p]]:\r\n c+=1\r\n color[j]=c\r\n c+=1\r\n \r\n\r\n\r\nn = int(input())\r\ntree = [[] for i in range(n+1)]\r\ncolor= [0]*(n+1)\r\nfor _ in range(n-1):\r\n x,y = put()\r\n tree[x].append(y)\r\n tree[y].append(x)\r\n\r\nans = 0\r\nfor i in range(1,n+1):\r\n ans = max(ans, len(tree[i])+1)\r\n\r\ndfs()\r\nprint(ans)\r\nprint(*color[1:])",
"def set_colors(i, pri, d):\r\n colors = {1:1}\r\n vertexes = [(1, 1, -1)]\r\n index = 0\r\n while(index < len(vertexes)):\r\n color = 1\r\n vertex = vertexes[index][0]\r\n color_i = vertexes[index][1]\r\n color_pri = vertexes[index][2]\r\n for nb in d[vertex]:\r\n if colors.get(nb, None) is not None: \r\n continue\r\n while color == color_i or color == color_pri:\r\n color += 1\r\n colors[nb] = color\r\n vertexes += [(nb, color, color_i)]\r\n color += 1\r\n index += 1\r\n return colors\r\nn = int(input())\r\nbegin = 1\r\nd = {i:[] for i in range(1,n+1)}\r\nfor i in range(n-1):\r\n x, y = [int(x) for x in input().split()]\r\n d[x].append(y)\r\n d[y].append(x)\r\nk = max([len(el) for el in d.values()])+1\r\ncolors = {1:1}\r\nprint(k)\r\ncolors = set_colors(1, 1, d)\r\nprint(\" \".join([str(colors.get(i, 0)) for i in range(1, n+1)]))",
"#!/usr/bin/env python3\n\nfrom collections import deque\n\n\n\ndef ri():\n\n return map(int, input().split())\n\n\n\nn = int(input())\n\nv = [0]*n\n\nc = [0]*n\n\np = [0]*n\n\nadj = [set() for i in range(n)]\n\nfor i in range(n-1):\n\n a, b = ri()\n\n a -= 1\n\n b -= 1\n\n adj[a].add(b)\n\n adj[b].add(a)\n\nfor s in range(n):\n\n if len(adj[s]) == 1:\n\n break\n\nans = 0\n\nq = deque()\n\nq.append(s)\n\nv[s] = 1\n\nc[s] = 1\n\np[s] = s\n\nwhile q:\n\n n = q.popleft()\n\n cc = 1\n\n for a in adj[n]:\n\n if v[a] == 0:\n\n while cc in [c[n], c[p[n]]]:\n\n cc+=1\n\n c[a] = cc\n\n cc+=1\n\n ans = max(2+len(adj[a])-1, ans)\n\n q.append(a)\n\n p[a] = n\n\n v[a] = 1\n\nprint(ans)\n\nprint(\" \".join(map(str,c)))\n\n\n\n\n\n# Made By Mostafa_Khaled",
"from collections import deque\r\n\r\nn = int(input())\r\ng = []\r\nvisited = []\r\ncolor = []\r\nmax_child_color = []\r\nparent = []\r\n\r\ndef initialize():\r\n for i in range(n+10):\r\n g.append([])\r\n visited.append(False)\r\n color.append(0)\r\n max_child_color.append(0)\r\n parent.append(0)\r\n for i in range(n-1):\r\n u, v = map(int, input().split())\r\n g[u] += [v]\r\n g[v] += [u]\r\n # print(g)\r\n\r\ndef get_color(u):\r\n for i in range(max_child_color[u]+1, n+1):\r\n if i != color[parent[u]] and i != color[u]:\r\n max_child_color[u] = i\r\n # print(f'Setting max child color of node = {u} to color {i}')\r\n return i\r\n\r\ndef bfs(start):\r\n visited[start] = True\r\n color[start] = 1\r\n q = deque()\r\n q.append(start)\r\n while q:\r\n u = q.popleft()\r\n for v in g[u]:\r\n parent[v] = u\r\n if not visited[v]:\r\n visited[v] = True\r\n color[v] = get_color(u)\r\n q.append(v)\r\n\r\nif __name__ == '__main__':\r\n initialize()\r\n bfs(1)\r\n print(max(color))\r\n c_string = \"\"\r\n for i in range(1, n+1):\r\n c_string += str(color[i]) + \" \"\r\n print(c_string)",
"\"\"\"\r\n#If FastIO not needed, used this and don't forget to strip\r\n#import sys, math\r\n#input = sys.stdin.readline\r\n\"\"\"\r\n\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nimport heapq as h \r\nfrom bisect import bisect_left, bisect_right\r\n\r\nfrom types import GeneratorType\r\nBUFSIZE = 8192\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n \r\n def __init__(self, file):\r\n import os\r\n self.os = os\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n \r\n def read(self):\r\n while True:\r\n b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n \r\n def readline(self):\r\n while self.newlines == 0:\r\n b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n \r\n def flush(self):\r\n if self.writable:\r\n self.os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n \r\n \r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n \r\n \r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\nimport collections as col\r\nimport math, string\r\n\r\ndef getInts():\r\n return [int(s) for s in input().split()]\r\n\r\ndef getInt():\r\n return int(input())\r\n\r\ndef getStrs():\r\n return [s for s in input().split()]\r\n\r\ndef getStr():\r\n return input()\r\n\r\ndef listStr():\r\n return list(input())\r\n\r\nMOD = 10**9+7\r\n\r\n\r\n\"\"\"\r\nEach node and all its neighbours must be different, so the minimum number of colours is X + 1 where the max number of neighbours any node has is 1\r\nAssign colours by BFS: every node must have a different colour to 1) its parent 2) its parent's parent 3) the other children of its parent\r\n\r\n\"\"\"\r\n\r\ndef solve():\r\n N = getInt()\r\n graph = col.defaultdict(set)\r\n for n in range(N-1):\r\n U, V = getInts()\r\n U -= 1\r\n V -= 1\r\n graph[U].add(V)\r\n graph[V].add(U)\r\n def bfs(node):\r\n import collections as col\r\n nodes.remove(node)\r\n cols[node] = 1\r\n queue = col.deque([])\r\n queue.append((node,1,-1,-1))\r\n while queue:\r\n node, colour, parent, parent_col = queue.popleft()\r\n y = set([j+1 for j in range(len(graph[node])+1)])\r\n if colour in y: y.remove(colour)\r\n if parent_col in y: y.remove(parent_col)\r\n for neighbour in graph[node]:\r\n if neighbour in nodes:\r\n nodes.remove(neighbour)\r\n new_col = next(iter(y))\r\n y.remove(new_col)\r\n cols[neighbour] = new_col\r\n queue.append((neighbour,new_col,node,colour))\r\n \r\n return\r\n nodes = set([j for j in range(N)])\r\n cols = [-1]*N\r\n bfs(0)\r\n print(max(cols))\r\n print(*cols)\r\n return\r\n \r\n \r\n\r\n \r\n#for _ in range(getInt()):\r\nsolve()",
"from sys import stdin\r\ninput=lambda : stdin.readline().strip()\r\nfrom math import ceil,sqrt,factorial,gcd\r\nfrom collections import deque\r\nn=int(input())\r\ngraph={i:set() for i in range(n)}\r\nfor i in range(n-1):\r\n\ta,b=map(int,input().split())\r\n\tgraph[a-1].add(b-1)\r\n\tgraph[b-1].add(a-1)\r\nma=0\r\nfor i in graph:\r\n\tif len(graph[i])+1>ma:\r\n\t\tma=len(graph[i])+1\r\n\t\tx=i\r\nprint(ma)\r\nans=[0 for i in range(n)]\r\nstack=[x]\r\npapa=[0 for i in range(n)]\r\nwhile stack:\r\n\tx=stack.pop()\r\n\t# z=set(s)\r\n\ta=1\r\n\tif ans[x]==0:\r\n\t\tans[x]=1\r\n\t\tz=[1]\r\n\telse:\r\n\t\tz=[]\r\n\t\tz.append(ans[x])\r\n\t\tz.append(ans[papa[x]])\r\n\tfor j in graph[x]:\r\n\t\twhile 1:\r\n\t\t\tif a in z:\r\n\t\t\t\ta+=1\r\n\t\t\telse:\r\n\t\t\t\tans[j]=a\r\n\t\t\t\ta+=1\r\n\t\t\t\tbreak\r\n\t\tstack.append(j)\r\n\t\tgraph[j].remove(x)\r\n\t\tpapa[j]=x\r\nprint(*ans)\r\n",
"n = int(input())\nadj = [[] for _ in range(n)]\n\nfor _ in range(n - 1):\n u, v = map(int, input().split())\n adj[u - 1].append(v - 1)\n adj[v - 1].append(u - 1)\n\nv, mx = -1, -1\nfor i in range(n):\n if len(adj[i]) > mx:\n v, mx = i, len(adj[i])\n\nmx += 1\nans = [-1] * n\nans[v] = 0\n\nfrom collections import deque\ndef bfs(i, ans):\n q = deque([(i, i)])\n while q:\n v, p = q.pop()\n col = (i for i in range(mx) if i != ans[v] and i != ans[p])\n for nv in adj[v]:\n if ans[nv] == -1:\n ans[nv] = next(col)\n q.append((nv, v))\n\nbfs(v, ans)\n\nfor i in range(n):\n ans[i] += 1\n\nprint(mx)\nprint(*ans)",
"#!/usr/bin/env python3\nfrom collections import deque\n\ndef ri():\n return map(int, input().split())\n\ndef bfs(s):\n ans = 0\n q = deque()\n q.append(s)\n v[s] = 1\n c[s] = 1\n p[s] = s\n while q:\n n = q.popleft()\n cc = 1\n for a in adj[n]:\n if v[a] == 0:\n while cc in [c[n], c[p[n]]]:\n cc+=1\n c[a] = cc\n cc+=1\n ans = max(2+len(adj[a])-1, ans)\n q.append(a)\n p[a] = n\n v[a] = 1\n return ans\n\nn = int(input())\nv = [0]*n\nc = [0]*n\np = [0]*n\nadj = [set() for i in range(n)]\nfor i in range(n-1):\n a, b = ri()\n a -= 1\n b -= 1\n adj[a].add(b)\n adj[b].add(a)\nfor i in range(n):\n if len(adj[i]) == 1:\n break\n\nprint(bfs(i))\nprint(*c)\n",
"import sys\r\ndef input(): return sys.stdin.buffer.readline().strip()\r\nn=int(input())\r\n\r\nadj = [[]for _ in range(n+1)]\r\n# print(adj)\r\n\r\n\r\nfor _ in range(n-1):\r\n a,b = map(int,input().split())\r\n adj[a].append(b)\r\n adj[b].append(a)\r\n \r\ncl=[0]*(n+1)\r\npar=[0]*(n+1)\r\ndef dfs(adj,i):\r\n vis=[0]*(n+1)\r\n q = [i]\r\n cl[1]=1\r\n while(len(q)>0):\r\n u = q[-1]\r\n if(vis[u]==0):\r\n vis[u]=1\r\n c=1\r\n for v in adj[u]:\r\n if(vis[v]==0):\r\n while(c==cl[u] or c==cl[par[u]]):\r\n c+=1\r\n cl[v]=c\r\n par[v]=u\r\n c+=1\r\n q.append(v)\r\n else:\r\n q.pop()\r\nm=0 \r\nfor i in range(1,n+1):\r\n m = max(m,len(adj[i])+1)\r\n\r\nprint(m)\r\ndfs(adj,1)\r\nfor i in range(1,n+1):\r\n print(cl[i],end=\" \")\r\n \r\n \r\n# 3\r\n# 1 3 2 \r\n\r\n# 5\r\n# 1 3 2 5 4 \r\n\r\n# 3\r\n# 1 2 3 1 2 \r\n\r\n \r\n \r\n \r\n \r\n \r\n"
] | {"inputs": ["3\n2 3\n1 3", "5\n2 3\n5 3\n4 3\n1 3", "5\n2 1\n3 2\n4 3\n5 4", "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2", "3\n2 1\n3 2", "10\n2 7\n8 2\n9 8\n1 9\n4 1\n3 4\n6 3\n10 6\n5 10", "5\n4 2\n3 1\n3 4\n3 5", "7\n3 6\n3 1\n3 2\n3 5\n3 4\n3 7", "10\n8 6\n10 5\n8 4\n2 7\n3 8\n10 3\n3 9\n2 1\n3 2", "50\n45 2\n4 48\n16 4\n17 29\n29 33\n31 2\n47 41\n41 33\n22 6\n44 40\n32 24\n12 40\n28 16\n18 30\n20 41\n25 45\n35 29\n10 32\n1 48\n15 50\n6 9\n43 2\n33 2\n38 33\n8 2\n36 7\n26 48\n50 8\n34 31\n48 33\n13 45\n37 33\n7 6\n40 32\n3 6\n30 49\n49 33\n11 40\n19 40\n24 2\n14 50\n5 50\n42 16\n23 2\n9 45\n39 6\n46 48\n27 13\n21 2", "50\n8 37\n40 8\n38 40\n10 38\n29 10\n33 29\n17 33\n25 17\n19 25\n3 19\n13 3\n24 13\n12 24\n5 12\n41 5\n11 41\n27 11\n45 27\n6 45\n35 6\n9 35\n50 9\n32 50\n21 32\n22 21\n1 22\n31 1\n28 31\n4 28\n30 4\n7 30\n48 7\n46 48\n16 46\n49 16\n39 49\n18 39\n14 18\n34 14\n23 34\n20 23\n15 20\n44 15\n42 44\n2 42\n36 2\n43 36\n26 43\n47 26", "50\n7 5\n6 40\n49 43\n48 2\n44 11\n10 3\n46 49\n22 18\n17 33\n4 29\n48 4\n47 41\n24 19\n48 8\n1 21\n2 17\n17 34\n16 10\n17 20\n1 22\n44 32\n6 28\n7 1\n47 26\n28 44\n23 50\n21 15\n1 30\n7 27\n28 25\n17 23\n14 42\n6 46\n5 24\n44 9\n25 39\n46 47\n21 35\n7 16\n34 12\n45 14\n35 36\n28 13\n6 48\n46 37\n39 45\n40 7\n2 31\n30 38"], "outputs": ["3\n1 3 2 ", "5\n1 3 2 5 4 ", "3\n1 2 3 1 2 ", "5\n1 2 1 3 2 1 2 3 4 5 ", "3\n1 2 3 ", "3\n1 1 2 3 2 1 2 3 2 3 ", "4\n1 1 2 3 4 ", "7\n1 4 2 6 5 3 7 ", "5\n1 2 4 3 1 2 3 1 5 3 ", "9\n1 4 4 3 4 2 3 6 5 2 5 4 3 3 2 1 2 2 6 2 9 1 8 7 2 4 2 2 1 1 2 1 5 1 3 1 7 6 6 3 3 4 3 2 1 6 1 2 8 1 ", "3\n1 3 2 1 1 2 2 2 3 2 2 2 1 1 3 2 2 2 3 1 3 2 2 3 1 3 1 2 1 3 3 1 3 3 1 2 3 3 3 1 3 1 1 2 3 3 2 1 1 2 ", "6\n1 2 2 3 2 1 4 5 5 1 1 2 5 3 3 5 1 2 3 5 2 3 6 1 4 2 3 2 1 5 3 4 3 4 4 1 5 2 1 6 1 1 1 3 2 3 4 4 2 2 "]} | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
3109c0e4b05b3087bcfdcb8b1ca095d3 | Heidi and Library (medium) | Whereas humans nowadays read fewer and fewer books on paper, book readership among marmots has surged. Heidi has expanded the library and is now serving longer request sequences.
Same as the easy version, but the limits have changed: 1<=≤<=*n*,<=*k*<=≤<=400<=000.
Same as the easy version.
Sample Input
4 100
1 2 2 1
4 1
1 2 2 1
4 2
1 2 3 1
Sample Output
2
3
3
| [
"# https://codeforces.com/problemset/problem/802/B\r\nimport heapq\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nd = {}\r\npos = {}\r\nQ = []\r\ncnt = 0\r\n\r\nfor i, x in enumerate(a):\r\n if x not in pos:\r\n pos[x] = []\r\n pos[x].append(i)\r\n \r\nfor i, x in enumerate(a):\r\n \r\n if x not in d:\r\n cnt += 1\r\n \r\n if len(d) == k:\r\n pos_, x_ = heapq.heappop(Q)\r\n del d[x_]\r\n d[x] = 1\r\n \r\n pos[x].pop(0)\r\n \r\n if len(pos[x]) > 0:\r\n heapq.heappush(Q, (-pos[x][0], x))\r\n else:\r\n heapq.heappush(Q, (-float('inf'), x)) \r\n \r\nprint(cnt) "
] | {"inputs": ["4 100\n1 2 2 1", "4 1\n1 2 2 1", "4 2\n1 2 3 1", "11 1\n1 2 3 5 1 10 10 1 1 3 5", "5 2\n1 2 3 1 2", "4 2\n1 2 3 2", "1 1\n1"], "outputs": ["2", "3", "3", "9", "4", "3", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
311321b9f47985d2496064b27ba62fd1 | The Wall (easy) | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segments. We call on you for help. Go forth and explore the wall! Report how many disconnected segments there are.
The wall is a two-dimensional structure made of bricks. Each brick is one unit wide and one unit high. Bricks are stacked on top of each other to form columns that are up to *R* bricks high. Each brick is placed either on the ground or directly on top of another brick. Consecutive non-empty columns form a wall segment. The entire wall, all the segments and empty columns in-between, is *C* columns wide.
The first line of the input consists of two space-separated integers *R* and *C*, 1<=≤<=*R*,<=*C*<=≤<=100. The next *R* lines provide a description of the columns as follows:
- each of the *R* lines contains a string of length *C*, - the *c*-th character of line *r* is B if there is a brick in column *c* and row *R*<=-<=*r*<=+<=1, and . otherwise.
The number of wall segments in the input configuration.
Sample Input
3 7
.......
.......
.BB.B..
4 5
..B..
..B..
B.B.B
BBB.B
4 6
..B...
B.B.BB
BBB.BB
BBBBBB
1 1
B
10 7
.......
.......
.......
.......
.......
.......
.......
.......
...B...
B.BB.B.
8 8
........
........
........
........
.B......
.B.....B
.B.....B
.BB...BB
Sample Output
2
2
1
1
3
2
| [
"n,m=map(int,input().split())\r\nfor i in range(n):\r\n k=input()\r\nf=1\r\nans=0\r\nfor i in k:\r\n if i=='B' and f:\r\n ans+=1\r\n f=0\r\n if i=='.':\r\n f=1\r\nprint(ans)",
"y, x = [int(each) for each in input().split(\" \")]\nfor _ in range(y-1):\n input()\nsegments = 0\nprev_hole = True\nfor each in input():\n if each == 'B':\n if prev_hole:\n segments += 1\n prev_hole = False\n else:\n prev_hole = True\nprint(segments)\n \t\t\t \t \t\t \t\t\t \t \t\t\t\t\t\t\t",
"r, c = map(int, input().split())\n\nlast = \"\"\nfor i in range(r):\n s = str(input())\n\n if i == r - 1:\n last = s\n\n\nanswer = 0\nleft = 0\n\nwhile left <= c - 1:\n if last[left] == \"B\":\n try:\n while last[left] == \"B\":\n left += 1\n except Exception:\n pass\n answer += 1\n else:\n left += 1\n\n\nprint(answer)\n\n",
"n, m = map(int, input().split())\r\na = ''\r\nfor _ in range(n):\r\n a = input()\r\nans = 0\r\ni = 0\r\nwhile i < m:\r\n if 'B' == a[i]:\r\n ans += 1\r\n while i < m and 'B' == a[i]:\r\n i += 1\r\n else:\r\n i += 1\r\nprint(ans)\r\n",
"\r\nr,c = [int(s) for s in input().split()]\r\n\r\nw =[]\r\nfor i in range(r):\r\n w.append(input())\r\n\r\ncount = 0\r\ndef isEmpty(i):\r\n for j in range(r):\r\n if(w[j][i] == 'B'):\r\n return False\r\n return True\r\n\r\nstarted = False\r\nfor i in range(c):\r\n if not (isEmpty(i) or started):\r\n started = True\r\n count += 1\r\n if isEmpty(i):\r\n started = False\r\n\r\nprint(count)\r\n",
"r, c = input().split()\r\nfor q in range(int(r)):\r\n s = input() + \".\"\r\n\r\nprint(s.count(\"B.\"))\r\n",
"row, col = list(map(int, input().split()))\r\nfor _ in range(row - 1):\r\n input()\r\ns = input()\r\n\r\nans = 0\r\nprev = '.'\r\nfor char in s:\r\n if char == \"B\" and prev == \".\":\r\n ans += 1\r\n\r\n prev = char\r\n\r\nprint(ans)",
"r = int(input().split()[0])\r\nfor i in range(r-1):\r\n\ttrash = input()\r\nprint((input().strip('.')+'.').count('B.'))",
"from sys import *\r\nprint((stdin.read().split()[-1] + '.').count('B.'))",
"n, m = map(int, input().split())\r\nfor i in range(n):\r\n s = input()\r\n\r\ns = s.strip('.')\r\n\r\nwhile '..' in s:\r\n s = s.replace('..', '.')\r\n\r\nprint(len(s.split('.')))\r\n",
"read = lambda: map(int, input().split())\r\nn, m = read()\r\na = [input() for i in range(n)]\r\ns = a[n - 1].split('.')\r\ncnt = len(s) - s.count('')\r\nprint(cnt)\r\n",
"r, c = map(int, input().split())\n\nfor _ in range(r-1):\n input()\n\nbottom = input()\n\nsections = 0\n\nlooking_for_new_section = True\n\n\nfor brick in bottom:\n if looking_for_new_section:\n if brick == 'B':\n looking_for_new_section = False\n sections += 1\n else:\n if brick == '.':\n looking_for_new_section = True\n\nprint(sections)\n",
"r, c = map(int, input().split())\r\nfor i in range(r):\r\n v = input()\r\n if i == r - 1:\r\n v = v.lstrip(\".\")\r\n v = v.rstrip(\".\")\r\n l = len(v)\r\n count = 0\r\n b = True\r\n for j in range(l):\r\n if v[j] == \".\" and b:\r\n count += 1\r\n b = False\r\n elif v[j] == \"B\" and not b:\r\n b = True\r\nprint(count + 1)\r\n\r\n",
"m,n=map(int,input().split())\r\nfor rows in range(m):\r\n row = input()\r\nrow=\".\"+row\r\nprint(row.count(\".B\"))",
"def to_int_list(inp):\n return list(map(lambda s: int(s), inp.split()))\n\n\nrows, columns = to_int_list(input())\n\nrow = ''\nfor r in range(rows):\n row = input()\n\nsegments = sum(map(lambda s: len(s) > 0, row.split('.')))\nprint(segments)\n",
"r,c=[int(i) for i in input().split()]\r\nfor i in range(r-1):\r\n input()\r\ns=input()\r\nfor i in range(c):\r\n s=s.replace('BB','B')\r\nprint(s.count('B'))\r\n",
"def transpose(mas: list):\r\n data_T = ['0'] * c\r\n for k in range(c):\r\n tmp = ''\r\n for j in range(r):\r\n tmp += data[j][k]\r\n data_T[k] = tmp\r\n return data_T\r\n\r\n\r\nr, c = map(int, input().split())\r\ndata = ['0'] * r\r\n\r\nfor i in range(r):\r\n data[i] = input()\r\n\r\n\r\nans = transpose(data)\r\nindexes = []\r\nfor i in range(c):\r\n if ans[i].count('B') > 0:\r\n indexes.append(i)\r\ncnt = 1\r\nfor i in range(len(indexes) - 1):\r\n if indexes[i + 1] - indexes[i] > 1:\r\n cnt += 1\r\n\r\nprint(cnt)",
"n, m = map(int, input().split())\na = [input() for i in range(n)]\nans = 0\ni = 0\nwhile i < m:\n if a[n-1][i] == \"B\":\n ans += 1\n while i < m and a[n-1][i] == \"B\":\n i += 1\n i += 1\n \nprint(ans)\n\t \t \t \t \t\t\t\t \t \t\t \t\t\t\t\t\t \t",
"r,c=list(map(int,input().split()))\r\nfor i in range(r):\r\n a=input()\r\nb=0\r\nz=0\r\nfor j in range(c):\r\n if a[j]=='B':\r\n if z==0:\r\n b+=1\r\n z=1\r\n else:\r\n z=0\r\nprint(b)",
"r, c = map(int, input().split())\r\n\r\nfor i in range(r-1):\r\n\ts = input()\r\ns = input()\r\n\r\nx = 0\r\ncnt = 0\r\nfor i in range(c):\r\n\tif s[i] == \"B\":\r\n\t\tx += 1\r\n\telse:\r\n\t\tif x > 0:\r\n\t\t\tcnt += 1\r\n\t\tx = 0\r\nif x > 0:\r\n\tcnt += 1\r\nprint (cnt)",
"n, m = map(int, input().split())\r\na = [input() for _ in range(n)]\r\nused = [[False] * m for _ in range(n)]\r\nans = 0\r\nfor i in range(n):\r\n for j in range(m):\r\n if not used[i][j] and a[i][j] == \"B\":\r\n ans += 1\r\n q = [(i, j)]\r\n used[i][j] = True\r\n head = 0\r\n while head < len(q):\r\n x, y = q[head]\r\n head += 1\r\n for d in range(4):\r\n xx = x + (1 if d == 0 else -1 if d == 1 else 0)\r\n yy = y + (1 if d == 2 else -1 if d == 3 else 0)\r\n if 0 <= xx < n and 0 <= yy < m and not used[xx][yy] and a[xx][yy] == \"B\":\r\n used[xx][yy] = True\r\n q.append((xx, yy))\r\nprint(ans)\r\n",
"r,x = map(int, input().split())\r\ns = \"\"\r\nfor i in range(r):\r\n s = input()\r\nc=0\r\nif s[0]=='B':\r\n c = 1\r\nfor i in range(1,x):\r\n if(s[i]=='B' and s[i-1]=='.'):\r\n c+=1\r\n\r\nprint(c)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nr, c = map(int, input().split())\r\n\r\nfor i in range(r-1):\r\n input()\r\ns = input()[:-1]\r\n\r\nfor i in range(c):\r\n s = s.replace('BB', 'B')\r\n\r\nprint(s.count('B'))\r\n",
"n,m = map(int,input().split())\r\nc = []\r\nfor i in range(n):\r\n a = list(input())\r\nl = 0\r\nfor i in range(len(a)-1):\r\n if(a[i]=='B' and a[i+1]=='.'):\r\n l+=1\r\nif(a[-1]=='B'):\r\n l+=1\r\nprint(l)\r\n",
"n, k = map(int, input().split())\r\n\r\nrows = []\r\nfor row in range(n):\r\n rows.append(input())\r\nseg = []\r\nind = []\r\nfor i in range(n):\r\n for j in range(k):\r\n if rows[i][j] == 'B':\r\n ind.append(j)\r\n\r\nfor i in range(min(ind), max(ind)+1):\r\n c = 0\r\n for j in rows:\r\n if j[i] == \".\":\r\n c += 1\r\n c -= 1\r\n if c == 0:\r\n seg.append(i)\r\n\r\nseg.sort()\r\nfin = 1\r\nif len(seg) > 0:\r\n fin += 1\r\nfor i in range(1, len(seg)):\r\n if seg[i] - 1 == seg[i-1]:\r\n continue\r\n else:\r\n fin += 1\r\n\r\nprint(fin)\r\n",
"import sys, math\r\nn,m = map(int,input().split())\r\nfor i in range(n-1):\r\n input()\r\nw=input()\r\nw+='.'\r\nans = 0\r\nnow=1\r\nfor i in w:\r\n if i == 'B':\r\n if now:\r\n now = 0\r\n ans+=1\r\n else:\r\n continue\r\n else:\r\n now = 1\r\nprint(ans)\r\n",
"inc=input().split(' ')\r\nfor i in range(int(inc[0])):\r\n foundation = input()\r\nbl=True\r\nblock=0\r\nfor i in range(int(inc[1])):\r\n if bl and foundation[i] == 'B':\r\n bl=False\r\n block+=1\r\n elif (not bl) and foundation[i] == '.':\r\n bl=True\r\nprint (block)",
"x=input().split()\r\nr=int(x[0])\r\nmas=\"\"\r\nfor i in range(r):\r\n if i+1==r:\r\n mas=input()\r\n mas=mas+\".\"\r\n mas=\".\"+mas\r\n else:\r\n input()\r\ng=0\r\nfor i in range(len(mas)-1):\r\n if mas[i]!=mas[i+1]:\r\n g=g+1\r\nprint(int(g/2))",
"mod = 1000000007\r\nii = lambda : int(input())\r\nsi = lambda : input()\r\ndgl = lambda : list(map(int, input()))\r\nf = lambda : map(int, input().split())\r\nil = lambda : list(map(int, input().split()))\r\nls = lambda : list(input())\r\nfrom itertools import groupby\r\nn,m=f()\r\ncnt=0\r\nx=''\r\nfor i in range(n):\r\n x=si()\r\nc=0\r\nfor i,j in groupby(x):\r\n c+=(i=='B')\r\nprint(c)",
"import poplib\r\nimport string\r\nimport math\r\n\r\ndef main_function():\r\n r, c = [int(i) for i in input().split(\" \")]\r\n wall = [input() for i in range(r)]\r\n currently_in_segment = False\r\n counter = 0\r\n for i in range(c):\r\n is_wall = False\r\n for j in range(r):\r\n if wall[j][i] == \"B\":\r\n is_wall = True\r\n break\r\n if currently_in_segment:\r\n if i == c - 1 or not is_wall:\r\n counter += 1\r\n currently_in_segment = False\r\n else:\r\n if is_wall:\r\n currently_in_segment = True\r\n if i == c - 1:\r\n counter += 1\r\n print(counter)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n main_function()",
"n, m = map(int, input().split())\r\na = [input() for i in range(n)]\r\nans = 0\r\ni = 0\r\nwhile i < m:\r\n if a[n-1][i] == \"B\":\r\n ans += 1\r\n while i < m and a[n-1][i] == \"B\":\r\n i += 1\r\n i += 1\r\n \r\nprint(ans)",
"h,w = list(map(int,input().split()))\r\narr = []\r\nfor i in range(h):\r\n arr.append(input())\r\nc = 0\r\nd = (arr[h-1].split(\".\"))\r\nfor i in range(len(d)):\r\n if d[i]!= \"\":\r\n c+=1\r\nprint(c)",
"a , b = map(int , input().split())\r\n\r\nfor i in range(a):\r\n l = list(map(str , input().split()))\r\n if i == a-1:\r\n l = str(l)\r\n l = l.replace('.' , ' '); l = l.replace('[' , ' '); l = l.replace(']' , ' '); l = l.replace(\"'\" , ' '); \r\n fragments = list(map(str , l.split()))\r\n print(len(fragments))\r\n",
"rc = input()\nrc = rc.split()\n\nr = int(rc[0])\nc = int(rc[1])\n\nfor i in range(r):\n\trow = input()\n\ncount=0\nfor i in range(len(row)):\n\t if(row[i] == 'B' and (i==0 or row[i-1]=='.')):\n\t \tcount+=2\n\t if(row[i] == 'B' and (i==len(row)-1 or row[i+1]=='.')):\n\t \tcount-=1\n\t \nprint (count)\n",
"n,m=map(int,input().split())\r\nk1=[]\r\nfor i in range(n):\r\n k=list(map(str,input()))\r\n k1.append(k)\r\np=0\r\nfor j in range(m):\r\n if (k1[n-1][j]==\"B\" and j>0 and k1[n-1][j-1]==\".\") or (k1[n-1][j]==\"B\" and j==0):\r\n p+=1\r\nprint(p)\r\n\r\n",
"r,c=list(map(int,input().split()))\r\n\r\nfor i in range(r):\r\n walls=input()\r\n \r\ncount=0\r\n\r\nfor i in range(c):\r\n if i==0 and walls[i]=='.':\r\n continue\r\n elif i==0 and walls[i]=='B':\r\n count+=1\r\n elif walls[i]=='B' and walls[i-1]=='.':\r\n count+=1\r\n else:\r\n continue\r\nprint(count)\r\n ",
"# 690 D1\r\nr,c = [int(i) for i in input().split()]\r\nfor i in range(r-1):\r\n\tinput()\r\ns = input()\r\nsegs = 0\r\nprev = '.'\r\nfor x in s:\r\n\tif x=='B' and prev =='.':\r\n\t\tsegs += 1\r\n\tprev = x\r\nprint(segs)\r\n"
] | {"inputs": ["3 7\n.......\n.......\n.BB.B..", "4 5\n..B..\n..B..\nB.B.B\nBBB.B", "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB", "1 1\nB", "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\nB.BB.B.", "8 8\n........\n........\n........\n........\n.B......\n.B.....B\n.B.....B\n.BB...BB"], "outputs": ["2", "2", "1", "1", "3", "2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 37 | |
311a06f18b45f0869a1d65aeb21bc2eb | Mausoleum | King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital.
The mausoleum will be constructed from 2*n* blocks, each of them has the shape of a cuboid. Each block has the bottom base of a 1<=×<=1 meter square. Among the blocks, exactly two of them have the height of one meter, exactly two have the height of two meters, ..., exactly two have the height of *n* meters.
The blocks are arranged in a row without spacing one after the other. Of course, not every arrangement of blocks has the form of a mausoleum. In order to make the given arrangement in the form of the mausoleum, it is necessary that when you pass along the mausoleum, from one end to the other, the heights of the blocks first were non-decreasing (i.e., increasing or remained the same), and then — non-increasing (decrease or remained unchanged). It is possible that any of these two areas will be omitted. For example, the following sequences of block height meet this requirement:
- [1,<=2,<=2,<=3,<=4,<=4,<=3,<=1]; - [1,<=1]; - [2,<=2,<=1,<=1]; - [1,<=2,<=3,<=3,<=2,<=1].
Suddenly, *k* more requirements appeared. Each of the requirements has the form: "*h*[*x**i*] sign*i* *h*[*y**i*]", where *h*[*t*] is the height of the *t*-th block, and a sign*i* is one of the five possible signs: '=' (equals), '<' (less than), '>' (more than), '<=' (less than or equals), '>=' (more than or equals). Thus, each of the *k* additional requirements is given by a pair of indexes *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=2*n*) and sign sign*i*.
Find the number of possible ways to rearrange the blocks so that both the requirement about the shape of the mausoleum (see paragraph 3) and the *k* additional requirements were met.
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=35, 0<=≤<=*k*<=≤<=100) — the number of pairs of blocks and the number of additional requirements.
Next *k* lines contain listed additional requirements, one per line in the format "*x**i* sign*i* *y**i*" (1<=≤<=*x**i*,<=*y**i*<=≤<=2*n*), and the sign is on of the list of the five possible signs.
Print the sought number of ways.
Sample Input
3 0
3 1
2 > 3
4 1
3 = 6
Sample Output
9
1
3
| [
"N, K = map(int, input().split())\r\nrel = [[0] * 75 for _ in range(75)]\r\ndp = [[-1] * 40 for _ in range(75)]\r\nsign = [\"=\", \"<\", \">\", \"<=\", \">=\"]\r\nrev = [0, 2, 1, 4, 3]\r\nrs = [[] for _ in range(75)]\r\ndef solve(st, pos):\r\n if pos >= N:\r\n if rel[st][st + 1] == 1 or rel[st][st + 1] == 2:\r\n return 0\r\n return 1\r\n if dp[st][pos] != -1:\r\n return dp[st][pos]\r\n res = 0\r\n en = 2 * N - (2 * pos - st - 1)\r\n fl = 1\r\n p, s = 0, 0\r\n for i in range(len(rs[st])):\r\n p = rs[st][i]\r\n s = rel[st][p]\r\n if p == en or p == st:\r\n if s == 2 or s == 1:\r\n fl = 0\r\n elif p < st or p > en:\r\n if s != 2 and s != 4:\r\n fl = 0\r\n elif s != 1 and s != 3:\r\n fl = 0\r\n for i in range(len(rs[en])):\r\n p = rs[en][i]\r\n s = rel[en][p]\r\n if p == st or p == en:\r\n if s == 2 or s == 1:\r\n fl = 0\r\n elif p < st or p > en:\r\n if s != 2 and s != 4:\r\n fl = 0\r\n elif s != 1 and s != 3:\r\n fl = 0\r\n if fl:\r\n res += solve(st + 1, pos + 1)\r\n fl = 1\r\n for i in range(len(rs[st])):\r\n p = rs[st][i]\r\n s = rel[st][p]\r\n if p == st + 1 or p == st:\r\n if s == 2 or s == 1:\r\n fl = 0\r\n elif p < st or p > en:\r\n if s != 2 and s != 4:\r\n fl = 0\r\n elif s != 1 and s != 3:\r\n fl = 0\r\n for i in range(len(rs[st + 1])):\r\n p = rs[st + 1][i]\r\n s = rel[st + 1][p]\r\n if p == st or p == st + 1:\r\n if s == 2 or s == 1:\r\n fl = 0\r\n elif p < st or p > en:\r\n if s != 2 and s != 4:\r\n fl = 0\r\n elif s != 1 and s != 3:\r\n fl = 0\r\n if fl:\r\n res += solve(st + 2, pos + 1)\r\n fl = 1\r\n for i in range(len(rs[en - 1])):\r\n p = rs[en - 1][i]\r\n s = rel[en - 1][p]\r\n if p == en or p == en - 1:\r\n if s == 2 or s == 1:\r\n fl = 0\r\n elif p < st or p > en:\r\n if s != 2 and s != 4:\r\n fl = 0\r\n elif s != 1 and s != 3:\r\n fl = 0\r\n for i in range(len(rs[en])):\r\n p = rs[en][i]\r\n s = rel[en][p]\r\n if p == en - 1 or p == en:\r\n if s == 2 or s == 1:\r\n fl = 0\r\n elif p < st or p > en:\r\n if s != 2 and s != 4:\r\n fl = 0\r\n elif s != 1 and s != 3:\r\n fl = 0\r\n if fl:\r\n res += solve(st, pos + 1)\r\n dp[st][pos] = res\r\n return res\r\nfor _ in range(K):\r\n a, s, b = map(str, input().split())\r\n a, b = int(a), int(b)\r\n x = sign.index(s)\r\n rs[a].append(b)\r\n rs[b].append(a)\r\n rel[a][b] = x\r\n rel[b][a] = rev[x]\r\nprint(solve(1, 1))# 1693600427.7071342"
] | {"inputs": ["3 0", "3 1\n2 > 3", "4 1\n3 = 6", "5 2\n1 < 2\n9 > 10", "35 0", "10 5\n17 <= 10\n16 >= 18\n9 > 18\n8 = 8\n6 >= 13", "5 2\n1 = 10\n2 = 9", "3 3\n1 = 2\n3 = 4\n5 = 6", "4 3\n2 > 3\n4 > 5\n6 > 7", "1 1\n1 > 2", "1 1\n1 <= 2", "5 3\n2 > 10\n4 > 8\n3 = 6", "5 3\n2 <= 4\n6 <= 7\n5 > 6", "8 5\n2 <= 4\n5 > 10\n3 < 9\n4 = 8\n12 >= 16", "5 5\n10 <= 8\n5 >= 7\n10 < 4\n5 = 5\n10 <= 2", "6 2\n3 <= 7\n6 >= 10", "5 10\n5 >= 8\n3 > 9\n5 >= 9\n5 = 6\n8 <= 3\n6 > 9\n3 < 1\n1 >= 9\n2 > 3\n8 <= 1", "5 8\n8 = 9\n7 >= 7\n3 <= 9\n4 > 10\n5 >= 1\n7 = 7\n2 < 6\n4 <= 7", "10 5\n11 >= 18\n1 > 10\n15 >= 19\n15 <= 13\n2 > 6", "20 50\n26 <= 22\n32 >= 40\n32 < 14\n2 > 22\n5 >= 34\n33 <= 19\n17 > 35\n14 >= 22\n35 < 25\n6 > 7\n2 >= 1\n35 <= 28\n35 < 34\n27 <= 15\n13 > 20\n9 >= 25\n8 > 22\n18 < 8\n12 >= 2\n2 > 24\n14 = 15\n5 >= 17\n29 <= 26\n25 > 28\n3 >= 35\n8 > 3\n31 < 7\n36 = 36\n39 <= 7\n35 < 18\n18 <= 4\n26 < 17\n20 >= 30\n14 <= 12\n35 < 8\n5 > 28\n22 <= 1\n19 >= 22\n13 < 9\n25 <= 2\n3 > 37\n40 < 4\n40 <= 2\n26 >= 33\n3 > 26\n25 >= 32\n13 > 14\n18 < 10\n16 = 1\n9 <= 7", "35 1\n26 >= 66", "35 1\n2 <= 28", "35 1\n69 <= 26", "35 35\n54 <= 25\n32 >= 61\n67 < 45\n27 <= 11\n32 > 44\n32 >= 41\n62 < 39\n21 > 33\n50 >= 66\n64 <= 51\n53 < 32\n22 > 35\n50 <= 44\n30 >= 35\n34 > 60\n24 < 20\n50 <= 20\n12 = 12\n53 < 23\n40 <= 9\n8 >= 53\n30 > 51\n23 >= 29\n58 < 24\n7 > 70\n20 >= 56\n38 <= 19\n35 < 21\n48 <= 31\n42 < 9\n25 > 37\n2 >= 50\n25 > 66\n21 >= 22\n42 <= 31", "30 50\n56 <= 26\n47 >= 42\n18 > 7\n51 < 28\n36 >= 5\n58 = 58\n49 > 24\n2 <= 31\n24 < 37\n7 >= 2\n7 <= 33\n14 < 16\n11 <= 35\n33 > 7\n55 < 31\n46 >= 41\n55 > 5\n18 >= 60\n12 > 59\n10 <= 30\n25 >= 23\n40 > 3\n49 >= 45\n20 > 6\n60 < 53\n21 >= 5\n11 <= 50\n12 < 33\n1 <= 10\n44 > 29\n48 >= 58\n49 > 47\n5 < 38\n20 <= 33\n4 < 7\n31 >= 23\n24 > 1\n18 >= 11\n23 <= 31\n37 > 13\n13 >= 5\n4 < 52\n40 > 21\n18 <= 26\n37 >= 27\n50 > 36\n37 >= 32\n54 = 55\n31 > 14\n58 < 52", "30 50\n46 <= 27\n19 < 18\n44 <= 21\n36 < 10\n39 >= 51\n23 > 60\n34 >= 45\n17 > 36\n34 <= 27\n14 >= 55\n9 > 12\n52 < 31\n59 <= 12\n59 < 46\n37 >= 46\n53 <= 28\n31 > 59\n46 < 24\n53 <= 25\n4 >= 26\n51 > 60\n14 < 7\n3 >= 22\n11 > 46\n60 <= 8\n6 >= 39\n13 > 16\n33 < 11\n18 >= 26\n47 <= 7\n47 < 3\n6 = 6\n56 <= 29\n29 > 54\n5 >= 34\n27 > 51\n48 < 3\n47 <= 7\n8 >= 34\n17 > 30\n4 >= 7\n13 < 9\n2 > 28\n14 = 14\n41 <= 12\n17 >= 19\n31 > 54\n13 >= 32\n1 > 7\n33 < 16", "30 0", "22 2\n32 = 39\n27 >= 27", "30 50\n17 >= 29\n19 <= 18\n3 > 50\n54 >= 56\n47 < 15\n50 <= 33\n49 < 8\n57 <= 16\n30 > 35\n49 < 21\n3 >= 37\n56 <= 51\n46 > 51\n35 >= 48\n32 < 15\n12 <= 4\n38 > 57\n55 < 9\n49 <= 1\n9 >= 38\n60 = 60\n1 > 12\n40 >= 43\n13 > 38\n24 >= 39\n9 < 2\n12 > 58\n15 >= 30\n13 > 50\n42 <= 16\n23 >= 54\n16 < 10\n1 > 43\n4 >= 57\n22 > 25\n2 >= 53\n9 > 55\n46 <= 10\n44 < 11\n51 <= 18\n15 >= 31\n20 > 23\n35 < 13\n46 <= 44\n10 < 6\n13 >= 28\n17 > 48\n53 <= 36\n36 >= 42\n29 < 15", "20 20\n26 <= 10\n10 >= 22\n2 > 17\n16 = 16\n16 >= 31\n31 < 16\n28 <= 3\n2 > 25\n4 >= 30\n21 < 9\n4 > 5\n27 <= 20\n27 >= 38\n18 > 37\n17 < 5\n10 <= 8\n21 < 10\n3 >= 9\n35 > 40\n19 <= 3", "20 50\n31 >= 18\n36 > 9\n23 <= 27\n8 < 22\n17 <= 18\n13 < 20\n27 >= 4\n13 <= 18\n25 < 36\n25 <= 29\n11 > 8\n24 < 26\n5 <= 35\n14 >= 5\n1 < 12\n40 <= 30\n2 < 38\n10 <= 27\n15 > 1\n5 < 16\n27 <= 31\n24 < 27\n21 >= 8\n10 <= 36\n25 > 6\n10 >= 9\n34 > 29\n3 < 24\n26 >= 2\n39 <= 6\n23 < 28\n6 <= 37\n36 > 16\n35 >= 1\n17 > 6\n27 = 27\n32 = 33\n11 < 23\n14 <= 20\n22 < 24\n25 >= 8\n32 > 20\n20 <= 34\n33 >= 26\n36 > 9\n9 < 31\n6 = 5\n12 <= 24\n32 >= 3\n27 > 1", "20 10\n17 <= 7\n22 >= 35\n13 < 12\n19 > 24\n2 >= 21\n19 > 35\n23 >= 32\n34 <= 29\n22 > 30\n3 >= 28", "35 15\n31 >= 14\n12 <= 62\n26 < 34\n48 > 46\n14 <= 35\n28 >= 19\n18 < 37\n61 > 28\n40 <= 54\n59 >= 21\n7 < 40\n6 > 4\n2 = 69\n48 <= 61\n46 >= 30"], "outputs": ["9", "1", "3", "27", "16677181699666569", "6804", "9", "4", "1", "0", "1", "5", "11", "0", "40", "153", "1", "8", "9", "16", "16672955716972557", "16677181687443426", "16677125911116153", "26126142062", "4805262", "9", "68630377364883", "209304", "36", "102", "8784", "61374", "1930894281"]} | UNKNOWN | PYTHON3 | CODEFORCES | 1 | |
313572d7684606e9ef8c0c75910331c7 | Wet Shark and Odd and Even | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
Sample Input
3
1 2 3
5
999999999 999999999 999999999 999999999 999999999
Sample Output
63999999996 | [
"def isOdd (x):\r\n\treturn x%2==1\r\ndef isEven (x):\r\n\treturn x%2==0\r\ninput()\r\narr = [int(z) for z in input().split()]\r\noddA = list(filter(isOdd,arr))\r\noddA.sort()\r\nevenSum = sum(filter(isEven,arr))\r\nif(isOdd(len(oddA))):\r\n\tprint(evenSum+sum(oddA[1:]))\r\nelse:\r\n\tprint(evenSum+sum(oddA))\r\n\r\n",
"n=int(input())\ns=0\nm=100000000000\nfor i in map(int,input().split()):\n s+=i\n if(i%2!=0):m=min(i,m)\nif(s%2!=0):s-=m\nprint(s)",
"n = int(input())\r\na = list(map(int,input().split()))\r\nlowest_odd = 10**9+1\r\nSum = 0\r\nfor a_i in a:\r\n\tSum += a_i\r\n\tif a_i % 2 == 1 and a_i < lowest_odd:\r\n\t\tlowest_odd = a_i\r\nif (Sum % 2 == 0):\r\n\tprint (Sum)\r\nelse:\r\n\tprint(Sum - lowest_odd)",
"Z = int(input())\r\nA = list(map(int, input().split()))\r\ns = sum(A)\r\nif s % 2 == 0:\r\n print(s)\r\nelse:\r\n print(s - min([x for x in A if x % 2 == 1]))",
"n = int(input())\r\na = sorted(map(int, input().split()))\r\nk = 0\r\nif sum(a) % 2 != 0:\r\n for i in a:\r\n if i % 2 != 0:\r\n c = i\r\n break\r\n for i in a:\r\n k += i\r\n print(k - c)\r\nelse:\r\n print(sum(a))\r\n",
"n=input()\r\nn=int(n)\r\nnumbers=list(map(int,input().split()))\r\neven=[]\r\nodd=[]\r\nsum=0\r\nfor i in range(0,n) :\r\n if numbers[i]%2==0 :\r\n even.append(numbers[i])\r\n else :\r\n odd.append(numbers[i])\r\n\r\n\r\nfor i in range(0,len(even)) :\r\n sum=sum+even[i]\r\n\r\nodd.sort()\r\nodd.reverse()\r\n\r\nx=len(odd)\r\n\r\nif x%2!=0 :\r\n x=x-1\r\n\r\nfor i in range(0,x) :\r\n sum=sum+odd[i]\r\n\r\n\r\n\r\nprint(sum)\r\n\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ne=[]\r\no=[]\r\nfor i in l:\r\n if i%2==0:\r\n e +=[i]\r\n else:\r\n o +=[i]\r\nif len(o)%2==0:\r\n print(sum(o)+sum(e))\r\nelse:\r\n o.sort()\r\n print(sum(e)+sum(o[1:]))\r\n",
"from sys import stdin\r\nn = int(stdin.readline())\r\nnums = list(map(int, stdin.readline().rstrip().split(' ')))\r\nodds = []\r\nevens = []\r\ns = 0\r\n\r\nfor num in nums:\r\n if num % 2 == 0:\r\n evens.append(num)\r\n s += num\r\n else:\r\n odds.append(num)\r\n\r\nodds.sort(reverse=True)\r\nif len(odds) % 2 == 0:\r\n s += sum(odds)\r\nelse:\r\n s += sum(odds[0:len(odds)-1])\r\nprint(s)",
"bob=int(input())\nl=input()\nl=l.split()\namount=0\nbig=0\nlittle=999999999\nfor i in range(len(l)):\n l[i]=int(l[i])\n amount+=l[i]\n if l[i]%2==1 and l[i]<little:\n little=l[i]\nif amount%2==0:\n big=amount\nelse:\n big=amount-little\nprint(big)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\nans,even,odd=0,0,0\r\na.sort()\r\nfor i in range(n):\r\n if a[i]%2!=0:\r\n even+=1\r\n odd+=1\r\n if even==1:\r\n ans=a[i]\r\nif odd%2==0:\r\n print(s)\r\nelse:\r\n print(s-ans)\r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n",
"count = int(input())\r\ntotal, smallest = 0, 10**9\r\nnumbers = map(int, input().split())\r\n\r\nfor x in numbers:\r\n if x < smallest and x % 2:\r\n smallest = x\r\n total += x\r\n \r\nif total % 2 == 0:\r\n print (total)\r\nelse:\r\n print (total - smallest)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nsum1=sum(l)\r\nif sum1%2==0:\r\n print(sum1)\r\nelse:\r\n l.sort()\r\n l=set(l)\r\n l=list(l)\r\n l.sort()\r\n for i in range(len(l)):\r\n sum2=sum1-l[i]\r\n if (sum2%2==0):\r\n print(sum2)\r\n break",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\nnch = []\r\nsum1 = 0\r\nfor i in a:\r\n if i%2 == 0:\r\n sum1 += i\r\n else:\r\n nch.append(i)\r\nif len(nch)%2 == 1:\r\n nch.remove(min(nch))\r\nfor i in nch:\r\n sum1 += i\r\nprint(sum1)",
"n = int(input())\r\ns = list(map(int, input().split(\" \")))\r\nodd = []\r\neven = []\r\nfor i in s:\r\n if i % 2 == 0:\r\n even.append(i)\r\n else:\r\n odd.append(i)\r\nodd.sort(reverse = True)\r\nif len(odd) % 2 == 0:\r\n print(sum(s))\r\nelse:\r\n print(sum(even) + sum(odd[0:len(odd)-1]))",
"n = int(input())\r\nl = list(map(int, input().rstrip().split()))\r\ne,o = [], []\r\nfor i in l:\r\n if i%2==0:\r\n e.append(i)\r\n else:\r\n o.append(i)\r\no.sort()\r\nif len(o)%2==0:\r\n print(sum(e)+sum(o))\r\nelse:\r\n print(sum(e)+sum(o[1:]))",
"n=int(input())\r\nlis=sorted(list(map(int,input().split())))\r\nk=sum(lis)\r\nif k%2==0:\r\n print(k)\r\nelse:\r\n b=0\r\n for i in range(n):\r\n if lis[i]%2!=0:\r\n k=k-lis[i]\r\n print(k)\r\n b=1\r\n break\r\n if b==0:\r\n print(\"0\")\r\n ",
"n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nisOdd = any(i % 2 != 0 for i in a)\r\n\r\nif(not isOdd):\r\n print([sum(a),0][sum(a) % 2 != 0])\r\nelse:\r\n print([sum(a),sum(a) - min(i for i in a if i % 2 == 1)][sum(a) % 2 != 0])",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\neven_sum = sum(filter(lambda x: x % 2 == 0, nums))\r\nodd_nums = sorted(filter(lambda x: x % 2 != 0, nums), reverse=True)\r\nif len(odd_nums) % 2 == 0:\r\n even_sum += sum(odd_nums)\r\nelse:\r\n even_sum += sum(odd_nums[:-1])\r\nprint(even_sum)\r\n",
"n = int(input())\nnumbers = list(map(int, input().split()))\n\n# Список четных чисел\neven = list()\n\n# Список нечетных чисел\nodd = list()\n\nfor number in numbers:\n if number % 2 == 0:\n even.append(number)\n else:\n odd.append(number)\n\nif len(odd) % 2 == 0:\n result = sum(numbers)\nelse:\n min_odd = min(odd)\n min_odd_index = numbers.index(min_odd)\n del numbers[min_odd_index]\n result = sum(numbers)\n\nprint(result)\n",
"def akula(lst):\r\n odd, even = list(), list()\r\n for elem in lst:\r\n if elem % 2 == 0:\r\n even.append(elem)\r\n else:\r\n odd.append(elem)\r\n odd = sorted(odd)\r\n return sum(even) + sum(odd[len(odd) % 2:])\r\n\r\n\r\nn = int(input())\r\na = [int(i) for i in input().split()]\r\nprint(akula(a))\r\n",
"n = int(input())\narr = [int(i) for i in input().split()]\nmn = 10000000000\nfor i in range(n):\n if arr[i] % 2 != 0:\n mn = min(arr[i], mn)\nsum_arr = sum(arr)\nif sum_arr % 2 != 0:\n sum_arr -= mn\n\nprint(sum_arr)\n\t\t \t\t\t \t\t \t \t \t\t \t\t \t",
"n = int(input())\r\nli = list(map(int, input().split()))\r\nodd = sorted([i for i in li if i % 2 != 0])\r\neven = [i for i in li if i % 2 == 0]\r\nif len(odd) % 2 != 0:\r\n odd.remove(odd[0])\r\n print(sum(odd) + sum(even))\r\n \r\nelse:\r\n print(sum(odd) + sum(even))\r\n",
"#!/usr/bin/env python\r\n\r\nimport math\r\nimport sys\r\nimport itertools\r\nimport fractions\r\n\r\nif __name__ == '__main__':\r\n wtf = sys.stdin.read()\r\n wtf = wtf.strip().split('\\n')\r\n n = int(wtf[0])\r\n A = list(map(int, wtf[1].split()))\r\n B = []\r\n ans = 0\r\n for a in A:\r\n if a%2 == 0:\r\n ans += a\r\n else:\r\n B.append(a)\r\n B = sorted(B,reverse=True)\r\n l = len(B)\r\n if l > 1:\r\n if l%2==0:\r\n ans += sum(B)\r\n else:\r\n ans += sum(B[:-1])\r\n print(ans)\r\n",
"x = int(input())\r\nls = sorted(list(map(int, input().split())))\r\ns = sum(ls)\r\nodd = []\r\nfor i in range(x):\r\n if (ls[i] & 1):\r\n odd.append(i)\r\n\r\nif (len(odd) & 1):\r\n s -= ls[odd[0]]\r\n\r\nprint(s)\r\n",
"n = int(input())\nlst = [int(x) for x in input().split()][:n]\nsum, oddCnt, odd_L = 0, 0, 0\nfor i in lst:\n sum += i\n if i % 2 != 0:\n oddCnt += 1\n if oddCnt == 1:\n odd_L = i\n if i < odd_L:\n odd_L = i\nif oddCnt % 2 == 0: print(sum)\nelse: print(sum - odd_L)\n \t\t \t\t \t \t \t \t \t \t\t\t \t",
"a = int(input())\r\narr = list(map(int, input().split(\" \")))\r\narr.sort()\r\ns = sum(arr)\r\nif s % 2 != 0:\r\n for i in arr:\r\n if i % 2 == 1:\r\n s -= i\r\n break\r\n\r\nprint(s)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl1=[]\r\ns=0\r\nfor i in l:\r\n if i%2==0:\r\n s=s+i\r\n else:\r\n l1.append(i)\r\nl1.sort(reverse=True)\r\nif (len(l1)%2==0):\r\n s+=sum(l1)\r\nelse:\r\n l1.pop()\r\n s+=sum(l1)\r\nprint(s)\r\n",
"n=int(input())\r\n\r\nl=list(map(int,input().split()))\r\n\r\ns=0\r\n\r\np1=[]\r\n\r\nfor i in range(n):\r\n if(l[i]%2==0):\r\n s+=l[i]\r\n else:\r\n p1.append(l[i])\r\n\r\n\r\np1.sort(reverse=True)\r\n\r\nif(len(p1)%2==0):\r\n s+=sum(p1)\r\nelse:\r\n s+=sum(p1)\r\n s-=p1[-1]\r\nprint(s)\r\n",
"n=int(input())\r\nlst=[int(x) for x in input().split()]\r\nc=0\r\nnst=[]\r\nfor i in lst:\r\n if i%2!=0:\r\n nst.append(i)\r\nprint(sum(lst)) if sum(nst)%2==0 else print(sum(lst)-min(nst))",
"n = int(input())\nnumbers = sorted(map(int, input().split()))\nsum = 0\nfor i in numbers:\n sum += i\nif sum % 2 == 0:\n print(sum)\nelse:\n for j in range(n):\n sum -= numbers[j]\n if sum % 2 == 0:\n print(sum)\n break\n else:\n sum += numbers[j]\n\n\t \t\t\t \t \t \t\t\t\t\t \t \t \t\t",
"n = int(input()) # Number of Socks\r\nnumber = [int(x) for x in input().split()]\r\nnumber = sorted(number)\r\ntotal = sum(number)\r\ni = 0\r\nwhile total%2 == 1:\r\n while number[i] % 2 == 0:\r\n i+=1\r\n total -= number[i]\r\n\r\nprint(total)",
"n = int(input())\r\nm = list(map(int, input().split()))\r\nm = sorted(m)\r\ns = sum(m)\r\nif s%2==0:\r\n print(s)\r\nelse:\r\n for i in range(n):\r\n if m[i]%2==1:\r\n s -= m[i]\r\n print(s)\r\n break\r\n",
"input()\r\nx = input().split()\r\nm = 10e9\r\ns = 0\r\nfor i in x :\r\n j = int(i)\r\n s += j\r\n if j%2 != 0 and j<m:\r\n m =j\r\nprint( s if s%2 ==0 else s-m )\r\n \r\n",
"input()\r\nnums = list(i for i in map(int, input().split()))\r\nprint(sum(nums) if sum(nums) % 2 == 0 else sum(nums) - min(i for i in nums if i % 2 != 0))",
"n=int(input())\r\na=list(map(int, input().split()))\r\na.sort()\r\nodd=[];even=[]\r\n\r\nfor i in range(n):\r\n\tif a[i]%2==0:\r\n\t\teven+=[a[i]]\r\n\telse:\r\n\t\todd+=[a[i]]\r\n\r\nm=len(odd)\r\nif m%2==1:\r\n\tprint(sum(even)+sum(odd[1:]))\r\nelse:\r\n\tprint(sum(even)+sum(odd))",
"n=int(input())\r\narr = list(map(int, input().split()))\r\nk = sum(arr)\r\n\r\nif k%2==0:\r\n print(k)\r\n \r\nelse:\r\n arr.sort()\r\n for i in arr:\r\n if i%2:\r\n k -= i\r\n break\r\n \r\n print(k)\r\n ",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(x for x in a if x % 2 == 0)\r\nb = sorted(x for x in a if x % 2 == 1)\r\nprint(s + sum(b) - (0 if len(b) % 2 == 0 else b[0]))",
"n = int(input().strip())\nnum = sorted(list(map(int, input().strip().split())))\nres = sum(num)\nif res % 2 == 0:\n print(res)\nelse:\n for i in num:\n if i % 2 == 0:\n continue\n else:\n res = res - i\n break\n print(res)\n",
"import sys\r\nn = int(input())\r\nl = [int(i) for i in input().split()]\r\nans = 0\r\nfor i in range(n):\r\n ans = ans + l[i]\r\nif(ans%2 ==0):\r\n print(ans)\r\n sys.exit(0)\r\nl.sort() \r\nfor i in range(n):\r\n if((ans-l[i])%2 == 0):\r\n print(ans-l[i])\r\n sys.exit(0)\r\n",
"input()\r\nnums = list(map(int, input().split()))\r\nn_sum = sum(nums)\r\nprint(n_sum - min(filter(lambda x:x%2, nums)) if n_sum & 1 else n_sum)",
"\r\nimport sys\r\ndef get_single_int ():\r\n return int (sys.stdin.readline ().strip ())\r\ndef get_string ():\r\n return sys.stdin.readline ().strip ()\r\ndef get_ints ():\r\n return map (int, sys.stdin.readline ().strip ().split ())\r\ndef get_list ():\r\n return list (map (int, sys.stdin.readline ().strip ().split ()))\r\n\r\n#code starts here\r\nn = get_single_int ()\r\nar = (get_list ())\r\nodd = []\r\nsumm = 0\r\nodd_count = 0\r\nfor i in ar:\r\n if i % 2 == 1:\r\n odd.append (i)\r\n odd_count += 1\r\nmini = 0\r\ncheck = True\r\nif odd_count % 2 == 1:\r\n mini = min (odd)\r\nfor i in range (n):\r\n if (check and mini != 0 and ar [i] == mini):\r\n check = False\r\n continue\r\n summ += ar [i]\r\nprint (summ)\r\n\r\n\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ntotal = sum(a)\r\n\r\nif total % 2 == 0:\r\n print(total)\r\nelse:\r\n min_odd = -1\r\n for e in a:\r\n if e % 2 == 1:\r\n if min_odd == -1 or e<min_odd:\r\n min_odd = e \r\n print(total-min_odd)",
"n = int(input())\na = list(map(int, input().split()))\nmin_odd = pow(10, 9) + 1\nans = 0\nfor x in a:\n if x % 2 == 1:\n min_odd = min(min_odd, x)\n ans += x\nif ans % 2 == 1:\n ans -= min_odd\nprint(ans)\n",
"input()\n\nnums = (int(x) for x in input().split())\n\ntotal = 0\nmin_odd = None\ncount_odd = 0\n\nfor num in nums:\n if num % 2 == 1:\n count_odd += 1\n if min_odd:\n min_odd = min(min_odd, num)\n else:\n min_odd = num\n total += num\n\nif count_odd % 2 == 1:\n total -= min_odd\n\nprint(total)\n\n\t \t\t \t\t \t\t\t \t\t \t \t \t\t",
"n = int(input())\r\nv = [int(x) for x in input().split()]\r\nimpar = []\r\nsum = 0\r\nfor i in range(n):\r\n sum += v[i]\r\n if(v[i]&1):\r\n impar.append(v[i])\r\nimpar.sort()\r\nif(len(impar)&1):\r\n sum -= impar[0]\r\nprint(sum)",
"n=int(input())\r\nm=list(map(int,input().split()))\r\nm.sort()\r\nif sum(m)%2==0:\r\n\tprint(sum(m))\r\nelse:\r\n\tfor i in m:\r\n\t\tif i%2!=0:\r\n\t\t\tprint(sum(m)-i)\r\n\t\t\tbreak",
"a=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nw=sum(l)\r\nif w%2!=0:\r\n for i in l:\r\n if i%2!=0:\r\n w-=i\r\n if w%2==0:\r\n break\r\nprint(w)\r\n",
"inp = input()\r\nl = sorted(list(map(int,input().split())))\r\np = sum(l)\r\nif p%2 == 0:\r\n print(p)\r\nelse:\r\n for num in l:\r\n if (p - num)%2 == 0:\r\n print(p - num)\r\n break",
"n=int(input())\r\nl=list(map(int,input().strip().split()))\r\neven=[]\r\nodd=[]\r\n\r\nfor x in l:\r\n\tif x%2==0:\r\n\t\teven.append(x)\r\n\telse:\r\n\t\todd.append(x)\r\neven.sort()\r\nodd.sort()\r\nif len(odd)%2==0:\r\n\tprint(sum(odd)+sum(even))\r\nelse:\r\n\tprint(sum(even)+sum(odd[1:]))",
"n = int(input())\r\na = list(map(int, input().split()))\r\nchet = []\r\nne_chet = []\r\nfor i in range(len(a)):\r\n if a[i] % 2 == 0:\r\n chet.append(a[i])\r\n else:\r\n ne_chet.append(a[i])\r\nsum_chet = sum(chet)\r\nne_chet.sort()\r\nif len(ne_chet) % 2 == 0:\r\n sum_ne_chet = sum(ne_chet)\r\nelse:\r\n sum_ne_chet = sum(ne_chet[1:])\r\nprint(sum_chet + sum_ne_chet)\r\n",
"# Bismillah\r\n# In the name of GOD\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\na.sort(reverse=True)\r\nodd = 0\r\nans = 0\r\nfor i in range(n):\r\n\tif a[i] % 2:\r\n\t\todd += 1\r\nif odd % 2:\r\n\todd -= 1\r\nfor i in range(n):\r\n\tif a[i] % 2:\r\n\t\tif odd:\r\n\t\t\tans += a[i]\r\n\t\t\todd -= 1\r\n\telse:\r\n\t\tans += a[i]\r\nprint(ans)\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort(reverse=True)\r\no=0\r\nfor i in range(n):\r\n if a[i]%2!=0:\r\n o+=1\r\n#print(o)\r\nif o%2==0:\r\n lim=o\r\nelse:\r\n lim=o-1\r\n#print(lim)\r\ns=0\r\nfor i in range(n):\r\n if a[i]%2!=0 and lim>0:\r\n s+=a[i]\r\n lim=lim-1\r\n \r\n elif a[i]%2==0:\r\n s+=a[i]\r\n \r\nprint(s)",
"input()\r\nodd_lst = []\r\neven_lst = []\r\nfor _ in map(int,input().split()):\r\n if _%2 == 1:\r\n odd_lst += [_]\r\n else:\r\n even_lst += [_]\r\nif len(odd_lst)%2 == 1:\r\n sum = sum(odd_lst) + sum(even_lst)-min(odd_lst)\r\nelse:\r\n sum = sum(odd_lst) + sum(even_lst)\r\nprint(sum)",
"n = int(input())\n\nl = sorted(map(int, input().split()))\n\ns = 0\n\na = []\nb = []\n\nfor x in l:\n\tif x % 2 == 0:\n\t\ts += x\n\telse:\n\t\tb.append(x)\n\nwhile len(b) > 1: s += b.pop() + b.pop()\n\nprint(s)\n \t\t \t\t\t \t \t\t\t\t \t \t \t\t \t",
"n = int(input())\r\nnums = [int(x) for x in input().split()]\r\nodds = []\r\ns = 0\r\nl = 0\r\nfor x in nums:\r\n if x % 2 == 0:\r\n s += x\r\n else:\r\n l += 1\r\n odds.append(x)\r\n\r\nif l > 1:\r\n odds.sort(reverse=True)\r\n if l % 2 == 0:\r\n s += sum(odds)\r\n else:\r\n s += sum(odds[:l-1])\r\nprint(s)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ns=sum(l)\r\nd=[]\r\nfor i in range(n):\r\n if(l[i]%2==1):\r\n d.append(l[i])\r\nif(s%2==0):\r\n print(s)\r\nelse:\r\n print(s-d[0])\r\n",
"n = int(input())\r\na = [*map(int, input().split())]\r\nprint(sum(a) if sum(a) % 2 == 0 else sum(a) - min([*filter(lambda x: x % 2 == 1, a)]))\r\n",
"n = int(input())\narr = [int(i) for i in input().split()]\ncnt = 0\nmiOdd = 10000000000\nans = 0\n# 1 2 3 7 > 12\nfor i in arr:\n ans += i\n if (i % 2 != 0):\n cnt += 1\n if (miOdd > i):\n miOdd = i\n\nif(cnt % 2 != 0):\n ans -= miOdd\n\nprint(ans)\n\n\t\t\t\t\t\t \t\t \t\t \t\t\t \t\t\t\t\t\t\t\t \t",
"n = int(input())\r\na = list(map(int, input().split()))\r\nodd = 0\r\nfor i in range(n):\r\n\tif a[i] % 2 == 1:\r\n\t\todd += 1\r\nodd = odd - (odd % 2)\r\nsumma = 0\r\na.sort()\r\nfor i in range(n - 1, -1, -1):\r\n\tif a[i] % 2 == 0:\r\n\t\tsumma += a[i]\r\n\telse:\r\n\t\tif odd > 0:\r\n\t\t\tsumma += a[i]\r\n\t\t\todd -= 1\r\nprint(summa)",
"is_debug = False\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\ne = []\r\no = []\r\nfor i in range(n):\r\n if a[i] % 2 == 0:\r\n e.append(a[i])\r\n else:\r\n o.append(a[i])\r\no = sorted(o)\r\nprint(f\"e={e}, o={o}\", end=\"|\") if is_debug else ''\r\n\r\nt = sum(e) + sum(o[(0 if len(o)%2==0 else 1) : ])\r\n\r\nprint(f\"{t}\")\r\n",
"#link : https://codeforces.com/problemset/problem/621/A\r\n#author : Mohamed Ibrahim\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\n \r\ns = sum(a)\r\n \r\nif s%2:\r\n s -= min(i for i in a if i%2)\r\nprint(s)\r\n",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\ns = sum(a)\r\n\r\nif s%2:\r\n s -= min(i for i in a if i%2)\r\nprint(s)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\nprint(sum(a) - min(b for b in a if b % 2) if s % 2 else sum(a))\r\n",
"n = int(input())\r\nalist = [int(x) for x in input().split()]\r\nasum = sum(alist)\r\nif asum %2 == 0:\r\n print(asum)\r\nelse:\r\n alist = sorted(alist)\r\n for i in alist:\r\n if i %2 != 0:\r\n print(asum - i)\r\n break",
"n = int(input())\r\ndata = list(map(int, input().split()))\r\n\r\nsum = 0\r\nodd = 0\r\ntmp = 100000000000\r\nfor d in data:\r\n sum += d\r\n if d%2==1:\r\n odd += 1\r\n if d<tmp:\r\n tmp = d\r\n\r\nif odd%2==1:\r\n sum -= tmp\r\nprint(sum)",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\ns = 0\r\nmn = 10 ** 10\r\nfor x in a:\r\n s += x\r\n if (x & 1) and x < mn:\r\n mn = x\r\n\r\nif s & 1:\r\n print(s - mn)\r\nelse:\r\n print(s)",
"n = int(input())\r\np = [int(i) for i in input().split()]\r\nodd = [i for i in p if i % 2 == 1]\r\nif sum(p) % 2 == 0:\r\n print(sum(p))\r\nelse:\r\n while sum(p) % 2 != 0:\r\n p.remove(min(odd))\r\n print(sum(p))\r\n",
"k=int(input())\r\na=list(map(int,input().split()))\r\nif(sum(a)%2==0):\r\n print(sum(a))\r\nelse:\r\n a.sort()\r\n d=0\r\n for i in a:\r\n if(i%2!=0):\r\n d=i\r\n break\r\n print(sum(a)-d) ",
"\r\ndef bracket_sequence_checker(s):\r\n input()\r\n a = [int(i) for i in input().split(\" \")]\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\ndef main_function():\r\n input()\r\n a = [int(i) for i in input().split(\" \")]\r\n odd_counter = 0\r\n min_val_odd = 10000000000000000000000000000000000000000000000000000000000000000000000000000\r\n for i in a:\r\n if i % 2:\r\n odd_counter += 1\r\n if i < min_val_odd:\r\n min_val_odd = i\r\n if not odd_counter % 2:\r\n return sum(a)\r\n return sum(a) - min_val_odd\r\n \r\n\r\n\r\n\r\nprint(main_function())\r\n\r\n\r\n\r\n\r\n",
"a=0\r\nb=10**9\r\nc=0\r\ninput()\r\nfor _ in map(int,input().split()):\r\n a+=_\r\n if (_%2):\r\n b=min(b,_)\r\n c+=1\r\nif c%2:\r\n a-=b\r\nprint(a)\r\n",
"from itertools import combinations, accumulate, groupby, count\nfrom sys import stdout, stdin, setrecursionlimit\nfrom collections import *\nfrom random import *\nfrom bisect import *\nfrom string import *\nfrom queue import *\nfrom heapq import *\nfrom math import *\nfrom re import *\n\n\ndef fast(): return stdin.readline().strip()\ndef zzz(): return [int(i) for i in fast().split()]\n\n\nz, zz = input, lambda: list(map(int, z().split()))\nszz, graph, mod, szzz = lambda: sorted(\n zz()), {}, 10**9 + 7, lambda: sorted(zzz())\n\n\ndef lcd(xnum1, xnum2): return (xnum1 * xnum2 // gcd(xnum1, xnum2))\ndef output(answer): stdout.write(str(answer))\n\n\ndx = [-1, 1, 0, 0, 1, -1, 1, -1]\ndy = [0, 0, 1, -1, 1, -1, -1, 1]\n\n\n###########################---Some Rule For Me To Follow---#################################\n\"\"\"\n --instants of Reading problem continuously try to understand them.\n\n --If you Know some , Then you probably don't know him !\n\n\"\"\"\n###########################---START-CODING---###############################################\n\n\n# num = int(z())\n# lst = []\n\n# for _ in range(num):\n# arr = zzz()\n# lst.append(arr)\n\n# left = 0\n# right = 10**9 + 1\n\n# while right - left > 1:\n# curr = (right + left) // 2\n# currSet = set()\n# for i in range(num):\n# msk = 0\n# for j in range(5):\n# if lst[i][j] >= curr:\n# msk |= 1 << j\n# currSet.add(msk)\n\n# flag = False\n\n# for x in currSet:\n# for y in currSet:\n# for k in currSet:\n# if x | y | k == 31:\n# flag = True\n# if flag:\n# left = curr\n# else:\n# right = curr\n# print(left)\n\nn = int(z())\n\narr = [0] + szzz()\n\ns = sum(arr)\n\nfor i in arr:\n if (s - i) % 2 == 0:\n print(s - i)\n exit()\nprint(0)\n",
"n=int(input())\r\na=list(map(int,input().split(\" \")))\r\nans=0\r\nfor i in range(0,n):\r\n ans+=a[i]\r\nif(ans%2==0):\r\n print(ans)\r\n\r\nelse:\r\n a.sort()\r\n for i in range(0,n):\r\n if((ans-a[i])%2==0):\r\n print(ans-a[i])\r\n break",
"input()\r\nnumbers = list(map(int, input().split()))\r\nodd_numbers = list(filter((2).__rmod__, numbers))\r\ntotal, odd_count_is_odd = sum(numbers), len(odd_numbers) % 2\r\nprint(total - min(odd_numbers) if odd_count_is_odd else total)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nx=sum(a)\r\nif x%2==1:x-=min([i for i in a if i%2==1])\r\nprint(x)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nan=0\r\nodd=10000000001\r\nfor x in l:\r\n an+=x\r\n if x%2==1:\r\n odd=min(odd,x)\r\n\r\nif an%2==1:\r\n print(an-odd)\r\nelse:\r\n print(an)",
"_ = input()\nnombres = [int(x) for x in input().split()]\n\npairs = [x for x in nombres if x % 2 == 0]\nimpairs = sorted([x for x in nombres if x % 2 == 1])\n\nif len(impairs) % 2 == 1:\n impairs = impairs[1:]\nprint(sum(impairs) + sum(pairs))\n",
"x=int(input())\r\ny=list(map(int,input().split()))\r\nz=max(y)\r\nfor i in y:\r\n if i%2==1 and z>i:\r\n z=i\r\nif sum(y)%2==0:\r\n print(sum(y))\r\nelif len(y)<2:\r\n print(0)\r\nelse:\r\n print(sum(y)-z)",
"n=int(input())\r\nli=list(map(int,input().split()))\r\nki=[]\r\nki1=[]\r\ncount=0\r\ncount1=0\r\nfor i in li:\r\n if i%2!=0:\r\n ki1.append(i)\r\n count+=1\r\n else:\r\n ki.append(i)\r\n count1+=1\r\nif count%2==0:\r\n print(sum(li))\r\nelse:\r\n print(sum(li)-min(ki1))",
"n = int(input())\r\nodd = []\r\nans = 0\r\nfor e in [int(c) for c in input().split()]:\r\n if e % 2 == 0:\r\n ans += e\r\n else:\r\n odd.append(e)\r\n\r\nodd.sort(reverse=True)\r\nlim = len(odd) if len(odd) % 2 == 0 else len(odd) - 1\r\nprint(ans + sum(odd[:lim]))\r\n",
"n = input()\nn = int(n)\nlist = list(map(int,input().split()))\n\nodd =[]\nsum = 0\nfor i in range(0,n):\n sum+=list[i]\n if list[i]%2==1:\n odd.append(list[i])\n\nif len(odd)%2==0:\n print(sum)\nelse: \n sum-=min(odd)\n print(sum)\n \t \t\t\t\t\t\t \t\t\t\t\t\t\t \t\t \t\t",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nodd=[]\r\nfor i in range(len(l)):\r\n if l[i]%2:\r\n odd.append(l[i])\r\nif(len(odd)%2==0):\r\n print(sum(l))\r\nelse:\r\n odd.sort()\r\n print(sum(l)-odd[0])\r\n",
"n = int(input())\nnumbers = list(map(int, input().split()))\n\neven_sum = sum(num for num in numbers if num % 2 == 0)\nodd_sum = sum(num for num in numbers if num % 2 == 1)\n\nif odd_sum % 2 == 0:\n print(even_sum + odd_sum)\nelse:\n print(even_sum + odd_sum - min(num for num in numbers if num % 2 == 1))\n\t\t\t \t\t \t\t \t \t \t\t \t\t\t \t\t \t \t",
"n=int(input())\r\na=sorted(list(map(int, input().split())))\r\nsm=0\r\nfor i in range(n):\r\n sm+=a[i]\r\nans=sm\r\ni=0\r\nwhile ans%2==1:\r\n ans=sm-a[i]\r\n i+=1\r\nprint(ans)",
"n=int(input())\r\neven=[]\r\nodd=[]\r\nl=list(map(int,input().split()))\r\nfor i in range(n):\r\n if l[i]%2==0:\r\n even.append(l[i])\r\n else:\r\n odd.append(l[i])\r\nsum_even=sum(even)\r\nodd.sort()\r\nif len(odd)%2==0:\r\n sum_even=sum_even+sum(odd)\r\nelse:\r\n sum_even=sum_even+sum(odd[1:])\r\nprint(sum_even)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=0\r\no=[]\r\nfor i in range(0,n):\r\n\tif a[i]%2==0:\r\n\t\ts+=a[i]\r\n\telse:\r\n\t\to.append(a[i])\r\nj=len(o)\r\ns+=sum(o)\r\nif j%2!=0:\r\n\to.sort()\r\n\ts-=o[0]\r\nprint(s)",
"# ///==========Libraries, Constants and Functions=============///\r\n#mk_Raghav\r\nimport sys\r\n\r\ninf = float(\"inf\")\r\nmod = 1000000007\r\n\r\n\r\ndef get_array(): return list(map(int, sys.stdin.readline().split()))\r\n\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().split())\r\n\r\n\r\ndef input(): return sys.stdin.readline()\r\n\r\n\r\n# ///==========MAIN=============///\r\n\r\ndef main():\r\n n=int(input())\r\n a=get_array()\r\n a.sort()\r\n z=sum(a)\r\n if z%2==0:\r\n print(z)\r\n else:\r\n for i in a:\r\n if i%2!=0:\r\n z=z-i\r\n break\r\n\r\n print(z)\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"import math\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\na.sort()\r\nt = math.fsum(a)\r\nif t%2 == 0:\r\n print(int(t))\r\nelse:\r\n for i in range(len(a)):\r\n if a[i]%2 == 1:\r\n print(int(t-a[i]))\r\n break\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\no=[]\r\ne=[]\r\nfor i in l:\r\n if(i%2==0):\r\n e.append(i)\r\n else:\r\n o.append(i)\r\nif(len(o)%2==0):\r\n print(sum(l))\r\nelse:\r\n s=0\r\n o.sort()\r\n s=s+sum(o[1:])+sum(e[0:])\r\n print(s)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nx,y=[],[]\r\nd=0\r\nfor i in range(n):\r\n if l[i]%2==0:\r\n x.append(l[i])\r\n else:\r\n y.append(l[i])\r\nd=d+sum(x)\r\ny.sort()\r\nif len(y)%2==0:\r\n d=d+sum(y)\r\nelse:\r\n for i in range(1,len(y),1):\r\n d=d+y[i]\r\nprint(d)",
"n=input()\nn=int(n)\nlist=list(map(int,input().split()))\n\nodd=[]\nsum=0\nfor i in range (0,n):\n sum+=list[i]\n if list[i]%2==1:\n odd.append(list[i])\n\nif len(odd)%2==0 :\n print(sum)\n\nelse :\n sum-=min(odd)\n print(sum)\n\n\n \t \t\t\t \t \t \t \t\t \t",
"import sys\r\n\r\n\r\n# Press the green button in the gutter to run the script.\r\nif __name__ == '__main__':\r\n num = int(sys.stdin.readline())\r\n #a, b = map(int, sys.stdin.readline().split())\r\n data = list(map(int,sys.stdin.readline().split()))\r\n data.sort()\r\n min_odd=0\r\n \r\n sum = 0\r\n for i in range (num) :\r\n if min_odd==0 and data[i] %2 ==1 :\r\n min_odd = data[i]\r\n sum += data[i]\r\n \r\n if sum % 2 ==0 :\r\n print (sum)\r\n else :\r\n print (sum - min_odd)\r\n\r\n",
"n, a = int(input()), [int(i) for i in input().split()]\r\nprint(sum(a) - min([i if i % 2 else int(1e10) for i in a]) if sum(a) % 2 else sum(a))\r\n",
"a = int(input())\r\ny = 0\r\nz = []\r\nx = [int(i) for i in input().split()]\r\nfor i in x:\r\n y += i\r\n if i % 2 == 1:\r\n z.append(i)\r\nif y % 2 == 0:\r\n print(y)\r\nelse:\r\n y -= min(z)\r\n print(y)\r\n",
"\r\na = input()\r\n\r\nx = [int(x) for x in input().split()]\r\n\r\nx.sort()\r\n\r\nif sum(x) % 2 == 0:\r\n print(sum(x))\r\nelse:\r\n for i in x:\r\n if i % 2 != 0:\r\n print(sum(x) - i)\r\n break",
"#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-18 23:11:14\nLastEditTime: 2021-11-18 23:17:28\nDescription: Wet Shark and Odd and Even\nFilePath: CF621A.py\n'''\n\n\ndef func():\n _ = int(input())\n lst = list(map(int, input().strip().split()))\n if sum(lst) % 2 == 0:\n print(sum(lst))\n else:\n odd = filter(lambda el: el % 2 != 0, lst)\n print(sum(lst) - min(odd))\n\n\nif __name__ == '__main__':\n func()\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=sum(l)\r\nif s%2==0:\r\n print(s)\r\nelse:\r\n m=min([i for i in l if i % 2 != 0])\r\n print(s-m)",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nmini = 10**9+1\r\ncount = 0\r\nfor i in arr:\r\n if i%2!=0:\r\n count += 1\r\n if mini>i:\r\n mini = i\r\nif count%2==0:\r\n print(sum(arr))\r\nelse:\r\n print(sum(arr)-mini)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Aug 22 04:56:58 2023\r\n\r\n@author: Haidy Talaat\r\n\"\"\"\r\nn=int(input())\r\nl = [int(i) for i in input().split()]\r\nsum=0\r\nmin=int(1e18)\r\nodd=0\r\n\r\nfor i in range(n):\r\n sum+=l[i]\r\n if l[i]&1 and l[i]<min:\r\n min=l[i]\r\n \r\nif(sum&1):\r\n print(sum-min)\r\n#print(list)\r\nelse:\r\n print(sum)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=0\r\nol=[]\r\nfor i in l:\r\n if i%2==0:\r\n s=s+i\r\n else:\r\n ol.append(i)\r\nif len(ol)%2==0:\r\n s=s+sum(ol)\r\nelse:\r\n s=s+sum(ol)-min(ol)\r\nprint(s)",
"n = int(input())\r\noc = 0\r\nar = input().split()\r\nfor i in range(n):\r\n ar[i] = int(ar[i])\r\n if ar[i]%2 !=0 :\r\n oc+=1\r\nar.sort()\r\nif oc % 2 != 0:\r\n oc-=1\r\ntot = 0\r\nfor j in range(n-1,-1,-1):\r\n if ar[j]%2 == 0:\r\n tot+= ar[j]\r\n elif oc>0:\r\n tot +=ar[j]\r\n oc-=1\r\nprint(tot)\r\n ",
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\neven=[]\r\nodd=[]\r\n\r\nfor x in a:\r\n if x%2==0:\r\n even.append(x)\r\n else:\r\n odd.append(x)\r\n\r\nans=sum(even)\r\n\r\n\r\nif len(odd)%2==0:\r\n ans+=sum(odd)\r\nelse:\r\n ans+=sum(odd)-min(odd)\r\n\r\nprint(ans)",
"n = int(input())\narr = list(map(int,input().split()))[:n]\ne = []\no = []\nif sum(arr) % 2 == 0:\n print(sum(arr))\nelse:\n for i in arr:\n e.append(i) if i % 2 == 0 else o.append(i)\n o.sort()\n o.pop(0)\n s = sum(o) + sum(e)\n print(s)\n\t \t \t \t \t \t \t\t\t\t\t",
"n=int(input())\nh=input().split()\nl=[]\nfor i in range(n):\n l.append(int(h[i]))\nuse=sorted(l)\nma=sum(l)\nt=ma\nif ma%2==0:\n print(ma)\nelse:\n for i in range(n):\n if use[i]%2!=0:\n ma=ma-use[i]\n print(ma)\n break\n \n \t \t\t \t \t\t \t\t\t \t\t\t\t\t \t\t",
"import sys\r\nimport math\r\ndef input(): return sys.stdin.readline().strip()\r\ndef iinput(): return int(input())\r\ndef rinput(): return map(int, sys.stdin.readline().strip().split()) \r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split())) \r\nmod = int(1e9)+7\r\n\r\nn = iinput()\r\nl = get_list()\r\nans = sum(l)\r\nl.sort()\r\n\r\nif ans%2 == 0:\r\n\tprint(ans)\r\nelse:\r\n\tfor item in l:\r\n\t\tif item%2 == 1:\r\n\t\t\tans -= item\r\n\t\t\tbreak\r\n\r\n\tprint(ans)\t\t\t",
"n = int(input())\r\na = list(map(int, input().split()))\r\nodd = 0\r\nfor i in range(n):\r\n if a[i] % 2 == 1:\r\n odd += 1\r\n\r\na.sort()\r\nif odd % 2 == 1:\r\n for i in range(n):\r\n if a[i] % 2 == 1:\r\n a.pop(i)\r\n break\r\n\r\nprint(sum(a))\r\n",
"n=int(input())\r\narr = list(map(int, input().split()))\r\nsum=0\r\nmini=10**9\r\nfor i in arr:\r\n sum+=i\r\n if i<mini and i%2 == 1:\r\n mini=i\r\nif sum%2 == 0:\r\n print(sum)\r\nelse:\r\n print(sum-mini)",
"input()\r\nl = list(map(int,input().split()))\r\n\r\n\r\nb = [i for i in l if i%2==1]\r\n\r\nprint(sum(l)-(min(b) if len(b)%2 else 0))\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\na.sort(); k = 0; b = []; l = 0\r\nfor i in range(len(a)):\r\n if a[i] % 2 == 0: k += a[i]\r\n else: k += a[i]; b.append(i); l += 1\r\nif l % 2 == 1: print(k-a[b[0]])\r\nelse: print(k)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nans = sum(a)\r\nt = 999999999\r\nfor i in range(n):\r\n if a[i] % 2 == 1:\r\n t = min(t, a[i])\r\nif ans % 2 == 0:\r\n print(ans)\r\nelse:\r\n print(ans - t)\r\n",
"n = int(input())\r\nl = list(map(int,input().split()))\r\nl = sorted(l)[::-1]\r\ne = []\r\no = []\r\nfor i in l:\r\n if(i%2==0):\r\n e.append(i)\r\n else:\r\n o.append(i)\r\ns = sum(l)\r\nif(s%2==0):\r\n print(s)\r\nelse:\r\n print(s-min(o))",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ns = sum(arr)\r\nif sum(arr)%2 == 0:\r\n\tprint(s)\r\nelse:\r\n\tfor i in sorted(arr):\r\n\t\tif i%2 != 0:\r\n\t\t\tprint(s-i)\r\n\t\t\texit()",
"n = int(input())\r\narr = sorted(list(map(int, input().split())))\r\nans = sum(arr)\r\nif not(ans & 1):\r\n print(ans)\r\n exit()\r\nfor x in arr:\r\n if not((ans - x) & 1):\r\n print(ans - x)\r\n exit()\r\n ",
"n = int(input())\r\nx = input().split()\r\nc = [int(i) for i in x]\r\ns = sum(c)\r\nif s%2 == 0:\r\n print(s)\r\nelse:\r\n c.sort()\r\n for i in range(n):\r\n if ((s-c[i])%2) == 0:\r\n print(s-c[i])\r\n break\r\n\r\n \r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nb=0\r\nc=0\r\nfor i in range(n):\r\n if a[i]%2==1:\r\n if b==0:\r\n b=a[i]\r\n c+=1\r\nprint(sum(a)-b*(c%2))",
"n=input()\nn=int(n)\ntxt=input()\nlist=txt.split()\n\nfor i in range (n):\n list[i]=int(list[i])\n\nlist.sort()\n\nsum=0\nflag=0\nfor i in range (n):\n sum=sum+list[i]\n\n if list[i]%2==1 and flag==0:\n flag=list[i]\n\nif sum%2==0:\n print(sum)\nelse:\n print(sum-flag)\n\n\t\t \t \t \t\t \t \t\t \t \t\t \t\t \t\t \t\t",
"n = int(input())\r\nl = [int(x) for x in input().split()]\r\nsm, e, mn = 0, 0, 1000000001\r\n\r\nfor i in l:\r\n if i % 2 != 0:\r\n sm += i\r\n mn = min(mn, i)\r\n e += 1\r\n else:\r\n sm += i \r\n\r\nif e % 2 == 0:\r\n print(sm)\r\nelse:\r\n print(sm-mn) ",
"from collections import deque\r\nfrom math import log\r\ndef ii(): return int(input())\r\ndef si(): return input()\r\ndef mi(): return map(int,input().strip().split(\" \"))\r\ndef li(): return list(mi())\r\nn=ii()\r\ns=0\r\na=li()\r\nx=1e9+5\r\nc=0\r\nfor i in range(n):\r\n if(a[i]%2):\r\n x=min(x,a[i])\r\n c+=1\r\nif(c%2):\r\n print(sum(a)-x)\r\nelse:\r\n print(sum(a))",
"n= int(input())\r\n\r\nli= list(map(int, input().split()))\r\nli.sort(reverse= True)\r\nodd=[i for i in li if int(i)%2!=0]\r\nx= len(odd)\r\n\r\nif x%2!=0:\r\n y= odd[-1]\r\n li.remove(y)\r\nprint(sum(li))",
"n=int(input())\r\na=list(map(int,input().split()))\r\nl,summ=[],sum(a)\r\nfor i in a:\r\n if i%2==0: l+=[i]\r\n if (summ-i)%2==0: l+=[summ-i]\r\n if summ%2==0: l+=[summ]\r\nprint(max(l))",
"times = int(input())\r\nnumbers = list(map(int, input().split()))\r\neven = []\r\nodd = []\r\nfor i in numbers:\r\n if i % 2 == 0:\r\n even += [i]\r\n else:\r\n odd += [i]\r\nif len(odd) % 2 == 0:\r\n qwe = even + odd\r\n print(sum(qwe))\r\nelse:\r\n odd.sort()\r\n odd.pop(0)\r\n qwe = even + odd\r\n print(sum(qwe))\r\n",
"_ = input()\nnombres=[int(x) for x in input().split()]\n\npairs=[x for x in nombres if x%2==0]\nimpairs=sorted([x for x in nombres if x %2==1],reverse=True)\n\ndoubles_impairs=[a+b for a,b in zip(impairs[::2], impairs[1::2])]\nprint(sum(doubles_impairs)+sum(pairs))\n \n",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nif (sum(a) % 2 == 0):\r\n print(sum(a))\r\nelse:\r\n a = sorted(a)\r\n \r\n k = 0\r\n b = 0\r\n \r\n while (k < len(a)):\r\n if (a[k] % 2 != 0):\r\n a.pop(k)\r\n break\r\n k += 1\r\n \r\n print(sum(a))",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\n\r\nodds = sorted([on for on in nums if on%2==1], reverse=True)\r\nprint(sum([en for en in nums if en%2==0]) + sum(odds[:len(odds)-len(odds)%2]))",
"n = int(input())\narr = list(map(int, input().split(\" \")))\nsum = sum(arr)\nprint(sum - min([i for i in arr if i % 2]) if sum % 2 else sum)\n\n\t \t\t\t \t \t \t \t \t\t \t \t",
"import math\r\nn=int(input())\r\na=[int(i) for i in input().split()]\r\ns=0\r\no=math.inf\r\nfor i in a:\r\n s+=i\r\n if i%2!=0:\r\n if i<o:\r\n o=i\r\nif s%2==0:\r\n print(s)\r\nelse:\r\n print(s-o)\r\n \r\n\r\n",
"n=int(input())\r\nd=list(map(int, input().split()))\r\nd.sort(reverse=True)\r\nx=[]\r\nsumm=0\r\nfor i in d:\r\n if i%2==0:\r\n summ+=i\r\n elif len(x)==0:\r\n x.append(i)\r\n else:\r\n summ+=x[0]+i\r\n x=[]\r\nprint(summ)\r\n",
"n=int(input())\r\n\r\nl=list(map(int,input().split()))\r\n\r\nans=0\r\nm=float('inf')\r\nfor i in l:\r\n\tif i%2 and m>i:\r\n\t\tm=i\r\n\tans+=i\r\n\r\nif ans%2:\r\n\tans-=m\r\n\r\nprint(ans)\r\n",
"a=0;b=10**9;c=0;input()\r\nfor _ in map(int,input().split()):\r\n a+=_\r\n if (_%2):b=min(b,_);c+=1\r\nif c%2:a-=b\r\nprint(a)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort() \r\nif(sum(l)%2==0):\r\n print(sum(l))\r\n exit()\r\nelse:\r\n s=sum(l)\r\n for i in range(len(l)):\r\n if(l[i]%2==1):\r\n s-=l[i]\r\n if(s%2==0):\r\n print(s)\r\n exit()\r\n \r\n ",
"def solve():\r\n size = input()\r\n numbers = sorted(map(int, input().split()))\r\n result = sum(numbers)\r\n \r\n if result & 1:\r\n for number in numbers:\r\n if number & 1:\r\n result -= number\r\n \r\n break\r\n \r\n print(result)\r\n \r\n \r\n \r\nif __name__ == \"__main__\":\r\n solve()\r\n ",
"import sys\r\nimport math\r\nfrom statistics import mean\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return (int (input ()))\r\n\r\n\r\ndef inlt():\r\n return (list (map (int, input ().split ())))\r\n\r\n\r\ndef insr():\r\n s = input ()\r\n return (list (s[:len (s) - 1]))\r\n\r\n\r\ndef invr():\r\n return (map (int, input ().split ()))\r\n\r\n\r\nn = inp()\r\nli = inlt()\r\ns = sum(li)\r\nif s % 2 == 0:\r\n print(s)\r\nelse:\r\n li.sort()\r\n for i in range(n):\r\n if li[i] % 2 != 0:\r\n s = s - li[i]\r\n break\r\n print(s)\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nmaxsum, odd=0, 0\r\nmina=10**9\r\nfor i in a:\r\n maxsum +=i\r\n if i % 2 ==1 and mina > i:\r\n mina=i\r\n odd +=1\r\n elif i % 2 == 1:\r\n odd +=1\r\nif odd % 2 == 1:\r\n print(maxsum-mina)\r\nelse:\r\n print(maxsum)",
"n = int(input())\r\nall = tuple(map(int, input().split()))\r\ns = sum(all)\r\n \r\nif s%2 == 0:\r\n print(str(s))\r\nelse:\r\n min_odd = min([i for i in all if i%2==1])\r\n print(str(s-min_odd))",
"n = int(input())\na = [int(i) for i in input().split()]\nodd=[]\neven = []\nfor it in a:\n if (it % 2) == 0:\n even.append(it)\n else:\n odd.append(it)\n\nans = sum (even)\n\noodd = len(odd)\nif oodd % 2 == 1:\n odd.sort()\n odd.pop(0)\n\nans += sum(odd)\n\nprint(ans)\n\n \t\t\t \t\t\t\t\t \t \t \t \t \t \t",
"n=int(input())\r\nif n==0:exit()\r\na,b,k=[],[],0\r\nfor i in list(map(int,input().split())):\r\n if i%2==1:b.append(i)\r\n k=k+i\r\nif len(b)>0 and k%2==1:b.sort();print(k-b[0])\r\nelif k%2==0:print(k)\r\nelse:print(0)\r\n",
"n = int(input())\r\nnums = [int(i) for i in input().split(' ')]\r\nwhile (len(nums) > 0):\r\n if len(nums) == 1:\r\n if nums[0]%2 == 0:\r\n print(nums[0])\r\n break\r\n else:\r\n print(0)\r\n break\r\n elif sum(nums)%2 == 0:\r\n print(sum(nums))\r\n break\r\n elif sum(nums)%2 == 1:\r\n odd = min(filter(lambda x:x%2 != 0, nums))\r\n if (sum(nums)-odd)%2 ==0:\r\n print(sum(nums)-odd)\r\n break",
"even=[]\r\nodd=[]\r\nn=int(input())\r\narr=sorted(list(map(int,input().split())))[::-1]\r\nc=0\r\nc_e=0\r\nfor i in range(n):\r\n if arr[i]%2==0:\r\n c_e+=1\r\n even.append(arr[i])\r\n else:\r\n c+=1\r\n odd.append(arr[i])\r\nif c%2==0:\r\n print(sum(even)+sum(odd[:c]))\r\nelse:\r\n print(sum(even)+sum(odd[:c-1]))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nl=[]\r\nsumm=sum(a)\r\nif summ % 2 == 0: print(summ)\r\nelse:\r\n for i in a:\r\n if i % 2 != 0 and (summ-i) % 2 == 0:\r\n l.append(summ-i)\r\n print(max(l))",
"def solve(numbers):\r\n result = 0\r\n odds = []\r\n\r\n for number in numbers:\r\n if number % 2 == 0:\r\n result += number\r\n else:\r\n odds.append(number)\r\n\r\n odds.sort()\r\n\r\n if len(odds) % 2 != 0:\r\n odds.pop(0)\r\n\r\n result += sum(odds)\r\n return result\r\n\r\ndef main():\r\n n = int(input())\r\n numbers = list(map(int, input().split()))\r\n print(solve(numbers))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n=int(input())\r\nst=list(map(int,input().split(' ')))\r\nst1=[]\r\nst2=[]\r\nfor i in range(len(st)):\r\n if int(st[i])%2 == 1:st2.append(st[i])\r\n else:st1.append(st[i])\r\nif len(st2)%2==1:\r\n del st2[st2.index(min(st2))]\r\nst1.extend(st2)\r\nprint(sum(st1))\r\n",
"num = int(input())\r\nchosen_num = input().split( )\r\nchosen_num =[int(i) for i in chosen_num]\r\nsum =0\r\ni = 0\r\nmin = 1000000000\r\nwhile i < num:\r\n if chosen_num[i] % 2 == 1 and chosen_num[i] < min:\r\n min = chosen_num[i]\r\n sum += chosen_num[i]\r\n i+=1\r\n\r\nif sum % 2 ==0:\r\n print(sum)\r\nelse:\r\n print(sum - min)\r\n",
"input()\r\ntotal, lowest_odd, odd_count_is_odd = 0, float(\"inf\"), False\r\nfor n in input().split():\r\n n = int(n)\r\n total += n\r\n if n % 2:\r\n lowest_odd = min(lowest_odd, n)\r\n odd_count_is_odd = not odd_count_is_odd\r\nprint(total - lowest_odd if odd_count_is_odd else total)",
"n = int(input())\r\narr = sorted(list(map(int, input().split())))\r\nodd = 0\r\nfor i in range(len(arr)):\r\n if arr[i] % 2 == 1:\r\n odd += 1\r\nif odd % 2 == 0:\r\n ans = sum(arr)\r\nelse:\r\n base = odd - 1\r\n ans = 0\r\n track = 0\r\n arr.reverse()\r\n for i in range(len(arr)):\r\n if arr[i] % 2 == 1:\r\n if track < base:\r\n ans += arr[i]\r\n track += 1\r\n if arr[i] % 2 == 0:\r\n ans += arr[i]\r\nprint(ans)\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\ntotal = 0\r\nminimumOdd = 1000000001\r\nfor i in range(n):\r\n temp = arr[i]\r\n total += temp\r\n if temp % 2 != 0:\r\n if temp < minimumOdd:\r\n minimumOdd = temp\r\n\r\nif total % 2 == 0:\r\n print(total)\r\nelse:\r\n print(total - minimumOdd)",
"if __name__ == '__main__':\r\n n = input()\r\n split = input().split()\r\n numbers = list(map(lambda x: int(x), split))\r\n _min = 10000000000\r\n sum = 0\r\n for n in numbers:\r\n sum += n\r\n if n < _min and n%2 != 0:\r\n _min = n\r\n if sum % 2 == 0:\r\n print(sum)\r\n else :\r\n sum -= _min\r\n print(sum)\r\n",
"n=int(input())\ns=list(map(int,input().split()))\nchet=[]\nnechet=[]\nfor i in s:\n if i%2==0:\n chet.append(i)\n else:\n nechet.append(i)\nif len(nechet)%2==0:\n print(sum(chet)+sum(nechet))\nelse:\n nechet.sort(reverse=True)\n print(sum(chet)+sum(nechet[:-1]))\n\n",
"n=int(input())\r\nlst=list(map(int,input().split(\" \")))\r\n\r\nlst.sort()\r\nif sum(lst)%2==0:\r\n print(sum(lst))\r\nelse:\r\n for i in lst:\r\n if i%2==1:\r\n print(sum(lst)-i);\r\n break;\r\n ",
"int(input())\r\neven = odd = []\r\nmin = sum = 0\r\nfor i in str(input()).split():\r\n sum += int(i)\r\n if(int(i)%2 == 0):\r\n even += [int(i)]\r\n else:\r\n min = int(i) if min == 0 else int(i) if min > int(i) else min\r\n odd += [int(i)]\r\nprint(sum if sum%2 == 0 else sum-min)\r\n",
"\nn = int(input())\nx = input().split(\" \")\ns = 0\nsm = 0\nfor ii in x:\n i = int(ii)\n if i&1:\n sm = i\n x.remove(ii)\n break\n\nfor ii in x:\n i = int(ii)\n if sm > i and i&1:\n s +=sm\n sm = i\n else:\n s += i\nif s & 1:\n s += sm\nprint(s)",
"n= int(input())\r\n\r\nl=list(map(int,input().split()))\r\n\r\nl.sort()\r\n\r\ns=sum(l)\r\nif s%2==0:\r\n print(str(s))\r\nelse:\r\n i=0\r\n while l[i]%2==0:\r\n i+=1\r\n print(str(s-l[i]))\r\n \r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nsu=sum(l)\r\nz=[]\r\nfor i in l:\r\n\tif i%2!=0:\r\n\t\tz.append(i)\r\nif len(z)%2!=0:\r\n\tprint(su-min(z))\r\nelse:\r\n\tprint(su)\t\t\t\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\neven_numbers = []\r\nodd_numbers = []\r\nx = 0\r\nif a == [0]:\r\n print(0)\r\nelse:\r\n for i in a:\r\n if i%2==0:\r\n even_numbers.append(i)\r\n elif i%2==1:\r\n odd_numbers.append(i)\r\n if len(odd_numbers)%2==1:\r\n m = (min(odd_numbers))\r\n odd_numbers.remove(m)\r\n s = (even_numbers)+(odd_numbers)\r\n else:\r\n s = (even_numbers)+(odd_numbers)\r\nfor i in s:\r\n x+=i\r\nprint(x)",
"n = int(input())\r\narr = list(map(int,input().split()))\r\n\r\nodd = 0\r\ns=0\r\nfor i in arr:\r\n if i%2!=0: odd+=1\r\n s+=i\r\n \r\nif odd%2!=0:\r\n arr.sort()\r\n for i in range(n):\r\n if arr[i]%2!=0:\r\n s-=arr[i]\r\n break\r\nprint(s)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nl,ans,m,x=[],0,float(\"inf\"),0\r\nfor i in a:\r\n ans+=i\r\n if i%2:\r\n m=min(m,i)\r\n x+=1\r\nif x%2:\r\n print(ans-m)\r\nelse:\r\n print(ans)",
"n = int(input())\ns = list(map(int,input().split()))\ns.sort()\nS = sum(s)\nif S%2 == 0:\n print(S)\nelse:\n\n for i in range(n):\n \n if s[i]%2 != 0:\n S = S-s[i]\n break\n print(S) \n \n \n \n\n \n \n \n \n \n\n\n \n\n",
"n = int(input())\r\narr = list(map(int,input().strip().split(' ')))\r\nc = []\r\nc = list(filter(lambda x: x%2!=0 , arr))\r\na = list(filter(lambda x : x%2 == 0,arr))\r\nsum1 = 0\r\nsum1 += sum(a)\r\nif len(c) % 2 == 0:\r\n sum1 += sum(c)\r\nelse:\r\n c = sorted(c)\r\n sum1+=sum(c)\r\n sum1 -= c[0]\r\nprint(sum1)",
"input()\n*a,=map(int,input().split())\nb=[i for i in a if i%2]\nprint(sum(a)-(min(b)if len(b)%2 else 0))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ns=sum(l)\r\nif s%2!=0:\r\n\tfor x in l:\r\n\t\tif x%2!=0:\r\n\t\t\ts-=x\r\n\t\t\tbreak\r\nprint(s)",
"n=int(input())\narr=[int(i) for i in input(). split()]\nsum=0\nfor i in range(n):\n sum+=arr[i]\nif sum%2==0:\n print(sum)\nelse:\n mn=2000000000\n for i in range(n):\n if arr[i]%2!=0:\n if arr[i]<mn:\n mn=arr[i]\n print(sum-mn)\n\n\n\n\t\t \t \t\t \t\t\t \t \t \t \t\t\t\t \t\t\t",
"input()\r\n\r\nmin_odd, max_sum = 999999999, 0\r\n\r\nfor num in map(int, input().split()):\r\n min_odd, max_sum = min(num, min_odd) if num % 2 else min_odd, max_sum + num\r\n\r\nprint(max_sum - min_odd if max_sum % 2 else max_sum)",
"# a,b,c,d,e = map(int, input().split())\n# sum=a+b+c+d+e\n# if (sum%5 == 0):\n# print(int(sum/5))\n# else:\n# print(-1)\n\nn=input()\nn=int(n)\nnum = list(map(int, input().strip().split()))\n# print(num)\nnum.sort()\nsum=0\nfor i in num:\n sum=sum+i\nif (sum%2==1):\n for i in num:\n if (i%2==1):\n sum-=i\n break\nprint(sum)",
"n=int(input())\nls=list(map(int,input().split()))\nans=0\nls1=[]\nfor i in ls:\n if i%2==0:\n ans+=i\n else:\n ls1.append(i)\nls1.sort()\nif len(ls1)%2==0:\n ans+=sum(ls1)\nelse:\n ans+=(sum(ls1)-ls1[0])\nprint(ans)\n\t\t\t \t \t \t \t\t\t \t \t \t \t\t \t",
"\r\nn=int(input())\r\nA=list(map(int,input().split()))\r\nan = 0\r\nodd = []\r\nfor a in A:\r\n if a % 2 == 0:\r\n an += a\r\n else:\r\n odd +=[a]\r\nodd.sort()\r\nif len(odd) % 2 == 0:\r\n an += sum(odd)\r\nelse:\r\n an += sum(odd[1:])\r\nprint(an)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=0\r\ncv=0\r\nfor i in range(n):\r\n if l[i]%2==0:\r\n s=s+l[i]\r\n l[i]=0\r\n else:\r\n cv=cv+1\r\nif cv%2==0:\r\n for i in l:\r\n s=s+i\r\nelse:\r\n l.sort(reverse=True)\r\n for i in range(cv-1):\r\n s=s+l[i]\r\nprint(s)\r\n",
"input()\r\nl = list(map(int,input().split()))\r\nmin=1000000001\r\nsum=0\r\nfor a in l:\r\n if a<min and a%2 ==1:\r\n min = a\r\n sum += a\r\nif sum%2 != 0:\r\n sum-=min\r\nprint(sum)",
"n = int(input())\nlistN = list(map(int, input().split()))\n\nlistN.sort()\n\nlistDiv2 = [i for i in listN if i%2]\n\nif(len(listDiv2)%2 == 0): print(sum(listN))\nelse: print(sum(listN) - listDiv2[0])\n \t\t\t\t\t \t\t\t \t\t \t\t \t\t\t\t\t \t\t\t \t\t",
"t=int(input())\r\nnum=[int(x) for x in input().split()]\r\nco=0\r\nce=0\r\nsum=0\r\nso=999999999999999999999\r\nfor j in range(t):\r\n if(num[j]%2==0):\r\n ce = ce + 1\r\n sum = sum + num[j]\r\n else:\r\n co = co + 1\r\n sum = sum + num[j]\r\n if(num[j]<so):\r\n so=num[j]\r\n #print(sum,so)\r\nif(co%2==0):\r\n print(sum)\r\nelse:\r\n sum=sum-so\r\n print(sum)",
"n=int(input());a=sorted(list(map(int,input().split())),reverse=True);p=k=l=0\r\nfor i in a:\r\n\tif i%2==0:p+=i\r\n\telse:p+=i;l+=1;k=i\r\nprint(p-k if l%2!=0 else p)",
"n = int(input())\r\na = list(map(int, input().split(\" \")))\r\ns = 0\r\nl = []\r\nfor x in a:\r\n if(x % 2 == 0):\r\n s += x\r\n else:\r\n l.append(x)\r\nl.sort(reverse = True)\r\nprint(s + sum(l[:(len(l)//2)*2]))\r\n \r\n \r\n \r\n",
"n=input()\nn=int(n)\nnumbers=list(map(int,input().split()))\neven=[]\nodd=[]\nsum=0\nfor i in range(0,n) :\n if numbers[i]%2==0 :\n even.append(numbers[i])\n else :\n odd.append(numbers[i])\n\n\nfor i in range(0,len(even)) :\n sum=sum+even[i]\n\nodd.sort()\nodd.reverse()\n\nx=len(odd)\n\nif x%2!=0 :\n x=x-1\n\nfor i in range(0,x) :\n sum=sum+odd[i]\n\n\n\nprint(sum)\n\n\n\t \t\t\t \t\t\t \t \t\t\t\t \t \t \t\t\t\t\t",
"n = int(input())\na = list(map(int, input().split()))\nsumm = 0\nmn = 34567886697\nfor i in range(len(a)):\n summ += a[i] \n if a[i] % 2:\n mn = min(mn, a[i])\nif summ % 2 == 0:\n print(summ)\nelse:\n print(summ - mn)\n",
"n = int(input())\n\nnums = list(map(int, input().split()))\ntotal = sum(nums)\n\nif total % 2 == 0:\n print(total)\n quit()\nelse:\n minim = 1000000001\n for i in range(n):\n if nums[i] % 2 != 0:\n minim = min(minim, nums[i])\n print(total - minim)",
"# 1 9 5 8 2 6 4 7 3 = 44\n\n# odd => 1 9 5 7 3 => 1 3 5 7 9 => 1 24 => 44\n# even => 2 4 6 8 => 20\n# odd + odd = even\n\nn = int(input())\narr = [int(i) for i in input().split()]\nodd = []\neven = []\nfor it in arr: # 8 % 2 => 6 4 2 0 | 9 % 2 => 7 5 3 1\n if (it % 2) == 0:\n # add in even\n even.append(it)\n else:\n # add in odd\n odd.append(it)\n\nans = sum(even)\n\nif (len(odd) % 2) == 1:\n odd.sort()\n odd.pop(0)\n\nans += sum(odd)\n\nprint(ans)\n\n\t \t \t\t\t\t\t \t\t\t\t \t\t\t \t\t\t\t\t \t\t",
"def main():\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n ans=sum(l)\r\n mn,oddcnt=int(1e9),0\r\n for i in l:\r\n if i&1:\r\n oddcnt+=1\r\n mn=min(mn,i)\r\n if oddcnt&1:\r\n ans-=mn\r\n print(ans)\r\nmain()",
"n = int(input())\r\nl = list(map(int, input().split()))\r\n\r\nl.sort()\r\ns = sum(l)\r\nwhile s % 2 > 0:\r\n i = 0\r\n while l[i] % 2 == 0:\r\n i += 1\r\n s -= l[i]\r\n\r\nprint(s)",
"input()\r\na=[*map(int,input().split())]\r\ns,o,m=sum(a),sum(x%2 for x in a),min([x for x in a if x%2],default=0)\r\nprint(s-o%2*m)",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\ns = sum(lst)\r\nx = []\r\n\r\nif s%2==0:\r\n print(s)\r\nelse:\r\n lst.sort()\r\n \r\n for i in range(n):\r\n if lst[i]%2!=0:\r\n x.append(lst[i])\r\n \r\n print(s - min(x))",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\ns = sum(lst)\r\nif s%2 == 0:\r\n print(s)\r\nelse:\r\n odd = float('inf')\r\n for i in range(n):\r\n if lst[i]%2 != 0:\r\n odd = min(odd, lst[i])\r\n print(s-odd)",
"input()\r\ndata = list(map(int, input().split()))\r\nres = sum(data)\r\nif res % 2 == 0:\r\n print(res)\r\nelse:\r\n print(res - min(filter(lambda v: v % 2, data)))",
"n=int(input())\r\narr=[int(i) for i in input().split()]\r\narr.sort()\r\ni=0\r\nwhile i<n:\r\n s=sum(arr)\r\n if s%2==0:\r\n print(s)\r\n exit()\r\n else:\r\n while i<n and arr[i]%2==0:\r\n i=i+1\r\n arr.pop(i)\r\n \r\n \r\n",
"n = int(input());\r\nl = map(int, input().split());\r\n\r\nl = sorted(l);\r\ns = sum(l);\r\n\r\nif s&1:\r\n for x in l:\r\n if x&1:\r\n s =s -x;\r\n break;\r\n\r\n\r\nprint(s);",
"n = int(input()); lst = list(map(int, input().split())); lst.sort()\r\nl0 = list(filter(lambda x: x % 2 == 0, lst)); l1 = list(filter(lambda x: x % 2, lst))\r\nprint((sum(l0)+sum(l1)-l1[0]) if len(l1) % 2 else (sum(l0)+sum(l1)))",
"n = int(input())\r\nx = [int(x) for x in input().split()]\r\ny = []\r\nz = []\r\nfor i in x:\r\n if i%2==0:\r\n y.append(i)\r\n else:\r\n z.append(i)\r\nif len(z)%2!=0:\r\n print(sum(z)-min(z)+sum(y))\r\nelse:\r\n print(sum(z)+sum(y))",
"num0 = int(input())\nnum1 = input().split(\" \")\nnum = [0]*len(num1)\nnuma = []\nsum = 0\nfor i in range(num0):\n num[i] = int(num1[i])\n if num[i] % 2 == 1:\n numa.append(num[i])\n sum += num[i]\nnuma = sorted(numa, reverse=False)\nif sum % 2 == 1:\n sum -= numa[0]\nprint(sum)\n\n\n \t\t \t \t\t\t \t \t\t \t\t\t \t",
"\nn=int(input())\narr=list(map(int,input().split()))\nsumnum=0\nls=[]\nfor i in arr:\n sumnum+=i\n if i%2==1:\n ls.append(i)\nif sumnum%2==1:\n sumnum=sumnum-min(ls)\nprint(sumnum) \n \t \t \t \t \t \t\t \t\t\t\t\t \t \t\t\t \t",
"n=int(input())\r\nk=list(map(int,input().split()))\r\ns=0\r\nsmin=10000000000\r\nif sum(k)%2==0:\r\n print(sum(k))\r\nelse:\r\n for i in range(n):\r\n if k[i]%2!=0 and k[i]<smin:\r\n smin=k[i]\r\n s=sum(k)-smin \r\n print(s)\r\n \r\n",
"input()\n\n*a,=map(int,input().split())\n\nb=[i for i in a if i%2]\n\nprint(sum(a)-(min(b)if len(b)%2 else 0))\n\n\n\n# Made By Mostafa_Khaled",
"n = int(input())\nnum = input().split()\nnum = [int(x) for x in num]\n\nnum = sorted(num)\n\nimpar1 = None\n\np = 0\nsoma = 0\n\nwhile p < n and num[p]%2 == 0:\n soma += num[p]\n p += 1\n\nif p < n:\n impar1 = num[p]\n while p < n:\n soma += num[p]\n p += 1\n\nif soma%2 == 1:\n soma -= impar1\n\nprint(soma) \n \n\n \n",
"n = int(input())\r\n*a, = map(int, input().split())\r\nprint(sum(a)- min(i for i in a if i % 2) if sum(a) % 2 else sum(a))\r\n",
"a = int(input())\r\nl = list(map(int,input().split()))\r\nif sum(l)%2==0:\r\n\tprint(sum(l))\r\nelse:\r\n\tl.sort()\r\n\tfor i in l:\r\n\t\tif i%2!=0:\r\n\t\t\tprint(sum(l)-i)\r\n\t\t\tbreak",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nsumi=sum(a)\r\nif sumi%2==0:\r\n\tprint(sumi)\r\nelse:\r\n\tfor i in range(n):\r\n\t\tif a[i]%2==1:\r\n\t\t\tsumi-=a[i]\r\n\t\t\tprint(sumi)\r\n\t\t\tbreak",
"def mx_ev(a):\r\n if sum(a)%2==0:\r\n return sum(a)\r\n a_chet=[i for i in a if i%2==0]\r\n a_nechet=sorted([i for i in a if i%2==1])\r\n k=sum(a_chet)+sum(a_nechet)\r\n i=0\r\n while k%2!=0:\r\n k-=a_nechet[i]\r\n i+=1\r\n return k\r\nn=int(input())\r\nt=[int(i) for i in input().split()]\r\nprint(mx_ev(t))",
"\nn = int(input())\n\nvetor = list(map(int, input().split(\" \")))\nsoma = sum(vetor)\n\nvetor.sort()\nfor i in range(n):\n if soma % 2 == 0:\n break\n if vetor[i] % 2 == 1:\n soma -= vetor[i]\n\nprint(soma)\n\t \t \t\t \t\t \t \t\t \t\t\t\t\t \t\t\t",
"n=int(input())\r\nvec=list(map(int,input().split()))\r\ncPar=0\r\ncImp=0\r\nminImp=1000000010\r\nres=0\r\nfor i in range(0,n):\r\n res+=vec[i]\r\n if vec[i]%2==0:\r\n cPar+=1\r\n else:\r\n cImp+=1\r\n minImp=min(minImp,vec[i])\r\nif cImp%2!=0:\r\n res-=minImp\r\nprint(res)",
"n=int(input());m=[int(i) for i in input().split()];s=0;t=m[0]\r\nfor i in range(n):\r\n s+=m[i]\r\n if m[i]%2==1 and (m[i]<t or t%2==0):t=m[i]\r\nprint([s,s-t][s%2==1])",
"# cook your dish here\r\nn=int(input())\r\nlst=list(map(int,input().rstrip().split()))\r\n\r\nsumm=sum(lst)\r\n\r\nif summ%2==0:\r\n print(summ)\r\nelse:\r\n lst.sort()\r\n for i in lst:\r\n if i%2!=0:\r\n summ-=i\r\n break\r\n print(summ)",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\na = sorted(a)\r\ns = sum(a)\r\nif s % 2 == 0:\r\n print(s)\r\nelse:\r\n bool = False\r\n for i in range(n):\r\n if a[i] % 2 != 0:\r\n s -= a[i]\r\n print(s)\r\n bool = True\r\n break\r\n if not bool:\r\n print(0)\r\n",
"n = int(input())\r\nnums = [int(i) for i in input().split()]\r\n\r\nif sum(nums) % 2 == 0:\r\n print(sum(nums))\r\nelse:\r\n nums.sort()\r\n for i in nums:\r\n if i % 2 == 1:\r\n nums.remove(i)\r\n break\r\n print(sum(nums))",
"n=int(input())\r\nT=list(map(int, input().split()))\r\nT.sort()\r\ns=sum(T)\r\ni=0\r\nwhile s%2!=0 :\r\n if T[i]%2!=0 :\r\n s=s-T[i]\r\n else :\r\n i=i+1\r\nprint(s)",
"input()\r\nl = list(map(int,input().split()))\r\n\r\n#print(l)\r\n\r\n#min1 = 0\r\ntry:\r\n min1 = min([i for i in l if i%2==1])\r\nexcept:\r\n min1=0\r\n\r\nprint(sum(l)-(min1 if sum(l)%2 else 0))\r\n",
"n = int(input())\r\nlst = [int(i) for i in input().split()]\r\ns = sum(lst)\r\nif s % 2 == 0:\r\n print(s)\r\nelse:\r\n l = []\r\n for i in sorted(lst):\r\n if i % 2 == 1:\r\n print(s - i)\r\n break\r\n",
"n=int(input())\na=list(map(int,input().split()))\nk=sum(a)\nb=list(filter(lambda x:x%2,a))\nb.sort()\nif k%2==0:\n\tprint(k)\nelse:\n\tprint(k-b[0])",
"from unittest import result\n\n\nbob=int(input())\nl=input()\nl=l.split()\nfor i in range(len(l)):\n l[i]=int(l[i])\n\nresult=0\nsmall=999999999\nfor i in range(len(l)):\n result+=l[i]\n\nif result%2==0:\n print(result)\nelse:\n for i in range(len(l)):\n if l[i]%2==1 and l[i]<small:\n small=l[i]\n print(result-small)",
"n = int(input())\r\na = list(map(int,input().split()))\r\na.sort()\r\n\r\nb = sum(a)\r\n\r\nif b % 2 == 0:\r\n print(b)\r\n exit(0)\r\n\r\nelse:\r\n i = 0\r\n while a[i] % 2 == 0:\r\n i += 1\r\n\r\nprint(b - a[i])",
"def arr_inp():\r\n return [int(x) for x in stdin.readline().split()]\r\n\r\n\r\nfrom sys import stdin\r\n\r\nn, a = int(input()), sorted(arr_inp())\r\nans = sum(a)\r\nif ans & 1:\r\n for i in a:\r\n if i & 1:\r\n ans -= i\r\n break\r\n\r\nprint(ans)\r\n",
"n = int(input())\r\nnums = [int(s)for s in input().split()]\r\n\r\nodd = []\r\neven = []\r\n\r\nfor elem in nums:\r\n if elem % 2 == 0:\r\n even.append(elem)\r\n else:\r\n odd.append(elem)\r\n\r\nodd.sort(reverse = True)\r\neven.sort(reverse = True)\r\n\r\nif len(odd)%2 != 0:\r\n print(sum(even) + sum(odd[:-1]))\r\nelse:\r\n print(sum(even) + sum(odd))\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nc = []\r\nd = []\r\nfor i in a:\r\n if i % 2 == 0:\r\n c.append(i)\r\n else:\r\n d.append(i)\r\nd.sort(reverse = True)\r\nif len(d)%2 != 0:\r\n d.pop()\r\nprint(sum(c+d))\r\n",
"n = int(input())\nlist = [int(x) for x in input().split()][:n]\nsum, odd, oddOne = 0, 0, 1000000000\nfor i in range(n):\n\tsum += list[i]\n\tif list[i] % 2: \n\t\todd += 1\n\t\tif list[i] < oddOne: oddOne = list[i]\nif not odd % 2: print(sum)\nelse: print(sum - oddOne)\n\t \t\t \t \t\t\t\t\t\t\t \t \t\t \t\t \t\t\t\t\t",
"input()\r\na = list(map(int,input().split()))\r\ns = sum(a)\r\nif s % 2:\r\n s -= min(i for i in a if i % 2)\r\nprint(s)",
"n = int(input())\r\nnum_list = list(map(int, input().split()))\r\n\r\nout = sum(filter(lambda x: x % 2 == 0, num_list))\r\n\r\ndata = list(filter(lambda x: x % 2 != 0, num_list))\r\nprint(out + sum(sorted(data, reverse=True)[:-1 if len(data) % 2 else n]))\r\n",
"# Wet Shark and Odd and Even\ndef big_boi_sum(arr):\n ini = sum(arr)\n if ini % 2 == 0:\n return ini\n eve = []\n odd = []\n for i in arr:\n if i % 2 == 0:\n eve.append(i)\n else:\n odd.append(i)\n if sum(odd) % 2 != 0:\n odd.remove(min(odd))\n fin = sum(eve + odd)\n return fin\n\n\nn = int(input())\narr = list(map(int, input().rstrip().split()))\nprint(big_boi_sum(arr))",
"n = int(input())\r\nx = input()\r\nx = x.split() \r\nfor i in range(n):\r\n x[i] = int(x[i])\r\nx = sorted(x)\r\ni = 0 \r\nres = sum(x)\r\nsu = sum(x)\r\nwhile True:\r\n if res%2==0:\r\n break\r\n res = su-x[i]\r\n i+=1\r\nprint(res)",
"n = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\nres = sum(a)\r\nif res % 2 != 0:\r\n for i in range(n):\r\n if a[i] % 2 != 0:\r\n res -= a[i]\r\n break\r\nprint(res)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = list()\r\nfor i in a:\r\n\tif i%2==1:\r\n\t\tb.append(i)\r\nprint(sum(a) if len(b)%2==0 else sum(a)-min(b))",
"def fi(items):\r\n # x & 1 == 0 is roughly equivalent and might be slightly faster\r\n return next((x for x in items if x % 2 != 0), -1)\r\na=int(input())\r\nb=list(map(int,input().split()))\r\nb.sort()\r\nc=sum(b)\r\nif c%2==0:\r\n print(c)\r\n quit()\r\nelse:\r\n d=fi(b)\r\n print(c-d)",
"n = int(input())\r\nl_n = list(map(int, input().split()))\r\nl_n.sort()\r\n\r\ns = 0\r\nn_o = 0\r\nl_o = -1\r\n\r\nfor i in range(len(l_n)):\r\n s += l_n[len(l_n) - 1 - i]\r\n if l_n[len(l_n) - 1 - i] % 2 == 1:\r\n l_o = l_n[len(l_n) - 1 - i]\r\n n_o += 1\r\n \r\nif n_o % 2 == 1:\r\n print(s - l_o)\r\nelse:\r\n print(s)",
"n = int(input())\na = input()\nl = a.split()\nmini = 1e9+1\nsm = 0\nfor i in range(len(l)):\n l[i] = int(l[i])\n sm+=l[i]\n if l[i]%2!=0 and mini > l[i]:\n mini = l[i]\nif sm % 2== 0:\n print(sm)\nelse:\n print(sm-mini)\n\t \t\t\t\t\t\t \t \t \t\t\t \t \t\t \t \t",
"\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nres = count = 0\r\nodd = []\r\nfor num in a:\r\n if num % 2 == 0:\r\n res += num\r\n else:\r\n count += 1\r\n odd.append(num)\r\nodd.sort()\r\nif count % 2 == 0:\r\n print(res + sum(odd))\r\nelse:\r\n print(res + sum(odd[1:]))\r\n \r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nl1,l2=[],[]\r\nfor i in range(len(l)):\r\n if(l[i]%2==0):\r\n l1.append(l[i])\r\n else:\r\n l2.append(l[i])\r\nif(len(l2)%2==0):\r\n print(sum(l1)+sum(l2))\r\nelse:\r\n print(sum(l2[1:])+sum(l1))\r\n",
"n= int(input())\r\na = list(map(int,input().split()))\r\ns = sum(a)\r\nif s%2==1:\r\n s = s - min([i for i in a if i%2]) \r\nprint(s)\r\n\r\n",
"N = int(input())\r\narr = [int(c) for c in input().split()]\r\nmn = None\r\nfor i in arr:\r\n if i % 2 != 0 and (mn is None or i < mn):\r\n mn = i\r\nif sum(arr) % 2 != 0:\r\n print(sum(arr) - mn)\r\nelse:\r\n print(sum(arr))\r\n",
"n=int(input(''))\r\nl=list(map(int,input().split()))\r\nl1=list(filter(lambda x:x%2==0,l))\r\nl2=list(filter(lambda x:x%2!=0,l))\r\nif len(l2)>0:\r\n if len(l2)%2==0:\r\n print(sum(l1)+sum(l2))\r\n else:\r\n l2.remove(min(l2))\r\n if len(l2)>0:\r\n print(sum(l1)+sum(l2))\r\n else:\r\n print(sum(l1))\r\nelse:\r\n print(sum(l1))",
"n,s,q,num,a = int(input()),sorted(map(int,input().split())),0,0,0\r\nfor i in range(n):\r\n if s[i] % 2:\r\n if q == 0:\r\n a = s[i]\r\n q += 1\r\n num += s[i]\r\nprint(num - a if q % 2 else num)",
"n=int(input())\r\na= list(map(int, input().split()))\r\na.sort()\r\ndef fn(a,n):\r\n ans=sum(a)\r\n if ans%2==0:return ans\r\n else:\r\n for i in range(n):\r\n if a[i]%2!=0:\r\n ans-=a[i]\r\n return ans\r\nprint(fn(a,n))\r\n",
"n = int(input())\r\n\r\nnumbers = sorted(list(map(int, input().split(\" \"))))\r\n\r\nsmallest_odd_number = 0\r\ncur_sum = 0\r\nfor i in numbers:\r\n if smallest_odd_number == 0 and i % 2 != 0:\r\n smallest_odd_number = i\r\n else:\r\n cur_sum += i\r\n\r\nif cur_sum % 2 != 0:\r\n cur_sum += smallest_odd_number\r\n \r\nprint(cur_sum)\r\n",
"n = int(input())\na = [int(i) for i in input().split()]\nodd = []\neven = []\nfor it in a:\n if (it % 2) == 0: # check if nubmer is even\n even.append(it)\n else:\n odd.append(it)\nans = sum(even)\nif (len(odd) % 2) == 1:\n odd.sort()\n odd.pop(0)\nans += sum(odd)\nprint(ans)\n\n# 9 % 2 => 7 => 5 => 3 => 1 | 9 / 2 => 4.5\n# 6 % 2 => 4 => 2 => 2 => 0 | 6 / 2 => 3\n# 1 2 4 3 7 5 9 4 2 6 => 30\n# odd => 1 3 7 5 9 => 24 => 42\n# even => 2 4 4 2 6 => 18\n# odd + odd = even\n# 3 + 5 = 8\n\n\t\t \t\t\t\t \t\t\t\t \t \t \t\t \t \t \t\t\t",
"n=int(input())\r\na=list(map(int,input().split()))[:n]\r\nb=[]\r\nif sum(a)%2==0:\r\n print(sum(a))\r\nelse:\r\n for i in a:\r\n if i%2!=0:\r\n b.append(i)\r\n print(sum(a)-min(b))",
"a=int(input())\r\nl=list(map(int,input().split()))\r\nk,s=[],0\r\nfor x in l:\r\n\tif x%2==0:s+=x\r\n\telse:k.append(x)\r\nif len(k)%2==1:\r\n\tk.sort()\r\n\ts+=sum(k)-k[0]\r\nelse:s+=sum(k)\r\nprint(s)",
"n=eval(input())\r\nl=input()\r\nl=str(l)\r\na=[0]*n\r\ni=len(l)-1\r\nd=1\r\ns=0\r\nj=0\r\nsu=0\r\nwhile (i>=0):\r\n while (l[i]!=\" \") and (i>=0):\r\n t=int(l[i])\r\n s+=t*d\r\n d*=10\r\n i-=1\r\n a[j]=s\r\n i-=1\r\n j+=1\r\n d=1\r\n s=0\r\nj=0\r\nwhile (j<n):\r\n su+=a[j]\r\n j+=1\r\nif (su%2==0):\r\n print (su)\r\nelse:\r\n j=0\r\n min=(10**9)+1\r\n while (j<n):\r\n if (a[j]<min) and (a[j]%2!=0):\r\n min =a[j]\r\n j+=1\r\n print (su-min)\r\n \r\n \r\n",
"t = int(input())\r\nlist_odds = []\r\ninp = []\r\ncounter = 0\r\n\r\nlist = list(map(int,input().split()))\r\n\r\nfor i in list:\r\n if i%2 == 0:\r\n counter += i\r\n else:\r\n list_odds.append(i)\r\nif(len(list_odds) % 2 == 0):\r\n for i in list_odds:\r\n counter += i\r\nelif len(list_odds) > 2:\r\n list_odds.remove(min(list_odds))\r\n for i in list_odds:\r\n counter += i\r\n\r\nprint(counter)",
"n = int(input())\r\na = list(map(int, input().split()))\r\na = sorted(a)\r\nsm = sum(a)\r\nfor num in a:\r\n if num % 2 == 1 and sm % 2 == 1:\r\n sm -= num\r\n \r\nprint(sm)",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nodd=[]\r\neven=[]\r\nfor i in a:\r\n if i%2==0:\r\n even.append(i)\r\n else:\r\n odd.append(i)\r\nif len(odd)%2!=0:\r\n odd=odd[1:]\r\ns=sum(odd)+sum(even)\r\nprint(s)\r\n \r\n",
"n = int(input())\r\nnumbers = list(map(int, input().split()))\r\nnumbers.sort(reverse=True)\r\n\r\nmax_sum = 0\r\n\r\nodd_left = False\r\nodd_index = None\r\n\r\nfor i in range(n):\r\n if numbers[i] % 2 == 0:\r\n max_sum += numbers[i]\r\n else:\r\n if odd_left:\r\n max_sum += numbers[i] + numbers[odd_index]\r\n odd_left = False\r\n else:\r\n odd_left = True\r\n odd_index = i\r\n\r\nprint(max_sum)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nss = sum(a)\r\na.sort()\r\nif ss%2 == 1:\r\n for i in range(0, n):\r\n if a[i]%2 == 1:\r\n ss -= a[i]\r\n break\r\nprint(ss)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\no=sum(l)\r\nx=[]\r\nif o%2==0:\r\n\tprint(o)\r\nelse:\r\n\tfor i in range(n):\r\n\t\tif l[i]%2!=0:\r\n\t\t\tx.append(l[i])\r\n\tprint(o-min(x))",
"n = int(input())\nx = list(map(int, input().split()))\nx.sort()\nans = 0\ncnt_odd = 0\nodd_min = 10 ** 10\nfor i in range(n):\n if x[i] % 2 != 0:\n cnt_odd += 1\n if x[i] < odd_min:\n odd_min = x[i]\nif cnt_odd % 2 == 0:\n print(sum(x))\nelse:\n print(sum(x) - odd_min)\n",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\ns = sum(a)\r\nif s & 1:\r\n b = s\r\n for i in a:\r\n if i & 1:\r\n b = min(b, i)\r\n print(s - b)\r\nelse:\r\n print(s)\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))[:n]\r\nodd = 0\r\neven = 0\r\ncnt = 0\r\nminn = 100000000000000000\r\nfor i in range(n):\r\n if(arr[i] & 1):\r\n odd += arr[i]\r\n cnt += 1\r\n minn = min(minn, arr[i])\r\n else:\r\n even += arr[i]\r\nif(cnt & 1):\r\n odd -= minn\r\nprint(odd+even)\r\n",
"\r\nn = int(input())\r\ninputArray = [int(x) for x in input().split(\" \") if x != '']\r\n\r\nevenList = [x for x in inputArray if x % 2 == 0]\r\noddList = sorted([x for x in inputArray if x % 2 == 1])\r\n\r\nresult = sum(inputArray) - (oddList[0] if len(oddList) % 2 == 1 else 0)\r\n\r\nprint(result)\r\n",
"count = int(input())\r\nl1 = []\r\ntake = input().split(' ')\r\nfor t in take:\r\n l1.append(int(t))\r\ns = sum(l1)\r\nif (s%2!=0):\r\n l1.sort()\r\n for ele in l1:\r\n if (ele%2!=0):\r\n s -= ele\r\n break\r\nprint (s)",
"from math import inf\n\n\ndef solve(n, a):\n nodds = 0\n minodd = inf\n s = 0\n for i in range(n):\n if a[i] & 1: \n nodds += 1\n minodd = min(minodd, a[i])\n s += a[i]\n return s - minodd if nodds & 1 else s\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))[:n]\n print(solve(n, a))\n\n\nmain()\n",
"#621A\nn = int(input())\nnum = sorted(list(map(int,input().split())),reverse=True)\ntotal = 0\neven,odd = [],[]\nfor i in range(n):\n if num[i]%2 == 0:\n even.append(num[i])\n else:\n odd.append(num[i])\nif (len(odd)%2 == 0): \n total = sum(num)\nelse:\n total = sum(even) + sum(odd) - odd[-1]\nprint(total)\n\t\t\t \t\t\t\t\t \t \t \t \t \t \t \t\t",
"def calc(arr, total_sum):\r\n max_sum = 0\r\n\r\n if total_sum % 2 == 0:\r\n print(total_sum)\r\n return\r\n else:\r\n for i in range(len(arr)):\r\n if arr[i] % 2 == 0:\r\n continue\r\n total_sum -= arr[i]\r\n max_sum = max(max_sum, total_sum)\r\n print(max_sum)\r\n\r\n\r\nn = int(input())\r\ninput_str = input()\r\n\r\ninput_values = input_str.split()\r\narr = [int(value) for value in input_values]\r\ntotal_sum = sum(arr)\r\n\r\narr.sort()\r\ncalc(arr, total_sum)\r\n",
"import sys\r\n_ = sys.stdin.readline()\r\nnumbers = list(map(int, sys.stdin.readline().split()))\r\nnumbers.sort()\r\ns = sum(numbers)\r\nif s % 2 == 1:\r\n s -= next(n for n in numbers if n % 2 == 1)\r\nprint(s)",
"n= int(input())\r\nl=list(map(int, input().split()))\r\nmn=None\r\nc=0\r\nfor i in l :\r\n if i%2 :\r\n c+=1\r\n if mn== None or i<mn :\r\n mn=i\r\nprint(sum(l)-mn if c%2 else sum(l))",
"n = int(input())\r\narr = [ int(i) for i in input().split() ]\r\n\r\nsm = sum(arr)\r\n\r\nif sm%2==0:\r\n print(sm)\r\nelse:\r\n sm=sm-min(int(i) for i in arr if i%2==1)\r\n print(sm)\r\n",
"n=int(input())\nresult=0\no=[]\nl=list(map(int, input().split()))\nfor i in l:\n if i%2==0:\n result+=i \n else:\n o.append(i)\nif len(o)%2==0:\n print(sum(o)+result)\nelse:\n o.sort()\n O=o[1:]\n print(sum(O)+result)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nif len(l)==1:\r\n if l[0]%2==0:\r\n print(l[0])\r\n else:\r\n print(0)\r\nelse:\r\n su=sum(l)\r\n l.sort()\r\n \r\n if su%2==0:\r\n print(su)\r\n else:\r\n i=0\r\n while i<len(l):\r\n if l[i]%2==1:\r\n su-=l[i]\r\n break\r\n i+=1\r\n print(su)\r\n \r\n \r\n",
"n = int(input())\r\ng = []\r\nk = []\r\nfor i in range(n):\r\n a = map(int, input().split())\r\n g += a\r\n break\r\nc = sum(g)\r\nfor j in g:\r\n if j % 2 != 0:\r\n k.append(j)\r\nfor u in g:\r\n if c % 2 == 0:\r\n break\r\n elif c % 2 != 0:\r\n c = c - min(k)\r\n g.remove(min(k))\r\nprint(c)\r\n\r\n\r\n",
"no_of_integers = int(input())\n\narr = list(map(int , input().split(\" \")))\n\nevens , odds = [] , []\n\nfor i in arr :\n if i % 2 == 0 :\n evens.append(i)\n else :\n odds.append(i)\n\nif len(odds) % 2 != 0:\n odds.remove(min(odds))\n\nprint(sum(odds) + sum(evens))\n",
"n=int(input())\r\nm=list(map(int,input().split()))\r\na=0\r\nb=0\r\nc=[]\r\nfor i in m:\r\n if i%2==0:\r\n a+=i\r\n else:\r\n b+=i\r\n c.append(i)\r\nif b%2!=0:\r\n b=b-(min(c))\r\nprint(a+b)",
"n=int(input())\r\nli=[int(x) for x in input().split()]\r\ns=sum(li)\r\nif s%2==0:\r\n\tprint(s)\r\nelse:\r\n\tli.sort()\r\n\tfor i in range(n):\r\n\t\tif (s-li[i])%2==0:\r\n\t\t\tprint(s-li[i])\r\n\t\t\tbreak\r\n\telse:\r\n\t\tprint(0)",
"x = int(input())\r\nl = sorted(list(map(int, input().split())), reverse=True)\r\nif (sum(l[0:x]) % 2 != 0):\r\n x -= 1\r\n while l[x] % 2 == 0:\r\n x -= 1\r\n l.pop(x)\r\nprint(sum(l))",
"n = int(input())\r\n#a = input()\r\n#a = a.split()\r\n#a = [int(x) for x in a]\r\n#n, m = a\r\na = input()\r\na = a.split()\r\na = [int(x) for x in a]\r\nsm = sum(a)\r\nif sm % 2 == 1:\r\n a.sort()\r\n for i in a:\r\n if i % 2 != 0:\r\n print(sm - i)\r\n break\r\nelse:\r\n print(sm)",
"n = int(input())\na = input()\nl = a.split()\nmini_odd = 100000000000 ; sm = 0\nfor i in range(len(l)):\n l[i] = int(l[i])\n sm+=l[i]\n if l[i] % 2 != 0:\n mini_odd = min(mini_odd , l[i])\nif sm %2 !=0:\n print(sm-mini_odd)\nelse:\n print(sm)\n\n\t\t \t\t\t \t\t \t\t\t\t \t\t \t \t \t \t\t",
"n = int(input())\r\nl = list(map(int ,input().split()))\r\npaire = [] \r\nimpaire =[] \r\nfor i in l :\r\n if i % 2 == 0 : \r\n paire.append(i)\r\n else:\r\n impaire.append(i)\r\nimpaire = sorted(impaire)\r\ncounter = 0 \r\nif len(impaire) % 2 == 0 : \r\n counter += sum(impaire)\r\nelse:\r\n counter += sum(impaire[1 : ])\r\ncounter += sum(paire)\r\nprint(counter)",
"n = int(input())\r\nsum_nechet, sum_all = 0, 0\r\nnums = list(map(int, input().split()[:n]))\r\nchet, nechet = [], []\r\nfor i in nums:\r\n if i % 2 == 0:\r\n chet.append(i)\r\n else:\r\n nechet.append(i)\r\nsum_all += sum(chet)\r\nif len(nechet) > 0 and len(nechet) % 2 != 0:\r\n nechet.pop(nechet.index(min(nechet)))\r\nsum_all += sum(nechet)\r\nprint(sum_all)",
"N = int(input())\r\nminNotEvent = 10**9 + 1\r\nSum = 0\r\nfor i in map(int, input().split()):\r\n if i % 2 == 1 and i < minNotEvent:\r\n minNotEvent = i\r\n Sum += i\r\nif Sum % 2 == 0:\r\n minNotEvent = 0\r\nprint(Sum - minNotEvent)",
"n = input()\na = list(map(int, input().split()))\nans = sum(a)\nif ans % 2 != 0:\n a.sort()\n for i in range(len(a)):\n if a[i] % 2 != 0:\n ans -= a[i]\n break\nprint(ans)\n \t \t\t\t \t \t\t \t \t\t \t \t",
"if __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n s = sum(a)\r\n min_odd = 1000000001\r\n for i in range(n):\r\n if a[i] < min_odd and a[i] % 2 == 1:\r\n min_odd = a[i]\r\n if s % 2 == 0:\r\n print(s)\r\n else:\r\n print(s - min_odd)\r\n",
"_ = input()\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\n\r\nprint(s - min(filter(lambda x: x % 2, a)) if s % 2 else s)\r\n",
"a=int(input())\r\nb=list(map(int,input().split()))\r\nc=list(filter(lambda x:x%2==0,b))\r\nd=sorted(list(filter(lambda x:x%2==1,b)))\r\nprint(sum(c)+(sum(d) if len(d)%2==0 else sum(d[1:]) ))\r\n",
"n = int(input())\na = list(map(int, input().split(\" \")))\ns = sum(a)\n\nif s % 2 == 0:\n print(s)\n exit(0)\n\nm = 10**9\nfor i in a: m = min(m, m if i % 2 == 0 else i)\nprint(s - m)\n",
"n=int(input())\r\nodd=99999999990\r\ns=0\r\nfor i in map(int,input().split()):\r\n if i%2==1:\r\n odd=min(odd,i)\r\n s+=i\r\nprint(s if s%2==0 else s-odd)",
"n = int(input())\r\na = list(map(int, input().split()))\r\neven = 0\r\nodd = []\r\nfor i in range(n):\r\n if a[i] % 2 == 0:\r\n even += a[i]\r\n else:\r\n odd.append(a[i])\r\nb = sorted(odd)\r\nif len(b) % 2 == 0:\r\n print(sum(b) + even)\r\nelse:\r\n print(sum(b[1:]) + even)\r\n",
"num = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nodds = [i for i in arr if i %2 != 0]\r\n\r\nevens = [i for i in arr if i %2 == 0]\r\n\r\nif len(odds) % 2 == 0:\r\n print(sum(arr))\r\nelse:\r\n print(sum(arr)-min(odds))\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nsu=0\r\nodd=[]\r\nfor i in l:\r\n if i&1==0:\r\n su+=i\r\n else:\r\n odd.append(i)\r\nodd=sorted(odd,reverse=True)\r\nif len(odd)&1==0:\r\n su+=sum(odd)\r\nelse:\r\n su+=sum(odd[:len(odd)-1])\r\nprint(su)\r\n\r\n",
"n = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\n\r\nprint(sum([en for en in nums if en%2==0]) + sum((odds:=sorted([on for on in nums if on%2==1], reverse=True))[:(l:=len(odds))-l%2]))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\neven=list(filter(lambda x:x%2==0, l))\r\nodd=list(filter(lambda x:x%2!=0, l))\r\ntotal=0\r\ntotal=sum(even)\r\nodd.sort()\r\nif len(odd)%2==0:\r\n\ttotal+=sum(odd)\r\nelse:\r\n\todd.remove(odd[0])\r\n\ttotal+=sum(odd)\r\nprint(total)",
"n = int(input())\r\na = list(map(int, input().split(\" \")))\r\nmainSum = 0\r\n\r\nodd = list([])\r\nfor i in range(0, n, 1):\r\n if((a[i] ^ 1) == (a[i] + 1)):\r\n mainSum = mainSum + a[i]\r\n else:\r\n odd.append(a[i])\r\n\r\nodd.sort(reverse = True)\r\n\r\ntotal = mainSum\r\nlength = len(odd)\r\nfor i in range(0, length, 1):\r\n total += odd[i]\r\n if((total ^ 1) == (total + 1)):\r\n mainSum = total\r\n\r\nprint(mainSum)",
"n = int(input())\r\n\r\nli = list(map(int, input().split()))\r\n\r\nsu = sum(li)\r\n\r\nli.sort()\r\n\r\nif su % 2 == 0:\r\n print(su)\r\n exit()\r\nelse:\r\n for i in li:\r\n if (su - i) % 2 == 0:\r\n print(su - i)\r\n break",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=sum(l)\r\nif s%2==0:\r\n print(s)\r\nelse:\r\n b=sorted(l)\r\n for i in range(n):\r\n if b[i]%2!=0:\r\n b.remove(b[i])\r\n break\r\n print(sum(b))",
"n=int(input())\r\n\r\na=list(map(int,input().split()))\r\nmina=1e9\r\nif(sum(a)%2):\r\n for i in range(n):\r\n if(a[i]%2):\r\n mina=min(mina,a[i])\r\n print(sum(a)-mina)\r\nelse:\r\n print(sum(a))\r\n\r\n\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\ns=sum(a)\r\nif(s%2):\r\n for i in range(0,n):\r\n if(a[i]%2):\r\n s=s-a[i]\r\n break;\r\nprint(s)\r\n\r\n \r\n \r\n \r\n",
"n, lst, le, chan = int(input()), list(map(int, input().split())), [], []\r\nfor x in lst:\r\n if (x & 1) == 1: le.append(x)\r\n else: chan.append(x)\r\ns = sum(lst)\r\nle.sort()\r\nprint(s - le[0]) if s & 1 == 1 else print(s)",
"n = int(input())\r\nnumbers = [int(val) for val in input().split()]\r\n# numbers.sort()\r\nmin_odd = 9999999999999999\r\nodd_sum = 0\r\nans = 0\r\n\r\nfor i in range(n):\r\n if numbers[i] % 2 == 0:\r\n ans += numbers[i]\r\n else:\r\n odd_sum += numbers[i]\r\n min_odd = min(numbers[i], min_odd)\r\n\r\nif odd_sum % 2 == 0:\r\n print(ans + odd_sum)\r\nelse:\r\n print(ans + (odd_sum - min_odd))\r\n\r\n",
"nr_of_ints = int(input())\r\nraw_ints = input()\r\nints = list(map(int, raw_ints.split(' ')))\r\n\r\nmin_odd = 10**9+1\r\nsum = 0\r\n\r\nfor x in range(nr_of_ints):\r\n sum += ints[x]\r\n if ints[x] % 2:\r\n min_odd = min(min_odd, ints[x])\r\n\r\nif sum % 2:\r\n sum -= min_odd\r\n\r\nprint(sum)",
"n = int(input())\r\nl = [int(i) for i in input().split()]\r\nl.sort()\r\nif sum(l)%2 == 0 :\r\n\tprint(sum(l))\r\nelse:\r\n\tm = 0\r\n\tfor i in range(n):\r\n\t\tif l[i]%2 == 1:\r\n\t\t\tm = l[i]\r\n\t\t\tbreak\r\n\tprint(sum(l)-m)\r\n",
"num = int(input())\r\nchosen_num = input().split( )\r\nchosen_num =[int(i) for i in chosen_num]\r\nmin_odd = 1000000000\r\nfor i in chosen_num: \r\n if i % 2 == 1 and i < min_odd:\r\n min_odd = i \r\n\r\nif sum(chosen_num) % 2 == 0:\r\n print(sum(chosen_num))\r\nelse:\r\n print(sum(chosen_num) - min_odd)",
"x = int(input())\r\nl = sorted(list(map(int, input().split())))\r\nnew = [n for n in l if n % 2 != 0]\r\n\r\nif sum(l) % 2 == 0:\r\n print(sum(l))\r\n\r\nelif (len(new)):\r\n print(sum(l[0:x])-new[0])\r\nelse:\r\n print(0)\r\n",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nif sum(arr)%2==0:\r\n print(sum(arr))\r\nelse:\r\n print(sum(arr)-min([el for el in arr if el%2]))\r\n ",
"n=int(input())\r\na=list(input().split())\r\nfor i in range(len(a)):\r\n a[i]=int(a[i])\r\nx=sum(a)\r\nif x%2==0:\r\n print(x)\r\nelse:\r\n f=max(a)\r\n for i in a:\r\n if i%2!=0 and i<f:\r\n f=i\r\n print(sum(a)-f)",
"n = int(input())\ns = str(input()).split()\ntot = 0\nsi = 0\nm = -1\n\nfor i in range(n):\n x = int(s[i])\n if int(x) % 2 == 0:\n tot += x\n else:\n if m == -1:\n m = x\n elif x < m:\n si += m\n m = x\n else:\n si += x\n\nif si % 2 == 0:\n tot += si\nelse:\n tot += si + m\n\nprint(tot)",
"input()\r\nl= list(map(int, input().split()))\r\nl.sort()\r\ntotal= sum(l)\r\nif sum(l)%2== 0:\r\n print(total)\r\nelse:\r\n for i in l:\r\n if i%2!= 0:\r\n print(total- i)\r\n break",
"if __name__ == \"__main__\":\n n = int(input())\n numbers = sorted(list(map(int, input().split())))\n\n s = sum(numbers)\n\n if s % 2 != 0:\n for n in numbers:\n if n % 2 != 0:\n break\n\n s -= n\n print(s)",
"n= int(input())\r\n\r\nl=list(map(int,input().split()))\r\n\r\nl.sort(reverse=True)\r\n\r\nnew_odd = list(filter(lambda x: (x%2 != 0) , l))\r\n\r\nmax_output= 0\r\nif len(new_odd)%2!=0:\r\n num=len(new_odd)-1\r\n\r\nelse:\r\n num=len(new_odd)\r\nfor i in l:\r\n if i %2==0:\r\n max_output+=i\r\n elif num>0:\r\n max_output+=i\r\n num-=1\r\n\r\nprint(max_output)",
"n = int(input() )\na = list(map(int, input().split() ) )\nb, s = [], 0\nfor x in a:\n if x % 2: b.append(x)\n else: s += x\nb.sort()\nprint(s + sum(b[len(b) & 1:] ) )\n",
"N = int(input())\r\nA = list(map(int, input().split()))\r\nif sum(A) % 2 == 0:\r\n\tprint(sum(A))\r\nelse:\r\n\todd = 1e18\r\n\tfor a in A:\r\n\t\tif a % 2 == 1 and a < odd:\r\n\t\t\todd = a\r\n\tprint(sum(A) - odd)",
"a=int(input())\r\n\r\n\r\nt=list(map(int,input().split()))\r\n\r\nt.sort()\r\n\r\n\r\np=sum(t)\r\n\r\n\r\nif len(t)==1:\r\n if p%2==0:\r\n print(p)\r\n else:\r\n print(0)\r\nelse:\r\n if p%2 == 0:\r\n print(p)\r\n else:\r\n s=0\r\n for j in range(a):\r\n if (p-t[j])%2==0:\r\n print((p-t[j]))\r\n s+=1\r\n break\r\n\r\n if s==0:\r\n print(0)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nsu=sum(l)\r\nli=[]\r\nif su%2==0:\r\n\tprint(su)\r\nelse:\r\n\tfor i in l:\r\n\t\tif i%2:\r\n\t\t\tli.append(i)\r\n\tprint(su-min(li))",
"n = input()\nn = int(n)\nsum = 0\nodd = []\na = input().split()\na = [int(x) for x in a]\nfor i in range(n):\n sum += a[i]\n if a[i] % 2 == 1: # odd\n odd.append(a[i])\n\nif sum % 2 == 0:\n print(sum)\n\nelif sum % 2 == 1:\n sum -= min(odd)\n print(sum)\n\t\t \t \t\t\t\t \t \t\t \t \t\t \t\t\t",
"t=int(input())\r\na=list(map(int,input().split()))\r\na.sort()\r\nk=sum(a)\r\nif k%2==0:\r\n print(k)\r\nelse:\r\n for i in a:\r\n if i%2==1:\r\n req=i\r\n break\r\n print(k-req)\r\n",
"input()\r\narr = list(map(int,input().split(\" \")))\r\nminOdd = None\r\ntotalSum =0\r\nfor i in arr:\r\n if i%2!=0:\r\n if minOdd==None:\r\n minOdd=i\r\n elif i<minOdd:\r\n minOdd = i\r\n totalSum+=i\r\nif totalSum%2==0:\r\n print(totalSum)\r\nelse:\r\n print(totalSum-minOdd)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nodd=[]\r\nsum1=0\r\nfor x in l:\r\n if(x%2==0):\r\n sum1+=x\r\n else:\r\n odd+=[x]\r\nif(len(odd)%2==0):\r\n sum1+=sum(odd)\r\nelse:\r\n sum1+=sum(odd)-min(odd)\r\nprint(sum1)\r\n",
"from math import inf\n\nn, a = int(input()), (int(i) for i in input().split())\nres, min_odd = 0, inf\nfor i in a:\n res += i\n if i & 1 == 1:\n min_odd = min(min_odd, i)\nres = res if res & 1 == 0 else res - min_odd\nprint(res)\n",
"n=int(input())\r\na=sorted([int(x) for x in input().split()])\r\ns=sum(a)\r\nf=0\r\nif s%2!=0:\r\n for i in range(n):\r\n if a[i]%2!=0:\r\n s-=a[i]\r\n f=1\r\n break\r\nelse:\r\n f=1\r\nif f==0:\r\n print(0)\r\nelse:\r\n print(s)",
"n = int(input())\r\nt = list(map(int, input().split()))\r\nsum, m = 0, max(t)\r\nfor i in range(len(t)):\r\n sum += t[i]\r\n if t[i] % 2 != 0 and t[i] < m:\r\n m = t[i]\r\nif sum % 2 != 0:\r\n sum -= m\r\nprint(sum)\r\n",
"input()\na=list(map(int,input().split()))\ns=sum(a)\nprint(s-min(i for i in a if i%2) if s%2 else s)\n##",
"n = int(input())\r\na = list(map(int,input().split()))\r\nlst = []\r\nfor i in a:\r\n if i % 2 != 0:\r\n lst.append(i)\r\nlst.sort()\r\nsm = sum(a)\r\nif sm % 2 != 0:\r\n sm = sm - lst[0]\r\nprint(sm)",
"n = int(input())\r\n\r\ns = [int(i) for i in input().split()]\r\n\r\nres = 0\r\n\r\nmass = []\r\n\r\nfor i in s:\r\n if i % 2 == 0:\r\n res += i\r\n else:\r\n mass.append(i)\r\nif len(mass) % 2 == 0:\r\n res += sum(mass)\r\nelse:\r\n mass.sort()\r\n res += sum(mass[1:])\r\nprint(res)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nodd=[]\r\nsum1=0\r\nfor x in l:\r\n if(x%2!=0):\r\n odd+=[x]\r\nif(len(odd)%2==0):\r\n print(sum(l))\r\nelse:\r\n print(sum(l)-min(odd))\r\n",
"n = int(input())\r\nnum = list(input().split())\r\nadd = maxadd = 0\r\nodd = []\r\neven = []\r\n\r\nfor i in num:\r\n if int(i) % 2 == 0:\r\n even.append(int(i))\r\n else:\r\n odd.append(int(i))\r\n\r\nodd.sort()\r\nif odd:\r\n add += sum(odd) \r\n\r\nif even:\r\n add += sum(even)\r\n \r\nif add%2 == 1:\r\n add -= odd[0]\r\n\r\nprint(add)",
"def fun():\n n = int(input())\n nS = sorted([int(x) for x in input().split()])\n sumN = sum(nS)\n\n if sumN % 2 == 0:\n print(sumN)\n return\n\n for i in range(n):\n if (sumN - nS[i]) % 2 == 0:\n print(sumN - nS[i])\n return\n print(0) # Should never happen\n\nfun()\n# ODD - ODD = EVEN\n# EVEN - EVEN = EVEN\n# EVEN - ODD = ODD\n\n \t\t \t \t\t \t\t \t \t\t\t\t\t \t\t\t \t",
"import sys\r\nfrom os import path\r\nimport math\r\nsys.setrecursionlimit(10000)\r\nif(path.exists('C://Users//Uncle//Dev//pythonstuff//CP//unclein.txt')):\r\n sys.stdin = open('C://Users//Uncle//Dev//pythonstuff//CP//unclein.txt','r')\r\n sys.stdout = open('C://Users//Uncle//Dev//pythonstuff//CP//uncleout.txt','w')\r\n def debug(obj):\r\n varname = [name for name in globals() if globals()[name] is obj][0] + ': '\r\n if str(obj)[0:2] == '[[':\r\n print(varname+'\\n')\r\n for line in list(obj):\r\n print(*line)\r\n print()\r\n return\r\n print(varname + str(obj)) \r\nelse:\r\n def debug(obj):\r\n pass\r\n##############################################\r\ndef solve():\r\n n = input()\r\n nums = list(map(int,input().split()))\r\n evens = sorted([x for x in nums if x%2==0], reverse = True)\r\n odds = sorted([x for x in nums if x%2!=0], reverse = True)\r\n total = sum(evens)\r\n if len(odds)%2==0:\r\n total+=sum(odds)\r\n else: total+=sum(odds[:-1])\r\n print(total)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n solve()\r\n\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nif sum(a)%2==0:print(sum(a))\r\nelse:\r\n a.sort()\r\n for i in range(n):\r\n if a[i]%2>0:print(sum(a)-a[i]);break",
"n=int(input())\nnumbers=list(map(int,input().split()))\ntotal=sum(numbers)\nlodd = 0\ncodd=0\nfor i in numbers:\n if i%2 :\n if lodd>i or not lodd:\n lodd=i\n codd+=1\n\nif codd%2:\n total-=lodd\n\nprint(total)\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\neven=[]\r\nodd=[]\r\nfor i in range(n):\r\n\tif a[i]%2==0:\r\n\t\teven.append(a[i])\r\n\telse:\r\n\t\todd.append(a[i])\r\nx=sum(even)\t\t\t\t\r\nif len(odd)%2==0:\r\n\ty=sum(odd)\r\nelse:\r\n\todd.sort()\r\n\todd=odd[1:]\r\n\ty=sum(odd)\r\nprint(x+y)",
"n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ns = sum(a)\r\n\r\nif s % 2 == 0:\r\n print(s)\r\nelse:\r\n a.sort()\r\n for i in range(n):\r\n if (s - a[i]) % 2 == 0:\r\n print(s - a[i])\r\n break\r\n",
"n=int(input())\r\na=[*map(int,input().split())]\r\ns=sum(a)\r\nm=0\r\nif s%2:\r\n m=int(1e10)\r\n for i in range(n):\r\n if a[i]%2:\r\n m=min(m,a[i])\r\n\r\nif m==int(1e10):\r\n print(0)\r\nelse:\r\n s-=m\r\n print(s)\r\n \r\n \r\n \r\n\r\n \r\n",
"import sys\r\ninput=sys.stdin.buffer.readline\r\n\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nodd=list(filter(lambda x:x%2==1,arr))\r\nodd.sort()\r\nans=sum(arr)\r\nif ans%2==0:\r\n\tprint(ans)\r\nelse:\r\n\tprint(ans-odd[0])",
"input();r=[*map(int,input().split())]\r\nif sum(r)%2:print(sum(r)-min([i for i in r if i%2]))\r\nif not sum(r)%2:print(sum(r))",
"n = int(input())\nvalues = input()\nvalues = values.split()\nans = 0\nres = -1\nsoma = 0\nfor i in range(n):\n if(int(values[i])%2!=0):\n if(res == -1):\n res = int(values[i])\n else:\n res = min(res, int(values[i]))\n ans += 1\n soma += int(values[i])\n\nif(ans%2!=0):\n print(soma - res)\nelse:\n print(soma)\n\n \t \t\t\t \t \t\t \t\t \t\t \t\t \t\t\t \t\t\t\t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=0\r\nm=10**9\r\nfor x in l:\r\n if x%2==1:\r\n if x<m:m=x\r\n s+=x\r\nif s%2==0:print(s)\r\nelse:print(s-m)\r\n",
"n = int(input())\r\nm = list(map(int, input().split()))\r\ns = 0\r\nmin = 0\r\nfor i in range(0, n):\r\n s += m[i]\r\n if m[i]%2 !=0:\r\n if min == 0:\r\n min = m[i]\r\n else:\r\n if m[i] < min:\r\n min = m[i]\r\nif s%2 == 0:\r\n print(s)\r\nelse:\r\n print(s - min)",
"n = int(input())\r\nL = list(map(int, input().split()))\r\nEven = []\r\nOdd = []\r\nfor i in L:\r\n if i % 2 == 0:\r\n Even += [i]\r\n else:\r\n Odd += [i]\r\nOdd = sorted(Odd)\r\nif len(Odd) % 2 != 0:\r\n del Odd[0]\r\nprint(sum(Odd)+sum(Even))\r\n",
"n = int(input())\r\nnumbers = list(map(int, input().split()))\r\n\r\neven_numbers, odd_numbers = [], []\r\nfor i in numbers:\r\n if i % 2 == 0:\r\n even_numbers.append(i)\r\n else:\r\n odd_numbers.append(i)\r\n\r\nodd_numbers.sort()\r\nif len(odd_numbers) % 2 == 0:\r\n print(sum(even_numbers) + sum(odd_numbers))\r\nelse:\r\n print(sum(even_numbers) + sum(odd_numbers[1:]))\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=[ ]\r\nif(sum(a)%2==0):\r\n print(sum(a))\r\nelse:\r\n for i in range (0,n):\r\n if(a[i]%2!=0):\r\n b.append(a[i])\r\n print(sum(a)-min(b))",
"n, a = int(input()), list(map(int, input().split()))\r\no = [x for x in a if x % 2]\r\nprint(sum(a) - (min(o) if len(o) % 2 else 0))",
"n=int(input())\narr=[int(i) for i in input().split()]\nx=0\nfor i in range (n):\n x+=arr[i]\nif x%2 == 0 :\n print(x)\nelse:\n c=1000000001\n for i in range(n):\n if arr[i]%2 != 0:\n if arr[i] < c :\n c = arr[i]\n print(x-c)\n \t \t\t\t\t \t\t \t \t \t\t\t",
"n=int(input())\r\na=list(map(int,input().split()))\r\nodd,even=0,0\r\nl=[]\r\nfor i in range(n):\r\n if(a[i]%2==0):\r\n even=even+1\r\n else:\r\n odd=odd+1\r\n l.append(a[i])\r\nif(odd%2==0):\r\n print(sum(a))\r\nelse:\r\n y=min(l)\r\n print(sum(a)-y)\r\n",
"sets=int(input())\r\ndata=list(map(int,input().split()))\r\ndata_chet=[i for i in data if i%2==0]\r\ndata_nechet=[i for i in data if i%2!=0]\r\nanswer=0\r\nif len(data_nechet)%2==0:\r\n answer+=sum(data_nechet)\r\nelif len(data_nechet)%2!=0:\r\n del(data_nechet[data_nechet.index(min(data_nechet))])\r\n answer+=sum(data_nechet)\r\nanswer+=sum(data_chet)\r\nprint(answer)\r\n",
"a=input()\r\nx=list(map(int,input().split()))\r\nx.sort()\r\nz=0\r\nq=sum(x)\r\nwhile q % 2 != 0 :\r\n q -= x[z]\r\n if q % 2 == 0 :\r\n break\r\n else :\r\n q += x[z]\r\n z+=1\r\nprint (q)\r\n",
"t = int(input())\r\n\r\narr = [int(i) for i in input().split()]\r\n\r\nus = {\r\n 1: [],\r\n 0: [],\r\n}\r\n\r\nfor i in arr:\r\n us[i % 2].append(i)\r\n \r\nus[1].sort()\r\n\r\nans = sum(us[0])\r\n\r\nif len(us[1]) % 2 == 0:\r\n ans += sum(us[1])\r\nelse:\r\n ans += sum(us[1][1::])\r\n\r\nprint(ans)",
"n = int(input())\r\nlis = [int(i) for i in input().split()]\r\nlis.sort()\r\nfor i in lis:\r\n\tif i%2 !=0:\r\n\t\tfodd = i\r\n\t\tbreak\r\nsum = 0\r\nfor i in lis:\r\n\tsum +=i\r\nif sum%2==0:\r\n\tres = sum\r\nelse:\r\n\tres = sum - fodd\r\nprint(res)",
"def solve(n, a):\n nodds = 0\n last_odd = -1\n s = 0\n a.sort()\n for i in range(n-1, -1, -1):\n if a[i] & 1: \n nodds += 1\n last_odd = a[i]\n s += a[i]\n if nodds & 1: s -= last_odd\n return s\n\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))[:n]\n print(solve(n, a))\n\n\nmain()\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nl=[]\r\nfor i in a:\r\n if i%2:\r\n l.append(i)\r\nif len(l)%2:\r\n ans=sum(a)-min(l)\r\nelse:\r\n ans=sum(a)\r\nprint(ans)",
"k = int(input())\r\na = [int(x) for x in input().split()]\r\nf = sum(a)\r\na.sort()\r\nfor i in range(len(a)):\r\n if(a[i] % 2 == 1):\r\n min = a[i]\r\n break\r\n else:\r\n continue\r\nif(f % 2 == 1):\r\n f = f - min\r\nprint(f) ",
"n = int(input())\r\na = [int(x) for x in input().split(' ')]\r\ne = [x for x in a if x % 2 == 0]\r\no = [x for x in a if x % 2 == 1]\r\nif len(o) == 0:\r\n ans = sum(e)\r\nelse:\r\n ans = sum(e) + sum(o) - (len(o) % 2) * min(o)\r\nprint(ans)",
"n = int(input())\r\na = sorted(map(int, input().split()))\r\nt = sum(a)\r\nif t % 2 == 1:\r\n for i in a:\r\n if i % 2 == 1:\r\n t -= i\r\n break\r\nprint(t)\r\n",
"n = int(input())\r\nsharks_number = [int(x) for x in input().split()]\r\nif sum(sharks_number)%2 == 0:\r\n\tprint(sum(sharks_number))\r\nelse:\r\n\tsharks_number.sort()\r\n\ti = 0\r\n\twhile i < n:\r\n\t\tif sharks_number[i]%2 != 0:\r\n\t\t\tprint(sum(sharks_number) - sharks_number[i])\r\n\t\t\tbreak\r\n\t\ti += 1\r\n\telse:\r\n\t\tprint(0)",
"n = int(input())\narr = [int(i) for i in input().split()]\n\nsum = 0\nmin = int(2e9)\nfor i in range(n):\n sum += arr[i]\n if arr[i]%2 != 0 and arr[i] < min:\n min = arr[i]\n\nif sum%2 == 0:\n print(sum)\nelse:\n print(sum - min)\n\t \t \t \t\t\t\t\t\t\t\t\t\t\t \t \t \t",
"sum = 0\r\nn = int(input())\r\nlst = [int(num) for num in input().split()]\r\nlst.sort()\r\nfor i in lst :\r\n sum = sum + i\r\nif sum % 2 == 0 :\r\n print(sum)\r\nwhile sum % 2 != 0 :\r\n for i in lst :\r\n sum = sum - i\r\n if sum % 2 == 0 :\r\n print(sum)\r\n break\r\n elif sum % 2 != 0:\r\n sum = sum + i",
"x = int(input())\r\na = map(int, input().split())\r\n\r\ns = 0\r\nmin_negative = float(\"inf\")\r\nn_odd = 0\r\nfor x in a:\r\n if x % 2 == 1:\r\n n_odd += 1\r\n min_negative = min(min_negative, x)\r\n s += x\r\nif n_odd % 2 == 0:\r\n print(s)\r\nelse:\r\n print(s - min_negative)\r\n",
"from sys import stdin\r\nn=int(stdin.readline().strip())\r\ns=list(map(int,stdin.readline().strip().split()))\r\npar=[]\r\nimpar=[]\r\nfor i in range(n):\r\n if s[i]%2==0:\r\n par.append(s[i])\r\n else:\r\n impar.append(s[i])\r\npar.sort()\r\nimpar.sort()\r\nx=0\r\nx=sum(par)\r\nwhile len(impar)>=2:\r\n x+=impar[-1]+impar[-2]\r\n impar.pop()\r\n impar.pop()\r\nprint(x)\r\n",
"n=int(input())\r\nchis=list(map(int, input().split()))\r\nsm=sum(chis)\r\nminnech=0\r\nif sm%2==0:\r\n print(sm)\r\nelse:\r\n for i in range(n):\r\n if chis[i]%2!=0:\r\n if minnech==0:\r\n minnech=chis[i]\r\n elif chis[i]<minnech:\r\n minnech=chis[i]\r\n print(sm-minnech)",
"n=int(input())\r\nnumber=list(map(int, input().split()))\r\nsm=0\r\nodd=[]\r\nfor i in number:\r\n if i%2==0:\r\n sm+=i\r\n else:\r\n odd.append(i)\r\nif len(odd)%2==0:\r\n print(sum(odd)+sm)\r\nelse:\r\n odd.sort()\r\n print(sum(odd[1:])+sm)",
"n=int(input())\r\na=list(map(int,input().split()))\r\nx=sum(a)\r\na=sorted(a)\r\nc=0\r\nb=[]\r\nfor i in a:\r\n if(i%2):\r\n b.append(i)\r\nwhile(x%2):\r\n x=x-b[c]\r\n c=c+1\r\nprint(x)\r\n",
"n = int(input())\r\nn_l = list(map(int, input().split()))\r\nn_o=[]\r\nn_e=[]\r\nfor i in n_l:\r\n if i % 2 ==0:\r\n n_e.append(i)\r\n else:\r\n n_o.append(i)\r\nn_o.sort()\r\n\r\nif len(n_o) % 2 == 0:\r\n print(sum(n_e)+sum(n_o))\r\nelse:\r\n print(sum(n_e)+sum(n_o[1:]))",
"n = int(input())\narr = [int(i) for i in input().split()]\nmn = 1e18\nres = 0\nfor i in range(n):\n res += arr[i]\n if arr[i] % 2 == 1:\n mn = min(mn, arr[i])\nif res % 2 == 1:\n res -= mn\nprint(res)\n\n \t \t\t\t\t\t\t \t \t\t\t\t\t \t \t\t\t \t\t",
"input()\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\nprint(s - min(i for i in a if i % 2) if s % 2 else s)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nx=sum(l)\r\nif x%2==0:print(x)\r\nelse:\r\n l.sort()\r\n for j in range(n):\r\n if (x-l[j])%2==0 :\r\n print(x-l[j])\r\n break",
"n = int(input())\na = list(map(int,input().split()))\ns = [i for i in a if i%2==1]\nk = sorted(s)\nif sum(a)%2==0:\n print(sum(a))\nelse:\n print(sum(a)-k[0])\n\t\t \t \t \t\t\t\t\t\t \t \t \t\t\t \t\t",
"a=int(input())\nb = list(map(int,input().split()))\nc = 0\nb.sort()\nfor i in range(0,a):\n c += b[i]\ni = 0\nd = c\nwhile (d % 2) != 0:\n d = c - b[i]\n i += 1\n if i == a+1:\n d = 0\nprint(d)\n \t \t\t \t \t\t\t \t\t \t\t \t",
"n = int(input())\na = list(map(int, input().split()))\n\nem = sum(num for num in a if num % 2 == 0)\nom = sum(num for num in a if num % 2 == 1)\n\nif om % 2 == 0:\n print(em + om)\nelse:\n print(em + om - min(num for num in a if num % 2 == 1))\n\n \t\t \t\t\t\t\t \t\t \t \t\t \t \t\t\t \t",
"n=int(input())\r\nm=list(map(int,input().split()))[:n]\r\nd=0\r\nfor i in range(0,n):\r\n if (m[i]%2!=0):\r\n d=d+1\r\nm.sort()\r\nfor i in range(0,n):\r\n if (m[i]%2!=0):\r\n a=m[i]\r\n break\r\nif (d%2==0):\r\n f=sum(m)\r\nelse:\r\n f=sum(m)-a\r\nprint(f)",
"n = int(input())\na = [int(i) for i in input().split()]\nodd = []\neven = []\nfor it in a:\n if (it % 2) ==0:\n even.append(it)\n else:\n odd.append(it)\nans = sum(even)\nif (len(odd)% 2) == 1:\n odd.sort()\n odd.pop(0)\nans += sum(odd)\n\nprint(ans)\n\n#Mohamed\n\t\t \t \t\t\t\t \t \t \t \t \t\t\t\t\t \t",
"n=int(input())\r\nt=list(map(int,input().split()))\r\nt.sort()\r\ns=sum(t)\r\na=s\r\nfor i in t:\r\n if a%2 == 0:\r\n break\r\n else:\r\n a=s-i\r\nprint(a)\r\n",
"input()\r\nl = list(map(int, input().split()))\r\nl = sorted(l)\r\ns = sum(l)\r\nif s%2 !=0:\r\n for i in l:\r\n if i%2 != 0:\r\n s = s-i\r\n break\r\nprint(s)\r\n \r\n \r\n \r\n \r\n \r\n",
"n = int(input())\r\nlist = list(input().split())\r\nodd = []\r\n\r\nsum = 0\r\nfor i in range (0 , len(list)) :\r\n if int (list[i]) % 2 == 0 : sum += int(list[i])\r\n else : odd.append(int(list[i]))\r\n\r\nodd.sort()\r\n\r\nwhile len(odd) >= 2 :\r\n sum += (int(odd[len(odd) - 1]) + int(odd[len(odd) - 2]))\r\n odd.pop(len(odd)-1)\r\n odd.pop(len(odd)-1)\r\n\r\nprint(sum)\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Jan 10 13:14:13 2023\r\n\r\n@author: Lenovo\r\n\"\"\"\r\n\r\nn = int(input())\r\nx = list(map(int,input().split()))\r\nx = sorted(x,reverse=True)\r\n\r\nimpares = 0\r\nfor i in range(n):\r\n if x[i]%2!=0:\r\n impares+=1\r\n j=i\r\n\r\nif impares%2==0:\r\n print(sum(x))\r\n\r\nelse:\r\n x.remove(x[j])\r\n print(sum(x))\r\n ",
"n = int(input())\r\n\r\nst = []\r\nst_Zoj = []\r\nst_Fard = [] \r\nans = 0\r\n\r\nfor a in map(int , input().split()): \r\n st.append(a)\r\n\r\nst.sort() \r\n\r\nfor i in range(len(st)):\r\n if st[i] % 2 is 0:\r\n st_Zoj.append(st[i])\r\n else:\r\n st_Fard.append(st[i])\r\n \r\nfor i in range(len(st_Zoj)):\r\n ans += st_Zoj[i]\r\nif len(st_Fard) % 2 is 0:\r\n for i in range(len(st_Fard)):\r\n ans += st_Fard[i]\r\nelse:\r\n for i in range(1 , len(st_Fard)):\r\n ans += st_Fard[i]\r\nprint (ans) ",
"import sys\r\ndef solved(n,arr):\r\n s = sum(arr)\r\n if s % 2 == 0:\r\n return s\r\n else:\r\n arr = sorted(arr)\r\n for i in range(n):\r\n if (s - arr[i]) % 2 == 0:\r\n return s - arr[i]\r\nif __name__ == '__main__':\r\n n = int(input())\r\n arr = list(map(int,input().split()))\r\n print(solved(n,arr))",
"n = int(input())\r\n\r\nline = list(map(int, input().split()))\r\n\r\nif sum(line) % 2 == 0:\r\n print(sum(line))\r\nelse:\r\n line = sorted(line)\r\n for el in line:\r\n if el%2:\r\n print(sum(line) - el)\r\n break",
"n=int(input())\r\nz=list(map(int,input().split()))\r\n\r\nz.sort()\r\n\r\nganjil=[]\r\ngenap=[]\r\n\r\nfor i in z :\r\n\tif i%2==0 :\r\n\t\tgenap.append(i)\r\n\telse :\r\n\t\tganjil.append(i)\r\n\r\nif len(ganjil)%2==0 :\r\n\tprint(sum(ganjil)+sum(genap))\r\nelse :\r\n\tprint(sum(ganjil)+sum(genap)-ganjil[0])",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Jan 10 13:14:13 2023\r\n\r\n@author: Lenovo\r\n\"\"\"\r\n\r\nn = int(input())\r\nx = list(map(int,input().split()))\r\nx = sorted(x,reverse=True)\r\n\r\nimpares = []\r\nfor i in range(n):\r\n if x[i]%2!=0:\r\n impares.append(i)\r\n\r\nif len(impares)%2==0:\r\n print(sum(x))\r\n\r\nelse:\r\n indice = impares[-1]\r\n x.remove(x[indice])\r\n print(sum(x))\r\n ",
"n = int(input())\r\narr = [int(i) for i in input().split()]\r\n\r\nsum = 0\r\nmin = int(2e9)\r\nfor i in range(n):\r\n sum += arr[i]\r\n if arr[i]%2 != 0 and arr[i] < min:\r\n min = arr[i]\r\n\r\nif sum%2 == 0:\r\n print(sum)\r\nelse:\r\n print(sum - min)",
"n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nb=[]\r\nfor i in a:\r\n\tif i%2!=0:\r\n\t\tb.append(i)\r\n\r\nif len(b)%2!=0:\r\n\tprint(sum(a)-min(b))\r\nelse:\r\n\tprint(sum(a))",
"sze = int(input())\r\nlst = sorted(list(map(int, input().split())))\r\ntotalSum = sum(lst)\r\nif(totalSum % 2 == 0):\r\n print(totalSum)\r\nelse:\r\n for num in lst:\r\n totalTemp = totalSum - num\r\n if(totalTemp % 2 == 0):\r\n print(totalTemp)\r\n break\r\n #totalSum = totalTemp",
"a=int(input())\nb=input()\nc=b.split()\nd=0\nmini=1000000000\nfor i in range(len(c)):\n c[i]=int(c[i])\n if c[i]%2!=0:\n mini=min(mini,c[i])\n d+=c[i]\nif d%2==0:\n print(d)\nelse:\n print(d-mini)\n\t \t \t\t\t\t\t\t\t \t \t\t \t \t",
"a=int(input())\r\nnum_list=[int(i) for i in list(input('').split(' '))]\r\nodd=list(filter(lambda x: x%2!=0,num_list))\r\nodd.sort(reverse=True)\r\nif len(odd)%2==0:\r\n print(sum(num_list))\r\nelse:\r\n num_list.remove(odd[-1])\r\n print(sum(num_list))\r\n",
"n = int(input())\r\nodd = 10**10\r\nout = 0\r\na = list(map(int, input().split()))\r\nfor i in a:\r\n if i%2==0:\r\n out += i\r\n else:\r\n out += i\r\n if i < odd:\r\n odd = i\r\n \r\nif out%2==0:\r\n print(out)\r\nelse:\r\n print(out - odd)",
"n=input()\nn=int(n)\nmessi=input()\nlist=messi.split()\nfor i in range(n):\n list[i]=int(list[i])\nlist.sort()\nsum=0\nflag=0\nfor i in range(n):\n sum=sum+list[i]\n if list[i]%2==1 and flag==0:\n flag=list[i]\nif sum%2==0:\n print(sum)\nelse:\n print(sum-flag)\n \t \t \t \t\t\t \t\t\t \t\t\t \t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=sum(l)\r\nif s%2==0:\r\n\tprint(s)\r\nelse:\r\n\tl.sort()\r\n\ta=0\r\n\tfor i in l:\r\n\t\tif i%2!=0:\r\n\t\t\ta=i\r\n\t\t\tbreak\r\n\tprint(s-a)\t\t",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\ns=0\r\nod=[]\r\nod1=0\r\nfor j in a:\r\n if j%2==0:\r\n s+=j\r\n else :\r\n od.append(j)\r\n od1+=1\r\nod.sort()\r\nif od1%2==0:\r\n print(s+sum(od))\r\nelse :\r\n print(s+sum(od)-od[0])",
"n = int(input())\r\nls = list(map(int,input().split()))\r\n\r\nmno=10**10\r\nans=sum(ls)\r\nfor i in range(n):\r\n if ls[i]&1: mno=min(mno,ls[i])\r\nif ans&1: ans-= mno\r\nprint(ans)",
"input()\r\nw = list(map(int, input().split()))\r\nif sum(w) % 2 == 0:\r\n print(sum(w))\r\nelse:\r\n x = min(filter(lambda x:x%2 != 0, w))\r\n print(sum(w)-x)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Jul 9 08:40:44 2019\r\n\r\n@author: avina\r\n\"\"\"\r\n\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nk = []\r\nsums = 0\r\nfor i in range(n):\r\n if l[i]%2 ==0:\r\n sums+=l[i]\r\n else:\r\n k.append(l[i])\r\nif len(k) >0:\r\n if len(k)%2 ==0:\r\n sums+= sum(k)\r\n else:\r\n k.sort()\r\n sums+= sum(k) - k[0]\r\nprint(sums)",
"\r\nt=int(input())\r\nl=list(map(int,input().split()))\r\nr=0\r\nodd=float('+inf')\r\nfor i in range (t):\r\n\tr+=l[i]\r\n\tif l[i]%2==1:\r\n\t\tif odd>l[i]:\r\n\t\t\todd=l[i]\r\nif r%2==0:\r\n\tprint(r)\r\n\texit()\r\nelif odd==0:\r\n\tprint(0)\r\n\texit()\r\nprint(r-odd)",
"n=int(input())\nlst=list(map(int, input().split()))\nlst.sort()\nlst.reverse()\nod=0\nfor i in lst:\n if(i&1):\n od+=1\nsum=0\nok=0\nfor i in range(n):\n if(lst[i]%2==0):\n sum+=lst[i]\n else:\n if(ok or od>1):\n sum+=lst[i]\n od-=1\n ok=not ok\nprint(sum)\n\t \t \t \t \t \t \t\t\t \t\t \t \t \t",
"n = int(input())\r\narr = list(map(int , input().split()))\r\nsumx = 0 \r\neven = 0 \r\nodd = 0\r\nmini = 1000000001\r\nfor x in arr :\r\n if (x%2)==0:\r\n even+=1\r\n \r\n else :\r\n odd +=1\r\n mini = min(mini,x)\r\n sumx += x\r\nif((sumx %2)==0):\r\n print(sumx)\r\nelse :\r\n print(sumx-mini)",
"n = int(input())\r\ns = list(map(int, input().split()))\r\nsym = 0\r\ni = 0\r\nwhile i < n:\r\n if s[i] % 10 % 2 == 0:\r\n sym += s.pop(i)\r\n i -= 1\r\n n -= 1\r\n i += 1\r\nif len(s) % 2 == 0 and len(s) != 0:\r\n for i in s:\r\n sym += i\r\n print(sym)\r\nelif len(s) % 2 != 0:\r\n s.sort(reverse = True)\r\n for i in range(len(s)-1):\r\n sym += s[i]\r\n print(sym)\r\nelse:\r\n print(sym)",
"n = int(input())\r\narr = [int(k) for k in input().split()]\r\n\r\ndef h():\r\n total = sum(arr)\r\n if total % 2 == 0:\r\n return total\r\n \r\n evens, odds = [], []\r\n for el in arr:\r\n if el % 2 == 0:\r\n evens.append(el)\r\n else:\r\n odds.append(el)\r\n \r\n odds.sort()\r\n return total - odds[0]\r\n\r\nprint(h())",
"n=input()\r\na=[int(i) for i in input().split()]\r\nma=[i for i in a if i%2==1]\r\nsm=sum(a)\r\nif sm%2!=0:\r\n sm=sm-min(ma)\r\nprint(sm)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nl1,l2=[],[]\r\nfor i in l:\r\n\tif i%2:\r\n\t\tl1.append(i)\r\n\telse:\r\n\t\tl2.append(i)\r\nl1.sort()\r\ns=0\r\nif len(l1)%2==0:\r\n\ts+=sum(l1)\r\nelse:\r\n\ts+=sum(l1[1:])\r\nprint(s+sum(l2))",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nif(sum(a) % 2 ==0):\r\n print(sum(a))\r\nelse:\r\n x =[]\r\n for i in a:\r\n if i % 2 !=0:\r\n x.append(i)\r\n print(sum(a) - min(x))\r\n ",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\nif s%2==0:\r\n print(s)\r\nelse:\r\n odd=[]\r\n for i in range(n):\r\n if a[i]%2!=0:\r\n odd.append(a[i])\r\n x=min(odd)\r\n s-=x\r\n print(s)",
"# import sys \r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"out.out\",'w')\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\nif s%2==0:\r\n\tprint(s)\r\nelse:\r\n\to=[]\r\n\tfor i in range(n):\r\n\t\tif a[i]%2!=0:\r\n\t\t\to.append(a[i])\r\n\to.sort()\r\n\ts-=o[0]\r\n\tprint(s)\r\n",
"n = int(input())\na = input()\nl = a.split()\nmini_odd=1000000000000000000; sm=0\nfor i in range(len(l)):\n l[i] = int(l[i])\n sm+=l[i]\n if l[i]%2!=0:\n mini_odd=min(mini_odd,l[i])\nif sm%2!=0:\n print(sm-mini_odd)\nelse:\n print(sm)\n \t\t \t\t \t\t \t\t\t \t \t \t\t\t\t\t \t",
"# input\nn = int(input())\nnums = [int(i) for i in input().split()[:n]]\n\n# code\nleast_odd = None\ntotal = 0\n\nfor num in nums:\n num_mod = num % 2\n if num_mod is 1:\n if least_odd is None:\n least_odd = num\n elif least_odd > num:\n least_odd = num\n total = total + num\n\nif total % 2 is 1:\n total = total - least_odd\n\nprint(total)\n \t\t\t\t\t\t \t\t \t \t \t\t \t \t\t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nif sum(l)%2==0:\r\n\tprint(sum(l))\r\nelse:\r\n\to=0\r\n\tl.sort()\r\n\tfor i in l:\r\n\t\tif i%2!=0:\r\n\t\t\to=i\r\n\t\t\tbreak\r\n\tprint(sum(l)-o)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nodd=[]\r\nfor j in l:\r\n if j%2!=0:\r\n odd.append(j)\r\njam=0\r\nfor i in l:\r\n jam=jam+i\r\nif jam%2==0:\r\n print(jam)\r\nelse:\r\n while jam%2!=0:\r\n jam=jam-min(odd)\r\n print(jam)\r\n",
"n = int(input())\r\ns = list(reversed(sorted(map(int, input().split()))))\r\nodd = 0\r\nsmall = s[0]\r\nfor i in s:\r\n if i % 2 == 1:\r\n odd += 1\r\n if i < small:\r\n small = i\r\nif odd % 2 == 0:\r\n print(sum(s))\r\nelse:\r\n print(sum(s) - small)\r\n\r\n# CodeForcesian\r\n# ♥\r\n# خودت همان تغییری باش که میخواهی در دنیا ببینی\r\n",
"n = int(input())\r\n\r\nlist1 = list(map(int, input().split()))\r\n\r\ncount = sum(list1)\r\nif count%2==0:\r\n print(count)\r\nelse:\r\n list1.sort()\r\n r = list1[0]\r\n x = 0\r\n\r\n while list1[x]%2==0:\r\n x += 1\r\n\r\n print(count - list1[x])\r\n",
"n = int(input())\nR = lambda : map(int, input().split())\nv = list(R())\ns = sum(v)\nif s%2==0:\n print(s)\nelse:\n v = sorted(v)\n for x in v:\n if x%2==1:\n print(s-x); exit();",
"n=int(input())\r\na=list(map(int,input().split()))\r\na.sort(reverse=True)\r\nres=x=0\r\nod=0\r\nfor item in a:\r\n if item%2!=0:\r\n od+=1\r\n if od%2==0:\r\n res+=item\r\n res+=x\r\n else:\r\n x=item\r\n else:\r\n res+=item\r\nprint(res)\r\n \r\n \r\n ",
"n= int(input())\r\n\r\nl= list(map(int, input().split()))\r\n\r\ns= sum(l)\r\nif s%2==0:\r\n print(s)\r\nelse:\r\n l.sort()\r\n i=0\r\n while l[i]%2==0:\r\n i+=1\r\n s= s- l[i]\r\n print(s)\r\n ",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\na.sort(reverse=True)\r\nsum = 0\r\nflag = -1\r\nfor i in range(n):\r\n if a[i] %2 == 0:\r\n sum+=a[i]\r\n else:\r\n if flag == -1:\r\n flag = i\r\n else:\r\n sum += a[i] + a[flag]\r\n flag = -1\r\nprint(sum)",
"\r\nn = int(input())\r\nl = list(map(int, input().split()))\r\nl.sort()\r\nb = sum(l)\r\nchet = []\r\nnechet = []\r\nfor i in range(len(l)):\r\n if l[i] % 2 == 0:\r\n chet.append(l[i])\r\n else:\r\n nechet.append(l[i])\r\n if b % 2 != 0 and len(nechet) != 0:\r\n b = sum(l)-nechet[0]\r\nprint(b)",
"n = int(input())\r\nl = list(map(int, input().split()))\r\nif sum(l) % 2 == 0:\r\n print(sum(l))\r\nelse:\r\n for i in sorted(l):\r\n if i % 2 != 0:\r\n print(sum(l) - i)\r\n break",
"n=int(input())\r\nmi=999999999999999999\r\ns=0\r\na=[int(n) for n in input().split(\" \")]\r\nfor i in range(len(a)):\r\n s=s+a[i]\r\n if a[i]<mi and a[i]%2==1:\r\n mi=a[i]\r\nif s%2==0:\r\n print(s)\r\nelse:\r\n print(s-mi)\r\n",
"n=int(input())\r\nnumbers=list(map(int,input().split()))[:n]\r\neven=[]\r\nodd=[]\r\nfor i in numbers:\r\n\tif i%2==0:\r\n\t\teven.append(i)\r\n\telse:\r\n\t\todd.append(i)\r\nif len(even)==0:\r\n\teven_sum=0\r\nelse:\r\n\teven_sum=sum(even)\r\nodd=sorted(odd,reverse=True)\r\nif len(odd)==0:\r\n\todd_sum=0\r\nelif len(odd)%2==0:\r\n\todd_sum=sum(odd)\r\nelse:\r\n\todd_sum=sum(odd[:len(odd)-1])\r\nprint(even_sum+odd_sum)\r\n",
"input()\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\nif(s%2==0):\r\n print(s)\r\nelse:\r\n s -= min(i for i in a if i%2)\r\n print(s)",
"n=int(input())\nl=input()\nk=list(map(int, l.split()))\nk.sort()\no=0\nfor item in k:\n o=o+int(item)\nif o%2==1:\n lo=-1\n for x in k:\n if x %2==1:\n lo=x\n break\n o-=lo\nprint(o)\n\t\t \t \t \t \t\t\t\t\t\t \t \t \t \t",
"n = int(input())\r\nv = list(map(int, input().split()))\r\nchet, nechet = [], []\r\nsum_nechet = 0\r\n\r\nfor i in v:\r\n if i % 2 == 0:\r\n chet.append(i)\r\n else:\r\n nechet.append(i)\r\nsum_chet = sum(chet)\r\n\r\nif len(nechet) % 2 == 0:\r\n sum_nechet = sum(nechet)\r\nelse:\r\n nechet.remove(min(nechet))\r\n sum_nechet = sum(nechet)\r\nprint(sum_chet + sum_nechet)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nb = sorted(a)\r\nc = sum(a)\r\nif c%2==0:\r\n print(c)\r\nelse:\r\n for i in range(n):\r\n if (c-b[i])%2==0:\r\n print(c-b[i])\r\n break\r\n ",
"n = int(input())\r\nmax_sum = 0\r\nseq_list = list(map(int, input().split()))\r\nodd = 0\r\nmin_odd = 9999999999999999\r\nseq_sum = 0\r\nfor num in seq_list:\r\n seq_sum += num\r\n if num % 2 == 1:\r\n odd += 1\r\n if num < min_odd:\r\n min_odd = num\r\nif odd % 2 == 0:\r\n print(seq_sum)\r\nelse:\r\n print(seq_sum - min_odd)\r\n",
"n = int(input())\nl = [*map(int,input().split())]\nSum = sum(l)\nOdd = 0\nMin_O = float('inf')\nfor i in range(n):\n if l[i]%2!=0:\n Odd+=1\n if l[i] < Min_O:\n Min_O = l[i]\nprint(Sum if Odd%2==0 else (Sum-Min_O))\n\n",
"import sys\r\nn=int(input())\r\nlist1=[int(x) for x in input().split()]\r\nlist1.sort()\r\nx=sum(list1)\r\nif x%2==0:\r\n print(x)\r\n sys.exit(0)\r\nelse:\r\n for i in list1:\r\n if i%2==1:\r\n print(x-i)\r\n break\r\n",
"from sys import stdin; inp = stdin.readline\r\nfrom math import dist, ceil, floor, sqrt\r\ndef IA(): return list(map(int, inp().split()))\r\ndef FA(): return list(map(float, inp().split()))\r\ndef SA(): return inp().split()\r\ndef I(): return int(inp())\r\ndef F(): return float(inp())\r\ndef S(): return inp()\r\n\r\ndef main():\r\n n = I()\r\n a = IA()\r\n odd = []\r\n _sum = 0\r\n \r\n for n in a:\r\n if n%2==1: \r\n odd.append(n) \r\n else: \r\n _sum += n\r\n \r\n c = len(odd)\r\n odd.sort(reverse=True)\r\n \r\n if c%2==1:\r\n odd.pop()\r\n \r\n _sum += sum(odd)\r\n \r\n return _sum\r\n \r\n \r\n\r\nif __name__ == '__main__':\r\n print(main())",
"from time import sleep as sle\r\nfrom math import *\r\nfrom random import randint as ri\r\n \r\ndef gcd(a,b):\r\n\tif a == b:\r\n\t\treturn a\r\n\telif a > b:\r\n\t\treturn gcd(a-b,b)\r\n\telse:\r\n\t\treturn gcd(b,a)\r\n\r\ndef pr(x):\r\n\tprint()\r\n\tfor s in x:\r\n\t\tprint(s)\r\n\r\ndef solve():\r\n\tn = int(input())\r\n\ta,a2 = [int(q) for q in input().split()],[]\r\n\tans = 0\r\n\tfor ai in a:\r\n\t\tif ai % 2 == 0:\r\n\t\t\tans += ai\r\n\t\telse:\r\n\t\t\ta2 += [ai]\r\n\ta2.sort()\r\n\tif len(a2) % 2 == 1:\r\n\t\tdel a2[0]\r\n\tans += sum(a2)\r\n\tprint(ans)\r\n\r\nsolve()",
"n=int(input())\r\nl=list(map(int,input().split()))\r\na=sum(l)\r\nx,t=0,[]\r\nif a%2==0:\r\n\tprint(a)\r\nelse:\r\n\t# l=set(l)\r\n\t# l=list(l)\r\n\tfor i in range(n):\r\n\t\tif l[i]%2!=0:\r\n\t\t\tt.append(l[i])\r\n\tx=min(t)\r\n\tprint(a-x)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=[]\r\nfor i in l:\r\n if(i%2!=0):\r\n m.append(i)\r\nm=sorted(m)\r\ns=sum(l)\r\nif(s%2!=0):\r\n print(s-m[0])\r\nelse:\r\n print(s)\r\n ",
"n=input()\nn=int(n)\n\nlist=list(map(int,input().split()))\nsum=0\nodd=[]\nfor i in range (0,n,1) :\n if list[i]%2==0:\n sum+=list[i]\n else :\n odd.append(list[i])\n\nodd.sort()\n\nif len(odd)%2==0:\n for i in range(0,len(odd),1):\n sum+=odd[i]\nelse :\n for i in range(1,len(odd),1):\n sum+=odd[i]\n\nprint(sum)\n \t\t\t\t\t \t \t\t \t \t \t\t\t\t \t\t\t",
"n = int(input())\r\narr = list(map(int,input().split()))\r\nif sum(arr)%2==0:\r\n print(sum(arr))\r\nelse:\r\n arr.sort()\r\n s = 0\r\n for i in range(n):\r\n if arr[i] % 2 == 1:\r\n s =arr[i]\r\n break\r\n print(sum(arr)-s)\r\n",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\ns = sum(a)\r\ne = -1\r\nm = -1\r\nfor e in a:\r\n if e % 2 == 1: \r\n if m == -1: m = e\r\n else: m = min(e, m)\r\nif s % 2 == 0: print(s)\r\nelse: print(s - m)",
"def main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n odd_arr = [number for number in arr if number % 2 == 1]\r\n even_arr = [number for number in arr if number % 2 == 0]\r\n\r\n s = sum(even_arr)\r\n if len(odd_arr) % 2 == 0:\r\n s += sum(odd_arr)\r\n else:\r\n s += sum(odd_arr) - min(odd_arr)\r\n\r\n print(s)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n=input()\r\nn=list(map(int,input().split()))\r\ne=sum([x for x in n if x%2==0])\r\no=[x for x in n if x%2==1]\r\nif len(o)%2==1:\r\n o.remove(min(o))\r\nprint(e+sum(o))\r\n",
"n = int(input())\n\nnumbers = map(int, input().split())\nnumbers = list(reversed(sorted(numbers)))\n\nis_holding = False\nodd_hold = 0\n\nans = 0\nfor number in numbers:\n if number % 2 == 0:\n ans += number\n else:\n if is_holding:\n is_holding = False\n ans += odd_hold + number\n else:\n odd_hold = number\n is_holding = True\nprint(ans)\n \t \t \t \t \t \t \t\t \t\t\t\t\t\t\t \t\t",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nodd=[i for i in l if i&1==True]\r\nif(sum(l)%2==0):\r\n print(sum(l))\r\nelse:\r\n print(sum(l)-min(odd))",
"n=eval(input())\r\nx=list(map(int,input().split()))\r\ni=0\r\ny=[]\r\ns=0\r\no=0\r\ne=0\r\nwhile(i<n):\r\n if(x[i]%2==0):\r\n s+=x[i]\r\n else:\r\n y+=[x[i]]\r\n o+=x[i]\r\n i+=1\r\nif(len(y)%2==0):\r\n r=s+o\r\nelse:\r\n i=0\r\n y.sort(reverse=True)\r\n while(i<len(y)-1):\r\n e+=y[i]\r\n i+=1\r\n r=s+e\r\n \r\nprint(r)\r\n",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\nif sum(a)%2==0:\r\n print(sum(a))\r\nelse:\r\n a.sort()\r\n for i in a:\r\n if i%2!=0:\r\n print(sum(a)-i)\r\n break",
"n=int(input())\r\nt=list(map(int,input().split()))\r\nt.sort()\r\nextdig=0\r\ndigsum=sum(t)\r\nif digsum%2==0:\r\n print(digsum)\r\nelse:\r\n for i in range (n):\r\n if t[i]%2==1:\r\n extdig=t[i]\r\n break\r\n print(digsum-extdig)\r\n \r\n \r\n \r\n \r\n \r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\na = sorted(a, reverse=True)\r\nodds = 0\r\nsum = 0\r\nlastodd = 0\r\nfor i in a:\r\n if i % 2 == 0:\r\n sum += i\r\n else:\r\n sum += i\r\n odds += 1\r\n lastodd = i\r\nif odds % 2 != 0:\r\n sum -= lastodd\r\nprint(sum)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n = int(input())\r\ns = input()\r\nl =s.split(' ')\r\nsum = 0\r\nfor i in range(0,n):\r\n l[i] = int(l[i])\r\n sum+=l[i]\r\nl.sort()\r\nif sum%2==0:\r\n print(sum)\r\nelse:\r\n for i in range(0,n):\r\n if l[i]%2!=0:\r\n sum-=l[i]\r\n break\r\n\r\n print(sum)\r\n",
"#https://codeforces.com/problemset/problem/621/A\n\nn=input()\nl=sorted(list(map(int,input().split())))\nc=0\nans=0\nodd=[]\nfor i in l:\n if i%2==0:\n ans+=i\n else:\n c+=1\n odd.append(i)\nans+=sum(odd)\nif len(odd)%2!=0:\n ans-=min(odd)\nprint(ans)",
"#-------------Program-------------\r\n#----KuzlyaevNikita-Codeforces----\r\n#---------------------------------\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ncounter=0;min_p=10**10;sumy=0\r\nfor i in range(n):\r\n if a[i]%2==1:\r\n counter+=1\r\n min_p=min(min_p,a[i])\r\n sumy+=a[i]\r\nif counter%2==1:\r\n sumy-=min_p\r\nprint(sumy)",
"def main():\n input()\n numbers = [int(_) for _ in input().split()]\n count_odd = sum(x % 2 != 0 for x in numbers)\n result = sum(numbers)\n\n if count_odd % 2 != 0:\n result -= min(x for x in numbers if x % 2 != 0) # remove the smallest odd number\n\n print(result)\n\n\nif __name__ == '__main__':\n main()\n",
"n = int(input())\r\narr = [int(x) for x in input().split()]\r\narr=sorted(arr)\r\nodd = 0\r\nfor i in arr:\r\n if i%2==1:odd+=1\r\n\r\nif odd%2==1:\r\n for i in range(n):\r\n if arr[i]%2 == 1:\r\n del arr[i] \r\n break\r\nprint(sum(arr))",
"n= int(input())\r\na= sorted(list(map(int, input().split())))\r\ns= sum(a)\r\n\r\nif s%2 == 0:\r\n print(s)\r\nelse:\r\n p= 0\r\n for x in a:\r\n if x%2 == 1:\r\n p= x\r\n break\r\n\r\n print(s-p)",
"n = eval(input())\r\nsuma = 0\r\ni = 0\r\nj = 0\r\nlista = []\r\nmini = 10**9\r\n\r\nk = [int(n) for n in input().split()]\r\nlista = lista + k\r\n \r\nwhile(i < len(lista)):\r\n if(lista[i]%2 == 1):\r\n if(lista[i] < mini):\r\n mini = lista[i]\r\n i += 1\r\n \r\nwhile(j < len(lista)):\r\n suma = suma + lista[j]\r\n j += 1\r\n \r\nif(suma % 2 == 1):\r\n suma = suma - mini\r\n \r\nprint(suma)\r\n",
"n = int(input())\r\n\r\nnums = [k for k in map(int, input().split())]\r\n\r\nmin_odd = 10**9 + 1\r\nfor k in nums:\r\n if k % 2 != 0:\r\n min_odd = min(min_odd, k)\r\n\r\nsumm = sum(nums)\r\nif summ % 2 != 0:\r\n print(summ - min_odd)\r\nelse:\r\n print(summ)\r\n",
"input()\r\nnumbers = map(int, input().split())\r\ntotal, lowest_odd, odd_count_is_odd = 0, float(\"inf\"), False\r\nfor n in numbers:\r\n total += n\r\n if n % 2:\r\n lowest_odd = min(lowest_odd, n)\r\n odd_count_is_odd = not odd_count_is_odd\r\nprint(total - lowest_odd if odd_count_is_odd else total)",
"N = int(input())\r\narr =[]\r\nnum_array = []\r\nif(1<=N and N<=100000):\r\n sum = 0\r\n point = input()\r\n str_num = ''\r\n for i in point:\r\n if ( i.isdigit()):\r\n str_num += i\r\n else:\r\n if ( i == ' '):\r\n arr.append(int(str_num))\r\n str_num = ''\r\n arr.append(int(str_num))\r\n for i in arr:\r\n if(i%2==0):\r\n sum += i\r\n\r\n elif(i%2!=0):\r\n num_array.append(i)\r\n\r\n cnt_array = len(num_array)\r\n\r\n if (cnt_array % 2 != 0):\r\n num_array.sort()\r\n num_array.pop(0)\r\n for i in num_array:\r\n sum+=i\r\n\r\n else:\r\n for i in num_array:\r\n sum+=i\r\n\r\n print(sum)\r\n\r\n\r\nelse:\r\n print(0)"
] | {"inputs": ["3\n1 2 3", "5\n999999999 999999999 999999999 999999999 999999999", "1\n1", "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "15\n59 96 34 48 8 72 67 90 15 85 7 90 97 47 25", "15\n87 37 91 29 58 45 51 74 70 71 47 38 91 89 44", "15\n11 81 49 7 11 14 30 67 29 50 90 81 77 18 59", "15\n39 21 95 89 73 90 9 55 85 32 30 21 68 59 82", "15\n59 70 48 54 26 67 84 39 40 18 77 69 70 88 93", "15\n87 22 98 32 88 36 72 31 100 97 17 16 60 22 20", "15\n15 63 51 13 37 9 43 19 55 79 57 60 50 59 31", "1\n4", "2\n1 4", "3\n1 2 4", "2\n9 3", "2\n1000000000 1001", "3\n1 8 4", "3\n7 4 4", "5\n2 3 4 5 3", "2\n4 5", "3\n2 4 5", "3\n2 2 3", "2\n2 3", "4\n2 3 7 7", "2\n999999999 2", "2\n2 5", "3\n5 3 1", "4\n3 2 5 7"], "outputs": ["6", "3999999996", "0", "870", "840", "922", "674", "848", "902", "798", "632", "4", "4", "6", "12", "1000000000", "12", "8", "14", "4", "6", "4", "2", "16", "2", "2", "8", "14"]} | UNKNOWN | PYTHON3 | CODEFORCES | 423 | |
315d11810d627ff4e0a6a72ba8f9720f | New Year Letter | Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas).
Vasya has come up with an algorithm he will follow while writing a letter. First he chooses two strings, *s*1 anf *s*2, consisting of uppercase English letters. Then the boy makes string *s**k*, using a recurrent equation *s**n*<==<=*s**n*<=-<=2<=+<=*s**n*<=-<=1, operation '+' means a concatenation (that is, the sequential record) of strings in the given order. Then Vasya writes down string *s**k* on a piece of paper, puts it in the envelope and sends in to Santa.
Vasya is absolutely sure that Santa will bring him the best present if the resulting string *s**k* has exactly *x* occurrences of substring AC (the short-cut reminds him оf accepted problems). Besides, Vasya decided that string *s*1 should have length *n*, and string *s*2 should have length *m*. Vasya hasn't decided anything else.
At the moment Vasya's got urgent New Year business, so he asks you to choose two strings for him, *s*1 and *s*2 in the required manner. Help Vasya.
The first line contains four integers *k*,<=*x*,<=*n*,<=*m* (3<=≤<=*k*<=≤<=50; 0<=≤<=*x*<=≤<=109; 1<=≤<=*n*,<=*m*<=≤<=100).
In the first line print string *s*1, consisting of *n* uppercase English letters. In the second line print string *s*2, consisting of *m* uppercase English letters. If there are multiple valid strings, print any of them.
If the required pair of strings doesn't exist, print "Happy new year!" without the quotes.
Sample Input
3 2 2 2
3 3 2 2
3 0 2 2
4 3 2 1
4 2 2 1
Sample Output
AC
AC
Happy new year!
AA
AA
Happy new year!
Happy new year!
| [
"def solve(k, x, m, n):\r\n for l1, r1 in [(0, 0), (0, 1), (1, 0), (1, 1)]:\r\n for l2, r2 in [(0, 0), (0, 1), (1, 0), (1, 1)]:\r\n for a1 in range((m - l1 - r1) // 2 + 1):\r\n for a2 in range((n - l2 - r2) // 2 + 1):\r\n ta1, ta2, tl1, tl2, tr1, tr2 = a1, a2, l1, l2, r1, r2\r\n for _ in range(k - 2):\r\n ta1, ta2 = ta2, ta1 + ta2 + (tr1 + tl2) // 2\r\n tl1, tl2 = tl2, tl1\r\n tr1 = tr2\r\n if ta2 == x:\r\n print('C' * l1 + 'AC' * a1 + 'B' * (m - 2 * a1 - l1 - r1) + 'A' * r1)\r\n print('C' * l2 + 'AC' * a2 + 'B' * (n - 2 * a2 - l2 - r2) + 'A' * r2)\r\n return\r\n print('Happy new year!')\r\n \r\nk, x, m, n = map(int, input().split())\r\nsolve(k, x, m, n)",
"def F(a, b, c, d, e, f, k):\r\n\tfor _ in range(k - 2):\r\n\t\ta, b, c, d, e, f = d, e, f, a, b + e + (c and d), f\r\n\treturn e\r\n\r\nk, x, n, m = map(int, input().split())\r\nfor a in [True, False]:\r\n\tfor c in [True, False]:\r\n\t\tfor b in range((n - a - c) // 2 + 1):\r\n\t\t\tfor d in [True, False]:\r\n\t\t\t\tfor f in [True, False]:\r\n\t\t\t\t\tfor e in range((m - d - f) // 2 + 1):\r\n\t\t\t\t\t\tif F(a, b, c, d, e, f, k) == x:\r\n\t\t\t\t\t\t\tprint(['', 'C'][a] + 'AC' * b + 'Z' * (n - a - b - b - c) + ['', 'A'][c])\r\n\t\t\t\t\t\t\tprint(['', 'C'][d] + 'AC' * e + 'Z' * (m - d - e - e - f) + ['', 'A'][f])\r\n\t\t\t\t\t\t\texit()\r\nprint('Happy new year!')",
"k,x,n,m=map(int,input().split())\n\ndef calc(k,a,b,op1,ed1,op2,ed2):\n\tif k==2:\n\t\treturn b\n\treturn calc(k-1,b,a+b+(ed1&op2),op2,ed2,op1,ed2)\n\ndef make(len,a,op,ed):\n\tres,i=\"\",0\n\tif op:\n\t\tres+=\"C\"\n\t\ti+=1\n\tif ed:\n\t\tlen-=1\n\twhile a:\n\t\tres+=\"AC\"\n\t\ta-=1\n\t\ti+=2\n\twhile i<len:\n\t\tres+=\"P\"\n\t\ti+=1\n\tif ed:\n\t\tres+=\"A\"\n\treturn res\n\n\ndef check(a,b,op1,ed1,op2,ed2):\n\tif (2*a+op1+ed1>n) or (2*b+op2+ed2>m):\n\t\treturn 0\n\tif calc(k,a,b,op1,ed1,op2,ed2) == x:\n\t\tprint(make(n,a,op1,ed1))\n\t\tprint(make(m,b,op2,ed2))\n\t\treturn 1\n\nflag=0\nfor i in range(0,(n>>1)+1):\n\tfor j in range(0,(m>>1)+1):\n\t\tfor l in range(0,16):\n\t\t\tif check(i,j,l&1,(l>>1)&1,(l>>2)&1,(l>>3)&1):\n\t\t\t\tflag=1\n\t\t\t\tbreak\n\t\tif flag:\n\t\t\tbreak\n\tif flag:\n\t\tbreak\nif not flag:\n\tprint(\"Happy new year!\")\n\n\t\t\t \t\t\t\t \t\t \t \t \t \t\t \t \t\t"
] | {"inputs": ["3 2 2 2", "3 3 2 2", "3 0 2 2", "4 3 2 1", "4 2 2 1", "3 0 1 1", "50 0 100 100", "50 1 100 100", "4 32 23 32", "5 45 23 32", "6 54 23 32", "7 120 23 32", "8 664 100 100", "8 661 100 99", "8 704 99 100", "10 189 44 100", "3 1 1 6", "3 1 6 1", "50 1000000000 100 100", "6 4 3 2", "5 4 3 2", "3 3 3 3", "48 512559680 100 100", "3 1 1 1", "5 4 2 3", "3 2 3 1", "5 2 1 1", "10 143 4 6", "7 3 1 3", "5 1 10 10", "6 4 2 2", "9 33 2 2", "5 1 2 2", "5 4 2 2", "5 1 1 1", "4 4 3 3", "33 100034454 87 58", "7 4 1 2", "6 7 3 2", "7 12 2 2", "48 512559680 2 2", "6 1 2 2", "6 3 1 1", "4 6 3 5", "13 6325 61 51", "8 7 1 1"], "outputs": ["AC\nAC", "Happy new year!", "AA\nAA", "Happy new year!", "Happy new year!", "A\nA", "AZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA\nAZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA", "Happy new year!", "ACACZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACZA", "AZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACZA", "ACACACZZZZZZZZZZZZZZZZA\nACACACACACACACACACZZZZZZZZZZZZZA", "AZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACZA", "ACACACACACZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACZZZA", "ACACACZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACA", "ACACACACACACACACACACZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA\nACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACZZZA", "ACACACACACACACACACZZZZZZZZZZZZZZZZZZZZZZZZZA\nAZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZA", "A\nACZZZA", "ACZZZA\nA", "Happy new year!", "AZA\nCA", "ACA\nCB", "ACA\nCAC", "Happy new year!", "A\nC", "CA\nACA", "ACA\nC", "A\nC", "CACA\nCACACA", "B\nCZA", "AZZZZZZZZB\nCZZZZZZZZA", "AA\nCA", "CA\nCA", "AB\nCA", "CA\nCA", "C\nA", "ACA\nCAC", "Happy new year!", "C\nAA", "ACA\nCA", "CA\nCA", "Happy new year!", "AB\nCA", "A\nC", "ACA\nCACAC", "Happy new year!", "Happy new year!"]} | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
315da27429573e9d68899fd06513f3c6 | Equator | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.
Determine the index of day when Polycarp will celebrate the equator.
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
Sample Input
4
1 3 2 1
6
2 2 2 2 2 2
Sample Output
2
3
| [
"\r\n#k=int(input())\r\n#n,m=map(int,input().split())\r\nimport sys\r\n\r\n\r\n#a=list(map(int,input().split()))\r\n\r\n#b=list(map(int,input().split()))\r\nimport math\r\n\r\n\r\nn=int(input())\r\n\r\na=list(map(int,input().split()))\r\nss=sum(a);\r\n\r\ns=0\r\nfor i in range(n):\r\n s+=a[i]\r\n\r\n if(2*s>=ss):\r\n print(i+1)\r\n sys.exit()\r\n",
"from math import ceil\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a); hf=ceil(s/2); s2=0\r\nfor i in range(n):\r\n s2+=a[i]\r\n if s2>=hf: print(i+1); break",
"n = input()\r\nnumbers = str(input()).split(' ')\r\n\r\nsum = 0\r\nfor i in numbers:\r\n sum += int(i)\r\n\r\ncount = 0\r\nfor i, val in enumerate(numbers):\r\n count += int(val)\r\n if count >= sum/2:\r\n print(i+1)\r\n break\r\n\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\ns = sum(a)\r\ns1 = 0\r\nfor i in range(len(a)):\r\n s1 += a[i]\r\n if (s1 >= s/2):\r\n print(i+1)\r\n break",
"n = int(input())\na = list(map(int, input().split()))\ns = []\ntmp = 0\nfor i in range(n):\n tmp += a[i]\n s.append(tmp)\nhalf = s[n - 1] / 2\n\nfor i in range(n):\n if s[i] >= half:\n print(i + 1)\n exit()\n",
"n = int(input())\r\nd = list(map(int, input().split()))\r\ne = sum(d)/2\r\nsum = 0\r\nfor i in range(n):\r\n\tsum += d[i]\r\n\tif sum >= e:\r\n\t\tprint(i+1)\r\n\t\tbreak\r\n",
"import math\r\n\r\nn = int(input())\r\na = [int(i) for i in input().split()]\r\n\r\ntotal = res = index = 0\r\n\r\nfor i in a:\r\n total += i\r\n\r\nfor i in range(n):\r\n res += a[i]\r\n if res >= math.ceil(total / 2):\r\n index = i\r\n break\r\n\r\nprint(index + 1)\r\n",
"#ROUNIAAUDI\r\nans=int(input())\r\nlist1=list(map(int,input().split()))\r\nsum2=sum(list1)\r\ns=sum2/2\r\nk=0\r\ni=0\r\nwhile s>k:\r\n k += list1[i]\r\n i+=1\r\nprint(i)\r\n",
"x=int(input())\r\ns=[int(n) for n in input().split()]\r\nj=x//2\r\nif sum(s[:j+1])*2>sum(s):\r\n\tn=j+1\r\n\twhile sum(s[:n])*2>=sum(s):\r\n\t\tn-=1\r\n\tprint(n+1)\r\nelif sum(s[:j+1])*2==sum(s):\r\n\tprint(j+1)\r\nelse:\r\n\tn=j+1\r\n\twhile sum(s[:n])*2<sum(s):\r\n\t\tn+=1\r\n\tprint(n)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)/2\r\nk=0\r\nindex=0\r\nwhile(k<s):\r\n\tk+=a[index]\r\n\tindex +=1\r\nprint(index)",
"import math\r\nn = int(input())\r\nli = list(map(int,input().split()))\r\nk = math.ceil(sum(li)/2)\r\ns=0\r\nfor i in range(n):\r\n s+=li[i]\r\n if(s>=k):\r\n print(i+1)\r\n exit(0)",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\ntotal = sum(a)\r\ntotal = total//2 + total%2\r\ns = 0\r\nfor i in range(n):\r\n s += a[i]\r\n if s>=total:\r\n print(i+1)\r\n break\r\n",
"x=input()\r\nx=int(x)\r\nif 0<x<200001:\r\n randVar=1\r\nelse:\r\n print('No. of days cannot be greater than 200000')\r\n exit()\r\nashu=input().split()\r\nwhile x>0:\r\n x=x-1\r\n ashu[x]=int(ashu[x])\r\n if 0<ashu[x]<10001:\r\n randVar1=1\r\n else:\r\n print('No. of assignment cannot be greater than 10000')\r\n quit()\r\na=sum(ashu)\r\nb=a/2\r\nc=0\r\nn=0\r\nwhile b>c:\r\n c=c+ashu[n]\r\n n=n+1\r\nprint(n)\r\n",
"n=int(input())\na=list(map(int,input().split()))\nsumm=sum(a)\ntmp=0\nfor i in range(n):\n tmp+=a[i]\n if tmp*2>=summ:\n print(i+1)\n break",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\nnew=0\r\ni=0\r\nwhile 2*(new+a[i])<s:\r\n new+=a[i]\r\n i+=1\r\nprint(i+1)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = 0\r\nk = 0\r\nt = 0\r\nfor i in range(0, n):\r\n s = s + a[i]\r\nwhile t < (s+1)//2:\r\n t = t + a[k]\r\n k = k+1\r\nprint(k)",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\ntotal = sum(a)\r\nhalf = total / 2\r\ntSoFar = 0\r\nfor i in range(0, n):\r\n tSoFar += a[i]\r\n if tSoFar >= half:\r\n print(i+1)\r\n break",
"n = int(input())\r\nseq = input().split()\r\na = []\r\nsum_a = 0\r\nfor i in range(n):\r\n sum_a += int(seq[i])\r\n a.append(sum_a)\r\n\r\nmean_a = a[-1] / 2\r\nfor i in range(n):\r\n if a[i] >= mean_a:\r\n print(i + 1)\r\n exit()\r\nprint(n)",
"from math import ceil\r\ninput()\r\nn = list(map(int,input().split()))\r\nfinalval = ceil(sum(n)/2)\r\ntotal = 0\r\nfor i in range(len(n)):\r\n total += n[i]\r\n if total >= finalval:\r\n print(i+1)\r\n break",
"def editor():\r\n\timport sys\r\n\tsys.stdin=open(\"input.txt\",'r')\r\n\tsys.stdout=open(\"output.txt\",'w')\r\n\r\ndef solve():\r\n\tn=int(input())\r\n\ta=list(map(int,input().split()))\r\n\tadd=(sum(a)+1)//2 # for ceil xD\r\n\teq=0\r\n\tfor i,num in enumerate(a):\r\n\t\teq+= num\r\n\t\tif eq>=add:\r\n\t\t\tprint(i+1)\r\n\t\t\treturn\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\t# editor()\r\n\tsolve()",
"n = int(input())\r\n\r\ndata = list(map(int,input().split()))\r\n\r\n\r\nsum_ = sum(data)\r\n\r\nind = 1\r\nh_sum = 0\r\nans = None\r\nfor el in data:\r\n h_sum+=el\r\n if h_sum * 2 >= sum_ and ans is None:\r\n ans = ind\r\n ind+=1\r\n\r\nprint(ans)\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nl = sum(a)\r\np = 0\r\nk = l//2+l%2\r\nfor i in range(n):\r\n p+=a[i]\r\n if p>=k:\r\n print(i+1)\r\n break\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)/2\r\nk=0\r\ni=0\r\nwhile(k<s):\r\n\tk+=a[i]\r\n\ti+=1\r\nprint(i)",
"n = int(input())\r\narr = input().split()\r\nsumd = 0\r\nans = 0\r\ncnt = 0\r\nnewarr=[]\r\nfor i in arr:\r\n newarr.append(int(i))\r\nif sum(newarr)%2 == 0:\r\n sumd = sum(newarr)//2\r\nelse:\r\n sumd = (sum(newarr)//2) + 1\r\nfor i in range(n):\r\n ans += newarr[i]\r\n if ans >= sumd:\r\n break\r\n else:\r\n cnt += 1\r\nprint(cnt + 1)",
"\r\ndef main():\r\n\tn = int(input())\r\n\tA = [int(x) for x in input().split()]\r\n\tprint(solver(n, A))\r\n\r\ndef solver(n, A):\r\n\thalf = sum(A) / 2\r\n\ttotal = 0\r\n\tfor i in range(n):\r\n\t\ttotal += A[i]\r\n\t\tif total >= half:\r\n\t\t\treturn i + 1\r\n\r\n#print(solver(4, [1, 3, 2, 1]))\r\n\r\nmain()\r\n",
"n = int(input())\nd = list(map(int, input().split()))\ne = sum(d)/2\nsum = 0\nfor i in range(n):\n\tsum += d[i]\n\tif sum >= e:\n\t\tprint(i+1)\n\t\tbreak\n",
"n = input()\na = list(map(int, input().split()))\nsm = sum(a)\nmed = int(sm//2+ 2*(sm/2 - int(sm/2)))\nk = 0\nfor j,i in enumerate(a):\n\tk+=i\n\tif k >= med:\n\t\tprint(j+1)\n\t\traise SystemExit",
"# Input.\r\nn = int(input())\r\nA = [int(a) for a in input().split()]\r\n\r\n# Prefix sum array.\r\nprefix = [0] * n\r\nprefix[0] = A[0]\r\nfor i in range(1, n):\r\n prefix[i] = prefix[i - 1] + A[i]\r\n\r\n# Binary Search.\r\ntarget = (sum(A) + 1) // 2\r\n\r\nfor i in range(n):\r\n if prefix[i] < target:\r\n continue\r\n else:\r\n print(i + 1)\r\n break",
"n = int(input())\r\nd = list(map(int, input().split()))\r\ns, c, ok = sum(d), 0, 0\r\nfor i in range(n):\r\n c += d[i]\r\n if c * 2 >= s:\r\n print(i + 1)\r\n break\r\n",
"a=int(input())\r\nb=input().split()\r\nr=len(b)\r\ni=0\r\nk=0\r\nj=0\r\nh=0\r\nif(r==a):\r\n for i in range(r):\r\n t=int(b[i])\r\n k=k+t\r\n d=k/2\r\n for j in range(r):\r\n f=int(b[j])\r\n h=h+f\r\n if(h>=d):\r\n print(j+1)\r\n break\r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n",
"n = int(input())\na = map(int,input().split())\na = list(a)\na = [0] + a\nfor i in range(1,n + 1):\n a[i] += a[i - 1]\nfor i in range(1,n + 1):\n if a[i] >=( a[n] + 1) // 2:\n print(i)\n break\n",
"from collections import deque\r\nfrom math import ceil\r\ndef ii():return int(input())\r\ndef si():return input()\r\ndef mi():return map(int,input().split())\r\ndef li():return list(mi())\r\nabc=\"abcdefghijklmnopqrstuvwxyz\"\r\nn=ii()\r\na=li()\r\ns=0\r\nfor i in a:\r\n s+=i\r\ns=ceil(s/2)\r\ns1=0\r\nfor i in range(n):\r\n s1+=a[i]\r\n if(s1>=s):\r\n print(i+1)\r\n break\r\n ",
"from math import ceil\nn=int(input())\nprobs=list(map(int,list(input().split())))\n\ncount=0\nhalf=ceil(sum(probs)/2)\nfor i in range(0,n):\n count+=probs[i]\n if(count>=half):\n print(i+1)\n exit(0)",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ntotal=0\r\nfor i in l:\r\n total+=i\r\n\r\nif total%2!=0:\r\n total=total//2+1\r\nelse:\r\n total=total//2\r\n\r\ncount=0\r\nfor i in range(n):\r\n count+=l[i]\r\n if count>=total:\r\n break\r\n\r\nprint(i+1) ",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nx=sum(l)/2\r\ncur=0\r\ni=0\r\nwhile cur<x:\r\n cur+=l[i]\r\n i+=1\r\nprint(i)",
"import sys\nfrom math import *\nreadints=lambda:map(int, input().strip('\\n').split())\n\nn=int(input())\narr=list(readints())\ntotal = sum(arr)\ntarget = (total+1)//2\n\ncur=0\nfor i in range(n):\n cur += arr[i]\n if cur>=target:\n print(i+1)\n sys.exit(0)\n",
"# --------------------------------#\r\n#-----------<HajLorenzo>-----------\r\n#Most Important Thing About Life\r\n#Is Loving What You Do...\r\n# --------------------------------#\r\n\r\nn=int(input())\r\nseq=list(map(int,input().split()))\r\nT_SUM=sum(seq)\r\nSUM=0\r\nfor i in range(n):\r\n SUM+=seq[i]\r\n if(SUM*2>=T_SUM):\r\n print(i+1)\r\n break",
"n = int(input())\r\nlis = list(map(int,input().split()))\r\nfor i in range(1,n):\r\n lis[i]+=lis[i-1]\r\nfor i in range(n):\r\n if lis[i]*2>=lis[-1]:\r\n print(i+1)\r\n break ",
"def main_function():\r\n n = int(input())\r\n a = [int(i) for i in input().split(\" \")]\r\n sum_a = sum(a)\r\n half_of_a = sum_a / 2\r\n counter = 0\r\n for i in range(len(a)):\r\n counter += a[i]\r\n if counter >= half_of_a:\r\n print(i + 1)\r\n break\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n main_function()",
"n, a = int(input()), list(map(int, input().split()))\r\ns, tem = sum(a), 0\r\nfor i in range(n):\r\n tem += a[i]\r\n if tem >= s / 2:\r\n exit(print(i + 1))\r\n",
"# ANSHUL GAUTAM\n# IIIT-D\n\nn = int(input())\nl = list(map(int, input().split()))\ns = 0\nsumm = sum(l)\nc = 0\nfor i in l:\n\tc += 1\n\ts += i\n\tif(s >= summ/2):\n\t\tbreak\nprint(c)\n\n\n\n\n\n\n\n\n\n\n\n\n",
"from itertools import accumulate\nfrom bisect import bisect_left\n\ninput()\nl = list(accumulate(map(int, input().split())))\nprint(bisect_left(l, (l[-1] + 1) // 2) + 1)",
"n = int(input())\r\nl = list(map(int, input().split()))\r\n\r\ns = sum(l)\r\nsm = 0\r\n\r\nif(n == 1):\r\n print(1)\r\nelse:\r\n for i in range(n):\r\n sm += l[i]\r\n if(sm >= s/2):\r\n print(i+1)\r\n break\r\n ",
"n = int(input())\r\nl = [int(i) for i in input().split()]\r\ns = sum(l)/2.0\r\nsm = 0\r\nfor i in range(n):\r\n sm+=l[i]\r\n if(sm >= s):\r\n print(i+1)\r\n exit(0)",
"from sys import stdin\r\nn = int(input())\r\nz = list(map(int, stdin.readline().rstrip().split(\" \")))\r\na = sum(z)\r\nc = 0\r\nr = False\r\nfor i in range(n):\r\n c = c + z[i]\r\n if c >= a/2:\r\n print(i+1)\r\n r = True\r\n break\r\nif not r:\r\n print(n)\r\n",
"n = int(input())\r\ntasks = [int(x) for x in input().split()]\r\nsum_tasks = sum(tasks)\r\nsum_ = 0\r\nfor i in range(n):\r\n sum_ += tasks[i]\r\n if sum_tasks / sum_ <= 2:\r\n print(i + 1)\r\n break",
"inp = int(input())\r\nproblems = [int(x) for x in input().split()]\r\ntotal = sum(problems)\r\nsolved = 0\r\ndays = 1\r\nfor i in problems:\r\n solved += i\r\n if solved >= (total / 2):\r\n print(days)\r\n break\r\n else:\r\n days += 1",
"import sys\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nhalf = (sum(a)+1) >> 1\r\nacc = 0\r\n\r\nfor i, x in enumerate(a, start=1):\r\n acc += x\r\n if half <= acc:\r\n print(i)\r\n exit()\r\n",
"import sys\r\ninput = sys.stdin.readline\r\nfrom itertools import accumulate\r\nimport bisect\r\n\r\nn = int(input())\r\nw = list(accumulate(map(int, input().split())))\r\ns = w[-1]/2\r\na = bisect.bisect_right(w, s)\r\nprint(a if w[a-1] == s else a+1)\r\n",
"n = int(input())\r\nlst = list(map(int, input().split()))\r\ntot = sum(lst)\r\ntarget = -(-tot // 2)\r\nsubtot = 0\r\nfor i, x in enumerate(lst):\r\n subtot += x\r\n if subtot >= target:\r\n print(i+1)\r\n break",
"x=int(input())\r\nk=1\r\ns=list(map(int,input().split()))\r\nif x==1:\r\n print(\"1\")\r\n k=0\r\nif k==1:\r\n z=sum(s)\r\n \r\n l=0 \r\n for n in range(x):\r\n l=l+s[n]\r\n \r\n if l>=z/2:\r\n print(n+1)\r\n break\r\n else:\r\n n=n\r\n \r\n ",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n# print(arr)\r\nSum = sum(arr)\r\nans = 0\r\nj = 0\r\nfor i in arr:\r\n ans += i\r\n j += 1\r\n if 2*ans >= Sum:\r\n break\r\nprint(j)\r\n\r\n\r\n# print(type(arr))\r\n",
"import math\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nsum,half=0,0\r\nfor i in a:\r\n sum+=i\r\ncount=0\r\nfor j in a: \r\n half+=j\r\n count+=1\r\n if(half>=math.ceil(sum/2)):\r\n break\r\nprint(count)",
"import math\na=int(input())\nb=input().split()\nfor i in range(len(b)):\n\tb[i]=int(b[i])\nd=int(0)\nfor j in range(len(b)):\n\td+=int(b[j])\nc=int(math.ceil(d/2))\nt=int(0)\nn=int(0)\nfor k in range(len(b)):\n\tt+=int(b[k])\n\tn+=1\n\tif t>=c:\n\t\tbreak\nprint(int(n))",
"a = input()\r\nc = input().split()\r\nd = 0\r\nequator = 0\r\nfor i in range (0 , int(a)):\r\n equator = equator + int(c[i])\r\nequator /= 2\r\nproblems = 0\r\ndays = 1\r\nwhile problems < equator and d <= int(a):\r\n problems += int(c[d])\r\n if problems >= equator:\r\n break\r\n d += 1\r\n days += 1\r\nprint(days)\r\n",
"\n\nn = int(input())\n\ntab = [int(x) for x in input().split()]\n\ns = sum(tab)\n\nc = 0\n\nfor i in range(n):\n c += tab[i]\n if (s + 1) // 2 <= c:\n print(i + 1)\n break\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns,k,l=0,0,0\r\nfor i in a:s=s+i\r\nfor i in a:\r\n k,l=k+i,l+1\r\n if k>s/2 or k==s/2:print(l);break\r\n",
"n=int(input())\r\nl=list(map(int,input().strip().split()))\r\ncnt=1\r\nans=0\r\ntemp=0\r\nif sum(l)%2==0:\r\n temp=sum(l)//2 \r\nelse:\r\n temp=(sum(l)//2)+1\r\nfor i in range(n):\r\n ans+=l[i]\r\n if ans>=temp:\r\n break\r\n else:\r\n cnt+=1 \r\nprint(cnt)\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\ns = sum(l)\r\nd = 0\r\nm = 0\r\nwhile m < s // 2 + s % 2:\r\n m += l[d]\r\n d += 1\r\nprint(d)\r\n",
"def main():\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n\r\n s = sum(a)\r\n idx,t = 0,0\r\n while idx<n and 2*t<s:\r\n t += a[idx]\r\n idx += 1\r\n print(idx)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\ntemp=0\r\nfor i in range(n):\r\n temp+=a[i]\r\n if 2*temp>=s:\r\n print(i+1)\r\n break",
"n = int(input())\r\na = [int (a) for a in input().strip().split()]\r\n\r\nsum = int()\r\ns = int()\r\n\r\nfor i in range (n) :\r\n sum = sum + a[i]\r\n \r\nif sum % 2 == 1 :\r\n sum = sum + 1\r\n \r\nfor i in range (n) :\r\n s = s + a[i]\r\n if sum // 2 < s or sum // 2 == s :\r\n print(i + 1)\r\n break;",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\ns2 = s/2\r\nsp = 0\r\nfor ind, e in enumerate(a):\r\n sp += e\r\n if sp >= s2:\r\n print(ind+1)\r\n break\r\n",
"n = int(input())\r\nx_list = input().split()\r\n\r\na_list = [int(item) for item in x_list]\r\n\r\nsumm = sum(a_list)\r\n\r\n\r\ndef uppper_bound(arr, x):\r\n l = 0\r\n r = len(arr) - 1\r\n while(l <= r):\r\n \r\n m = (l+r)//2\r\n if sum(arr[:m+1]) < x:\r\n l = m + 1\r\n else:\r\n r = m - 1\r\n \r\n return l\r\n\r\nif summ % 2 != 0: \r\n search = summ//2 + 1\r\n\r\nelse:\r\n search = summ/2\r\n#print(search)\r\npos = uppper_bound(a_list, search) + 1 \r\n \r\nprint(pos)",
"n = int(input().strip())\narr = list(map(int, input().split()))\nsum = 0\nans = 0\nfor i in range(n):\n sum += arr[i]\nfor i in range(n):\n ans += arr[i]\n if ans >= sum / 2:\n print(i+1)\n break\n\n\t \t \t\t\t \t \t\t \t\t\t \t",
"def find_half_solved(tot_days, problem_list):\r\n total_problems = sum(problem_list)\r\n running_total = 0\r\n curr_idx = 0\r\n for problem in problem_list:\r\n running_total += problem\r\n if running_total >= total_problems/2:\r\n print(curr_idx + 1)\r\n break\r\n curr_idx += 1\r\n\r\n\r\ntot_days = input()\r\nproblem_list = input()\r\nproblem_list = [int(number) for number in problem_list.split(' ')]\r\nfind_half_solved(tot_days, problem_list)\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\nsu=sum(a)\r\nsum=0\r\nfor i in range(n):\r\n sum+=a[i]\r\n if sum>=su/2:\r\n exit(print(i+1))",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns,c=sum(l),int(0)\r\nfor i in range(len(l)):\r\n c+=l[i]\r\n if c*2>=s:\r\n print(i+1)\r\n break\r\n",
"\"\"\"\nUse binary to find the upper limit of the tot_sum / 2 \ninput: int :1≤n≤200000\n int[] : (1≤ai≤10000)\n \noutput: int: mid+1\n\n\"\"\"\n\nclass Solution(object):\n \n def __init__(self):\n return\n \n def binary_search(self, arr, target):\n k = 0\n while arr[k] < target:\n k += 1\n \n return k\n \n def solve(self):\n \n n = int(input())\n arr = [int(i) for i in input().split(\" \")]\n \n for i in range(1, len(arr)):\n arr[i] = arr[i-1] + arr[i]\n \n target = arr[len(arr)-1]/2\n return (self.binary_search(arr, target)+1)\n \n\na = Solution()\nprint(a.solve())\n\n\n\n",
"import math\nn=int(input())\na=[int(x) for x in input().split()]\nb=sum(a)\nc=int(math.ceil(b/2))\nd=0\ni=0\nwhile((d+a[i])<c):\n d+=a[i]\n i+=1\nprint(i+1)\n",
"\"\"\"Problem A - Equator.\n\nhttp://codeforces.com/contest/962/problem/a\n\nPolycarp has created his own training plan to prepare for the programming\ncontests. He will train for `n` days, all days are numbered from `1` to `n`,\nbeginning from the first.\n\nOn the `i`-th day Polycarp will necessarily solve `a_i` problems. One evening\nPolycarp plans to celebrate the equator. He will celebrate it on the first\nevening of such a day that from the beginning of the training and to this day\ninclusive he will solve half or more of all the problems.\n\nDetermine the index of day when Polycarp will celebrate the equator.\n\nInput:\n\nThe first line contains a single integer `n` (`1 <= n <= 200\\,000`) — the\nnumber of days to prepare for the programming contests.\n\nThe second line contains a sequence `a_1, a_2, ..., a_n` (`1 <= a_i <=\n10\\,000`), where `a_i` equals to the number of problems, which Polycarp will\nsolve on the `i`-th day.\n\nOutput:\n\nPrint the index of the day when Polycarp will celebrate the equator.\n\n\"\"\"\nimport logging\n\n\nfmt = '%(levelname)s - %(name)s (line:%(lineno)s) - %(message)s'\nformatter = logging.Formatter(fmt)\n\nch = logging.StreamHandler()\nch.setLevel(logging.ERROR)\nch.setFormatter(formatter)\n\nlogger = logging.getLogger('equator')\nlogger.setLevel(logging.ERROR)\nlogger.addHandler(ch)\n\n\ndef solve(seq):\n total = sum(seq)\n count = 0\n # while count < total / 2: \n for i, v in enumerate(seq):\n count += v\n if count >= total / 2:\n return i + 1\n return len(seq) + 1\n\n\ndef main():\n _ = int(input().strip())\n seq = [int(x) for x in input().strip().split()]\n result = solve(seq)\n print(result)\n \n\nif __name__ == '__main__':\n main()\n",
"#!/usr/bin/env python3\n\nf = int(input())\n\na = list(map(int,input().split()))\ns = sum(a)/2\np = 0\nindex = 0\nwhile p < s:\n p+=a[index]\n index += 1\nprint(index)\n",
"\ndef main():\n _ = input()\n a = list(map(int, input().split()))\n\n cur = 0\n all_probs = sum(a)\n\n for i, v in enumerate(a):\n cur = cur + v\n if 2 * cur >= all_probs:\n print(i + 1)\n return\n\nmain()",
"n = int(input())\r\na =[int(i) for i in input().split()]\r\ns = sum(a)\r\nif s%2==0:\r\n s = s//2\r\nelse:\r\n s=(s//2)+1\r\nc = 0\r\nfor i in range(n):\r\n c+=a[i]\r\n if c>=s:\r\n break\r\nprint(i+1)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nt = (sum(a) + 1) // 2\r\nans = 0\r\ns = 0\r\nwhile s < t:\r\n s += a[ans]\r\n ans += 1\r\nprint(ans)\r\n",
"import math\r\n#n,m = map(int, input().strip().split(' '))\r\nn=int(input())\r\nlst = list(map(int, input().strip().split(' ')))\r\ns=sum(lst)\r\ns1=math.ceil(s/2)\r\nc=0\r\nfor i in range(n):\r\n c+=lst[i]\r\n if c>=s1:\r\n print(i+1)\r\n break\r\n ",
"n, s = int(input()), [0]\r\nfor x in map(int, input().split()):\r\n s.append(s[-1] + x)\r\nfor i, si in enumerate(s):\r\n if si >= s[-1] - si:\r\n print(i)\r\n break",
"n=int(input());s=input().split();k=[];ans=1;p=0\nfor i in range(0,n):\n k.append(int(s[i]))\nq=sum(k)/2\nfor j in range(0,n):\n p+=k[j]\n if p>=q:\n break\n ans+=1\nprint(ans)",
"#Author : Junth Basnet\r\n\r\na=int(input())\r\nb=list(map(int,input().split()))\r\n\r\nc=sum(b)/2\r\n\r\nans=0\r\ni=0\r\n\r\nwhile (i<c):\r\n i+=b[ans]\r\n ans+=1\r\n \r\nprint(ans)\r\n \r\n\r\n",
"n = int(input())\r\na = [int(e) for e in input().split()]\r\ns, t = sum(a), 0\r\nfor i, j in enumerate(a):\r\n t += j\r\n if t * 2 >= s:\r\n print(i + 1)\r\n exit(0)\r\n",
"n = int(input())\r\nA = list(map(int, input().split(' ')))\r\ns = sum(A)\r\n\r\nif s%2==0:\r\n\ts = s//2\r\nelse:\r\n\ts = s//2 + 1\r\n\r\nc = 0\r\nans = 1\r\nfor i in A:\r\n\tc+=i\r\n\tif c>=s:\r\n\t\tbreak\r\n\tans+=1\r\nprint(ans)\r\n",
"days = int(input())\r\nproblems = list(map(int, input().split()))\r\nsumma = sum(problems)\r\nif summa % 2 == 0:\r\n half_sum = summa // 2\r\nelse:\r\n half_sum = summa // 2 + 1\r\nproblems_sum = 0\r\ni = 0\r\nwhile problems_sum < half_sum:\r\n problems_sum += problems[i]\r\n i += 1\r\nprint(i)",
"n = int(input())\r\na = [int(x) for x in input().split()]\r\nsum = 0\r\nfor i in a:\r\n sum += i\r\nsum1 = 0\r\nfor i in range(n):\r\n sum1 += a[i]\r\n if sum1 >= sum/2:\r\n print(i+1)\r\n break",
"import bisect\r\n\r\ndef solve():\r\n n = int(input())\r\n a = [int(x) for x in input().split(' ')]\r\n p = [0]\r\n for x in a:\r\n p.append(p[-1] + x)\r\n return bisect.bisect_left(p, p[-1] / 2)\r\n\r\nprint(solve())",
"# LUOGU_RID: 101739141\nn, *a = map(int, open(0).read().split())\r\ns = (sum(a) + 1) // 2\r\nt = 0\r\nfor i in range(n):\r\n t += a[i]\r\n if t >= s:\r\n exit(print(i + 1))\r\n",
"n = int(input())\r\na =input().split()\r\ns =0\r\ns1 =0\r\nfor i in range(n):\r\n a[i] = int(a[i])\r\n s+=a[i]\r\nfor i in range(n):\r\n s1+=a[i]\r\n if (s1>=s/2):\r\n print(i+1)\r\n break\r\n \r\n \r\n",
"n=int(input())\r\narr=list(map(int,input().split()))\r\ntotal=sum(arr);summ=0\r\nfor i in range(n):\r\n summ+=arr[i]\r\n if (total+1)//2<=summ:print(i+1);break\r\n",
"import math\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nk=sum(l)\r\nk=int(math.ceil(k/2))\r\ns,c=0,0\r\nfor i in range(len(l)):\r\n s+=l[i]\r\n c+=1\r\n if(s>=k):\r\n break\r\nprint(c)\r\n\r\n",
"import sys, os\r\nfrom io import BytesIO, IOBase\r\nfrom math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log\r\nfrom collections import defaultdict as dd, deque\r\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\r\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\r\n\r\nif os.path.exists('input.txt'):\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\n\r\nn=int(input())\r\nml=list(map(int,input().split()))\r\ns=0\r\ns1=sum(ml)\r\nfor i in range(n):\r\n s+=ml[i]\r\n if s>= s1/2:\r\n print(i+1)\r\n exit()",
"arr = list()\r\nn = int(input())\r\nsum = 0\r\nval = input()\r\nx=0\r\narr = val.split()\r\nfor i in arr:\r\n sum = sum+int(i)\r\nsum = float(sum)\r\nfor i in range(0,n):\r\n x = x+int(arr[i])\r\n if (x >= sum/2):\r\n print(i+1)\r\n break\r\n\r\n\r\n",
"import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef solve():\r\n\tn = int(input())\r\n\t*a, = map(int,input().split())\r\n\ts = sum(a)\r\n\tx = 0\r\n\tfor i in range(n):\r\n\t\tx += a[i]\r\n\t\tif x*2 >= s:\r\n\t\t\tprint(i+1)\r\n\t\t\treturn\r\n\r\nsolve()\r\n",
"input()\na = [0]\nfor x in map(int, input().split()):\n a.append(x + a[-1])\nfor i in range(len(a)):\n if a[i] * 2 >= a[-1]:\n print(i)\n break\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)/2\r\ns1 = 0\r\ni = 0\r\nwhile s1 < s:\r\n s1 += a[i]\r\n i += 1\r\nprint(i)",
"import math\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nsum=0\r\nfor i in range(0,n,1):\r\n sum=sum+a[i]\r\nr=sum/2\r\ns=0\r\nfor i in range(0,n,1):\r\n s=s+a[i]\r\n if s>=r:\r\n break\r\nprint(i+1)",
"n = int(input())\r\ns = list(map(int, input().split()))\r\nsumma = sum(s)\r\na = 0\r\ni = 0\r\nwhile a < summa/2:\r\n a += s[i]\r\n i+=1\r\nprint(i)\r\n",
"x=int(input())\r\ntotal=0\r\nflag=False\r\nsp=[int(i) for i in input().split()]\r\nx=sum(sp)\r\nh=0\r\nfor el in sp:\r\n total+=el\r\n h+=1\r\n if total>=(x/2):\r\n print(h)\r\n flag=True\r\n break\r\nif not(flag):\r\n print(len(sp))",
"n = int(input());\r\n\r\na = [int (i) for i in input().split()];\r\n\r\ntotal = 0;\r\ntotal1 = 0;\r\n\r\nfor i in range(0, n):\r\n total += a[i];\r\n\r\nif(total%2 == 0):\r\n need = total/2;\r\nelse:\r\n need = total//2 + 1;\r\n\r\nfor i in range(0, n):\r\n total1 += a[i];\r\n if(total1 >= need):\r\n place = i+1;\r\n break;\r\n\r\nprint(place);",
"x=int(input())\r\nl=list(map(int,input().split()))\r\ns=sum(l)/2\r\nc=0\r\nfor i in range(x):\r\n\tc+=l[i]\r\n\tif c>=s:\r\n\t\tprint(i+1)\r\n\t\tbreak",
"input()\narr = list(map(int, input().split()))\ns = sum(arr)\n\nacc = 0\nj = 0\nfor i in range(len(arr)):\n acc += arr[i]\n j += 1\n if acc >= s/2:\n break\n\nprint(j)\n",
"n = int(input())\r\na=list(map(int,input().split()))\r\nflag = sum(a)/2\r\ntemp = 0\r\nfor i in range(n):\r\n temp = temp+a[i]\r\n if(temp>=flag):\r\n print(i+1)\r\n break",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nw=0\r\ns=sum(l)\r\nif(s%2==0):\r\n c=s//2\r\nelse:\r\n c=s//2+1\r\nfor i in range(n):\r\n w=w+l[i]\r\n if(w>=c):\r\n print(i+1)\r\n break\r\n",
"n=int(input())\r\nw=[int(k) for k in input().split()]\r\nc=sum(w)//2+sum(w)%2\r\nfor j in range(n):\r\n c-=w[j]\r\n if c<=0:\r\n print(j+1)\r\n break",
"n=int(input())\r\nx=list(map(int,input().split()))\r\nz=sum(x)\r\nif z%2!=0:\r\n y=0\r\n for i in range(n):\r\n y+=x[i]\r\n if y>=(z//2)+1:\r\n print(i+1)\r\n break\r\nelse:\r\n y=0\r\n for i in range(n):\r\n y+=x[i]\r\n if y>=z//2:\r\n print(i+1)\r\n break",
"from bisect import bisect_right, bisect_left\n\nn = int(input())\na = list(map(int, input().split()))\n\nfor i in range(1, n):\n a[i] += a[i - 1]\n\nres = bisect_left(a, a[-1] / 2) + 1\n\nprint(res)\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\ns=sum(l)\r\nif s%2==0:\r\n s//=2\r\nelse:\r\n s//=2\r\n s+=1\r\nif l[0]>=s:\r\n print(1)\r\nelse:\r\n for i in range(1,n):\r\n l[i]+=l[i-1]\r\n if l[i]>=s:\r\n print(i+1)\r\n break\r\n ",
"n=int(input())\r\na=list(map(int,input().split()))\r\nind=0\r\ns=sum(a)\r\ns=(s+1)//2\r\ns1=0\r\nfor i in range(n):\r\n if(s1>=s):\r\n break\r\n s1+=a[i]\r\n ind=i\r\n if(s1>=s):\r\n break\r\nprint(ind+1)\r\n",
"n = int(input())\r\nprobs = list(map(int,input().split(\" \")))[:n]\r\ntotal = sum(probs)\r\nsumProb=0\r\nfor i in range(n):\r\n sumProb+=probs[i]\r\n if(sumProb >= total/2):\r\n print(i+1)\r\n break",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\ns=0\r\nfor i in a:\r\n s+=i\r\ns=s/2\r\nc=0\r\nfor i in range(n):\r\n c+=a[i]\r\n if c>=s:\r\n print(i+1)\r\n break",
"n=int(input())\r\nr=[int(i) for i in input().split()]\r\ng=0\r\nfor i in range(n):\r\n g+=r[i]\r\nc=0\r\nfor i in range(n):\r\n c+=r[i]\r\n if c >= g/2:\r\n print(i+1)\r\n break\r\n",
"import math\r\n\r\ninp=input()\r\nn=int(inp)\r\nl=list()\r\na=input()\r\nnumber=a.split()\r\nfor num in number:\r\n l.append(int(num))\r\navg=sum(l)/2\r\ntot=int(math.ceil(avg))\r\nlargest=0\r\nfor i in range(len(l)):\r\n largest+=l[i]\r\n if(largest>=tot):\r\n print(i+1)\r\n break\r\n\r\n\r\n ",
"from math import *\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nsumx=sum(arr)\r\nans=-1\r\nsumy=0\r\nfor i in range(n):\r\n sumy+=arr[i]\r\n if(sumy>=ceil(sumx/2)):\r\n ans=i+1\r\n break\r\nprint(ans)",
"n=int(input())\r\ns=0\r\ns1=0\r\nw=[]\r\nw=list(map(int,input().split()))\r\nfor i in range(n):\r\n s+=w[i]\r\nfor i in range(n):\r\n s1+=w[i]\r\n if s1*2>=s:\r\n print(i+1)\r\n break\r\n\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\nday = 0\r\nsolved = 0\r\n\r\ntarget = sum(a)/2\r\n\r\nfor index, element in enumerate(a):\r\n solved += element\r\n if solved >= target:\r\n print(index + 1)\r\n break",
"n = int(input())\r\na = list(input().split(' '))\r\na = list(int(x) for x in a)\r\nres = sum(a)/2\r\ncur = 0\r\nfor i in range(n):\r\n cur += a[i]\r\n if cur >= res:\r\n print(i + 1)\r\n break\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\ns = 0\r\ntemp = sum(a)\r\nfor i in range(n):\r\n\ts+=a[i]\r\n\tif s>=temp*0.5:\r\n\t\tprint(i+1)\r\n\t\tbreak\r\n",
"n = int(input())\r\na = [*map(int, input().split())]\r\nS = sum(a); s = 0\r\nfor i in range(n):\r\n s += a[i]\r\n if 2*s >= S:\r\n print(i+1)\r\n break",
"n = int(input())\na = list(map(int,input().split()))\ns=sum(a)\nans=0\nfor i in range(n) :\n ans+=a[i]\n if ans >= s/2.0 :\n print (i+1)\n break\n",
"a=[]\r\nsuml = 0\r\nsm = 0\r\n\r\nn= int(input())\r\nx=input().split()\r\nfor j in x:\r\n j=int(j)\r\n a.append(j)\r\n suml= suml + j\r\nsuml=(suml/2)\r\nval=0\r\nfor m in a:\r\n sm=sm+m\r\n if(sm>=suml):\r\n val=val+1\r\n break\r\n else:\r\n val=val+1\r\n \r\nprint(val)\r\n",
"import math\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nss=sum(arr)\r\nxx=0\r\nfor i in range(n):\r\n\txx+=arr[i]\r\n\tif xx>=math.ceil(ss/2):\r\n\t\tprint(i+1)\r\n\t\texit()\r\n",
"n = int(input())\r\nar = list(map(int, input().split()))\r\ns = sum(ar)\r\ncnt, s2, = 0, 0\r\n\r\nfor i in range(n):\r\n if (s2 >= s / 2):\r\n break\r\n s2 += ar[i]\r\n cnt += 1\r\n\r\nprint(cnt)\r\n",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\nx=sum(a)\r\ny=0\r\nfor i in range(n):\r\n y+=a[i]\r\n if x-y<=y:\r\n print(i+1)\r\n break\r\n",
"from math import *\r\ndef sol():\r\n n = input()\r\n arr = list(map(int, input().split()))\r\n s = sum(arr)\r\n curr = 0\r\n for i in range(len(arr)):\r\n curr += arr[i]\r\n if curr >= s/2:\r\n print(i+1)\r\n return\r\n print(n)\r\nsol()",
"n = int(input())\nprobs = list(map(int,input().strip().split(' ')))\n\ntotal = sum(probs)\nhalf = total / 2\n\ncsum = 0\nfor i,prob in enumerate(probs):\n csum += prob\n if csum >= half:\n print(i+1)\n break",
"n = input()\r\nbar = input().split()\r\nbar = [int(x) for x in bar]\r\nadd = sum(bar)\r\ncount = 0\r\nallofem = 0\r\n\r\nfor i in bar:\r\n count += 1\r\n allofem += int(i)\r\n if allofem >= (add/2):\r\n print(count)\r\n break\r\n",
"n=input()\r\na=input().split()\r\ns=0\r\ns2=0\r\nfor i in range(len(a)):\r\n a[i]=int(a[i])\r\n s+=a[i]\r\nfor i in range(len(a)):\r\n s2+=a[i]\r\n if s2>=s/2:\r\n print(i+1)\r\n exit()\r\n",
"from sys import *\r\ninput = lambda:stdin.readline()\r\n\r\nint_arr = lambda : list(map(int,stdin.readline().strip().split()))\r\nstr_arr = lambda :list(map(str,stdin.readline().split()))\r\nget_str = lambda : map(str,stdin.readline().strip().split())\r\nget_int = lambda: map(int,stdin.readline().strip().split())\r\nget_float = lambda : map(float,stdin.readline().strip().split())\r\n\r\n\r\nmod = 1000000007\r\nsetrecursionlimit(1000)\r\n\r\nn = int(input())\r\narr = int_arr()\r\n\r\nval = sum(arr)\r\ntarget = val // 2 if val % 2 == 0 else val // 2 + 1\r\ntot = 0\r\nfor i in range(n):\r\n tot += arr[i]\r\n if tot >= target:\r\n print(i+1)\r\n break",
"n = int(input())\na = list(map(int, input().split()))\n\nt = sum(a) / 2\n\nq = 0\n\nfor k, i in enumerate(a):\n q += i\n\n if q >= t:\n print(k + 1)\n break\n",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nj=sum(a)/2\r\nm=0\r\nfor i in range(n):\r\n m+=a[i]\r\n if m>=j:\r\n print(i+1)\r\n break\r\n",
"import sys \r\nimport math as mt\r\nimport bisect\r\n#input=sys.stdin.readline\r\n#t=int(input())\r\nt=1 \r\n \r\ndef solve():\r\n suma=sum(l[:])\r\n suma1=0\r\n for i in range(n):\r\n suma1+=l[i]\r\n if suma1>=(suma/2):\r\n return i+1\r\n \r\n \r\n \r\nfor _ in range(t):\r\n n=int(input())\r\n #a=int(input())\r\n #b=int(input())\r\n #n,m,k=map(int,input().split())\r\n #x,y,k=map(int,input().split())\r\n #n,h=(map(int,input().split()))\r\n l=list(map(int,input().split()))\r\n #l2=list(map(int,input().split()))\r\n print(solve())",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\ni = 0\r\nj = 0\r\nif s%2==0:\r\n while i<(s//2):\r\n i = i + a[j]\r\n j = j + 1\r\n print(j)\r\nelse:\r\n while i<(s//2)+1:\r\n i = i + a[j]\r\n j = j + 1\r\n print(j)",
"def main():\r\n _ = int(input())\r\n arr = list(map(int, input().split()))\r\n s = sum(arr)\r\n curr = 0\r\n for i, el in enumerate(arr):\r\n curr += el\r\n if 2 * curr >= s:\r\n print(i + 1)\r\n return\r\n\r\n\r\nmain()",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\ns = s // 2 + s % 2\r\ntemp_s = 0\r\nfor i in range(n):\r\n temp_s += a[i]\r\n if temp_s >= s:\r\n print(i + 1)\r\n break",
"n = int(input())\r\na = [int(i) for i in input().split()]\r\nx, s, ss = 0, 0, sum(a)\r\nwhile s * 2 < ss:\r\n\ts += a[x]\r\n\tx += 1\r\nprint(x)",
"def main():\r\n\r\n\tn=int(input())\r\n\tip=[int(item) for item in input().split(\" \")]\r\n\r\n\tprefixSum=[]\r\n\tprefixSum.append(ip[0])\r\n\tfor i in range(1,n):\r\n\t\tprefixSum.append(ip[i]+prefixSum[i-1])\r\n\r\n\thalfIp=prefixSum[n-1]/2\r\n\tfor i in range(n):\r\n\t\tif prefixSum[i]>=halfIp:\r\n\t\t\tprint(i+1)\r\n\t\t\texit()\r\n\r\nif __name__==\"__main__\":\r\n\tmain()",
"n = int(input())\r\nmas = list(map(int,input().split()))\r\nsum = 0\r\nfor i in range(n):\r\n sum+=mas[i]\r\n mas[i]=sum\r\n#l=0\r\n#r=n\r\n#while r!=l:\r\n# \r\n# m = (r+l)//2\r\n# print(r,m,l)\r\n# if mas[m]>=sum//2+sum%2:\r\n# r=m\r\n# else:\r\n# l=m\r\nfor i in range(len(mas)):\r\n if mas[i] >= sum/2:\r\n print(i+1)\r\n break",
"n = int(input())\r\ns = input().split()\r\na = []\r\nsum = 0\r\nfor x in s:\r\n a.append(int(x))\r\n sum += int(x)\r\nt = (sum + 1) // 2\r\nsum = 0\r\nans = 0\r\nfor i in range(n):\r\n sum += a[i]\r\n if sum >= t:\r\n ans = i + 1\r\n break\r\nprint(ans)",
"n = int(input())\ntasks = list(map(int, input().split()))\ns = sum(tasks)\nans, now = 0, 0\nwhile 2 * now < s:\n ans, now = ans + 1, now + tasks[ans]\nprint(ans)",
"n = int(input())\r\na = list(map(int, input().split()))\r\nss, s = 0, sum(a)\r\nfor i in range(n):\r\n ss += a[i]\r\n if(2 * ss >= s):\r\n print(i + 1)\r\n break\r\nelse:\r\n print(n)",
"input()\r\na = list(map(int, input().split()))\r\n\r\nsum = (sum(a) + 1) // 2\r\nk = i = 0\r\n\r\nwhile k < sum:\r\n k += a[i]\r\n i += 1\r\n\r\nprint(i)\r\n",
"n=int(input())\r\narr=list(map(int,input().split()))\r\nsum=sum(arr)\r\ntar=sum/2;\r\ntar2=int(tar)\r\nif tar-tar2:\r\n tar2+=1\r\nget=0\r\ni=1\r\nfor x in arr:\r\n get+=x\r\n if get>=tar2:\r\n break\r\n i=i+1\r\nprint(i)\r\n",
"n=int(input())\na=list(map(int,input().split()))\ns=sum(a)\nx=0\nfor i in range(n):\n\tx+=a[i]\n\tif 2*x>=s:\n\t\tprint(i+1)\n\t\texit()\n",
"n = int(input())\nx = list(map(int, input().split()))\ntotal_sum = sum(x)\ncnt, i = 0, 0\nwhile 2 * cnt < total_sum:\n cnt += x[i]\n i += 1\nprint(i)\n",
"N=int(input())\narr=input().split(\" \")\ntotal=0\ntotal1=0\nfor i in range(0,len(arr)):\n total+=int(arr[i])\nfor j in range(0,len(arr)):\n total1+=int(arr[j])\n if (total/total1<=2.0):\n print(j+1)\n break\n",
"def main():\r\n n = int(input())\r\n problems = [int(i) for i in input().split()]\r\n all_problems = sum(problems)\r\n now_problems = problems[0]\r\n i = 0\r\n while now_problems < (all_problems + 1) // 2:\r\n i += 1\r\n now_problems += problems[i]\r\n print(i + 1)\r\n\r\n\r\nmain()",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=sum(a)\r\nc=0\r\nfor i in range(n):\r\n c+=a[i]\r\n if c>=b/2:\r\n print(i+1)\r\n break",
"n, a = int(input()), list(map(int, input().split()))\r\ntotal = sum(a)\r\ncur, pos = 0, 0\r\nfor elem in a:\r\n cur += elem\r\n if 2 * cur >= total:\r\n print(pos + 1)\r\n exit()\r\n pos += 1",
"input()\r\na = [int(x) for x in input().split()]\r\ns = sum(a)\r\nt = 0\r\nfor i in range(len(a)):\r\n t = t + a[i]\r\n if t >= s / 2:\r\n print(i + 1)\r\n break\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ntemp,k=0,sum(a)\r\nfor i in range(n):\r\n temp+=a[i]\r\n if temp>=k/2:\r\n print(i+1)\r\n break\r\n",
"import sys\r\nimport math\r\nimport bisect\r\n\r\ndef solve(A):\r\n n = len(A)\r\n total = sum(A)\r\n val = 0\r\n for i in range(n):\r\n val += A[i]\r\n if val * 2 >= total:\r\n return i\r\n return -1\r\n\r\ndef main():\r\n n = int(input())\r\n A = list(map(int, input().split()))\r\n print(solve(A) + 1)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"from itertools import accumulate\r\nimport bisect\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n half = (1 + sum(arr)) // 2\r\n acc = [*accumulate(arr)]\r\n print(bisect.bisect_left(acc, half) + 1)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n = int(input())\r\ntasks = [int(x) for x in input().split()]\r\n\r\n'''for i in range(n):\r\n total += tasks[i]'''\r\ntotal = sum(tasks)\r\n\r\nequator = int(total / 2) + 1 if total % 2 == 1 else total / 2\r\n\r\ntemp = 0\r\ni = 0\r\nwhile i < len(tasks):\r\n temp += tasks[i]\r\n if temp >= equator:\r\n break\r\n i += 1\r\n\r\n\r\n\r\n\r\nprint(i + 1)\r\n\r\n'''for i in range(n):\r\n temp += total\r\n if temp >= equator:\r\n break\r\ni = 0\r\nif i < n:\r\n print(i + 1)\r\nelse:\r\n print(\"not working\")'''\r\n",
"# ===================================\r\n# (c) MidAndFeed aka ASilentVoice\r\n# ===================================\r\n# import math \r\n# import collections\r\n# ===================================\r\nn = int(input())\r\nq = [int(x) for x in input().split()]\r\ns = sum(q)\r\nit = 0\r\nfor i in range(n):\r\n\tx = q[i]\r\n\tit += x\r\n\tif it*2 >= s:\r\n\t\tprint(i+1)\r\n\t\tbreak\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)/2\r\nss=0\r\nfor i in range(n):\r\n ss+=a[i]\r\n if(ss>=s):\r\n print(i+1)\r\n break\r\n",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\n \r\nal=sum(a)\r\nnum=0\r\nfor i in range(n):\r\n num+=a[i]\r\n if num*2>=al:\r\n print(i+1)\r\n break",
"n = int(input())\r\na = input()\r\na = a.split()\r\nsum = 0\r\nfor i in a:\r\n sum += int(i)\r\nhalfsum = 0\r\nfor i in range(0, n):\r\n halfsum += int(a[i])\r\n if halfsum >= (sum/2):\r\n print(i + 1)\r\n break",
"n = int(input())\na = input().split(' ')\nsum = 0\nfor i in a:\n sum += int(i)\nnum = 0\nj = 0\nfor i in a:\n j += 1\n num += int(i)\n if num >= sum/2:\n break\nprint(int(j))\n",
"from sys import stdin\r\n\r\nn = int(stdin.readline())\r\n\r\na = [int(x) for x in input().split(' ')]\r\n\r\nt = []\r\np = 0\r\n\r\nfor i in range(len(a)):\r\n p += a[i]\r\n t.append(p)\r\n\r\nfor i in range(len(t)):\r\n if t[i] >= t[-1]/2:\r\n print(i+1)\r\n break\r\n\r\n\r\n \r\n",
"x=int(input())\ny=list(map(int,input().split()))\nsumm=sum(y)\ncurrent=0\nfor i in range(x):\n current=current+y[i]\n if current >= summ/2 :\n \n print(i+1)\n break\n\n",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\ns = (sum(a)+1)//2 ; cur=0\r\nfor i in range(n):\r\n cur+=a[i]\r\n if cur>=s:\r\n print(i+1)\r\n exit(0)\r\n\r\n \r\n \r\n ",
"# from scipy.misc import imread, imsave, imresize\r\n# import numpy as np\r\n# import matplotlib.pyplot as plt\r\n\r\nDay = int(input())\r\na = input()\r\nalist = a.split(' ')\r\nalist = [int(alist[i]) for i in range(Day)]\r\nS = sum(alist)\r\nt = 0\r\nfor i in range(Day):\r\n t += alist[i]\r\n if t >= S / 2:\r\n break\r\nprint(i + 1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n# inpath = 'C:\\\\Users\\\\17824\\\\Pictures\\\\puppy.jpg'\r\n# I = imread(inpath)\r\n# print(I.shape)\r\n# plt.figure(1)\r\n# plt.imshow(I)\r\n#\r\n# x = np.arange(0, 3 * np.pi, 0.1)\r\n# y1 = np.sin(x)\r\n# y2 = np.cos(x)\r\n#\r\n# plt.figure(2)\r\n# plt.plot(x, y1)\r\n# plt.plot(x, y2)\r\n# plt.xlabel('x axis')\r\n# plt.ylabel('y axis')\r\n# plt.title('sin and cos')\r\n# plt.legend(['sin', 'cos'])\r\n# plt.show()\r\n\r\n\r\n# x = ['say', 'hello', 'world']\r\n# for ind, i in enumerate(x):\r\n# print(ind, i)\r\n# d = {'s': 'say', 'h': 'hello', 'w': 'world'}\r\n# for ind, i in d.items():\r\n# print(ind, i)\r\n# s = {'say', 'hello', 'world'}\r\n# print(len(s))\r\n#\r\n#\r\n# class Greet(object):\r\n# def __init__(self, name):\r\n# self.name = name\r\n#\r\n# def greet(self, loud=False):\r\n# if loud:\r\n# print('hello %s' % self.name.upper())\r\n# else:\r\n# print('hello %s' % self.name)\r\n#\r\n# g = Greet('Ming')\r\n# g.greet()\r\n# g.greet(loud=True)\r\n",
"n = int(input())\na = [int(x) for x in input().split()]\nt = sum(a)\ns = 0\nfor i, c in enumerate(a):\n s += c\n if 2*s >= t:\n print(i+1)\n break\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\nk=sum(a)\r\n\r\nif k%2:\r\n k=k//2+1\r\nelse:\r\n k//=2\r\n\r\ncnt=0\r\nfor i in range(n):\r\n cnt+=a[i]\r\n if cnt>=k:\r\n print(i+1)\r\n exit(0)\r\n",
"import math\r\n\r\nn= int(input())\r\narr = [int(x) for x in input().split()]\r\n\r\ns = 0;\r\nd = 0;\r\nfor i in range(0,n):\r\n\ts = s + arr[i]\r\n\r\nfor i in range(0,n):\r\n\td = d+arr[i]\r\n\tif d>=s/2:\r\n\t\tprint(i+1)\r\n\t\tbreak",
"n = int(input())\r\na = list(map(int,input().split()))\r\nSum = sum(a)\r\nans,j = 0,1\r\n#print(a,Sum,ans,j)\r\nfor i in a:\r\n ans = ans+i\r\n if ans*2 >= Sum:\r\n print(j)\r\n break\r\n j+=1;\r\n\r\n",
"n=int(input())\r\na=list(map(int,input().split()))\r\n\r\nc=0\r\ns=0\r\nt=sum(a)\r\nif t%2==0:\r\n t=t//2\r\nelse:\r\n t=t//2\r\n t+=1\r\n\r\nfor i in range(len(a)):\r\n s+=a[i]\r\n c+=1\r\n if s>=(t):\r\n break\r\nprint(c)\r\n",
"n = int(input())\r\na = str(input()).split()\r\nb = 0\r\nc = 0\r\nf = 0\r\ncnt = 0\r\nj = 0\r\n\r\n\r\nfor i in range(n):\r\n b += int(a[i])\r\n\r\n\r\nif b % 2 != 0:\r\n f = 1\r\n\r\n\r\nwhile c < b // 2 + f:\r\n c += int(a[j])\r\n j += 1\r\n cnt += 1\r\n\r\n\r\nprint(cnt)\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\neq = sum(a)/2\r\n\r\nsum = 0\r\nfor index in range(n):\r\n sum += a[index]\r\n if sum >= eq:\r\n print(index+1)\r\n break\r\n",
"n = int(input())\n\nnumber_sequence = [int(x) for x in input().split(\" \")]\nnumber_total = sum(number_sequence)\n\ncurrent_total = 0\ncurrent_position = 0\n\nfor number in number_sequence:\n current_total = current_total + number\n current_position = current_position + 1\n if(current_total >= number_total/2):\n print(current_position)\n break\n",
"n=int(input())\r\narr=list(map(int,input().split()))\r\ns=0\r\nss=sum(arr)\r\nfor i in range(n):\r\n s+=arr[i]\r\n if s>=ss/2:\r\n print(i+1)\r\n break",
"n=int(input())\r\na=list(map(int,input().split()))\r\nb=sum(a)\r\ncnt=0\r\nfor i in range(n):\r\n cnt+=a[i]\r\n if(cnt>=b/2):\r\n print(i+1)\r\n break",
"n = int(input())\na = list(map(int, input().split()))\nsum = 0\nsum2 = 0\nfor i in range(n):\n\tsum += a[i];\nfor i in range(n):\n\tsum2 += a[i]\n\tif sum2*2 >= sum:\n\t\tprint(i+1)\n\t\tbreak",
"n = int(input())\r\narr = [float(arr) for arr in input().split()]\r\nequator = sum(arr)/2\r\nptr = 0.0\r\nsumx = 0.0\r\nfor i in range (n):\r\n sumx+=arr[i]\r\n ptr+=1\r\n if(sumx>=equator):\r\n print(int(ptr))\r\n break",
"n=int(input())\r\na=list(map(int,input().split()))\r\nsum1=sum(a)/2\r\nsum2=0\r\nfor i in range(len(a)):\r\n sum2+=a[i]\r\n if sum2>=sum1:\r\n print(i+1)\r\n break;",
"from itertools import accumulate\nfrom bisect import bisect_left\nimport math\n\nn = int(input())\na = list(map(int, input().split()))\n\nd = list(accumulate(a))\nh = math.ceil(sum(a) / 2.0)\ni = bisect_left(d, h)\nprint(i + 1)\n",
"a = [0] * int(input())\r\nsum = 0\r\na = list(map(int, input().split()))\r\nfor i in range(len(a)):\r\n\tsum += a[i]\r\nsum = sum / 2\r\nk = 0\r\nq = 0\r\ni = 0\r\n\r\nwhile (k < sum):\r\n\tk += a[i]\r\n\ti += 1\r\n\r\nprint(i)\r\n\r\n# i k\r\n# 0 0\r\n# 1 2 \r\n# 2 4\r\n# 3 6\r\n#",
"n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\ns = sum(a)\r\nt=0;\r\n\r\nfor i in range(n):\r\n\tif t+a[i] >= (s+1)//2:\r\n\t\tprint(i+1)\r\n\t\texit(0)\r\n\telse:\r\n\t\tt += a[i]",
"import math\r\n#from decimal import *\r\n#from collections import deque\r\n \r\ndef transformare_baza(numar,baza):\r\n \r\n transformare=\"\"\r\n while numar>=baza:\r\n rest=numar%baza\r\n numar=numar//bazami\r\n transformare+=str(rest)\r\n \r\n transformare+=str(numar)\r\n noua_baza=transformare[::-1]\r\n return noua_baza\r\n \r\n \r\ndef produs_cifre(numar):\r\n \r\n produs=1\r\n for i in numar:\r\n produs=produs*int(i)\r\n return (produs)\r\n \r\ndef prime_generator(nr_elemente_prime):\r\n \r\n #print(\"pornire\")\r\n vector_prime=[-1]*nr_elemente_prime\r\n vector_rasp=[0]*nr_elemente_prime\r\n \r\n vector_prime[1]=1\r\n \r\n vector_rasp[1]=1\r\n#primes sieve \r\n contor=2\r\n \r\n for i in range(2,nr_elemente_prime):\r\n if vector_prime[i]==-1:\r\n vector_prime[i]=1\r\n vector_rasp[contor]=i\r\n contor=contor+1\r\n for j in range(i+i,nr_elemente_prime,i):\r\n if vector_prime[j]==-1:\r\n vector_prime[j]=i\r\n #print(i,j) \r\n \r\n my_set=set(vector_rasp)\r\n my_set.remove(0)\r\n my_set.remove(1)\r\n \r\n lista_prime=list(my_set)\r\n lista_prime.sort()\r\n return lista_prime\r\n \r\n \r\ndef bitwise_xor(a,b):\r\n stringul_1=transformare_baza(a,2)\r\n stringul_2=transformare_baza(b,2)\r\n \r\n lungime=max(len(stringul_1), len(stringul_2))\r\n raspunsul=0\r\n #print(stringul_1,stringul_2)\r\n \r\n str_answ=[0]*lungime\r\n# print('lungime=', lungime)\r\n \r\n #print(str_answ)\r\n \r\n for i in range(0,lungime):\r\n # print(i,str_answ)\r\n j=lungime-1-i\r\n if len(stringul_1)>i and len(stringul_2)>i:\r\n if stringul_1[len(stringul_1)-1-i]!= stringul_2[len(stringul_2)-1-i]:\r\n raspunsul+=2**(i)\r\n str_answ[i]='1'\r\n elif len(stringul_1)>i and stringul_1[len(stringul_1)-1-i]=='1':\r\n raspunsul+=2**(i)\r\n str_answ[i]='1'\r\n elif len(stringul_2)>i and stringul_2[len(stringul_2)-1-i]=='1':\r\n raspunsul+=2**(i)\r\n str_answ[i]='1'\r\n \r\n #print(str_answ)\r\n \r\n return raspunsul\r\n \r\n \r\ndef bitwise_and(a,b):\r\n stringul_1=transformare_baza(a,2)\r\n stringul_2=transformare_baza(b,2)\r\n \r\n lungime=max(len(stringul_1), len(stringul_2))\r\n raspunsul=0\r\n #print(stringul_1,stringul_2)\r\n \r\n str_answ=[0]*lungime\r\n# print('lungime=', lungime)\r\n \r\n #print(str_answ)\r\n \r\n for i in range(0,lungime):\r\n # print(i,str_answ)\r\n j=lungime-1-i\r\n if len(stringul_1)>i and len(stringul_2)>i:\r\n if stringul_1[len(stringul_1)-1-i]=='1' and stringul_2[len(stringul_2)-1-i]=='1':\r\n raspunsul+=2**(i)\r\n str_answ[i]='1'\r\n else:\r\n str_answ[i]='0'\r\n \r\n #print(str_answ)\r\n \r\n return raspunsul\r\n \r\n \r\n \r\n#z=int(input())\r\nfor contor in range(0,1):\r\n \r\n# n,m=list(map(int,input().split()))\r\n n=int(input())\r\n \r\n lista=list(map(int,input().split()))\r\n half=sum(lista)/2\r\n \r\n suma=0\r\n for i in range(0,n):\r\n suma+=lista[i]\r\n if suma>=half:\r\n print(i+1)\r\n \r\n break\r\n",
"n = int(input())\ns = [int(x) for x in input().split()]\nsumma = sum(s)\nq = 0\nfor i in range(n):\n q += s[i]\n if q * 2 >= summa:\n print(i + 1)\n exit()\n",
"n = int(input())\r\nps = [int(x) for x in (input().split())]\r\ntop = sum(ps)/2\r\ncount = 0\r\nfor i,x in enumerate(ps):\r\n count+=x\r\n if(count >= top):\r\n print(i+1)\r\n break\r\n else:\r\n continue\r\n",
"n = int(input()); r = [int(y) for y in input().split()]; t = f = m = 0\r\nfor z in r:\r\n m += z\r\nwhile 2 * f < m:\r\n f += r.pop(0); t += 1\r\nelse:\r\n print(t)",
"#http://codeforces.com/problemset/problem/962/A\r\nimport math\r\nn=int(input())\r\nList=list(map(int,input().split()))\r\ns=math.ceil(sum(List)/2)\r\nd=1\r\nk=List[0]\r\nwhile (k<s):\r\n k+=List[d]\r\n d+=1\r\nprint (d)\r\n",
"n = int(input())\r\na = [float(i) for i in input().split(' ')]\r\n\r\nthreshold = sum(a) / 2\r\ntemp = 0\r\n\r\nfor i in range(n):\r\n\ttemp += a[i]\r\n\tif temp >= threshold:\r\n\t\tprint(i + 1)\r\n\t\tbreak\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\n\r\nhalfTotal = sum(arr) / 2\r\n\r\nans = 0\r\nfor i in range(n):\r\n ans += arr[i]\r\n if ans >= halfTotal:\r\n print(i+1)\r\n break\r\n",
"n = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\nk = s/2\r\nss=0\r\nans=-1\r\nfor i in range(n):\r\n\tss+=a[i]\r\n\tif ss>=k:\r\n\t\tans=i+1\r\n\t\tbreak\r\nprint(ans)\r\n\t",
"n=int(input())\r\na=[int(x) for x in input().split()]\r\ns=sum(a)/2\r\nc=0\r\nfor i in range(n):\r\n c+=a[i]\r\n if c>=s:\r\n print(i+1)\r\n break",
"n=int(input())\r\narray = list(map(int, input().rstrip().split()))\r\ns=0\r\nfor item in array:\r\n s+=item\r\nminm=0\r\nif s%2==0:\r\n minm=s//2\r\nelse:\r\n minm=(s//2)+1\r\ns2=0\r\nfor i in range(n):\r\n s2+=array[i]\r\n if s2>=minm:\r\n print(i+1)\r\n break",
"n = int(input())\r\narr = [int(a) for a in input().strip().split(' ')]\r\ns = sum(arr)\r\nhalf = s / 2\r\no = 0\r\nfor i in range(1,n+1):\r\n o += arr[i-1]\r\n if o >= half:\r\n print(i)\r\n break\r\n",
"l = []\r\nn = int(input())\r\nl = input().split()\r\nfor i in range(len(l)):\r\n l[i] = int(l[i])\r\n\r\ns = sum(l)/2\r\ncurVal = 0\r\nfor i in range(n):\r\n curVal += l[i]\r\n if curVal >= s:\r\n print(i + 1)\r\n break\r\n\r\n",
"n = int(input())\r\narr = list(map(int,input().split()))\r\npre = []\r\nfor i in range(n):\r\n if i==0:\r\n pre.append(arr[i])\r\n continue\r\n pre.append(pre[-1]+arr[i])\r\nans = 0\r\ns = (sum(arr)+1)//2\r\nfor i in range(n):\r\n if pre[i]>=s:\r\n print(i+1)\r\n break\r\n \r\n ",
"input()\r\na = input().split(' ')\r\nsum = 0\r\nfor i in range(len(a)):\r\n a[i] = int(a[i])\r\n sum += a[i]\r\neq_val = sum / 2\r\ntot_probs_solved = 0\r\ni = 0\r\nwhile eq_val > tot_probs_solved:\r\n tot_probs_solved += a[i]\r\n i += 1\r\nprint(i)\r\n\r\n",
"'''\n Educational Codeforces Round 42\n Problem A\n \"Equator\"\n Solution: Jakub Ziółkowski ([email protected])\n'''\n\ndays = int(input())\nproblems = input().split(\" \")\ngeneral_sum = 0\nactual_sum = 0\nfor i in range (0, days):\n general_sum += int(problems[i])\n\nfor i in range (0, days):\n actual_sum += int(problems[i])\n if(actual_sum >= general_sum / 2):\n print(i+1)\n break",
"kac_gun = int(input())\r\ndizi = input().split()\r\ntoplam, toplam2 = 0, 0\r\nfor i in range(kac_gun):\r\n toplam += int(dizi[i])\r\n\r\n\r\nfor a in range(kac_gun + 1):\r\n if toplam / 2 <= toplam2:\r\n print(a)\r\n break\r\n toplam2 += int(dizi[a])\r\n\r\n\r\n\r\n",
"#http://codeforces.com/problemset/problem/962/A\r\ndef main():\r\n input()\r\n tusks=list(map(int,input().split()))\r\n tusk_resheno=0\r\n equator=sum(tusks)/2\r\n for i in range(len(tusks)):\r\n tusk_resheno+=tusks[i]\r\n if tusk_resheno>=equator:\r\n print(i+1)\r\n break\r\n\r\n\r\n\r\n\r\nif __name__==\"__main__\":\r\n main()\r\n",
"suml = 0\r\nsm = 0\r\n\r\nn= int(input())\r\na=list(map(int,input().split()))\r\nfor j in a:\r\n suml= suml + j\r\nsuml=(suml/2)\r\nday=0\r\nfor m in a:\r\n sm=sm+m\r\n if(sm>=suml):\r\n day=day+1\r\n break\r\n else:\r\n day=day+1\r\n \r\nprint(day)\r\n",
"n = int(input())\r\nl = list(map(int, input().split()))\r\ns = 0\r\nfor i in range(n):\r\n l[i] += s\r\n s = l[i]\r\ng = l[-1] / 2\r\nfor i in range(n):\r\n if l[i] >= g:\r\n print(i + 1)\r\n break\r\n",
"n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\ntot = sum(arr)\r\ncur = 0\r\n\r\nfor x in range(n):\r\n cur = cur + arr[x]\r\n if cur >= tot/2:\r\n print(x+1)\r\n break",
"from math import ceil\nimport sys\nn = int(sys.stdin.readline().strip())\narr = list(map(int, sys.stdin.readline().strip().split()))\ntotal = sum(arr)\ncurrSum = 0\nfor i in range(len(arr)):\n\tcurrSum += arr[i]\n\tif 2*currSum >= total:\n\t\tans = i+1\n\t\tbreak\nprint(ans)",
"n=int(input())\r\nli=list(map(int,input().split()))\r\nx=sum(li)\r\ncur=0\r\nfor i in range(n):\r\n cur+=li[i]\r\n if cur>=x/2:\r\n print(i+1)\r\n break\r\n",
"\r\ndef get_input():\r\n n=input()\r\n aArrayStr=input()\r\n aArray=aArrayStr.split(\" \")\r\n return (int(n), aArray)\r\n\r\nif __name__ == '__main__':\r\n (n, aArray) = get_input()\r\n count = 0\r\n for i in range(n):\r\n numOfProblemsSolvedToday=int(aArray[i])\r\n count=count+numOfProblemsSolvedToday\r\n halfWayMark = count / 2\r\n count = 0\r\n position = -1\r\n for i in range(n):\r\n numOfProblemsSolvedToday=int(aArray[i])\r\n count=count+numOfProblemsSolvedToday\r\n if count >= halfWayMark:\r\n position = (i + 1)\r\n break\r\n\r\n print (str(position))\r\n",
"def upper_bound_binary_search(arr, x):\r\n l, r = 0, len(arr) - 1\r\n while l <= r:\r\n mid = (l + r) // 2\r\n if arr[mid] >= x:\r\n r = mid - 1\r\n else:\r\n l = mid + 1\r\n return l\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n presum_arr = []\r\n for i in range(n):\r\n if i == 0:\r\n presum_arr.append(arr[i])\r\n else:\r\n presum_arr.append(presum_arr[i - 1] + arr[i])\r\n\r\n n_half = (presum_arr[-1] + 1) // 2\r\n l = upper_bound_binary_search(presum_arr, n_half)\r\n print(l + 1)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n=int(input())\r\n\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\nt=0\r\nfor i in range(n):\r\n t+=a[i]\r\n if(t>=s/2):\r\n print(i+1)\r\n exit()\r\n",
"'''input\r\n6\r\n2 2 2 2 2 2\r\n'''\r\nn = int(input())\r\nl = [int(i) for i in input().split(\" \")]\r\ns = sum(l)\r\nre = s // 2 + s % 2\r\nss = 0\r\nfor i in range(n):\r\n\tss += l[i]\r\n\tif ss >= re:\r\n\t\tprint(i + 1)\r\n\t\tbreak\r\n",
"T=int(input())\n\n\ndays = list(map(int, input().strip().split()))[:T]\nsum=0\nfinished=0\nfor j in range(T):\n sum+=days[j]\nfor i in range(T):\n finished+=days[i]\n if finished>=(sum-finished):\n print(i+1)\n break\n \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t \t\t\t \t",
"from collections import Counter\r\nfrom itertools import combinations\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n a = [int(i) for i in input().split()]\r\n s = sum(a)\r\n t = s\r\n\r\n while n > 0 and t > (s / 2):\r\n t -= a[n - 1]\r\n n -= 1\r\n print(n + 1 if t < s / 2 else n)",
"s = input()\r\nli = input().split(' ')\r\nli = list(map(int, li))\r\n\r\ntarget = (sum(li) + 1) // 2\r\n\r\ndone = False\r\n\r\nfront_sum = 0\r\n\r\nfor i in range(1, len(li)):\r\n front_sum += li[i - 1]\r\n if front_sum >= target:\r\n done = True\r\n print(i)\r\n break\r\n\r\nif not done:\r\n print(len(li))",
"n = int(input())\r\nl = list(map(int, input().split()))\r\ns = sum(l)\r\nm = 0\r\nif s % 2 == 0:\r\n m += s // 2\r\nelse:\r\n m += (s // 2) + 1\r\nt = 0\r\nfor i in range(n):\r\n t += l[i]\r\n if t >= m:\r\n print(i + 1)\r\n break",
"import math\n\nn = int(input())\ndays = list(map(int, input().split(\" \")))\ntotal = sum(days)\n\ns = 0\nfor i in range(len(days)):\n s += days[i]\n if s >= math.ceil(total / 2):\n print(i + 1)\n break\n\n",
"from itertools import accumulate\r\nfrom bisect import bisect_left\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n acc = [*accumulate(list(map(int, input().split())))]\r\n half = (1 + acc[len(acc) - 1]) // 2\r\n print(bisect_left(acc, half) + 1)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"if __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().split(' ')))\r\n\r\n s = 0\r\n for i in range(n):\r\n s += a[i]\r\n\r\n tmp = 0\r\n for i in range(n):\r\n tmp += a[i]\r\n if (tmp >= s / 2):\r\n print(i+1)\r\n break\r\n\r\n\r\n\r\n",
"n = int (input())\narr = [int (x) for x in input().split()]\nall = sum(arr)\n\ncur = 0\nans = -1\nfor i in range(n):\n cur += arr[i]\n if(2 * cur >= all):\n ans = i\n break\n\nprint(ans + 1)",
"import os\r\nimport sys\r\nimport math\r\n\r\ndef main():\r\n n = int(input())\r\n a = input().split()\r\n for i in range(n):\r\n a[i] = int(a[i])\r\n\r\n s = sum(a)\r\n \r\n ss = 0\r\n j = 0\r\n while ss < math.ceil(s / 2):\r\n ss += a[j]\r\n j += 1\r\n print(j)\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"n=int(input())\r\nli=list(map(int,input().split()))\r\ns=sum(li)\r\nif s%2:\r\n s=s//2+1\r\nelse:\r\n s//=2\r\ncount=0\r\nfor i in range(n):\r\n count+=li[i]\r\n if count>=s:\r\n print(i+1)\r\n exit(0)",
"\r\nfrom math import ceil\r\nn=int(input())\r\nthen= input().split()\r\ncount1=0\r\ncount2=0\r\ncount3=0\r\nli1= list(then)\r\n\r\nfor i in li1:\r\n count1+= int(i)\r\n \r\ncount1 = ceil(count1/2)\r\nfor i in li1:\r\n count3+=1\r\n count2+= int(i)\r\n if count2>=count1:\r\n break\r\n \r\nprint(count3)",
"n = int(input())\narr = list(map(int,input().split()))\nsum_arr = sum(arr)\ncurr = 0\nfor i in range(n):\n curr+=arr[i]\n if curr*2 >= sum_arr:\n print (i+1)\n break\n",
"from sys import stdin\r\n\r\n\r\ninput_number = int(stdin.readline())\r\n\r\narray = [int(x) for x in stdin.readline().split()]\r\n\r\n\r\ncalendar = dict()\r\ncurrent_sum = 0\r\n\r\nfor i in range(input_number):\r\n\r\n current_sum += array[i]\r\n\r\n calendar.setdefault(str(i+1), current_sum)\r\n\r\n\r\nfor k, v in calendar.items():\r\n\r\n if v*2 >= (current_sum + input_number - i - 1):\r\n\r\n print(k)\r\n\r\n break\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n=int(input())\na=list(map(int,input().split()))\ns=sum(a)/2\nk=0\ni=0\nwhile(k<s):\n\tk+=a[i]\n\ti+=1\nprint(i)",
"n = int(input())\r\npro = [int(i) for i in input().split()]\r\np = sum(pro)\r\ncur = 0\r\nfor i in range(n):\r\n cur += pro[i]\r\n if cur >= p/2:\r\n break\r\nprint (i+1)\r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nr=0;k=sum(l)/2\r\nfor i in range(n):\r\n r+=l[i]\r\n if r>=k:\r\n print(i+1)\r\n break",
"n = int(input())\r\nu = list(map(int, input().split()))\r\ns = sum(u)\r\nk = 0\r\ni = 0\r\nwhile k * 2 < s:\r\n k += u[i]\r\n i += 1\r\nprint(i)\r\n\r\n",
"n = int(input())\r\na = list(map(int,input().split()))\r\nk = 0\r\np = 0\r\ni = 0\r\nif sum(a) % 2 == 0:\r\n l = sum(a)// 2\r\nelse:\r\n l = sum(a) // 2 + 1\r\nwhile k < l and i < len(a):\r\n k += a[i]\r\n p += 1\r\n i += 1\r\nprint(p)",
"from math import ceil\n\nn = int(input())\n\na = list(map(int, input().split()))\n\nif n == 1:\n print(1)\n exit(0)\n\ntotal = sum(a)\n\ns = 0\nfor i in range(n):\n s += a[i]\n if s >= ceil(total / 2):\n print(i + 1)\n exit(0)\n",
"import math\r\nin_put = int(input(''))\r\n\r\nlist = []\r\n\r\nin_put1 = str(input(''))\r\nin_put1 = in_put1.split(' ')\r\nfor items in in_put1:\r\n list.insert(len(list),float(items))\r\n\r\nSum = 0.0\r\nfor items in list:\r\n Sum = items + Sum\r\n\r\nquater = math.ceil(Sum/2)\r\n\r\ncounter = 1\r\nsum = 0\r\n\r\nfor items in list:\r\n sum = items + sum\r\n if(quater<=sum):\r\n print(counter,end = '')\r\n break\r\n else:\r\n counter = counter+1",
"n=int(input())\r\na=list([int(x) for x in input().split()])\r\ns=sum(a)\r\ncheck=0\r\n#print(s/2)\r\nfor i in range(len(a)):\r\n check+=a[i]\r\n if(check>=(s/2)):\r\n print(i+1)\r\n break",
"n = int(input())\r\na = list(map(int, input().split()))\r\nsuma = sum(a)\r\nsuma1 = suma\r\n\r\ni = 1\r\nwhile suma - a[i-1] > suma1/2:\r\n suma -=a[i-1]\r\n i+=1\r\nprint(i)",
"n=int(input())\r\nll=list(map(int,input().split()))\r\nk=sum(ll)/2\r\nc=0\r\nfor i in range(n):\r\n c+=ll[i]\r\n if c>=k:\r\n print(i+1)\r\n exit()",
"def h(i): return (i >> 1) + (i & 1)\ninput()\na = [int(i) for i in input().split()]\nt, c = h(sum(a)), 0\nfor i, ai in enumerate(a):\n\tc += ai\n\tif c >= t:\n\t\tprint(i+1)\n\t\tbreak\n",
"# -*- coding: utf-8 -*-\n\n\n\ndef solve():\n n = int(input())\n a = list(map(int, input().split(' ')))\n\n sum = 0\n for i in range(n): sum += a[i]\n sum = (sum + 1) // 2\n\n cur = 0\n for i in range(n):\n cur += a[i]\n if (cur >= sum):\n print(i + 1)\n return\n\n \ndef main():\n t = 1\n # t = int(input())\n for i in range(t):\n solve()\n\nif __name__ == \"__main__\":\n main()\n\t \t \t \t\t\t\t \t\t \t \t \t \t\t\t",
"\r\ndef main():\r\n input()\r\n data=list(map(int,input().split()))\r\n data_r=0\r\n equator=sum(data)/2\r\n for i in range(len(data)):\r\n data_r+=data[i]\r\n if data_r>=equator:\r\n print(i+1)\r\n break\r\n\r\n\r\n\r\n\r\nif __name__==\"__main__\":\r\n main()",
"n = int(input())\na = list(map(int, input().split()))\nsum1 = sum(a)\nsum2 = 0\ni = 0\nwhile sum2 < (sum1 + 1) // 2:\n sum2 += a[i]\n i += 1\nprint(i)",
"from bisect import bisect_left\r\n\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nfor i in range(1, n):\r\n a[i] += a[i-1]\r\n\r\nif a[-1] % 2:\r\n mid = (a[-1]+1)//2\r\nelse:\r\n mid = a[-1]//2\r\n\r\nprint(bisect_left(a, mid)+1)\r\n",
"input()\r\nl = [int(i) for i in input().split()]\r\nk = sum(l)\r\ns = 0\r\ni = 0\r\nwhile s < k/2:\r\n\ts+=l[i]\r\n\ti+=1\r\nprint(i)\r\n",
"n=int(input());\r\na=list(map(int,input().split()));\r\ns=sum(a);\r\nans=0;\r\ntmp=0;\r\nwhile tmp<s/2:\r\n tmp+=a[ans];\r\n ans+=1;\r\nprint(ans)",
"mod = 1000000007\r\nii = lambda : int(input())\r\nsi = lambda : input()\r\ndgl = lambda : list(map(int, input()))\r\nf = lambda : map(int, input().split())\r\nil = lambda : list(map(int, input().split()))\r\nls = lambda : list(input())\r\nn=ii()\r\nl=il()\r\nsm=sum(l)\r\nx=0\r\nfor i in range(n):\r\n if x+l[i]>=(sm+1)//2:\r\n exit(print(i+1))\r\n x+=l[i]",
"n=int(input())\r\narr=[]\r\nf=0\r\ng=0\r\narr=list(map(int,input().split()))\r\n\r\nfor i in range(len(arr)):\r\n\tf=f+arr[i]\r\n\r\n\r\nfor i in range(len(arr)):\r\n\tg=g+arr[i]\r\n\tif g >= f/2:\r\n\t\tprint(i+1)\r\n\t\tbreak\r\n",
"def binsearch(nums, target):\r\n left = 0\r\n right = len(nums) - 1\r\n while left <= right:\r\n mid = (left + right) // 2\r\n if nums[mid] == target:\r\n return mid\r\n elif nums[mid] > target:\r\n right = mid - 1\r\n elif nums[mid] < target:\r\n left = mid + 1\r\n\r\n return left\r\n\r\n\r\nn = int(input())\r\n\r\ndays = [int(i) for i in input().split()]\r\n\r\nprefsums = [days[0]]\r\n\r\nfor i in range(1, n):\r\n prefsums.append(days[i] + prefsums[i - 1])\r\n\r\ns = sum(days)\r\n\r\npl = binsearch(prefsums, (s/2) - .1)\r\n\r\n#print(prefsums, s)\r\n\r\nprint(pl+1)\r\n\r\n",
"from math import *\nq = int(input())\nw = list(map(int, input().split()))\nd = sum(w)\ni = 0\nfor j in range(q):\n i += w[j]\n if i >= ceil(d / 2):\n break\nprint(j + 1)\n",
"import sys\r\nimport math\r\n#import random\r\nsys.setrecursionlimit(100000)\r\ninput = sys.stdin.readline\r\n \r\n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inara():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n################################################################\r\n############ ---- THE ACTUAL CODE STARTS BELOW ---- ############\r\n\r\nn=inp()\r\nara=inara()\r\n\r\ntot=0\r\nfor num in ara:\r\n\ttot+=num\r\n\r\nnow=0\r\nfor i in range(n):\r\n\tnow+=ara[i]\r\n\tif now>=(tot+1)//2:\r\n\t\tprint(i+1)\r\n\t\texit(0)\r\n\t\r\n\t\t\t\r\n\t\t\t\r\n\t\t\t\r\n",
"n=int(input())\r\ni=0\r\nx=[int(i)for i in input().split()]\r\nSum=sum(x)\r\nnew_sum=0\r\nwhile i<n:\r\n new_sum+=x[i]\r\n if new_sum >=Sum/2:\r\n print(i+1)\r\n break\r\n i+=1 ",
"n = int(input())\r\nar = list(map(int, input().split()))\r\nfor i in range(1,n):\r\n ar[i] += ar[i-1]\r\n\r\nmid = ar[n-1]/2\r\n\r\nfor i in range(n):\r\n if ar[i] >= mid:\r\n print(i+1)\r\n break\r\n",
"n = int(input())\r\nList_problems = [int(List_problems) for List_problems in input().split()]\r\nSum = sum(List_problems)\r\nequator = int((Sum / 2) + (Sum % 2))\r\ncount = 0\r\nfor i in range(len(List_problems)):\r\n if count < equator:\r\n count += List_problems[i]\r\n if count >= equator:\r\n print(i+1)\r\n break\r\n",
"class CodeforcesTask962ASolution:\r\n def __init__(self):\r\n self.result = ''\r\n self.n = 0\r\n self.tasks = []\r\n\r\n def read_input(self):\r\n self.n = int(input())\r\n self.tasks = [int(x) for x in input().split(\" \")]\r\n\r\n def process_task(self):\r\n tasks = sum(self.tasks)\r\n eq = tasks // 2 + tasks % 2\r\n s = 0\r\n for x in range(self.n):\r\n s += self.tasks[x]\r\n if s >= eq:\r\n self.result = str(x + 1)\r\n break\r\n\r\n def get_result(self):\r\n return self.result\r\n\r\n\r\nif __name__ == \"__main__\":\r\n Solution = CodeforcesTask962ASolution()\r\n Solution.read_input()\r\n Solution.process_task()\r\n print(Solution.get_result())\r\n",
"\r\n\r\n\r\n\r\nn = int(input())\r\n\r\nt = list(map(int,input().split()))\r\n\r\n\r\np = sum(t)\r\nimport math\r\n\r\na = math.ceil(p/2)\r\n\r\nu=0\r\nfor j in range(n):\r\n u+=t[j]\r\n if u>=a:\r\n print(j+1)\r\n break\r\n \r\n",
"import sys\r\n\r\nn = int(input())\r\nproblems = list(map(int, sys.stdin.readline().strip().split(' ')))\r\nhalf = sum(problems)/2\r\n\r\nsum = 0\r\nfor i in range(len(problems)):\r\n sum += problems[i]\r\n if sum>=half:\r\n print(i+1)\r\n break",
"n=int(input())\r\na=[int(i) for i in input().split()]\r\nd=sum(a)\r\nsum=0\r\nc=0\r\nfor i in range(0,len(a)):\r\n sum=sum+a[i]\r\n c=c+1\r\n if(sum>=d//2 and d%2==0):\r\n break\r\n elif(sum>=(d//2)+1 and d%2!=0):\r\n break\r\nprint(c)",
"n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\nif(s%2==0):\r\n s=int(s/2)\r\nelse:\r\n s=int((s+1)/2)\r\nm=0\r\nfor i in range(0,n):\r\n m+=a[i]\r\n if(m>=s):\r\n print(i+1)\r\n break\r\n ",
"days=int(input())\r\nl=list(map(int,input().split()))\r\nb=sum(l)\r\nsum=0\r\nflag=0\r\nfor i in range(0,len(l)):\r\n sum=sum+l[i]\r\n flag+=1\r\n if(sum>=b/2):\r\n print(flag)\r\n break\r\n\r\n \r\n \r\n",
"n=int(input())\r\nl=list(map(int,input().split()))\r\nm=sum(l)\r\ns=0\r\ni=0\r\nwhile s<m/2:\r\n s+=l[i]\r\n i+=1\r\n \r\nprint(i)\r\n",
"n = int(input())\r\nsum = 0\r\narray = [0]*n\r\n\r\n_input = input()\r\n\r\nnums = _input.split(\" \")\r\n\r\nfor i in range(n):\r\n array[i] = int(nums[i])\r\n sum += array[i]\r\n\r\nday = 0\r\n\r\nnewSum = 0\r\nfor i in range(n):\r\n newSum += array[i]\r\n if(sum/newSum)<= 2:\r\n day = i+1\r\n break\r\n\r\nprint(day)\r\n\r\n",
"n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\ns = sum(a)\r\n\r\nif s % 2:\r\n s = (s+1)//2\r\nelse:\r\n s //= 2\r\nc = 0\r\nfor i, v in enumerate(a):\r\n if c + v >= s:\r\n print(i+1)\r\n break\r\n else:\r\n c += v\r\n",
"import math\nN,l,c = int(input()),[int(i) for i in input().split(\" \")],0\nfor i in range(1,N):\n l[i] = l[i-1] + l[i]\nfor i in range(N):\n if l[i] >= math.ceil(l[N-1] / 2):\n c = c + 1\n break\n c = c + 1\nprint(c)\n",
"x = input()\ny = input()\nm = y.split()\ntotal = 0\nsum = 0\nindex = 0\nfor i in m:\n\ttotal += int(i)\nfor i in m:\n\tindex +=1\n\tsum += int(i)\n\tif(sum >= (total/2)):\n\t\tprint(index)\n\t\tbreak\n\t\n",
"N = int(input())\r\nA = input().split()\r\nfor i in range(N):\r\n A[i] = int(A[i])\r\n \r\neq = 0\r\nAsums = []\r\nvari = 0\r\nfor i in range(N):\r\n Asums.append(A[i] + vari)\r\n vari += A[i]\r\nfor i in range(N):\r\n if Asums[i] >= Asums[N - 1] * 0.5:\r\n eq = i + 1\r\n break\r\n \r\nprint(eq)",
"n=input()\r\ns=list(map(int,input().split()))\r\np=sum(s)/2\r\nfor (a,b) in enumerate(s):\r\n p-=b\r\n if (p<=0):\r\n print(a+1)\r\n break\r\n",
"import math\n\ninput()\nall_days_problems = list(map(int, input().split()))\nsum_count = sum(all_days_problems)\nhalf_problems = math.ceil(sum_count/2)\ncurrent_sum = 0\nanswer = 0\nfor num in all_days_problems:\n answer += 1\n current_sum +=num\n if current_sum >=half_problems:\n break\n\nprint(answer)\n \t \t \t \t \t\t\t\t\t\t\t\t \t \t\t \t \t",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ns = sum(a)\r\nx = 0\r\nfor i in range(n):\r\n x += a[i]\r\n if 2 * x >= s:\r\n ans = i + 1\r\n break\r\nprint(ans)"
] | {"inputs": ["4\n1 3 2 1", "6\n2 2 2 2 2 2", "1\n10000", "3\n2 1 1", "2\n1 3", "4\n2 1 1 3", "3\n1 1 3", "3\n1 1 1", "2\n1 2", "3\n2 1 2", "5\n1 2 4 3 5", "5\n2 2 2 4 3", "4\n1 2 3 1", "6\n7 3 10 7 3 11", "2\n3 4", "5\n1 1 1 1 1", "4\n1 3 2 3", "2\n2 3", "3\n32 10 23", "7\n1 1 1 1 1 1 1", "3\n1 2 4", "6\n3 3 3 2 4 4", "9\n1 1 1 1 1 1 1 1 1", "5\n1 3 3 1 1", "4\n1 1 1 2", "4\n1 2 1 3", "3\n2 2 1", "4\n2 3 3 3", "4\n3 2 3 3", "4\n2 1 1 1", "3\n2 1 4", "2\n6 7", "4\n3 3 4 3", "4\n1 1 2 5", "4\n1 8 7 3", "6\n2 2 2 2 2 3", "3\n2 2 5", "4\n1 1 2 1", "5\n1 1 2 2 3", "5\n9 5 3 4 8", "3\n3 3 1", "4\n1 2 2 2", "3\n1 3 5", "4\n1 1 3 6", "6\n1 2 1 1 1 1", "3\n3 1 3", "5\n3 4 5 1 2", "11\n1 1 1 1 1 1 1 1 1 1 1", "5\n3 1 2 5 2", "4\n1 1 1 4", "4\n2 6 1 10", "4\n2 2 3 2", "4\n4 2 2 1", "6\n1 1 1 1 1 4", "3\n3 2 2", "6\n1 3 5 1 7 4", "5\n1 2 4 8 16", "5\n1 2 4 4 4", "6\n4 2 1 2 3 1", "4\n3 2 1 5", "1\n1", "3\n2 4 7", "5\n1 1 1 1 3", "3\n3 1 5", "4\n1 2 3 7", "3\n1 4 6", "4\n2 1 2 2", "2\n4 5", "5\n1 2 1 2 1", "3\n2 3 6", "6\n1 1 4 1 1 5", "5\n2 2 2 2 1", "2\n5 6", "4\n2 2 1 4", "5\n2 2 3 4 4", "4\n3 1 1 2", "5\n3 4 1 4 5", "4\n1 3 1 6", "5\n1 1 1 2 2", "4\n1 4 2 4", "10\n1 1 1 1 1 1 1 1 1 8", "4\n1 4 5 1", "5\n1 1 1 1 5", "4\n1 3 4 1", "4\n2 2 2 3", "4\n2 3 2 4", "5\n2 2 1 2 2", "3\n4 3 2", "3\n6 5 2", "69\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "6\n1 1 1 1 1 2", "5\n1 2 5 4 5", "2\n9 10", "3\n1 1 5", "4\n3 4 3 5", "4\n1 4 3 3", "4\n7 1 3 4", "3\n100 100 1", "4\n5 2 2 2"], "outputs": ["2", "3", "1", "1", "2", "3", "3", "2", "2", "2", "4", "4", "3", "4", "2", "3", "3", "2", "2", "4", "3", "4", "5", "3", "3", "3", "2", "3", "3", "2", "3", "2", "3", "4", "3", "4", "3", "3", "4", "3", "2", "3", "3", "4", "3", "2", "3", "6", "4", "4", "4", "3", "2", "5", "2", "5", "5", "4", "3", "3", "1", "3", "4", "3", "4", "3", "3", "2", "3", "3", "4", "3", "2", "3", "4", "2", "4", "4", "4", "3", "9", "3", "5", "3", "3", "3", "3", "2", "2", "35", "4", "4", "2", "3", "3", "3", "2", "2", "2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 255 | |
316f0e162d83207ee04cbb016580e7bf | Code obfuscation | Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol *a*, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with *b*, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.
You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.
In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters.
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
Sample Input
abacaba
jinotega
Sample Output
YES
NO
| [
"import string\n\nobf = [x for x in input()]\nobf = [x for i, x in enumerate(obf) if x not in obf[:i]]\nn = len(obf)\n\nletters = list(string.ascii_lowercase)\nletters = letters[:n]\n\nif obf == letters:\n\tprint('Yes')\nelse:\n\tprint('No')\n\n",
"alphabet = 'abcdefghijklmnopqrstuvwxyz'\r\nprogramm = input()\r\nfor i in programm:\r\n if i in alphabet and i != alphabet[0]:\r\n print('NO')\r\n exit(0)\r\n if i == alphabet[0]:\r\n if len(alphabet) > 1:\r\n alphabet = alphabet[1:]\r\n else:\r\n break\r\nprint('YES')",
"s = list(input())\r\nr = list(\"abcdefghijklmnopqrstuvwxyz\")\r\n\r\nif len(s) == 1:\r\n if s[0] == 'a':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n while len(s) > 0:\r\n if s[0] == r[0]:\r\n while r[0] in s:\r\n s.remove(r[0])\r\n r.remove(r[0])\r\n else:\r\n print(\"NO\")\r\n exit()\r\n\r\n print(\"YES\")",
"s = input()\r\nb = [False] * 26\r\nfor i in range(len(s)):\r\n c = ord(s[i]) - ord('a')\r\n b[c] = True\r\n if (c != 0 and b[c] and not b[c - 1]):\r\n print(\"NO\")\r\n exit()\r\nfor i in range(25):\r\n if b[i + 1] and not b[i]:\r\n print(\"NO\")\r\n exit()\r\n\r\nprint(\"YES\")",
"s = str(input())\r\nflag = True\r\nfor i in range(len(s)):\r\n if ord(s[i])==ord('a'):\r\n continue\r\n elif chr(ord(s[i])-1) not in s[:i]:\r\n flag = False\r\n break\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"x=[]\r\nfor i in input():\r\n\tif i not in x:x+=i,\r\nprint('YES' if x==[chr(97+i) for i in range(len(x))] else 'NO')",
"a=input()\r\nt=97\r\n\r\nd=1\r\nwhile(a!=\"\"):\r\n b=\"\"\r\n if(ord(a[0])==t):\r\n for i in a:\r\n if(ord(i)!=t):\r\n b=b+(i)\r\n else:\r\n d=0\r\n t+=1\r\n a=b\r\nif(d==1):print(\"YES\")\r\nelse:print(\"NO\")",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ns = list(input().rstrip())\r\nla = 96\r\nans = \"YES\"\r\nfor i in s:\r\n if i - la > 1:\r\n ans = \"NO\"\r\n break\r\n la = max(la, i)\r\nprint(ans)",
"kingu=input()\n\nst=sorted(set(kingu),key=kingu.index)\n\nfor got in range(len(st)):\n\n\n\n if st[got]!=chr(97+got):exit(print('NO'))\nprint('YES')\n \t \t\t \t \t \t\t\t \t\t\t \t \t \t\t",
"def code(s):\r\n count = 0\r\n for i in range(len(s)):\r\n if ord(s[i]) - ord('a') > count:\r\n return \"NO\"\r\n if ord(s[i]) - ord('a') == count:\r\n count += 1\r\n return \"YES\"\r\n\r\n\r\nprint(code(input()))\r\n",
"s=input()\r\nif s[0]==\"a\":\r\n arr=[0 for i in range(26)]\r\n arr[ord(\"z\")-97]+=1\r\n arr[ord(s[0])-97]+=1\r\n res=True\r\n for i in range(1,len(s)):\r\n if arr[ord(s[i])-98]>0:\r\n arr[ord(s[i])-97]+=1\r\n else:\r\n res=False\r\n break\r\n if res:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\") \r\nelse:\r\n print(\"NO\")",
"# 19:50\ns = input()\n\ndef main(s):\n\tobphLetters = []\n\tusedLetters = 'abcdefghijklmnopqrstuvwxyz'\n\tmaxLetterIndex = 0\n\tfor letter in s:\n\t\tnowIndex = usedLetters.index(letter)\n\t\tif nowIndex == maxLetterIndex and letter not in obphLetters:\n\t\t\tobphLetters.append(letter)\n\t\t\tmaxLetterIndex += 1\n\t\telif nowIndex > maxLetterIndex:\n\t\t\treturn 'NO'\n\treturn 'YES'\n\nprint(main(s))",
"a = input()\r\ns = ''\r\nst = set()\r\nfor i in a:\r\n if i not in st:\r\n st.add(i)\r\n s += i\r\nalph = 'abcdefghijklmnopqrstuvwxyz'\r\nif s == alph[:len(s)]:\r\n print('YES')\r\nelse:\r\n print('NO')",
"s = input(); tmp = 'a'\r\nfor i in s:\r\n if i > tmp:\r\n print('NO'); exit()\r\n if i == tmp: tmp = chr(ord(tmp)+1)\r\nprint('YES')\r\n \r\n",
"#!/bin/python3\r\n\r\nimport sys\r\ns = input()\r\ncur = ord('a')\r\nfor ch in s:\r\n if cur < ord(ch):\r\n print(\"NO\");\r\n sys.exit()\r\n elif cur == ord(ch):\r\n cur+=1\r\nprint(\"YES\")",
"s = input()\na = [0] * 26\nl = []\nfor c in s:\n if c not in l:\n l.append(c)\n a[ord(c) - ord('a')] += 1\n\ncnt = 0\nfor n in a:\n if n == 0:\n break\n cnt += n\n\nif l == sorted(l) and cnt == len(s):\n print('YES')\nelse:\n print('NO')\n",
"def manners(s):\r\n if s[0] != 'a':\r\n return 'NO'\r\n b = 97\r\n for i in range(1, len(s)):\r\n if b < ord(s[i-1]):\r\n b = ord(s[i-1])\r\n if ord(s[i]) - b > 1:\r\n return 'NO'\r\n return 'YES'\r\n\r\nprint(manners(input()))",
"l=[chr(i) for i in range(97,123)]\r\ns=input()\r\nfrom collections import Counter\r\nd=Counter()\r\nm=[]\r\nf=1\r\nfor i in s:\r\n for j in range(97,ord(i)):\r\n if chr(j) not in m:\r\n f=0\r\n break\r\n # print(i)\r\n m.append(i)\r\nprint('YES' if f else 'NO')\r\n",
"s = input()\nfreq = [0 for i in range(26)]\nmax1 = s[0]\ninv = 1\nfor i in s:\n\tfreq[ord(i)-ord('a')] += 1\n\tif(i<=max1 or ord(i) == ord(max1)+1):\n\t\tmax1 = max(max1,i)\n\telse:\n\t\tinv = -1\t\nif(s[0] != 'a'):\n\tinv = -1\n# for i in freq:\n# \tif(i == 0):\n# \t\tc = 0\n# \tif(c == 0 and i != 0):\n# \t\tc = -1\n# \t\tbreak\nif(inv == -1):\n\tprint('NO')\nelse:\n\tprint('YES')\n",
"#\n# Joseph Matsushita\n# Problem C\n#\n\ncode = list(input())\n\nasciin = 97\ngood = True\nfor i in code:\n if ord(i) > asciin:\n good = False\n break\n elif ord(i) == asciin:\n asciin += 1\n\nif(good):\n print(\"YES\")\nelse:\n print(\"NO\")\n\n \t\t\t\t\t\t \t \t\t \t \t \t \t \t \t\t",
"def solve(s):\r\n tmp=ord('a')\r\n for i in s:\r\n if ord(i)>tmp:\r\n return \"NO\"\r\n elif ord(i)==tmp:\r\n tmp+=1\r\n return \"YES\"\r\n\r\n\r\ns=input()\r\nprint(solve(s))\r\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ns = input()[:-1]\r\na = 97\r\nfor i in s:\r\n if i > chr(a):\r\n print(\"NO\")\r\n break\r\n elif i == chr(a):\r\n a += 1\r\nelse:\r\n print(\"YES\")",
"string = input()\nvariables = \"\"\nabc = \"abcdefghijklmnopqrstuvwxyz\"\nfor i in string:\n if i not in variables:\n variables = variables + i\nlargo = len(variables)\norden = abc[:largo]\nif orden == variables:\n print(\"YES\")\nelse:\n print(\"NO\")\n \t\t \t \t\t\t\t \t \t \t\t \t\t\t\t \t\t",
"t = input()\r\nk = list(set(t))\r\nk.sort()\r\nfor i in range(len(k)):\r\n\tif ord(k[i]) != 97+i:\r\n\t\tprint(\"NO\")\r\n\t\texit()\r\nl1 = float(\"-inf\")\r\nfor i in k:\r\n\tvar = t.index(i)\r\n\tif l1 < var:\r\n\t\tl1 = var\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\t\texit()\r\nprint(\"YES\")\r\n",
"s = input()\nused = [96]\nfor i in range(len(s)):\n if ord(s[i]) > used[-1] + 1:\n print('NO')\n exit()\n elif ord(s[i]) == used[-1] + 1:\n used.append(ord(s[i]))\nprint('YES')\n",
"\r\ndef solution(T):\r\n\ts=input()\r\n\r\n\tst=set()\r\n\r\n\ttmp=\"abcdefghijklmnopqrstuvwxyz\"\r\n\tf=0\r\n\tfor c in s:\r\n\t\tif c in st:\r\n\t\t\tcontinue\r\n\t\telif c not in st and tmp[f]!=c:\r\n\t\t\tprint(\"NO\")\r\n\t\t\treturn\r\n\t\telse:\r\n\t\t\tst.add(c)\r\n\t\t\tf+=1\r\n\tprint(\"YES\")\r\n\t\t\r\n\r\n\r\nTT=1\r\n# TT=int(input())\r\nfor T in range(1,TT+1):\r\n\tsolution(T)",
"a=input()\r\nx=96\r\nb=''\r\nc=[]\r\nfor i in set(a):\r\n if x<ord(i):\r\n x=ord(i)\r\nfor i in range(97,x+1):\r\n if chr(i) in a:\r\n b+=(chr(i))\r\n else:\r\n print(\"NO\")\r\n exit(0)\r\n\r\nfor i in b:\r\n c.append(a.index(i))\r\nd=sorted(c)\r\nif d==c:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n ",
"s = input()\r\nse = set()\r\nind = 0\r\nalph = \"abcdefghijklmnopqrstuvwxyz\"\r\nans = True\r\n\r\nfor i in s:\r\n if i in se:\r\n continue\r\n elif i == alph[ind]:\r\n se.add(i)\r\n ind += 1\r\n continue\r\n else:\r\n ans = False\r\n break\r\n\r\nif ans:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"s = input()\r\na = \"abcdefghijklmnopqrstuvwxyz\"\r\ni = a.index(max(s))\r\na = a[:i+1]\r\nc = -1\r\nfor l in a:\r\n if l in s and s.index(l) > c:\r\n c = s.index(l)\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n ",
"from math import inf,sqrt,floor,ceil\r\nfrom collections import Counter,defaultdict,deque\r\nfrom heapq import heappush as hpush,heappop as hpop,heapify as h\r\nfrom operator import itemgetter\r\nfrom itertools import product\r\nfrom bisect import bisect_left,bisect_right\r\n\r\n\r\n#for _ in range(int(input())):\r\n#n=int(input())\r\ns=input()\r\nfind=set()\r\nstring='abcdefghijklmnopqrstuvwxyz'\r\nans=\"YES\"\r\nfor i in range(len(s)):\r\n if i==0:\r\n if s[i]!='a':\r\n ans=\"NO\"\r\n break\r\n else:\r\n find.add(s[0])\r\n else:\r\n if s[i] not in find:\r\n ind=string.index(s[i])\r\n for j in range(ind):\r\n if string[j] not in find:\r\n ans=\"NO\"\r\n break\r\n if ans==\"NO\":\r\n break\r\n find.add(s[i])\r\nprint(ans)\r\n \r\n \r\n \r\n ",
"s = input()\r\na = [0] * 26\r\nvis = [97]\r\nfor i in range(len(s)):\r\n a[ord(s[i]) - 97] += 1\r\nb = True\r\nfor i in range(26):\r\n if a[i] == 0:\r\n b = False\r\n elif b == False and a[i] > 0:\r\n print(\"NO\")\r\n exit()\r\nif s[0] != \"a\":\r\n print(\"NO\")\r\n exit()\r\nfor i in range(len(s)):\r\n if ord(s[i]) <= vis[len(vis)-1]:\r\n continue\r\n elif ord(s[i]) - 1 == vis[len(vis)-1]:\r\n vis.append(ord(s[i]))\r\n else:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")",
"s = input()\r\nmemo = {}\r\ntemp = list(\"abcdefghijklmnopqrstuvwxyz\")\r\nfor char in s:\r\n memo[char] = True\r\n\r\nanswer = list(memo.keys()) == temp[:len(memo.keys())]\r\nif answer:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"import string\r\nimport sys\r\n\r\ns = input()\r\nt = sorted(set(s))\r\nst = string.ascii_lowercase[:len(t)]\r\nif t != list(st):\r\n print(\"NO\")\r\n sys.exit()\r\n\r\nfor x in range(len(t)):\r\n if st[x] == s[0]:\r\n s = s.replace(st[x], '')\r\n else:\r\n print(\"NO\")\r\n sys.exit()\r\n\r\nprint(\"YES\")\r\n",
"##n = int(input())\r\n##a = list(map(int, input().split()))\r\n##print(' '.join(map(str, res)))\r\n\r\ns = list(input())\r\nn = len(s)\r\n\r\nflag = True\r\nlast = ord(s[0])\r\nif last != ord('a'):\r\n flag = False\r\nelse:\r\n for i in range(1, n):\r\n cur = ord(s[i])\r\n if cur-last > 1:\r\n flag = False\r\n break\r\n last = max(last, cur)\r\nif flag == True:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ",
"s=input()\r\nx=sorted(set(s),key=s.index)\r\nfor i in range(len(x)):\r\n if x[i]!=chr(ord('a')+i):exit(print(\"NO\"))\r\nprint(\"YES\")",
"\r\nobfuscation = list(input())\r\nletters = list(\"abcdefghijklmnopqrstuvwxyz\")\r\n\r\nif len(obfuscation) == 1:\r\n if obfuscation[0] == 'a':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n while len(obfuscation) > 0:\r\n if obfuscation[0] == letters[0]:\r\n while letters[0] in obfuscation:\r\n obfuscation.remove(letters[0])\r\n letters.remove(letters[0])\r\n else:\r\n print(\"NO\")\r\n exit()\r\n print(\"YES\")\r\n",
"s = str(input())\na = \"abcdefghijklmnopqrstuvwxyz\"\n\nl_s = list(s)\nl_a = list(a)\n\ni = len(l_s)\nans = 'NO'\n\nwhile i:\n if l_s[0] != l_a[0]:\n ans = 'NO'\n break\n else:\n while l_a[0] in l_s:\n l_s.remove(l_a[0])\n i -= 1\n if len(l_s) == 0:\n ans = \"YES\"\n break\n \n l_a.remove(l_a[0])\n\nprint(ans) ",
"def Obfuscate(s):\r\n letters = list(\"abcdefghijklmnopqrstuvwxyz\")\r\n used = []\r\n for i in s:\r\n if i in used:\r\n pass\r\n elif i == letters[0] and i not in used:\r\n used.append(letters.pop(0))\r\n elif i not in used:\r\n print(\"NO\")\r\n break\r\n else:\r\n print(\"YES\")\r\nObfuscate(input())",
"try:\r\n s= input()\r\n s1 =set(s)\r\n\r\n l = list(s)\r\n l2=[]\r\n for i in range(len(l)):\r\n if l[i] in s1:\r\n l2.append(l[i])\r\n s1.remove(l[i])\r\n\r\n k = ''.join(l2)\r\n m = ''.join(sorted(l2))\r\n c=0\r\n haha = ord('a')\r\n\r\n for i in range(len(k)):\r\n if(ord(k[i])==haha):\r\n c+=1\r\n haha+=1\r\n\r\n if(c==(len(k))):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nexcept EOFError:\r\n pass\r\n\r\n",
"s=list(input())\r\nk=len(s)\r\nr=[]\r\nk=97\r\nc=0\r\nf=0\r\nfor i in range(len(s)):\r\n\tif(ord(s[i])<=(k)):\r\n\t\tc=c+1\r\n\t\tr.append(ord(s[i]))\r\n\telif(ord(s[i])==(k+1)):\r\n\t\tif k in r:\r\n\t\t\tk=k+1\r\n\t\t\tr.append(ord(s[i]))\r\n\t\telse:\r\n\t\t\tf=1\r\n\t\t\tbreak\r\n\telse:\r\n\t\tf=1\r\n\t\tbreak\r\nif(f==1):\r\n\tprint('NO')\r\nelse:\r\n\tprint('YES')",
"s = input()\nsortstr = sorted(set(s),key=s.index)\nfor i in range(len(sortstr)):\n if sortstr[i] != chr(97+i):\n exit(print('NO'))\n\n\nprint('YES')",
"from string import ascii_lowercase\nrmv = lambda c, s: ''.join([ch for ch in s if ch != c])\ncur = iter(ascii_lowercase)\ns = input()\nwhile len(s):\n c = next(cur)\n if(s[0] != c):\n print('NO')\n exit(0)\n s = rmv(c, s)\nprint('YES')\n",
"s = input()\nif s[0] != 'a':\n print(\"NO\")\nelse:\n last = 'a'\n was = [0] * 30\n was[0] = 1\n for i in range(1, len(s)):\n if was[ord(s[i]) - ord('a')]:\n pass\n else:\n if ord(s[i]) == ord(last) + 1:\n last = s[i]\n was[ord(s[i]) - ord('a')] = 1\n else:\n print(\"NO\")\n exit()\n print(\"YES\")",
"from string import ascii_lowercase\r\n\r\n\r\ndef main():\r\n string = input()\r\n\r\n previous_index = 0\r\n flag = True\r\n for character in ascii_lowercase:\r\n find_index = string.find(character)\r\n if find_index == -1:\r\n for i in range(ord(character) + 1, ord(\"z\") + 1):\r\n if chr(i) in string:\r\n flag = False\r\n break\r\n break\r\n\r\n if previous_index > find_index:\r\n flag = False\r\n break\r\n else:\r\n previous_index = find_index\r\n\r\n print(\"YES\" if flag else \"NO\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"line = input()\r\nexpected = ord('a')-1\r\nfor i in line:\r\n\tif ord(i) > expected:\r\n\t\tif ord(i)==expected + 1:\r\n\t\t\texpected += 1\r\n\t\telse:\r\n\t\t\texit(print(\"NO\"))\r\nprint(\"Yes\")\r\n",
"def f(s):\r\n alfabet = \"abcdefghijklmnopqrstuvwxyzЯ\"\r\n for i in s:\r\n if i > alfabet[0]:\r\n return \"NO\"\r\n elif i == alfabet[0]:\r\n alfabet = alfabet[1:]\r\n else:\r\n pass\r\n return \"YES\"\r\n\r\n\r\ns = input()\r\nprint(f(s))\r\n",
"alphabet = [chr(i) for i in range(97, 123)]\r\nline = input()\r\nobfuscated_array = []\r\nfor el in line:\r\n obfuscated_array.append(el)\r\n\r\npoint = 0\r\nwhile len(obfuscated_array) != 0:\r\n if obfuscated_array[0] == alphabet[0]:\r\n for _ in range(obfuscated_array.count(alphabet[0])):\r\n obfuscated_array.remove(alphabet[0])\r\n alphabet.pop(0)\r\n else:\r\n print(\"NO\")\r\n break\r\nif len(obfuscated_array) == 0:\r\n print(\"YES\")",
"s= input()\r\ns1 =set(s)\r\n#print(s)\r\nl = list(s)\r\nl2=[]\r\nfor i in range(len(l)):\r\n if l[i] in s1:\r\n l2.append(l[i])\r\n s1.remove(l[i])\r\n#print(l2)\r\nk = ''.join(l2)\r\nm = ''.join(sorted(l2))\r\nc=0\r\nhaha = ord('a')\r\n#print(haha)\r\nfor i in range(len(k)):\r\n if(ord(k[i])==haha):\r\n c+=1\r\n haha+=1\r\n\r\nif(c==(len(k))):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n#if k==m and s[0]=='a':\r\n# print(\"YES\")\r\n#else:\r\n# print(\"NO\")\r\n\r\n",
"cmp = ord('a')\r\ns = input()\r\nfor i in range( len(s)):\r\n if ord(s[i]) > cmp:\r\n print ( \"NO\")\r\n exit(0)\r\n elif ord(s[i]) == cmp:\r\n cmp = cmp + 1\r\nprint(\"YES\")",
"import math\r\n\r\ninput_string = input()\r\n\r\nmap = []\r\nfirst_index = []\r\n\r\nfor i in range(0,26):\r\n map.append(0)\r\n first_index.append(math.inf)\r\n\r\nfor i in range(0, len(input_string)):\r\n\r\n if map[ord(input_string[i]) - 97] == 0:\r\n first_index[ord(input_string[i]) - 97] = i\r\n\r\n\r\n map[ord(input_string[i]) - 97]+=1\r\n\r\nfault = False\r\n\r\nfor i in range(1, len(map)):\r\n if map[i - 1] == 0 and map[i] > 0:\r\n fault = True\r\n break\r\n\r\n\r\nfor i in range(0, len(first_index) - 1):\r\n if first_index[i] > first_index[i + 1]:\r\n fault = True\r\n break\r\n\r\nif fault == True:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n \r\n",
"a=input()\r\nb=[]\r\nfor i in a:\r\n\tif i not in b:\r\n\t\tb += i\r\nprint(\"YES\" if b==[chr(97+i) for i in range(len(b))] else \"NO\")",
"'''\r\nCreated on 22 feb. 2017\r\n\r\n@author: Mirela\r\n'''\r\n\r\n\r\ndef solve(s):\r\n '''\r\n rezolvam prolema\r\n '''\r\n fr=200*[0]\r\n ok=True\r\n for i in range(len(s)):\r\n if s[i]!='a':\r\n o=ord(s[i])\r\n if fr[o-1]==0:\r\n ok=False\r\n break\r\n else:\r\n fr[o]=1\r\n else:\r\n fr[ord('a')]=1\r\n if ok==True:\r\n print('YES')\r\n else:print('NO')\r\n\r\ndef read():\r\n '''\r\n citim stringul\r\n '''\r\n s=input()\r\n solve(s)\r\nread()\r\n \r\n",
"s=input()\r\nl=[]\r\np=97\r\nc=0\r\nfor i in s:\r\n if not i in l:\r\n l.append(i)\r\n if ord(i)<=p:\r\n c+=1\r\n p+=1\r\n else:\r\n break\r\nif c==len(set(s)):\r\n print('YES')\r\nelse:\r\n print('NO')",
"n=input()\r\nk=\"a\"\r\nf=[]\r\np=\"abcdefghijklmnopqrstuvwxyz\"\r\nfor i in range(len(n)):\r\n if k>n[i] and n[i] not in f:\r\n print(\"NO\")\r\n exit()\r\n else:\r\n f+=[n[i]]\r\n if n[i]>k:\r\n k=n[i]\r\ns=set(n)\r\nfor i in range(len(s)):\r\n if p[i] not in s:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")",
"sc = 96\r\na = input()\r\nfor i in a:\r\n if ord(i) == sc+1:\r\n sc+=1\r\n elif ord(i) > sc+1:\r\n print(\"NO\")\r\n exit(0)\r\nprint(\"YES\")",
"import sys\r\ncharacter_list=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nstring=sys.stdin.readline().strip()\r\nlast_first_pos=-1\r\nlength=26\r\nfor i in range(length):\r\n first_pos=string.find(character_list[i])\r\n if(first_pos!=-1):\r\n if(first_pos<=last_first_pos):\r\n print('NO')\r\n #print('character',character_list[i],' came before a previous character')\r\n exit()\r\n last_first_pos=first_pos\r\n else:\r\n break\r\nfor j in range(i+1,length):\r\n first_pos=string.find(character_list[j])\r\n if(first_pos!=-1):\r\n print('NO')\r\n #print('character missed ',character_list[i])\r\n exit()\r\nprint('YES')\r\n ",
"a=input()\nb='a'\nc=0\nfor i in range(0,len(a)):\n if b==a[i]:\n b=chr(ord(b)+1)\n c+=1\n else:\n if(ord(a[i])<ord(b)):\n c+=1\nif c==len(a):\n print(\"YES\")\nelse:\n print(\"NO\")",
"s, cur = input(), 96\r\nfor i in s:\r\n asc = ord(i)\r\n if asc > cur:\r\n if asc != cur + 1:\r\n exit(print('NO'))\r\n cur = asc\r\n\r\nprint('YES')\r\n",
"king=input()\n\n\nst=sorted(set(king),key=king.index)\nfor got in range(len(st)):\n\n\n\n if st[got]!=chr(97+got):exit(print('NO'))\nprint('YES')\n \t \t \t \t\t\t \t \t \t \t\t",
"s = input()\r\nnxt = 'a'\r\nfor c in s:\r\n if c == nxt:\r\n nxt = chr(ord(nxt)+1)\r\n elif c > nxt:\r\n print('NO')\r\n exit()\r\nprint('YES')\r\n",
"\r\n#print(os.path.commonprefix(ls[0:2]))\r\ns=input()\r\nv=[0]*26\r\nfor i in s:\r\n if i==\"a\" or v[ord(i)-97-1]==1:\r\n v[ord(i) - 97] = 1\r\n pass\r\n\r\n else:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")",
"# http://codeforces.com/contest/765/problem/A\n# http://codeforces.com/contest/765/problem/B\n# http://codeforces.com/contest/765/problem/C\n\ndef Neverending_competitions():\n n = int(input())\n home = input()\n for i in range(n):\n new = input()\n if n % 2 == 0:\n return \"home\"\n else:\n return \"contest\"\n#print(Neverending_competitions())\n\ndef Code_obfuscation():\n s = input()\n a = [0] * 26\n okay = True\n for i in s:\n for j in range(ord(i)-97):\n if not a[j]:\n okay = False\n break\n if okay:\n a[ord(i) - 97] = 1\n else:\n break\n if okay:\n print(\"YES\")\n else:\n print(\"NO\")\n\nCode_obfuscation()",
"s = list(input())\r\nw = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nst = []\r\n\r\nfor k in range(len(s)):\r\n if(s[k] not in st):\r\n st.append(s[k])\r\nif(st == w[:len(st)]):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") ",
"from sys import exit\r\n\r\ndef chert(a, b):\r\n for i in range(len(b)):\r\n if b[i] != a[i]:\r\n return False\r\n return True\r\n\r\nalphabet = ''.join([chr(i) for i in range(ord('a'), ord('z') + 1)])\r\ns = input()\r\nif ''.join(sorted(list(set(s)))) not in alphabet:\r\n print(\"NO\")\r\n exit(0)\r\n\r\nletters_so_far = ''\r\nfor i in s:\r\n if i not in letters_so_far:\r\n letters_so_far += i\r\nif not chert(alphabet, letters_so_far):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")",
"s = list(input())\r\ng = []\r\nfor x in s:\r\n g.append(ord(x)-96)\r\nc = 0\r\np = []\r\nfor x in g:\r\n if x not in p:\r\n p.append(x)\r\nfor x in p:\r\n c += 1\r\n if x != c: print('NO'); exit()\r\nprint('YES')",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Apr 16 23:19:43 2018\r\n\r\n@author: niharika\r\n\"\"\"\r\n\r\ncode = input()\r\nif code[0]=='a':\r\n '''\r\n strt = set()\r\n \r\n for c in code:\r\n if c not in strt:\r\n strt.add(c)\r\n print(strt)\r\n '''\r\n strt = []\r\n for i in range(26):\r\n strt.append(-1)\r\n \r\n for i in range(len(code)):\r\n index = ord(code[i])-97\r\n if index>-1 and index<len(strt) and strt[index]==-1:\r\n strt[index] = i\r\n \r\n j=0\r\n while j<len(strt)-1 and strt[j]!=-1:\r\n if strt[j]<strt[j+1]:\r\n j+=1\r\n else:\r\n break\r\n if len(set(strt[j+1:]))<=1:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n \r\nelse:\r\n print(\"NO\")",
"s=input()\r\nl='abcdefghijklmnopqrstuvwxyz'\r\nz=''\r\nfor i in range(len(s)):\r\n if len(z)==0:\r\n z=z+s[i]\r\n else:\r\n if s[i] not in z:\r\n z=z+s[i]\r\nn=len(z)\r\nif z==l[:n]:\r\n print('YES')\r\nelse:\r\n print('NO')",
"n = input()\r\nff = False\r\nm = len(n)\r\nz = ord('a') - 1\r\nwhile m:\r\n z += 1\r\n if z > ord('z'):\r\n ff = True\r\n print('NO')\r\n break\r\n f = False\r\n for i in n:\r\n if f:\r\n if i == chr(z):\r\n m -= 1\r\n else:\r\n if ord(i) < z:\r\n pass\r\n elif ord(i) == z:\r\n f = True\r\n m -= 1\r\n else:\r\n print('NO')\r\n ff = True\r\n m = 0\r\n break\r\nif not ff:\r\n print('YES')\r\n",
"#!/usr/bin/env python3\nfrom sys import stdin,stdout\n\ndef ri():\n return map(int, stdin.readline().split())\ns = list(input())\n\nc = 'abcdefghijklmnopqrstuvwxyz'\nfor cc in c:\n if len(s) == 0:\n print(\"YES\")\n exit()\n if s[0] != cc:\n print(\"NO\")\n exit()\n s = [e for e in s if e!= cc]\n\nprint(\"YES\")\n",
"import sys\nimport math\n# input = sys.stdin.readline\n\ns=input()\ncur=0\nflag=True\nfor i in range(len(s)):\n\tx=ord(s[i])-97\n\tif x>cur:\n\t\tflag=False\n\t\tbreak\n\telif x==cur:\n\t\tcur+=1\n\nif flag:\n\tprint(\"YES\")\nelse:\n\tprint(\"NO\")",
"s=input()\r\ns1=sorted(set(s),key=s.index)\r\nfor i in range(len(s1)):\r\n if s1[i]!=chr(97+i):exit(print('NO'))\r\nprint('YES')\r\n",
"ping=input()\n\n\nst=sorted(set(ping),key=ping.index)\nfor got in range(len(st)):\n\n\n\n if st[got]!=chr(97+got):exit(print('NO'))\nprint('YES')\n \t\t\t\t\t\t \t \t\t\t \t \t\t\t\t \t \t\t\t",
"s = input()\r\nc = ord('a') - 1\r\nfor i in range(len(s)):\r\n if(ord(s[i]) > c + 1):\r\n print(\"NO\")\r\n exit()\r\n c = max(c,ord(s[i]))\r\n\r\nprint(\"YES\")",
"s = list(input())\r\nhas=[0]*(26)\r\nj=0\r\nans=\"YES\"\r\nfor i in s:\r\n ind=ord(i)-ord('a')\r\n if j<ind:\r\n ans='NO'\r\n break\r\n elif j==ind:\r\n has[j]+=1\r\n j+=1\r\nprint(ans)\r\n",
"import sys, string\r\n\r\narr = list(sys.stdin.readline().rstrip())\r\nst = []\r\nfor i in arr:\r\n if i not in st:\r\n st.append(i)\r\n\r\ncomp = list(string.ascii_lowercase)\r\ncan = True\r\nfor i in range(min(len(comp), len(st))):\r\n if comp[i] != st[i]:\r\n can = False\r\n break\r\nprint('YES' if can else 'NO')\r\n\r\n",
"s=input()\r\ndic={}\r\nfor i in s:\r\n if i in dic:\r\n dic[i]=dic[i]+1\r\n else:\r\n dic[i]=1\r\nl=list(dic.keys())\r\nn=len(l)\r\nc=97\r\nres=[]\r\nfor i in range(0,26):\r\n res.append(chr(c))\r\n c=c+1\r\n#print(l)\r\n#print(res)\r\nx=res[0:n]\r\n#print(x)\r\nif l==x:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"s = str(input())\r\nS = set()\r\nfor c in s:\r\n c = ord(c)-ord('a')\r\n if c != 0:\r\n if c-1 not in S:\r\n print('NO')\r\n exit()\r\n S.add(c)\r\nprint('YES')\r\n",
"s=input()\r\n\r\npos=ord('a')-1\r\nfor i in s:\r\n\tif ord(i)-pos==1:\r\n\t\tpos+=1\r\n\telif ord(i)-pos>1:\r\n\t\tprint(\"NO\")\r\n\t\texit()\r\nprint(\"YES\")",
"class CodeforcesTask765BSolution:\n def __init__(self):\n self.result = ''\n self.code = ''\n\n def read_input(self):\n self.code = input()\n\n def process_task(self):\n used = {}\n obf = \"a\"\n can = True\n for c in self.code:\n if c not in used:\n if c == obf:\n used[obf] = True\n obf = chr(ord(obf) + 1)\n else:\n can = False\n break\n self.result = \"YES\" if can else \"NO\"\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask765BSolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n",
"from string import ascii_lowercase\n\ndef can_decrypt(string):\n cur_idx = 0\n seen = set()\n\n for c in encoded:\n if c in seen:\n continue\n else:\n if c != ascii_lowercase[cur_idx]:\n return False\n else:\n seen.add(ascii_lowercase[cur_idx])\n cur_idx += 1\n return True\n\nencoded = input()\nif can_decrypt(encoded):\n print('YES')\nelse:\n print('NO')",
"def Main():\r\n\tinp = list(input())\r\n\tfound = 0\r\n\terror = False\r\n\r\n\tfor c in inp:\r\n\t\tp = ord(c) - ord('a') + 1\r\n\t\tif p == found + 1:\r\n\t\t\tfound += 1\r\n\t\telif p > found:\r\n\t\t\terror = True\r\n\t\t\tbreak\r\n\t\r\n\tif error == False:\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tMain()",
"# bsdk idhar kya dekhne ko aaya hai, khud kr!!!\r\n# import math\r\n# from itertools import *\r\n# import random\r\n# import calendar\r\n# import datetime\r\n# import webbrowser\r\n\r\n# f = open(\"input.txt\", 'r')\r\n# g = open(\"output.txt\", 'w')\r\n# n, m = map(int, f.readline().split())\r\n\r\nstring = input()\r\nsorted_string = sorted(set(string), key=string.index)\r\nfor i in range(0, len(sorted_string)):\r\n if sorted_string[i] == chr(97 + i):\r\n continue\r\n else:\r\n exit(print(\"NO\"))\r\nprint(\"YES\")\r\n",
"S = input()\r\n\r\nfor ch in 'abcdefghijklmnopqrstuvwxyz_':\r\n if not S:\r\n print('YES')\r\n break\r\n if S[0] != ch:\r\n print('NO')\r\n break\r\n S = S.replace(ch, '')",
"s = input().strip()\r\ntable = [-1]*26\r\ncount = 0\r\nfor i,c in enumerate(s):\r\n index = ord(c)-ord('a')\r\n if table[index]==-1:\r\n table[index] = i\r\n count+=1\r\nfor i in range(count):\r\n if table[i]==-1 or (i>0 and table[i-1]>table[i]):\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n",
"s = input()\r\nd = [0] * 26\r\nfor i in s:\r\n d[ord(i) - ord('a')] += 1\r\n for k in range(ord(i) - ord('a')):\r\n if d[k] == 0:\r\n print('NO')\r\n exit()\r\nprint('YES')\r\n\r\n\r\n\r\n",
"s=input()\r\nd=''\r\ns1=\"abcdefghijklmnopqrstuvwxyz\"\r\nflag=False\r\nfor j in range(len(s)):\r\n if s[j] not in d:\r\n d+=s[j]\r\nif d==s1[:len(d)]:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"import string\r\ns = input()\r\n\r\narr = \"\"\r\n\r\nfor char in s:\r\n if char not in arr:\r\n arr += char\r\n\r\nif arr == string.ascii_lowercase[:len(arr)]:\r\n print(\"YES\")\r\n\r\nelse:\r\n print(\"NO\")\r\n",
"from collections import Counter\r\nimport string\r\n\r\ns = input()\r\nc = Counter(s)\r\nalpha = string.ascii_lowercase\r\ni=0\r\nfor data in zip(c,alpha):\r\n if data[0] != data[1]:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")\r\n ",
"import math\n\nv = [ord(x) - 97 for x in input()]\nwhile len(v) > 0:\n if v[0] != 0:\n print('NO')\n exit(0)\n i = 0\n while i < len(v):\n if v[i] == 0:\n v.pop(i)\n else:\n v[i] -= 1\n i += 1\nprint('YES')\n\n\n\n\n\n",
"# kiểm tra xem các chữ cái trước nó đã xuất hiện lần lượt chưa\r\ncmp = ord('a')\r\ns = input()\r\nfor i in range( len(s)) :\r\n if ord(s[i]) > cmp :\r\n print(\"NO\")\r\n exit(0)\r\n if ord(s[i]) == cmp:\r\n cmp += 1\r\n\r\nprint(\"YES\")",
"s=input()\r\nl=list(set(s))\r\nl.sort()\r\nif l[0]!='a':\r\n print(\"NO\")\r\nelse:\r\n c=1\r\n for i in range(len(l)-1):\r\n if not chr(ord(l[i])+1)==l[i+1] or not s.index(l[i])<s.index(l[i+1]):\r\n c=0\r\n print(\"NO\")\r\n break\r\n if c:\r\n print(\"YES\")\r\n \r\n \r\n \r\n",
"def main():\n m, s = 96, set()\n for c in map(ord, input()):\n if c not in s:\n if not m < c < m + 2:\n print('NO')\n return\n else:\n m = c\n s.add(c)\n print('YES')\n\n\nif __name__ == '__main__':\n main()\n",
"string = str(input())\r\nexpected = 97\r\noutput = 1\r\nfor j in range(len(string)):\r\n if string[j] == chr(expected):\r\n expected += 1\r\n elif ord(string[j]) < expected:\r\n continue\r\n else:\r\n output = 0\r\n break\r\nif output == 1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"s=input()\nst=sorted(set(s),key=s.index)\nfor i in range(len(st)):\n if st[i]!=chr(97+i):exit(print('NO'))\nprint('YES')\n\n\t\t \t \t\t\t\t \t \t\t \t",
"s = input()\r\nvisited = [0] * 26\r\nfor i in s:\r\n visited[ord(i) - ord('a')] = 1\r\n if i != 'a' and visited[ord(i) - ord('a') - 1] == 0:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")\r\n",
"ch=input()\r\nk=0\r\nv=True\r\nfor x in range(len(ch)):\r\n a=ord(ch[x])-97\r\n if a==k+1:\r\n k+=1\r\n elif a>k:\r\n v=False\r\nif v and ch[0]=='a':\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n\r\n ",
"s = input()\r\nhm = set()\r\nflag = True\r\nstrings = 'abcdefghijklmnopqrstuvwxyz'\r\ncurr = 0\r\nfor char in s:\r\n if char not in hm:\r\n if char == strings[curr]:\r\n hm.add(char)\r\n curr += 1\r\n else:\r\n flag = False\r\n break\r\n else:\r\n continue\r\n\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"def solve(S):\r\n next_char = 'a'\r\n for ch in S:\r\n if ch > next_char:\r\n return False\r\n elif ch == next_char:\r\n next_char = chr(ord(next_char) + 1)\r\n return True\r\n\r\nS = input()\r\nprint(\"YES\" if solve(S) else \"NO\")",
"st = ''\n\ndef inp():\n global st\n st = input()\n\ndef solve():\n global st\n cp = 'a'\n if st[0] != 'a':\n return 'NO'\n while True:\n st = st.replace(cp,'')\n if st == '':\n return 'YES'\n if ord(st[0]) != ord(cp) + 1:\n return 'NO'\n cp = st[0]\n\n\n\nif __name__=='__main__':\n\n inp()\n rs = solve()\n print(rs)",
"from sys import exit\r\n\r\ns = input()\r\ncur = ord('a')\r\n\r\nfor i in range(len(s)):\r\n if ord(s[i]) == cur:\r\n cur = cur + 1\r\n elif ord(s[i]) > cur:\r\n print('NO')\r\n exit(0)\r\n\r\nprint('YES')\r\n\r\n",
"a=list(input())\r\nb=a\r\na=list(set(a))\r\nc=[]\r\nfor k in range(len(b)):\r\n if b[k] not in c:\r\n c.append(b[k])\r\na.sort()\r\nif ord(a[len(a)-1])==96+len(a) and a==c:\r\n print('YES')\r\nelse:\r\n print('NO')",
"s = [ord(x) for x in input()]\r\nm = ord('a') - 1\r\nfor i in s:\r\n if i - m > 1:\r\n print(\"NO\")\r\n exit()\r\n m = max(i, m)\r\nprint(\"YES\")",
"s=input()\r\nst=sorted(set(s),key=s.index)\r\nfor i in range(len(st)):\r\n if st[i]!=chr(97+i):exit(print('NO'))\r\nprint('YES')\r\n",
"import sys\r\ns = input()\r\nexpected = ord('a')\r\n\r\nfor i in s :\r\n if ord(i) > expected:\r\n print('NO')\r\n sys.exit()\r\n elif ord(i) == expected:\r\n expected +=1\r\n\r\nprint('YES')\r\n",
"# Ripped from editorial\r\nc = ord('a') - 1\r\nfor s in map(ord, input()):\r\n if s > c + 1:\r\n print('NO')\r\n exit()\r\n c = max(c, s)\r\nprint('YES')",
"from collections import Counter\r\n\r\nst = input()\r\n# st = sorted(st)\r\ncounter = Counter(st)\r\n\r\nl = [chr(i) for i in range(97,123)]\r\n# ctr = 0\r\n# for i in counter:\r\n# if (i != l[ctr]):\r\n# print(\"NO\")\r\n# break\r\n# ctr+=1\r\n# else:\r\n# print(\"YES\")\r\n \r\nunq = []\r\n\r\nj = 0\r\nif (st[0] != 'a'):\r\n print(\"NO\")\r\nelse:\r\n for i in counter.keys():\r\n #print(i,type(i))\r\n if (l[j] != i):\r\n print(\"NO\")\r\n \r\n break\r\n j+=1\r\n else:\r\n print(\"YES\")\r\n",
"a=list(input())\r\nb=[]\r\nfor i in a:\r\n if i not in b:\r\n b.append(i)\r\nfor i in range(len(b)):\r\n if (ord(b[i])-ord('a'))!=i:\r\n exit(print('NO'))\r\nprint('YES')\r\n",
"str = list(input())\r\nletters = list(\"abcdefghijklmnopqrstuvwxyz\")\r\n\r\nif len(str) == 1:\r\n if str[0] == 'a':\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n while len(str) > 0:\r\n if str[0] == letters[0]:\r\n while letters[0] in str:\r\n str.remove(letters[0])\r\n letters.remove(letters[0])\r\n else:\r\n print(\"NO\")\r\n exit()\r\n print(\"YES\")",
"s = input()\r\nr = []\r\n\r\nif s[0] != 'a':\r\n print('NO')\r\nelse:\r\n r.append('a')\r\n ans = 'yes'\r\n for i in range(1, len(s)):\r\n if s[i] in r:\r\n continue\r\n elif ord(s[i])-ord(r[-1]) == 1:\r\n r.append(s[i])\r\n else:\r\n ans = 'no'\r\n\r\n print(ans.upper())",
"a=input()\r\nb='a'\r\na=list(a)\r\ni=0\r\nflag=0\r\nwhile i<len(a):\r\n if a[i]==b:\r\n p=a[i]\r\n j=0\r\n while j<len(a):\r\n if a[j]==p:\r\n a[j]=0\r\n j+=1\r\n b=chr(ord(b)+1)\r\n elif a[i]==0:\r\n i+=1\r\n continue\r\n else:\r\n flag=1\r\n break\r\n i+=1\r\nif flag==1:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")",
"s = input()\nflag = True;\nl = len(s)\nmax = ord('a')-1\ni = 0\nwhile i < l and flag:\n cur = ord(s[i])\n if cur - max > 1:\n flag = False\n elif cur > max:\n max = cur\n i += 1\nprint (\"YES\") if flag else print (\"NO\")\n",
"A = input()\r\no = 97\r\nwhile len(A) != 0 and A[0] == chr(o):\r\n while A.find(chr(o)) != -1:\r\n x = A.find(chr(o)) \r\n if x != len(A) - 1:\r\n A = A[:x] + A[x+1:]\r\n else:\r\n A = A[:-1]\r\n o += 1\r\nif len(A) == 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n",
"from collections import Counter\r\ndef solve():\r\n s=input();s=list(Counter(s));n=len(s)\r\n curr='a'\r\n if s!=sorted(s):print(\"NO\");return\r\n for i in range(n):\r\n if s[i]!=chr(ord(curr)+i):print(\"NO\");return\r\n print(\"YES\")\r\n\r\nsolve()\r\n#for _ in range(int(input())):solve()",
"from string import ascii_lowercase\r\n\r\ndef solve(w):\r\n for c in ascii_lowercase:\r\n if w[0] != c:\r\n return \"NO\"\r\n else:\r\n w = w.replace(c,'')\r\n if len(w) == 0:\r\n return \"YES\"\r\n\r\nw = input()\r\nprint(solve(w))",
"s=''.join({}.fromkeys((input())).keys())\r\na='abcdefghijklmnopqrstuvwxyz'\r\nif a[:len(s)]==s:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n"
] | {"inputs": ["abacaba", "jinotega", "aaaaaaaaaaa", "aba", "bab", "a", "abcdefghijklmnopqrstuvwxyz", "fihyxmbnzq", "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr", "bbbbbb", "aabbbd", "abdefghijklmnopqrstuvwxyz", "abcdeghijklmnopqrstuvwxyz", "abcdefghijklmnopqrsuvwxyz", "abcdefghijklmnopqrstuvwxy", "abcdefghijklmnopqrsutvwxyz", "acdef", "z", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabbbabbaaabbaaaaabaabbaa", "aababbabbaabbbbbaabababaabbbaaaaabbabbabbaabbbbabaabbaaababbaaacbbabbbbbbcbcababbccaaacbaccaccaababbccaacccaabaaccaaabacacbaabacbaacbaaabcbbbcbbaacaabcbcbccbacabbcbabcaccaaaaaabcbacabcbabbbbbabccbbcacbaaabbccbbaaaaaaaaaaaadbbbabdacabdaddddbaabbddbdabbdacbacbacaaaabbacadbcddddadaddabbdccaddbaaacbceebbceadbeaadecddbbbcaaecbdeaebaddbbdebbcbaabcacbdcdc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbaabaabaababbbabbacacbbbacbbaaaabbccacbaabaaccbbbbbcbbbacabbccaaabbaaacabcbacbcabbbbecbecadcbacbaadeeadabeacdebccdbbcaecdbeeebbebcaaaeacdcbdeccdbbdcdebdcbdacebcecbacddeeaebcedffedfggbeedceacaecagdfedfabcfchffceachgcbicbcffeeebgcgiefcafhibhceiedgbfebbccegbehhibhhfedbaeedbghggffehggaeaidifhdhaggdjcfjhiaieaichjacedchejg", "b", "ac", "cde", "abd", "zx", "bcd", "aaac", "aacb", "acd", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "abcdefghijklmnopqrstuvwxyzz", "bc", "aaaaaaaaad", "abb", "abcb", "aac", "abcbcb", "bb", "abbb", "bbb", "x", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazz", "acbccccccccccc", "za", "ade", "bbbbbbbbbb", "bac", "bcddcb", "aaacb", "aaaaac", "aaaaaaaaaaad", "c", "abcccccccc", "aaaaaaac"], "outputs": ["YES", "NO", "YES", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO"]} | UNKNOWN | PYTHON3 | CODEFORCES | 115 | |
3180e2f8457950e4376b77f29145be1f | none | Emuskald considers himself a master of flow algorithms. Now he has completed his most ingenious program yet — it calculates the maximum flow in an undirected graph. The graph consists of *n* vertices and *m* edges. Vertices are numbered from 1 to *n*. Vertices 1 and *n* being the source and the sink respectively.
However, his max-flow algorithm seems to have a little flaw — it only finds the flow volume for each edge, but not its direction. Help him find for each edge the direction of the flow through this edges. Note, that the resulting flow should be correct maximum flow.
More formally. You are given an undirected graph. For each it's undirected edge (*a**i*, *b**i*) you are given the flow volume *c**i*. You should direct all edges in such way that the following conditions hold:
1. for each vertex *v* (1<=<<=*v*<=<<=*n*), sum of *c**i* of incoming edges is equal to the sum of *c**i* of outcoming edges; 1. vertex with number 1 has no incoming edges; 1. the obtained directed graph does not have cycles.
The first line of input contains two space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=2·105, *n*<=-<=1<=≤<=*m*<=≤<=2·105), the number of vertices and edges in the graph. The following *m* lines contain three space-separated integers *a**i*, *b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*, 1<=≤<=*c**i*<=≤<=104), which means that there is an undirected edge from *a**i* to *b**i* with flow volume *c**i*.
It is guaranteed that there are no two edges connecting the same vertices; the given graph is connected; a solution always exists.
Output *m* lines, each containing one integer *d**i*, which should be 0 if the direction of the *i*-th edge is *a**i*<=→<=*b**i* (the flow goes from vertex *a**i* to vertex *b**i*) and should be 1 otherwise. The edges are numbered from 1 to *m* in the order they are given in the input.
If there are several solutions you can print any of them.
Sample Input
3 3
3 2 10
1 2 10
3 1 5
4 5
1 2 10
1 3 10
2 3 5
4 2 15
3 4 5
Sample Output
1
0
1
0
0
1
1
0
| [
"import sys\n\nONLINE_JUDGE = True\n\nif not ONLINE_JUDGE:\n sys.stdin = open(\"input.text\", \"r\")\n\n############ ---- Input Functions ---- ############\n\n\ndef inp(): # integer\n return int(input())\n\n\ndef inlt(): # lists\n return list(map(int, input().split()))\n\n\ndef insr(): # list of characters\n s = input()\n return list(s[: len(s) - 1])\n\n\ndef invr(): # space seperate integers\n return map(int, input().split())\n\n\n############ ---- Solution ---- ############\n\nfrom collections import deque\n\ndef traverse(flow, graph, n, m):\n dirs = [-1] * m\n queue = deque()\n queue.append(0)\n while queue:\n node = queue.popleft()\n for neighbor, flow_vol, edge_num, dir in graph[node]:\n if dirs[edge_num] == -1:\n dirs[edge_num] = dir\n flow[neighbor] -= flow_vol\n if flow[neighbor] == 0 and neighbor != n - 1:\n queue.append(neighbor)\n return dirs\n\n\nn, m = inlt()\n\nflow = [0] * (n + 1)\ngraph = [[] for _ in range(n + 1)]\n\nfor edge_num in range(m):\n a, b, flow_vol = inlt()\n a, b = a - 1, b - 1\n graph[a].append((b, flow_vol, edge_num, 0))\n graph[b].append((a, flow_vol, edge_num, 1))\n\n flow[a] += flow_vol\n flow[b] += flow_vol\nfor i in range(n):\n flow[i] //= 2\n\ndirs = traverse(flow, graph, n, m)\nfor d in dirs:\n print(d)\n",
"class Node:\r\n def __init__(self, data):\r\n self.data = data\r\n self.next = None\r\n \r\nclass Queue:\r\n def __init__(self):\r\n self.rear = None\r\n self.front = None\r\n self.count = 0\r\n \r\n def dequeue(self): \r\n if self.front is None:\r\n exit(-1)\r\n \r\n temp = self.front \r\n self.front = self.front.next\r\n if self.front is None:\r\n self.rear = None\r\n self.count -= 1\r\n return temp.data\r\n \r\n def enqueue(self, item): \r\n node = Node(item)\r\n if self.front is None:\r\n self.front = node\r\n self.rear = node\r\n else:\r\n self.rear.next = node\r\n self.rear = node\r\n self.count += 1\r\n\r\nclass Edge:\r\n w = 0\r\n a = 0\r\n b = 0\r\n c = 0\r\n\r\nmaxN = 200005\r\nmaxM = 950005\r\nedges = [Edge() for i in range(maxM)]\r\nvisited = [0 for i in range(maxM)]\r\nnext = [0 for i in range(maxM)]\r\nfirst = [-1 for i in range(maxN)]\r\nflow = [0 for i in range(maxN)]\r\ntotal = 0\r\n\r\ndef insertEdge(x, y, w):\r\n global total\r\n flow[x] += w\r\n flow[y] += w\r\n edges[total].a = x\r\n edges[total].b = y\r\n edges[total].w = w\r\n edges[total].c = 1\r\n next[total] = first[x]\r\n first[x] = total\r\n total += 1\r\n edges[total].a = y\r\n edges[total].b = x\r\n edges[total].w = w\r\n edges[total].c = 1\r\n next[total] = first[y]\r\n first[y] = total\r\n total += 1\r\n\r\ndef bfs():\r\n for i in range(1, n+1):\r\n flow[i] = int(flow[i]/2)\r\n queue = Queue()\r\n queue.enqueue(1)\r\n while (queue.count != 0):\r\n temp = queue.dequeue()\r\n # print(queue.count)\r\n # print(\"size above\")\r\n # print(temp)\r\n # print(\"temp above\")\r\n j = first[temp]\r\n # print(j)\r\n # print(\"j above\")\r\n while (j != -1):\r\n if (visited[j] == 0):\r\n e = edges[j]\r\n flow[e.b] -= e.w\r\n visited[j] = visited[j^1]\r\n visited[j^1] = 1\r\n if (flow[e.b] == 0 and e.b != n):\r\n # print(e.b)\r\n # print(\"e.b above\")\r\n queue.enqueue(e.b)\r\n # print(queue.count)\r\n # print(\"size above\")\r\n e.c = 0\r\n j = next[j]\r\n\r\nline1 = [int(i) for i in input().split()]\r\nn = line1[0]\r\nm = line1[1]\r\nx = 0\r\ny = 0\r\nz = 0\r\nfor j in range(m):\r\n line1 = [int(i) for i in input().split()]\r\n x = line1[0]\r\n y = line1[1]\r\n z = line1[2]\r\n insertEdge(x, y, z)\r\nbfs()\r\nfor i in range(0, total, 2):\r\n print(edges[i].c)\r\n",
"import sys, collections\n\nn, m = list(map(int, sys.stdin.readline().strip().split()))\nN, M = 200005, 400005\nx = [0 for _ in range(N)]\ninto = [0 for _ in range(N)]\nvis = [False for _ in range(N)]\nans = [0 for _ in range(N)]\nnexts = [0 for _ in range(M)]\ndests = [0 for _ in range(M)]\ncp = [0 for _ in range(M)]\nq = collections.deque()\ntotal = 1\n\ndef insertEdge(a, b, c):\n global total\n total += 1\n nexts[total]=x[a]\n dests[total]=b\n x[a] = total\n cp[total]=c\n\nfor i in range(1, m + 1):\n a, b, c = list(map(int, sys.stdin.readline().strip().split()))\n insertEdge(a,b,c)\n insertEdge(b,a,c)\n into[a] += c\n into[b] += c\n\nfor i in range(2, n):\n into[i] >>= 1\n\nvis[1] = True\ninto[1] = 0\nq.append(1)\n\nwhile q:\n cur = q.popleft()\n i = x[cur]\n \n while i:\n if not vis[dests[i]]:\n into[dests[i]] -= cp[i]\n ans[i>>1] = i % 2\n if into[dests[i]] == 0:\n vis[dests[i]] = True\n q.append(dests[i])\n i = nexts[i] \n\nfor i in range(1, m+1):\n print(ans[i])\n\n# n, m, k = list(map(int, sys.stdin.readline().strip().split()))\n\n# matching = [-1 for _ in range(1001)]\n# adj = [[] for _ in range(1001)]\n# visited = [False for _ in range(1001)]\n\n# for i in range(k):\n# a, b = list(map(int, sys.stdin.readline().strip().split()))\n# adj[a-1].append(b-1)\n\n# output = 0\n\n# def dfs(cur):\n# visited[cur] = True\n# for b in adj[cur]:\n# if matching[b] < 0 or (not visited[matching[b]] and dfs(matching[b])):\n# matching[b] = cur\n# return 1\n# return 0\n\n# for i in range(n):\n# visited = [False for _ in range(1001)]\n# output += dfs(i)\n\n# print(output)\n\n# for i in range(m):\n# if ~matching[i]:\n# print(f\"{matching[i] + 1} {i + 1}\")\n\n"
] | {"inputs": ["3 3\n3 2 10\n1 2 10\n3 1 5", "4 5\n1 2 10\n1 3 10\n2 3 5\n4 2 15\n3 4 5", "10 17\n8 1 1\n4 8 2\n7 10 8\n1 4 1\n5 4 3\n6 9 6\n3 5 4\n1 9 1\n3 9 5\n7 1 1\n1 2 1\n1 3 1\n6 7 7\n8 2 1\n1 10 1\n1 5 1\n6 1 1", "10 20\n3 8 41\n1 2 21\n9 1 31\n1 3 53\n5 9 67\n10 1 8\n6 1 16\n5 2 21\n1 7 50\n5 4 38\n6 4 16\n4 8 16\n5 10 93\n9 10 126\n8 9 16\n4 1 38\n5 7 50\n3 9 12\n1 5 10\n5 8 41", "2 1\n1 2 1", "2 1\n2 1 1", "3 2\n1 2 1\n2 3 1", "4 4\n4 3 5000\n1 2 10000\n3 1 5000\n4 2 10000", "3 3\n3 1 10000\n2 1 10000\n3 2 10000", "3 3\n3 2 10000\n2 1 10000\n3 1 10000", "10 17\n9 1 8\n7 10 1\n5 4 4\n1 10 1\n3 10 1\n10 5 1\n6 3 6\n10 4 1\n4 6 5\n7 5 3\n2 10 1\n9 3 7\n9 10 1\n8 10 1\n10 6 1\n2 7 2\n2 8 1", "5 6\n1 3 10\n2 1 10\n3 5 10\n1 4 10\n2 5 10\n4 5 10", "5 6\n2 1 8\n5 2 8\n5 3 4\n4 1 9\n3 1 4\n5 4 9", "10 23\n10 5 94\n6 9 20\n10 2 79\n3 9 63\n1 6 80\n7 8 21\n3 5 6\n3 1 94\n2 5 21\n1 2 100\n1 7 79\n6 10 59\n8 1 60\n10 3 37\n9 1 37\n4 8 40\n7 10 100\n6 4 41\n5 1 79\n8 10 79\n9 10 80\n10 4 60\n4 1 59", "9 9\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n7 9 1\n8 9 1\n1 8 1", "6 6\n1 2 1\n2 6 1\n1 3 1\n3 4 1\n4 5 1\n5 6 1"], "outputs": ["1\n0\n1", "0\n0\n1\n1\n0", "1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n0\n0\n0\n1\n0\n0\n1", "0\n0\n1\n0\n0\n1\n1\n1\n0\n1\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1", "0", "1", "0\n0", "1\n0\n1\n1", "1\n1\n1", "1\n1\n1", "1\n0\n1\n0\n0\n1\n1\n1\n1\n1\n0\n0\n0\n0\n1\n1\n0", "0\n1\n0\n0\n0\n0", "1\n1\n1\n1\n1\n1", "1\n1\n1\n0\n0\n1\n1\n1\n0\n0\n0\n0\n1\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1", "0\n0\n0\n0\n0\n0\n0\n0\n0", "0\n0\n0\n0\n0\n0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 3 | |
318a48f1fb2864089f31d5bec97f167e | DZY Loves Physics | DZY loves Physics, and he enjoys calculating density.
Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows:
Once DZY got a graph *G*, now he wants to find a connected induced subgraph *G*' of the graph, such that the density of *G*' is as large as possible.
An induced subgraph *G*'(*V*',<=*E*') of a graph *G*(*V*,<=*E*) is a graph that satisfies:
- ; - edge if and only if , and edge ; - the value of an edge in *G*' is the same as the value of the corresponding edge in *G*, so as the value of a node.
Help DZY to find the induced subgraph with maximum density. Note that the induced subgraph you choose must be connected.
The first line contains two space-separated integers *n* (1<=≤<=*n*<=≤<=500), . Integer *n* represents the number of nodes of the graph *G*, *m* represents the number of edges.
The second line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=106), where *x**i* represents the value of the *i*-th node. Consider the graph nodes are numbered from 1 to *n*.
Each of the next *m* lines contains three space-separated integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*; 1<=≤<=*c**i*<=≤<=103), denoting an edge between node *a**i* and *b**i* with value *c**i*. The graph won't contain multiple edges.
Output a real number denoting the answer, with an absolute or relative error of at most 10<=-<=9.
Sample Input
1 0
1
2 1
1 2
1 2 1
5 6
13 56 73 98 17
1 2 56
1 3 29
1 4 42
2 3 95
2 4 88
3 4 63
Sample Output
0.000000000000000
3.000000000000000
2.965517241379311
| [
"n,m = [int(x) for x in input().split()]\r\n\r\nl = [int(x) for x in input().split()]\r\n\r\nx = 0;\r\nfor i in range(m):\r\n a,b,c = [int(x) for x in input().split()]\r\n cur = (l[a-1]+l[b-1])/c\r\n #print(a,b,c,cur)\r\n if cur > x: x = cur\r\nprint(\"%0.15f\"%x)\r\n",
"a = input().split(' ')\r\nn = int(a[0])\r\nm = int(a[1])\r\nb = input().split(' ')\r\na.clear()\r\nfor i in range(0, n) :\r\n a.append(int(b[i]))\r\nans = 0\r\nfor i in range(0, m) :\r\n b = input().split(' ')\r\n c = []\r\n for j in range(0, 3) : \r\n c.append(int(b[j]))\r\n ans = max(ans, (a[c[0] - 1] + a[c[1] - 1]) / c[2])\r\nprint(ans)\r\n",
"import sys\r\ninput=sys.stdin.readline\r\nn,m=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nans=0\r\nfor _ in range(m):\r\n u,v,c=map(int,input().split())\r\n if ans<(x[u-1]+x[v-1])/c:\r\n ans=(x[u-1]+x[v-1])/c\r\nprint(ans)",
"[n,m] = list(map(int, input().split(\" \")))\r\nV = list(map(int, input().split(\" \")))\r\nwyn = 0.0\r\nfor i in range(m):\r\n [a,b,c] = list(map(int, input().split(\" \")))\r\n wyn = max(wyn, (V[a-1]+V[b-1])/c)\r\nprint(wyn)",
"from sys import stdin\r\ninput = stdin.readline\r\n\r\nn, m = [int(x) for x in input().split()]\r\na = [int(x) for x in input().split()]\r\n\r\nans = 0\r\nfor _ in range(m):\r\n u, v, w = [int(x) for x in input().split()]\r\n ans = max(ans, (a[u-1]+a[v-1])/w)\r\nprint(ans)",
"nodes, edges = map(int, input().split())\r\nnodesValues = list(map(int,input().split()))\r\ndensity = 0\r\ntotal = 0\r\nfor i in range(edges):\r\n node1, node2, edgeValue = map(int, input().split())\r\n total = (nodesValues[node2-1] + nodesValues[node1-1])/edgeValue\r\n if total > density:\r\n density = total\r\nprint(density)\r\n",
"n,m = map(int, input().split())\r\narr =list(map(int, input().split()))\r\no = 0\r\nfor _ in range(m):\r\n a, b, c = map(int, input().split())\r\n o = max(o, (arr[a-1]+arr[b-1])/c)\r\nprint(o)",
"#\r\n# CS21-Science-Day-24\r\n# Name: Mahmoud Abdallah Hassan\r\n# GitHub link: https://github.com/RaymondReddigton\r\n# problem link: https://codeforces.com/contest/445/problem/C\r\n# Time Complexity: O(n)\r\n#\r\n#\r\n\r\n\r\nnodes , edges = map(int, input().split())\r\n \r\nnodesValues= list(map(int, input().split()))\r\n \r\nanswer = 0\r\n \r\nfor i in range(edges):\r\n \r\n a, b, c = map(int,input().split())\r\n \r\n answer = max(answer , (nodesValues[a-1] + nodesValues[b-1])/c)\r\n \r\nprint(answer)",
"n, m = map(int, input().split())\r\nt, v = 0, [0] + list(map(int, input().split()))\r\nfor i in range(m):\r\n x, y, d = map(int, input().split())\r\n t = max(t, (v[x] + v[y]) / d)\r\nprint(t)",
"import sys\nfrom collections import defaultdict\nimport math\nfrom heapq import *\nimport itertools\n\nMAXNUM = math.inf\nMINNUM = -1 * math.inf\nASCIILOWER = 97\nASCIIUPPER = 65\n\npq = [] # list of entries arranged in a heap\nentry_finder = {} # mapping of tasks to entries\nREMOVED = \"<removed-task>\" # placeholder for a removed task\ncounter = itertools.count() # unique sequence count\n\n\ndef add_task(task, priority=0):\n \"Add a new task or update the priority of an existing task\"\n if task in entry_finder:\n remove_task(task)\n count = next(counter)\n entry = [priority, count, task]\n entry_finder[task] = entry\n heappush(pq, entry)\n\n\ndef remove_task(task):\n \"Mark an existing task as REMOVED. Raise KeyError if not found.\"\n entry = entry_finder.pop(task)\n entry[-1] = REMOVED\n\n\ndef pop_task():\n \"Remove and return the lowest priority task. Raise KeyError if empty.\"\n while pq:\n priority, count, task = heappop(pq)\n if task is not REMOVED:\n del entry_finder[task]\n return task\n raise KeyError(\"pop from an empty priority queue\")\n\n\ndef getInt():\n return int(sys.stdin.readline().rstrip())\n\n\ndef getInts():\n return map(int, sys.stdin.readline().rstrip().split(\" \"))\n\n\ndef getString():\n return sys.stdin.readline().rstrip()\n\n\ndef printOutput(ans):\n sys.stdout.write(\"%.15f\" % (ans))\n\n\ndef findParent(a, parents):\n\n cur = a\n while parents[cur] != cur:\n cur = parents[cur]\n\n parents[a] = cur # reduction of search time on next search\n return cur\n\n\ndef union(a, b, parents):\n\n parents[b] = a\n\n\ndef solve(nodeList, edgeList, edgeHeap):\n parents = [i for i in range(nodeList)]\n\n minTreeEdges = []\n totalEdges = defaultdict(int)\n\n # Get min spanning tree\n while edgeHeap:\n eVal, n1, n2 = heappop(edgeHeap)\n n1Parent = findParent(n1, parents)\n n2Parent = findParent(n2, parents)\n if n1Parent != n2Parent:\n union(n1Parent, n2Parent, parents)\n totalEdges[n1] += 1\n totalEdges[n2] += 1\n add_task(n1, totalEdges[n1])\n add_task(n2, totalEdges[n2])\n\n minTreeEdgeList[n1] = (n2, eVal)\n minTreeEdgeList[n2] = (n1, eVal)\n\n # prune min spanning tree starting from leaves\n\n\ndef readinput():\n heap = []\n v, e = getInts()\n nodes = [0] + list(getInts()) \n mx = 0\n for i in range(e):\n n1, n2, e = getInts()\n mx = max(mx, (nodes[n1] + nodes[n2]) / e)\n printOutput(mx)\n\nreadinput()\n",
"def main():\r\n n, m = list(map(int, input().split()))\r\n V = [0]\r\n V = V + list(map(int, input().split()))\r\n ans = 0\r\n for _ in range(m):\r\n a, b, c = list(map(int, input().split()))\r\n ans = max(ans, (V[a] + V[b]) / c)\r\n print(f\"{ans:.15f}\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"from sys import stdin\r\ninput = stdin.readline\r\n \r\nn, m = map(int, input().split())\r\narr = [int(i) for i in input().split()]\r\nres = 0.0\r\nfor _ in range(m):\r\n\ta, b, c = map(int, input().split())\r\n\tif c: res = max(res, (arr[a-1] + arr[b-1]) / c)\r\nprint(res)\r\n",
"n,m=map(int,input().split());a=list(map(int,input().split()));o=0.0\n\nfor i in range(m):\n\n x,y,c=map(int,input().split());o=max(o,(a[x-1]+a[y-1])/c)\n\nprint(o)\n\n\n\n\n\n# Made By Mostafa_Khaled",
"N, E = 0, 0\r\nCost, Edges = [], []\r\nAnswer = 0.0\r\n\r\ndef Solve():\r\n global Answer\r\n for e in Edges:\r\n Answer = max(Answer, (1.0 * (Cost[e[0]] + Cost[e[1]]) / (1.0 * e[2])))\r\n\r\ndef ReadInput():\r\n global N, E, Cost, Edges\r\n N, E = map(int, input().split())\r\n Cost = list(map(int, input().split()))\r\n for i in range(0, E):\r\n x, y, c = map(int, input().split())\r\n Edges.append((x - 1, y - 1, c))\r\n\r\ndef PrintOutput():\r\n print(Answer)\r\n\r\ndef main():\r\n ReadInput()\r\n Solve()\r\n PrintOutput()\r\n\r\nmain()\r\n",
"\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nw = list(map(int, input().split()))\r\nc = 0\r\nfor _ in range(m):\r\n a, b, t = map(int, input().split())\r\n c = max(c, (w[a-1]+w[b-1])/t)\r\nprint(c)",
"import sys\ndef input(): return sys.stdin.readline().strip()\n\nn, m = map(int, input().split())\nx = [int(i) for i in input().split()]\n\nedge = []\nval = 0\nfor i in range(m):\n\ta, b, c = map(int, input().split())\n\tval = max((x[a-1]+x[b-1])/c, val)\nprint(val)",
"n, m=map(int, input().split())\r\nans=0\r\nf=list(map(int, input().split()))\r\nfor i in range(m):\r\n a, b, x=map(int, input().split())\r\n ans=max(ans, (f[a-1]+f[b-1])/x)\r\nprint(ans)\r\n",
"# import sys\r\n# input = sys.stdin.readline\r\n# for _ in range(int(input())):\r\nn,m = map(int,input().split(\" \"))\r\nx = list(map(int,input().split(\" \")))\r\nans = 0\r\nfor _ in range(m):\r\n a,b,c = map(int,input().split(\" \"))\r\n ans = max(ans,1.0*(x[a-1]+x[b-1])/c)\r\nprint(ans)",
"# HEY STALKER\r\nn, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nans = 0\r\nfor t in range(m):\r\n x, y, c = map(int, input().split())\r\n ans = max(ans, (l[x-1] + l[y-1]) / c)\r\nprint(ans)",
"n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nans = 0\r\nfor i in range(m):\r\n ax,bx,x = map(int,input().split())\r\n ans = max(ans,(a[ax-1]+a[bx-1])/x)\r\nprint(ans)",
"n, m = map(int, input().split())\r\n\r\nnodes = list(map(int, input().split()))\r\n\r\nhighest = 0\r\n\r\nfor i in range(m):\r\n a, b, e = map(int, input().split())\r\n val = (nodes[a-1] + nodes[b-1])/e\r\n if highest < val:\r\n highest = val\r\n\r\nprint(\"{0:.9f}\".format(highest))",
"nodes , edges = map(int,input().split())\r\n \r\nx=list(map(int,input().split()))\r\n\r\nerror =0\r\nfor i in range(edges):\r\n a,b,c=map(int,input().split())\r\n error = max(error , (x[a-1]+x[b-1])/c)\r\nprint(error)",
"R = lambda:map(int, input().split())\r\nans = 0\r\nn, m = R()\r\nF = list(R())\r\nfor i in range(m):\r\n\ta, b, x = R()\r\n\tans = max(ans, (F[a - 1]+ F[b - 1]) / x)\r\nprint(ans)",
"n, m = map(int, input().split())\nnodes = list(map(int, input().split()))\n\nmax_density = 0\nfor i in range(m):\n n1, n2, e = map(int, input().split())\n val = (nodes[n1-1]+nodes[n2-1])/e\n if (val > max_density):\n max_density = val\n\nmax_density = \"{:.16f}\".format(max_density)\nif (max_density[-1] >= '5'):\n print(max_density[:-2], int(max_density[-2])+1, sep=\"\")\nelse:\n print(max_density[:-1])\n"
] | {"inputs": ["1 0\n1", "2 1\n1 2\n1 2 1", "5 6\n13 56 73 98 17\n1 2 56\n1 3 29\n1 4 42\n2 3 95\n2 4 88\n3 4 63", "1 0\n734135", "10 10\n132402 148489 472187 403302 657890 205188 750668 276911 372190 828796\n8 10 162\n1 8 489\n6 7 279\n1 10 740\n5 6 721\n3 6 862\n2 3 194\n7 10 601\n2 10 658\n1 5 930", "20 20\n265918 744212 196368 74731 293587 679367 460805 632939 453630 565881 835276 606327 181087 721045 219431 849838 370939 582350 335676 32244\n2 16 989\n14 19 628\n1 6 483\n5 8 733\n13 19 556\n10 17 911\n2 7 599\n13 17 390\n10 20 965\n9 11 449\n3 15 310\n3 6 557\n14 18 225\n1 18 703\n10 18 234\n6 14 114\n8 18 23\n1 7 13\n5 6 108\n4 12 80", "30 7\n757449 649347 745109 33126 786508 643820 514399 195852 220502 122381 298189 760229 330623 782818 92550 737997 981538 185996 139833 694984 605470 928975 574293 485050 265558 56466 247185 372975 847922 530210\n21 22 604\n3 12 859\n24 30 56\n15 24 627\n3 23 494\n2 27 409\n13 25 806", "40 0\n333755 354468 763743 983044 791235 558007 639137 977841 767439 595261 276101 212062 189789 573751 751706 311404 689132 603080 300272 15008 274365 411257 191645 451302 387673 289269 427129 352075 335498 665358 917537 392450 219168 587894 920119 930721 72109 817927 33248 189473", "5 7\n348 348 348 348 348\n1 2 9\n2 4 9\n2 3 9\n1 4 9\n3 5 9\n1 3 9\n3 4 9", "10 23\n483 482 483 483 483 482 483 482 483 482\n4 6 360\n1 4 360\n3 4 360\n1 2 360\n1 9 359\n3 5 360\n7 9 359\n6 7 360\n1 6 360\n5 10 359\n3 7 360\n2 9 360\n3 10 359\n1 10 360\n4 5 359\n1 7 360\n7 8 359\n3 8 359\n4 7 359\n2 7 359\n2 10 360\n1 8 359\n2 5 360", "3 3\n100 100 1\n1 2 50\n1 3 49\n2 3 49"], "outputs": ["0.000000000000000", "3.000000000000000", "2.965517241379311", "0.000000000000000", "6825.351851851852200", "55901.769230769234000", "18129.642857142859000", "0.000000000000000", "77.333333333333329", "2.690807799442897", "4.000000000000000"]} | UNKNOWN | PYTHON3 | CODEFORCES | 24 | |
31b2068c4127a3a6df25dd29749cbb94 | Text Messaging | Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing *n* characters (which is the size of one text message). Thus, whole sentences and words get split!
Fangy did not like it, so he faced the task of breaking the text into minimal messages on his own so that no sentence were broken into pieces when it is sent and the number of text messages to be sent would be minimal. If two consecutive sentences are in different messages, the space between them can be ignored (Fangy does not write this space).
The little walrus's text looks in the following manner:
SPACE stands for the symbol of a space.
So, how many messages did Fangy send?
The first line contains an integer *n*, which is the size of one message (2<=≤<=*n*<=≤<=255). The second line contains the text. The length of the text does not exceed 104 characters. It is guaranteed that the text satisfies the above described format. Specifically, this implies that the text is not empty.
On the first and only line print the number of text messages Fangy will need. If it is impossible to split the text, print "Impossible" without the quotes.
Sample Input
25
Hello. I am a little walrus.
2
How are you?
19
Hello! Do you like fish? Why?
Sample Output
2
Impossible
3
| [
"# /*******************************************************************************\r\n# * Author : Quantum Of Excellence\r\n# * email : quantumofexcellence (at) gmail (dot) com\r\n# * copyright : 2014 - 2015\r\n# * date : 6 - 11 - 2015\r\n# * Judge Status : \r\n# * Problem Category : \r\n# * file name : 70B.py\r\n# * version : 1.0\r\n# *\r\n# * TERMS OF USE - Write a mail to the author before copying or reusing the content of this file \r\n# * seeking our permission for the same.\r\n# * Copying/reuse of the below code without the permission of the author is prohibited and illegal.\r\n# *\r\n# * All rights reserved by Quantum Of Excellence.\r\n# ******************************************************************************/\r\n\r\n# /*******************************************************************************\r\n# * some pointers on the logic/idea - \r\n# * \r\n# * \r\n# *******************************************************************************/\r\n\r\n\r\n# test cases-\r\n\r\n\r\n#import sys\r\n#fi = open(\"g:\\dump\\input.in\",\"r\")\r\n#sys.stdin = fi\r\nu=input\r\ne=1\r\nwhile(e):\r\n n=int(u())\r\n s=u().replace('?','.').replace('!','.');\r\n f=1\r\n p=len(s)-1\r\n i=0\r\n if('.'!=s[p]):f=0\r\n else:\r\n l=s[:p].split('.')\r\n q,t,i=0,1,0\r\n while(i<len(l)):\r\n r=len(l[i])+1\r\n # if even the individual len(after removing the space at the start) > n, set f=0\r\n if(len( str(l[i]).lstrip() )>n ):\r\n f=0\r\n break\r\n if(q+r<=n):\r\n q+=r\r\n else:\r\n l[i]=str(l[i]).lstrip()\r\n q=len(l[i])+1\r\n t+=1\r\n i+=1\r\n if(f):print(t)\r\n else:print(\"Impossible\")\r\n e-=1",
"n = int(input())\ns = input()\na = [\"\"]\nfor c in s:\n if a[-1] == \"\" and c == ' ':\n continue\n a[-1] += c;\n if c == '?' or c == '!' or c == '.':\n a.append(\"\");\n\nans = 0\nlast = 0\nfor i in range(len(a)):\n if len(a[i]) > n:\n print('Impossible')\n exit(0)\n add = len(a[i]) + 1 if i + 1 != len(a) else len(a[i])\n if i == 0 or (last + add) > n:\n ans += 1\n last = len(a[i])\n else:\n last += add\nprint(ans)",
"import sys\nn = int(input())\ns = str(input())\nm = len(s)\ncnt = 0\ngd = False\nans = 0\nlst = 0\nend = ['.', '?', '!']\nrem = 0\nfor i in range(m):\n cnt += 1\n if(s[i] in end):\n gd = True\n lst = cnt # store the last good one\n if(cnt == n):\n if(not gd):\n print(\"Impossible\")\n exit(0)\n else:\n cnt = cnt - lst - 1\n gd = False\n ans += 1\n rem = i\nif(s[m - 1] not in end):\n print(\"Impossible\")\n exit(0)\nelif(rem != (m - 1)):\n ans += 1\nprint(ans)\n",
"import re\n\nsegment_size = int(input())\nsentences = re.findall('\\w.*?[.?!]', input())\n\nfor sentence in sentences:\n if len(sentence) > segment_size:\n print('Impossible')\n import sys\n sys.exit()\n\nlen_current = len(sentences[0])\nnum_segments = 1\nfor sentence in sentences[1:]:\n if len_current + 1 + len(sentence) <= segment_size:\n len_current += 1 + len(sentence)\n else:\n num_segments += 1\n len_current = len(sentence)\n\nprint(num_segments)\n",
"\r\nn = int(input()) ;\r\ns = input() ; count = 0 ; ans = 0\r\ni = 0 ; L = []\r\n\r\nwhile i < len(s):\r\n if s[i] not in ['.','?','!'] : count += 1 ; i += 1\r\n elif s[i] in ['.','?','!'] :\r\n L.append(count + 1) ; ans += 1 ; count = 0 ; i += 2\r\n\r\n#print(L,n)\r\ni = 1 ; a = len(L)\r\n#print(a)\r\nflag = False\r\nif L[0] > n : flag = True ; print(\"Impossible\")\r\nelse :\r\n while i < a:\r\n if L[i] > n : print(\"Impossible\") ; flag = True ; break\r\n elif L[i] + L[i - 1] + 1 <= n : L[i - 1] += L[i] + 1 ; L.pop(i) ; a -= 1\r\n else : i += 1\r\n#print(L)\r\nif not flag :\r\n print(len(L))\r\n",
"import re\r\nn=int(input())\r\nans,sumL=1,0\r\nfor s in re.split(\"[.?!]\", input()):\r\n s=s.strip()+'.'\r\n L=len(s)\r\n if L>1:\r\n if L>n:\r\n print(\"Impossible\")\r\n exit()\r\n if sumL+L+(sumL>0) > n:\r\n ans+=1\r\n sumL=L\r\n else:\r\n sumL=sumL+L+(sumL>0)\r\nprint(ans)\r\n",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ns = input()[:-1]\r\nq = []\r\nc = ''\r\nfor i in s:\r\n if i in '!.?':\r\n c += i\r\n q.append(c.lstrip(' '))\r\n c = ''\r\n else:\r\n c += i\r\n\r\nc = 0\r\na = 1\r\nfor i in q:\r\n if c == 0:\r\n c += len(i)\r\n if c > n:\r\n print('Impossible')\r\n exit()\r\n else:\r\n c += len(i) + 1\r\n if c > n:\r\n a += 1\r\n c = len(i)\r\n if len(i) > n:\r\n print('Impossible')\r\n exit()\r\nprint(a)",
"n, text, SMSes, SMS_len = int(input()), input(), 0, 0\r\n\r\nfor ch in '.?!':\r\n text = text.replace(ch, '_')\r\n\r\nfor L in map(len, (' ' + text).split('_')[:-1]):\r\n if L > n:\r\n print('Impossible')\r\n break\r\n SMS_len += (L + 1) if SMS_len else L\r\n if SMS_len > n:\r\n SMSes, SMS_len = SMSes + 1, L\r\nelse:\r\n print(SMSes + 1)",
"# compiler on CodeForces: PyPy 3 64bit\nimport sys\ninput = lambda: sys.stdin.readline()[:-1]\nprint = lambda *args: sys.stdout.write(' '.join(map(str, args)) + '\\n')\n\nn = int(input())\nsentences = input().replace('?', '.').replace('!', '.').strip('.').split('. ')\nsentences = [len(e) + 1 for e in sentences]\n\nif max(sentences) > n:\n print('Impossible')\n exit(0)\n\nanswer = 0\nbuffer = sentences[0]\nfor l in sentences[1:]:\n if buffer + 1 + l <= n:\n buffer += 1 + l\n continue\n\n answer += 1\n buffer = l\nanswer += 1\nprint(answer)\n"
] | {"inputs": ["25\nHello. I am a little walrus.", "2\nHow are you?", "19\nHello! Do you like fish? Why?", "4\na. A.", "191\nEvx vnxZtUSgtzH yDNXCsTaxCKQus gVZLHppOplkGGekIK xbme. krbusMqUs YEnBBTJpjNicZPlx TqEtBPcbejZMzvn fFTub CHYWLmiOFkDdzR! LoQmXPfHJ KVnfrbrFooVSkj xwAZwrRr DdILZ kpco cLoRmJbVKhnbOEhnHKpci. PgYhxFPXdlvlrp mDLZBnVRf AgRMUjxepFuLyKlIAhLS wtmEiLDNUAHpZEsKnkOu!", "146\niIQVkDsPqzAJyBrtHk EhBSN gzDoigItCMzETerb cIbXhTPbKYMdMoYqyFTEN. qcrrseVwmaZEiQUQoGT SUyErST lJDejKkjqTdoUrHR tsZYDyI? pmuNNHYqQUISxdZfWOB XdEECvNz hnNmVfODaIC qjhRIEPAlEsQBxo apZ! gCpqoiUFIwWLBOmYubywj qJojFVhLd dCpovICpXHfgihydEOoij?", "151\nayDIuxJXWNqu OImqJLodviANkQNxZ OpDpwyoPQdZyosXJpqRx! ZFQNQJPnoEVUEEbjqs iyfUYK HuGCOtlsEllsCiHIdEuW ZmlRSWVOmLAD MSYsC? CGKxobjmddejDDdF qbQsAWi qxViwV iLmPHfhLjP ZfNCItjZikwaQyhQGC? bvSaaZhwHdbNKSiiI bEJXRjANEasfrElNHPA UuQCajtuODHgxwgL qbssJss TqT.", "123\nOjg CVJm qfE RnHislFds nNKKt TCPLWukqNGAsVBplYbTfq? VeYKjfFGTzXWA ydpVZLIImNub yApKnAHv iXQmqv GjQvxrnAgtfTApiQyCKtg. GdmapGwvI udRqxTbnzgnOUNZx slAuEuLGCJycZJvtCczQ vommS xuuT eIK! DOJeFEaubbz HYLGlIIlNKfyaJQKVN eFNnUvKKCQLXvGhwX gjmRscMkedELUlHq? aTbyMGB EofzX wcAEjyRQpxghWvXhdJb cwIz FEUsEFicYZ.", "126\ntjQvloOnRednqfvIRudX wAPhGdwEZ BiuuuAW EfSzDuRTdC rptjpHnxyM? FkLaTBruN IwuIQMdpdUpn etTVVJUsKztaR YNY EAENiDgJwYXDDrayjyuKp! yKqRNHznLRpnTqjisR LuapWDnWmwYDE NcClOZBNzMYrpa? SEZdSZIgBekpCPvyEiO AMjztArkFRJuS ilycvolFExqxrXJK. sLvBUxjIOomxUqYd jZsOXWN iBtqSykbeUbAsQgRVs DinPLrpzt.", "118\ngweVo bjbEKaZQw PpSi AWOYt sQSvAHNRswh vUaGuLbtExNECz! USsQxMCjaGOmUESwHvyY SshkERibaWkmNLSZOtWZy FFTUWQgekPRjLRetAdSFt! sIhcimZTisFvndrYioLF HetLn wjoaDUKfbkagupl QdYb fFiV GNqBygStKQw. XLiYZEOGnTLSHmCwktEr pVBePMoRGopNt LdEujxuxzmlbycQdR?", "16\nAbacaba. Abacaba. abacaba. abacab.", "21\nHello. I am a little walrus.", "16\nAbacaba. Abacab. abacaba. abacaba.", "10\nhello! how are you?", "5\nabc. abcd.", "16\nabacaba. abacab. Abacaba. Abacaba.", "5\na. b. c. d.", "8\nabc! ab.", "2\na. b."], "outputs": ["2", "Impossible", "3", "2", "2", "2", "2", "3", "3", "4", "3", "2", "3", "Impossible", "2", "3", "2", "1", "2"]} | UNKNOWN | PYTHON3 | CODEFORCES | 9 | |
31d742885e0896f01ad4f25eb86abb43 | Magic Odd Square | Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd.
The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49).
Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd.
Sample Input
1
3
Sample Output
1
2 1 4
3 5 7
6 9 8
| [
"n = int(input())\r\nc, o, e = n // 2, 1, 2\r\nfor i in range(n):\r\n for j in range(n):\r\n if abs(i - c) + abs(j - c) <= c:\r\n print(o, end=\" \")\r\n o += 2\r\n else:\r\n print(e, end=\" \")\r\n e += 2\r\n print(\"\")\r\n",
"import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nimport time\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max\r\ndef _heappush_max(heap,item):\r\n heap.append(item)\r\n heapq._siftdown_max(heap, 0, len(heap)-1)\r\ndef _heappushpop_max(heap, item):\r\n if heap and item < heap[0]:\r\n item, heap[0] = heap[0], item\r\n heapq._siftup_max(heap, 0)\r\n return item\r\nfrom math import gcd as GCD\r\nread=sys.stdin.read\r\nreadline=sys.stdin.readline\r\nreadlines=sys.stdin.readlines\r\nwrite=sys.stdout.write\r\n\r\nN=int(readline())\r\nans_lst=[[None]*N for x in range(N)]\r\ncur=1\r\nfor x in range(N):\r\n for y in range(N):\r\n if abs(x-N//2)+abs(y-N//2)<=N//2:\r\n ans_lst[x][y]=cur\r\n cur+=2\r\ncur=2\r\nfor x in range(N):\r\n for y in range(N):\r\n if abs(x-N//2)+abs(y-N//2)>N//2:\r\n ans_lst[x][y]=cur\r\n cur+=2\r\nfor i in range(N):\r\n print(*ans_lst[i])",
"n = int(input())\r\n\r\nk = n//2\r\n\r\n\r\ncur_odd = 1\r\ncur_even = 2\r\n\r\nfor i in range(k + 1):\r\n a = '0'*(k-i) + '1'*(n + 2*i - 2*k) + '0'*(k-i)\r\n b =[]\r\n for x in a:\r\n if x == '0':\r\n b.append(cur_even)\r\n cur_even += 2\r\n else:\r\n b.append(cur_odd)\r\n cur_odd += 2\r\n print(*b)\r\n #print('-'.join(b))\r\n\r\nfor i in range(1, k + 1):\r\n a = '0'*(i) + '1'*(n - 2*i) + '0'*(i)\r\n\r\n b =[]\r\n for x in a:\r\n if x == '0':\r\n b.append(cur_even)\r\n cur_even += 2\r\n else:\r\n b.append(cur_odd)\r\n cur_odd += 2\r\n #print(''.join(b))\r\n print(*b)",
"n=int(input())\r\no=[i for i in range(1,n**2 +1,2)]\r\ne=[i for i in range(2,n**2,2)]\r\n\r\nx=[[0 for i in range(n)] for j in range(n)]\r\n\r\nfor i in range(n):\r\n y=n//2\r\n if y-i>=0:\r\n for j in range(y-i,y+i+1):\r\n x[i][j]=o.pop()\r\n else:\r\n for j in range(y+i-n+1,y-i+n):\r\n x[i][j]=o.pop()\r\n for j in range(n):\r\n if x[i][j]==0:\r\n x[i][j]=e.pop()\r\n\r\nfor i in range(n):\r\n print(*x[i])\r\n",
"n = int(input())\npar = [[0]*n for _ in range(n)]\nh = -(-n//2)\nfor l in range(int(h&1),h+1,2):\n for i in range(l):\n for j in range(l):\n if i==l-1 or j==l-1:\n par[i][j] = 1\nfor i in range(n):\n for j in range(n):\n if i <= n//2 and j <= n//2:\n continue\n if j <= n//2:\n par[i][j] = par[n-i-1][j]\n else:\n par[i][j] = par[i][n-j-1]\neo = [2,1]\nans = [[0]*n for _ in range(n)]\nfor i in range(n):\n for j in range(n):\n ans[i][j] = eo[par[i][j]]\n eo[par[i][j]] += 2\nprint(\"\\n\".join(\" \".join(map(str, i)) for i in ans))\n\t\t \t\t \t\t \t \t \t \t \t\t\t\t\t",
"n=int(input())\r\nmp=[[0 for i in range(n)]for i in range(n)]\r\nod=1\r\nev=2\r\ncnt=0\r\ng=False\r\nfor i in range(n):\r\n for j in range(n):\r\n if j<(n//2-cnt) or j>(n//2+cnt):\r\n mp[i][j]=ev\r\n ev+=2\r\n else:\r\n mp[i][j]=od\r\n od+=2\r\n if i<n//2:\r\n cnt+=1\r\n else:\r\n cnt-=1\r\nfor i in mp:\r\n print(*i)",
"n=int(input())\na=[i for i in range(1,n*n+1)]\neven=[]\nodd=[]\nfor x in a:\n if x%2==0:\n even.append(x)\n else:\n odd.append(x)\n\nc=1\n\nfor i in range(n):\n si=(n-c)//2\n ei=si+c-1\n for j in range(n):\n if j>=si and j<=ei:\n print(odd[0],end=\" \")\n odd.pop(0)\n else:\n print(even[0],end=\" \")\n even.pop(0)\n print()\n\n if i>=n//2:\n c-=2\n else:\n c+=2\n\n\n \n \n\n\n\"\"\"\ne e o e e\ne o o o e\no o o o o\ne o o o e\ne e o e e\n\n\"\"\"",
"__author__ = 'Think'\r\nn=int(input())\r\nparity=((n-1)//2)%2\r\ndef cell(r, c):\r\n\tr=min(r, n+1-r)\r\n\tc=min(c, n+1-c)\r\n\tid=max(r, c)\r\n\treturn (id-parity)%2\r\nodd=-1\r\neven=0\r\ndef get(par, odd, even):\r\n\tif par==0:\r\n\t\teven+=2\r\n\t\treturn even, odd, even\r\n\tif par==1:\r\n\t\todd+=2\r\n\t\treturn odd, odd, even\r\nfor r in range(1, n+1):\r\n\tfor c in range(1, n+1):\r\n\t\t(val, odd, even)=get(cell(r, c), odd, even)\r\n\t\tprint(val, end=\"\")\r\n\t\tif c!=n:\r\n\t\t\tprint(\" \", end=\"\")\r\n\tprint()\r\n\r\n\r\n",
"import math\nimport re\n\nn = int(input())\n\narr = [[0] * n for i in range(n)]\n\na = [1] + [1 + 2*i for i in range(1, n*n//2+1)]\nb = [2*i for i in range(1, n*n//2 + 1)]\n\n\nk = 0\n\nfor i in range(n//2+1):\n for j in range(n//2-i, n//2 + i + 1):\n arr[i][j] = a[k]\n k += 1\n\nfor i in range(n // 2):\n for j in range(i + 1, n - i - 1):\n arr[n // 2 + 1 + i][j] = a[k]\n k += 1\n\nk = 0\n\nfor i in range(n):\n for j in range(n):\n if arr[i][j] == 0:\n arr[i][j] = b[k]\n k += 1\n\n\nfor i in range(n):\n print(' '.join(list(map(str, arr[i]))))\n\n\n\n\n# arr = list(map(int, input().split()))\n# m = int(input())\n# spis = list(map(int, input().split()))\n#\n# arr1 = sorted(arr, reverse=True)\n# a = [n - arr1.index(arr[el - 1]) for el in spis]\n# print(' '.join(map(str, a)))",
"N = int(input())\ncnt = 0\nthe_odd = -1\nthe_eve = 0\ndef get_with_eve_N(x, y) :\n\treturn -1\ndef get_with_odd_N(x, y) :\n\tglobal the_odd\n\tglobal the_eve\n\tif (x + y <= N + 1 >> 1 or x + y >= N + (N + 1 >> 1) + 1 or y - x >= N + 1 >> 1 or x - y >= N + 1 >> 1) :\n\t\tthe_eve += 2\n\t\treturn the_eve\n\telse :\n\t\tthe_odd += 2\n\t\treturn the_odd\nif N % 2 == 0 :\n\tfor i in range(1, N + 1) :\n\t\tfor j in range(1, N + 1) :\n\t\t\tif j == N :\n\t\t\t\tprint(get_with_eve_N(i, j))\n\t\t\telse :\n\t\t\t\tprint(get_with_eve_N(i, j), end = ' ')\nelse :\n\tfor i in range(1, N + 1) :\n\t\tfor j in range(1, N + 1) :\n\t\t\tif j == N :\n\t\t\t\tprint(get_with_odd_N(i, j))\n\t\t\telse :\n\t\t\t\tprint(get_with_odd_N(i, j), end = ' ')\n",
"#!/usr/bin/env\tpython\n#-*-coding:utf-8 -*-\nn=int(input())\nm=n>>1\na=1\nb=2\nfor x in range(n):\n\tl=abs(m-x)\n\tr=n-l\n\tfor y in range(l):\n\t\tprint(b,end=' ')\n\t\tb+=2\n\tfor y in range(l,r):\n\t\tprint(a,end=' 'if n-1>y else'\\n')\n\t\ta+=2\n\tfor y in range(r,n):\n\t\tprint(b,end=' 'if n-1>y else'\\n')\n\t\tb+=2\n",
"import sys\n\nn = int(input())\n\n\nodd = list(range(1, n * n + 1, 2))\neven = list(range(2, n * n + 1, 2))\n\nA = [[0] * n for _ in range(n)]\n\nfor i in range(n):\n A[i][n // 2] = odd.pop()\n\nfor i in range(n):\n if i != n // 2:\n A[n // 2][i] = odd.pop()\n\nn_off = (n + 1) // 2\n\nfor p in range(2):\n for q in range(2):\n even_to_spend = ((n // 2) * (n + 1) // 2) // 2\n for i in range(n // 2):\n for j in range(n // 2):\n if even_to_spend > 0:\n even_to_spend -= 1\n A[i + p * n_off][j + q * n_off] = even.pop()\n else:\n A[i + p * n_off][j + q * n_off] = odd.pop()\n\nfor i in range(n):\n for j in range(n):\n print(A[i][j], end=' ')\n print()\n",
"sz = int(input())\r\n\r\nodd_no = 1\r\neven_no = 2\r\n\r\nfor z in range(sz):\r\n\todds_to_print = sz - 2*int(abs(sz//2-z))\r\n\tevens_to_print = (sz - odds_to_print)//2\r\n\twhile evens_to_print > 0:\r\n\t\tprint(even_no, end= ' ')\r\n\t\teven_no+=2\r\n\t\tevens_to_print -= 1\r\n\twhile odds_to_print > 0:\r\n\t\tprint(odd_no, end = ' ')\r\n\t\todd_no+=2\r\n\t\todds_to_print -= 1\r\n\todds_to_print = sz - 2*abs(sz//2-z)\r\n\tevens_to_print = (sz - odds_to_print)//2\r\n\twhile evens_to_print > 0:\r\n\t\tprint(even_no, end= ' ')\r\n\t\teven_no+=2\r\n\t\tevens_to_print -= 1\r\n\tprint(\"\")\r\n\t",
"#Magic odd square\nimport sys\nn=int(input())\nodd=[i for i in range(1,n**2+1,2)]\neven=[i for i in range(2,n**2,2)]\nfor i in range(1,n+1,2):\n for j in range((n-i)//2):\n sys.stdout.write(\"%-2d \"%(even.pop()))\n for j in range(i):\n sys.stdout.write(\"%-2d \"%(odd.pop()))\n for j in range((n-i)//2):\n sys.stdout.write(\"%-2d \"%(even.pop()))\n sys.stdout.write(\"\\n\")\nfor i in reversed(range(1,n,2)):\n for j in range((n-i)//2):\n sys.stdout.write(\"%-2d \"%(even.pop()))\n for j in range(i):\n sys.stdout.write(\"%-2d \"%(odd.pop()))\n for j in range((n-i)//2):\n sys.stdout.write(\"%-2d \"%(even.pop()))\n sys.stdout.write(\"\\n\")\n \n\n \t \t \t \t\t \t\t\t \t\t \t \t\t",
"n=int(input())\r\nmatrix=[[0 for i in range(n)] for j in range(n)]\r\ni=n//2\r\nj=n-1\r\no=1\r\nwhile o<=n*n:\r\n if i==-1 and j==n:\r\n j=n-2\r\n i=0\r\n else:\r\n if j==n:\r\n j=0\r\n if i<0:\r\n i=n-1\r\n if matrix[i][j]:\r\n j-=2\r\n i+=1\r\n continue\r\n else:\r\n matrix[i][j]=str(o)\r\n o+=1\r\n j+=1\r\n i-=1\r\nfor i in range(n):\r\n print(\" \".join(matrix[i]))\r\n",
"#!/usr/bin/python3\n\nread = input().split(\" \");\nn = int(read[0])\n\ntab = [[0 for x in range(n)] for y in range(n) ]\n\np = int((n - 1) / 2)\nk = p + 1\nfor i in range(n):\n for j in range(p, k):\n tab[i][j] = 1\n if i < ((n-1) / 2):\n p -= 1\n k += 1\n else:\n p += 1\n k -= 1\n\nodd = 1\neven = 2\nfor i in range(n):\n output = \"\"\n for j in range(n):\n if tab[i][j] == 1:\n result = odd\n odd += 2\n else:\n result = even\n even += 2\n output += str(result)\n output += \" \"\n print (output)\n\n",
"n = int(input())\r\nA = [[0 for i in range(n)] for i in range(n)]\r\nc = n//2\r\nodds = (n*n+1)//2\r\n\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tif abs(i-c)+abs(j-c) <= c:\r\n\t\t\tA[i][j] = 1\r\n\r\no, e = 1, 2\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tif A[i][j]==0:\r\n\t\t\tA[i][j] = e\r\n\t\t\te += 2\r\n\t\telse:\r\n\t\t\tA[i][j] = o\r\n\t\t\to += 2\r\n\r\nfor row in A:\r\n\tprint(*row)",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nd = [[0]*n for i in range(n)]\r\nc = 1\r\nfor i in range(n):\r\n if d[i][n//2] == 0:\r\n d[i][n//2] = c\r\n c += 2\r\n if d[n//2][i] == 0:\r\n d[n//2][i] = c\r\n c += 2\r\n\r\nx = (n**2 // 2 - (n-1)*2) // 4\r\nf = list(range(n-2, 0, -2))\r\nq = []\r\nfor i in range(len(f)):\r\n if x >= f[i]:\r\n x -= f[i]\r\n q.append(i)\r\n if x == 0:\r\n break\r\n\r\nfor a in q:\r\n for i in range(a, n-a):\r\n if d[a][i] == 0:\r\n d[a][i] = c\r\n c += 2\r\n if d[i][a] == 0:\r\n d[i][a] = c\r\n c += 2\r\n if d[n-a-1][i] == 0:\r\n d[n-a-1][i] = c\r\n c += 2\r\n if d[i][n-a-1] == 0:\r\n d[i][n-a-1] = c\r\n c += 2\r\n\r\nc = 2\r\nfor i in range(n):\r\n for j in range(n):\r\n if d[i][j] == 0:\r\n d[i][j] = c\r\n c += 2\r\n\r\n\r\nfor i in d:\r\n print(' '.join(map(str, i)))",
"n = int(input())\r\nmt = [[0 for col in range(n)] for row in range(n)]\r\nr = 0\r\nc = (n - 1) // 2\r\nx = 1\r\n# print(mt)\r\nwhile x < n * n + 1:\r\n mt[r][c] = x\r\n # print(mt)\r\n if not x % n:\r\n r = (r + 1) % n\r\n else:\r\n r = (r - 1 + n) % n\r\n c = (c + 1) % n\r\n x += 1\r\n# print(mt)\r\nfor i in range(n):\r\n for j in range(n):\r\n print(\"%s%d\" % (\" \" if j else \"\", mt[i][j]), end=\"\")\r\n print()\r\n",
"n = int(input())\npp = 2\npn = 1\nif n == 1:\n print(1)\nelse:\n k = n // 2\n for i in range (k + 1):\n for j in range (k - i):\n print(pp, end = ' ')\n pp += 2\n for j in range (k - i, n - k + i):\n print(pn, end = ' ')\n pn += 2\n for j in range (n - k + i, n):\n print(pp, end = ' ')\n pp += 2\n print()\n for i in range (k - 1, -1, -1):\n for j in range (k - i):\n print(pp, end = ' ')\n pp += 2\n for j in range (k - i, n - k + i):\n print(pn, end = ' ')\n pn += 2\n for j in range (n - k + i, n):\n print(pp, end = ' ')\n pp += 2\n print()",
"n=int(input())\r\nmat=[[0]*n for i in range(n)]\r\nfor i in range(n):\r\n mat[n//2][i]=1\r\n mat[i][n//2]=1\r\nrem=(n*n+1)//2-n-n+1\r\nfor i in range(n//2):\r\n for j in range(n//2):\r\n if rem:\r\n rem-=4\r\n for x in [i,n-1-i]:\r\n for y in [j,n-1-j]:\r\n mat[x][y]=1\r\n\r\nodd=[]\r\neven=[]\r\nfor i in range(1,n*n+1):\r\n if i%2==1:\r\n odd.append(i)\r\n else:\r\n even.append(i)\r\n\r\nfor i in range(n):\r\n for j in range(n):\r\n if mat[i][j]:\r\n mat[i][j]=odd.pop()\r\n else:\r\n mat[i][j]=even.pop()\r\n\r\nfor row in mat:\r\n print(*row)",
"import sys, math\r\ninput=sys.stdin.readline\r\nINF=int(1e9)+7\r\n\r\ndef solve():\r\n n=int(input())\r\n result=[[0]*n for _ in range(n)]\r\n odd=1\r\n even=2\r\n mid=n//2\r\n for i in range(mid+1):\r\n for j in range(mid-i,mid+i+1):\r\n result[i][j]=odd\r\n odd+=2\r\n for i in range(mid+1,n):\r\n now=n-1-i\r\n for j in range(mid-now,mid+now+1):\r\n result[i][j]=odd\r\n odd+=2\r\n for i in range(n):\r\n for j in range(n):\r\n if result[i][j]==0:\r\n result[i][j]=even\r\n even+=2\r\n for i in range(n):\r\n print(*result[i],sep=' ')\r\n \r\nt=1\r\nwhile t:\r\n t-=1\r\n solve()\r\n",
"n=int(input())\r\nmatrix=[[0]*n for i in range(n)]\r\n\r\nfor i in range(n):\r\n matrix[i][n-1-i]=int((n*n-n+2)/2)+i\r\n\r\np=1\r\nsx=0\r\nsy=n-2\r\nx=0\r\ny=n-2\r\nj=0\r\nwhile p!=int((n*n-n+2)/2):\r\n if y!=j:\r\n matrix[x][y]=p\r\n matrix[n-1-x][n-1-y]=n*n+1-p\r\n p+=1\r\n y-=1\r\n elif x+y!=n-1:\r\n matrix[x][y]=p\r\n matrix[n-1-x][n-1-y]=n*n+1-p\r\n p+=1\r\n x+=1\r\n elif x+y==n-1:\r\n x=sx+1\r\n y=sy-1\r\n sx+=1\r\n sy-=1\r\n j+=1\r\n\r\n\r\nfor i in range(n):\r\n for j in range(n):\r\n print(matrix[i][j],end=\"\")\r\n if j!=n-1:\r\n print(\" \",end=\"\")\r\n print(\"\\n\",end=\"\")",
"'''\r\nCreated on Aug 24, 2016\r\n\r\n@author: Md. Rezwanul Haque\r\n'''\r\nn = int(input())\r\nc = n//2 + 1\r\n#print(c)\r\nodd = 1\r\neven = 2\r\nfor i in range(1,n+1):\r\n s = \"\"\r\n for j in range(1,n+1):\r\n if abs(c - i) + abs(c - j) <= n//2:\r\n s = s+str(odd) + \" \"\r\n odd += 2 \r\n else:\r\n s = s+str(even) + \" \"\r\n even += 2\r\n print(s)",
"d, n = [-1, 0], int(input())\r\nfor x in range(n):\r\n t = []\r\n for y in range(n):\r\n s = min(abs(x - n // 2), abs(y - n // 2)) & 1\r\n d[s] += 2\r\n t += [d[s]]\r\n print(*t)",
"n = int(input())\r\n\r\ns = [i for i in range(1, n ** 2 + 1)] \r\n\r\n\r\nAns = [[0] * (n) for i in range(n)]\r\n\r\nif n == 1:\r\n print(1)\r\nelse:\r\n Centre = n // 2\r\n Ans[Centre][Centre] = 1\r\n line = 1\r\n \r\n while line < n:\r\n s = [i for i in range(line ** 2 + 1, (line + 2) ** 2 + 1)]\r\n line += 2\r\n \r\n if Ans[Centre - line // 2 + 1][Centre - line // 2 + 1] % 2 == 0:\r\n s = s[1:] + s[:1]\r\n \r\n ind = 0\r\n \r\n for j in range(Centre - line // 2, Centre + 1 + line // 2):\r\n Ans[Centre - line // 2][j] = s[ind]\r\n ind += 1\r\n for i in range(Centre - line // 2 + 1, Centre + 1 + line // 2):\r\n Ans[i][Centre + line // 2] = s[ind]\r\n ind += 1 \r\n for j in range(Centre + line // 2 - 1, Centre - 1 - line // 2, - 1):\r\n Ans[Centre + line // 2][j] = s[ind]\r\n ind += 1 \r\n for i in range(Centre + line // 2 - 1, Centre - line // 2, - 1):\r\n Ans[i][Centre - line // 2] = s[ind]\r\n ind += 1 \r\n \r\n for i in range(n):\r\n print(' '.join(map(str,Ans[i])))\r\n ",
"n = int(input())\r\nk = 1\r\nt = -1\r\ntek_chetn = 2\r\ntek_nechetn = 1\r\nfor x in range(1, n+1):\r\n for y in range(1, n+1):\r\n if y <= (n-k) // 2 or y >= ((n-k) // 2 + k+1):\r\n print(tek_chetn, end = ' ')\r\n tek_chetn += 2\r\n else:\r\n print(tek_nechetn, end = ' ')\r\n tek_nechetn += 2\r\n print()\r\n if k < n and t == -1:\r\n k += 2\r\n else:\r\n t = 1\r\n k -= 2\r\n ",
"n = int(input())\r\na = [[0] * n for _ in range(n)]\r\n\r\nodds = iter(range(1, n ** 2 + 1, 2))\r\nevens = iter(range(2, n ** 2 + 1, 2))\r\n\r\nfor i in range((n + 1) // 2):\r\n for j in range(n):\r\n a[i][j] = next(odds) if i + j >= n // 2 >= j - i else next(evens)\r\n\r\nfor i in range((n + 1) // 2, n):\r\n for j in range(n):\r\n a[i][j] = next(odds) if i - j <= n // 2 and i + j <= (n - 1) + n // 2 else next(evens)\r\n\r\nfor i in range(n):\r\n print(*a[i])\r\n",
"n = int(input())\r\nif n == 1:\r\n print(1)\r\n exit()\r\n\r\nif n == 3:\r\n print(2,1,4)\r\n print(3,5,7)\r\n print(6,9,8)\r\n exit()\r\n\r\nmat = []\r\nplace = []\r\ncnt = 1\r\neven = []\r\nfor i in range(n):\r\n o = []\r\n for j in range(n):\r\n if cnt%2:\r\n place.append(cnt)\r\n\r\n else:\r\n even.append(cnt)\r\n\r\n o.append(0)\r\n cnt += 1\r\n\r\n mat.append(o)\r\n\r\nfor i in range((n//2)+1):\r\n # print(mat)\r\n j = n//2\r\n k = j\r\n cnt = 0\r\n while cnt <= i:\r\n if j == k:\r\n mat[i][k] = place.pop()\r\n\r\n else:\r\n mat[i][k] = place.pop()\r\n mat[i][j] = place.pop()\r\n\r\n k += 1\r\n j -= 1\r\n cnt += 1\r\n\r\n# print(mat)\r\ni = n-1\r\nr = 0\r\nfor q in range((n//2)+1,n):\r\n j = n // 2\r\n k = j\r\n cnt = 0\r\n while cnt <= r:\r\n if j == k:\r\n mat[i][k] = place.pop()\r\n\r\n else:\r\n mat[i][k] = place.pop()\r\n mat[i][j] = place.pop()\r\n\r\n k += 1\r\n j -= 1\r\n cnt += 1\r\n\r\n i -= 1\r\n r += 1\r\n\r\n# print(mat)\r\nfor i in range(n):\r\n for j in range(n):\r\n if mat[i][j] == 0:\r\n mat[i][j] = even.pop()\r\n\r\nfor i in mat:\r\n print(*i)",
"#\n# Joseph Matsushita\n# Problem F\n#\n\nn = int(input())\n\nm = int(n/2)\no = 1\ne = 2\n\nfor i in range(n):\n s = \"\"\n for j in range(n):\n if i+j >= m and i+j <= m+n-1 and abs(i-j) <= m:\n s += str(o) + ' '\n o += 2\n else:\n s += str(e) + ' '\n e += 2\n print(s)\n \t\t\t \t\t\t \t \t\t \t \t \t \t\t \t\t\t\t",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nans = [[-1] * n for _ in range(n)]\r\no = [i for i in range(1, n * n + 1, 2)]\r\ne = [i for i in range(2, n * n + 1, 2)]\r\ncx, cy = n // 2, n // 2\r\nfor i in range(n):\r\n for j in range(n):\r\n if abs(i - cx) + abs(j - cy) <= n // 2:\r\n ans[i][j] = o.pop()\r\n else:\r\n ans[i][j] = e.pop()\r\nfor i in range(n):\r\n print(*ans[i])",
"n=int(input())\r\nmatrix=[[0]*n for i in range(n)]\r\nans=[[0]*n for i in range(n)]\r\na=(n*n)//2\r\nlis=[]\r\nfor i in range(a+1):\r\n lis.append((2*i)+1)\r\nfor i in range(a):\r\n lis.append(2*(i+1))\r\nj=0\r\nx=n//2\r\ny=x+1\r\nfor i in range(n):\r\n if i<=n//2:\r\n for k in range(x,y):\r\n ans[i][k]=lis[j]\r\n matrix[i][k]=1\r\n j+=1\r\n if i!=n//2:\r\n x-=1\r\n y+=1\r\n else:\r\n x+=1\r\n y-=1\r\n for k in range(x,y):\r\n ans[i][k]=lis[j]\r\n matrix[i][k]=1\r\n j+=1\r\nfor i in range(n):\r\n for k in range(n):\r\n if matrix[i][k]==0:\r\n ans[i][k]=lis[j]\r\n j+=1\r\nfor i in range(n):\r\n print(\" \".join(str(x) for x in ans[i]))\r\n ",
"import sys\r\n\r\nn = int(input())\r\nmatrix = [[0]*n for _ in range(n)]\r\nnum = 1\r\nfor i, s, t in zip(range(n), range(n//2, -1, -1), range(n//2+1, n+1)):\r\n for j in range(s, t):\r\n matrix[i][j] = num\r\n num += 2\r\nfor i, s, t in zip(range(n//2+1, n), range(1, n), range(n-1, -1, -1)):\r\n for j in range(s, t):\r\n matrix[i][j] = num\r\n num += 2\r\n\r\nnum = 2\r\nfor i in range(n):\r\n for j in range(n):\r\n if matrix[i][j] == 0:\r\n matrix[i][j] = num\r\n num += 2\r\n\r\nfor row in matrix:\r\n print(*row)\r\n",
"n = int(input())\r\nlst = [[0 for _ in range(n)] for _ in range(n)]\r\nx = n//2\r\ny = 0\r\nfor i in range(1,n*n+1):\r\n lst[y%n][x%n] = i\r\n x+=1\r\n y -= 1\r\n if lst[y%n][x%n]!= 0:\r\n x-=1\r\n y+=2\r\nfor i in lst:\r\n for j in i:\r\n print(j, end=\" \")\r\n print()",
"n = int(input())\r\nanswer = [[0] * n] * n\r\n\r\neven = []\r\nnot_even = []\r\n\r\nfor i in range(1, n ** 2 + 1):\r\n if i % 2 == 0:\r\n even.append(i)\r\n else:\r\n not_even.append(i)\r\n\r\nlevels = [(0, 0)] * n\r\n\r\nif n == 1:\r\n print(1)\r\nelse:\r\n for i in range(n):\r\n if i > n // 2:\r\n middle_r = levels[n - i - 1][1]\r\n middle_l = levels[n - i - 1][0]\r\n else:\r\n middle_r = max(n // 2 + i, n // 2 - i)\r\n middle_l = min(n // 2 - i, n // 2 + i)\r\n levels[i] = (middle_l, middle_r)\r\n for j in range(n):\r\n if middle_r >= j >= middle_l:\r\n print(not_even.pop(len(not_even) - 1), end=' ')\r\n else:\r\n print(even.pop(len(even) - 1), end=' ')\r\n print('\\n')",
"n = int(input())\r\nit = n//2\r\nn1,n2 = 1,2\r\nfor i in range(n):\r\n for j in range(n):\r\n if j >= it and j <= n-it-1:\r\n print(n1,end = ' ')\r\n n1+=2;\r\n else:\r\n print(n2, end = ' ')\r\n n2+=2\r\n if i < n/2-1:\r\n it-=1\r\n else:\r\n it+=1\r\n print()\r\n\"\"\"\r\nfor i in A:\r\n for j in i:\r\n print(j,end = ' ')\r\n print()\r\n\"\"\"\r\n",
"n=int(input())\r\nm=n>>1\r\na=1\r\nb=2\r\nfor x in range(n):\r\n\tl=abs(m-x)\r\n\tr=n-l\r\n\tfor y in range(l):\r\n\t\tprint(b,end=' ')\r\n\t\tb+=2\r\n\tfor y in range(l,r):\r\n\t\tprint(a,end=' 'if n-1>y else'\\n')\r\n\t\ta+=2\r\n\tfor y in range(r,n):\r\n\t\tprint(b,end=' 'if n-1>y else'\\n')\r\n\t\tb+=2",
"from math import *\n\nn = int(input())\nnn = 1\nnc = 2\na = []\nfor i in range(n):\n a.append([0] * n)\n for q in range(n):\n #print(i, q, (n - 1) // 2 - i + (n - 1) // 2 - q)\n if abs((n - 1) // 2 - i) + abs((n - 1) // 2 - q) <= (n - 1) // 2:\n a[i][q] = nn\n nn += 2\n else:\n a[i][q] = nc\n nc += 2\nfor i in range(n):\n print(*a[i])\n",
"from decimal import Decimal, getcontext, MAX_PREC\r\nfrom itertools import combinations, permutations\r\nfrom fractions import Fraction\r\nimport datetime\r\nimport itertools\r\nimport random\r\nimport collections\r\nimport string\r\nimport math\r\nimport copy\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\n\r\n\r\ndef input(): return sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\n\"\"\"\r\nfrom dataclasses import dataclass\r\n\r\n@dataclass\r\nclass point:\r\n x: float\r\n y: float\r\n \r\n \r\n@dataclass\r\nclass line:\r\n A: float\r\n B: float\r\n C: float\r\n \r\n def gety(self, x):\r\n return (self.A*x+self.C)/-self.B\r\n \r\n def getx(self, y):\r\n return (self.B*y+self.C)/-self.A\r\n \r\n def k(self):\r\n return -self.A/self.B\r\n \r\n def b(self):\r\n return -self.C/self.B\r\n \r\n def dist(self, p: point):\r\n return abs((self.A*p.x+self.B*p.y+self.C)/(self.A**2+self.B**2)**0.5)\r\n \r\n \r\ndef calc_line(u: point, v: point):\r\n return line(A=u.y-v.y, B=v.x-u.x, C=u.y*(u.x-v.x)-u.x*(u.y-v.y))\r\n \r\n \r\ndef is_parallel(u: line, v: line) -> bool:\r\n f1 = False\r\n f2 = False\r\n try:\r\n k1 = u.k()\r\n except:\r\n f1 = True\r\n try:\r\n k2 = v.k()\r\n except:\r\n f2 = True\r\n if f1 != f2:\r\n return False\r\n return f1 or k1 == k2\r\n \r\n \r\ndef seg_len(_from: point, _to: point):\r\n return ((_from.x - _to.x)**2 + (_from.y - _to.y)**2) ** 0.5\r\n \r\ndef in_range(_from: point, _to: point, _point: point) -> bool:\r\n if _from.x < _to.x:\r\n if _from.y < _to.y:\r\n return _from.x <= _point.x <= _to.x and _from.y <= _point.y <= _to.y\r\n else:\r\n return _from.x <= _point.x <= _to.x and _from.y >= _point.y >= _to.y\r\n else:\r\n if _from.y < _to.y:\r\n return _from.x >= _point.x >= _to.x and _from.y <= _point.y <= _to.y\r\n else:\r\n return _from.x >= _point.x >= _to.x and _from.y >= _point.y >= _to.y\r\n \r\ndef intersect(u: line, v: line) -> point:\r\n tx = (u.B*v.C-v.B*u.C)/(v.B*u.A-u.B*v.A)\r\n if u.B!=0.0:\r\n ty = -u.A*tx/u.B - u.C/u.B\r\n else:\r\n ty = -v.A*tx/v.B - v.C/v.B\r\n return point(x=tx, y=ty)\r\n \r\ndef in_direction(_from: point, _to: point, _point: point) -> bool:\r\n if _from.x < _to.x:\r\n if _from.y < _to.y:\r\n return _to.x < _point.x and _to.y < _point.y\r\n else:\r\n return _to.x < _point.x and _point.y <= _to.y\r\n else:\r\n if _from.y < _to.y:\r\n return _to.x >= _point.x and _to.y < _point.y\r\n else:\r\n return _to.x >= _point.x and _point.y <= _to.y\r\n\r\n\r\n\"\"\"\r\nmo = int(1e9+7)\r\n\r\n\r\ndef exgcd(a, b):\r\n if not b:\r\n return 1, 0\r\n y, x = exgcd(b, a % b)\r\n y -= a//b * x\r\n return x, y\r\n\r\n\r\ndef getinv(a, m):\r\n x, y = exgcd(a, m)\r\n return -1 if x == 1 else x % m\r\n\r\n\r\ndef comb(n, b):\r\n res = 1\r\n b = min(b, n-b)\r\n for i in range(b):\r\n res = res*(n-i)*getinv(i+1, mo) % mo\r\n # res %= mo\r\n return res % mo\r\n\r\n\r\ndef quickpower(a, n):\r\n res = 1\r\n while n:\r\n if n & 1:\r\n res = res * a % mo\r\n n >>= 1\r\n a = a*a % mo\r\n return res\r\n\r\n\r\ndef dis(a, b):\r\n return abs(a[0]-b[0]) + abs(a[1]-b[1])\r\n\r\n\r\ndef getpref(x):\r\n if x > 1:\r\n return (x)*(x-1) >> 1\r\n else:\r\n return 0\r\n\r\n\r\ndef orafli(upp):\r\n primes = []\r\n marked = [False for i in range(upp+3)]\r\n prvs = [i for i in range(upp+3)]\r\n for i in range(2, upp):\r\n if not marked[i]:\r\n primes.append(i)\r\n for j in primes:\r\n if i*j >= upp:\r\n break\r\n marked[i*j] = True\r\n prvs[i*j] = j\r\n if i % j == 0:\r\n break\r\n return primes, prvs\r\n\r\n\r\ndef lower_ord(c: str) -> int:\r\n return ord(c)-97\r\n\r\n\r\ndef upper_ord(c: str) -> int:\r\n return ord(c) - 65\r\n\r\n\r\ndef read_list():\r\n return [int(i) for i in input().split()]\r\n\r\n\r\ndef read_int():\r\n s = input().split()\r\n if len(s) == 1:\r\n return int(s[0])\r\n else:\r\n return map(int, s)\r\n\r\n\r\ndef ask(s):\r\n print(f\"? {s}\", flush=True)\r\n\r\n\r\ndef answer(s):\r\n print(f\"{s}\", flush=True)\r\n\r\n\r\ndef lowbit(x):\r\n return x & -x\r\n\r\n\r\ngetcontext().prec = 50\r\n\r\n\r\ndef solve():\r\n n = read_int()\r\n mat = [\r\n [0 for i in range(n)]\r\n for j in range(n)\r\n ]\r\n pos = [0, n>>1]\r\n for i in range(n):\r\n for j in range(n):\r\n mat[(pos[0]+2*i-j)%n][(pos[1]-i+j)%n] = i*n+j+1\r\n # mat[n+1>>1] = 1\r\n # print(mat)\r\n for i in mat:\r\n print(*i)\r\n\r\n\r\n# fi = open('C:\\\\cppHeaders\\\\CF2020.12.17\\\\test.data', 'r')\r\n# def input(): return fi.readline().rstrip(\"\\r\\n\")\r\n# primes, prv = orafli(10001)\r\n# t = int(input())\r\n\r\nt = 1\r\n# solve()\r\n\r\nfor ti in range(t):\r\n # print(f\"Case #{ti+1}: \", end='')\r\n solve()\r\n\r\n\"\"\"\r\n1\r\n\r\n\"\"\"\r\n",
"mat = []\r\nn = int(input())\r\nfor i in range(n):\r\n mat.append([\" \"]*n)\r\nk = n//2\r\nfor i in range(n//2-1, -1, -1):\r\n for j in range(i, 0, -1):\r\n mat[n//2-i-1][j-1] = \"O\"\r\n for j in range(n//2-i):\r\n mat[n//2-i-1][i+j] = \"E\"\r\n mat[n//2-i-1][n//2] = \"O\"\r\n for j in range(n//2-i):\r\n mat[n//2-i-1][n//2+j+1] = \"E\"\r\n for j in range(i):\r\n mat[n//2-i-1][n-1-j] = \"O\"\r\nmat[k] = [\"O\"]*n\r\nfor i in range(n//2):\r\n for j in range(i, 0, -1):\r\n mat[n//2+i+1][j-1] = \"O\"\r\n for j in range(n//2-i):\r\n mat[n//2+i+1][i+j] = \"E\"\r\n mat[n//2+i+1][n//2] = \"O\"\r\n for j in range(n//2-i):\r\n mat[n//2+i+1][n//2+j+1] = \"E\"\r\n for j in range(i):\r\n mat[n//2+i+1][n-1-j] = \"O\"\r\no = 1\r\ne = 2\r\nfor i in range(n):\r\n for j in range(n):\r\n if mat[i][j] == \"O\":\r\n mat[i][j] = o\r\n o += 2\r\n else:\r\n mat[i][j] = e\r\n e += 2\r\nfor i in range(n):\r\n for j in range(n):\r\n print(mat[i][j], end=\" \")\r\n print()\r\n",
"from collections import defaultdict\r\nimport sys\r\n\r\nif __name__ == \"__main__\":\r\n #n, m = list(map(int, input().split()))\r\n n = int(input())\r\n table = [[0] * 100 for _ in range(100)]\r\n i, j = 0, n // 2\r\n for num in range(1, n * n + 1):\r\n table[i][j] = num\r\n if table[(i - 1 + n) % n][(j + 1 + n) % n] == 0:\r\n i = (i - 1 + n) % n\r\n j = (j + 1 + n) % n\r\n else:\r\n i = (i + 1 + n) % n \r\n for i in range(n):\r\n print(' '.join([str(j) for j in table[i][:n]]))\r\n ",
"\r\ndef ind (i, j, len) :\r\n mid = int(len / 2)\r\n if(mid == i or mid == j):\r\n return 1\r\n if(i < mid):\r\n if(j < mid):\r\n if(j >= i):\r\n return 0\r\n else:\r\n return 1\r\n elif(i + j >= len):\r\n return 1\r\n else:\r\n return 0\r\n elif(j < mid):\r\n if (i + j + 1 >= len):\r\n return 0\r\n else:\r\n return 1\r\n else:\r\n if(j > i):\r\n return 1\r\n else:\r\n return 0\r\n\r\nlen = int(input())\r\n\r\nevn = 1;\r\nodd = 2;\r\n\r\nfor i in range(len):\r\n str1 = \"\";\r\n for j in range(len):\r\n if( ind(i, j, len) == 1):\r\n str1 += str(evn) + \" \"\r\n evn += 2\r\n else:\r\n str1 += str(odd) + \" \"\r\n odd += 2\r\n print(str1)\r\n\r\n\r\n",
"n=int(input())\r\nmxc=((n*n+1)//2-(2*n-1))//4\r\nm=[]\r\nfor i in range(n):\r\n\tl=[0]*n\r\n\tm.append(l)\r\nodd=1\r\ni=n//2\r\nj=0\r\nwhile(j<n):\r\n\tm[i][j]=odd\r\n\tj+=1\r\n\todd+=2\r\nj=0\r\nwhile(j<n):\r\n\tif i==j:\r\n\t\tj+=1\r\n\t\tcontinue\r\n\tm[j][i]=odd\r\n\tj+=1\r\n\todd+=2\r\ni=0\r\nj=0\r\nc=0\r\nwhile(c<mxc):\r\n\tc+=1\r\n\tm[i][j]=odd\r\n\todd+=2\r\n\tm[i][n-1-j]=odd\r\n\todd+=2\r\n\tm[n-1-i][j]=odd\r\n\todd+=2\r\n\tm[n-i-1][n-1-j]=odd\r\n\todd+=2\r\n\tj+=1\r\n\tif j==n//2:\r\n\t\tj=0\r\n\t\ti+=1\r\neven=2\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tif m[i][j]==0:\r\n\t\t\tm[i][j]=even\r\n\t\t\teven+=2\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tprint(m[i][j],end=\" \")\r\n\tprint()\r\n\r\n",
"a = int(input())\r\n\r\nodd = 1\r\neven = 2\r\nc = a//2\r\n\r\nl = [[] for x in range(a)]\r\n\r\nfor row in range(0, a):\r\n for col in range(0, a):\r\n if c <= col <= a - 1 - c:\r\n l[row].append(odd)\r\n odd += 2\r\n else:\r\n l[row].append(even)\r\n even += 2\r\n\r\n if row < a//2:\r\n c -= 1\r\n else:\r\n c += 1\r\n\r\nfor row in l:\r\n print(\" \".join(list(map(str, row))))",
"n = int(input())\r\nmx = [[0 for x in range(n)] for y in range(n)]\r\nxx = 0\r\nyy = (n-1) // 2 \r\nfor i in range(1,n*n+1):\r\n\tif mx[xx][yy] == 0:\r\n\t\tmx[xx][yy] = i\r\n\telse:\r\n\t\tyy = (yy-1) %n\r\n\t\txx = (xx+2) %n\r\n\t\tmx[xx][yy] = i\r\n\tyy = (yy+1) %n\r\n\txx = (xx-1) %n\r\nfor i in range(n):\r\n\tfor j in range(n-1):\r\n\t\tprint(mx[i][j], end = \" \")\r\n\tprint(mx[i][n-1])",
"n = int(input())\r\nA = [[0]*n for i in range(n)]\r\n\r\nc = n//2\r\n\r\nfor i in range(n):\r\n for j in range(n):\r\n if abs(i-c)+abs(j-c) <= c:\r\n A[i][j] = 1\r\n\r\ne, o = 2, 1\r\nfor i in range(n):\r\n for j in range(n):\r\n if A[i][j] == 1:\r\n A[i][j] = o\r\n o += 2\r\n else:\r\n A[i][j] = e\r\n e += 2\r\n\r\nfor i in range(n):\r\n print(*A[i])\r\n",
"def matrix(k):\r\n\tfor i in range(len(k)):\r\n\t\tfor j in range(len(k[i])):\r\n\t\t\tprint(k[i][j],end=' ')\r\n\t\tprint(\"\\n\",end='')\r\nn=int(input())\r\nl = [[0]*n for _ in range(n)]\r\ns=1;\r\nx=int((n+1)/2)\r\ny=int((n-1)/2)\r\nfor j in range(x):\r\n\tfor i in range(y-j,y+j+1,1):\r\n\t\tl[i][j]=s\r\n\t\ts+=2\r\nfor j in range(x,n,1):\r\n\tfor i in range(j-x+1,x-j+n-2+1,1):\r\n\t\tl[i][j]=s\r\n\t\ts+=2\r\ns=2\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tif l[i][j]==0:\r\n\t\t\tl[i][j]=s\r\n\t\t\ts+=2\r\nmatrix(l)",
"q,n=[-1, 0],int(input())\r\nfor i in range(n):\r\n r=\"\"\r\n for j in range(n):\r\n k=min(abs(i-n//2),abs(j-n//2))%2\r\n q[k]+=2\r\n r+=str(q[k])+\" \"\r\n print(r)",
"a = int(input())\r\nlist = []\r\nfor i in range (a):\r\n list.append([0]*a)\r\nit = [int(a / 2), 0]\r\nlist[it[0]][it[1]] = 1\r\nfor i in range(2, a ** 2 + 1):\r\n if list[(it[0] + 1) % a][(it[1] - 1) % a] == 0:\r\n list[(it[0] + 1) % a][(it[1] - 1) % a] = i\r\n it[0] = (it[0] + 1) % a\r\n it[1] = (it[1] - 1) % a\r\n else:\r\n list[it[0]][(it[1] + 1) % a] = i\r\n it[1] = (it[1] + 1) % a\r\nfor i in range(a):\r\n for j in range(a):\r\n print(list[i][j],end=\" \")\r\n print(\"\")\r\n",
"n = eval(input())\nlst = [[None]*n for i in range(n)]\nrow = 0\ncol = int((n-1)/2)\nfor i in range(1,n**2+1):\n if lst[row][col] == None:\n lst[row][col] = i\n else:\n row += 2\n col -= 1\n if row > (n-1) :row-=n\n if col == -1:col+=n\n lst[row][col] = i\n row -= 1\n col += 1\n if row == -1:row +=n\n if col == n :col -=n\nfor i in lst:\n for j in i:\n print(j,end='\\t')\n print()\n \t\t\t\t \t\t\t\t \t\t \t\t\t\t\t \t\t\t\t\t\t\t",
"n = int(input())\nnn = n**2\nEs = [2*i for i in range(1,nn//2+1)]\nOs = [2*i + 1 for i in range(nn//2+1)]\n\nk = n//2\nfor i in range(n//2):\n o = [str(Es.pop()) for i in range(k)] + [str(Os.pop()) for q in range(n-2*k)] + [str(Es.pop()) for i in range(k)]\n print(' '.join(o))\n k-=1\nprint(' '.join([str(Os.pop()) for i in range(n)]))\nfor i in range(n//2):\n k+=1\n o = [str(Es.pop()) for i in range(k)] + [str(Os.pop()) for q in range(n-2*k)] + [str(Es.pop()) for i in range(k)]\n print(' '.join(o))\n\n \t \t\t \t \t\t\t\t\t \t \t\t",
"n = int(input())\nif n==1:\n print(1)\n exit()\n\nodd = 1\nevn = 2\n\n\n\ntable = [[0 for i in range(n)] for i in range(n)]\n\n#(x,y) x row, y col\nfor x in range(n):\n for y in range(n):\n x1 = min(x, n-1-x)\n if y < (n - 1)/2-x1 or y > (n - 1)/2+x1: #even con\n table[x][y] = evn\n evn += 2\n else:\n table[x][y] = odd\n odd += 2\n\nfor x in table:\n for y in x:\n print(y, end=\" \")\n print()\n\n \t\t \t \t \t \t \t\t\t \t \t\t\t \t\t"
] | {"inputs": ["1", "3", "5", "7", "9", "11", "13", "15", "17", "19", "21", "23", "25", "27", "29", "31", "33", "35", "37", "39", "41", "43", "45", "47", "49"], "outputs": ["1", "2 1 4\n3 5 7\n6 9 8", "2 4 1 6 8\n10 3 5 7 12\n9 11 13 15 17\n14 19 21 23 16\n18 20 25 22 24", "2 4 6 1 8 10 12\n14 16 3 5 7 18 20\n22 9 11 13 15 17 24\n19 21 23 25 27 29 31\n26 33 35 37 39 41 28\n30 32 43 45 47 34 36\n38 40 42 49 44 46 48", "2 4 6 8 1 10 12 14 16\n18 20 22 3 5 7 24 26 28\n30 32 9 11 13 15 17 34 36\n38 19 21 23 25 27 29 31 40\n33 35 37 39 41 43 45 47 49\n42 51 53 55 57 59 61 63 44\n46 48 65 67 69 71 73 50 52\n54 56 58 75 77 79 60 62 64\n66 68 70 72 81 74 76 78 80", "2 4 6 8 10 1 12 14 16 18 20\n22 24 26 28 3 5 7 30 32 34 36\n38 40 42 9 11 13 15 17 44 46 48\n50 52 19 21 23 25 27 29 31 54 56\n58 33 35 37 39 41 43 45 47 49 60\n51 53 55 57 59 61 63 65 67 69 71\n62 73 75 77 79 81 83 85 87 89 64\n66 68 91 93 95 97 99 101 103 70 72\n74 76 78 105 107 109 111 113 80 82 84\n86 88 90 92 115 117 119 94 96 98 100\n102 104 106 108 110 121 112 114 116 118 120", "2 4 6 8 10 12 1 14 16 18 20 22 24\n26 28 30 32 34 3 5 7 36 38 40 42 44\n46 48 50 52 9 11 13 15 17 54 56 58 60\n62 64 66 19 21 23 25 27 29 31 68 70 72\n74 76 33 35 37 39 41 43 45 47 49 78 80\n82 51 53 55 57 59 61 63 65 67 69 71 84\n73 75 77 79 81 83 85 87 89 91 93 95 97\n86 99 101 103 105 107 109 111 113 115 117 119 88\n90 92 121 123 125 127 129 131 133 135 137 94 96\n98 100 102 139 141 143 145 147 149 151 104 106 108\n110 112 114 116 153 155 157 159 161 118 120 122 124\n126 128 130 132 134 163 165 167 136 ...", "2 4 6 8 10 12 14 1 16 18 20 22 24 26 28\n30 32 34 36 38 40 3 5 7 42 44 46 48 50 52\n54 56 58 60 62 9 11 13 15 17 64 66 68 70 72\n74 76 78 80 19 21 23 25 27 29 31 82 84 86 88\n90 92 94 33 35 37 39 41 43 45 47 49 96 98 100\n102 104 51 53 55 57 59 61 63 65 67 69 71 106 108\n110 73 75 77 79 81 83 85 87 89 91 93 95 97 112\n99 101 103 105 107 109 111 113 115 117 119 121 123 125 127\n114 129 131 133 135 137 139 141 143 145 147 149 151 153 116\n118 120 155 157 159 161 163 165 167 169 171 173 175 122 124\n126 128 1...", "2 4 6 8 10 12 14 16 1 18 20 22 24 26 28 30 32\n34 36 38 40 42 44 46 3 5 7 48 50 52 54 56 58 60\n62 64 66 68 70 72 9 11 13 15 17 74 76 78 80 82 84\n86 88 90 92 94 19 21 23 25 27 29 31 96 98 100 102 104\n106 108 110 112 33 35 37 39 41 43 45 47 49 114 116 118 120\n122 124 126 51 53 55 57 59 61 63 65 67 69 71 128 130 132\n134 136 73 75 77 79 81 83 85 87 89 91 93 95 97 138 140\n142 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 144\n129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161...", "2 4 6 8 10 12 14 16 18 1 20 22 24 26 28 30 32 34 36\n38 40 42 44 46 48 50 52 3 5 7 54 56 58 60 62 64 66 68\n70 72 74 76 78 80 82 9 11 13 15 17 84 86 88 90 92 94 96\n98 100 102 104 106 108 19 21 23 25 27 29 31 110 112 114 116 118 120\n122 124 126 128 130 33 35 37 39 41 43 45 47 49 132 134 136 138 140\n142 144 146 148 51 53 55 57 59 61 63 65 67 69 71 150 152 154 156\n158 160 162 73 75 77 79 81 83 85 87 89 91 93 95 97 164 166 168\n170 172 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 174 176\n178...", "2 4 6 8 10 12 14 16 18 20 1 22 24 26 28 30 32 34 36 38 40\n42 44 46 48 50 52 54 56 58 3 5 7 60 62 64 66 68 70 72 74 76\n78 80 82 84 86 88 90 92 9 11 13 15 17 94 96 98 100 102 104 106 108\n110 112 114 116 118 120 122 19 21 23 25 27 29 31 124 126 128 130 132 134 136\n138 140 142 144 146 148 33 35 37 39 41 43 45 47 49 150 152 154 156 158 160\n162 164 166 168 170 51 53 55 57 59 61 63 65 67 69 71 172 174 176 178 180\n182 184 186 188 73 75 77 79 81 83 85 87 89 91 93 95 97 190 192 194 196\n198 200 202 99 101 103 ...", "2 4 6 8 10 12 14 16 18 20 22 1 24 26 28 30 32 34 36 38 40 42 44\n46 48 50 52 54 56 58 60 62 64 3 5 7 66 68 70 72 74 76 78 80 82 84\n86 88 90 92 94 96 98 100 102 9 11 13 15 17 104 106 108 110 112 114 116 118 120\n122 124 126 128 130 132 134 136 19 21 23 25 27 29 31 138 140 142 144 146 148 150 152\n154 156 158 160 162 164 166 33 35 37 39 41 43 45 47 49 168 170 172 174 176 178 180\n182 184 186 188 190 192 51 53 55 57 59 61 63 65 67 69 71 194 196 198 200 202 204\n206 208 210 212 214 73 75 77 79 81 83 85 87 89 ...", "2 4 6 8 10 12 14 16 18 20 22 24 1 26 28 30 32 34 36 38 40 42 44 46 48\n50 52 54 56 58 60 62 64 66 68 70 3 5 7 72 74 76 78 80 82 84 86 88 90 92\n94 96 98 100 102 104 106 108 110 112 9 11 13 15 17 114 116 118 120 122 124 126 128 130 132\n134 136 138 140 142 144 146 148 150 19 21 23 25 27 29 31 152 154 156 158 160 162 164 166 168\n170 172 174 176 178 180 182 184 33 35 37 39 41 43 45 47 49 186 188 190 192 194 196 198 200\n202 204 206 208 210 212 214 51 53 55 57 59 61 63 65 67 69 71 216 218 220 222 224 226 228\n...", "2 4 6 8 10 12 14 16 18 20 22 24 26 1 28 30 32 34 36 38 40 42 44 46 48 50 52\n54 56 58 60 62 64 66 68 70 72 74 76 3 5 7 78 80 82 84 86 88 90 92 94 96 98 100\n102 104 106 108 110 112 114 116 118 120 122 9 11 13 15 17 124 126 128 130 132 134 136 138 140 142 144\n146 148 150 152 154 156 158 160 162 164 19 21 23 25 27 29 31 166 168 170 172 174 176 178 180 182 184\n186 188 190 192 194 196 198 200 202 33 35 37 39 41 43 45 47 49 204 206 208 210 212 214 216 218 220\n222 224 226 228 230 232 234 236 51 53 55 57 59 61...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 1 30 32 34 36 38 40 42 44 46 48 50 52 54 56\n58 60 62 64 66 68 70 72 74 76 78 80 82 3 5 7 84 86 88 90 92 94 96 98 100 102 104 106 108\n110 112 114 116 118 120 122 124 126 128 130 132 9 11 13 15 17 134 136 138 140 142 144 146 148 150 152 154 156\n158 160 162 164 166 168 170 172 174 176 178 19 21 23 25 27 29 31 180 182 184 186 188 190 192 194 196 198 200\n202 204 206 208 210 212 214 216 218 220 33 35 37 39 41 43 45 47 49 222 224 226 228 230 232 234 236 238 240\n242 244 2...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 1 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60\n62 64 66 68 70 72 74 76 78 80 82 84 86 88 3 5 7 90 92 94 96 98 100 102 104 106 108 110 112 114 116\n118 120 122 124 126 128 130 132 134 136 138 140 142 9 11 13 15 17 144 146 148 150 152 154 156 158 160 162 164 166 168\n170 172 174 176 178 180 182 184 186 188 190 192 19 21 23 25 27 29 31 194 196 198 200 202 204 206 208 210 212 214 216\n218 220 222 224 226 228 230 232 234 236 238 33 35 37 39 41 43 45 47 49 240 242 244 24...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 1 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64\n66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 3 5 7 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124\n126 128 130 132 134 136 138 140 142 144 146 148 150 152 9 11 13 15 17 154 156 158 160 162 164 166 168 170 172 174 176 178 180\n182 184 186 188 190 192 194 196 198 200 202 204 206 19 21 23 25 27 29 31 208 210 212 214 216 218 220 222 224 226 228 230 232\n234 236 238 240 242 244 246 248 250 252 254 256 33 35...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 1 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68\n70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 3 5 7 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132\n134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 9 11 13 15 17 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192\n194 196 198 200 202 204 206 208 210 212 214 216 218 220 19 21 23 25 27 29 31 222 224 226 228 230 232 234 236 238 240 242 244 246 248\n250 252 254 256 258 2...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 1 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72\n74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 3 5 7 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140\n142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 9 11 13 15 17 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204\n206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 19 21 23 25 27 29 31 236 238 240 242 244 246 248 250 252 254 256 258 26...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 1 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76\n78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 3 5 7 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148\n150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 9 11 13 15 17 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216\n218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 19 21 23 25 27 29 31 250 252 254 256 258 26...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 1 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80\n82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 3 5 7 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156\n158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 9 11 13 15 17 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228\n230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 19 21 23 25 27 ...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 1 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84\n86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 3 5 7 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164\n166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 9 11 13 15 17 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 234 236 238 240\n242 244 246 248 250 252 254 256 258 260 262 264 266 268 270...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 1 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88\n90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 3 5 7 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172\n174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 9 11 13 15 17 214 216 218 220 222 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252\n254 256 258 260 262 264 266 268 270...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 1 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92\n94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 3 5 7 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180\n182 184 186 188 190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 9 11 13 15 17 224 226 228 230 232 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264\n266 268 270...", "2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 1 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96\n98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 3 5 7 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188\n190 192 194 196 198 200 202 204 206 208 210 212 214 216 218 220 222 224 226 228 230 232 9 11 13 15 17 234 236 238 240 242 244 246 248 250 252 254 256 258 260 262 264 266 268 270 ..."]} | UNKNOWN | PYTHON3 | CODEFORCES | 52 | |
31f82a93c86ffaf724da238d322c7f70 | Periodical Numbers | A non-empty string *s* is called binary, if it consists only of characters "0" and "1". Let's number the characters of binary string *s* from 1 to the string's length and let's denote the *i*-th character in string *s* as *s**i*.
Binary string *s* with length *n* is periodical, if there is an integer 1<=≤<=*k*<=<<=*n* such that:
- *k* is a divisor of number *n* - for all 1<=≤<=*i*<=≤<=*n*<=-<=*k*, the following condition fulfills: *s**i*<==<=*s**i*<=+<=*k*
For example, binary strings "101010" and "11" are periodical and "10" and "10010" are not.
A positive integer *x* is periodical, if its binary representation (without leading zeroes) is a periodic string.
Your task is to calculate, how many periodic numbers are in the interval from *l* to *r* (both ends are included).
The single input line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018). The numbers are separated by a space.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print a single integer, showing how many periodic numbers are in the interval from *l* to *r* (both ends are included).
Sample Input
1 10
25 38
Sample Output
3
2
| [
"from itertools import combinations\r\nfrom fractions import gcd\r\n\r\n#Numeros primos hasta el 59\r\nprimos = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59]\r\n\r\n#Para obtener la cadena binaria de x.\r\ndef ToBinary(x):\r\n if x == 0:\r\n return \"0\"\r\n if x == 1:\r\n return \"1\"\r\n if x % 2 == 0:\r\n return ToBinary(x>>1)+ \"0\"\r\n else:\r\n return ToBinary(x>>1)+ \"1\"\r\n\r\n#Obtiene la cantidad de numeros periodicos con longitud de cadena binaria\r\n#igual a \"length\".\r\ndef CountPeriodic(length):\r\n #Contiene los numeros primos que dividen a \"length\".\r\n p = [x for x in primos if length % x == 0]\r\n ans = 0\r\n for x in p:\r\n #\"d\" cantidad de repeticiones en las variaciones de \"0\" y \"1\", y \"x\" cantidad de subcadenas.\r\n d = length/x\r\n #Se agrega a la respuesta la cantidad de variaciones de \"0\" y \"1\" con \"d-1\" repeticiones\r\n #porque el primer elemento siempre es \"1\".\r\n ans += 2**(d-1)\r\n for x,y in combinations(p,2):\r\n #Se calcula el mcd de todos los primos 2 a 2.\r\n d = gcd(length/x, length/y)\r\n #Se elimina de la respuesta el total de variaciones con cantidad de repeticiones igual al\r\n #\"mcd -1\", mcd de dos primos diferentes dichas variaciones se contaron doble, es decir,\r\n #una vez por cada uno de los primos.\r\n ans -= 2**(d-1)\r\n for x,y,z in combinations(p,3):\r\n d = gcd(gcd(length/x, length/y), length/z)\r\n #Aplicando el principio de inclusion-exclusion, si en el paso anterior se sustrajo\r\n #el total de variaciones de \"0\" y \"1\" con cantidad de repeticiones asociadas al mismo mcd de tres primos distintos, significa que se quitaron\r\n #dos veces, luego se debe agregar a la respuesta la cardinalidad del conjunto de esas\r\n #variaciones (solo una vez).\r\n ans += 2**(d-1)\r\n return ans\r\n\r\n#Chequea las variaciones para las cadenas binarias cuyos numeros son mayores o iguales\r\n#que el de la cadena \"l\".\r\ndef L(l,x,d):\r\n ans = 0\r\n d = int(d)\r\n x = int(x)\r\n p = 1\r\n while True:\r\n #\"q\" es la posicion de \"0\" en el substring \"l[p:d]\".\r\n q = l[p:d].find('0')\r\n if q == -1:\r\n break\r\n #Se añade a la respuesta el total de variacines de \"0\" y \"1\" con \"d\" repeticiones, pero con todas las\r\n #posiciones fijadas desde la primera hasta la del \"p\"-esimo \"0\" encontrado en el substring.\r\n ans += 2**(d-(p+q)-1)\r\n p += q+1\r\n\r\n for k in range(1,x):\r\n #Si todos los digitos en el substring \"l[0:d]\" son mayores que los del siguente k substring, se debe\r\n #aumentar la respuesta en 1 porque es posible crear una cadena binaria de periodo \"x\" con \"l[0:d]\". \r\n if l[0:d] > l[d*k:d*(k+1)]:\r\n return ans+1 \r\n elif l[0:d] == l[d*k:d*(k+1)]:\r\n continue\r\n else:\r\n #No es posible obtener una cadena binaria de periodo \"x\" con \"l[0:d]\". \r\n return ans\r\n #Si el programa llega hasta aqui implica que todos los substring son iguales\r\n #por tanto la cadena binaria pertenece a un numero periodico entonces hay que\r\n #aumentar la respuesta en 1.\r\n return ans+1\r\n\r\ndef CountPeriodicL(l):\r\n length = len(l)\r\n p = [x for x in primos if length % x == 0]\r\n ans = 0\r\n for x in p:\r\n d = length/x\r\n ans += L(l,x,d)\r\n for x,y in combinations(p,2):\r\n d = gcd(length/x, length/y) \r\n ans -= L(l,length/d,d)\r\n for x,y,z in combinations(p,3):\r\n d = gcd(gcd(length/x, length/y), length/z)\r\n ans += L(l,length/d,d)\r\n return ans\r\n\r\n\r\n#Chequea las variaciones para las cadenas binarias cuyos numeros son menores o iguales\r\n#que el de la cadena \"r\".\r\ndef R(r,x,d,eq=False):\r\n ans = 0\r\n d = int(d)\r\n x = int(x)\r\n p = 1\r\n while True: \r\n q = r[p:d].find('1')\r\n if q == -1:\r\n break\r\n ans += 2**(d-(p+q)-1)\r\n p += q+1\r\n for k in range(1,x):\r\n if r[0:d] < r[d*k:d*(k+1)]:\r\n return ans+1\r\n elif r[0:d] == r[d*k:d*(k+1)]:\r\n continue\r\n else:\r\n return ans\r\n return ans+(1 if not eq else 0)\r\n\r\ndef CountPeriodicR(r,eq=False):\r\n length = len(r)\r\n p = [x for x in primos if length % x == 0]\r\n ans = 0\r\n for x in p:\r\n d = length/x\r\n ans += R(r,x,d,eq)\r\n for x,y in combinations(p,2):\r\n d = gcd(length/x, length/y) \r\n ans -= R(r,length/d,d,eq)\r\n for x,y,z in combinations(p,3):\r\n d = gcd(gcd(length/x, length/y), length/z)\r\n ans += R(r,length/d,d,eq)\r\n return ans\r\n\r\n\r\n\r\nl,r = map(int,input().split())\r\n\r\nl_binary = ToBinary(l)\r\nr_binary = ToBinary(r)\r\n\r\nans = 0\r\n\r\n#Chequea la cantidad de numeros periodicos cuya longitud de cadena binaria se encuentra en el\r\n#interior del intervalo conformado por las longitudes de las cadenas binaras de los numeros del intervalo del\r\n#ejercicio.\r\nfor i in range(len(l_binary)+1,len(r_binary)): \r\n ans += CountPeriodic(i)\r\n\r\n#Chequea la cantidad de numeros periodicos con longitud de cadenas binarias igual a la de los extremos\r\n#del intervalo del ejercicio, en el caso del extremo izquierdo solo se calculan aquellos numeros mayores o\r\n#iguales a \"l\", y en el caso del derecho los menores o iguales a \"r\".\r\nif len(l_binary)==len(r_binary):\r\n ans += CountPeriodicR(r_binary)\r\n ans -= CountPeriodicR(l_binary,True)\r\nelse:\r\n ans += CountPeriodicL(l_binary)\r\n ans += CountPeriodicR(r_binary)\r\n\r\n\r\nprint(int(ans))",
"def rb(x):\r\n i=0\r\n while (1<<(i+1))<=x:\r\n i+=1\r\n return i\r\nD=[[i for i in range(1,x) if x%i==0] for x in range(61)]\r\nG={}\r\ndef g(x,y):\r\n if (x,y) in G.keys():\r\n return G[(x,y)]\r\n G[(x,y)]=(1<<(y-1))-sum(g(x,i) for i in D[y])\r\n return G[(x,y)]\r\nc=0\r\nu=[]\r\na=[]\r\ndef pr(i):\r\n if u[i]:\r\n return\r\n u[i]=1\r\n for j in a[i]:\r\n pr(j)\r\nH={}\r\ndef h(x,y,z):\r\n if (x,y,z) in H.keys():\r\n return H[(x,y,z)]\r\n n=rb(x)+1\r\n for i in range(n-1,n-1-y,-1):\r\n if i+z<n and bool(x&(1<<i))!=bool(x&(1<<(i+z))):\r\n return 0\r\n global c\r\n global u\r\n global a\r\n c=0\r\n u=[0]*n\r\n a=[set() for i in range(n)]\r\n for i in range(1,y):\r\n a[i].add(i-1)\r\n a[i-1].add(i)\r\n for i in range(n-z):\r\n a[i].add(i+z)\r\n a[i+z].add(i)\r\n for i in range(n):\r\n if not u[i]:\r\n c+=1\r\n pr(i)\r\n H[(x,y,z)]=(1<<(c-1))-sum(h(x,y,i) for i in D[z])\r\n return H[(x,y,z)]\r\ndef f(x):\r\n if x<1:\r\n return 0\r\n n=rb(x)+1\r\n return sum(sum(g(i,j) for j in D[i]) for i in range(1,n+1))-sum(sum(h(x|(1<<i),n-i,j) for j in D[n]) for i in range(n) if not (x&(1<<i)))\r\nl,r=[int(e) for e in input().split()]\r\nprint(f(r)-f(l-1))"
] | {"inputs": ["1 10", "25 38", "7 9", "12 20", "7 49", "28 97", "65 72", "49 116", "883 947", "1 1000000000000000000", "6967967 165556564", "74 99", "883 947", "3165 7131", "31958 81314", "134285 645597", "7404389 8927556", "29906716 35911991", "168183636 812682195", "856218974 3052460231", "29374454626 62592774235", "288565475053 662099878640", "2812400704972 4018154546667", "46017661651072 51016144673308", "208170109961052 582944028089477", "4644682781404278 9958408561221547", "10339710010772692 73118299589861909", "301180038343176710 553123999745170565", "580416 34018624576", "55795878 9393826256809", "72008 90484456049439993", "281 195999930590991", "2316699 57740665489369", "39 62829", "6937109 214001924643", "41751157 81619803901641136", "94889574706765 302945996536537188", "844 773163", "39 62829", "4 63489939", "4941728 1044573059727", "1870 77928372376127898", "9209325 530298582", "4173501391 7904052815", "680405 494044979780664129", "59 8401", "815041 1158613950585175"], "outputs": ["3", "2", "1", "1", "7", "6", "0", "2", "2", "932234960", "8453", "0", "2", "18", "129", "398", "141", "292", "14809", "20661", "109379", "111059", "579418", "595866", "4982263", "7100878", "191515094", "0", "132608", "2249141", "268766132", "11728514", "6915162", "275", "410178", "268728801", "528975174", "790", "275", "8027", "1002391", "268720705", "14524", "2717", "537396259", "73", "33621881"]} | UNKNOWN | PYTHON3 | CODEFORCES | 2 | |
32006bbd8168b03e94f8db7f3234053e | Nested Segments | You are given *n* segments on a line. There are no ends of some segments that coincide. For each segment find the number of segments it contains.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of segments on a line.
Each of the next *n* lines contains two integers *l**i* and *r**i* (<=-<=109<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — the coordinates of the left and the right ends of the *i*-th segment. It is guaranteed that there are no ends of some segments that coincide.
Print *n* lines. The *j*-th of them should contain the only integer *a**j* — the number of segments contained in the *j*-th segment.
Sample Input
4
1 8
2 3
4 7
5 6
3
3 4
1 5
2 6
Sample Output
3
0
1
0
0
1
1
| [
"'''\r\nDescripttion: your project\r\nversion: 1.0\r\nAuthor: ElysiaRealme\r\nDate: 2023-10-23 16:56:58\r\nLastEditors: ElysiaRealme\r\nLanguage: Python\r\n'''\r\nfrom io import BytesIO, IOBase\r\nimport sys\r\nimport os\r\n\r\n# import time\r\nimport bisect\r\n# import functools\r\nimport math\r\nimport random\r\n# import re\r\nfrom collections import Counter, defaultdict, deque\r\n# from copy import deepcopy\r\nfrom functools import cmp_to_key, lru_cache, reduce\r\nfrom heapq import heapify, heappop, heappush, heappushpop, nlargest, nsmallest\r\nfrom itertools import accumulate, combinations, permutations\r\n# from operator import add, iand, ior, itemgetter, mul, xor\r\n# from string import ascii_lowercase, ascii_uppercase\r\nfrom typing import *\r\n\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\ndef I():\r\n return input()\r\n\r\n\r\ndef II():\r\n return int(input())\r\n\r\n\r\ndef MII():\r\n return map(int, input().split())\r\n\r\n\r\ndef LI():\r\n return list(input().split())\r\n\r\n\r\ndef LII():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n\r\n\r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n\r\n\r\ndx, dy = [0, 1, 0, -1, 1, -1, 1, -1], [1, 0, -1, 0, -1, -1, 1, 1]\r\ninf = float('inf')\r\n\r\nfrom bisect import *\r\n\r\n\r\nclass BIT:\r\n def __init__(self, n):\r\n self.tree = [0] * n # 注意下标从1开始\r\n\r\n def lowbit(self, x):\r\n return x & (-x)\r\n\r\n # arr[i] += val\r\n def update(self, i, val):\r\n while i < len(self.tree):\r\n self.tree[i] += val\r\n i += self.lowbit(i)\r\n\r\n # 返回arr[:i+1]的sum\r\n def query(self, i):\r\n res = 0\r\n while i > 0:\r\n res += self.tree[i]\r\n i -= self.lowbit(i)\r\n return res\r\n\r\nt = II()\r\ng = []\r\na = []\r\nfor i in range(1, t + 1):\r\n l, r = MII()\r\n g.append((r, l, i))\r\n a.append(l)\r\na = sorted(set(a))\r\nd = {}\r\nfor i, x in enumerate(a):\r\n d[x] = i\r\ng.sort()\r\ntree = BIT(t + 10)\r\nn = t\r\nres = [0] * (n + 1)\r\n#print(g)\r\nfor x in range(1, n + 1):\r\n r, l, i = g[x - 1]\r\n idx = d[l] + 1\r\n tree.update(idx, 1)\r\n res[i] = x - tree.query(idx)\r\nfor i in range(1, n + 1):\r\n print(res[i])",
"import sys\r\nfrom bisect import bisect_left,bisect_right,insort_left,insort_right,insort\r\n# from collections import deque, Counter, defaultdict\r\n# from heapq import heappush, heappop, heapify\r\n# from math import ceil, floor, gcd\r\n# from string import ascii_lowercase as chars\r\n# from functools import reduce, cache\r\n# from itertools import accumulate\r\ninf = float(\"inf\")\r\n\r\n\r\ndef input():\r\n return sys.stdin.readline().rstrip()\r\n\r\n\r\ndef read_ints():\r\n return map(int, input().split())\r\n\r\ndef group_read_ints():\r\n return map(lambda x: int(x)-1, input().split())\r\n\r\nclass SortedList:\r\n def __init__(self, a=None):\r\n self.small = []\r\n self.big = [] if not a else a\r\n \r\n def add(self, v):\r\n if len(self.small) > 1500:\r\n self.big += self.small\r\n self.big.sort()\r\n self.small.clear()\r\n insort(self.small, v)\r\n \r\n def __len__(self):\r\n return len(self.small) + len(self.big)\r\n \r\n def bisect_left(self, v):\r\n return bisect_left(self.small, v) + bisect_left(self.big, v)\r\n\r\ndef main():\r\n n = int(input())\r\n q = [(-1,-1,-1)] * n\r\n for i in range(n):\r\n x,y = read_ints()\r\n q[i] = (x,y,i)\r\n q.sort(key=lambda e: e[1])\r\n # print(q)\r\n res = [0] * n\r\n\r\n left = SortedList()\r\n # O(n)\r\n for (x,y,idx) in q:\r\n # O(log n)\r\n cnt = left.bisect_left(x)\r\n res[idx] = len(left) - cnt\r\n # O(log n)\r\n left.add(x)\r\n \r\n # print(left)\r\n for e in res: \r\n print(e)\r\n\r\n \r\n\r\n\r\nif __name__ == \"__main__\":\r\n # t = int(input())\r\n t = 1\r\n for _ in range(t):\r\n main()\r\n",
"import sys\r\n\r\n\r\nclass BIT_RSQ(object):\r\n __slots__ = ['nodes', 'size']\r\n\r\n def __init__(self, size: int):\r\n self.nodes = [0]*(size+1)\r\n self.size = size+1\r\n\r\n def add(self, index: int, value: int):\r\n while index < self.size:\r\n self.nodes[index] += value\r\n index += index & -index\r\n\r\n def sum(self, right: int):\r\n result = 0\r\n\r\n while right:\r\n result += self.nodes[right]\r\n right -= right & -right\r\n\r\n return result\r\n\r\n\r\nn = int(sys.stdin.buffer.readline().decode('utf-8'))\r\nsegment = []\r\ncset = set()\r\nfor i, (li, ri) in enumerate(map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer):\r\n cset.add(li)\r\n cset.add(ri)\r\n segment.append((li, ri, i))\r\n\r\nm = len(cset) + 5\r\nrsq = BIT_RSQ(m)\r\n\r\ncomp_dict = {x: i for i, x in enumerate(sorted(cset), start=2)}\r\nfor _, ri, _ in segment:\r\n rsq.add(comp_dict[ri], 1)\r\n\r\nsegment.sort()\r\nans = [0]*n\r\nsi = 0\r\n\r\nfor i in range(2, m):\r\n while si < n and comp_dict[segment[si][0]] <= i:\r\n if comp_dict[segment[si][0]] == i:\r\n rsq.add(comp_dict[segment[si][1]], -1)\r\n ans[segment[si][2]] = rsq.sum(\r\n comp_dict[segment[si][1]]) - rsq.sum(comp_dict[segment[si][0]])\r\n si += 1\r\n\r\nsys.stdout.buffer.write(('\\n'.join(map(str, ans))).encode('utf-8'))\r\n",
"from random import getrandbits, randrange\r\nfrom string import ascii_lowercase, ascii_uppercase\r\nimport sys\r\nfrom math import ceil, floor, sqrt, pi, factorial, gcd, log, log10, log2, inf, cos, sin\r\nfrom copy import deepcopy, copy\r\nfrom collections import Counter, deque, defaultdict\r\nfrom heapq import heapify, heappop, heappush\r\nfrom itertools import (\r\n accumulate,\r\n product,\r\n combinations,\r\n combinations_with_replacement,\r\n permutations,\r\n)\r\nfrom bisect import bisect, bisect_left, bisect_right\r\nfrom functools import lru_cache, reduce\r\nfrom decimal import Decimal, getcontext\r\nfrom typing import List, Tuple, Optional\r\n\r\n\r\ninf = float(\"inf\")\r\n\r\n\r\ndef ceil_div(a, b):\r\n return (a + b - 1) // b\r\n\r\n\r\ndef isqrt(x):\r\n return int(sqrt(x))\r\n\r\n\r\ndef int1(s):\r\n return int(s) - 1\r\n\r\n\r\nimport sys\r\nimport os\r\nfrom io import BytesIO, IOBase\r\n\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\nprint = lambda *args, end=\"\\n\", sep=\" \": sys.stdout.write(\r\n sep.join(map(str, args)) + end\r\n)\r\n\r\n\r\ndef I():\r\n return input()\r\n\r\n\r\ndef II():\r\n return int(input())\r\n\r\n\r\ndef MII():\r\n return map(int, input().split())\r\n\r\n\r\ndef LI():\r\n return list(input().split())\r\n\r\n\r\ndef LII():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n\r\n\r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n\r\n\r\ndef yes(res):\r\n return print(\"Yes\" if res else \"No\")\r\n\r\n\r\ndef YES(res):\r\n return print(\"YES\" if res else \"NO\")\r\n\r\n\r\nclass Debug:\r\n def __init__(self, debug=False):\r\n self.debug = debug\r\n\r\n def get_ic(self):\r\n if self.debug:\r\n from icecream import ic\r\n\r\n return ic\r\n else:\r\n return lambda *args, **kwargs: ...\r\n\r\n\r\nclass BIT:\r\n def __init__(self, n):\r\n self.size = n\r\n self.n0 = 1 << (n.bit_length() - 1)\r\n self.tree = [0] * (n + 1)\r\n\r\n def sum(self, i):\r\n i += 1\r\n s = 0\r\n while i > 0:\r\n s += self.tree[i]\r\n i -= i & -i\r\n return s\r\n\r\n def add(self, i, x):\r\n i += 1\r\n while i <= self.size:\r\n self.tree[i] += x\r\n i += i & -i\r\n\r\n def range_sum(self, l, r):\r\n return self.sum(r - 1) - self.sum(l - 1)\r\n\r\n def get(self, i):\r\n return self.sum(i) - self.sum(i - 1)\r\n\r\n def lower_bound(self, x):\r\n\r\n pos = 0\r\n plus = self.n0\r\n while plus > 0:\r\n if pos + plus <= self.size and self.tree[pos + plus] < x:\r\n x -= self.tree[pos + plus]\r\n pos += plus\r\n plus //= 2\r\n return pos\r\n\r\n\r\nclass Discrete:\r\n def __init__(self, a=[]):\r\n\r\n self.nums = set(a)\r\n self.d = {}\r\n self.n = 0\r\n\r\n def add(self, num):\r\n self.nums.add(num)\r\n\r\n def distinct(self):\r\n self.n = len(self.nums)\r\n self.nums = list(self.nums)\r\n self.nums.sort()\r\n self.d = dict(zip(self.nums, range(self.n)))\r\n\r\n\r\nic = Debug(False).get_ic()\r\nn = II()\r\nsegs = []\r\na = []\r\nfor i in range(n):\r\n l, r = MII()\r\n a.append(l)\r\n a.append(r)\r\n segs.append((l, r, i))\r\nsegs.sort(key=lambda x: x[1])\r\n\r\nres = [0] * n\r\ndc = Discrete(a)\r\ndc.distinct()\r\n\r\nbit = BIT(dc.n)\r\nfor l, r, i in segs:\r\n res[i] = bit.range_sum(dc.d[l], dc.d[r])\r\n bit.add(dc.d[l], 1)\r\nprint(*res, sep=\"\\n\")\r\n",
"from collections import defaultdict,Counter\r\nfrom sys import stdin\r\ninput=stdin.readline\r\nclass BIT():\r\n\tdef __init__(self, n):\r\n\t\tself.n = n\r\n\t\tself.tree = [0] * (n + 1)\r\n\r\n\tdef sum(self, i):\r\n\t\tans = 0\r\n\t\ti += 1\r\n\t\twhile i > 0:\r\n\t\t\tans += self.tree[i]\r\n\t\t\ti -= (i & (-i))\r\n\t\treturn ans\r\n\r\n\tdef update(self, i, value):\r\n\t\ti += 1\r\n\t\twhile i <= self.n:\r\n\t\t\tself.tree[i] += value\r\n\t\t\ti += (i & (-i))\r\ndef score(t):\r\n\tcnt=Counter(t)\r\n\treturn list(cnt.values()).count(2)\r\ndef year():\r\n\tdct = defaultdict(list)\r\n\tn = int(input())\r\n\tleft=[0]*(n)\r\n\tright=[0]*(n)\r\n\tfor i in range(n):\r\n\t\ta, b = map(int, input().strip().split())\r\n\t\tleft[i]=a\r\n\t\tright[i]=b\r\n\torder=list(range(n))\r\n\torder=sorted(order,key=lambda s:left[s])\r\n\tfor i in range(n):\r\n\t\tleft[order[i]]=i\r\n\torder = list(range(n))\r\n\torder = sorted(order, key=lambda s: right[s])\r\n\tft=BIT(n)\r\n\tres=[0]*(n)\r\n\tfor i,k in enumerate(order):\r\n\t\ta=left[k]\r\n\t\tres[k]=i-ft.sum(a-1)\r\n\t\tft.update(a,1)\r\n\tprint(*res,sep=\"\\n\")\r\n\r\nyear()\r\n",
"class BIT:\r\n def __init__(self, n):\r\n self.tree = [0]*n\r\n\r\n def add(self, i, delta):\r\n while i<len(self.tree):\r\n self.tree[i] += delta\r\n i += i&-i\r\n\r\n def query(self, i):\r\n res = 0\r\n while i>0:\r\n res += self.tree[i]\r\n i -= i&-i\r\n return res\r\n\r\nn = int(input())\r\nintervals = []\r\nends = set()\r\nfor _ in range(n):\r\n l, r = list(map(int, input().split()))\r\n intervals.append((l, r))\r\n ends.add(l)\r\n ends.add(r)\r\nsorted_intervals = sorted(enumerate(intervals), key=lambda x: x[1][1])\r\nrank_map = {x: i for i, x in enumerate(sorted(ends))}\r\nres = [0]*n\r\nt = BIT(len(rank_map)+1)\r\nfor i, [l, r] in sorted_intervals:\r\n idx_l, idx_r = rank_map[l], rank_map[r]\r\n res[i] = t.query(idx_r+1)-t.query(idx_l)\r\n t.add(idx_l+1, 1)\r\nprint(*res, sep='\\n')\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"#!/usr/bin/env python3\r\n# -*- encoding: utf-8 -*-\r\n'''\r\n@File : test.py\r\n@Time : 2023/03/09 13:52:49\r\n@Author : @bvf\r\n'''\r\n\r\nimport sys\r\nimport os\r\nfrom io import BytesIO, IOBase\r\nfrom types import GeneratorType\r\n\r\nBUFSIZE = 4096\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = 'x' in file.mode or 'r' not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self, **kwargs):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b'\\n') + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode('ascii'))\r\n self.read = lambda: self.buffer.read().decode('ascii')\r\n self.readline = lambda: self.buffer.readline().decode('ascii')\r\n\r\ndef debug(func):\r\n def wrapper(*args, **kwargs):\r\n res = func(*args, **kwargs)\r\n print('----------------')\r\n return res\r\n return wrapper\r\n\r\n# 'return->yield','dfs()->yield dfs()'\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n if type(to) is GeneratorType:\r\n stack.append(to)\r\n to = next(to)\r\n else:\r\n stack.pop()\r\n if not stack:\r\n break\r\n to = stack[-1].send(to)\r\n return to\r\n return wrappedfunc\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip('\\r\\n')\r\n\r\ndef I():\r\n return input()\r\n\r\ndef II():\r\n return int(input())\r\n\r\ndef MI():\r\n return map(int, input().split())\r\n\r\ndef LI():\r\n return list(input().split())\r\n\r\ndef LII():\r\n return list(map(int, input().split()))\r\n\r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n\r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n\r\n# ------------------------------FastIO---------------------------------\r\n# from typing import *\r\nfrom bisect import bisect_left, bisect_right\r\n# from copy import deepcopy, copy\r\n# from math import comb, gcd, factorial, log, log2\r\n# from collections import Counter, defaultdict, deque\r\n# from itertools import accumulate, combinations, permutations, groupby\r\n# from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace\r\n# from functools import lru_cache, reduce\r\n# from sortedcontainers import SortedList, SortedSet\r\n\r\nMOD = int(1e9 + 7)\r\nM9D = int(998244353)\r\nINF = int(1e20)\r\n# -------------------------------@bvf----------------------------------\r\n# https://github.com/tatyam-prime/SortedSet/blob/main/SortedSet.py\r\nimport math\r\nfrom bisect import bisect_left, bisect_right\r\nfrom typing import Generic, Iterable, Iterator, TypeVar, Union, List\r\nT = TypeVar('T')\r\n\r\nclass SortedSet(Generic[T]):\r\n BUCKET_RATIO = 50\r\n REBUILD_RATIO = 170\r\n\r\n def _build(self, a=None) -> None:\r\n \"Evenly divide `a` into buckets.\"\r\n if a is None: a = list(self)\r\n size = self.size = len(a)\r\n bucket_size = int(math.ceil(math.sqrt(size / self.BUCKET_RATIO)))\r\n self.a = [a[size * i // bucket_size : size * (i + 1) // bucket_size] for i in range(bucket_size)]\r\n \r\n def __init__(self, a: Iterable[T] = []) -> None:\r\n \"Make a new SortedSet from iterable. / O(N) if sorted and unique / O(N log N)\"\r\n a = list(a)\r\n if not all(a[i] < a[i + 1] for i in range(len(a) - 1)):\r\n a = sorted(set(a))\r\n self._build(a)\r\n\r\n def __iter__(self) -> Iterator[T]:\r\n for i in self.a:\r\n for j in i: yield j\r\n\r\n def __reversed__(self) -> Iterator[T]:\r\n for i in reversed(self.a):\r\n for j in reversed(i): yield j\r\n \r\n def __len__(self) -> int:\r\n return self.size\r\n \r\n def __repr__(self) -> str:\r\n return \"SortedSet\" + str(self.a)\r\n \r\n def __str__(self) -> str:\r\n s = str(list(self))\r\n return \"{\" + s[1 : len(s) - 1] + \"}\"\r\n\r\n def _find_bucket(self, x: T) -> List[T]:\r\n \"Find the bucket which should contain x. self must not be empty.\"\r\n for a in self.a:\r\n if x <= a[-1]: return a\r\n return a\r\n\r\n def __contains__(self, x: T) -> bool:\r\n if self.size == 0: return False\r\n a = self._find_bucket(x)\r\n i = bisect_left(a, x)\r\n return i != len(a) and a[i] == x\r\n\r\n def add(self, x: T) -> bool:\r\n \"Add an element and return True if added. / O(√N)\"\r\n if self.size == 0:\r\n self.a = [[x]]\r\n self.size = 1\r\n return True\r\n a = self._find_bucket(x)\r\n i = bisect_left(a, x)\r\n if i != len(a) and a[i] == x: return False\r\n a.insert(i, x)\r\n self.size += 1\r\n if len(a) > len(self.a) * self.REBUILD_RATIO:\r\n self._build()\r\n return True\r\n\r\n def discard(self, x: T) -> bool:\r\n \"Remove an element and return True if removed. / O(√N)\"\r\n if self.size == 0: return False\r\n a = self._find_bucket(x)\r\n i = bisect_left(a, x)\r\n if i == len(a) or a[i] != x: return False\r\n a.pop(i)\r\n self.size -= 1\r\n if len(a) == 0: self._build()\r\n return True\r\n \r\n def lt(self, x: T) -> Union[T, None]:\r\n \"Find the largest element < x, or None if it doesn't exist.\"\r\n for a in reversed(self.a):\r\n if a[0] < x:\r\n return a[bisect_left(a, x) - 1]\r\n\r\n def le(self, x: T) -> Union[T, None]:\r\n \"Find the largest element <= x, or None if it doesn't exist.\"\r\n for a in reversed(self.a):\r\n if a[0] <= x:\r\n return a[bisect_right(a, x) - 1]\r\n\r\n def gt(self, x: T) -> Union[T, None]:\r\n \"Find the smallest element > x, or None if it doesn't exist.\"\r\n for a in self.a:\r\n if a[-1] > x:\r\n return a[bisect_right(a, x)]\r\n\r\n def ge(self, x: T) -> Union[T, None]:\r\n \"Find the smallest element >= x, or None if it doesn't exist.\"\r\n for a in self.a:\r\n if a[-1] >= x:\r\n return a[bisect_left(a, x)]\r\n \r\n def __getitem__(self, x: int) -> T:\r\n \"Return the x-th element, or IndexError if it doesn't exist.\"\r\n if x < 0: x += self.size\r\n if x < 0: raise IndexError\r\n for a in self.a:\r\n if x < len(a): return a[x]\r\n x -= len(a)\r\n raise IndexError\r\n \r\n def index(self, x: T) -> int:\r\n \"Count the number of elements < x.\"\r\n ans = 0\r\n for a in self.a:\r\n if a[-1] >= x:\r\n return ans + bisect_left(a, x)\r\n ans += len(a)\r\n return ans\r\n\r\n def index_right(self, x: T) -> int:\r\n \"Count the number of elements <= x.\"\r\n ans = 0\r\n for a in self.a:\r\n if a[-1] > x:\r\n return ans + bisect_right(a, x)\r\n ans += len(a)\r\n return ans\r\n\r\ndef solve():\r\n n = II()\r\n res = [0]*n\r\n S = SortedSet()\r\n c = []\r\n for i in range(n):\r\n c.append([*LII(),i])\r\n c.sort(key = lambda x: x[1])\r\n for l,r,idx in c:\r\n pos = bisect_left(S,l)\r\n res[idx] = len(S) - pos\r\n S.add(l)\r\n for x in res:\r\n print(x)\r\n return\r\n\r\nsolve()\r\n",
"import bisect\r\nimport copy\r\nimport gc\r\nimport itertools\r\nfrom array import array\r\nfrom fractions import Fraction\r\nimport heapq\r\nimport math\r\nimport operator\r\nimport os, sys\r\nimport profile\r\nimport cProfile\r\nimport random\r\nimport re\r\nimport string\r\nfrom bisect import bisect_left, bisect_right\r\nfrom collections import defaultdict, deque, Counter\r\nfrom functools import reduce, lru_cache\r\nfrom io import IOBase, BytesIO\r\nfrom itertools import count, groupby, accumulate, permutations, combinations, combinations_with_replacement, product\r\nfrom math import gcd\r\nfrom operator import xor, add\r\nfrom typing import List\r\n\r\n\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\n# print = lambda d: sys.stdout.write(str(d)+\"\\n\")\r\ndef read_int_list(): return list(map(int, input().split()))\r\ndef read_int_tuple(): return tuple(map(int, input().split()))\r\ndef read_int(): return int(input())\r\n\r\nif 'AW' in os.environ.get('COMPUTERNAME', ''):\r\n f = open('inputs', 'r')\r\n def input(): return f.readline().rstrip(\"\\r\\n\")\r\n\r\nclass SegmentTree:\r\n def __init__(self, init_val, segfunc, ide_ele):\r\n n = len(init_val)\r\n self.segfunc = segfunc\r\n self.ide_ele = ide_ele\r\n self.num = 1 << (n - 1).bit_length()\r\n self.tree = [ide_ele] * 2 * self.num\r\n self.size = n\r\n for i in range(n):\r\n self.tree[self.num + i] = init_val[i]\r\n for i in range(self.num - 1, 0, -1):\r\n self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])\r\n\r\n def update(self, k, x):\r\n k += self.num\r\n self.tree[k] = x\r\n while k > 1:\r\n k >>= 1\r\n self.tree[k] = self.segfunc(self.tree[2 * k], self.tree[2 * k + 1])\r\n\r\n def query(self, l, r): # [l, r)\r\n if r == self.size:\r\n r = self.num\r\n\r\n res = self.ide_ele\r\n\r\n l += self.num\r\n r += self.num\r\n # right = []\r\n while l < r:\r\n if l & 1:\r\n res = self.segfunc(res, self.tree[l])\r\n l += 1\r\n if r & 1:\r\n # right.append(self.tree[r - 1])\r\n res = self.segfunc(res, self.tree[r - 1])\r\n l >>= 1\r\n r >>= 1\r\n\r\n # for e in right[::-1]:\r\n # res = self.segfunc(res, e)\r\n return res\r\n\r\n def __repr__(self):\r\n return self.tree[self.num: self.num + self.size].__repr__()\r\n\r\n\r\ndef main():\r\n n = read_int()\r\n st = SegmentTree([0] * 2 * n, add, 0)\r\n\r\n dots, book = [], []\r\n for i in range(n):\r\n l, r = read_int_tuple()\r\n dots.extend([l, r])\r\n book.append([l, r, i])\r\n d = defaultdict(int)\r\n for i, x in enumerate(sorted(dots)):\r\n d[x] = i\r\n for i in range(n):\r\n book[i][0], book[i][1] = map(d.get, book[i][:2])\r\n\r\n book.sort(reverse=True)\r\n\r\n res = [0] * n\r\n\r\n for l, r, x in book:\r\n res[x] = st.query(l + 1, r)\r\n st.update(r, 1)\r\n\r\n for x in res: print(x)\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n# cProfile.run(\"main()\")\r\n",
"#!/usr/bin/env python3\n \nfrom __future__ import division, print_function\n \ndef least_significant_bit(i):\n return ((i) & -(i))\n \nclass FenwickTree():\n def __init__(self, n):\n # 1-indexed\n self.n = n + 1 \n self.data = [0,] * self.n\n \n def add(self, index, value):\n # 1-indexed\n i = index + 1\n while i < self.n:\n self.data[i] += value\n i += least_significant_bit(i)\n \n def prefix_sum(self, index):\n # 1-indexed\n i = index + 1\n result = 0\n while i > 0:\n result += self.data[i]\n i -= least_significant_bit(i)\n return result\n \n def range_sum(self, start, end):\n return self.prefix_sum(end) - self.prefix_sum(start-1)\n\n \ndef main():\n import sys\n data = iter(map(int, sys.stdin.buffer.read().decode('ascii').split()))\n n = next(data)\n left = [0,] * n\n right = [0,] * n\n for i in range(n):\n a, b = next(data), next(data)\n left[i] = a\n right[i] = b\n order = list(range(n))\n order.sort(key=lambda x: left[x])\n for i, k in enumerate(order):\n left[k] = i\n order = list(range(n))\n order.sort(key=lambda x:right[x])\n res = [0, ] * n\n ft = FenwickTree(n)\n for i, k in enumerate(order):\n a = left[k]\n res[k] = i - ft.prefix_sum(a-1)\n ft.add(a, 1)\n print('\\n'.join(str(x) for x in res))\n return 0\n \nif __name__ == '__main__':\n main()\n",
"import functools\nimport random\nimport sys\nimport os\nfrom collections import Counter, defaultdict, deque\nfrom functools import lru_cache, reduce\nfrom heapq import nsmallest, nlargest, heapify, heappop, heappush\nfrom io import BytesIO, IOBase\n\nBUFSIZE = 8012\n\n\nclass FastIO(IOBase):\n newlines = 0\n\n def __init__(self, file):\n self._fd = file.fileno()\n self.buffer = BytesIO()\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\n self.write = self.buffer.write if self.writable else None\n\n def read(self):\n while True:\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n if not b:\n break\n ptr = self.buffer.tell()\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n self.newlines = 0\n return self.buffer.read()\n\n def readline(self):\n while self.newlines == 0:\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n self.newlines = b.count(b\"\\n\") + (not b)\n ptr = self.buffer.tell()\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n self.newlines -= 1\n return self.buffer.readline()\n\n def flush(self):\n if self.writable:\n os.write(self._fd, self.buffer.getvalue())\n self.buffer.truncate(0), self.buffer.seek(0)\n\n\nclass IOWrapper(IOBase):\n def __init__(self, file):\n self.buffer = FastIO(file)\n self.flush = self.buffer.flush\n self.writable = self.buffer.writable\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\n self.read = lambda: self.buffer.read().decode(\"ascii\")\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\n\n\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\n\n\ndef I():\n return input()\n\n\ndef II():\n return int(input())\n\n\ndef MI():\n return map(int, input().split())\n\n\ndef LI():\n return list(input().split())\n\n\ndef LII():\n return list(map(int, input().split()))\n\n\ndef GMI():\n return map(lambda x: int(x) - 1, input().split())\n\n\ndef LGMI():\n return list(map(lambda x: int(x) - 1, input().split()))\n\n\ndef FMI():\n return list(map(lambda x: -int(x), input().split()))\n\nif sys.hexversion == 50924784:\n sys.stdin = open('data')\n\n# 题目思路:\n# 思路一(错误):算成了交集:将左右端点整合排序,遍历,记录左端点个数cl和右端点个数cr。每个区间【a, b】有交集的数量为:cl[b] - cr[a]\n# 思路二(TLE):按照右端点排序。a, b之间的集合数量等于 b左边的右端点数减去a左边的左端点数,结合树状数组记录a左边的左端点个数。\n# 思路三 (): a的值加一层排序索引映射,把树状数组的长度压缩到n来节省时间\ndef solve():\n n = II()\n la = [0] * n\n lb = [[0, i] for i in range(n)]\n for i in range(n):\n a, b = LII()\n la[i] = a\n lb[i][0] = b\n li = [i for i in range(n)]\n li.sort(key=lambda x: la[x])\n ai = [0] * n\n for i, t in enumerate(li):\n ai[t] = i + 1\n bi = {}\n def add(i):\n while i < n + 1:\n bi[i] = bi.get(i, 0) + 1\n i += i & -i\n def ps(i):\n r = 0\n while i > 0:\n r += bi.get(i, 0)\n i -= i & -i\n return r\n r = [0] * n\n lb.sort()\n c = 0\n for b, i in lb:\n r[i] = c - ps(ai[i])\n add(ai[i])\n c += 1\n print('\\n'.join(map(str, r)))\n\ndef solve2():\n n = II()\n l = []\n for i in range(n):\n a, b = LII()\n l.append((b, a, i))\n ba = min(x[1] for x in l) - 1\n s = max(x[1] for x in l) - ba + 2\n bi = {}\n def add(i):\n i -= ba\n while i < s:\n bi[i] = bi.get(i, 0) + 1\n i += i & -i\n def ps(i):\n i -= ba\n r = 0\n while i > 0:\n r += bi.get(i, 0)\n i -= i & -i\n return r\n r = [0] * n\n l.sort()\n c = 0\n for b, a, i in l:\n r[i] = c - ps(a)\n add(a)\n c += 1\n print('\\n'.join(map(str, r)))\n\ndef solve1():\n n = II()\n r = [0] * n\n l = [0] * n * 2\n for i in range(n):\n a, b = LII()\n l[2 * i] = (a, -1 - i)\n l[2 * i + 1] = (b, i)\n l.sort()\n cl = 0\n cr = 1\n for v, t in l:\n if t < 0:\n cl += 1\n r[-1-t] -= cr\n else:\n cr += 1\n r[t] += cl\n for t in r:\n print(t)\n# f = open('data')\n# # input = lambda: f.readline().rstrip(\"\\r\\n\")\n# for t in range(II()):\n# print(solve())\nsolve()",
"class BIT:\r\n def __init__(self, n):\r\n self.n = n\r\n self.bit = [0]*(self.n+1) # 1-indexed\r\n\r\n def init(self, init_val):\r\n for i, v in enumerate(init_val):\r\n self.add(i, v)\r\n\r\n def add(self, i, x):\r\n # i: 0-indexed\r\n i += 1 # to 1-indexed\r\n while i <= self.n:\r\n self.bit[i] += x\r\n i += (i & -i)\r\n\r\n def sum(self, i, j):\r\n # return sum of [i, j)\r\n # i, j: 0-indexed\r\n return self._sum(j) - self._sum(i)\r\n\r\n def _sum(self, i):\r\n # return sum of [0, i)\r\n # i: 0-indexed\r\n res = 0\r\n while i > 0:\r\n res += self.bit[i]\r\n i -= i & (-i)\r\n return res\r\n\r\n def lower_bound(self, x):\r\n s = 0\r\n pos = 0\r\n depth = self.n.bit_length()\r\n v = 1 << depth\r\n for i in range(depth, -1, -1):\r\n k = pos + v\r\n if k <= self.n and s + self.bit[k] < x:\r\n s += self.bit[k]\r\n pos += v\r\n v >>= 1\r\n return pos\r\n\r\n def __str__(self): # for debug\r\n arr = [self.sum(i,i+1) for i in range(self.n)]\r\n return str(arr)\r\n\r\nimport sys\r\nimport io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nLR = []\r\nX = set()\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n LR.append((l,r,i))\r\n X.add(l)\r\n X.add(r)\r\nX = list(X)\r\nX.sort()\r\ntoid = {}\r\nfor i, x in enumerate(X):\r\n toid[x] = i\r\nLR = [(toid[l], toid[r], i) for l, r, i in LR]\r\n#print(LR)\r\nN = len(X)\r\nevent = [[] for i in range(N)]\r\nfor l, r, i in LR:\r\n event[r].append((l, i))\r\nevent = [sorted(L, key=lambda x:-x[0]) for L in event]\r\nbit = BIT(N+1)\r\nans = [0]*n\r\nfor r in range(N):\r\n for l, i in event[r]:\r\n ans[i] = bit.sum(l, r+1)\r\n bit.add(l, 1)\r\nprint(*ans, sep='\\n')\r\n",
"# Problem: D. Nested Segments\r\n# Contest: Codeforces - Educational Codeforces Round 10\r\n# URL: https://codeforces.com/problemset/problem/652/D\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 ms\r\n\r\nimport sys\r\nimport bisect\r\nimport random\r\nimport io, os\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom contextlib import redirect_stdout\r\nfrom itertools import *\r\nfrom array import *\r\nfrom functools import lru_cache\r\nfrom types import GeneratorType\r\nfrom heapq import *\r\nfrom math import sqrt, gcd, inf\r\n\r\nif sys.version >= '3.8': # ACW没有comb\r\n from math import comb\r\n\r\nRI = lambda: map(int, sys.stdin.buffer.readline().split())\r\nRS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())\r\nRILST = lambda: list(RI())\r\nDEBUG = lambda *x: sys.stderr.write(f'{str(x)}\\n')\r\n\r\nMOD = 10 ** 9 + 7\r\nPROBLEM = \"\"\"https://codeforces.com/problemset/problem/652/D\r\n\r\n输入 n(≤2e5) 和 n 个闭区间,区间左右端点范围在 [-1e9,1e9],所有端点互不相同。\r\n\r\n对每个区间,输出它包含多少个其它的区间。\r\n输入\r\n4\r\n1 8\r\n2 3\r\n4 7\r\n5 6\r\n输出\r\n3\r\n0\r\n1\r\n0\r\n\r\n输入\r\n3\r\n3 4\r\n1 5\r\n2 6\r\n输出\r\n0\r\n1\r\n1\r\n\"\"\"\r\n\r\n\r\nclass SortedList:\r\n def __init__(self, a=None):\r\n self.small = []\r\n self.big = [] if not a else a\r\n\r\n def add(self, v):\r\n if len(self.small) > 1000:\r\n self.big += self.small\r\n self.big.sort()\r\n self.small.clear()\r\n insort(self.small, v)\r\n\r\n def __len__(self):\r\n return len(self.small) + len(self.big)\r\n\r\n def bisect_left(self, v):\r\n return bisect_left(self.small, v) + bisect_left(self.big, v)\r\n\r\n\r\n# ms\r\ndef solve():\r\n n, = RI()\r\n a = []\r\n for i in range(n):\r\n l, r = RI()\r\n a.append((r, l, i))\r\n a.sort()\r\n p = SortedList()\r\n ans = [0] * n\r\n for r, l, i in a:\r\n ans[i] = len(p) - p.bisect_left(l)\r\n p.add(l)\r\n print(*ans, sep='\\n')\r\n\r\n\r\n# ms\r\ndef solve1():\r\n n, = RI()\r\n a = []\r\n hs = []\r\n for _ in range(n):\r\n l, r = RI()\r\n hs.extend([l, r])\r\n a.append((l, r))\r\n a.sort(key=lambda x: x[1])\r\n hs.sort()\r\n\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n",
"class bintree:#放入数组\r\n def __init__(self, nums):\r\n self.has = {x:i for i,x in enumerate(nums)}\r\n self.tree = [0]*(len(nums)+5)\r\n self.n = len(nums)\r\n def add(self,i):#第i个位置的值加上v\r\n i = self.has[i]+1\r\n while i <= self.n:\r\n self.tree[i] -= 1\r\n i += i&(-i)\r\n def find_(self,i):#找到 <=i 的最大值\r\n res = 0\r\n while i:\r\n res += self.tree[i]\r\n i -= i&(-i)\r\n return res\r\n def find(self,right):\r\n return self.has[right]+self.find_(self.has[right])\r\nimport sys\r\ninput = lambda: sys.stdin.readline().strip()\r\nn = int(input())\r\nti = []\r\nfor _ in range(n):\r\n a,b = map(int,input().split())\r\n ti.append([a,b])\r\nsotb = sorted([x for _,x in ti])\r\nbin = bintree(sotb)\r\nans = {}\r\nfor i,j in sorted(ti):\r\n lin = bin.find(j)\r\n ans[i] = lin\r\n bin.add(j)\r\nres = []\r\nfor i,_ in ti:\r\n print(ans[i])",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ndef make_tree(n):\r\n tree = [0] * (n + 1)\r\n return tree\r\n\r\ndef get_sum(i):\r\n s = 0\r\n while i > 0:\r\n s += tree[i]\r\n i -= i & -i\r\n return s\r\n\r\ndef add(i, x, l):\r\n while i <= l:\r\n tree[i] += x\r\n i += i & -i\r\n\r\nn = int(input())\r\nlr = []\r\ns = set()\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n s.add(r)\r\n lr.append([l, r, i])\r\ns = list(s)\r\ns.sort()\r\nd = dict()\r\nfor i in range(n):\r\n d[s[i]] = i + 1\r\nm = n + 1\r\ntree = make_tree(m)\r\nlr.sort(reverse = True)\r\nans = [0] * n\r\nfor l, r, i in lr:\r\n dr = d[r]\r\n ans[i] = get_sum(dr)\r\n add(dr, 1, m)\r\nprint(\"\\n\".join(map(str, ans)))",
"from bisect import bisect_right\r\nfrom collections import defaultdict\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nfrom collections import defaultdict\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ndef sum(BIT, i):\r\n s = 0\r\n while i > 0:\r\n s += BIT[i]\r\n i -= i & (-i)\r\n return s\r\n\r\n\r\ndef update(BIT, i, v):\r\n while i < len(BIT):\r\n BIT[i] += v\r\n\r\n i += i & (-i)\r\n\r\n\r\ndef find(fen, k):\r\n curr = 0\r\n ans = 0\r\n prevsum = 0\r\n for i in range(19, -1, -1):\r\n if ((curr + (1 << i) < n) and fen[curr + (1 << i)] + prevsum < k):\r\n ans = curr + (1 << i)\r\n curr = ans\r\n prevsum += fen[curr]\r\n return ans + 1\r\n\r\ndef Rank(x,BIT) :\r\n\r\n return sum(BIT,x)\r\n\r\n\r\ndef sum(BIT, i):\r\n s = 0\r\n while i > 0:\r\n s += BIT[i]\r\n i -= i & (-i)\r\n return s\r\n\r\n\r\ndef update(BIT, i, v):\r\n while i < len(BIT):\r\n BIT[i] += v\r\n\r\n i += i & (-i)\r\n\r\n\r\ndef find(fen, k):\r\n curr = 0\r\n ans = 0\r\n prevsum = 0\r\n for i in range(19, -1, -1):\r\n if ((curr + (1 << i) < n) and fen[curr + (1 << i)] + prevsum < k):\r\n ans = curr + (1 << i)\r\n curr = ans\r\n prevsum += fen[curr]\r\n return ans + 1\r\n\r\ndef Rank(x,BIT) :\r\n\r\n return sum(BIT,x)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nn=int(input())\r\ninc=[]\r\nout=[]\r\nfor j in range(n):\r\n p,q=map(int,input().split())\r\n inc.append([p,j])\r\n out.append([q,j])\r\n\r\ninc.sort()\r\nout.sort()\r\ncurr=0\r\nj1=0\r\nj2=0\r\nind=[]\r\nwhile(j1<n or j2<n):\r\n if j1<n and j2<n:\r\n if inc[j1][0]<=out[j2][0]:\r\n ind.append(inc[j1][1])\r\n j1+=1\r\n else:\r\n ind.append(out[j2][1])\r\n j2+=1\r\n elif j1<n:\r\n ind.append(inc[j1][1])\r\n j1+=1\r\n else:\r\n ind.append(out[j2][1])\r\n\r\n j2 += 1\r\n\r\nd=dict()\r\nj=0\r\nres=[0]*(n)\r\nBIT = [0] * (2*n + 1)\r\ncurr=0\r\nwhile(j<2*n):\r\n if ind[j] not in d.keys():\r\n d[ind[j]]=j+1\r\n else:\r\n res[ind[j]]=curr-Rank(d[ind[j]],BIT)\r\n update(BIT,d[ind[j]],1)\r\n\r\n curr+=1\r\n\r\n\r\n j+=1\r\n\r\nfor j in res:\r\n print(j)\r\n\r\n\r\n\r\n"
] | {"inputs": ["4\n1 8\n2 3\n4 7\n5 6", "3\n3 4\n1 5\n2 6", "1\n-1000000000 1000000000", "2\n-1000000000 999999999\n-999999999 1000000000", "2\n-1000000000 1000000000\n-999999999 999999999", "3\n-999999997 999999997\n-999999998 999999998\n-999999999 999999999", "3\n-999999999 999999997\n-999999998 999999998\n-999999997 999999999", "7\n1 14\n2 7\n3 4\n5 6\n8 13\n9 10\n11 12", "8\n1 16\n2 7\n3 4\n5 6\n8 9\n10 15\n11 12\n13 14", "8\n1 16\n2 7\n3 4\n5 8\n6 9\n10 15\n11 13\n12 14", "10\n-3 -1\n-10 4\n0 6\n-4 -2\n1 3\n2 9\n5 10\n-7 -6\n-8 8\n-9 7", "1\n-1 0", "10\n-513515548 596545048\n-864922524 -143639540\n-186185108 253442195\n-325311097 557247880\n-843432193 -793445411\n-589321824 602462994\n-980740122 -845522939\n-20465341 192085177\n363969852 718880403\n-797865714 644017524", "10\n-128739791 -39063859\n-103449295 927503025\n95979137 136886112\n-204849739 909268860\n-172975545 140068443\n-795229308 -495885136\n204945615 853645963\n-333018842 605274895\n-580345079 953606768\n335800547 686581467", "10\n-317257964 738085350\n-989968614 735410270\n-870119900 197330499\n335597813 781352203\n-109119439 116242045\n604692366 819316837\n269683555 704665430\n-510921778 563710518\n340538827 963493707\n-925778993 739625150", "10\n-644829480 485279434\n-54170850 756394598\n-103264442 39454200\n-12413554 577524970\n-909155364 193038318\n362781551 722749393\n-766782831 137745252\n811928942 870183784\n-43075984 270955026\n-159109789 303861267", "10\n68572123 724714249\n104192140 802439320\n-890197541 150898768\n-912647426 208916264\n-942374086 -391426562\n-865405682 -491142593\n-623954751 425004801\n368985304 960241411\n-492740831 54907671\n-553720998 567496293"], "outputs": ["3\n0\n1\n0", "0\n1\n1", "0", "0\n0", "1\n0", "0\n1\n2", "0\n0\n0", "6\n2\n0\n0\n2\n0\n0", "7\n2\n0\n0\n0\n2\n0\n0", "7\n1\n0\n0\n0\n2\n0\n0", "0\n4\n1\n0\n0\n0\n0\n0\n5\n5", "0", "3\n1\n1\n2\n0\n4\n0\n0\n0\n5", "0\n3\n0\n5\n2\n0\n1\n3\n8\n0", "2\n4\n1\n0\n0\n0\n0\n1\n1\n5", "3\n3\n0\n0\n2\n0\n1\n0\n0\n2", "0\n0\n2\n3\n1\n0\n1\n0\n0\n1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 15 | |
3204a88d5f3940fd5744f4629c906e37 | Land Lot | Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fruit because there’s no house in the garden! Vasya had been saving in for some time and finally he decided to build the house. The rest is simple: he should choose in which part of the garden to build the house. In the evening he sat at his table and drew the garden’s plan. On the plan the garden is represented as a rectangular checkered field *n*<=×<=*m* in size divided into squares whose side length is 1. In some squares Vasya marked the trees growing there (one shouldn’t plant the trees too close to each other that’s why one square contains no more than one tree). Vasya wants to find a rectangular land lot *a*<=×<=*b* squares in size to build a house on, at that the land lot border should go along the lines of the grid that separates the squares. All the trees that grow on the building lot will have to be chopped off. Vasya loves his garden very much, so help him choose the building land lot location so that the number of chopped trees would be as little as possible.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) which represent the garden location. The next *n* lines contain *m* numbers 0 or 1, which describe the garden on the scheme. The zero means that a tree doesn’t grow on this square and the 1 means that there is a growing tree. The last line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=50). Note that Vasya can choose for building an *a*<=×<=*b* rectangle as well a *b*<=×<=*a* one, i.e. the side of the lot with the length of *a* can be located as parallel to the garden side with the length of *n*, as well as parallel to the garden side with the length of *m*.
Print the minimum number of trees that needs to be chopped off to select a land lot *a*<=×<=*b* in size to build a house on. It is guaranteed that at least one lot location can always be found, i. e. either *a*<=≤<=*n* and *b*<=≤<=*m*, or *a*<=≤<=*m* и *b*<=≤<=*n*.
Sample Input
2 2
1 0
1 1
1 1
4 5
0 0 1 0 1
0 1 1 1 0
1 0 1 0 1
1 1 1 1 1
2 3
Sample Output
0
2
| [
"\r\ndef calcTrees(cont, startRow, startCol, a, b):\r\n trees = 0\r\n for i in range(a):\r\n for j in range(b):\r\n if cont[startRow + i][startCol + j] == 1:\r\n trees += 1\r\n return trees\r\n\r\n\r\n\r\nn, m = list(map(int, input().split(' ')))\r\ncont = []\r\nfor i in range(n):\r\n cont.append([int(item) for item in input().split(' ')])\r\n\r\na, b = list(map(int, input().split(' ')))\r\nans = a * b\r\nfor i in range(n):\r\n for j in range(m):\r\n if i <= n - a and j <= m - b:\r\n helper = calcTrees(cont, i, j, a, b)\r\n if ans > helper:\r\n ans = helper\r\n if i <= n - b and j <= m - a:\r\n helper = calcTrees(cont, i, j, b, a)\r\n if ans > helper:\r\n ans = helper\r\n\r\n\r\n\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"Homura = [int(i) for i in input().split()]\r\nm = Homura[0]\r\nn = Homura[1]\r\n\r\ngarden = []\r\nfor i in range(m):\r\n\tgarden.append([int(i) for i in input().split()])\r\n\r\nMadoka = [int(i) for i in input().split()]\r\na = Madoka[0]\r\nb = Madoka[1]\r\n\r\nans = a*b\r\n\r\nfor i in range(m+1-a):\r\n\tfor j in range(n+1-b):\r\n\t\ttrees = 0\r\n\t\tfor x in range(a):\r\n\t\t\tfor y in range(b):\r\n\t\t\t\ttrees += garden[i+x][j+y]\r\n\t\tans = min(ans,trees)\r\n\r\nfor i in range(m+1-b):\r\n\tfor j in range(n+1-a):\r\n\t\ttrees = 0\r\n\t\tfor x in range(b):\r\n\t\t\tfor y in range(a):\r\n\t\t\t\ttrees += garden[i+x][j+y]\r\n\t\tans = min(ans,trees)\r\n\r\nprint(ans)\r\n",
"def calcTrees(cont, startRow, startCol, a, b):\r\n ans = 0\r\n for i in range(startRow, startRow + a):\r\n for j in range(startCol, startCol + b):\r\n ans += cont[i][j]\r\n return ans\r\n\r\n\r\nn, m = [int(item) for item in input().split(' ')]\r\ncont = list()\r\nfor i in range(n):\r\n cont.append([int(item) for item in input().split(' ')])\r\n\r\na, b = [int(item) for item in input().split(' ')]\r\nans = a*b\r\nfor i in range(n):\r\n for j in range(m):\r\n if i + a <= n and j + b <= m:\r\n helper = calcTrees(cont,i,j,a,b)\r\n if ans > helper:\r\n ans = helper\r\n if i + b <= n and j + a <= m:\r\n helper = calcTrees(cont,i,j,b,a)\r\n if ans > helper:\r\n ans = helper\r\nprint(ans)\r\n",
"n, m = map(int, input().split())\r\ngarden = [list(map(int, input().split())) for i in range(n)]\r\na, b = map(int, input().split())\r\nmin_chopped_trees = float('inf')\r\nfor i in range(n - a + 1):\r\n for j in range(m - b + 1):\r\n chopped_trees = sum(garden[i + k][j + l] for k in range(a) for l in range(b))\r\n if chopped_trees < min_chopped_trees:\r\n min_chopped_trees = chopped_trees\r\nfor i in range(n - b + 1):\r\n for j in range(m - a + 1):\r\n chopped_trees = sum(garden[i + k][j + l] for k in range(b) for l in range(a))\r\n if chopped_trees < min_chopped_trees:\r\n min_chopped_trees = chopped_trees\r\nprint(min_chopped_trees)",
"n,m = map(int, input().split())\r\nfl = [list(map(int, input().split())) for i in range(n)]\r\na,b = map(int, input().split())\r\nans_min = 2500\r\nfor i in range(n-a+1):\r\n for j in range(m-b+1):\r\n ans_min=min(ans_min,sum([sum(fl[k][j:j+b]) for k in range(i,i+a)]))\r\nfor i in range(n-b+1):\r\n for j in range(m-a+1):\r\n ans_min=min(ans_min,sum([sum(fl[k][j:j+a]) for k in range(i,i+b)]))\r\nprint(ans_min)",
"\r\nn,m = [int(s) for s in input().split()]\r\n\r\ng = []\r\n\r\nfor i in range(n):\r\n g.append(input().split())\r\n\r\nx,y = [int(s) for s in input().split()]\r\n\r\ndef getTrees(a,b,Index):\r\n count = 0\r\n for i in range(Index[0],Index[0] + a):\r\n for j in range(Index[1],Index[1] + b):\r\n if(g[i][j] == '1'):\r\n count += 1\r\n return count\r\n\r\ndef calculate(a,b):\r\n count = 3600\r\n for i in range(0,n - a + 1):\r\n for j in range(0,m - b + 1):\r\n count = min(count,getTrees(a,b,(i,j)))\r\n return count\r\n\r\nprint(min(calculate(x,y),calculate(y,x)))\r\n",
"n,m=map(int, input().split())\r\nc=[]\r\nfor i in range(n):\r\n c.append([])\r\n for j in input().split():\r\n c[i].append(int(j))\r\na,b=map(int, input().split())\r\nans=n*m\r\nfor i in range(n-a+1):\r\n for j in range(m-b+1):\r\n s=0\r\n for k in range(i,i+a):\r\n s+=sum(c[k][j:j+b])\r\n ans=min(s,ans)\r\nfor i in range(n-b+1):\r\n for j in range(m-a+1):\r\n s=0\r\n for k in range(i,i+b):\r\n s+=sum(c[k][j:j+a])\r\n ans=min(s,ans)\r\nprint(ans)",
"import sys\r\nimport math\r\nimport bisect\r\n\r\ndef solve(A, x, y):\r\n n = len(A)\r\n m = len(A[0])\r\n min_val = 10 ** 18\r\n if x > n or y > m:\r\n return min_val\r\n for i in range(n):\r\n for j in range(m):\r\n if i + x <= n and j + y <= m:\r\n val = 0\r\n for s in range(i, i + x):\r\n for t in range(j, j + y):\r\n val += A[s][t]\r\n min_val = min(min_val, val)\r\n return min_val\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n A = []\r\n for i in range(n):\r\n A.append(list(map(int, input().split())))\r\n a, b = map(int, input().split())\r\n val1 = solve(A, a, b)\r\n val2 = solve(A, b, a)\r\n print(min(val1, val2))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"import sys\r\ninputlist=sys.stdin.readlines()\r\ndef traverse_row(s,b,m):\r\n sum_of_b_elements=0\r\n for i in range(b):\r\n sum_of_b_elements=sum_of_b_elements+s[i]\r\n i=i+1\r\n min_now=sum_of_b_elements\r\n #print(sum_of_b_elements)\r\n while(i<m):\r\n sum_of_b_elements=sum_of_b_elements+s[i]-s[i-b]\r\n #print(sum_of_b_elements)\r\n if (sum_of_b_elements<min_now):\r\n min_now=sum_of_b_elements\r\n i+=1\r\n return min_now\r\ndef check_min_trees(n,m,a,b,landlot):\r\n if(a>n or b>m):\r\n return 2501\r\n s=[0]*m\r\n for i in range(m):\r\n #print(i)\r\n for j in range(a):\r\n s[i]=s[i]+landlot[j][i]\r\n #print(s)\r\n min_of_row=traverse_row(s,b,m)\r\n #print(min_of_row)\r\n for i in range(a,n):\r\n for j in range(m):\r\n s[j]=s[j]+landlot[i][j]-landlot[i-a][j]\r\n #print('printing s for ',i,' iteration')\r\n #print(s)\r\n new_row_min=traverse_row(s,b,m)\r\n if(new_row_min<min_of_row):\r\n min_of_row=new_row_min\r\n #print('min of all rows=',min_of_row)\r\n return min_of_row\r\nn,m=list(map(int,inputlist[0].strip().split(' ')))\r\na,b=list(map(int,inputlist[n+1].strip().split(' ')))\r\nlandlot=[]\r\nfor i in range(n):\r\n newlist=list(map(int,inputlist[i+1].strip().split(' ')))\r\n landlot.append(newlist)\r\nresult1=check_min_trees(n,m,a,b,landlot)\r\n'''\r\nif(result1==False):\r\n result1=2501\r\n'''\r\nresult2=check_min_trees(n,m,b,a,landlot)\r\n'''\r\nif(result2==False):\r\n result2=2501\r\n'''\r\n#print(result1,result2)\r\nif(result1<result2):\r\n print(result1)\r\nelse:\r\n print(result2)\r\n",
"#\"from dust i have come, dust i will be\"\n\nn,m=map(int,input().split())\n\narr=[list(map(int,input().split())) for r in range(n)]\n\na,b=map(int,input().split())\n\nmx=10000000;\nfor i in range(n-a+1):\n for j in range(m-b+1):\n count=0;\n for w in range(i,i+a):\n for e in range(j,j+b):\n count+=arr[w][e]\n\n mx=min(mx,count)\n\n\nfor i in range(n-b+1):\n for j in range(m-a+1):\n count=0;\n for w in range(i,i+b):\n for e in range(j,j+a):\n count+=arr[w][e]\n\n mx=min(mx,count)\n\nprint(mx)\n",
"I = lambda: map(int, input().split())\r\n\r\nn, m = I()\r\nA = [[*I()] for _ in range(n)]\r\na, b = I()\r\n\r\nprint(min(sum(A[i][j] for i in range(x,x+dx) for j in range(y,y+dy))\r\n for dx,dy in ((a,b),(b,a))\r\n for x in range(n-dx+1) for y in range(m-dy+1)))",
"n, m = map(int, input().split())\ngrid = [ list(map(int, input().split())) for r in range(n) ]\na, b = map(int, input().split())\n\nrow_sums = n * [ None ]\nfor r in range(n):\n sum = (m + 1) * [ 0 ]\n for c in range(m):\n sum[c + 1] = sum[c] + grid[r][c]\n row_sums[r] = sum\n\nresult = a * b\n\ndef solve(a, b):\n chopped = a * b\n for r in range(n):\n r_limit = r + a\n if r_limit > n:\n break\n for c in range(m):\n c_limit = c + b\n if c_limit > m:\n break\n count = 0\n for i in range(r, r_limit):\n count += row_sums[i][c_limit] - row_sums[i][c]\n chopped = min(chopped, count)\n return chopped\n\nif a <= n and b <= m:\n result = min(result, solve(a, b))\nif b <= n and a <= m:\n result = min(result, solve(b, a))\nprint(result)\n",
"import array\r\nimport collections\r\nimport math\r\nsums = lambda n: int(n * (n + 1) / 2) # sum from 1 to n\r\nsumsqur = lambda n: int( (n) * (n + 1) * (2*n +1)/6) # sum square from 1 to n\r\n\r\n\r\ndef im(): return map(int, input().split())\r\ndef il(): return list(map(int, input().split()))\r\ndef ii(): return int(input())\r\n\r\n# \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\ndef isPalindrom(a):\r\n return True if a[::-1] == a else False\r\nxx=lambda n:int(n * (n - 1) / 2) # 2->1,3->3,4->6,5->10,6->15\r\n\r\ndef solve():\r\n n,m=im()\r\n arr=[[0]*(m+1)]\r\n dp=[[0]*(m+1)]\r\n for i in range(n):\r\n a=[0]\r\n a.extend(il())\r\n arr.append(a)\r\n a,b=im()\r\n for i in range(1,n+1):\r\n aa=[0]\r\n for j in range(1,m+1):\r\n aa.append(arr[i][j] + dp[i-1][j] + aa[j-1] - dp[i-1][j-1])\r\n dp.append(aa)\r\n count=1000\r\n x,y=a,b\r\n while a<=n:\r\n while b<=m:\r\n count=min(count,dp[a][b]-dp[a][b-y]-dp[a-x][b]+dp[a-x][b-y])\r\n b+=1\r\n a+=1\r\n b=y\r\n a,b=y,x\r\n while a<=n:\r\n while b<=m:\r\n count=min(count,dp[a][b]-dp[a-y][b]-dp[a][b-x]+dp[a-y][b-x])\r\n b+=1\r\n a+=1\r\n b=x\r\n\r\n return count\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n #for i in range(ii()):\r\n print(solve())\r\n",
"\r\nn,m=map(int,input().split())\r\n\r\nf = []\r\nfor i in range(n):\r\n f.append(list(map(int,input().split())))\r\n\r\na,b=map(int,input().split())\r\n\r\n\r\nd=[[0 for i in range(m+1)] for j in range(n+1)]\r\nfor i in range(1,n+1):\r\n for j in range(1,m+1):\r\n d[i][j] = d[i-1][j] + d[i][j-1] + f[i-1][j-1] - d[i-1][j-1]\r\n\r\nres = n*m\r\nfor j in range(a,m+1):\r\n for i in range(b, n+1):\r\n v = d[i][j] + d[i-b][j-a] - d[i-b][j] - d[i][j-a]\r\n res = min(v, res)\r\n\r\nfor i in range(a, n+1):\r\n for j in range(b,m+1):\r\n v = d[i][j] + d[i-a][j-b] - d[i-a][j] - d[i][j-b]\r\n res = min(v, res)\r\n\r\nprint(res)",
"def calc_trees(cont, start_row, start_col, a, b):\r\n counter = 0\r\n for i in range(start_row, start_row + a):\r\n for j in range(start_col, start_col + b):\r\n counter += cont[i][j]\r\n return counter\r\n\r\n\r\nn, m = list(map(int, input().split(\" \")))\r\n\r\ncont = []\r\nfor i in range(n):\r\n cont.append(list(map(int, input().split(\" \"))))\r\n\r\na, b = list(map(int, input().split(\" \")))\r\nans, helper = n * m, 0\r\nfor i in range(n):\r\n for j in range(m):\r\n if i + a <= n and j + b <= m:\r\n helper = calc_trees(cont, i, j, a, b)\r\n if helper < ans:\r\n ans = helper\r\n if i + b <= n and j + a <= m:\r\n helper = calc_trees(cont, i, j, b, a)\r\n if helper < ans:\r\n ans = helper\r\nprint(ans)\r\n",
"def countTrees(cont: list, i: int, j: int, x: int, y: int):\r\n ans = 0\r\n\r\n for rowInd in range(i, i + x):\r\n for colInd in range(j, j + y):\r\n ans += cont[rowInd][colInd]\r\n return ans\r\n\r\n\r\nn, m = [int(item) for item in input().split()]\r\ncont = []\r\n\r\nfor i in range(n):\r\n cont.append([int(item) for item in input().split()])\r\n\r\nx, y = [int(item) for item in input().split()]\r\nans = n * m\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if i <= n - x and j <= m - y:\r\n helper = countTrees(cont, i, j, x, y)\r\n if ans > helper:\r\n ans = helper\r\n\r\n if i <= n - y and j <= m - x:\r\n helper = countTrees(cont, i, j, y, x)\r\n if ans > helper:\r\n ans = helper\r\n\r\nprint(ans)\r\n",
"n,m=list(map(int,input().split()))\r\nc=[list(map(int,input().split())) for i in range(n)]\r\na,b=list(map(int,input().split()))\r\nd=[]\r\nfor i in range(n):\r\n d.append([])\r\n e=0\r\n for j in range(m):\r\n e+=c[i][j]\r\n d[i].append(e)\r\n d[i].append(0)\r\nf=-1\r\nfor i in range(n-b+1):\r\n for j in range(m-a+1):\r\n g=0\r\n for k in range(b):\r\n g+=d[i+k][j+a-1]-d[i+k][j-1]\r\n if f==-1 or g<f:\r\n f=g\r\nh=a\r\na=b\r\nb=h\r\nfor i in range(n-b+1):\r\n for j in range(m-a+1):\r\n g=0\r\n for k in range(b):\r\n g+=d[i+k][j+a-1]-d[i+k][j-1]\r\n if f==-1 or g<f:\r\n f=g\r\nprint(f)",
"n,m=map(int,input().split())\r\narr=[list(map(int,input().split())) for r in range(n)]\r\na,b=map(int,input().split())\r\nmx=3000;\r\nfor i in range(n-a+1):\r\n for j in range(m-b+1):\r\n count=0;\r\n for k in range(i,i+a):\r\n for l in range(j,j+b):\r\n count+=arr[k][l]\r\n \r\n mx=min(mx,count)\r\n \r\n \r\nfor i in range(n-b+1):\r\n for j in range(m-a+1):\r\n count=0;\r\n for k in range(i,i+b):\r\n for l in range(j,j+a):\r\n count+=arr[k][l]\r\n \r\n mx=min(mx,count)\r\n \r\nprint(mx)",
"sums = lambda n: int(n * (n + 1) / 2) # sum from 1 to n\r\ndef im(): return map(int, input().split())\r\ndef il(): return list(map(int, input().split()))\r\ndef ii(): return int(input())\r\n\r\n\r\ndef solve():\r\n n, m = im()\r\n ls = []\r\n for _ in range(n):\r\n ls.append(il())\r\n a, b = im()\r\n pre = [[0 for i in range(m+1)] for j in range(n+1)]\r\n for i in range (1, n+1):\r\n for j in range(1, m+1):\r\n pre[i][j] = ls[i-1][j-1] + pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1]\r\n\r\n mn = 2500\r\n\r\n for i in range(n-a+1):\r\n for j in range(m-b+1):\r\n mn = min(mn, pre[i+a][j+b] - pre[i][j+b] - pre[i+a][j] + pre[i][j])\r\n\r\n temp = a\r\n a = b\r\n b = temp\r\n\r\n for i in range(n-a+1):\r\n for j in range(m-b+1):\r\n mn = min(mn, pre[i+a][j+b] - pre[i][j+b] - pre[i+a][j] + pre[i][j])\r\n\r\n return mn\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n #for _ in range(ii()):\r\n print(solve())\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n, m = map(int, input().split())\r\nfl = [list(map(int, input().split())) for i in range(n)]\r\na, b = map(int, input().split())\r\nans_min = 2500\r\nfor i in range(n-a+1):\r\n for j in range(m-b+1):\r\n ans_min = min(ans_min, sum([sum(fl[k][j:j+b]) for k in range(i, i+a)]))\r\nfor i in range(n-b+1):\r\n for j in range(m-a+1):\r\n ans_min = min(ans_min, sum([sum(fl[k][j:j+a]) for k in range(i, i+b)]))\r\nprint(ans_min)\r\n",
"n,m = map(int,input().split())\r\nlot = []\r\nfor i in range(n):\r\n lot.append(list(map(int,input().split())))\r\na,b = map(int,input().split())\r\n\r\nmn = 2500\r\nfor i in range(n-a+1):\r\n for j in range(m-b+1):\r\n curr = 0\r\n for i2 in range(i, i+a):\r\n for j2 in range(j, j + b):\r\n curr += lot[i2][j2]\r\n mn = min(mn, curr)\r\n\r\nfor i in range(n-b+1):\r\n for j in range(m-a+1):\r\n curr = 0\r\n for i2 in range(i, i+b):\r\n for j2 in range(j, j + a):\r\n curr += lot[i2][j2]\r\n mn = min(mn, curr)\r\n \r\nprint(mn)\r\n \r\n",
"n, m = map(int, input().split())\r\nx = [list(map(int, input().split())) for i in range(n)]\r\na, b = map(int, input().split())\r\ndef solve(n, m, x):\r\n y = [[0]*(m+1) for i in range(n+1)]\r\n for i in range(n):\r\n for j in range(m):\r\n y[i+1][j+1]=y[i+1][j]+x[i][j]\r\n for j in range(m):\r\n y[i+1][j+1]+=y[i][j+1]\r\n ans = n*m\r\n for i in range(a, n+1):\r\n for j in range(b, m+1):\r\n ans = min(ans, y[i][j]-y[i-a][j]-y[i][j-b]+y[i-a][j-b])\r\n return ans\r\nprint(min(solve(n, m, x), solve(m, n, list(map(list, zip(*x))))))",
"\r\n\r\n\r\nn,m= map(int,input().split())\r\n\r\n\r\nt=[]\r\n\r\nfor j in range(n):\r\n t.append(list(map(int,input().split())))\r\n\r\n\r\n\r\na,b = map(int,input().split())\r\nans=99999999\r\n\r\nfor i in range(n-a+1):\r\n for j in range(m-b+1):\r\n u=0\r\n for x in range(i,i+a):\r\n for y in range(j,j+b):\r\n u+=t[x][y]\r\n\r\n \r\n ans=min(ans,u)\r\n\r\nf=[]\r\n\r\nfor j in range(m):\r\n y=[]\r\n for k in range(n):\r\n y.append(t[k][j])\r\n f.append(y)\r\n\r\nfor i in range(m-a+1):\r\n for j in range(n-b+1):\r\n u=0\r\n for x in range(i,i+a):\r\n for y in range(j,j+b):\r\n u+=f[x][y]\r\n\r\n \r\n ans=min(ans,u)\r\n\r\nprint(ans)\r\n",
"'''\r\n\r\n Online Python Compiler.\r\n Code, Compile, Run and Debug python program online.\r\nWrite your code in this editor and press \"Run\" button to execute it.\r\n\r\n'''\r\n\r\nn,m=map(int,input().split())\r\nmat=[[0 for times in range(m)] for t in range(n)]\r\nfor i in range(n):\r\n temp=list(map(int,input().split()))\r\n for j in range(m):\r\n if temp[j]==0:\r\n if i==0:\r\n mat[i][j]=1\r\n else:\r\n mat[i][j]=mat[i-1][j]+1\r\n else:\r\n if i==0:\r\n mat[i][j]=0\r\n else:\r\n mat[i][j]=mat[i-1][j]\r\na,b=map(int,input().split())\r\n\r\nbest=1000\r\n\r\ni,j=0,a-1\r\nwhile j<m:\r\n for k in range(n-b+1):\r\n s=0\r\n for z in range(i,j+1):\r\n if k==0:\r\n val=mat[k+b-1][z]\r\n else:\r\n val=mat[k+b-1][z]-mat[k-1][z]\r\n s+=b-val\r\n \r\n if s<best:\r\n best=s\r\n \r\n i+=1\r\n j+=1\r\n \r\ni,j=0,b-1\r\nwhile j<m:\r\n for k in range(n-a+1):\r\n s=0\r\n for z in range(i,j+1):\r\n if k==0:\r\n val=mat[k+a-1][z]\r\n else:\r\n val=mat[k+a-1][z]-mat[k-1][z]\r\n s+=a-val\r\n if s<best:\r\n best=s\r\n \r\n i+=1\r\n j+=1 \r\n \r\nprint(best)\r\n",
"def findHouse(n,m,house,a,b):\r\n resTab1 = []\r\n resTab2 = []\r\n #First side\r\n for i in range(n):\r\n row1 = []\r\n for j in range(m):\r\n areaSum1 = 0 \r\n if i + b <= n and j + a <= m:\r\n for k in range(i,i+b):\r\n for l in range(j,j+a):\r\n areaSum1 += house[k][l]\r\n else:\r\n areaSum1 = None \r\n row1.append(areaSum1)\r\n resTab1.append(row1)\r\n #SecondSide\r\n for i in range(n):\r\n row2 = []\r\n for j in range(m):\r\n areaSum2 = 0\r\n if i + a <= n and j + b <= m:\r\n for k in range(i,i+a):\r\n for l in range(j,j+b):\r\n areaSum2 += house[k][l]\r\n else:\r\n areaSum2 = None\r\n row2.append(areaSum2)\r\n resTab2.append(row2)\r\n\r\n minTree = float('inf')\r\n\r\n res = []\r\n for i in range(n):\r\n for j in range(m):\r\n if resTab1[i][j] != None:\r\n res.append(resTab1[i][j]) \r\n if resTab2[i][j]!= None:\r\n res.append(resTab2[i][j]) \r\n #print(resTab1)\r\n #print(resTab2)\r\n #print(min(res))\r\n return min(res)\r\n\r\nn,m = [int(a) for a in input().split()]\r\nhouse = []\r\nfor i in range(n):\r\n house.append([int(a) for a in input().split() ])\r\n\r\na,b = [int(a) for a in input().split() ]\r\n\r\n\r\nprint(findHouse(n,m,house,a,b))\r\n\r\n\r\n \r\n",
"n, m = map(int, input().split())\r\ng, v = [], n * m\r\nfor i in range(n):\r\n g.append([0])\r\n for x in map(int, input().split()):\r\n g[-1].append(g[-1][-1] + x)\r\na, b = map(int, input().split())\r\nfor i in range(n):\r\n for j in range(1, m + 1):\r\n if i >= a - 1 and j >= b:\r\n v = min(v, sum(g[k][j] - g[k][j - b] for k in range(i - a + 1, i + 1)))\r\n if i >= b - 1 and j >= a:\r\n v = min(v, sum(g[k][j] - g[k][j - a] for k in range(i - b + 1, i + 1)))\r\nprint(v)",
"n,m=map(int,input().split())\r\nL=[list(map(int,input().split())) for i in range(n)]\r\na,b=map(int,input().split())\r\na,b=min(a,b),max(a,b)\r\nans=a*b;h=0\r\nfor i in range(n):\r\n for j in range(1,m):L[i][j]+=L[i][j-1]\r\nfor i in range(n):L[i].insert(0,0)\r\nfor i in range(m-b+1):\r\n\tfor j in range(n-a+1):\r\n\t\tfor k in range(a):h+=L[k+j][i+b]-L[k+j][i]\r\n\t\tans=min(ans,h)\r\n\t\th=0\r\nh=0\r\nfor i in range(m-a+1):\r\n\tfor j in range(n-b+1):\r\n\t\tfor k in range(b):h+=L[k+j][i+a]-L[k+j][i]\r\n\t\tans=min(ans,h);h=0\r\nprint(ans)",
"Y,X=map(int,input().split())\r\nPS=[]\r\nfor a in range(Y):\r\n F=[0]+list(map(int,input().split()))\r\n for i in range(X):F[i+1]+=F[i]\r\n PS.append(F)\r\ny,x=map(int,input().split())\r\nM=x*y\r\nfor a in range(Y-y+1):\r\n for b in range(X-x+1):\r\n m=sum([PS[a+i][b+x]-PS[a+i][b] for i in range(y)])\r\n M=min(M,m)\r\nx,y=y,x\r\nfor a in range(Y-y+1):\r\n for b in range(X-x+1):\r\n m=sum([PS[a+i][b+x]-PS[a+i][b] for i in range(y)])\r\n M=min(M,m)\r\nprint(M)",
"w,h=list(map(int,input().split(\" \")))\r\ndata=[list(map( int, input().split(\" \"))) for i in range(w)]\r\nhd=list(map(int,input().split(\" \")))\r\ncheck=[hd]\r\nif hd[0]!=hd[1]:\r\n check.append([hd[1],hd[0]])\r\nminimum=w*h\r\nfor d in check:\r\n for i in range(w-d[0]+1):\r\n for j in range(h-d[1]+1):\r\n amount=0\r\n for x in range(d[0]):\r\n for y in range(d[1]):\r\n amount+=data[i+x][j+y]\r\n if amount<minimum:\r\n minimum=amount\r\nprint(minimum)\r\n \r\n\r\n\r\n",
"def countTrees(cont:list,i:int,j:int,x:int,y:int)->int:\r\n ans = 0\r\n for rowInd in range(i,i+x):\r\n for colInd in range(j,j+y):\r\n ans += cont[rowInd][colInd]\r\n return ans\r\n\r\n\r\n\r\n\r\nn,m = [int(item) for item in input().split()]\r\ncont = []\r\nfor i in range(n):\r\n cont.append([int(item) for item in input().split()])\r\nx,y = [int(item) for item in input().split()]\r\nans = n * m\r\nfor i in range(n):\r\n for j in range(m):\r\n if i <= n - x and j <= m - y:\r\n helper = countTrees(cont,i,j,x,y)\r\n if ans > helper:\r\n ans = helper\r\n if i <= n - y and j <= m - x:\r\n helper = countTrees(cont,i,j,y,x)\r\n if ans > helper:\r\n ans = helper\r\n\r\nprint(ans)",
"n,m=map(int,input().split())\r\nL=[input().split() for i in range(n)]\r\na,b=map(int,input().split())\r\nc=a*b\r\na,b=min(a,b),max(a,b)\r\nfor i in range(m-b+1):\r\n\tfor j in range(n-a+1):\r\n\t\tl=[]\r\n\t\tfor k in range(a):l+=L[k+j][i:b+i]\r\n\t\tc=min(c,l.count('1'))\r\nfor i in range(m-a+1):\r\n\tfor j in range(n-b+1):\r\n\t\tl=[]\r\n\t\tfor k in range(b):l+=L[k+j][i:a+i]\r\n\t\tc=min(c,l.count('1'))\r\nprint(c)",
"\r\ndef STR(): return list(input())\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef MAP2():return map(float,input().split())\r\ndef LIST(): return list(map(int, input().split()))\r\ndef STRING(): return input()\r\nimport string\r\nimport sys\r\nfrom heapq import heappop , heappush\r\nfrom bisect import *\r\nfrom collections import deque , Counter , defaultdict\r\nfrom math import *\r\nfrom itertools import permutations , accumulate\r\ndx = [-1 , 1 , 0 , 0 ]\r\ndy = [0 , 0 , 1 , - 1]\r\n#visited = [[False for i in range(m)] for j in range(n)]\r\n# primes = [2,11,101,1009,10007,100003,1000003,10000019,102345689]\r\n#sys.stdin = open(r'input.txt' , 'r')\r\n#sys.stdout = open(r'output.txt' , 'w')\r\n#for tt in range(INT()):\r\n#arr.sort(key=lambda x: (-d[x], x)) Sort with Freq\r\n\r\n#Code\r\ndef solve1(n , m , a , b):\r\n ans = 1000000\r\n for i in range(n - a + 1):\r\n for j in range(m - b + 1):\r\n sm = 0\r\n for k in range(i , i + a ):\r\n for l in range(j , j + b):\r\n sm += g[k][l]\r\n ans = min(ans,sm)\r\n\r\n return ans\r\n\r\ndef solve2(n,m,a,b):\r\n ans1 = 1000000\r\n for i in range(n - b + 1):\r\n for j in range(m - a + 1):\r\n sm = 0\r\n for k in range(i , i + b ):\r\n for l in range(j , j + a):\r\n sm += g[k][l]\r\n ans1 = min(ans1 , sm)\r\n\r\n return ans1\r\n\r\nn , m = MAP()\r\ng= []\r\nfor i in range(n):\r\n g.append(LIST())\r\na , b = MAP()\r\n#print(g)\r\nr2=(solve1(n,m,a,b))\r\nr1 = (solve2(n,m,a,b))\r\nprint(min(r1,r2))\r\n\r\n"
] | {"inputs": ["2 2\n1 0\n1 1\n1 1", "4 5\n0 0 1 0 1\n0 1 1 1 0\n1 0 1 0 1\n1 1 1 1 1\n2 3", "3 3\n0 0 0\n0 0 0\n0 0 0\n1 2", "3 3\n1 1 1\n1 1 1\n1 1 1\n2 1", "3 2\n1 1\n1 1\n1 0\n2 1", "2 3\n1 0 1\n0 1 0\n3 2", "1 1\n0\n1 1", "1 1\n1\n1 1", "3 4\n1 0 1 0\n0 1 0 1\n1 0 1 0\n2 2", "3 4\n1 1 1 1\n1 0 0 1\n1 1 1 1\n3 1", "10 10\n1 1 1 0 0 0 0 1 1 0\n1 1 1 0 1 1 0 1 1 1\n1 0 1 1 0 1 1 1 1 0\n0 1 1 1 1 1 1 1 1 1\n1 1 1 1 0 1 1 1 1 1\n1 1 1 1 0 0 1 1 1 1\n1 1 1 1 0 1 1 1 0 1\n0 1 1 1 1 1 1 0 1 0\n1 1 1 1 1 0 0 1 0 1\n1 1 0 1 0 1 1 1 1 0\n5 4", "10 10\n0 1 1 1 1 1 1 0 1 1\n0 1 1 1 1 1 0 0 1 1\n1 1 0 0 1 1 0 0 0 0\n0 0 0 0 1 0 1 1 1 0\n1 0 1 0 1 0 1 1 1 1\n1 0 0 1 1 1 1 1 0 1\n0 0 0 1 1 0 1 1 1 0\n1 0 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n0 0 0 1 1 0 0 1 1 1\n1 10", "10 10\n1 0 1 1 1 1 0 0 1 1\n1 1 1 1 1 1 1 1 0 1\n1 0 0 1 1 1 1 1 1 1\n1 0 1 1 1 1 0 1 1 1\n0 0 1 0 1 1 1 1 1 1\n1 1 1 0 0 1 1 1 1 1\n0 1 1 0 1 1 0 1 1 0\n1 0 1 1 1 0 1 1 1 1\n1 0 1 1 1 0 1 1 0 1\n1 1 0 1 1 1 0 0 1 0\n10 1", "10 7\n0 1 1 0 0 1 1\n1 1 0 0 0 0 1\n0 1 0 0 0 1 0\n0 1 0 1 1 1 1\n1 1 0 1 0 0 1\n0 1 0 0 0 0 0\n0 1 0 0 1 0 1\n0 1 0 1 1 0 0\n1 1 0 1 1 1 0\n1 1 0 0 0 1 0\n1 8", "10 8\n1 1 0 1 1 1 0 0\n0 1 0 1 1 1 1 1\n1 1 0 0 1 0 0 1\n0 1 1 1 1 0 1 0\n0 1 1 0 1 1 0 1\n0 1 1 0 0 1 0 1\n1 0 0 0 1 1 0 1\n0 1 1 0 1 1 1 1\n0 1 1 1 0 1 0 1\n1 1 0 1 1 0 1 1\n4 9", "10 10\n1 0 1 1 1 1 1 1 1 1\n1 1 1 0 1 1 0 1 1 1\n1 1 1 0 1 1 1 1 0 1\n1 1 0 1 1 1 0 0 0 1\n0 1 0 1 1 1 0 1 1 1\n1 0 1 0 1 0 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 0 1 1\n1 1 1 1 0 1 1 1 1 1\n0 1 1 1 1 0 1 1 0 1\n10 10", "10 10\n0 1 1 0 0 0 1 0 0 0\n0 0 1 1 1 1 0 1 0 0\n1 1 0 1 1 0 0 1 0 0\n1 0 0 0 0 0 0 0 1 0\n0 0 0 1 0 0 0 1 0 0\n0 1 0 0 1 0 0 0 1 0\n0 1 0 1 1 1 1 0 0 0\n1 0 0 1 0 1 0 0 0 0\n0 0 0 0 1 0 0 0 0 0\n1 1 0 0 0 0 0 0 1 0\n3 7", "10 10\n1 1 1 0 1 1 1 1 0 0\n1 1 1 1 1 0 0 0 0 1\n0 1 1 0 0 1 1 1 0 0\n1 1 1 1 0 1 1 1 1 1\n1 0 0 1 0 1 1 1 1 1\n1 1 1 1 1 1 0 1 0 1\n1 1 1 1 1 1 1 1 0 0\n0 1 0 0 1 1 1 1 1 1\n0 1 1 1 0 1 0 1 0 0\n1 1 0 1 0 1 1 1 1 0\n6 7", "10 8\n0 1 1 1 1 1 1 0\n0 0 1 1 1 1 1 1\n0 1 0 1 1 1 1 0\n0 0 1 0 1 0 1 1\n0 1 1 1 1 1 1 1\n0 1 0 1 0 0 1 1\n0 0 0 0 0 0 0 1\n1 1 1 1 1 0 1 1\n1 1 1 0 1 1 1 0\n1 1 0 0 1 1 0 1\n8 10", "10 1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1 5"], "outputs": ["0", "2", "0", "2", "1", "3", "0", "1", "2", "1", "12", "4", "4", "0", "20", "80", "4", "27", "51", "4"]} | UNKNOWN | PYTHON3 | CODEFORCES | 32 | |
322ce5c93133c4b042488dad39f21d9a | Magnets | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.
Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.
Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
On the single line of the output print the number of groups of magnets.
Sample Input
6
10
10
10
01
10
10
4
01
01
10
10
Sample Output
3
2
| [
"n=int(input())\r\nm_o=[input() for _ in range(n)]\r\ngrp=1\r\nfor i in range(1,n):\r\n if m_o[i]!=m_o[i-1]:\r\n grp+=1\r\nprint(grp)\r\n \r\n ",
"def count_groups(n, magnets):\r\n groups = 1\r\n for i in range(1, n):\r\n if magnets[i] != magnets[i-1]:\r\n groups += 1\r\n return groups\r\n\r\n# Read input\r\nn = int(input())\r\nmagnets = [input() for _ in range(n)]\r\n\r\n# Count the number of groups formed by the magnets\r\nresult = count_groups(n, magnets)\r\n\r\n# Print the output\r\nprint(result)\r\n",
"import sys\r\nsys.setrecursionlimit(100000000)\r\ninput=lambda:sys.stdin.readline().strip()\r\nwrite=lambda x:sys.stdout.write(str(x))\r\n\r\n# from random import randint\r\n# from copy import deepcopy\r\n# from collections import deque\r\n# from heapq import heapify,heappush,heappop\r\n# from bisect import bisect_left,bisect,insort\r\n# from math import inf,sqrt,gcd,ceil,floor,log,log2,log10\r\n# from functools import cmp_to_key\r\n\r\nn=int(input())\r\ncnt=1\r\nlast=input()\r\nfor i in range(n-1):\r\n s=input()\r\n if s[0]==last[-1]:\r\n cnt+=1\r\n last=s\r\nprint(cnt)",
"_list = [input() for _ in range(int(input()))]\r\nprint(len([i for i in range(len(_list) - 1) if _list[i] != _list[i + 1]]) + 1)",
"n = int(input())\r\nx = [input() for i in range(n)]\r\ncount=0\r\nk = None\r\nfor j in x:\r\n if j !=k:\r\n count += 1\r\n k=j\r\nprint(count)\r\n\r\n",
"cnt = 0\r\nl_p = '2'\r\nfor _ in range(int(input())):\r\n i = input()\r\n if l_p == i[0] or l_p == '2':\r\n cnt += 1\r\n l_p = i[1]\r\nprint(cnt)",
"n=int(input())\r\ngroups=1\r\nlast=0\r\nfor i in range(n):\r\n x=int(input())\r\n if i==0:\r\n last=x\r\n else:\r\n if x==last:\r\n groups=groups+0\r\n else:\r\n groups=groups+1\r\n last=x\r\nprint(groups)",
"n=int(input())\r\nmagnets=[]\r\nfor i in range(n):\r\n magnet=input()\r\n magnets.append(magnet)\r\nx=1\r\nfor i in range(n-1):\r\n if magnets[i]==magnets[i+1]:\r\n x=x\r\n else:\r\n x+=1\r\nprint(x)",
"s = []\r\na = int(input())\r\nm = 1\r\nfor _ in range(a) :\r\n n = input()\r\n s.append(n)\r\n \r\nfor i in range(1,a) : \r\n if s[i] != s[i-1] :\r\n m+=1 \r\nprint(m) \r\n ",
"x = y = -1\r\nfor z in open(0):\r\n y += x != z\r\n x = z\r\nprint(y)\r\n\r\n",
"n = int(input())\nm = [input() for i in range(n)]\ng = 1 \nfor i in range(1,len(m)):\n if m[i] !=m[i-1]:\n g += 1 \nprint(g)",
"n = int(input())\nx = ''\nfor i in range(n):\n\tm = input()\n\tx += m\na = x.split('11')\nb = x.split('00')\n\nprint(len(a)+len(b)-1)",
"n=int(input())\r\nm=[input() for i in range(n)]\r\ngr=1\r\nfor i in range(1,n):\r\n if m[i]!=m[i-1]:\r\n gr+=1\r\nprint(gr)",
"num = int(input())\r\ncount = 0\r\ncheck = 0\r\nfor i in range(num):\r\n x = str(input())\r\n if check != x and i != 0:\r\n count += 1\r\n check = x\r\nprint(count + 1)",
"n=int(input())\r\nline=[]\r\nnum=1\r\nfor _ in range(n):\r\n line.append(input())\r\nfor _ in range(len(line)-1):\r\n if line[_]!=line[_+1]:\r\n num+=1\r\nprint(num)\r\n \r\n\r\n ",
"n = int(input(\"\"))\r\ncount = 1;\r\nlast = \"\"\r\nlast = input()\r\nfor i in range(n-1):\r\n now = input()\r\n if (last[1] == now[0]):\r\n count+=1;\r\n last = now\r\nprint(count)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Sep 21 21:44:50 2023\r\n\r\n@author: 2300011413\r\n\"\"\"\r\n\r\nn=int(input())\r\nnum=1\r\nmagnets=[]\r\nfor i in range(n):\r\n magnet=input()\r\n magnets.append(magnet)\r\n if i>=1:\r\n if magnets[i]!=magnets[i-1]:\r\n num+=1\r\nprint(num)",
"c=0\r\nx=0\r\nfor i in range(int(input())):\r\n s=int(input())\r\n if s!=x:\r\n c+=1\r\n x=s\r\nprint(c)\r\n",
"# Wadea #\r\n\r\narr = []\r\nfor i in range(int(input())):\r\n n = input()\r\n arr.append(n)\r\nc = 0\r\nfor i in range(1,len(arr)):\r\n if arr[i] == arr[i-1]:\r\n pass\r\n else:\r\n c += 1\r\nprint(c+1)\r\n",
"n=int(input())\r\na=[]\r\nfor i in range(n):\r\n a.append(int(input()))\r\nctr=1\r\nfor i in range(n-1):\r\n if a[i]!=a[i+1]:\r\n ctr+=1\r\nprint(ctr)\r\n",
"n=int(input())\r\nms=[]\r\nfor i in range (n):\r\n m=input()\r\n ms.append(m)\r\ncount=1\r\nfor i in range (1,n):\r\n if ms[i]!=ms[i-1]:\r\n count+=1\r\n \r\nprint(count)\r\n ",
"n = int(input())\r\nt = [input() for _ in range(n)]\r\nc = 1\r\nfor i in range(1, n):\r\n\r\n if not t[i] == t[i-1]:\r\n c += 1\r\nprint(c)\r\n\r\n",
"n = int(input())\r\nl = list()\r\n\r\nfor i in range(n):\r\n x = input()\r\n l.append(x)\r\ns = 0\r\nfor i in range(n-1):\r\n if l[i+1] != l[i]:\r\n s += 1\r\n\r\nprint(s+1)\r\n",
"def groups_of_magnets(magnets):\r\n groups = 1\r\n right_end = '-1'\r\n for m in magnets:\r\n if m[0] == right_end:\r\n groups += 1\r\n right_end = m[1]\r\n return groups\r\n\r\nn = int(input())\r\nmagnets = []\r\nfor i in range(n):\r\n magnets.append(input())\r\nprint(groups_of_magnets(magnets))",
"n = int(input())\r\nr, c, p = 0, [], -1\r\n\r\nfor i in range(n):\r\n c.append(input())\r\nfor t, i in enumerate(c):\r\n if t == len(c)-1:\r\n r += 1\r\n if p != -1 and p != i:\r\n r += 1\r\n p = i\r\n\r\nprint(r)",
"n = int(input())\r\nr = \"\"\r\n\r\nfor i in range(n):\r\n r += f\"{input()} \"\r\nprint(r.count(\"10 01\")+ r.count(\"01 10\")+1)",
"num = int(input())\r\nposible = 0\r\nar = [0]\r\nwhile num > 0:\r\n check = input()\r\n if check != ar[-1]:\r\n ar.append(check)\r\n posible += 1\r\n \r\n num -= 1\r\nprint(posible)",
"import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef solve():\r\n # Your code goes here\r\n pass \r\n\r\ndef main():\r\n currentMag = \"\"\r\n groupN = 0\r\n for i in range(int(input())):\r\n mag = input().strip()\r\n if currentMag != mag:\r\n groupN += 1\r\n currentMag = mag\r\n print(groupN)\r\n \r\n\r\nif __name__ == \"__main__\":\r\n main()",
"if __name__ == \"__main__\":\r\n num = int(input())\r\n result = 1\r\n pole = '-1'\r\n for i in range(num):\r\n poles = input()\r\n if pole == '-1':\r\n pole = poles[1]\r\n else:\r\n if pole == poles[0]:\r\n result += 1\r\n pole = poles[1]\r\n print(result)\r\n",
"k = int(input())\r\na = ''\r\nfor i in range(0,k):\r\n m = input()\r\n a +=m\r\ncount = 1\r\nfor i in range(0, len(a)-1):\r\n if(a[i]==a[i+1]):\r\n count+=1\r\nprint(count)",
"n = int(input())\r\njudge = \"\"\r\nfor _ in range(n):\r\n word = input()\r\n judge = judge + word\r\njudge_list = list(judge)\r\nk = 1\r\nfor i in range(int(len(judge_list))-1):\r\n if judge_list[i] == judge_list[i+1]:\r\n k += 1\r\nprint(k)",
"# Read the number of magnets\r\nn = int(input())\r\n\r\n# Initialize variables to keep track of the current magnet and the number of groups\r\ncurrent_magnet = None\r\ngroups = 0\r\n\r\n# Iterate over the magnets\r\nfor _ in range(n):\r\n magnet = input()\r\n # Check if the current magnet is different from the previous one\r\n if magnet != current_magnet:\r\n groups += 1\r\n current_magnet = magnet\r\n\r\n# Print the number of groups\r\nprint(groups)\r\n",
"prev_line = curr_line = -1\r\nfor line in open(0):\r\n curr_line += prev_line != line\r\n prev_line = line\r\nprint(curr_line)\r\n",
"# -*- coding: utf-8 -*-\n\"\"\"Magnets.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1Cmo8WcC1xV3Z1225lHEffNJadxoszQTv\n\"\"\"\n\nn = int(input())\ngroups = 0\nmagnet_0 = input()\nfor i in range(n-1):\n magnet_1 = input()\n if magnet_0[1]==magnet_1[0]:\n groups += 1\n magnet_0 = magnet_1\nprint(groups + 1)",
"n = int(input())\r\npairs = 1\r\nmag = str(input())\r\npole = mag[-1]\r\nfor i in range(n - 1):\r\n mag = str(input())\r\n if mag[0] == pole:\r\n pairs += 1\r\n pole = mag[-1]\r\n\r\nprint(pairs)",
"n = int(input())\r\n\r\ngroups = 1\r\nprior = input()\r\nfor i in range(n-1):\r\n cur = input()\r\n if cur != prior:\r\n groups += 1\r\n\r\n prior = cur\r\n\r\nprint(groups)",
"n = int(input())\r\nli=[]\r\ni=0\r\nwhile i<n:\r\n number = int(input())\r\n li.append(number)\r\n i+=1\r\n\r\nislands =1\r\nj=0\r\nwhile j<n-1:\r\n if li[j]!=li[j+1]:\r\n islands+=1\r\n j+=1\r\nprint(islands)",
"n=int(input())\r\na=int(input())\r\nl=1\r\nfor i in range(n-1):\r\n b = int(input())\r\n if a!=b:\r\n l+=1\r\n a=b\r\nprint(l)",
"n = int(input())\r\nk = []\r\nfor i in range(n):\r\n\r\n x = int(input())\r\n k.append(x)\r\n \r\ncount = 1\r\n\r\nfor i in range(n-1):\r\n if k[i] == k[i+1]:\r\n continue\r\n else:\r\n count += 1\r\n\r\nprint(count) ",
"l=[];g=1\r\nfor i in range(int(input())):\r\n l.append(input())\r\nt=l[0]\r\nfor i in l:\r\n if i==t:\r\n continue\r\n else:\r\n g+=1\r\n t=i\r\nprint(g)",
"mag = ''\r\nfor i in range(int(input())):\r\n mag+=input()\r\n \r\nchunk = 1\r\nfor i in range(1,len(mag)-1):\r\n chunk+= 1 if mag[i]==mag[i+1] else 0\r\nprint(chunk)\r\n ",
"l=int(input())\r\nt = input()\r\nr=1\r\nfor _ in range(l-1):\r\n i = input()\r\n if t!=i:\r\n r+=1\r\n t=i\r\nprint(r)",
"s=0\r\nt=int(input())\r\nx=input()\r\nfor _ in range(t-1):\r\n k=input()\r\n if(k[0]==x[-1]):\r\n s+=1\r\n x=k\r\nprint(s+1)",
"n=int(input())\r\nrow=[]\r\ncount=1\r\nfor i in range(0,n):\r\n magnent=int(input())\r\n row.append(magnent)\r\nfor j in range(0,n-1):\r\n if row[j]!=row[j+1]:\r\n count+=1\r\n else:\r\n count+=0\r\nprint(count)\r\n",
"import sys\n\ninput = sys.stdin.readline\n\nn = int(input())\n\nclusters = 1\n\nprev = input()[:-1]\n\nfor _ in range(n - 1):\n current = input()[:-1]\n if current[0] == prev[1]:\n clusters += 1\n\n prev = current\n\nsys.stdout.write(f\"{clusters}\")\n",
"n = int(input())\r\nk = 1\r\ns = []\r\n\r\nfor i in range(n):\r\n x = input()\r\n s.append(x)\r\n\r\nfor i in range(len(s) - 1):\r\n if s[i] != s[i + 1]:\r\n k += 1\r\n\r\nprint(k)",
"n = int(input())\r\nsm = 1\r\nflag = input()\r\nfor i in range(1, n):\r\n b = input()\r\n if flag != b:\r\n sm += 1\r\n flag = b\r\n\r\nprint(sm)\r\n",
"n = int(input())\r\na = [input() for _ in range(n)]\r\ncount = 1\r\nx = a[0]\r\nfor i in range(n):\r\n if a[i] == x:\r\n continue\r\n else:\r\n x = a[i]\r\n count += 1\r\nprint(count)",
"t= int(input())\r\nres=1\r\nlast=input()[-1]\r\nfor i in range(t-1):\r\n s=input()\r\n if last!=s[-1]:\r\n res+=1\r\n last=s[-1]\r\nprint(res)",
"n = int(input())\r\ncounter = 0\r\n\r\nfor i in range(n):\r\n magnet = input()\r\n if i == 0:\r\n last_char = magnet[-1]\r\n else:\r\n if magnet[0] == last_char:\r\n counter += 1\r\n last_char = magnet[-1]\r\n\r\nprint(counter + 1)",
"n = int(input())\r\n\r\npre = input()\r\ngroup = 1\r\n\r\nfor i in range(1, n):\r\n cur = input()\r\n if (cur[0] == pre[1]):\r\n group += 1\r\n pre = cur\r\n\r\nprint(group)\r\n",
"l=[]\r\nr=1\r\nfor i in range(int(input())):\r\n x=int(input())\r\n l.append(x)\r\nfor i in range(len(l)-1):\r\n if l[i] != l[i+1]:\r\n r+=1\r\n\r\nprint(r)\r\n",
"def solution(n):\r\n previous_magnet = ''\r\n flip = 0\r\n\r\n for _ in range(n):\r\n current_magnet = input()\r\n if current_magnet != previous_magnet:\r\n flip += 1\r\n previous_magnet = current_magnet\r\n\r\n print(flip)\r\n\r\nn = int(input())\r\nsolution(n)",
"n=int(input())\r\nd=[]\r\ns=1\r\nfor i in range(n):\r\n dom=input()\r\n d.append(dom)\r\nfor i in range(n-1):\r\n #print(d[i])\r\n #print(d[i+1])\r\n if d[i]!=d[i+1]:\r\n s+=1\r\nprint(s)",
"n, c = 0, 0\r\nfor _ in range(int(input())):\r\n prev = n\r\n n = int(input())\r\n if prev!=n:\r\n c+=1\r\nprint(c)",
"w2=Tw2=-1\r\nfor swg in open(0):Tw2+=w2!=swg;w2=swg\r\nprint(Tw2)\r\n",
"n = int(input())\r\nres = []\r\nfor i in range(n):\r\n res.append(int(input()))\r\ncount = 1\r\nfor i in range(len(res) - 1):\r\n if res[i] != res[i+1]:\r\n count += 1\r\nprint(count)\r\n",
"n = int(input())\r\nmagnet = [input() for i in range(n)]\r\n\r\ncount = 1 \r\n\r\nfor i in range(1, n):\r\n if magnet[i] != magnet[i - 1]:\r\n count += 1\r\n\r\nprint(count)",
"line1 = input()\r\nnumOfmagnets = int(line1)\r\n\r\nnew_list = []\r\nold_list = []\r\n\r\ndef caculateMagnet(old_list):\r\n for number in old_list:\r\n if new_list == [] or number != new_list[-1]:\r\n new_list.append(number)\r\n \r\nfor magnet in range(numOfmagnets):\r\n position = int(input())\r\n old_list.append(position)\r\n \r\ncaculateMagnet(old_list)\r\n\r\nprint(len(new_list))",
"# Read the number of magnets\r\nn = int(input())\r\n\r\n# Read the magnet orientations and store them in a list\r\nmagnet_orientations = [input() for _ in range(n)]\r\n\r\n# Initialize variables to keep track of groups and previous orientation\r\ngroups = 0\r\nprev_orientation = \"\"\r\n\r\n# Iterate through each magnet's orientation\r\nfor orientation in magnet_orientations:\r\n # If the current orientation is different from the previous one, it forms a new group\r\n if orientation != prev_orientation:\r\n groups += 1\r\n prev_orientation = orientation\r\n\r\n# Print the number of groups\r\nprint(groups)\r\n",
"n = int(input())\r\nans = 1\r\nmgns = []\r\nfor _ in range(n):\r\n mgn = input()\r\n mgns.append(mgn)\r\nfor i in range(n-1):\r\n if mgns[i] != mgns[i+1]:\r\n ans += 1\r\nprint(ans)",
"n=int(input())\r\ns=[]\r\nv=0\r\nfor i in range(n):\r\n s.append(int(input()))\r\nfor i in range(n-1):\r\n if s[i]!=s[i+1]:\r\n v=v+1\r\nprint(v+1)\r\n",
"n = int(input())\nmagnets = []\n\nfor x in range(n):\n temp = input()\n magnets.append(temp)\nislands = 1\nfor key,item in enumerate(magnets):\n if key != 0 and item != magnets[key-1]:\n islands += 1\n\nprint(islands) ",
"num = int(input())\r\nmag_list = []\r\nmag_list.append(input())\r\ncounter = 1\r\n\r\nfor i in range(num - 1):\r\n new_item = input()\r\n if new_item[0] == mag_list[-1][1]:\r\n counter += 1\r\n mag_list.append(new_item)\r\n\r\nprint(counter)\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Oct 2 15:49:44 2023\r\n\r\n@author: 25419\r\n\"\"\"\r\n\r\nn=int(input())\r\nsum=1\r\nstr1='2'\r\nfor i in range(n):\r\n temp=input()\r\n str1=str1+temp\r\n \r\nfor i in range(1,2*n):\r\n if str1[i]==str1[i-1]:\r\n sum=sum+1\r\nprint(sum)",
"n = int(input())\r\n\r\nmagnets = []\r\nfor i in range(n):\r\n magnets.append(input())\r\n\r\ncount = 1\r\nfor i in range(n-1):\r\n if magnets[i] != magnets[i+1]:\r\n count += 1\r\nprint(count)",
"n = int(input())\r\nx=[]\r\nfor i in range(n):\r\n a=int(input())\r\n x.append(a)\r\nM=1\r\nfor i in range(n-1):\r\n if((x[i]==10 and x[i+1]==1) or (x[i]==1 and x[i+1]==10)):\r\n M+=1\r\nprint(M)",
"num = int(input())\r\ncount = 1\r\nmagnets= str()\r\n\r\nfor i in range(num):\r\n magnet = input()\r\n magnets += magnet\r\n\r\ncount += magnets.count('00')\r\ncount += magnets.count('11')\r\n \r\nprint(count)",
"n = int(input())\r\na = []\r\nfor _ in range(n):\r\n b = input()\r\n a.append(b)\r\nc = 1\r\nfor i in range(n-1):\r\n if a[i][1]==a[i+1][0]:\r\n c = c+1\r\nprint(c)",
"a=int(input())\r\nlast=5\r\npast=0\r\ncnt=0\r\n\r\nfor x in range(a):\r\n mag=input()\r\n if mag!=past:\r\n cnt=cnt+1\r\n \r\n if mag[-1]==last:\r\n last=mag[-1]\r\n elif mag[-1]!=last:\r\n past=mag\r\n\r\n\r\nprint(cnt)",
"def count_magnet_groups(n, magnets):\r\n groups = 0\r\n prev_magnet = None\r\n \r\n for magnet in magnets:\r\n if magnet != prev_magnet:\r\n groups += 1\r\n prev_magnet = magnet\r\n \r\n return groups\r\n\r\nn = int(input())\r\nmagnets = [input() for _ in range(n)]\r\nresult = count_magnet_groups(n, magnets)\r\nprint(result)\r\n",
"n=int(input())\r\nnew=[]\r\nfor i in range(n):\r\n a=input()\r\n new.append(a)\r\ncount=1\r\nfor j in range(len(new)-1):\r\n if new[j]!=new[j+1]:\r\n count += 1\r\nprint(count)",
"import sys\r\ndata = sys.stdin.read().strip().split(\"\\n\")\r\nn, magnets = int(data[0]), data[1:]\r\nprint(sum(1 for a, b in zip(magnets, magnets[1:]) if a != b) + 1)",
"n = int(input())\r\nprev = ['#', '#']\r\ncount = 0\r\nfor _ in range(n):\r\n s = [*input()]\r\n if s[0] == prev[1] or prev[1] == '#':\r\n count += 1\r\n prev = s\r\nprint(count)\r\n",
"'''\r\n==TEST CASE==\r\nInput:\r\n6\r\n10\r\n10\r\n10\r\n01\r\n10\r\n10\r\n\r\nOutput:\r\n3\r\n'''\r\nn=int(input())\r\nl=[]\r\ngroup=1\r\n\r\nfor i in range(n):\r\n val=int(input())\r\n l.append(val)\r\n if val != l[i-1]:\r\n group+=1\r\n\r\nprint(group)",
"def count_magnet_groups(n, magnets):\r\n groups = 1 # Initialize with 1 group for the first magnet\r\n for i in range(1, n):\r\n if magnets[i] != magnets[i - 1]:\r\n groups += 1\r\n return groups\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n magnets = [input() for _ in range(n)]\r\n result = count_magnet_groups(n, magnets)\r\n print(result)\r\n",
"# Read the number of magnets\r\nn = int(input())\r\n\r\n# Read the magnet configurations into a list\r\nmagnets = [input() for _ in range(n)]\r\n\r\n# Initialize variables to count the groups and the current group\r\ngroups = 0\r\ncurrent_group = magnets[0]\r\n\r\n# Iterate through the magnets\r\nfor magnet in magnets:\r\n if magnet != current_group:\r\n groups += 1\r\n current_group = magnet\r\n\r\n# The last magnet is also a group\r\ngroups += 1\r\n\r\n# Print the number of groups\r\nprint(groups)\r\n",
"p = f = -1\r\nfor s in open(0): \r\n f += str(p) != str(s)\r\n p = s\r\nprint(f)",
"num = int(input())\r\nmagnets = list()\r\ncount = 1\r\n\r\nfor i in range(num):\r\n magnet = input()\r\n magnets.append(magnet)\r\n\r\nfor j in range(num-1):\r\n if magnets[j] != magnets[j+1]:\r\n count+=1\r\n\r\nprint(count)",
"try:\r\n n = int(input())\r\n if n >= 1 and n <= 100000:\r\n m = [input() for i in range(n)]\r\n verticle = True\r\n for i in m:\r\n if i not in [\"01\",\"10\"]:\r\n verticle = False\r\n break\r\n del i\r\n if verticle == True:\r\n g, p = 1,m[0]\r\n for i in m[1:]:\r\n if i == p[::-1]:\r\n g+=1\r\n p = i\r\n print(g)\r\nexcept: pass",
"def Magnets():\r\n n = int(input())\r\n old = 0\r\n group = 0\r\n for i in range(n):\r\n current = int(input())\r\n if old != 0:\r\n if current != old:\r\n group += 1\r\n old = current \r\n print(group+1)\r\n\r\nMagnets()",
"n= int(input())\r\ny = []\r\nfor i in range(n):\r\n x = input()\r\n y.append(x)\r\nc = 0\r\nfor i in range(n-1):\r\n if y[i] != y[i+1]:\r\n c+=1\r\nprint(c+1)",
"c=1\r\nn=int(input())\r\narr=[]\r\nfor i in range(n):\r\n arr.append(str(input()))\r\n\r\nfor i in range(n-1):\r\n if arr[i]!=arr[i+1]:\r\n c+=1\r\n\r\nprint(c)\r\n",
"n = int(input())\r\n\r\nlst = []\r\ncnt = 1\r\nc = 'm'\r\nfor i in range(n):\r\n s = input()\r\n if s[0] == c:\r\n cnt += 1\r\n c = s[1]\r\n \r\nprint(cnt)",
"n=int(input(\"\"))\r\ny=[]\r\nc=0\r\nfor i in range (n):\r\n x=input(\"\")\r\n y.append(x)\r\nfor e in range (n):\r\n if e > n-2:\r\n break\r\n elif y[e]!=y[e+1] :\r\n c+=1\r\nprint(c+1)",
"n = int(input())\r\nmagnets=[]\r\nfor _ in range(n):\r\n magnet=input().strip()\r\n magnets.append(magnet)\r\ngroup_count=1\r\ncurrent_orientation=magnets[0]\r\nfor magnet in magnets[1:]:\r\n if magnet != current_orientation:\r\n group_count+=1\r\n current_orientation=magnet\r\nprint(group_count)",
"def main():\r\n n = int(input())\r\n previous = 0\r\n total = 0\r\n\r\n for _ in range(n):\r\n current = int(input())\r\n if current != previous:\r\n total += 1\r\n previous = current\r\n\r\n print(total)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"x=int(input())\r\nl=[]\r\ncount=0\r\nfor i in range(x):\r\n y=int(input())\r\n l.append(y)\r\nfor j in range(x-1):\r\n if l[j] != l[j+1]:\r\n count=count+1\r\nprint(count+1)",
"n=int(input())\r\nmg=[input() for _ in range(n)]\r\ng=1\r\nfor i in range(1,n):\r\n if mg[i]!=mg[i-1]:\r\n g+=1\r\nprint(g)",
"n = int(input())\r\nm = \"m\"\r\nm2 = m\r\ncnt = 0\r\nfor i in range(n):\r\n m2 = m\r\n m = input()\r\n if m != m2:\r\n cnt += 1\r\nprint(cnt)",
"a=c=-1\r\nfor b in open(0):c+=a!=b;a=b\r\nprint(c)\r\n#hi codeforces\r\n#",
"x=int(input())\r\nf1=[]\r\ns1=[]\r\nfor i in range(x):\r\n s=list(input())\r\n if len(s1)==0:\r\n s1=s\r\n else:\r\n if s1[len(s1)-1]!=s[0]:\r\n s1.append(s[0])\r\n s1.append(s[1])\r\n else:\r\n f1.append(s1)\r\n s1=[]\r\n s1.append(s[0])\r\n s1.append(s[1])\r\nf1.append(s1)\r\nprint(len(f1))\r\n",
"n=int(input())\r\nmagnets=[input() for i in range(n)]\r\n\r\ngroups=1\r\n\r\nfor i in range(1,n):\r\n if magnets[i] != magnets[i-1]:\r\n groups +=1\r\n \r\nprint(groups)",
"n = int(input())\r\ng = 1\r\nm = input()\r\nfor i in range(n-1):\r\n m2 = input()\r\n if m != m2:\r\n m = m2\r\n g += 1\r\nprint(g)\r\n",
"n = int(input())\r\nk = 1\r\nt = []\r\nfor i in range(n):\r\n s = input()\r\n if t:\r\n if t[-1] != s:\r\n k+=1\r\n t.append(s)\r\n \r\nprint(k)\r\n ",
"n= int(input())\r\na=[]\r\ncount=0\r\nfor i in range(n):\r\n new= int(input())\r\n a.append(new)\r\n if i>0:\r\n if a[i]!=a[i-1]:\r\n count=count+1\r\nprint(count+1)\r\n \r\n",
"n = int(input())\nans = 1\narr = []\nfor i in range(n):\n arr.append(int(input()))\nfor i in range(1, len(arr)):\n if arr[i] != arr[i-1]:\n ans += 1\nprint(ans)\n",
"n = int(input())\n\nn_groups = 1\nlast_sign = None\nfor _ in range(n):\n s = input()\n if s[0] == last_sign:\n n_groups += 1\n last_sign = s[1]\nprint(n_groups)\n",
"n=input()\nn=int(n)\n\nlist=[]\nfor i in range(0,n,1):\n s=input()\n list.append(s)\n\ncnt=0\n\nfor i in range(1,n,1):\n if list[i]!=list[i-1]:\n cnt+=1\n\nprint(cnt+1)\n\n\t\t \t \t \t \t \t\t \t\t\t \t\t \t",
"n = int(input())\r\ns = ''\r\nm = 0\r\nfor i in range(n):\r\n a = input()\r\n s = s + a\r\nfor j in range(0,len(s)-3,2):\r\n if s[j]+s[j+1] != s[j+2]+s[j+3]:\r\n m = m + 1\r\nprint(m+1)\r\n",
"n = int(input())\r\ncount = 0 \r\nj = 0 \r\nfor i in range(0,n):\r\n s = int(input())\r\n if(j!=s):\r\n count += 1\r\n j = s \r\n else:\r\n j=s \r\nprint(count)\r\n\r\n\r\n",
"n = int(input())\r\ns = []\r\nfor _ in range(n):\r\n i = input()\r\n s.append(i)\r\n\r\ndef magnet_groups(s):\r\n group = 1\r\n for i in range(1, len(s)):\r\n if s[i] != s[i - 1]:\r\n group += 1\r\n return group\r\n \r\nresult = magnet_groups(s)\r\nprint(result)\r\n",
"# Read the number of magnets\r\nn = int(input())\r\n\r\n# Read the first magnet\r\nprev_magnet = input()\r\n\r\n# Initialize the number of groups to 1 (assuming the first magnet starts a group)\r\nnum_groups = 1\r\n\r\n# Iterate through the remaining magnets\r\nfor _ in range(1, n):\r\n current_magnet = input()\r\n \r\n # If the current magnet is different from the previous one, it starts a new group\r\n if current_magnet != prev_magnet:\r\n num_groups += 1\r\n \r\n # Update the previous magnet\r\n prev_magnet = current_magnet\r\n\r\n# Print the number of groups\r\nprint(num_groups)\r\n",
"N=int(input())\r\nlist1=[]\r\nfor m in range(N):\r\n A=int(input())\r\n list1.append(A)\r\ncount=1\r\nfor i in range(1,N):\r\n if list1[i]!=list1[i-1]:\r\n count+=1\r\nprint(count)",
"x = int(input())\r\nct = 1\r\ns = []\r\nfor i in range (0,x):\r\n s.append(input())\r\n if s[i] != s[i-1]:\r\n ct = ct + 1\r\nprint(ct) ",
"n=int(input())\r\nlist=[]\r\nnum=1\r\nfor i in range(n):\r\n list.append(input())\r\nfor i in range(n-1):\r\n if list[i][1]==list[i+1][0]:\r\n num+=1\r\nprint(num)",
"n = int(input())\r\nmagnets = [input() for _ in range(n)]\r\n# print(magnets)\r\n\r\ngroup = 1\r\n\r\nfor i in range(1, n):\r\n if magnets[i] != magnets[i-1]:\r\n group += 1\r\n \r\nprint(group)",
"n = int(input())\r\n\r\ndomno_list = []\r\n\r\nfor i in range(n):\r\n x = input()\r\n domno_list.append(list(x)) \r\n\r\ngroup_list = 1\r\n\r\nfor j in range(len(domno_list)-1):\r\n if domno_list[j][1] == \"0\" and domno_list[j+1][0] == \"1\":\r\n group_list = group_list\r\n\r\n elif domno_list[j][1] == \"1\" and domno_list[j+1][0] == \"0\":\r\n group_list = group_list\r\n \r\n elif domno_list[j][1] == \"0\" and domno_list[j+1][0] == \"0\":\r\n group_list += 1\r\n \r\n elif domno_list[j][1] == \"1\" and domno_list[j+1][0] == \"1\":\r\n group_list += 1\r\n \r\n else:\r\n group_list = group_list\r\n \r\nprint(group_list)",
"n = int(input())\r\n\r\ngroups = 1 \r\nprev_magnet = input()\r\n\r\nfor _ in range(n - 1):\r\n magnet = input()\r\n \r\n if magnet != prev_magnet:\r\n groups += 1\r\n \r\n prev_magnet = magnet\r\n\r\nprint(groups)\r\n",
"n = int(input())\r\na = []\r\nfor i in range(n):\r\n a.append(int(input()))\r\ntemp = a[0]\r\nkolvo = 1\r\nfor i in range(1, n):\r\n if not (a[i] == temp):\r\n temp = a[i]\r\n kolvo += 1\r\nprint(kolvo)\r\n ",
"n = int(input())\r\nmagnets = []\r\nfor _ in range(n):\r\n magnet = input() \r\n magnets.append(magnet)\r\ngroups = 1\r\nfor i in range(1, n):\r\n if magnets[i] != magnets[i-1]:\r\n groups += 1\r\nprint(groups)\r\n",
"n=int(input())\r\nli=[]\r\nfor i in range(n):\r\n item=input()\r\n li.append(item)\r\nresult=1\r\nfor i in range(n-1): \r\n if li[i][1]==li[i+1][0]:\r\n result+=1\r\nprint(result)",
"# import sys \n# sys.stdin = open(\"/Users/swasti/Desktop/coding/cp/codeforces/input.txt\", \"r\")\n# sys.stdout = open(\"/Users/swasti/Desktop/coding/cp/codeforces/output.txt\", \"w\")\ncount = 1\nmagnet = []\nr = int(input())\nfor i in range (r):\n polarity = input()\n magnet.append(polarity)\n if magnet[i] != magnet [i-1]:\n count += 1\nprint(count)",
"a = [input() for _ in range(int(input()))]\r\nprint(1 + sum(1 for x, y in zip(a, a[1:]) if x != y))",
"n = int(input())\r\nc = 0\r\nl = None\r\nfor i in range(n):\r\n m = input()\r\n if l == None:\r\n l = m[1]\r\n c += 1\r\n elif m[0] == l:\r\n c += 1\r\n l = m[1]\r\nprint(c)",
"n=int(input())\r\na=int(input())\r\ns=1\r\nfor i in range(n-1):\r\n b=int(input())\r\n if a != b:\r\n s += 1\r\n a=b\r\nprint(s) \r\n \r\n ",
"n = int(input())\r\nprev = input()\r\ngrp = 1\r\nfor i in range(1,n):\r\n curr = input()\r\n if(prev != curr):\r\n grp += 1\r\n prev = curr\r\nprint(grp)",
"n=int(input())\r\ncount=1\r\nl1=input()\r\nfor i in range(1,n):\r\n l2=input()\r\n if l1!=l2:\r\n count=count+1\r\n l1=l2\r\n\r\nprint(count)\r\n \r\n",
"x=int(input())\r\ncounter =0\r\nfirst_input=input()\r\nfor i in range(1,x):\r\n mag=input()\r\n if mag == first_input:\r\n continue\r\n else :\r\n first_input = mag\r\n counter +=1\r\ncounter+=1\r\nprint (counter)\r\n\r\n",
"n = int(input())\r\ng=0\r\na=[]\r\nfor i in range(0,n):\r\n b= int(input())\r\n a.append(b)\r\nmag=1\r\nfor j in range(0,n-1):\r\n if a[j]!=a[j+1]:\r\n mag+=1\r\nprint(mag)",
"s=int(input())\r\nn=[input() for _ in range(s)]\r\nc=1\r\nfor i in range(1,s):\r\n if n[i]!=n[i-1]:\r\n c+=1\r\nprint(c)\r\n \r\n ",
"n = int(input())\r\nvastus = 0\r\nnumber1 = \"1\"\r\nfor i in range(n):\r\n number = input()\r\n \r\n if number1 != number:\r\n vastus += 1\r\n \r\n number1 = number\r\n\r\nprint(vastus)\r\n",
"n = int(input())\r\nl = []\r\nfor i in range(n):\r\n s = input()\r\n l.append(s)\r\ncnt = 1\r\nfor i in range(len(l)-1):\r\n if l[i]!=l[i+1]:\r\n cnt+=1\r\nprint(cnt)",
"n = int(input())\r\ncount = 0\r\nprevious = 2\r\nfor i in range(n):\r\n x = int(input())\r\n if x != previous:\r\n count += 1\r\n previous = x\r\nprint(count)\r\n",
"n = int(input())\r\nk=1\r\npr = 0\r\nfor i in range(n):\r\n m =int(input())\r\n\r\n if i!=0 and m!=pr:\r\n k+=1\r\n pr = m\r\nprint(k)",
"n=int(input())\r\nc=[]\r\nc1=1\r\nfor i in range(n):\r\n r=int(input())\r\n c.append(r)\r\nfor i in range(1,n):\r\n if(c[i]!=c[i-1]):\r\n c1+=1\r\nprint(c1) ",
"n = int(input())\r\nnums = []\r\ncount = 1\r\nfor i in range(n):\r\n a = input()\r\n nums.append(a)\r\n if nums[i] != nums[i - 1]:\r\n count += 1\r\nprint(count)",
"m = int(input())\r\nr = 0\r\nprev = 0\r\nfor i in range(m):\r\n n = int(input())\r\n if n!= prev:\r\n r += 1\r\n prev = n\r\nprint(r)",
"n = int(input())\r\nk=0;\r\ns = ''\r\nfor i in range(n):\r\n s+=input()\r\nfor j in range(1, n*2):\r\n if s[j-1] == s[j]:\r\n k += 1\r\nprint(k+1)\r\n \r\n",
"# Read the number of magnets\r\nn = int(input())\r\n\r\n# Initialize variables\r\ngroups = 1 # At least one group for the first magnet\r\nprev_magnet = input()\r\n\r\n# Iterate through the remaining magnets\r\nfor _ in range(n - 1):\r\n current_magnet = input()\r\n \r\n # If the orientation of the current magnet is different from the previous one,\r\n # increment the group count\r\n if current_magnet != prev_magnet:\r\n groups += 1\r\n \r\n # Update the previous magnet orientation\r\n prev_magnet = current_magnet\r\n\r\n# Print the number of groups\r\nprint(groups)",
"def my_solution(n):\r\n magnets = [input() for _ in range(n)]\r\n\r\n flip = 1\r\n for i in range(len(magnets) - 1):\r\n if magnets[i] != magnets[i+1]:\r\n flip += 1\r\n\r\n print(flip)\r\n\r\nn = int(input())\r\nmy_solution(n)",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 12 23:10:19 2023\r\n\r\n@author: Zinc\r\n\"\"\"\r\nlist=[]\r\ns=1\r\nn=int(input())\r\nfor i in range(n):\r\n list.append(input())\r\nstart=list[0]\r\nfor c in list:\r\n if c==start:\r\n continue\r\n else:\r\n s+=1\r\n start=c\r\nprint(s)\r\n \r\n ",
"a=[]\r\nn=int(input())\r\nct=1\r\nfor _ in range(n):\r\n a.append(int(input()))\r\nfor i in range(1,n):\r\n if a[i]!=a[i-1]:\r\n ct+=1\r\nprint(ct)",
"n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n k=input()\r\n l.append(k)\r\ng=0\r\nfor i in range(n-1):\r\n if((l[i]=='10' and l[i+1]=='01') or (l[i]=='01' and l[i+1]=='10')):\r\n g+=1\r\nprint(g+1)\r\n \r\n ",
"n = int(input())\r\nlst = [input() for i in range(n)]\r\ncount = 1\r\nfor i in range(n-1):\r\n if lst[i][1] == lst[i+1][0]:\r\n count += 1\r\nprint(count)",
"t = int(input())\r\na = list()\r\nfor i in range(t):\r\n x = int(input())\r\n a.append(x)\r\nc = 1\r\nif t == 1:\r\n c = 1\r\nelse:\r\n for i in range(t-1):\r\n if a[i] != a[i+1]:\r\n c = c + 1\r\nprint(c)",
"def count_groups_of_magnets(n, magnets):\r\n count = 1\r\n for i in range(1, n):\r\n if magnets[i] != magnets[i - 1]:\r\n count += 1\r\n return count\r\n\r\n\r\nn = int(input())\r\nmagnets = [input() for _ in range(n)]\r\n\r\n\r\nresult = count_groups_of_magnets(n, magnets)\r\nprint(result)\r\n",
"a = int(input())\r\nb = input()\r\ns = 1\r\nfor i in range(a-1):\r\n x = input()\r\n if b!=x:\r\n b = x\r\n s+=1\r\nprint(s)",
"a=int(input())\r\nb=1\r\nc=input()\r\nd=0\r\ne=1\r\nwhile b<a:\r\n b+=1\r\n d=c\r\n c=input()\r\n if d!=c:\r\n e+=1\r\nprint(e)",
"p = \"\"\r\nq = 0\r\nfor i in range(int(input())):\r\n t = input()\r\n if t!=p:\r\n p=t\r\n q+=1\r\nprint(q)\r\n",
"n = int(input())\r\nm_count = 0 ### количество магнитов\r\nm = \"mm\" ### предыдущий магнит\r\nfor _ in range(n):\r\n x = str(input())\r\n if m[1] == x[0]: m_count += 1\r\n m = x\r\nprint(m_count + 1)",
"n=int(input())\r\nlist1=[]\r\nfor x in range(n):\r\n a=input()\r\n list1.append(a)\r\nmagnet=1\r\nfor x in range(len(list1)-1):\r\n if list1[x]==list1[x+1]:\r\n pass\r\n else:\r\n magnet+=1\r\nprint(magnet)",
"\r\nn = int(input())\r\nc=1\r\np = None\r\nfor i in range(n):\r\n\r\n m = input().strip()\r\n if p==None:\r\n p = m\r\n if p != m:\r\n c+=1\r\n p = m\r\nprint(c)\r\n",
"n = int(input())\r\na, t = '', 1\r\nfor i in range(n):\r\n a += input()\r\nfor i in range(n*2-1):\r\n if a[i] == a[i+1]:\r\n t += 1\r\nprint(t)",
" \r\nc = int(input())\r\nl = 0\r\ng = \"0\"\r\nfor i in range(c):\r\n n = input()\r\n if n != g:\r\n l = l + 1\r\n g = n\r\n\r\nprint(l)",
"n = int(input())\r\nc = 1\r\nmag_start = input()\r\nfor i in range(n-1):\r\n mag_next = input()\r\n if mag_start[1] == mag_next[0]:\r\n c += 1\r\n mag_start = mag_next\r\nprint(c)",
"n = int(input())\r\nnum = n\r\nmag = [0]*n\r\nfor i in range(n):\r\n mag[i] = input()\r\nfor i in range(n-1):\r\n if (mag[i] == '10' and mag[i+1] == '10') or (mag[i] == '01' and mag[i+1] == '01'):\r\n num -= 1\r\nprint(num)",
"n=int(input())\r\ncount=0\r\nmn=0\r\nwhile n!=0:\r\n m=int(input())\r\n if m!=mn:\r\n mn=m\r\n count+=1\r\n\r\n n-=1\r\nprint(count)\r\n\r\n",
"import sys\r\n#file=open(\"C:/Users/MAHAMUD MATIN/Desktop/input.txt\", \"r\").readlines()\r\nl=list(map(str, sys.stdin.readlines()))\r\nn=int(l[0])\r\n#p=file[1]\r\nflag=1\r\nfor i in range(2,n+1):\r\n if l[i]!=l[i-1]:\r\n flag+=1\r\nsys.stdout.write(str(flag))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n#open(\"C:/Users/MAHAMUD MATIN/Desktop/output.txt\", \"w\").writelines(map(str,l))\r\n",
"n = int(input())\r\ngroups = 1 # The first magnet forms a group by itself\r\nprev_magnet = input()\r\n\r\nfor _ in range(n - 1):\r\n curr_magnet = input()\r\n if curr_magnet != prev_magnet:\r\n groups += 1\r\n prev_magnet = curr_magnet\r\n\r\nprint(groups)\r\n",
"n=int(input())\nprev=''\ncount=1\nfor i in range(n):\n s=str(input())\n if prev!='' and s!=prev:\n count+=1\n prev=s\nprint(count)",
"n=int(input())\r\nposs=[]\r\ncount=1\r\nfor _ in range(n): poss.append(input())\r\nfor i in range(n-1):\r\n if poss[i]!=poss[i+1]: count+=1\r\nprint(count)",
"ct=0\r\nprv=0\r\nfor i in range(int(input())):\r\n x=int(input())\r\n if x!=prv:\r\n ct+=1\r\n prv=x\r\nprint(ct)",
"# Wadea #\r\n \r\nn = int(input())\r\nl = \"\"\r\nfor i in range(n):\r\n s = str(input())\r\n l += s\r\na = \"11\"\r\nb = \"00\"\r\na1 = l.count(a)\r\nb1 = l.count(b)\r\nnumber_of_magnets = a1 +b1 + 1\r\nprint(number_of_magnets)",
"n = int(input())\r\narr = [int(input()) for _ in range(n)]\r\n\r\ndef main(arr):\r\n count = 1\r\n for i in range(1,len(arr)):\r\n if arr[i] != arr[i-1]:\r\n count += 1\r\n return count\r\n\r\nprint(main(arr))\r\n\r\n",
"a = int(input())\r\nc = 0\r\np= 2\r\nfor i in range(a):\r\n r= int(input())\r\n if r != p:\r\n c += 1\r\n p = r\r\nprint(c)\r\n",
"n = int(input())\na = []\nfor i in range(n):\n a.append(input())\nans = 1\nfor i in range(1, n):\n if a[i] != a[i-1]:\n ans += 1\nprint(ans)\n ",
"n=int(input())\r\na=[]\r\nw=''\r\ns=1\r\nfor i in range(n):\r\n b=input()\r\n a.append(b)\r\nfor k in a:\r\n w=w+k\r\nfor h in range(1,len(w)-1):\r\n if w[h]==w[h+1]:\r\n s=s+1\r\nprint(s)\r\n ",
"n = int(input())\nlist_= list()\nfor i in range(n):\n list_.append(input())\ng = 1\nfor i in range(1,len(list_)):\n if list_[i] != list_[i-1]:\n g += 1\n\nprint(g)\n",
"n=int(input())\r\nc=1\r\npre=int(input())\r\nfor i in range(1,n):\r\n s=int(input())\r\n if pre != s:\r\n pre=s\r\n c+=1\r\nprint(c)",
"n = int(input())\r\narr = []\r\nt = 0\r\nfor i in range(n):\r\n a = int(input())\r\n arr.append(a)\r\n \r\nfor i in range(n-1):\r\n if arr[i]!=arr[i+1]:\r\n t+=1\r\nprint(t+1)",
"n = int(input())\r\ns=[str]*n\r\nr=0\r\nk=\"\"\r\nfor i in range(n):\r\n s[i]=input()\r\n k=k+s[i]\r\n\r\naa=k.count(\"11\")\r\nbb=k.count(\"00\")\r\n\r\nr=aa+bb+1\r\nprint(r)\r\n",
"t=int(input())\r\nx=[]\r\nk=1\r\nfor i in range(t):\r\n a=int(input())\r\n x.append(a)\r\nfor j in range(len(x)-1):\r\n if x[j]!=x[j+1]:\r\n k+=1\r\nprint(k)\r\n",
"noMagnet = int(input())\r\nx = []\r\ncount = 1\r\nfor i in range(noMagnet):\r\n magent = input()\r\n x.append(magent)\r\n if i > 0 and x[i-1] !=x [i]:\r\n count += 1\r\nprint(count)",
"n = int(input())\r\ngroup_of_magnets=1\r\nprevious_pole=int(input())\r\n\r\nfor i in range(n-1):\r\n pole=int(input())\r\n if pole!= previous_pole:\r\n group_of_magnets+=1\r\n previous_pole=pole\r\n\r\nprint(group_of_magnets)",
"n=int(input())\r\nprev_magnet=''\r\ngroup=0\r\nfor _ in range(n):\r\n magnet=input()\r\n if prev_magnet!=magnet:\r\n group+=1\r\n prev_magnet=magnet\r\nprint(group)",
"import sys\r\n\r\nnum = int(input())\r\ncnt = 0\r\nfirst = 0\r\nsecond = 0\r\n\r\nfor i in range(num):\r\n first = second\r\n second = int(input())\r\n cnt += (first != second)\r\n\r\nprint(cnt)\r\n0",
"n=int(input())\r\nmagnets=[]\r\nfor i in range(n):\r\n x=input()\r\n magnets.append(x)\r\nc=1\r\nfor i in range(0,n):\r\n for j in range(i+1,n):\r\n if magnets[i]==magnets[j]:\r\n break\r\n else:\r\n c+=1\r\n break\r\nprint(c)\r\n",
"n = int(input())\r\nmagnets = []\r\n\r\nfor _ in range(n):\r\n magnet = input()\r\n magnets.append(magnet)\r\n\r\n# Initialize the number of groups to 1 since the first magnet always forms a group.\r\nnum_groups = 1\r\n\r\n# Iterate through the magnets starting from the second one.\r\nfor i in range(1, n):\r\n if magnets[i] != magnets[i - 1]:\r\n num_groups += 1\r\nprint(num_groups)\r\n\r\n",
"ans = 0\r\nlast = \"X\"\r\n\r\nfor _ in range(int(input())):\r\n magnet = input()\r\n ans += int(magnet[0] == last)\r\n last = magnet[1]\r\n\r\nprint(ans + 1)",
"n = int(input()) \r\nmagnet_arrange = [input() for i in range(n)] \r\ngroups = 1 \r\nfor i in range(1, n):\r\n if magnet_arrange[i] != magnet_arrange[i - 1]:\r\n groups += 1\r\nprint(groups)\r\n",
"t = int(input())\r\nCurrent = int(input()[0])\r\nGroups = 1\r\nfor i in range(t - 1):\r\n v = int(input()[0])\r\n if v != Current:\r\n Current = v\r\n Groups += 1\r\nprint(Groups)",
"from collections import Counter\r\n \r\n\r\nN = int(input())\r\ncnt = 0\r\ncurr = '~'\r\nfor i in range(N):\r\n s = input()\r\n if curr == '~':\r\n cnt += 1\r\n elif s[0] == curr:\r\n cnt += 1\r\n curr = s[1]\r\nprint(cnt)",
"a = int(input())\r\nb = input()\r\nk = 1\r\nfor i in range(a - 1):\r\n c = input()\r\n if c != b:\r\n k += 1\r\n b = c\r\nprint(k)",
"t=int(input())\r\nn=t\r\nl=[]\r\nwhile(n>0):\r\n i=int(input())\r\n l.append(i)\r\n n-=1\r\ns=l[0]\r\ng=1\r\nfor i in range(1,t):\r\n if(s!=l[i]):\r\n g+=1\r\n s=l[i]\r\nprint(g)",
"a=int(input())\r\nb=int(input())\r\nk=0\r\nfor i in range(1,a):\r\n s=int(input())\r\n if b!=s:\r\n b=s\r\n k+=1\r\nprint(k+1)",
"n=int(input())\r\nc=[]\r\nfor i in range(n):\r\n a=int(input())\r\n c.append(a)\r\nj=1\r\nfor i in range(n-1):\r\n if c[i]!=c[i+1]:\r\n j+=1\r\n \r\n\r\nprint(j)",
"n = int(input())\r\nmagnets = []\r\n\r\nfor _ in range(n):\r\n magnet = input()\r\n magnets.append(magnet)\r\n\r\n# Initialize the number of groups to 1 (at least one group with the first magnet)\r\ngroups = 1\r\n\r\n# Iterate through the magnets and count the number of groups\r\nfor i in range(1, n):\r\n if magnets[i] != magnets[i - 1]: # Check for a change in polarity\r\n groups += 1\r\n\r\nprint(groups)\r\n",
"t=int(input())\r\ncount1=0\r\nc=0\r\nfor i in range(t):\r\n n=int(input())\r\n if n!=c:\r\n count1=count1+1\r\n c=n\r\nprint(count1)",
"n = int(input()) # Number of magnets\nmagnets = [input() for _ in range(n)] # Read the magnet orientations into a list\n\ngroups = 1 # Initialize the group count to 1, assuming the first magnet starts a new group\n\nfor i in range(1, n):\n if magnets[i] != magnets[i - 1]:\n groups += 1 # Increment the group count when there's a change in orientation\n\nprint(groups)\n\n\t\t \t \t \t \t\t\t \t\t\t\t\t",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Jul 26 11:19:35 2023\r\n\r\n@author: lakne\r\n\"\"\"\r\n\r\nn = int(input())\r\nmagnets = []\r\nfor i in range(n):\r\n magnet = input()\r\n magnets.append(magnet)\r\n\r\nx = 1\r\nfor i in range(n-1):\r\n if magnets[i] != magnets[i+1]:\r\n x += 1\r\n\r\nprint(x)",
"previous_line = current_line = -1\r\nfor line in open(0):\r\n current_line += previous_line != line\r\n previous_line = line\r\nprint(current_line)\r\n",
"\r\nn = int(input())\r\n\r\ngroups = 1 \r\ncurrent_magnet = input()\r\n\r\n\r\nfor i in range(1, n):\r\n magnet = input()\r\n \r\n \r\n if magnet != current_magnet:\r\n groups += 1\r\n \r\n \r\n current_magnet = magnet\r\n\r\nprint(groups)\r\n",
"n = int(input()) \r\nlst = [] \r\nfor _ in range(n):\r\n lst.append(input())\r\ns = 1\r\nfor i in range(1, n):\r\n if lst[i] != lst[i - 1]:\r\n s += 1\r\n\r\nprint(s)\r\n",
"n=int(input())\r\nl=[]\r\ncount=0\r\nfor i in range(n):\r\n m=int(input())\r\n l.append(m)\r\nfor i in range(len(l)):\r\n for j in range(i+1,len(l)):\r\n if l[i]==l[j]:\r\n break\r\n else:\r\n count+=1\r\n break\r\nprint(count+1)\r\n\r\n",
"n = int(input())\r\n\r\ncount = 1\r\nmagnets = []\r\nfor i in range(n):\r\n magnets.append(input())\r\n\r\nfor i in range(n-1):\r\n if magnets[i] != magnets[i+1]:\r\n count+=1\r\n\r\nprint(count)\r\n",
"n = int(input())\r\nx=[]\r\nfor i in range(n):\r\n a=int(input())\r\n x.append(a)\r\nc=1\r\nfor i in range(n-1):\r\n if((x[i]==10 and x[i+1]==1) or (x[i]==1 and x[i+1]==10)):\r\n c+=1\r\nprint(c)",
"r = int(input())\r\nh = 0\r\nfor i in range(r):\r\n g = input()\r\n h += 1 if i == 0 or c != g else 0\r\n c = g\r\nprint(h)",
"a=int(input())\nj=0\ncount = 1\nb1=int(input())\nwhile j<a-1:\n b=int(input())\n if b == b1:\n count-=0\n else:\n count+=1\n b1=b\n j+=1\nprint(count)\n\n",
"from itertools import groupby as gb\r\n\r\nn = int(input())\r\n\r\nln = [input() for i in range(n)]\r\n\r\nprint(len(list(gb(ln))))",
"strings = []\r\nfor i in range(int(input())):\r\n strings.append(input())\r\nstring = \"\".join(strings)\r\nstring = string.replace(\"00\", \"0 0\")\r\nstring = string.replace(\"11\", \"1 1\")\r\nprint(string.count(\" \") + 1)",
"n = int(input())\r\nmagnet_list = []\r\ngroups = 1\r\nfor x in range(n):\r\n y = input()\r\n magnet_list.append(y)\r\n\r\nfor a in range(1,len(magnet_list),1):\r\n if magnet_list[a-1] != magnet_list[a]:\r\n groups += 1\r\n\r\nprint(groups)\r\n\r\n\r\n",
"list = []\r\n\r\nn = int(input())\r\n\r\nfor i in range(0, n):\r\n ele = int(input())\r\n list.append(ele)\r\n \r\n \r\ncount = 0\r\nfor i in range(0, n-1):\r\n if list[i] != list[i+1]:\r\n count += 1\r\n \r\nprint(count+1)",
"n = int(input())\r\ns = ''\r\nfor i in range(n):\r\n m = str(input())\r\n s += m\r\ncnt = 0\r\nfor i in range(1, len(s)):\r\n if (s[i-1] == '0' and s[i] == '0') or (s[i-1] == '1' and s[i] == '1'):\r\n cnt += 1\r\nprint(cnt + 1)",
"from sys import stdin\ninput = stdin.readline\n\n\nif __name__ == \"__main__\":\n n = int(input())\n data = [0] * n\n for i in range(n):\n data[i] = input().strip()\n r = 1\n x = data[0]\n for v in data[1:]:\n if v != x:\n x = v\n r += 1\n print(r)\n\t \t \t\t \t \t \t\t\t \t \t",
"n=int(input())\r\na=str()\r\nans=1\r\nfor i in range(n):\r\n magnet=input()\r\n a+=magnet\r\nfor j in range(len(a)-1):\r\n if a[j]==a[j+1]:\r\n ans+=1\r\nprint(ans)",
"# Magnets\n\namount = int(input())\n\nmagnet_list = []\n\nfor i in range(amount):\n magnet = input()\n magnet_list.append(magnet)\n\noutput = 1 # 1st magnet(s) are different already\n\nfor i in range(len(magnet_list) - 1):\n if magnet_list[i] != magnet_list[i+1]:\n output += 1\n\nprint(output)\n",
"n = int(input())\r\ncnt = 0\r\na = input()\r\nfor i in range(n-1):\r\n b = input()\r\n if b[1] == a[0]:\r\n cnt += 1\r\n a = b\r\nprint(cnt + 1)",
"n = int(input())\n\npreMag = \"\"\nmagnets = []\nfor i in range(n):\n magnet = input()\n if magnet == preMag:\n magnets[len(magnets)-1].append(magnet)\n else:\n magnets.append([magnet])\n preMag = magnet\n\nprint(len(magnets))\n \t\t\t \t \t \t\t\t \t \t\t \t \t",
"n = int(input())\nmagnets = []\nfor i in range(n):\n a = int(input())\n magnets.append(a)\n \nx = 1\nfor i in range(1, n):\n if magnets[i]!=magnets[i-1]:\n x+=1\n\nprint(x)\n \t \t\t \t\t \t\t \t \t\t\t\t\t \t",
"n = int(input())\r\narr = []\r\ncount = 0\r\nfor i in range(n):\r\n s = input()\r\n if arr != []:\r\n if arr[-1] != s:\r\n count += 1\r\n else:\r\n count += 1\r\n arr.append(s)\r\nprint(count)\r\n",
"n=int(input())\r\nmagnets=1\r\npre=input()\r\nfor i in range(n-1):\r\n curr=input()\r\n if pre!=curr:\r\n magnets+=1\r\n pre=curr\r\nprint(magnets)",
"n = int(input())\r\ngroups = 1\r\n\r\nmagn = input()\r\n\r\nfor i in range(1, n):\r\n magn2 = input()\r\n if magn2 != magn:\r\n groups += 1\r\n magn = magn2\r\n\r\nprint(groups)\r\n\r\n",
"n = int(input())\r\ncurrent = input()\r\nmag = 1\r\n\r\nfor _ in range(n-1):\r\n i = input()\r\n if i != current:\r\n mag += 1\r\n current = i\r\n \r\nprint(mag)",
"# Считываем количество магнитов\r\nn = int(input())\r\n\r\n# Инициализируем счетчик островков\r\ncount = 1 # Первый магнит всегда начинает новый островок\r\n\r\n# Считываем последовательность магнитов и сразу проверяем их положение\r\nprev_magnet = input()\r\nfor _ in range(n - 1):\r\n current_magnet = input()\r\n if current_magnet != prev_magnet:\r\n count += 1\r\n prev_magnet = current_magnet\r\n\r\n# Выводим количество островков\r\nprint(count)",
"a=int(input())\r\nl=\"\"\r\nfor i in range(a):\r\n l+=input()\r\naa=l.count(\"11\")\r\nbb=l.count(\"00\")\r\nprint(bb+aa+1)",
"n = int(input()) # Number of magnets\r\nmagnets = [input() for _ in range(n)] # List of magnet positions\r\n\r\ngroups = 1 # Initialize with 1 group for the first magnet\r\n\r\nfor i in range(1, n):\r\n if magnets[i] != magnets[i - 1]: # If the current magnet is different from the previous one\r\n groups += 1\r\n\r\nprint(groups)\r\n",
"# 01 - plus,minus\r\n# 10 - minus,plus\r\n\r\nmagnets=[input() for _ in range(int(input()))]\r\ncount=0\r\nfor i in range (len(magnets)-1):\r\n if(magnets[i]!=magnets[i+1]):\r\n count+=1\r\nprint(count+1)",
"x = []\r\nfor i in range(n:=int(input())):\r\n x.append(input())\r\n\r\nbig = []\r\nsmall = []\r\n\r\nfor i in x:\r\n try:\r\n if i==small[-1]:\r\n small.append(i)\r\n\r\n else:\r\n big.append(small)\r\n small = []\r\n small.append(i)\r\n except IndexError:\r\n small.append(i)\r\n\r\nelse:\r\n big.append(small)\r\nprint(len(big))",
"num = int(input())\r\nrag = input()\r\ngroup = 1\r\nfor i in range(num - 1):\r\n x = input()\r\n if x != rag:\r\n rag = x\r\n group += 1\r\n \r\nprint(group)",
"n=int(input())\r\nm=[input() for i in range(n)]\r\ngrps=1\r\nfor i in range(1,n):\r\n if m[i]!=m[i-1]:\r\n grps+=1\r\nprint(grps)",
"n=int(input())\r\n\r\nj=int(input())\r\nc=0\r\nfor i in range(1, n):\r\n x=int(input())\r\n if x!=j:\r\n c+=1 \r\n j=x\r\nprint(c+1)",
"n=int(input()); sv=1\r\nfor i in range(n):\r\n s=input()\r\n if i!=0:\r\n if s!=ab:\r\n sv+=1\r\n ab=s\r\nprint(sv)\r\n",
"n=int(input())\r\na=1\r\np=int(input())\r\nfor i in range(1,n):\r\n b=int(input())\r\n if p!=b:\r\n p=b\r\n a+=1\r\nprint(a)\r\n",
"lst = []\r\nfor i in range(int(input())):\r\n\tx = input()\r\n\tlst.append(x)\r\ng = 1 \r\nfor i in range(len(lst)-1):\r\n\tif lst[i][-1] == lst[i+1][0]:\r\n\t\tg = g + 1\r\nprint(g)\r\n",
"n = int(input())\r\ncount = 1\r\n\r\ncurr = \"\"\r\nfor t in range(n):\r\n magnet = input()\r\n if t == 0:\r\n curr = magnet\r\n else:\r\n if magnet != curr:\r\n count += 1\r\n curr = magnet\r\n \r\nprint(count)",
"n = int(input())\r\nx = []\r\nfor i in range(n):\r\n\r\n a = (input())\r\n\r\n x.append(a)\r\ny = 1 #at least one group\r\nfor j in range(1,n):\r\n \r\n if x[j] != x[j-1]:\r\n \r\n y +=1\r\nprint(y) ",
"n = int(input())\r\nm = []\r\ncounter = 1\r\n\r\nfor _ in range(n): # Loop n times to get the input\r\n mag = int(input())\r\n m.append(mag)\r\n\r\nfor i in range(len(m)-1 ): # Loop through the list m\r\n if m[i] != m[i + 1]:\r\n counter += 1 # Increment counter when consecutive elements are the same\r\n i+=1\r\nprint(counter)",
"number_of_magnets = int(input())\r\nmagnet_groups = 0\r\n \r\nmagnet = \"\"\r\nprevious_magnet = \"\"\r\n \r\nfor magnet_index in range(number_of_magnets):\r\n previous_magnet = magnet\r\n magnet = input()\r\n \r\n if magnet_groups == 0:\r\n magnet_groups += 1\r\n elif previous_magnet[-1] == magnet[0]:\r\n magnet_groups += 1\r\n \r\nprint(magnet_groups)",
"n = int(input()) \nmagnet_positions = [input() for _ in range(n)] \n\nnum_groups = 1\ncurrent_group = magnet_positions[0]\n\n\nfor i in range(1, n):\n\n if magnet_positions[i] != current_group:\n num_groups += 1\n current_group = magnet_positions[i]\n\nprint(num_groups)\n \t\t\t \t \t \t \t \t \t \t",
"t=int(input())\r\nn=int(input())\r\nc=1\r\nfor _ in range(t-1):\r\n n1=int(input())\r\n if n1!=n:\r\n n=n1\r\n c=c+1\r\nprint(c)",
"amountmagnets = int(input())\r\nlastmagnet = 0\r\na = 0\r\nfor e in range(amountmagnets):\r\n i = input()\r\n if lastmagnet != i:\r\n a+=1 \r\n lastmagnet = i\r\nprint(a) ",
"inp = int(input())\r\nres = 1\r\nsep = (int(input()))%10\r\nfor i in range(1,inp):\r\n inp1 = int(input())\r\n p,q = inp1//10,inp1%10\r\n if sep != q:\r\n res += 1\r\n sep = q\r\n \r\n \r\nprint(res)",
"l=int(input())\r\nlst=[]\r\nres=1\r\nfor j in range(l):\r\n n=int(input())\r\n lst.append(n)\r\n\r\nfor i in range(len(lst)-1):\r\n if lst[i] != lst[i+1]:\r\n res += 1\r\n\r\nprint(res)\r\n",
"# I'm The King Of Pirates\r\n\r\nn = int(input())\r\nc = 0\r\nl = []\r\nfor i in range(n):\r\n x = input()\r\n l.append(x[0])\r\n\r\n#print(l)\r\n\r\nfor i in range(len(l) - 1): # Iterate up to len(l) - 1 to avoid index out of range\r\n if l[i] == l[i + 1]:\r\n continue\r\n else:\r\n c += 1\r\n \r\nprint(c+1)\r\n",
"num_cases = int(input()) # Number of cases\r\n\r\ncount = 0 # Counter for valid cases\r\n\r\nlast_char = None # Initialize last character\r\n\r\n\r\nfor _ in range(num_cases):\r\n\r\n case = input() # Input for each case\r\n\r\n \r\n\r\n if last_char is None: # For the first case\r\n last_char = case[1]\r\n count += 1\r\n elif case[0] == last_char: # If the first character matches the last character of the previous case\r\n count += 1\r\n last_char = case[1] # Update last character for the next iteration\r\n\r\nprint(count) # Print the total count of valid cases\r\n",
"n=int(input())\r\n\r\nmagnets =[ input() for _ in range(n) ]\r\n\r\ngroup=1\r\n\r\nfor i in range(1,n):\r\n\r\n if magnets[i] != magnets[i-1]:\r\n\r\n group+=1\r\n\r\nprint(group)\r\n\r\n",
"t=int(input())\r\nreq=[]\r\ncount=0\r\nfor i in range(t):\r\n if not req:\r\n req.append(input())\r\n else:\r\n a=input()\r\n if a[0]==req[-1][-1]:\r\n count+=1\r\n req.append(a)\r\nprint(count+1)\r\n",
"n = int(input())\r\nans = 0\r\ns = []\r\nwhile n:\r\n s.append(input())\r\n if len(s) >= 2 and s[-1] != s[-2]:\r\n ans += 1\r\n n -= 1\r\nprint(ans + 1)\r\n",
"n = int(input())\r\nmagnets = []\r\n\r\n\r\nfor i in range(n):\r\n orientation = input()\r\n magnets.append(orientation)\r\n\r\nprev = magnets[0]\r\ntotal = 1\r\n\r\n\r\nfor i in range(1, n):\r\n current = magnets[i]\r\n if current != prev:\r\n total += 1\r\n prev = current\r\n\r\nprint(total)\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 5 10:48:29 2023\r\n\r\n@author: HyFlu\r\n\"\"\"\r\n\r\nmagnets_number=int(input())\r\ngroups=1\r\nmagnets=[]\r\nfor i in range(magnets_number):\r\n magnets.append(input())\r\nfor i in range(magnets_number-1):\r\n if magnets[i]!=magnets[i+1]:\r\n groups+=1\r\nprint(groups)",
"n=int(input())\r\ns=\"\"\r\nfor i in range(n):\r\n r=str(input())\r\n s+=r\r\nl=s.count(\"11\")\r\nm=s.count(\"00\")\r\nprint(l+m+1)\r\n ",
"t=int(input())\r\nprev=input();count=1\r\nfor _ in range(1,t):\r\n curr=input()\r\n if prev!=curr:\r\n count+=1\r\n prev=curr \r\n\r\n# if t=1:\r\n# count=1\r\nprint(count)",
"import sys\r\n\r\ndef magnet(n):\r\n prev = \"\"\r\n groups = 0\r\n for _ in range(n):\r\n s = sys.stdin.readline().strip()\r\n if prev != s[-1]:\r\n groups += 1\r\n prev = s[-1]\r\n return groups\r\n\r\nn = int(input())\r\nprint(magnet(n))",
"n=int(input())\r\nnum=0\r\nA=[]\r\nfor i in range(n):\r\n ai=input()\r\n A.append(ai)\r\nfor m in range(0,n-1):\r\n if A[m]!=A[m+1]:\r\n num+=1\r\n else:\r\n num+=0\r\nprint(num+1)",
"st = ''\r\nfor _ in range(int(input())):\r\n st += input()\r\nprint(st.count('00') + st.count('11') + 1)",
"san = int(input())\r\nres = []\r\ncount = 0\r\nfor i in range(san):\r\n sandar = int(input())\r\n res.append(sandar)\r\nfor i in range(1,len(res)):\r\n if res[i] != res[i-1]:\r\n count+=1\r\nprint(count+1)",
"n=int(input())\r\nc=0\r\nx=0\r\nfor i in range(n):\r\n a=int(input())\r\n if x!=a:\r\n c+=1\r\n x=a\r\nprint(c)\r\n ",
"n_magnets = int(input())\r\n\r\nmagnets = []\r\nfor _ in range(n_magnets):\r\n magnet = input()\r\n magnets.append(magnet)\r\n\r\n\r\ngroups = 0\r\nreference = magnets[0]\r\n\r\nfor magnet in magnets[1:] + [magnets[-1][1]]:\r\n if reference[1] == magnet[0]:\r\n groups = groups + 1\r\n \r\n reference = magnet\r\n\r\nprint(groups)\r\n",
"import sys\r\n\r\nn = int(sys.stdin.readline())\r\nmags = []\r\nfor _ in range(n):\r\n mags.append(sys.stdin.readline())\r\n\r\ngroups = 1\r\nprev = mags[0]\r\nfor i in range(1, n):\r\n if prev != mags[i]:\r\n groups += 1\r\n prev = mags[i]\r\n\r\nprint(groups)",
"l=\"\"\r\nn=int(input())\r\nfor i in range(n):\r\n x=input()\r\n l+=x\r\nb1=l.count(\"11\")\r\nb2=l.count(\"00\")\r\nprint(b1+b2+1)",
"n=int(input())\r\nb=\"\"\r\nfor i in range(n):\r\n a=input()\r\n b=b+a\r\nprint(b.count(\"00\")+b.count(\"11\")+1)\r\n ",
"et=f=0\r\nfor i in[*open(0)][1:]:f+=et!=i;et=i\r\nprint(f)",
"n=int(input())\r\ns=\"\"\r\ncount=1\r\nl=[]\r\nfor i in range(1,n+1):\r\n a=str(input())\r\n s=s+a\r\nfor i in s:\r\n l.append(i)\r\nfor i in range(len(l)-1):\r\n if l[i]==l[i+1]:\r\n count+=1\r\nelse:\r\n count=count\r\nprint(count)",
"import sys\r\n\r\nn = int(sys.stdin.readline().split()[0])\r\nmagnets = []\r\n\r\nfor line in sys.stdin:\r\n for word in line.split():\r\n magnets.append(word)\r\n\r\nislands = 1\r\ni = 0\r\n\r\nwhile i < n-1:\r\n if magnets[i] != magnets[i+1]:\r\n islands += 1\r\n i += 1\r\n\r\nprint(islands)",
"n = int(input())\r\ncounter = 0\r\nlast = \"\"\r\nfor i in range(n):\r\n magnet = input()\r\n if last == \"\" or last == magnet:\r\n last = magnet\r\n else:\r\n last = magnet\r\n counter += 1\r\n\r\nprint(counter + 1)",
"n11 = int(input())\r\nmagnets = [input() for _ in range(n11)]\r\n\r\ngroups11 = 1\r\nfor i in range(1, n11):\r\n if magnets[i] != magnets[i - 1]:\r\n groups11 += 1\r\n\r\nprint(groups11)\r\n",
"\r\nn=int(input())\r\nx=0\r\ns=0\r\nfor i in range(n):\r\n l=int(input())\r\n if(l!=x):\r\n s+=1\r\n x=l\r\nprint(s)",
"n = int(input())\r\nk = 1\r\na = int(input())\r\nfor i in range(n - 1):\r\n pred = a\r\n a = int(input())\r\n if a != pred:\r\n k += 1\r\nprint(k)",
"n = int(input())\r\ns = 00\r\nd = 0\r\nfor i in range(n):\r\n l = int(input())\r\n if l !=s:\r\n d += 1\r\n s = l\r\nprint(d)",
"n=int(input())\r\ns1=\" \"\r\ncount=0\r\nfor i in range(n):\r\n s=input()\r\n if(s==s1):\r\n continue\r\n else:\r\n count=count+1\r\n s1=s\r\nprint(count)",
"n = int(input())\r\n\r\ncount = 1\r\nlast = input()\r\nfor i in range(n-1):\r\n value = input()\r\n if value[0] == last[1]:\r\n count += 1\r\n last = value\r\nprint(count)",
"n=int(input())\r\nm1=input()\r\nc=1\r\nfor i in range(1,n):\r\n m2=input()\r\n if m1!=m2:\r\n c=c+1\r\n m1=m2\r\nprint(c)\r\n \r\n \r\n ",
"n = int(input())\r\ncount = 1\r\nflag = 0\r\ns = []\r\nfor i in range(n):\r\n k = int(input())\r\n s.append(k)\r\nfor j in range(1,len(s)):\r\n if s[j] != s[j-1]:\r\n count = count + 1\r\nprint(count)\r\n \r\n",
"num=int(input())\r\nthe_list=[]\r\ngroup=1\r\nfor i in range(num):\r\n the_list+=[int(input())]\r\n if i >0:\r\n if the_list[i] !=the_list[i-1]:\r\n group+=1\r\n\r\nprint(group)",
"n=int(input())\r\np=\"\"\r\nc=0\r\nfor i in range(n):\r\n s=input()\r\n if s!=p:\r\n c+=1\r\n p=s\r\n else:\r\n continue\r\nprint(c)",
"n=int(input())\r\ncounter=1\r\na=input()\r\nfor i in range(n-1):\r\n b=input()\r\n if(a!=b):\r\n counter+=1\r\n a=b\r\nprint(counter)\r\n\r\n",
"n=int(input())\r\ncount=0\r\nb=0\r\nfor i in range(n):\r\n \r\n a = int(input())\r\n if b != a:\r\n count += 1\r\n b = a\r\n \r\nprint(count)",
"c=''\r\nd=0\r\nfor i in range(int(input())):\r\n a=input()\r\n if a!=c:\r\n d=d+1\r\n c=a\r\nprint(d)",
"number_of_magnets = int(input())\r\nmagnet_start = []\r\ni = 0\r\nnumber_of_groups = 1\r\nfor _ in range(number_of_magnets):\r\n magnet_position = input()\r\n magnet_start.append(magnet_position[0])\r\nwhile i < len(magnet_start) - 1 :\r\n if magnet_start[i] != magnet_start[i+1]:\r\n number_of_groups += 1\r\n i += 1\r\nprint(number_of_groups)",
"n = int(input())\r\nmagnets = []\r\nris = 1\r\nfor _ in range(n):\r\n magnets.append(input())\r\n\r\nfor i in range(len(magnets)-1):\r\n if magnets[i] != magnets[i+1]:\r\n ris += 1\r\nprint(ris)\r\n",
"m=int(input())\r\nc=1\r\ninitial=int(input())\r\n\r\nfor i in range(1,m):\r\n s=int(input())\r\n if s!=initial:\r\n initial=s\r\n c+=1\r\nprint(c)\r\n",
"N = int(input())\r\nMagnet = [input() for _ in range(N)]\r\nGrp = 1\r\nfor i in range(1, N):\r\n if Magnet[i] != Magnet[i - 1]:\r\n Grp += 1\r\nprint(Grp)",
"c=1\r\nl=[]\r\nfor i in range(int(input())):\r\n n=input()\r\n l.append(n)\r\nfor i in range (1,len(l)):\r\n if l[i-1]!=l[i]:\r\n c+=1\r\nprint (c)",
"\r\nn = int(input())\r\n\r\ncount = 1\r\nnum = input()\r\nfor i in range(n-1):\r\n x = input()\r\n if num != x: \r\n count +=1 \r\n num = x \r\n\r\nprint ( count )",
"import sys\r\nfrom collections import Counter, deque\r\n\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n li = []\r\n for i in range(n):\r\n li.append(input())\r\n ans = 1\r\n for i in range(1, n):\r\n if li[i] != li[i-1]:\r\n ans+=1\r\n print(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n t = 1\r\n #t = int(input())\r\n for _ in range(t):\r\n solve()\r\n",
"k=1\r\nb=[]\r\nfor i in range(int(input())):\r\n b.append(input())\r\nfor j in range(len(b)-1):\r\n if b[j]!=b[j+1]:\r\n k=k+1\r\nprint(k) ",
"def count_magnet_groups(n, magnets):\n groups = 1 # Initialize with 1 group because the first magnet starts a group\n\n for i in range(1, n):\n if magnets[i] != magnets[i - 1]:\n groups += 1\n\n return groups\n\n# Read input\nn = int(input())\nmagnets = [input().strip() for _ in range(n)]\n\n# Count the number of groups\nnum_groups = count_magnet_groups(n, magnets)\n\n# Print the result\nprint(num_groups)\n",
"x=1\r\nn = int(input()) #satir sayisi,\r\nmag1 = str(input())\r\nwhile n-1>0 :\r\n n = n-1\r\n mag2 = str(input())\r\n if mag1 == mag2 :\r\n mag1 = mag2\r\n else :\r\n mag1 = mag2\r\n x = x+1\r\nprint(x)\r\n",
"p=f=-1\r\nfor s in open(0): f+=p!=s;p=s\r\nprint(f)",
"n = int(input())\r\nmagnets = [input() for _ in range(n)]\r\n\r\ng = 1 \r\n\r\nfor i in range(1,n):\r\n if magnets[i] != magnets[i - 1]:\r\n g+=1\r\n\r\nprint(g)",
"n=int(input())\r\nr=[]\r\nfor i in range(n):\r\n r.append(input())\r\ngroup=1\r\nfor i in range(1,n):\r\n if int(r[i][0])==int(r[i-1][1]):\r\n group+=1\r\n else:\r\n continue\r\nprint(group)",
"\r\nt = int(input())\r\nres = 0\r\nword = input()\r\ncurr = word[-1]\r\nres = 1\r\nfor i in range(t-1):\r\n word = input()\r\n if curr == word[0]:\r\n res += 1\r\n curr = word[-1]\r\nprint(res)\r\n \r\n \r\n \r\n \r\n",
"n = int(input())\nislands = 1\na = input()\nfor i in range(1, n):\n b = input()\n if a != b:\n islands += 1\n a = b\nprint(islands)",
"n = int(input())\r\nc = 0\r\np = \"\"\r\nfor _ in range(n):\r\n i = input()\r\n if p != i:\r\n c += 1\r\n p = i\r\n\r\nprint(c)\r\n",
"n = int(input())\r\n# s = [int(x) for x in input().split(\" \")]\r\n\r\na = int(input())\r\nt = 1\r\nfor i in range(1,n):\r\n c = int(input())\r\n if a != c:\r\n t += 1\r\n a = c\r\nprint(t)\r\n\r\n",
"def find(array):\r\n s = 0\r\n for i in range(len(array) - 1):\r\n if array[i] != array[i + 1]:\r\n s += 1\r\n s += 1\r\n return s\r\n\r\ndef main():\r\n n = int(input())\r\n data = []\r\n\r\n for _ in range(n):\r\n magnet = input().strip()\r\n data.append(magnet)\r\n\r\n print(find(data))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"n = int(input())\r\narr = []\r\nprev = input()\r\nans = 0\r\nfor i in range(1,n):\r\n curr = input()\r\n if prev != curr:\r\n ans += 1\r\n prev = curr\r\nprint(ans + 1)\r\n\r\n",
"# Read the number of magnets\r\nn = int(input())\r\n\r\n# Initialize variables\r\ngroup_count = 1 # Start with one group because there's at least one magnet\r\nprev_magnet = input()\r\n\r\n# Iterate through the magnets\r\nfor _ in range(1, n):\r\n current_magnet = input()\r\n \r\n # If the current magnet's arrangement is different from the previous one, increment the group count\r\n if current_magnet != prev_magnet:\r\n group_count += 1\r\n \r\n prev_magnet = current_magnet # Update the previous magnet's arrangement\r\n\r\n# Output the number of groups\r\nprint(group_count)\r\n",
"n = int(input())\r\nlst1 = list()\r\ngroup = 1\r\n\r\nfor i in range(0,n):\r\n lst1.append(input())\r\n\r\nfor i in range(0,len(lst1)):\r\n if i != len(lst1)-1:\r\n if lst1[i] != lst1[i+1]:\r\n group += 1\r\n\r\nprint(group)",
"# from collections import defaultdict,OrderedDict,Counter\r\n# from itertools import permutations,combinations\r\n# from bisect import bisect_left,bisect_right\r\n# from queue import Queue,PriorityQueue\r\n# from heapq import heapify,heappop,heappush\r\nfrom math import gcd,sqrt,floor,factorial,ceil,log2,log10\r\n\r\n# import math\r\n# import bisect\r\n# import collections\r\n# import heapq\r\n\r\n# --------- Pre - Defined Functions --------\r\n\r\nmod = 10**9 + 7\r\n\r\n# def decToBin(n):\r\n# return bin(n).replace(\"0b\", \"\")\r\n \r\n# def binToDec(n):\r\n# return int(n,2)\r\n \r\n# def isPrime(n):\r\n# if n < 2:\r\n# return False\r\n# i = 2\r\n# while i*i <= n:\r\n# if n % i == 0:\r\n# return False\r\n# i += 1\r\n# return True\r\n\r\n# def is_integer(n):\r\n# return isinstance(n, int)\r\n\r\ninp1 = lambda: input()\r\ninp2 = lambda: int(input())\r\ninp3 = lambda: list(input())\r\ninp4 = lambda: map(int,input().split())\r\ninp5 = lambda: list(map(int,input().split()))\r\n\r\n# --------- Pre - Defined Functions --------\r\n\r\n# for _ in range(inp2()):\r\nn = inp2()\r\nans = ''\r\nfor _ in range(n):\r\n s = inp1()\r\n ans += s\r\ncount = 0\r\nfor i in range(len(ans) - 1):\r\n if ans[i] == ans[i+1]:\r\n count += 1\r\nprint(count + 1)\r\n\r\n\r\n\r\n\r\n",
"g=\"01\"\r\nj=0\r\nfor i in range(int(input())):\r\n w=input()\r\n if j==0 and w==g:\r\n j+=1\r\n if w!=g:\r\n j+=1\r\n g=w\r\nprint(j) ",
"n = int(input())\r\ncnt, prev = 0, -1\r\nfor i in range(n):\r\n val = input()\r\n if val!=prev:\r\n cnt+=1\r\n prev=val\r\nprint(cnt)\r\n",
"groups = 0 \r\nlast = '00'\r\nfor i in range(int(input())):\r\n new = input()\r\n if new != last:\r\n groups +=1\r\n last = new\r\n \r\n \r\nprint(groups)\r\n ",
"s = ''\r\nn = int(input())\r\nfor i in range(n):\r\n s += str(input())\r\ns = s.replace('11','1 1', -1)\r\ns = s.replace('00','0 0', -1)\r\nprint(s.count(' ')+1)",
"n = input()\r\nc = 0\r\nl = None\r\nfor _ in range(int(n)):\r\n s = input()\r\n if l == s:\r\n l = s\r\n continue\r\n l = s\r\n c += 1\r\nprint(c)",
"t=int(input())\r\ncount=0\r\na=[]\r\nfor i in range(t):\r\n a.append(input())\r\nfor i in range(len(a)-1):\r\n if a[i] != a[i+1]:\r\n count=count+1\r\nprint(count+1)",
"n = int(input())\r\n\r\ngroups, prev = 0, 0\r\nfor i in range(n):\r\n pos = input()\r\n if prev != pos:\r\n groups += 1\r\n else:\r\n continue\r\n prev = pos\r\n\r\nprint(groups)",
"import sys\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n \r\nn = int(input())\r\nl = input()\r\ncount = 0\r\nfor _ in range(n-1):\r\n s = input()\r\n if l != s:\r\n count += 1\r\n l = s\r\nprint(count + 1)",
"n = int(input())\r\nr = []\r\nfor i in range(n):\r\n a = input()\r\n r.append(a)\r\np =1\r\nfor i in range(1,len(r)):\r\n if r[i] != r[i-1]:\r\n p+=1\r\nprint(p)",
"n = int(input())\r\nm = [input() for _ in range(n)]\r\ng = 0\r\nc = None\r\nfor t in m:\r\n if t != c:\r\n g += 1\r\n c = t\r\nprint(g)\r\n",
"N = int(input())\r\njupid = []\r\n\r\nfor i in range (N):\r\n sisend = str(input())\r\n jupid.append(sisend) \r\n \r\njuppide_arv = 1\r\n\r\nx = 0\r\nwhile x < len(jupid)-1:\r\n \r\n if jupid [x] != jupid[x+1]:\r\n juppide_arv +=1\r\n x += 1\r\n\r\nprint(juppide_arv)",
"n = int(input())\r\nc = 1\r\nlast_s = input()\r\nfor i in range(n-1):\r\n s = input()\r\n if s[0] == last_s[-1] :\r\n c += 1 \r\n last_s = s \r\nprint(c)\r\n ",
"n=int(input())\nl=[]\ncount=0\nfor i in range(n):\n a=input()\n l.append(a)\n if len(l)==1:\n count=1\n elif l[i]!=l[i-1]:\n count+=1\n else:\n continue\nprint(count)\n\n\n\n\n\n\n\n\n\n\n",
"numberOfMagnents = int(input())\r\n\r\nnumberOfGroups = 0\r\n\r\nlastMagnent = \"\"\r\n\r\nfor x in range(numberOfMagnents):\r\n magnent = input()\r\n if lastMagnent != magnent:\r\n lastMagnent = magnent\r\n numberOfGroups += 1\r\n\r\nprint(numberOfGroups)",
"a = ''\r\nfor i in range(int(input())):\r\n a = a + input()\r\nprint(a.count('00')+ + a.count('11') + 1)",
"T = int(input())\r\na = 1\r\nN = [int(N) for N in input().split()][:1]\r\nwhile T > 1:\r\n x = int(input())\r\n if(N[0] != x):\r\n a += 1\r\n N[0] = x\r\n T -= 1\r\nprint(a)",
"# https://codeforces.com/problemset/problem/344/A\r\n\r\nn = int(input())\r\n\r\nc = 0\r\nprev_m = input()\r\nfor i in range(1, n):\r\n m = input()\r\n if prev_m != m:\r\n c += 1\r\n prev_m = m\r\n\r\nc += 1\r\nprint(c)\r\n",
"n = int(input())\ninitial = input()\ngroups = 1\nfor k in range(n-1):\n current = input()\n if current != initial:\n groups += 1\n initial = current\nprint(groups)",
"n = int(input()) # Number of magnets\r\nmagnet_positions = [input() for _ in range(n)] # Magnet positions\r\n\r\nnum_groups = 1 # Initialize the number of groups to 1\r\nfor i in range(1, n):\r\n if magnet_positions[i] != magnet_positions[i - 1]:\r\n num_groups += 1\r\n\r\nprint(num_groups)",
"n = int(input())\r\nprev = None\r\ncount = 0\r\nfor i in range(n):\r\n magnet = int(input())\r\n if magnet != prev:\r\n count += 1\r\n prev = magnet\r\n\r\nprint(count)",
"t = \"\"\ncount = 0\nfor i in [0]*int(input()):\n inp = input()\n if inp == t:\n pass\n else:\n t = inp\n count+=1\nprint(count)\n",
"# Input the number of magnets\r\nn = int(input())\r\n\r\n# Initialize variables to keep track of the number of groups and the previous magnet orientation\r\nnum_groups = 1 # Initialize to 1 since there is at least one group with the first magnet\r\nprev_orientation = input()\r\n\r\n# Iterate through the remaining magnets\r\nfor _ in range(1, n):\r\n orientation = input()\r\n if orientation != prev_orientation:\r\n # If the orientation changes, it's the start of a new group\r\n num_groups += 1\r\n prev_orientation = orientation\r\n\r\n# Print the number of groups\r\nprint(num_groups)\r\n",
"t=int(input())\r\nl=[]\r\nfor i in range(t):\r\n e=input()\r\n l.append(e)\r\nc=1\r\nfor i in range(1,t):\r\n if l[i]!=l[i-1]:\r\n c+=1\r\nprint(c)\r\n \r\n ",
"n_of_m=int(input())\r\nr1=[]\r\nn_of_g=0\r\nfor i in range(n_of_m):\r\n a=input()\r\n if len(r1)==0:r1.append(a)\r\n else:\r\n if r1.pop()==a:\r\n r1.append(a)\r\n continue\r\n else:\r\n r1.append(a)\r\n n_of_g+=1\r\nprint(n_of_g+1)\r\n",
"n = int(input())\r\nmylist = [list(input()) for i in range(n)]\r\ncount = 1\r\nres = mylist[0][0]\r\nfor i in range(len(mylist)):\r\n if res == mylist[i][0]:\r\n continue\r\n else:\r\n res = mylist[i][0]\r\n count += 1\r\nprint(count)",
"a = int(input())\r\nb = 0\r\nc = 0\r\nd = 0\r\n\r\n\r\nfor i in range(a):\r\n b = int(input())\r\n if c != b:\r\n d += 1\r\n c = b\r\n\r\n\r\nprint(d)",
"p=f=0\r\nfor s in[*open(0)][1:]:f+=p!=s;p=s\r\nprint(f)\r\n",
"n = int(input())\n\nprior = input()\nres = 1\n\nfor i in range(n - 1):\n cur = input()\n if prior != cur:\n prior = cur \n res += 1 \n\nprint(res)\n",
"n = int(input())\r\nl = []\r\nfor i in range(0,n):\r\n a = input()\r\n l.append(a)\r\ncount = 0\r\nfor i in range(1,len(l)):\r\n if l[i-1]!=l[i]:\r\n count = count + 1\r\nprint(count+1)",
"import sys\r\n \r\ndata = [x.rstrip() for x in sys.stdin]\r\ndel data[0]\r\ngroups = 0\r\nfor i in range(len(data)):\r\n string1 = data[i]\r\n try:\r\n string2 = data[i+1]\r\n except IndexError:\r\n break\r\n if (string1[1] == string2[0]):\r\n groups += 1\r\ngroups += 1\r\nprint(groups)",
"import sys\r\n\r\n\r\ndef input():\r\n return sys.stdin.readline().rstrip()\r\n\r\nn=int(input())\r\nd=input()\r\nans=1\r\nfor i in range(n-1):\r\n s=input()\r\n if d!=s:\r\n ans+=1\r\n d=s\r\n\r\nprint(ans)\r\n\r\n",
"num = int(input())\r\n\r\nprevMag = str(input())\r\nlicznik = 1\r\nfor i in range(num-1):\r\n nextMag = str(input())\r\n if prevMag != nextMag:\r\n licznik = licznik +1\r\n\r\n prevMag = nextMag\r\n\r\nprint(licznik)\r\n",
"n = int(input())\r\n\r\nall_llist = []\r\nfor i in range(n):\r\n all_llist.append(int(input()))\r\n\r\nx = 1\r\nfor i in range(n - 1):\r\n if all_llist[i] != all_llist[i + 1]:\r\n x += 1\r\n\r\nprint(x)",
"\r\nn = int(input())\r\n\r\ngroups = 1 \r\nprev_magnet = input()\r\n\r\nfor _ in range(1, n):\r\n current_magnet = input()\r\n if current_magnet != prev_magnet:\r\n groups += 1\r\n prev_magnet = current_magnet\r\n\r\nprint(groups)\r\n",
"n = int(input())\r\na, t = '', 1\r\nfor i in range(n):\r\n a += input()\r\nt += a.count('00') + a.count('11')\r\nprint(t)",
"def code(*args):\r\n n, magnets = args\r\n\r\n i = 1\r\n\r\n groups = 0\r\n current_magnet = magnets[0]\r\n\r\n while i < n:\r\n if magnets[i] != current_magnet:\r\n current_magnet = magnets[i]\r\n groups += 1\r\n\r\n i += 1\r\n return groups + 1\r\n\r\n# Solution - 2 \r\ndef code1(*args):\r\n n, magnets = args\r\n\r\n i, j = 0, 1\r\n\r\n group = 0\r\n\r\n # Find where two pointers has same value.\r\n while i < len(magnets) and j < len(magnets):\r\n if magnets[i] == magnets[j]:\r\n group += 1\r\n\r\n i += 1\r\n j += 1 \r\n \r\n return group + 1\r\n\r\nif __name__ == \"__main__\":\r\n # Take inputs here\r\n n = int(input())\r\n\r\n # Input for Solution - 2\r\n # magnets = ''\r\n # for _ in range(n):\r\n # magnets += input()\r\n\r\n magnets = [int(input()) for _ in range(n)]\r\n result = code(n, magnets) # Pass arguments\r\n print(result)\r\n\r\n",
"n = int (input())\r\ns = []\r\ni = 0\r\nj = 1\r\nnum = 0\r\nfor _ in range(n):\r\n h = input()\r\n s.append(list(h))\r\n\r\nfor _ in range(len(s)-1):\r\n if s[i][1] == s[j][0] :\r\n num += 1 \r\n i += 1\r\n j += 1\r\n \r\nprint(num + 1)\r\n",
"n = int(input())\r\nm=[]\r\nfor i in range(n) :\r\n m.append(input())\r\ncount=1\r\nfor i in range(1,n) :\r\n if m[i-1] != m[i] : \r\n count+=1\r\n \r\n \r\n\r\nprint(count)\r\n",
"n = int(input())\r\na=[]\r\ncount=0\r\nfor i in range(n):\r\n _a = input()\r\n a.append(_a)\r\nfor i in range(0,n-1):\r\n if a[i] != a[i+1]:\r\n count += 1\r\nprint(count+1)",
"n=int(input())\r\nlist=[]\r\nv=0\r\nfor i in range(n):\r\n c=int(input())\r\n list.append(c)\r\nfor i in range(n-1):\r\n if list[i]==list[i+1]:\r\n v+=0\r\n else:v+=1\r\nprint(v+1) \r\n \r\n \r\n \r\n ",
"import sys\r\n\r\nn = int(input())\r\ngroups = 1\r\nlast = sys.stdin.readline()\r\nfor _ in range(n-1):\r\n magnet = sys.stdin.readline()\r\n if magnet != last:\r\n groups += 1\r\n last = magnet\r\nprint(groups)\r\n",
"num_m=int(input())\r\nl_m=\"\"\r\nnum_g=0\r\nfor i in range(num_m):\r\n curr_m=input()\r\n if i==0:\r\n num_g+=1\r\n l_m=curr_m\r\n else:\r\n if l_m[1]!= curr_m[0]:\r\n l_m=curr_m\r\n else:\r\n num_g+=1\r\n l_m=curr_m \r\nprint(num_g)\r\n",
"n=int(input())\r\nx=[]\r\nfor i in range(n):\r\n a=input()\r\n x.append(a)\r\n\r\nd=1\r\nfor i in range(n-1):\r\n a=x[i]\r\n b=x[i+1]\r\n if a!=b:\r\n d+=1\r\n\r\nprint(d)\r\n",
"n=int(input())\r\na=\"\"\r\nk=0\r\nfor i in range(n):\r\n a+=str(input())\r\nfor i in range(1,2*n):\r\n if a[i]==a[i-1]:\r\n k+=1\r\nprint(k+1)",
"x = \"\"\r\ny = 0\r\nfor a in range(int(input())):\r\n z = input()\r\n if z[1] == '0':\r\n x += z\r\n elif z[1] == '1':\r\n x += z\r\nfor i in range(1, len(x)):\r\n if x[i-1] == x[i]:\r\n y += 1\r\nprint(y + 1)\r\n",
"n = int(input())\r\ngroups = 1\r\nx = input()\r\nfor i in range(n-1):\r\n y = input()\r\n if (y != x):\r\n groups += 1\r\n x = y\r\nprint(groups)",
"n = int(input())\nmagnets = [input() for _ in range(n)]\ngroups = 1 # Initialize groups to 1 since there's at least one group.\n\nfor i in range(1, n):\n if magnets[i] != magnets[i - 1]:\n groups += 1\n\nprint(groups)\n",
"s = \"\"\r\nn = int(input())\r\nfor i in range(n):\r\n p = input()\r\n s += p\r\n\r\n\r\ni = 0\r\nc = 1\r\nwhile i != (len(s)-1):\r\n if s[i] == s[i+1]:\r\n c += 1\r\n i += 1\r\n\r\nif s[-1] == s[-2]:\r\n c += 1\r\nprint(c)",
"n = int(input())\r\ngroups = 0\r\ncurrent_polarity = None\r\nfor _ in range(n):\r\n magnet = input().strip()\r\n magnet_polarity = magnet[0]\r\n if current_polarity is None or current_polarity != magnet_polarity:\r\n groups += 1\r\n current_polarity = magnet_polarity\r\nprint(groups)\r\n",
"n = int(input())\r\ncount = 1\r\nlists = []\r\nfor i in range(n):\r\n inp = input()\r\n lists.append(inp)\r\nfor j in range(len(lists)-1):\r\n if lists[j] != lists[j + 1]:\r\n count += 1\r\nprint(count)",
"d=0\r\nc=''\r\nfor i in range(int(input())):\r\n a=input()\r\n if a!= c:\r\n d+=1\r\n c=a\r\nprint(d)\r\n ",
"n=int(input())\r\nlis=[]\r\nc=0\r\nwhile(n>0):\r\n h=input()\r\n lis.append(h)\r\n n-=1\r\nfor i in range(0,len(lis)-1):\r\n if(lis[i]!=lis[i+1]):\r\n c+=1\r\nprint(c+1)",
"import sys\nn = int(input())\nrez = 0\ncounter= 0\nfor i in range(n):\n magnet = sys.stdin.readline().strip()\n if magnet!=rez:\n counter+=1\n rez = magnet\n\nprint(counter)\n",
"n=int(input())\r\nc=1\r\nl=[]\r\nfor j in range(n):\r\n s=input()\r\n l.append(s)\r\nfor i in range(len(l)-1):\r\n if l[i][1]==l[i+1][0]:\r\n c+=1 \r\nif len(l)==0:\r\n c=0\r\nprint(c)",
"n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n l.append(input())\r\ncount=0\r\nfor i in range(1,n):\r\n if l[i-1]==l[i]:\r\n continue\r\n else:\r\n count+=1\r\nprint(count+1)",
"n = int(input())\r\npairs = [None]*n\r\npairs[0] = str(input())\r\ni = 1\r\nwhile i < n:\r\n pairs[i] = str(input())\r\n i += 1\r\ni = 0\r\ncount = 1\r\np = 1\r\nwhile i < n and p < n:\r\n if pairs[i][1] == pairs[p][0]:\r\n count += 1\r\n i += 1\r\n p += 1\r\nprint(count)\r\n",
"import sys \r\ninput=sys.stdin.readline\r\nn=int(input())\r\nw=[]\r\nnach=input()\r\nq=1\r\nfor i in range(n-1):\r\n d=input()\r\n if d!=nach:\r\n q+=1\r\n nach=d\r\nprint(q)\r\n ",
"n=int(input())\r\ntemp = input()\r\nresult=1\r\nfor i in range(n-1):\r\n item = input()\r\n if temp!=item:\r\n result+=1\r\n temp=item\r\nprint(result)",
"n = int(input())\r\na = 999\r\nc = 0\r\n\r\nfor i in range(n):\r\n r = int(input())\r\n if r != a:\r\n c += 1\r\n a = r\r\n\r\nprint(c)\r\n",
"import sys\r\n\r\n\r\ndef inp():\r\n return int(input())\r\n\r\n\r\ndef inlt():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef int_to_arr():\r\n return list(map(int, str(input()).strip()))\r\n\r\n\r\ndef insr():\r\n return input().strip()\r\n\r\n\r\ndef out(x):\r\n sys.stdout.write(str(x) + \"\\n\")\r\n\r\n\r\ndef main():\r\n times = inp()\r\n poles = []\r\n for _ in range(times):\r\n poles.append(inp())\r\n\r\n out(group(poles))\r\n\r\n\r\ndef group(input_list):\r\n result = []\r\n if input_list:\r\n current_group = [input_list[0]]\r\n\r\n for i in range(1, len(input_list)):\r\n if input_list[i] == current_group[-1]:\r\n current_group.append(input_list[i])\r\n else:\r\n result.append(current_group)\r\n current_group = [input_list[i]]\r\n\r\n result.append(current_group)\r\n\r\n return len(result)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"t = int(input())\r\n\r\nm = []\r\n\r\nfor i in range(t):\r\n\r\n cm = input()\r\n\r\n m.append(cm)\r\n\r\n\r\ncount = 1\r\n\r\n \r\nfor i in range(t - 1):\r\n\r\n cm = m[i]\r\n\r\n if cm[0] != m[i + 1][0]:\r\n\r\n count += 1\r\n\r\nprint(count)",
"k , s = 1 , ''\r\nfor i in range(int(input())):\r\n a=input()\r\n s=s+a\r\nfor j in range(len(s)-1):\r\n if s[j]==s[j+1]:\r\n k+=1\r\nprint(k)\r\n ",
"import sys\r\n\r\nn = int(sys.stdin.readline())\r\nlast = sys.stdin.readline()\r\ncount = 1\r\nfor i in range(n-1):\r\n current = sys.stdin.readline()\r\n if last != current:\r\n count += 1\r\n last = current\r\nprint(count)\r\n",
"n = int(input())\r\nans = 0\r\ns1 = \"0\"\r\nfor i in range(n):\r\n s = input()\r\n if s1 != s:\r\n ans += 1\r\n s1 = s\r\nprint(ans)",
"z = int(input())\r\nmagnets = [input() for _ in range(z)]\r\n\r\ngroups = 1 # Initialize the group count to 1, as the first magnet forms a group\r\n\r\nfor i in range(1, z):\r\n if magnets[i] != magnets[i - 1]:\r\n groups += 1\r\n\r\nprint(groups)\r\n",
"n = int(input())\r\n\r\nmaglist = []\r\n\r\nwhile (n > 0):\r\n s = input()\r\n maglist.append(s)\r\n n -= 1\r\n\r\ngroups = 1\r\n\r\nfor i in range(len(maglist)-1):\r\n if maglist[i] != maglist[i+1]: groups += 1\r\n\r\nprint(groups)",
"n=int(input())\ns=1\na=[]\nfor i in range(n):\n a.append(list(map(int,input().split())))\nfor i in range(1,n):\n s+=(a[i]!=a[i-1])\nprint(s)\n",
"c=1\r\nl=[]\r\nfor _ in range(int(input())):\r\n l.append(input())\r\n\r\nfor i in range(0,len(l)-1):\r\n if l[i].endswith('0') and l[i+1].startswith('1'):\r\n continue\r\n elif l[i].endswith('1') and l[i+1].startswith('0'):\r\n continue\r\n else:\r\n c+=1\r\n\r\nprint(c)\r\n",
"n=int(input())\r\nc=1\r\nt=[int(t) for t in input().split()][:1]\r\nwhile n>1:\r\n x=int(input())\r\n if(t[0]!=x):\r\n c+=1\r\n t[0]=x\r\n n-=1\r\nprint(c)",
"r = 0\r\npre = ''\r\nfor i in range(int(input())):\r\n c = int(input())\r\n if c != pre:\r\n r+=1\r\n pre = c\r\nprint(r)",
"n = int(input())\r\ns = \"\"\r\ncount = 0\r\nfor i in range(n):\r\n magnet = input()\r\n s += magnet\r\ncount += s.count(\"11\") + s.count(\"00\")\r\nprint(count+1)",
"n=int(input(\"\"))\r\nl1=[]\r\nl2=[]\r\ncount=0\r\nx=int(input(\"\"))\r\nl1.append(x)\r\nfor i in range(1,n):\r\n y=int(input(\"\"))\r\n l1.append(y)\r\n if y==l1[i-1]:\r\n count+=1\r\n else:\r\n l2.append(count)\r\n count=0 \r\nprint(len(l2)+1) ",
"n = int(input())\n\nlist = []\n\nfor i in range(n) :\n list.append(str(input()))\n\nnumOfGroups = 1\nfor i in range(0,len(list)-1) :\n if list[i] == list[i+1] :\n continue\n else :\n numOfGroups+=1\n\nprint(numOfGroups)\n\n\n\n \t\t\t\t\t\t \t \t \t \t \t \t",
"number = int(input())\r\ncounter=1\r\nfor i in range(number):\r\n s=input()\r\n if(i>0 and s!=t):\r\n counter+=1\r\n t=s\r\nprint(counter)",
"n = int(input())\r\nmagnets = [input() for _ in range(n)]\r\n\r\ngroups = 0\r\ncurrent_group = None\r\n\r\nfor magnet in magnets:\r\n if magnet != current_group:\r\n groups += 1\r\n current_group = magnet\r\n\r\nprint(groups)\r\n",
"n=int(input())\r\na=[]\r\nc=0\r\nfor i in range(n):\r\n k=int(input())\r\n a.append(k)\r\nfor i in range(1,len(a)):\r\n if a[i]!=a[i-1]:\r\n c+=1\r\nprint(c+1)",
"n = int(input())\na = []\nfor i in range(n):\n e = int(input())\n a.append(e)\n \ngroups = 1\n\nfor i in range(n):\n \n if i != (n-1) and a[i]!=a[i+1]:\n groups+=1\n \n \nprint(groups)\n\t \t\t\t\t \t\t \t\t \t\t \t\t \t\t\t\t",
"n=int(input())\r\nmag=[input() for i in range(n)]\r\ngroup=1\r\nfor i in range(1,n):\r\n if mag[i] != mag[i-1]:\r\n group += 1\r\nprint(group) ",
"A=list()\r\nfor _ in range(int(input())):\r\n A.append(input())\r\n\r\nans=0\r\ni=0\r\nwhile i+1<len(A):\r\n if A[i][0]==A[i+1][0]:\r\n while i+1<len(A) and A[i][0]==A[i+1][0]:\r\n i+=1\r\n else:\r\n ans+=1\r\n i+=1\r\nprint(ans+1)",
"number_of_magnets = int(input())\r\ncounter = [1]\r\nmagnet = 0\r\nturn = 0\r\nmagnet = input()\r\nfor i in range(number_of_magnets-1):\r\n save_magnet = magnet\r\n magnet = input()\r\n if save_magnet == magnet:\r\n counter[turn] += 1\r\n \r\n else:\r\n counter.append(1)\r\n turn += 1\r\n \r\n\r\n\r\nprint(len(counter))",
"n = int(input())\r\n\r\narr = []\r\n\r\nfor i in range(n):\r\n arr.append(int(input()))\r\n\r\ncount = 0\r\n\r\nfor i in range(1, len(arr)):\r\n if arr[i] != arr[i - 1]:\r\n count += 1\r\n \r\nprint(count + 1)",
"n=int(input())\r\na=\"\"\r\nfor i in range(n):\r\n r=input()\r\n a+=r\r\nans=1\r\nfor i in range(len(a)-1):\r\n if a[i]==a[i+1]:\r\n ans+=1 \r\nprint(ans)\r\n ",
"t = int(input())\r\ni = t\r\nlist=[]\r\nwhile(i>0):\r\n temp = str(input()[:2])\r\n list.append(temp)\r\n i=i-1\r\n\r\ngroup=0\r\nprev=\"\"\r\nfor x,y in list:\r\n\r\n if(str(x+y)!=prev):\r\n group=group+1\r\n prev= str(x+y)\r\n\r\nprint(group)",
"p=int(input())\r\nc=1\r\npr=int(input())\r\nfor i in range(1,p):\r\n s=int(input())\r\n if pr!=s:\r\n pr=s\r\n c+=1\r\n\r\nprint(c)",
"n,a,b=int(input()),1,0\r\nfor i in range(n):\r\n x=int(input())\r\n if i!=0 and b!=x:\r\n a+=1\r\n b=x\r\nprint(a)",
"n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n v=input()\r\n l.append(v)\r\ns=1\r\nfor i in range(len(l)-1):\r\n if l[i]!=l[i+1]:\r\n s+=1\r\nprint(s)\r\n \r\n \r\n",
"############ ----By Bisrat Kebere ---- ############\r\n############ ---- Input Functions ---- ############\r\nimport bisect\r\n\r\n\r\ndef inp():\r\n return (int(input()))\r\n\r\n\r\ndef inlt():\r\n return (list(map(int, input().split())))\r\n\r\n\r\ndef insr():\r\n s = input()\r\n return (list(s[:len(s) - 1]))\r\n\r\n\r\ndef invr():\r\n return (map(int, input().split()))\r\n\r\n\r\n# n = inp()\r\n# a = inlt()\r\n\r\nstack = []\r\ncount = 0\r\n\r\nfor i in range(inp()):\r\n s = input()\r\n\r\n while stack and stack[-1] == s[0]:\r\n count += 1\r\n stack.pop()\r\n stack.append((s[1]))\r\n\r\n else:\r\n stack.append(s[1])\r\n\r\nprint(count + 1)\r\n",
"n=v=-1\r\nfor s in open(0):\r\n v+=n!=s\r\n n=s\r\nprint(v) ",
"n = int(input())\r\ngroups = 0\r\nc = None\r\nfor _ in range(n):\r\n s = input()\r\n if s[0] != c:\r\n groups += 1\r\n c = s[0]\r\nprint(groups)",
"n = int(input())\r\nans = 1\r\nchecker = input()\r\nfor _ in range(n-1):\r\n word = input()\r\n if checker != word:\r\n checker = word\r\n ans += 1\r\n \r\nprint(ans)",
"n = int(input())\r\npre = '00'\r\nans = 0\r\nfor i in range(0, n):\r\n s = input()\r\n if s != pre:\r\n ans += 1\r\n pre = s\r\nprint(ans)\r\n",
"n = int(input())\r\na = int(input())\r\nc = 1\r\nfor i in range(1,n):\r\n x = int(input())\r\n if x != a:\r\n c += 1\r\n a = x\r\nprint(c)",
"import sys\n\nn = input()\ngroups = 0\ncurGroup = \"\"\n\nfor line in sys.stdin:\n #start a new group\n if groups == 0 or line != curGroup:\n groups += 1\n curGroup = line\n #continue the current one\n else:\n continue\nprint(groups)\n ",
"x = int(input())\r\ny=0\r\np=[]\r\nv=0\r\nc=0\r\nn=0\r\nfor i in range(x):\r\n y = input()\r\n p.append(y)\r\nc = len(p)\r\nfor i in range(c):\r\n if p[i]!=n:\r\n v= v ++ 1\r\n elif c == 1:\r\n v=1\r\n else:\r\n 0\r\n n = p[i]\r\nprint(v)",
"n = input()\nn = int(n)\nans = 0\npre = 0\nfor i in range(n):\n line = input()\n if pre != line:\n ans += 1\n pre = line\nprint(ans)\n\t\t \t \t\t\t\t \t\t\t\t \t\t \t\t \t \t",
"n = int(input())\r\ns = []\r\nfor g in range(n):\r\n for d in input().split():\r\n s.append(d)\r\nd = 0\r\nj = 1\r\nwhile d < n -1:\r\n if s[d] != s[d+1]:\r\n j += 1\r\n d +=1\r\nprint(j)\r\n\r\n",
"chir = int(input())\r\nris=input()\r\nfgh = 1\r\nfor i in range(chir-1):\r\n\tvan=input()\r\n\tif ris!=van:\r\n\t\tfgh+=1\r\n\t\tris=van\r\n\t\t\r\nprint(fgh)",
"n = int(input())\r\narr = []\r\nfor i in range(n):\r\n a = int(input())\r\n arr.append(a)\r\n\r\nhold = arr[0]\r\ncounter = 1\r\nfor i in range(1,len(arr)):\r\n if arr[i] != hold:\r\n counter += 1\r\n hold = arr[i]\r\nprint(counter)",
"import sys\r\n\r\nn = int(input())\r\n\r\ngroups = 0\r\n\r\nfor i in range(n):\r\n num = int(input())\r\n if(i == 0):\r\n groups += 1\r\n elif(num != temp):\r\n groups += 1\r\n temp = num \r\nprint(groups)\r\n\r\n \r\n \r\n ",
"x = int(input())\r\nc = 1\r\nz = input()[1]\r\nfor i in range(x-1):\r\n z_ = input()\r\n if z == z_[0]:\r\n c+=1\r\n z = z_[1]\r\nprint(c)",
"n = int(input())\nmagnets = []\ngroups = 0\nfor _ in range(n):\n poles = input()\n magnets.append(poles)\ni = 0\nwhile i<n-1:\n if magnets[i] != magnets[i+1]:\n groups += 1\n i += 1\nprint(groups+1)",
"n = int(input())\r\ncount = 0\r\nfor i in range(n):\r\n a = input()\r\n if i == 0:\r\n count = count + 1\r\n elif prev == a[0]:\r\n count = count + 1 \r\n prev = a[1]\r\nprint(count)",
"n = int(input())\r\nqueue = []\r\nfor i in range(n):\r\n magnet = input()\r\n queue.append(magnet)\r\nj = 1\r\nfor i in range(1, n):\r\n if queue[i] != queue[i-1]:\r\n j += 1\r\nprint(j)\r\n",
"n = int(input())\ni = 1\ny = input()\nfor z in range(1, n):\n x = input()\n if x != y:\n i += 1\n y = x\nprint(i)\n\t\t\t \t \t \t \t\t\t \t\t \t\t \t",
"n=int(input())\r\nm=[input() for i in range(n)]\r\ngroups=1 \r\nfor i in range(1, n):\r\n if m[i]!=m[i - 1]:\r\n groups+=1\r\nprint(groups)\r\n",
"num=int(input())\r\nlst=[]\r\nres=1\r\nfor n in range(num):\r\n lst.append(input())\r\n\r\n\r\nfor i in range(len(lst)-1):\r\n if lst[i] == '10' and lst[i+1] == '01':\r\n res+=1\r\n elif lst[i] == '01' and lst[i+1] == '10':\r\n res+=1\r\nprint(res)\r\n",
"def Magnets(list_of_magnets):\r\n number_of_groups_of_magnets = 1\r\n\r\n if len(list_of_magnets) == 1:\r\n return number_of_groups_of_magnets\r\n\r\n for i in range(len(list_of_magnets) -1 ):\r\n if list_of_magnets[i] != list_of_magnets[i+1]:\r\n number_of_groups_of_magnets += 1\r\n\r\n return number_of_groups_of_magnets\r\n\r\n\r\n return list_of_groups_of_magnets\r\nif __name__ == \"__main__\" :\r\n list_of_magnets = list()\r\n number_of_magnets = int(input())\r\n for i in range(number_of_magnets):\r\n characters = input()\r\n list_of_magnets.append(characters)\r\n print(Magnets(list_of_magnets))\r\n\r\n",
"n = int(input())\r\nl = []\r\ncount = 1\r\nfor i in range(n):\r\n t = input()\r\n l.append(t)\r\nfor i in range(n-1):\r\n if(l[i] != l[i+1]):\r\n count += 1\r\nprint(count)\r\n ",
"p=f=-1\r\nfor s in open(0):f+=p!=s;p=s\r\nprint(f)",
"p = f = -1\r\nfor s in open(0):\r\n f += p != s\r\n p = s\r\nprint(f)\r\n\r\n\r\n# n = int(input())\r\n# output = 1\r\n# prev = input()\r\n# for i in range(1, n):\r\n# curr = input()\r\n# if curr != prev:\r\n# output += 1\r\n# prev = curr\r\n# print(output)\r\n",
"n = int(input())\r\ngr = 1\r\nprev_magnet = input()\r\nfor _ in range(n - 1):\r\n cm = input()\r\n if cm != prev_magnet:\r\n gr += 1\r\n prev_magnet = cm\r\nprint(gr)\r\n",
"n=input()\r\ni=1\r\nl=[]\r\nwhile i<=int(n):\r\n m=input()\r\n l.append(m)\r\n i+=1\r\na='-'.join(l)\r\nb=a.count('10-01')\r\nc=a.count('01-10')\r\nprint(b+c+1)",
"num=eval(input())\r\ny=[]\r\nc=0\r\nn=0\r\nfor i in range(num):\r\n x=int(input())\r\n y.append(x)\r\nfor i in range(len(y)-1):\r\n if y[i]==y[i+1]:\r\n c+=1\r\n #n+=1\r\n else:\r\n c=0\r\n n+=1\r\nn+=1\r\nprint(n)",
"def count_magnet_groups(n, magnet_arrangement):\n groups = 1 \n for i in range(1, n):\n if magnet_arrangement[i] != magnet_arrangement[i - 1]:\n groups += 1\n return groups\n\n\nn = int(input())\nmagnet_arrangement = [input() for i in range(n)]\n\n\nresult = count_magnet_groups(n, magnet_arrangement)\nprint(result)\n\t\t \t \t \t \t\t\t \t \t\t \t\t",
"n = int(input())\nmagnets = [input() for _ in range(n)]\n\nres = 1\nfor i in range(len(magnets) - 1):\n if magnets[i][1] == magnets[i + 1][0]:\n res += 1\n\nprint(res) ",
"prev = ''\r\nans = 1\r\nfor _ in range(int(input())):\r\n s = input()\r\n if prev:\r\n if s[0] == prev[-1]:\r\n ans += 1\r\n prev = s\r\nprint(ans)",
"n=int(input())\r\na=[]\r\ncount=1\r\n\r\nfor _ in range(n):\r\n x=int(input())\r\n a.append(x)\r\n \r\nfor i in range(1,n):\r\n if a[i]!=a[i-1]:\r\n count+=1\r\n \r\nprint(count)",
"n = int(input())\r\nc = None\r\nans= 1\r\nfor _ in range(n):\r\n m=str(input())\r\n if m[0] == c:\r\n ans+=1\r\n c = m[1]\r\nprint(ans)\r\n",
"d = 00\r\nc = 0\r\nfor x in range(int(input())):\r\n s = int(input())\r\n if d != s:\r\n c += 1\r\n d = s\r\nprint(c)\r\n",
"n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n a=input()\r\n if(len(l)<1):\r\n l.append(a)\r\n else:\r\n if(a!=l[len(l)-1]):\r\n l.append(a)\r\n j=0\r\nprint(len(l))",
"count_magnets = int(input())\r\ncount_islands = 1\r\nlast_magnet = input()\r\nfor i in range(count_magnets -1):\r\n current_magnet = input()\r\n if current_magnet != last_magnet:\r\n count_islands += 1\r\n last_magnet = current_magnet\r\nprint(count_islands)\r\n",
"n = int(input())\r\ngroups = 1\r\nprev = input()\r\nfor _ in range(n-1):\r\n curr = input()\r\n if curr != prev:\r\n groups += 1\r\n prev = curr\r\nprint(groups)\r\n",
"n = int(input())\r\nisland = 0\r\nmagnit = []\r\nfor i in range(n):\r\n magnit.append(input())\r\nfor j in range(n):\r\n if j == n-1:\r\n break\r\n elif magnit[j] == magnit[j+1]:\r\n continue\r\n else:\r\n island += 1\r\nprint(island+1)",
"n,m=[],1\r\nfor i in range(int(input())):\r\n n2=input()\r\n if n==[] or n[-1]==n2:\r\n n.append(n2)\r\n else:\r\n m+=1\r\n n=[n2]\r\nprint(m)",
"if __name__ == \"__main__\":\r\n num = int(input())\r\n\r\n groups = 1\r\n allMagnets = []\r\n for i in range(num):\r\n magnet = input()\r\n if(i != 0):\r\n if(allMagnets[-1] != magnet):\r\n groups += 1\r\n allMagnets.append(magnet) \r\n print(groups)",
"n = int(input())\r\ncounter = 1\r\ndata = []\r\nfor i in range(n):\r\n magnet = input()\r\n if data:\r\n if data[-1] != magnet:\r\n counter += 1\r\n data.append(magnet)\r\n else:\r\n data.append(magnet)\r\n\r\nprint(counter)",
"n = int(input())\r\ngroups = 0\r\n\r\nlist1 =[]\r\nfor i in range(n):\r\n k = input()\r\n list1.append(k)\r\n \r\n if(len(list1) > 1):\r\n if list1[i]!=list1[i-1] :\r\n groups +=1 \r\n i = i +1 \r\n \r\n\r\nprint(groups + 1)\r\n \r\n\r\n\r\n",
"s = int(input())\r\nc = []\r\nfor _ in range(s):\r\n p = input()\r\n #c =[]\r\n c.append(p)\r\n k = 0\r\nfor i in range(1,len(c)):\r\n if c[i] != c[i-1]:\r\n k+=1\r\nprint(k+1)",
"# Read the number of magnets\r\nn = int(input())\r\n\r\n# Initialize variables to keep track of the current group and the count of groups\r\ncurrent_group = None\r\ngroup_count = 0\r\n\r\n# Iterate through the magnets\r\nfor _ in range(n):\r\n magnet = input()\r\n\r\n # If the current magnet is different from the previous one, start a new group\r\n if magnet != current_group:\r\n current_group = magnet\r\n group_count += 1\r\n\r\n# Print the number of groups\r\nprint(group_count)\r\n",
"n=m=-1\r\nfor s in open(0):m+=n!=s;n=s\r\nprint(m)",
"\r\nn = int(input())\r\nlist1 = []\r\ntag = 1\r\nfor i in range(n):\r\n list1.append(input())\r\nfor i in range(n-1):\r\n if list1[i] != list1[i+1]:\r\n tag += 1\r\nprint(tag)",
"a = int(input())\r\n\r\nb = input()\r\nchk = b[1]\r\ncnt = 1\r\n\r\nfor i in range(1,a):\r\n k = input()\r\n if k[0] == chk:\r\n cnt = cnt + 1\r\n chk = k[1]\r\n\r\nprint(cnt)\r\n\r\n",
"t = int(input())\r\n\r\ngroup = 1\r\nprev = input()\r\nfor _ in range(t-1):\r\n curr = input()\r\n if curr != prev:\r\n group += 1\r\n prev = curr\r\nprint(group)",
"n = int(input())\r\nmagnets = [input() for _ in range(n)]\r\n\r\n# Initialize variables to count groups and set the initial group to the first magnet\r\ngroups = 1\r\ncurrent_magnet = magnets[0]\r\n\r\n# Iterate through the magnets and count groups based on their orientation and polarity\r\nfor i in range(1, n):\r\n if magnets[i] != current_magnet:\r\n groups += 1\r\n current_magnet = magnets[i]\r\n\r\nprint(groups)\r\n",
"n = int(input())\r\n\r\ncount = 0\r\nmagnets = []\r\nfor _ in range(n):\r\n magnets.append(str(input()))\r\n\r\nfor i in range(n-1):\r\n if magnets[i] != magnets[i+1]:\r\n count += 1\r\nprint(count+1)\r\n",
"n = int(input())\r\nprev = input()\r\nk = 1\r\nfor _ in range(n-1):\r\n s = input()\r\n k += int(s[0] == prev[1])\r\n prev = s\r\nprint(k)",
"n = int(input()) \r\nmagnet_groups = 1 \r\nprev_magnet = input() \r\nfor _ in range(n - 1):\r\n current_magnet = input() \r\n \r\n \r\n if current_magnet != prev_magnet:\r\n magnet_groups += 1 \r\n prev_magnet = current_magnet \r\n\r\nprint(magnet_groups)\r\n",
"n = int(input()) \r\nc = 0 \r\nb = 0 \r\nfor i in range(n): \r\n a = int(input()) \r\n if a != b: \r\n c += 1 \r\n b =a \r\n \r\nprint(c)",
"n = int(input())\r\ncount = 1\r\nmagnet0 = str(input())\r\nfor i in range(n-1):\r\n magnet = str(input())\r\n if magnet != magnet0:\r\n count += 1\r\n magnet0 = magnet\r\n else:\r\n magnet0 = magnet\r\n\r\n\r\nprint(count)\r\n \r\n",
"num = int(input(\"\"))\nn = 0\nres = 1\nli = []\nwhile(n < num):\n x = int(input(\"\"))\n \n if((n != 0) and (li.pop() != x)):\n res = res+1\n li.append(x)\n n = n+1\n\nprint(res)\n \t\t \t\t\t \t\t\t \t\t \t \t \t \t \t",
"n=int(input())\r\nc=1 \r\nold=int(input())\r\nfor i in range(1,n):\r\n s=int(input())\r\n if old!=s:\r\n old=s\r\n c+=1 \r\nprint(c)",
"number_of_magnets = int(input())\r\n_list = []\r\nfor i in range(number_of_magnets):\r\n x = input()\r\n _list.append(x)\r\n\r\nnumber_of_groups = 1\r\nfor i in range(len(_list)):\r\n if i != len(_list) - 1:\r\n if _list[i] != _list[i+1]:\r\n number_of_groups += 1\r\n\r\nprint(number_of_groups)\r\n",
"LastMagnet = None\r\nGroups = 0\r\n\r\nfor i in range(int(input())):\r\n Magnet = input()\r\n if Magnet != LastMagnet:\r\n Groups += 1\r\n LastMagnet = Magnet\r\n\r\nprint(Groups)",
"n=int(input())\r\nmagnets=[input() for i in range(n)]\r\ngroups=1\r\nfor i in range(1,n):\r\n if magnets[i]!=magnets[i-1]:\r\n groups+=1\r\nprint(groups)",
"n = int(input())\nprev = \"\"\ngroups = 0\n\nfor _ in range(n):\n s = input()\n if s != prev:\n groups += 1\n prev = s\n\nprint(groups)",
"n = int(input())\r\nc = 0\r\ns = ''\r\nfor i in range(n):\r\n a = input()\r\n s += a\r\nfor j in range(1,len(s)):\r\n if s[j] == s[j-1]:\r\n c += 1\r\nprint(c+1)",
"n=int(input())\r\nl=[]\r\nc=0\r\nfor i in range(n):\r\n a=int(input())\r\n l.append(a)\r\nfor j in range(n-1):\r\n if l[j] != l[j+1]:\r\n c=c+1\r\nprint(c+1)",
"a=[]\r\ncount=1\r\nn=int(input())\r\nfor _ in range(n):\r\n \r\n a.append(int(input()))\r\nfor i in range(n-1):\r\n if a[i]==a[i+1]:\r\n continue\r\n else:\r\n count+=1\r\nprint(count)\r\n \r\n",
"def magnet():\r\n n_magnet = int(input())\r\n series = \"\"\r\n counter = 1\r\n for x in range(n_magnet):\r\n series += input()\r\n \r\n for i in range(1, len(series) - 1):\r\n if series[i - 1] == series[i]:\r\n counter += 1\r\n return counter\r\nprint(magnet())",
"p=w=-1\r\nfor s in open(0):w+=p!=s;p=s\r\nprint(w)",
"last=\"-1\"\r\nc=1\r\nfor i in range(int(input())):\r\n tmp=input()\r\n if last == tmp[0]:\r\n c+=1\r\n last=tmp[1]\r\nprint(c)",
"number_of_magnets = int(input())\r\ncount = 1\r\nprev = int(input())\r\n\r\nfor i in range(1, number_of_magnets):\r\n next=int(input())\r\n if prev != next:\r\n prev = next\r\n count += 1\r\n\r\nprint(count)\r\n\r\n",
"\r\nN = int(input())\r\n\r\ngroups = 1\r\np = input()\r\n\r\nfor _ in range(N - 1):\r\n c = input()\r\n if c != p:\r\n groups += 1\r\n p = c\r\n\r\nprint(groups)\r\n",
"q=f=-1\r\nfor u in open(0):f+=q!=u;q=u\r\nprint(f)\r\n",
"n = int(input())\r\nmagnet_list = [input() for _ in range(n)]\r\n\r\n# Initialize variables\r\ngroups = 0\r\ncurrent_magnet = magnet_list[0]\r\n\r\n# Count the number of groups\r\nfor magnet in magnet_list:\r\n if magnet == current_magnet:\r\n continue\r\n else:\r\n groups += 1\r\n current_magnet = magnet\r\n\r\n# Add 1 for the last group\r\ngroups += 1\r\n\r\nprint(groups)\r\n",
"n = int(input())\r\ntrash=[]\r\nfor i in range(n):\r\n word = input()\r\n trash.append(word)\r\ncount = 1 \r\nfor i in range(len(trash)-1):\r\n if (trash[i][1]=='0' and trash[i+1][0]=='1') or (trash[i][1]=='1' and trash[i+1][0]=='0'):\r\n continue\r\n else:\r\n count+=1\r\nprint(count) ",
"a=int(input())\r\ncnt=1\r\nn1=int(input())\r\nfor _ in range(a-1):\r\n n2=int(input())\r\n if n2!=n1:\r\n n1=n2\r\n cnt=cnt+1\r\nprint(cnt)",
"groups = 0\nprevious = None\nn = int(input())\nfor i in range(n):\n line = input()\n if previous is None or previous != line:\n previous = line\n groups+=1\n else:\n continue\nprint(groups)\n\t \t \t\t \t\t \t\t\t \t\t\t\t \t",
"n = int(input())\r\ncount = 1\r\nmagnets = []\r\nfor i in range(0, n):\r\n m = input()\r\n magnets.append(m)\r\nfor i in range(0, n-1):\r\n if (magnets[i]) != (magnets[i+1]): count += 1\r\n\r\n \r\nprint(count)",
"d = int(input())\nl = []\nfor i in range(d):\n l.append(list(input()))\ng = 1\nfor i in range(d - 1):\n a = l[i][1]\n b = l[i + 1][0]\n if a == b:\n g += 1\nprint(g)",
"t=int(input())\r\nm=[input() for i in range(t)]\r\ng=1\r\nfor i in range(1,t):\r\n if m[i]!=m[i-1]:\r\n g+=1\r\n \r\nprint(g)",
"s = int(input())\r\nprev_magnet = input()\r\nnum_groups = 1\r\nfor _ in range(1, s):\r\n current_magnet = input()\r\n if current_magnet != prev_magnet:\r\n num_groups += 1\r\n prev_magnet = current_magnet\r\nprint(num_groups)",
"def count_magnet_groups(n, magnets):\r\n groups = 1\r\n for i in range(1, n):\r\n if magnets[i] != magnets[i-1]:\r\n groups += 1\r\n return groups\r\nn = int(input())\r\nmagnets = [input() for _ in range(n)]\r\nnum_groups = count_magnet_groups(n, magnets)\r\nprint(num_groups)\r\n",
"a=[input()for _ in range(int(input()))]\r\nprint(sum(e!=a[i]for i,e in enumerate(a[1:]))+1)",
"# LUOGU_RID: 133150235\na = int(input())\r\nc = 1\r\nd = []\r\nfor i in range(1,a+1):\r\n b = input()\r\n d.append(b)\r\n\r\nm=d[1:]\r\nn=d[:-1]\r\nfor i in zip(m, n):\r\n if i[0]!=i[1]:\r\n c += 1\r\n\r\n\r\nprint(c)",
"n = int(input())\r\nm = [input() for _ in range(n)]\r\ngrp= 1 \r\nfor i in range(1, n):\r\n if m[i] != m[i - 1]:\r\n grp += 1\r\nprint(grp)\r\n",
"def main():\r\n from sys import stdin,stdout\r\n state=''\r\n counter=0\r\n for _ in range(int(stdin.readline())):\r\n s=stdin.readline()\r\n if s!=state:\r\n counter+=1\r\n state=s\r\n stdout.write(str(counter))\r\nif __name__=='__main__':\r\n main()",
"n = int(input())\r\nc = 0\r\ncharacter = \"\"\r\n\r\nfor i in range(n):\r\n s = input().strip()\r\n ch = s\r\n if ch != character:\r\n c += 1\r\n character = ch\r\n\r\nprint(c)",
"n = int(input())\r\nf = input()\r\ncurr = f\r\nans = 1\r\nfor i in range(n-1):\r\n m = input()\r\n if m != curr:\r\n ans += 1\r\n curr = m\r\n\r\nprint(ans)\r\n",
"x=f=-1\r\nfor s in open(0):f+=x!=s;x=s\r\nprint(f)",
"n = int(input())\r\np = input()\r\ni = 1\r\nfor _ in range(n - 1):\r\n c = input()\r\n if c != p:\r\n i += 1\r\n p = c\r\nprint(i)",
"# Read the number of magnets\r\nn = int(input())\r\n\r\n# Initialize variables to keep track of groups and the previous magnet's orientation\r\ngroups = 0\r\nprev_magnet = None\r\n\r\n# Iterate through the magnets\r\nfor _ in range(n):\r\n magnet = input().strip()\r\n \r\n # If the current magnet's orientation is different from the previous one, it forms a new group\r\n if magnet != prev_magnet:\r\n groups += 1\r\n \r\n # Update the previous magnet's orientation\r\n prev_magnet = magnet\r\n\r\n# Print the number of groups\r\nprint(groups)\r\n",
"n = int(input()) # Number of magnets\r\nmagnets = []\r\n\r\nfor i in range(n):\r\n magnet = input()\r\n magnets.append(magnet)\r\n \r\ngroups = 1 # Initialize with 1 group for the first magnet\r\nfor i in range(1, n):\r\n if magnets[i] != magnets[i - 1]:\r\n groups += 1\r\n \r\nprint(groups)\r\n\r\n \r\n ",
"iter= int(input())\r\nall=[]\r\nnum=1\r\nfor i in range(iter):\r\n all.append(input())\r\n if (i != 0):\r\n if (all[i][0]!= all[i-1][0]):\r\n num +=1\r\n\r\n\r\nprint(num)\r\n\r\n\r\n",
"\r\nnum_magnets = int(input())\r\nmagnets = []\r\ngroups = 1\r\n\r\nfor i in range(num_magnets):\r\n magnet_type = input()\r\n magnets.append(magnet_type)\r\n \r\nfor j in range(1, len(magnets)):\r\n if magnets[j] != magnets[j-1]:\r\n groups += 1\r\n \r\nprint(groups)\r\n \r\n \r\n",
"n = int(input())\r\na = []\r\nfor _ in range(n):\r\n a.append(int(input()))\r\ncount = 1\r\n\r\nfor i in range(len(a)-1):\r\n if a[i] == a[i+1]:\r\n continue\r\n else:\r\n count += 1\r\n\r\nprint(count)",
"a=int(input())\r\nb=input()\r\nc=1\r\nfor i in range(0,a-1):\r\n d=input()\r\n if d!=b:\r\n c+=1\r\n b=d\r\nprint(c)",
"n=int(input())\r\nx=[]\r\nfor i in range(n):\r\n m=int(input())\r\n x.append(m)\r\nc=1\r\nfor i in range(n-1):\r\n if x[i]==x[i+1]:\r\n continue\r\n else:\r\n c+=1\r\nprint(c)\r\n \r\n ",
"n = int(input())\nanterior = 0\ntotal = 0\n\nfor x in range(n):\n i = int(input())\n if i != anterior:\n total+=1\n anterior = i\n\nprint(total)",
"n = int(input())\r\nmagn = [input() for _ in range(n)]\r\n\r\nisl = 1\r\nfor i in range(1, n):\r\n if magn[i] != magn[i-1]:\r\n isl += 1\r\n\r\nprint(isl)\r\n",
"n = int(input())\r\nprevious = int(input())\r\na = 1 #从一组开始,如果全都没有不一样的最后拼完还是一组\r\n\r\nfor i in range(1,n):\r\n new = int(input())\r\n if new != previous:\r\n a += 1\r\n previous = new\r\n\r\nprint(a)",
"magnet = int(input())\r\nmagnets = [input() for i in range(magnet)]\r\n \r\ngroups = 1\r\nfor i in range(1, magnet):\r\n if magnets[i] != magnets[i - 1]:\r\n groups += 1\r\n \r\nprint(groups)",
"n = int(input())\r\nc = 1\r\nm = [int(input())]\r\nfor i in range(1, n):\r\n m.append(int(input()))\r\n if m[i] != m[i - 1]:\r\n c += 1\r\nprint(c)\r\n",
"def count_magnet_groups(n, magnet_arrangement):\r\n groups = 1 \r\n for i in range(1, n):\r\n if magnet_arrangement[i] != magnet_arrangement[i - 1]:\r\n groups += 1 \r\n return groups\r\nn = int(input())\r\nmagnet_arrangement = [input() for _ in range(n)]\r\nprint(count_magnet_groups(n, magnet_arrangement))\r\n",
"n = int(input())\r\nmagnets = []\r\ncounter = 1\r\ni = 0\r\n\r\nwhile i < n:\r\n magnets.append(input())\r\n i += 1\r\n\r\nfor i in range(1, n):\r\n if magnets[i] != magnets[i - 1]:\r\n counter += 1\r\n\r\nprint(counter)\r\n",
"n = int(input())\na = input()\nc = 1\nfor i in range(1,n):\n b = input()\n if a != b:\n c+=1\n a = b\n\nprint(c)\n\n\n\t\t \t\t \t \t \t \t \t\t\t",
"l=[]\r\nfor i in range(int(input())):\r\n l.append(int(input()))\r\n\r\ncount=1\r\nfor i in range(1,len(l)):\r\n if l[i]!=l[i-1]:\r\n count+=1\r\nprint(count)",
"number_of_magnets = int(input())\r\ngroups = 1\r\npole_direction = []\r\nfor magnet in range(number_of_magnets):\r\n pole_direction += input().split() # plus-minus 01 , minus-plus 10\r\n if not magnet == 0:\r\n if pole_direction[magnet] != pole_direction[magnet - 1]:\r\n groups += 1\r\nprint(groups) \r\n ",
"number_of_magnets = int(input())\r\nmagnet_start = \"\"\r\ni = 0\r\nnumber_of_groups = 0\r\nfor _ in range(number_of_magnets):\r\n magnet_position = input()\r\n if magnet_start != magnet_position[0]:\r\n number_of_groups += 1\r\n magnet_start = magnet_position[0]\r\nprint(number_of_groups)",
"n = int(input())\r\nmagnet_str = ''\r\nfor i in range (n):\r\n magnet = input()\r\n magnet_str += magnet\r\n \r\nnumber_of_groups = 1\r\n\r\nnegatives_together = magnet_str.count('00')\r\npositives_together = magnet_str.count('11')\r\n\r\nnumber_of_groups += negatives_together + positives_together\r\n\r\nprint(number_of_groups)\r\n",
"x=int(input())\r\nans=[]\r\np=0\r\nfor a in range(x):\r\n y=input()\r\n ans.append(int(y[0]))\r\n ans.append(int(y[1]))\r\nfor b in range(len(ans)-2):\r\n if ans[b]==ans[b+1]:\r\n p=p+1\r\nprint(p+1)\r\n",
"n = int(input())\nmagnets = []\n\nfor x in range(n):\n temp = input()\n magnets.append(temp)\n \nislands = 1\n\n\nfor key,item in enumerate(magnets):\n #print(key,item)\n if key != 0 and item != magnets[key-1]:\n islands += 1\n\nprint(islands) ",
"koll=int(input())\r\nx=[input() for i in range(koll)]\r\ncou=1\r\nfor i in range(1,koll):\r\n if x[i-1]!=x[i]:\r\n cou+=1\r\nprint(cou)",
"n=int(input())\r\nmag=[input() for i in range(n)]\r\nt=1 \r\nfor i in range(1,n):\r\n if mag[i]!=mag[i-1]:\r\n t+=1 \r\nprint(t)",
"n = int(input())\r\nmag = []\r\nmain = []\r\nfor i in range(n):\r\n string = input()\r\n if len(mag) == 0:\r\n mag.append(string)\r\n elif string == mag[-1]:\r\n mag.append(string)\r\n else:\r\n main.append(mag[:]) \r\n mag.clear()\r\n mag.append(string)\r\nif mag:\r\n main.append(mag[:])\r\nprint(len(main))\r\n\r\n",
"array = []\r\ncount = 1\r\nfor _ in range(int(input())):\r\n justMyUniverse = input()\r\n array.append(justMyUniverse)\r\nfor i in range(1,len(array)):\r\n if array[i - 1] != array[i]:\r\n count+=1\r\nprint(count)",
"n=int(input())\r\nmy_list=[]\r\ncount=1\r\n\r\nfor _ in range(n):\r\n my_str=input()\r\n my_list.append(my_str)\r\n \r\nfor i in range(len(my_list)-1):\r\n if my_list[i]==my_list[i+1]:\r\n pass\r\n else:\r\n count +=1\r\n\r\nprint(count)\r\n ",
"n = int(input())\r\ns=''\r\ni = 0\r\n\r\nfinalGroup = 1\r\n\r\nwhile (i<n):\r\n s += input()\r\n i += 1\r\n\r\nfor j in range(len(s)-1):\r\n if (s[j] == '1' and s[j + 1] == '1') or (s[j] == '0' and s[j + 1] == '0'):\r\n finalGroup += 1\r\n else:\r\n continue\r\n\r\nprint(finalGroup)\r\n",
"n = int(input())\r\nmagnets = []\r\njoined_magnets = []\r\njoined = []\r\ncounter = 0\r\n\r\nfor i in range(n):\r\n magnet = int(input())\r\n magnets.append(magnet)\r\n\r\nmagnets.append(-1)\r\n\r\nfor i in range(len(magnets)-1):\r\n if magnets[i] == magnets[i+1]:\r\n joined_magnets.append(magnets[i])\r\n continue\r\n else:\r\n joined_magnets.append(magnets[i])\r\n joined.append(joined_magnets)\r\n joined_magnets = []\r\n\r\n\r\nprint(len(joined))",
"ans = 0\r\nf = '-1'\r\nfor _ in range(int(input())):\r\n s = input()\r\n ans += int(f != s)\r\n f = s\r\nprint(ans)",
"\r\nn = int(input())\r\n\r\nislands = 0\r\ncurrent_magnet = None\r\n\r\n\r\nfor i in range(n):\r\n magnet = input().strip()\r\n \r\n if current_magnet is None:\r\n current_magnet = magnet\r\n elif current_magnet != magnet:\r\n islands += 1\r\n current_magnet = magnet\r\n\r\n\r\nif current_magnet is not None:\r\n islands += 1\r\n\r\n\r\nprint(islands)\r\n",
"import sys\r\n\r\n\r\ndef iinp():\r\n return int(sys.stdin.readline().strip())\r\n\r\n\r\ndef linp():\r\n return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\n\r\ndef lsinp():\r\n return sys.stdin.readline().strip().split()\r\n\r\n\r\ndef digit():\r\n return [int(i) for i in (list(sys.stdin.readline().strip()))]\r\n\r\n\r\ndef char():\r\n return list(sys.stdin.readline().strip())\r\n\r\n\r\nfrom math import factorial\r\n\r\n\r\ndef solve():\r\n n = iinp()\r\n prev = iinp()\r\n ans = 1\r\n for i in range(n - 1):\r\n cur = iinp()\r\n if prev != cur:\r\n ans += 1\r\n prev = cur\r\n print(ans)\r\n\r\n\r\nq = 1\r\nfor _ in range(q):\r\n solve()\r\n",
"n = int(input())\r\nm = input()\r\nq = 1\r\nfor i in range(n - 1):\r\n l = input()\r\n if m[1] == l[0]:\r\n q += 1\r\n m = l\r\nprint(q)\r\n\r\n"
] | {"inputs": ["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10", "1\n10", "2\n01\n10", "2\n10\n10", "3\n10\n01\n10", "1\n01", "2\n01\n01", "2\n10\n01", "3\n01\n01\n01", "3\n10\n10\n01", "3\n01\n10\n10", "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n10\n10\n10\n10\n01\n01\n01\n10\n10\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n10\n10\n01\n10\n01\n01\n01\n01\n01\n10\n01\n10\n10\n01\n01\n01\n10\n01\n01\n10\n10\n01\n01\n01\n01\n01\n10\n01\n10\n01\n10\n01\n01\n01\n10\n01\n10\n10\n01\n10\n10\n01\n01\n01\n10\n10\n10\n10\n10\n10\n10\n10"], "outputs": ["3", "2", "1", "2", "1", "3", "1", "1", "2", "1", "2", "2", "55"]} | UNKNOWN | PYTHON3 | CODEFORCES | 484 | |
322e8db062139940fd3ce280df4450dd | Guess Your Way Out! | Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the leaf nodes from the left to the right from 1 to 2*h*. The exit is located at some node *n* where 1<=≤<=*n*<=≤<=2*h*, the player doesn't know where the exit is so he has to guess his way out!
Amr follows simple algorithm to choose the path. Let's consider infinite command string "LRLRLRLRL..." (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules:
- Character 'L' means "go to the left child of the current node"; - Character 'R' means "go to the right child of the current node"; - If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node; - If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command; - If he reached a leaf node that is not the exit, he returns to the parent of the current node; - If he reaches an exit, the game is finished.
Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit?
Input consists of two integers *h*,<=*n* (1<=≤<=*h*<=≤<=50, 1<=≤<=*n*<=≤<=2*h*).
Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm.
Sample Input
1 2
2 3
3 6
10 1024
Sample Output
25102046 | [
"from collections import defaultdict, deque, Counter\r\nfrom sys import stdin, stdout\r\nfrom heapq import heappush, heappop\r\nimport math\r\nimport io\r\nimport os\r\nimport math\r\nimport bisect\r\n\r\n#?############################################################\r\n\r\n\r\ndef isPrime(x):\r\n for i in range(2, x):\r\n if i*i > x:\r\n break\r\n if (x % i == 0):\r\n return False\r\n return True\r\n\r\n#?############################################################\r\n\r\n\r\ndef ncr(n, r, p):\r\n num = den = 1\r\n for i in range(r):\r\n num = (num * (n - i)) % p\r\n den = (den * (i + 1)) % p\r\n return (num * pow(den, p - 2, p)) % p\r\n\r\n\r\n#?############################################################\r\n\r\ndef primeFactors(n):\r\n l = []\r\n while n % 2 == 0:\r\n l.append(2)\r\n n = n / 2\r\n for i in range(3, int(math.sqrt(n))+1, 2):\r\n while n % i == 0:\r\n l.append(int(i))\r\n n = n / i\r\n if n > 2:\r\n l.append(n)\r\n return list(set(l))\r\n\r\n\r\n#?############################################################\r\n\r\ndef power(x, y, p):\r\n res = 1\r\n x = x % p\r\n if (x == 0):\r\n return 0\r\n while (y > 0):\r\n if ((y & 1) == 1):\r\n res = (res * x) % p\r\n y = y >> 1\r\n x = (x * x) % p\r\n return res\r\n\r\n#?############################################################\r\n\r\n\r\ndef sieve(n):\r\n prime = [True for i in range(n+1)]\r\n p = 2\r\n while (p * p <= n):\r\n if (prime[p] == True):\r\n for i in range(p * p, n+1, p):\r\n prime[i] = False\r\n p += 1\r\n return prime\r\n\r\n\r\n#?############################################################\r\n\r\ndef digits(n):\r\n c = 0\r\n while (n > 0):\r\n n //= 10\r\n c += 1\r\n return c\r\n\r\n#?############################################################\r\n\r\n\r\ndef ceil(n, x):\r\n if (n % x == 0):\r\n return n//x\r\n return n//x+1\r\n\r\n#?############################################################\r\n\r\n\r\ndef mapin():\r\n return map(int, input().split())\r\n\r\n#?############################################################\r\n\r\n\r\n# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n# python3 15.py<in>op\r\n\r\n\r\ndef solve(a,b,size):\r\n \r\n msf = -1e9\r\n meh = 0\r\n for i in range(b,size):\r\n meh = meh + a[i]\r\n if (msf < meh):\r\n msf = meh\r\n \r\n if meh < 0:\r\n meh = 0 \r\n return msf\r\nt = 1\r\nll = [2**i for i in range(60)]\r\nfor _ in range(t):\r\n h, n =mapin()\r\n \r\n l = [0]*(h+1)\r\n l[h] = n\r\n z = h\r\n c = ll[h-1]\r\n while(z):\r\n te = l[z]\r\n if(l[z]> ll[z-1]):\r\n te = l[z]-ll[z-1]\r\n z-=1\r\n l[z] = te\r\n \r\n \r\n \r\n # print(l)\r\n # print(ll)\r\n # print(h) \r\n \r\n \r\n i = 0\r\n ans = 0\r\n curr = 0\r\n while(h>0):\r\n # print(h, l[h], ll[h-1], ll[h])\r\n \r\n if(i&1 == 0):\r\n if(l[h]<= ll[h-1]):\r\n ans+=1\r\n i+=1\r\n else: \r\n ans+=ll[h]\r\n \r\n else:\r\n if(l[h]> ll[h-1]):\r\n ans+=1\r\n i+=1\r\n else: \r\n ans+=ll[h]\r\n \r\n h-=1\r\n \r\n\r\n \r\n \r\n \r\n # i+=1\r\n \r\n \r\n print(ans)\r\n \r\n \r\n \r\n ",
"h, p = map(int, input().split());\r\nans = 0;\r\nml = 0;\r\ngl = True;\r\n\r\nwhile(h >= 1):\r\n h-= 1;\r\n if(p > ml and p <= ml + (1 << h)):\r\n if(gl):\r\n ans += 1;\r\n gl = not gl;\r\n else:\r\n ans += (2 * (1 << h));\r\n else:\r\n ml += 1 << h;\r\n if(not gl):\r\n ans += 1;\r\n gl = not gl;\r\n else:\r\n ans += (2 * (1 << h));\r\n\r\nprint(f\"{ans}\");\r\n",
"def pow1(x, base):\r\n sq = 1\r\n while (base > 0):\r\n\r\n if base % 2:\r\n base -= 1\r\n sq = (sq * x) # % mod\r\n\r\n base //= 2\r\n x = (x * x) # % mod\r\n\r\n return sq\r\n\r\n\r\nh, n = map(int, input().split())\r\nlevels = pow1(2, h)\r\ncur, be, en = 1, 1, levels\r\nlast = 1\r\n\r\nwhile h:\r\n mid, flag = (be + en) // 2, 0\r\n if n <= mid:\r\n en, flag = mid, 0\r\n else:\r\n be, flag = mid + 1, 1\r\n\r\n if flag != last:\r\n cur += 1\r\n else:\r\n cur += pow1(2, h)\r\n last = flag\r\n h -= 1\r\n\r\nprint(cur - 1)\r\n",
"import time\r\nstartTimeProblem=time.time()\r\n\r\nimport fileinput, sys, itertools, functools, math\r\nfrom bisect import *\r\nfrom heapq import *\r\nfrom collections import *\r\n\r\n\r\nMOD = 10**9+7 #isprime\r\ndef lcm(a, b): \r\n return (a*b)/math.gcd(a, b)\r\n\r\ndef precompute_binom(n,p):\r\n facts = [0]*n\r\n invfacts = [0]*n\r\n\r\n facts[0] = 1\r\n invfacts[0] = 1\r\n\r\n for i in range(1,n): \r\n facts[i] = (facts[i-1]*i)%p\r\n invfacts[i] = pow(facts[i],p-2,p)\r\n\r\n return facts, invfacts\r\n\r\ndef binom_pre_computed(facts, invfacts, n, k, p):\r\n # n! / (k!^(p-2) * (n-k)!^(p-2)) (mod p)\r\n return (facts[n] * ((invfacts[k]*invfacts[n-k] % p))) % p\r\n\r\nclass UnionFind:\r\n def __init__(self, n):\r\n self.link = [i for i in range(n)]\r\n self.size = [i for i in range(n)]\r\n \r\n def find(self, i):\r\n while i!=self.link[i]:\r\n i = self.link[i]\r\n return i\r\n \r\n def same(self, i, j):\r\n return self.find(i) == self.find(j)\r\n \r\n def unite(self, i, j):\r\n i = self.find(i)\r\n j = self.find(j)\r\n\r\n if self.size[i] < self.size[j]:\r\n i, j = j,i\r\n \r\n size[i]+=size[j]\r\n link[j] = i\r\n\r\n\r\nclass InputHelper:\r\n def __init__(self):\r\n self.myinput = fileinput.input()\r\n\r\n def isLocal(self):\r\n return not fileinput.isstdin()\r\n\r\n def int(self):\r\n return int(self.myinput.readline().rstrip())\r\n\r\n def ints(self):\r\n return [int(_) for _ in self.myinput.readline().rstrip().split()]\r\n\r\n def str(self):\r\n return self.myinput.readline().rstrip()\r\n\r\n def strs(self):\r\n return [_ for _ in self.myinput.readline().rstrip().split()]\r\n\r\nclass OutputHelper:\r\n def int(self, a):\r\n print(a) \r\n\r\n def ints(self, a): \r\n print(\" \".join([str(_) for _ in a]))\r\n \r\n def intsNL(self, a):\r\n for _ in a:\r\n print(_)\r\n \r\n def str(self, s):\r\n print(s)\r\n\r\n def strs(self, s):\r\n print(\" \".join([_ for _ in s]))\r\n\r\n def strsNL(self, s):\r\n for st in s:\r\n print(st)\r\n\r\nclass ListNode:\r\n def __init__(self, val):\r\n self.val = val\r\n self.next = None\r\n self.prev = None\r\n\r\nclass SegmentTree:\r\n def __init__(self, arr): \r\n self.n = 2**math.ceil(math.log2(len(arr)))\r\n self.me = [0]*(self.n*2) \r\n \r\n for i in range(self.n, 2*self.n):\r\n ct = i-self.n\r\n\r\n if ct>=len(arr):\r\n break\r\n\r\n self.me[i] = arr[ct] if ct<len(arr) else 0 \r\n \r\n for i in range(2*self.n-1, 0, -1):\r\n self.me[i//2] += self.me[i]\r\n \r\n def getFromToIncl(self, a, b):\r\n \"\"\"\r\n O(log n)\r\n \"\"\"\r\n\r\n a+=self.n\r\n b+=self.n\r\n\r\n s = 0\r\n\r\n while a<=b:\r\n if a%2==1:\r\n s += self.me[a]\r\n a+=1\r\n if b%2==0:\r\n s += self.me[b]\r\n b-=1\r\n \r\n a//=2\r\n b//=2\r\n\r\n return s\r\n \r\n def op(self, pos, val):\r\n \"\"\"\r\n O(log n)\r\n \"\"\"\r\n pos+=self.n\r\n self.me[pos]+=val\r\n\r\n pos//=2\r\n\r\n while pos>=1:\r\n self.me[pos] = self.me[2*pos]+self.me[2*pos+1]\r\n pos//=2\r\n \r\n\r\nIn = InputHelper()\r\nOut = OutputHelper()\r\n\r\n#######################################\r\n#sys.setrecursionlimit(10000)\r\n\r\nh,n = In.ints()\r\n\r\nh+=1\r\nl = 1\r\nr = 2**(h-1)\r\n\r\nswitch=True\r\nlatest=\"r\"\r\n\r\nans = 0\r\n\r\nwhile l<r:\r\n mid = (l+r)//2\r\n\r\n if n<=mid:\r\n ans += 1 if switch else 2**(h-1)\r\n r=mid \r\n switch=not switch if latest==\"r\" else switch\r\n latest=\"l\"\r\n else:\r\n ans += 1 if not switch else 2**(h-1)\r\n l=mid+1\r\n switch=not switch if latest==\"l\" else switch\r\n latest=\"r\"\r\n h-=1\r\n\r\n\r\nOut.int(ans)\r\n\r\n######################################\r\n\r\nif len(sys.argv)>2 and sys.argv[2]==\"TIMEIT\":\r\n fin = (time.time()-startTimeProblem)*1000\r\n print(\"{:.2f}\".format(fin) + \"ms\")",
"H,n=map(int,input().split(\" \"))\r\nres=0\r\ns=0\r\nfor h in range(H,0,-1):\r\n res+=1\r\n if s ^ ( n > 1 << (h-1) ):\r\n res+= (1 << h) - 1\r\n else:\r\n s^=1\r\n if n>1<<(h-1):\r\n n-=1<<(h-1)\r\nprint(res)\r\n",
"def call(l,r,d,asf,s):\r\n if l==r:\r\n print(asf)\r\n exit()\r\n mid=(l+r)//2\r\n if s:\r\n if d>mid:\r\n call(mid+1,r,d,r-l+1+asf,True)\r\n else:\r\n call(l,mid,d,1+asf,False)\r\n else:\r\n if d>mid:\r\n call(mid+1,r,d,1+asf,True)\r\n else:\r\n call(l,mid,d,r-l+1+asf,False)\r\n\r\n\r\n\r\n\r\n\r\nh,n=map(int,input().split())\r\na=1<<h\r\ncall(1,1<<h,n,0,True)\r\n \r\n\r\n\r\n\r\n",
"h, n = map(int, input().split())\r\nn = n - 1 + (1 << h)\r\nres = h\r\nfor i in range(1, h+1):\r\n a = n & (1 << i)\r\n b = n & (1 << (i-1))\r\n if not ((a == 0) ^ (b == 0)):\r\n res += (1 << i) - 1\r\nprint(res)\r\n",
"S=input().split()\r\nh=int(S[0]);n=int(S[1])-1\r\nans=0;di=0\r\nwhile h>0:\r\n h=h-1\r\n if (((n>>h)&1)^di)!=0 :\r\n ans=2**(h+1)+ans\r\n #print(1)\r\n else :\r\n ans=ans+1;di=di^1\r\n #print(2)\r\n # print(ans,h)\r\nprint(ans)\r\n",
"h, n = map(int, input().split())\r\ns, k = h, 2\r\nn += (1 << h) - 1\r\nfor i in range(h):\r\n if (n & k) ^ ((n << 1) & k) == 0: s += k - 1\r\n k <<= 1\r\nprint(s)",
"h,n = map(int, input().split())\r\nnth = 1+2*(n-1)\r\ndiv = 1<<(h-1)\r\nc = 1<<h\r\nop = 'L'\r\nopd={'L':'R', 'R':'L'}\r\nvis=0\r\nlv = h+1\r\nwhile c != nth:\r\n if c < nth :# Going Right\r\n if op == 'R' : # If god wants me to go right:\r\n c += div\r\n div = div >> 1\r\n vis += 1\r\n else: # If god wanted to go left:\r\n c += div\r\n div >>= 1\r\n vis += ((1<<(lv-1)))\r\n op='R'\r\n elif c > nth:\r\n if op == 'L':\r\n c -= div\r\n div = div >> 1\r\n vis += 1\r\n else:\r\n c -= div\r\n div = div >> 1\r\n vis += (1<<(lv-1))\r\n op = 'L'\r\n lv-=1\r\n op = opd[op] \r\nprint(vis)",
"import sys\nfrom math import *\nfrom fractions import gcd\nreadints=lambda:map(int, input().strip('\\n').split())\n\nh,n=readints()\n\npath=''\nlo,hi=1,2**h\n\nwhile lo!=hi:\n mid = (lo+hi)//2\n if n<=mid:\n path+='L'\n hi=mid\n else:\n path+='R'\n lo=mid+1\n\n# print(path)\nans=0\ncur='L'\nfor i in range(len(path)):\n ans += 1 # self\n # calculate cost of detour\n if cur!=path[i]:\n ans += (2**(h-i)-1)\n if path[i]=='L':\n cur='R'\n else:\n cur='L'\n # print(i,ans)\n\n\nprint(ans)\n",
"import math\r\nimport sys\r\n\r\nh,n=map(int,sys.stdin.readline().split(\" \"))\r\nsize=(2**(h+1))-1\r\nset={\"\"}\r\nexitGate=2**(h)-1+n-1\r\nset.add(exitGate)\r\ncurr=(exitGate-1)//2\r\nset.add(0)\r\nwhile(curr>0):\r\n set.add(curr)\r\n curr=(curr-1)//2\r\nflag=0\r\ncurr=0\r\nres=0\r\nlevel=h\r\nwhile(curr!=exitGate):\r\n if flag==0:\r\n if curr*2+1 in set:\r\n res+=1\r\n flag=1\r\n curr=2*curr+1\r\n level-=1\r\n continue\r\n else:\r\n res=res+(2**level)\r\n curr=2*curr+2\r\n level-=1\r\n continue\r\n else:\r\n if curr*2+2 in set:\r\n res+=1\r\n flag=0\r\n curr=curr*2+2\r\n level-=1\r\n continue\r\n else:\r\n res=res+(2**level)\r\n curr=curr*2+1\r\n level-=1\r\n continue\r\n \r\nprint(res) \r\n \r\n \r\n ",
"from sys import stdin,stdout\r\nnmbr = lambda: int(input())\r\nlst = lambda: list(map(int, input().split()))\r\ndef fn(s,e,left,dpth):\r\n global ans\r\n if s==e:return\r\n mid=(s+e)>>1\r\n left^=1\r\n nodes=(1<<(h-dpth+1))-1\r\n if s<=n<=mid:\r\n if left==0:\r\n ans+=nodes//2\r\n fn(s,mid,1,dpth+1)\r\n else:\r\n if left==1:\r\n ans+=nodes//2\r\n fn(mid+1,e,0,dpth+1)\r\n\r\nfor _ in range(1):#nmbr()):\r\n h,n=lst()\r\n ans=0\r\n end=(1<<h)\r\n mid=(1+end)//2\r\n if 1<=n<=mid:fn(1,mid,1,1)\r\n else:\r\n ans+=(1<<(h))-1\r\n fn(mid+1,end,0,1)\r\n # fn(1,end,1,0)\r\n print(ans+h)",
"import sys\nimport math\n\nMAXNUM = math.inf\nMINNUM = -1 * math.inf\nASCIILOWER = 97\nASCIIUPPER = 65\n\n\ndef getInt():\n return int(sys.stdin.readline().rstrip())\n\n\ndef getInts():\n return map(int, sys.stdin.readline().rstrip().split(\" \"))\n\n\ndef getString():\n return sys.stdin.readline().rstrip()\n\n\ndef printOutput(ans):\n sys.stdout.write(str(ans) + \"\\n\")\n\n\ndef solve(h, n):\n heightNodes = [1 for _ in range(51)]\n for height in range(1, 51):\n heightNodes[height] = 2 ** height + heightNodes[height - 1]\n\n curPos = 2 ** (h - 1)\n depth = h\n add = 2 ** (h - 1)\n direction = -1\n total = 0 # visited root\n while True:\n if depth == 0:\n break\n if (curPos >= n and direction == -1) or (\n curPos < n and direction == 1\n ): # this means n is to the left\n total += 1\n depth -= 1\n add //= 2\n curPos += direction * (add)\n else:\n total += heightNodes[depth - 1]\n direction *= -1\n\n return total\n\n\ndef readinput():\n h, n = getInts()\n printOutput(solve(h, n))\n\n\nreadinput()\n",
"sl = [0]*51\nsl[0] = 1\nfor i in range(1,51):\n sl[i] = sl[i-1] + (2**i)\n \nh,n = map(int,input().split())\n\nnl = []\nn += sl[h-1]\ntn = n\nnl.append(tn)\nwhile tn != 1:\n tn = tn//2\n nl.append(tn)\n \nans = 0\ncn = 1\ncp = False\n \nwhile cn != n:\n tnl = []\n for i in range(h):\n tnl.append(cn);\n if cp == False:\n cn *= 2\n else:\n cn = cn*2+1\n cp = not cp\n if cn == n:\n ans += h\n break\n \n tnl.append(cn)\n tnl = tnl[::-1]\n for i in range(1,h+1):\n if nl[i] == tnl[i]:\n ans += sl[i-1]+h-i+1\n h=i-1\n cn=tnl[i-1]\n if cn == tnl[i]*2:\n cn = tnl[i]*2+1\n cp = False\n else:\n cn = tnl[i]*2\n cp = True\n break\nprint(ans)\n",
"h,n=map(int,input().split())\r\n\r\nl=1\r\nr=2**h\r\nans=0\r\nlast_dir='r'\r\nfor level in range(h):\r\n mid = (l+r+1)//2\r\n if n < mid:\r\n if last_dir=='r':\r\n ans+=1\r\n else:\r\n ans+=2**(h-level)\r\n r=mid-1\r\n last_dir='l'\r\n else:\r\n if last_dir=='r':\r\n ans+=2**(h-level)\r\n else:\r\n ans+=1\r\n l=mid\r\n last_dir='r'\r\n\r\nprint(ans)\r\n\r\n",
"\n\n\n######################################################################################\n#--------------------------------------code here-------------------------------------#\n######################################################################################\nh, ext = map(int, input().split());\nroot = 0;\ntem = 0;\nlft = True;\n \nwhile(h >= 1):\n h-= 1;\n if(ext > tem and ext <= tem + (pow(2,h))):\n if(lft):\n root += 1;\n lft = not lft;\n else:\n root += (pow(2,h+1));\n else:\n tem += pow(2,h);\n if(not lft):\n root += 1;\n lft = not lft;\n else:\n root += (pow(2,h+1));\n \nprint(f\"{root}\");"
] | {"inputs": ["1 2", "2 3", "3 6", "10 1024", "10 577", "11 550", "19 12783", "28 72803174", "39 457181784666", "12 955", "13 154", "14 2334", "15 15512", "16 21395", "17 80239", "18 153276", "20 589266", "21 1687606", "24 14428281", "29 113463931", "1 1", "3 8", "31 1819651953", "33 2599588275", "38 262402936512", "4 13", "40 615535158153", "42 1042128038474", "45 17519319833295", "46 34999315964173", "49 295606900104348", "50 905353992267944", "3 5", "4 14", "6 40", "7 31", "8 19", "10 359", "11 349", "13 4796", "20 742273", "22 3343393", "24 3543583", "25 678676", "27 109473899", "29 19827102", "8 204", "30 414940886", "32 3786259360", "35 31233562499", "38 99361414961", "9 43", "40 874338951117", "33 2696188969", "35 12080044014", "12 2715", "29 524109003", "50 1", "50 1125899906842624", "50 562949953421312", "50 844424930131968", "50 375299968947542"], "outputs": ["2", "5", "10", "2046", "1345", "408", "503251", "50649698", "830699159852", "2871", "7770", "9440", "14926", "2899", "177237", "328766", "1505684", "3522472", "26969983", "347736449", "1", "14", "3412135549", "1357401405", "519008349260", "27", "1572205271927", "3195908899134", "17381304930499", "34646522010881", "820858833984106", "1871650493613618", "11", "26", "88", "95", "205", "91", "1057", "10298", "1182599", "7009189", "10865127", "31527640", "209022797", "478963048", "422", "372407442", "8003335020", "60951693197", "28342263489", "391", "1800799608767", "505562011", "2415167450", "4185", "1052258991", "1125899906842623", "2251799813685246", "562949953421312", "1407374883553280", "50"]} | UNKNOWN | PYTHON3 | CODEFORCES | 17 | |
322e969544dec25cdee4270be8cac5b7 | Parking Lot | To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.
The parking lot before the office consists of one line of (2*n*<=-<=2) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That's why there are no free spaces on the parking lot ever.
Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly *n* successive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way.
The only line of the input contains one integer *n* (3<=≤<=*n*<=≤<=30) — the amount of successive cars of the same make.
Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way.
Sample Input
3
Sample Output
24 | [
"def binpow(a, b):\r\n res = 1\r\n while b > 0:\r\n if b & 1:\r\n res = res * a\r\n a = a * a\r\n b >>= 1\r\n return res\r\n\r\n\r\ndef ans(n):\r\n return binpow(4,n-3)*(9*n-3)\r\n\r\nn = int(input())\r\n\r\nprint(ans(n))\r\n",
"n=int(input())\r\nC=24*(4**(n-3))+36*(4**(n-4))*(n-3)\r\nC=int(C)\r\nprint(C)\r\n",
"n = int(input())\r\nres = 2*3*4*(4**(n-3)) + (n-3)*4*9*(4**(n-4))\r\nprint(int(res))",
"ans = 0\r\nn = int(input())\r\nans += 4*3*4**(2*n-2-n-1)*2\r\ni = 1\r\nwhile i + n - 1 < 2*n - 3:\r\n ans += 4*3*3*4**(2*n-n-4)\r\n i += 1\r\nprint(ans)",
"def binpow(x, n):\r\n res = 1\r\n while n > 0:\r\n if n & 1:\r\n res = res * x\r\n x = x * x\r\n n >>= 1\r\n return res\r\n\r\nn = int(input())\r\n\r\nprint(2*4*3*binpow(4, n-3) + (n-3)*3*3*binpow(4, n-3))",
"n = int(input())\r\nprint(4**(n-3)*(9*n-3))",
"n = int(input())\r\ndef f(n):\r\n return 6*(4**(n-3) * 4) + (n-3)*9*4**(n-3)\r\nprint(f(n))\r\n",
"def bin_pow(a, b):\r\n res = 1\r\n while b > 0:\r\n if b & 1:\r\n res *= a\r\n a *= a\r\n b >>= 1\r\n return res\r\n\r\n\r\nn = int(input())\r\nLEN = 2*n - 2\r\n \r\nLEFT = 4*3*(bin_pow(4, (LEN-n-1)))\r\nRIGHT = 4*3*(bin_pow(4, (LEN-n-1)))\r\nMID = 4*3*3*(n-3)*(bin_pow(4, (LEN-n-2)))\r\nprint(int(LEFT+RIGHT+MID))",
"n = int(input())\r\nprint(2*4*3*4**(n-3) + (n-3)*9*4**(n-3))",
"def pow(x,n):\r\n if n<=0: return 1\r\n if n==1: return x\r\n if n&1: return x*pow(x*x,n>>1)\r\n return pow(x*x,n>>1)\r\n\r\nn=int(input())\r\n\r\nprint(24*pow(4,n-3)+(n-3)*36*pow(4,n-4))",
"n = int(input())\r\nprint(int(24 * 4 ** (n - 3) + 36 * (n - 3) * 4 ** (n - 4)))",
"def main():\r\n n = int(input())\r\n count = 12 * (2 * 4 ** (n - 3) + 3 * (n - 3) * 4 ** (n - 4))\r\n return int(count)\r\n\r\n\r\nprint(main())\r\n",
"n=int(input())\r\nif(n==3):\r\n print(24)\r\nelse:\r\n r=4*((4**(n-4))*3*3)*(n-3)+4*((4**(n-3))*3)*2\r\n print(r)",
"n = int(input())\r\nLEN = 2*n - 2\r\n\r\nLEFT = 4*3*(4**(LEN-n-1))\r\nRIGHT = 4*3*(4**(LEN-n-1))\r\nMID = 4*3*3*(n-3)*(4**(LEN-n-2))\r\nprint(int(LEFT+RIGHT+MID))",
"n = int(input())\r\nspace = 2 * n - 2\r\nsame = n\r\nresult = 0\r\n\r\ndef binpower(n,p):\r\n result = 1\r\n while p > 0:\r\n if p & 1:\r\n result *= n\r\n n *= n \r\n p >>= 1\r\n return result\r\n\r\n\r\npower = space - same\r\n# print(power,binpower(3,power))\r\npower = binpower(4,n-3)\r\nresult = 6 * power * 4+ (n-3) * power * 9 \r\nprint(result)\r\n\r\n# Write dijistra algorithm \r\n# from sortedcontainers import Sorted",
"import math\r\n\r\nn = int(input())\r\n\r\nprefix = [0] * ((2 * n - 2) - n + 1);\r\n\r\nprefix[0] = 4 * (4 ** ((2 * n - 2) - n - 1)) * 3\r\n\r\nfor i in range(1, len(prefix) - 1):\r\n prefix[i] = 4 * (4 ** ((2 * n - 2) - n - 2)) * 3 * 3\r\n \r\n for j in range(max(0, i - n)):\r\n prefix[i] -= prefix[j]\r\n \r\nprefix[len(prefix) - 1] = 4 * (4 ** ((2 * n - 2) - n - 1)) * 3\r\n\r\nfor j in range(max(0, len(prefix) - n - 1)):\r\n prefix[len(prefix) - 1] -= prefix[j]\r\n \r\nprint(sum(prefix))",
"n = int(input())\r\nm = 2 * (n - 1) - n\r\nans = 0\r\nfor i in range(m + 1):\r\n if (i == 0 or i == m):\r\n ans += 4 * 3 * pow(4, (m - 1))\r\n else:\r\n ans += 4 * 3 * 3 * pow(4, (m - 2))\r\nprint(ans)",
"import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\ndef binpow(x, n):\n res = 1\n while n > 0:\n if n & 1:\n res = res * x\n x = x * x\n n >>= 1\n return res\n\nn = int(input())\n\nprint(2*4*3*binpow(4, n-3) + (n-3)*3*3*binpow(4, n-3))"
] | {"inputs": ["3", "4", "5", "6", "7", "12", "15", "28", "29", "30"], "outputs": ["24", "132", "672", "3264", "15360", "27525120", "2214592512", "280349076803813376", "1161928703861587968", "4809844402031689728"]} | UNKNOWN | PYTHON3 | CODEFORCES | 18 | |
323c38bee176928e348c80e88e4daf6f | Calendar | Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:
Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.
In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.
Look at the sample to understand what borders are included in the aswer.
The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900<=≤<=*yyyy*<=≤<=2038 and yyyy:mm:dd is a legal date).
Print a single integer — the answer to the problem.
Sample Input
1900:01:01
2038:12:31
1996:03:09
1991:11:12
Sample Output
50768
1579
| [
"import datetime\r\nd1=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nd2=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((d2-d1).days))",
"\r\ndef STR(): return list(input())\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef MAP2():return map(float,input().split())\r\ndef LIST(): return list(map(int, input().split()))\r\ndef STRING(): return input()\r\nimport string\r\nimport sys\r\nimport datetime\r\nfrom heapq import heappop , heappush\r\nfrom bisect import *\r\nfrom collections import deque , Counter , defaultdict\r\nfrom math import *\r\nfrom itertools import permutations , accumulate\r\ndx = [-1 , 1 , 0 , 0 ]\r\ndy = [0 , 0 , 1 , - 1]\r\n#visited = [[False for i in range(m)] for j in range(n)]\r\n# primes = [2,11,101,1009,10007,100003,1000003,10000019,102345689]\r\n#sys.stdin = open(r'input.txt' , 'r')\r\n#sys.stdout = open(r'output.txt' , 'w')\r\n#for tt in range(INT()):\r\n#arr.sort(key=lambda x: (-d[x], x)) Sort with Freq\r\n\r\n#Code\r\n\r\ndef leap_year(y):\r\n if (y % 4 == 0 and y % 100 !=0) or (y % 400 == 0 ):\r\n return 366\r\n return 365\r\n\r\n\r\ns1 = input()\r\ns2 = input()\r\nmonths = [31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31, 30 , 31]\r\ny1 , m1 , d1 = '' , '' , ''\r\ny2 , m2 , d2 = '' , '' , ''\r\nfor i in range(4):\r\n y1+=s1[i]\r\n y2+=s2[i]\r\nfor i in range(5 , 7):\r\n m1 += s1[i]\r\n m2 += s2[i]\r\nfor i in range(8 , len(s1)):\r\n d1+=s1[i]\r\n d2+=s2[i]\r\n\r\ny1 , m1 , d1 = int(y1) , int(m1) , int(d1)\r\ny2 , m2 , d2 = int(y2) , int(m2) , int(d2)\r\n\r\nres1 , res2 = d1 , d2\r\nfor i in range(y1):\r\n res1 = res1 + leap_year(i)\r\n\r\nfor i in range(y2):\r\n res2 = res2 + leap_year(i)\r\n\r\nfor i in range(0 , m1 - 1):\r\n res1 += months[i]\r\n if leap_year(y1) == 366 and i == 1 :\r\n res1+=1\r\n\r\nfor i in range(0 , m2-1):\r\n res2 +=months[i]\r\n if leap_year(y2) == 366 and i == 1 :\r\n res2+=1\r\n\r\nprint(abs(res1 - res2))\r\n\r\n",
"import datetime\r\n\r\n\r\nd1 = list(map(int, input().split(':')))\r\nd2 = list(map(int, input().split(':')))\r\n\r\n\r\nd1dt = datetime.date(*d1)\r\nd2dt = datetime.date(*d2)\r\n\r\n\r\n\r\n\r\nres = d2dt - d1dt\r\n\r\nprint(abs(res.days))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"from datetime import date as d;print(abs((d(*map(int,input().split(':')))-d(*map(int,input().split(':')))).days))",
"import datetime\r\nt1 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nt2 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((t2-t1).days))",
"d1 = (list)(map(int , input().split(':')))\r\nd2 = (list)(map(int , input().split(':')))\r\nif d1[0] > d2[0] or (d1[0] == d2[0] and d1[1] > d2[1]) or (d1[0] == d2[0] and d1[1] == d2[1] and d1[2] > d2[2]) : d1 , d2 = d2 , d1\r\nmonth_days = [0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31]\r\nans = 0\r\nwhile d1 != d2 : \r\n ans += 1\r\n if d1[1] != 2 : days = month_days[d1[1]]\r\n else :\r\n days = 28\r\n if d1[0] % 400 == 0 : days += 1\r\n elif d1[0] % 4 == 0 and d1[0] % 100 != 0 : days += 1\r\n if d1[2] < days : d1[2] += 1\r\n else :\r\n d1[2] = 1\r\n d1[1] += 1\r\n if d1[1] == 13 :\r\n d1[1] = 1\r\n d1[0] += 1\r\nprint(ans)",
"# Author: KurtNettle\r\n# Github: https://github.com/KurtNettle\r\n# Created on: 2023-03-27 00:05:24.059+06\r\n#\r\n# Problem: B. Calendar\r\n# Contest: Codeforces - Codeforces Round 183 (Div. 2)\r\n# URL: https://codeforces.com/contest/304/problem/B\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 ms\r\n#\r\n# Powered by CP Editor (https://cpeditor.org)\r\n\r\nimport datetime\r\n\r\nd1 = input()\r\nd2 = input()\r\n\r\nd1 = datetime.datetime.strptime(d1, '%Y:%m:%d')\r\nd2 = datetime.datetime.strptime(d2, '%Y:%m:%d')\r\n\r\nprint(abs(d1-d2).days)",
"# LUOGU_RID: 100927002\nimport datetime\nt1=datetime.datetime.strptime(input(),'%Y:%m:%d')\nt2=datetime.datetime.strptime(input(),'%Y:%m:%d')\nprint(abs((t2-t1).days))",
"from datetime import date\n\ns1=list(map(int,input().split(':')))\ns2=list(map(int,input().split(':')))\na = date(s1[0],s1[1],s1[2])\nb = date(s2[0],s2[1],s2[2])\nx=abs((a-b).days)\nprint(x)\n",
"# /**\r\n# * author: brownfox2k6\r\n# * created: 12/07/2023 15:31:36 Hanoi, Vietnam\r\n# **/\r\n\r\nfrom datetime import date\r\n\r\ndef gd():\r\n y, m, d = map(int, input().split(':'))\r\n return date(y, m, d)\r\n\r\nprint(abs(gd()-gd()).days)",
"from sys import stdin as read\r\nfrom sys import stdout as out\r\n\r\ndef leap_year(y):\r\n if y == 1900:\r\n return False\r\n else:\r\n return y%4 == 0\r\n \r\nmonths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n\r\ndef cur_date(date):\r\n res = 0\r\n y, m, d = date\r\n for i in range(1900, y):\r\n res += 365 + leap_year(i)\r\n for i in range(1, m):\r\n res += months[i]+(i == 2 and leap_year(y))\r\n return res + d\r\n\r\ndate_1 = tuple(map(int, read.readline().split(\":\")))\r\ndate_2 = tuple(map(int, read.readline().split(\":\")))\r\n\r\nif date_2 < date_1:\r\n date_1, date_2 = date_2, date_1\r\nout.write(str(cur_date(date_2)-cur_date(date_1))+\"\\n\")\r\n",
"import datetime\nfrom pprint import pprint\nyear, month, day = (int(i) for i in input().split(':'))\nx = datetime.date(year, month, day)\nyear, month, day = (int(i) for i in input().split(':'))\ny = datetime.date(year, month, day)\npprint(abs(int((x - y).days)))\n",
"import datetime\r\ntime1 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\ntime2 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((time2-time1).days))",
"import re\r\nfrom datetime import date\r\n\r\n\r\nv = [\"a\", \"b\"]\r\nv[0] = input()\r\nv[1] = input()\r\nv.sort()\r\n\r\np = re.compile(r\"(\\d+):(\\d+):(\\d+)\")\r\n\r\nm = re.search(p, v[0])\r\nd1 = date(int(m[1]), int(m[2]), int(m[3]))\r\n\r\nm = re.search(p, v[1])\r\nd2 = date(int(m[1]), int(m[2]), int(m[3]))\r\nprint((d2 - d1).days)\r\n",
"from datetime import date\ny1,m1,d1=map(int,input().split(':'))\ny2,m2,d2=map(int,input().split(':'))\n\na=date(y1,m1,d1)\nb=date(y2,m2,d2)\nprint(abs((b-a).days))\n\n",
"#!/usr/bin/python3\r\n\r\nmonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n\r\ndef isn(yyyy):\r\n if yyyy == 1900:\r\n return False\r\n return yyyy % 4 == 0\r\n\r\ndef toint(date):\r\n yyyy, mm, dd = date\r\n res = 0\r\n for y in range(1900, yyyy):\r\n res += 365 + isn(y)\r\n for m in range(1, mm):\r\n res += month[m] + (m == 2 and isn(yyyy))\r\n return res + dd\r\n\r\nfirst = tuple(map(int, input().strip().split(':')))\r\nlast = tuple(map(int, input().strip().split(':')))\r\nif last < first:\r\n last, first = first, last\r\nprint(toint(last) - toint(first))\r\n",
"days = [\r\n 0,\r\n 31,\r\n 28,\r\n 31,\r\n 30,\r\n 31,\r\n 30,\r\n 31,\r\n 31,\r\n 30,\r\n 31,\r\n 30,\r\n 31\r\n]\r\n\r\nd = []\r\nfor i in range(0,2):\r\n s = input()\r\n year_to = int(s[0:4])\r\n month_to = int(s[5:7])\r\n day_to = int(s[8:10])\r\n\r\n year = 1900\r\n month = 1\r\n day = 1\r\n days_in_month = 31\r\n\r\n num_days = 1\r\n while year != year_to or month != month_to or day != day_to:\r\n # print(year,month,day)\r\n day += 1\r\n num_days += 1\r\n if day > days_in_month:\r\n month += 1\r\n day = 1\r\n if month == 13:\r\n year += 1\r\n month = 1\r\n elif month == 2 and (year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)):\r\n days_in_month = 29\r\n else:\r\n days_in_month = days[month]\r\n d.append(num_days)\r\n\r\nprint(abs(d[0]-d[1]))",
"def f(a,b,c):\r\n if b<3:\r\n a-=1\r\n b+=12\r\n ans=365*a+a//4 - a//100+a//400+(153*b-457)//5+c-306\r\n return ans\r\n\r\ndef days(s,s2):\r\n y=int(s[0]+s[1]+s[2]+s[3])\r\n m=int(s[5]+s[6])\r\n d=int(s[8]+s[9])\r\n y2=int(s2[0]+s2[1]+s2[2]+s2[3])\r\n m2=int(s2[5]+s2[6])\r\n d2=int(s2[8]+s2[9])\r\n #print(str(y) + \" \" + str(m) + \" \" + str(d))\r\n #print(str(y2) + \" \" + str(m2) + \" \" + str(d2))\r\n a=f(y,m,d)\r\n b=f(y2,m2,d2)\r\n ans=abs(a-b)\r\n return ans\r\n\r\ns=input()\r\ns2=input()\r\nprint(days(s,s2))\r\n",
"import datetime as dt\r\na=dt.datetime.strptime(input().replace(':','-'),'%Y-%m-%d')\r\nb=dt.datetime.strptime(input().replace(':','-'),'%Y-%m-%d')\r\nc=a-b\r\nprint(abs(c.days))",
"\r\ndef STR(): return list(input())\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef MAP2():return map(float,input().split())\r\ndef LIST(): return list(map(int, input().split()))\r\ndef STRING(): return input()\r\nimport string\r\nimport sys\r\nimport datetime\r\nfrom heapq import heappop , heappush\r\nfrom bisect import *\r\nfrom collections import deque , Counter , defaultdict\r\nfrom math import *\r\nfrom itertools import permutations , accumulate\r\ndx = [-1 , 1 , 0 , 0 ]\r\ndy = [0 , 0 , 1 , - 1]\r\n#visited = [[False for i in range(m)] for j in range(n)]\r\n# primes = [2,11,101,1009,10007,100003,1000003,10000019,102345689]\r\n#months = [31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31, 30 , 31]\r\n#sys.stdin = open(r'input.txt' , 'r')\r\n#sys.stdout = open(r'output.txt' , 'w')\r\n#for tt in range(INT()):\r\n#arr.sort(key=lambda x: (-d[x], x)) Sort with Freq\r\n\r\n#Code\r\n\r\n\r\ns1 = input()\r\ns2 = input()\r\ny1 , m1 , d1 = '' , '' , ''\r\ny2 , m2 , d2 = '' , '' , ''\r\nfor i in range(4):\r\n y1+=s1[i]\r\n y2+=s2[i]\r\nfor i in range(5 , 7):\r\n m1 += s1[i]\r\n m2 += s2[i]\r\nfor i in range(8 , len(s1)):\r\n d1+=s1[i]\r\n d2+=s2[i]\r\n\r\ny1 , m1 , d1 = int(y1) , int(m1) , int(d1)\r\ny2 , m2 , d2 = int(y2) , int(m2) , int(d2)\r\n\r\n\r\ndt1 = datetime.date(y1 , m1 , d1)\r\ndt2 = datetime.date(y2 , m2 , d2)\r\nprint(abs(dt1 - dt2).days)\r\n\r\n",
"from datetime import date\r\na = date(*map(int,input().split(':')))\r\nb = date(*map(int,input().split(':')))\r\nprint(abs(a-b).days) \r\n",
"import datetime\nt1 = datetime.datetime.strptime(input(), \"%Y:%m:%d\")\nt2 = datetime.datetime.strptime(input(), \"%Y:%m:%d\")\nprint(abs((t2 - t1).days))",
"def ifLeap(year):\r\n\tif(year %100 == 0):\r\n\t\tif(year%400 == 0):\r\n\t\t\treturn True\r\n\telif(year%4 == 0):\r\n\t\treturn True\r\n\treturn False\r\nyear1,month1,day1 = map(int,input().split(':'))\r\nyear2,month2,day2 = map(int,input().split(':'))\r\n\r\nmonth =[]\r\njan = []\r\nfor i in range(1,32):\r\n\tjan.append(i)\r\nmonth.append(jan)\r\nfeb = []\r\nfor i in range(32,61):\r\n\tfeb.append(i)\r\nmonth.append(feb)\r\nmar = []\r\nfor i in range(61,92):\r\n\tmar.append(i)\r\nmonth.append(mar)\r\napr =[]\r\nfor i in range(92,122):\r\n\tapr.append(i)\r\nmonth.append(apr)\r\nmay = []\r\nfor i in range(122,153):\r\n\tmay.append(i)\r\nmonth.append(may)\r\njun = []\r\nfor i in range(153,183):\r\n\tjun.append(i)\r\nmonth.append(jun)\r\njul = []\r\nfor i in range(183,214):\r\n\tjul.append(i)\r\nmonth.append(jul)\r\naug = []\r\nfor i in range(214,245):\r\n\taug.append(i)\r\nmonth.append(aug)\r\nsep =[]\r\nfor i in range(245,275):\r\n\tsep.append(i)\r\nmonth.append(sep)\r\noct = []\r\nfor i in range(275,306):\r\n\toct.append(i)\r\nmonth.append(oct)\r\nnov = []\r\nfor i in range(306,336):\r\n\tnov.append(i)\r\nmonth.append(nov)\r\ndec = []\r\nfor i in range(336,367):\r\n\tdec.append(i)\r\nmonth.append(dec)\r\n\r\nrday1 = month[month1-1][day1-1]\r\nrday2 = month[month2-1][day2-1]\r\n\r\nif(year2 < year1):\r\n\tyear1,year2 = year2,year1\r\n\trday1,rday2 = rday2,rday1\r\nelif(year2 == year1):\r\n\tif(rday2 < rday1):\r\n\t\tyear1,year2 = year2,year1\r\n\t\trday1,rday2 = rday2,rday1\r\ndifday = 0\r\ndifyear = year2 - year1\r\nif(rday2 < rday1):\r\n\tdifday = 366-rday1 + rday2\r\n\tdifyear -= 1\r\nelse :\r\n\tdifday = rday2 - rday1\r\nif(not ifLeap(year1)):\r\n\tif rday1<60 and rday2 > 60 :\r\n\t\tdifday -= 1\r\n\telif(rday1 > rday2 and rday1 <60):\r\n\t\tdifday -= 1\r\nif(not ifLeap(year2)):\r\n\tif(rday2 < rday1 and rday2 > 60):\r\n\t\tdifday -= 1\r\ndifday += difyear * 365\r\nfor i in range(year1+1,year2):\r\n\tif(ifLeap(i)) :\r\n\t\tdifday += 1\r\nprint (difday)\r\n",
"is_leap = {}\r\nfor year in range(1900, 2039):\r\n is_leap[year] = year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)\r\n\r\nDAYS_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n\r\nya, ma, da = map(int, input().split(':'))\r\nyb, mb, db = map(int, input().split(':'))\r\n\r\nif (ya, ma, da) > (yb, mb, db):\r\n ya, ma, da, yb, mb, db = yb, mb, db, ya, ma, da\r\n\r\nans = 0\r\nif ya != yb:\r\n if is_leap[ya]:\r\n DAYS_MONTH[2] += 1\r\n\r\n ans += DAYS_MONTH[ma] - da + 1\r\n\r\n for m in range(ma + 1, 13):\r\n ans += DAYS_MONTH[m]\r\n\r\n if is_leap[ya]:\r\n DAYS_MONTH[2] -= 1\r\n\r\n for y in range(ya + 1, yb):\r\n ans += 366 if is_leap[y] else 365\r\n\r\n ya, ma, da = yb, 1, 1\r\n\r\nif ma != mb:\r\n if is_leap[ya]:\r\n DAYS_MONTH[2] += 1\r\n\r\n ans += DAYS_MONTH[ma] - da + 1\r\n\r\n for m in range(ma + 1, mb):\r\n ans += DAYS_MONTH[m]\r\n\r\n if is_leap[ya]:\r\n DAYS_MONTH[2] -= 1\r\n\r\n ma, da = mb, 1\r\n\r\nif da != db:\r\n ans += db - da\r\n\r\nprint(ans)\r\n",
"from datetime import *\n\nd1 = datetime.strptime(input(), '%Y:%m:%d')\nd2 = datetime.strptime(input(), '%Y:%m:%d')\nprint(abs((d1 - d2).days))",
"import datetime\r\ntry:print(abs(int(str(datetime.date(*map(int,input().split(\":\")))-datetime.date(*map(int,input().split(\":\")))).split()[0])))\r\nexcept: print(0)",
"# LUOGU_RID: 100926659\nimport datetime\nbt=datetime.datetime.strptime(input(),'%Y:%m:%d')\net=datetime.datetime.strptime(input(),'%Y:%m:%d')\nprint(abs((et-bt).days))",
"from datetime import *\n\n# wdnmd UKE\n\nt1 = datetime.strptime(input(), \"%Y:%m:%d\")\nt2 = datetime.strptime(input(), \"%Y:%m:%d\")\n\nprint(abs((t2-t1).days))\n",
"import bisect\r\nimport collections\r\nimport copy\r\nimport enum\r\nimport functools\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport re\r\nimport sys\r\nimport time\r\nimport string\r\nimport datetime\r\nfrom typing import List\r\nsys.setrecursionlimit(3001)\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ns1 = input()\r\ns2 = input()\r\n\r\nd1 = datetime.date(int(s1[:4]), int(s1[5:7]), int(s1[8:10]))\r\nd2 = datetime.date(int(s2[:4]), int(s2[5:7]), int(s2[8:10]))\r\nprint(abs((d1-d2).days))\r\n",
"# from collections import defaultdict,deque,OrderedDict\r\n# from sys import stdin\r\n# import itertools\r\n# import bisect\r\n# from math import sqrt,ceil,floor,gcd,sin,radians\r\n# from sortedcontainers import SortedList\r\n# from functools import reduce\r\n# from typing import *\r\nfrom datetime import date as d\r\n\r\ndef func(put,mapping,unpack):\r\n a,b = put(str),put(str)\r\n print(abs(d(*map(int,a.split(':')))-d(*map(int,b.split(':')))).days)\r\n \r\n\r\ndef init(TestCases=True):\r\n put = lambda s: s(input().strip())\r\n mapping = lambda s: list(map(s,input().split()))\r\n unpack = lambda s: map(s,input().split())\r\n for _ in range(int(input()) if TestCases else 1):\r\n func(put,mapping,unpack)\r\n\r\nif __name__ == '__main__':\r\n init(False)",
"from datetime import date as x\r\nprint(abs((x(*map(int,input().split(':')))-x(*map(int,input().split(':')))).days))\r\n",
"from datetime import datetime\r\nprint(abs(datetime.strptime(input(),\"%Y:%m:%d\")-datetime.strptime(input(),\"%Y:%m:%d\")).days)",
"from collections import Counter\r\nimport string\r\nimport math\r\ndicti={'1':31,'2':28,'3':31,'4':30,'5':31,'6':30,'7':31,'8':31\r\n ,'9':30,'10':31,'11':30,'12':31}\r\ndef array_int():\r\n\r\n return [int(i) for i in input().split()]\r\ndef vary(number_of_variables):\r\n if number_of_variables==1:\r\n return int(input())\r\n if number_of_variables>=2:\r\n return map(int,input().split()) \r\ndef makedict(var):\r\n return dict(Counter(var))\r\nmod=1000000007\r\n\r\nfrom datetime import date\r\nprint(abs((date(*map(int,input().split(':')))-date(*map(int,input().split(':')))).days))\r\n \r\n\r\n\r\n\r\n\r\n\r\n",
"# LUOGU_RID: 111548801\nfrom datetime import datetime\r\nprint(abs((datetime.strptime(input(), '%Y:%m:%d') - datetime.strptime(input(), '%Y:%m:%d')).days))\r\n",
"import datetime\r\ntA = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\ntB = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((tB-tA).days))",
"import math\r\n\r\nfrom datetime import date\r\n\r\ndef main():\r\n\r\n\ta = input().split(':')\r\n\tb = input().split(':')\r\n\r\n\td1 = date(int(a[0]), int(a[1]), int(a[2]))\r\n\td2 = date(int(b[0]), int(b[1]), int(b[2]))\r\n\t\r\n\r\n\tprint(abs((d1 - d2).days))\r\n\r\nmain()\r\n",
"months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n\r\ndef calc(day, month, year):\r\n days = 0\r\n for i in range(1899, year):\r\n if i % 4 != 0:\r\n days += 365\r\n elif i % 100 != 0:\r\n days += 366\r\n elif i % 100 == 0 and i % 400 != 0:\r\n days += 365\r\n elif i % 400 == 0:\r\n days += 366\r\n \r\n for i in range(1, month):\r\n days += months[i]\r\n if i == 2:\r\n if year % 4 != 0:\r\n days += 0\r\n elif year % 100 != 0:\r\n days += 1\r\n elif year % 100 == 0 and i % 400 != 0:\r\n days += 0\r\n elif year % 400 == 0:\r\n days += 1\r\n \r\n days += day\r\n\r\n return days\r\n\r\n\r\ndate1 = input()\r\ndate2 = input()\r\ndate1 = date1.split(\":\")\r\ndate2 = date2.split(\":\")\r\nday1 = int(date1[2])\r\nday2 = int(date2[2])\r\nmonth1 = int(date1[1])\r\nmonth2 = int(date2[1])\r\nyear1 = int(date1[0])\r\nyear2 = int(date2[0])\r\n\r\n\r\ndays1 = calc(day1, month1, year1)\r\ndays2 = calc(day2, month2, year2)\r\n\r\nprint(abs(days1-days2))\r\n\r\n\r\n\r\n",
"from datetime import datetime\r\ndate1 = input()\r\ndate2 = input()\r\ndate_format = '%Y:%m:%d'\r\nstart_date = datetime.strptime(date1, date_format)\r\nend_date = datetime.strptime(date2, date_format)\r\n\r\ndelta = end_date - start_date\r\ndays = delta.days\r\n\r\nprint(abs(days))",
"import datetime\r\na = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nb = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((a-b).days))",
"a = ([int(x) for x in input().split(':')])\r\nb = ([int(x) for x in input().split(':')])\r\n\r\na, b = min(a, b), max(a, b)\r\na.reverse()\r\nb.reverse()\r\n\r\ndef ydays(x):\r\n\tif(x%400==0):\r\n\t\treturn 366\r\n\telif(x%100==0):\r\n\t\treturn 365\r\n\telif(x%4==0):\r\n\t\treturn 366\r\n\telse:\r\n\t\treturn 365\r\n\r\ndef mdays(m, y):\r\n\tif(m==2):\r\n\t\tif(ydays(y)==366):\r\n\t\t\treturn 29\r\n\t\telse:\r\n\t\t\treturn 28\r\n\treturn {1: 31, 3: 31, 4: 30, 5:31, 6: 30, 7:31, 8: 31, 9:30, 10:31, 11:30, 12:31}[m]\r\n\r\n\r\ndef next(a):\r\n\tmd = mdays(a[1], a[2])\r\n\tif(a[0]!=md):\r\n\t\ta[0]+=1\r\n\t\treturn a\r\n\tif(a[1]!=12):\r\n\t\ta[0] = 1\r\n\t\ta[1] += 1\r\n\t\treturn a\r\n\ta[0] = 1\r\n\ta[1] = 1\r\n\ta[2] += 1\r\n\treturn a\r\n\r\nans = 0\r\nwhile(a!=b):\r\n\ta = next(a)\r\n\tans += 1\r\nprint(ans)",
"\r\na = list(map(int, input().split(\":\"))) \r\nb = list(map(int, input().split(\":\")))\r\n\r\nfrom datetime import date\r\nd0 = date(a[0], a[1], a[2])\r\nd1 = date(b[0], b[1], b[2])\r\ndelta = abs(d0 - d1)\r\nprint(delta.days)\r\n\r\n",
"# LUOGU_RID: 127364259\nimport datetime as dt\na=dt.datetime.strptime(input().replace(':','-'),'%Y-%m-%d')\nb=dt.datetime.strptime(input().replace(':','-'),'%Y-%m-%d')\nc=a-b\nprint(abs(c.days))",
"def isLeep(year):\r\n if year % 400 == 0:\r\n return 1;\r\n else:\r\n if year % 4 == 0 and year % 100 != 0:\r\n return 1;\r\n return 0;\r\n \r\ndef cmp(y1, m1, d1, y2, m2, d2):\r\n if y1 > y2:\r\n return 0;\r\n else:\r\n if y1 == y2 and m1 > m2:\r\n return 0;\r\n else:\r\n if y1 == y2 and m1 == m2 and d1 > d2:\r\n return 0;\r\n return 1;\r\n\r\ny1, m1, d1 = map(int, input().split(':'))\r\ny2, m2, d2 = map(int, input().split(':'))\r\n\r\ndays = [31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\r\n\r\nif cmp(y1, m1, d1, y2, m2, d2) == 0:\r\n t = y1; y1 = y2; y2 = t;\r\n t = m1; m1 = m2; m2 = t;\r\n t = d1; d1 = d2; d2 = t;\r\n\r\nres = 0;\r\nwhile True:\r\n res = res + 1;\r\n if y1 == y2 and m1 == m2 and d1 == d2:\r\n break;\r\n d1 = d1 + 1;\r\n if d1 <= days[m1]:\r\n continue;\r\n else:\r\n if d1 == 29:\r\n if isLeep(y1):\r\n continue;\r\n else:\r\n m1 = 3;\r\n d1 = 1;\r\n else:\r\n if d1 == 30:\r\n m1 = 3;\r\n d1 = 1;\r\n else:\r\n if d1 == 31:\r\n m1 = m1 + 1;\r\n d1 = 1;\r\n else:\r\n if d1 == 32:\r\n if m1 == 12:\r\n y1 = y1 + 1;\r\n m1 = 1;\r\n d1 = 1;\r\n else:\r\n m1 = m1 + 1;\r\n d1 = 1;\r\n\r\nprint (res - 1)\r\n \r\n\r\n",
"import datetime\r\na = input()\r\nb = input()\r\nta = datetime.datetime.strptime(a, \"%Y:%m:%d\")\r\ntb = datetime.datetime.strptime(b, \"%Y:%m:%d\")\r\nd = (abs(tb-ta)).total_seconds() / 3600 / 24\r\nprint(round(d))",
"import datetime as dt\r\na=list(map(int,input().split(':')))\r\nb=list(map(int,input().split(':')))\r\ntime1=dt.date(a[0],a[1],a[2])\r\ntime2=dt.date(b[0],b[1],b[2])\r\nprint(abs((time1-time2).days))",
"class Data:\n\tdef __init__(self, dia, mes, ano):\n\t\tself.dia = dia\n\t\tself.mes = mes\n\t\tself.ano = ano\n\t\n\tdef __lt__(self, other):\n\t\tif self.ano == other.ano:\n\t\t\tif self.mes == other.mes:\n\t\t\t\treturn self.dia < other.dia\n\t\t\telse:\n\t\t\t\treturn self.mes < other.mes\n\t\telse:\n\t\t\treturn self.ano < other.ano\n\ndef eh_bissexto(ano):\n\treturn (ano % 4 == 0 and ano % 100 != 0) or (ano % 400 == 0)\n\ndef check_data(dia, mes, ano):\n\tqtd_dias_mes = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n\tif eh_bissexto(ano):\n\t\tqtd_dias_mes[1] = 29\n\tif 1 <= mes <= 12:\n\t\tif 1 <= dia <= qtd_dias_mes[mes-1]:\n\t\t\treturn True\n\treturn False\n\n\nano1, mes1, dia1 = map(int, input().split(':'))\nano2, mes2, dia2 = map(int, input().split(':'))\n\ndatas = [Data(dia1, mes1, ano1), Data(dia2, mes2, ano2)]\ndatas.sort()\n\nd1 = datas[0]\nd2 = datas[1]\n\ndia1 = d1.dia\nmes1 = d1.mes\nano1 = d1.ano\n\ndia2 = d2.dia\nmes2 = d2.mes\nano2 = d2.ano\n\nqtd = 0\n\nwhile ano1 != ano2 or mes1 != mes2 or dia1 != dia2:\n\tqtd += 1\n\tdia1 += 1\n\tif not check_data(dia1, mes1, ano1):\n\t\tdia1 = 1\n\t\tmes1 += 1\n\t\n\tif not check_data(dia1, mes1, ano1):\n\t\tmes1 = 1\n\t\tano1 += 1\n\nprint(qtd)\n",
"import datetime\ntime1 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\ntime2 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nprint(abs((time1-time2).days))",
"import datetime\r\ny,m,d=map(int,input().split(':'))\r\na=datetime.date(y,m,d)\r\ny,m,d=map(int,input().split(':'))\r\nb=datetime.date(y,m,d)\r\nprint(abs(a-b).days)\r\n",
"from datetime import *\r\nR = lambda: datetime(*map(int, input().split(':')))\r\ndate1 = R()\r\ndate2 = R()\r\nprint(abs(date2 - date1).days)",
"import datetime\n\nfdYear, fdMonth, fdDay = list(map(int, input().split(':')))\nsdYear, sdMonth, sdDay = list(map(int, input().split(':')))\n\nfirstDate = datetime.datetime(fdYear, fdMonth, fdDay)\nsecondDate = datetime.datetime(sdYear, sdMonth, sdDay)\n\ndiff = secondDate - firstDate\nprint(abs(diff.days))\n\n# sample inputs\n# 1900:01:01\n# 2038:12:31\n\n# 1996:03:09 \n# 1991:11:12\n\n# sample output\n# 1579\n# 50768",
"y1, m1, d1 = input().split(\":\")\r\ny2, m2, d2 = input().split(\":\")\r\n\r\n\r\nfrom datetime import *\r\n\r\ndate1 = datetime(year=int(y1), month=int(m1), day=int(d1))\r\ndate2 = datetime(year=int(y2), month=int(m2), day=int(d2))\r\n\r\nres = date2 - date1\r\n\r\nprint(abs(res.days))",
"# LUOGU_RID: 127364680\nimport datetime as dt\na=dt.datetime.strptime(input().replace(':','-'),'%Y-%m-%d')\nb=dt.datetime.strptime(input().replace(':','-'),'%Y-%m-%d')\nc=a-b\nprint(abs(c.days))",
"dm = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\ndef leap(y):\r\n return y % 4 == 0 and y != 1900\r\ndef dn(y, m, d):\r\n return d + sum(dm[i] + (i == 2 and leap(y)) for i in range(m))\r\nd = sorted(list(map(int, input().split(':'))) for i in range(2))\r\nif d[0][0] == d[1][0]:\r\n print(dn(*d[1]) - dn(*d[0]))\r\nelse:\r\n print(365 + leap(d[0][0]) - dn(*d[0]) + sum(365 + leap(i) for i in range(d[0][0] + 1, d[1][0])) + dn(*d[1]))",
"# henrytb python water\r\nimport datetime as d\r\nt1 = d.datetime.strptime(input(),\"%Y:%m:%d\")\r\n#zhushi zhushi\r\n'''\r\nqwqwq\r\n\r\nhenrytb!!!\r\n'''\r\nt2 = d.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((t2-t1).days)) #abs QAQ",
"from datetime import date\r\nfrom datetime import timedelta\r\n\r\na = input()\r\na = [int(x) for x in a.split(\":\")]\r\nb = input()\r\nb = [int(x) for x in b.split(\":\")]\r\n\r\nx = date(a[0],a[1],a[2])\r\ny = date(b[0],b[1],b[2])\r\n\r\nif x > y:\r\n x,y = y,x\r\n\r\nans = 0\r\nwhile x != y:\r\n x = x + timedelta(days=1)\r\n ans+=1\r\nprint(ans)\r\n\r\n",
"from array import array\r\nfrom sys import stdin ,stdout \r\ninput=stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n stdout.write(sep.join(map(str, args)) + end)\r\n\r\ndate1=list(map(int,input().split(\":\"))) ; date2=list(map(int,input().split(\":\"))) ; s31=[1,3,5,7,8,10,12] ; ans=0\r\nif date2<date1:\r\n date1,date2=date2,date1\r\nwhile date1 < date2:\r\n year,month,day=date1\r\n syear,smonth,sday=list(map(str,date1))\r\n if syear[-1]==\"0\" and syear[-2]==\"0\" and syear[-3]!=\"0\" or year%4!=0:\r\n if month==2:\r\n if day==28:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n elif month in s31:\r\n if month==12:\r\n if day==31:\r\n ans+=1\r\n day=1\r\n month=1\r\n year+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n else:\r\n if day==31:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n else:\r\n if day==30:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n\r\n elif year%4==0:\r\n if month==2:\r\n if day==29:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n elif month in s31:\r\n if month==12:\r\n if day==31:\r\n ans+=1\r\n day=1\r\n month=1\r\n year+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n else:\r\n if day==31:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n else:\r\n if day==30:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1 \r\n else:\r\n if month==2:\r\n if day==28:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n elif month in s31:\r\n if month==12:\r\n if day==31:\r\n ans+=1\r\n day=1\r\n month=1\r\n year+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n else:\r\n if day==31:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n else:\r\n if day==30:\r\n ans+=1\r\n day=1\r\n month+=1\r\n else:\r\n ans+=1\r\n day+=1\r\n date1=[year,month,day]\r\n\r\n\r\nprint(ans)\r\n\r\n",
"import datetime\nd1=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nd2=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nprint(abs((d2-d1).days))",
"leap=[]\r\nfor i in range(1900 ,2039):\r\n if i%4==0 and i%100!=0:\r\n leap.append(i)\r\n elif i%4==0 and i%100==0 and i%400==0:\r\n leap.append(i)\r\n#print(leap)\r\nd1=[1900,1,1]\r\nd2=[2038,12,31]\r\ndate=[]\r\ndate.append(d1[:])\r\nmon=[0,1,2,1,0,1,0,1,1,0,1,0,1]\r\nt=0\r\nwhile d1!=d2:\r\n d1[2]+=1\r\n if d1[2]==30 and d1[0] in leap and mon[d1[1]]==2:\r\n d1[1]+=1\r\n d1[2]=1 \r\n elif d1[2]==29 and mon[d1[1]==2] and d1[0] not in leap:\r\n d1[1]+=1\r\n d1[2]=1 \r\n elif d1[2]==32 and mon[d1[1]]==1:\r\n if d1[1]!=12:\r\n d1[1]+=1\r\n d1[2]=1\r\n else:\r\n d1[0]+=1\r\n d1[1]=1\r\n d1[2]=1 \r\n elif d1[2]==31 and mon[d1[1]]==0:\r\n d1[2]=1\r\n d1[1]+=1\r\n date.append(d1[:])\r\n# print(date) \r\n#print(date[-1],len(date))\r\ndt1 = list(map(int,input().split(':')))\r\ndt2 = list(map(int,input().split(':')))\r\n#print(dt1,dt2)\r\nprint(abs(date.index(dt2)-date.index(dt1)))\r\n",
"from datetime import datetime\r\n\r\ndate1 = input().strip()\r\ndate2 = input().strip()\r\n\r\nformat_str = \"%Y:%m:%d\"\r\ndt1 = datetime.strptime(date1, format_str)\r\ndt2 = datetime.strptime(date2, format_str)\r\n\r\ndiff = abs((dt2 - dt1).days)\r\n\r\nprint(diff)\r\n",
"'''\r\n Auther: ghoshashis545 Ashis Ghosh\r\n college: jalpaiguri Govt Enggineering College\r\n Date:07/03/2020\r\n'''\r\nfrom math import ceil,sqrt,gcd,log,floor\r\nfrom collections import deque\r\ndef ii(): return int(input())\r\ndef si(): return input()\r\ndef mi(): return map(int,input().strip().split(\":\"))\r\ndef li(): return list(mi())\r\ndef msi(): return map(str,input().strip().split(\" \"))\r\ndef lsi(): return list(msi())\r\n#for _ in range(ii()):\r\n\r\nmonth=[31,28,31,30,31,30,31,31,30,31,30,31]\r\ndef Date_calculation(d1,m1,y1):\r\n c1=0\r\n for i in range(1900,y1):\r\n if(i%400==0 or (i%4==0 and i%100!=0)):\r\n c1+=366\r\n else:\r\n c1+=365\r\n f=0\r\n if(y1%400==0 or (y1%4==0 and y1%100!=0)):\r\n f=1\r\n for i in range(1,m1):\r\n if(i==2):\r\n if(f==1):\r\n c1+=29\r\n else:\r\n c1+=28\r\n continue\r\n c1+=month[i-1]\r\n c1+=d1\r\n return c1\r\n\r\ny1,m1,d1=mi()\r\ny2,m2,d2=mi()\r\nc1=Date_calculation(d1,m1,y1)\r\nc2=Date_calculation(d2,m2,y2)\r\nprint(abs(c2-c1))",
"import datetime\r\nx=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\ny=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((x-y).days))",
"#!/usr/local/bin/python3.3 -tt\n\nimport datetime\nimport sys\n\n\nif __name__ == '__main__':\n for l in sys.stdin:\n a = tuple(int(i) for i in l.strip().split(':'))\n s = datetime.date(*a)\n break\n\n for l in sys.stdin:\n a = tuple(int(i) for i in l.strip().split(':'))\n e = datetime.date(*a)\n break\n\n print(abs((e - s).days))\n",
"from datetime import date\r\n\r\nd1 = list(map(int, input().split(':')))\r\nd2 = list(map(int, input().split(\":\")))\r\n\r\ndate1 = date(*d1)\r\ndate2 = date(*d2)\r\n\r\nres =abs( date2 - date1)\r\nprint(res.days)\r\n\r\n\r\n\r\n\r\n\r\n# import calendar\r\n# leap_years = 0\r\n# for i in range(1900, 2039):\r\n# if(calendar.isleap(i)):\r\n# leap_years +=1\r\n",
"import datetime\na=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nb=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nprint(abs((b-a).days))",
"from datetime import datetime\r\n\r\n\r\nd1 = input()\r\nd2 = input()\r\n\r\ndate1 = datetime.strptime(d1,\"%Y:%m:%d\")\r\ndate2 = datetime.strptime(d2,\"%Y:%m:%d\")\r\n\r\nprint(abs(date1-date2).days)",
"from datetime import date\r\na = [int(x) for x in input().split(\":\")]\r\nb = [int(x) for x in input().split(\":\")]\r\nx = date(a[0], a[1], a[2])\r\ny = date(b[0], b[1], b[2])\r\nz = x - y\r\nprint(abs(z.days))",
"\nfrom datetime import datetime\ny,m,d = map(int,input().split(':'))\na = datetime(y,m,d)\ny,m,d = map(int,input().split(':'))\nb = datetime(y,m,d)\nprint(abs((b-a).days))\n",
"from datetime import date\r\ny1,m1,d1=map(int,input().split(':'))\r\ny2,m2,d2=map(int,input().split(':'))\r\na=date(y1,m1,d1)\r\nb=date(y2,m2,d2)\r\nprint(abs((b-a).days))",
"import datetime\r\nprint(abs((datetime.datetime.strptime(input(),\"%Y:%m:%d\")-datetime.datetime.strptime(input(),\"%Y:%m:%d\")).days))\r\n",
"import datetime\r\nt1 = datetime.datetime.strptime(input(), \"%Y:%m:%d\")\r\nt2 = datetime.datetime.strptime(input(), \"%Y:%m:%d\")\r\nprint(abs((t2- t1).days))",
"print(abs((__import__('datetime').datetime.strptime(input(),\"%Y:%m:%d\")-__import__('datetime').datetime.strptime(input(),\"%Y:%m:%d\")).days))",
"from datetime import date\r\na, b, c = input().split(':')\r\nd, e, f = input().split(':')\r\na = int(a)\r\nb = int(b)\r\nc = int(c)\r\nd = int(d)\r\ne = int(e)\r\nf = int(f)\r\ng = date(a, b, c)\r\nh = date(d, e, f)\r\nif g > h:\r\n g, h = h, g\r\nn = h - g\r\nn = n.days\r\nprint(n)",
"first = list(map(int, input().split(':')))\nsecond = list(map(int, input().split(':')))\ndays_each_month_in_normal_year = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\ndays_each_month_in_leap_year = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n\n\nstart = []\nend = []\nif first[0] > second[0]:\n start = second\n end = first\nelif first[0] < second[0]:\n start = first\n end = second\nelse:\n if first[1] > second[1]:\n start = second\n end = first\n elif first[1] < second[1]:\n start = first\n end = second\n else:\n if first[2] > second[2]:\n start = second\n end = first\n else:\n start = first\n end = second\n\ndays = 0\nfor i in range(start[0], end[0] + 1):\n if i % 4 == 0:\n if i == 1900:\n days += 365\n else:\n days += 366\n else:\n days += 365\n\ndays_have_passed_first = start[2]\nif end[0] % 4 == 0 and end[0] != 1900:\n days_still_remains_second = days_each_month_in_leap_year[(end[1] - 1)] - end[2]\nelse:\n days_still_remains_second = days_each_month_in_normal_year[(end[1] - 1)] - end[2]\n\n\nfor j in range(start[1] - 1):\n if start[0] % 4 == 0 and start[0] != 1900:\n days_have_passed_first += days_each_month_in_leap_year[j]\n else:\n days_have_passed_first += days_each_month_in_normal_year[j]\n\nfor k in range(11, end[1] - 1, -1):\n if end[0] % 4 == 0 and end[0] != 1900:\n days_have_passed_first += days_each_month_in_leap_year[k]\n else:\n days_have_passed_first += days_each_month_in_normal_year[k]\n\nprint(days - days_have_passed_first - days_still_remains_second)\n\n",
"# LUOGU_RID: 100927090\nimport datetime\nq1111=datetime.datetime.strptime(input(),'%Y:%m:%d')\nw1111=datetime.datetime.strptime(input(),'%Y:%m:%d')\nprint(abs((w1111-q1111).days))",
"from datetime import date\r\n\r\na1 = [int(i) for i in input().split(':')]\r\na2 = [int(i) for i in input().split(':')]\r\n\r\nprint(abs((date(a1[0], a1[1], a1[2]) - date(a2[0], a2[1], a2[2])).days))\r\n",
"import datetime\na = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nb = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nprint(abs((b-a).days))",
"import datetime\r\n\r\nt1 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\n\r\nt2 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\n\r\nprint(abs((t2-t1).days))",
"import datetime\r\na, b, c = map(int, input().split(':'))\r\nd1 = datetime.date(a, b, c)\r\na, b, c = map(int, input().split(':'))\r\nd2 = datetime.date(a, b, c)\r\nd3 = abs(d2 - d1)\r\nprint(d3.days)\r\n",
"from datetime import date,timedelta\nimport sys\n\ndef get_input ():\n return map (int,input().split(':'))\n\nsy,sm,sd = get_input()\ney,em,ed = get_input()\n\n#start = date (sy,sm,sd)\n#end = date (ey,em,ed)\n\nend = date (sy,sm,sd)\nstart = date (ey,em,ed)\n\nprint (abs((end-start).days))\n",
"import datetime\r\na=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nb=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((b-a).days))",
"# LUOGU_RID: 121045798\nimport datetime\nkkksc03 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nAKIOI = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nprint(abs((AKIOI-kkksc03).days))\n",
"import datetime\r\nt1=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nt2=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((t2-t1).days))",
"import datetime\r\n_a = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\n_b = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint (abs((_a-_b).days))",
"import datetime\r\n\r\nkkk = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\ncz = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\n\r\nprint(abs((cz-kkk).days))",
"def s():\n import datetime\n dt = datetime.datetime\n print(abs((dt(*list(map(int,input().split(':'))))-dt(*list(map(int,input().split(':'))))).days))\ns()\n",
"import datetime\nt1 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nt2 = datetime.datetime.strptime(input(),\"%Y:%m:%d\")\nprint(abs((t2-t1).days))\n\t \t \t \t \t \t \t\t\t \t\t\t \t \t",
"import datetime\r\ny1, m1, d1 = map(int, input().split(\":\"))\r\ndate_1 = datetime.date(y1, m1, d1)\r\ny2, m2, d2 = map(int, input().split(\":\"))\r\ndate_2 = datetime.date(y2, m2, d2)\r\n\r\nprint((abs(date_2-date_1)).days)\r\n\r\n\"\"\"\r\ndef leap_year(x, y):\r\n d = 0\r\n for i in range(x, y+1):\r\n if (i%4 == 0 and i % 100 != 0) or (i%400 == 0):\r\n d += 366\r\n else:\r\n d += 365\r\n return d\r\nd = leap_year(y1, y2)\r\nd += (m2-m1)*30 + (d2-d1)\r\nprint(d)\r\n\"\"\"\r\n",
"def is_leap_year(year):\r\n if year % 4 != 0:\r\n return False\r\n elif year % 100 != 0:\r\n return True\r\n elif year % 400 != 0:\r\n return False\r\n else:\r\n return True\r\n\r\ndef count_days(date1, date2):\r\n year1, month1, day1 = map(int, date1.split(':'))\r\n year2, month2, day2 = map(int, date2.split(':'))\r\n\r\n month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\r\n\r\n total_days1 = (year1 - 1) * 365 + (year1 - 1) // 4 - (year1 - 1) // 100 + (year1 - 1) // 400\r\n for i in range(month1 - 1):\r\n total_days1 += month_days[i]\r\n if month1 > 2 and is_leap_year(year1):\r\n total_days1 += 1\r\n total_days1 += day1\r\n\r\n total_days2 = (year2 - 1) * 365 + (year2 - 1) // 4 - (year2 - 1) // 100 + (year2 - 1) // 400\r\n for i in range(month2 - 1):\r\n total_days2 += month_days[i]\r\n if month2 > 2 and is_leap_year(year2):\r\n total_days2 += 1\r\n total_days2 += day2\r\n\r\n diff = abs(total_days2 - total_days1)\r\n\r\n return diff\r\n\r\ndate1 = input().strip()\r\ndate2 = input().strip()\r\n\r\nprint(count_days(date1, date2))\r\n",
"import datetime\r\nfirsttime=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nlasttime=datetime.datetime.strptime(input(),\"%Y:%m:%d\")\r\nprint(abs((lasttime-firsttime).days))",
"import sys\nimport datetime\n\ny1, m1, d1 = map(int, input().split(':'))\ny2, m2, d2 = map(int, input().split(':'))\n\nprint(abs((datetime.date(y1, m1, d1) - datetime.date(y2, m2, d2)).days))\n"
] | {"inputs": ["1900:01:01\n2038:12:31", "1996:03:09\n1991:11:12", "1999:12:31\n2000:02:29", "1903:09:27\n1988:06:15", "1913:11:14\n1901:05:11", "1915:01:01\n2007:07:01", "1925:07:15\n2010:06:22", "1935:10:08\n1923:01:07", "1986:08:24\n1926:04:13", "1932:11:18\n2028:09:25", "1942:06:04\n1982:12:29", "1993:08:25\n1985:02:16", "1954:06:30\n1911:05:04", "2005:08:01\n1963:08:23", "2015:10:17\n1966:07:12", "2025:08:10\n2018:09:03", "2027:07:31\n1945:04:06", "2037:05:16\n1996:03:11", "1949:07:09\n1901:10:24", "2028:04:11\n1931:09:01", "1900:02:06\n1997:12:07", "1902:09:06\n1951:03:31", "1912:03:09\n1954:06:17", "1963:05:02\n2005:08:02", "1973:03:18\n1932:11:07", "1934:01:09\n1935:02:22", "1985:08:24\n1987:05:01", "1995:06:03\n1990:07:22", "1907:04:04\n1902:10:01", "1910:01:11\n1987:02:08", "1996:03:09\n1996:03:09", "1900:03:02\n2038:03:01", "2000:01:02\n2000:02:02", "1999:04:08\n1999:02:04", "1999:01:01\n1999:01:10", "2012:05:29\n2012:02:29", "1900:01:01\n1900:01:01", "1996:02:01\n1996:01:27", "1901:12:31\n1901:12:31", "2000:02:28\n2000:02:28"], "outputs": ["50768", "1579", "60", "30943", "4570", "33784", "31023", "4657", "22048", "35010", "14818", "3112", "15763", "15319", "17994", "2533", "30066", "15041", "17425", "35287", "35733", "17738", "15440", "15433", "14741", "409", "615", "1777", "1646", "28152", "0", "50403", "31", "63", "9", "90", "0", "5", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 90 | |
324634a6d5274599dbfc95cf907a3d09 | Bus Game | After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus.
- Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen coins. - They take turns alternatively. Ciel takes the first turn. - In each turn, they must take exactly 220 yen from the pile. In Ciel's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 100-yen coins. In Hanako's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 10-yen coins. - If Ciel or Hanako can't take exactly 220 yen from the pile, she loses.
Determine the winner of the game.
The first line contains two integers *x* (0<=≤<=*x*<=≤<=106) and *y* (0<=≤<=*y*<=≤<=106), separated by a single space.
If Ciel wins, print "Ciel". Otherwise, print "Hanako".
Sample Input
2 2
3 22
Sample Output
Ciel
Hanako
| [
"import sys\r\nimport string\r\n\r\nfrom collections import Counter, defaultdict\r\nfrom math import fsum, sqrt, gcd, ceil, factorial\r\nfrom operator import add\r\nfrom itertools import accumulate\r\n\r\ninf = float('inf')\r\n# input = sys.stdin.readline\r\nflush = lambda : sys.stdout.flush\r\ncomb = lambda x , y : (factorial(x) // factorial(y)) // factorial(x - y) \r\n\r\n\r\n#inputs\r\n# ip = lambda : input().rstrip()\r\nip = lambda : input()\r\nii = lambda : int(input())\r\nr = lambda : map(int, input().split())\r\nrr = lambda : list(r())\r\n\r\n\r\na , b =r()\r\nc = 1\r\n\r\nwhile a or b:\r\n x = 220\r\n while a and x>=100:\r\n a-=1\r\n x-=100\r\n while b and x:\r\n b-=1\r\n x-=10\r\n \r\n if c%2==0:\r\n if b>9:\r\n a+=1\r\n b-=10\r\n if b>9:\r\n a+=1\r\n b-=10\r\n \r\n if x:\r\n print(\"Hanako\" if c%2 else \"Ciel\")\r\n exit() \r\n c+=1\r\n \r\n\r\nprint(\"Hanako\" if c%2 else \"Ciel\")\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n",
"x,y = map(int, input().split())\r\nn = ['Ciel','Hanako']\r\nwhile True:\r\n if x>=2 and y>=2:\r\n x,y = x-2,y-2\r\n elif x>=1 and y>=12:\r\n x,y = x-1,y-12\r\n elif x>=0 and y>=22:\r\n x,y = x,y-22\r\n else:\r\n s = 1\r\n break\r\n if x>=0 and y>=22:\r\n x,y = x,y-22\r\n elif x>=1 and y>=12:\r\n x,y = x-1,y-12\r\n elif x>=2 and y>=2:\r\n x,y = x-2,y-2\r\n else:\r\n s = 0\r\n break\r\nprint(n[s])",
"x, y = map(int, input().split())\r\n\r\nc = min(x // 2, y // 24)\r\nx -= 2 * c\r\ny -= 24 * c\r\n\r\nc = min(x // 3, y // 14)\r\nx -= 3 * c\r\ny -= 14 * c\r\n\r\nc = min(x // 4, y // 4)\r\nx -= 4 * c\r\ny -= 4 * c\r\n\r\nc = min(x, y // 34)\r\nx -= 1 * c\r\ny -= 34 * c\r\n\r\nc = y // 44\r\ny -= 44 * c\r\n\r\nif y >= 2 and 10 * x + y >= 22:\r\n print('Ciel')\r\nelse:\r\n print('Hanako')",
"x,y=map(int,input(\"\").split())\r\nc=0\r\ni=0\r\nwhile(c==0):\r\n if i%2==0:\r\n if x>=2:\r\n x=x-2\r\n if y>=2:\r\n y=y-2\r\n else:\r\n break\r\n elif x<2:\r\n s=(220-(x*100))//10\r\n if y>=s:\r\n y=y-s\r\n else:\r\n break\r\n else:\r\n if y>=22:\r\n y=y-22\r\n elif y<22 and y>=12:\r\n y=y-12\r\n if x>=1:\r\n x=x-1\r\n else:\r\n break\r\n elif y<12 and y>=2:\r\n y=y-2\r\n if x>=2:\r\n x=x-2\r\n \r\n else:\r\n break\r\n else:\r\n break\r\n\r\n \r\n i+=1\r\nif i%2==0:\r\n print(\"Hanako\")\r\nelse:\r\n print(\"Ciel\")\r\n\r\n",
"\r\nn = input().split()\r\nx = int(n[0])\r\ny = int(n[1])\r\nt = 0\r\na = [0]*2\r\na[0] = \"Ciel\"\r\na[1] = \"Hanako\"\r\nwhile True:\r\n if t % 2==0:\r\n if y >=2:\r\n if x >= 2:\r\n x -=2\r\n y -=2\r\n elif x == 1 and y >= 12:\r\n x -=1\r\n y -= 12\r\n elif x ==0 and y >= 22:\r\n y -= 22\r\n else:\r\n break\r\n else:\r\n break\r\n else:\r\n if y >= 22:\r\n y -=22\r\n elif y >= 12 and x >= 1:\r\n y -= 12\r\n x -= 1\r\n elif y >= 2 and x >=2:\r\n y -=2\r\n x -=2\r\n else:\r\n break\r\n t +=1\r\nres = a[(t+1)%2]\r\nprint(res)\r\n \r\n",
"x,y=list(map(int,input().split()))\r\ncnt=0\r\nwhile True:\r\n if cnt%2==0:\r\n if x>=2 and y>=2:\r\n num_100=2\r\n elif y>=22:\r\n num_100=0\r\n elif x>=1 and y>=12:\r\n num_100=1\r\n else:\r\n break\r\n num_10=(220-100*num_100)//10\r\n x-=num_100\r\n y-=num_10\r\n else:\r\n if y>=22:\r\n num_10=22\r\n elif y>=12 and x>=1:\r\n num_10=12\r\n elif y>=2 and x>=2:\r\n num_10=2\r\n else:\r\n break\r\n num_100=(220-10*num_10)//100\r\n x-=num_100\r\n y-=num_10\r\n cnt+=1\r\nif cnt%2==0:\r\n print(\"Hanako\")\r\nelse:\r\n print(\"Ciel\")",
"s = input().split()\r\n\r\nx = int(s[0])\r\ny = int(s[1])\r\nis_odd = False\r\nwhile ((x >= 2) or ((x >= 1) and (y >= 12)) or (y >= 22)):\r\n if not(is_odd):\r\n if (x >= 2) and (y >= 2):\r\n x -= 2\r\n y -= 2\r\n elif (x >= 1) and (y >= 12):\r\n x -= 1\r\n y -= 12\r\n elif (y >= 22):\r\n y -= 22\r\n else:\r\n break\r\n else:\r\n if y >= 22:\r\n y -= 22\r\n elif ((y >= 12) and (x >= 1)):\r\n y -= 12\r\n x -= 1\r\n elif ((x >= 2) and (y >= 2)):\r\n x -= 2\r\n y -= 2\r\n else:\r\n break\r\n\r\n is_odd = (not(is_odd))\r\nif (is_odd):\r\n print(\"Ciel\")\r\nelse:\r\n print(\"Hanako\")",
"def main():\r\n x, y = map(int, input().split())\r\n turns = min(x // 2, y // 24)\r\n x -= 2 * turns\r\n y -= 24 * turns\r\n\r\n while True:\r\n if x >= 2 and y >= 2:\r\n x -= 2\r\n y -= 2\r\n elif x >= 1 and y >= 12:\r\n x -= 1\r\n y -= 12\r\n elif y >= 22:\r\n y -= 22\r\n else:\r\n print(\"Hanako\")\r\n break\r\n\r\n if y >= 22:\r\n y -= 22\r\n elif x >= 1 and y >= 12:\r\n x -= 1\r\n y -= 12\r\n elif x >= 2 and y >= 2:\r\n x -= 2\r\n y -= 2\r\n else:\r\n print(\"Ciel\")\r\n break\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"'''\r\n\n13.07.2021\r\n\r\n\n\nCF 071 A\r\n\n'''\n\n\r\n\r\ns = (input ()).split ()\r\n\nx = int (s [0])\n\r\ny = int (s [1])\r\n\n\r\n\n\ngo = 0\r\n\nwhile x*10 + y >= 22 :\r\n\n if go == 0 :\n\r\n if x >= 2 and y >= 2 :\r\n\n x -= 2; y -= 2\n\r\n elif x == 1 and y >= 12 :\r\n\n x -= 1; y -= 12\n\r\n elif x == 0 and y >= 22 :\r\n\n y -= 22\n\r\n else :\n\r\n break\r\n\n else :\n\r\n if y >= 22 :\r\n\n y -= 22\n\r\n elif x >= 1 and y >= 12 :\r\n\n x -= 1; y -= 12\n\r\n elif x >= 2 and y >= 2 :\r\n\n x -= 2; y -= 2\n\r\n else :\n\r\n break\r\n\n go = 1 - go\r\n\r\n\n\nif go == 0 :\r\n\n print (\"Hanako\")\r\n\nelse :\n\r\n print (\"Ciel\")\n",
"x,y=map(int,input().split())\r\nwhile(True):\r\n if x>=2 and y>=2:\r\n x=x-2\r\n y=y-2\r\n elif y>=22:\r\n y=y-22\r\n elif x>=1 and y>=12:\r\n x=x-1\r\n y=y-12\r\n else:\r\n print(\"Hanako\")\r\n break\r\n if y>=22:\r\n y=y-22\r\n elif x>=1 and y>=12:\r\n x=x-1\r\n y=y-12\r\n\r\n elif x>=2 and y>=2:\r\n x=x-2\r\n y=y-2\r\n else:\r\n print(\"Ciel\")\r\n break\r\n \r\n \r\n \r\n ",
"x, y = list(map(int, input().split()))\r\nf = 1\r\nwhile (True):\r\n if f == 1:\r\n if x >= 2 and y >= 2: x -= 2; y -= 2\r\n elif x >= 1 and y >= 12: x -= 1; y -= 12\r\n elif y >= 22: y -= 22\r\n else:\r\n print(\"Hanako\")\r\n break\r\n else:\r\n if y >= 22: y -= 22\r\n elif y >= 12 and x >= 1: y -= 12; x -= 1\r\n elif y >= 2 and x >= 2: y -= 2; x -= 2\r\n else:\r\n print(\"Ciel\")\r\n break\r\n f *= -1",
"x,y=map(int,input().split())\r\nt=0\r\nwhile True:\r\n if t%2==0:\r\n if x>=2 and y>=2:\r\n x-=2;y-=2\r\n elif x==1 and y>=12:\r\n x-=1;y-=12\r\n elif x==0 and y>=22:\r\n y-=22\r\n else:exit(print('Hanako'))\r\n else:\r\n if y>=22:\r\n y-=22\r\n elif x>=1 and y>=12:\r\n y-=12;x-=1\r\n elif x>=2 and y>=2:\r\n x-=2;y-=2\r\n else:exit(print('Ciel'))\r\n t+=1",
"x,y=map(int,input().rstrip().split());flag=0\r\nwhile(x*10+y>21 and y>1):\r\n if not flag:\r\n if(x>1):x-=2;y-=2\r\n elif(x):x-=1;y-=12\r\n else: y-=22\r\n else :\r\n if(y>21):y-=22\r\n elif(y>11):x-=1;y-=12;\r\n else: x-=2;y-=2\r\n flag= not flag\r\nif flag:print(\"Ciel\")\r\nelse:print(\"Hanako\")",
"inp1, inp2 = [int(i) for i in input().split()]\r\nhundred = 100 * inp1\r\nten = 10 * inp2\r\nlista = [\"Ciel\", \"Hanako\"] * 1000000\r\n\r\nfor i in range(len(lista)):\r\n if i % 2 == 0:\r\n if (hundred >= 200 and ten >= 20):\r\n hundred = hundred - 200\r\n ten = ten - 20\r\n elif (hundred >= 100 and ten >= 120):\r\n hundred = hundred - 100\r\n ten = ten - 120\r\n elif (hundred == 0 and ten >= 220):\r\n ten = ten - 220\r\n else:\r\n print(\"Hanako\")\r\n exit()\r\n else:\r\n if (ten >= 220):\r\n ten = ten - 220\r\n elif (ten >= 120 and hundred >= 100):\r\n ten = ten - 120\r\n hundred = hundred - 100\r\n elif (ten >= 20 and hundred >= 200):\r\n ten = ten - 20\r\n hundred = hundred - 200\r\n else:\r\n print(\"Ciel\")\r\n exit()\r\n",
"import sys\r\nimport math\r\n \r\nx, y = [int(x) for x in (sys.stdin.readline()).split()]\r\n \r\nwhile(1):\r\n if(x >= 2 and y >= 2):\r\n x -= 2\r\n y -= 2\r\n elif(x >= 1 and y >= 12):\r\n x -= 1\r\n y -= 1\r\n elif(x == 0 and y >= 22):\r\n y -= 22\r\n else:\r\n print(\"Hanako\")\r\n exit()\r\n \r\n if(y >= 22):\r\n y -= 22\r\n elif(x >= 1 and y >= 12):\r\n x -= 1\r\n y -= 12\r\n elif(x >= 2 and y >= 2):\r\n x -= 2\r\n y -= 2\r\n else:\r\n print(\"Ciel\")\r\n exit()\r\n ",
"# LUOGU_RID: 104833348\nn, m = map(int, input().split())\r\nfor x, y in ((2, 24), (3, 14), (4, 4), (1, 32)):\r\n t = min(n // x, m // y)\r\n n -= x * t\r\n m -= y * t\r\nm -= m // 44 * 44\r\nprint(m >= 2 and 10 * n + m >= 22 and 'Ciel' or 'Hanako')\r\n",
"def determine_winner(x, y):\n while True:\n # Ciel's turn\n if x >= 2 and y >= 2:\n x -= 2\n y -= 2\n elif x >= 1 and y >= 12:\n x -= 1\n y -= 12\n elif y >= 22:\n y -= 22\n else:\n return \"Hanako\"\n\n # Hanako's turn\n if y >= 22:\n y -= 22\n elif x >= 1 and y >= 12:\n x -= 1\n y -= 12\n elif x >= 2 and y >= 2:\n x -= 2\n y -= 2\n else:\n return \"Ciel\"\n\n\nx, y = map(int, input().split())\nwinner = determine_winner(x, y)\nprint(winner)\n",
"def busgame():\r\n x, y = map(int, input().split())\r\n turn = True\r\n while True:\r\n if y < 2:\r\n break\r\n y -= 2\r\n\r\n if turn:\r\n if x >= 2:\r\n x -= 2\r\n elif x >= 1 and y >= 10:\r\n x -= 1\r\n y -= 10\r\n elif y >= 20:\r\n y -= 20\r\n else:\r\n break\r\n else:\r\n if y >= 20:\r\n y -= 20\r\n elif x >= 1 and y >= 10:\r\n x -= 1\r\n y -= 10\r\n elif x >= 2:\r\n x -= 2\r\n else:\r\n break\r\n\r\n turn = not turn\r\n\r\n if not turn:\r\n print('Ciel')\r\n else:\r\n print('Hanako')\r\n\r\nif __name__ == '__main__':\r\n busgame()",
"x, y = map(int, input().split())\r\n\r\nCielWon = False\r\n\r\nwhile (y > 1 and x * 10 + y > 21):\r\n t = min(x, 2)\r\n x -= t\r\n y -= (2 - t) * 10 + 2\r\n \r\n if (y < 2 or 10 * x + y < 22):\r\n CielWon = True\r\n break\r\n \r\n y -= 2\r\n t = min(2, y // 10)\r\n y -= 10 * t\r\n x -= 2 - t\r\n\r\nprint ('Ciel' if CielWon else 'Hanako')\r\n",
"x,y = map(int, input().split())\r\nt=0\r\nwhile (1):\r\n if t%2==0:\r\n if x >= 2 and y >= 2:\r\n x -= 2\r\n y -= 2\r\n elif x >= 1 and y >= 12:\r\n x -= 1\r\n y -= 1\r\n elif (x == 0 and y >= 22):\r\n y -= 22\r\n else:\r\n print(\"Hanako\")\r\n break\r\n else:\r\n if (y >= 22):\r\n y -= 22\r\n elif (x >= 1 and y >= 12):\r\n x -= 1\r\n y -= 12\r\n elif (x >= 2 and y >= 2):\r\n x -= 2\r\n y -= 2\r\n else:\r\n print(\"Ciel\")\r\n break\r\n t+=1",
"x,y=map(int,input().split())\r\n\r\ndef solve(x,y):\r\n valuex=100*x\r\n valuey=10*y\r\n\r\n count=0\r\n while True:\r\n if count%2==0:\r\n if x>=2 and y>=2:\r\n x-=2\r\n valuex-=200\r\n y-=2\r\n valuey-=20\r\n count+=1\r\n elif x==1 and y>=12:\r\n x-=1\r\n valuex-=100\r\n y-=12\r\n valuey-=120\r\n count+=1\r\n elif x==0 and y>=22:\r\n y-=22\r\n valuey-=220\r\n count+=1\r\n else:\r\n return \"Hanako\"\r\n else:\r\n if y>=22:\r\n y-=22\r\n valuey-=220\r\n count+=1\r\n \r\n elif x>0 and y>=12:\r\n x-=1\r\n valuex-=1\r\n y-=12\r\n valuey-=120\r\n count+=1\r\n elif x>1 and y>=2:\r\n x-=2\r\n valuex-=200\r\n y-=2\r\n valuey-=20\r\n count+=1\r\n else:\r\n return \"Ciel\"\r\n \r\nprint(solve(x,y))\r\n\r\n",
"state = 1\r\nx, y = map(int, input().split())\r\n\r\nwhile True:\r\n state = 1-state\r\n if state == 0:\r\n if x >= 2 and y >= 2:\r\n x -= 2\r\n y -= 2\r\n continue\r\n elif x >= 1 and y >= 12:\r\n x -= 1\r\n y -= 12\r\n continue\r\n elif x >= 0 and y >= 22:\r\n x -= 0\r\n y -= 22\r\n continue\r\n else:\r\n break\r\n elif state == 1:\r\n if x >= 0 and y >= 22:\r\n x -= 0\r\n y -= 22\r\n continue\r\n elif x >= 1 and y >= 12:\r\n x -= 1\r\n y -= 12\r\n continue\r\n elif x >= 2 and y >= 2:\r\n x -= 2\r\n y -= 2\r\n continue\r\n else:\r\n break\r\n\r\n\r\nprint(['Hanako', 'Ciel'][state])\r\n\r\n\r\n",
"x,y=map(int,input().split())\r\nwhile True:\r\n # Client's turn\r\n if(x>=2 and y>=2):\r\n x-=2\r\n y-=2\r\n elif(x>=1 and y>=12):\r\n x-=1\r\n y-=12\r\n elif(x>=0 and y>=22):\r\n y-=22\r\n else:\r\n print(\"Hanako\")\r\n exit()\r\n # Hanako's turn\r\n if(x>=0 and y>=22):\r\n y-=22\r\n elif(x>=1 and y>=12):\r\n x-=1\r\n y-=12\r\n elif(x>=2 and y>=2):\r\n y-=2\r\n x-=2\r\n else:\r\n print(\"Ciel\")\r\n exit()\r\n",
"x,y=map(int,input().strip().split())\r\n# -2, -2\r\n# -0, -22\r\n# total, -2, -24\r\na = min(x//2, y//24)\r\nx -= a*2\r\ny -= a*24\r\n\r\nwhile x and y:\r\n tot = 220\r\n while x > 0 and tot >= 100:\r\n x -= 1\r\n tot -= 100\r\n while y > 0 and tot >= 10:\r\n y -= 1\r\n tot -= 10\r\n if tot:\r\n print(\"Hanako\")\r\n exit(0)\r\n tot = 220\r\n while y > 0 and tot >= 210:\r\n y -= 1\r\n tot -= 10\r\n while y >= 10 and tot:\r\n y -= 10\r\n tot -= 100\r\n while x > 0 and tot >= 100:\r\n x -= 1\r\n tot -= 100\r\n if tot:\r\n print(\"Ciel\")\r\n exit(0)\r\nif x:\r\n print(\"Hanako\")\r\n exit(0)\r\nif not (y//22)%2:\r\n print(\"Hanako\")\r\nelse:\r\n print(\"Ciel\")",
"x, y = map(int, input().split())\nturn = 0\nres = \"\"\nwhile 1:\n\tif turn == 0:\n\t\tif x >= 2 and y >= 2:\n\t\t\tx-=2\n\t\t\ty-=2\n\t\telif x == 1 and y >= 12:\n\t\t\tx-=1\n\t\t\ty-=12\n\t\telif x == 0 and y >= 22:\n\t\t\ty-=22\n\t\telse:\n\t\t\tres = \"Hanako\"\n\t\t\tbreak\n\telse:\n\t\tif y >= 22:\n\t\t\ty-= 22\n\t\telif y >= 12 and x >= 1:\n\t\t\tx-=1\n\t\t\ty-=12\n\t\telif y >= 2 and x >= 2:\n\t\t\tx-=2\n\t\t\ty-=2\n\t\telse:\n\t\t\tres = \"Ciel\"\n\t\t\tbreak\n\t\t\t\t\t\n\tturn^=1\nprint(res)",
"x, y = map(int, input().split())\r\nm = 0\r\n\r\nwhile True:\r\n if m:\r\n if y<2:\r\n b = 0\r\n else:\r\n b = max(k for k in (2,12,22) if k<=y)\r\n a = min(x, (220-10*b)//100)\r\n else:\r\n a = min(2,x)\r\n b = min(y, (220-100*a)//10)\r\n if 100*a+10*b < 220:\r\n print('Ciel' if m else 'Hanako')\r\n break\r\n x -= a\r\n y -= b\r\n m = 1-m",
"class solve:\r\n def __init__(self):\r\n x,y=map(int,input().split())\r\n turn=0\r\n flag=0\r\n ans=0\r\n while True:\r\n if x>=2 and y>=2:\r\n x-=2\r\n y-=2\r\n elif x>=1 and y>=12:\r\n x-=1\r\n y-=12\r\n elif y>=22:\r\n y-=22\r\n else:\r\n print(\"Hanako\")\r\n break\r\n if y>=22:\r\n y-=22\r\n elif y>=12 and x>=1:\r\n y-=12\r\n x-=1\r\n elif y>=2 and x>=2:\r\n y-=2\r\n x-=2\r\n else:\r\n print(\"Ciel\")\r\n break\r\n\r\nobj=solve()",
"\r\nx,y=map(int,input().split())\r\ncnt=0\r\nwhile(True):\r\n if(cnt%2==0):\r\n if(x>=2 and y>=2):\r\n x-=2\r\n y-=2\r\n cnt+=1\r\n elif(x>=1 and y>=12):\r\n x-=1\r\n y-=12\r\n cnt+=1\r\n elif(y>=22):\r\n y-=22\r\n cnt+=1\r\n else:\r\n break\r\n else:\r\n if(y>=22):\r\n y-=22\r\n cnt+=1\r\n elif(x>=1 and y>=12):\r\n x-=1\r\n y-=12\r\n cnt+=1\r\n elif(x>=2 and y>=2):\r\n x-=2\r\n y-=2\r\n cnt+=1\r\n else:\r\n break\r\nprint(\"Ciel\" if cnt%2==1 else \"Hanako\")",
"a, b = map(int,input().split())\nk = \"Hanako\"\nz = False\nwhile True:\n\tif z == True:break\n\tif k == 'Ciel':\n\t\tif b >= 22:\n\t\t\tb -= 22\n\t\t\tk = 'Hanako'\n\t\telif b >= 12 and a >= 1:\n\t\t\ta-= 1\n\t\t\tb-= 12\n\t\t\tk = 'Hanako'\n\t\telif b >= 2 and a >= 2:\n\t\t\ta -= 2\n\t\t\tb -= 2\n\t\t\tk = 'Hanako'\n\t\telse:z = True\n\telse:\n\t\tif a >= 2 and b > 1:\n\t\t\ta -= 2\n\t\t\tb -= 2\n\t\t\tk = 'Ciel'\n\t\telif a == 1 and b > 11:\n\t\t\ta -= 1\n\t\t\tb -= 12\n\t\t\tk = 'Ciel'\n\t\telif a == 0 and b > 21:\n\t\t\tb -= 22\n\t\t\tk = 'Ciel'\n\t\telse:z = True\nprint(k)\n\t",
"import sys\nn,m=map(int, input().split())\nwhile True:\n if n*10+m<22 or m<2:\n print(\"Hanako\")\n sys.exit()\n if n>=2:\n n-=2\n m-=2\n elif n==1:\n n-=1\n m-=12\n else:\n m-=22\n \n if n*10+m<22 or m<2:\n print(\"Ciel\")\n sys.exit()\n if m>=22:\n m-=22\n elif m>=12:\n n-=1\n m-=12\n else:\n n-=2\n m-=2",
"hundred, ten = [int(x) for x in input().split()]\r\ntotal = 100*hundred + 10*ten\r\n\r\n#reduce by number of rounds where Ciel can take 2 100-yen and 2 10-yen, and Hanako can take 22 10-yen\r\nskipped = min(hundred//2,ten//24)\r\nhundred = hundred - 2*skipped\r\nten = ten - 24*skipped\r\n\r\nwhile True:\r\n win = 0\r\n if hundred >= 2 and ten >= 2:\r\n hundred = hundred - 2\r\n ten = ten - 2\r\n elif hundred >= 1 and ten >= 12:\r\n hundred = hundred - 1\r\n ten = ten - 12\r\n elif ten >= 22:\r\n ten = ten - 22\r\n else:\r\n break\r\n win = 1\r\n if ten >= 22:\r\n ten = ten - 22\r\n elif hundred >= 1 and ten >= 12:\r\n hundred = hundred - 1\r\n ten = ten - 12\r\n elif hundred >= 2 and ten >= 2:\r\n hundred = hundred - 2\r\n ten = ten - 2\r\n else:\r\n break\r\nif win == 0:\r\n print (\"Hanako\")\r\nelse:\r\n print (\"Ciel\")\r\n \r\n",
"import re\nimport itertools\nfrom collections import Counter\n\nclass Task:\n x, y = 0, 0\n answer = \"\" \n\t\n def getData(self):\n self.x, self.y = [int(x) for x in input().split(' ')]\n #inFile = open('input.txt', 'r')\n #inFile.readline().rstrip()\n #self.childs = inFile.readline().rstrip()\n\n def solve(self):\n while True:\n if self.cielStep() == \"can't move\":\n self.answer = 'Hanako'\n return\n if self.hanakoStep() == \"can't move\":\n self.answer = 'Ciel'\n return\n \n def cielStep(self):\n if self.x >= 2 and self.y >= 2:\n self.x -= 2\n self.y -= 2\n return 'next'\n if self.x >= 1 and self.y >= 12:\n self.x -= 1\n self.y -= 12\n return 'next'\n if self.y >= 22:\n self.y -= 22\n return 'next'\n return \"can't move\"\n \n def hanakoStep(self):\n if self.y >= 22:\n self.y -= 22\n return 'next'\n if self.y >= 12 and self.x >= 1:\n self.y -= 12\n self.x -= 1\n return 'next'\n if self.y >= 2 and self.x >= 2:\n self.x -= 2\n self.y -= 2\n return 'next'\n return \"can't move\"\n\n def printAnswer(self):\n print(self.answer)\n #outFile = open('output.txt', 'w')\n #outFile.write(self.answer)\n\ntask = Task()\ntask.getData()\ntask.solve()\ntask.printAnswer()\n",
"\r\n\r\n\r\na,b = map(int,input().split())\r\n\r\n\r\n\r\n\r\n\r\nx=1\r\n\r\n\r\nwhile True:\r\n if x%2:\r\n\r\n if a>=0 and b>0:\r\n\r\n if a>=2:\r\n if b>=2:\r\n a-=2\r\n b-=2\r\n x+=1\r\n elif b<2:\r\n print('Hanako')\r\n break\r\n elif a==1:\r\n if b>=12:\r\n b-=12\r\n a-=1\r\n x+=1\r\n else:\r\n print('Hanako')\r\n break\r\n elif a==0:\r\n if b>=22:\r\n b-=22\r\n x+=1\r\n else:\r\n print('Hanako')\r\n break\r\n\r\n else:\r\n print('Hanako')\r\n break\r\n \r\n else:\r\n\r\n if a>=0 and b>0:\r\n\r\n if b>=22:\r\n b-=22\r\n x+=1\r\n else:\r\n if a>=1 and b>=12:\r\n a-=1\r\n b-=12\r\n x+=1\r\n elif a>=2 and b>=2:\r\n a-=2\r\n b-=2\r\n x+=1\r\n else:\r\n print('Ciel')\r\n break\r\n else:\r\n print('Ciel')\r\n break\r\n\r\n",
"#Ya Hassan Mojtaba\r\nx,y=map(int,input().split())\r\ni=1\r\nwhile 1:\r\n if i%2==1:\r\n if x>=2 and y>=2:\r\n x-=2\r\n y-=2\r\n elif x==1 and y>=12:\r\n x-=1\r\n y-=12\r\n elif y>=22:\r\n y-=22\r\n else:\r\n print('Hanako')\r\n exit()\r\n else:\r\n if y>=22:\r\n y-=22\r\n elif y>=12 and x>=1:\r\n x-=1\r\n y-=12\r\n elif x>=2 and y>=2:\r\n x-=2\r\n y-=2\r\n else:\r\n print('Ciel')\r\n exit()\r\n i+=1",
"\r\ndef STR(): return list(input())\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef MAP2():return map(float,input().split())\r\ndef LIST(): return list(map(int, input().split()))\r\ndef STRING(): return input()\r\nimport string\r\nimport sys\r\nfrom heapq import heappop , heappush\r\nfrom bisect import *\r\nfrom collections import deque , Counter\r\nfrom math import *\r\nfrom itertools import permutations , accumulate\r\ndx = [-1 , 1 , 0 , 0 ]\r\ndy = [0 , 0 , 1 , - 1]\r\n#visited = [[False for i in range(m)] for j in range(n)]\r\n#sys.stdin = open(r'input.txt' , 'r')\r\n#sys.stdout = open(r'output.txt' , 'w')\r\n#for tt in range(INT()):\r\n\r\n\r\nx, y = MAP()\r\n\r\nflag1 = True\r\nflag2 = True\r\nf = 0\r\nwhile True:\r\n if f == 0 :\r\n v = 220\r\n k = min(x , 2)\r\n x -= k\r\n k1 = k * 100\r\n v-= k1\r\n k2 = v // 10\r\n if y >= k2 :\r\n y-= k2\r\n v = v % 10\r\n if v > 0 :\r\n flag1 = False\r\n break\r\n else:\r\n f = 1\r\n\r\n else:\r\n flag1 = False\r\n break\r\n\r\n else:\r\n v2 = 220\r\n if y >= 22 :\r\n y -= 22\r\n f = 0\r\n\r\n else:\r\n if x == 0 :\r\n flag2 = False\r\n break\r\n else:\r\n v2 -= 100\r\n x-=1\r\n if y >= 12:\r\n v2 = 0\r\n y -= 12\r\n f = 0\r\n else:\r\n v2 -= 100\r\n x-=1\r\n if x < 0 :\r\n flag2 = False\r\n break\r\n else:\r\n v2 -= 20\r\n y-=2\r\n if y < 0 :\r\n flag2 = False\r\n break\r\n else:\r\n f = 0\r\n\r\n\r\n#print(flag1)\r\n#print(flag2)\r\n\r\nif flag1:\r\n print('Ciel')\r\nelse:\r\n print('Hanako')\r\n\r\n\r\n\r\n\r\n",
"a = input()\r\na = a.split()\r\na = [int(x) for x in a]\r\nx, y = a\r\nwhile True:\r\n if x >= 2 and y >= 2:\r\n x -= 2 \r\n y -= 2\r\n elif x == 1 and y >= 12:\r\n x -= 1\r\n y -=12\r\n elif y >= 22:\r\n y -= 22\r\n else:\r\n print('Hanako')\r\n break\r\n \r\n if y >= 22:\r\n y -= 22\r\n elif x >= 1 and y >= 12:\r\n x -= 1\r\n y -=12\r\n elif x >= 2 and y >= 2:\r\n y -= 2\r\n x -= 2 \r\n else:\r\n print('Ciel')\r\n break\r\n "
] | {"inputs": ["2 2", "3 22", "0 22", "1000 1000", "0 0", "0 21", "1 11", "1 12", "2 1", "2 23", "2 24", "3 1", "3 2", "3 13", "3 14", "4 1", "4 2", "4 25", "4 26", "5 1", "5 2", "5 15", "5 16", "5 23", "5 24", "6 1", "6 2", "6 13", "6 14", "6 23", "6 24", "7 1", "7 2", "7 13", "7 14", "7 25", "7 26", "8 1", "8 2", "8 15", "8 16", "8 25", "8 26", "9 1", "9 2", "9 15", "9 16", "9 23", "9 24", "10 12", "10 13", "10 22", "10 23", "11 12", "11 13", "11 24", "11 25", "12 14", "12 15", "12 24", "12 25", "0 1000000", "1000000 0", "1000000 1000000", "178087 42116", "378897 104123", "61207 166129", "743519 228136", "425829 771644", "626640 833651", "308950 895657", "991262 957664", "192071 19670", "874382 81677", "202081 745873", "233663 723781", "783744 701689", "333825 679597", "365407 657504", "915488 635412", "947070 613320", "497151 591228", "528732 87635", "78813 65543", "6 4", "3 5", "4 24", "2 14", "2 26", "5 26", "5 5", "359 479", "1 20", "11 0", "3 0", "0 30", "0 35", "100 99", "3 4"], "outputs": ["Ciel", "Hanako", "Ciel", "Ciel", "Hanako", "Hanako", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Hanako", "Ciel", "Ciel", "Hanako", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Ciel", "Ciel", "Hanako", "Hanako", "Ciel", "Ciel", "Hanako", "Ciel", "Hanako", "Hanako", "Ciel", "Ciel", "Hanako", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Ciel", "Ciel", "Hanako", "Ciel", "Ciel", "Ciel", "Ciel", "Ciel", "Ciel", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Ciel", "Ciel", "Ciel", "Hanako", "Ciel", "Ciel", "Ciel", "Hanako", "Ciel", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Hanako", "Ciel", "Hanako", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Ciel", "Hanako", "Hanako", "Ciel", "Hanako", "Hanako", "Ciel", "Ciel", "Ciel", "Ciel"]} | UNKNOWN | PYTHON3 | CODEFORCES | 36 | |
326a73695d6ab2a8c0ceb3ffa601d027 | Dragons | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals *s*.
If Kirito starts duelling with the *i*-th (1<=≤<=*i*<=≤<=*n*) dragon and Kirito's strength is not greater than the dragon's strength *x**i*, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by *y**i*.
Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss.
The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
Sample Input
2 2
1 99
100 0
10 1
100 100
Sample Output
YES
NO
| [
"s, n = map(int, input().split())\r\ndata = []\r\nfor i in range(n):\r\n dragonStrength, gain = map(int, input().split())\r\n data.append((dragonStrength, gain))\r\ndata = sorted(data)\r\nWon = True\r\nfor i in data:\r\n if s > i[0]:\r\n s += i[1]\r\n else:\r\n print(\"NO\")\r\n Won = False\r\n break\r\nif Won:\r\n print(\"YES\")",
"n = list(map(int, input().split()))\r\n\r\ndragons = []\r\nresult = \"YES\"\r\n\r\nfor i in range(n[1]):\r\n dragons.append(list(map(int, input().split())))\r\n\r\ndragons.sort()\r\n\r\nfor i in dragons:\r\n if i[0] < n[0]:\r\n n[0] += i[1]\r\n else:\r\n result = \"NO\"\r\n break\r\n\r\nprint(result)",
"import sys\ninput = sys.stdin.readline\n\ns, n = map(int, input().split())\nlist_dragon = []\nlist_bonus = []\nfor _ in range(n):\n x, y = map(int, input().split())\n tuple_dragon = (x,y)\n list_dragon.append(tuple_dragon)\nlist_dragon.sort(key=lambda x: x[0])\nfor i in list_dragon:\n if s > i[0]:\n s += i[1]\n else:\n print(\"NO\")\n exit() \nprint(\"YES\")\n",
"s, n = map(int, input().split())\n\ndragons = []\nfor _ in range(n):\n x, y = map(int, input().split())\n dragons.append((x, y))\n\ndragons.sort() # Sort dragons based on their strength\n\nfor dragon in dragons:\n if s > dragon[0]:\n s += dragon[1]\n else:\n print(\"NO\")\n exit(0)\n\nprint(\"YES\")\n\n\t \t \t \t\t \t\t\t \t \t \t\t",
"def solve():\r\n s, n = map(int, input().split())\r\n v=[]\r\n for i in range(n):\r\n a,b = map(int, input().split())\r\n v.append((a,b))\r\n \r\n v.sort()\r\n for i in range(n):\r\n if s>v[i][0]:\r\n s=s+v[i][1]\r\n else:\r\n print(\"NO\")\r\n return\r\n print(\"YES\")\r\n return\r\n\r\ndef main():\r\n t=1\r\n while t>0:\r\n solve()\r\n t-=1\r\n\r\nif __name__==\"__main__\":\r\n main()",
"s, n = map(int, input().split())\r\ndragons = []\r\n\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n dragons.append((x, y))\r\n\r\ndragons.sort()\r\n\r\nfor dragon in dragons:\r\n if s > dragon[0]:\r\n s += dragon[1]\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n",
"s,n=map(int,input().split())\r\ndragons=[]\r\nfor _ in range(n):\r\n xi,yi=map(int,input().split())\r\n dragons.append((xi,yi))\r\ndragons.sort() \r\nfor xi,yi in dragons:\r\n if s>xi:\r\n s+=yi\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")",
"s, n = map(int, input().split())\r\na = sorted([list(map(int, input().split())) for i in range(n)])\r\nfor i in range(len(a)):\r\n if s <= a[i][0]:\r\n print(\"NO\")\r\n exit(0)\r\n else:\r\n s += a[i][1]\r\nprint(\"YES\")",
"s,n=map(int,input().split())\r\ndef check(l):\r\n for i in range(len(l)-1):\r\n if l[i+1][0]<l[i][0]:\r\n return False\r\n return True\r\ndef bsort(l):\r\n for i in range(len(l)-1):\r\n if l[i][0]>l[i+1][0]:\r\n dmy=l[i]\r\n l[i]=l[i+1]\r\n l[i+1]=dmy\r\n if check(l)==True:\r\n return\r\n else:\r\n bsort(l)\r\nL=[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n L.append([a,b])\r\nbsort(L)\r\nr=\"YES\"\r\nfor i in range(n):\r\n if s>L[i][0]:\r\n s+=L[i][1]\r\n else:\r\n r=\"NO\"\r\n break\r\nprint(r)",
"s, n = list(map(int, input().split()))\r\ncnt = 0\r\nl = []\r\n\r\nfor i in range(n):\r\n x, y = list(map(int, input().split()))\r\n a = (x, y)\r\n l.append(a)\r\nl.sort() \r\n\r\nfor i in range(n):\r\n \r\n if s > l[i][0]:\r\n s += l[i][1]\r\n cnt += 1\r\n if s <= l[i][0]:\r\n print(\"NO\")\r\n break\r\nif cnt == n:\r\n print(\"YES\")",
"s,n = map(int,input().split())\r\nd = []\r\nfor i in range(n):\r\n ds,b = map(int,input().split())\r\n d.append([ds,b])\r\nd.sort()\r\nwin = True\r\nfor i in d:\r\n if s>i[0]:\r\n s+=i[1]\r\n else:\r\n win = False\r\n\r\nif win:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"s, n = map(int, input().split())\r\nl = []\r\nfor i in range (n):\r\n x, y = map(int, input().split())\r\n l.append((x, y))\r\nl.sort()\r\nfor i in range (n):\r\n if s > l[i][0]:\r\n s += l[i][1]\r\n if (i == n - 1):\r\n print (\"YES\")\r\n else:\r\n print (\"NO\")\r\n break",
"s, n = list(map(int, input().split(\" \")))\r\nds = []\r\nfor i in range(n):\r\n ds.append(list(map(int, input().split(\" \"))))\r\nwhile len(ds) > 0:\r\n ezd = False\r\n for d in ds:\r\n if d[0] < s:\r\n if ezd:\r\n if d[1] > ezd[1]: ezd = d\r\n else:\r\n ezd = d\r\n if not ezd:\r\n print(\"NO\")\r\n break\r\n ds.remove(ezd)\r\n s+=ezd[1]\r\nif len(ds) == 0:\r\n print(\"YES\")",
"m,n = map(int,input().split())\r\na = []\r\nfor i in range(n):\r\n a1,a2 = map(int,input().split())\r\n a.append((a1,a2))\r\ndef cmp(x):\r\n return x[0],x[1]\r\na.sort(key=cmp)\r\nnow = m\r\nko = 0\r\nfor i in range(n):\r\n if now>a[i][0]:\r\n ko+=1\r\n now+=a[i][1]\r\n else:break\r\nif ko==n:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"s, n = map(int, input().split())\r\ndragons = []\r\nfor i in range(n):\r\n dragons.append(list(map(int, input().split())))\r\ndragons.sort()\r\nfor i in range(n):\r\n if s > dragons[i][0]:\r\n s += dragons[i][1]\r\n else:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")",
"s, n = list(int(num) for num in input().split())\r\n\r\ndragons = list([False, 0] for i in range(10000))\r\nfor i in range(n):\r\n dragon_power, profit = list(int(num) for num in input().split())\r\n dragons[dragon_power - 1][0] = True \r\n dragons[dragon_power - 1][1] += profit \r\n \r\nKirito_wins = True\r\nfor dragon_power in range(1, 10001):\r\n if dragons[dragon_power - 1][0] and s <= dragon_power:\r\n Kirito_wins = False \r\n else:\r\n s += dragons[dragon_power - 1][1]\r\n\r\nif Kirito_wins:\r\n print('YES')\r\nelse:\r\n print('NO')",
"def sortSync(arr1, arr2):\r\n x = zip(arr1, arr2)\r\n xs = sorted(x, key=lambda tup: tup[0], reverse=True)\r\n\r\n return [x[1] for x in xs], [x[0] for x in xs]\r\n\r\n\r\ns, n = list(map(int, input().split()))\r\np = []\r\nb = []\r\n\r\nfor i in range(n):\r\n x, y = list(map(int, input().split()))\r\n p.append(x)\r\n b.append(y)\r\n\r\nstrongest = max(p)\r\np, b = sortSync(b, p)\r\n\r\nflag = False\r\n\r\nwhile len(p) > 0:\r\n if s > strongest:\r\n flag = True\r\n for i in range(len(p)):\r\n if s > p[i]:\r\n s += b[i]\r\n p.pop(i)\r\n b.pop(i)\r\n break\r\n else:\r\n break\r\n\r\nif flag:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"\r\n\r\ns, n = input().split()\r\ns = int(s)\r\nn = int(n)\r\n\r\ndragons = []\r\nfor i in range(n):\r\n x, y = input().split()\r\n x = int(x)\r\n y = int(y)\r\n dragons.append((x, y)) # a tuple is appended here\r\ndragons.sort()\r\n\r\nfor dragon in dragons:\r\n if s <= dragon[0]:\r\n print(\"NO\")\r\n break\r\n s += dragon[1]\r\nelse:\r\n print(\"YES\")\r\n\r\n",
"s,n = list(map(int,input().split()))\r\nd = [tuple(map(int,input().split())) for i in range(n)]\r\nd.sort()\r\nfor j in d:\r\n if s>j[0]:\r\n s+=j[1]\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\") ",
"s, n = map(int,input().split())\n\ninfo = []\n\nfor i in range(n):\n l, r = map(int,input().split())\n info.append([l,r])\n \ninfo.sort(key = lambda x: (x[0], -x[1]))\n\nfor i in range(n):\n if s <= info[i][0]:\n print(\"NO\")\n exit()\n else:\n s += info[i][1]\n \nprint(\"YES\")",
"s,n = map(int,input().split())\r\ncheck = 0\r\na = [list((map(int,input().split()))) for _ in range(n)]\r\nfor x,y in sorted(a):\r\n if s > x:\r\n s += y\r\n else:\r\n print(\"NO\")\r\n exit()\r\nprint(\"YES\")",
"#Coder_1_neel\r\ns, n = map(int, input().split())\r\ndragons = []\r\n\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n dragons.append((x, y))\r\n\r\ndragons.sort(key=lambda dragon: dragon[0])\r\n\r\nfor dragon in dragons:\r\n x, y = dragon\r\n if s <= x:\r\n print(\"NO\")\r\n break\r\n else:\r\n s += y\r\nelse:\r\n print(\"YES\")\r\n",
"s, n = [int(i) for i in input().split()]\r\nd, b = [], []\r\nfor i in range(n):\r\n x, y = [int(j) for j in input().split()]\r\n d.append(x), b.append(y)\r\nfor i in range(1, len(d)):\r\n for j in range(i, 0, -1):\r\n if d[j] < d[j-1]:\r\n d[j], d[j-1] = d[j-1], d[j]\r\n b[j], b[j - 1] = b[j - 1], b[j]\r\n else:\r\n break\r\nfor i in range(len(d)):\r\n if s > d[i]:\r\n s += b[i]\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n",
"s, n=list(map(int, input().split()))\r\ndragons=[]\r\nfor i in range(n):\r\n a, b=list(map(int, input().split()))\r\n dragons.append([a, b])\r\ndragons.sort(key = lambda x: x[0])\r\nfor i in dragons:\r\n a=i[0]\r\n b=i[1]\r\n if s<=a:\r\n print(\"NO\")\r\n break\r\n elif s>a:\r\n s+=b\r\nelse:\r\n print(\"YES\")",
"# CF_Problem:\t230A_Dragons\r\n\r\ndef levelUp(s, n):\r\n\t\r\n l1 = list()\r\n while n > 0:\r\n x, y = [int(i) for i in input().split(\" \")]\r\n l1.append([x, y])\r\n n -= 1\r\n l2 = sorted(l1, key=lambda i: i[0])\r\n\r\n for i in l2:\r\n if s > i[0]:\r\n s += i[1]\r\n else:\r\n return \"NO\"\r\n return \"YES\"\r\n\r\n\r\ns, n = [int(i) for i in input().split(\" \")]\r\nprint(levelUp(s, n))\r\n",
"s, n = map(int, input().split())\r\na = []\r\nfor i in range(n):\r\n b = []\r\n x, y = map(int, input().split())\r\n b.append(x)\r\n b.append(y)\r\n a.append(b)\r\na.sort()\r\nfor i in range(n):\r\n if s > a[i][0]:\r\n s += a[i][1]\r\n else:\r\n print('NO')\r\n quit()\r\nprint('YES')\r\n",
"# https://codeforces.com/problemset/problem/230/A\r\n\r\ns, n = [int(x) for x in input().split()]\r\nx_y = []\r\nfor i in range(n):\r\n x_y.append([int(e) for e in input().split()])\r\n\r\ndef custom_key(item):\r\n return (item[0], -item[1])\r\n\r\nx_y.sort(key=custom_key)\r\n\r\npossible = True\r\nfor x, y in x_y:\r\n if s > x:\r\n s += y\r\n else:\r\n possible = False\r\n break\r\n\r\nif possible:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n",
"s,n=map(int,input().split())\r\ndragons=[]\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n dragons.append((x,y))\r\ndragons.sort()\r\nfor dragon in dragons:\r\n if s>dragon[0]:\r\n s+=dragon[1]\r\n else:\r\n print('NO')\r\n break\r\nelse:\r\n print('YES')",
"s,n=map(int,input().split(' ',1))\r\nopp=[]\r\ndeff=0\r\ntries=n\r\nswi=0\r\n\r\nfor i in range(n):\r\n x=list(map(int,input().split(' ',1)))\r\n opp.append(x)\r\nwhile tries>0:\r\n swi=0\r\n for d in opp:\r\n if s>d[0] and d[0]!=0 and swi==0:\r\n s+=d[1]\r\n d[0]=0\r\n deff+=1\r\n swi=1\r\n tries-=1\r\nif deff==n:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n ",
"s, n = map(int, input().split())\r\nx = []\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n x.append((a, b))\r\nx.sort()\r\nfor i in range(n):\r\n if s <= x[i][0]:\r\n print(\"NO\")\r\n break\r\n s += x[i][1]\r\nelse:\r\n print(\"YES\")# 1698062007.7944608",
"s, n = list(map(int, input().split(\" \")))\r\ndragons = []\r\n\r\nfor i in range(n):\r\n x, y = list(map(int, input().split(\" \")))\r\n dragons.append((x, y))\r\n \r\ndragons.sort()\r\n\r\npossible = True\r\n\r\nfor dragon in dragons:\r\n x, y = dragon\r\n\r\n if s > x:\r\n s += y\r\n else:\r\n possible = False\r\n print(\"NO\")\r\n break\r\n\r\nif possible:\r\n print(\"YES\")\r\n",
"k, n = tuple(map(int, input().split(' ')))\n\na = [tuple(map(int, input().split(' '))) for _ in range(n)]\n\na.sort(key=lambda x: x[0])\n\nfor e in a:\n if e[0] >= k:\n print('NO')\n break\n\n k += e[1]\nelse:\n print('YES')\n",
"s, n = input().split()\r\ns , n = int(s) , int(n)\r\nd={}\r\nl=[]\r\nfor i in range(n):\r\n x,y = input().split()\r\n x,y = int(x), int(y)\r\n m = [x,-y]\r\n l.append(m)\r\nl.sort()\r\nfor i in range(len(l)):\r\n if s>l[i][0]:\r\n s += abs(l[i][1])\r\n else:\r\n print(\"NO\")\r\n exit(0)\r\n \r\nprint(\"YES\")",
"s,n = map(int, input().split())\r\nmylist = []\r\nfor i in range(n):\r\n a,b = map(int, input().split())\r\n mylist.append([a,b])\r\nmylist.sort()\r\nfor i in range(n):\r\n if s > mylist[i][0]:\r\n s += mylist[i][1]\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")",
"if __name__ == '__main__':\n dragon = []\n _ = list(map(int, input().split()))\n s, n = _[0], _[1]\n for _ in range(n):\n dragon.append(list(map(int, input().split())))\n dragon.sort(key=lambda x: x[0], reverse=False)\n beat = True\n for feature in dragon:\n if feature[0] < s:\n s += feature[1]\n else:\n beat = False\n break\n print('YES' if beat else 'NO')\n\t\t\t \t \t\t\t\t\t \t\t\t\t \t\t\t \t",
"n, m = map(int, input().split())\r\nf = []\r\nd = []\r\nfor i in range(m):\r\n z, x = map(int, input().split())\r\n f.append(z)\r\n d.append(x)\r\n\r\ni = 0\r\nwhile m > i:\r\n if min(f) < n:\r\n n += d[f.index(min(f))]\r\n d.pop(f.index(min(f)))\r\n f.pop(f.index(min(f)))\r\n else:\r\n print('NO')\r\n exit()\r\n i += 1\r\nprint('YES')",
"\ndef solve(s, n, xy):\n xy.sort(key=lambda t:t[0])\n ok = True\n for i in range(n):\n x,y = xy[i]\n if s<=x:\n ok = False\n break\n s += y\n return ok\n\ns, n = [int(_) for _ in input().split()]\nxy = []\nfor i in range(n):\n xy.append(tuple(int(_) for _ in input().split()))\nprint(\"YES\" if solve(s, n, xy) else \"NO\")\n \n",
"s,n = map(int,input().split())\nl = []\nfor i in range(n):\n x,y=map(int,input().split())\n l.append([x,y])\nl.sort()\nans ='YES'\nfor i in range(n):\n if s>l[i][0]:\n s+=l[i][1]\n else:\n ans = 'NO'\n break\nprint(ans)\n\n \n# Fri Nov 10 2023 16:50:32 GMT+0300 (Moscow Standard Time)\n",
"s, n = list(map(int,input().split()))\r\nmatrix = []\r\nfor i in range(n):\r\n A = list(map(int,input().split()))\r\n matrix.append(A)\r\nmatrix.sort()\r\nfor i in range(n):\r\n if s > matrix[i][0]:\r\n s += matrix[i][1]\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")",
"s,n = input().split()\ns,n = int(s),int(n)\nL=[]\nfor i in range(n):\n L.append(input().split())\n L[i][0],L[i][1]=int(L[i][0]),int(L[i][1])\ndef func(a):\n return a[0]\nL.sort(key=func)\nflag=True\ni=0\nwhile i<n and flag==True:\n if L[i][0]<s:\n s=s+L[i][1]\n i=i+1\n else:\n flag=False\nif flag:\n print(\"YES\")\nelse:\n print(\"NO\")\n",
"s,n = map(int,input().split())\r\nfl =1\r\nl=[]\r\nfor i in range(n):\r\n\tx,y = map(int,input().split())\r\n\tl.append([x,y])\r\n\r\nl = sorted(l)\r\n# print l\r\nfor i in range(n):\r\n\tif s > l[i][0]:\r\n\t\ts+=l[i][1]\r\n\t\t# print s\r\n\telse:\r\n\t\tfl =0\t\r\n\t\tbreak\r\nif fl:\r\n\tprint (\"YES\")\r\nelse:\r\n\tprint (\"NO\")\r\n",
"s, n = [int(x) for x in input().split()]\ndragons = []\nfor x in range(n):\n dragon, bonus = [int(x) for x in input().split()]\n dragons.append([dragon, bonus])\ndragons.sort(key=lambda x: x[0])\nfor dragon in dragons:\n if dragon[0] < s:\n s += dragon[1]\n else:\n print(\"NO\")\n exit()\nprint(\"YES\")",
"s, n = map(int, input().split())\r\nd = []\r\ndef fn(x):\r\n global s\r\n return s > x[0]\r\nfor _ in range(n):\r\n d.append(tuple(map(int, input().split())))\r\nwhile len(d) != 0:\r\n fl = list(filter(fn, d))\r\n if len(fl) == 0:\r\n print(\"NO\")\r\n exit()\r\n for e in fl:\r\n d.pop(d.index(e))\r\n s += e[-1]\r\nprint(\"YES\")\r\n",
"s, n = map(int, input().split())\r\nlst = []\r\nwhile n:\r\n n -= 1\r\n lst.append(list(map(int, input().split())))\r\n\r\nlst = sorted(lst, key=lambda x: (x[0], -x[1]))\r\nch = 1\r\nfor st in lst:\r\n if s > st[0]:\r\n s += st[1]\r\n else:\r\n ch = 0\r\n break\r\nif ch:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n",
"s, n = map(int, input().split())\r\nlst1 = []\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n lst1.append((x, y))\r\na = sorted(lst1)\r\nflag = True\r\nfor i in range(len(a)):\r\n if a[i][0] >= s:\r\n flag = False\r\n break\r\n else:\r\n s += a[i][1]\r\nif flag:\r\n print('YES')\r\nelse:\r\n print('NO')",
"s,n = map(int,input().split())\r\nl = []\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n l.append([x,y])\r\nl.sort()\r\nans ='YES'\r\nfor i in range(n):\r\n if s>l[i][0]:\r\n s+=l[i][1]\r\n else:\r\n ans = 'NO'\r\n break\r\nprint(ans)\r\n\r\n ",
"s, n = map(int, input().split())\r\ndragons = []\r\nfor i in range(n):\r\n x,y = map(int, input().split())\r\n dragons.append((x,y))\r\ndragons.sort()\r\nfor i in dragons:\r\n if s > i[0]:\r\n s += i[1]\r\n else:\r\n print('NO')\r\n break\r\nelse:\r\n print('YES')\r\n ",
"s, n = map(int, input().split())\r\n\r\ndragons = []\r\nfor _ in range(n):\r\n xi, yi = map(int, input().split())\r\n dragons.append((xi, yi))\r\n\r\n# Sort dragons based on their strength in ascending order\r\ndragons.sort()\r\n\r\n# Check if Kirito can defeat all dragons without a single loss\r\nfor xi, yi in dragons:\r\n if s > xi:\r\n s += yi\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n",
"s, n = map(int, input().split())\r\ndragons = []\r\nfor _ in range(n):\r\n xi, yi = map(int, input().split())\r\n dragons.append((xi, yi))\r\ndragons.sort()\r\nfor dragon in dragons:\r\n xi, yi = dragon\r\n if s <= xi:\r\n print(\"NO\")\r\n exit()\r\n s += yi\r\nprint(\"YES\")",
"\r\nstrength, number_of_enemies = [int(i) for i in input().split()]\r\n\r\nenemy_list = []\r\n#in any order\r\nfor _ in range(number_of_enemies):\r\n new_dragon = [int(i) for i in input().split()]\r\n enemy_list.append((new_dragon))\r\nenemy_list.sort()\r\n#print(enemy_list)\r\n\r\nfor dragon in range(number_of_enemies):\r\n if strength > enemy_list[dragon][0]:\r\n strength += enemy_list[dragon][1]\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")",
"s, n = map(int, input().split())\r\nl = [list(map(int, input().split())) for _ in range(n)]\r\n\r\nl.sort(key=lambda x: x[0])\r\nc = 0\r\n\r\nfor dragon in l:\r\n x, y = dragon\r\n if x < s:\r\n c += 1\r\n s += y\r\n else:\r\n break\r\n\r\nif c == n:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"def s(t):\r\n return t[0]\r\n\r\n\r\nk, n = map(int, input().split())\r\na = []\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n a.append((x, y))\r\na = sorted(a, key=s)\r\nb = True\r\nfor i in range(n):\r\n s = a[i]\r\n if s[0] < k:\r\n k += s[1]\r\n else:\r\n b = False\r\n break\r\nif b:\r\n print('YES')\r\nelse:\r\n print('NO')",
"def bubbleSort(arr , bonus):\n n = len(arr)\n # Traverse through all array elements\n for i in range(n):\n # Last i elements are already in place\n for j in range(0, n-i-1):\n # traverse the array from 0 to n-i-1\n # Swap if the element found is greater\n # than the next element\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n bonus[j], bonus[j+1] = bonus[j+1], bonus[j]\n \n \n \ns,n=input().split()\ns,n=int(s),int(n)\nx=[]\ny=[]\n \nfor i in range(n):\n a=input().split()\n x.append(int(a[0]))\n y.append(int(a[1]))\n \nwin = 0\nbubbleSort (x, y)\nfor i in range(n):\n if s>x[i]:\n s += y[i]\n win+=1\n else:\n print(\"NO\")\n break\nif(win==n):print(\"YES\")\n \t \t\t \t\t \t\t\t\t \t\t \t\t\t \t \t\t",
"s, n = map(int, input().split())\r\ndragons = []\r\nfor _ in range(n):\r\n xi, yi = map(int, input().split())\r\n dragons.append((xi, yi))\r\ndragons.sort()\r\nfor dragon in dragons:\r\n if s <= dragon[0]:\r\n print(\"NO\")\r\n break\r\n else:\r\n s += dragon[1]\r\nelse:\r\n print(\"YES\")",
"s, n = map(int,input().split())\r\nk = 0\r\nx = []\r\ny = []\r\nmas = [[0]]*n\r\nfor i in range(n):\r\n mas[i] = list(map(int,input().split()))\r\nmas = sorted(mas)\r\n\r\nfor i in mas:\r\n x.append(i[0])\r\n y.append(i[1])\r\n\r\nfor i in range(n):\r\n if s > x[i]:\r\n s+=y[i]\r\n k+=1\r\n \r\n else:\r\n break\r\n #print(s)\r\n \r\nif k == n:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")",
"s, n=list(map(int, input().split()))\r\nl=[]\r\nfor i in range(n):\r\n a, b=list(map(int, input().split()))\r\n l.append([a, b])\r\nl.sort(key = lambda x: x[0])\r\n#print(l)\r\nfor i in l:\r\n a=i[0]\r\n b=i[1]\r\n if s<=a:\r\n print(\"NO\")\r\n break\r\n elif s>a:\r\n s+=b\r\nelse:\r\n print(\"YES\")\r\n",
"s, n = map(int, input().split())\r\n\r\ndragons = []\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n dragons.append((x, y))\r\n\r\n# Sort the dragons by their strength in ascending order\r\ndragons.sort()\r\n\r\nfor dragon in dragons:\r\n x, y = dragon\r\n if s > x:\r\n s += y\r\n else:\r\n print(\"NO\")\r\n break\r\nelse:\r\n print(\"YES\")\r\n"
] | {"inputs": ["2 2\n1 99\n100 0", "10 1\n100 100", "123 2\n78 10\n130 0", "999 2\n1010 10\n67 89", "2 5\n5 1\n2 1\n3 1\n1 1\n4 1", "2 2\n3 5\n1 2", "1 2\n1 0\n1 0", "5 10\n20 1\n4 3\n5 1\n100 1\n4 2\n101 1\n10 0\n10 2\n17 3\n12 84", "2 2\n1 98\n100 0", "2 2\n1 2\n3 5", "5 3\n13 20\n3 10\n15 5", "2 5\n1 1\n2 1\n3 1\n4 1\n5 1", "3 3\n1 1\n1 2\n4 0", "10 4\n20 1\n3 5\n2 4\n1 3", "10 1\n1 1", "4 1\n100 1000", "5 1\n6 7", "10 1\n10 10", "6 2\n496 0\n28 8128", "4 2\n2 1\n10 3", "11 2\n22 0\n33 0", "1 2\n100 1\n100 1", "10 3\n12 0\n13 0\n14 0", "50 3\n39 0\n38 0\n37 0", "14 3\n1 5\n1 6\n1 7", "1 3\n1 10\n1 11\n1 9", "10 10\n2 10\n3 10\n4 10\n2 20\n3 20\n3 20\n100 50\n100 30\n150 30\n200 10", "9983 34\n6626 5976\n4448 3568\n2794 2309\n3741 8806\n4754 129\n2780 9275\n5785 9243\n3915 6159\n2609 4331\n238 6756\n6987 3887\n3384 5711\n4349 5563\n1135 4483\n9151 1584\n1500 766\n1608 4440\n7768 5005\n7205 2360\n9088 2933\n3923 7814\n7538 9372\n7504 165\n5277 1636\n2061 4384\n7668 1422\n9582 2121\n5483 7967\n487 2944\n7432 5794\n8208 8970\n5747 3800\n4322 3920\n8261 9319", "1 10\n8 8\n54 3\n1 8\n26 3\n16 1\n29 9\n38 10\n57 8\n48 6\n17 9", "5 10\n7 0\n7 0\n10 0\n10 0\n7 2\n4 2\n9 0\n6 1\n7 0\n7 0", "2 3\n1 1\n1 10\n17 2", "100 5\n99 100\n199 1\n199 1\n199 1\n202 1", "1 1\n10000 1"], "outputs": ["YES", "NO", "YES", "YES", "YES", "YES", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "YES", "NO"]} | UNKNOWN | PYTHON3 | CODEFORCES | 57 | |
326c9cfa4b463c80581756abe06cf25f | Vasya's Function | Vasya is studying number theory. He has denoted a function *f*(*a*,<=*b*) such that:
- *f*(*a*,<=0)<==<=0; - *f*(*a*,<=*b*)<==<=1<=+<=*f*(*a*,<=*b*<=-<=*gcd*(*a*,<=*b*)), where *gcd*(*a*,<=*b*) is the greatest common divisor of *a* and *b*.
Vasya has two numbers *x* and *y*, and he wants to calculate *f*(*x*,<=*y*). He tried to do it by himself, but found out that calculating this function the way he wants to do that might take very long time. So he decided to ask you to implement a program that will calculate this function swiftly.
The first line contains two integer numbers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=1012).
Print *f*(*x*,<=*y*).
Sample Input
3 5
6 3
Sample Output
3
1
| [
"'''\n Python3(PyPy3) Template for Programming-Contest.\n'''\n\nimport math\nimport sys\n\n\ndef input():\n return sys.stdin.readline().rstrip()\n\n\nDXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # LDRU\nmod = 998244353\ninf = 1 << 64\n\n\ndef fact(n: int):\n res = []\n for p in range(2, n + 1):\n if p * p > n:\n break\n if n % p == 0:\n while n % p == 0:\n n //= p\n res.append(p)\n if n > 1:\n res.append(n)\n return res\n\nsys.setrecursionlimit(10)\ndef main():\n x, y = map(int, input().split())\n\n def f(a: int, b: int) -> int:\n if b == 0:\n return 0\n if a == 1:\n return b\n g = math.gcd(a, b)\n a, b = a // g, b // g\n rem = inf\n for p in fact(a):\n rem = min(rem, b % p)\n return rem + f(a, b - rem)\n\n ans = f(x, y)\n print(ans)\n return 0\n\n\nif __name__ == \"__main__\":\n main()\n",
"import math\r\n\r\ndef vas(x, y):\r\n if y == 0:\r\n return 0\r\n if x == 1:\r\n return y\r\n maximal = 0\r\n for p in prime:\r\n if x%p == 0:\r\n maximal = max(maximal, (y//p)*p)\r\n return y - maximal + vas(x//math.gcd(x, maximal), maximal//math.gcd(x, maximal))\r\n\r\nx, y = map(int,input().split())\r\nprime = []\r\np = 2\r\nn = x\r\nwhile p*p <= n:\r\n if n%p == 0:\r\n prime.append(p)\r\n while n%p == 0:\r\n n//=p\r\n p+=1\r\nif n != 1:\r\n prime.append(n)\r\nprint(vas(x, y))# 1690483122.8404496",
"import sys\nimport math\nfrom fractions import gcd\n\n\ndef prime_factors(n):\n res = []\n if n % 2 == 0:\n res.append(2)\n while n % 2 == 0:\n n //= 2\n for i in range(3, int(math.sqrt(n) + 1), 2):\n if n % i == 0:\n res.append(i)\n while n % i == 0:\n n //= i\n if n > 2:\n res.append(n)\n return res\n\n\ndef main():\n a, b = map(int, sys.stdin.readline().split())\n r = prime_factors(a)\n ans = 0\n while b > 1:\n g = gcd(a, b)\n b //= g\n a //= g\n v = 0\n for i in range(len(r)):\n if (a % r[i] == 0):\n v = max(v, b - b % r[i])\n ans += b - v\n b = v\n\n if b == 1:\n ans += 1\n\n print(ans)\n\n\nmain()\n# from fractions import gcd\n# x, y = map(int, input().split())\n#\n# a = int(x**.5 + 1)\n# p = []\n# x1 = x\n# for i in range(2, a + 1):\n# if (x1 % i == 0):\n# p.append(i)\n# while (x1 % i == 0):\n# x1 //= i\n# if (x1 > 1):\n# p.append(x1)\n# ans = 0\n# while (y != 0):\n# r = gcd(x, y)\n# x //= r\n# y //= r\n# max_can = 0\n# for i in range(len(p)):\n# if (x % p[i] == 0):\n# max_can = max(max_can, y - y % p[i])\n# ans += y - max_can\n# y = max_can\n# print(ans)\n",
"import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nfrom types import GeneratorType\r\nfrom collections import defaultdict\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\nsys.setrecursionlimit(2*10**5)\r\n\r\n\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n if type(to) is GeneratorType:\r\n stack.append(to)\r\n to = next(to)\r\n else:\r\n stack.pop()\r\n if not stack:\r\n break\r\n to = stack[-1].send(to)\r\n return to\r\n return wrappedfunc\r\n\r\nimport heapq\r\nimport math\r\n#t=int(input())\r\n\r\n\r\n\r\n\r\nx,y=map(int,input().split())\r\nans1=0\r\nif(y>x):\r\n ans1+=(y//x)\r\n y=(y%x)\r\n if(y==0):\r\n y=x\r\n ans1-=1\r\n\r\ndiv=[]\r\ni=1\r\nwhile((i*i)<=x):\r\n if(x%i==0):\r\n div.append(i)\r\n div.append(x//i)\r\n i+=1\r\n\r\ndiv=list(sorted(list(set(div))))\r\nans=0\r\nfor j in div:\r\n l=0\r\n\r\n\r\n r=y//j\r\n last=1\r\n if(math.gcd(y,x)==j and (j%last==0)):\r\n\r\n while(l<r):\r\n m=(l+r)//2\r\n curr=y-j*m\r\n a1=x//j\r\n b2=curr//j\r\n b3=y//j\r\n poss=0\r\n for k in div[1:]:\r\n if(a1%k==0):\r\n r1=((b3//k)-((b2-1)//k))\r\n\r\n if(r1>0):\r\n poss=1\r\n\r\n\r\n if(poss):\r\n\r\n r=m\r\n else:\r\n l=m+1\r\n\r\n\r\n y-=l*j\r\n last=j\r\n\r\n\r\n ans+=l\r\n\r\nprint(ans+ans1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"from fractions import gcd\nx, y = map(int, input().split())\n\na = int(x**.5 + 1)\np = []\nx1 = x\nfor i in range(2, a + 1):\n if (x1 % i == 0):\n p.append(i)\n while (x1 % i == 0):\n x1 //= i\nif (x1 > 1):\n p.append(x1)\nans = 0\nwhile (y != 0):\n r = gcd(x, y)\n x //= r\n y //= r\n max_can = 0\n for i in range(len(p)):\n if (x % p[i] == 0):\n max_can = max(max_can, y - y % p[i])\n ans += y - max_can\n y = max_can\nprint(ans)",
"def sqrt(n):\r\n return n**.5\r\n\r\ndef pfs(n):\r\n A = []\r\n while n % 2 == 0:\r\n A += [2]\r\n n //= 2\r\n return A + pfs_dummy(n, 3)\r\ndef pfs_dummy(n, start):\r\n if n == 1: return []\r\n A = []\r\n for k in range(start, int(sqrt(n)+1), 2):\r\n if n % k == 0:\r\n while n % k == 0:\r\n A.append(k)\r\n n //= k\r\n return A + pfs_dummy(n, k+2)\r\n if len(A) == 0: return [n]\r\n\r\ndef gcd(a, b):\r\n if a > b:\r\n return gcd(b, a)\r\n if a == 0:\r\n return b\r\n if b == 0:\r\n return a\r\n return gcd(b % a, a)\r\n\r\n\r\ns = input()\r\nx = int(s.split()[0])\r\ny = int(s.split()[1])\r\n\r\nd = gcd(x, y)\r\nx //= d\r\ny //= d\r\n\r\narr = pfs(x)\r\nans = 0\r\n\r\nwhile y > 0:\r\n if x == 1:\r\n ans += y\r\n y = 0\r\n \r\n else:\r\n maxcand = -1\r\n for p in set(arr):\r\n maxcand = max(maxcand, y - (y % p))\r\n ans += (y - maxcand)\r\n y = maxcand\r\n e = gcd(x, y)\r\n x //= e\r\n y //= e\r\n arr1 = pfs(e)\r\n for pf in arr1:\r\n arr.remove(pf)\r\n\r\nprint(ans)\r\n",
"A,B=map(int,input().split())\r\n\r\nprime=[]\r\np=2\r\nn=A\r\nwhile p*p<=n:\r\n if n%p==0:\r\n prime.append(p)\r\n while n%p==0:\r\n n//=p\r\n p+=1\r\nif n!=1:\r\n prime.append(n)\r\n \r\nimport math\r\ndef calc(a,b):\r\n if b==0:\r\n return 0\r\n if a==1:\r\n return b\r\n mx=0\r\n for p in prime:\r\n if a%p==0:\r\n c=b//p*p\r\n mx=max(mx,c)\r\n res=b-mx\r\n g=math.gcd(mx,a)\r\n return res+calc(a//g,mx//g)\r\n\r\nprint(calc(A,B))",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ndef divisor(i):\r\n s = set()\r\n for j in range(1, int(i ** (1 / 2)) + 1):\r\n if i % j == 0:\r\n s.add(i // j)\r\n s.add(j)\r\n s = list(s)\r\n s.sort()\r\n return s\r\n\r\ndef gcd(a, b):\r\n while b:\r\n a, b = b, a % b\r\n return a\r\n\r\ndef lcm(a, b):\r\n return a * b // gcd(a, b)\r\n\r\na, b = map(int, input().split())\r\ns = divisor(a)\r\nn = len(s)\r\nans = 0\r\ni = 0\r\nwhile b:\r\n si = s[i]\r\n c = b // si\r\n m = i\r\n for j in range(i + 1, n):\r\n if s[j] > b:\r\n break\r\n l = lcm(si, s[j])\r\n x = b // l * l\r\n if (b - x) // si < c:\r\n c = (b - x) // si\r\n m = j\r\n ans += c\r\n b -= c * si\r\n i = m\r\nprint(ans)"
] | {"inputs": ["3 5", "6 3", "1000000009 1000000008", "1000000007 1000000006", "2000000018 2000000017", "1000000000000 1", "1000000000000 1000000000000", "1 1000000000000", "100000000000 100000000000", "1 100000000000", "100000000000 1", "1000000009 1000000000000", "1000000000000 1000000007", "124556361363 136616361", "153136316 5153643", "15316888 315347573", "153907320131 11351356", "3 135415909531", "1 157831805135", "1000000009 1000000010", "767389814 1136900240", "999966000289 999966000288", "150917076326 287596534405", "49544527863 318162327511", "999999999989 999999999988", "339860248091 167735311934", "414654652183 366894205623", "450002679907 706296532001", "243220976099 419527537895", "3 100000007", "999962000357 100000000000", "1000000007 1000000000000", "963761198400 999999999997", "3999999979 3999999978", "154210543621 542105421054", "191480607107 629918602611", "516832075292 844855235404", "598718273423 543198266606", "963761198400 787405476727", "283286197375 459489599842", "963761198400 33129788784", "104338884626 894039957000", "963761198400 394879907912", "324161862590 324161862595", "450002679907 2", "999999999958 999999999957"], "outputs": ["3", "1", "1000000008", "1000000006", "1000000009", "1", "1", "1000000000000", "1", "100000000000", "1", "999992008", "4", "1617", "1288412", "59298", "16996", "45138636511", "157831805135", "2", "14254", "1999964", "14306025", "6965053451", "999999999988", "1843245188", "366894205623", "55285", "580057", "33333337", "200044", "999994006", "20", "3999999978", "96099620", "55476781293", "103412121", "1769375540", "45", "1409627228", "30", "40428", "21", "2", "2", "499999999979"]} | UNKNOWN | PYTHON3 | CODEFORCES | 8 | |
32713f0e3bc63c4144e2655dda3099c3 | Case of the Zeros and Ones | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
Sample Input
4
1100
5
01010
8
11101111
Sample Output
0
1
6
| [
"n=int(input())\r\nstr1=str(input())\r\na=str1.count('0')\r\nb=str1.count('1')\r\nprint(abs(a-b))\r\n",
"n = int(input())\r\ns = input()\r\nans = 0\r\nfor i in s:\r\n ans = ans + int(i)*2 - 1\r\nprint(abs(ans))",
"n = int(input())\r\na = input()\r\nx = []\r\n\r\nfor i in a:\r\n if len(x) == 0 or x[-1] == i:\r\n x.append(i)\r\n else:\r\n x.pop()\r\nprint(len(x))",
"def solucao(n, string):\r\n l = list(string)\r\n zeros = l.count('0')\r\n ones = l.count('1')\r\n return n - (2 * min(zeros, ones))\r\n\r\nn = int(input())\r\nstring = input()\r\nprint(solucao(n, string))",
"a=int(input())\r\nb=input()\r\n\r\nzero=b.count('0')\r\none=b.count('1')\r\np=min(zero,one)\r\nt=max(zero-p,one-p)\r\nprint(t)\r\n",
"n = int(input())\r\nnum = input()\r\n\r\nzeroes = num.count('0')\r\nones = num.count('1')\r\npairs = min(zeroes, ones)\r\n\r\nprint(n - pairs * 2)",
"s=int(input())\r\ns1=input()\r\no=s1.count(\"0\")\r\no2=s1.count(\"1\")\r\nprint(abs(o-o2)) ",
"n=int(input())\ny=input()\none=zero=0\nfor i in range(n):\n if(y[i]=='1'):\n one+=1\n else:\n zero+=1\nprint(abs(one-zero)) \n\n \t \t \t\t \t \t\t \t\t \t \t\t\t \t",
"#Complejidad O(n)\nn = int(input())\np = input()\n\ncount = 0\naux = 0\nif len(p)==n:\n for char in p:\n if char == \"0\":\n count += 1\n elif char == \"1\":\n aux += 1\n\n\nans = abs(count - aux) #La funcion abs me devuelve el valor absoluto\n #De una resta\nprint(ans)\n \t\t\t\t\t\t\t\t \t \t \t\t\t\t \t \t",
"x = int(input()) \ny = str(input())\no = 0 \nz = 0\nfor i in range(x):\n if y[i] == '0' :\n o+=1\n elif y[i] == '1':\n z+=1\n \nif o == z :\n print(0)\nelse:\n print(abs(o-z))\n \n \t \t\t\t \t \t\t \t\t\t \t \t \t \t",
"n=int(input())\nx=input()\nz=min(x.count('1'), x.count('0'))\nprint(n-z*2)\n \t \t\t\t \t \t\t \t \t\t\t\t \t\t\t\t",
"b=input()\r\nc=input()\r\nun=c.count(\"1\")\r\nzero=c.count(\"0\")\r\nprint(abs(zero-un))\r\n",
"n = int(input())\r\na = input()\r\num = a.count(\"1\")\r\nzero = a.count(\"0\")\r\nprint(abs(um - zero))",
"n=int(input())\ns=input()\none=0\nfor i in s:\n if(i=='1'):\n one+=1\nprint((n - (min(one, n - one) * 2)))\n\t\t\t\t\t \t \t \t\t \t\t \t\t\t \t",
"sunn=int(input())\r\nf=input()\r\nz=f.count('0')\r\no=f.count('1')\r\nprint(sunn-(2*min(z,o)))",
"n = int(input())\r\ns = list(input())\r\nz = 0\r\no = 0\r\nfor i in s:\r\n if i =='0':\r\n o = o + 1\r\n else:\r\n z = z + 1\r\nif z == o:\r\n print(0)\r\nelse:\r\n if z > o:\r\n print(z - o)\r\n else:\r\n print(o - z)",
"from collections import Counter\r\n\r\nn = int(input())\r\ns = input() \r\ncnt = Counter(s)\r\n\r\nprint(abs(cnt['0'] - cnt['1']))",
"n = int(input())\r\nstring = input()\r\nprint(n - min(string.count('1'), string.count('0')) * 2)",
"n=int(input())\r\ns=input()\r\ns1=list(map(int,str(s)))\r\nc0=0\r\nc1=0\r\nfor i in range(n):\r\n if s1[i]==0:\r\n c0+=1\r\nc1=n-c0\r\nif c0==c1:\r\n print(\"0\")\r\nelif c1>c0:\r\n print(c1-c0)\r\nelse:\r\n print(c0-c1)",
"n = int(input())\r\ns = input()\r\nzeros = s.count(\"0\")\r\nones = s.count(\"1\")\r\nmincount = min(zeros,ones)\r\nprint(n-2*mincount)",
"n = input()\r\ns = input()\r\npairs = min(s.count(\"0\"), s.count(\"1\")) * 2\r\n\r\nprint(len(s) - pairs)",
"zero = 0\none = 0\n\nsz = int(input())\nstring = input()\n\nfor char in string:\n if char == '0':\n zero += 1\n else:\n one += 1\n\nprint(abs(one - zero))\n\n\t \t\t \t \t\t \t\t \t \t\t \t \t\t\t \t\t",
"n=int(input())\r\ns=input()\r\nc=0\r\nfor i in range(0,n):\r\n if s[i]==\"1\":\r\n c+=1\r\nv=n-c\r\nprint(abs(c-v))",
"a=int(input())\r\nb=input()\r\nc=b.count(\"0\")\r\nd=b.count(\"1\")\r\nprint(a-min(c,d)*2)",
"n = int(input())\r\nli = list(map(int, input()))\r\nres = []\r\nfor i in li:\r\n if res == []:\r\n res.append(i)\r\n else:\r\n if res[-1] != i:\r\n res.pop()\r\n else:\r\n res.append(i)\r\nprint(len(res))\r\n",
"l = int(input())\r\nn = input()\r\nzero = 0\r\none = 0\r\nfor i in n:\r\n if i == \"0\":\r\n zero += 1\r\n else:\r\n one += 1\r\n\r\nif zero > one:\r\n print(zero - one)\r\nelse:\r\n print(one - zero)",
"len_s, s = int(input()), input()\r\nprint(abs(s.count('0') - s.count('1')))",
"n = int(input())\r\na = input()\r\ns1=0\r\ns0=0\r\nfor o in a:\r\n if(o ==\"1\"):\r\n s1+=1\r\n else:\r\n s0+=1\r\nprint(abs(s1-s0))",
"n = int(input())\r\nstring = input()\r\n\r\nones = string.count('1')\r\nzeroes = string.count('0')\r\n\r\nans = abs(ones - zeroes)\r\n\r\nprint(ans)",
"tamanho_string = int(input())\n\nstring = input()\nconta_u = 0\nconta_z = 0\n\nfor x in string:\n if x == '1': conta_u += 1\n if x == '0': conta_z += 1\n\nif conta_u < conta_z:\n tamanho_string -= conta_u * 2\nelse:\n tamanho_string -= conta_z * 2\n\nprint(tamanho_string)\n \t\t \t \t\t \t\t \t\t\t\t \t\t\t\t \t\t\t",
"n=int(input())\r\ns=str(input())\r\no=0\r\nz=0\r\nfor i in s:\r\n if i=='1':\r\n o+=1\r\n else:\r\n z+=1\r\nprint(n-2*min(o,z))",
"# Case of the Zeros and Ones\r\nn = int(input())\r\ns = input()\r\ncounter_0 = 0\r\ncounter_1 = 0\r\nfor i in s:\r\n if i == \"1\":\r\n counter_1 += 1\r\n elif i == \"0\":\r\n counter_0 += 1\r\nmin_1_0 = min(counter_0,counter_1)\r\nprint(n-(min_1_0*2))",
"n = int(input())\r\n\r\nstr_ = list(input())\r\n\r\nprint(abs(str_.count('0') - str_.count('1')))\r\n",
"def srr(n,str1):\n count_0=0\n count_1=0\n for i in str1:\n if i=='1':\n count_1+=1\n \n else:\n count_0+=1\n if count_0>count_1:\n print(n-2*count_1)\n else:\n print(n-2*count_0)\nn=int(input())\nstr1=input()\nsrr(n,str1)\n \t\t\t \t \t \t \t \t\t \t",
"a = int(input())\r\nb = input()\r\nlength = len(b)\r\nc = b.count('0')\r\nd = b.count('1')\r\nlist_1 = [c, d]\r\nmi = min(list_1)\r\na = length - 2 * mi\r\nprint(a)",
"n = int(input())\r\nstr = input()\r\nprint(abs(str.count('0') - str.count('1')))",
"n = int(input())\r\nnums = list(input())\r\nprint(max(nums.count('0'), nums.count('1')) - min(nums.count('0'), nums.count('1')))\r\n",
"import math\r\n\r\nn = int(input())\r\ns = input()\r\n\r\ni = 0\r\nj = 0\r\n\r\nif len(set(s)) == 1:\r\n\tprint(len(s))\r\n\r\nelse:\r\n\r\n\tfor c in s:\r\n\r\n\t\tif c == '0':\r\n\r\n\t\t\ti += 1\r\n\r\n\t\telse:\r\n\r\n\t\t\tj += 1\r\n\r\n\tprint(int(math.fabs(i - j)))",
"n = int(input())\ns = map(int, input())\no = sum(s)\nprint(n - (min(o, n - o) * 2))\n",
"n = int(input())\r\nm = input()\r\nz = m.count(\"0\")\r\no = m.count(\"1\")\r\nif o == n:\r\n print(n)\r\nelse:\r\n print(o+z-2*min(z,o))",
"a=int(input())\r\nd=1\r\ne=0\r\nf=input()\r\ns=f.count('1')\r\nr=f.count('0')\r\nif max(s,r)==s:\r\n t=s-r\r\nelse:\r\n t=r-s\r\nprint(t)",
"from collections import deque\nn = int(input())\ns = input()\nk = deque()\nfor x in s:\n if x == '1':\n if k and k[-1] == '0':\n k.pop()\n else:\n k.append(x)\n else:\n if k and k[-1] == '1':\n k.pop()\n else:\n k.append(x)\nprint(len(k))",
"\"\"\"\r\n@auther:Abdallah_Gaber \r\n\"\"\"\r\nn = int(input())\r\nword = input()\r\nnum1 = word.count('0')\r\nnum2 = word.count('1')\r\n\r\nprint(abs(num1-num2))\r\n",
"n=int(input())\r\nl=list(input())\r\nprint(abs(l.count('0')-l.count('1')))",
"n = int(input())\r\ns = str(input())\r\nzero = 0\r\none = 0\r\nfor i in s:\r\n if i == '0':\r\n zero += 1\r\n else:\r\n one += 1\r\nprint(n-2*(min(one, zero)))",
"a=int(input())\nb=list(input())\nx=0\nn=0\nfor i in range(len(b)):\n b[i]=int(b[i])\nfor i in range(0,len(b)):\n if b[i]==0:\n x+=1\n else:\n n+=1\nprint(abs(x-n))\n \t \t \t \t \t\t \t \t \t",
"n=int(input())\r\nstroca=input()\r\nx=stroca.count('0')\r\ny=stroca.count('1')\r\nz=(min(x,y)*2)\r\nprint(n-z)",
"n=int(input())\r\ns=input()\r\n\r\nc=0\r\n\r\nfor i in range(n):\r\n if s[i]=='0':\r\n c+=1\r\n\r\nprint(abs(n-2*c))\r\n",
"n = int(input())\r\nx = list(input())\r\nprint(abs(x.count('0')-x.count('1')))",
"j=int(input())\r\ni=input()\r\na=i.count(\"0\")\r\nb=i.count(\"1\")\r\nresult=abs(a-b)\r\nprint(result)",
"n=int(input())\nx=input(str())\nprint(abs(int(x.count('1'))-int(x.count('0'))))\n\t\t \t\t\t\t\t \t\t \t \t \t\t\t\t\t\t \t",
"n=int(input())\r\na=input()\r\nzero=a.count(\"0\")\r\none=a.count(\"1\")\r\nif one == 0 or zero==0:\r\n print(n)\r\nelse:\r\n print(n-(2*min(zero,one)))",
"input()\r\ns = input()\r\nprint(abs(s.count('1') - s.count('0')))\r\n",
"#import sys\r\n#input = sys.stdin.readline\r\n#def solve():\r\n#n = str(input())\r\nn = int(input())\r\na = str(input())\r\n#n,a,b =map(int, input().split())\r\n#a = list(map(int, input().split()))\r\n#a =map(int, input().split())\r\nb = []\r\nfor i in range(n):\r\n b.append(int(a[i]))\r\ns = sum(b)\r\nif s <= n/2:\r\n ans = n - s*2\r\nelse: ans = n - (n-s)*2\r\nprint(ans)\r\n# return\r\n#for _ in range(int(input())):\r\n # solve()\r\n\r\n\r\n\r\n",
"n = int(input())\r\ns = input()\r\noc = s.count('1')\r\nzc = s.count('0')\r\n\r\nprint(abs(oc- zc))",
"n=int(input())\r\ns=input()\r\na1=s.count('1')\r\na0=s.count('0')\r\nprint(max(a1,a0)-min(a1,a0))\r\n",
"n = int(input())\ns = list(input())\nf = []\nones = s.count('1')\nzeros = s.count('0')\n\nfor i in s:\n if i == '0':\n if ones > 0:\n ones-= 1;\n if i == '1':\n if zeros > 0:\n zeros-= 1;\nprint(zeros + ones)\n# if i == '1':\n# if '0' in f:\n# f.remove('0')\n# else:\n# f.append(i)\n# if i == '0':\n# if '1' in f:\n# f.remove('1')\n# else:\n# f.append(i)\n# print(f.__len__())\n ",
"################### Prasad.TGS #####################\n####################################################\n####################################################\nn=int(input())\ns=input()\no=s.count('1')\nz=s.count('0')\nif o==z:\n print(0)\nelif o>z:\n print(o-z)\nelse:\n print(z-o)",
"n = int(input())\r\ns = list(input())\r\nf = len(list(filter(lambda x: x=='0', s)))\r\nprint(max(n-f,f)-min(n-f,f))\r\n",
"n = int(input())\r\nk = input()\r\n# count the no of zeroes and ones\r\nc0 = k.count(\"0\")\r\nc1 = k.count(\"1\")\r\nif c0 == c1:\r\n print(0)\r\nelse:\r\n print(n-min(c0,c1)*2)",
"n = int(input())\r\n\r\ntext = input()\r\nind = 0\r\ncount = 0\r\nfor item in text:\r\n if item == \"1\":\r\n count += 1\r\n else:\r\n count -= 1\r\n\r\n \r\nprint(abs(count))\r\n\r\n",
"from collections import Counter\r\nn=int(input())\r\ns=input()\r\nc=Counter(s)\r\np=min(c['0'],c['1'])\r\nprint(n-(2*p))",
"#for _ in range(int(input())):\n#a,b=map(int,input().split())\nn=int(input())\ns=input()\non=s.count('1')\nze=min(n-on,on)\nprint(n-2*ze)",
"n=int(input())\r\ns=input()\r\nS=list(s)\r\nprint(abs(S.count('0')-S.count('1')))",
"n = int(input())\r\ncode = input()\r\n\r\nprint(abs(n - 2 * code.count(\"0\")))",
"lengths = int(input())\r\nnum = input()\r\nnum2 = list(num)\r\n\r\nonelen = num2.count('1')\r\nzerolen = num2.count('0') \r\n\r\nprint(lengths - (2*min(onelen,zerolen)))",
"n=int(input())\r\ns=input()\r\nx=s.count('1')\r\ny=s.count('0')\r\nif(y==0)or(x==0):\r\n print(n)\r\nelif(x>y):\r\n print(n-(2*y))\r\nelse:\r\n print(n-(2*x))\r\n",
"print(abs(int(input()) - 2 * input().count('1')))",
"n = int(input())\nline = input()\n\nzeros = line.count(\"0\")\nones = line.count(\"1\")\n\nremove = 2 * min(ones, zeros)\n\nnew_len = n - remove\n\nprint(new_len)\n \t \t\t \t\t\t \t\t\t \t \t\t \t\t\t \t",
"num=int(input())\r\ns1=input()\r\nx=s1.count(\"0\")\r\nz=s1.count(\"1\")\r\nprint(abs(z-x))",
"n= int(input())\r\nstring = input()\r\n\r\nuno = string.count('1')\r\ncero = string.count('0')\r\nprint(max(uno,cero) - min(uno,cero))\r\n",
"input()\r\nx = list(input())\r\nprint(abs(x.count('1') - x.count('0')))",
"int(input())\r\nx = input()\r\na = x.count('0')\r\nb = x.count('1')\r\nprint(len(x)-(2*min(a,b)))",
"#!/usr/bin/env python\r\n\r\nimport math\r\nimport sys\r\nimport itertools\r\nimport fractions\r\n\r\nif __name__ == '__main__':\r\n wtf = sys.stdin.read()\r\n wtf = wtf.strip().split('\\n')\r\n n = int(wtf[0])\r\n S = wtf[1]\r\n z = S.count('0')\r\n o = S.count('1')\r\n m = len(S)\r\n print(m-2*min(z,o))\r\n",
"n = int(input())\r\na = input()\r\nc0 = a.count('0')\r\nc1 = a.count('1')\r\nn -= min(c0, c1) * 2\r\nprint(n)\r\n",
"n=int(input())\nstr=input()\nk=l=s=0\nfor i in str :\n if i=='1' :\n k=k+1\n if i=='0' :\n l=l+1\ns=k-l\nif s<0 :\n s=s*-1\nprint(s)\n \n \n\t\t \t\t \t \t \t\t \t \t \t \t \t \t\t\t",
"import sys\r\n# from functools import lru_cache\r\n# @lru_cache(maxsize=None)\r\n\r\ndef _input():\r\n return sys.stdin.readline().strip()\r\n\r\ndef main():\r\n n = int(_input())\r\n s = str(_input())\r\n a = s.count('0')\r\n b = s.count('1')\r\n print(abs(a-b))\r\n\r\nmain()",
"n=int(input())\r\ns=str(input())\r\nif s.count('1')<s.count('0'):\r\n print(n-s.count('1')*2)\r\nelse:\r\n print(n-s.count('0')*2)",
"n=int(input())\r\nax=list(map(int,input()))\r\nprint(n-2*min(ax.count(0),ax.count(1)))",
"def helper(n,s):\r\n \r\n cnt0=s.count('0')\r\n cnt1=s.count('1')\r\n \r\n print(n-2*min(cnt0,cnt1))\r\n\r\nn=int(input())\r\ns=list(map(str,input()))\r\nhelper(n,s)",
"length_of_string = input()\r\ninput_string = input()\r\n\r\narr = []\r\n\r\nfor num in input_string:\r\n if len(arr) == 0:\r\n arr.append(num)\r\n continue\r\n\r\n if arr[len(arr) - 1] == '1' and num == '0':\r\n arr.pop(len(arr) - 1)\r\n continue\r\n\r\n if arr[len(arr) - 1] == '0' and num == '1':\r\n arr.pop(len(arr) - 1)\r\n continue\r\n\r\n arr.append(num)\r\n\r\nprint(len(arr))",
"from itertools import count\r\n\r\n\r\nn=int(input())\r\nx=list(input())\r\ns1=x.count('1')\r\ns2=x.count('0')\r\nprint(abs(s1-s2))",
"def main():\r\n string_length = int(input())\r\n string = input()\r\n solution = solver(string_length, string)\r\n sw_sol(solution)\r\n\r\n\r\ndef solver(length: int, string: str) -> int:\r\n number_of_units = 0\r\n number_of_zeros = 0\r\n for symbol in string:\r\n if symbol == '1':\r\n number_of_units += 1\r\n else:\r\n number_of_zeros += 1\r\n if number_of_units > number_of_zeros:\r\n result = number_of_units - number_of_zeros\r\n else:\r\n result = number_of_zeros - number_of_units\r\n return result\r\n\r\n\r\ndef sw_sol(result: int):\r\n print(result)\r\n\r\n\r\nmain()\r\n\r\n\r\n",
"n = int(input())\r\ns = input()\r\nm = {'0':0, '1':0}\r\nfor i in range(n):\r\n m[s[i]] += 1\r\nprint(abs(m['0']-m['1']))",
"import sys\nn=int(input())\ndigit=sys.stdin.readline().strip()\nprint(n-2*min(digit.count('0'),digit.count('1')))\n\n",
"import sys\r\n\r\n#---------------------------------\r\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\n\r\n\r\n# sys.stdin = open('input.txt', 'r')\r\n# sys.stdout = open('output.txt', 'w')\r\n\r\n#---------------------------------\r\n\r\n\r\nn = int(input())\r\nls= input()\r\nzero=0\r\nfor i in ls:\r\n if i =='0':\r\n zero+=1\r\nprint(abs(n-(zero*2)))\r\n",
"n=int(input())\r\ns=input()\r\nk=min(s.count(\"1\"),s.count(\"0\"))\r\nprint(len(s)-(2*k))",
"n=int(input())\r\ns=input()\r\na=0\r\nb=0\r\nfor i in range(n):\r\n if s[i]=='1':\r\n a+=1\r\n else:\r\n b+=1\r\nprint(n-2*min(a, b)) ",
"n = int(input())\r\n\r\ns = input()\r\n\r\nzero = s.count('0')\r\none = s.count('1')\r\n\r\n\r\nprint(len(s) - min(zero, one)*2)",
"n = int(input())\r\ns = input()\r\nones = s.count('1')\r\nzeroes = s.count('0')\r\nunion = min(ones, zeroes)\r\nprint(max(ones - union, zeroes - union))\r\n",
"n = int(input(\"\"))\r\nstr = input(\"\")\r\nzeros = str.count('0')\r\nones = str.count('1')\r\n\r\nprint(abs(zeros-ones))",
"t = int(input())\r\ns = input()\r\nz = 0\r\no = 0\r\n\r\nfor i in s:\r\n \r\n if i == \"0\":\r\n z+=1\r\n elif i == \"1\":\r\n o+=1\r\n\r\nif z == o:\r\n print(0)\r\nelif z>o:\r\n print(z-o)\r\nelif o>z:\r\n print(o-z)",
"n = int(input())\r\n\r\nn = input()\r\ns = [n[0]]\r\nj = 0\r\ni = 1\r\n\r\n\r\nwhile i < len(n):\r\n if s and n[i] != s[-1]:\r\n s.pop()\r\n j += 2\r\n else:\r\n s.append(n[i])\r\n\r\n i += 1\r\n\r\nprint(len(n) - j)",
"length = int(input())\r\nstring = input()\r\n\r\nzeros = string.count('0')\r\nones = string.count('1')\r\n\r\nprint(abs(zeros-ones))",
"n = int(input())\r\nnumbers = input()\r\nnumbers = list(numbers)\r\nfor i in range(n):\r\n numbers[i] = int(numbers[i])\r\nzero = 0\r\none = 0\r\n\r\nfor x in numbers:\r\n if x == 0:\r\n zero +=1\r\n else:\r\n one +=1\r\n\r\nmini = min(zero,one) * 2\r\n\r\nprint(len(numbers)-mini)",
"s = int(input())\r\nx = input()\r\nprint(abs(x.count('1')-x.count('0')))",
"n = int(input())\ns = input()\nst = []\nfor i in s:\n if st and i != st[-1]:\n st.pop()\n else:\n st.append(i)\nprint(len(st))",
"n=int(input())\r\nstr=input()\r\nzero=0\r\nfor it in str:\r\n\tif it=='0': zero+=1\r\nprint(abs(n-2*zero))",
"n = int(input())\r\ns = input()\r\nl = list(s)\r\nc0 = 0\r\nc1 = 0\r\nfor i in l:\r\n if i == '0':\r\n c0 += 1\r\n else:\r\n c1 += 1\r\n#print(l, c1, c0)\r\nprint(abs(c1-c0))\r\n\r\n",
"print(abs(int(input())-2*input().count('1')))",
"\r\ndef zero(s):\r\n one=0\r\n zero=0\r\n\r\n for i in range(0,len(s)):\r\n if s[i]==\"0\":\r\n zero=zero+1\r\n elif s[i]==\"1\":\r\n one=one+1\r\n\r\n\r\n print(abs(one-zero))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n= int(input())\r\n s= input()\r\n zero(s)",
"n=int(input())\r\ns=input()\r\nzeroes=s.count('0')\r\nones=s.count('1')\r\nprint(n-(2*min(zeroes,ones)))",
"n = int(input())\r\ninp = input()\r\nc = i = 0\r\nwhile i<n:\r\n c = c+1 if inp[i]=='1' else c-1\r\n i+=1\r\nprint(abs(c))",
"s = int(input())\r\na = list(input())\r\ns1 = 0\r\ns2 = 0\r\nif s != 1:\r\n for i in range(len(a)):\r\n if a[i] == '0':\r\n s1 += 1\r\n else:\r\n s2 += 1\r\n print(len(a) - (min(s1, s2) * 2))\r\nelse:\r\n print(1)\r\n",
"n=int(input())\na=input()\nx=[]\nb=[]\nfor i in a:\n b.append(int(i))\n\nx.append(b.count(1))\nx.append(b.count(0))\nprint(max(x)-min(x))\n\n\n\t \t \t \t\t\t\t\t \t\t\t \t",
"n=int(input())\r\ns=input()\r\na=s.count('0')\r\nb=s.count('1')\r\nprint(abs(a-b))\r\n\r\n\r\n\r\n",
"n = int(input())\r\ns = input()\r\n\r\nzeros = s.count('0')\r\nones = s.count('1')\r\n\r\nprint(abs(zeros - ones))\r\n",
"c,s=int(input()),input()\r\na=min(s.count('1'),s.count('0'))\r\nprint(c-a*2)",
"n=int(input())\r\n\r\ns=input()\r\nzeros=s.count('0')\r\nones=s.count('1')\r\nif zeros==ones:\r\n print(\"0\")\r\nelse:\r\n print(abs(ones-zeros))\r\n ",
"n = int(input())\r\n\r\ns = str(input())\r\n\r\nc0, c1 = 0, 0\r\n\r\nfor el in s:\r\n if el == '0':\r\n c0 += 1\r\n\r\n else:\r\n c1 += 1\r\n\r\nprint(abs(c0 - c1))\r\n",
"n = int(input())\r\nl = input()\r\na = l.count(\"1\")\r\nb = l.count(\"0\")\r\nprint(abs(a-b))",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Aug 30 14:18:32 2021\r\n\r\n@author: rupert\r\n\"\"\"\r\n\r\n\r\ndef grouping(s,n):\r\n freq = [0]\r\n prevchar = s[0]\r\n for i in range(n):\r\n if s[i] == prevchar:\r\n freq[-1] += 1\r\n elif s[i] != prevchar:\r\n freq.append(1)\r\n prevchar = s[i] \r\n \r\n return freq\r\n \r\nimport sys\r\nsysinput = sys.stdin.readline\r\n#sysinput = input\r\nn = int(sysinput())\r\ns = sysinput()\r\n# n = len(s)\r\ngroupcnt = grouping(s,n)\r\n#print(groupcnt)\r\nminlen = 0\r\nfor i in range(len(groupcnt)):\r\n minlen += (-1)**i*groupcnt[i]\r\nprint(abs(minlen))\r\n\r\n ",
"import string as st\r\n\r\ndef main_function():\r\n n = int(input())\r\n s = input()\r\n count_1 = 0\r\n count_0 = 0\r\n for i in s:\r\n if i == \"1\":\r\n count_1 += 1\r\n else:\r\n count_0 += 1\r\n return abs(count_0 - count_1)\r\n\r\n\r\n\r\n\r\n\r\nprint(main_function())",
"n = int(input())\r\ns = str(input())\r\nt = abs(n - 2*s.count('1'))\r\nprint(t)\r\n\r\n",
"n = int(input())\r\ns = input()\r\nx1 = s.count('0')\r\nx2 = s.count('1')\r\nprint(n - 2*min(x1,x2))",
"# https://codeforces.com/problemset/problem/556/A\n_ = int(input())\nbin = input()\nprint(abs(bin.count(\"0\") - bin.count(\"1\")))\n",
"n = int(input())\r\ns = input()\r\nz = s.count(\"0\")\r\no = s.count(\"1\")\r\nif z == o:\r\n print(0)\r\nelif z > o:\r\n print(n - 2 * o)\r\nelif o > z:\r\n print(n - 2 * z)\r\n\r\n",
"# ЖАДНЫЕ АЛГОРИТМЫ\r\n\r\nn = int(input())\r\nl = input()\r\nzero = l.count('0')\r\none = l.count('1')\r\nprint(abs(zero-one))",
"##a=50\r\n##while a<=150:\r\n## print(a)\r\n## a+=1\r\n \r\n\r\n##a=13\r\n##while a<=349:\r\n## print(a)\r\n## a+=7\r\n\r\n\r\n##a=15\r\n##while a!=-1:\r\n## print(a)\r\n## a-=1\r\n##print(\"let\\'s gooooo!\")\r\n\r\n\r\n##a=str(input())\r\n##while a[0]!=\"я\" and a[0]!=\"Я\" :\r\n## print(a[0])\r\n## a=str(input())\r\n\r\n\r\n##n=int(input())\r\n##q=1\r\n##while q*q<=n:\r\n## print(q*q)\r\n## q+=1\r\n\r\n\r\n##x=int(input())\r\n##y=int(input())\r\n##i=1\r\n##while x<y:\r\n## x+=x/100*10\r\n## i+=1\r\n##print(i)\r\n\r\n\r\n##a,b=map(int,input().split())\r\n##i=0\r\n##if (1<=a<=10 and 1<=b<=10) and (b>a or a==b):\r\n## while b>=a:\r\n## a*=3\r\n## b*=2\r\n## i+=1\r\n##print(i)\r\n\r\n\r\nn=int(input())\r\ns=str(input())\r\nif len(s)==n and 1<=n<=20**5:\r\n if s.count(\"0\")>s.count(\"1\"):\r\n print(s.count(\"0\")-s.count(\"1\"))\r\n else:\r\n print(s.count(\"1\")-s.count(\"0\"))\r\n \r\n\r\n",
"def solve(s,n):\n tot_0=0\n tot_1=0\n for c in s:\n if c == '0':\n tot_0+=1\n else:\n tot_1+=1\n return n-min(tot_0,tot_1)*2\n\n\n \n\n \ndef main() :\n n = int(input())\n s = input()\n # arr = list(map(int, input().split(' ')))\n # res=''\n # for _ in range(8):\n # i = input()\n # res+=i\n print(solve(s,n))\nmain()\n",
"# Details\r\n'''\r\nContest: \r\nProblem: \r\nRating: \r\nDifficulty: \r\nAuthor: Sarthak Mittal\r\n'''\r\n\r\n# Input into int array\r\n'''\r\ndef arrin ():\r\n return list(map(int,input().strip().split()))\r\n'''\r\n \r\n# Printing int array\r\n'''\r\ndef printer (a,n):\r\n for i in range (0,n):\r\n print(a[i], end = ' ')\r\n print()\r\n'''\r\n\r\n# Array Maxima\r\n'''\r\ndef maxima (a,n):\r\n m = 0\r\n for i in range (0,n):\r\n if (a[i] >= a[m]):\r\n m = i\r\n return a[m]\r\n'''\r\n\r\n# Array Minima\r\n'''\r\ndef minima (a,n):\r\n m = 0\r\n for i in range (0,n):\r\n if (a[i] <= a[m]):\r\n m = i\r\n return a[m]\r\n'''\r\n\r\n# Array Sorter\r\n'''\r\ndef sorter (a):\r\n a.sort()\r\n'''\r\n\r\n# Rhetoric Printer\r\n'''\r\ndef rhetoric (b):\r\n if (b):\r\n print('YES')\r\n else:\r\n print('NO')\r\n'''\r\n\r\n# String to List\r\ndef strtolis (l,s):\r\n for i in range (0,len(s)):\r\n l.append(s[i])\r\n\r\nn = int(input())\r\ns = input()\r\n\r\ncount = 0\r\nfor i in range (0,n):\r\n if int(s[i]):\r\n count += 1\r\n else:\r\n count -= 1\r\nprint(int(abs(count)))",
"N=int(input())\r\narray=[int(x) for x in list(input())]\r\ncounter1=0\r\ncounter0=0\r\nfor i in array:\r\n\tif i==1:\r\n\t\tcounter1+=1\r\n\telse:\r\n\t\tcounter0+=1\r\nprint(abs(counter1-counter0))",
"t = int(input())\r\nk = input()\r\ns = k.count('0')\r\nd = k.count('1')\r\nprint(abs(d - s))\r\n \r\n",
"n=int(input())\r\ns=input()\r\none = s.count(\"1\")\r\nzero = s.count(\"0\")\r\nprint(abs(one-zero))",
"n=int(input())\r\na=list(input())\r\ncnt1=0\r\ncnt0=0\r\nfor i in range (n) :\r\n if a[i]=='0' : cnt0+=1\r\n else : cnt1+=1\r\n#print(cnt0, cnt1)\r\nprint( abs(cnt1-cnt0) )",
"\n\n_ = input()\nchaine = input()\n\nu=chaine.count('1')\nprint(abs(len(chaine)-2*u))\n",
"n = int(input())\r\ns = input()\r\nstack = []\r\nstack.append(s[0])\r\nfor i in range(1 , n):\r\n if len(stack) == 0:\r\n stack.append(s[i])\r\n elif stack[len(stack) - 1] == '0' and s[i] == '1':\r\n stack.pop()\r\n elif stack[len(stack) - 1] == '1' and s[i] == '0':\r\n stack.pop()\r\n else:\r\n stack.append(s[i])\r\nprint(len(stack))",
"_ = input()\r\ns = input()\r\nprint (len(s) - min(s.count(\"0\"), s.count(\"1\")) * 2)\r\n",
"n = int(input())\r\ns = str(input())\r\ncnt = min(s.count('0'),s.count('1'))\r\nprint(n-(2*cnt))",
"a = int(input())\r\nb = list(input())\r\nb0 = b.count('0')\r\nb1 = b.count('1')\r\nif b0 > b1:\r\n print(b0-b1)\r\nelif b1 > b0:\r\n print(b1 - b0)\r\nelse:\r\n print(0)",
"a = input()\r\nb= input()\r\n\r\nprint(abs(b.count(\"0\")-b.count(\"1\")))",
"n=int(input())\r\ns=input()\r\nstk=[]\r\nfor i in s:\r\n if not stk:\r\n stk.append(i)\r\n else:\r\n if stk[-1]!=i:\r\n stk.pop()\r\n else:\r\n stk.append(i)\r\nprint(len(stk))",
"nLen = int(input())\r\nn = input()\r\nn0 = n.count('0')\r\nn1 = n.count('1')\r\nnT = n0 + n1\r\nif nLen == nT:\r\n if n0 > n1:\r\n nT = nT - (n1 * 2)\r\n elif n0 < n1:\r\n nT = nT - (n0 * 2)\r\n elif n0 == n1:\r\n nT = 0\r\n print(nT)\r\n",
"def main():\r\n n = int(input())\r\n string = [int(x) for x in list(input())]\r\n ans = 0\r\n for i in string:\r\n if i:\r\n ans += 1\r\n else:\r\n ans -= 1\r\n\r\n print(abs(ans))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()",
"n=int(input())\r\ns=input()\r\none=0\r\nzero=0\r\nfor i in range(len(s)):\r\n if s[i]=='1':\r\n one+=1\r\n else:\r\n zero+=1\r\nprint(len(s)-(2*min(one,zero)))",
"total=int(input())\r\nlista=input()\r\n\r\nos=int(lista.count(\"0\"))\r\nais=int(lista.count(\"1\"))\r\nif ais>=os:\r\n print(total-(2*os))\r\nelse:\r\n print(total-(2*ais))\r\n\r\n",
"n=int(input())\r\nst=list(input())\r\nzero=st.count('0') \r\none=st.count('1') \r\nprint(max(zero,one)-min(zero,one))\r\n",
"entrada = int(input())\r\nseq = input()\r\n \r\nzero = 0\r\num = 0\r\n \r\nfor e in seq:\r\n\tif e == \"1\":\r\n\t\tum += 1\r\n\telif e == \"0\":\r\n\t\tzero += 1\r\n\t\r\nprint(abs(zero - um))\r\n ",
"n = int(input())\r\ns = str(input())\r\nzeroes = s.count('0')\r\nones = s.count('1')\r\nprint(len(s) - 2 * min(zeroes, ones))\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
"n = int(input())\r\ns = input()\r\nones = 0\r\nzeros = 0\r\nfor c in s:\r\n if c == '1':\r\n ones += 1\r\n else:\r\n zeros += 1\r\nprint(n - 2*min(ones, zeros))",
"n=int(input())\r\nm=[int(i) for i in input()]\r\nprint(abs(m.count(0)-m.count(1)))",
"numero = int(input())\nlista = input()\n\ni = 0\n\nnum1 = 0\nnum0 = 0\nwhile i < len(lista):\n if(lista[i] == \"1\"):\n num1 += 1\n else:\n num0 += 1\n i+=1\n \n\nif(num1 > num0):\n saida = num1 - num0\nelse:\n saida = num0 - num1\n\nprint(saida)\n \t\t \t \t\t \t\t \t\t \t",
"from itertools import combinations\r\n\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n s = input()\r\n print(abs(s.count('1') - s.count('0')))\r\n\r\n",
"n = int(input())\r\nm = input()\r\none = m.count(\"1\")\r\nzero = m.count(\"0\")\r\nprint(abs(one-zero))",
"input()\r\nl=input()\r\nprint(abs(l.count(\"0\")-l.count(\"1\")))\r\n",
"n = int(input())\r\na = input()\r\n\r\na = sorted(a)\r\n\r\nb = a.count(\"1\")\r\nd = a.count(\"0\")\r\n\r\ncount = 0\r\n\r\nif (b == d):\r\n count = 0\r\nelif (b > d and d > 0):\r\n while (b != d):\r\n b -= 1\r\n count += 1\r\nelif (d > b and b > 0):\r\n while (d != b):\r\n d -= 1\r\n count += 1\r\nelif (b == 0 or d == 0):\r\n count = len(a)\r\n \r\nprint(count)",
"n=int(input())\r\na=list(map(int,input().strip()))\r\nzero=0\r\none=0\r\nfor i in a:\r\n if i%2==0:\r\n zero+=1\r\n else:\r\n one+=1\r\nprint(abs(zero-one))",
"n=int(input())\r\ns=input()\r\nprint(len(s)-2*min(s.count('1'),s.count('0')))",
"n = int(input())\r\ns = input()\r\nzero,one=0,0\r\nfor i in s:\r\n if i == '0':\r\n zero+=1\r\n else :\r\n one += 1\r\n\r\nprint(abs(zero-one))\r\n",
"n=int(input())\r\ns=input()\r\none=s.count('1')\r\nzero=s.count('0')\r\nprint(n-2*min(one,zero))",
"n = int(input())\r\ns = input()\r\nm = min(s.count('1'),s.count('0'))\r\nprint(n-2*m)",
"def main(s):\r\n\tzer = 0\r\n\tones = 0\r\n\r\n\tfor i in s:\r\n\t\tif i == '1':\r\n\t\t\tones+=1\r\n\t\telse:\r\n\t\t\tzer+=1\r\n\treturn max(zer, ones) - min(zer, ones)\r\n\r\n\t\r\n\r\n\r\n\r\nif __name__=='__main__':\r\n\tn = int(input())\r\n\ts = input()\r\n\tprint(main(s))\r\n\t\r\n\r\n\r\n\r\n",
"n=int(input())\r\ns=input()\r\nc1=0\r\nc0=0\r\nfor i in s:\r\n if i==\"1\":\r\n c1=c1+1\r\n else:\r\n c0=c0+1\r\nprint(abs(c1-c0))",
"n = int(input())\r\nl = input()\r\none = 0\r\nzero = 0\r\nfor i in range(0,n):\r\n if l[i] == '1':\r\n one += 1\r\n else:\r\n zero += 1\r\nif one > zero:\r\n print(one-zero)\r\nelif one < zero:\r\n print(zero-one)\r\nelse:\r\n print('0')",
"n=int(input())\r\nstr1=input()\r\na=str1.count('1')\r\nb=str1.count('0')\r\nprint(abs(a-b))",
"n = int(input())\na = input()\nj = 0\nk = 0\nfor i in range(len(a)):\n if a[i] == \"1\":\n j += 1\n else:\n k += 1\nprint(abs(j - k))",
"z = input()\r\nx = input()\r\nif \"0\" in x and \"1\" in x:\r\n zes = x.count(\"0\")\r\n ons = x.count(\"1\")\r\n if zes<ons:\r\n print(len(x)-(zes*2))\r\n elif ons<zes:\r\n print(len(x)-(ons*2))\r\n else:\r\n print(0)\r\nelse:\r\n print(len(x))",
"import re\r\nx = int(input())\r\ny = input()\r\na = \" \".join(y)\r\nh = re.split(r\"\\s\", a)\r\nc = 0\r\nfor i in h:\r\n if i == '0':\r\n c += 2\r\nprint(abs(x - c))",
"n = int(input())\r\ns = input()\r\nzeros = s.count('0')\r\nones = s.count('1')\r\npairs = 2 * min( zeros, ones )\r\nprint( zeros + ones - pairs )",
"n = int(input())\r\ns = input()\r\nones = s.count('1')\r\nzeros = s.count('0')\r\nprint(n-2*min(ones, zeros)) ",
"# Wadea #\r\n\r\nn = int(input())\r\nm = str(input())\r\nlst = []\r\nfor i in m:\r\n lst += i\r\no = \"0\"\r\nl = \"1\"\r\nq = 0\r\nw = 0\r\nfor j in lst:\r\n if j == o:\r\n q += 1\r\n else:w += 1\r\n\r\nif q > w:\r\n print(q - w)\r\nelif q < w:\r\n print(w - q)\r\nelse:print(\"0\")\r\n",
"n=int(input())\r\na=input()\r\nm=min(a.count(\"1\"),a.count(\"0\"))\r\nprint(n-(m*2))\r\n",
"def solve():\r\n x = int(input())\r\n s = input()\r\n print(x-min(s.count('0'), s.count('1'))*2)\r\n\r\n\r\n# t = int(input())\r\nt = 1\r\nwhile t:\r\n solve()\r\n t -= 1\r\n",
"import sys\ninput = sys.stdin.readline\n\nSTR_LEN = int(input())\nSTR = input().rstrip()\n\ndelNum = 0\nst = []\nfor c in STR :\n if c == \"0\" :\n if st and st[0] == \"1\" :\n st.pop()\n delNum += 2\n else :\n st.append(c)\n\n else :\n if st and st[0] == \"0\" :\n st.pop()\n delNum += 2\n else :\n st.append(c)\nprint(STR_LEN - delNum)\n",
"n = int(input())\r\ns = input()\r\nstack = []\r\nfor i in range(n):\r\n d = int(s[i])\r\n if len(stack) == 0 or stack[-1] == d:\r\n stack.append(d)\r\n else:\r\n del stack[-1]\r\nprint(len(stack))\r\n",
"n = int(input())\r\nline = input()\r\n\r\nzeros = line.count(\"0\")\r\nones = line.count(\"1\")\r\n\r\nremove = 2 * min(ones, zeros)\r\n\r\nnew_len = n - remove\r\n\r\nprint(new_len)",
"l, n = input(), input()\r\no = n.count(\"1\")\r\nz = n.count(\"0\")\r\nprint(int(l)-2*min(z, o))",
"n=int(input())\r\ns=input()\r\nd=0\r\nm=0\r\nfor i in s:\r\n if int(i)==0:\r\n d+=1\r\n else:\r\n m+=1\r\nif d==m:\r\n print(\"0\")\r\nelse:\r\n r=abs(d-m)\r\n print(r)\r\n \r\n",
"n = int(input())\r\nm = input()\r\ni = m.count(\"0\")\r\nj = m.count(\"1\")\r\nprint(abs(i-j))",
"n=int(input())\r\ns=input()\r\nc0=c1=0\r\nfor z in s:\r\n if z==\"0\":\r\n c0+=1\r\n else :\r\n c1+=1\r\nprint(n-(min(c0,c1)*2))",
"from pickletools import stringnl\nimport sys\nif __name__ == \"__main__\":\n _ = sys.stdin.readline()\n string = sys.stdin.readline()\n stk0 = stk1 = 0\n for char in string:\n if char == \"0\"and stk1 == 0: stk0 += 1\n elif char == \"0\" and stk1 != 0: stk1 -= 1\n elif char == \"1\" and stk0 == 0: stk1 += 1\n elif char == \"1\" and stk0 != 0: stk0 -= 1\n print(stk0 + stk1)",
"def zeros_ones(size):\n s = input()\n count_ones = 0\n count_zero = 0\n for i in range(size):\n if s[i] == '0':\n count_zero += 1\n else:\n count_ones += 1\n if count_zero > count_ones:\n size = size - (count_ones * 2)\n else:\n size = size - (count_zero * 2)\n return size\n\n\ndef main():\n size = int(input())\n print(zeros_ones(size))\n\nmain()\n\n",
"_ = input()\n\nstring = input()\n\nopposite = {\"1\": \"0\", \"0\": \"1\"}\n\n\ndef func(string):\n string = list(string)\n new_string = []\n for d in string:\n if new_string and new_string[-1] == opposite[d]:\n new_string.pop()\n else:\n new_string.append(d)\n\n return len(new_string)\n\nprint(func(string))\n",
"n = int(input())\r\n\r\ns = input()\r\np = ''\r\nq = ''\r\ntemp = 0\r\nx = s.count('0')\r\ny = s.count('1')\r\n\r\nprint(abs(x-y))",
"n=int(input())\r\nd=[int(i) for i in input()]\r\nones=d.count(0)\r\nzeros=d.count(1)\r\nwhile zeros>0 or ones>0 : \r\n zeros-=1\r\n ones-=1 \r\nprint(abs(zeros+ones))",
"n = int(input())\r\nword = input()\r\nprint(abs(word.count('0')-word.count('1')))",
"input()\r\nline = input()\r\n\r\nzeroes = line.count(\"0\")\r\nones = line.count(\"1\")\r\n\r\nprint(abs(zeroes-ones))",
"n=int(input())\r\narr=input()\r\nc=0\r\nd=0\r\nfor i in arr:\r\n if i=='1':\r\n c+=1\r\n else:\r\n d+=1\r\nprint(abs(c-d))\r\n",
"l = int(input(\"\"))\nzo = input(\"\")\n\nzo = list(zo)\n\n\n\"\"\"\nindx = 0\n\nwhile \"1\" in zo and \"0\" in zo and len(zo) >= 2:\n if zo[indx+1] != zo[indx]:\n # Pop it twice cause \n zo.pop(indx)\n zo.pop(indx)\n indx = 0\n else:\n indx+=1\n\nprint(len(zo))\n\n\"\"\"\n\n\nzero = zo.count(\"0\")\none = zo.count(\"1\")\n\nif zero > one:\n print(len(zo)-(one*2))\nelif one > zero:\n print(len(zo)-(zero*2))\nelse:\n print(0)",
"n = int (input ())\r\nstring = input ()\r\nzeroes = ones = 0\r\nfor char in string:\r\n if char == '0':\r\n zeroes += 1\r\n else:\r\n ones += 1\r\nprint (n - min (zeroes, ones) * 2)\r\n",
"n = int(input())\r\ns = input()\r\nc1=0\r\nc0=0\r\nfor i in range(len(s)):\r\n if(s[i]=='0'):\r\n c0+=1\r\n else:\r\n c1+=1\r\nprint(abs(c0-c1))",
"n = int(input())\r\nstr1 = input()\r\n# If there are odd number of zeroes then there will be one zero at the end\r\n# Same goes for 1\r\nx=[]\r\nfor i in str1:\r\n x.append(i)\r\nzero = x.count('0')\r\none = x.count('1')\r\nprint(abs(zero-one))\r\n",
"print(abs(int(input())-2*list(input()).count('0')))",
"numero = int(input())\r\npalavra = input()\r\nquantidade_zero = 0\r\nquantidade_um = 0\r\n\r\nfor i in range(len(palavra)):\r\n if (palavra[i] == \"0\"):\r\n quantidade_zero += 1\r\n else:\r\n quantidade_um += 1\r\n\r\nif (quantidade_zero >= quantidade_um):\r\n print(quantidade_zero - quantidade_um)\r\nelse:\r\n print(quantidade_um - quantidade_zero)",
"_ = input()\ns = input()\nprint (len(s) - min(s.count(\"0\"), s.count(\"1\")) * 2)",
"n = int(input())\r\ns = input()\r\nz = 0\r\no = 0\r\nfor i in range(n):\r\n if s[i] == '0':\r\n z+=1\r\n elif s[i] == '1':\r\n o+=1\r\nprint(int(abs(z-o)))",
"a = int(input())\r\nc = input()\r\n\r\nd1 = c.count(\"1\")\r\nd2 = c.count(\"0\")\r\n\r\nprint(abs(d1-d2))\r\n\r\n# for i in range(d):\r\n# if c.find(\"10\") != -1:\r\n# c = c.replace(\"10\",\"\")\r\n# elif c.find(\"01\") != -1:\r\n# c = c.replace(\"01\", \"\")\r\n\r\n# print(len(c))",
"n = int(input())\r\nstring = input()\r\none = string.count('1')\r\nzero = string.count('0')\r\nif(one == zero):\r\n print(0)\r\nelif(one != zero):\r\n print(abs(zero - one))\r\n",
"n=int(input())\nx=input()\ncount0=0\ncount1=0\nfor i in x:\n if i==\"1\":\n count1+=1\n else:\n count0+=1\nif count1>count0:\n print(count1-count0)\nelse:\n print(count0-count1)\n\n\t \t\t\t\t \t \t \t \t\t \t\t\t\t\t \t \t",
"n = int(input())\r\nstring = input()\r\n\r\nprint(abs(string.count('0') - string.count('1')))\r\n",
"n = int(input())\r\nm = input()\r\nv = m.replace(\"0\",\"\")\r\nd = m.replace(\"1\",\"\")\r\nprint(len(m)-(min(len(v),len(d)) * 2))",
"n = int(input())\r\ns = input()\r\nzero = s.count(\"0\")\r\none = s.count(\"1\")\r\nprint(abs(zero-one))",
"from collections import Counter\r\n\r\n_ = input()\r\ns = input()\r\nvls = dict(Counter(s))\r\nif '1' not in s or '0' not in s:\r\n print(len(s))\r\nelif vls['1'] == vls['0']:\r\n print(0)\r\nelse:\r\n print(abs(vls['1'] - vls['0']))\r\n",
"l = int(input())\r\ns = input()\r\ncnt0 = 0 \r\ncnt1 = 0\r\n\r\nfor i in s:\r\n if i == '1':\r\n cnt1 += 1 \r\n else:\r\n cnt0 += 1\r\nprint(l - (min(cnt0, cnt1)*2))",
"n = int(input())\r\ns = input()\r\nprint(n - 2 * min(s.count(\"0\"), s.count(\"1\")))",
"input()\r\ns=input()\r\nprint(abs(s.count('0')-s.count('1')))",
"n = int(input())\r\nst = input()\r\nif st.count('0') == st.count('1'): \r\n print(0)\r\nelse: \r\n print(abs(st.count('0')-st.count('1')))\r\n",
"a = int(input())\nentrada = input()\nlista = []\nfor i in range(len(entrada)):\n lista.append(entrada[i])\n\num = 0\nzero = 0\n\nfor i in range(len(lista)):\n if (lista[i] == '1'):\n um += 1\n if (lista[i] == '0'):\n zero += 1\n\nprint(abs(um-zero))\n \t \t \t\t \t\t\t\t \t \t\t\t \t \t",
"n = int(input())\r\ns = input()\r\nceros = s.count('0')\r\nunos = s.count('1')\r\nprint(abs(ceros-unos))\r\n",
"print( abs( int(input()) - 2*input().count('1') ))",
"n = int(input())\r\na = [int(i) for i in input()]\r\nx = a.count(0)\r\ny = a.count(1)\r\nprint(abs(x - y))",
"tam = int(input())\r\nnums = list(input())\r\n\r\nrestam = tam\r\nzeros, uns = 0, 0\r\n\r\nfor i in range(tam):\r\n if nums[i] == \"1\": uns += 1\r\n else: zeros += 1\r\n\r\nans = restam - 2 * min(zeros, uns)\r\nprint(ans)",
"n=int(input())\r\nb=input()\r\nones=b.count(\"1\")\r\nzeros=b.count(\"0\")\r\nunion=min(ones,zeros)\r\nrez=max(ones-zeros,zeros-ones)\r\nprint(rez)",
"n = int(input())\r\nt = str(input())\r\nq = t.count(\"1\")\r\nw = t.count(\"0\")\r\nprint(abs(q-w))",
"n=int(input())\r\ns=input(\"\")\r\nl=s.count(\"1\")\r\nk=s.count(\"0\")\r\nprint(abs(l-k))",
"n = int(input())\n\nline = str(input())\n\nline1 = ''.join(sorted(line))\n\nif (line1 == line ) and (line1.find('1') == -1 or line1.find('0') == -1):\n\tprint(len(line))\n\texit()\n\nidx = line1.find('1')\nprint(abs(n - 2*idx))\n\n# print(line)\n\n\t\n\n\n\n\t\n\n\n",
"n=int(input())\r\ns=input()\r\nc1=s.count('1')\r\nc2=s.count('0')\r\nif c1==c2:\r\n print('0')\r\nelif c1>c2:\r\n print(n-(2*c2))\r\nelse:\r\n print(n-(2*c1))",
"n = int(input())\r\ns = input()\r\n\r\ns0 = sum([1 if i == '0' else 0 for i in s])\r\ns1 = sum([1 if i == '1' else 0 for i in s])\r\n\r\nans = abs(s0 - s1)\r\nprint(ans)",
"n = int(input())\r\nnumbers = list(input())\r\n\r\nc0 = numbers.count(\"0\")\r\nc1 = numbers.count(\"1\")\r\n\r\nprint(max(c0, c1)-min(c0, c1))\r\n",
"n = int(input())\nstring = input()\n\ncont = 0\nfor s in string:\n if s == \"1\":\n cont += 1\n\nresult = abs(n - (cont * 2))\nprint(result)\n \t \t \t \t \t\t \t \t \t\t\t \t",
"n = int(input())\ns = input()\nstek = []\nfor i in range(len(s)):\n stek.append(s[i])\n if len(stek) >= 2:\n if stek[-1] != stek[-2]:\n stek.pop()\n stek.pop()\n\nprint(len(stek))",
"n = int(input())\r\ns= input()\r\nprint(abs(n-s.count('0')*2))",
"n = int(input())\r\nlst = []\r\nlst += input()\r\nres = n - 2 * min(lst.count(\"1\"), lst.count(\"0\"))\r\nprint(res)\r\n",
"n=int(input())\r\ns=input()\r\no=s.count('1')\r\nz=n-o\r\nprint(abs(o-z))",
"def Sol():\r\n t = int(input())\r\n s = list(input())\r\n \r\n n1 = s.count(\"1\")\r\n n0 = s.count(\"0\")\r\n print(abs(n1-n0))\r\n \r\n \r\nif __name__ == \"__main__\":\r\n Sol()\r\n ",
"n=int(input())\r\nl=list(input())\r\nc=l.count('0')\r\nprint(abs((n-2*c)))\r\n \r\n ",
"length_of_string = int(input())\ns = input()\n\nprint(length_of_string - 2 * min(s.count('0'), s.count('1')))",
"n = int(input())\r\nx = input()\r\nans = min(x.count(\"1\"), x.count(\"0\"))*2\r\nprint(n - ans)\r\n",
"input()\nbinario = input()\nprint(abs(binario.count('1') - binario.count('0')))\n",
"n=int(input())\r\ns=input()\r\nx,y=s.count('1'),s.count('0')\r\nprint(abs(x-y))",
"n=int(input())\r\ns=input()\r\ns1,s0=0,0\r\nfor i in s:\r\n if i==\"1\":\r\n s1+=1\r\n else:\r\n s0+=1\r\nremv=min(s1,s0)\r\nprint(n-remv*2)",
"n = int(input())\r\ns = input()\r\n\r\nones = s.count(\"1\")\r\nzeros = s.count(\"0\")\r\n\r\nif ones < zeros:\r\n print(len(s)-ones * 2)\r\nelse:\r\n print(len(s)-zeros * 2)\r\n\r\n",
"a=int(input())\r\nb=input()\r\nprint(a-min(b.count(\"0\"),b.count(\"1\"))*2)",
"n=int(input())\r\ns=input()\r\nres=0\r\nones=0\r\nzeros=0\r\n\r\nfor i in range(n):\r\n if s[i]=='1':\r\n ones+=1\r\n else:\r\n zeros+=1\r\n\r\n\r\nprint(abs(ones-zeros))",
"n = int(input())\r\nstring = input()\r\n\r\nprint(len(string) - (min(string.count(\"1\"), string.count(\"0\")) * 2))\r\n",
"t = int(input())\r\nstring = input()\r\none = string.count('1')\r\nzero = string.count('0')\r\nif (one>zero):\r\n many = zero*2\r\n print(t-many)\r\nelif(zero>one):\r\n many = one*2\r\n print(t-many)\r\nelse:\r\n print(0)",
"n = int(input())\r\ns = input()\r\n\r\nones = s.count(\"1\")\r\nzeros = s.count(\"0\")\r\n\r\nprint(len(s)-min(ones , zeros) * 2)\r\n",
"n=int(input())\r\ns=input()\r\nprint(abs(n-2*(s.count('1'))))\r\n",
"n=int(input())\r\nlst=input()\r\nm=0\r\nk=0\r\nfor i in range(0,n):\r\n if lst[i]==\"0\":\r\n k+=1\r\n else:\r\n m+=1\r\nprint(abs(m-k))\r\n",
"n = int(input())\r\ns = input()\r\nzeros = s.count('0')\r\nones = s.count('1')\r\nans = n - 2 * min(zeros, ones)\r\nprint(ans)\r\n",
"n = int(input())\r\nst = input()\r\none = 0\r\nzero = 0\r\nfor i in range(n):\r\n if st[i] == '1':\r\n one += 1\r\n elif st[i] == '0':\r\n zero += 1\r\nprint(n - min(one, zero) * 2)",
"n = int(input(\"\"))\nstring = input(\"\")\n\nzero_count = 0\none_count = 0\n\nfor i in range(0, len(string)):\n if string[i] == \"0\":\n zero_count = zero_count + 1\n else:\n one_count = one_count + 1\n\n\nprint(max(zero_count - one_count, one_count - zero_count))\n",
"from sys import stdin, stdout\n\n\ndef input():\n return stdin.readline().strip()\n\n\ndef print(string):\n return stdout.write(str(string) + \"\\n\")\n\n\ndef main():\n n = int(input())\n m = n - input().count(\"1\")\n print(n - min(m, n - m) * 2)\n\n\nif __name__ == \"__main__\":\n main()\n",
"n = int(input())\n\ns = list(input())\n\nans = [s[0]]\n\nfor i in range(1, n):\n ans.append(s[i])\n \n if len(ans) > 1:\n if (ans[-1] == '0' and ans[-2] == '1') or (ans[-1] == '1' and ans[-2] == '0'):\n ans.pop()\n ans.pop()\n\nprint(len(ans))\n\n \t\t\t\t\t \t\t \t \t \t \t",
"length_string = int(input())\r\nString = input()\r\ncount_0 = String.count('0')\r\ncount_1 = String.count('1')\r\nif count_0 > count_1:\r\n print(count_0-count_1)\r\nelif count_0 < count_1:\r\n print(count_1-count_0)\r\nelse:\r\n print(0)\r\n",
"n = int(input())\r\na = input()\r\nx = a.count(\"1\")\r\ny = n - x\r\nprint(abs(x-y))",
"def main(s):\r\n n, m = 0, 0\r\n\r\n for i in range(len(s)):\r\n if s[i] == \"0\":\r\n if m > 0:\r\n n -= 1\r\n m -= 1\r\n n += 1\r\n elif s[i] == \"1\":\r\n if n > 0:\r\n n -= 1\r\n m -= 1\r\n m += 1\r\n\r\n return n + m\r\n\r\nif __name__ == \"__main__\":\r\n _ = int(input())\r\n\r\n s = input()\r\n\r\n print(main(s))",
"n = int(input())\r\nst = input()\r\nc0=0\r\nc1=0\r\nfor i in st:\r\n if i=='1':\r\n c1 += 1\r\n else:\r\n c0 += 1\r\nprint(abs(c0-c1))",
"number = int(input())\r\ntotal = input()\r\nprint(number - 2 + 2 - 2 * min(total.count('0'), total.count('1')))",
"n=int(input())\ns=str(input())\nc=0\nd=0\nfor i in range(n):\n if s[i]=='1':\n c=c+1\n else:\n d=d+1\nprint(abs(c-d))\n \t \t \t\t \t\t \t\t\t\t\t\t\t",
"b= input()\r\nn = input()\r\nprint(abs(int(n.count('1')-n.count('0'))))",
"n = int(input())\nk = input()\n# while(k.count('10')>0 or k.count('01') >0) :\n# k = k.replace('01', '')\n# if len(k) == k.count('1') or len(k) == k.count('0'):\n# break\nzero = k.count('0')\nones = k.count('1')\nminn = min(zero, ones)\nprint(len(k) - 2*minn)",
"n=int(input())\ns=input()\ncount=0\ntest=0\nfor i in range(n):\n\tif s[i]=='0':\n\t\tif test<0:\n\t\t\tcount+=1\n\t\ttest+=1\n\telse:\n\t\t#print(test)\n\t\tif test>0:\n\t\t\tcount+=1\n\t\ttest-=1\nprint(n-count*2)\n\t\t\t",
"n = int(input())\r\ns = input()\r\nn0 = s.count(\"0\")\r\nn1 = s.count(\"1\")\r\nprint(abs(n0-n1))\r\n",
"def Count(Str):\r\n Count1,Count0 = 0,0\r\n for x in Str:\r\n if x == '1':\r\n Count1 = Count1 + 1\r\n elif x == '0':\r\n Count0 = Count0 + 1\r\n if Count1 >= Count0 :\r\n return (Count1 - Count0)\r\n else:\r\n return ( Count0 - Count1)\r\n \r\n \r\nN = int(input())\r\nStr = input()\r\nprint(Count(Str))",
"import math\r\ndef stringfetis(s):\r\n alist=[int(d) for d in s]\r\n return abs(alist.count(1)-alist.count(0))\r\nf=int(input())\r\nj=input()\r\nprint(stringfetis(j))",
"n = int(input(\"\"))\r\ns = input(\"\")\r\nttl = len(s)\r\nsub = 0\r\n\r\nif \"0\" and \"1\" in s:\r\n count_0 = s.count(\"0\")\r\n count_1 = s.count(\"1\")\r\n if count_0 < count_1:\r\n sub = count_0\r\n else:\r\n sub = count_1\r\n\r\nprint(ttl-(sub*2))",
"n=int(input())\r\ns=str(input())\r\nzero=0\r\none=0\r\nfor i in range(n):\r\n if(s[i]=='0'):\r\n zero=zero+1\r\n else:\r\n one=one+1\r\nprint(abs(zero-one)) \r\n",
"n = int(input())\r\ns = input()\r\nprint(len(s) - 2 * min(s.count('1'), s.count('0')))\r\n",
"n=int(input())\r\ns=input()\r\n\r\nz=s.count('0')\r\n\r\no=s.count('1')\r\n\r\nprint(abs(o-z))",
"\n\nn = int(input())\nval = input()\n\nodd = 0\nfor ch in val:\n if ch==\"1\":\n odd+=1\nprint(n-min(odd,n-odd)*2)\n\t \t\t \t \t \t\t \t \t\t\t \t\t\t\t\t \t\t",
"\r\nimport sys\r\ndef get_single_int ():\r\n return int (sys.stdin.readline ().strip ())\r\ndef get_string ():\r\n return sys.stdin.readline ().strip ()\r\ndef get_ints ():\r\n return map (int, sys.stdin.readline ().strip ().split ())\r\ndef get_list ():\r\n return list (map (int, sys.stdin.readline ().strip ().split ()))\r\n\r\n#code starts here\r\nn = get_single_int ()\r\ns = get_string ()\r\ncount_zero = 0\r\ncount_odd = 0\r\nfor i in range (n):\r\n if s [i] == '0':\r\n count_zero += 1\r\n else:\r\n count_odd += 1\r\nprint (n - 2*(min (count_odd,count_zero)))\r\n",
"print(abs(int(input())-2*input().count('0')))",
"length = int(input())\r\none = 0\r\nzero = 0\r\n\r\nfor num in input() : \r\n if num == \"1\" : one += 1\r\n else : zero += 1\r\n \r\nprint(length - (min([zero , one]) * 2)) ",
"n = int(input())\nstring = input()\nx = string.count('1')\ny = string.count('0')\nprint(abs(x-y))\n\n \t \t\t \t\t \t \t \t\t\t\t\t \t\t\t\t\t \t",
"x = input()\r\ny = list(map(int,input()))\r\n\r\na = y.count(0)\r\nb = y.count(1)\r\n\r\nprint(abs(a-b))",
"entrada = int(input())\nnumeros = input()\nqtdZero = 0\nqtdUm = 0\nresultado = 0\nfor i in numeros:\n if i == '0':\n qtdZero +=1\n else:\n qtdUm +=1\n\nif qtdZero == qtdUm:\n print(resultado)\nelse:\n if qtdUm > qtdZero:\n resultado = qtdUm - qtdZero\n print(resultado)\n else:\n resultado = qtdZero - qtdUm\n print(resultado)\n \t \t\t\t\t \t\t \t \t\t\t\t\t\t \t",
"numero = int(input())\npalavra = input()\nquantidade_zero = 0\nquantidade_um = 0\n\nfor i in range(len(palavra)):\n if (palavra[i] == \"0\"):\n quantidade_zero += 1\n else:\n quantidade_um += 1\n\nif (quantidade_zero >= quantidade_um):\n print(quantidade_zero - quantidade_um)\nelse:\n print(quantidade_um - quantidade_zero)\n \t\t \t \t \t \t\t \t \t \t\t\t\t",
"input()\r\ns = input()\r\n\r\nprint(len(s) - 2 * min(s.count('0'), s.count('1')))\r\n",
"n1 = int(input())\r\nn2 = input()\r\n\r\ncount_0 = 0\r\ncount_1 = 0\r\nfor i in n2:\r\n if i == \"0\":\r\n count_0 += 1\r\n else:\r\n count_1 += 1\r\n\r\nprint(n1 - 2*min(count_1,count_0))",
"from sys import stdin, stdout\r\nn = int(stdin.readline())\r\ngiven_string = stdin.readline().strip()\r\npairs = 0\r\ncount_dict = {\"1\":0, \"0\":0}\r\nfor j in given_string:\r\n if j==\"1\":\r\n count_dict[\"1\"]+=1\r\n else:\r\n count_dict[\"0\"]+=1\r\nmin_one = n+1\r\nfor j in count_dict.values():\r\n if j<min_one:\r\n min_one = j\r\nstdout.write(f\"{n - 2*min_one}\\n\")\r\n ",
"n = int(input())\r\nst = input()\r\none = st.count(\"1\")\r\nzero = st.count(\"0\")\r\nif one>=zero:\r\n print(one-zero)\r\nelse:\r\n print(zero-one)\r\n",
"n = int(input())\nzeros = input().count('0')\nrm = min(zeros,n-zeros) * 2\nprint(n-rm)\n",
"x=input()\ny=input()\nc1=0\nc0=0\nfor i in range(int(x)):\n if int(y[i])==0:\n c0+=1\n else:\n c1+=1\nprint(abs(c1-c0))\n\n \t\t \t\t\t\t \t\t \t\t \t \t\t\t\t \t\t \t",
"x = input(); y = input()\r\n\r\nones = y.count('1')\r\nzero = y.count('0')\r\n\r\nprint(abs(ones-zero))",
"n=int(input())\r\na=input()\r\nprint(n-(min(a.count(\"1\"),a.count(\"0\"))*2))",
"t = int(input())\r\nstr1 = input()\r\nc1 = str1.count(\"1\")\r\nc0 = str1.count(\"0\")\r\nif(c1>c0):\r\n r = c1-c0\r\nelse:\r\n r = c0 - c1\r\nprint(r)",
"n = int(input())\r\nstr = input()\r\none = str.count('1')\r\nzero = str.count('0')\r\nprint(len(str)-min(zero,one)*2)",
"a = int(input())\r\nw = input()\r\nprint(a-2*(min(w.count('1'),w.count('0'))))",
"n=int(input())\r\nx=input()\r\n'''i=0\r\nwhile i<len(x)-1:\r\n if x[i]+x[i+1]==\"10\" or x[i]+x[i+1]==\"01\":\r\n x=x[0:i]+x[i+2:]\r\n i=i-1\r\n continue\r\n i=i+1\r\nprint(len(x))'''\r\ncount0,count1=0,0\r\nfor i in x:\r\n if i==\"0\":\r\n count0=count0+1\r\n if i==\"1\":\r\n count1=count1+1\r\nif count0==count1 and count0+count1==n:\r\n print(0)\r\nelif count0==count1:\r\n print(n-2*count0)\r\nelse:\r\n print(n-2*min(count0,count1))\r\n",
"str_length = int(input())\nzeros_ones = str(input())\n\nprint(abs(str_length - (2 * zeros_ones.count(\"0\"))))\n",
"n=int(input())\r\na=str(input())\r\nzero_count=a.count('0')\r\none_count=a.count('1')\r\nprint(abs(zero_count-one_count))",
"# for _ in range(int(input())):\r\nn = int(input())\r\n# arr = list(map(int, input().split()))\r\narr = list(input())\r\n\r\nans = n\r\nstack = [\"a\"]\r\n\r\nfor i in range(n):\r\n stack.append(arr[i])\r\n\r\n if (stack[-1] == \"0\" and stack[-2] == \"1\") or (stack[-1] == \"1\" and stack[-2] == \"0\"):\r\n ans -= 2\r\n stack.pop()\r\n stack.pop()\r\n\r\nprint(ans)",
"from collections import Counter\r\na = int(input())\r\ng = input(); b = tuple(Counter(g).values())\r\ntry:\r\n\tc, d = b[0], b[1]\r\n\tprint(abs(c-d))\r\nexcept:\r\n\tprint(len(g))",
"n = input()\r\nzer_one = input()\r\nprint(abs(zer_one.count(\"0\")-zer_one.count(\"1\")))",
"n = int(input())\r\nk = input()\r\nprint(n-(min(k.count('0'), k.count('1'))*2))",
"a = int(input())\r\nb = input()\r\narr = list(b)\r\ni = 0\r\nz = 0\r\nj = 0\r\nfor i in range(0, len(arr)):\r\n if arr[i] == \"0\":\r\n z =z+ 1\r\n elif arr[i] == \"1\":\r\n j += 1\r\nwynik=abs(z-j)\r\nprint(wynik)\r\n",
"if __name__ == \"__main__\":\r\n n = int(input())\r\n s = list(input())\r\n sum_ones = s.count('1')\r\n sum_zeros = s.count('0')\r\n print(max(sum_ones, sum_zeros)-min(sum_ones, sum_zeros))",
"n=int(input())\r\nnumber=input()\r\na=number.replace('',' ')\r\nb=a[1:-1]\r\nc=b.split()\r\nif c.count('1')>c.count('0'):\r\n print(len(c)-((c.count('0')*2)))\r\nelse:\r\n print(len(c)-((c.count('1')*2)))\r\n\r\n\r\n\r\n",
"n = int(input())\r\nl = list(map(int,input()))\r\nres = []\r\nfor i in l:\r\n if res == []:\r\n res.append(i)\r\n else:\r\n if res[-1] != i:\r\n res.pop()\r\n else:\r\n res.append(i)\r\nprint(len(res)) ",
"a = int(input())\r\nb = input()\r\nones = b.count(\"1\")\r\nzeroes = b.count(\"0\")\r\n\r\nunion = min(ones,zeroes)\r\n\r\n# while \"10\" in b or \"01\" in b:\r\n# b = b.replace(\"10\",'')\r\n# b = b.replace(\"01\",'')\r\n\r\nprint(ones-union + zeroes-union)\r\n",
"l=int(input())\r\ns=input()\r\nz=s.count('0')\r\no=l-z\r\nprint(abs(o-z))",
"n = int(input())\r\nm = input()\r\nans = m .count('0')\r\nans1 = m .count('1')\r\nprint(n - (min(ans ,ans1) * 2))\r\n",
"a=int(input())\r\nb=input()\r\nj=0\r\ne=0\r\nfor i in b:\r\n if i==\"0\":\r\n j=j+1\r\n if i==\"1\":\r\n e=e+1\r\nif j>=e:\r\n print(len(b)-2*e)\r\nelse:\r\n print(len(b)-2*j)",
"input()\r\na=input()\r\nprint(len(a)-(min(a.count('1'),a.count('0'))*2))",
"n=int(input())\r\ns=input()\r\na=s.count('0')\r\nb=s.count('1')\r\nif a>=b:\r\n c=a-b\r\n print(c)\r\nelse:\r\n c=b-a\r\n print(c)",
"from collections import Counter\nn = int(input())\ns = list(input())\nc = Counter(s)\n\nprint(n - 2*min(c[\"0\"],c[\"1\"]))\n",
"n=int(input())\r\ns=input()\r\nc1=c2=0\r\nfor i in range(n):\r\n if s[i]=='0':\r\n c1=c1+1 \r\n else:\r\n c2=c2+1 \r\nprint(n-min(c1,c2)*2) \r\n \r\n ",
"n = input()\r\ns = input()\r\nans = 0\r\nfor i in s:\r\n if i =='0':\r\n ans+=1\r\n else:\r\n ans-=1\r\nprint(abs(ans))",
"def main():\r\n\t#t = int(input())\r\n\t#for _ in range(t):\r\n\tprint(case())\r\n\r\ndef case():\r\n\tn = int(input())\r\n\ts = input()\r\n\ts0 = s.count('0')\r\n\ts1 = s.count('1')\r\n\r\n\treturn n-min(s1,s0)*2\r\n\r\nmain()",
"length = int(input())\n\nbinary_string = str(input())\n\ncount_0 = 0\ncount_1 = 0\n\nfor i in binary_string:\n if (i == '1'):\n count_1 += 1\n\n else:\n count_0 += 1\n\nif (count_1 > count_0):\n print(len(binary_string) - count_0*2)\n\nelse:\n print(len(binary_string) - count_1*2)\n\n",
"n = int(input())\r\narr = [int(i) for i in input()]\r\n\r\nprint(abs(arr.count(1) - arr.count(0)))",
"liczbaLiter = int(input())\r\nnapis = input()\r\nileZer = 0\r\nileJedynek = 0\r\nktoraMniejsza = 0\r\nileLiczbMoznaUsunac = 0\r\nif len(napis) == liczbaLiter:\r\n for x in range(len(napis)):\r\n if napis[x] == '0':\r\n ileZer += 1\r\n elif napis[x] == '1':\r\n ileJedynek += 1\r\n if ileZer <= ileJedynek:\r\n ktoraMniejsza = ileZer\r\n else:\r\n ktoraMniejsza = ileJedynek\r\n ileLiczbMoznaUsunac = 2 * ktoraMniejsza\r\n print(len(napis) - ileLiczbMoznaUsunac)\r\n",
"gp = input()\r\na = input()\r\nstack = []\r\nfor i in a:\r\n if not stack:\r\n stack.append(i)\r\n elif stack[-1] == \"0\":\r\n if i == \"1\":\r\n stack.pop()\r\n else:\r\n stack.append(i)\r\n elif stack[-1] == \"1\":\r\n if i == \"0\":\r\n stack.pop()\r\n else:\r\n stack.append(i)\r\nprint(len(stack))",
"n = int(input())\r\ns = input()\r\nx = s.count('0')\r\ny = n - x\r\nprint(abs(x - y))\r\n",
"n = int(input())\r\nk = input()\r\none = zero = 0\r\nfor i in k:\r\n if i==\"1\":\r\n one+=1\r\n else:\r\n zero+=1\r\nprint(n-2*min(one,zero))",
"a=int(input())\r\ns=input()\r\n\r\ncouple = min(s.count('1'), s.count('0') )\r\nprint(a-couple*2)\r\n",
"# https://codeforces.com/problemset/problem/556/A\r\n#Get min num of 0s or 1s -> max num of pairs (01 or 10)\r\n#len(input_string) - 2*max num of pairs\r\n\r\nn = int(input()) #length of string\r\n\r\ninput_string = input() #eg 1100\r\n\r\nmax_pairs = min([input_string.count('1'), input_string.count('0')])\r\n\r\nprint(n - 2*max_pairs)\r\n",
"\r\n\r\n\r\nn = int(input())\r\n\r\nstring = input()\r\n\r\ncounter_ones = 0\r\ncounter_zeros = 0\r\n\r\nfor char in string:\r\n if char == '0':\r\n counter_zeros += 1\r\n else:\r\n counter_ones += 1\r\n\r\nif counter_zeros == counter_ones:\r\n print(0)\r\nelse:\r\n print(abs(counter_ones - counter_zeros))",
"v1=int(input());v3=input();v2=list(\"\".join(v3));c=v2.count(\"0\");c1=v2.count(\"1\");print(len(v2)-2*min(c,c1))",
"n = int(input())\r\na = input()\r\n\r\nq0 = 0\r\nq1 = 0\r\n\r\nfor e in a:\r\n if e == '0':\r\n q0 += 1\r\n else:\r\n q1 += 1\r\n\r\nprint(abs(q0-q1))",
"#-------------------------------------------------------------------------------\r\n# Name: module1\r\n# Purpose:\r\n#\r\n# Author: vkiefner\r\n#\r\n# Created: 09.05.2023\r\n# Copyright: (c) vkiefner 2023\r\n# Licence: <your licence>\r\n#-------------------------------------------------------------------------------\r\n\r\nn = int(input())\r\nzo = str(input())\r\nzo_lst = list(int(bit) for bit in zo)\r\n\r\nzeros = []\r\nones = []\r\n\r\nfor i in zo_lst:\r\n if i == 0:\r\n zeros.append(i)\r\n else:\r\n ones.append(i)\r\n\r\nif len(zeros)>len(ones):\r\n print(len(zeros)-len(ones))\r\nelif len(zeros)<len(ones):\r\n print(len(ones)-len(zeros))\r\nelse:\r\n print(0)\r\n\r\n",
"n = int(input())\nnumbers = [int(number) for number in input()]\n\n# Time Limit Exceed\n# index = 1\n# while index < len(numbers) :\n#\n# if numbers[index] != numbers[index-1]:\n# numbers.pop(index)\n# numbers.pop(index-1)\n# index = 0\n#\n# else :\n# index += 1\n#\n# print(len(numbers))\n\none_count = 0\nzero_count = 0\n\nfor number in numbers:\n\n if number == 1:\n one_count += 1\n zero_count -= 1\n\n elif number == 0:\n zero_count += 1\n one_count -= 1\n\nprint(max(one_count,zero_count))",
"n=int(input())\r\nk=input()\r\nl=2*k.count('1')\r\nans=abs(n-l)\r\nprint(ans)",
"n = int(input())\r\ns = input()\r\ntotal = 0\r\nfor i in range(n):\r\n if s[i] == \"1\":\r\n total += 1\r\nzeros = n - total\r\nif zeros >= total:\r\n print(zeros - total)\r\nelse:\r\n print(total - zeros)",
"n = int(input())\r\nstr = input()\r\na = str.count('1')\r\nb = str.count('0')\r\nprint(max(a,b)-min(a,b))",
"n=int(input())\r\ns=input()\r\no=s.count('1')\r\nz=s.count('0')\r\nif o>z:\r\n print(o-z)\r\nif z>o:\r\n print(z-o)\r\nif z==o:\r\n print('0')",
"n=int(input())\r\ns=input()\r\no,z=0,0\r\nfor i in s:\r\n if i==\"1\":\r\n o+=1\r\n else:\r\n z+=1\r\nprint(abs(o-z))",
"n = int(input())\r\ns = input()\r\nz = 0\r\no = 0\r\nfor i in s:\r\n if i==\"0\": z+=1\r\n else: o+=1\r\n\r\nprint(max(z,o)-min(z,o))\r\n",
"n=int(input())\nstr1=input()\na=str1.split(str1[-1])\nprint(abs(n-2*(len(a)-1)))\n \t \t\t\t\t \t\t\t\t\t\t \t \t\t\t \t \t\t",
"a=int(input())\r\nstroka=input()\r\ncol_0=0\r\ncol_1=0\r\nfor i in stroka:\r\n if int(i)==0:\r\n col_0+=1\r\n else:\r\n col_1+=1\r\nprint(a-min(col_0,col_1)*2)",
"n=int(input())\r\ns=input()\r\nl=(list(s))\r\no,z=l.count('1'),l.count('0')\r\nif(o==z):\r\n print(0)\r\nelif(o==n or z==n):\r\n print(n)\r\nelse:\r\n print(n-min(o,z)*2)\r\n",
"n = int(input())\r\ns = input()\r\nzero = s.count('0')\r\none = s.count('1')\r\n\r\nans = len(s) - 2*min(zero,one)\r\nprint(ans)",
"num = int(input())\r\ns = input()\r\ns1= s.count('1')\r\ns0= s.count('0')\r\noutput= abs(s1 - s0)\r\nprint(output)",
"import sys\r\nfrom collections import Counter\r\n\r\ndef main():\r\n _, s = sys.stdin.read().strip().split()\r\n c = Counter(s)\r\n return abs(c['1'] - c['0'])\r\n\r\nprint(main())\r\n",
"n=int(input())\r\ns=input()\r\nzero=s.count('0')\r\none=s.count('1')\r\nprint(n-min(zero,one)*2)",
"n = int(input())\r\ns = input()\r\na = 0\r\nb = 0\r\nfor i in range(n):\r\n if s[i] == \"1\" :\r\n a += 1\r\n if s[i] == \"0\" :\r\n b += 1\r\nif b < a :\r\n print( a - b )\r\nelse :\r\n print( b - a )",
"n = int(input())\r\nnum = input()\r\nzeroCount = oneCount = 0\r\n\r\nfor i in range(0, n):\r\n if num[i] == '0':\r\n zeroCount += 1\r\n else:\r\n oneCount += 1\r\n\r\nprint (abs(zeroCount - oneCount))",
"n=int(input())\r\ns=list(input())\r\none=s.count(\"1\")\r\nzero=s.count('0')\r\nprint(abs(one-zero))",
"n=int(input())\r\ns=input()\r\ncount=0\r\nsum=0\r\nfor i in s:\r\n if i==\"0\":\r\n count+=1\r\n else:\r\n sum+=1\r\nprint(n-2*min(sum,count))\r\n\r\n\r\n\r\n",
"n = int(input())\r\ns = input()\r\nzeros = s.count('0')\r\nones = s.count('1')\r\nif zeros != 0 and ones != 0:\r\n d = min(zeros, ones)\r\n print(n - d * 2)\r\nelse:\r\n print(n)\r\n",
"n = int(input())\r\ns = input()\r\n\r\nzeros = s.count('0')\r\nones = s.count('1')\r\n\r\nif zeros == 0 or ones == 0:\r\n print(n)\r\nelse:\r\n print(abs(zeros - ones))",
"num=int(input())\r\ns1=input()\r\nx=s1.count(\"0\")\r\nprint(abs(num-x*2))",
"import re\r\n\r\nn = int(input())\r\nstring = ''.join(sorted(input()))\r\nres = len(string)\r\nif '1' in string:\r\n start_one = string.index('1')\r\n minimum_count = min(len(string[:start_one]), len(string[start_one:]))\r\n res = n - minimum_count*2\r\nprint(res)\r\n",
"n=int(input())\r\ns=list(input())\r\nc1=s.count('1')\r\nc2=s.count('0')\r\nc=min(c1,c2)\r\nprint(n-(2*c))\r\n",
"def main():\r\n n = int(input())\r\n s = list(input())\r\n count_1 = s.count(\"0\")\r\n c_zero = s.count(\"1\")\r\n\r\n x = abs(c_zero - count_1)\r\n print(x)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()",
"l=int(input())\r\nn = input()\r\n\r\nn1=n.count(\"0\")\r\nn2=n.count(\"1\")\r\n\r\nprint(max(n1,n2)-min(n1,n2))",
"#556A Case of the Zeros and Ones\r\nn=int(input())\r\ns=input()\r\nc0=s.count(\"0\")\r\nc1=s.count(\"1\")\r\nif c0>c1:\r\n print(n-c1*2)\r\nelse:\r\n print(n-c0*2)",
"n=int(input())\r\ns=input()\r\nc0=0\r\nc1=0\r\nfor i in s:\r\n if i=='0':\r\n c0+=1\r\n\r\nc1=n-c0\r\nans=abs(c1-c0)\r\nprint(ans)\r\n",
"n = int(input())\r\narr = input()\r\nprint(n - 2 * min(arr.count(\"0\"), arr.count(\"1\")))",
"n = int(input())\r\ns = input()\r\na = s.count('0')\r\nprint(abs(n - 2 * a))\r\n",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Jan 19 15:01:13 2023\r\n\r\n@author: Lenovo\r\n\"\"\"\r\n\r\nn = int(input())\r\ns = input()\r\nzero = 0\r\num = 0\r\nfor i in s:\r\n if i=='0':\r\n zero+=1\r\num = n-zero\r\n\r\nif zero>um:\r\n res = n-2*um\r\n print(res)\r\nelse:\r\n res = n-2*zero\r\n print(res)\r\n ",
"l = int(input(\"\"))\nzo = input(\"\")\n\nzo = list(zo)\n\nzero = zo.count(\"0\")\none = zo.count(\"1\")\n\nif zero > one:\n print(len(zo)-(one*2))\nelif one > zero:\n print(len(zo)-(zero*2))\nelse:\n print(0)",
"\r\nn = int(input())\r\ns = input()\r\n\r\nstack = [] \r\n\r\n\r\nfor i in range(len(s)) :\r\n \r\n if s[i]=='1' :\r\n \r\n if stack and stack[-1]=='0' :\r\n stack.pop()\r\n \r\n else :\r\n stack.append(s[i])\r\n \r\n else :\r\n \r\n if stack and stack[-1]=='1' :\r\n \r\n stack.pop()\r\n \r\n else :\r\n stack.append(s[i])\r\n \r\nprint(len(stack))\r\n \r\n",
"n, string = int(input()), list(map(int, input()))\n\nsaida = []\n\nfor i in string:\n if not saida:\n saida.append(i)\n else:\n if saida[-1] != i:\n saida.pop()\n else:\n saida.append(i)\n\nprint(len(saida))\n\n \t\t \t\t\t\t\t\t\t\t\t \t \t \t\t",
"length = int(input())\r\nstring = str(input())\r\n\r\ndef solution(string):\r\n zeros = string.count(\"0\")\r\n return len(string) - 2 * min(zeros, abs(len(string) - zeros))\r\n \r\n\r\nprint(solution(string))",
"n = int(input())\r\ns = input()\r\none = s.count(\"1\")\r\nzero = s.count(\"0\")\r\nif one > zero:\r\n print(one - zero)\r\nelif zero > one:\r\n print(zero - one)\r\nelse:\r\n print(0)",
"num= int(input())\r\nstr_1= input()\r\nprint(abs(str_1.count(\"1\")-str_1.count(\"0\")))",
"n = int(input())\r\nm = input()\r\none = m.count('1')\r\nzero = m.count('0')\r\nunion = min(one,zero)\r\nprint(max(one-union,zero-union))\r\n",
"n=int(input())\r\ns=input()\r\nz=s.count('0')\r\no=s.count('1')\r\nprint(n-2*min(z,o))",
"# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Apr 13 15:39:39 2023\r\n\r\n@author: Srusty Sahoo\r\n\"\"\"\r\n\r\nn=int(input())\r\ns=input()\r\nz=s.count(\"0\")\r\no=s.count(\"1\")\r\nprint(n-2*min(z,o))",
"n=int(input())\r\ns=input()\r\na=0\r\nb=0\r\nfor i in range (n):\r\n if(s[i]==\"0\"):\r\n a+=1\r\n else:\r\n b+=1\r\nprint(n-2*min(a,b))",
"lstring = int(input())\nzerosandones = input()\n\nzeros = 0\nones = 0\n\nfor i in range(lstring):\n if (zerosandones[i] == '1'):\n ones += 1\n else:\n zeros += 1\n\nprint(lstring - (min(zeros, ones) * 2))\n\n\t \t\t \t \t \t \t\t\t \t \t \t\t",
"input()\ns = input()\nzeroes = list(filter(lambda x: x == '0', s))\nones = list(filter(lambda x: x == '1', s))\nremaining = 0\nones_l = len(ones)\nzeroes_l = len(zeroes)\nif ones_l < zeroes_l:\n remaining = len(s) - (ones_l * 2)\nelse:\n remaining = len(s) - (zeroes_l * 2)\nprint(remaining)\n\n \t\t\t \t\t \t \t \t\t\t\t\t\t \t\t\t\t",
"n = int(input())\r\ns = input()\r\nzeros = 0; ones = 0\r\nfor i in range(n):\r\n if s[i] == '0': zeros += 1\r\n else: ones += 1\r\n\r\nprint(abs(ones - zeros))",
"n = int(input())\r\ns = input()\r\nprint(n - (2*min(s.count('0'),s.count('1'))))",
"length = input()\nstring = input()\n\num = 0\nzero = 0\n\nfor numero in string:\n if numero ==\"1\":\n um += 1\n elif numero == \"0\":\n zero += 1\n\nresult = 0\n\nif um > zero:\n result = um - zero\nelse:\n result = zero - um\n\nprint(result)\n \t \t \t \t\t\t\t\t \t\t \t \t \t",
"n=int(input())\r\ns=input()\r\nones=s.count('1')\r\nzeroes=s.count('0')\r\nprint(abs(ones-zeroes))",
"n, a = input(), input()\r\nprint(abs(a.count('1')-a.count('0')))",
"n = int(input())\r\ns = input()\r\n\r\nstack = []\r\n\r\nfor char in s:\r\n if stack and stack[-1] != char:\r\n stack.pop()\r\n else:\r\n stack.append(char)\r\n\r\nmin_length = len(stack)\r\nprint(min_length)",
"x = int(input())\r\ny = list(input())\r\na = y.count(\"0\")\r\nb = y.count(\"1\")\r\nprint(max(a-b, b-a))",
"length = eval(input())\r\nnew_length = []\r\nstring = input()\r\nzeros_values = 0\r\nones_values = 0\r\n\r\nfor i in string:\r\n new_length.append(int(i))\r\n\r\nnew_length.sort()\r\n\r\nfor i in new_length:\r\n if i == 0:\r\n zeros_values += 1\r\n else:\r\n ones_values += 1\r\n\r\ntotal = abs(zeros_values - ones_values)\r\n\r\nprint(total)\r\n",
"n = int(input())\r\ns = input()\r\nc1 = s.count('1')\r\nc2 = s.count('0')\r\nprint(max(c1, c2) - min(c1, c2))",
"n = int(input())\r\ns = input()\r\nz = 0\r\nfor i in s:\r\n z += int(i=='0')\r\no = n-z\r\nprint(n-2*min(o,z))",
"# count 0\n# count 1\n# x = 2 * min(c0, c1)\n# output = n - x\n\nn = int(input())\ns = input()\n\nc0 = s.count(\"0\")\nc1 = s.count(\"1\")\nx = 2 * min(c0, c1)\nprint(n - x)",
"a=int(input())\r\nstring=input()\r\nprint(a-(min(string.count(\"1\"),string.count(\"0\"))*2))",
"n = int(input()); a = list(input())\r\nb = a.count(\"0\"); c = a.count(\"1\")\r\nprint(len(a)-(min(b,c)*2))",
"num = input()\r\nstrk = input()\r\n\r\nnulls = 0\r\nones = 0\r\n\r\nfor a in strk:\r\n if a == '0':\r\n nulls += 1\r\n else:\r\n ones += 1\r\n \r\nif nulls > ones:\r\n print (nulls - ones)\r\nelif nulls < ones:\r\n print (ones - nulls)\r\nelse:\r\n print (0)",
"N = int(input())\r\nStr = input()\r\n\r\nNum1 = Str.count('1')\r\nNum2 = Str.count('0')\r\n\r\nif Num1 >= Num2:\r\n print( Num1 - Num2)\r\nelse:\r\n print(Num2 - Num1)\r\n ",
"# cook your dish here\r\nt = int(input())\r\ns = input()\r\nno0 = s.count('0')\r\nno1 = s.count('1')\r\nif no0 == no1:\r\n print(0)\r\nelse:\r\n if no0 > no1:\r\n print(no0-no1)\r\n else:\r\n print(no1-no0)\r\n ",
"n = input()\r\nstring10 = input()\r\nstring1 = string10.replace('0', '')\r\nzero = int(len(string10)-len(string1))\r\nanswer = abs(len(string1) - zero)\r\nprint(answer)\r\n\r\n\r\n",
"import math,re\r\n\r\ndef fast():\r\n return list(map(int,input().split()))\r\n\r\ndef solve():\r\n n = int(input())\r\n s = input()\r\n print(abs(s.count('1')-s.count('0')))\r\n \r\nif __name__ == '__main__':\r\n solve()",
"n, s = int(input()), input()\nones = s.count(\"1\")\nres = abs(ones - (n - ones))\nprint(res)\n",
"import math\r\nimport sys\r\n\r\n# s,n=map(int,input().split())\r\n# t=True\r\n\r\n# for m in range(int(input())):\r\nn=int(input()) \r\n# t=input()\r\n # n,k,r,c=map(int,input().split()) \r\n # ar=[a,b]\r\n # arr=list(map(int,input().split()))\r\ns=input()\r\nc1=s.count('1')\r\nc0=s.count('0')\r\nprint(abs(c1-c0))",
"n=int(input())\r\ns=input()\r\nc=min(s.count('0'),s.count('1'))\r\nprint(n-2*c)",
"l = int(input())\r\nn = input()\r\nprint(abs(n.count('0') - n.count('1')))",
"import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\nn=int(input())\r\ns=input()\r\nprint(abs(s.count('1')-s.count('0')))",
"import sys\r\ninput = sys.stdin.readline\r\n\r\ndef main() -> None :\r\n string:str = \"\"\r\n input()\r\n string = input().rstrip()\r\n\r\n MIN_LEN:int = len(string) - min(string.count(\"1\"), string.count(\"0\"))*2\r\n\r\n print(MIN_LEN)\r\n\r\nmain()",
"x=int (input())\r\ns=input ()\r\nres=abs(s.count ('1')-s.count('0'))\r\nprint (res)",
"#URL: https://codeforces.com/problemset/problem/556/A\n\nn=int(input())\nstr=input()\nc0=str.count(\"0\")\nc1=str.count(\"1\")\nprint(n-2*(min(c0,c1)))\n\n \n\n\n\n",
"length = input()\r\nstring = input()\r\n\r\num = 0\r\nzero = 0\r\n\r\nfor numero in string:\r\n if numero ==\"1\":\r\n um += 1\r\n elif numero == \"0\":\r\n zero += 1\r\n\r\nresult = 0\r\n\r\nif um > zero:\r\n result = um - zero\r\nelse:\r\n result = zero - um\r\n\r\nprint(result)",
"n = int(input())\ns = input()\n\nprint(n - (2 * min(s.count('0'), n - s.count('0'))))\n\t\t\t\t \t \t \t \t\t \t\t \t\t\t\t \t\t\t\t",
"quant = input()\nlis = list(input())\n\nquant0 = 0\nquant1 = 0\n\n\nfor i in lis:\n if i == '1':\n quant1 += 1\n else:\n quant0 += 1\n\nprint(max(0,abs(quant1-quant0)))\n",
"n = int(input())\r\ns = input()\r\nzeros = s.count('0')\r\nones = s.count('1')\r\nans = zeros + ones - 2*min(zeros,ones)\r\nprint(ans)\r\n",
"length, text = int(input()), input()\nprint(text.count(\"1\") - text.count(\"0\") if text.count(\"1\") > text.count(\"0\") else text.count(\"0\") - text.count(\"1\"))\n",
"a=int(input())\r\nb=input()\r\nc=0\r\nfor i in b:\r\n if i=='0':\r\n c=c+1\r\nprint(abs(a-2*c))",
"#CF556A A. Case of the Zeros and Ones\r\nn=int(input())\r\na=input()\r\nx=a.count(\"0\");y=n-x\r\nprint(abs(x-y))",
"n = int(input())\r\ns = input()\r\n\r\nz = s.count('0')\r\no = s.count('1')\r\nprint(n - min(z,o) * 2)\r\n",
"n = int(input())\r\ns = input()\r\n\r\n# Initialize counters for zeros and ones\r\ncount_zeros = s.count('0')\r\ncount_ones = s.count('1')\r\n\r\n# Calculate the minimum length of the remaining string\r\nmin_length = min(count_zeros, count_ones)\r\n\r\n# Print the result\r\nprint(n - 2 * min_length)\r\n",
"n=int(input())\r\nw=input()\r\nprint(n-min(w.count('1'),w.count('0'))*2)",
"length=int(input())\r\nn=input()\r\nno_of_zero,no_of_one=0,0 \r\nfor i in n:\r\n if i==\"0\":\r\n no_of_zero+=1 \r\n else:\r\n no_of_one+=1 \r\nprint(length- 2*min(no_of_one,no_of_zero))",
"import math \r\nn = input()\r\ns = input()\r\ns1 = s.count('1')\r\ns2 = s.count('0')\r\nprint(abs(s1-s2))",
"n = int(input())\r\ns = str(input())\r\nprint(abs(s.count(\"1\") - s.count(\"0\")))",
"m=int(input())\r\na=(input())\r\nb=min(a.count(\"0\"),a.count(\"1\"))\r\nprint(m-2*b)\r\n \r\n\r\n \r\n ",
"n = int(input())\nm = input()\n\nprint(abs(m.count(\"0\")-m.count(\"1\")))\n \n",
"# Read input\r\nn = int(input())\r\ns = input()\r\n\r\n# Initialize counters for zeros and ones\r\ncount_zeros = 0\r\ncount_ones = 0\r\n\r\n# Count the number of zeros and ones in the string\r\nfor char in s:\r\n if char == '0':\r\n count_zeros += 1\r\n else:\r\n count_ones += 1\r\n\r\n# Calculate the minimum length that can remain\r\nmin_length = abs(count_zeros - count_ones)\r\n\r\n# Print the result\r\nprint(min_length)",
"n=int(input())\r\ns=str(input())\r\nx=s.count(\"1\")\r\ny=n-x\r\nz=min(x,y)\r\nprint(n-(2*z))\r\n\r\n",
"n=int(input())\r\na=input()\r\nprint(abs(a.count(\"0\")-a.count(\"1\")))\r\n",
"ap = int(input())\r\nbp = input()\r\nzeros = bp.count('0')\r\nmin_length = abs(zeros - bp.count('1'))\r\n\r\nprint(min_length)\r\n",
"a=int(input())\r\ns=input()\r\nprint(abs(a-(s.count(\"0\")*2)))",
"s = [*open(0)][1]\r\nprint(abs(s.count('0')-s.count('1')))\r\n",
"input()\r\ns=input()\r\nprint(len(s)-(min([s.count(\"0\"),s.count(\"1\")])*2))",
"n = int(input())\nm = input()\n\nif m.count('1') == m.count('0'):\n print('0')\nelif m.count('1') > m.count('0'):\n print(n - 2*m.count('0'))\nelse:\n print(n - 2*m.count('1'))\n\t \t \t\t \t \t\t\t\t \t\t\t\t\t \t\t \t",
"len = input() #useless lol\r\nstring = str(input())\r\nzero = one = 0\r\n\r\nfor char in string:\r\n if(char == \"1\"):\r\n one += 1\r\n else:\r\n zero += 1\r\nprint(abs(zero - one))",
"n=int(input())\r\ns=input()\r\nzero=0\r\none=0\r\nfor i in s:\r\n if i==\"1\":\r\n one+=1\r\n else:\r\n zero+=1\r\nprint(abs(one-zero))",
"\"\"\"\r\n██████╗ ██████╗ █████╗ ██╗ ██╗\r\n██╔══██╗██╔══██╗██╔══██╗╚██╗██╔╝\r\n██║ ██║██████╔╝███████║ ╚███╔╝\r\n██║ ██║██╔══██╗██╔══██║ ██╔██╗\r\n██████╔╝██║ ██║██║ ██║██╔╝ ██╗\r\n╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝\r\n\r\n\"\"\"\r\nn=int(input())\r\np=input()\r\nc_1=0\r\nc_0=0\r\nfor x in p:\r\n if x == \"1\":c_1+=1\r\n else: c_0+=1\r\nprint(abs(c_1-c_0))",
"n=int(input())\r\na=list(input(\"\"))\r\nprint(abs(a.count(\"1\")-a.count(\"0\")))",
"n = int(input())\r\ns = input().count(\"0\")\r\na = n - s - s\r\nprint(a if a >= 0 else -a)",
"n=int(input())\r\nm=input()\r\nprint(abs(n-m.count(\"0\")*2))",
"def split(string):\r\n return [char for char in string]\r\n\r\n\r\nn = int(input())\r\nstring = input()\r\nstring = split(string)\r\n\r\nzeroes = string.count(\"0\")\r\nones = string.count(\"1\")\r\n\r\nsub = min(zeroes, ones)\r\n\r\nzeroes -= sub\r\nones -= sub\r\n\r\nprint(max(zeroes, ones))\r\n",
"maxLength = int(input())\r\ninputVal = (input())\r\nzeros = inputVal.count('0')\r\nones = inputVal.count('1')\r\nif zeros == ones:\r\n print(0)\r\nelif zeros > ones:\r\n print(zeros-ones)\r\nelse:\r\n print(ones-zeros)",
"n = int(input())\r\nst= input()\r\nprint(n - (min(st.count('0'),st.count('1')))*2)",
"n = int(input())\r\ns = input()\r\nz = s.count(\"0\")\r\no = s.count(\"1\")\r\nif z == o:\r\n print(0)\r\nelif z > o:\r\n print(z - o)\r\nelse:\r\n print(o - z)",
"n = int(input())\r\na = input()\r\nprint(abs(a.count(\"1\") - a.count(\"0\")))",
"def func1(n,s):\r\n count_1,count_0 = 0,0\r\n for each in s:\r\n if each==\"1\":\r\n count_1+=1\r\n else:\r\n count_0+=1\r\n ans = n - (2*min(count_0,count_1))\r\n return ans\r\nn = int(input())\r\ns = input()\r\nprint(func1(n,s))",
"n=int(input())\r\nx=input()\r\na=x.count('1')\r\nb=x.count('0')\r\nprint(abs(a-b))\r\n",
"n=int(input())\r\ns=input()\r\na=s.count(\"0\")\r\nb=s.count(\"1\")\r\nk=min(a,b)\r\nprint(n-k-k)",
"a=input()\r\nstring=input()\r\nprint(abs(string.count(\"1\")-string.count('0')))\r\n",
"l=int(input())\r\nseq= input()\r\none=0\r\nzero=0\r\nfor i in seq:\r\n if i == '1':\r\n one+=1\r\n elif i == '0':\r\n zero+=1\r\nlen_new_seq = one-zero\r\nif len_new_seq < 0:\r\n len_new_seq*=-1\r\nprint(len_new_seq)\r\n",
"import sys\r\nfrom math import *\r\ninput = sys.stdin.readline\r\n\r\ndef solve(n,s):\r\n\ttot = 0\r\n\to = s.count(\"1\")\r\n\tz = s.count(\"0\")\r\n\tif o > z:\r\n\t\tprint(n-2*z)\r\n\telif z > o:\r\n\t\tprint(n-2*o)\r\n\telse:\r\n\t\tprint(0)\r\n\r\n\r\n# for _ in range(int(input())):\r\nn = int(input())\r\ns = str(input())\r\nsolve(n,s)",
"n = int(input())\r\nstring = input()\r\nprint(abs(string.count(\"0\")-string.count(\"1\")))",
"count_time=False\r\nif count_time:\r\n import time\r\n start_time = time.time()\r\n#------------------------------------------\r\nfrom collections import Counter\r\nn=int(input())\r\ns=Counter(input())\r\nprint(n-2*min(s['0'],s['1']))\r\n#------------------------------------------\r\nif count_time:\r\n end_time = time.time()\r\n print('----------------\\nRunning time: {} s'\r\n .format(end_time - start_time))\r\n",
"a = int(input())\r\nentrada = input()\r\nlista = []\r\nfor i in range(len(entrada)):\r\n lista.append(entrada[i])\r\n\r\num = 0\r\nzero = 0\r\n\r\nfor i in range(len(lista)):\r\n if (lista[i] == '1'):\r\n um += 1\r\n if (lista[i] == '0'):\r\n zero += 1\r\n\r\nprint(abs(um-zero))\r\n\r\n \r\n \r\n ",
"n = int(input())\r\na = input()\r\nc0 = 0\r\nc1 = 0\r\nfor i in a:\r\n if i == '1':\r\n c1+=1\r\n else:\r\n c0+=1\r\nprint(n - (min(c0,c1)*2))",
"n = int(input())\r\ns = input()\r\ncount0 = count1 = 0\r\nfor x in s:\r\n if x == '0':\r\n count0 += 1\r\n else:\r\n count1 += 1\r\nprint(n - 2 * min(count0, count1))\r\n",
"n = int(input())\r\nk = list(map(int, input()))\r\nnum_zero = k.count(0)\r\nnum_one = k.count(1)\r\n# print(num_one, num_zero, end=' ')\r\nif num_zero < num_one:\r\n length_k = len(k) - num_zero - num_zero\r\nelif num_one < num_zero:\r\n length_k = len(k) - num_one - num_one\r\nelif num_one == num_zero:\r\n length_k = 0\r\nprint(length_k)",
"number_long = int(input())\r\nnumbers = input()\r\n\r\ntemp = 0\r\n\r\nfor i in range(len(numbers)):\r\n if numbers[i]=='0':\r\n temp = temp+1\r\n\r\ntemp2 = number_long-temp\r\nres = abs (temp - temp2)\r\n\r\nprint (res)",
"n=int(input())\r\ns=input()\r\nc_0=s.count(\"0\")\r\nc_1=s.count(\"1\")\r\nprint(len(s)-min(c_0,c_1)*2)",
"n = int(input())\r\nn1 = input()\r\nif n1.count('1') > n1.count('0'):\r\n print(n1.count('1') - n1.count('0'))\r\nelse: print(n1.count('0') - n1.count('1'))",
"m = int(input())\r\nt = input()\r\nk,n = 0,0\r\nfor i in t:\r\n if i == \"1\":\r\n k+=1\r\n else:\r\n n+=1\r\nprint(m-min(k,n)*2)\r\n",
"n = int(input())\r\ns = input()\r\n\r\nc0 = s.count('0')\r\nc1 = s.count('1')\r\n\r\nrm = min(c0, c1)\r\nresult = n - 2 * rm\r\n\r\nprint(result)\r\n",
"n=int(input())\r\ns=input()\r\nres=0\r\nones=0\r\nzeros=0\r\n\r\nfor i in range(n):\r\n if s[i]=='1':\r\n ones+=1\r\n else:\r\n zeros+=1\r\n\r\n if ones>=zeros and zeros!=0:\r\n res+=zeros*2\r\n ones-=zeros\r\n zeros=0\r\n if zeros>=ones and ones!=0:\r\n res+=ones*2\r\n zeros-=ones\r\n ones=0\r\nprint(len(s)-res)",
"n = int(input())\r\ns = input()\r\narr = []\r\narr = list(s)\r\narr.sort()\r\none = arr.count(\"1\")\r\nzero = arr.count(\"0\")\r\nprint(abs(one - zero))\r\n",
"stringLength = int(input())\r\nstring = input()\r\nzeroCount = 0\r\noneCount = 0\r\nsmallCount = 0\r\ndifferenceCount = 0\r\nfor i in range(len(string)):\r\n if string[i] == '0':\r\n zeroCount += 1\r\n else:\r\n oneCount += 1\r\n if zeroCount > oneCount:\r\n smallCount = oneCount\r\n else:\r\n smallCount = zeroCount\r\n differenceCount = len(string) - smallCount * 2\r\nprint(differenceCount) \r\n ",
"n = int(input())\r\nstring = list(str(input()))\r\nzero = 0\r\none = 0\r\n\r\nfor i in string:\r\n if i == '1':\r\n one += 1\r\n elif i == '0':\r\n zero += 1\r\nmax_len = max(one, zero)\r\nnew_str = ''\r\ni = 0\r\nwhile i < int(max_len):\r\n if one == 0 or zero == 0:\r\n if one >= 1:\r\n ones = '1' * one\r\n new_str += ones\r\n elif zero >= 1:\r\n zeros = '0' * zero\r\n new_str += zeros\r\n break\r\n else:\r\n new_str += '10'\r\n one -= 1\r\n zero -= 1\r\n i += 1\r\nprint(len(new_str.replace('10', '')))",
"n = int(input())\r\na = input()\r\ns = 0\r\nt = 0\r\nfor i in a:\r\n if '1' in i:\r\n s+=1\r\n elif '0' in i:\r\n t+=1\r\nprint(abs(t-s)) ",
"n=int(input())\ns=input()\none=0\nfor i in range(n):\n if s[i]=='1':\n one += 1\nzero = n- one # 001111 # 2\nmn = min(zero,one)\nmn *= 2\nprint(n - mn)\n\t \t\t \t \t \t\t\t \t\t \t\t \t\t \t",
"a,b=int(input()),input()\r\none= b.count(\"1\")\r\nzero=b.count(\"0\")\r\nvmeste= min(one,zero)\r\nprint(max(one-vmeste, zero-vmeste))",
"try:\r\n n = int(input())\r\n s = input()\r\n n1 = s.count(\"1\")\r\n n2 = s.count(\"0\")\r\n print(abs(n1 - n2))\r\nexcept:\r\n pass",
"n = int(input())\r\ns = input()\r\nz = s.count('0')\r\no = s.count('1')\r\nprint(abs(z-o))",
"n=int(input())\r\na=input()\r\nm=min(a.count(\"0\"),a.count(\"1\"))\r\nprint(n-2*m)",
"n=int(input())\r\ns=input()\r\na=s.count('1')\r\nb=s.count('0')\r\nprint(n-(2*min(a,b)))\r\n",
"s=input()\r\nss=input()\r\nprint(abs(ss.count('0')-ss.count('1')))\r\n",
"N = int(input())\r\nS = input()\r\nnum_one = S.count(\"1\")\r\nnum_zero = S.count(\"0\")\r\nprint(N - (2 * (min(num_one,num_zero))))",
"n=int(input())\r\ns=input()\r\ntemp=s.count(\"0\")\r\ntemp1=s.count(\"1\")\r\ntemp=temp*2\r\ntemp1=temp1*2\r\nprint(max(n-temp,n-temp1))\r\n",
"p=int(input())\r\nx=input().count('1')\r\nprint(p-2*min(x,p-x))",
"n = int(input())\r\nm = input()\r\nones = 0\r\nzeros = 0\r\nfor i in m:\r\n if i == \"1\":\r\n ones += 1\r\n else:\r\n zeros += 1\r\nprint(abs(ones-zeros))\r\n",
"n = int(input())\r\ns = input()\r\nzeros =0\r\nones =0\r\nfor i in range(n):\r\n if s[i] == '0':\r\n zeros+=1\r\n else :\r\n ones+=1\r\nprint(abs(ones-zeros))\r\n",
"n = int(input())\r\ns = input()\r\ne,o = 0,0\r\nfor i in s:\r\n e+=1\r\n if i == '0':\r\n e-=1\r\n o+=1\r\nprint(len(s)-min(e,o)*2)",
"n = int(input())\r\nch = input()\r\n\r\nprint(abs(ch.count('0') - ch.count(('1'))))",
"n = int(input())\r\nstr = input()\r\nones = str.count('1')\r\nzeroes = n - ones\r\nunion = min(ones, zeroes)\r\nprint(max(ones - union, zeroes - union))\r\n",
"n=int(input());w=input();l=[];l.append(w.count(\"1\"));l.append(w.count(\"0\"));print(n-(min(l)*2))",
"n=int(input())\r\ns=input()\r\na=s.count('1')\r\nprint(max(a,n-a)-min(a,n-a))",
"n=int(input())\r\ns=str(input())\r\n\r\nc1=0\r\nc0=0\r\n\r\nfor i in range(0,n):\r\n if s[i]=='0':\r\n c0=c0+1\r\n if s[i]=='1':\r\n c1=c1+1\r\n\r\nprint(abs(c1-c0))",
"\r\ndef zeros(n,u):\r\n s = []\r\n for i in range(n):\r\n if len(s) >=1 and s[-1] != u[i]:\r\n s.pop()\r\n else:\r\n s.append(u[i])\r\n return len(s)\r\n\r\n\r\nn = int(input())\r\ns = input()\r\nprint(zeros(n,s))",
"n = int(input())\r\ns = input()\r\n\r\nnum1 = s.count('1')\r\nnum0 = s.count('0')\r\nprint(abs(num0-num1))",
"n=int(input())\r\ns=input()\r\nx=s.count(\"0\")\r\nz=s.count(\"1\")\r\nprint(n-(2*min(z,x)))\r\n ",
"n = int(input())\r\ns = input()\r\n\r\nstack = [s[0]]\r\nfor i in range(1, n):\r\n if stack and s[i] != stack[-1]:\r\n stack.pop()\r\n else:\r\n stack.append(s[i])\r\n\r\nprint(len(stack))\r\n",
"n=int(input(\"\"))\r\ns=input()\r\na=0 \r\nb=0 \r\nfor i in s:\r\n if i=='1':\r\n a+=1 \r\n else:\r\n b+=1 \r\nprint(abs(a-b))",
"n = int(input())\r\ns=input()\r\nz = s.count('0')\r\no = s.count('1')\r\n\r\n\r\nif z == o:print(0)\r\nelse :\r\n print(abs(o-z))\r\n",
"n=int(input())\r\ns=input()\r\nprint(n-2*min(s.count('1'),s.count('0')))",
"N=int(input())\r\nch=input()\r\nprint(abs(ch.count('1')-ch.count('0')))\r\n \r\n \r\n",
"n = int(input())\r\ns = str(input())\r\no = s.count(\"1\")\r\nz = s.count(\"0\")\r\nprint(abs(o - z))",
"n=int(input())\r\ns=str(input())\r\nz=0\r\no=0\r\nfor i in s:\r\n if i=='0':\r\n z+=1\r\n elif i=='1':\r\n o+=1\r\nprint(abs(z-o))",
"n=int(input())\r\na=input()\r\nb=list(a)\r\nx=0\r\ny=0\r\nfor i in range(0,n):\r\n if(b[i]=='0'):\r\n x=x+1\r\n else:\r\n y=y+1\r\n\r\nprint(abs(x-y)) ",
"# https://codeforces.com/problemset/problem/556/A\r\n\r\nn = int(input())\r\n\r\ns = input()\r\n\r\nones = 0\r\nfor e in s:\r\n if e == '1':\r\n ones += 1\r\nprint( abs(ones - (len(s) - ones)) )\r\n",
"n = int(input())\r\ns = input()\r\nc0, c1 = 0, 0\r\nfor v in s:\r\n if v == '1':\r\n c1 += 1\r\n elif v == '0':\r\n c0 += 1\r\nprint(abs(c0 - c1))\r\n",
"from math import*\r\nj=int(input())\r\nm=list(input())\r\nc1,c0=0,0\r\nfor i in range(len(m)):\r\n if m[i]=='1':c1+=1\r\n else:c0+=1\r\nprint(j-min(c1,c0)*2)\r\n",
"n = int(input())\r\ns = input() \r\nc1 = 0\r\nc0 = 0\r\n \r\nfor i in s:\r\n if i=='1':\r\n c1 += 1\r\n c0 -= 1\r\n else:\r\n c1 -= 1\r\n c0 += 1\r\n \r\nprint(max(c0,c1))",
"n = int(input())\r\ns = input()\r\ns0 = s.count(\"0\")\r\ns1 = s.count(\"1\")\r\nif s0 > s1:\r\n print(s0 - s1)\r\nelse:\r\n print(s1 - s0)",
"n = int(input())\r\nstrng = input()\r\ncnt = [0, 0]\r\nfor x in strng:\r\n cnt[int(x)] += 1\r\nprint(n-2*min(cnt))",
"n = int(input())\r\ns = list(input())\r\n\r\ncount_one = 0\r\ncount_zero = 0\r\n\r\nfor e in s:\r\n if e == '1':\r\n if count_one <= 0:\r\n count_zero += 1\r\n else:\r\n count_one -= 1\r\n else:\r\n if count_zero <= 0:\r\n count_one += 1\r\n else:\r\n count_zero -= 1\r\n\r\nprint(count_zero + count_one)",
"n=int(input())\r\ns=input()\r\nA=s.count(\"0\")\r\nB=s.count(\"1\")\r\nprint(n-2*min(A,B))",
"\n\nl=int(input())\ns=input()\n\n\ns = [int(i) for i in s]\nc= len(s)\nfrom queue import deque\n\nq = deque()\n\ni = 0\nwhile i < len(s):\n\tif len(q) == 0 or q[-1] + s[i] != 1:\n\t\tq.appendleft(s[i])\n\telif q[-1] + s[i] == 1:\n\t\tq.popleft()\n\t\tc -= 2\n\ti += 1 \n\t\n\nprint(c)\n\t\t\t\t\n\t\t\n\t\t\n\t\n\t\t\n\t\t\t\n\n\t\t\t",
"n = int(input())\r\na = input()\r\ncount_zero = 0\r\ncount_one = 0\r\nfor i in a:\r\n if i=='0':\r\n count_zero+=1\r\n else:\r\n count_one+=1\r\nprint(abs(count_zero-count_one))\r\n",
"n = int(input())\r\ns = input()\r\n\r\nstack = []\r\n\r\nfor c in s:\r\n if len(stack) > 0 and stack[-1] != c:\r\n stack.pop()\r\n else:\r\n stack.append(c)\r\n\r\nprint(len(stack))",
"n=int(input())\r\ns=input()\r\nif s.count(\"1\")==s.count(\"0\"):\r\n print(0)\r\nelif s.count(\"1\")>s.count(\"0\"):\r\n print(s.count(\"1\")-s.count(\"0\"))\r\nelse:\r\n print(s.count(\"0\")-s.count(\"1\"))",
"n = int(input())\r\ns = input()\r\n\r\n# Count the number of '0's and '1's\r\ncount_zeros = s.count('0')\r\ncount_ones = s.count('1')\r\n\r\n# Calculate the minimum length\r\nmin_length = abs(count_ones - count_zeros)\r\n\r\nprint(min_length)\r\n",
"n = int(input())\r\nx = input()\r\nx_1 = x.count(\"1\") # Находим сколько 1 в строке\r\nx_0 = x.count(\"0\") # Находим сколько 0 в строке\r\nunion = min(x_0, x_1) # Находим сколько пар можем составить\r\nprint(max(x_1 - union, x_0 - union))",
"def solve(s):\r\n\ts = list(map(int, list(s)))\r\n\tstack = []\r\n\t\r\n\tfor i in s:\r\n\t\tstack.append(i)\r\n\t\tif len(stack) >= 2:\r\n\t\t\tif (stack[-1] == 0 and stack[-2] == 1) or (stack[-1] == 1 and stack[-2] == 0):\r\n\t\t\t\tstack.pop()\r\n\t\t\t\tstack.pop()\r\n\r\n\treturn len(stack)\r\n\r\ndef main():\r\n\tn = int(input())\r\n\tprint(solve(input()))\r\nmain()",
"x=int(input())\r\nz=input()\r\nd=min(z.count('1'),z.count('0'))\r\nprint(x-2*d)",
"cnt = cnt2 = 0\r\nn = int(input())\r\ns = str(input())\r\nfor i in range (len(s)):\r\n if (s[i]=='0'):\r\n cnt+=1\r\n elif (s[i] == '1'):\r\n cnt2+=1\r\nprint(abs(cnt-cnt2))",
"input()\r\ns = input()\r\none = s.count('1')\r\nzero = s.count('0')\r\n\r\nprint(abs(one-zero))",
"n=int(input());s=list(input())\r\none=s.count(\"1\");zero=s.count(\"0\")\r\nprint(n-(min(one,zero)*2))",
"a =int(input())\r\nb = list(input())\r\nA = b.count(\"1\")\r\nB = b.count(\"0\")\r\nif A>B:\r\n print(A-B)\r\nelse:\r\n print(B-A)",
"from sys import stdin, stdout\r\ninput, print = stdin.readline, stdout.write\r\n\r\n\r\ndef str_input():\r\n s = input()\r\n return s[:len(s)-1]\r\n\r\n\r\ndef list_input():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef map_input():\r\n return map(int, input().split())\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n s = str_input()\r\n zero = s.count('0')\r\n one = s.count('1')\r\n ans = n - 2 * min(zero, one)\r\n print(f\"{ans}\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n",
"a=int(input())\r\nb=input()\r\n\r\nprint(abs(b.count(\"1\")-b.count(\"0\")))\r\n\r\n",
"n = input()\r\ns = input()\r\n\r\ncnt0, cnt1 = 0, 0\r\n\r\nfor c in s:\r\n \r\n if c == '1':\r\n cnt1 += 1\r\n \r\n else:\r\n cnt0 += 1\r\n \r\nprint(abs(cnt0 - cnt1))",
"n = int(input())\r\ncase = input()\r\nprint(n-(2*min(case.count('0'), case.count('1'))))\r\n",
"s = input()\r\ns = input().strip()\r\nans = 0\r\nfor c in s:\r\n\tif int(c):\r\n\t\tans += 1\r\n\telse:\r\n\t\tans -= 1\r\nprint(abs(ans))",
"\n#exercice A - Case of the Zeros and Ones\n#complejidad O(i)\nn = int(input())\ns = input()\ncount = 0\nfor i in range(n):\n if s[i] == '0':\n count += 1\n else:\n count -= 1\n\nprint(abs(count))#calcula el valor absoluto de count\n\n \t \t\t \t\t \t \t \t\t\t\t \t\t \t\t",
"n=int(input())\r\na=input()\r\nb=abs(a.count(\"1\")-a.count(\"0\"))\r\nprint(b)",
"n=int(input())\r\nstr1=input()\r\ncountofzeros=str1.count('0')\r\ncountofones=str1.count('1')\r\nprint (abs(countofones-countofzeros))\r\n",
"n=int(input())\r\na=input()\r\ny=a.count('1')\r\ns=a.count('0')\r\nm=min(y,s)\r\ny-=m\r\ns-=m\r\nprint(max(s,y))\r\n",
"num= int(input())\r\nstr_1= input()\r\nprint(abs(str_1.count(\"0\")-str_1.count(\"1\")))",
"import sys\r\n\r\ninputs = []\r\nfor line in sys.stdin:\r\n inputs.append(line)\r\n\r\nn = int(inputs[0].strip())\r\nseq = inputs[1].strip()\r\n\r\nones = 0\r\nzeros = 0\r\nfor i in range(0,n):\r\n ones+=(seq[i]==\"1\")\r\n zeros+=(seq[i]==\"0\")\r\nprint(n - (min(ones,zeros) * 2))\r\n",
"\r\nn = int(input())\r\nword = input()\r\nstack =[]\r\n\r\nfor w in word:\r\n if stack and stack[-1] != w:\r\n stack.pop()\r\n else:\r\n stack.append(w)\r\n\r\nprint(len(stack))",
"import sys\r\nimport math\r\nimport collections\r\nfrom heapq import heappush, heappop\r\ninput = sys.stdin.readline\r\n \r\nints = lambda: list(map(int, input().split()))\r\n\r\n\r\nn = int(input())\r\ns = input().strip()\r\nprint(abs(s.count(\"0\") - s.count(\"1\")))",
"n = int(input())\r\ns = input()\r\n\r\nlist = []\r\n\r\nfor char in s:\r\n if list and list[-1] != char:\r\n list.pop()\r\n else:\r\n list.append(char)\r\n\r\nmin_length = len(list)\r\n\r\nprint(min_length)\r\n\r\n \r\n\r\n",
"n=int(input())\r\ns=input()\r\nc1=s.count(\"0\")\r\nc2=s.count('1')\r\nprint(n-min(c1,c2)*2)",
"n=int(input())\r\ns=input()\r\na=0\r\nb=0\r\nfor i in s:\r\n if i=='0':\r\n a=a+1\r\n else:\r\n b=b+1\r\nprint(abs(a-b))",
"#556A - Case of the Zeros and Ones\r\nx,s=int(input()),input()\r\nprint(abs(s.count(\"0\")-s.count(\"1\")))",
"a=int(input())\r\nb=input()\r\ncnt=0\r\ndnt=0\r\nfor i in range(a):\r\n if b[i]=='1':\r\n cnt+=1 \r\n else:\r\n dnt+=1 \r\nprint(abs(cnt-dnt))",
"n = int(input())\r\nl = list(input())\r\nprint(max(l.count('0'), l.count('1')) - min(l.count('0'), l.count('1')))",
"n=int(input())\r\na=input()\r\nb=a.count('0')\r\nc=a.count('1')\r\nprint(abs(b-c))",
"n = int(input())\r\nS = input()\r\n\r\nones = S.count('1')\r\nzeros = n - ones\r\n\r\nprint(ones + zeros - 2*min(zeros, ones))",
"n = int(input())\r\ns = input()\r\na = s.count('0')\r\nprint(abs(a-(n-a)))",
"n = int(input())\r\nstring = input()\r\ny = string.count('0') \r\nx = string.count('1') \r\nl = min(y ,x)\r\nresult = len(string) - (l * 2) \r\nprint(result) ",
"a=int(input())\r\nb=input()\r\nprint(max(b.count('0'),b.count('1'))-min(b.count('0'),b.count('1')))\r\n",
"a = int(input())\nb = input()\nu = b.count(\"1\")\nmi = min(u,a-u)\nprint(a-2*mi)\n \t\t \t\t \t\t \t\t \t\t\t \t \t\t \t \t\t\t \t\t",
"tam = int(input())\ns = input().count('1')\n\nprint(tam-2*min(s,tam-s))\n",
"#Ram\r\nfrom sys import stdin,stdout\r\ninput = stdin.readline\r\n\r\ndef print(n):\r\n stdout.write(str(n)+\"\\n\")\r\n\r\ndef printl(l):\r\n for i in l:\r\n stdout.write(str(i)+\" \")\r\n\r\n\r\nn=int(input())\r\ns=input()\r\nones=0\r\nzeros=0\r\nfor i in s[0:n]:\r\n if i==\"1\":\r\n ones+=1\r\n else:\r\n zeros+=1\r\nprint(abs(ones-zeros))",
"total = int(input())\ncadeia_input = list(input())\n\nqtd_zeros = 0\nqtd_uns = 0\n\nfor elem in cadeia_input:\n if elem == '1':\n qtd_uns += 1\n elif elem == '0':\n qtd_zeros += 1\n\nif qtd_uns == qtd_zeros: print(0)\nelif qtd_uns > qtd_zeros: print(qtd_uns - qtd_zeros)\nelse: print(qtd_zeros - qtd_uns)\n\t \t \t \t\t \t \t\t \t \t \t",
"import sys\nLI=lambda:list(map(int,sys.stdin.readline().split()))\nMI=lambda:map(int,sys.stdin.readline().split())\nSI=lambda:sys.stdin.readline().strip('\\n')\nII=lambda:int(sys.stdin.readline())\n\n\"\"\" for _ in range(II()): \"\"\"\nn=II()\nst=[]\nfor c in SI():\n if not st or c==st[-1]:\n st.append(c)\n else:\n st.pop()\nprint(len(st))",
"n = int(input())\r\ns = input()\r\na, b = s.count('0'), s.count('1')\r\nprint(n-min(a, b)*2)\r\n",
"x = input()\r\ny = input()\r\nnum0 = 0\r\nnum1 = 0\r\n\r\nfor i in y:\r\n if i == \"1\":\r\n num1 += 1\r\n if i == \"0\":\r\n num0 += 1\r\n\r\n\r\nif num1 > num0:\r\n print(num1 - num0)\r\nif num0 > num1:\r\n print(num0 - num1)\r\nif num1 == num0:\r\n print(0)\r\n",
"n = int(input())\r\nones = input().count(\"1\")\r\nprint(n - 2 * min(ones, n - ones))",
"n = int(input())\r\ns = input()\r\na = 0\r\nb = 0\r\ni = 0\r\nwhile i < n:\r\n if s[i] == '1':\r\n a+=1\r\n else:\r\n b+=1\r\n i+=1\r\nprint(abs(a-b))",
"n = int(input())\ns = [c for c in input()]\n\nnumer_of_ones = s.count(\"1\")\nnumer_of_zeros = s.count(\"0\")\n\nchars_to_delete = min(numer_of_ones, numer_of_zeros) * 2\n\nprint(n - chars_to_delete)\n",
"n = input()\nstring = input()\n\ncount1 = 0\ncount0 = 0\n\nfor i in range(int(n)):\n if string[i] =='1':\n count1+=1\n else:\n count0+=1\n\nif count1 >= count0:\n print(count1-count0)\nelse:\n print(count0-count1)\n \t\t\t \t\t \t \t\t \t \t\t \t \t \t",
"n = int(input())\ndata = input()\n\nzero_count = 0\none_count = 0\n\nfor i in range(len(data)):\n if data[i] == \"0\":\n zero_count += 1\n else: one_count += 1\n\nmenor = zero_count\nif one_count < zero_count:\n menor = one_count\n\nprint(n-(menor*2))\n \t \t\t\t \t \t \t\t \t\t\t \t\t \t\t\t \t",
"# https://codeforces.com/problemset/problem/556/A\r\n\r\n\r\ninput()\r\nc0, c1 = 0, 0\r\nfor i in input():\r\n if i == '0':\r\n c0 += 1\r\n else:\r\n c1 += 1\r\nprint(abs(c1 - c0))",
"def main():\r\n n = int(input())\r\n s = input()\r\n zeros = 0\r\n ones = 0\r\n for i in s:\r\n if i == '0':\r\n zeros += 1\r\n else:\r\n ones += 1\r\n k = min(zeros, ones)\r\n print(len(s)-2*k)\r\nif __name__==\"__main__\":\r\n main()\r\n",
"n = int(input())\r\na = list(input())\r\nfor i in range(n):\r\n a[i] = int(a[i])\r\nb = a.count(1)\r\nc = a.count(0)\r\nif b == c:\r\n print(0)\r\nelse:\r\n print(abs(b-c))",
"n = int(input())\r\nm = input()\r\nc=0\r\nfor i in m:\r\n if i=='0':\r\n c-=1\r\n else:\r\n c+=1\r\nprint(abs(c))",
"n = int(input())\r\n\r\ns = input()\r\n\r\nz, o = s.count('0'), s.count('1')\r\n\r\nprint(n-(z*2) if z<=o else n-(o*2))",
"def main():\r\n input()\r\n lst = [int(x) for x in input()]\r\n print(abs(lst.count(1) - lst.count(0)))\r\n\r\n\r\nmain()\r\n",
"length = int(input())\r\nstring = input()\r\ncount1, count0 = string.count(\"1\"), string.count(\"0\")\r\nprint(length - min(count1, count0)*2)",
"n=int(input())\r\ns=input()\r\no=s.count('0')\r\nl=s.count('1')\r\nprint(n-2*min(o,l))",
"n=int(input())\r\ns=input()\r\non=0\r\nze=0\r\nfor i in s:\r\n if(i=='1'):\r\n on+=1\r\n else:\r\n ze+=1\r\nprint(abs(on-ze))",
"# A. Case of the Zeros and Ones\r\nn = int(input())\r\nstring = input()\r\nlst = list(map(int, string))\r\nres = 0\r\nfor x in range(0, n):\r\n if lst[x] == 1:\r\n res += 1\r\n else:\r\n res -= 1\r\nprint(abs(res))",
"n = int(input())\r\ns = input()\r\nones = 0\r\nzeros = 0\r\nfor i in s:\r\n if i==\"1\":\r\n ones+=1\r\n else:\r\n zeros+=1\r\nprint(n-min(ones,zeros)*2)\r\n \r\n",
"c = input()\r\nn = input()\r\nzeroes = n.count('0')\r\nones = n.count('1')\r\n\r\n\r\n\r\nprint(abs(zeroes - ones))",
"n = int(input())\n\nline = input()\n\nstack = []\n\nfor i in range(n):\n if i == 0:\n stack.append(line[i])\n else:\n if len(stack) > 0 and int(stack[-1]) + int(line[i]) == 1:\n stack.pop()\n else:\n stack.append(line[i])\n\nprint(len(stack))\n \n\t \t\t\t\t \t\t \t\t \t\t\t\t \t\t \t \t",
"n = int(input())\na = str(input())\n# print(bin(a)[2:].count('0'))\nprint(abs(a.count('0') - a.count('1')))\n\n# 10001001100",
"n=int(input())\r\ns=input()\r\nx=s.count('0')\r\ny=s.count('1')\r\nprint(abs(x-y))",
"n=int(input())\r\ns=input()\r\no=s.count(\"1\")\r\nz=s.count(\"0\")\r\nif z>=o:\r\n print(z-o)\r\nelse:\r\n print(o-z)",
"n = int(input())\r\nnum = input()\r\nzero = 0\r\none = 0\r\nfor i in num:\r\n if int(i) == 0:\r\n zero += 1\r\n else:\r\n one += 1\r\nresult = abs(zero - one)\r\nprint(result)",
"n,f = int(input()),input().strip()\r\nprint(n - min(f.count('1'),f.count('0'))* 2)",
"\n\nn = int(input())\n\ns= input()\n\n\n\nans = s.count(\"1\")-s.count(\"0\")\nprint(max(ans,-1*ans))\n",
"from sys import stdin, stdout\r\n\r\ndef main():\r\n n = stdin.readline()\r\n s = stdin.readline()[:-1]\r\n ones = s.count('1')\r\n zeros = len(s)-ones\r\n x = abs(ones-zeros)\r\n stdout.write(str(x)+'\\n')\r\n\r\nif __name__ == \"__main__\":\r\n main()",
"input()\r\ninp = input()\r\n\r\nprint(abs(inp.count(\"1\") - inp.count(\"0\")))\r\n",
"n = int(input())\n\nstring = input()\naux = {1: 0 , 0: 0}\n\nfor s in string:\n if s == '0':\n aux[0] += 1\n else:\n aux[1] += 1\n\nif aux[0] - aux[1] != 0:\n print(abs(aux[0] - aux[1]))\nelse:\n print(0) \n\t \t\t \t\t\t \t \t\t\t \t \t \t \t",
"n=int(input())\nst=input()\nz=0\nc=0\nfor i in st:\n if i=='0':\n z+=1\n else:\n c+=1\nprint(abs(c-z))",
"import sys, os\r\nimport math\r\nfrom collections import Counter\r\n\r\nTC = False\r\n\r\ndef solve():\r\n n = int(input())\r\n s = str(input())\r\n zero, one = 0, 0\r\n for i in range(n):\r\n if s[i] == '1':\r\n one += 1\r\n else:\r\n zero += 1\r\n \r\n if one>zero:\r\n print(len(s)-2*zero)\r\n else:\r\n print(len(s)-2*one)\r\n\r\n\r\n\r\n \r\n\r\nif os.path.exists('input.txt'):\r\n debug = True\r\n sys.stdin = open(\"input.txt\",\"r\")\r\n #sys.stdout = open(\"output.txt\",\"w\")\r\n\r\nif TC:\r\n for _ in range(int(input())):\r\n solve()\r\nelse:\r\n solve()",
"n = int(input())\r\ns = input()\r\nx = s.count('1')\r\ny = s.count('0')\r\n#print(x,y)\r\nprint((n-2*min(x,y)))",
"n = int(input())\r\ns = input()\r\nc = 0\r\nfor i in s:\r\n if i == '1':\r\n c+=1\r\n else:\r\n c-=1\r\nprint(abs(c))",
"a=int(input())\r\nb=input()\r\nc=[]\r\nfor i in b:\r\n c.append(i)\r\nc0=0\r\nfor j in c:\r\n if j=='0':\r\n c0+=1\r\nc1=0\r\nfor k in c:\r\n if k=='1':\r\n c1+=1\r\nif c0>c1:\r\n print(len(c)-c1*2)\r\nelse:\r\n print(len(c)-c0*2)",
"n = int(input())\r\nst = input()\r\none = st.count('1')\r\nzero = st.count('0')\r\nprint(abs(one-zero))",
"n=int(input())\nzero,one =0,0\nfor j in input():\n if j=='1':\n one+=1\n else:\n zero+=1\nn=zero-one\nif n<0:\n n= (-n)\nprint(n)\n \t \t \t\t \t \t\t \t \t \t\t \t \t \t",
"L = int(input())\r\ns = input()\r\nprint(abs(s.count('0')*2-L))\r\n",
"n = int(input())\na = input()\none = 0 ; ze = 0\nfor i in range(len(a)):\n if a[i] =='1':\n one+=1\n else:\n ze+=1\nprint(abs(one - ze ))\n \t \t\t \t\t\t \t \t \t\t \t \t \t",
"n = int(input())\r\ns = input()\r\n\r\none = s.count('1')\r\nzero = s.count('0')\r\n\r\nif one == zero:\r\n print(0)\r\nelse:\r\n if one > zero:\r\n print(n-(2*zero))\r\n else:\r\n print(n-(2*one))",
"n = int(input())\r\ns = input()\r\na = list(s)\r\none = a.count(\"1\")\r\nzero = a.count(\"0\")\r\nif one == zero:\r\n print(0)\r\nelse:\r\n m = min(one, zero)\r\n print(n - (m*2))\r\n\r\n",
"n = int(input())\r\ns = input()\r\nodd = [0, 0]\r\neven = [0, 0]\r\n\r\nfor index in range(1, len(s)+1):\r\n shift = [0, 0]\r\n if s[index-1] == \"0\":\r\n shift[0] = 1\r\n else:\r\n shift[1] = 1\r\n if index % 2 == 0:\r\n even[0] += shift[0]\r\n even[1] += shift[1]\r\n else:\r\n odd[0] += shift[0]\r\n odd[1] += shift[1]\r\n\r\nprint(abs(odd[0]-even[1]) + abs(odd[1]-even[0]))\r\n",
"from collections import Counter\ntest = int(input())\n\nstrings = input()\n\n# while '01' or '10' in strings:\n# if '01' in strings:\n# strings = strings.replace('01', '')\n# elif '10' in strings:\n# strings = strings.replace('10', '')\n# else:\n# break\n#\n# print(len(strings))\n\nx = Counter(strings)\nif (x['0']== x['1']) and (x['0']+ x['1'])==len(strings):\n print(0)\nelif not x['1'] or not x['0']:\n print(len(strings))\nelse:\n a = min(x['0'], x['1'])\n print(len(strings) - 2*a)",
"from collections import Counter\r\n\r\nint(input())\r\nstring = input()\r\nprint(abs(Counter(string)[\"1\"]-Counter(string)[\"0\"]))",
"n=int(input())\r\ns=input()\r\nc0=s.count(\"0\")\r\nc1=s.count(\"1\")\r\nprint(len(s)-2*min(c0,c1))",
"numero = int(input())\r\nlista = input()\r\n\r\ni = 0\r\n\r\nnum1 = 0\r\nnum0 = 0\r\nwhile i < len(lista):\r\n if(lista[i] == \"1\"):\r\n num1 += 1\r\n else:\r\n num0 += 1\r\n i+=1\r\n \r\n\r\nif(num1 > num0):\r\n saida = num1 - num0\r\nelse:\r\n saida = num0 - num1\r\n\r\nprint(saida)",
"n = int(input())\na = list(input())\nprint(len(a)-2 * min(a.count('0'),a.count('1')))\n\n \t\t\t \t\t \t\t\t \t\t \t \t\t \t \t",
"# LUOGU_RID: 113620769\ninput()\na=input()\nprint(abs(a.count('0')-a.count('1')))",
"from sys import stdin\r\n\r\nn = int(stdin.readline().strip())\r\ns = stdin.readline().strip()\r\n\r\nmapping = {}\r\nfor ch in s:\r\n mapping[ch] = mapping.get(ch, 0) + 1\r\n\r\nif mapping.get('1', 0) == 0 or mapping.get('0', 0) == 0:\r\n print(n)\r\nelse:\r\n ans = 0\r\n mini = min(mapping['1'], mapping['0'])\r\n ans = n - (mini*2)\r\n print(ans)\r\n",
"qntd = int(input())\nstring = input()\n\nqntd_1 = string.count('1')\nqntd_0 = string.count('0')\nminimo = qntd_1 - qntd_0 if qntd_1 >= qntd_0 else qntd_0 - qntd_1\nprint(minimo)\n \t\t \t \t\t \t\t \t \t \t \t\t \t\t",
"from collections import deque\r\n\r\nstring_length = int(input())\r\nstring = input()\r\n\r\nd = deque()\r\n\r\nfor number in string:\r\n if (d and d[-1] != number):\r\n d.pop()\r\n else:\r\n d.append(number)\r\n\r\nprint(len(d))",
"n = int(input())\r\nnumber = input()\r\nnumber_ones = 0\r\nfor i in number:\r\n if i==\"1\":\r\n number_ones+=1\r\nprint(abs(n-2*number_ones))\r\n",
"length = int(input())\r\n\r\nstring = input()\r\n\r\ncounterZero = string.count('0')\r\ncounterOne = string.count('1')\r\n\r\nprint(len(string) - (min(counterZero, counterOne) * 2))",
"n = int(input())\r\ncnt1 = 0\r\ncnt0 = 0\r\nstrn = str(input())\r\nfor i in strn:\r\n if(i == \"1\"):\r\n cnt1 += 1\r\n else:\r\n cnt0 += 1\r\n\r\nprint(abs(cnt0-cnt1))",
"def main() -> int:\r\n _ = int(input())\r\n my_str = [1 if int(x) else -1 for x in input()]\r\n return abs(sum(my_str))\r\n\r\nif __name__ == '__main__':\r\n print(main())",
"n = int(input())\r\nS = input() \r\nones = S.count('1')\r\nzeros = n - ones\r\n\r\nprint(n - 2*min(ones, zeros))",
"qtd_digitos = int(input())\ndigitos = list(map(int, input().replace('', ' ').strip().split(' ')))\n\nqtd_zeros = digitos.count(0)\nqtd_uns = digitos.count(1)\n\nprint (abs(qtd_zeros - qtd_uns))",
"size = int(input())\r\nline = list(input())\r\nzeros = line.count('0')\r\nones = line.count('1')\r\nretorno = abs(zeros - ones)\r\nprint(retorno)",
"n = input()\nbstr = input()\n\npilha_zero = []\npilha_um = []\n\nfor c in bstr:\n\n if c == '0':\n\n if len(pilha_um) > 0:\n pilha_um.pop()\n else:\n pilha_zero.append(c)\n \n else:\n\n if len(pilha_zero) > 0:\n pilha_zero.pop()\n else:\n pilha_um.append(c)\n\nprint(len(pilha_zero) + len(pilha_um))",
"k=int(input())\r\nn=list(map(int,input()))\r\nprint(abs(k-(sum(n)*2)))",
"x = input()\r\ny = input()\r\nprint(abs(int(x)-2*y.count('1')))",
"n = int(input())\r\ns = input()\r\nc0,c1=0,0\r\nfor i in s:\r\n if i =='0':\r\n c0+=1\r\n else:\r\n c1+=1\r\nif c0>c1:\r\n print(c0-c1)\r\nelse:\r\n print(c1-c0)\r\n",
"n=int(input())\ns=input()\nc0=0\nc1=0\nfor i in s:\n if i=='0':\n c0=c0+1\n elif i=='1':\n c1=c1+1\nif c0>=c1:\n print(n-(2*c1))\nelif c1>c0:\n print(n-(2*c0))\n \t\t \t\t \t\t \t\t \t \t \t \t",
"n=int(input())\r\na=list(map(int,input()))\r\nr=[]\r\nfor i in a:\r\n if r==[]:\r\n r.append(i)\r\n else:\r\n if r[-1]!=i:\r\n r.pop()\r\n else:\r\n r.append(i)\r\nprint(len(r))",
"'''\r\n# Submitted By M7moud Ala3rj\r\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\r\n'''\r\n# Problem Name = \"Case of the Zeros and Ones2\"\r\n# Class: A\r\n\r\nimport sys\r\n#sys.setrecursionlimit(2147483647)\r\ninput = sys.stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n sys.stdout.write(sep.join(map(str, args)) + end)\r\n\r\nfrom collections import deque\r\n\r\nclass Stack:\r\n\r\n def __init__(self, elements : list = []):\r\n self.container = deque(elements)\r\n \r\n def push(self, x):\r\n self.container.append(x)\r\n \r\n def pop(self):\r\n return self.container.pop()\r\n \r\n def peek(self):\r\n return self.container[-1]\r\n \r\n def empty(self):\r\n return len(self.container)==0\r\n \r\n def size(self):\r\n return len(self.container)\r\n \r\n def __str__(self):\r\n return '{0}'.format(self.container)\r\n\r\ndef Solve():\r\n n = int(input())\r\n s = input().strip()\r\n stack = Stack()\r\n for i in s[::-1]:\r\n if not stack.empty():\r\n if stack.peek() != i:\r\n stack.pop()\r\n else:\r\n stack.push(i)\r\n else:\r\n stack.push(i)\r\n \r\n print(stack.size())\r\n\r\nif __name__ == \"__main__\":\r\n Solve()",
"n = int(input())\r\nnumber = list(input())\r\nzeros = [e for e in number if e == \"0\"]\r\nones = [e for e in number if e == \"1\"]\r\nx = min(len(zeros), len(ones))\r\nprint(len(number)-x*2)",
"a = input()\r\nb = input()\r\n\r\nnull = b.count(\"0\") \r\none = b.count(\"1\")\r\n\r\nprint(null-one) if null > one else print(one-null) ",
"n = int(input())\r\ns = input()\r\ncount1, count0 = 0, 0\r\nfor i in s:\r\n if i == '1':\r\n count1 += 1\r\n else:\r\n count0 += 1\r\nprint(abs(count0 - count1))\r\n",
"n = input()\r\ns1 = input()\r\nprint(abs(s1.count('1')-s1.count('0')))",
"n = int(input())\ns = str(input())\nz = 0\no = 0\nfor i in s:\n if i=='0':\n z+=1\n else:\n o+=1\n \na = abs(z-o)\nprint(a)\n\t \t\t\t \t \t \t \t\t \t\t\t \t",
"n = int(input())\nstring = input()\nzeros, ones = string.count(\"0\"), string.count(\"1\")\nprint(abs(zeros-ones))\n\t\t \t \t\t \t \t\t \t\t \t \t\t\t\t",
"string_length = int(input())\ns = input().count('1')\nprint(string_length-2*min(s,string_length-s))\n",
"n = int(input())\r\ns = input()\r\n\r\ncount_0 = s.count('0')\r\ncount_1 = s.count('1')\r\n\r\noperations = min(count_0, count_1)\r\nmin_length = n - 2 * operations\r\n\r\nprint(min_length)",
"t=int(input())\r\na=input()\r\nb=a.count(\"1\")\r\nc=a.count(\"0\")\r\nprint(abs(b-c))\r\n",
"input()\r\nresult = list(input())\r\n\r\nresult.sort()\r\n\r\nif '1' in result:\r\n amount_of_zero = result.index('1')\r\n amount_of_one = len(result)-amount_of_zero\r\n\r\n diff = amount_of_one-amount_of_zero\r\n\r\n if diff > 0:\r\n print(diff)\r\n else:\r\n print(-diff)\r\nelse:\r\n print(len(result))",
"n = int(input())\r\ns = input()\r\none = s.count(\"1\")\r\nzero = s.count(\"0\")\r\n\r\nif one == zero:\r\n print(0)\r\nelse:\r\n result = abs(one - zero)\r\n print(result)",
"n = int(input())\r\nstring = input()\r\n\r\nsum_1 = 0\r\n\r\nfor i in string:\r\n if i == '1':\r\n sum_1 += 1\r\n\r\nsum_0 = n - sum_1\r\n\r\nprint(abs(sum_1-sum_0))",
"n = int(input())\r\ns = input()\r\nprint(abs(n - 2*s.count(\"0\")))",
"n = int(input())\r\ns = input()\r\none=0\r\nzero=0\r\n\r\nfor i in range(0,len(s)):\r\n if s[i]==\"0\":\r\n zero=zero+1\r\n elif s[i]==\"1\":\r\n one=one+1\r\n\r\n\r\nprint(abs(one-zero))",
"from sys import stdin, stdout\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nfor i in range(1):#nmbr()):\r\n n=nmbr()\r\n s=input()\r\n print(abs(s.count('1')-s.count('0')))",
"n = int(input())\r\ns = input()\r\na = s.count(\"0\")\r\nb = s.count(\"1\")\r\nif a == b:\r\n print(\"0\")\r\nelif a > b:\r\n print(len(s) - 2 * b)\r\nelse:\r\n print(len(s) - 2 * a)\r\n",
"n = int(input())\ns = input()\n\nfreq = [0, 0]\nfor i in range(n):\n if s[i] == \"1\":\n freq[1] += 1\n else:\n freq[0] += 1\n\ncount = min(freq[0], freq[1]) * 2\nans = n - count\nprint(ans)\n\t \t\t \t \t \t \t\t\t\t\t\t\t \t \t \t",
"n=input();a = list(input());print(abs(a.count('0') - a.count('1')))\r\n",
"count0 = count1 = 0\r\nn = int(input())\r\nl = list(input())\r\nfor i in l:\r\n if i == '0':count0 += 1\r\n else: count1 += 1\r\nprint(abs(count1-count0))",
"# from sys import stdin, stdout\r\n# import math\r\n# import re\r\n# import itertools\r\nimport collections\r\n# import statistics\r\n# import calendar\r\n# import datetime\r\n# import operator\r\n# import cProfile\r\n# import pstats\r\n\r\n################################### TEMPLATE #################################\r\n# def DEBUGGER_seperate():\r\n# print('-'*50)\r\n \r\n# def is_odd(n: int):\r\n# return True if bool(n & 1) else False\r\n\r\n\r\n# arr = list(map(int, input().split()))\r\n################################### TEMPLATE #################################\r\n\r\n\r\ndef solve(n:int, s: str):\r\n d = collections.Counter(s)\r\n return n - (min(d['0'], d['1'])*2)\r\n \r\n\r\ndef main():\r\n n = int(input())\r\n string = input()\r\n print(solve(n, string))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()",
"n=int(input())\r\na=input()\r\nb=a.count(\"1\")\r\nc=a.count(\"0\")\r\nif b==c:\r\n print(\"0\")\r\nelif b>c:\r\n print(b-c)\r\nelif b<c:\r\n print(c-b)\r\n",
"x=int(input())\r\ny=input()\r\ns1=0\r\ns0=0\r\nfor i in range(0,x):\r\n if y[i]=='0':\r\n s0+=1\r\n else:\r\n s1+=1\r\nprint(abs(s0-s1))\r\n",
"n = int(input())\r\n\r\ns = input()\r\ncount = ''\r\n\r\nzer = s.count('0')\r\none = s.count('1')\r\n\r\nprint(n - (2*(min(zer, one))))\r\n\r\n\r\n\r\n",
"n = int(input())\r\nzo = input()\r\nl = []\r\no = 0\r\nz = 0\r\ncount = 0 \r\nfor i in zo:\r\n l.append(i)\r\nfor j in range(n):\r\n if l[j]==\"1\":\r\n o+=1\r\n else:\r\n z+=1\r\nz=min(z,o)\r\nprint(n-(2*z))",
"from sys import stdin\t\r\nfrom collections import Counter\r\n\r\n\r\ndef readarray(typ):\r\n return list(map(typ, stdin.readline().split()))\r\n\r\n\r\nn = int(input())\r\n\r\ns = input()\r\n\r\n\r\ns = Counter(list(s))\r\n\r\nif '0' not in s or '1' not in s:\r\n print(n)\r\nelse:\r\n while s['0'] > 0 and s['1'] > 0:\r\n s['0'] -= 1\r\n s['1'] -= 1\r\n \r\n print(sum(s.values()))\r\n\r\n",
"m=input()\r\nn=input()\r\nzeros=0\r\nones=0\r\nfor i in n:\r\n if i=='0':\r\n zeros+=1\r\n else:\r\n ones+=1\r\n\r\nprint(abs(ones-zeros))",
"n = int(input())\r\ntext_input = input()\r\n\r\na = text_input.count(\"0\")\r\nb = text_input.count(\"1\")\r\nc = min(a, b)\r\n\r\nprint(len(text_input) - (2 * c))\r\n",
"m=int(input())\r\nn=input()\r\ne=n.count('1')\r\no=n.count('0')\r\nif(e==o):\r\n print(0)\r\nelse:\r\n print(abs(e-o))",
"from collections import Counter\r\n\r\ndef case_of_zeros_and_ones():\r\n\r\n n = int(input())\r\n\r\n s = input()\r\n\r\n\r\n\r\n counts = Counter(s)\r\n\r\n\r\n if len(counts) == 1:\r\n print(n)\r\n else:\r\n print( n - min(counts.values()) * 2)\r\n\r\n\r\n\r\ncase_of_zeros_and_ones()\r\n\r\n\r\n\r\n\r\n",
"import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\ns = list(input().rstrip())\r\ncnt = [0] * 2\r\nfor i in s:\r\n cnt[i & 1] += 1\r\nans = abs(cnt[0] - cnt[1])\r\nprint(ans)",
"n = int(input())\r\narr = input()\r\na = b = 0\r\nfor e in arr:\r\n if e == '0':\r\n a += 1\r\n else:\r\n b += 1\r\nprint(abs(a - b))",
"length = int(input())\r\nastring = input()\r\none = astring.count(\"1\")\r\nprint(length - 2*min(length - one, one))",
"n=int(input())\r\ns=input()\r\nprint(abs(n-2*s.count(\"0\")))",
"n = int(input())\r\ns = input()\r\nones,zeros = s.count('1'),s.count('0')\r\nprint(n-(min(ones,zeros)*2))",
"n=int(input())\r\ns=input()\r\nc0=s.count(\"0\")\r\nc1=s.count(\"1\")\r\nprint(c0+c1-2*min(c0,c1))\r\n",
"number = int(input())\r\ncase = input()\r\n\r\nnumberOf0 = case.count('0')\r\nnumberOf1 = case.count('1')\r\nif numberOf0 < numberOf1:\r\n print(len(case)- 2*numberOf0)\r\nelse:\r\n print(len(case)- 2*numberOf1)",
"\r\na=int(input())\r\nb=input()\r\nzero=b.count('0')\r\nones=b.count('1')\r\nprint(abs(zero-ones))",
"num=input()\r\nst=input()\r\ncoun1,coun2=0,0\r\nfor i in st:\r\n if i=='0':\r\n coun1+=1\r\n else:\r\n coun2+=1\r\nprint(max(coun1,coun2)-min(coun1,coun2))",
"n = int(input())\r\nt = input()\r\nkol1=t.count('0')\r\nkol2=t.count('1')\r\nprint(n-(min(kol1,kol2)*2))\r\n ",
"n = int (input ())\na = input ()\none = 0 ; ze = 0\nfor i in range (len(a)):\n if a [i] == \"1\":\n one += 1\n else :\n ze += 1\nprint (abs (one-ze))\n \n \t \t \t\t\t \t \t \t \t \t \t\t\t \t \t \t \t",
"\r\nimport math as mth\r\nimport sys\r\n#input=sys.stdin.readline\r\n\r\n\r\n\r\ndef solve():\r\n \r\n #n,m=map(int,input().split())\r\n #a=list(map(int,input().split()))\r\n \r\n n=input()\r\n s=input()\r\n z_cnt=s.count(\"0\")\r\n ones_cnt=s.count(\"1\")\r\n print(abs(z_cnt-ones_cnt))\r\n return\r\n\r\ndef main():\r\n #for _ in range(int(input())):\r\n solve()\r\n return\r\n\r\n\r\nif __name__ == '__main__':\r\n main()",
"# Online Python compiler (interpreter) to run Python online.\r\n# Write Python 3 code in this online editor and run it.\r\nn=int(input())\r\ns=str(input())\r\nc1=0\r\nc0=0\r\nfor i in range(0,n):\r\n if s[i]=='0':\r\n c0=c0+1\r\n if s[i]=='1':\r\n c1=c1+1\r\nprint(abs(c1-c0))",
"import math\r\nn = int(input())\r\na = input()\r\nx = a.count(\"1\")\r\ny = a.count(\"0\")\r\nprint(abs(x-y))",
"n=int(input())\nl=[int(i) for i in input()]\n\ncount_0=0\ncount_1=0\n\nfor i in l:\n if i==0:\n count_0+=1\n else:\n count_1+=1\n\nt=count_0-count_1\nprint(abs(t))\n\t\t \t \t\t \t \t\t\t\t \t\t \t \t",
"#https://codeforces.com/problemset/problem/556/A\r\nn = int(input())\r\nn_ones = sum([int(x) for x in input() if x == \"1\"])\r\nn_zeroes = n - n_ones\r\nprint(abs(n_zeroes-n_ones))\r\n",
"n = int(input())\ns = input()\nzeros = s.count(\"0\")\nones = n-zeros\nprint(max(zeros, ones)-min(zeros, ones))",
"n = int(input())\r\nst = input()\r\nt0 = st.count(\"0\")\r\nt1 = st.count(\"1\")\r\nprint(abs(t1-t0))",
"from sys import stdin\r\n\r\nlen = int(stdin.readline())\r\nsen = stdin.readline()\r\ncnt1 = 0\r\ncnt0 = 0\r\n\r\nfor i in range(len):\r\n if sen[i] == \"1\":\r\n cnt1 += 1\r\n else:\r\n cnt0 += 1\r\n\r\nprint(abs(cnt0 - cnt1))",
"n = int(input())\r\ns = input()\r\nres1, res2 = 0, 0\r\nfor i in s:\r\n if i == '0':\r\n res1 += 1\r\n else:\r\n res2 += 1\r\nprint(n - min(res1, res2) * 2)",
"n = int(input())\r\na = input()\r\nprint(max(a.count('1'), a.count('0'))-min(a.count('1'), a.count('0')))",
"input()\r\nls=list(input())\r\ns1=ls.count('1')\r\ns0=ls.count(\"0\")\r\nmaxs=max(s1,s0)\r\nmins=min(s1,s0)\r\nprint(maxs-mins)",
"def solve(s):\r\n occurrences = [0, 0]\r\n\r\n for c in s:\r\n occurrences[c] += 1\r\n\r\n return len(s) - 2 * min(occurrences)\r\n\r\ndef main():\r\n _ = int(input())\r\n s = [int(c) for c in input()]\r\n \r\n result = solve(s)\r\n \r\n print(result)\r\n \r\nif __name__ == \"__main__\":\r\n main()",
"n= int(input())\ncase = input()\nprint(abs(case.count(\"1\") - case.count(\"0\")))",
"from collections import Counter\r\n\r\nn = int(input())\r\ns = Counter(input())\r\nif (not s.keys().__contains__('0')):\r\n s['0'] = 0\r\nif (not s.keys().__contains__('1')):\r\n s['1'] = 0\r\nprint(n - 2 * min(s.values()))",
"n=int(input())\r\ns=input()\r\nczero,cone=0,0\r\nfor i in range(0,len(s)):\r\n if(s[i]=='1'):\r\n cone+=1\r\n else:\r\n czero+=1\r\nif(czero==cone):\r\n print(0)\r\nelse:\r\n print(abs(czero-cone))\r\n \r\n",
"n=int(input())\r\nl=[int(x) for x in input()]\r\nz=l.count(0)\r\no=l.count(1)\r\nprint(abs(z-o))",
"n=int(input())\r\na=str(input())\r\none_count=zero_count=0\r\none_count=a.count(\"1\")\r\nzero_count=a.count('0')\r\n# for i in a:\r\n# if a==\"1\": one_count+=1\r\n# elif a==\"0\": zero_count+=1\r\nprint(abs(one_count-zero_count))",
"t = int(input())\r\ns=input()\r\n\r\nprint(abs(s.count('0')-s.count('1')))",
"n=int(input(\"\"))\r\nnum=input(\"\")\r\none=num.count(\"1\")\r\nzero=num.count(\"0\")\r\nans=zero-one\r\nprint(abs(ans))",
"input();n=input();print(len(n)-2*min(n.count('1'),n.count('0')))",
"n = int(input())\r\ns = input()\r\nzeroes = 0\r\nones = 0\r\nd = 0\r\nfor i in range(len(s)):\r\n if(s[i] == '0'):\r\n zeroes = zeroes + 1\r\n else:\r\n ones = ones + 1\r\nif(ones >= zeroes):\r\n d = zeroes\r\nelse:\r\n d = ones\r\nprint(n - 2 * d)",
"n = int(input())\r\ns = input().strip()\r\nz = s.count(\"0\")\r\no = s.count(\"1\")\r\nans = len(s)\r\nans -= min(z, o)*2\r\nprint(ans)",
"n=int(input())\r\nn1=input()\r\np=0\r\nk=0\r\nfor i in range(len(n1)):\r\n if n1[i]=='1':p=p+1\r\n if n1[i]=='0':k=k+1\r\nprint(abs(p-k))\r\n",
"a = input()\r\na = list(input())\r\nf = map(int, a)\r\nnum = sum(f)\r\nzero = len(a) - num\r\nif num < zero:\r\n f = zero - num\r\n\r\nelse:\r\n f = num - zero\r\nprint(f)",
"n = int(input())\r\n\r\nstring = input()\r\n\r\nstack = []\r\nfor char in string:\r\n if not stack: stack.append(char)\r\n else:\r\n if stack[-1] == char:\r\n stack.append(char)\r\n else:\r\n stack.pop()\r\nprint(len(stack))",
"from math import*\r\nn=int(input())\r\ns=input()\r\ncnt0=0;cnt1=0;\r\nfor i in range(n):\r\n if s[i]=='1':\r\n cnt1+=1\r\n else:\r\n cnt0+=1\r\nprint(abs(cnt0-cnt1))",
"size = int(input())\r\n\r\nll = list(input())\r\n\r\nzeros = 0\r\nones = 0\r\nfor l in ll:\r\n if l == '0':\r\n zeros += 1\r\n else: \r\n ones +=1 \r\n \r\n \r\nresult = abs(zeros - ones)\r\nprint(result)",
"n = int(input())\r\ns = input()\r\nones = s.count('1')\r\nzeroes = s.count('0')\r\nunion = min(ones, zeroes)\r\nprint(n-2*union)",
"n = int(input())\r\ns = input()\r\n\r\ntotal_one = s.count('1')\r\ntotal_zero = s.count('0')\r\nresult = 0\r\nif(total_one > total_zero):\r\n result = total_one - total_zero\r\nelse:\r\n result = total_zero - total_one\r\nprint(result)\r\n \r\n ",
"n=int(input())\r\ns=input()\r\na=[s[0]]\r\nfor i in range(1,n):\r\n if len(a)==0:\r\n a.append(s[i])\r\n continue\r\n if a[len(a)-1]+s[i]=='10' or a[len(a)-1]+s[i]=='01':\r\n del a[len(a)-1]\r\n else:\r\n a.append(s[i])\r\nprint(len(a))",
"t = int(input())\n# n, m = map(int, input().split())\ns = input()\no = 0\nz = 0\nfor i in s:\n if i == \"1\":\n o += 1\n else:\n z += 1\nprint(abs(z - o))\n# while t != 0:\n# # n = int(input())\n# t -= 1\n",
"print(abs(int(input())-input().count('0')*2))",
"elem = int(input())\r\ns = input()\r\nzero = 0\r\none = 0\r\nfor i in range(len(s)):\r\n if s[i] == '0':\r\n zero = zero + 1\r\n else:\r\n one = one + 1\r\nprint(abs(one - zero))",
"# Bismillah\r\n# In the name of GOD\r\n\r\nn = int(input())\r\ni = n\r\ns = input()\r\nz = 0\r\no = 0\r\nwhile i > 0:\r\n\ti -= 1\r\n\tif s[i] == '0':\r\n\t\tz += 1\r\n\telse:\r\n\t\to += 1\r\nprint(n - min(z, o) * 2)\r\n",
"n = int(input())\r\n\r\ns = input()\r\n\r\nzero, one = 0,0\r\nfor c in s:\r\n if c=='0':\r\n zero +=1\r\n else :\r\n one+=1\r\n\r\nprint(len(s) - min(zero, one)*2)",
"n=int(input())\r\ns=input()\r\nk=s.count('0')\r\nl=s.count('1')\r\nprint(len(s)-min(k,l)*2)",
"n = int(input())\r\ns = input()\r\na = 0\r\nb = 0\r\nfor i in range(n):\r\n if s[i] == '1':\r\n a += 1\r\n else:\r\n b += 1\r\nc = a\r\nif b < c:\r\n c = b\r\nprint(n - 2 * c)",
"n=int(input())\r\nstring=input()\r\ncount0=0\r\ncount1=0\r\nfor i in range(n):\r\n if string[i]=='1':\r\n count0+=1\r\n else:\r\n count1+=1\r\n\r\nanswer=count0+count1-(2*min(count0,count1))\r\nprint(answer)",
"\r\ndef answer(length, n):\r\n return abs(n.count('1') - n.count('0'))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ndef main():\r\n length = int(input())\r\n n = input() #keep as string\r\n print(answer(length, n))\r\n \r\n \r\n \r\n \r\n\r\n\r\nmain()",
"n=int(input())\r\ns=input()\r\na=[0, 0]\r\nfor i in range(0,n):\r\n a[int(s[i])]+=1\r\nprint(n-2*min(a[0], a[1]))\r\n",
"from collections import Counter\r\n\r\n\r\nn = int(input())\r\nstring = input()\r\nd = Counter(string)\r\nprint(abs(d[\"0\"] - d[\"1\"]))",
"# TLE\r\nl = int(input())\r\nn = [*input()]\r\n\r\nz, u = n.count(\"0\"), n.count(\"1\")\r\n\r\nprint(abs(u - z))",
"t=int(input())\r\ny=str(input())\r\ns=y.count(\"1\")\r\nx=y.count(\"0\")\r\nif x<s:\r\n g=int(t)-(x*2)\r\nelse:\r\n g=int(t)-(s*2)\r\nprint(g)",
"import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\n\r\nstring = input()\r\nstring = list(string[:len(string) - 1])\r\n\r\nsum0 = 0\r\nsum1 = 0\r\n\r\nfor s in string:\r\n if s == '0':\r\n sum0 += 1\r\n else:\r\n sum1 += 1\r\n\r\nprint(max(sum0, sum1) - min(sum0, sum1))\r\n\r\n\r\n",
"n = int(input())\r\ns = input()\r\n\r\noc = s.count(\"0\")\r\nzc = s.count(\"1\")\r\n\r\nif oc==zc:\r\n print(0)\r\nelif abs(oc-zc)==1:\r\n print(1)\r\nelse:\r\n print(abs(oc-zc))",
"n = int(input())\r\nl = input().count(\"1\")\r\n\r\nprint(n - 2 * min(l, n - l))\r\n",
"n = int(input())\ns = input()\n\nstack = []\nfor c in s:\n if stack and stack[-1] != c:\n stack.pop()\n else:\n stack.append(c)\n\nprint(len(stack))\n\n\t \t \t \t \t \t\t \t\t\t \t\t\t \t \t\t \t",
"n = int(input())\r\nstring = input()\r\nones = string.count('1')\r\nzeroes = string.count('0')\r\nprint(abs(ones-zeroes))",
"#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-30 23:33:21\nLastEditTime: 2021-11-30 23:34:38\nDescription: Case of the Zeros and Ones\nFilePath: CF556A.py\n'''\n\n\ndef func():\n n = int(input())\n num = input().strip()\n print(abs(num.count(\"1\") - num.count(\"0\")))\n\n\nif __name__ == '__main__':\n func()\n",
"n = int(input())\ns = input()\nct0, ct1 = 0, 0\nfor i in range(len(s)):\n if s[i] == '0':\n ct0 += 1\n else:\n ct1 += 1\n\nprint(abs(ct0-ct1))",
"n=int(input())\r\ns=input()\r\none=0\r\nfor i in range(n):\r\n if s[i]=='1':\r\n one += 1\r\nzero = n- one\r\nmn = min(zero,one)\r\nmn *= 2\r\nprint(n - mn)",
"# A. Case of the Zeros and Ones\r\nn=int(input())\r\ns=input()\r\no=s.count(\"1\")\r\nc=min(o,n-o)*2\r\nprint(n-c)",
"n = int(input())\r\ns = input()\r\no = s.count('1')\r\nz = s.count('0')\r\nprint(abs(o-z))",
"n = int(input())\r\ns = input()\r\nst = []\r\nfor i in s:\r\n if len(st) == 0 or i == st[-1]:\r\n st.append(i)\r\n else:\r\n st.pop()\r\nprint(len(st))",
"n=int(input())\r\nnum=input()\r\nc0,c1=0,0\r\nfor i in num:\r\n if(i=='0'):\r\n c0+=1\r\n else:\r\n c1+=1\r\nmax=max(c0,c1)\r\nmin=min(c0,c1)\r\nprint(max-min)\r\n",
"from math import *\r\nn = int(input())\r\ns = input(); one = 0; zero = 0\r\nfor i in range(n):\r\n if (s[i] == '1'):\r\n one += 1\r\n else:\r\n zero += 1\r\nprint(abs(one - zero))",
"user_input = int(input())\na = list(map(int, input()))[:user_input]\n\nprint(abs(a.count(1) - a.count(0)))\n\t \t\t\t\t \t \t \t \t \t\t\t\t \t \t\t\t \t",
"input();x=input()\r\nprint(abs(x.count(\"0\") - x.count(\"1\")))",
"q = map(int, input().split())\r\nr = input()\r\no = 0\r\nt = 0\r\nfor i in r:\r\n if i == '0':\r\n o += 1\r\n else:\r\n t += 1\r\nprint(max(t, o) - min(o, t))",
"n=int(input())\r\ns=input()\r\na=s.count('0')\r\nb=s.count('1')\r\nc=a-b\r\nif c<0:\r\n c=c-c*2\r\n print(c)\r\nelse:\r\n print(c)",
"n=int(input())\r\ns=input()\r\nprint(n-min(s.count('0'),s.count('1'))*2)",
"length = int(input())\r\n\r\ninp = input()\r\none_counter = 0\r\nzero_counter = 0\r\nfor i in inp:\r\n if i == '1':\r\n one_counter += 1\r\n else:\r\n zero_counter += 1\r\nprint(abs(one_counter-zero_counter))\r\n",
"def min_length_after_operations(n, s):\r\n stack = []\r\n for i in range(n):\r\n if len(stack) > 0 and stack[-1] != s[i]:\r\n stack.pop()\r\n else:\r\n stack.append(s[i])\r\n return len(stack)\r\n\r\n# Read input\r\nn = int(input())\r\ns = input()\r\n\r\n# Call the function and print the result\r\nresult = min_length_after_operations(n, s)\r\nprint(result)\r\n",
"n = int(input())\r\ndata = [char for char in input()]\r\n\r\na = 0\r\nb = 0\r\n\r\nfor d in data: \r\n\r\n if d == '0':\r\n a += 1\r\n\r\n else:\r\n b += 1\r\n\r\naux = abs(a - b)\r\n\r\nprint(aux)",
"Number=int(input())\r\nstring=input()\r\ncount=0\r\nsumNum=0\r\nfor i in range(Number):\r\n if(string[i]==\"0\"):\r\n count+=1\r\n elif(string[i]==\"1\"):\r\n sumNum+=1\r\nprint(abs(sumNum-count))\r\n",
"n=int(input())\nbinaryString=input()\ncount=0\ncountZ=0\nfor i in range(n):\n if binaryString[i]=='1':\n count+=1\n else:\n countZ+=1\nprint(n-(min(count,countZ))*2)",
"n = int(input())\r\ns = str(input())\r\ns_new = []\r\n\r\nfor i in s:\r\n val = int(i)\r\n s_new.append(val)\r\n\r\none_count = 0\r\nzero_count = 0\r\n\r\nfor i in range(0,len(s_new)):\r\n if s_new[i] == 1:\r\n one_count += 1\r\n elif s_new[i] == 0:\r\n zero_count += 1\r\n\r\nif one_count > zero_count:\r\n one_count -= zero_count\r\n zero_count = 0\r\n print(one_count)\r\n\r\nelif zero_count > one_count:\r\n zero_count -= one_count\r\n one_count = 0\r\n print(zero_count)\r\n\r\nelif zero_count == one_count:\r\n print(0)",
"n = int(input())\ns = input()\nzero = s.count(\"0\")\nif zero > n//2: ans = n - 2*(n-zero)\nelse: ans = n - 2*zero\nprint(ans)\n \t \t\t\t \t\t \t \t \t\t \t\t\t\t\t\t\t",
"def main():\r\n l=int(input())\r\n s=input()\r\n x =min( s.count('0'),s.count('1'))\r\n return l-(x*2)\r\nprint(main())\r\n",
"n = int(input())\r\ns = input()\r\nl = list(s)\r\none = l.count('1')\r\nzero = l.count('0')\r\nm = min(one,zero)\r\nif m == one:\r\n print(zero-m)\r\nelse:\r\n print(one-m)\r\n\r\n\r\n",
"n=int(input())\r\ns=input()\r\nn1=s.count('1')\r\nn2=s.count('0')\r\nv=min(n1,n2)\r\nans=n-v*2\r\nprint(ans)",
"from math import fabs\r\ninp = int(input())\r\nst = input()\r\nprint(int(fabs(st.count('1')-st.count('0'))))",
"a=int(input())\r\ns=input()\r\n\r\nzero=s.count('0')\r\none=s.count('1')\r\nprint(abs(one-zero))\r\n",
"input()\r\ns = list(input())\r\nx = []\r\nfor i in s:\r\n if not x:\r\n x.append(i)\r\n else:\r\n if x[-1] != i:\r\n x.pop()\r\n else:\r\n x.append(i)\r\nprint(len(x))\r\n",
"m=int(input())\r\nn=input()\r\ns=\"\"\r\nsm=\"\"\r\nfor i in n:\r\n if(i==\"0\"):\r\n s+=i\r\n else:\r\n sm+=i \r\nif(len(s)>len(sm)):\r\n print(len(n)-2*len(sm))\r\nelif(len(s)<len(sm)):\r\n print(len(n)-2*len(s))\r\nelif(len(s)==len(sm)):\r\n print(len(n)-2*len(s))\r\n ",
"n = int(input())\r\nbinary = input()\r\ndelete = min(binary.count('0'), binary.count('1'))\r\nprint(n - (2 * delete))"
] | {"inputs": ["4\n1100", "5\n01010", "8\n11101111", "1\n0", "1\n1", "2\n00", "2\n01", "2\n10", "2\n11", "3\n001", "6\n110110", "7\n0000011", "6\n110010", "6\n110100", "3\n100", "6\n010111", "8\n01011100", "6\n001011", "7\n1110000", "9\n011111101"], "outputs": ["0", "1", "6", "1", "1", "2", "0", "0", "2", "1", "2", "3", "0", "0", "1", "2", "0", "0", "1", "5"]} | UNKNOWN | PYTHON3 | CODEFORCES | 684 | |
3276d7d8749b698eee6a4ed34e59647f | BF Calculator | In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators.
You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression.
We use a fairly standard Brainfuck interpreter for checking the programs:
- 30000 memory cells.- memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.- console input (, command) is not supported, but it's not needed for this problem.
The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries).
Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps.
Sample Input
2+3
9-7
Sample Output
++>
+++>
<[<+>-]<
++++++++++++++++++++++++++++++++++++++++++++++++.
+++++++++>
+++++++>
<[<->-]<
++++++++++++++++++++++++++++++++++++++++++++++++.
| [
"a = input()\r\nb = int(eval(a))\r\nres = '+' * 48;\r\nif b >= 200:\r\n res += \"++.--\";\r\n b -= 200;\r\nelif b >= 100:\r\n res += \"+.-\";\r\n b -= 100;\r\nk = b // 10\r\nb %= 10\r\nif k > 0:\r\n res += (\"+\" * k + '.' + '-' * k)\r\nres += ('+' * b + '.')\r\n \r\nprint(res)",
"#By: Luogu@rui_er(122461)\r\nx = eval(input())\r\n\r\ndef gen_bf(x):\r\n expr = \"\"\r\n for i in range(x+48):\r\n expr += \"+\"\r\n expr += \".[-]\"\r\n return expr\r\n\r\nbf = \"\"\r\nif x >= 100:\r\n bf += gen_bf(x//100)\r\n bf += gen_bf(x//10%10)\r\n bf += gen_bf(x%10)\r\nelif x >= 10:\r\n bf += gen_bf(x//10)\r\n bf += gen_bf(x%10)\r\nelse:\r\n bf += gen_bf(x)\r\nprint(bf)\r\n",
"s = input()\nans = eval(s)\nlst = list()\nif ans == 0:\n lst.append(0)\nwhile ans:\n lst.append(ans%10)\n ans //= 10\nlst.reverse()\nidx = 0\nfor i in lst:\n num = i+48\n while idx < num:\n print('+', end=\"\")\n idx+=1\n while idx > num:\n print('-', end=\"\")\n idx-=1\n print('.')\n\n\t \t\t\t \t\t\t\t \t\t\t\t\t \t \t",
"str = input()\r\nres = eval(str)\r\n\r\na = res // 100\r\nb = res // 10 % 10\r\nc = res % 10\r\n\r\ndef getans(x: int):\r\n for i in range(0, 48 + x):\r\n print('+', end = \"\")\r\n print('.>', end = \"\")\r\n\r\nif a != 0:\r\n getans(a)\r\nif b != 0:\r\n getans(b)\r\ngetans(c)\r\n",
"inp = input()\nnum = str(eval(inp))\nfor i in num:\n print('>' + '+'*ord(i) + '.')\n\n\t\t \t\t\t \t \t \t \t \t\t \t \t \t\t",
"for d in str(eval(input())):\n print(ord('0')*'+' + int(d)*'+' + '.>')\n",
"expr = input()\r\nres = eval(expr)\r\n\r\nr1 = res // 100\r\nr2 = res % 100 // 10\r\nr3 = res % 10\r\n\r\ndef brainfxxk(x: int):\r\n for i in range(0, 48 + x):\r\n print(\"+\", end=\"\")\r\n print(\".>\", end=\"\")\r\n\r\nif r1 != 0:\r\n brainfxxk(r1)\r\nif r2 != 0:\r\n brainfxxk(r2)\r\nbrainfxxk(r3)",
"x = eval(input())\r\nprint('+' * 48)\r\nfor c in str(x):\r\n\ta = int(c)\r\n\tprint('+' * a)\r\n\tprint('.')\r\n\tprint('-' * a)\r\n",
"a = eval(input())\ns = str(a)\nfor i in s:\n b = \"\"\n for j in range(ord(i)):\n b += \"+\"\n b += '.>'\n print (b)\n\n\t \t\t \t\t\t\t\t \t \t\t \t \t \t \t",
"a = str(eval(input()))\r\nfor x in a:\r\n print('+' * (48 + int(x)) + '.')\r\n print('>')",
"expr = input()\r\nresult = eval(expr)\r\nr1 = result//100\r\nr2 = result%100//10\r\nr3 = result%10\r\n\r\ndef bf(x: int):\r\n for i in range(0, 48 + x):\r\n print(\"+\", end=\"\")\r\n print(\".>\", end=\"\")\r\n\r\nif r1 != 0:\r\n bf(r1)\r\nif r2 != 0:\r\n bf(r2)\r\nbf(r3)\r\n",
"res = str(eval(input()))\r\nfor i in res:\r\n print('+'*ord(i), \".>\")",
"# LUOGU_RID: 124681307\nres=str(eval(input()))\r\nfor i in res:\r\n print((\"+\"*ord(i))+\"\",end='.>')",
"n=str(eval(input()))\r\ns=\"\"\r\nfor i in n:\r\n x=ord(i)\r\n while x:\r\n x-=1\r\n s+=\"+\"\r\n s+=\".>\"\r\nprint(s)",
"res = str(eval(input()))\r\n\r\nfor c in res:\r\n dif = int(c)\r\n for i in range(48 + dif):\r\n print('+')\r\n print('.>')",
" #yl7\na=str(eval(input()))\nfor i in a:\n print((48+int(i))*'+'+'.>')\n\t \t\t\t \t\t\t \t\t \t \t\t \t",
"n = str(eval(input()))\nfor _ in n:\n print('.'.join(['+'*ord(_), '-'*ord(_)]))\n\t\t\t \t \t \t \t \t\t\t \t\t \t \t\t\t \t",
"# coding: utf-8\r\n\r\nfor digit in str(eval(input())):\r\n print('+' * ord(digit) + '.>')",
"print(*['+' * ord(i) + '.>' for i in str(eval(input()))], sep='\\n')",
"print(*[\">++++++++++++++++++++++++++++++++++++++++++++++++\"+(int(i)*\"+\")+\".\" for i in str(eval(input()))])",
"def process(x):\n return '++++++++++++++++++++++++++++++++++++++++++++++++' + ''.join(\n ['+' for i in range(0, x)]) + '.>'\n\n\ndef main():\n res = str(eval(input()))\n for i in res:\n print(process(int(i)))\n\n\nmain()",
"s = eval(input())\r\nq = '+'\r\nif s < 0:\r\n q= '-'\r\ntemp = str(s)\r\nfor j in temp:\r\n for i in range(int(int(str(j)) + 48)):\r\n print(q, end='')\r\n print('.>')",
"s = input()\r\ns = str(eval(s))\r\np = '++++++[>++++++++<-]>'\r\nprint(p, end = '')\r\npre = 0\r\nfor dig in s:\r\n digit = int(dig)\r\n if digit == pre: print('.', end = '')\r\n elif digit < pre: \r\n for i in range(pre - digit): print('-', end = '')\r\n print('.', end = '')\r\n else:\r\n for i in range(digit - pre): print('+', end = '')\r\n print('.', end = '')\r\n pre = digit",
"digits = \"0123456789\"\r\na = input()+\" \"\r\n\r\ndef get_dig(i):\r\n x = 0\r\n while (i < len(a)) & (a[i] in digits):\r\n x = 10*x + int(a[i])\r\n i+=1\r\n return i, x\r\n\r\n(i, x) = get_dig(0)\r\nwhile i + 1 < len(a):\r\n if a[i] == \"+\":\r\n (i, y) = get_dig(i+1)\r\n x += y\r\n else:\r\n (i, y) = get_dig(i+1)\r\n x -= y\r\n\r\ns = str(x)\r\nout = \"\"\r\nfor letter in s:\r\n for i in range(ord(letter)):\r\n out += \"+\"\r\n out += \".>\"\r\nprint(out)\r\n",
"for i in str(eval(input())): \r\n\tprint('+' * ord(i), end = '.>')\r\n# eval 返回表达式的值 \r\n# ord ASCII 码 ",
"N=input()\r\nT=eval(N)\r\nN1=T//100\r\nN2=T%100//10\r\nN3=T%10\r\ndef Output(X:int):\r\n for i in range(0,48+X):\r\n print(\"+\",end=\"\")\r\n print(\".>\",end=\"\")\r\nif N1!=0:\r\n Output(N1)\r\nif N2!=0:\r\n Output(N2)\r\nOutput(N3)",
"for c in str(eval(input())):\r\n print('+' * ord(c) + '.>')",
"#!/usr/bin/env python3\n\nimport sys\n\ns = sys.stdin.readline().strip()\n\ns = '+' + s + '+'\n\nsps = [i for i, c in enumerate(s) if c in '+-']\nres = sum(int(s[i0:i1]) for i0,i1 in zip(sps[:-1], sps[1:]))\n\nprint ('.>\\n'.join('+'*ord(r) for r in str(res)) + '.')\n",
"s = str(eval(input()))\r\nfor c in s:\r\n\tprint('+' * ord(c) + str(\".>\"))",
"s = input().strip()\r\ns = str(eval(s))\r\n\r\nfor c in s:\r\n print('[-]')\r\n print('+'*ord(c))\r\n print('.')",
"s = map(int, str(eval(input())))\r\nprint('++++++++++++++++++++++++++++++++++++++++++++++++',end='')\r\nfor c in s:\r\n print('+'*c+'.'+'-'*c, end='')\r\nprint()",
"for i in str(eval(input())): print('+' * ord(i), end='.>')",
"from sys import stdin,stdout\r\n# from os import _exit\r\n# from bisect import bisect_left,bisect\r\n# from heapq import heapify,heappop,heappush\r\n# from sys import setrecursionlimit\r\n# from collections import defaultdict,Counter\r\n# from itertools import permutations\r\n# from math import gcd,ceil,sqrt,factorial\r\n# setrecursionlimit(int(1e5))\r\ninput,print = stdin.readline,stdout.write\r\n\r\nfor i in str(eval(input())):\r\n print('+'*ord(i)+' . '+'-'*ord(i))\r\n",
"a = str(eval(input()))\nfor c in a:\n print('+' * ord(c) + \".>\")\nprint()\n",
"k=eval(input())\r\no=\"\"\r\nfor i in str(k):\r\n\ta=ord(i)\r\n\to+=\"+\"*a+\".[-]\"\r\nprint(o)",
"s = input()\nval = str(eval(s))\n\nprint('+' * 48)\nlastDigit = '0'\nfor digit in val:\n delta = ord(digit) - ord(lastDigit)\n if delta != 0:\n print(('+' if delta > 0 else '-') * abs(delta))\n print('.')\n lastDigit = digit\n\n",
"s = input()\r\nx = str(eval(s))\r\nprint('+'*48, end='')\r\nfor i in range(len(x)):\r\n\tif i == 0:\r\n\t\tprint('+'*int(x[i]) + '.', end='')\r\n\telse:\r\n\t\td = int(x[i]) - int(x[i-1])\r\n\t\tif d > 0:\r\n\t\t\tprint('+'*d + '.', end='')\r\n\t\telse:\r\n\t\t\tprint('-'*(-d) + '.', end='')\r\n",
"a=input()\r\nfor i in str(eval(a)):print('+' * ord(i), end='.>')",
"y = str(eval(input()))\r\nfor i in y: \r\n print(ord(i)*\"+\"+\".\"+ord(i)*\"-\",end=\"\")",
"result = str(eval(input()))\r\nfor d in result:\r\n print('+' * (48 + int(d)) + '.>')\r\n",
"n = str(eval(input()))\r\nfor i in n:\r\n print('+' * ord(i), '.', '-' * ord(i))\r\n",
"a=input()\r\nif eval(a)//100!=0:\r\n for i in range(0,48+eval(a)//100):\r\n print(\"+\",end=\"\")\r\n print(\".>\",end=\"\")\r\nif eval(a)%100//10!=0:\r\n for i in range(0,48+eval(a)%100//10):\r\n print(\"+\",end=\"\")\r\n print(\".>\",end=\"\")\r\nfor i in range(0,48+eval(a)%10):\r\n print(\"+\",end=\"\")\r\nprint(\".>\",end=\"\")",
"s = input()\nv = eval(s)\nif(v//100 > 0):\n\tprint('+'*(ord('0')+v//100)+'.>')\nv %= 100\nif(v//10 > 0):\n\tprint('+'*(ord('0')+v//10)+'.>')\nv %= 10\nprint('+'*(ord('0')+v)+'.>')\n"
] | {"inputs": ["2+3", "9-7", "1+1+1", "1+11+111", "111-11-1", "1+1-1+1-1+1-1+1-1+1", "9+1", "10-1", "31+49+49+71-51-61+59-111+51", "255+255+255+255+255-255-255-255-255-255", "100+100+10+10+10+10+10+5", "255-255+255-255+255-255+255-255+255", "0-255-255-255-255+255+255+255+255+255", "34+45+29-49+52-111-4+4+2+9", "0+0+0+0+0+0+0+0+0+0", "193+235+47+150+222-3-90-248-187-100", "66-165-34+209+76", "36+90+6+102", "255-12-34-56-69-78", "243-173+90-56+78-53+53-21"], "outputs": ["+++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++.>", "+++++++++++++++++++++++++++++++++++++++++++++++++++.>", "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>", "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++.>", "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++.>", "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "++++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "+++++++++++++++++++++++++++++++++++++++++++++++++.>\n++++++++++++++++++++++++++++++++++++++++++++++++++++++.>\n+++++++++++++++++++++++++++++++++++++++++++++++++.>"]} | UNKNOWN | PYTHON3 | CODEFORCES | 43 | |
3278bb2a3c74f0b3ae56cb0cb81379c1 | Peter and Snow Blower | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.
Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.
Peter decided to tie his car to point *P* and now he is wondering what is the area of the region that will be cleared from snow. Help him.
The first line of the input contains three integers — the number of vertices of the polygon *n* (), and coordinates of point *P*.
Each of the next *n* lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.
All the numbers in the input are integers that do not exceed 1<=000<=000 in their absolute value.
Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Sample Input
3 0 0
0 1
-1 2
1 2
4 1 -1
0 0
1 2
2 0
1 1
Sample Output
12.566370614359172464
21.991148575128551812
| [
"__author__ = 'Utena'\r\nimport math\r\nn,a,b=map(int,input().split())\r\nm=[]\r\ns=[]\r\nfor i in range(n):\r\n m.append(list(map(int,input().split())))\r\nfor i in range(n):\r\n a1,b1=m[i]\r\n s.append((a1-a)**2+(b1-b)**2)\r\nfor i in range(n-1):\r\n a1,b1=m[i]\r\n a2,b2=m[i+1]\r\n if ((a2-a1)*(a2-a)+(b2-b1)*(b2-b))*((a2-a1)*(a1-a)+(b2-b1)*(b1-b))<=0:\r\n l=((b2-b1)*a-(a2-a1)*b-a1*b2+a2*b1)**2/((b2-b1)**2+(a2-a1)**2)\r\n s.append(l)\r\na1,b1=m[-1]\r\na2,b2=m[0]\r\nif ((a2-a1)*(a2-a)+(b2-b1)*(b2-b))*((a2-a1)*(a1-a)+(b2-b1)*(b1-b))<=0:\r\n l=((b2-b1)*a-(a2-a1)*b-a1*b2+a2*b1)**2/((b2-b1)**2+(a2-a1)**2)\r\n s.append(l)\r\nt=math.pi*(max(s)-min(s))\r\nprint(t)",
"import math\r\nn, a, b = map(int, input().split())\r\nvals = []\r\nfor _ in range(n):\r\n u, v = map(int, input().split())\r\n vals.append((u - a, v - b))\r\ncurrX, currY = vals[-1]\r\nans = []\r\nfor nextX, nextY in vals:\r\n ans.append(nextX * nextX + nextY * nextY)\r\n dx = nextX - currX\r\n dy = nextY - currY\r\n if (currX * dx + currY * dy) * (nextX * dx + nextY * dy) < 0:\r\n val = currX * nextY - nextX * currY\r\n ans.append((val * val) / (dx * dx + dy * dy))\r\n currX = nextX\r\n currY = nextY\r\nprint((max(ans) - min(ans)) * math.pi)",
"#!/usr/bin/python\n# -*- coding: utf-8 -*-\n\nimport sys\nimport math\n\ndef dist2(x1, y1, x2, y2):\n return (x1 - x2) ** 2 + (y1 - y2) ** 2\n\ndef find_dist(x1, y1, x2, y2, X, Y):\n if x2 == x1:\n if min(y1, y2) <= Y <= max(y1, y2):\n return (x1 - X) ** 2\n else:\n return min(dist2(x1, y1, X, Y), dist2(x2, y2, X, Y))\n a = (y2 - y1) / (x2 - x1)\n b = y1 - a * x1\n x = (X + a * (Y - b)) / (1 + a * a)\n if min(x1, x2) <= x <= max(x1, x2):\n return dist2(x, a * x + b, X, Y)\n else:\n return min(dist2(x1, y1, X, Y), dist2(x2, y2, X, Y))\n\ndef main():\n N, X, Y = map(int, sys.stdin.readline().split())\n maxr = 0\n minr = 10**15\n pts = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]\n pts.append(pts[0])\n for i in range(0, len(pts)-1):\n x, y = pts[i]\n r = dist2(x, y, X, Y)\n if r > maxr:\n maxr = r\n r = find_dist(x, y, pts[i+1][0], pts[i+1][1], X, Y)\n if r < minr:\n minr = r\n\n print (\"%.10f\" % (math.pi * (maxr - minr)))\n\nif __name__ == '__main__':\n main()\n",
"from math import hypot, pi, copysign\n\n\ndef main():\n n, a, b = map(int, input().split())\n l, res = [], []\n for _ in range(n):\n x0, y0 = map(int, input().split())\n l.append((x0 - a, y0 - b))\n x0, y0 = l[-1]\n for x1, y1 in l:\n res.append(hypot(x1, y1))\n dx, dy = x1 - x0, y1 - y0\n if copysign(1., x0 * dx + y0 * dy) != copysign(1., x1 * dx + y1 * dy):\n res.append(abs(x0 * y1 - x1 * y0) / hypot(dx, dy))\n x0, y0 = x1, y1\n print((max(res) ** 2 - min(res) ** 2) * pi)\n\n\nif __name__ == '__main__':\n main()\n",
"import math\r\n\r\ndef main():\r\n\t(n, xp, yp) = (int(x) for x in input().split())\r\n\tpolygon = [None] * n\r\n\tfor i in range(n):\r\n\t\t(xi, yi) = (int(x) for x in input().split())\r\n\t\tpolygon[i] = (xi, yi)\r\n\tprint(solver((xp, yp), polygon))\r\n\r\ndef solver(P, polygon):\r\n\tn = len(polygon)\r\n\t(xp, yp) = P\r\n\tdistances = [distance(xp, yp, x, y) for (x, y) in polygon]\r\n\tmaxDist = max(distances)\r\n\tminDist = min(distances)\r\n\tfor i in range(n):\r\n\t\tp = perpenPoint(polygon[i%n], polygon[(i+1)%n], P)\r\n\t\tif p != None:\r\n\t\t\tdist = distance(xp, yp, p[0], p[1])\r\n\t\t\tif dist < minDist:\r\n\t\t\t\tminDist = dist\r\n\tarea = math.pi * (maxDist**2 - minDist**2)\r\n\treturn area\r\n\r\n\r\n\r\n# ax + by = c\r\ndef toLine(point1, point2):\r\n\t(x1, y1) = point1\r\n\t(x2, y2) = point2\r\n\tif x1 == x2:\r\n\t\tif y1 == y2:\r\n\t\t\tassert(False)\r\n\t\telse:\r\n\t\t\treturn (1, 0, x1)\r\n\telse:\r\n\t\ta = (y2 - y1) / (x1 - x2)\r\n\t\tc = a * x1 + y1\r\n\t\treturn (a, 1, c)\r\n\r\n# perpendicular point from point to the line segment: point1 to point3\r\ndef perpenPoint(point1, point2, point):\r\n\tline = toLine(point1, point2)\r\n\t(a, b, c) = line\r\n\t# perpendicular line\r\n\tif a == 0:\r\n\t\t(ap, bp) = (b, a)\r\n\telse:\r\n\t\t(ap, bp) = (-b / a, 1)\r\n\t(x, y) = point\r\n\tcp = ap * x + bp * y\r\n\t(xi, yi) = intersection(line, (ap, bp, cp))\r\n\t(x1, y1) = point1\r\n\t(x2, y2) = point2\r\n\tif min(x1, x2) <= xi and xi <= max(x1, x2) and \\\r\n\tmin(y1, y2) <= yi and yi <= max(y1, y2):\r\n\t\treturn (xi, yi)\r\n\telse:\r\n\t\treturn None\r\n\r\ndef intersection(line1, line2):\r\n\t(a1, b1, c1) = line1\r\n\t(a2, b2, c2) = line2\r\n\tif b1 == 0 and a2 == 0:\r\n\t\treturn (c1, c2)\r\n\telif a1 == 0 and b2 == 0:\r\n\t\treturn (c2, c1)\r\n\telse:\r\n\t\tx = (b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1)\r\n\t\ty = (c1 - a1 * x) / b1\r\n\t\treturn (x, y)\r\n\r\ndef almostEqual(x, y):\r\n\treturn abs(x - y) < 10**-16\r\n\r\ndef distance(x1, y1, x2, y2):\r\n\tleg1 = abs(x1 - x2)\r\n\tleg2 = abs(y1 - y2)\r\n\treturn (leg1**2 + leg2**2)**0.5\r\n\r\nmain()\r\n#print(perpenPoint((-1, 0), (0, 1), (1.1, 0)))\r\n#print(perpenPoint((-2, 0), (-2, 1), (0, 0)))\r\n#print(perpenPoint((-1, 1), (2, 1), (0, 0)))\r\n#print(perpenPoint((-1, 0), (1, 1), (0, 0)))\r\n#print(12.56637061435 / math.pi)\r\n#print(solver((0, 0), [(0, 1), (-1, 2), (1, 2)]))\r\n#print(solver((1, -1), [(0, 0), (1, 2), (2, 0), (1, 1)]))",
"from math import sqrt, inf, pi\n\nclass Point:\n def __init__(self, x, y):\n self.x = x\n self.y = y\n\ndef dis(a, b):\n return sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2)\ndef dcmp(x, eps = 1e-10):\n return 0 if abs(x) < eps else -1 if x < 0 else 1\ndef dot(a, b):\n return a.x * b.x + a.y * b.y\ndef cross(a, b):\n return a.x * b.y - a.y * b.x\ndef eq(a, b):\n return dcmp(a.x - b.x) == 0 and dcmp(a.y - b.y) == 0\n\nn, sx, sy = map(int, input().split())\ns = Point(sx, sy)\nmaxdis = 0\nmindis = inf\npts = []\n\nfor i in range(n):\n tx, ty = map(int, input().split())\n t = Point(tx, ty)\n ds = dis(s, t)\n pts.append(t)\n if ds > maxdis:\n maxdis = ds\n\nfor i in range(n):\n a = pts[i]\n b = pts[(i + 1) % n]\n if eq(a, b):\n ds = dis(s, a)\n else:\n v1 = Point(b.x - a.x, b.y - a.y)\n v2 = Point(s.x - a.x, s.y - a.y)\n v3 = Point(s.x - b.x, s.y - b.y)\n if dcmp(dot(v1, v2)) < 0:\n ds = dis(Point(0, 0), v2)\n elif dcmp(dot(v1, v3)) > 0:\n ds = dis(Point(0, 0), v3)\n else:\n ds = abs(cross(v1, v2)) / dis(Point(0, 0), v1)\n if ds < mindis:\n mindis = ds\n\nprint('%.6f' % (pi * maxdis ** 2 - pi * mindis ** 2))\n\n \t \t\t \t \t \t \t\t\t \t\t\t\t \t",
"s = input().split()\nn = int(s[0])\n\npx = int(s[1])\npy = int(s[2])\n\n\ny = []\nx = []\n\nfor i in range(n):\n s=input().split()\n x.append(int(s[0]) - px)\n y.append(int(s[1]) - py)\n #print(x[i],y[i])\n\nl = []\nx0, y0 = x[-1], y[-1]\n\nfor i in range(n):\n l.append(x[i]*x[i] + y[i]*y[i])\n dx, dy = x[i] - x0, y[i] - y0\n if (x0*dx+y0*dy)*(x[i]*dx + y[i]*dy) < 0:\n x0 = x0*y[i]-x[i]*y0\n l.append(x0*x0/(dx*dx+dy*dy))\n x0,y0 = x[i],y[i]\n\na = 3.141592653589793 * (max(l) -min(l))\n#print (px,py)\n#print (x[imax],y[imax])\n#print (x[imin],y[imin])\n#print (((px - x[imax])*(px - x[imax]) + (py - y[imax])*(py - y[imax]))) \n#print (((px - x[imin])*(px - x[imin]) + (py - y[imin])*(py - y[imin])))\n\nprint (a)\n",
"import functools\r\n \r\nclass Point:\r\n def __init__(self, x, y):\r\n self.x = x\r\n self.y = y\r\n \r\n def squared_distance(self, another_point):\r\n return (self.x - another_point.x) ** 2 + (self.y - another_point.y) ** 2\r\n\r\ndef point_segment_distance(p, a, b):\r\n ap = (p.x - a.x, p.y - a.y)\r\n ab = (b.x - a.x, b.y - a.y)\r\n bp = (p.x - b.x, p.y - b.y)\r\n\r\n indicator = (ap[0] * ab[0] + ap[1] * ab[1]) / (ab[0] ** 2 + ab[1] ** 2)\r\n if 0 < indicator < 1:\r\n return (ap[0] ** 2 + ap[1] ** 2) - indicator ** 2 * (ab[0] ** 2 + ab[1] ** 2)\r\n if indicator <= 0:\r\n return ap[0] ** 2 + ap[1] ** 2\r\n if indicator >= 1:\r\n return bp[0] ** 2 + bp[1] ** 2\r\n \r\nclass SnowBlower: \r\n def solution(self):\r\n first_line = input()\r\n first_line = first_line.split(\" \")\r\n num_vertices = int(first_line[0])\r\n origin = Point(int(first_line[1]), int(first_line[2]))\r\n \r\n vertices = []\r\n for _ in range(num_vertices):\r\n point = input()\r\n point = point.split(\" \")\r\n vertices.append(Point(int(point[0]), int(point[1])))\r\n \r\n max_distance = float(\"-inf\")\r\n min_distance = float(\"inf\")\r\n for vertex in vertices:\r\n squared_distance = origin.squared_distance(vertex)\r\n max_distance = squared_distance if squared_distance > max_distance else max_distance\r\n \r\n \r\n for i in range(num_vertices):\r\n distance = point_segment_distance(origin, vertices[i], vertices[i - 1])\r\n min_distance = distance if distance < min_distance else min_distance\r\n \r\n \r\n pi = 3.14159265358\r\n \r\n print(pi * (max_distance - min_distance))\r\n \r\n \r\nif __name__ == \"__main__\":\r\n snow_blower = SnowBlower()\r\n snow_blower.solution()",
"import math\r\n\r\ndef dis(a0, b0, x, y):\r\n return ((a0-x) ** 2 + (b0-y) ** 2) ** 0.5\r\n \r\n# distance from point to segment\r\ndef minDistance(A, B, E) : \r\n \r\n AB = [B[0] - A[0], B[1] - A[1]] \r\n BE = [E[0] - B[0], E[1] - B[1]]\r\n AE = [E[0] - A[0], E[1] - A[1]]\r\n \r\n AB_BE = AB[0] * BE[0] + AB[1] * BE[1]; \r\n AB_AE = AB[0] * AE[0] + AB[1] * AE[1]; \r\n \r\n reqAns = 0; \r\n \r\n # Case 1 \r\n if AB_BE > 0: \r\n # Finding the magnitude \r\n y = E[1] - B[1] \r\n x = E[0] - B[0] \r\n return (x * x + y * y) ** 0.5 \r\n \r\n # Case 2 \r\n elif (AB_AE < 0) : \r\n y = E[1] - A[1] \r\n x = E[0] - A[0] \r\n return (x * x + y * y) ** 0.5\r\n \r\n # Case 3 \r\n else: \r\n # Finding the perpendicular distance \r\n x1, y1, x2, y2 = AB[0], AB[1], AE[0], AE[1] \r\n mod = (x1 * x1 + y1 * y1) ** 0.5\r\n \r\n return abs(x1 * y2 - y1 * x2) / mod\r\n \r\nn, x0, y0 = map(int, input().split())\r\nP = [list(map(int, input().split())) for _ in range(n)]\r\n\r\nmax_ = 0\r\nmin_ = float(\"inf\")\r\n\r\nfor i in range(n):\r\n p = P[i]\r\n \r\n min_ = min(min_, minDistance(P[i], P[(i+1)%n], [x0, y0]))\r\n max_ = max(max_, dis(x0, y0, p[0], p[1]))\r\n \r\nprint(math.pi * (max_ * max_ - min_ * min_))",
"import math\r\nn, px, py = map(int, input().split())\r\nxs, ys, l = list(), list(), list()\r\nfor _ in range(n):\r\n\tx, y = map(int, input().split())\r\n\txs.append(x - px)\r\n\tys.append(y - py)\r\nx0, y0 = xs[-1], ys[-1]\r\nfor x, y in zip(xs, ys):\r\n\tl.append(x * x + y * y)\r\n\tdx, dy = x - x0, y - y0\r\n\tif (x0 * dx + y0 * dy) * (x * dx + y * dy) < 0:\r\n\t\tx0 = x0 * y - x * y0\r\n\t\tl.append(x0 * x0 / (dx * dx + dy * dy))\r\n\tx0, y0 = x, y\r\nprint(math.pi * (max(l) - min(l)))",
"from math import *\r\n\r\ndef dist(a,b,p):\r\n\txu = b[0]-a[0]\r\n\tyu = b[1]-a[1]\r\n\txv = p[0]-a[0]\r\n\tyv = p[1]-a[1]\r\n\tc1 = xu*xv + yu*yv\r\n\tc2 = xu*xu + yu*yu\r\n\tx,y = 0,0\r\n\tif c1<=0:\r\n\t\tx = a[0]-p[0]\r\n\t\ty = a[1]-p[1]\r\n\telif c2<=c1:\r\n\t\tx = b[0]-p[0]\r\n\t\ty = b[1]-p[1]\r\n\telse:\r\n\t\tx = a[0] + xu*(c1/c2)-p[0]\r\n\t\ty = a[1] + yu*(c1/c2)-p[1]\r\n\treturn x*x + y*y\r\n\r\n\r\nn,cx,cy = map(int,input().split())\r\npts = [ list(map(int,input().split())) for _ in range(n) ]\r\nmini,maxi = float('inf'),0\r\nfor i in range(n):\r\n\tpx,py = pts[i]\r\n\tmaxi = max((px-cx)**2+(py-cy)**2,maxi)\r\n\tmini = min(dist(pts[i-1],pts[i],[cx,cy]),mini)\r\nprint((maxi-mini)*pi)",
"def dot_product(v1, v2):\r\n return v1.x * v2.x + v1.y * v2.y\r\n\r\n\r\nclass vector:\r\n def __init__(self, x, y):\r\n self.x = x\r\n self.y = y\r\n\r\n def length(self):\r\n return (self.x ** 2 + self.y ** 2) ** 0.5\r\n\r\n def cross_product(self, v):\r\n return self.x * v.y - self.y * v.x\r\n\r\nclass line:\r\n def __init__(self, a, b):\r\n self.a = a\r\n self.b = b\r\n\r\n def distance(self, p):\r\n return abs(vector(p.x - self.a.x, p.y - self.a.y).cross_product(vector(p.x - self.b.x, p.y - self.b.y)) / vector(self.a.x - self.b.x, self.a.y - self.b.y).length())\r\n\r\nclass ray:\r\n def __init__(self, a, b):\r\n self.a = a\r\n self.b = b\r\n\r\n def distance(self, p):\r\n if dot_product(vector(self.b.x - self.a.x, self.b.y - self.a.y), vector(p.x - self.a.x, p.y - self.a.y)) >= 0:\r\n return line(self.a, self.b).distance(p)\r\n return vector(self.a.x - p.x, self.a.y - p.y).length()\r\n\r\nclass segment:\r\n def __init__(self, a, b):\r\n self.a = a\r\n self.b = b\r\n\r\n def min_distance(self, p):\r\n if dot_product(vector(self.b.x - self.a.x, self.b.y - self.a.y), vector(p.x - self.a.x, p.y - self.a.y)) >= 0:\r\n return ray(self.b, self.a).distance(p)\r\n return vector(self.a.x - p.x, self.a.y - p.y).length()\r\n\r\n def max_distance(self, p):\r\n return max(vector(self.a.x - p.x, self.a.y - p.y).length(), vector(self.b.x - p.x, self.b.y - p.y).length())\r\n\r\n\r\nn, x, y = map(int, input().split())\r\np = vector(x, y)\r\n\r\nmin_r = 2000000\r\nmax_r = 0\r\n\r\na = [[] for i in range(n + 1)]\r\n\r\nfor i in range(n):\r\n a[i] = list(map(int, input().split()))\r\n a[i] = vector(a[i][0], a[i][1])\r\n\r\na[n] = a[0]\r\n\r\nfor i in range(n):\r\n s = segment(a[i], a[i + 1])\r\n min_r = min(min_r, s.min_distance(p))\r\n max_r = max(max_r, s.max_distance(p))\r\n\r\npi = 3.141592653589\r\nprint(pi * max_r ** 2 - pi * min_r ** 2)",
"import math\r\ndef dist(x, y, x1, y1, x2, y2):\r\n a = x-x1\r\n b = y-y1\r\n c = x2-x1\r\n d = y2-y1\r\n dot = a*c+b*d\r\n lensq = c*c+d*d\r\n param=-1\r\n if lensq != 0:\r\n param = dot / lensq\r\n if param < 0:\r\n xx = x1\r\n yy = y1\r\n elif param > 1:\r\n xx = x2\r\n yy = y2\r\n else:\r\n xx = x1 + param * c\r\n yy = y1 + param * d\r\n\r\n dx = x - xx\r\n dy = y - yy\r\n return (dx*dx+dy*dy)**0.5\r\ndef dist2(x, y):\r\n return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5\r\nimport math\r\nmaxx = -1\r\nminn = 100000000000000000\r\npts = []\r\na, b, c = map(int, input().split(' '))\r\nfor i in range(a):\r\n x, y = map(int, input().split(' '))\r\n pts.append([x, y])\r\n\r\nk = []\r\nfor i in pts:\r\n k.append(dist2(i, [b, c]))\r\npts.append(pts[0])\r\nfor i in range(a):\r\n k.append(dist(b, c, pts[i][0], pts[i][1], pts[i+1][0], pts[i+1][1]))\r\n\r\nprint((max(k)**2-min(k)**2)*math.pi)\r\n",
"PI = 3.141592653589793\r\nn, a, b = map(int, input().split())\r\narr, res = [], []\r\nfor _ in range(n):\r\n u, v = input().split()\r\n arr.append((int(u) - a, int(v) - b))\r\nx0, y0 = arr[-1]\r\nfor x1, y1 in arr:\r\n res.append(x1 * x1 + y1 * y1)\r\n dx, dy = x1 - x0, y1 - y0\r\n if (x0 * dx + y0 * dy) * (x1 * dx + y1 * dy) < 0:\r\n x0 = x0 * y1 - x1 * y0\r\n res.append((x0 * x0) / (dx * dx + dy * dy))\r\n x0, y0 = x1, y1\r\nprint((max(res) - min(res)) * PI)\r\n",
"import math\r\nn,x,y = map(int,input().split())\r\nli=[]\r\ndis=[]\r\nfor i in range(n):\r\n\ta,b = map(int,input().split())\r\n\tli.append([a,b])\r\n\tdis.append((x-a)**2+(y-b)**2)\r\n#print(li)\r\nfor i in range(n-1):\r\n\ta,b = li[i]\r\n\tm,n = li[i+1]\r\n\tif ((m-a)*(m-x)+(n-b)*(n-y))*((m-a)*(a-x)+(n-b)*(b-y))<=0:\r\n\t\tlen = ((n-b)*x-(m-a)*y+m*b-a*n)**2/((n-b)**2+(m-a)**2)\r\n\t\tdis.append(len)\r\na,b = li[-1]\t\r\nm,n = li[0]\r\nif ((m-a)*(m-x)+(n-b)*(n-y))*((m-a)*(a-x)+(n-b)*(b-y))<=0:\r\n\t\tlen = ((n-b)*x-(m-a)*y+m*b-a*n)**2/((n-b)**2+(m-a)**2)\r\n\t\tdis.append(len)\r\n#print(dis)\t\t\r\nprint(math.pi*(max(dis)-min(dis)))\t\t\r\n\t\t",
"\"\"\" Peter and Snow Blower \"\"\"\nimport math\n\n\ndef cross(vecA, vecB):\n return abs(vecA[0] * vecB[1] - vecA[1] * vecB[0])\n\n\ndef l2_norm(pointA, pointB):\n return (pointA[0] - pointB[0]) ** 2 + (pointA[1] - pointB[1]) ** 2\n\n\ndef height5(P, A, B):\n a = l2_norm(A, P)\n b = l2_norm(B, P)\n base = l2_norm(A, B)\n\n # If obtuse triangles\n if a >= base + b or b >= base + a:\n return min(a, b)\n\n else:\n # If acute triangles\n vecA = (A[0] - P[0], A[1] - P[1])\n vecB = (B[0] - P[0], B[1] - P[1])\n area = cross(vecA, vecB)\n h = area * area / base\n return h\n\n\ndef CF613A():\n # Read number of points, center and the points\n N, cx, cy = list(map(int, input().split()))\n points = [tuple(map(int, input().split())) for _ in range(N)]\n\n # N, cx, cy = 3, 0, 0 # 12.56\n # points = [(0, 1), (-1, 2), (1, 2)]\n #\n # N, cx, cy = 4, 1, -1 # 21.99\n # points = [(0, 0), (1, 2), (2, 0), (1, 1)]\n #\n # N, cx, cy = 3, 0, 0 # 25.13\n # points = [(-1, 1), (0, 3), (1, 1)]\n #\n # N, cx, cy = 3, -4, 2 # 405.26\n # points = [(-3, 2), (5, -5), (5, 3)]\n\n # Compute the max distance\n center = (cx, cy)\n distances = [l2_norm(center, point) for point in points]\n max_radius = max(distances)\n\n # Compute the min distance\n min_radius = float('inf')\n for i in range(N):\n height = height5(center, points[i], points[(i + 1) % N])\n min_radius = min(min_radius, height)\n\n area = math.pi * (max_radius - min_radius)\n return area\n\n\nif __name__ == '__main__':\n res = CF613A()\n print(res)\n",
"from math import *\r\nfrom sys import *\r\nfrom decimal import *\r\n\r\ndef S(r1,r2):\r\n return acos(-1)*(r2-r1)\r\n\r\ndef geth(x0,y0,x1,y1,x2,y2):\r\n U1=x1*(y1-y2)+y1*(x2-x1)\r\n U2=x0*(x1-x2)+y0*(y1-y2)\r\n KEK1=y1-y2\r\n KEK2=x1-x2\r\n det1=U1*KEK1+U2*KEK2\r\n det2=U2*KEK1-U1*KEK2\r\n det=KEK1**2+KEK2**2\r\n return det1/det,det2/det\r\n\r\ndef diist(x0,y0,x1,y1):\r\n return sqrt((x0-x1)**2+(y0-y1)**2)\r\n\r\nn,x0,y0=(int(z) for z in stdin.readline().split())\r\nma,mi=0,10**15\r\nxp,yp=10**7,10**7\r\nxf,yf=0,0\r\nfor i in range(n):\r\n xc,yc=(int(z) for z in stdin.readline().split())\r\n dist=(x0-xc)**2+(y0-yc)**2\r\n ma=max(dist,ma)\r\n mi=min(dist,mi)\r\n if xp<=10**6:\r\n xmid,ymid=geth(x0,y0,xc,yc,xp,yp)\r\n #print(xmid,ymid)\r\n if diist(xmid,ymid,xc,yc) + diist(xmid,ymid,xp,yp) <= diist(xc,yc,xp,yp):\r\n mi=min((xmid-x0)**2+(ymid-y0)**2,mi)\r\n else:\r\n xf,yf=xc,yc\r\n xp,yp=xc,yc\r\nxmid,ymid=geth(x0,y0,xc,yc,xf,yf)\r\n#print(xmid,ymid)\r\n#print(xc,yc,xf,yf)\r\n#print(diist(xmid,ymid,xc,yc)+diist(xmid,ymid,xf,yf),diist(xc,yc,xf,yf))\r\nif diist(xmid,ymid,xc,yc)+diist(xmid,ymid,xf,yf)<=diist(xc,yc,xf,yf):\r\n #print(\"OK\")\r\n mi=min((xmid-x0)**2+(ymid-y0)**2,mi)\r\n#print(mi,ma)\r\nprint(S(mi,ma))",
"#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\nimport math\nimport sys\n\ndef rl(proc=None):\n if proc is not None:\n return proc(sys.stdin.readline())\n else:\n return sys.stdin.readline().rstrip()\n\ndef srl(proc=None):\n if proc is not None:\n return list(map(proc, rl().split()))\n else:\n return rl().split()\n\nINF = 10 ** 30\n\ndef dist(x1, y1, x2, y2):\n return ((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2))\n\ndef dist2(x0, y0, x1, y1, x2, y2):\n x1 -= x0\n y1 -= y0\n x2 -= x0\n y2 -= y0\n dx = x2-x1\n dy = y2-y1\n a = - (x1 * dx + y1 * dy) / (dx * dx + dy * dy)\n if a < 0 or a > 1:\n return INF\n xt = x1 + a * dx\n yt = y1 + a * dy\n\n return xt * xt + yt * yt\n\ndef main():\n N, Px, Py = srl(int)\n A = [\n srl(int) for _ in range(N)\n ]\n mx = 0\n mn = INF\n for x, y in A:\n d = dist(Px, Py, x, y)\n mx = max(mx, d)\n mn = min(mn, d)\n mn = min(mn, dist2(Px, Py, A[0][0], A[0][1], A[-1][0], A[-1][1]))\n for i in range(1, len(A)):\n mn = min(mn, dist2(Px, Py, A[i][0], A[i][1], A[i-1][0], A[i-1][1]))\n print('%.9f' % (math.pi * (mx - mn)))\n\nif __name__ == '__main__':\n main()\n",
"# https://codeforces.com/contest/614\r\n\r\nimport sys\r\nimport math\r\n\r\ninput = lambda: sys.stdin.readline().rstrip() # faster\r\n\r\n\r\ndef dist(x1, y1, x2, y2):\r\n return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5\r\n\r\n\r\nn, x, y = map(int, input().split())\r\nv = [tuple(map(int, input().split())) for _ in range(n)]\r\n\r\ndist_min, dist_max = math.inf, 0\r\nfor i in range(n):\r\n x1, y1 = v[i]\r\n x2, y2 = v[(i + 1) % n]\r\n\r\n d1 = dist(x, y, x1, y1)\r\n dist_min = min(dist_min, d1)\r\n dist_max = max(dist_max, d1)\r\n\r\n d = dist(x1, y1, x2, y2)\r\n t = ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1)) / d ** 2\r\n t = max(0, min(1, t))\r\n d2 = dist(x, y, x1 + t * (x2 - x1), y1 + t * (y2 - y1))\r\n dist_min = min(dist_min, d2)\r\n\r\nans = math.pi * (dist_max ** 2 - dist_min ** 2)\r\nprint(ans)",
"from math import pi\n\n\ndef vadd(v1, v2):\n return v1[0]+v2[0], v1[1]+v2[1]\n\ndef vsub(v1, v2):\n return v1[0]-v2[0], v1[1]-v2[1]\n\ndef smul(s, v):\n return s*v[0], s*v[1]\n\ndef dot(v1, v2):\n return v1[0]*v2[0] + v1[1]*v2[1]\n\ndef vmag2(v):\n return v[0]*v[0] + v[1]*v[1]\n\n\ndef segment_dist2(p, v, w):\n vp = vsub(p, v)\n vw = vsub(w, v)\n l2 = vmag2(vw)\n t = dot(vp, vw) / float(l2)\n\n if t <= 0:\n proj = v\n elif t >= 1:\n proj = w\n else:\n proj = vadd(v, smul(t, vw))\n\n return vmag2(vsub(p, proj))\n\n\ndef area(p, q):\n r2min, r2max = None, None\n qprev = q[-1]\n for qi in q:\n r2 = vmag2(vsub(p, qi))\n sd2 = segment_dist2(p, qi, qprev)\n if r2max is None or r2 > r2max:\n r2max = r2\n if r2min is None or sd2 < r2min:\n r2min = sd2\n qprev = qi\n\n return pi * (r2max-r2min)\n\n\nif __name__ == '__main__':\n n, px, py = map(int, input().split())\n q = [tuple(map(int, input().split())) for _ in range(n)]\n print(area((px, py), q))\n"
] | {"inputs": ["3 0 0\n0 1\n-1 2\n1 2", "4 1 -1\n0 0\n1 2\n2 0\n1 1", "3 0 0\n-1 1\n0 3\n1 1", "3 -4 2\n-3 2\n5 -5\n5 3", "3 -84 8\n-83 8\n21 -62\n3 53", "6 -94 -51\n-93 -51\n48 -25\n61 27\n73 76\n-10 87\n-48 38", "5 -94 52\n-93 52\n-78 -56\n-54 -81\n56 -87\n97 85", "10 -100 90\n-99 90\n-98 -12\n-72 -87\n7 -84\n86 -79\n96 -2\n100 36\n99 59\n27 83\n-14 93", "11 -97 -15\n-96 -15\n-83 -84\n-61 -97\n64 -92\n81 -82\n100 -63\n86 80\n58 95\n15 99\n-48 83\n-91 49", "10 -500 420\n-499 420\n-489 -173\n-455 -480\n160 -464\n374 -437\n452 -352\n481 -281\n465 75\n326 392\n-398 468", "10 -498 -161\n-497 -161\n-427 -458\n-325 -475\n349 -500\n441 -220\n473 28\n475 62\n468 498\n-444 492\n-465 264", "5 -1 -1\n0 0\n8 5\n10 7\n7 5\n2 5", "5 -1 -1\n0 0\n20 3\n26 17\n23 21\n98 96", "10 -1 -1\n0 0\n94 7\n100 52\n87 48\n37 26\n74 61\n59 57\n87 90\n52 90\n26 73", "10 -1 -1\n0 0\n78 22\n53 24\n78 50\n46 39\n45 56\n21 46\n2 7\n24 97\n5 59", "49 -1 -1\n0 0\n95 2\n47 1\n42 1\n93 7\n56 6\n47 7\n63 13\n98 24\n94 27\n90 28\n86 28\n17 6\n64 24\n42 19\n66 35\n63 35\n98 60\n75 48\n28 18\n71 46\n69 46\n99 68\n64 47\n56 43\n72 58\n35 29\n82 81\n68 69\n79 84\n72 77\n79 86\n54 59\n35 39\n20 23\n73 86\n80 97\n79 100\n69 99\n29 45\n26 63\n23 56\n12 33\n13 39\n25 85\n27 96\n6 23\n4 47\n1 60", "49 -1 -1\n0 0\n69 2\n74 7\n62 10\n64 15\n93 22\n78 22\n56 17\n86 29\n24 9\n91 43\n8 4\n90 50\n99 57\n39 23\n81 50\n91 58\n67 46\n95 66\n52 39\n91 69\n69 54\n93 84\n93 98\n70 80\n85 98\n30 39\n55 79\n41 59\n50 72\n57 88\n58 92\n58 94\n37 63\n43 87\n30 63\n19 40\n38 81\n40 86\n38 100\n2 6\n30 100\n23 89\n16 62\n11 49\n12 64\n9 52\n5 62\n1 88", "27 -999899 136015\n-999898 136015\n-999877 -297518\n-999832 -906080\n-999320 -977222\n-998896 -995106\n-962959 -999497\n-747200 -999814\n417261 -999929\n844204 -999911\n959527 -999826\n998944 -999180\n999413 -989979\n999556 -943026\n999871 -774660\n999993 -261535\n999963 938964\n998309 991397\n989894 997814\n988982 998459\n987145 999235\n972224 999741\n603140 999994\n-812452 999962\n-980920 999788\n-996671 987674\n-999472 977919\n-999808 639816", "19 -995486 -247212\n-995485 -247212\n-995004 -492984\n-993898 -887860\n-938506 -961227\n-688481 -971489\n178005 -999731\n541526 -999819\n799710 -988908\n905862 -967693\n987335 -887414\n983567 824667\n973128 892799\n914017 960546\n669333 986330\n-441349 986800\n-813005 986924\n-980671 973524\n-988356 849906\n-995289 404864", "15 -994057 554462\n-994056 554462\n-975707 -994167\n-711551 -996810\n13909 -997149\n809315 -993832\n980809 -984682\n996788 -303578\n993267 173570\n978439 877361\n898589 957311\n725925 992298\n-57849 999563\n-335564 997722\n-989580 990530\n-993875 973633", "23 -999840 738880\n-999839 738880\n-998291 -847192\n-995443 -982237\n-906770 -996569\n360950 -999295\n800714 -998808\n985348 -995579\n990091 -928438\n996690 -817256\n998844 -736918\n998377 674949\n998008 862436\n993320 971157\n978831 979400\n853341 986660\n802107 989497\n513719 996183\n140983 998592\n-158810 999459\n-677966 999174\n-949021 981608\n-982951 976421\n-993452 962292", "20 -999719 -377746\n-999718 -377746\n-997432 -940486\n-982215 -950088\n-903861 -997725\n-127953 -999833\n846620 -999745\n920305 -992903\n947027 -986746\n991646 -959876\n998264 -944885\n999301 870671\n994737 985066\n640032 998502\n-87871 999984\n-450900 999751\n-910919 999086\n-971174 995672\n-995406 975642\n-998685 946525\n-999684 673031", "26 -999922 -339832\n-999921 -339832\n-999666 -565163\n-998004 -942175\n-992140 -985584\n-965753 -998838\n-961074 -999911\n120315 -999489\n308422 -999258\n696427 -997199\n724780 -996955\n995651 -985203\n997267 -975745\n999745 -941705\n999897 -770648\n999841 -211766\n999436 865172\n999016 992181\n980442 997414\n799072 998987\n348022 999183\n-178144 999329\n-729638 998617\n-953068 997984\n-991172 990824\n-997976 939889\n-999483 581509", "22 -999930 -362070\n-999929 -362070\n-994861 -919993\n-989365 -946982\n-964007 -997050\n-418950 -998064\n351746 -998882\n830925 -996765\n867755 -996352\n964401 -992258\n996299 -964402\n997257 -930788\n999795 -616866\n999689 327482\n997898 996234\n923521 997809\n631104 998389\n-261788 999672\n-609744 999782\n-694662 999001\n-941227 993687\n-997105 992436\n-999550 895326", "29 -999961 689169\n-999960 689169\n-999927 -938525\n-999735 -989464\n-993714 -997911\n-870186 -999686\n-796253 -999950\n-139940 -999968\n969552 -999972\n985446 -999398\n992690 -997295\n999706 -973137\n999898 -848630\n999997 -192297\n999969 773408\n999495 960350\n999143 981671\n998324 993987\n997640 998103\n986157 998977\n966840 999418\n670113 999809\n477888 999856\n129160 999900\n-373564 999947\n-797543 999976\n-860769 999903\n-995496 999355\n-998771 984570\n-999768 927157", "3 -3 3\n-3 2\n5 -5\n5 3", "3 -9 7\n-9 6\n3 -6\n4 2", "5 -9 8\n-9 7\n-6 -1\n-3 -6\n1 -3\n10 8", "6 -6 -1\n-6 -2\n0 -7\n8 -9\n9 -1\n5 10\n-5 0", "10 -99 91\n-99 90\n-98 -12\n-72 -87\n7 -84\n86 -79\n96 -2\n100 36\n99 59\n27 83\n-14 93", "11 -96 -14\n-96 -15\n-83 -84\n-61 -97\n64 -92\n81 -82\n100 -63\n86 80\n58 95\n15 99\n-48 83\n-91 49", "13 -98 25\n-98 24\n-96 10\n-80 -71\n-71 -78\n-31 -99\n82 -98\n92 -39\n94 -2\n94 40\n90 80\n50 96\n-41 97\n-86 80", "17 -99 -53\n-99 -54\n-97 -71\n-67 -99\n-61 -99\n56 -98\n82 -85\n95 -47\n90 -2\n82 30\n63 87\n54 95\n-12 99\n-38 99\n-87 89\n-90 87\n-95 67\n-96 49", "19 -995485 -247211\n-995485 -247212\n-995004 -492984\n-993898 -887860\n-938506 -961227\n-688481 -971489\n178005 -999731\n541526 -999819\n799710 -988908\n905862 -967693\n987335 -887414\n983567 824667\n973128 892799\n914017 960546\n669333 986330\n-441349 986800\n-813005 986924\n-980671 973524\n-988356 849906\n-995289 404864", "15 -994056 554463\n-994056 554462\n-975707 -994167\n-711551 -996810\n13909 -997149\n809315 -993832\n980809 -984682\n996788 -303578\n993267 173570\n978439 877361\n898589 957311\n725925 992298\n-57849 999563\n-335564 997722\n-989580 990530\n-993875 973633", "23 -999839 738881\n-999839 738880\n-998291 -847192\n-995443 -982237\n-906770 -996569\n360950 -999295\n800714 -998808\n985348 -995579\n990091 -928438\n996690 -817256\n998844 -736918\n998377 674949\n998008 862436\n993320 971157\n978831 979400\n853341 986660\n802107 989497\n513719 996183\n140983 998592\n-158810 999459\n-677966 999174\n-949021 981608\n-982951 976421\n-993452 962292", "20 -999718 -377745\n-999718 -377746\n-997432 -940486\n-982215 -950088\n-903861 -997725\n-127953 -999833\n846620 -999745\n920305 -992903\n947027 -986746\n991646 -959876\n998264 -944885\n999301 870671\n994737 985066\n640032 998502\n-87871 999984\n-450900 999751\n-910919 999086\n-971174 995672\n-995406 975642\n-998685 946525\n-999684 673031", "26 -999921 -339831\n-999921 -339832\n-999666 -565163\n-998004 -942175\n-992140 -985584\n-965753 -998838\n-961074 -999911\n120315 -999489\n308422 -999258\n696427 -997199\n724780 -996955\n995651 -985203\n997267 -975745\n999745 -941705\n999897 -770648\n999841 -211766\n999436 865172\n999016 992181\n980442 997414\n799072 998987\n348022 999183\n-178144 999329\n-729638 998617\n-953068 997984\n-991172 990824\n-997976 939889\n-999483 581509", "22 -999929 -362069\n-999929 -362070\n-994861 -919993\n-989365 -946982\n-964007 -997050\n-418950 -998064\n351746 -998882\n830925 -996765\n867755 -996352\n964401 -992258\n996299 -964402\n997257 -930788\n999795 -616866\n999689 327482\n997898 996234\n923521 997809\n631104 998389\n-261788 999672\n-609744 999782\n-694662 999001\n-941227 993687\n-997105 992436\n-999550 895326", "27 -999898 136016\n-999898 136015\n-999877 -297518\n-999832 -906080\n-999320 -977222\n-998896 -995106\n-962959 -999497\n-747200 -999814\n417261 -999929\n844204 -999911\n959527 -999826\n998944 -999180\n999413 -989979\n999556 -943026\n999871 -774660\n999993 -261535\n999963 938964\n998309 991397\n989894 997814\n988982 998459\n987145 999235\n972224 999741\n603140 999994\n-812452 999962\n-980920 999788\n-996671 987674\n-999472 977919\n-999808 639816", "13 -1000000 -1000000\n-1000000 0\n0 -1000000\n999417 840\n999781 33421\n999994 131490\n999993 998865\n962080 999911\n629402 999973\n378696 999988\n53978 999788\n25311 999558\n6082 999282\n1565 998489", "16 -1000000 -1000000\n-1000000 0\n0 -1000000\n999744 572\n999931 96510\n1000000 254372\n999939 748173\n999894 953785\n999683 986098\n999051 999815\n980586 999969\n637250 999988\n118331 999983\n27254 999966\n9197 999405\n4810 997733\n1661 995339", "4 0 0\n1 -1\n1 3\n3 3\n3 -1", "3 0 0\n-10 1\n0 2\n1 1", "3 0 0\n-1 1\n4 1\n0 2"], "outputs": ["12.566370614359172464", "21.991148575128551812", "25.132741228718344928", "405.26545231308331191", "50026.721415763865583", "138283.48383306192359", "131381.40477312514811", "198410.42563011697403", "133558.52848206287476", "4719573.802783449531", "4295926.8918542123392", "574.91145560693214023", "60343.711690152746165", "50337.739088469255101", "32129.068068262814194", "52147.296456936975932", "58543.579099645794717", "16600304470662.964855", "16257949833603.158278", "19694832748836.689348", "21831930831113.094931", "18331542740428.216614", "18127026556380.411608", "18335297542813.80731", "21409384775316.574772", "399.0305992005743379", "980.17690792001545219", "1130.9820337250702449", "816.18577140262825159", "198309.89857373595223", "131821.20868619133483", "149316.61930888936332", "144023.17094830233827", "16257930301545.657524", "19694830011124.045712", "21831929255745.74826", "18331521646100.671528", "18127005627407.454252", "18335276455623.960732", "16600299044211.965457", "23547598153913.984406", "23547697574489.259052", "53.407075111026482965", "314.1592653589793116", "50.265482457436689849"]} | UNKNOWN | PYTHON3 | CODEFORCES | 20 | |
327dbb40ce764338d44efe10a6b74c17 | none | Appleman has a tree with *n* vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.
Consider a set consisting of *k* (0<=≤<=*k*<=<<=*n*) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (*k*<=+<=1) parts. Note, that each part will be a tree with colored vertices.
Now Appleman wonders, what is the number of sets splitting the tree in such a way that each resulting part will have exactly one black vertex? Find this number modulo 1000000007 (109<=+<=7).
The first line contains an integer *n* (2<=<=≤<=*n*<=≤<=105) — the number of tree vertices.
The second line contains the description of the tree: *n*<=-<=1 integers *p*0,<=*p*1,<=...,<=*p**n*<=-<=2 (0<=≤<=*p**i*<=≤<=*i*). Where *p**i* means that there is an edge connecting vertex (*i*<=+<=1) of the tree and vertex *p**i*. Consider tree vertices are numbered from 0 to *n*<=-<=1.
The third line contains the description of the colors of the vertices: *n* integers *x*0,<=*x*1,<=...,<=*x**n*<=-<=1 (*x**i* is either 0 or 1). If *x**i* is equal to 1, vertex *i* is colored black. Otherwise, vertex *i* is colored white.
Output a single integer — the number of ways to split the tree modulo 1000000007 (109<=+<=7).
Sample Input
3
0 0
0 1 1
6
0 1 1 0 4
1 1 0 0 1 0
10
0 1 2 1 4 4 4 0 8
0 0 0 1 0 1 1 0 0 1
Sample Output
2
1
27
| [
"n = int(input())\nedges = [int(x) for x in input().split()]\ncolor = [int(x) for x in input().split()]\ngraph = [[] for _ in range(n)]\n\nfor a,b in enumerate(edges):\n graph[a+1].append(b)\n graph[b].append(a+1)\ndp = [[0]*2 for _ in range(n)]\nvisited = [0]*n\n\nstack = [0]\nwhile stack:\n v = stack[-1]\n visited[v] = -1\n cn = 0\n for u in graph[v]:\n if visited[u] is not 0:\n continue\n else:\n cn += 1\n stack.append(u)\n if not cn:\n dp[v][0] = 1\n dp[v][1] = 0\n for u in graph[v]:\n if visited[u] is -1:\n continue\n dp[v][1] *= dp[u][0]\n dp[v][1] += dp[v][0] * dp[u][1]\n dp[v][0] *= dp[u][0]\n dp[v][1] %= 1000000007\n dp[v][0] %= 1000000007\n \n if color[v] is 1:\n dp[v][1] = dp[v][0]\n else:\n dp[v][0] += dp[v][1]\n dp[v][0] %= 1000000007\n visited[v] = 1\n stack.pop()\n \n\n# def dfs(v):\n # dp[v][0] = 1\n # dp[v][1] = 0\n# visited[v] = True\n# for u in graph[v]:\n # if visited[u] is True:\n # continue\n# dfs(u)\n# dp[v][1] *= dp[u][0]\n# dp[v][1] += dp[v][0] * dp[u][1]\n# dp[v][0] *= dp[u][0]\n# dp[v][1] %= 1000000007\n# dp[v][0] %= 1000000007\n \n# if color[v] is 1:\n# dp[v][1] = dp[v][0]\n# else:\n# dp[v][0] += dp[v][1]\n# dp[v][0] %= 1000000007\n\n# dfs(0)\nans = dp[0][1]\nprint(ans)\n",
"from collections import UserDict\n\n\nclass Tree(UserDict):\n def __init__(self, g):\n super().__init__()\n for name, value in enumerate(g, 1):\n self[value] = name\n\n def __setitem__(self, name, value):\n if name in self:\n if value is not None:\n self[name].add(value)\n self[value] = None\n else:\n if value is None:\n super().__setitem__(name, set())\n else:\n super().__setitem__(name, {value})\n self[value] = None\n\n\nif __name__ == '__main__':\n n = int(input())\n\n tree = Tree(int(i) for i in input().split())\n colors = [int(i) for i in input().split()]\n t = [()] * n\n\n def dfs(v):\n stack = [v]\n visited = set()\n\n while stack:\n v = stack.pop()\n if v not in visited:\n visited.add(v)\n stack.append(v)\n stack.extend(tree[v])\n else:\n t[v] = (1, colors[v])\n for u in tree[v]:\n t[v] = (\n (t[v][0] * t[u][1] + t[v][0] * t[u][0] * (not colors[u])) % (10**9 + 7),\n (t[v][1] * t[u][1] + t[v][0] * t[u][1] * (not colors[v])\n + t[v][1] * t[u][0] * (not colors[u])) % (10**9 + 7)\n )\n\n \n dfs(0)\n\n print(t[0][1])\n\n\n\n \n\n\n\n\n# Made By Mostafa_Khaled",
"MOD = 1000000007\r\n \r\nn = int(input())\r\np = [int(x) for x in input().split()]\r\nx = [int(x) for x in input().split()]\r\n \r\nchildren = [[] for x in range(n)]\r\n \r\nfor i in range(1,n):\r\n children[p[i-1]].append(i)\r\n\r\ncount = [(0,0) for i in range(n)]\r\nfor i in reversed(range(n)):\r\n prod = 1\r\n for ch in children[i]:\r\n prod *= count[ch][0]+count[ch][1]\r\n if x[i]:\r\n count[i] = (0,prod % MOD)\r\n else:\r\n tot = 0\r\n for ch in children[i]:\r\n cur = count[ch][1]*prod // (count[ch][0]+count[ch][1])\r\n tot += cur\r\n count[i] = (prod % MOD, tot % MOD)\r\n \r\nprint(count[0][1])",
"# by the authority of GOD author: manhar singh sachdev #\r\n\r\nimport os,sys\r\nfrom io import BytesIO,IOBase\r\n\r\ndef main():\r\n mod = 10**9+7\r\n n = int(input())\r\n path = [[] for _ in range(n)]\r\n for ind,i in enumerate(map(int,input().split())):\r\n path[i].append(ind+1)\r\n path[ind+1].append(i)\r\n col = list(map(int,input().split()))\r\n dp = [[1,0] for _ in range(n)]\r\n for i in range(n):\r\n dp[i][col[i]] = 1\r\n dp[i][col[i]^1] = 0\r\n # number of ways to construct subtree\r\n # no black vertex ; one black vertex\r\n st,poi,visi = [0],[0]*n,[1]+[0]*(n-1)\r\n while len(st):\r\n x,y = st[-1],path[st[-1]]\r\n if poi[x] != len(y) and visi[y[poi[x]]]:\r\n poi[x] += 1\r\n if poi[x] == len(y):\r\n if not col[st.pop()]:\r\n dp[x][1] = (dp[x][1]*dp[x][0])%mod\r\n if len(st):\r\n if col[st[-1]]:\r\n dp[st[-1]][0] = 0\r\n dp[st[-1]][1] = (dp[st[-1]][1]*sum(dp[x]))%mod\r\n else:\r\n dp[st[-1]][0] = (dp[st[-1]][0]*sum(dp[x]))%mod\r\n dp[st[-1]][1] = (dp[st[-1]][1]+dp[x][1]*pow(sum(dp[x]),mod-2,mod))%mod\r\n else:\r\n i = y[poi[x]]\r\n st.append(i)\r\n visi[i] = 1\r\n poi[x] += 1\r\n print(dp[0][1])\r\n\r\n# Fast IO Region\r\nBUFSIZE = 8192\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n def __init__(self,file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))\r\n self.newlines = b.count(b\"\\n\")+(not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd,self.buffer.getvalue())\r\n self.buffer.truncate(0),self.buffer.seek(0)\r\nclass IOWrapper(IOBase):\r\n def __init__(self,file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s:self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda:self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda:self.buffer.readline().decode(\"ascii\")\r\nsys.stdin,sys.stdout = IOWrapper(sys.stdin),IOWrapper(sys.stdout)\r\ninput = lambda:sys.stdin.readline().rstrip(\"\\r\\n\")\r\nif __name__ == \"__main__\":\r\n main()",
"mod=10**9+7\r\nn=int(input())\r\nedges=list(map(int,input().split()))\r\ncolored=list(map(int,input().split()))\r\nchilds=[[] for i in range(n)]\r\n\r\nfor i in range(1,n):\r\n childs[edges[i-1]].append(i)\r\n\r\ndp = [[0,0] for i in range(n)]\r\n\r\nfor i in range(n-1,-1,-1):\r\n prod=1\r\n for child in childs[i]:\r\n prod*=sum(dp[child])\r\n if colored[i]:\r\n dp[i]=[0,prod%mod]\r\n else:\r\n sec=0\r\n for child in childs[i]:\r\n now=dp[child][1]*prod//sum(dp[child])\r\n sec+=now\r\n dp[i]=[prod%mod,sec%mod]\r\n\r\n\r\nprint(dp[0][1])\r\n",
"import threading\r\nimport sys\r\n\r\nsys.setrecursionlimit(3 * 10 ** 5 + 200)\r\nthreading.stack_size(3 * 10 ** 5 + 100)\r\n\r\nMOD = 10 ** 9 + 7\r\n\r\ndp0u, dp1u = -1, -1\r\ndef dfs(v):\r\n if c[v]: # black\r\n dp0v = 0\r\n dp1v = 1\r\n \r\n for u in edges[v]:\r\n dp0u, dp1u = yield u\r\n dp1v *= dp0u + dp1u\r\n dp1v %= MOD\r\n else:\r\n dp0v = 1\r\n dp1v = 0\r\n \r\n for u in edges[v]:\r\n dp0u, dp1u = yield u\r\n dp1v *= dp0u + dp1u\r\n dp1v += dp0v * dp1u\r\n dp0v *= dp0u + dp1u\r\n dp0v %= MOD\r\n dp1v %= MOD\r\n \r\n yield v\r\n yield dp0v, dp1v\r\n\r\n# def dfs_interact(v):\r\n# stack = [(v, dfs(v))]\r\n# p = 0\r\n# while stack:\r\n# \r\n# \r\n# for u in stack[-1]:\r\n# if u == stack[-1][0]:\r\n# # all needed values were supplied\r\n# \r\n# break\r\n# else:\r\n# stack.append((u, dfs(u)))\r\n# else:\r\n# dp0u, dp1u = next(stack[-1][1])\r\n# stack.pop()\r\n\r\nn = int(input())\r\n*p, = [int(x) for x in input().split()]\r\n*c, = [int(x) for x in input().split()]\r\n\r\nedges = [[] for _ in range(n)]\r\nfor i in range(n - 1):\r\n edges[p[i]].append(i + 1)\r\n\r\ndp = [[0] * n, [0] * n]\r\nfor v in range(n)[::-1]:\r\n gen = dfs(v)\r\n \r\n u = gen.send(None)\r\n while u != v:\r\n u = gen.send((dp[0][u], dp[1][u]))\r\n \r\n dp[0][v], dp[1][v] = gen.send(None)\r\n\r\nprint(dp[1][0])"
] | {"inputs": ["3\n0 0\n0 1 1", "6\n0 1 1 0 4\n1 1 0 0 1 0", "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1", "5\n0 1 1 3\n0 0 0 1 1", "10\n0 1 1 2 4 3 3 3 2\n1 0 1 1 1 0 0 1 1 0", "100\n0 0 2 2 0 3 5 0 6 2 0 4 0 2 3 7 8 3 15 19 13 8 18 19 3 14 23 9 6 3 6 17 26 24 20 6 4 27 8 5 14 5 35 31 27 3 41 25 20 14 25 31 49 40 0 1 10 5 50 13 29 58 1 6 8 1 40 52 30 15 50 8 66 52 29 71 25 68 36 7 80 60 6 2 11 43 62 27 84 86 71 38 14 50 88 4 8 95 53\n1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1", "2\n0\n1 0", "115\n0 0 1 2 0 4 1 3 4 1 4 5 4 5 0 0 3 1 2 3 3 0 5 1 3 4 1 5 2 0 1 3 3 1 3 5 0 4 5 1 3 0 0 1 3 1 1 3 3 3 2 3 1 3 0 2 5 5 1 1 2 2 1 1 3 2 1 2 3 1 5 4 2 1 2 1 1 2 3 4 3 1 5 0 2 4 4 5 2 5 0 2 4 5 5 5 5 0 3 1 1 4 2 2 4 3 3 0 3 3 0 2 0 0\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"], "outputs": ["2", "1", "27", "1", "3", "9523200", "1", "1"]} | UNKNOWN | PYTHON3 | CODEFORCES | 6 | |
328f6c972f176799aaf085e6e87dbdad | Love Triangles | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has *n* characters. The characters are labeled from 1 to *n*. Every pair of two characters can either mutually love each other or mutually hate each other (there is no neutral state).
You hate love triangles (A-B are in love and B-C are in love, but A-C hate each other), and you also hate it when nobody is in love. So, considering any three characters, you will be happy if exactly one pair is in love (A and B love each other, and C hates both A and B), or if all three pairs are in love (A loves B, B loves C, C loves A).
You are given a list of *m* known relationships in the anime. You know for sure that certain pairs love each other, and certain pairs hate each other. You're wondering how many ways you can fill in the remaining relationships so you are happy with every triangle. Two ways are considered different if two characters are in love in one way but hate each other in the other. Print this count modulo 1<=000<=000<=007.
The first line of input will contain two integers *n*,<=*m* (3<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000).
The next *m* lines will contain the description of the known relationships. The *i*-th line will contain three integers *a**i*,<=*b**i*,<=*c**i*. If *c**i* is 1, then *a**i* and *b**i* are in love, otherwise, they hate each other (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*, ).
Each pair of people will be described no more than once.
Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1<=000<=000<=007.
Sample Input
3 0
4 4
1 2 1
2 3 1
3 4 0
4 1 0
4 4
1 2 1
2 3 1
3 4 0
4 1 1
Sample Output
4
1
0
| [
"class DisjointSet(object):\r\n def __init__(self, n):\r\n self.parent = list(range(n))\r\n self.rank = [0] * n\r\n self.num = n # number of disjoint sets\r\n\r\n def union(self, x, y):\r\n self._link(self.find_set(x), self.find_set(y))\r\n\r\n def _link(self, x, y):\r\n if x == y:\r\n return\r\n self.num -= 1\r\n if self.rank[x] > self.rank[y]:\r\n self.parent[y] = x\r\n else:\r\n self.parent[x] = y\r\n if self.rank[x] == self.rank[y]:\r\n self.rank[y] += 1\r\n\r\n def find_set(self, x):\r\n xp = self.parent[x]\r\n if xp != x:\r\n self.parent[x] = self.find_set(xp)\r\n return self.parent[x]\r\n\r\n\r\ndef solve():\r\n n, m = map(int, input().split())\r\n ds = DisjointSet(n * 2)\r\n for i in range(m):\r\n a, b, c = map(int, input().split())\r\n a -= 1\r\n b -= 1\r\n aA = a * 2\r\n aB = aA + 1\r\n bA = b * 2\r\n bB = bA + 1\r\n if c == 0:\r\n if ds.find_set(aA) == ds.find_set(bA):\r\n return 0\r\n ds.union(aA, bB)\r\n ds.union(aB, bA)\r\n else:\r\n if ds.find_set(aA) == ds.find_set(bB):\r\n return 0\r\n ds.union(aA, bA)\r\n ds.union(aB, bB)\r\n return pow(2, (ds.num // 2) - 1, 10**9 + 7)\r\n\r\n\r\nprint(solve())\r\n",
"class DSU(object):\r\n def __init__(self, n):\r\n self.father = list(range(n))\r\n self.size = n\r\n\r\n def union(self, x, s):\r\n x = self.find(x)\r\n s = self.find(s)\r\n if x == s:\r\n return\r\n self.father[s] = x\r\n self.size -= 1\r\n\r\n def find(self, x):\r\n xf = self.father[x]\r\n if xf != x:\r\n self.father[x] = self.find(xf)\r\n return self.father[x]\r\n\r\n\r\ndef is_invalid(a, b, ds):\r\n return ds.find(a) == ds.find(b)\r\n\r\n\r\nn, k = map(int, input().split())\r\nds = DSU(n * 2)\r\nfor i in range(k):\r\n first, second, color = map(int, input().split())\r\n first -= 1\r\n second -= 1\r\n if color == 0:\r\n if is_invalid(first, second, ds):\r\n print(0)\r\n exit()\r\n ds.union(first, second + n)\r\n ds.union(first + n, second)\r\n else:\r\n if is_invalid(first, second + n, ds):\r\n print(0)\r\n exit()\r\n ds.union(first, second)\r\n ds.union(first + n, second + n)\r\n\r\nsum = 1\r\nfor i in range(ds.size // 2 - 1):\r\n sum = (sum * 2) % (10 ** 9 + 7)\r\nprint(sum)\r\n",
"# union-find 2-SAT (A==B or A!=B)\r\nMOD = int(1e9 + 7)\r\nN, M = map(int, input().split())\r\ngroup = [ _ for _ in range(N*2+1)]\r\nvisit = [ 0 for _ in range(N*2+1)]\r\n\r\ndef pow2(a):\r\n if a==0: return 1\r\n if a%2==1:\r\n return pow2(a-1)*2%MOD\r\n res = pow2(a//2)\r\n return res*res%MOD\r\n\r\ndef find(a):\r\n if a == group[a]: return a\r\n group[a] = find(group[a])\r\n return group[a]\r\n\r\ndef union(a, b):\r\n group[ find(a) ] = find(b)\r\n\r\nfor _ in range(M):\r\n a, b, c = map(int, input().split())\r\n if c == 1: # same group\r\n union(a,b) # a == b\r\n union(a+N, b+N) # not a == not b\r\n else:\r\n union(a,b+N) # a == not b\r\n union(a+N,b) # not a == b\r\n\r\ngcnt = 0\r\nfor i in range(1,N*2+1):\r\n g = find(i)\r\n if visit[g]: continue\r\n visit[g] = 1\r\n gcnt+=1\r\n\r\nif gcnt%2 == 0:\r\n print(pow2(gcnt//2-1))\r\nelse:\r\n print(0)\r\n ",
"import sys\r\ninput = sys.stdin.buffer.readline\r\n\r\ndef find_root(root_dict, x):\r\n L = []\r\n while x != root_dict[x]:\r\n L.append(x)\r\n x = root_dict[x]\r\n for y in L:\r\n root_dict[y] = x\r\n return x\r\n\r\np = 10**9+7\r\ndef process(n, G):\r\n g = [[] for i in range(n+1)]\r\n root_dict = [i for i in range(n+1)]\r\n for a, b, t in G:\r\n if t==1:\r\n a1 = find_root(root_dict, a)\r\n b1 = find_root(root_dict, b)\r\n root_dict[a1] = b1\r\n for a, b, t in G:\r\n if t==0:\r\n a1 = find_root(root_dict, a)\r\n b1 = find_root(root_dict, b)\r\n g[a1].append(b1)\r\n g[b1].append(a1)\r\n sign = [None for i in range(n+1)]\r\n components = 0\r\n for root in range(1, n+1):\r\n if find_root(root_dict, root)==root and sign[root] is None:\r\n components+=1\r\n start = [root]\r\n sign[root] = 1\r\n while len(start) > 0:\r\n next_s = []\r\n for x in start:\r\n for y in g[x]:\r\n if sign[x]==sign[y]:\r\n sys.stdout.write('0\\n')\r\n return\r\n if sign[y] is None:\r\n sign[y] = -1*sign[x]\r\n next_s.append(y)\r\n start = next_s\r\n answer = pow(2, components-1, p)\r\n sys.stdout.write(f'{answer}\\n')\r\n \r\nn, m = [int(x) for x in input().split()]\r\nG = []\r\nfor i in range(m):\r\n a, b, t = [int(x) for x in input().split()]\r\n G.append([a, b, t])\r\nprocess(n, G)"
] | {"inputs": ["3 0", "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0", "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1", "100000 0", "100 3\n1 2 0\n2 3 0\n3 1 0", "9 2\n1 2 0\n2 3 0", "28567 13\n28079 24675 1\n18409 26720 1\n980 10815 1\n20794 16571 1\n7376 19861 1\n11146 706 1\n4255 16391 1\n27376 18263 1\n10019 28444 1\n6574 28053 1\n5036 16610 1\n3543 7122 1\n512 9554 1", "4 4\n1 2 0\n2 3 0\n2 4 0\n3 4 0", "4 3\n2 3 0\n3 4 0\n2 4 0", "6 6\n1 2 0\n2 3 1\n3 4 0\n4 5 1\n5 6 0\n6 1 1", "5 5\n1 2 0\n2 3 0\n3 4 0\n4 5 0\n1 5 0"], "outputs": ["4", "1", "0", "303861760", "0", "64", "928433852", "0", "0", "0", "0"]} | UNKNOWN | PYTHON3 | CODEFORCES | 4 | |
32affc2f5bd9de0f7bc25972e4d32d68 | Game of Robots | In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the *n*-th robot says his identifier.
Your task is to determine the *k*-th identifier to be pronounced.
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(2·109,<=*n*·(*n*<=+<=1)<=/<=2).
The second line contains the sequence *id*1,<=*id*2,<=...,<=*id**n* (1<=≤<=*id**i*<=≤<=109) — identifiers of roborts. It is guaranteed that all identifiers are different.
Print the *k*-th pronounced identifier (assume that the numeration starts from 1).
Sample Input
2 2
1 2
4 5
10 4 18 3
Sample Output
1
4
| [
"n, k = map(int, input().split())\nrobos = list(input().split())\nfor i in range(n):\n if k <= i + 1:\n print(robos[k - 1])\n break\n else:\n k -= i + 1\n \t\t \t \t\t\t\t \t\t \t \t \t\t",
"n,k=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nk1=int((2*k)**0.5)\r\nif k1*(k1+1)>=2*k:\r\n k1-=1\r\n k-=k1*(k1+1)//2\r\n print(a[k-1])\r\nelse:\r\n k-=k1*(k1+1)//2\r\n print(a[k-1])",
"k, n = input().split(\" \")\r\n\r\nline = list(map(int,input().split()))\r\n\r\nposi = 1\r\n\r\nn = int(n)\r\n\r\nwhile True:\r\n\r\n if n > posi:\r\n n -= posi\r\n posi += 1\r\n else:\r\n print(line[n-1])\r\n break\r\n \r\n ",
"def pos(n,k):\n for i in range(1,n+1):\n if((i-1) * i/2 < k and k <= i * (i+1)/2):\n break;\n k -= ((i-1) * (i/2)) + 1;\n return int(k); \n\n\n\nn, k = map(int,input().split(\" \"));\nids = input().split(\" \");\nprint(ids[pos(n,k)]);\n\t\t\t \t\t \t \t\t\t \t\t\t\t \t \t \t \t \t",
"n, k = list(map(lambda number: int(number), input().split(\" \")))\nlist_id = list(map(lambda number: int(number), input().split(\" \")))\n\nt = 1\nwhile k > t:\n k -= t\n t += 1\n\nprint(list_id[k-1])\n\n \t \t \t \t\t \t \t \t \t\t \t\t",
"n, k = input().split()\nids = input().split()\n\npa = 1\nult = 1\n\nk = int(k)\nfor i in range(int(n)):\n if ult >= k:\n ult -= pa\n break\n else:\n pa += 1\n ult += pa\n\nindex = (k - ult) - 1\n\nprint(ids[index])",
"n, k = input().split()\nrobos = input().split()\nk = int(k)\n\ni = 0\ncount = 0\nwhile count < k:\n\ti += 1\n\tcount += i\n\nposicao = count - k\nsaida = robos[:i][-(posicao + 1)]\nprint(saida)\n\n \t\t\t \t \t\t\t \t\t\t \t \t\t\t\t",
"def main():\r\n n,k = map(int, input().split())\r\n ids = input().split()\r\n a_s = [0]*(n+1)\r\n a_s[0] = 1\r\n a_s[1] = 1\r\n if k == 1:\r\n print(ids[0])\r\n return\r\n for i in range(2,n+1):\r\n a_s[i] = a_s[i-1]+i\r\n if a_s[i]>=k:\r\n print(ids[k-a_s[i-1]-1])\r\n return\r\n\r\nmain() ",
"n, k = map(int,input().split())\n\nseq = list(map(int,input().split()))\n\ncont = 0\n\nfor i in range(1,n + 1):\n\tcont += i\n\t\n\tif cont >= k:\n\t\tcont = i - (cont - k)\n\t\tprint(seq[cont - 1])\n\t\tbreak\n\t\t \t \t\t\t \t \t \t \t \t\t\t \t\t",
"n,k = tuple(map(int,list(input().split())))\r\nid = list(map(int,list(input().split())))\r\n\r\nt = 1\r\nwhile k>=t:\r\n k = k - t\r\n t = t + 1\r\n\r\nif k>0:\r\n print(id[k-1])\r\nelse:\r\n print(id[t-2])",
"read = input()\r\nn = int((read.split())[0])\r\nk = int((read.split())[1])\r\nrow = input()\r\nidentifiers = row.split()\r\nindex = 0\r\nnumeros_falados = 0\r\nfor i in range(1, len(identifiers)):\r\n if ((numeros_falados + i) < k):\r\n numeros_falados += i\r\n index += 1\r\n\r\n\r\nfaltam_falar = k - numeros_falados\r\nprint(identifiers[faltam_falar - 1])",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\ni = 1\r\nwhile k>i:\r\n k-=i\r\n i+=1\r\nprint(a[k-1])",
"from sys import stdin\nfrom math import sqrt, ceil\n\nn, k = map(int, stdin.readline().strip().split())\n\nids = stdin.readline().strip().split()\n\n\nrn = ceil((-1 + sqrt(1+8*k))/2) # simplified form of the quadratic formula for this equation\n\nindex = k-int((rn*(rn-1))/2)-1\nprint(ids[index])\n \t \t \t\t\t \t \t \t\t\t\t\t \t\t\t",
"n,k=map(int,input().split())\r\nlist1=list(map(int,input().split()))\r\n\r\ndata=0\r\nvalue=0\r\nwhile value<k:\r\n data+=1\r\n value=(data*(data+1))//2\r\ndata-=1\r\nreal=k-(data*(data+1)//2)\r\nprint(list1[real-1])\r\n",
"listaIndent = []\n\nqntRobos = input().split()\nindentRobos = input().split()\n\nrobo = int(qntRobos[1])-1\nqntRemovido = 0\n\nfor i in indentRobos:\n listaIndent.append(i)\n\n if qntRemovido + len(listaIndent) > robo:\n print(listaIndent[robo - qntRemovido])\n break\n else:\n qntRemovido += len(listaIndent)\n\n \t \t \t \t \t \t\t\t \t\t \t \t \t \t \t\t",
"n, k = map(int, input().split())\r\na, cur, now = list(map(int, input().split())), 0, 1\r\nwhile cur < k: cur, now = cur + now, now + 1\r\nprint(a[k - cur + now - 2])",
"n, k = [int(x) for x in input().split(' ')]\n\nrobots = [int(x) for x in input().split(' ')]\n\ncurrent = 0\n\nfor i in range(len(robots)):\n\n current += i\n\n if i+1 + current >= k:\n break\n\nprint(robots[(k - current) - 1])\n \t\t\t \t \t\t \t \t \t \t \t\t\t\t\t\t\t \t \t",
"n, k = input().split()\nn = int(n)\nk = int(k)\nseq = input().split()\nfor i in range(n):\n if k - i > 0:\n k -= i\n else:\n break\n\nprint(seq[k - 1])\n\n\t \t\t \t \t \t\t \t\t \t \t \t",
"n,k = [int(x) for x in input().split()]\r\nids = [int(x) for x in input().split()]\r\ncounter = 0\r\n\r\nfor i in range(n):\r\n counter += i + 1\r\n if counter >= k:\r\n print(ids[k - (counter - i)])\r\n break\r\n ",
"n, k = map(int, input().split())\r\nids = [int(i) for i in input().split()]\r\n\r\ni = 0\r\nm = 0\r\nwhile i < n and (m + i + 1) < k:\r\n i += 1\r\n m += i\r\n\r\nprint(ids[k - m - 1])\r\n",
"n , k = [int(x) for x in input().split()]\r\narr = [int(x) for x in input().split()]\r\n\r\nc = 0\r\nfor i in range(1 , 100000 + 1):\r\n if k - i > 0:\r\n k -= i\r\n else:\r\n break\r\n\r\nprint(arr[k-1])",
"import sys\ninput = sys.stdin.readline\n\nn, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\ncount = 1\nwhile k - count > 0:\n k -= count\n count += 1\nprint(a[k - 1])\n",
" \r\nn = input().split()\r\nidentificator= list(input().split())\r\n \r\n# auxiliar = []\r\n# c =0 \r\n# for i in range(0, int(n[0])):\r\n \r\n# if c >= int(n[1]):\r\n# break\r\n# auxiliar.clear()\r\n# auxiliar.append(identificator[:i+1])\r\n# c += len(identificator[:i+1])\r\n# print(c, 'é o C')\r\n \r\n# print(auxiliar[-1][int(n[1])-c-1])\r\n\r\nk = int(n[1])\r\nc= 0\r\nfor i in range(1, int(n[0])+1):\r\n if(c + i >= k):\r\n break\r\n c += i\r\n\r\nprint(identificator[k-c-1])\r\n\r\n # Otra forma de resolver el problema es usando un contador para saber cuantas\r\n # veces se ha recorrido la lista y asi saber en que posicion se encuentra el\r\n # robot.\r\n\r\n# if int(n[0]) == int(n[1]):\r\n# print(identificator[0])\r\n# elif int(n[0]) < int(n[1]):\r\n# print(identificator[-1])\r\n# else:\r\n# print(auxiliar[c-int(n[1])])\r\n\r\n\r\n\r\n",
"n, k = str(input()).split()\nn = int(n)\nk = int(k)\n\nrobots = str(input()).split()\n\ncount = 1\nwhile True:\n if k-count > 0:\n k -= count\n count+=1\n else:\n print(robots[k-1])\n break\n\n \t\t\t\t\t\t\t \t \t\t \t \t\t \t \t\t \t\t",
"n, k = map(int, input().split())\nidr = list(map(int, input().split()))\n\ncnt = 0\n\nfor i in range(1, n+1):\n\tcnt += i\n\tif cnt >= k:\n\t\tres = k - (cnt-i) - 1\n\t\tprint(idr[res])\n\t\tbreak\n\n \t\t \t \t \t \t\t\t \t \t \t",
"\nn,k = input().split(\" \")\nn, k = int(n),int(k)\nrobos = input().split(\" \")\ncount = 0\nfor i in range(1, n + 1):\n count += i\n if count >= k:\n print(robos[k - (count - i) - 1])\n break\n\n \t \t\t \t \t\t \t\t\t\t \t\t\t\t\t \t \t",
"n,k=map(int ,input().split())\r\na=list(map(int,input().split()))\r\ni=0\r\nc=0\r\nt=k\r\nwhile(k>i):\r\n k=k-i\r\n i+=1\r\nprint(a[k-1])\r\n",
"from math import sqrt\nfrom math import ceil\n\nn, k = map(int, input().split())\nsequence = list(map(int, input().split()))\n\nrobot = ceil((1 / 2) * (sqrt(1 + 8 * k) - 1))\npos = int(k - (robot * (robot - 1)) / 2)\nprint(sequence[pos - 1])\n \t\t\t \t\t \t\t\t \t\t\t\t \t \t\t\t \t",
"n,k=map(int,input().split()) ; s=input().split() \r\nfor i in range(1,n+1):\r\n if k-i>0:\r\n k-=i\r\n else:\r\n print(s[k-1]) ; break",
"n, k = [int(i) for i in input().split()]\r\na = [int(i) for i in input().split()]\r\n\r\nfor i in range(n):\r\n if (i + 1) >= k:\r\n print(a[k - 1])\r\n break\r\n else:\r\n k -= (i + 1)\r\n",
"n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\ni=0\r\nwhile True:\r\n\tif k-i>0:\r\n\t\tk-=i\r\n\t\ti+=1\r\n\telse:\r\n\t\tprint(l[k-1])\r\n\t\tbreak",
"import sys \r\ninput = sys.stdin.readline \r\nn, k = map(int, input().split())\r\nid = list(map(int, input().split()))\r\ni = 0\r\nwhile(k > i):\r\n k -= i \r\n i += 1 \r\nprint(id[k - 1])",
"n,k = map(int,input().split(' '))\r\nl = list(map(int,input().split(' ')))\r\n\r\nfor i in range(n):\r\n\tif k-i > 0:\r\n\t\tk = k-i\r\n\telse : \r\n\t\tbreak\r\n\r\nprint(l[k-1])",
"n,k = map(int,input().split())\r\narr = list(input().split())\r\n\r\ni = 1\r\nans = 0\r\nwhile True:\r\n ans += i\r\n if ans<k:\r\n i+=1\r\n else:\r\n break\r\nprint(arr[i+k-ans-1])",
"n,k = input().split(\" \")\nn = int(n)\nk = int(k)\n\narray = input().split(\" \")\narray_aux = []\nactual= \"\"\ncont = 0\n\nwhile True:\n if k-cont >0:\n k-= cont\n cont+=1\n else:\n print(array[k-1])\n break\n \t \t \t \t \t\t\t\t \t \t \t",
"k,p=map(int,input().split())\r\nh=list(map(int,input().split()))\r\nx=1\r\nwhile p>x:\r\n\tp=p-x\r\n\tx=x+1\r\nprint(h[p-1])",
"[n, k] = [int(i) for i in input().split(' ')]\r\n\r\narr = [int(i) for i in input().split(' ')]\r\n\r\ni = 1\r\nwhile int((i*(i+1)/2)) < k:\r\n\ti += 1\r\n\r\nres = int((i-1)*i/2)\r\ni = 0\r\n\r\nwhile res < k:\r\n\tres += 1\r\n\ti += 1\r\n\r\nprint(arr[i-1])",
"n,k = [int(x) for x in input().split()]\nidentifier = input().split()\nindex = 0\nfor i in range(n):\n if index + (i) < k:\n index += (i)\n else:\n break\nprint(identifier[(k-index)-1])\n\t\t \t \t\t\t \t \t\t\t \t\t \t\t",
"from math import sqrt, ceil\r\nn, k = [int(i) for i in input().split()] \r\na = [int(i) for i in input().split()]\r\nx1 = (-1 + sqrt(1 - 4 * 1 * (-2*k)))/2\r\nx2 = (-1 - sqrt(1 - 4 * 1 * (-2*k)))/2\r\nN = ceil(x1) if x1 >= 0 else ceil(x2) \r\nN -= ((N**2 + N)//2 - k)\r\nprint(a[N-1])",
"n, k = [int(i) for i in input().split()]\r\nids = [int(i) for i in input().split()]\r\n\r\nelem = 0\r\nindices = 0\r\n\r\nfor offset in range(1, n + 1):\r\n indices += offset\r\n\r\n if indices >= k:\r\n diff = indices - k\r\n elem = ids[offset - diff - 1]\r\n break\r\n\r\nprint(elem)\r\n",
"# Dada a sequência 1,1,2,1,2,3,1,2,3,4(...) retorna o k-ésimo termo\n# A sequencia é construida por \"somas\", onde cada soma é a soma dos n-primeiros naturais\ndef findKthElemSeq(k):\n n = 0 \n S = 0\n while S < k:\n n += 1 \n S = n*(n+1)//2\n if S > k:\n S = (n-1)*(n) // 2\n if S == k:\n return n\n else:\n return k - S\n\n# Author: Pedro Adrian Pereira Martinez\nif __name__ == \"__main__\":\n nk = list(map(int,input().split()))\n n,k = nk[0],nk[1]\n A = list(map(int,input().split()))\n print(A[findKthElemSeq(k)-1])\n\t \t\t\t \t \t \t \t \t \t \t\t",
"n, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\np = 1\r\ns = 0\r\nwhile s < k:\r\n s += p\r\n p += 1\r\np -= 1\r\nif s == k:\r\n print(arr[p - 1])\r\nelse:\r\n p -= (s - k)\r\n print(arr[p - 1])\r\n",
"a=[]\nn,k =input().split(\" \")\nn = int(n)\nk = int(k)\ncount1= 0\ncount=0\na.append(input().split(\" \")) \nfor i in range(k):\n count1= i+count1+1\n if(count1>=k):\n print(str(a[0][i-count1%k]))\n break\n \t\t \t \t \t\t \t \t\t\t \t",
"\r\nimport math\r\n\r\nn, k = map(int, input().split())\r\nl_i = list(map(int, input().split()))\r\n\r\nx = int((-1 + math.sqrt(1 + 4 * 2 * k)) // 2)\r\n\r\nif (x ** 2 + x) // 2 == k:\r\n print(l_i[x - 1])\r\nelse:\r\n print(l_i[k - (x**2 + x) // 2 - 1])",
"k=int(input().split()[1])\na=*map(int,input().split()),\ni=1\nwhile k>i:k-=i;i+=1\nprint(a[k-1])\n\t\t \t\t \t\t\t \t \t \t\t \t \t \t",
"n, k = map(int, input().split())\nl = list(map(int, input().split()))\n\nseqLast = 1\n\nwhile(k > seqLast):\n\tk -= seqLast\n\tseqLast += 1\n\nprint(l[k - 1])\n \t \t \t \t \t \t \t \t\t\t",
"n, k = map(int, input().split())\nID = input().split()\n\nt = 1\nwhile k > t:\n k -= t\n t += 1\n\nprint(ID[k - 1])\n \t\t\t \t \t \t\t\t \t\t\t \t\t \t\t \t\t",
"n, k = list(map(int, input().split()))\r\nid = list(map(int, input().split()))\r\ntriangle = 1\r\nwhile k > triangle:\r\n k -= triangle\r\n triangle += 1\r\n\r\nprint(id[k - 1])",
"t, k = map(int, input().split())\n\narr = list(map(int, input().split()))\n\nquant = 0\nveri = False\nfor c in range(1, len(arr) + 1):\n quant += c\n\n if(quant == k):\n print(arr[c - 1])\n veri = True \n break\n if(quant > k):\n passou = quant - k\n print(arr[c - passou - 1])\n veri = True\n break\nif(not veri):\n print(-1)\n\n \t \t\t \t\t \t \t\t\t\t\t \t \t \t\t\t",
"n,k = list( int(_) for _ in input().split())\r\nseq = list(int(_) for _ in input().split())\r\nx=1\r\nwhile k>x:\r\n\tk=k-x\r\n\tx=x+1\r\nprint(seq[k-1])\r\n",
"def l(k):\n m = 1\n mod = 1\n flag = True\n\n while flag:\n m += mod\n mod += 1\n if k >= m and k <= m + mod - 1:\n flag = False\n \n return m\n\nn, k = list(map(int, input().split()))\nid = list(map(int, input().split()))\n\nif k == 1:\n print(id[0])\nelse:\n min = l(k)\n print(id[k - min])\n\n\n\n\n\n \t\t \t \t \t\t \t\t\t \t\t \t\t \t\t \t",
"n, k = map(int, input().split())\r\n*id, = map(int, input().split())\r\ns = 1\r\nwhile k > s:\r\n k -= s\r\n s += 1\r\nprint(id[k - 1])\r\n",
"\r\nnum_inp=lambda: int(input())\r\narr_inp=lambda: list(map(int,input().split()))\r\nsp_inp=lambda: map(int,input().split())\r\nstr_inp=lambda:input()\r\na,b=map(int,input().split());s=0;i=1\r\nwhile(s+i<b):s+=i;i+=1\r\nprint(int(input().split()[b-s-1]))",
"from sys import stdin\r\n\r\nn, k = stdin.readline().split()\r\nn, k = int(n), int(k)\r\nids = stdin.readline().split()\r\n\r\nfor i in range(1, n+1):\r\n if ((i * (i+1)) / 2) >= k:\r\n k -= int((i * (i-1)) / 2)\r\n break\r\n\r\nprint(ids[k - 1])\r\n# a = []\r\n# x = 0\r\n# for i in range(1, n+1):\r\n# ids[i % ]\r\n# for j in range(i):\r\n# x += 1\r\n# if (x) == k: print(ids[j])",
"n,k = map(int,input().split())\r\narr = list(input().split())\r\n\r\nfor i in range(1,n++1):\r\n if k<=i:\r\n print(arr[k-1])\r\n break\r\n k-=i",
"n, k = map(int, input().split())\r\nID = input().split()\r\n \r\nt = 1\r\nwhile k > t:\r\n k -= t\r\n t += 1\r\n \r\nprint(ID[k - 1])",
"n,k = map(int,input().split())\nidt = list(map(int,input().split()))\nt,count =0,0\nfor i in range(1,n+1):\n\tcount+=i;t=i\n\tif count>=k:\n\t\tbreak\nans = t-(count-k)\nprint(idt[ans-1])",
"n , k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\npos = 1\r\nwhile k > pos:\r\n k -= pos\r\n pos += 1\r\nprint(arr[k-1])\r\n",
"n,k=map(int ,input().split())\na=list(map(int,input().split()))\ni=0\nc=0\nt=k\nwhile(k>i):\n k=k-i\n i+=1\nprint(a[k-1])\n \t \t\t \t\t \t \t \t\t\t\t\t\t \t\t\t",
"a,b=map(int,input().split());s=0;i=1\r\nwhile(s+i<b):s+=i;i+=1\r\nprint(int(input().split()[b-s-1]))",
"n, k = map(int, input().split())\nids = list(map(int, input().split()))\n\ni = 1\nr = 1\nwhile r < k:\n i += 1\n r += i\n\ndiff = r- k\npos = i - diff\n\nprint(ids[pos-1])\n\n\t\t\t \t\t\t\t\t\t\t \t \t \t\t \t \t \t\t\t\t",
"import math\r\nn,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nx1=math.floor((-1+(1+8*k)**0.5)/2)\r\nx2=math.floor((-1-(1+8*k)**0.5)/2)\r\nif x1>0:\r\n k-=((x1*(x1+1))/2)\r\n if k==0:\r\n print(l[x1-1])\r\n else:\r\n print(l[int(k-1)])\r\nelse:\r\n k-=((x2*(x2+1))/2)\r\n if k==0:\r\n print(l[x2-1])\r\n else:\r\n print(l[int(k-1)])\r\n",
"n, k = map(int, input().split())\r\nidr = list(map(int, input().split()))\r\n\r\ncnt = 0\r\n\r\nfor i in range(1, n+1):\r\n\tcnt += i\r\n\tif cnt >= k:\r\n\t\tres = k - (cnt-i) - 1\r\n\t\tprint(idr[res])\r\n\t\tbreak\r\n",
"nk = input().split()\r\nids = [int(x) for x in input().split()]\r\n\r\nn = int(nk[0])\r\nk = int(nk[1])\r\n\r\na = 0\r\nfor i in range(n):\r\n a += i\r\n if a >= k:\r\n a -= i\r\n break\r\n\r\nr = k - a\r\nprint(ids[r-1])",
"def solve(n,v):\r\n n-=1\r\n ans=-1\r\n for i in range(len(v)):\r\n if n<i+1:\r\n ans=v[n]\r\n break\r\n else:\r\n n-=i+1\r\n return ans\r\n\r\nln,n=map(int,input().split())\r\nv=list(map(int,input().split()))\r\nprint(solve(n,v))\r\n",
"n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nk_ = 0\r\nfor i in range(n):\r\n k_ += i + 1\r\n\r\n if k_ >= k:\r\n x = -(k_ - k) - 1\r\n print(a[:i + 1][x])\r\n break\r\n",
"n, k = map(int, input().split())\nids = list(map(int, input().split()))\n\nelemento = 0\nwhile k > 0:\n k -= elemento + 1\n elemento += 1\n\nk += elemento\nprint(ids[k - 1])\n\n\t\t\t \t \t\t \t\t \t\t \t\t\t\t",
"\ndef acressimo(n):\n r = n*(n+1)/2\n return int(r)\n\ndef procuraIndice(k):\n x = 1\n z = 0\n\n while True:\n y = acressimo(x)\n if y > k:\n break\n elif y == k:\n return x-1 \n x += 1\n z = y\n \n return k-z -1 \n\nen = str(input())\nl = en.split(\" \")\nseq = str(input())\nlist = seq.split(\" \")\ni = procuraIndice(int(l[1]))\nprint(list[i])\n\t \t\t \t\t \t \t\t \t \t \t\t \t \t\t",
"def robot (n,k,id) :\r\n current = 0\r\n robot_no = 1\r\n while current < k :\r\n current += robot_no\r\n robot_no += 1\r\n \r\n robot_no -= 1\r\n current -= robot_no\r\n diff = k - current\r\n return id[diff-1]\r\n \r\nn,k = list(map(int,input().split()))\r\nid = list(map(int,input().split()))\r\n\r\nprint (robot(n,k,id))\r\n \r\n \r\n ",
"import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\nn,k=(int(i) for i in input().split())\r\nl=[int(i) for i in input().split()]\r\nif(k==1):\r\n print(l[0])\r\nelse:\r\n for i in range(1,n+1):\r\n if((i*(i+1))//2<k and ((i+1)*(i+2))//2>=k):\r\n ind=i\r\n break\r\n print(l[k-(ind*(ind+1))//2-1])",
"n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\n\r\ni=1\r\nwhile i<k:\r\n\tk-=i\r\n\ti+=1\r\nprint(l[k-1])",
"n, k = map(int, input().split())\nidentifiers = list(map(int, input().split()))\n\ni = 0\nwhile True:\n if (1 + i) * i // 2 >= k:\n break\n\n else:\n i += 1\n\nif (i + 1) * i // 2 > k:\n i -= 1\n\ny = (i + 1) * i // 2\n\nif y == k:\n print(identifiers[i-1])\n\nelse:\n print(identifiers[k-y-1])\n\n \t\t \t\t\t \t \t\t\t\t\t \t\t \t \t \t\t \t",
"a,b=map(int,input().split())\r\nc=list(map(int,input().split()))\r\ns=1;o=1;flag=0\r\nfor i in range(a):\r\n if b-s<=0:\r\n while 1:\r\n if b-o==0:\r\n flag=1\r\n break\r\n o+=1\r\n if flag==1:\r\n print(c[o-1])\r\n exit()\r\n b-=s\r\n s+=1",
"#Игра роботов\n\nn, k = input().split(\" \")\nn, k = int(n), int(k)\n\nids = input().split(\" \")\nids = list(map(lambda s: int(s), ids))\n\ns = 1\nwhile ((s+2)*(s+1)/2 <= k):\n s = s + 1\n\nif s*(s+1)/2 == k:\n print(ids[s-1])\nelse:\n print(ids[int(k - s*(s+1)/2) - 1])",
"from math import sqrt, floor\n\nn, k = (int(i) for i in input().split())\nid = [int(i) for i in input().split()]\n# (1 + x) * x // 2 = k\n# x^2 + x - 2k = 0\n# D = 1 + 8k\n# x = (sqrt(D) - 1) / 2\nx = (sqrt(1 + 8 * k) - 1) / 2\n# check the position in the last segment\nx = int(x) - 1 if x == floor(x) else floor(x)\ni = k - (1 + x) * x // 2\nres = id[i - 1]\nprint(res)\n\n",
"n, k = map(int, input().split())\r\nnames = list(map(int, input().split()))\r\ni = 1\r\nwhile k > i:\r\n k -= i\r\n i += 1\r\nprint(names[k - 1])\r\n",
"n, k = map(int, input().split())\nids = input().split()\n\ni = 1\nwhile k > i:\n k-=i\n i+=1\n\nprint(ids[k-1])\n \t \t\t\t\t \t \t\t\t\t\t \t \t\t\t\t \t\t\t",
"n, k = map(int, input().split())\r\nids = list(map(int, input().split()))\r\n\r\ncurrent = 0\r\nwhile k > 0:\r\n k -= current + 1\r\n current += 1\r\n\r\nk += current\r\nprint(ids[k - 1])",
"n, k = [int(i) for i in input().split()]\r\na = [int(i) for i in input().split()]\r\nfor i in range(1, n + 1):\r\n if k > i:\r\n k -= i\r\n else:\r\n print(a[k - 1])\r\n break\r\n",
"n, k = map(int, input().split())\nid = list(map(int, input().split()))\nids = []\n\nfor robot in range(n):\n if k <= 0:\n break\n ids.append(id[robot])\n k -= len(ids)\n\nprint(ids[k-1])\n\t \t \t\t \t \t\t \t\t\t \t\t\t\t\t \t",
"n, k = list(map(lambda number: int(number), input().split(\" \")))\r\nids = list(map(lambda number: int(number), input().split(\" \")))\r\n\r\ncount = 1\r\nwhile k > count:\r\n k -= count\r\n count += 1\r\n\r\nprint(ids[k-1])\r\n",
"x,y = map(int,input().split())\r\nide = list(map(int,input().split()))\r\ncnt = 0\r\nfor i in range(1,x+1):\r\n\tcnt += i\r\n\tif(cnt >= y):\r\n\t\tans = ide[y-(cnt-i)-1]\r\n\t\tprint(ans)\r\n\t\tbreak\r\n\t",
"n, k = [int(x) for x in input().split(\" \")]\nsequencia = input().split(\" \")\nnums = 0\n\nfor i in range(n):\n nums = i+1\n if nums >= k:\n break\n k -= nums\n\nprint(sequencia[k-1])\n\n\t\t\t \t \t\t\t \t \t \t \t\t \t \t\t \t\t",
"numbers = input().split()\r\nk = int(numbers[1])\r\nsequence = input().split()\r\n\r\nnum = 1\r\n\r\nwhile True:\r\n\tif k - num > 0:\r\n\t\tk -= num\r\n\t\tnum += 1\r\n\telse:\r\n\t\tbreak\r\n\t\t\r\nprint(sequence[k-1])",
"a=input().split()\r\nn=int(a[0])\r\nk=int(a[1])\r\nd=list(map(int, input().split()))\r\ni=1 \r\nwhile k>i:\r\n k-=i\r\n i+=1\r\nprint(d[k-1])\r\n",
"x = list(map(int,input().strip().split()))[:2]\nrobos = x[0]\nkth = x[1]\nordem = list(map(int,input().strip().split()))[:robos]\nind = 0\n\nwhile(ind+1 < kth):\n ind += 1\n if (ind < kth):\n kth -= ind\n\nprint(ordem[kth-1])\n\t\t \t\t\t\t \t \t\t \t \t \t\t\t\t \t\t\t",
"n,k=map(int,input().split())\narr=list(map(int,input().split()))\nr=1\nwhile True:\n if r*(r+1)<=2*k :\n r=r+1\n else:\n r=r-1\n break\nl=k-((r*(r+1))//2)\nif l==0:\n print(arr[r-1])\nelse:\n print(arr[l-1])\n \t\t \t \t \t\t \t \t\t \t\t\t \t\t\t",
"n, k = map(int,input().split())\nl = []\nl = input().split()\nl = list(map(int, l))\n\nfor i in range(1,n+1):\n if (i*(i+1))/2 > k:\n answer = ((i*(i+1))/2) - k\n answer = int(answer)\n print(l[i-1-answer])\n\n break\n elif (i*(i+1))/2 == k:\n print(l[i-1])\n break\n\n\t\t\t\t\t\t\t\t\t \t \t\t \t \t \t \t",
"n, m = map(int, input().split())\n\na = list(map(int, input().split()))\ni = 1\nwhile True:\n if i * (i + 1) // 2 == m:\n pos = i\n break\n if i * (i + 1) // 2 > m:\n pos = m - (i * (i - 1) // 2)\n break\n i += 1\n\nprint(a[pos - 1])\n\n\n\t\t\t\t \t\t\t \t\t\t \t \t \t\t",
"# Wadea #\r\n \r\nn,k = map(int,input().split())\r\n \r\narr = list(map(int,input().split()))\r\nfor i in range(1,n+1):\r\n if k-i > 0:\r\n k -= i\r\n else:\r\n print(arr[k-1])\r\n break",
"n,k = map(int, input().split())\n\nk_els = [x for x in input().split()]\n\n\nprevious = 0\ncur_count = 0\nadditive_factor = 1\nfor i in range(len(k_els)):\n if k <= cur_count:\n break\n\n previous = cur_count\n\n cur_count += additive_factor\n additive_factor += 1\n\nprint(k_els[k-previous-1])\n \t\t \t\t \t \t\t \t \t\t \t \t\t \t \t",
"n,k=list(map(int,input().split()))\r\narr=list(map(int,input().split()))\r\nc=1\r\ns=0\r\nwhile True:\r\n s=s+c\r\n if s>(k-1):\r\n break\r\n else:\r\n c=c+1\r\n continue\r\nv=k-(s-c)\r\nprint(arr[v-1])\r\n \r\n \r\n",
"\r\n\r\n\r\ndef solve():\r\n n, k = map(int, input().split())\r\n ids = [int(i) for i in input().split()]\r\n \r\n x = (-1+(1 + 4*2*k) ** 0.5) / 2\r\n x = int(x)+1 if int(x) != x else int(x)\r\n f = x*(x-1)//2\r\n print(ids[k-f-1])\r\n\r\n\r\nsolve()\r\n",
"n, k = [int(x) for x in input().split()]\r\nidt = input().split()\r\n\r\nsoma = 1\r\ni = 0\r\n\r\nwhile soma <= k:\r\n\ti += 1\r\n\tsoma += i\r\n\r\naux = k - (soma - i)\r\nprint(idt[aux])\r\n\r\n",
"n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\ni = 1\r\nwhile True:\r\n if m <= i:\r\n print(a[m - 1])\r\n break\r\n m -= i\r\n i += 1# 1698251046.6190042",
"read = input()\nn = int((read.split())[0])\nk = int((read.split())[1])\nrow = input()\nidentifiers = row.split()\nindex = 0\nnumeros_falados = 0\nfor i in range(1, len(identifiers)):\n if ((numeros_falados + i) < k):\n numeros_falados += i\n index += 1\n\n\nfaltam_falar = k - numeros_falados\nprint(identifiers[faltam_falar - 1])\n\t\t\t \t \t\t \t \t\t \t\t\t\t\t\t\t \t \t",
"import math\nimport sys\nfrom collections import defaultdict\n#input = sys.stdin.readline\n\nUSE_FILE = False \n\ndef search(n, k):\n p = 0\n a = n\n while a >= 1:\n while p + a < n and (p+a) * (p+a+1) // 2 < k:\n p += a\n a //= 2\n return p\n\n\n\ndef main():\n n, k = tuple(map(int, input().split()))\n v = [int(i) for i in input().split()]\n p = 0\n\n p = search(n, k)\n modulo = k - p * (p+1) // 2\n if modulo == 0:\n return v[p]\n else:\n return v[modulo - 1]\n\n\n\n\nif __name__==\"__main__\":\n if USE_FILE:\n sys.stdin = open('/home/stefan/input.txt', 'r')\n print(main())\n",
"n,k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\n\r\nfor i in range(1,n+1):\r\n if k > i:\r\n k -= i\r\n continue\r\n else:\r\n print(arr[k-1])\r\n break",
"#670B (71No. Problem B)\r\n\r\nr,k = map(int,input().split())\r\nid = list(map(int,input().split()))\r\ntotal = 0\r\nfor i in range(1,r+1):\r\n if k - i > 0:\r\n k-=i\r\n else:\r\n print(id[k-1]) \r\n break\r\n\r\n",
"a,b=map(int,input().split());s=0;i=0\nwhile(s+i<b):s+=i;i+=1\nprint(int(input().split()[b-s-1]))\n\t \t \t\t \t \t \t \t \t \t\t\t \t",
"import sys\r\nfrom collections import Counter\r\ninput = lambda:sys.stdin.readline()\r\n\r\nint_arr = lambda: list(map(int,input().split()))\r\nstr_arr = lambda: list(map(str,input().split()))\r\nget_str = lambda: map(str,input().split())\r\nget_int = lambda: map(int,input().split())\r\nget_flo = lambda: map(float,input().split())\r\n\r\nmod = 1000000007\r\n\r\ndef solve(n,k,arr):\r\n\ti = 0\r\n\twhile i < k:\r\n\t\tk -= i\r\n\t\ti += 1\r\n\tprint(arr[k-1])\r\n\r\n\r\n\r\n\r\n\r\n\r\n# for _ in range(int(input())):\r\nn,k = get_int()\r\narr = int_arr()\r\nsolve(n,k,arr)",
"I=lambda:list(map(int,input().split()))\r\nn,k=I()\r\ni=0\r\nwhile i<k:k-=i;i+=1\r\nprint(I()[k-1])",
"n,k = map(int,input().split(\" \"))\nl = list(map(int,input().split(\" \")))\n\ns = (n / 2) * (1 + n)\ncontador = n\nfor i in range(n):\n oper = s - contador\n if oper < k:\n s -= contador\n break\n s -= contador\n contador -= 1\nan = contador -1\nsn = (((1 + an)*an) / 2 ) + 1\npos = k - sn\nprint(l[int(pos)])\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t \t \t\t\t \t \t \t\t\t \t \t",
"import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\nw = list(map(int, input().split()))\r\n\r\nm = [0, 0]\r\ns = 0\r\nfor i in range(1, n+1):\r\n s += i\r\n if k <= s:\r\n break\r\n m[i%2] = s\r\nprint(w[k - max(m) - 1])",
"from math import*\r\n\r\nn,k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nx = floor((-0.5) * (1 - sqrt(8 * k + 1)))\r\n\r\nif k == int(0.5*x*(x+1)):\r\n print(a[x - 1])\r\nelse:\r\n print(a[int(k - 0.5*x*(x + 1)) - 1])",
"import sys, io, os\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport string\r\nimport re\r\nfrom decimal import *\r\nfrom collections import defaultdict,Counter,deque\r\ninput = sys.stdin.readline\r\nsys.setrecursionlimit(100000) \r\n \r\ndef I():\r\n return input()\r\n \r\ndef II():\r\n return int(input())\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \r\ndef LI():\r\n return list(input().split())\r\n \r\ndef LII():\r\n return list(map(int, input().split()))\r\n \r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n \r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n \r\ndef WRITE(out):\r\n return print('\\n'.join(map(str, out)))\r\n \r\ndef WS(out):\r\n return print(' '.join(map(str, out)))\r\n \r\ndef WNS(out):\r\n return print(''.join(map(str, out)))\r\n\r\ndef WSNOPRINT(out):\r\n return ''.join(map(str, out))\r\n\r\n\r\n'''\r\n'''\r\ndef index(a, x):\r\n 'Locate the leftmost value exactly equal to x'\r\n i = bisect_left(a, x)\r\n if i != len(a) and a[i] == x:\r\n return i\r\n raise ValueError\r\n\r\ndef find_lt(a, x):\r\n 'Find rightmost value less than x'\r\n i = bisect_left(a, x)\r\n if i:\r\n return a[i-1]\r\n raise ValueError\r\n\r\ndef find_le(a, x):\r\n 'Find rightmost value less than or equal to x'\r\n i = bisect_right(a, x)\r\n if i:\r\n return a[i-1]\r\n raise ValueError\r\n\r\ndef find_gt(a, x):\r\n 'Find leftmost value greater than x'\r\n i = bisect_right(a, x)\r\n if i != len(a):\r\n return a[i]\r\n raise ValueError\r\n\r\ndef find_ge(a, x):\r\n 'Find leftmost item greater than or equal to x'\r\n i = bisect_left(a, x)\r\n if i != len(a):\r\n return a[i]\r\n raise ValueError\r\n\r\n\"\"\"\r\n1 2 3 4 5 6\r\n1 1 2 1 2 3 1 2 3 4 5 1 2 3 4 5 6\r\n\r\n1 3 6 10 15\r\n\"\"\"\r\ndef solve():\r\n n, k = MII()\r\n a = LII()\r\n\r\n b = [0,1]\r\n i = 2\r\n while b[-1] <= 2*10**9:\r\n b.append(i*(i+1)//2)\r\n i += 1\r\n\r\n idx = bisect.bisect_left(b, k) - 1\r\n dx = k - b[idx] - 1\r\n print(a[dx])\r\n\r\ndef main():\r\n solve()\r\n\r\nmain()\r\n\r\n",
"import math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\nimport functools\r\nfrom operator import itemgetter, attrgetter\r\nfrom collections import Counter\r\n\r\nif __name__ == '__main__':\r\n Y = lambda: list(map(int, input().split()))\r\n P = lambda: map(int, input().split())\r\n\r\n n, k = P()\r\n s, i, a = 0, 1, Y()\r\n\r\n while s + i < k:\r\n s += i\r\n i += 1\r\n print(a[k - s - 1])",
"n, k = list(map(lambda number: int(number), input().split(\" \")))\nids = list(map(lambda number: int(number), input().split(\" \")))\n\ncount = 1\nwhile k > count:\n k -= count\n count += 1\n\nprint(ids[k-1])\n\n \t \t\t \t\t\t \t \t \t \t\t\t\t\t\t \t\t"
] | {"inputs": ["2 2\n1 2", "4 5\n10 4 18 3", "1 1\n4", "2 1\n5 1", "2 2\n1 4", "2 3\n6 7", "3 1\n4 5 6", "3 2\n4 5 6", "3 3\n4 5 6", "3 4\n4 5 6", "3 5\n4 5 6", "3 6\n4 5 6", "4 1\n5 1000000000 999999999 12", "4 2\n5 1000000000 999999999 12", "4 3\n5 1000000000 999999999 12", "4 4\n5 1000000000 999999999 12", "4 5\n5 1000000000 999999999 12", "4 6\n5 1000000000 999999999 12", "4 7\n5 1000000000 999999999 12", "4 8\n5 1000000000 999999999 12", "4 9\n5 1000000000 999999999 12", "4 10\n5 1000000000 999999999 12"], "outputs": ["1", "4", "4", "5", "1", "7", "4", "4", "5", "4", "5", "6", "5", "5", "1000000000", "5", "1000000000", "999999999", "5", "1000000000", "999999999", "12"]} | UNKNOWN | PYTHON3 | CODEFORCES | 108 |
Subsets and Splits